Skip to content

ja-cop/sc-chat-bridge

Repository files navigation

Sven Coop Chat Bridge

Container Image

Bot for bridging the in-game Sven Coop chat to Discord.

Features

  • Relays chat messages from game chat to Discord and vice versa
  • Announces to Discord when players join or leave the server
  • Chat messages and player announcements have player model preview images on Discord
  • Announces level changes to Discord, including series progress and map data from SCMapDB
  • Level changes and player announcements are edited to reflect players loading into the server
  • Current map and number of players also shown in the bot's Discord status
  • Announces to game chat when a user joins or leaves the specified Discord voice channel (optional)
  • Run RCON commands by sending messages to the specified command channel (optional)
  • Map voting by Discord emoji reactions (optional)

Installation

Prerequisities

The instructions below describe how to run the bot in a container on Linux. For other operating systems, see below. The containerized approach ensures that all dependencies are available, and should make installation easy across many different Linux distributions.

Before continuing with the instructions, you will also need to create a Discord "app" and get its bot token, on this page of Discord's website. (Always be careful and verify you're on the right site before putting in your Discord credentials anywhere on the web!)

This bot requires the "MESSAGE CONTENT INTENT" privileged intent to be enabled in the Discord application's bot settings.

Installing the Sven Coop Plugin

To install the plugin, download ChatBridgeLog.as (click "Raw" for direct download link) to <game dir>/svencoop/scripts/plugins/ChatBridgeLog.as, then edit <game dir>/svencoop/default_plugins.txt and add the following in "plugins":

"plugin"
{
    "name" "ChatBridgeLog"
    "script" "ChatBridgeLog"
}

While in the server files, make sure your server has an RCON password by setting rcon_password YOURPASSWORD in <game dir>svencoop/server.cfg.

Running the Bot

The container image is designed to be run "rootless", which is the default with Podman. These instructions assume the bot is running on the same host as the game server - instructions for running remotely will be added later.

The commands below should be run as an unprivileged user, which can be different from the game server's user, as long as the bot's user has read access to the game directories.

  1. Install Podman. Docker can be made to work too, but it's more complicated, so these instructions will use Podman
  2. Create a cache directory for the bot: mkdir -p "$HOME/.cache/sc-chat-bridge"
  3. Register your bot token as a Podman secret: printf "YOUR BOT TOKEN" | podman secret create scbridge-bot-token -
  4. Register your RCON password as a Podman secret: printf "YOUR PASSWORD" | podman secret create scbridge-rcon-password -
  5. Find the Discord channel ID for your bridge channel, where chat messages will be relayed. Optionally, also find the IDs for your voice channel and RCON command channel

Then, to run the bot directly from the command line, run:

podman run -it --rm --network=host \
    -v "/PATH/TO/SVEN:/svends" \
    -v "$HOME/.cache/sc-chat-bridge:/var/cache/sc-chat-bridge" \
    --secret scbridge-bot-token \
    --secret scbridge-rcon-password \
    ghcr.io/ja-cop/sc-chat-bridge:latest \
    sc-chat-bridge \
        --bridge-channel-id "PUT BRIDGE CHANNEL ID HERE" \
        --voice-channel-id "PUT VOICE CHANNEL ID HERE" \
        --rcon-channel-id "PUT COMMAND CHANNEL ID HERE" \
        --enable-map-voting

In the above command, replace /PATH/TO/SVEN with the path to your Sven Coop server's game directory (which contains svencoop, svencoop_addon etc), and also supply your own channel IDs.

This will pull the container image from Github and start the bot in a new container that runs in the foreground. Press Ctrl+C when you want to stop the bot, which will also remove the container.

Some things to note:

  • --rcon-channel-id is optional - but if you specify the RCON channel, make sure to use Discord permissions to only allow server administrators to send messages to this channel. The output of some RCON commands may also include personal information like IP addresses, so it's probably best if non-administrators can't view the channel at all
  • The scbridge-rcon-password Podman secret is required even without an RCON channel, as the bot uses RCON to communicate back to the game server
  • --voice-channel-id and --enable-map-voting are optional
  • If you encounter issues, add --bridge-log-level debug and --discord-log-level debug for more log output

Long-term, you might want to run the bot as a system service in order to run in the background, and optionally start on system boot. See here for instructions.

Discord Permissions

It's recommended to create a Discord role to give the bot the required permissions. The bot needs the following permissions:

  • "View Channel" for the bridge, voice and RCON channels
  • "Send Messages" for the bridge and RCON channels
  • "Attach Files" and "Add Reactions" for the bridge channel
  • "Read Message History" for the RCON channel (required for message replies)

Windows & Others

The bot is written to be platform-agnostic, and it is possible to run the bot directly, without a container. However, I haven't tested running it on Windows or other operating systems, so I don't know what issues might crop up. If anyone is interested in doing this, file an issue at this repository and I can try to help!

Credits

Thanks also to the developers of all the other dependencies!

About

Bridge Sven Coop in-game chat to Discord

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors