From a51a54bc5979a2491f152abc47ad54e6b63f27c8 Mon Sep 17 00:00:00 2001 From: Dylam De La Torre Date: Tue, 23 Nov 2021 05:21:56 +0100 Subject: Restructure source and resource files (#46) importantly, res is now res/res and css is now res/css --- src/discord/user.hpp | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/discord/user.hpp (limited to 'src/discord/user.hpp') diff --git a/src/discord/user.hpp b/src/discord/user.hpp new file mode 100644 index 0000000..d4711fa --- /dev/null +++ b/src/discord/user.hpp @@ -0,0 +1,82 @@ +#pragma once +#include "snowflake.hpp" +#include "json.hpp" +#include + +enum class EPremiumType { + None = 0, + NitroClassic = 1, + Nitro = 2, +}; + +struct UserData { + enum { + DiscordEmployee = 1 << 0, + PartneredServerOwner = 1 << 1, + HypeSquadEvents = 1 << 2, + BugHunterLevel1 = 1 << 3, + HouseBravery = 1 << 6, + HouseBrilliance = 1 << 7, + HouseBalance = 1 << 8, + EarlySupporter = 1 << 9, + TeamUser = 1 << 10, // no idea what this is + System = 1 << 12, + BugHunterLevel2 = 1 << 14, + VerifiedBot = 1 << 16, + EarlyVerifiedBotDeveloper = 1 << 17, + CertifiedModerator = 1 << 18, + + MaxFlag_PlusOne, + MaxFlag = MaxFlag_PlusOne - 1, + }; + + static const char *GetFlagName(uint64_t flag); + static const char *GetFlagReadableName(uint64_t flag); + + Snowflake ID; + std::string Username; + std::string Discriminator; + std::string Avatar; // null + std::optional IsBot; + std::optional IsSystem; + std::optional IsMFAEnabled; + std::optional Locale; + std::optional IsVerified; + std::optional Email; // null + std::optional Flags; + std::optional PremiumType; // null + std::optional PublicFlags; + + // undocumented (opt) + std::optional IsDesktop; + std::optional IsMobile; + std::optional IsNSFWAllowed; // null + std::optional Phone; // null? + // for now (unserialized) + std::optional BannerHash; // null + std::optional Bio; // null + + friend void from_json(const nlohmann::json &j, UserData &m); + friend void to_json(nlohmann::json &j, const UserData &m); + void update_from_json(const nlohmann::json &j); + + bool IsDeleted() const; + bool HasAvatar() const; + bool HasAnimatedAvatar() const; + std::string GetAvatarURL(Snowflake guild_id, std::string ext = "png", std::string size = "32") const; + std::string GetAvatarURL(const std::optional &guild_id, std::string ext = "png", std::string size = "32") const; + std::string GetAvatarURL(std::string ext = "png", std::string size = "32") const; + std::string GetDefaultAvatarURL() const; + Snowflake GetHoistedRole(Snowflake guild_id, bool with_color = false) const; + std::string GetMention() const; + std::string GetEscapedName() const; + std::string GetEscapedBoldName() const; + std::string GetEscapedString() const; + template + inline std::string GetEscapedBoldString() const { + if constexpr (with_at) + return "@" + Glib::Markup::escape_text(Username) + "#" + Discriminator; + else + return "" + Glib::Markup::escape_text(Username) + "#" + Discriminator; + } +}; -- cgit v1.2.3