From bebdc6bf4b7bd41f213d941054152b7b7f038eb5 Mon Sep 17 00:00:00 2001 From: professor91 Date: Mon, 18 Sep 2023 13:01:45 +0530 Subject: [PATCH 1/7] added cache example --- docpages/example_code/using_cache.cpp | 26 +++++++++++++++++++ docpages/example_programs/the_basics.md | 3 ++- .../the_basics/using_cache.md | 16 ++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 docpages/example_code/using_cache.cpp create mode 100644 docpages/example_programs/the_basics/using_cache.md diff --git a/docpages/example_code/using_cache.cpp b/docpages/example_code/using_cache.cpp new file mode 100644 index 0000000000..8a93f2e881 --- /dev/null +++ b/docpages/example_code/using_cache.cpp @@ -0,0 +1,26 @@ +#include + +int main() { + /* Create bot */ + dpp::cluster bot("token", dpp::i_default_intents | dpp::i_guild_members); + + bot.on_log(dpp::utility::cout_logger()); + + /* This event is fired when someone removes their reaction from a message*/ + bot.on_message_reaction_remove([&bot](const dpp::message_reaction_remove_t& event) { + + /* Find the user in the cache using his discord id */ + dpp::user* reacting_user = dpp::find_user(event.reacting_user_id); + + /* If user not found in cache, log and return */ + if (!reacting_user) { + bot.log(dpp::ll_info, "User with the id " + std::to_string(event.reacting_user_id) + " was not found."); + return; + } + + bot.log(dpp::ll_info, reacting_user->format_username() + " removed his reaction."); + }); + + bot.start(dpp::st_wait); + return 0; +} diff --git a/docpages/example_programs/the_basics.md b/docpages/example_programs/the_basics.md index 74b462c035..0522b99d7e 100644 --- a/docpages/example_programs/the_basics.md +++ b/docpages/example_programs/the_basics.md @@ -7,4 +7,5 @@ These example programs are great to get started with simple things in the D++ li * \subpage attach-file "Attaching a file" * \subpage webhooks "Webhooks" * \subpage callback-functions "Using Callback Functions" -* \subpage editing-channels-and-messages \ No newline at end of file +* \subpage editing-channels-and-messages +* \subpage using-cache \ No newline at end of file diff --git a/docpages/example_programs/the_basics/using_cache.md b/docpages/example_programs/the_basics/using_cache.md new file mode 100644 index 0000000000..f2768df6b0 --- /dev/null +++ b/docpages/example_programs/the_basics/using_cache.md @@ -0,0 +1,16 @@ +\page using-cache Using Cache + +Sometimes you may need information that is not directly available in the event callback object. + +To handle this DPP maintains a cache of commonly used data for you. + +Below is an example showing how to get a user from the cache + +\include{cpp} using_cache.cpp + +DPP caches more than just users, which you can get using the below-mentioned functions: +- `dpp::find_role()` +- `dpp::find_channel()` +- `dpp::find_emoji()` +- `dpp::find_guild()` +- `dpp::find_guild_member()` \ No newline at end of file From bcfe30e16d8d3542ccab211e02f8c4c33ff9af7d Mon Sep 17 00:00:00 2001 From: professor91 Date: Mon, 18 Sep 2023 13:15:10 +0530 Subject: [PATCH 2/7] replace - with _ in filenames --- ...g-with-jenkins.md => automating_with_jenkins.md} | 0 docpages/advanced_reference/lambdas_and_locals.md | 2 +- .../{separate-events.md => separate_events.md} | 0 ...{detecting-messages.md => detecting_messages.md} | 0 .../{private-messaging.md => private_messaging.md} | 0 ...{user-only-messages.md => user_only_messages.md} | 0 ...ermissions.md => checking_member_permissions.md} | 0 ...messages.md => editing_channels_and_messages.md} | 0 ...ucture.png => build_clion_project_structure.png} | Bin ...ect.png => build_clion_reload_cmake_project.png} | Bin ...ean-time-travel.gif => delorean_time_travel.gif} | Bin docpages/make_a_bot/clion.md | 4 ++-- 12 files changed, 3 insertions(+), 3 deletions(-) rename docpages/advanced_reference/{automating-with-jenkins.md => automating_with_jenkins.md} (100%) rename docpages/advanced_reference/{separate-events.md => separate_events.md} (100%) rename docpages/example_programs/interactions_and_components/{detecting-messages.md => detecting_messages.md} (100%) rename docpages/example_programs/interactions_and_components/{private-messaging.md => private_messaging.md} (100%) rename docpages/example_programs/interactions_and_components/{user-only-messages.md => user_only_messages.md} (100%) rename docpages/example_programs/the_basics/{checking-member-permissions.md => checking_member_permissions.md} (100%) rename docpages/example_programs/the_basics/{editing-channels-and-messages.md => editing_channels_and_messages.md} (100%) rename docpages/images/{build-clion-project-structure.png => build_clion_project_structure.png} (100%) rename docpages/images/{build-clion-reload-cmake-project.png => build_clion_reload_cmake_project.png} (100%) rename docpages/images/{delorean-time-travel.gif => delorean_time_travel.gif} (100%) diff --git a/docpages/advanced_reference/automating-with-jenkins.md b/docpages/advanced_reference/automating_with_jenkins.md similarity index 100% rename from docpages/advanced_reference/automating-with-jenkins.md rename to docpages/advanced_reference/automating_with_jenkins.md diff --git a/docpages/advanced_reference/lambdas_and_locals.md b/docpages/advanced_reference/lambdas_and_locals.md index ea41394066..74b1ae6364 100644 --- a/docpages/advanced_reference/lambdas_and_locals.md +++ b/docpages/advanced_reference/lambdas_and_locals.md @@ -4,7 +4,7 @@ If you are reading this page, you have likely been sent here by someone helping It is important to remember that when you put a lambda callback onto a function in D++, that this lambda will execute at some point in the **future**. As with all things in the future and as 80s Sci-Fi movies will tell you, when you reach the future, things may well have changed! -\image html delorean-time-travel.gif +\image html delorean_time_travel.gif To explain this situation and how it causes issues, I'd like you to imagine the age-old magic trick, where a magician sets a fine table full of cutlery, pots, pans and wine. He indicates to the audience that this is authentic, then with a whip of his wrist, he whips the tablecloth away, leaving the cutlery and other tableware in place (if he is any good as a magician!) diff --git a/docpages/advanced_reference/separate-events.md b/docpages/advanced_reference/separate_events.md similarity index 100% rename from docpages/advanced_reference/separate-events.md rename to docpages/advanced_reference/separate_events.md diff --git a/docpages/example_programs/interactions_and_components/detecting-messages.md b/docpages/example_programs/interactions_and_components/detecting_messages.md similarity index 100% rename from docpages/example_programs/interactions_and_components/detecting-messages.md rename to docpages/example_programs/interactions_and_components/detecting_messages.md diff --git a/docpages/example_programs/interactions_and_components/private-messaging.md b/docpages/example_programs/interactions_and_components/private_messaging.md similarity index 100% rename from docpages/example_programs/interactions_and_components/private-messaging.md rename to docpages/example_programs/interactions_and_components/private_messaging.md diff --git a/docpages/example_programs/interactions_and_components/user-only-messages.md b/docpages/example_programs/interactions_and_components/user_only_messages.md similarity index 100% rename from docpages/example_programs/interactions_and_components/user-only-messages.md rename to docpages/example_programs/interactions_and_components/user_only_messages.md diff --git a/docpages/example_programs/the_basics/checking-member-permissions.md b/docpages/example_programs/the_basics/checking_member_permissions.md similarity index 100% rename from docpages/example_programs/the_basics/checking-member-permissions.md rename to docpages/example_programs/the_basics/checking_member_permissions.md diff --git a/docpages/example_programs/the_basics/editing-channels-and-messages.md b/docpages/example_programs/the_basics/editing_channels_and_messages.md similarity index 100% rename from docpages/example_programs/the_basics/editing-channels-and-messages.md rename to docpages/example_programs/the_basics/editing_channels_and_messages.md diff --git a/docpages/images/build-clion-project-structure.png b/docpages/images/build_clion_project_structure.png similarity index 100% rename from docpages/images/build-clion-project-structure.png rename to docpages/images/build_clion_project_structure.png diff --git a/docpages/images/build-clion-reload-cmake-project.png b/docpages/images/build_clion_reload_cmake_project.png similarity index 100% rename from docpages/images/build-clion-reload-cmake-project.png rename to docpages/images/build_clion_reload_cmake_project.png diff --git a/docpages/images/delorean-time-travel.gif b/docpages/images/delorean_time_travel.gif similarity index 100% rename from docpages/images/delorean-time-travel.gif rename to docpages/images/delorean_time_travel.gif diff --git a/docpages/make_a_bot/clion.md b/docpages/make_a_bot/clion.md index 6aadb74a2d..786188d230 100644 --- a/docpages/make_a_bot/clion.md +++ b/docpages/make_a_bot/clion.md @@ -25,7 +25,7 @@ In the `libs/` directory, clone D++ with: `git clone https://github.com/brainbox Your project directory should look like this: -\image html build-clion-project-structure.png +\image html build_clion_project_structure.png ### Configure CMake file @@ -69,7 +69,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES Then open the "File" menu and click on "Reload CMake Project" to reload the CMake configuration. -\image html build-clion-reload-cmake-project.png +\image html build_clion_reload_cmake_project.png ### Add an example program From 3df283aba33f43c7d1dfd17059a59f28df974338 Mon Sep 17 00:00:00 2001 From: professor91 Date: Mon, 18 Sep 2023 15:15:23 +0530 Subject: [PATCH 3/7] moved permissions example in misc folder --- .../{the_basics => misc}/checking_member_permissions.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docpages/example_programs/{the_basics => misc}/checking_member_permissions.md (100%) diff --git a/docpages/example_programs/the_basics/checking_member_permissions.md b/docpages/example_programs/misc/checking_member_permissions.md similarity index 100% rename from docpages/example_programs/the_basics/checking_member_permissions.md rename to docpages/example_programs/misc/checking_member_permissions.md From c0013aac86043eb5c4c68775a639e8dff6f92641 Mon Sep 17 00:00:00 2001 From: professor91 Date: Mon, 18 Sep 2023 18:23:56 +0530 Subject: [PATCH 4/7] add intents note --- docpages/example_programs/the_basics/using_cache.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docpages/example_programs/the_basics/using_cache.md b/docpages/example_programs/the_basics/using_cache.md index f2768df6b0..8b578720f1 100644 --- a/docpages/example_programs/the_basics/using_cache.md +++ b/docpages/example_programs/the_basics/using_cache.md @@ -2,6 +2,8 @@ Sometimes you may need information that is not directly available in the event callback object. +@note As of August 30th, 2022, Discord made Guild Members a privileged intent. You must have GUILD_MEMBERS intent enabled for your app from discord developers portal to be able to look for members in cache. + To handle this DPP maintains a cache of commonly used data for you. Below is an example showing how to get a user from the cache From 0ef812d6b8096d71bd2f56dbbad4d6b0e1befaca Mon Sep 17 00:00:00 2001 From: professor91 Date: Mon, 18 Sep 2023 20:36:59 +0530 Subject: [PATCH 5/7] revert img file names --- docpages/advanced_reference/lambdas_and_locals.md | 2 +- ...ucture.png => build-clion-project-structure.png} | Bin ...ect.png => build-clion-reload-cmake-project.png} | Bin ...ean_time_travel.gif => delorean-time-travel.gif} | Bin docpages/make_a_bot/clion.md | 4 ++-- 5 files changed, 3 insertions(+), 3 deletions(-) rename docpages/images/{build_clion_project_structure.png => build-clion-project-structure.png} (100%) rename docpages/images/{build_clion_reload_cmake_project.png => build-clion-reload-cmake-project.png} (100%) rename docpages/images/{delorean_time_travel.gif => delorean-time-travel.gif} (100%) diff --git a/docpages/advanced_reference/lambdas_and_locals.md b/docpages/advanced_reference/lambdas_and_locals.md index 74b1ae6364..ea41394066 100644 --- a/docpages/advanced_reference/lambdas_and_locals.md +++ b/docpages/advanced_reference/lambdas_and_locals.md @@ -4,7 +4,7 @@ If you are reading this page, you have likely been sent here by someone helping It is important to remember that when you put a lambda callback onto a function in D++, that this lambda will execute at some point in the **future**. As with all things in the future and as 80s Sci-Fi movies will tell you, when you reach the future, things may well have changed! -\image html delorean_time_travel.gif +\image html delorean-time-travel.gif To explain this situation and how it causes issues, I'd like you to imagine the age-old magic trick, where a magician sets a fine table full of cutlery, pots, pans and wine. He indicates to the audience that this is authentic, then with a whip of his wrist, he whips the tablecloth away, leaving the cutlery and other tableware in place (if he is any good as a magician!) diff --git a/docpages/images/build_clion_project_structure.png b/docpages/images/build-clion-project-structure.png similarity index 100% rename from docpages/images/build_clion_project_structure.png rename to docpages/images/build-clion-project-structure.png diff --git a/docpages/images/build_clion_reload_cmake_project.png b/docpages/images/build-clion-reload-cmake-project.png similarity index 100% rename from docpages/images/build_clion_reload_cmake_project.png rename to docpages/images/build-clion-reload-cmake-project.png diff --git a/docpages/images/delorean_time_travel.gif b/docpages/images/delorean-time-travel.gif similarity index 100% rename from docpages/images/delorean_time_travel.gif rename to docpages/images/delorean-time-travel.gif diff --git a/docpages/make_a_bot/clion.md b/docpages/make_a_bot/clion.md index 786188d230..6aadb74a2d 100644 --- a/docpages/make_a_bot/clion.md +++ b/docpages/make_a_bot/clion.md @@ -25,7 +25,7 @@ In the `libs/` directory, clone D++ with: `git clone https://github.com/brainbox Your project directory should look like this: -\image html build_clion_project_structure.png +\image html build-clion-project-structure.png ### Configure CMake file @@ -69,7 +69,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES Then open the "File" menu and click on "Reload CMake Project" to reload the CMake configuration. -\image html build_clion_reload_cmake_project.png +\image html build-clion-reload-cmake-project.png ### Add an example program From b859d8216a5130e26e31b87e4a86f73f2666a222 Mon Sep 17 00:00:00 2001 From: professor91 Date: Tue, 19 Sep 2023 19:29:03 +0530 Subject: [PATCH 6/7] new line at EOF and moved note --- docpages/example_programs/the_basics/using_cache.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docpages/example_programs/the_basics/using_cache.md b/docpages/example_programs/the_basics/using_cache.md index 8b578720f1..b1f2b2654f 100644 --- a/docpages/example_programs/the_basics/using_cache.md +++ b/docpages/example_programs/the_basics/using_cache.md @@ -2,10 +2,10 @@ Sometimes you may need information that is not directly available in the event callback object. -@note As of August 30th, 2022, Discord made Guild Members a privileged intent. You must have GUILD_MEMBERS intent enabled for your app from discord developers portal to be able to look for members in cache. - To handle this DPP maintains a cache of commonly used data for you. +@note As of August 30th, 2022, Discord made Guild Members a privileged intent. You must have GUILD_MEMBERS intent enabled for your app from discord developers portal to be able to look for members in cache. + Below is an example showing how to get a user from the cache \include{cpp} using_cache.cpp @@ -15,4 +15,4 @@ DPP caches more than just users, which you can get using the below-mentioned fun - `dpp::find_channel()` - `dpp::find_emoji()` - `dpp::find_guild()` -- `dpp::find_guild_member()` \ No newline at end of file +- `dpp::find_guild_member()` From d56f74a6e7d53bf677db42ead1a1e9a69978e24f Mon Sep 17 00:00:00 2001 From: professor91 Date: Wed, 20 Sep 2023 09:35:54 +0530 Subject: [PATCH 7/7] revert filename changes --- .../{automating_with_jenkins.md => automating-with-jenkins.md} | 0 .../advanced_reference/{separate_events.md => separate-events.md} | 0 .../{detecting_messages.md => detecting-messages.md} | 0 .../{private_messaging.md => private-messaging.md} | 0 .../{user_only_messages.md => user-only-messages.md} | 0 ...cking_member_permissions.md => checking-member-permissions.md} | 0 ..._channels_and_messages.md => editing-channels-and-messages.md} | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename docpages/advanced_reference/{automating_with_jenkins.md => automating-with-jenkins.md} (100%) rename docpages/advanced_reference/{separate_events.md => separate-events.md} (100%) rename docpages/example_programs/interactions_and_components/{detecting_messages.md => detecting-messages.md} (100%) rename docpages/example_programs/interactions_and_components/{private_messaging.md => private-messaging.md} (100%) rename docpages/example_programs/interactions_and_components/{user_only_messages.md => user-only-messages.md} (100%) rename docpages/example_programs/misc/{checking_member_permissions.md => checking-member-permissions.md} (100%) rename docpages/example_programs/the_basics/{editing_channels_and_messages.md => editing-channels-and-messages.md} (100%) diff --git a/docpages/advanced_reference/automating_with_jenkins.md b/docpages/advanced_reference/automating-with-jenkins.md similarity index 100% rename from docpages/advanced_reference/automating_with_jenkins.md rename to docpages/advanced_reference/automating-with-jenkins.md diff --git a/docpages/advanced_reference/separate_events.md b/docpages/advanced_reference/separate-events.md similarity index 100% rename from docpages/advanced_reference/separate_events.md rename to docpages/advanced_reference/separate-events.md diff --git a/docpages/example_programs/interactions_and_components/detecting_messages.md b/docpages/example_programs/interactions_and_components/detecting-messages.md similarity index 100% rename from docpages/example_programs/interactions_and_components/detecting_messages.md rename to docpages/example_programs/interactions_and_components/detecting-messages.md diff --git a/docpages/example_programs/interactions_and_components/private_messaging.md b/docpages/example_programs/interactions_and_components/private-messaging.md similarity index 100% rename from docpages/example_programs/interactions_and_components/private_messaging.md rename to docpages/example_programs/interactions_and_components/private-messaging.md diff --git a/docpages/example_programs/interactions_and_components/user_only_messages.md b/docpages/example_programs/interactions_and_components/user-only-messages.md similarity index 100% rename from docpages/example_programs/interactions_and_components/user_only_messages.md rename to docpages/example_programs/interactions_and_components/user-only-messages.md diff --git a/docpages/example_programs/misc/checking_member_permissions.md b/docpages/example_programs/misc/checking-member-permissions.md similarity index 100% rename from docpages/example_programs/misc/checking_member_permissions.md rename to docpages/example_programs/misc/checking-member-permissions.md diff --git a/docpages/example_programs/the_basics/editing_channels_and_messages.md b/docpages/example_programs/the_basics/editing-channels-and-messages.md similarity index 100% rename from docpages/example_programs/the_basics/editing_channels_and_messages.md rename to docpages/example_programs/the_basics/editing-channels-and-messages.md