From b80dd236117cd47fd5bdebb5ee788eb1f3eed2b4 Mon Sep 17 00:00:00 2001 From: firewire Date: Thu, 24 Sep 2026 08:48:50 -0400 Subject: [PATCH] 01-07 --- .vscode/launch.json | 7 ++ .vscode/tasks.json | 134 ++++++++++++++++++++++++-- CMakeLists.txt | 1 + src/01_basics/07_cache/CMakeLists.txt | 15 +++ src/01_basics/07_cache/src/main.cpp | 58 +++++++++++ 5 files changed, 208 insertions(+), 7 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 src/01_basics/07_cache/CMakeLists.txt create mode 100644 src/01_basics/07_cache/src/main.cpp diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5c7247b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 1631ea8..7ee2d0f 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -4,7 +4,18 @@ { "label": "Build: Debug", "type": "shell", - "command": "cd scripts; ./build-debug.sh", + "command": "./scripts/build_script build -b debug", + "windows": { + "command": "powershell.exe", + "args": [ + "-NoProfile", + "-Command", + "& './scripts/build_script.exe' build -b debug" + ], + "options": { + "cwd": "${workspaceFolder}" + } + }, "group": { "kind": "build", "isDefault": true @@ -15,7 +26,18 @@ { "label": "Configure: Debug", "type": "shell", - "command": "cd scripts; ./configure-debug.sh", + "command": "./scripts/build_script configure -b debug", + "windows": { + "command": "powershell.exe", + "args": [ + "-NoProfile", + "-Command", + "& './scripts/build_script.exe' configure -b debug" + ], + "options": { + "cwd": "${workspaceFolder}" + } + }, "group": { "isDefault": false }, @@ -25,7 +47,18 @@ { "label": "Configure: Relwithdeb", "type": "shell", - "command": "cd scripts; ./configure-relwithdeb.sh", + "command": "./scripts/build_script configure -b relwithdeb", + "windows": { + "command": "powershell.exe", + "args": [ + "-NoProfile", + "-Command", + "& './scripts/build_script.exe' configure -b relwithdeb" + ], + "options": { + "cwd": "${workspaceFolder}" + } + }, "group": { "isDefault": false }, @@ -35,7 +68,18 @@ { "label": "Build: Relwithdeb", "type": "shell", - "command": "cd scripts; ./build-relwithdeb.sh", + "command": "./scripts/build_script build -b relwithdeb", + "windows": { + "command": "powershell.exe", + "args": [ + "-NoProfile", + "-Command", + "& './scripts/build_script.exe' build -b relwithdeb" + ], + "options": { + "cwd": "${workspaceFolder}" + } + }, "group": { "kind": "build", "isDefault": true @@ -43,10 +87,64 @@ "problemMatcher": [], "detail": "Build Release with debug info" }, + { + "label": "Configure: Release", + "type": "shell", + "command": "./scripts/build_script configure -b release", + "windows": { + "command": "powershell.exe", + "args": [ + "-NoProfile", + "-Command", + "& './scripts/build_script.exe' configure -b release" + ], + "options": { + "cwd": "${workspaceFolder}" + } + }, + "group": { + "isDefault": false + }, + "problemMatcher": [], + "detail": "Configure Release" + }, + { + "label": "Build: Release", + "type": "shell", + "command": "./scripts/build_script build -b release", + "windows": { + "command": "powershell.exe", + "args": [ + "-NoProfile", + "-Command", + "& './scripts/build_script.exe' build -b release" + ], + "options": { + "cwd": "${workspaceFolder}" + } + }, + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [], + "detail": "Build Release" + }, { "label": "Clean: Debug", "type": "shell", - "command": "cd build/debug; ninja clean", + "command": "./scripts/build_script clean -b debug", + "windows": { + "command": "powershell.exe", + "args": [ + "-NoProfile", + "-Command", + "& './scripts/build_script.exe' clean -b debug" + ], + "options": { + "cwd": "${workspaceFolder}" + } + }, "group": { "isDefault": false }, @@ -55,7 +153,18 @@ { "label": "Build: All", "type": "shell", - "command": "cd scripts; ./build.sh", + "command": "./scripts/build_script build", + "windows": { + "command": "powershell.exe", + "args": [ + "-NoProfile", + "-Command", + "& './scripts/build_script.exe' build" + ], + "options": { + "cwd": "${workspaceFolder}" + } + }, "group": { "kind": "build", "isDefault": true @@ -66,7 +175,18 @@ { "label": "Clean: All", "type": "shell", - "command": "cd scripts; ./clean.sh", + "command": "./scripts/build_script clean", + "windows": { + "command": "powershell.exe", + "args": [ + "-NoProfile", + "-Command", + "& './scripts/build_script.exe' clean" + ], + "options": { + "cwd": "${workspaceFolder}" + } + }, "group": { "isDefault": false }, diff --git a/CMakeLists.txt b/CMakeLists.txt index 48ed28c..b11bf01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,3 +33,4 @@ add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/01_basics/03_private_messages" add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/01_basics/04_adding_files") add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/01_basics/05_webhooks") add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/01_basics/06_callbacks") +add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/01_basics/07_cache") diff --git a/src/01_basics/07_cache/CMakeLists.txt b/src/01_basics/07_cache/CMakeLists.txt new file mode 100644 index 0000000..bf081c2 --- /dev/null +++ b/src/01_basics/07_cache/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.28) +project(dppbots) +set(example_name "01_07_cache") +message("Setting up ${example_name}") +add_executable(${example_name} "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp") +target_include_directories(${example_name} PUBLIC + "${dpp_SOURCE_DIR}/include" + "${dotenv-cpp_SOURCE_DIR}/include/laserpants" + +) +target_link_libraries(${example_name} + dpp + dotenv +) +SET_OUTPUT_NAMES(${example_name}) diff --git a/src/01_basics/07_cache/src/main.cpp b/src/01_basics/07_cache/src/main.cpp new file mode 100644 index 0000000..8284188 --- /dev/null +++ b/src/01_basics/07_cache/src/main.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include + +#include +#include +#include + +#include "dotenv.h" + +int main() { + // Load the .env into the environment + dotenv::init(); + // Make sure the DISCORD_TOKEN environment var exists + if (!std::getenv("DISCORD_TOKEN")) { + std::cout << "Failed to get DISCORD_TOKEN from .env or the environment." + << std::endl; + exit(EXIT_FAILURE); + } + // Get the bot token from DISCORD_TOKEN + std::string botToken = std::getenv("DISCORD_TOKEN"); + + // Create the bot, passing in our token as well as the intents + dpp::cluster bot(botToken, dpp::i_default_intents | dpp::i_guild_members); + + // Create a lamba as a callback for when a reaction is removed + bot.on_message_reaction_remove( + [&bot](const dpp::message_reaction_remove_t& event) { + // Get the user from the cache. + // More then just users are cached, you can use the following + // functions to interact with it + // dpp::find_role() + // dpp::find_channel() + // dpp::find_guild() + // dpp::find_guild_member() + // dpp::find_user() + dpp::user* reacting_user = dpp::find_user(event.reacting_user_id); + + // Make sure the user was actually found in the cache + if (!reacting_user) { + bot.log(dpp::ll_info, + "User with id " + + std::to_string(event.reacting_user_id) + + " was not found."); + return; + } + // Log the action, using their username that we grabbed from the + // cache + bot.log(dpp::ll_info, reacting_user->format_username() + + " removed their reaction."); + }); + + // Start the bot + bot.start(dpp::st_wait); + + return 0; +}