Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.
/ Hlin-discord-bot Public archive

A discord bot to generate inspiring and comforting quotes

Notifications You must be signed in to change notification settings

Overlrd/Hlin-discord-bot

Repository files navigation

Hlin-discord-bot

A discord bot to generate inspiring and comforting quotes , part of the Hlin project


loading

Setup

Prerequisites

To run the bot, you will need the following:

Helpfull Ressources

Running the Bot

To run the bot:

  • Create a Python virtual environment and install the dependencies listed in requirements.txt
 $ python3 -m venv .virtual-env
 $ source .virtual-env/bin/activate
 $ pip install -r requirements.txt
  • Run the setup.py file to automaticaly create and write config.json and .env files
 $ python3 setup.py
  • You will need to provide your Discord Bot token , Mongodb Connection Link and Google Perspective API Key

  • Run the feed_database.py file to get quotes from the zenquotes API (make sure to read the docs) or any other API (which may require further configuration).

$ python3 feed_database.py
  • And start the Bot
$ python3 main.py

Hosting with Replit (optional)

If you plan to host the bot with replit.com, note that the Replit servers shut down if 30 minutes pass without them being pinged. To work around this, you can start a Flask server with the keep_alive.py file and use a website like Uptime Robot that will ping your server periodically.

About the Database

By default, a database called quotes will be created, and the quotes will be stored in a collection called quotes_collection.

The quotes are structured as follows:

{
  "_id": { "$oid": "63f4c572798e1cdb2613fd04" },
  "author": "Walt Whitman",
  "quote": "Simplicity is the glory of expression. ",
  "date": "23:02:21:13:21:54"
}

When retrieving a quote from the database, a random quote is selected, and only the author and quote fields are retrieved.

When feeding a quote to the database, the author, quote, and date``` fields are required. The document to insert should look like:

doc = { "author": quote_author, "quote": quote_text, "date": now }

Bot Structure

The bot has three commands stored in cogs/quote_cogs.py:

  • inspire: grab a quote from the database.

    • Calls the utils.get_quote_from_db() function.
    • Returns a string structured like: quote - author.
    • Sends the quote string to the user.
  • add_quote: post a quote to the database.

    • Calls the perspective_client.analyze_quote(quote) function.
    • Returns a toxicity score.
    • Calls the utils.post_quote(quote, username) function and sends the quote to the database based on the toxicity score.
  • daily_quotes: sends a daily quote at a specified hour.

    • Calls the utils.setup_daily_quotes(interaction, time) function with the provided time in HH:MM format passed by the user.
    • Updates or creates if not exist the user's configuration stored in a config.json file.
    • The utils.start_scheduled_task() function starts on the bot's on_ready() event.
    • Reads the configs and triggers the utils.send_daily_quote_to_user(user_id, bot) function.
    • Sends the quote to the user at the specified GMT time.

About

A discord bot to generate inspiring and comforting quotes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages