summaryrefslogtreecommitdiff
path: root/bot/src/main.cpp
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 /bot/src/main.cpp
parentb53c72f7421ff8218354ec8a13187c984960778c (diff)
Ajout de la vérification des permissions pour l'action de suppression et gestion des statuts d'activitéHEADmain
Diffstat (limited to 'bot/src/main.cpp')
-rw-r--r--bot/src/main.cpp49
1 files changed, 45 insertions, 4 deletions
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;