basic pomelo support
This commit is contained in:
@@ -438,6 +438,7 @@ void Store::SetUser(Snowflake id, const UserData &user) {
|
||||
s->Bind(7, user.IsMFAEnabled);
|
||||
s->Bind(8, user.PremiumType);
|
||||
s->Bind(9, user.PublicFlags);
|
||||
s->Bind(10, user.GlobalName);
|
||||
|
||||
if (!s->Insert())
|
||||
fprintf(stderr, "user insert failed for %" PRIu64 ": %s\n", static_cast<uint64_t>(id), m_db.ErrStr());
|
||||
@@ -1109,6 +1110,7 @@ std::optional<UserData> Store::GetUser(Snowflake id) const {
|
||||
s->Get(6, r.IsMFAEnabled);
|
||||
s->Get(7, r.PremiumType);
|
||||
s->Get(8, r.PublicFlags);
|
||||
s->Get(9, r.GlobalName);
|
||||
|
||||
s->Reset();
|
||||
|
||||
@@ -1233,7 +1235,8 @@ bool Store::CreateTables() {
|
||||
system BOOL,
|
||||
mfa BOOL,
|
||||
premium INTEGER,
|
||||
pubflags INTEGER
|
||||
pubflags INTEGER,
|
||||
global_name TEXT
|
||||
)
|
||||
)";
|
||||
|
||||
@@ -1797,7 +1800,7 @@ bool Store::CreateStatements() {
|
||||
|
||||
m_stmt_set_user = std::make_unique<Statement>(m_db, R"(
|
||||
REPLACE INTO users VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
)
|
||||
)");
|
||||
if (!m_stmt_set_user->OK()) {
|
||||
|
@@ -1,5 +1,9 @@
|
||||
#include "user.hpp"
|
||||
|
||||
bool UserData::IsPomelo() const noexcept {
|
||||
return Discriminator.size() == 1 && Discriminator[0] == '0';
|
||||
}
|
||||
|
||||
bool UserData::IsABot() const noexcept {
|
||||
return IsBot.has_value() && *IsBot;
|
||||
}
|
||||
@@ -18,49 +22,54 @@ bool UserData::HasAnimatedAvatar() const noexcept {
|
||||
|
||||
bool UserData::HasAnimatedAvatar(Snowflake guild_id) const {
|
||||
const auto member = Abaddon::Get().GetDiscordClient().GetMember(ID, guild_id);
|
||||
if (member.has_value() && member->Avatar.has_value() && member->Avatar.value()[0] == 'a' && member->Avatar.value()[1] == '_')
|
||||
if (member.has_value() && member->Avatar.has_value() && member->Avatar.value()[0] == 'a' && member->Avatar.value()[1] == '_') {
|
||||
return true;
|
||||
else if (member.has_value() && !member->Avatar.has_value())
|
||||
} else if (member.has_value() && !member->Avatar.has_value()) {
|
||||
return HasAnimatedAvatar();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UserData::HasAnimatedAvatar(const std::optional<Snowflake> &guild_id) const {
|
||||
if (guild_id.has_value())
|
||||
if (guild_id.has_value()) {
|
||||
return HasAnimatedAvatar(*guild_id);
|
||||
else
|
||||
return HasAnimatedAvatar();
|
||||
}
|
||||
|
||||
return HasAnimatedAvatar();
|
||||
}
|
||||
|
||||
std::string UserData::GetAvatarURL(Snowflake guild_id, const std::string &ext, std::string size) const {
|
||||
const auto member = Abaddon::Get().GetDiscordClient().GetMember(ID, guild_id);
|
||||
if (member.has_value() && member->Avatar.has_value()) {
|
||||
if (ext == "gif" && !(member->Avatar.value()[0] == 'a' && member->Avatar.value()[1] == '_'))
|
||||
if (ext == "gif" && !(member->Avatar.value()[0] == 'a' && member->Avatar.value()[1] == '_')) {
|
||||
return GetAvatarURL(ext, size);
|
||||
}
|
||||
return "https://cdn.discordapp.com/guilds/" +
|
||||
std::to_string(guild_id) + "/users/" + std::to_string(ID) +
|
||||
"/avatars/" + *member->Avatar + "." +
|
||||
ext + "?" + "size=" + size;
|
||||
} else {
|
||||
return GetAvatarURL(ext, size);
|
||||
}
|
||||
return GetAvatarURL(ext, size);
|
||||
}
|
||||
|
||||
std::string UserData::GetAvatarURL(const std::optional<Snowflake> &guild_id, const std::string &ext, std::string size) const {
|
||||
if (guild_id.has_value())
|
||||
if (guild_id.has_value()) {
|
||||
return GetAvatarURL(*guild_id, ext, size);
|
||||
else
|
||||
return GetAvatarURL(ext, size);
|
||||
}
|
||||
return GetAvatarURL(ext, size);
|
||||
}
|
||||
|
||||
std::string UserData::GetAvatarURL(const std::string &ext, std::string size) const {
|
||||
if (HasAvatar())
|
||||
if (HasAvatar()) {
|
||||
return "https://cdn.discordapp.com/avatars/" + std::to_string(ID) + "/" + Avatar + "." + ext + "?size=" + size;
|
||||
else
|
||||
return GetDefaultAvatarURL();
|
||||
}
|
||||
return GetDefaultAvatarURL();
|
||||
}
|
||||
|
||||
std::string UserData::GetDefaultAvatarURL() const {
|
||||
if (IsPomelo()) {
|
||||
return "https://cdn.discordapp.com/embed/avatars/" + std::to_string((static_cast<uint64_t>(ID) >> 22) % 6) + ".png";
|
||||
}
|
||||
return "https://cdn.discordapp.com/embed/avatars/" + std::to_string(std::stoul(Discriminator) % 5) + ".png"; // size isn't respected by the cdn
|
||||
}
|
||||
|
||||
@@ -72,16 +81,27 @@ std::string UserData::GetMention() const {
|
||||
return "<@" + std::to_string(ID) + ">";
|
||||
}
|
||||
|
||||
std::string UserData::GetName() const {
|
||||
if (IsPomelo() && GlobalName.has_value()) {
|
||||
return *GlobalName;
|
||||
}
|
||||
|
||||
return Username;
|
||||
}
|
||||
|
||||
std::string UserData::GetEscapedName() const {
|
||||
return Glib::Markup::escape_text(Username);
|
||||
return Glib::Markup::escape_text(GetName());
|
||||
}
|
||||
|
||||
std::string UserData::GetEscapedBoldName() const {
|
||||
return "<b>" + Glib::Markup::escape_text(Username) + "</b>";
|
||||
return "<b>" + Glib::Markup::escape_text(GetName()) + "</b>";
|
||||
}
|
||||
|
||||
std::string UserData::GetEscapedString() const {
|
||||
return Glib::Markup::escape_text(Username) + "#" + Discriminator;
|
||||
if (IsPomelo()) {
|
||||
return GetEscapedName();
|
||||
}
|
||||
return Glib::Markup::escape_text(GetName()) + "#" + Discriminator;
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json &j, UserData &m) {
|
||||
@@ -104,6 +124,7 @@ void from_json(const nlohmann::json &j, UserData &m) {
|
||||
JS_ON("phone", m.Phone);
|
||||
JS_ON("bio", m.Bio);
|
||||
JS_ON("banner", m.BannerHash);
|
||||
JS_N("global_name", m.GlobalName);
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json &j, const UserData &m) {
|
||||
@@ -127,6 +148,7 @@ void to_json(nlohmann::json &j, const UserData &m) {
|
||||
JS_IF("mobile", m.IsMobile);
|
||||
JS_IF("nsfw_allowed", m.IsNSFWAllowed);
|
||||
JS_IF("phone", m.Phone);
|
||||
JS_IF("global_name", m.GlobalName);
|
||||
}
|
||||
|
||||
void UserData::update_from_json(const nlohmann::json &j) {
|
||||
@@ -146,6 +168,7 @@ void UserData::update_from_json(const nlohmann::json &j) {
|
||||
JS_RD("mobile", IsMobile);
|
||||
JS_RD("nsfw_allowed", IsNSFWAllowed);
|
||||
JS_RD("phone", Phone);
|
||||
JS_RD("global_name", GlobalName);
|
||||
}
|
||||
|
||||
const char *UserData::GetFlagName(uint64_t flag) {
|
||||
|
@@ -25,6 +25,11 @@ struct UserData {
|
||||
VerifiedBot = 1 << 16,
|
||||
EarlyVerifiedBotDeveloper = 1 << 17,
|
||||
CertifiedModerator = 1 << 18,
|
||||
BotHTTPInteractions = 1 << 19,
|
||||
Spammer = 1 << 20,
|
||||
DisablePremium = 1 << 21,
|
||||
ActiveDeveloper = 1 << 22,
|
||||
Quarantined = 1ULL << 44,
|
||||
|
||||
MaxFlag_PlusOne,
|
||||
MaxFlag = MaxFlag_PlusOne - 1,
|
||||
@@ -37,6 +42,7 @@ struct UserData {
|
||||
std::string Username;
|
||||
std::string Discriminator;
|
||||
std::string Avatar; // null
|
||||
std::optional<std::string> GlobalName;
|
||||
std::optional<bool> IsBot;
|
||||
std::optional<bool> IsSystem;
|
||||
std::optional<bool> IsMFAEnabled;
|
||||
@@ -60,6 +66,7 @@ struct UserData {
|
||||
friend void to_json(nlohmann::json &j, const UserData &m);
|
||||
void update_from_json(const nlohmann::json &j);
|
||||
|
||||
[[nodiscard]] bool IsPomelo() const noexcept;
|
||||
[[nodiscard]] bool IsABot() const noexcept;
|
||||
[[nodiscard]] bool IsDeleted() const;
|
||||
[[nodiscard]] bool HasAvatar() const;
|
||||
@@ -72,6 +79,7 @@ struct UserData {
|
||||
[[nodiscard]] std::string GetDefaultAvatarURL() const;
|
||||
[[nodiscard]] Snowflake GetHoistedRole(Snowflake guild_id, bool with_color = false) const;
|
||||
[[nodiscard]] std::string GetMention() const;
|
||||
[[nodiscard]] std::string GetName() const;
|
||||
[[nodiscard]] std::string GetEscapedName() const;
|
||||
[[nodiscard]] std::string GetEscapedBoldName() const;
|
||||
[[nodiscard]] std::string GetEscapedString() const;
|
||||
|
Reference in New Issue
Block a user