diff --git a/.vscode/tasks.json b/.vscode/tasks.json index ec66a8b..1631ea8 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,16 +1,6 @@ { "version": "2.0.0", "tasks": [ - { - "label": "Configure: Debug", - "type": "shell", - "command": "cd scripts; ./configure-debug.sh", - "group": { - "isDefault": false - }, - "problemMatcher": [], - "detail": "Configure Debug" - }, { "label": "Build: Debug", "type": "shell", @@ -22,6 +12,16 @@ "problemMatcher": [], "detail": "Build Debug" }, + { + "label": "Configure: Debug", + "type": "shell", + "command": "cd scripts; ./configure-debug.sh", + "group": { + "isDefault": false + }, + "problemMatcher": [], + "detail": "Configure Debug" + }, { "label": "Configure: Relwithdeb", "type": "shell", diff --git a/CMakeLists.txt b/CMakeLists.txt index d569ad7..9039eec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,3 +22,4 @@ add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/01_basics/01_first_bot") add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/01_basics/02_embeds") 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") diff --git a/cmake/dpp.cmake b/cmake/dpp.cmake index 6112ea0..56ba428 100644 --- a/cmake/dpp.cmake +++ b/cmake/dpp.cmake @@ -1,5 +1,5 @@ CPMAddPackage( - URI "gh:brainboxdotcc/DPP@10.1.5" + URI "gh:brainboxdotcc/DPP@10.1.6" OPTIONS "BUILD_VOICE_SUPPORT ON" OPTIONS "RUN_LDCONFIG OFF" OPTIONS "DPP_INSTALL OFF" @@ -7,5 +7,4 @@ CPMAddPackage( OPTIONS "DPP_NO_VCPKG ON" OPTIONS "DPP_NO_CONAN ON" OPTIONS "DPP_FORMATTERS ON" - OPTIONS "DPP_USE_PCH ON" -) + OPTIONS "DPP_USE_PCH ON") diff --git a/src/01_basics/05_webhooks/CMakeLists.txt b/src/01_basics/05_webhooks/CMakeLists.txt new file mode 100644 index 0000000..12db258 --- /dev/null +++ b/src/01_basics/05_webhooks/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.28) +project(dppbots) +set(example_name "01_05_webhooks") +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/05_webhooks/src/main.cpp b/src/01_basics/05_webhooks/src/main.cpp new file mode 100644 index 0000000..43d2e99 --- /dev/null +++ b/src/01_basics/05_webhooks/src/main.cpp @@ -0,0 +1,41 @@ +#include +#include + +#include +#include +#include +#include + +#include "dotenv.h" + +int main() { + // Load in the .env file into the environment + dotenv::init(); + if (!std::getenv("DISCORD_WEBHOOK")) { + std::cout << "Failed to get webhook from .env or environment" + << std::endl; + exit(EXIT_FAILURE); + } + + // Get the webhook url from the environment + std::string webhookUrl = std::getenv("DISCORD_WEBHOOK"); + + // When using webhooks, a bot token is not needed, + // we can just create the cluster without it + dpp::cluster bot; + // Start the bot, returning once its initializaed + bot.start(dpp::st_return); + // Create a webhook object with our webhook url + dpp::webhook wh(webhookUrl); + + // Send a simple message over the webhook + bot.execute_webhook(wh, dpp::message("This is a webhook message!")); + + // Wait for all active requests to be completed + while (bot.active_requests() > 0) { + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + + // Exit, the bot will automatically be cleaned up + return 0; +}