forked from OpenGamers/abaddon
basic support of per-guild avatars
This commit is contained in:
parent
fe9642f1f1
commit
14d0968c92
@ -1086,7 +1086,7 @@ ChatMessageHeader::ChatMessageHeader(const Message *data) {
|
||||
m_static_avatar = pb->scale_simple(AvatarSize, AvatarSize, Gdk::INTERP_BILINEAR);
|
||||
m_avatar->property_pixbuf() = m_static_avatar;
|
||||
};
|
||||
img.LoadFromURL(author->GetAvatarURL(), sigc::track_obj(cb, *this));
|
||||
img.LoadFromURL(author->GetAvatarURL(data->GuildID), sigc::track_obj(cb, *this));
|
||||
|
||||
if (author->HasAnimatedAvatar()) {
|
||||
auto cb = [this](const Glib::RefPtr<Gdk::PixbufAnimation> &pb) {
|
||||
|
@ -26,7 +26,7 @@ MemberListUserRow::MemberListUserRow(const GuildData *guild, const UserData &dat
|
||||
|
||||
m_status_indicator->set_margin_start(3);
|
||||
|
||||
m_avatar->SetURL(data.GetAvatarURL("png"));
|
||||
m_avatar->SetURL(data.GetAvatarURL(guild->ID, "png"));
|
||||
|
||||
get_style_context()->add_class("members-row");
|
||||
get_style_context()->add_class("members-row-member");
|
||||
|
@ -10,6 +10,7 @@ void from_json(const nlohmann::json &j, GuildMember &m) {
|
||||
JS_D("deaf", m.IsDeafened);
|
||||
JS_D("mute", m.IsMuted);
|
||||
JS_O("user_id", m.UserID);
|
||||
JS_ON("avatar", m.Avatar);
|
||||
}
|
||||
|
||||
std::vector<RoleData> GuildMember::GetSortedRoles() const {
|
||||
@ -33,4 +34,5 @@ void GuildMember::update_from_json(const nlohmann::json &j) {
|
||||
JS_RD("nick", Nickname);
|
||||
JS_RD("joined_at", JoinedAt);
|
||||
JS_RD("premium_since", PremiumSince);
|
||||
JS_RD("avatar", Avatar);
|
||||
}
|
||||
|
@ -16,6 +16,9 @@ struct GuildMember {
|
||||
bool IsMuted;
|
||||
std::optional<Snowflake> UserID; // present in merged_members
|
||||
|
||||
// undocuemtned moment !!!1
|
||||
std::optional<std::string> Avatar;
|
||||
|
||||
std::vector<RoleData> GetSortedRoles() const;
|
||||
|
||||
void update_from_json(const nlohmann::json &j);
|
||||
|
@ -210,6 +210,7 @@ void Store::SetGuildMember(Snowflake guild_id, Snowflake user_id, const GuildMem
|
||||
Bind(m_set_member_stmt, 6, data.PremiumSince);
|
||||
Bind(m_set_member_stmt, 7, data.IsDeafened);
|
||||
Bind(m_set_member_stmt, 8, data.IsMuted);
|
||||
Bind(m_set_member_stmt, 9, data.Avatar);
|
||||
|
||||
if (!RunInsert(m_set_member_stmt))
|
||||
fprintf(stderr, "member insert failed: %s\n", sqlite3_errstr(m_db_err));
|
||||
@ -520,6 +521,7 @@ std::optional<GuildMember> Store::GetGuildMember(Snowflake guild_id, Snowflake u
|
||||
Get(m_get_member_stmt, 5, ret.PremiumSince);
|
||||
Get(m_get_member_stmt, 6, ret.IsDeafened);
|
||||
Get(m_get_member_stmt, 7, ret.IsMuted);
|
||||
Get(m_get_member_stmt, 8, ret.Avatar);
|
||||
|
||||
Reset(m_get_member_stmt);
|
||||
|
||||
@ -823,6 +825,7 @@ bool Store::CreateTables() {
|
||||
premium_since TEXT,
|
||||
deaf BOOL NOT NULL,
|
||||
mute BOOL NOT NULL,
|
||||
avatar TEXT,
|
||||
PRIMARY KEY(user_id, guild_id)
|
||||
)
|
||||
)";
|
||||
@ -1039,7 +1042,7 @@ bool Store::CreateStatements() {
|
||||
|
||||
constexpr const char *set_member = R"(
|
||||
REPLACE INTO members VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?, ?
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
)
|
||||
)";
|
||||
|
||||
|
@ -13,11 +13,33 @@ bool UserData::HasAnimatedAvatar() const {
|
||||
return Avatar.size() > 0 && Avatar[0] == 'a' && Avatar[1] == '_';
|
||||
}
|
||||
|
||||
std::string UserData::GetAvatarURL(Snowflake guild_id, 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())
|
||||
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);
|
||||
}
|
||||
|
||||
std::string UserData::GetAvatarURL(const std::optional<Snowflake> &guild_id, std::string ext, std::string size) const {
|
||||
if (guild_id.has_value())
|
||||
return GetAvatarURL(*guild_id, ext, size);
|
||||
else
|
||||
return GetAvatarURL(ext, size);
|
||||
}
|
||||
|
||||
std::string UserData::GetAvatarURL(std::string ext, std::string size) const {
|
||||
if (HasAvatar())
|
||||
return "https://cdn.discordapp.com/avatars/" + std::to_string(ID) + "/" + Avatar + "." + ext + "?size=" + size;
|
||||
else
|
||||
return "https://cdn.discordapp.com/embed/avatars/" + std::to_string(std::stoul(Discriminator) % 5) + ".png"; // size isn't respected by the cdn
|
||||
return GetDefaultAvatarURL();
|
||||
}
|
||||
|
||||
std::string UserData::GetDefaultAvatarURL() const {
|
||||
return "https://cdn.discordapp.com/embed/avatars/" + std::to_string(std::stoul(Discriminator) % 5) + ".png"; // size isn't respected by the cdn
|
||||
}
|
||||
|
||||
Snowflake UserData::GetHoistedRole(Snowflake guild_id, bool with_color) const {
|
||||
|
@ -63,7 +63,10 @@ struct UserData {
|
||||
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<Snowflake> &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;
|
||||
|
Loading…
Reference in New Issue
Block a user