Cleanup Discord class and fix reload error

This commit is contained in:
Salanto 2021-08-12 22:55:27 +02:00
parent 931365d1bd
commit f4038d4678
4 changed files with 6 additions and 21 deletions

View File

@ -141,17 +141,6 @@ private:
*/ */
QTimer* m_uptimePostTimer; QTimer* m_uptimePostTimer;
/**
* @brief Stores how long the interval between postings is.
**/
int m_uptimeInterval;
/**
* @brief Proof that Salanto does not know what he is doing.
* @details Counts how often the server alive counter has been posted.
*/
int m_uptimeCounter;
private slots: private slots:
/** /**
* @brief Handles a network reply from a webhook POST request. * @brief Handles a network reply from a webhook POST request.

View File

@ -293,7 +293,7 @@ class Server : public QObject {
/** /**
* @brief Handles Discord webhooks. * @brief Handles Discord webhooks.
*/ */
Discord* discord; Discord* discord = nullptr;
/** /**
* @brief Handles HTTP server advertising. * @brief Handles HTTP server advertising.

View File

@ -26,12 +26,9 @@ Discord::Discord(QObject* parent) :
if (ConfigManager::discordUptimeEnabled()){ if (ConfigManager::discordUptimeEnabled()){
m_uptimePostTimer = new QTimer; m_uptimePostTimer = new QTimer;
m_uptimeInterval = ConfigManager::discordUptimeTime() * 60000;
m_uptimeCounter = 0;
connect(m_uptimePostTimer, &QTimer::timeout, connect(m_uptimePostTimer, &QTimer::timeout,
this, &Discord::onUptimeWebhookRequested); this, &Discord::onUptimeWebhookRequested);
m_uptimePostTimer->start(m_uptimeInterval); m_uptimePostTimer->start(ConfigManager::discordUptimeTime() * 60000);
onUptimeWebhookRequested(); onUptimeWebhookRequested();
} }
} }
@ -57,7 +54,7 @@ void Discord::onBanWebhookRequested(const QString &f_ipid, const QString &f_mode
void Discord::onUptimeWebhookRequested() void Discord::onUptimeWebhookRequested()
{ {
ulong l_expiredTimeSeconds = (m_uptimeCounter * m_uptimeInterval) / 1000; qint64 l_expiredTimeSeconds = ConfigManager::uptime() / 1000;
int minutes = (l_expiredTimeSeconds / 60) % 60; int minutes = (l_expiredTimeSeconds / 60) % 60;
int hours = (l_expiredTimeSeconds / (60 * 60)) % 24; int hours = (l_expiredTimeSeconds / (60 * 60)) % 24;
int days = (l_expiredTimeSeconds / (60 * 60 * 24)) % 365; int days = (l_expiredTimeSeconds / (60 * 60 * 24)) % 365;
@ -66,7 +63,6 @@ void Discord::onUptimeWebhookRequested()
QString f_timeExpired = QString::number(days) + " days, " + QString::number(hours) + " hours and " + QString::number(minutes) + " minutes."; QString f_timeExpired = QString::number(days) + " days, " + QString::number(hours) + " hours and " + QString::number(minutes) + " minutes.";
QJsonDocument l_json = constructUptimeJson(f_timeExpired); QJsonDocument l_json = constructUptimeJson(f_timeExpired);
postJsonWebhook(l_json); postJsonWebhook(l_json);
m_uptimeCounter++;
} }
QJsonDocument Discord::constructModcallJson(const QString &f_name, const QString &f_area, const QString &f_reason) const QJsonDocument Discord::constructModcallJson(const QString &f_name, const QString &f_area, const QString &f_reason) const
@ -107,8 +103,8 @@ QJsonDocument Discord::constructUptimeJson(const QString& f_timeExpired)
QJsonArray l_array; QJsonArray l_array;
QJsonObject l_object { QJsonObject l_object {
{"color", "13312842"}, {"color", "13312842"},
{"title", "Your server is still running!"}, {"title", "Your server is online!"},
{"description", "Hello World!\nYour server has been online for " + f_timeExpired} {"description", "Your server has been online for " + f_timeExpired}
}; };
l_array.append(l_object); l_array.append(l_object);
l_json["embeds"] = l_array; l_json["embeds"] = l_array;

View File

@ -287,7 +287,7 @@ void Server::handleDiscordIntegration()
{ {
if (discord != nullptr) { if (discord != nullptr) {
discord->deleteLater(); discord->deleteLater();
return; discord = nullptr;
} }
if (ConfigManager::discordWebhookEnabled()) { if (ConfigManager::discordWebhookEnabled()) {