mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-31 09:06:46 +00:00
[Discord Integration] Native Discord Integration (#2140)
* Start of discord integration work * more testing * Discord client work * More discord work * Cleanup * Handle retry timer response and max retries * Update base retry timer * Move Discord queue handler to UCS, add queuer to own thread * Post merge * Send up Zone::SendDiscordMessage * Start of discord integration work * more testing * Discord client work * More discord work * Cleanup * Move Discord queue handler to UCS, add queuer to own thread * Post merge * Push up tables * Quest API stuff. * Update 2022_05_07_discord_webhooks.sql * Post merge fixes * Push up manifest * Flip logging signs in logic from copy / paste of inverse logic before * Make sure we add new line to quest api sourced messages Co-authored-by: Kinglykrab <kinglykrab@gmail.com>
This commit is contained in:
@@ -0,0 +1,336 @@
|
||||
/**
|
||||
* DO NOT MODIFY THIS FILE
|
||||
*
|
||||
* This repository was automatically generated and is NOT to be modified directly.
|
||||
* Any repository modifications are meant to be made to the repository extending the base.
|
||||
* Any modifications to base repositories are to be made by the generator only
|
||||
*
|
||||
* @generator ./utils/scripts/generators/repository-generator.pl
|
||||
* @docs https://eqemu.gitbook.io/server/in-development/developer-area/repositories
|
||||
*/
|
||||
|
||||
#ifndef EQEMU_BASE_DISCORD_WEBHOOKS_REPOSITORY_H
|
||||
#define EQEMU_BASE_DISCORD_WEBHOOKS_REPOSITORY_H
|
||||
|
||||
#include "../../database.h"
|
||||
#include "../../string_util.h"
|
||||
#include <ctime>
|
||||
|
||||
class BaseDiscordWebhooksRepository {
|
||||
public:
|
||||
struct DiscordWebhooks {
|
||||
int id;
|
||||
std::string webhook_name;
|
||||
std::string webhook_url;
|
||||
time_t created_at;
|
||||
time_t deleted_at;
|
||||
};
|
||||
|
||||
static std::string PrimaryKey()
|
||||
{
|
||||
return std::string("id");
|
||||
}
|
||||
|
||||
static std::vector<std::string> Columns()
|
||||
{
|
||||
return {
|
||||
"id",
|
||||
"webhook_name",
|
||||
"webhook_url",
|
||||
"created_at",
|
||||
"deleted_at",
|
||||
};
|
||||
}
|
||||
|
||||
static std::vector<std::string> SelectColumns()
|
||||
{
|
||||
return {
|
||||
"id",
|
||||
"webhook_name",
|
||||
"webhook_url",
|
||||
"UNIX_TIMESTAMP(created_at)",
|
||||
"UNIX_TIMESTAMP(deleted_at)",
|
||||
};
|
||||
}
|
||||
|
||||
static std::string ColumnsRaw()
|
||||
{
|
||||
return std::string(implode(", ", Columns()));
|
||||
}
|
||||
|
||||
static std::string SelectColumnsRaw()
|
||||
{
|
||||
return std::string(implode(", ", SelectColumns()));
|
||||
}
|
||||
|
||||
static std::string TableName()
|
||||
{
|
||||
return std::string("discord_webhooks");
|
||||
}
|
||||
|
||||
static std::string BaseSelect()
|
||||
{
|
||||
return fmt::format(
|
||||
"SELECT {} FROM {}",
|
||||
SelectColumnsRaw(),
|
||||
TableName()
|
||||
);
|
||||
}
|
||||
|
||||
static std::string BaseInsert()
|
||||
{
|
||||
return fmt::format(
|
||||
"INSERT INTO {} ({}) ",
|
||||
TableName(),
|
||||
ColumnsRaw()
|
||||
);
|
||||
}
|
||||
|
||||
static DiscordWebhooks NewEntity()
|
||||
{
|
||||
DiscordWebhooks entry{};
|
||||
|
||||
entry.id = 0;
|
||||
entry.webhook_name = "";
|
||||
entry.webhook_url = "";
|
||||
entry.created_at = 0;
|
||||
entry.deleted_at = 0;
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
static DiscordWebhooks GetDiscordWebhooksEntry(
|
||||
const std::vector<DiscordWebhooks> &discord_webhookss,
|
||||
int discord_webhooks_id
|
||||
)
|
||||
{
|
||||
for (auto &discord_webhooks : discord_webhookss) {
|
||||
if (discord_webhooks.id == discord_webhooks_id) {
|
||||
return discord_webhooks;
|
||||
}
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static DiscordWebhooks FindOne(
|
||||
Database& db,
|
||||
int discord_webhooks_id
|
||||
)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE id = {} LIMIT 1",
|
||||
BaseSelect(),
|
||||
discord_webhooks_id
|
||||
)
|
||||
);
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
DiscordWebhooks entry{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.webhook_name = row[1] ? row[1] : "";
|
||||
entry.webhook_url = row[2] ? row[2] : "";
|
||||
entry.created_at = strtoll(row[3] ? row[3] : "-1", nullptr, 10);
|
||||
entry.deleted_at = strtoll(row[4] ? row[4] : "-1", nullptr, 10);
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static int DeleteOne(
|
||||
Database& db,
|
||||
int discord_webhooks_id
|
||||
)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"DELETE FROM {} WHERE {} = {}",
|
||||
TableName(),
|
||||
PrimaryKey(),
|
||||
discord_webhooks_id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
DiscordWebhooks discord_webhooks_entry
|
||||
)
|
||||
{
|
||||
std::vector<std::string> update_values;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
update_values.push_back(columns[1] + " = '" + EscapeString(discord_webhooks_entry.webhook_name) + "'");
|
||||
update_values.push_back(columns[2] + " = '" + EscapeString(discord_webhooks_entry.webhook_url) + "'");
|
||||
update_values.push_back(columns[3] + " = FROM_UNIXTIME(" + (discord_webhooks_entry.created_at > 0 ? std::to_string(discord_webhooks_entry.created_at) : "null") + ")");
|
||||
update_values.push_back(columns[4] + " = FROM_UNIXTIME(" + (discord_webhooks_entry.deleted_at > 0 ? std::to_string(discord_webhooks_entry.deleted_at) : "null") + ")");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
implode(", ", update_values),
|
||||
PrimaryKey(),
|
||||
discord_webhooks_entry.id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static DiscordWebhooks InsertOne(
|
||||
Database& db,
|
||||
DiscordWebhooks discord_webhooks_entry
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
|
||||
insert_values.push_back(std::to_string(discord_webhooks_entry.id));
|
||||
insert_values.push_back("'" + EscapeString(discord_webhooks_entry.webhook_name) + "'");
|
||||
insert_values.push_back("'" + EscapeString(discord_webhooks_entry.webhook_url) + "'");
|
||||
insert_values.push_back("FROM_UNIXTIME(" + (discord_webhooks_entry.created_at > 0 ? std::to_string(discord_webhooks_entry.created_at) : "null") + ")");
|
||||
insert_values.push_back("FROM_UNIXTIME(" + (discord_webhooks_entry.deleted_at > 0 ? std::to_string(discord_webhooks_entry.deleted_at) : "null") + ")");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
implode(",", insert_values)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
discord_webhooks_entry.id = results.LastInsertedID();
|
||||
return discord_webhooks_entry;
|
||||
}
|
||||
|
||||
discord_webhooks_entry = NewEntity();
|
||||
|
||||
return discord_webhooks_entry;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
std::vector<DiscordWebhooks> discord_webhooks_entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &discord_webhooks_entry: discord_webhooks_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
|
||||
insert_values.push_back(std::to_string(discord_webhooks_entry.id));
|
||||
insert_values.push_back("'" + EscapeString(discord_webhooks_entry.webhook_name) + "'");
|
||||
insert_values.push_back("'" + EscapeString(discord_webhooks_entry.webhook_url) + "'");
|
||||
insert_values.push_back("FROM_UNIXTIME(" + (discord_webhooks_entry.created_at > 0 ? std::to_string(discord_webhooks_entry.created_at) : "null") + ")");
|
||||
insert_values.push_back("FROM_UNIXTIME(" + (discord_webhooks_entry.deleted_at > 0 ? std::to_string(discord_webhooks_entry.deleted_at) : "null") + ")");
|
||||
|
||||
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
|
||||
}
|
||||
|
||||
std::vector<std::string> insert_values;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES {}",
|
||||
BaseInsert(),
|
||||
implode(",", insert_chunks)
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static std::vector<DiscordWebhooks> All(Database& db)
|
||||
{
|
||||
std::vector<DiscordWebhooks> all_entries;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{}",
|
||||
BaseSelect()
|
||||
)
|
||||
);
|
||||
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
DiscordWebhooks entry{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.webhook_name = row[1] ? row[1] : "";
|
||||
entry.webhook_url = row[2] ? row[2] : "";
|
||||
entry.created_at = strtoll(row[3] ? row[3] : "-1", nullptr, 10);
|
||||
entry.deleted_at = strtoll(row[4] ? row[4] : "-1", nullptr, 10);
|
||||
|
||||
all_entries.push_back(entry);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<DiscordWebhooks> GetWhere(Database& db, std::string where_filter)
|
||||
{
|
||||
std::vector<DiscordWebhooks> all_entries;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE {}",
|
||||
BaseSelect(),
|
||||
where_filter
|
||||
)
|
||||
);
|
||||
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
DiscordWebhooks entry{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.webhook_name = row[1] ? row[1] : "";
|
||||
entry.webhook_url = row[2] ? row[2] : "";
|
||||
entry.created_at = strtoll(row[3] ? row[3] : "-1", nullptr, 10);
|
||||
entry.deleted_at = strtoll(row[4] ? row[4] : "-1", nullptr, 10);
|
||||
|
||||
all_entries.push_back(entry);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static int DeleteWhere(Database& db, std::string where_filter)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"DELETE FROM {} WHERE {}",
|
||||
TableName(),
|
||||
where_filter
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int Truncate(Database& db)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"TRUNCATE TABLE {}",
|
||||
TableName()
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //EQEMU_BASE_DISCORD_WEBHOOKS_REPOSITORY_H
|
||||
@@ -24,6 +24,8 @@ public:
|
||||
int log_to_console;
|
||||
int log_to_file;
|
||||
int log_to_gmsay;
|
||||
int log_to_discord;
|
||||
int discord_webhook_id;
|
||||
};
|
||||
|
||||
static std::string PrimaryKey()
|
||||
@@ -39,6 +41,8 @@ public:
|
||||
"log_to_console",
|
||||
"log_to_file",
|
||||
"log_to_gmsay",
|
||||
"log_to_discord",
|
||||
"discord_webhook_id",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -50,6 +54,8 @@ public:
|
||||
"log_to_console",
|
||||
"log_to_file",
|
||||
"log_to_gmsay",
|
||||
"log_to_discord",
|
||||
"discord_webhook_id",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -95,6 +101,8 @@ public:
|
||||
entry.log_to_console = 0;
|
||||
entry.log_to_file = 0;
|
||||
entry.log_to_gmsay = 0;
|
||||
entry.log_to_discord = 0;
|
||||
entry.discord_webhook_id = 0;
|
||||
|
||||
return entry;
|
||||
}
|
||||
@@ -135,6 +143,8 @@ public:
|
||||
entry.log_to_console = atoi(row[2]);
|
||||
entry.log_to_file = atoi(row[3]);
|
||||
entry.log_to_gmsay = atoi(row[4]);
|
||||
entry.log_to_discord = atoi(row[5]);
|
||||
entry.discord_webhook_id = atoi(row[6]);
|
||||
|
||||
return entry;
|
||||
}
|
||||
@@ -173,6 +183,8 @@ public:
|
||||
update_values.push_back(columns[2] + " = " + std::to_string(logsys_categories_entry.log_to_console));
|
||||
update_values.push_back(columns[3] + " = " + std::to_string(logsys_categories_entry.log_to_file));
|
||||
update_values.push_back(columns[4] + " = " + std::to_string(logsys_categories_entry.log_to_gmsay));
|
||||
update_values.push_back(columns[5] + " = " + std::to_string(logsys_categories_entry.log_to_discord));
|
||||
update_values.push_back(columns[6] + " = " + std::to_string(logsys_categories_entry.discord_webhook_id));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
@@ -199,6 +211,8 @@ public:
|
||||
insert_values.push_back(std::to_string(logsys_categories_entry.log_to_console));
|
||||
insert_values.push_back(std::to_string(logsys_categories_entry.log_to_file));
|
||||
insert_values.push_back(std::to_string(logsys_categories_entry.log_to_gmsay));
|
||||
insert_values.push_back(std::to_string(logsys_categories_entry.log_to_discord));
|
||||
insert_values.push_back(std::to_string(logsys_categories_entry.discord_webhook_id));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
@@ -233,6 +247,8 @@ public:
|
||||
insert_values.push_back(std::to_string(logsys_categories_entry.log_to_console));
|
||||
insert_values.push_back(std::to_string(logsys_categories_entry.log_to_file));
|
||||
insert_values.push_back(std::to_string(logsys_categories_entry.log_to_gmsay));
|
||||
insert_values.push_back(std::to_string(logsys_categories_entry.log_to_discord));
|
||||
insert_values.push_back(std::to_string(logsys_categories_entry.discord_webhook_id));
|
||||
|
||||
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
|
||||
}
|
||||
@@ -271,6 +287,8 @@ public:
|
||||
entry.log_to_console = atoi(row[2]);
|
||||
entry.log_to_file = atoi(row[3]);
|
||||
entry.log_to_gmsay = atoi(row[4]);
|
||||
entry.log_to_discord = atoi(row[5]);
|
||||
entry.discord_webhook_id = atoi(row[6]);
|
||||
|
||||
all_entries.push_back(entry);
|
||||
}
|
||||
@@ -300,6 +318,8 @@ public:
|
||||
entry.log_to_console = atoi(row[2]);
|
||||
entry.log_to_file = atoi(row[3]);
|
||||
entry.log_to_gmsay = atoi(row[4]);
|
||||
entry.log_to_discord = atoi(row[5]);
|
||||
entry.discord_webhook_id = atoi(row[6]);
|
||||
|
||||
all_entries.push_back(entry);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* EQEmulator: Everquest Server Emulator
|
||||
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; version 2 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY except by those people which sell it, which
|
||||
* are required to give you total support for your newly bought product;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef EQEMU_DISCORD_WEBHOOKS_REPOSITORY_H
|
||||
#define EQEMU_DISCORD_WEBHOOKS_REPOSITORY_H
|
||||
|
||||
#include "../database.h"
|
||||
#include "../string_util.h"
|
||||
#include "base/base_discord_webhooks_repository.h"
|
||||
|
||||
class DiscordWebhooksRepository: public BaseDiscordWebhooksRepository {
|
||||
public:
|
||||
|
||||
/**
|
||||
* This file was auto generated and can be modified and extended upon
|
||||
*
|
||||
* Base repository methods are automatically
|
||||
* generated in the "base" version of this repository. The base repository
|
||||
* is immutable and to be left untouched, while methods in this class
|
||||
* are used as extension methods for more specific persistence-layer
|
||||
* accessors or mutators.
|
||||
*
|
||||
* Base Methods (Subject to be expanded upon in time)
|
||||
*
|
||||
* Note: Not all tables are designed appropriately to fit functionality with all base methods
|
||||
*
|
||||
* InsertOne
|
||||
* UpdateOne
|
||||
* DeleteOne
|
||||
* FindOne
|
||||
* GetWhere(std::string where_filter)
|
||||
* DeleteWhere(std::string where_filter)
|
||||
* InsertMany
|
||||
* All
|
||||
*
|
||||
* Example custom methods in a repository
|
||||
*
|
||||
* DiscordWebhooksRepository::GetByZoneAndVersion(int zone_id, int zone_version)
|
||||
* DiscordWebhooksRepository::GetWhereNeverExpires()
|
||||
* DiscordWebhooksRepository::GetWhereXAndY()
|
||||
* DiscordWebhooksRepository::DeleteWhereXAndY()
|
||||
*
|
||||
* Most of the above could be covered by base methods, but if you as a developer
|
||||
* find yourself re-using logic for other parts of the code, its best to just make a
|
||||
* method that can be re-used easily elsewhere especially if it can use a base repository
|
||||
* method and encapsulate filters there
|
||||
*/
|
||||
|
||||
// Custom extended repository methods here
|
||||
|
||||
};
|
||||
|
||||
#endif //EQEMU_DISCORD_WEBHOOKS_REPOSITORY_H
|
||||
Reference in New Issue
Block a user