Skip to content

Commit

Permalink
moving url methods to utility and changing class methods to work with…
Browse files Browse the repository at this point in the history
… them
  • Loading branch information
ruslan-ilesik committed Sep 14, 2023
1 parent ab8b035 commit 8c92ef1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
34 changes: 34 additions & 0 deletions include/dpp/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,40 @@ namespace dpp {
*/
std::string DPP_EXPORT role_mention(const snowflake& id);

/**
* @brief Create a URL for message.
* @param guild_id The ID of the guild where message is written.
* @param channel_id The ID of the channel where message is written.
* @param message_id The ID of the message.
* @return std::string The URL to message.
*/
std::string DPP_EXPORT message_url(const snowflake& guild_id, const snowflake& channel_id, const snowflake& message_id);

/**
* @brief Create a URL for message.
* @param guild_id The ID of the guild where channel is located.
* @param channel_id The ID of the channel.
* @return std::string The URL to message.
*/
std::string DPP_EXPORT channel_url(const snowflake& guild_id, const snowflake& channel_id);

/**
* @brief Create a URL for message.
* @param guild_id The ID of the guild where thread is located.
* @param thread_id The ID of the thread.
* @return std::string The URL to message.
*/
std::string DPP_EXPORT thread_url(const snowflake& guild_id, const snowflake& thread_id);

/**
* @brief Create a URL for message.
* @param user_id The ID of the guild where thread is located.
* @return std::string The URL to message.
*/
std::string DPP_EXPORT user_url(const snowflake& user_id);



#ifdef _DOXYGEN_
/**
* @brief Get the mime type for an image type.
Expand Down
2 changes: 1 addition & 1 deletion src/dpp/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ std::string channel::get_icon_url(uint16_t size, const image_type format) const
}

std::string channel::get_url() const{
return "https://discord.com/channels/" + std::to_string(guild_id) + "/" + std::to_string(id);
return utility::channel_url(guild_id, id);
}

channel_type channel::get_type() const {
Expand Down
2 changes: 1 addition & 1 deletion src/dpp/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ bool message::has_remix_attachment() const {
}

std::string message::get_url() const {
return "https://discord.com/channels/" + std::to_string(guild_id) + "/" + std::to_string(channel_id) + "/" + std::to_string(id);
return utility::message_url(guild_id, channel_id, id);
}

sticker::sticker() : managed(0), pack_id(0), type(st_standard), format_type(sf_png), available(true), guild_id(0), sort_value(0) {
Expand Down
2 changes: 1 addition & 1 deletion src/dpp/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ std::string user::get_mention() const {
}

std::string user::get_url() const{
return "https://discord.com/users/" + std::to_string(id);
return utility::user_url(id);
}

bool user::is_active_developer() const {
Expand Down
16 changes: 16 additions & 0 deletions src/dpp/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,22 @@ namespace dpp {
return "<@&" + std::to_string(id) + ">";
}

std::string message_url(const snowflake& guild_id, const snowflake& channel_id, const snowflake& message_id){
return "https://discord.com/channels/" + std::to_string(guild_id) + "/" + std::to_string(channel_id) + "/" + std::to_string(message_id);
}

std::string channel_url(const snowflake& guild_id, const snowflake& channel_id){
return "https://discord.com/channels/" + std::to_string(guild_id) + "/" + std::to_string(channel_id);
}

std::string thread_url(const snowflake& guild_id, const snowflake& thread_id){
return channel_url(guild_id, thread_id);
};

std::string user_url(const snowflake& user_id){
return "https://discord.com/users/" + std::to_string(user_id);
};

template <typename T>
std::enable_if_t<std::is_same_v<T, image_type>, std::string> mime_type(T type) {
static constexpr auto get_image_mime = [](image_type t) constexpr noexcept {
Expand Down

0 comments on commit 8c92ef1

Please sign in to comment.