A Star Sonata chat relay bot.
Install Docker and docker-compose
Sign up for Discord Developer and create a bot.
Head to the OAuth2 tab, under the OAuth2 URL Generator section, check the bot scope and copy the generated URL. Paste this in your browser's address bar to invite the bot to your Discord server.
# clone a copy of the repository
git clone git@github.com:Delph/Relayer.git
cd Relayer
# grab the SS API dependency
git submodule update --init --recursive
# configure
nano bot.env
nano mapping.json
# build image
docker-compose build
# run it
docker-compose up -dbot.env loads some core information required for the bot to run, all the keys listed in the sample below are required.
RELAY_CHARACTER is the character you wish to use to log in as, numbered in order they appear in the client, with 0 being the first one (i.e., 0 is the first character, 1 is the second character, 4 is the fifth character).
Sample file:
DISCORD_TOKEN=YourDiscordBotToken
# relay user
RELAY_USERNAME=ssUsername
RELAY_PASSWORD=ssPassword
RELAY_CHARACTER=0
mapping.json defines what messages get relayed from what channels to what channels.
Sample file:
[
{
"DISCORD_CHANNEL": 1,
"STARSONATA_CHANNEL": "TEAM",
"MODE": "rw"
},
{
"DISCORD_CHANNEL": 2,
"STARSONATA_CHANNEL": "ALL",
"MODE": "r"
}
]DISCORD_CHANNELis the channel ID (turn on Developer Mode in Settings -> Appearance, right click on a channel to get it's ID).STARSONATA_CHANELis the channel in game, valid options areALL,GALAXY,TEAM,TRADE,SQUADandHELP. Note that whileSQUADandGALAXYare options, the bot has no squad functionality and galaxy chat is unlikely to work.MODEis the relay mode, which can either be read, write, or both (rworwr). Read means the messages are relayed to Discord, write means the messages are relayed to the game. Do not use write mode for public chats.
You can have as many relay options as you want and overlapping channels (e.g., you could setup an #announcements channel which is write only, and a team relay which is read-write).
alerts.json defines what messages the bot should send alerts for.
Sample file:
[
{
"name": "attack",
"pattern": "^\\[WARNING\\] Base (?P<base>.*?) in (?P<galaxy>.*?) is under attack from player (?P<player>.*?)(?: on team (?P<team>.*?))?$",
"channels": [804411672609161359],
"message": "Station {base} in {galaxy} is under attack by {player} on team {team}",
"mentions": [674207458045984801],
"ignore": ["team=Deep Space Federation"]
},
{
"name": "cutoff",
"pattern": "^The following galax(?:ies are|y is) cut off from your HQ galaxy and will be unowned after 24 hours: (?P<galaxy>.*) \\((?P<time>.*)\\)$",
"channels": [804411672609161359],
"message": "{galaxy} is cutoff from the HQ",
"mentions": [720637616621355029]
}
]nameis an internal name used to reference the alertpatternis a Python regular expression to match an incoming message from Star Sonata against. Regular expressions can be tested on regex101.com. Note that named capture groups are used in the patternchannelsis a list of channel IDs of where to send the alert tomessageis the message to send tochannels, any captured value frompatterncan be used and substitutedmentionsis a list of user or role IDs to mention in the message (although, this could be baked directly intomessage).ignoreis a list of conditions on when to ignore an alert, again, matching on captured groups frompattern. This allows you filter out self-attack alerts and such.
You can have as many alerts as you wish, but do note they are only one way.
Currently the bot has one command, !restart, occasionally the connection to the game server can be lost and the bot doesn't become aware to automatically reconnect to it. In these instances the restart command can be used.