Giter Club home page Giter Club logo

watch-exchange-bot's Introduction

/r/Watchexchange Bot

Monitors /r/Watchexchange for certain criteria and posts to a Discord webhook when found.

Running

The program is designed to run "indefinitely". At a certain point, PRAW's "stream" function may encounter an error and the program will crash. No crash recovery is built-in, so using Docker Compose is recommended.

Bare Metal

Install Requirements

ℹ️A virtual environment is recommended for running on bare metal.

cd /wemb/src
python -m pip install -r requirements.txt

Running

python main.py

The program will run indefinitely (or until an error happens, see above). To quit prematurely, press Ctrl+C.

Docker Compose

A valid docker-compose.yaml file has been provided:

version: '3.9'
services:
  wemb-core:
    build: './wemb'
    restart: unless-stopped
    environment:
      - praw_client_id=${PRAW_CLIENT_ID}
      - praw_client_secret=${PRAW_CLIENT_SECRET}
      - praw_user_agent=${PRAW_USER_AGENT}
      - WEMB_LOGLEVEL=DEBUG
    volumes:
      - './wemb/src/config.yaml:/app/config.yaml:ro'

Note: This compose file uses an .env file to get the client id, secret, and user agent.

See the below sections on configuration for how to properly provide authentication, etc.

Configuration

There are two major configuration files / info that are required for this application to run.

PRAW Authentication

PRAW authentication can be provided in two ways: a praw.ini file, and through environment variables.

Prerequisites

Firstly, you need to provide some authentication for the Reddit API to function. This can be done by going to https://www.reddit.com/prefs/apps and creating an app. (more information here)

Since we only need read-only access to the API, we don't need much. Pick "script", give it a description and name. We need to copy two things:

  1. The client ID found under the bolded subheader of "personal use script" near the top of the box.
  2. The client secret, titled as "secret".

Both of these, along with a user agent, will be used to authenticate with the Reddit API.

Environment Variables

PRAW also takes configuration via environment variables. As described by PRAW's docs, the necessary/relevant environment variables are:

  • praw_client_id
  • praw_client_secret
  • praw_user_agent

You amy set these manually yourself, or use the method below.

Docker Compose .env File

If you run the program using Docker Compose (recommended), copy .env-example as .env, and fill in the client ID and secret. Don't forget to replace your username in the user-agent string:

 # Authentication used for PRAW
-PRAW_CLIENT_ID=
-PRAW_CLIENT_SECRET=
-PRAW_USER_AGENT=linux:com.example.watchexchangemonitorbot:0.1.0 (by /u/username)
+PRAW_CLIENT_ID=bjarElX6axdaiVnApRAaLP
+PRAW_CLIENT_SECRET=ZvxYlKpMd1z80SxZmTxZp2rkILRC3B
+PRAW_USER_AGENT=linux:com.example.watchexchangemonitorbot:0.1.0 (by /u/youruserhere)

⚠️Make sure to run docker compose from the same location as the .env file.

praw.ini

If you choose to use a praw.ini file, copy praw.ini.example as praw.ini, and fill in the client ID and secret. Don't forget to replace your username in the user-agent string:

 [DEFAULT]
-client_id=
-client_secret=
-user_agent=linux:com.example.watchexchangemonitorbot:0.1.0 (by /u/username)
+client_id=bjarElX6axdaiVnApRAaLP
+client_secret=ZvxYlKpMd1z80SxZmTxZp2rkILRC3B
+user_agent=linux:com.example.watchexchangemonitorbot:0.1.0 (by /u/youruserhere)

⚠️Make sure praw.ini is in the same directory as the script.

Application Configuration YAML

This program uses a config.yaml to control some application configuration. Each of the major sections are summarized below:

🚨 This will likely be removed in the future!

Note About Docker

When running in Docker Compose, a valid configuration must be mounted to the container, as one is not available as default. There is an example provided in the docker-compose.yaml file

Criteria

A top-level list of criteria that the bot will use to evaluate posts against. This is the only way to provide criteria to the bot.

Each element in the list needs four pieces of information:

  1. submissionType - Either "WTS" or "WTB". Filters the submission by those tags.
  2. minTransactions - The minimum number of transactions the posting user needs to have for this to be considered. Default 5.
  3. keywords - A LIST of keywords that need to show up in the submission for it to be considered. The behaviour of this is affected by the option below.
  4. allRequired - If true, ALL keywords in the previous option must be present for the post to be considered. If false, only one of them needs to be.

Webhook Information

The rest of the configuration file deals with webhook configuration. The following two pieces of information are required:

  1. webhookUrl - The URL for the webhook to post the message to. This can be copied directly from the webhook creation screen on a channel.
  2. mentionString - A mention string. This allows the bot to mention a specific person, or role. You MUST use IDs. Enable Developer mode in Discord settings to get the "Copy ID" button.
    • Example: <@&320244003583033356> is a role mention; and
    • <@575252669443211264> is a user mention.

Other Environment Variables

The application also takes other environment variables as configuration. They are listed below:

Environment Variable Possible Values Description
WEMB_LOGLEVEL Described in docs Controls the logging level. Turn up or down if you want more/less logs. Default: DEBUG.

watch-exchange-bot's People

Contributors

tabrnicus avatar

Watchers

 avatar

watch-exchange-bot's Issues

Exceptions in run_monitor do not restart the loop properly

run_monitor() does not handle exceptions properly. If there's an error in the reddit API that causes an exception to occur in the function, the call is propagated to the task and the task closes, leaving the bot without the monitor running

Properly support other databases

This at least includes postgres and sqlite.
This will also include some way to provide the connection string (using env vars)?

Should include example docker compose commands

on_ready is not idempotent within one session

If an error in the Discord API causes an exception that forces the bot to reconnect, cogs will load again without first unloading, This causes an exception in on_ready.

This can also cause the monitor loop to be called twice, if the first exception is handled. Consider cancelling the named task and starting it again to avoid this.

POC discord front-end

Represents a barebones POC discord bot frontend, where there is some way to CRUD on criteria

This also includes a way to spawn the WEMB-core process from another thread

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.