01-07
This commit is contained in:
Vendored
+7
@@ -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": []
|
||||
}
|
||||
Vendored
+127
-7
@@ -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
|
||||
},
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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})
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user