Created the add.cpp command
This commit is contained in:
parent
64e7b6a397
commit
1a614ea8e8
32
src/commands/add.cpp
Normal file
32
src/commands/add.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include "add.h"
|
||||||
|
#include "api/util.h"
|
||||||
|
#include <mariadb/conncpp.hpp>
|
||||||
|
|
||||||
|
using namespace sql;
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
void add::execute(sql::Connection &con, dpp::cluster &bot, const dpp::slashcommand_t &event) {
|
||||||
|
ResultSet *res = util::getResultSet(con, "SELECT * FROM channels WHERE guildId = ? AND channelId = ?",
|
||||||
|
{event.command.guild_id.str(), event.command.channel_id.str()});
|
||||||
|
if (res->next()) {
|
||||||
|
util::sendError(event, "This channel is already registered.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dpp::webhook newWebhook = dpp::webhook();
|
||||||
|
newWebhook.name = "Sheepstar";
|
||||||
|
newWebhook.channel_id = event.command.channel_id;
|
||||||
|
|
||||||
|
bot.create_webhook(newWebhook, [&con, event](const dpp::confirmation_callback_t &res) {
|
||||||
|
if (res.is_error()) {
|
||||||
|
util::sendError(event, "An error occurred while creating the webhook.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string url = json::parse(res.http_info.body)["url"].get<std::string>();
|
||||||
|
util::executeQuery(con, "INSERT INTO channels (guildId, channelId, webhookToken, cachedName) VALUES (?, ?, ?, ?)",
|
||||||
|
{event.command.guild_id.str(), event.command.channel_id.str(), url, event.command.channel.name});
|
||||||
|
|
||||||
|
util::sendSuccess(event, "This channel has been registered.");
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user