Skip to content

M45-Science/ChatWire

Repository files navigation

ChatWire Logo

ChatWire

Factorio Server Manager & Discord Bridge

License: MPL 2.0 Go CI Go Report Go Version Vulncheck

Command Overview

Requirements:

Linux
Golang 1.24.11+

ChatWire is approximately 15.9k lines of Go code across 120 files. Launching will create a default auto-config to get you started.
Needs permissions to create files and directories in its own directory, and up one directory.

Some dirs and files that can be auto-created:
cw-local-config.json, ../cw-global-config.json
cw.lock, ../playerdb.json
../map-gen-json/, ./log/, ./audit-log/, ../www/public_html/archive/
Discord token, appid, guild-id and channel-id are required, as well as Factorio username and token.

Building ChatWire:

git clone https://github.com/Distortions81/M45-ChatWire.git
cd M45-ChatWire
go build

This produces the ChatWire binary in the current directory.
Launching the binary for the first time will create cw-local-config.json and ../cw-global-config.json.
Edit these files to provide your Discord credentials, Factorio token and server paths.
After configuring run ./ChatWire -regCommands to register slash commands.

Default path layout:

A 'base' folder the chatwire folder resides in.
~/factServers/

For ChatWire:
./cw-a/ChatWire-binary-here

Factorio:
./cw-a/factorio/

Binary:
./cw-a/factorio/bin/x64/Factorio
This is setup to have many servers running, and so some files and directories are setup to be common.

Example files

The example-files directory contains sample systemd units, configuration files and helper scripts for managing multiple servers. Copy them and adjust the paths as needed for your environment.

Launch parameters:

Flag Description
-cleanBans Clean and minimise the player database, remove bans then exit.
-cleanDB Clean and minimise the player database then exit.
-deregCommands Deregister Discord commands and quit.
-localTest Disable public/auth mode for testing.
-noAutoLaunch Disable auto-launch.
-noDiscord Disable Discord integration.
-proxy HTTP caching proxy URL. Format: proxy/http://example.domain/path.
-regCommands Register Discord commands.

Setting up your Discord bot

  1. Visit https://discord.com/developers/applications and create a New Application.
  2. Under Bot click Add Bot. Enable the Presence, Server Members and Message Content intents and grant these permissions: view channels, manage channels, manage roles, send messages, embed links, attach files, mention all roles, manage messages (delete message if register code leaked), read message history and use application commands.
  3. Copy the Token from the bot page and note the Application ID from OAuth2 > General.
  4. In Discord enable Developer Mode and right click your server to Copy ID for the guild ID.
  5. Copy a channel ID or leave ChatChannel blank in cw-local-config.json and ChatWire will create one on first run.

Development and Testing

Run go fmt to format the code and go vet for linting before committing. Tests can be executed with:

go fmt ./...
go vet ./...
go test ./...

These are the same checks executed by the CI pipeline. Some integration tests connect to Discord. Set CW_TEST_TOKEN, CW_TEST_GUILD and CW_TEST_APP to enable them.

Regenerating configuration

If you need to reset the configuration files, delete cw-local-config.json and ../cw-global-config.json and start ChatWire again. Fresh copies will be generated automatically. You can also reload the configs at runtime using the ReloadConfig moderator command.

Running the bot locally

Build the binary and register the Discord slash commands:

go build
./ChatWire -regCommands
./ChatWire

Ensure the generated configuration files contain your Discord token, application ID, guild ID and channel ID, along with Factorio credentials.

Signals

Send SIGUSR1 to queue a reboot once there are no players online. Send SIGUSR2 to reload cw-local-config.json and ../cw-global-config.json.

Automatic reloads

ChatWire monitors the player database and ban list for modifications. Configuration files are reloaded via /chatwire action reload-config or SIGUSR2. To reload configs for all running instances at once, see example-files/reload-config.sh.

About

Factorio to Discord chat bridge and server manager

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •