A Discord.py bot for the Swansea University MSc Computer Science (Non-specialist) Discord server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Genevieve Clifford 2233a0ddda
Merge branch 'master' of gitlab.com:merchygoedwig/ghostOfFinzi
9 months ago
lib mass addition of comments for everything that matters 9 months ago
scripts finished scripts and readme 9 months ago
.gitignore finished scripts and readme 9 months ago
LICENSE Add LICENSE 9 months ago
README.md changed readme again oops 9 months ago
install.sh mass addition of comments for everything that matters 9 months ago

README.md

finziBot: a Discord.py bot for fatigued Computer Science students

Preamble

finziBot is a Discord.py bot that posts reminders for lectures in a Discord server. It is principly designed around the needs of the MSc Computer Science Discord server for students on that course at Swansea University. finziBot is designed with the intention that it is run on a Raspberry Pi running Raspberry Pi OS. The reader is more than welcome to try this on other operating systems and architectures, but the author can make no guarantees that it will work.

Structure

The bot is designed around three services: bot, dbUpdate and finziDB. These three services run natively on the Raspberry Pi, with the first two being scheduled cron jobs written in Python that trigger hourly at XX:55 hrs and each day (6pm) and the latter being a MySQL server that is run all the time.

Setup

This GitLab repo contains all the executables and scripts needed to run the server, but additional setup will be needed beyond that, the exact instructions for the reader will depend upon who they are.

Instructions for fellow MSc Computer Science users

Please ask the author for access to the private GitLab repo containing data description files. If you'd like access to the Discord server for testing the main implementation of finziBot, please ask for that too.

Instructions for everyone else

The reader will need to setup their own data definition files, the syntax of which is discussed here. You'll need to provide three files, modules.json, lectureInfo.json and .env.

modules.json

modules.json is a list defining the name and lecturer for each module available. The primary key in each list is a string representing the code for the module, for example "CODE01". The value of each of the primary keys is another list containing "name" and "lecturer" keys, with user definable strings for the values. You may include as many modules in this definition file as you'd like.

// modules.json

{
    "CODE01": {
        "name": "Module Name 1",
        "lecturer": "Lecturer 1"
    },
    "CODE02": {
        "name": "Module Name 2",
        "lecturer": "Lecturer 2"
    },
    "CODE03": {
        "name": "Module Name 3",
        "lecturer": "Lecturer 3"
    }
}

lectureInfo.json

lectureInfo.json is a list defining all of the events that would typically be displayed in a timetable. The primary key for each key-value pair in the list is the same as modules.json. The value for each of these contains a nested list.

Nested List items
Key Allowed variables
"type" "zoom", "youtube-live", "discord"
"event" "lecture", "lab", "seminar"
"url" Link to event or false
"note" A string (optional)
"repeatInfo" See below
Key Allowed variables
"repeat" true or false
"start" "YYYY-MM-DD HH:mm"
"frequency" integer
"interval" integer (in days)
// lectureInfo.json

{
    "CODE01": [
        {
            "type": "zoom",
            "event": "lecture",
            "url": "[zoom-url]",
            "repeatInfo": {
                "repeat": true,
                "start": "2020-10-21 09:00",
                "frequency": 8,
                "interval": 7
            }
        }
    ],
    "CODE02": [
        {
            "type": "zoom",
            "event": "lecture",
            "url": "[zoom-url]",
            "repeatInfo": {
                "repeat": true,
                "start": "2020-10-27 09:00",
                "frequency": 7,
                "interval": 7
            }
        },
        {
            "type": "zoom",
            "event": "lab",
            "url": "[zoom-url]",
            "repeatInfo": {
                "repeat": true,
                "start": "2020-10-28 09:00",
                "frequency": 7,
                "interval": 7
            }
        },
        {
            "type": "zoom",
            "event": "lab",
            "url": "[zoom-url]",
            "repeatInfo": {
                "repeat": true,
                "start": "2020-10-28 11:00",
                "frequency": 7,
                "interval": 7
            }
        }
    ],
    "CODE03": [
        {
            "type": "youtube-live",
            "event": "lecture",
            "url": false,
            "note": "URL not provided, somebody post it when it's available!",
            "repeatInfo": {
                "repeat": true,
                "start": "2020-10-20 13:00",
                "frequency": 8,
                "interval": 7
            }
        },
        {
            "type": "youtube-live",
            "event": "lecture",
            "url": false,
            "note": "URL not provided, somebody post it when it's available!",
            "repeatInfo": {
                "repeat": true,
                "start": "2020-10-23 12:00",
                "frequency": 8,
                "interval": 7
            }
        },
        {
            "type": "discord",
            "event": "lab",
            "url": "[discord-invite-link]",
            "repeatInfo": {
                "repeat": true,
                "start": "2020-10-21 09:00",
                "frequency": 8,
                "interval": 7
            }
        }
    ]
}

.env

.env contains only one value at present, the token required to connect to the Discord API, this is read in using the python-dotenv and os Python libraries.

# .env

DISCORD_TOKEN=[your Discord token for the bot]

Installation

Initialising the Raspberry Pi

sudo apt update
sudo apt upgrade
sudo apt install git
git clone url # substitite with this project's URL

# at this point, clone your definition files over to the Pi, .env goes in lib/python/botStuff, the two json files go in lib/python/botStuff/data (you'll need to create the directory)
cd ghostOfFinzi/
sudo chmod +x install.sh
source install.sh
source ~/.bashrc

Setting up cron jobs

sudo chmod +x scripts/hourly.sh scripts/daily.sh scripts/project_env.sh

Run crontab -e and add the following to the top of the file after you've selected your preferred editor:

SHELL=/bin/bash

Add the following lines to the bottom of the cron file

55 * * * * . $HOME/ghostOfFinzi/scripts/project-env.sh; $HOME/ghostOfFinzi/scripts/hourly.sh >/dev/null 2>&1
0 18 * * * . $HOME/ghostOfFinzi/scripts/project-env.sh; $HOME/ghostOfFinzi/scripts/daily.sh >/dev/null 2>&1

You should now be done!