A Discord chatbot for Factorio written in Golang
This bot will work without mods. It supports chat messages and player join/quit. If you want to be able to see more information on Discord you can use the companion mod OR if you don't want to use mods you can manually edit your save game!
You can run this bot in Windows, Unix or Docker!
You will need to create your own 'bot' (application).
- Go to: https://discord.com/developers/applications
- Click 'New Application'
- Give the bot a name
- Go to the 'Bot' tab
- Click 'Add Bot'
- Enabled 'Message Content Intent'
- Generate token
- Go to the 'General Information' tab and get your application ID
- Go to: https://discord.com/oauth2/authorize?client_id={appid}&permissions=377957370944&scope=bot (Replace
{appid}
with your application ID) - Then login and add the bot to your server
This bot uses a channel ID. In order to see this you need to set your Discord client to 'Developer Mode' ( settings/apperance). With this setting enabled you can right-click on a channe and copy the ID.
You will need to launch your (headless) factorio with the following flags:
--rcon-port xx
--rcon-password xx
--console-log /path/to/chatlog (this can also be simply console.log for a file in your servers main directory)
RCON is required in order to send messages TO the Factorio server.
If you run your server with a management tool please refer to that documentation. For
example factorio-server-manager has a chat-log
option (= --console-log
)
This bot uses environment variable to configure. Or an .env
file in the same directory as the executable.
Here is a list of all variables available:
LOG_LEVEL=info (optional) # This is the log level, when submitting a bug please set this to debug
DISCORD_TOKEN=xx # The Discord Authentication token for your bot
DISCORD_CHANNEL_ID=xx # The Discord channel ID
RCON_IP=xx # The IP of your Factorio server, a hostname is also allowed
RCON_PORT=xx # The rcon port
RCON_PASSWORD=xx # The rcon password
FACTORIO_LOG=C:\Users\xx\AppData\Roaming\Factorio\console.log (Unix path also supported) # Path to the chat log (--console-log)
MOD_LOG=C:\Users\xx\AppData\Roaming\Factorio\script-output\factorigo-chat-bot\factorigo-chat-bot.log (Optional) # If you use the companion mod supply the path to that log file here
POLL_LOG=false # If this is set, logs will be polled instead of using inotify. This may be required with docker depending on your storage setup
ALL_ROCKET_LAUNCHES=false # By default it will say only some rocket launches (1, 10, 100 etc). If you want to see all set this to true
ACHIEVEMENT_MODE=true # Set `false` for nicer text-layout (and possible some special commands in the future), we need to execute commands `/silent-command game.print(...)`. THIS WILL DISABLE ACHIEVEMENTS.
SEND_GPS_PING=false # If this is set, the bot will send all GPS/Location pings to Discord
SEND_JOIN_LEAVE=true # Set to false if you don't want join/leave events to be send to Discord
When using docker: don't forget to also mount/bind the log-files to your container.
(See config options above)
Nicer layout: not compabitle with achivements
Default layout (and commands disabled): compatible with achievements
Simply download the Unix or Windows binary from this repo and run the executeable. You will need to pass some
configuration. You can either create a file called .env
(keep it in the same directory as the executable) or create a
script that first sets these variables. For example in Windows a .bat
file cound be created with the following:
set LOG_LEVEL=info
set DISCORD_TOKEN=xx
(etc)
factorigo-chat-bot.exe
Get the image from https://hub.docker.com/r/mattie112/factorigo-chat-bot and run it with the variables as listed above.
Example command:
docker run -d --name='factorigo-chat-bot' -e 'LOG_LEVEL'='info' -e 'DISCORD_TOKEN'='xx.xx.xx-xx-xx' -e 'DISCORD_CHANNEL_ID'='xx' -e 'RCON_IP'='192.168.100.xx' -e 'RCON_PORT'='34198' -e 'RCON_PASSWORD'='xx' -e 'FACTORIO_LOG'='/opt/project/factorio.log' -e 'MOD_LOG'='/opt/project/factorigo-chat-bot.log' -v '/mnt/user/appdata/fsm_factorio/console.log':'/opt/project/factorio.log':'rw' -v '/mnt/user/appdata/fsm_factorio/script-output/factorigo-chat-bot/factorigo-chat-bot.log':'/opt/project/factorigo-chat-bot.log':'rw' 'mattie112/factorigo-chat-bot:latest'
Do you use Unraid? Let me know then I can see if I can provide a template!
Unix:
GOOS=linux GARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.VERSION=$(git rev-parse --short HEAD) -X main.BUILDTIME=`date -u +%Y%m%d.%H%M%S`" -o ./bin/factorigo-chat-bot
Windows:
GOOS=windows GARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.VERSION=$(git rev-parse --short HEAD) -X main.BUILDTIME=$(date -u +%Y%m%d.%H%M%S)" -o ./bin/factorigo-chat-bot.exe
If you don't have a build environment:
Run: docker-compose run --rm builder
then copy/paste the commands listed above
In order to build a docker image, first run the commands above and then:
docker build -t mattie112/factorigo-chat-bot:latest .
docker push mattie112/factorigo-chat-bot:latest
(With companion mod)
- Research started / finished
- Player deaths
- Rocket launched
If you don't want to use my companion mod you can also manually edit your save file to get the extra data!
- Extract your factorio save/zip file
- Add the contents of control.lua to
the
control.lua
in your save - Re-zip your save file