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