Created the channel.cpp command

This commit is contained in:
Mathias Wagner 2023-11-04 23:57:06 +01:00
parent d53c01c734
commit 8941b875ea
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

28
src/commands/channel.cpp Normal file
View File

@ -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<std::string>(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.");
}
}