Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ out
CMakeSettings.json
build

# cache
.cache

# token
config.json
/src/config.json
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions src/commands/commands.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef COMMANDS_H
#define COMMANDS_H

#include <iostream>
#include <list>
#include <dpp/dpp.h>
#include <dpp/cluster.h>
#include <dpp/dispatcher.h>
Expand Down Expand Up @@ -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
{
/**
Expand All @@ -69,6 +76,8 @@ struct cmdStruct

typedef std::function<void(dpp::cluster&, dpp::slashcommand_t)> cmdFunc;
cmdFunc function;

std::list<dpp::command_option> args;
};

#endif // COMMANDS_H
45 changes: 45 additions & 0 deletions src/commands/rule_cmd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "commands.h"
#include "../globals/globals.h"

#include <dpp/appcommand.h>
#include <dpp/dpp.h>
#include <dpp/channel.h>
#include <string>
#include <vector>

void cmd::ruleCommand(dpp::cluster& bot, const dpp::slashcommand_t& event)
{
std::vector<std::string> 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<long>(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);
}
5 changes: 5 additions & 0 deletions src/globals/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <iostream>
#include <list>
#include <fstream>
#include <dpp/dpp.h>

Expand All @@ -13,7 +14,8 @@ std::list<cmdStruct> 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()
Expand All @@ -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);
Expand Down