A reddit bot replying to comments, containing factorials, with the solution. This little fella is currently running on r/mathmemes, r/unexpectedfactorial and on r/ProgrammerHumor.
Follow these steps to set up and run the Factorion bot on your local machine and account.
- Rust (latest stable version) - Install Rust
- Reddit Account - To run the bot, you'll need a Reddit account. Reddit
You can go to Reddit API Documentation to checkout all the different endpoints you can access.
- We need
Application ID
andSecret Key
so that Reddit can know about our app. preferences/apps - Click the are you a Developer? button to start setting up the bot.
- Fill in the required details:
- Name: Choose a name for your bot.
- App type: Select Script.
- Redirect URI: Use
http://localhost:8080
(or any URI; it’s not used for script bots).
- After creating the app, you'll receive:
client_id
(listed under the app name)client_secret
- A
username
andpassword
(for the Reddit account that created the app)
You might need to install some build dependecies: openssl, gmp, m4, pkg-config
cargo install --locked factorion-bot-reddit
Use the provided flake.
nix build github:tolik518/factorion-bot
# The binaries will be in result/bin
Skip to Running on a server.
Fork/Clone the repository and navigate to the project directory:
git clone https://github.com/tolik518/factorion-bot.git
cd factorion-bot
# To just build
cargo build -r
# The binaries will be in target/release
# To install
cargo install --path .
Create a .env
file in the project root with the following variables:
APP_CLIENT_ID=<your_client_id>
APP_SECRET=<your_client_secret>
REDDIT_USERNAME=<reddit_app_username>
REDDIT_PASSWORD=<reddit_app_password>
SLEEP_BETWEEN_REQUESTS=<sleep_time>
SUBREDDITS=<subreddits>
TERMIAL_SUBREDDITS=<subbreddits_with_termials>
CHECK_MENTIONS=<check_mentions>
CHECK_POSTS=<check_posts>
MENTIONS_EVERY=<check_mentions_every_nth_loop>
POSTS_EVERY=<check_posts_every_nth_loop>
FLOAT_PRECISION=<the_precision_floats_use> 1024
UPPER_CALCULATION_LIMIT=<maximum_number_to_precisely_calculate> 1000000
UPPER_APPROXIMATION_LIMIT=<maximum_number_to_approximte_exponent> 300
UPPER_SUBFACTORIAL_LIMIT=<maximum_number_to_precisely_calculate_subfactorial> 1000000
UPPER_TERMIAL_LIMIT=<maximum_number_to_precisely_calculate_termial_exponent> 10000
UPPER_TERMIAL_APPROXIMATION_LIMIT=<maximum_number_to_approximate_termial_bits> 1073741822
INTEGER_CONSTRUCTION_LIMIT=<maximum_integer_to_parse_exponent> 100000000
NUMBER_DECIMALS_SCIENTIFIC=<how_many_decimals_to_display> 30
INFLUXDB_HOST=localhost:8889
INFLUXDB_BUCKET=factorion-test
INFLUXDB_TOKEN=<token>
RUST_LOG=<factorion_bot|info|debug|trace|error|warn>
Replace with the values you received from the Reddit App creation.
InfluxDB is optional and can be removed if not needed.
The limits, precision and number of deciamls are optional, and will use default values if left away.
The _EVERY
variables are optional and default to 1
.
They control how often posts/mentions are checked compared to comments.
Setting them to 0
will result in a crash.
Set RUST_LOG
to factorion_bot
to see all logs, or error
to see only errors.
If built manually, run the bot with:
cargo run
Otherwise run the binary factorion-bot-reddit
.
# If in path (cargo install)
factorion-bot-reddit
# If local nix build
result/bin/factorion-bot-reddit
-
Create a new user for the bot so it can be mentioned by
/u/<botname>
-
Create a new subreddit
/r/<botname>
as a test play ground.
The recommended way would be running the bot using docker.
git clone https://github.com/tolik518/factorion-bot
docker build -t factorion-bot .
# either create a network called `service-network` or remove the network if not needed
export VERSION=<your_version_here>
export SSH_PATH=<your_path_on_server>
docker compose up -d
Feel free to submit issues or pull requests if you would like to contribute to this project. Help with ideas, math, code, documentation, etc. is greatly appreciated. If you are unsure about how to start, visit Contributing
If you use nix you can use nix develop
and/or nix-direnv to enter a devshell, that provides all dependencies.