├── .gitattributes ├── .gitignore ├── LICENCE ├── Procfile ├── README.md ├── add.html ├── dev_requirements.txt ├── images ├── blue_heart.png ├── calculator.png ├── calculator.svg ├── downarrow.png ├── logo.png ├── patreon.png ├── tex.png └── wa-logo.jpg ├── index.html ├── logo.svg ├── mathbot ├── __init__.py ├── __main__.py ├── advertising.py ├── autoreload ├── bot.py ├── calc ├── calculator │ ├── __init__.py │ ├── __main__.py │ ├── ast.md │ ├── blackbox.py │ ├── bytecode.md │ ├── bytecode.py │ ├── crucible.py │ ├── errors.py │ ├── formatter.py │ ├── functions.py │ ├── grammar.md │ ├── interpereter.py │ ├── library.c5 │ ├── operators.py │ ├── parser.py │ ├── runtime.py │ └── scripts │ │ ├── addition.c5 │ │ ├── aperture.c5 │ │ ├── assignment.c5 │ │ ├── c6.c5 │ │ ├── cycle.c5 │ │ ├── error_evaluation.c5 │ │ ├── error_parse.c5 │ │ ├── exponential_bytecode.c5 │ │ ├── fib.c5 │ │ ├── filter.c5 │ │ ├── graph.c5 │ │ ├── large.c5 │ │ ├── lists.c5 │ │ ├── nothing.c5 │ │ ├── queue.c5 │ │ ├── quicksort.c5 │ │ ├── sayaks.c5 │ │ ├── simple.c5 │ │ └── user.c5 ├── core │ ├── __init__.py │ ├── blame.py │ ├── help.py │ ├── keystore.py │ ├── parameters.py │ ├── settings.py │ └── util.py ├── count_objects.py ├── fonts │ └── roboto │ │ ├── LICENSE.txt │ │ ├── Roboto-Black.ttf │ │ ├── Roboto-BlackItalic.ttf │ │ ├── Roboto-Bold.ttf │ │ ├── Roboto-BoldItalic.ttf │ │ ├── Roboto-Italic.ttf │ │ ├── Roboto-Light.ttf │ │ ├── Roboto-LightItalic.ttf │ │ ├── Roboto-Medium.ttf │ │ ├── Roboto-MediumItalic.ttf │ │ ├── Roboto-Regular.ttf │ │ ├── Roboto-Thin.ttf │ │ └── Roboto-ThinItalic.ttf ├── help │ ├── about.md │ ├── blame.md │ ├── calculator_brief.md │ ├── calculator_full.md │ ├── calculator_history.md │ ├── calculator_libraries.md │ ├── commands.md │ ├── help.md │ ├── latex.md │ ├── management.md │ ├── oeis.md │ ├── prefix.md │ ├── purge.md │ ├── roll.md │ ├── settings.md │ ├── theme.md │ ├── turing.md │ ├── turing_functions.md │ ├── units.md │ └── wolfram.md ├── imageutil.py ├── modules │ ├── __init__.py │ ├── about.py │ ├── analytics.py │ ├── blame.py │ ├── calcmod.py │ ├── dice.py │ ├── echo.py │ ├── greeter.py │ ├── heartbeat.py │ ├── help.py │ ├── latex │ │ ├── __init__.py │ │ ├── replacements.json │ │ └── template.tex │ ├── oeis.py │ ├── purge.py │ ├── reboot.py │ ├── reporter.py │ ├── settings.py │ ├── throws.py │ └── wolfram.py ├── not_an_image ├── open_relative.py ├── parameters_default.json ├── patrons.py ├── queuedict.py ├── safe.py ├── startup_queue.py ├── test ├── test_specific ├── update_logo.py ├── utils.py ├── wolfapi.py └── wordfilter │ ├── __init__.py │ ├── __main__.py │ └── bad_words.txt ├── requirements.txt ├── runtime.txt ├── scripts ├── _install_deployment_deps.sh ├── _push_code.sh ├── cleanup_redis_store.py ├── grab_recent_logs.sh ├── install_deployment_deps.sh ├── pm2_main.sh ├── pull_redis_creds_from_heroku.sh ├── push_code.sh ├── push_config.sh └── startup_queue.sh ├── stats.txt ├── style.css └── tests ├── __init__.py ├── _conftest.py ├── _test_using_automata.py ├── test_calc_helpers.py ├── test_calc_library.py ├── test_calculator.py ├── test_core_help.py ├── test_parameters.py ├── test_safe_print.py ├── test_supress_params.py └── test_wordfilter.py /.gitattributes: -------------------------------------------------------------------------------- 1 | *.svg binary -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.png 2 | __pycache__ 3 | *.sublime* 4 | .cache 5 | *.zip 6 | ignore 7 | keystore.json 8 | parameters.json 9 | # virtualenv directory 10 | venv/ 11 | .flake8 12 | # coverage.py 13 | .coverage* 14 | htmlcov 15 | .mypy_cache 16 | *.pyc 17 | .pytest_cache 18 | .vscode/ 19 | Pipfile.lock 20 | .venv 21 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | amethyst: cd mathbot && python entrypoint.py PARAMETERS.env '{"shards": {"mine": [6, 7]}}' 2 | emerald: cd mathbot && python entrypoint.py PARAMETERS.env '{"shards": {"mine": [8, 9]}}' 3 | saphire: cd mathbot && python entrypoint.py PARAMETERS.env '{"shards": {"mine": [10, 11]}}' 4 | topaz: cd mathbot && python entrypoint.py PARAMETERS.env '{"shards": {"mine": [12, 13]}}' 5 | opal: cd mathbot && python entrypoint.py PARAMETERS.env '{"shards": {"mine": [14]}}' 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MathBot 2 | 3 | MathBot is a discord bot that contains a number of features to help with mathematics. 4 | 5 | It's primary features are: 6 | - LaTeX rendering 7 | - Querying Wolfram|Alpha 8 | - A Turing complete calculator 9 | 10 | The bot is currently developed on python `3.8.10`, but should work on later versions of Python. 11 | 12 | ## Links 13 | 14 | - [Add the bot to your own server](https://dxsmiley.github.io/mathbot/add.html) 15 | - [Official Discord Server](https://discord.gg/JbJbRZS) 16 | 17 | ## Setup for use 18 | 19 | ```bash 20 | git clone https://github.com/DXsmiley/mathbot.git 21 | cd mathbot 22 | cp mathbot/parameters_default.json ./parameters.json 23 | python3.8 -m venv .venv # or later version 24 | source .venv/bin/activate 25 | pip install -r requirements.txt 26 | ``` 27 | 28 | Then open parameters.json and change `tokens` to the token of the bot used for development. Optionally change the other parameters. 29 | 30 | It is *strongly* recommend that you setup an instance of Redis if you want to use the bot on even a moderate scale. The disk-based keystore is easy to setup but runs very slowly, and as such is only useful of a development tool. 31 | 32 | Run the bot with `python -m mathbot parameters.json`. 33 | 34 | ## Setup for development 35 | 36 | Follow above instructions, but additionally run `pip install -r dev_requirements.txt` 37 | 38 | ## Contributing guide 39 | 40 | Relevent discussion takes place on [the MathBot Discord server](https://discord.gg/JbJbRZS). 41 | 42 | ## Setting up Wolfram|Alpha 43 | 44 | 1. [Grab yourself an API key](https://products.wolframalpha.com/api/) 45 | 2. Open parameters.json and change `wolfram > key`. 46 | 47 | This should really only be used for development and personal use. 48 | 49 | ## Test Suite 50 | 51 | Invoke `pytest` to run the test suite. 52 | 53 | ~~Some of the tests require that a bot is running and connected to Discord. To enable them, use the `--run-automata` command line argument. In addition a file with the necessary tokens filled out needs to be provided to the `--parameter-file` argument. To get all tests running, the *token*, *automata* and *wolfram* parameters need to be filled out.~~ 54 | 55 | ~~For the sake of example, I run my tests with the command `./test --run-automata --parameter-file=dev.json`. You should replace `dev.json` with a path to your own parameter file.~~ 56 | 57 | ~~There are some additional tests that require a human to verify the bot's output. These can be enabled with `--run-automata-human`.~~ 58 | 59 | ## Guide to `parameters.json` 60 | 61 | - *release* : Release mode for the bot, one of `"development"`, `"beta"` or `"production"` 62 | - *token* : Token to use for running the bot 63 | - *wolfram* 64 | - *key* : API key for making Wolfram|Alpha queries 65 | - *keystore* 66 | - *disk* 67 | - *filename* : The file to write read and write data to when in disk mode 68 | - *redis* 69 | - *url* : url used to access the redis server 70 | - *number* : the number of the database, should be a non-negative integer 71 | - *mode* : Either `"disk"` or `"redis"`, depending on which store you want to use. Disk mode is not recommended for deployment. 72 | - *patrons* : list of patrons 73 | - Each *key* should be a Discord user ID. 74 | - Each *value* should be a string starting with one one of `"linear"`, `"quadratic"`, `"exponential"` or `"special"`. The string may contains additional information after this for human use, such as usernames or other notes. 75 | - *analytics* : Keys used to post information to various bot listings. 76 | - *carbon*: Details for [carbonitex](http://carbonitex.net/) 77 | - *discord-bots*: API Key for [bots.discord.pw](https://bots.discord.pw/#g=1) 78 | - *bots-org*: API Key for [discordbots.org](https://discordbots.org/) 79 | - *automata* 80 | - *token* : token to use for the automata bot 81 | - *target* : the username of the bot that the automata should target 82 | - *channel*: the ID of the channel that the tests should be run in 83 | - *advertising* 84 | - *enable* : should be `true` or `false`. When `true`, the bot will occasionally mention the Patreon page when running queries. 85 | - *interval* : the number of queries between mentions of the Patreon page. This is measured on a per-channel basis. 86 | - *starting-amount* : Can be increased to lower the number of commands until the Patreon page is first mention. 87 | - *error-reporting* 88 | - *channel*: ID of channel to send error reports to. 89 | - *webhook*: Webhook to send error reports to. 90 | - *shards* 91 | - *total*: The total number of shards that the bot is running on. 92 | - *mine*: A list of integers (starting at `0`) specifying which shards should be run in this process. 93 | 94 | ## Additional Installation Issues (Ubuntu only) 95 | 96 | If you don't have python 3.8 97 | ``` 98 | sudo add-apt-repository ppa:deadsnakes/ppa 99 | sudo apt update 100 | sudo apt install python3.8 101 | ``` 102 | 103 | If you have installation troubles with cffi or psutil 104 | ``` 105 | sudo apt-get install python3.8-dev 106 | ``` 107 | -------------------------------------------------------------------------------- /add.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |