From fb1caf6cee9e82e928be760c4affd05981514e17 Mon Sep 17 00:00:00 2001
From: Salanto <support@salanto.de>
Date: Wed, 12 May 2021 00:12:46 +0200
Subject: [PATCH] Add optional content field for Webhook

Allows the usage of pings with the webhook. Only added to the hook message if configured.
---
 include/server.h | 6 ++++++
 src/discord.cpp  | 2 ++
 src/server.cpp   | 1 +
 3 files changed, 9 insertions(+)

diff --git a/include/server.h b/include/server.h
index c76417b..35c8c00 100644
--- a/include/server.h
+++ b/include/server.h
@@ -317,11 +317,17 @@ class Server : public QObject {
      * @brief The minimum time between IC messages, in milliseconds.
      */
     int message_floodguard;
+
     /**
      * @brief URL send to the client during handshake to set the remote repository URL.
      */
     QUrl asset_url;
 
+    /**
+     * @brief Opional text to be send with the Discord embeed. Can be used to configure pings.
+     */
+    QString webhook_content;
+
   public slots:
     /**
      * @brief Handles a new connection.
diff --git a/src/discord.cpp b/src/discord.cpp
index e18f784..437cb6a 100644
--- a/src/discord.cpp
+++ b/src/discord.cpp
@@ -42,6 +42,8 @@ void Discord::postModcallWebhook(QString name, QString reason, int current_area)
     };
     jsonArray.append(jsonObject);
     json["embeds"] = jsonArray;
+    if (server->webhook_content != NULL)
+      json["content"] = server->webhook_content;
 
     nam->post(request, QJsonDocument(json).toJson());
 
diff --git a/src/server.cpp b/src/server.cpp
index 2afdbe6..02e7922 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -311,6 +311,7 @@ void Server::loadServerConfig()
     webhook_enabled = config.value("webhook_enabled", "false").toBool();
     webhook_url = config.value("webhook_url", "Your webhook url here.").toString();
     webhook_sendfile = config.value("webhook_sendfile", false).toBool();
+    webhook_content = config.value("webhook_content", NULL).toString();
     config.endGroup();
 }