From 058b5cef63508b5fb8fcebc9692f97fe43862b9b Mon Sep 17 00:00:00 2001
From: Salanto <62221668+Salanto@users.noreply.github.com>
Date: Tue, 10 Aug 2021 20:45:53 +0200
Subject: [PATCH] Update ban webhook to utilize different url

+ Update sample config
+ Clarify webhook urls in the config and configmanager.
---
 bin/config_sample/config.ini  |  7 +++++--
 core/include/config_manager.h | 11 +++++++++--
 core/src/config_manager.cpp   | 13 +++++++++----
 core/src/discord.cpp          |  7 +++----
 4 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/bin/config_sample/config.ini b/bin/config_sample/config.ini
index 863379d..1ca4e07 100644
--- a/bin/config_sample/config.ini
+++ b/bin/config_sample/config.ini
@@ -86,10 +86,10 @@ max_dice=100
 webhook_enabled=false
 
 ; The URL of the discord webhook to send messages to. Must contain the webhook ID and token.
-webhook_url=
+webhook_modcall_url=
 
 ; Whether to attach a file containing the area log when a modcall message is sent to the webhook.
-webhook_sendfile=false
+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=
@@ -97,6 +97,9 @@ 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=
+
 [Password]
 ; Whether or not to enforce password requirements. Only applicable under advanced authorization.
 password_requirements = true
diff --git a/core/include/config_manager.h b/core/include/config_manager.h
index 3364c0d..8296ed5 100644
--- a/core/include/config_manager.h
+++ b/core/include/config_manager.h
@@ -202,7 +202,7 @@ class ConfigManager {
      *
      * @return See short description.
      */
-    static QString discordWebhookUrl();
+    static QString discordModcallWebhookUrl();
 
     /**
      * @brief Returns the discord webhook content.
@@ -216,7 +216,7 @@ class ConfigManager {
      *
      * @return See short description.
      */
-    static bool discordWebhookSendFile();
+    static bool discordModcallWebhookSendFile();
 
     /**
      * @brief Returns true if the discord ban webhook is enabled.
@@ -225,6 +225,13 @@ class ConfigManager {
      */
     static bool discordBanWebhookEnabled();
 
+    /**
+     * @brief Returns the Discord Ban Webhook URL.
+     *
+     * @return See short description.
+     */
+    static QString discordBanWebhookUrl();
+
     /**
      * @brief Returns true if password requirements should be enforced.
      *
diff --git a/core/src/config_manager.cpp b/core/src/config_manager.cpp
index f54e805..563a296 100644
--- a/core/src/config_manager.cpp
+++ b/core/src/config_manager.cpp
@@ -270,9 +270,9 @@ bool ConfigManager::discordWebhookEnabled()
     return m_settings->value("Discord/webhook_enabled", false).toBool();
 }
 
-QString ConfigManager::discordWebhookUrl()
+QString ConfigManager::discordModcallWebhookUrl()
 {
-    return m_settings->value("Discord/webhook_url", "").toString();
+    return m_settings->value("Discord/webhook_modcall_url", "").toString();
 }
 
 QString ConfigManager::discordWebhookContent()
@@ -280,9 +280,9 @@ QString ConfigManager::discordWebhookContent()
     return m_settings->value("Discord/webhook_content", "").toString();
 }
 
-bool ConfigManager::discordWebhookSendFile()
+bool ConfigManager::discordModcallWebhookSendFile()
 {
-    return m_settings->value("Discord/webhook_sendfile", false).toBool();
+    return m_settings->value("Discord/webhook_modcall_sendfile", false).toBool();
 }
 
 bool ConfigManager::discordBanWebhookEnabled()
@@ -290,6 +290,11 @@ bool ConfigManager::discordBanWebhookEnabled()
     return m_settings->value("Discord/webhook_ban_enabled", false).toBool();
 }
 
+QString ConfigManager::discordBanWebhookUrl()
+{
+    return m_settings->value("Discord/webhook_ban_url", "").toString();
+}
+
 bool ConfigManager::passwordRequirements()
 {
     return m_settings->value("Password/password_requirements", true).toBool();
diff --git a/core/src/discord.cpp b/core/src/discord.cpp
index 0b4693c..098179a 100644
--- a/core/src/discord.cpp
+++ b/core/src/discord.cpp
@@ -20,20 +20,18 @@
 Discord::Discord(QObject* parent) :
     QObject(parent)
 {
-    if (!QUrl(ConfigManager::discordWebhookUrl()).isValid())
-        qWarning("Invalid webhook URL!");
     m_nam = new QNetworkAccessManager();
     connect(m_nam, &QNetworkAccessManager::finished,
             this, &Discord::onReplyFinished);
-    m_request.setUrl(QUrl(ConfigManager::discordWebhookUrl()));
 }
 
 void Discord::onModcallWebhookRequested(const QString &f_name, const QString &f_area, const QString &f_reason, const QQueue<QString> &f_buffer)
 {
+    m_request.setUrl(QUrl(ConfigManager::discordModcallWebhookUrl()));
     QJsonDocument l_json = constructModcallJson(f_name, f_area, f_reason);
     postJsonWebhook(l_json);
 
-    if (ConfigManager::discordWebhookSendFile()) {
+    if (ConfigManager::discordModcallWebhookSendFile()) {
         QHttpMultiPart *l_multipart = constructLogMultipart(f_buffer);
         postMultipartWebhook(*l_multipart);
     }
@@ -41,6 +39,7 @@ void Discord::onModcallWebhookRequested(const QString &f_name, const QString &f_
 
 void Discord::onBanWebhookRequested(const QString &f_ipid, const QString &f_moderator, const QString &f_duration, const QString &f_reason, const int &f_banID)
 {
+    m_request.setUrl(QUrl(ConfigManager::discordBanWebhookUrl()));
     QJsonDocument l_json = constructBanJson(f_ipid,f_moderator, f_duration, f_reason, f_banID);
     postJsonWebhook(l_json);
 }