-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
acfd7e4
commit af6ce15
Showing
9 changed files
with
185 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <dpp/dpp.h> | ||
#include <sstream> | ||
|
||
int main() { | ||
/* Create bot */ | ||
dpp::cluster bot("token", dpp::i_default_intents | dpp::i_message_content); /* Because we're handling messages, we need to use the "i_message_content" intent! */ | ||
|
||
/* Create a cache to contain types of dpp::message */ | ||
dpp::cache<dpp::message> message_cache; | ||
|
||
bot.on_log(dpp::utility::cout_logger()); | ||
|
||
/* Message handler */ | ||
bot.on_message_create([&](const dpp::message_create_t &event) { | ||
/* Make a permanent pointer using new, for each message to be cached */ | ||
dpp::message* m = new dpp::message(); | ||
|
||
/* Store the message into the pointer by copying it */ | ||
*m = event.msg; | ||
|
||
/* Store the new pointer to the cache using the store() method */ | ||
message_cache.store(m); | ||
}); | ||
|
||
/* The event is fired when someone issues your commands */ | ||
bot.on_slashcommand([&bot, &message_cache](const dpp::slashcommand_t& event) { | ||
/* Check which command they ran */ | ||
if (event.command.get_command_name() == "get") { | ||
|
||
dpp::message* find_msg = message_cache.find(std::get<std::string>(event.get_parameter("message_id"))); | ||
|
||
/* If find_msg is null, tell the user and return. */ | ||
if (!find_msg) { | ||
event.reply("There is no message cached with this ID"); | ||
return; | ||
} | ||
|
||
event.reply("This message had the following content: " + find_msg->content); | ||
} | ||
}); | ||
|
||
bot.on_ready([&bot](const dpp::ready_t& event) { | ||
if (dpp::run_once<struct register_bot_commands>()) { | ||
|
||
/* Create a new command. */ | ||
dpp::slashcommand newcommand("get", "Get the contents of a message that was cached via an id", bot.me.id); | ||
|
||
/* Add a parameter option. */ | ||
newcommand.add_option(dpp::command_option(dpp::co_string, "message_id", "The ID of the message you want to find", true)); | ||
|
||
/* Register the command */ | ||
bot.global_command_create(newcommand); | ||
} | ||
}); | ||
|
||
/* Start bot */ | ||
bot.start(dpp::st_wait); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <dpp/dpp.h> | ||
|
||
/* To create a collector we must derive from dpp::collector. As dpp::collector is a complicated template, | ||
* various pre-made forms exist such as this one, reaction_collector. | ||
*/ | ||
class react_collector : public dpp::reaction_collector { | ||
public: | ||
/* Collector will run for 20 seconds */ | ||
react_collector(dpp::cluster* cl, dpp::snowflake id) : dpp::reaction_collector(cl, 20, id) { } | ||
|
||
/* Override the "completed" event and then output the number of collected reactions as a message. */ | ||
virtual void completed(const std::vector<dpp::collected_reaction>& list) override { | ||
if (list.size()) { | ||
owner->message_create(dpp::message(list[0].react_channel->id, "I collected " + std::to_string(list.size()) + " reactions!")); | ||
} else { | ||
owner->message_create(dpp::message("... I got nothin'.")); | ||
} | ||
} | ||
}; | ||
|
||
|
||
int main() { | ||
/* Create bot */ | ||
dpp::cluster bot("token", dpp::i_default_intents | dpp::i_message_content); | ||
|
||
/* Pointer to reaction collector */ | ||
react_collector* r = nullptr; | ||
|
||
bot.on_log(dpp::utility::cout_logger()); | ||
|
||
/* Message handler */ | ||
bot.on_message_create([&r, &bot](const dpp::message_create_t& event) { | ||
|
||
/* If someone sends a message that has the text 'collect reactions!' start a reaction collector */ | ||
if (event.msg.content == "collect reactions!" && r == nullptr) { | ||
/* Create a new reaction collector to collect reactions */ | ||
r = new react_collector(&bot, event.msg.id); | ||
} | ||
|
||
}); | ||
|
||
/* Start bot */ | ||
bot.start(dpp::st_wait); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <dpp/dpp.h> | ||
#include <iostream> | ||
|
||
int main() { | ||
dpp::cluster bot("TOKEN GOES HERE"); | ||
|
||
bot.on_log(dpp::utility::cout_logger()); | ||
|
||
bot.on_ready([&bot](const dpp::ready_t& event) { | ||
// Arbitrary post data as a string | ||
std::string mypostdata = "{\"value\": 42}"; | ||
// Make a HTTP POST request. HTTP and HTTPS are supported here. | ||
bot.request( | ||
"http://www.somebotlist.com/api/servers", dpp::m_post, [](const dpp::http_request_completion_t & cc) { | ||
// This callback is called when the HTTP request completes. See documentation of | ||
// dpp::http_request_completion_t for information on the fields in the parameter. | ||
std::cout << "I got reply: " << cc.body << " with HTTP status code: " << cc.status << "\n"; | ||
}, | ||
mypostdata, | ||
"application/json", | ||
{ | ||
{"Authorization", "Bearer tokengoeshere"} | ||
} | ||
); | ||
}); | ||
|
||
bot.start(dpp::st_wait); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <dpp/dpp.h> | ||
|
||
int main() | ||
{ | ||
/* Create the bot */ | ||
dpp::cluster bot("token"); | ||
|
||
bot.on_log(dpp::utility::cout_logger()); | ||
|
||
bot.on_ready([&bot](const dpp::ready_t& event) { | ||
/* We don't need the run_once here as we're not registering commands! */ | ||
|
||
/* Set the bot presence as online and "Playing..."! */ | ||
bot.set_presence(dpp::presence(dpp::ps_online, dpp::at_game, "games!")); | ||
}); | ||
|
||
bot.start(dpp::st_wait); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <dpp/dpp.h> | ||
|
||
int main() | ||
{ | ||
/* Create the bot */ | ||
dpp::cluster bot("token"); | ||
|
||
bot.on_log(dpp::utility::cout_logger()); | ||
|
||
bot.on_ready([&bot](const dpp::ready_t& event) { | ||
/* We put our status updating inside "run_once" so that multiple shards don't try do this as "set_presence" updates all the shards. */ | ||
if (dpp::run_once<struct register_bot_commands>()) { | ||
/* We update the presence now as the timer will do the first execution after the x amount of seconds we specify */ | ||
bot.set_presence(dpp::presence(dpp::presence_status::ps_online, dpp::activity_type::at_game, "with " + std::to_string(dpp::get_guild_cache()->count()) + " guilds!")); | ||
|
||
/* Create a timer that runs every 120 seconds, that sets the status */ | ||
bot.start_timer([&bot](const dpp::timer& timer) { | ||
bot.set_presence(dpp::presence(dpp::presence_status::ps_online, dpp::activity_type::at_game, "with " + std::to_string(dpp::get_guild_cache()->count()) + " guilds!")); | ||
}, 120); | ||
} | ||
}); | ||
|
||
bot.start(dpp::st_wait); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.