Announce the death of a player in a Discord channel. Bonus: Track the amount of rockets launched.
This project is made with Node.js. You can download and install it from the offical website.
After installation, both node
and npm
binaries should be accessible from path.
Note: Currently this bot must be hosted on the same server as the Factorio server.
Factorio doesn't log the deaths of players. To do so I wrote a small mod based on this Reddit comment.
In order to install the mod you must first create a savefile. Then unzip the savefile and opencontrol.lua
.
It should contain the following:
local handler = require("event_handler")
handler.add_lib(require("freeplay"))
handler.add_lib(require("silo-script"))
Replace the contents with this:
local handler = require("event_handler")
handler.add_lib(require("freeplay"))
handler.add_lib(require("silo-script"))
local function log_message(msg)
print ("FDDLOGGER: " .. msg)
end
local function log_player_message(event, msg_in)
local msg = "Player " .. game.players[event.player_index].name .. " " .. msg_in
log_message (msg)
end
script.on_event(defines.events.on_player_died, function(event) log_player_message(event, "died") end)
script.on_event(defines.events.on_rocket_launched, function(event) log_message("A rocket was launched") end)
This adds the player deaths and rocket launches to the printed output of the server. But unfortunately it doesn't log to the default factorio-current.log
.
In order to be readable by the bot we need to create or own logfile. With Blackjack. And hookers.
In order to do that you need to output your server output to a file with 2>&1 | tee log-all
. If this is your startup command:
/opt/factorio/main/bin/x64/factorio --start-server-load-latest --server-settings /opt/factorio/main/data/server-settings.json
Then it becomes this.
/opt/factorio/main/bin/x64/factorio --start-server-load-latest --server-settings /opt/factorio/main/data/server-settings.json 2>&1 | tee log-all
Clone the project and cd
into newly cloned directory. Then run npm install
from your command line. This will install the necessary libraries.
Copy config.example.json
to config.json
and populate the entries:
logfile
: path to logfile above, like/opt/factorio/main/log-all
discordToken
: Put your token here, you can follow the instructions to get it here.textChannel
: The ID of your Discord text channel. You need Discord developer mode enabled to find it.
Run the command npm start
in the directory of the cloned project and all should be good! You can then add the bot to your server:
- Go to the Discord developer portal
- Select your application
- Select OAuth2
- Select the
bot
permission - Copy and paste the link to add the bot to your server.
The bot will automatically announce a death of the player like so:
You can enter the command !stats
to get an overview of all deaths and rockets launched.
That's quite likely, this project is the result of a few hours of coding because I wanted to do something fun for the 1.0 release of Factorio. You can submit your bugs to the GitHub issue tracker and I'll take a look!
Enjoy!