diff --git a/bin/config_sample/config.ini b/bin/config_sample/config.ini index 882106d..f89cfd9 100644 --- a/bin/config_sample/config.ini +++ b/bin/config_sample/config.ini @@ -82,36 +82,6 @@ max_value=100 ; The maximum number of dice that can be rolled at once. max_dice=100 -[Discord] -; Whether the discord webhook is enabled or not. -; The server will send messages to this webhook whenever a modcall is sent. -; Changing this requires a server restart. -webhook_enabled=false - -; The URL of the discord webhook to send messages to. Must contain the webhook ID and token. -webhook_modcall_url= - -; Whether to attach a file containing the area log when a modcall message is sent to the webhook. -webhook_modcall_sendfile=false - -; Additional text to send with the webhook message. Usually for adding tags for role. Ensure the format is <@&[RoleID]>. -webhook_content= - -; Enables the ban webhook. -webhook_ban_enabled = false - -; The URL of the ban discord webhook to send messages to. Must contain the webhook ID and token. -webhook_ban_url= - -; Enables Uptime Webhook. -webhook_uptime_enabled = false - -; The time between message posting. This time is in minutes, with a default of 60. -webhook_uptime_time = 60 - -; The URL of the uptime discord webhook to send messages to. Must contain the webhook ID and token. -webhook_uptime_url= - [Password] ; Whether or not to enforce password requirements. Only applicable under advanced authorization. password_requirements = true diff --git a/bin/config_sample/discord.ini b/bin/config_sample/discord.ini new file mode 100644 index 0000000..dcefa23 --- /dev/null +++ b/bin/config_sample/discord.ini @@ -0,0 +1,32 @@ +[Discord] +; Whether the discord webhook is enabled or not. +; The server will send messages to this webhook whenever a modcall is sent. +; Changing this requires a server restart. +webhook_enabled=false + +;Enables the modcall webhook to post a notification when a modcall is made. +webhook_modcall_enabled=false + +; The URL of the discord webhook to send messages to. Must contain the webhook ID and token. +webhook_modcall_url= + +; Additional text to send with the webhook message. Usually for adding tags for role. Ensure the format is <@&[RoleID]>. +webhook_modcall_content= + +; Whether to attach a file containing the area log when a modcall message is sent to the webhook. +webhook_modcall_sendfile=false + +; Enables the ban webhook. +webhook_ban_enabled = false + +; The URL of the ban discord webhook to send messages to. Must contain the webhook ID and token. +webhook_ban_url= + +; Enables Uptime Webhook. +webhook_uptime_enabled = false + +; The time between message posting. This time is in minutes, with a default of 60. +webhook_uptime_time = 60 + +; The URL of the uptime discord webhook to send messages to. Must contain the webhook ID and token. +webhook_uptime_url= diff --git a/core/include/config_manager.h b/core/include/config_manager.h index 4103ff8..60e9a41 100644 --- a/core/include/config_manager.h +++ b/core/include/config_manager.h @@ -191,12 +191,19 @@ class ConfigManager { static int diceMaxDice(); /** - * @brief Returns true if the discord webhook is enabled. + * @brief Returns true if the discord webhook integration is enabled. * * @return See short description. */ static bool discordWebhookEnabled(); + /** + * @brief Returns true if the discord modcall webhook is enabled. + * + * @return See short description. + */ + static bool discordModcallWebhookEnabled(); + /** * @brief Returns the discord webhook URL. * @@ -406,6 +413,11 @@ private: */ static QSettings* m_settings; + /** + * @brief Stores all discord webhook configuration values. + */ + static QSettings* m_discord; + /** * @brief Returns a stringlist with the contents of a .txt file from config/text/. * diff --git a/core/src/config_manager.cpp b/core/src/config_manager.cpp index 36b4e2e..af4718f 100644 --- a/core/src/config_manager.cpp +++ b/core/src/config_manager.cpp @@ -18,6 +18,7 @@ #include "include/config_manager.h" QSettings* ConfigManager::m_settings = new QSettings("config/config.ini", QSettings::IniFormat); +QSettings* ConfigManager::m_discord = new QSettings("config/discord.ini", QSettings::IniFormat); ConfigManager::CommandSettings* ConfigManager::m_commands = new CommandSettings(); bool ConfigManager::verifyServerConfig() @@ -90,6 +91,7 @@ bool ConfigManager::verifyServerConfig() void ConfigManager::reloadSettings() { m_settings->sync(); + m_discord->sync(); } QStringList ConfigManager::loadConfigFile(const QString filename) @@ -267,43 +269,48 @@ int ConfigManager::diceMaxDice() bool ConfigManager::discordWebhookEnabled() { - return m_settings->value("Discord/webhook_enabled", false).toBool(); + return m_discord->value("Discord/webhook_enabled", false).toBool(); +} + +bool ConfigManager::discordModcallWebhookEnabled() +{ + return m_discord->value("Discord/webhook_modcall_enabled", false).toBool(); } QString ConfigManager::discordModcallWebhookUrl() { - return m_settings->value("Discord/webhook_modcall_url", "").toString(); + return m_discord->value("Discord/webhook_modcall_url", "").toString(); } QString ConfigManager::discordWebhookContent() { - return m_settings->value("Discord/webhook_content", "").toString(); + return m_discord->value("Discord/webhook_content", "").toString(); } bool ConfigManager::discordModcallWebhookSendFile() { - return m_settings->value("Discord/webhook_modcall_sendfile", false).toBool(); + return m_discord->value("Discord/webhook_modcall_sendfile", false).toBool(); } bool ConfigManager::discordBanWebhookEnabled() { - return m_settings->value("Discord/webhook_ban_enabled", false).toBool(); + return m_discord->value("Discord/webhook_ban_enabled", false).toBool(); } QString ConfigManager::discordBanWebhookUrl() { - return m_settings->value("Discord/webhook_ban_url", "").toString(); + return m_discord->value("Discord/webhook_ban_url", "").toString(); } bool ConfigManager::discordUptimeEnabled() { - return m_settings->value("Discord/webhook_uptime_enabled","false").toBool(); + return m_discord->value("Discord/webhook_uptime_enabled","false").toBool(); } int ConfigManager::discordUptimeTime() { bool ok; - int l_aliveTime = m_settings->value("Discord/webhook_uptime_time","60").toInt(&ok); + int l_aliveTime = m_discord->value("Discord/webhook_uptime_time","60").toInt(&ok); if (!ok) { qWarning("alive_time is not an int"); l_aliveTime = 60; @@ -313,7 +320,7 @@ int ConfigManager::discordUptimeTime() QString ConfigManager::discordUptimeWebhookUrl() { - return m_settings->value("Discord/webhook_uptime_url", "").toString(); + return m_discord->value("Discord/webhook_uptime_url", "").toString(); } bool ConfigManager::passwordRequirements()