store emoji data
This commit is contained in:
@@ -175,6 +175,8 @@ add_executable(abaddon
|
||||
discord/invite.cpp
|
||||
discord/permissions.hpp
|
||||
discord/permissions.cpp
|
||||
discord/emoji.hpp
|
||||
discord/emoji.cpp
|
||||
windows/mainwindow.hpp
|
||||
windows/mainwindow.cpp
|
||||
)
|
||||
|
@@ -480,8 +480,7 @@ ChatMessageHeader::ChatMessageHeader(const Message *data) {
|
||||
m_extra->set_can_focus(false);
|
||||
m_extra->set_use_markup(true);
|
||||
m_extra->set_markup("<b>Webhook</b>");
|
||||
}
|
||||
else if (data->Author.IsBot) {
|
||||
} else if (data->Author.IsBot) {
|
||||
m_extra = Gtk::manage(new Gtk::Label);
|
||||
m_extra->get_style_context()->add_class("message-container-extra");
|
||||
m_extra->set_single_line_mode(true);
|
||||
|
@@ -5,7 +5,6 @@
|
||||
DiscordClient::DiscordClient()
|
||||
: m_http(DiscordAPI)
|
||||
, m_decompress_buf(InflateChunkSize) {
|
||||
|
||||
m_msg_dispatch.connect(sigc::mem_fun(*this, &DiscordClient::MessageDispatch));
|
||||
|
||||
LoadEventMap();
|
||||
@@ -206,6 +205,10 @@ const PermissionOverwrite *DiscordClient::GetPermissionOverwrite(Snowflake chann
|
||||
return m_store.GetPermissionOverwrite(channel_id, id);
|
||||
}
|
||||
|
||||
const Emoji *DiscordClient::GetEmoji(Snowflake id) const {
|
||||
return m_store.GetEmoji(id);
|
||||
}
|
||||
|
||||
Snowflake DiscordClient::GetMemberHoistedRole(Snowflake guild_id, Snowflake user_id, bool with_color) const {
|
||||
auto *data = m_store.GetGuildMemberData(guild_id, user_id);
|
||||
if (data == nullptr) return Snowflake::Invalid;
|
||||
@@ -504,6 +507,9 @@ void DiscordClient::ProcessNewGuild(Guild &guild) {
|
||||
|
||||
for (auto &r : guild.Roles)
|
||||
m_store.SetRole(r.ID, r);
|
||||
|
||||
for (auto &e : guild.Emojis)
|
||||
m_store.SetEmoji(e.ID, e);
|
||||
}
|
||||
|
||||
void DiscordClient::HandleGatewayReady(const GatewayMessage &msg) {
|
||||
|
@@ -82,6 +82,7 @@ public:
|
||||
const Guild *GetGuild(Snowflake id) const;
|
||||
const GuildMember *GetMember(Snowflake user_id, Snowflake guild_id) const;
|
||||
const PermissionOverwrite *GetPermissionOverwrite(Snowflake channel_id, Snowflake id) const;
|
||||
const Emoji *GetEmoji(Snowflake id) const;
|
||||
Snowflake GetMemberHoistedRole(Snowflake guild_id, Snowflake user_id, bool with_color = false) const;
|
||||
std::unordered_set<Snowflake> GetUsersInGuild(Snowflake id) const;
|
||||
std::unordered_set<Snowflake> GetRolesInGuild(Snowflake id) const;
|
||||
|
20
discord/emoji.cpp
Normal file
20
discord/emoji.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "emoji.hpp"
|
||||
|
||||
void from_json(const nlohmann::json &j, Emoji &m) {
|
||||
JS_N("id", m.ID);
|
||||
JS_N("name", m.Name);
|
||||
JS_O("roles", m.Roles);
|
||||
JS_O("user", m.Creator);
|
||||
JS_O("require_colons", m.NeedsColons);
|
||||
JS_O("managed", m.IsManaged);
|
||||
JS_O("animated", m.IsAnimated);
|
||||
JS_O("available", m.IsAvailable);
|
||||
}
|
||||
|
||||
std::string Emoji::GetURL() const {
|
||||
return "https://cdn.discordapp.com/emojis/" + std::to_string(ID) + ".png";
|
||||
}
|
||||
|
||||
std::string Emoji::URLFromID(std::string emoji_id) {
|
||||
return "https://cdn.discordapp.com/emojis/" + emoji_id + ".png";
|
||||
}
|
22
discord/emoji.hpp
Normal file
22
discord/emoji.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "json.hpp"
|
||||
#include "snowflake.hpp"
|
||||
#include "user.hpp"
|
||||
|
||||
struct Emoji {
|
||||
Snowflake ID; // null
|
||||
std::string Name; // null (in reactions)
|
||||
std::vector<Snowflake> Roles; // opt
|
||||
User Creator; // opt
|
||||
bool NeedsColons = false; // opt
|
||||
bool IsManaged = false; // opt
|
||||
bool IsAnimated = false; // opt
|
||||
bool IsAvailable = false; // opt
|
||||
|
||||
friend void from_json(const nlohmann::json &j, Emoji &m);
|
||||
|
||||
std::string GetURL() const;
|
||||
static std::string URLFromID(std::string emoji_id);
|
||||
};
|
@@ -26,7 +26,7 @@ void from_json(const nlohmann::json &j, Guild &m) {
|
||||
JS_D("default_message_notifications", m.DefaultMessageNotifications);
|
||||
JS_D("explicit_content_filter", m.ExplicitContentFilter);
|
||||
JS_D("roles", m.Roles);
|
||||
// JS_D("emojis", m.Emojis);
|
||||
JS_D("emojis", m.Emojis);
|
||||
JS_D("features", m.Features);
|
||||
JS_D("mfa_level", m.MFALevel);
|
||||
JS_N("application_id", m.ApplicationID);
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#include "snowflake.hpp"
|
||||
#include "role.hpp"
|
||||
#include "channel.hpp"
|
||||
#include "emoji.hpp"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
@@ -27,7 +28,7 @@ struct Guild {
|
||||
int DefaultMessageNotifications; //
|
||||
int ExplicitContentFilter; //
|
||||
std::vector<Role> Roles; //
|
||||
// std::vector<EmojiData> Emojis; //
|
||||
std::vector<Emoji> Emojis; //
|
||||
std::vector<std::string> Features; //
|
||||
int MFALevel; //
|
||||
Snowflake ApplicationID; // null
|
||||
|
@@ -13,6 +13,7 @@
|
||||
#include "message.hpp"
|
||||
#include "invite.hpp"
|
||||
#include "permissions.hpp"
|
||||
#include "emoji.hpp"
|
||||
|
||||
// most stuff below should just be objects that get processed and thrown away immediately
|
||||
|
||||
|
@@ -28,6 +28,10 @@ void Store::SetPermissionOverwrite(Snowflake channel_id, Snowflake id, const Per
|
||||
m_permissions[channel_id][id] = perm;
|
||||
}
|
||||
|
||||
void Store::SetEmoji(Snowflake id, const Emoji &emoji) {
|
||||
m_emojis[id] = emoji;
|
||||
}
|
||||
|
||||
User *Store::GetUser(Snowflake id) {
|
||||
auto it = m_users.find(id);
|
||||
if (it == m_users.end())
|
||||
@@ -118,6 +122,13 @@ PermissionOverwrite *Store::GetPermissionOverwrite(Snowflake channel_id, Snowfla
|
||||
return &pit->second;
|
||||
}
|
||||
|
||||
Emoji *Store::GetEmoji(Snowflake id) {
|
||||
auto it = m_emojis.find(id);
|
||||
if (it != m_emojis.end())
|
||||
return &it->second;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const GuildMember *Store::GetGuildMemberData(Snowflake guild_id, Snowflake user_id) const {
|
||||
auto git = m_members.find(guild_id);
|
||||
if (git == m_members.end())
|
||||
@@ -138,6 +149,13 @@ const PermissionOverwrite *Store::GetPermissionOverwrite(Snowflake channel_id, S
|
||||
return &pit->second;
|
||||
}
|
||||
|
||||
const Emoji *Store::GetEmoji(Snowflake id) const {
|
||||
auto it = m_emojis.find(id);
|
||||
if (it != m_emojis.end())
|
||||
return &it->second;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Store::ClearGuild(Snowflake id) {
|
||||
m_guilds.erase(id);
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@ public:
|
||||
void SetMessage(Snowflake id, const Message &message);
|
||||
void SetGuildMemberData(Snowflake guild_id, Snowflake user_id, const GuildMember &data);
|
||||
void SetPermissionOverwrite(Snowflake channel_id, Snowflake id, const PermissionOverwrite &perm);
|
||||
void SetEmoji(Snowflake id, const Emoji &emoji);
|
||||
|
||||
User *GetUser(Snowflake id);
|
||||
Channel *GetChannel(Snowflake id);
|
||||
@@ -24,6 +25,7 @@ public:
|
||||
Message *GetMessage(Snowflake id);
|
||||
GuildMember *GetGuildMemberData(Snowflake guild_id, Snowflake user_id);
|
||||
PermissionOverwrite *GetPermissionOverwrite(Snowflake channel_id, Snowflake id);
|
||||
Emoji *GetEmoji(Snowflake id);
|
||||
const User *GetUser(Snowflake id) const;
|
||||
const Channel *GetChannel(Snowflake id) const;
|
||||
const Guild *GetGuild(Snowflake id) const;
|
||||
@@ -31,6 +33,7 @@ public:
|
||||
const Message *GetMessage(Snowflake id) const;
|
||||
const GuildMember *GetGuildMemberData(Snowflake guild_id, Snowflake user_id) const;
|
||||
const PermissionOverwrite *GetPermissionOverwrite(Snowflake channel_id, Snowflake id) const;
|
||||
const Emoji *GetEmoji(Snowflake id) const;
|
||||
|
||||
void ClearGuild(Snowflake id);
|
||||
void ClearChannel(Snowflake id);
|
||||
@@ -42,6 +45,7 @@ public:
|
||||
using messages_type = std::unordered_map<Snowflake, Message>;
|
||||
using members_type = std::unordered_map<Snowflake, std::unordered_map<Snowflake, GuildMember>>; // [guild][user]
|
||||
using permission_overwrites_type = std::unordered_map<Snowflake, std::unordered_map<Snowflake, PermissionOverwrite>>; // [channel][user/role]
|
||||
using emojis_type = std::unordered_map<Snowflake, Emoji>;
|
||||
|
||||
const channels_type &GetChannels() const;
|
||||
const guilds_type &GetGuilds() const;
|
||||
@@ -57,4 +61,5 @@ private:
|
||||
messages_type m_messages;
|
||||
members_type m_members;
|
||||
permission_overwrites_type m_permissions;
|
||||
emojis_type m_emojis;
|
||||
};
|
||||
|
Reference in New Issue
Block a user