Skip to content

Commit

Permalink
feat, docs: slight improvements to messages. README changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 committed Dec 18, 2023
1 parent 06c8db2 commit 2c613e3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ This section will tell you what each part of the config means.
- `bot_token` is the Discord bot's token that you want to use for this.
- `msg_channel` is the ID of the channel that will be used for sending and receiving messages.
- `allow_achievements` is either `true` or `false`. If true (default), messages will be prefixed with `<server>:`. If false, messages will look tidier.
- `console_log_path` should be pointing to a `factorio-current.log`. You can look at [this guide](https://wiki.factorio.com/Application_directory#User_data_directory) by the Factorio wiki to see where it's located.
- `console_log_path` should be pointing to a log file created by adding `--console-log=<path>` to your server's arguments. Whatever path you give to that, set `console_log_path` to that.
- `admin_role` is the ID of a role that is allowed to execute the `/command <any_factorio_command>` command in Discord.
36 changes: 25 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ int main() {
}

if (event.msg.channel_id == FDR::config.msg_channel) {
// ID here doesn't matter really, we're not wanting a response.
rcon_client.send_data(event.msg.content, 999, data_type::SERVERDATA_EXECCOMMAND);
if(FDR::config.allow_achievements) {
// ID here doesn't matter really, we're not wanting a response.
rcon_client.send_data(event.msg.content, 999, data_type::SERVERDATA_EXECCOMMAND);
} else {
rcon_client.send_data("/silent-command game.print(\"[Discord] " + event.msg.author.username + " » " + event.msg.content + "\")", 999, data_type::SERVERDATA_EXECCOMMAND);
}
}
});

Expand Down Expand Up @@ -199,7 +203,12 @@ int main() {
}

bot.message_create(dpp::message(FDR::config.msg_channel, "Factorio-Discord-Relay (FDR) has loaded!"), [&rcon_client](const dpp::confirmation_callback_t& callback) {
rcon_client.send_data("Factorio-Discord-Relay (FDR) has loaded!", 999, data_type::SERVERDATA_EXECCOMMAND);
if(FDR::config.allow_achievements) {
rcon_client.send_data("Factorio-Discord-Relay (FDR) has loaded!", 999,
data_type::SERVERDATA_EXECCOMMAND);
} else {
rcon_client.send_data("/silent-command game.print(\"Factorio-Discord-Relay (FDR) has loaded!\")", 999, data_type::SERVERDATA_EXECCOMMAND);
}
});
});

Expand All @@ -221,28 +230,33 @@ void FDR::read_console() {
}
console_file.clear();

last_char_read = console_file.tellg();

console_file.close();
if (last_char_read == 0) {
last_char_read = console_file.tellg();
console_file.close();
return;
}

for (const std::string& log : strings) {
std::cout << "log line: " << log << "\n";
if (log.find("[JOIN]") != std::string::npos) {
std::string msg = dpp::unicode_emoji::green_circle + pretify_log_line(log);
std::string msg = std::string(dpp::unicode_emoji::green_circle) + " " + pretify_log_line(log);

FDR::botRef->message_create(dpp::message(FDR::config.msg_channel, msg));
} else if (log.find("[LEAVE]") != std::string::npos) {
std::string msg = dpp::unicode_emoji::red_circle + pretify_log_line(log);
std::string msg = std::string(dpp::unicode_emoji::red_circle) + " " + pretify_log_line(log);

FDR::botRef->message_create(dpp::message(FDR::config.msg_channel, msg));
} else if (log.find("[CHAT]") != std::string::npos) {
std::string msg = dpp::unicode_emoji::speech_balloon + pretify_log_line(log);
std::string msg = std::string(dpp::unicode_emoji::speech_balloon) + " " + pretify_log_line(log);

FDR::botRef->message_create(dpp::message(FDR::config.msg_channel, msg));
} else if (log.find("[COMMAND]") != std::string::npos) {
std::string msg = dpp::unicode_emoji::keyboard + pretify_log_line(log);
std::string msg = std::string(dpp::unicode_emoji::keyboard) + " " + pretify_log_line(log);

FDR::botRef->message_create(dpp::message(FDR::config.msg_channel, msg));
}
}

last_char_read = console_file.tellg();

console_file.close();
}

0 comments on commit 2c613e3

Please sign in to comment.