Coder Social home page Coder Social logo

pyre-bot / pyre-bot Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 0.0 531 KB

Discord bot used to manage Risk of Rain 2 servers.

Home Page: http://discord.pyre-bot.com

License: GNU General Public License v3.0

Python 99.62% Dockerfile 0.38%
discord-py discord-bot risk-of-rain-2 steam-api steamworks pyre-bot discord game-servers ror2 botcommands

pyre-bot's Introduction

Pyre Bot

made-with-python Discord GPLv3 license Donate PRs Welcome Open Source Love svg3 ForTheBadge built-with-love Docker Pulls

Pyre Bot has one main goal: Create an easy-to-use way to manage a maintain dedicated game servers from within Discord. From sending commands to the game console to allowing players to initiate a restart vote, Pyre was created to make it as easy as possible.

Feel free to join our Discord if you want to discuss the bot or hang out!

Getting Started

These instructions will help make sure your system is ready to run the bot and help you get started using it for your needs.

Prerequisites

The bot can be ran without everything listed below, but this is what we recommend:

Installing

Pyre Bot is meant to be ran within Docker; we use AWS ECS but you can use whatever container service you like. If you prefer not to use containers, install the requirements and it can be ran locally.

The latest pre-built Docker images can be found here.

Discord

You need to get an API token from the Discord Developer Portal. The token will be used later in the environment variables. Invite the bot you create on the developer portal to your server and create the following for each RoR2 server you plan on running:

  • Admin commands channel
  • Public commands channel
  • In-game chat channel
  • Role for linked members

Also create a channel for all servers to post updates to.

Seq

Set up a Seq server to ingest the logs from the game, we use Twiner's GotSeq plugin to send our logs there. Seq needs te be set up with an API key for each server you plan to host.

AWS

Pyre Bot uses Amazon DynamoDB to store player stats from the servers and link Discord IDs to SteamIDs. You will need to setup an AWS account an add some tables to DynamoDB for this to work. Create the following tables:

  • BotCommands_Stats - Primary key: DiscordID (String)
  • Players - Primary key: DiscordID (String)
EFS

Since we host our Seq server in AWS as well as the bot, it is recommended to use EFS to enable your files to be shared between these services.

Environment Variables

Several variables need to be configured in the environment to make the bot run correctly, without these it will fail to run:

  • ADMIN_CHANNELS
  • ADMIN_ROLE
  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_KEY_ID
  • CHAT_CHANNELS
  • COMMANDS_CHANNELS
  • DISCORD_TOKEN
  • LINKED_ID
  • LOG_LEVEL
  • LOG_PATH
  • PLAYERS_TABLE
  • SEQ_API
  • SERVER_ADDRESSES
  • SERVER_CHANNEL
  • STATS_ENDPOINT
  • STATS_REGION
  • STATS_TABLE
  • TRACK_STATS

Never upload online or share your configuration to anyone you do not trust. These API keys are private and can result in your access from the services being removed if they get out.

Risk of Rain 2 requirements

The bot requires that you are using the following mods in your RoR2 server. Not having all of these mods installed and updated to their latest builds can result in certain features not working properly.

Required Mods

  • BepInEx
    • Change redirectOutputLog to true in your doorstop_config.ini to prevent double messages being sent to BepInEx terminal.
  • BotCommands
    • Used to send commands to the server from Discord
  • R2DSE
    • Outputs steam player names and IDs
  • DebugToolkit
    • Outputs run time and stages cleared
    • Enables additional commands to be sent to the server (i.e. give_item, give_equip)

Running and using the bot

If running in Docker, launch the bot using the following example command; consult your hosting server if using another container platform.

docker build -f Dockerfile -t pyre-bot:latest . 
&& docker run
-v path/to/your/log/folder:/data
--env ADMIN_CHANNELS=list,of,channels
--env ADMIN_ROLE=Admin
--env AWS_ACCESS_KEY_ID=
--env AWS_SECRET_ACCESS_KEY=
--env CHAT_CHANNELS=list,of,channels
--env COMMANDS_CHANNELS=list,of,channels
--env DISCORD_TOKEN=
--env LINKED_ID=
--env LOG_PATH=/data/
--env SEQ_API=
--env SERVER_ADDRESSES=list_of_server_address:with_ports
--env SERVER_CHANNEL=
--env STATS_ENDPOINT=https://dynamodb.us-east-2.amazonaws.com
--env STATS_REGION=us-east-2
--env STATS_TABLE=BotCommands_Stats
--env TRACK_STATS=yes
--env LOG_LEVEL=info
--name pyre-bot
--rm
pyre-bot:latest

Bot Commands

Available to everyone

  • restart : Initiates a vote to restart the server
    • Requires a majority vote (at least 75% of in-game player count)
  • votekick {player}: Initiates a 30-second vote to kick {player} from the Risk of Rain 2 server
    • Requires a majority vote (at least 75% of in-game player count)
  • endrun : Initiates a 30-second vote to end the current run in the Risk of Rain 2 server
    • Requires a majority vote (at least 75% of in-game player count)
  • info : Lists the game server status via Steamworks API
    • Listed info includes server name, current stage, player count, player names, and ping
  • link {SteamID} : Allows players to see their play stats for the Risk of Rain 2 server
    • Assigns the "Linked" role (NOTE: requires further config to not be hardcoded)
  • stats : Outputs your player stats to chat
    • Currently supported stats are Time Played, Stages Cleared, and Runs Completed
  • help : Displays all commands

Admin only

  • start : Starts the Risk of Rain 2 server
  • stop : Stops the Risk of Rain 2 server
  • delete {number} : Deletes the given amount of messages in the channel
  • say {message} : Sends an in-game message from the perspective of the server
  • cmd {command with args} : Passes on a command to execute by the server
    • Very experimental as of now, only use when you are sure of the results, as passing commands in certain contexts can cause unhandled exceptions with BotCommands
  • giveitem {player} {item} {quantity (default - 1)} : Gives a player a specified quantity of an item
  • giveequip {player} {equip} : Gives a player a specified equipment
  • restart_admin : Restarts the server without votes
  • help_admin : Displays information on how to use admin commands

Modifying the commands

By default the bot is configured to manage a Risk of Rain 2 server. This can be changed by calling the executables for other servers and pointing the checks at their respective logs.

Built With

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

To add functionality for other games or servers, add a new file in the cogs folder.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the GPL-3.0 License - see the LICENSE file for details

Changelog

0.10.0

  • Moved chat to its on cog
  • Server now posts updates to server update channel
  • Created Server class
  • Finally updated the README?

0.9.0

  • These updates got lost somewhere :)

0.8.0

  • Moved all stat tracking to Amazon DynamoDB for a better experience
  • Custom version of the Pygtail module is now packaged with the bot
  • Fixed an exception that occurred when the bot reconnected to Discord servers.
  • Complete rewrite of setup.py
  • Updated all requirements to newest versions
  • Various fixes, improvements, and optimizations that makes everyone's lives better

0.7.0

  • Added player stat tracking
  • Improved integration with DebugToolkit
  • Gets run time and stage number from the server log output directly
  • Other things I've likely just forgotten about ... it's been a while

0.6.0

  • Added configuration options for admin and command channels
    • This allows running multiple bot instances to manage more than one server
    • New global check makes sure the bot only listens to commands in these channels
  • Added dictionaries for items, equipment, and stages
  • Commands check dictionaries for values before issuing to the server
  • Added basic logging
  • Log can be found in the bot.log file in the bot's directory.
  • New delete command allows simpler delete or testing messages
  • Improved error handling
  • Steam query is now used to check if the server is running

0.5.1

  • Added giveequip command
  • status command now shows current stage name

0.5.0

  • Added say, endrun, giveitem, and votekick commands
  • Added a setup script to create config.ini on first launch
  • Added option to output game chat to Discord channel
    • Enabled by default, change in config.ini
  • Added automatic server restarts
    • Enabled by default, change in config.ini
  • Using new Steamworks API

pyre-bot's People

Contributors

dependabot-preview[bot] avatar infernalplacebo avatar superrayss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pyre-bot's Issues

[BUG] Discord bot does not verify the existence of an item or equipment before passing on give_item or give_equip

Since it doesn't verify the existence of the item or equip, it passes along a command which features (none) items or equips if given an argument that doesn't match anything in the game. The solution for this is to add dictionaries for items and equips that can be referenced. Keep in mind that DebugToolkit, which is the plugin that handles the give_item and give_equip commands, has autocomplete, i.e. you can say the item name is "shield" and it will know you meant to give the "PersonalShield" item and carry that out.

At the very least, the bot could wait for the server output, because if it doesn't find the item or equip it will give this as part of the output:
[Info : Unity Log] The requested object could not be found:

We could set that up the same way we set up the chat command to inform the sender on Discord that the item / equip is not found and to try again, and not passing the command to botcmd.txt.

Also add a dictionary for stages so that their "real" names can be referenced rather than their dev names (see: https://github.com/risk-of-thunder/R2Wiki/wiki/List-of-scene-names)

[REQUEST] Command to stop server on lobby, notify admin

Create an admin command which signals to the bot that next time the respective server hits the lobby, pass the "disconnect" cmd to the game server to shut it down and ping the admin user who used this command. I want this because I'm constantly checking to see which servers are in lobby when I want to shut down a server to update a plugin or something else. This would make it so I don't have to monitor them manually.

[BUG] Duplicate chat after reload

Describe the bug
When using the reload commands, autochat gets duplicated

To Reproduce
Steps to reproduce the behavior:

  1. Use >reload on the bot

Expected behavior
The bot will only output the chat once.

[REQUEST] Add update command

Is your feature request related to a problem? Please describe.
Create update command for admins that actually updates the server.

[REQUEST] Update setup script

Is your feature request related to a problem? Please describe.

  • The setup script sources an old version of BotCommands, please have it grab the latest at any given time
  • Allow setup script to read server configuration to set port automatically
  • Allow setup script to read IP to setup server address automatically
  • Rename server_config to match server.cfg

[REQUEST] Allow single bot instance to control multiple servers

Is your feature request related to a problem? Please describe.
Running multiple bot instances is excessive

Describe the solution you'd like
Single bot for several servers

Describe alternatives you've considered
Using the current channel dictionary, determine which bot is being used

Roadmap for new branch "cloud"

This branch is for developing a singular version of the bot, one that only requires one instance to control multiple servers. This requires the bot to read from server log files in a central directory for output to discord, as well as for the servers to read commands to ingest. Previously, each bot had its own installation, and had to be located on the same machine as the server, in order to read and write to the necessary files.

As of now, we have seq working to ingest logs from all servers simultaneously, filter out irrelevant events, and forward the resulting events to logs stored in centralized directory that can be (theoretically) read by one bot instance. I want to explore putting additional tags to the logs that signify to the bot which server wrote it, rather than the file name prefix notation I'm using now (which requires 1 log file per server).

The major challenge from this point is how to ingest commands to the game servers using our database system. I know that taking commands from discord and outputting them to another service with the Python bot is easy, and I just need to move that to its own feed, but how we go about having the server read from that feed is what we have to figure out now.

[REQUEST] Log players overall activity on the Risk of Rain 2 server

Access the player.duration variable in players.py, any time a player connects / disconnects (detected by the server log output already), add the duration of their time spent to a log that is tracked across sessions and can be output to the discord.

In the future, be able to assign Steam players to their Discord IDs so they can track their own stats. Can be expanded to things like runs cleared, times joined, etc.

Possible issue I forsee: May not be able to retrieve player.duration if the player just disconnected. Will have to test this out. If this is a problem, you could just compare the real time at which they joined to the real time at which they left to get their stay duration, instead of using player.duration.

[REQUEST] Disable stat tracking by default

Change stat tracking to disabled by default

Before this is completed the following must be done:

  • Disable stat tracking by default
  • Create config entries to enable or disable
  • Update documentation to reflect stat tracking
  • Update setup script to configure AWS credentials and create tables to ease setup

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.