From 204fdcc0b6473dd9b3c5caef135629ed55637747 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sat, 4 Nov 2023 14:09:04 +0100 Subject: [PATCH] Created the remove.cpp --- src/commands/remove.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/commands/remove.cpp diff --git a/src/commands/remove.cpp b/src/commands/remove.cpp new file mode 100644 index 0000000..d3d462d --- /dev/null +++ b/src/commands/remove.cpp @@ -0,0 +1,26 @@ +#include "remove.h" +#include + +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(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; +} \ No newline at end of file