From 1d707ec57d34f1451801eef043a6a23ddd5332a9 Mon Sep 17 00:00:00 2001 From: fellalli Date: Fri, 14 Feb 2025 23:35:05 +0100 Subject: [PATCH] Add rule command --- .gitignore | 3 +++ CMakeLists.txt | 3 ++- src/commands/commands.h | 15 ++++++++++--- src/commands/rule_cmd.cpp | 45 +++++++++++++++++++++++++++++++++++++++ src/globals/globals.h | 5 +++++ src/main.cpp | 9 +++++++- 6 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 src/commands/rule_cmd.cpp diff --git a/.gitignore b/.gitignore index 0cc6ae0..32b0d73 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,9 @@ out CMakeSettings.json build +# cache +.cache + # token config.json /src/config.json diff --git a/CMakeLists.txt b/CMakeLists.txt index fe8b943..01f03b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,8 @@ add_executable(bot src/commands/close_cmd.cpp src/commands/ticket_cmd.cpp src/commands/code_cmd.cpp - src/commands/project_cmd.cpp + src/commands/project_cmd.cpp + src/commands/rule_cmd.cpp # utils src/utils/suggestion/suggestion.cpp diff --git a/src/commands/commands.h b/src/commands/commands.h index c92b9d1..e8459bb 100644 --- a/src/commands/commands.h +++ b/src/commands/commands.h @@ -1,7 +1,7 @@ #ifndef COMMANDS_H #define COMMANDS_H -#include +#include #include #include #include @@ -44,12 +44,19 @@ namespace cmd void codeCommand(dpp::cluster& bot, const dpp::slashcommand_t& event); /** - * @brief Replies with a coding project idea + * @brief Replies with a coding project idea * @param bot * @param slashcommand event - */ + */ void projectCommand(dpp::cluster& bot, const dpp::slashcommand_t& event); + /** + * @brief Replies with the rules + * @param bot + * @param slashcommand event + */ + void ruleCommand(dpp::cluster& bot, const dpp::slashcommand_t& event); + namespace utils { /** @@ -69,6 +76,8 @@ struct cmdStruct typedef std::function cmdFunc; cmdFunc function; + + std::list args; }; #endif // COMMANDS_H diff --git a/src/commands/rule_cmd.cpp b/src/commands/rule_cmd.cpp new file mode 100644 index 0000000..315a031 --- /dev/null +++ b/src/commands/rule_cmd.cpp @@ -0,0 +1,45 @@ +#include "commands.h" +#include "../globals/globals.h" + +#include +#include +#include +#include +#include + +void cmd::ruleCommand(dpp::cluster& bot, const dpp::slashcommand_t& event) +{ + std::vector rules = { + "Follow Discord's Terms of Service: Adhere to Discord's Terms of Service (ToS) and Community Guidelines.", + "Be respectful: Treat others with kindness, respect, and patience. Avoid harassment, personal attacks, or any form of offensive behavior.", + "Stay on topic: Keep discussions focused on C++ coding and related topics. Avoid excessive off-topic conversations that may disrupt the flow of the server.", + "No spam or self-promotion: Refrain from spamming, advertising, or excessive self-promotion. This includes sharing unrelated links, excessive emojis, or repeated messages.", + "Use appropriate language: Ensure your language remains appropriate and professional. Avoid excessive swearing, offensive language, or any content that may violate Discord's guidelines.", + "Provide helpful assistance: When providing assistance, be constructive and offer accurate information. Help others to the best of your knowledge and avoid misleading advice.", + "Respect privacy and copyright: Do not share personal information without consent. Respect the intellectual property rights of others and avoid sharing copyrighted material.", + "Do not provide or request help on projects that may violate terms of service, or that may be deemed inappropriate, malicious, or illegal.", + "Do not offer or ask for paid work of any kind.", + "Do not copy and paste answers from ChatGPT or similar AI tools." + }; + + dpp::command_interaction cmdData = event.command.get_command_interaction(); + if (cmdData.options.empty()) + return event.reply(dpp::message("Please follow our <#" + globals::channel::rulesId.str() + ">.")); + + const auto option = cmdData.options[0]; + + if (option.type != dpp::co_integer) + return; // should never happen + + const long index = std::get(option.value); + + if ((index < 1 || index > rules.size())) + return event.reply(dpp::message("Rule number " + std::to_string(index) + " does not exist. Visit <#" + globals::channel::rulesId.str() + "> to see all available rules.").set_flags(dpp::m_ephemeral)); + + const std::string rule = rules.at(index-1); + const dpp::embed embed = dpp::embed() + .set_color(globals::color::defaultColor) + .add_field("Rule " + std::to_string(index), rule); + dpp::message message(event.command.channel_id, embed); + event.reply(message); +} diff --git a/src/globals/globals.h b/src/globals/globals.h index 9006665..b6ca32a 100644 --- a/src/globals/globals.h +++ b/src/globals/globals.h @@ -16,6 +16,11 @@ namespace globals static constexpr dpp::snowflake no = 1226134940006219817; } + namespace channel + { + static constexpr dpp::snowflake rulesId = 1130464978860785705; + } + namespace category { static constexpr dpp::snowflake ticketId = 1234179713182732374; diff --git a/src/main.cpp b/src/main.cpp index 1b81f8f..4cb495e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -13,7 +14,8 @@ std::list cmdList = { { "close", "Close a ticket or forum post", cmd::closeCommand }, { "ticket", "Open a ticket", cmd::ticketCommand }, { "code", "Formatting code on Discord", cmd::codeCommand }, - { "project", "Get a project idea", cmd::projectCommand } + { "project", "Get a project idea", cmd::projectCommand }, + { "rule", "Get the server rules", cmd::ruleCommand, { dpp::command_option(dpp::command_option_type::co_integer, "number", "Rule to mention", false) } } }; int main() @@ -36,6 +38,11 @@ int main() slashcommand.set_name(item.name); slashcommand.set_description(item.desc); slashcommand.set_application_id(bot.me.id); + + for (dpp::command_option arg : item.args) + { + slashcommand.add_option(arg); + } slashcommands.push_back(slashcommand); } bot.global_bulk_command_create(slashcommands);