summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsoler_j <soler_j@etna-alternance.net>2025-04-30 23:44:34 +0200
committersoler_j <soler_j@etna-alternance.net>2025-04-30 23:44:34 +0200
commit23cba7cd6b32b7c5db98aa5a3f9206d4bce07902 (patch)
treef9b32c80987937143681178f6b52f1a661ee6928
parentb53c72f7421ff8218354ec8a13187c984960778c (diff)
Ajout de la vérification des permissions pour l'action de suppression et gestion des statuts d'activitéHEADmain
-rw-r--r--bot/src/actions/delete.cpp12
-rw-r--r--bot/src/handle_actions.cpp4
-rw-r--r--bot/src/main.cpp49
3 files changed, 56 insertions, 9 deletions
diff --git a/bot/src/actions/delete.cpp b/bot/src/actions/delete.cpp
index 4549950..58835cf 100644
--- a/bot/src/actions/delete.cpp
+++ b/bot/src/actions/delete.cpp
@@ -27,10 +27,14 @@ dpp::task<bool> delete_action(const dpp::slashcommand_t &event, const nlohmann::
}
// let's retrieve the current channel
const dpp::channel *channel_ptr = &event.command.get_channel();
-
- // let's check if the user has permission to delete messages
- if (!channel_ptr->get_user_permissions(member_ptr).has(dpp::p_manage_messages) &&
- !channel_ptr->get_user_permissions(bot_member_ptr).has(dpp::p_manage_messages))
+ auto user_as_perms = channel_ptr->get_user_permissions(member_ptr).has(dpp::p_manage_messages);
+ auto bot_as_perms = channel_ptr->get_user_permissions(bot_member_ptr).has(dpp::p_manage_messages);
+ if (!user_as_perms)
+ {
+ event.edit_response(error_messages["error_perm_channel"]);
+ co_return false;
+ }
+ if (!bot_as_perms)
{
event.edit_response(error_messages["error_perm_channel"]);
co_return false;
diff --git a/bot/src/handle_actions.cpp b/bot/src/handle_actions.cpp
index 15645cb..e469ec7 100644
--- a/bot/src/handle_actions.cpp
+++ b/bot/src/handle_actions.cpp
@@ -17,13 +17,15 @@ dpp::task<bool> handle_actions(const dpp::slashcommand_t &event, const nlohmann:
std::string action_type = action["type"];
if (action_type == "delete_messages" && event.command.is_guild_interaction())
{
- co_await thinking;
auto return_value = co_await delete_action(event, action, key_values, user_ptr, cluster);
+ co_await thinking;
// if it's a false, we need to return false !
if (!return_value)
{
co_return false;
}
+
+
}
}
if (i == actions.size())
diff --git a/bot/src/main.cpp b/bot/src/main.cpp
index 557463e..42e84bd 100644
--- a/bot/src/main.cpp
+++ b/bot/src/main.cpp
@@ -5,6 +5,25 @@
#include "../include/handle_actions.hpp"
#include <thread>
+
+dpp::activity_type activity_type_from_string(const std::string& type) {
+ if (type == "playing") {
+ return dpp::activity_type::at_game;
+ } else if (type == "streaming") {
+ return dpp::activity_type::at_streaming;
+ } else if (type == "listening") {
+ return dpp::activity_type::at_listening;
+ } else if (type == "watching") {
+ return dpp::activity_type::at_watching;
+ } else if (type == "custom") {
+ return dpp::activity_type::at_custom;
+ } else if (type == "competing") {
+ return dpp::activity_type::at_competing;
+ } else {
+ throw std::invalid_argument("Invalid activity type");
+ }
+}
+
int main(int argc, char* argv[]) {
if (argc > 2) {
setenv("BOT_TOKEN", argv[1], 1);
@@ -57,9 +76,9 @@ int main(int argc, char* argv[]) {
bot.on_ready([&bot, &json_data, &PORT](const dpp::ready_t& event) {
if (dpp::run_once<struct register_bot_commands>()) {
- std::thread http_thread([&json_data, &PORT]() {
+ std::thread http_thread([&json_data, &PORT,&bot]() {
try {
- HttpWebhookServer server(std::stoi(PORT), [&json_data](const HttpWebhookServer::HttpRequest& req) {
+ HttpWebhookServer server(std::stoi(PORT), [&json_data, &bot](const HttpWebhookServer::HttpRequest& req) {
HttpWebhookServer::HttpResponse res;
if (req.method == "POST") {
@@ -70,8 +89,30 @@ int main(int argc, char* argv[]) {
nlohmann::json body_json = app::json_from_string(req.body);
res.body = R"({"received": "POST request received"})";
- if (body_json.contains("command") && body_json["command"] == "update") {
- json_data = std::make_unique<nlohmann::json>(body_json["data"]);
+ if (body_json.contains("command")) {
+ if(body_json["command"] == "update"){
+ json_data = std::make_unique<nlohmann::json>(body_json["data"]);
+ }else if(body_json["command"] == "update_status"){
+ std::string status = body_json.contains("status") ? body_json["status"] : "online";
+ std::string activity = body_json.contains("activity") ? body_json["activity"] : "";
+ std::string activity_status = body_json.contains("activity_status") ? body_json["activity_status"] : "";
+ std::string activity_url = body_json.contains("activity_url") ? body_json["activity_url"] : "";
+ std::string activity_type = body_json.contains("activity_type") ? body_json["activity_type"] : "playing";
+ dpp::presence p;
+ if (status == "online") {
+ p = dpp::presence(dpp::presence_status::ps_online, dpp::activity(activity_type_from_string(activity_type), activity, activity_status, activity_url));
+ } else if (status == "offline") {
+ p = dpp::presence(dpp::presence_status::ps_offline, dpp::activity(activity_type_from_string(activity_type), activity, activity_status, activity_url));
+ } else if (status == "dnd") {
+ p = dpp::presence(dpp::presence_status::ps_dnd, dpp::activity(activity_type_from_string(activity_type), activity, activity_status, activity_url));
+ } else if (status == "idle") {
+ p = dpp::presence(dpp::presence_status::ps_idle, dpp::activity(activity_type_from_string(activity_type), activity, activity_status, activity_url));
+ } else if (status == "invisible") {
+ p = dpp::presence(dpp::presence_status::ps_invisible, dpp::activity(activity_type_from_string(activity_type), activity, activity_status, activity_url));
+ }
+ bot.set_presence(p);
+ }
+ res.body = R"({"status": "success", "message": "Command executed successfully"})";
}
} catch (const std::exception& e) {
res.status_code = 400;