/discord-simp

Simple user-configurable Discord bot that will respond to messages whenever there is a RegEx match.

Primary LanguagePythonMIT LicenseMIT

Discord Simple RegEx Message Bot unittest

This bot will read messages from any channel it is in, search the message for a RegEx pattern defined in the first column of 'replies.csv', and replies with the second column of 'replies.csv' if a match is found. It was not designed as a public bot, but pull requests to support this feature and store responses per server are welcomed.

Installation

  1. Create your Discord bot user and invite it to your server by following this guide: https://discordpy.readthedocs.io/en/stable/discord.html
  2. Download and install latest version of Python.
  3. git clone this repository or download zip (under the green Code button or from Releases page) and extract it.
  4. Open cmd and go into the repository folder by typing cd <REPOSITORY_FOLDER_PATH>
  5. Create virtual environment: python -m venv bot-env
  6. Activate virtual environment: bot-env\Scripts\activate on Windows, bot-env/bin/activate on Linux.
  7. Install dependencies: pip install -r requirements.txt
  8. Run the bot: python bot.py which will generate the config.ini file. It will then exit, telling you to get your bot's token from https://discord.com/developers/applications.
  9. Edit config.ini so that token = <YOUR_BOT_TOKEN>
  10. Repeat step #8.

 

Help! I get gcc build errors when installing the multilib or yarl dependencies!

Try MULTILIB_NO_EXTENSIONS=1 YARL_NO_EXTENSIONS=1 pip install -r -requirements.txt. This issue occurs when multilib and yarl wheel binaries are not available for your operating system, so these extra flags will disable the compiled speedups and use the slower Python scripts instead.


replies.csv Example

RegEx Pattern Message to Send Requires Mention? React with Emoji
\bfries\b "there is the thin skinless ones, thick skinless, thic with skin, truffle oil, sour scream fries, fries dip on MCD ice cream cone" 0 🍟

fries


Administrator Commands

Type these commands in any text channel the bot is in to execute them. Only works with users having the Administrator role in that channel.

  • !list

    Shows a truncated list of all rows in the .csv file and their indices. The row index is used in add/delete operations.

    list

  • !list <index>

    Shows the full detail of the given row index.

    list0

  • !add <row>

    Adds a comma-delimited string as a new row into the .csv file.

    add

    The 'row' parameter is entered exactly as how you would type it in the .csv file. In this example, the parameter can be broken into 4 parts: \bsomething\b, i'm alive!, 0 and <custom emoji>. It corresponds to the 4 fields shown in the previous 'replies.csv Example' section.

  • !reload

    Loads 'replies.csv' without restarting the bot client. This should be done after add or delete.

    reload

    After reloading, sending a message that matches the \bsomething\b regular expression shown in the previous !add example will now trigger the bot's response:

    saysomething

  • !delete <index>

    Deletes the given row index from the .csv file.

    delete