From 8941b875ea5fc1564da7a82061d08a2bcf7ee0ac Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sat, 4 Nov 2023 23:57:06 +0100 Subject: [PATCH] Created the channel.cpp command --- src/commands/channel.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/commands/channel.cpp diff --git a/src/commands/channel.cpp b/src/commands/channel.cpp new file mode 100644 index 0000000..a13c589 --- /dev/null +++ b/src/commands/channel.cpp @@ -0,0 +1,28 @@ +#include "channel.h" +#include "api/util.h" + +void channel::execute(sql::Connection &con, dpp::cluster &bot, const dpp::slashcommand_t &event) { + std::string cmd = event.command.get_command_interaction().options[0].name; + + sql::ResultSet *res = util::getResultSet(con, "SELECT * FROM `channels` WHERE `channelId` = ? AND `guildId` = ?", + {event.command.channel_id.str(), event.command.guild_id.str()}); + + if (!res->next()) { + util::sendError(event, "This channel is not a global chat!"); + return; + } + + std::string value = std::get(event.command.get_command_interaction().options[0].options[0].value); + if (cmd == "language") { + util::executeQuery(con, "UPDATE `channels` SET `langCode` = ? WHERE `channelId` = ? AND `guildId` = ?", + {value, event.command.channel_id.str(), event.command.guild_id.str()}); + util::sendSuccess(event, "The language of this channel has been updated."); + } else if (cmd == "topic") { + util::executeQuery(con, "UPDATE `channels` SET `topicId` = ? WHERE `channelId` = ? AND `guildId` = ?", + {value, event.command.channel_id.str(), event.command.guild_id.str()}); + util::sendSuccess(event, "The topic of this channel has been updated."); + } else { + util::sendError(event, "Invalid subcommand."); + } + +} \ No newline at end of file