Compare commits

..
2 Commits
Author SHA1 Message Date
firewire e28f17e513 01-08
Build / Build (push) Failing after 38s
2026-09-24 09:08:33 -04:00
firewire b80dd23611 01-07 2026-09-24 08:48:50 -04:00
7 changed files with 268 additions and 7 deletions
+7
View File
@@ -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": []
}
+127 -7
View File
@@ -4,7 +4,18 @@
{ {
"label": "Build: Debug", "label": "Build: Debug",
"type": "shell", "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": { "group": {
"kind": "build", "kind": "build",
"isDefault": true "isDefault": true
@@ -15,7 +26,18 @@
{ {
"label": "Configure: Debug", "label": "Configure: Debug",
"type": "shell", "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": { "group": {
"isDefault": false "isDefault": false
}, },
@@ -25,7 +47,18 @@
{ {
"label": "Configure: Relwithdeb", "label": "Configure: Relwithdeb",
"type": "shell", "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": { "group": {
"isDefault": false "isDefault": false
}, },
@@ -35,7 +68,18 @@
{ {
"label": "Build: Relwithdeb", "label": "Build: Relwithdeb",
"type": "shell", "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": { "group": {
"kind": "build", "kind": "build",
"isDefault": true "isDefault": true
@@ -43,10 +87,64 @@
"problemMatcher": [], "problemMatcher": [],
"detail": "Build Release with debug info" "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", "label": "Clean: Debug",
"type": "shell", "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": { "group": {
"isDefault": false "isDefault": false
}, },
@@ -55,7 +153,18 @@
{ {
"label": "Build: All", "label": "Build: All",
"type": "shell", "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": { "group": {
"kind": "build", "kind": "build",
"isDefault": true "isDefault": true
@@ -66,7 +175,18 @@
{ {
"label": "Clean: All", "label": "Clean: All",
"type": "shell", "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": { "group": {
"isDefault": false "isDefault": false
}, },
+2
View File
@@ -33,3 +33,5 @@ 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/04_adding_files")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/01_basics/05_webhooks") 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/06_callbacks")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/01_basics/07_cache")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/01_basics/08_listening_to_messages")
+15
View File
@@ -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})
+58
View File
@@ -0,0 +1,58 @@
#include <cache.h>
#include <cluster.h>
#include <intents.h>
#include <misc-enum.h>
#include <cstdlib>
#include <iostream>
#include <string>
#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;
}
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.28)
project(dppbots)
set(example_name "01_08_listening_to_messages")
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})
@@ -0,0 +1,44 @@
#include <cluster.h>
#include <dispatcher.h>
#include <intents.h>
#include <cstdlib>
#include <iostream>
#include "dotenv.h"
// Please note:
// Discord made message content a privileged intent in August 2022.
// Directly pulling the message content and using prefixes for commands is
// generally an older technique for running bot commands. Nowadays it is
// recommanded to use slash commands, which is covered in 02_01.
int main() {
// Load the .env into the environment
dotenv::init();
// Make sure the DISCORD_TOKEN env var exists
if (!std::getenv("DISCORD_TOKEN")) {
std::cout << "Failed to get DISCORD_TOKEN from .env or environment"
<< std::endl;
exit(EXIT_FAILURE);
}
// Load in the bot token from the env
std::string botToken = std::getenv("DISCORD_TOKEN");
// Create the bot
dpp::cluster bot(botToken, dpp::i_default_intents | dpp::i_message_content);
// Create a lambda for the on_message_create event.
bot.on_message_create([](const dpp::message_create_t& event) {
// Filter through the message content
if (event.msg.content.find("bad word") != std::string::npos) {
event.reply("That is not allowed here. Please, mind you language.",
true);
}
});
// Start the bot
bot.start(dpp::st_wait);
return 0;
}