Created the remove.cpp

This commit is contained in:
Mathias Wagner 2023-11-04 14:09:04 +01:00
parent f42b40091b
commit 204fdcc0b6
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

26
src/commands/remove.cpp Normal file
View File

@ -0,0 +1,26 @@
#include "remove.h"
#include <api/util.h>
void remove::execute(sql::Connection &con, dpp::cluster &bot, const dpp::slashcommand_t &event) {
dpp::channel channel = event.command.get_command_interaction().options.empty() ? event.command.channel
: event.command.get_resolved_channel(
std::get<dpp::snowflake>(event.get_parameter("channel")));
if (channel.get_type() != dpp::channel_type::CHANNEL_TEXT) {
util::sendError(event, "You can only remove text channels!");
return;
}
sql::ResultSet *res = util::getResultSet(con, "SELECT * FROM `channels` WHERE `channelId` = ? AND `guildId` = ?",
{channel.id.str(), channel.guild_id.str()});
if (res->next()) {
util::sendSuccess(event, "This channel is no longer a global chat channel!");
util::executeQuery(con, "DELETE FROM `channels` WHERE `channelId` = ? AND `guildId` = ?",
{channel.id.str(), channel.guild_id.str()});
} else {
util::sendError(event, "This channel is not in the global chat!");
}
delete res;
}