[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:
Chris Miles
2022-06-09 17:22:23 -05:00
committed by GitHub
parent 8ef3e87370
commit 4639405fdf
32 changed files with 1052 additions and 259 deletions
@@ -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);
}