Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Uses the Kings Maths School Seven Day Maths Weekly Challenge and their archive of problems for a Python Discord bot.

License

Notifications You must be signed in to change notification settings

CyberDiscovery/discord-maths-bot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Discord Maths Bot

A Discord Maths Bot written in Python. designed to give problems from the Kings Maths School Seven Day Maths website. https://www.kcl.ac.uk/mathsschool/weekly-maths-challenge/weekly-maths-challenge.aspx This includes the current weekly challenge, as well as a random problem from their archive.

Usage

  • !weekly to get the weekly challenge
  • !question to get a random problem from the archive

Dependencies

Python libraries:

  • discord - An API wrapper for Discord
  • requests - Used for HTTP requests to fetch content from the website
  • BeautifulSoup - From bs4, used to parse the HTML from the website
  • randint - From random, does what it says on the tin
  • re - Regular expressions, or regex, used for searching through the HTML
  • math - Mathematical functions, used for its .floor() function
  • requests_html - Used for additional HTTP requests and parsing HTML

Other

To know when the weekly challenge has change, the bot relies on a webhook that posts to a Discord channel to trigger the message with the Weekly Challenge in it. This is used because @sevendaymaths only tweets when the challenge has updated, and thus serves as a useful trigger for the bot. Currently, this is done with an IFTTT applet; further details can be found in the Installation guide but details of the applet can be found below.

Installation

Docker

The recommended way to deploy the bot is using the included Dockerfile. This will automatically set up the enviroment for the bot.

Manual Installation

The bot currently is only confirmed to work with Python 3.6. This may change depending on how discord.py is updated, but it is recommended to use at least Python 3.4, and any higher than Python 3.6 may not function correctly.

Install the required libraries using pip install -r requirements.txt. This will automatically install known good versions.

Setup

Once all the libraries are installed, the webhook and Discord channel must be set up. Create an IFTTT account if you have not already, then create a new applet. The trigger should be New tweet by a specific user where the username to watch is sevendaymaths. The response should be to Make a web request with IFTTT's webhook functionality. The URL should be your own Discord webhook URL; information on how to set this up can be found here. Make sure in your Discord server there is a dedicated (ideally private) channel set up, that can be used with this webhook. The following information should then be filled in about your request:

  • Method: POST
  • Content Type: application/json
  • Body: { "content":"!post {{Text}}"} (note: the content can contain anything, so long as it starts with !post)

Finally, set the enviroment variables that the bot needs.

TOKEN = "XXX" #This is the token from Discord for your bot. This assumes your bot has been created and set up already.
NOTIF_CHANNEL_ID = 'XXX' #This is the ID of the channel that your webhook will send messages to
TARGET_CHANNEL_ID = 'XXX' #This is the ID of the channel you would like the bot to send the message containing the Weekly Challenge to

And you should be good to go! Simply run your program python maths-bot.py to get your bot online.


This project is licensed under the terms of the MIT license, which can be found in the LICENSE.txt file in the root of the repository.

About

Uses the Kings Maths School Seven Day Maths Weekly Challenge and their archive of problems for a Python Discord bot.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 87.7%
  • Shell 10.8%
  • Dockerfile 1.5%