From 8c92ef19e695011547d6db75285da0c9a3721529 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Thu, 14 Sep 2023 18:29:09 -0400 Subject: [PATCH] moving url methods to utility and changing class methods to work with them --- include/dpp/utility.h | 34 ++++++++++++++++++++++++++++++++++ src/dpp/channel.cpp | 2 +- src/dpp/message.cpp | 2 +- src/dpp/user.cpp | 2 +- src/dpp/utility.cpp | 16 ++++++++++++++++ 5 files changed, 53 insertions(+), 3 deletions(-) diff --git a/include/dpp/utility.h b/include/dpp/utility.h index 59093a9099..150860122b 100644 --- a/include/dpp/utility.h +++ b/include/dpp/utility.h @@ -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. diff --git a/src/dpp/channel.cpp b/src/dpp/channel.cpp index b95d0fdb60..ddbdc35dd8 100644 --- a/src/dpp/channel.cpp +++ b/src/dpp/channel.cpp @@ -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 { diff --git a/src/dpp/message.cpp b/src/dpp/message.cpp index dafaf019eb..9e08c62d8d 100644 --- a/src/dpp/message.cpp +++ b/src/dpp/message.cpp @@ -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) { diff --git a/src/dpp/user.cpp b/src/dpp/user.cpp index cd9ee099eb..d40b5eb401 100644 --- a/src/dpp/user.cpp +++ b/src/dpp/user.cpp @@ -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 { diff --git a/src/dpp/utility.cpp b/src/dpp/utility.cpp index 657a034d4d..7f08112373 100644 --- a/src/dpp/utility.cpp +++ b/src/dpp/utility.cpp @@ -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 std::enable_if_t, std::string> mime_type(T type) { static constexpr auto get_image_mime = [](image_type t) constexpr noexcept {