mirror of
https://gitlab.com/niansa/discordlistforbots.git
synced 2025-03-06 20:49:22 +01:00
Added webhook log
This commit is contained in:
parent
b49760fecc
commit
b55683c4e5
1 changed files with 27 additions and 4 deletions
|
@ -19,6 +19,20 @@
|
|||
|
||||
|
||||
|
||||
void webhookSend(const std::string& message) {
|
||||
auto discordapi = HttpClient::newHttpClient("https://discord.com");
|
||||
// Build request
|
||||
auto req = HttpRequest::newHttpRequest();
|
||||
req->setPath("/api/webhooks/" LOG_WEBHOOK);
|
||||
req->setContentTypeCode(ContentType::CT_APPLICATION_X_FORM);
|
||||
req->setMethod(HttpMethod::Post);
|
||||
{
|
||||
req->setParameter("content", message);
|
||||
}
|
||||
// Send request
|
||||
discordapi->sendRequest(req);
|
||||
}
|
||||
|
||||
Bot deserializeBot(orm::Row row) {
|
||||
Bot thisbot;
|
||||
# define sf(f) thisbot.f = row[#f]
|
||||
|
@ -294,6 +308,8 @@ void views::botedit(const HttpRequestPtr& req, std::function<void (const HttpRes
|
|||
} else {
|
||||
final();
|
||||
}
|
||||
// Send webhook log message
|
||||
webhookSend("Bot `"+std::to_string(bot.app_id)+"` updated");
|
||||
}, dbErr);
|
||||
} break;
|
||||
default: break;
|
||||
|
@ -303,12 +319,15 @@ void views::botedit(const HttpRequestPtr& req, std::function<void (const HttpRes
|
|||
case Get: {
|
||||
auto data = HttpViewDataPrep(sessionData);
|
||||
data.insert("botname", HttpViewData::htmlTranslate(bot.name));
|
||||
|
||||
callback(HttpResponse::newHttpViewResponse("botdelete.csp", data));
|
||||
|
||||
} break;
|
||||
case Post: {
|
||||
db->execSqlAsync("DELETE FROM bots WHERE app_id = '"+std::to_string(bot.app_id)+"'",
|
||||
[callback] (const orm::Result &) {
|
||||
[app_id = bot.app_id, callback] (const orm::Result &) {
|
||||
// Send webhook log message
|
||||
webhookSend("Bot `"+std::to_string(app_id)+"` deleted");
|
||||
// Return to start page
|
||||
toStartPage(callback);
|
||||
}, dbErr);
|
||||
} break;
|
||||
|
@ -319,8 +338,10 @@ void views::botedit(const HttpRequestPtr& req, std::function<void (const HttpRes
|
|||
} else if (action == "approve") {
|
||||
db->execSqlAsync("UPDATE bots SET approved = 't' "
|
||||
"WHERE app_id = '"+std::to_string(bot.app_id)+"'",
|
||||
[final] (const orm::Result &) {
|
||||
[app_id = bot.app_id, final] (const orm::Result &) {
|
||||
final();
|
||||
// Send webhook log message
|
||||
webhookSend("Bot `"+std::to_string(app_id)+"` approved");
|
||||
}, dbErr);
|
||||
} else {
|
||||
else_part:
|
||||
|
@ -378,8 +399,10 @@ void views::botregister_submit(const HttpRequestPtr& req, std::function<void (co
|
|||
db->execSqlAsync(fmt::format("INSERT INTO bots (name, short_description, long_description, avatar_url, owner, support_server, prefix, owner_id, app_id, votes, approved) "
|
||||
"VALUES('{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', 0, 'f')",
|
||||
dbEsc(botuser["username"].asString()), dbEsc(short_description), dbEsc(long_description), dbEsc(botuser["avatar_url"].asString()), sessionData->discord_fullname(), dbEsc(support_server), dbEsc(prefix), sessionData->discord_id, app_id),
|
||||
[app_id, callback] (const orm::Result &) {
|
||||
[app_id, sessionData, callback] (const orm::Result &) {
|
||||
callback(HttpResponse::newRedirectionResponse(std::to_string(app_id)+"/detail"));
|
||||
// Send webhook log message
|
||||
webhookSend("Bot `"+std::to_string(app_id)+"` registered by `"+std::to_string(sessionData->discord_id)+'`');
|
||||
}, dbErr);
|
||||
});
|
||||
}, dbErr);
|
||||
|
|
Loading…
Add table
Reference in a new issue