Skip to content

Repository files navigation

RustBot

Bot is still under development and not ready for production use

RustBot is a discord bot that executes whatever rust code you throw at it. In a nutshell, it is remote code execution as a service 😛. Some practical applications of a bot that executes whatever code you throw at it is for Code Golf on discord servers (this bot only does rust), or for educational purposes where you could show code examples in a conversation.

For more information on how RustBot works, see our internals page.

Future work for this bot includes:

  • Multitenancy/Admin commands: Allow admins to configure various settings, this would involve some form of database integration and adding additional contexts to bot messages.

Configuration

Want to run your own RustBot? Great! I only have instructions to get you started developing locally on your own machine. In the future I will provide instructions for server deployments.

  1. You need Podman installed.
  2. Clone this repo, and add the .env file with your token. See our instructions on how to make a token and add a bot to your server for local development
    DISCORD_TOKEN="YOUR_TOKEN_HERE"
    
  3. Build the container by running podman build -f Dockerfile_runner -t rustbot-runner:latest .
  4. OPTIONAL: if you are working on the container for rustbot itself, see the section on how to build the container
  5. Build and run this project with cargo run

Environment Variables

These can either by specified by a .env file, or by exposing them the regular way.

NameDescriptionRequired?Default Value
DISCORD_TOKENDiscord bot tokenRequired
BOT_PREFIXPrefix to use for commandsOptional!
MAX_CONTAINER_RUNTIMEMax amount of milliseconds before the container is killedOptional5000
CONTAINER_CPUMax amount of CPU to delegate to the containerOptional0.5
CONTAINER_MEMORYMax amount of memory available to the containerOptional100m
CONTAINER_SWAPMax amount of swap available to the containerOptional5m
CONTAINER_IMAGEContainer image to useOptionalUses a local rustbot-runner:latest for dev builds, for release it uses the ghcr.io container image
IS_RUNNING_IN_CONTAINERTells RustBot if it's running as a containerOptionalFalse by default, True by default for our container builds

Bot Commands

More commands should be coming soon, here is what we support at the moment:

  • !run: runs arbitrary code. The command expects there to be a code block.

    For example:

    !run

    ```rs

    fn main() { println!("Hello RustBot"); }

    ```

    Or, without the language identifier:

    !run

    ```

    fn main() { println!("Hello RustBot"); }

    ```

    The bot will react with 🔨 to indicate your code is building / being executed, a to indicate the run is successful, and to indicate something went wrong. A reply will be posted by the bot with the standard output of your code. For the above example the response would be

    Hello RustBot
    

    For edge cases such as if a response is too long, the response will be truncated to fit Discord's max message length.

  • !ping: Checks if the bot is working. The bot will react to your message and respond with PONG.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

A discord bot that safely executes whatever rust you throw at it. Remote code execution as a service

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages