Chris Sprance

Character Technical Director

My Robot Army

While on Miscreated we encountered lots of situations where we wanted to create a system to monitor some "thing" or allow some user to restart some server or run some commands on any number of servers.

The company uses discord as our main form of communication and because of this we were able to take advantage of the Discord API to create a bot to do any number of company functions. This has a couple of benefits:

  1. It's really easy to keep grant a permission to do some task using roles in discord
  2. Inversely that means it's easy to revoke a permission.
  3. By nature of a chat room every interaction is logged for all to see.
  4. No user authentication needs to be handled.
  5. Communication with the bot outside of approved channels isn't possible.
  6. All bot facilities can be accessed from one simple command line in a chat room

Framework

The bot had a few different types of "things" it could do.

  • Extensions
    • Extensions are generally self contained tools that only use the bot messaging facilities to report but otherwise are self contained tools
  • Middleware
    • Middleware run on specific chat events: messageRecieved, userJoined, userLeft, etc, etc and allow you to react to things happening but aren't something a user would specifically execute they just happen.
  • Commands
    • A command is something a user explicitly executes by calling it from chat addressing it to the bot

Middleware

Profanity

We used the bot to control profanity in all of the community discord channels. We've found that generally most messages with profanity in them tend to be fairly useless as far as feedback goes.

It also had the surprising effect of someone coming in angry and typing a profanity laced message. Have it removed and then they type a more coherent message without profanity because they've been given a chance to cool down. This works better then a moderator policing these kinds of things because then there is never any one person to direct ire at. It's just a robot how angry can you be at a bot?

Extensions

Server Health Checks

I wrote a script to ping all of the game servers with an RCON command every 5 minutes. If the server fails the ping command 3 times in a row it will send out a notification in a special health-check channel containg a few moderators with special permissions to send a command to those servers to force a restart or link to click on that will redirect to a server control panel to look at more metrics.

It also checked to see if the official servers were registered on the steam master servers because occasionally there were situations in which a server would be working just fine but for whatever reason fail to register on the master server making it look like the server was down.

If this happened any of the moderators in the health-check channel could easily send a command to restart the server:

bot restart-server [SERVERID]

PerfMon

This extension will send a command every few minutes to all server and gather specific data about that server and store it in a database. This database could then be used to query with the a bot command and compile a graph or in real time using a grafana dashboard. This helped us analyze changes we made to server code and track performance over longer periods of time as well as give as an estimate of primetimes for each specific server and adjust restart times if those times intersected with the maximum amount of players on a server.

Commands

restart-server

This command when executed will send a restart command using a specific API to restart a server. It will then report back if the command was executed

sysinfo

This command when executed and provided a server id will collect data from a server using RCON parsing the response and then formatting it and sending it in chat. This is a useful command to gather data on what is happening internally with a server.

Often in chat people would complain that a specific server was messing up or had bad performance. Rather than forcing a moderator or developer to jump in to the game (a process that could take anywhere from 5-10 minutes) you just send a command and take a look at the data. It's usually fairly obvious when a server is having problem and when it's just a user experiencing issues or internet connectivity problems