Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added dpp::utility::guild_navigation helper #810

Merged
merged 14 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -3302,7 +3302,7 @@ class DPP_EXPORT cluster {
void guild_stickers_get(snowflake guild_id, command_completion_event_t callback);

/**
* @brief Get sticker packs
* @brief Get a list of available sticker packs
* @see https://discord.com/developers/docs/resources/sticker#list-nitro-sticker-packs
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::sticker_pack_map object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
Expand Down
2 changes: 1 addition & 1 deletion include/dpp/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ struct DPP_EXPORT attachment {
* @brief Represents the type of a sticker
*/
enum sticker_type : uint8_t {
/// Nitro pack sticker
/// An official sticker in a pack
st_standard = 1,
/// Guild sticker
st_guild = 2
Expand Down
23 changes: 22 additions & 1 deletion include/dpp/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ namespace dpp {
tf_short_time = 't',
};

/**
* @brief Guild navigation types for dpp::utility::guild_navigation()
*/
enum guild_navigation_type {
/// _Customize_ tab with the server's dpp::onboarding_prompt
gnt_customize,
/// _Browse Channels_ tab
gnt_browse,
/// Server Guide
gnt_guide,
};

/**
* @brief The base URL for CDN content such as profile pictures and guild icons.
*/
Expand Down Expand Up @@ -147,6 +159,15 @@ namespace dpp {
*/
std::string DPP_EXPORT timestamp(time_t ts, time_format tf = tf_short_datetime);

/**
* @brief Create a mentionable guild navigation (used in a message).
*
* @param guild_id The guild ID
* @param gnt Guild navigation type using dpp::utility::guild_navigation_type
* @return std::string The formatted timestamp
*/
std::string DPP_EXPORT guild_navigation(const snowflake guild_id, guild_navigation_type gnt);

/**
* @brief Returns current date and time
*
Expand Down Expand Up @@ -479,7 +500,7 @@ namespace dpp {
*/
std::string DPP_EXPORT slashcommand_mention(snowflake command_id, const std::string &command_name, const std::string &subcommand_group, const std::string &subcommand);

/**
/**
* @brief Create a mentionable user.
* @param id The ID of the user.
* @return std::string The formatted mention of the user.
Expand Down
18 changes: 18 additions & 0 deletions src/dpp/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,24 @@ namespace dpp {
return "<t:" + std::to_string(ts) + ":" + format + ">";
}

std::string guild_navigation(const snowflake guild_id, guild_navigation_type gnt) {
std::string type;
switch (gnt) {
case gnt_customize:
type = "customize";
break;
case gnt_browse:
type = "browse";
break;
case gnt_guide:
type = "guide";
break;
default:
return "";
}
return "<" + std::to_string(guild_id) + ":" + type + ">";
}

std::string avatar_size(uint32_t size) {
if (size) {
if ( (size & (size - 1)) != 0 ) { // check if the size is a power of 2
Expand Down
6 changes: 6 additions & 0 deletions src/unittest/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,12 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
}

{ // utility methods
set_test(UTILITY_GUILD_NAVIGATION, false);
auto gn1 = dpp::utility::guild_navigation(123, dpp::utility::gnt_customize);
auto gn2 = dpp::utility::guild_navigation(1234, dpp::utility::gnt_browse);
auto gn3 = dpp::utility::guild_navigation(12345, dpp::utility::gnt_guide);
set_test(UTILITY_GUILD_NAVIGATION, gn1 == "<123:customize>" && gn2 == "<1234:browse>" && gn3 == "<12345:guide>");

set_test(UTILITY_ICONHASH, false);
auto iconhash1 = dpp::utility::iconhash("a_5532c6414c70765a28cf9448c117205f");
set_test(UTILITY_ICONHASH, iconhash1.first == 6139187225817019994 &&
Expand Down
1 change: 1 addition & 0 deletions src/unittest/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ DPP_TEST(USER_GET_CREATION_TIME, "user::get_creation_time", tf_offline);
DPP_TEST(USER_GET_AVATAR_URL, "user::get_avatar_url", tf_offline);
DPP_TEST(CHANNEL_SET_TYPE, "channel::set_type", tf_offline);
DPP_TEST(CHANNEL_GET_MENTION, "channel::get_mention", tf_offline);
DPP_TEST(UTILITY_GUILD_NAVIGATION, "utility::guild_navigation", tf_offline);
DPP_TEST(UTILITY_ICONHASH, "utility::iconhash", tf_offline);
DPP_TEST(UTILITY_MAKE_URL_PARAMETERS, "utility::make_url_parameters", tf_offline);
DPP_TEST(UTILITY_MARKDOWN_ESCAPE, "utility::markdown_escape", tf_offline);
Expand Down