From ab8b0353cf7705d90d06407c60306d5f4ad5e2c6 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Thu, 14 Sep 2023 18:11:24 -0400 Subject: [PATCH] making basic instance methods to get urls --- include/dpp/channel.h | 7 +++++++ include/dpp/message.h | 7 +++++++ include/dpp/user.h | 7 +++++++ src/dpp/channel.cpp | 4 ++++ src/dpp/message.cpp | 4 ++++ src/dpp/user.cpp | 4 ++++ 6 files changed, 33 insertions(+) diff --git a/include/dpp/channel.h b/include/dpp/channel.h index d14037bc0d..afa09823d9 100644 --- a/include/dpp/channel.h +++ b/include/dpp/channel.h @@ -609,6 +609,13 @@ class DPP_EXPORT channel : public managed, public json_interface { */ std::string get_icon_url(uint16_t size = 0, const image_type format = i_png) const; + /** + * @brief Returns string of URL to channel + * + * @return string of URL to channel + */ + std::string get_url() const; + /** * @brief Returns true if the channel is NSFW gated * diff --git a/include/dpp/message.h b/include/dpp/message.h index ed7137eeeb..422722fb0c 100644 --- a/include/dpp/message.h +++ b/include/dpp/message.h @@ -1555,6 +1555,13 @@ struct DPP_EXPORT message : public managed { * @return true if message has remixed attachment */ bool has_remix_attachment() const; + + /** + * @brief Returns URL to message + * + * @return string of URL to message + */ + std::string get_url() const; }; /** A group of messages */ diff --git a/include/dpp/user.h b/include/dpp/user.h index 4595c8e9c8..71c0978e7e 100644 --- a/include/dpp/user.h +++ b/include/dpp/user.h @@ -164,6 +164,13 @@ class DPP_EXPORT user : public managed, public json_interface { */ std::string get_mention() const; + /** + * @brief Returns URL to user + * + * @return string of URL to user + */ + std::string get_url() const; + /** * @brief Return true if user has the active Developer badge * diff --git a/src/dpp/channel.cpp b/src/dpp/channel.cpp index 021428d17e..b95d0fdb60 100644 --- a/src/dpp/channel.cpp +++ b/src/dpp/channel.cpp @@ -636,6 +636,10 @@ 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); +} + channel_type channel::get_type() const { return static_cast(flags & CHANNEL_TYPE_MASK); } diff --git a/src/dpp/message.cpp b/src/dpp/message.cpp index e1fb150570..dafaf019eb 100644 --- a/src/dpp/message.cpp +++ b/src/dpp/message.cpp @@ -1126,6 +1126,10 @@ 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); +} + 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 05a7726b44..cd9ee099eb 100644 --- a/src/dpp/user.cpp +++ b/src/dpp/user.cpp @@ -130,6 +130,10 @@ std::string user::get_mention() const { return utility::user_mention(id); } +std::string user::get_url() const{ + return "https://discord.com/users/" + std::to_string(id); +} + bool user::is_active_developer() const { return this->flags & u_active_developer; }