forked from OpenGamers/abaddon
improve build process, add github actions
This commit is contained in:
@@ -60,7 +60,7 @@ void to_json(nlohmann::json &j, const ActivitySecrets &m) {
|
||||
JS_IF("match", m.Match);
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json &j, Activity &m) {
|
||||
void from_json(const nlohmann::json &j, ActivityData &m) {
|
||||
JS_D("name", m.Name);
|
||||
JS_D("type", m.Type);
|
||||
JS_ON("url", m.URL);
|
||||
@@ -77,7 +77,7 @@ void from_json(const nlohmann::json &j, Activity &m) {
|
||||
JS_O("flags", m.Flags);
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json &j, const Activity &m) {
|
||||
void to_json(nlohmann::json &j, const ActivityData &m) {
|
||||
if (m.Type == ActivityType::Custom) {
|
||||
j["name"] = "Custom Status";
|
||||
j["state"] = m.Name;
|
||||
@@ -100,7 +100,7 @@ void to_json(nlohmann::json &j, const Activity &m) {
|
||||
JS_IF("flags", m.Flags);
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json &j, const Presence &m) {
|
||||
void to_json(nlohmann::json &j, const PresenceData &m) {
|
||||
j["activities"] = m.Activities;
|
||||
j["status"] = m.Status;
|
||||
j["afk"] = m.IsAFK;
|
||||
|
||||
@@ -71,7 +71,7 @@ struct ActivitySecrets {
|
||||
friend void to_json(nlohmann::json &j, const ActivitySecrets &m);
|
||||
};
|
||||
|
||||
struct Activity {
|
||||
struct ActivityData {
|
||||
std::string Name; //
|
||||
ActivityType Type; //
|
||||
std::optional<std::string> URL; // null
|
||||
@@ -87,15 +87,15 @@ struct Activity {
|
||||
std::optional<bool> IsInstance; //
|
||||
std::optional<ActivityFlags> Flags; //
|
||||
|
||||
friend void from_json(const nlohmann::json &j, Activity &m);
|
||||
friend void to_json(nlohmann::json &j, const Activity &m);
|
||||
friend void from_json(const nlohmann::json &j, ActivityData &m);
|
||||
friend void to_json(nlohmann::json &j, const ActivityData &m);
|
||||
};
|
||||
|
||||
struct Presence {
|
||||
std::vector<Activity> Activities; // null (but never sent as such)
|
||||
struct PresenceData {
|
||||
std::vector<ActivityData> Activities; // null (but never sent as such)
|
||||
std::string Status;
|
||||
bool IsAFK;
|
||||
int Since = 0;
|
||||
|
||||
friend void to_json(nlohmann::json &j, const Presence &m);
|
||||
friend void to_json(nlohmann::json &j, const PresenceData &m);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "../abaddon.hpp"
|
||||
#include "channel.hpp"
|
||||
|
||||
void from_json(const nlohmann::json &j, Channel &m) {
|
||||
void from_json(const nlohmann::json &j, ChannelData &m) {
|
||||
JS_D("id", m.ID);
|
||||
JS_D("type", m.Type);
|
||||
JS_O("guild_id", m.GuildID);
|
||||
@@ -23,7 +23,7 @@ void from_json(const nlohmann::json &j, Channel &m) {
|
||||
JS_ON("last_pin_timestamp", m.LastPinTimestamp);
|
||||
}
|
||||
|
||||
void Channel::update_from_json(const nlohmann::json &j) {
|
||||
void ChannelData::update_from_json(const nlohmann::json &j) {
|
||||
JS_RD("type", Type);
|
||||
JS_RD("guild_id", GuildID);
|
||||
JS_RV("position", Position, -1);
|
||||
@@ -43,17 +43,17 @@ void Channel::update_from_json(const nlohmann::json &j) {
|
||||
JS_RD("last_pin_timestamp", LastPinTimestamp);
|
||||
}
|
||||
|
||||
std::optional<PermissionOverwrite> Channel::GetOverwrite(Snowflake id) const {
|
||||
std::optional<PermissionOverwrite> ChannelData::GetOverwrite(Snowflake id) const {
|
||||
return Abaddon::Get().GetDiscordClient().GetPermissionOverwrite(ID, id);
|
||||
}
|
||||
|
||||
std::vector<User> Channel::GetDMRecipients() const {
|
||||
std::vector<UserData> ChannelData::GetDMRecipients() const {
|
||||
const auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
if (Recipients.has_value())
|
||||
return *Recipients;
|
||||
|
||||
if (RecipientIDs.has_value()) {
|
||||
std::vector<User> ret;
|
||||
std::vector<UserData> ret;
|
||||
for (const auto &id : *RecipientIDs) {
|
||||
auto user = discord.GetUser(id);
|
||||
if (user.has_value())
|
||||
@@ -63,5 +63,5 @@ std::vector<User> Channel::GetDMRecipients() const {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return std::vector<User>();
|
||||
return std::vector<UserData>();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ enum class ChannelType : int {
|
||||
GUILD_STORE = 6,
|
||||
};
|
||||
|
||||
struct Channel {
|
||||
struct ChannelData {
|
||||
Snowflake ID;
|
||||
ChannelType Type;
|
||||
std::optional<Snowflake> GuildID;
|
||||
@@ -29,7 +29,7 @@ struct Channel {
|
||||
std::optional<int> Bitrate;
|
||||
std::optional<int> UserLimit;
|
||||
std::optional<int> RateLimitPerUser;
|
||||
std::optional<std::vector<User>> Recipients; // only access id
|
||||
std::optional<std::vector<UserData>> Recipients; // only access id
|
||||
std::optional<std::vector<Snowflake>> RecipientIDs;
|
||||
std::optional<std::string> Icon; // null
|
||||
std::optional<Snowflake> OwnerID;
|
||||
@@ -37,9 +37,9 @@ struct Channel {
|
||||
std::optional<Snowflake> ParentID; // null
|
||||
std::optional<std::string> LastPinTimestamp; // null
|
||||
|
||||
friend void from_json(const nlohmann::json &j, Channel &m);
|
||||
friend void from_json(const nlohmann::json &j, ChannelData &m);
|
||||
void update_from_json(const nlohmann::json &j);
|
||||
|
||||
std::optional<PermissionOverwrite> GetOverwrite(Snowflake id) const;
|
||||
std::vector<User> GetDMRecipients() const;
|
||||
std::vector<UserData> GetDMRecipients() const;
|
||||
};
|
||||
|
||||
@@ -60,7 +60,7 @@ std::unordered_set<Snowflake> DiscordClient::GetGuilds() const {
|
||||
return m_store.GetGuilds();
|
||||
}
|
||||
|
||||
const User &DiscordClient::GetUserData() const {
|
||||
const UserData &DiscordClient::GetUserData() const {
|
||||
return m_user_data;
|
||||
}
|
||||
|
||||
@@ -159,19 +159,19 @@ std::optional<Message> DiscordClient::GetMessage(Snowflake id) const {
|
||||
return m_store.GetMessage(id);
|
||||
}
|
||||
|
||||
std::optional<Channel> DiscordClient::GetChannel(Snowflake id) const {
|
||||
std::optional<ChannelData> DiscordClient::GetChannel(Snowflake id) const {
|
||||
return m_store.GetChannel(id);
|
||||
}
|
||||
|
||||
std::optional<User> DiscordClient::GetUser(Snowflake id) const {
|
||||
std::optional<UserData> DiscordClient::GetUser(Snowflake id) const {
|
||||
return m_store.GetUser(id);
|
||||
}
|
||||
|
||||
std::optional<Role> DiscordClient::GetRole(Snowflake id) const {
|
||||
std::optional<RoleData> DiscordClient::GetRole(Snowflake id) const {
|
||||
return m_store.GetRole(id);
|
||||
}
|
||||
|
||||
std::optional<Guild> DiscordClient::GetGuild(Snowflake id) const {
|
||||
std::optional<GuildData> DiscordClient::GetGuild(Snowflake id) const {
|
||||
return m_store.GetGuild(id);
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ std::optional<PermissionOverwrite> DiscordClient::GetPermissionOverwrite(Snowfla
|
||||
return m_store.GetPermissionOverwrite(channel_id, id);
|
||||
}
|
||||
|
||||
std::optional<Emoji> DiscordClient::GetEmoji(Snowflake id) const {
|
||||
std::optional<EmojiData> DiscordClient::GetEmoji(Snowflake id) const {
|
||||
return m_store.GetEmoji(id);
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ Snowflake DiscordClient::GetMemberHoistedRole(Snowflake guild_id, Snowflake user
|
||||
const auto data = GetMember(guild_id, user_id);
|
||||
if (!data.has_value()) return Snowflake::Invalid;
|
||||
|
||||
std::vector<Role> roles;
|
||||
std::vector<RoleData> roles;
|
||||
for (const auto &id : data->Roles) {
|
||||
const auto role = GetRole(id);
|
||||
if (role.has_value()) {
|
||||
@@ -202,7 +202,7 @@ Snowflake DiscordClient::GetMemberHoistedRole(Snowflake guild_id, Snowflake user
|
||||
|
||||
if (roles.size() == 0) return Snowflake::Invalid;
|
||||
|
||||
std::sort(roles.begin(), roles.end(), [this](const Role &a, const Role &b) -> bool {
|
||||
std::sort(roles.begin(), roles.end(), [this](const RoleData &a, const RoleData &b) -> bool {
|
||||
return a.Position > b.Position;
|
||||
});
|
||||
|
||||
@@ -381,7 +381,7 @@ void DiscordClient::BanUser(Snowflake user_id, Snowflake guild_id) {
|
||||
m_http.MakePUT("/guilds/" + std::to_string(guild_id) + "/bans/" + std::to_string(user_id), "{}", [](auto) {});
|
||||
}
|
||||
|
||||
void DiscordClient::UpdateStatus(const std::string &status, bool is_afk, const Activity &obj) {
|
||||
void DiscordClient::UpdateStatus(const std::string &status, bool is_afk, const ActivityData &obj) {
|
||||
UpdateStatusMessage msg;
|
||||
msg.Presence.Status = status;
|
||||
msg.Presence.IsAFK = is_afk;
|
||||
@@ -614,7 +614,7 @@ void DiscordClient::HandleGatewayHello(const GatewayMessage &msg) {
|
||||
SendIdentify();
|
||||
}
|
||||
|
||||
void DiscordClient::ProcessNewGuild(Guild &guild) {
|
||||
void DiscordClient::ProcessNewGuild(GuildData &guild) {
|
||||
if (guild.IsUnavailable) {
|
||||
printf("guild (%lld) unavailable\n", static_cast<uint64_t>(guild.ID));
|
||||
return;
|
||||
@@ -662,7 +662,7 @@ void DiscordClient::HandleGatewayReady(const GatewayMessage &msg) {
|
||||
|
||||
m_session_id = data.SessionID;
|
||||
m_user_data = data.SelfUser;
|
||||
m_user_settings = data.UserSettings;
|
||||
m_user_settings = data.Settings;
|
||||
m_signal_gateway_ready.emit();
|
||||
}
|
||||
|
||||
@@ -710,7 +710,7 @@ void DiscordClient::HandleGatewayPresenceUpdate(const GatewayMessage &msg) {
|
||||
PresenceUpdateMessage data = msg.Data;
|
||||
auto cur = m_store.GetUser(data.User.at("id").get<Snowflake>());
|
||||
if (cur.has_value()) {
|
||||
User::update_from_json(data.User, *cur);
|
||||
UserData::update_from_json(data.User, *cur);
|
||||
m_store.SetUser(cur->ID, *cur);
|
||||
}
|
||||
}
|
||||
@@ -736,7 +736,7 @@ void DiscordClient::HandleGatewayChannelUpdate(const GatewayMessage &msg) {
|
||||
}
|
||||
|
||||
void DiscordClient::HandleGatewayChannelCreate(const GatewayMessage &msg) {
|
||||
Channel data = msg.Data;
|
||||
ChannelData data = msg.Data;
|
||||
m_store.BeginTransaction();
|
||||
m_store.SetChannel(data.ID, data);
|
||||
m_guild_to_channels[*data.GuildID].insert(data.ID);
|
||||
@@ -929,7 +929,7 @@ void DiscordClient::HandleGatewayGuildMemberListUpdate(const GatewayMessage &msg
|
||||
}
|
||||
|
||||
void DiscordClient::HandleGatewayGuildCreate(const GatewayMessage &msg) {
|
||||
Guild data = msg.Data;
|
||||
GuildData data = msg.Data;
|
||||
ProcessNewGuild(data);
|
||||
|
||||
m_signal_guild_create.emit(data.ID);
|
||||
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
using permission_overwrites_type = Store::permission_overwrites_type;
|
||||
|
||||
std::unordered_set<Snowflake> GetGuilds() const;
|
||||
const User &GetUserData() const;
|
||||
const UserData &GetUserData() const;
|
||||
const UserSettings &GetUserSettings() const;
|
||||
std::vector<Snowflake> GetUserSortedGuilds() const;
|
||||
std::set<Snowflake> GetMessagesForChannel(Snowflake id) const;
|
||||
@@ -79,12 +79,12 @@ public:
|
||||
void FetchMessagesInChannel(Snowflake id, std::function<void(const std::vector<Snowflake> &)> cb);
|
||||
void FetchMessagesInChannelBefore(Snowflake channel_id, Snowflake before_id, std::function<void(const std::vector<Snowflake> &)> cb);
|
||||
std::optional<Message> GetMessage(Snowflake id) const;
|
||||
std::optional<Channel> GetChannel(Snowflake id) const;
|
||||
std::optional<Emoji> GetEmoji(Snowflake id) const;
|
||||
std::optional<ChannelData> GetChannel(Snowflake id) const;
|
||||
std::optional<EmojiData> GetEmoji(Snowflake id) const;
|
||||
std::optional<PermissionOverwrite> GetPermissionOverwrite(Snowflake channel_id, Snowflake id) const;
|
||||
std::optional<User> GetUser(Snowflake id) const;
|
||||
std::optional<Role> GetRole(Snowflake id) const;
|
||||
std::optional<Guild> GetGuild(Snowflake id) const;
|
||||
std::optional<UserData> GetUser(Snowflake id) const;
|
||||
std::optional<RoleData> GetRole(Snowflake id) const;
|
||||
std::optional<GuildData> GetGuild(Snowflake id) const;
|
||||
std::optional<GuildMember> GetMember(Snowflake user_id, Snowflake guild_id) const;
|
||||
Snowflake GetMemberHoistedRole(Snowflake guild_id, Snowflake user_id, bool with_color = false) const;
|
||||
Snowflake GetMemberHighestRole(Snowflake guild_id, Snowflake user_id) const;
|
||||
@@ -105,7 +105,7 @@ public:
|
||||
void LeaveGuild(Snowflake id);
|
||||
void KickUser(Snowflake user_id, Snowflake guild_id);
|
||||
void BanUser(Snowflake user_id, Snowflake guild_id); // todo: reason, delete messages
|
||||
void UpdateStatus(const std::string &status, bool is_afk, const Activity &obj);
|
||||
void UpdateStatus(const std::string &status, bool is_afk, const ActivityData &obj);
|
||||
void CreateDM(Snowflake user_id);
|
||||
std::optional<Snowflake> FindDM(Snowflake user_id); // wont find group dms
|
||||
void AddReaction(Snowflake id, Glib::ustring param);
|
||||
@@ -120,7 +120,7 @@ private:
|
||||
std::vector<uint8_t> m_decompress_buf;
|
||||
z_stream m_zstream;
|
||||
|
||||
void ProcessNewGuild(Guild &guild);
|
||||
void ProcessNewGuild(GuildData &guild);
|
||||
|
||||
void HandleGatewayMessageRaw(std::string str);
|
||||
void HandleGatewayMessage(std::string str);
|
||||
@@ -168,7 +168,7 @@ private:
|
||||
|
||||
std::unordered_map<Snowflake, std::unordered_set<Snowflake>> m_guild_to_channels;
|
||||
|
||||
User m_user_data;
|
||||
UserData m_user_data;
|
||||
UserSettings m_user_settings;
|
||||
|
||||
Store m_store;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "emoji.hpp"
|
||||
|
||||
void from_json(const nlohmann::json &j, Emoji &m) {
|
||||
void from_json(const nlohmann::json &j, EmojiData &m) {
|
||||
JS_N("id", m.ID);
|
||||
JS_N("name", m.Name);
|
||||
JS_O("roles", m.Roles);
|
||||
@@ -11,7 +11,7 @@ void from_json(const nlohmann::json &j, Emoji &m) {
|
||||
JS_O("available", m.IsAvailable);
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json &j, const Emoji &m) {
|
||||
void to_json(nlohmann::json &j, const EmojiData &m) {
|
||||
if (m.ID.IsValid())
|
||||
j["id"] = m.ID;
|
||||
else
|
||||
@@ -28,10 +28,10 @@ void to_json(nlohmann::json &j, const Emoji &m) {
|
||||
JS_IF("available", m.IsAvailable);
|
||||
}
|
||||
|
||||
std::string Emoji::GetURL() const {
|
||||
std::string EmojiData::GetURL() const {
|
||||
return "https://cdn.discordapp.com/emojis/" + std::to_string(ID) + ".png";
|
||||
}
|
||||
|
||||
std::string Emoji::URLFromID(std::string emoji_id, std::string ext) {
|
||||
std::string EmojiData::URLFromID(std::string emoji_id, std::string ext) {
|
||||
return "https://cdn.discordapp.com/emojis/" + emoji_id + "." + ext;
|
||||
}
|
||||
|
||||
@@ -5,18 +5,18 @@
|
||||
#include "snowflake.hpp"
|
||||
#include "user.hpp"
|
||||
|
||||
struct Emoji {
|
||||
struct EmojiData {
|
||||
Snowflake ID; // null
|
||||
std::string Name; // null (in reactions)
|
||||
std::optional<std::vector<Snowflake>> Roles;
|
||||
std::optional<User> Creator; // only reliable to access ID
|
||||
std::optional<UserData> Creator; // only reliable to access ID
|
||||
std::optional<bool> NeedsColons;
|
||||
std::optional<bool> IsManaged;
|
||||
std::optional<bool> IsAnimated;
|
||||
std::optional<bool> IsAvailable;
|
||||
|
||||
friend void from_json(const nlohmann::json &j, Emoji &m);
|
||||
friend void to_json(nlohmann::json &j, const Emoji &m);
|
||||
friend void from_json(const nlohmann::json &j, EmojiData &m);
|
||||
friend void to_json(nlohmann::json &j, const EmojiData &m);
|
||||
|
||||
std::string GetURL() const;
|
||||
static std::string URLFromID(std::string emoji_id, std::string ext = "png");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "guild.hpp"
|
||||
#include "../abaddon.hpp"
|
||||
|
||||
void from_json(const nlohmann::json &j, Guild &m) {
|
||||
void from_json(const nlohmann::json &j, GuildData &m) {
|
||||
JS_D("id", m.ID);
|
||||
if (j.contains("unavailable")) {
|
||||
m.IsUnavailable = true;
|
||||
@@ -62,7 +62,7 @@ void from_json(const nlohmann::json &j, Guild &m) {
|
||||
m.ApproximatePresenceCount = std::stol(*tmp);
|
||||
}
|
||||
|
||||
void Guild::update_from_json(const nlohmann::json &j) {
|
||||
void GuildData::update_from_json(const nlohmann::json &j) {
|
||||
if (j.contains("unavailable")) {
|
||||
IsUnavailable = true;
|
||||
return;
|
||||
@@ -118,27 +118,27 @@ void Guild::update_from_json(const nlohmann::json &j) {
|
||||
JS_RD("approximate_presence_count", ApproximatePresenceCount);
|
||||
}
|
||||
|
||||
bool Guild::HasIcon() const {
|
||||
bool GuildData::HasIcon() const {
|
||||
return Icon != "";
|
||||
}
|
||||
|
||||
bool Guild::HasAnimatedIcon() const {
|
||||
bool GuildData::HasAnimatedIcon() const {
|
||||
return HasIcon() && Icon[0] == 'a' && Icon[1] == '_';
|
||||
}
|
||||
|
||||
std::string Guild::GetIconURL(std::string ext, std::string size) const {
|
||||
std::string GuildData::GetIconURL(std::string ext, std::string size) const {
|
||||
return "https://cdn.discordapp.com/icons/" + std::to_string(ID) + "/" + Icon + "." + ext + "?size=" + size;
|
||||
}
|
||||
|
||||
std::vector<Snowflake> Guild::GetSortedChannels(Snowflake ignore) const {
|
||||
std::vector<Snowflake> GuildData::GetSortedChannels(Snowflake ignore) const {
|
||||
std::vector<Snowflake> ret;
|
||||
|
||||
const auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
auto channels = discord.GetChannelsInGuild(ID);
|
||||
|
||||
std::unordered_map<Snowflake, std::vector<Channel>> category_to_channels;
|
||||
std::map<int, std::vector<Channel>> position_to_categories;
|
||||
std::map<int, std::vector<Channel>> orphan_channels;
|
||||
std::unordered_map<Snowflake, std::vector<ChannelData>> category_to_channels;
|
||||
std::map<int, std::vector<ChannelData>> position_to_categories;
|
||||
std::map<int, std::vector<ChannelData>> orphan_channels;
|
||||
for (const auto &channel_id : channels) {
|
||||
const auto data = discord.GetChannel(channel_id);
|
||||
if (!data.has_value()) continue;
|
||||
@@ -151,7 +151,7 @@ std::vector<Snowflake> Guild::GetSortedChannels(Snowflake ignore) const {
|
||||
}
|
||||
|
||||
for (auto &[pos, channels] : orphan_channels) {
|
||||
std::sort(channels.begin(), channels.end(), [&](const Channel &a, const Channel &b) -> bool {
|
||||
std::sort(channels.begin(), channels.end(), [&](const ChannelData &a, const ChannelData &b) -> bool {
|
||||
return a.ID < b.ID;
|
||||
});
|
||||
for (const auto &chan : channels)
|
||||
@@ -159,7 +159,7 @@ std::vector<Snowflake> Guild::GetSortedChannels(Snowflake ignore) const {
|
||||
}
|
||||
|
||||
for (auto &[pos, categories] : position_to_categories) {
|
||||
std::sort(categories.begin(), categories.end(), [&](const Channel &a, const Channel &b) -> bool {
|
||||
std::sort(categories.begin(), categories.end(), [&](const ChannelData &a, const ChannelData &b) -> bool {
|
||||
return a.ID < b.ID;
|
||||
});
|
||||
for (const auto &category : categories) {
|
||||
@@ -168,7 +168,7 @@ std::vector<Snowflake> Guild::GetSortedChannels(Snowflake ignore) const {
|
||||
auto it = category_to_channels.find(category.ID);
|
||||
if (it == category_to_channels.end()) continue;
|
||||
auto &channels = it->second;
|
||||
std::sort(channels.begin(), channels.end(), [&](const Channel &a, const Channel &b) -> bool {
|
||||
std::sort(channels.begin(), channels.end(), [&](const ChannelData &a, const ChannelData &b) -> bool {
|
||||
return a.Position < b.Position;
|
||||
});
|
||||
for (auto &channel : channels) {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
// a bot is apparently only supposed to receive the `id` and `unavailable` as false
|
||||
// but user tokens seem to get the full objects (minus users)
|
||||
struct Guild {
|
||||
struct GuildData {
|
||||
Snowflake ID;
|
||||
std::string Name;
|
||||
std::string Icon; // null
|
||||
@@ -27,8 +27,8 @@ struct Guild {
|
||||
int VerificationLevel;
|
||||
int DefaultMessageNotifications;
|
||||
int ExplicitContentFilter;
|
||||
std::vector<Role> Roles; // only access id
|
||||
std::vector<Emoji> Emojis; // only access id
|
||||
std::vector<RoleData> Roles; // only access id
|
||||
std::vector<EmojiData> Emojis; // only access id
|
||||
std::vector<std::string> Features;
|
||||
int MFALevel;
|
||||
Snowflake ApplicationID; // null
|
||||
@@ -43,7 +43,7 @@ struct Guild {
|
||||
std::optional<int> MemberCount; // *
|
||||
// std::vector<VoiceStateData> VoiceStates; // opt*
|
||||
// std::vector<MemberData> Members; // opt* - incomplete anyways
|
||||
std::optional<std::vector<Channel>> Channels; // *
|
||||
std::optional<std::vector<ChannelData>> Channels; // *
|
||||
// std::vector<PresenceUpdateData> Presences; // opt*
|
||||
std::optional<int> MaxPresences; // null
|
||||
std::optional<int> MaxMembers;
|
||||
@@ -64,7 +64,7 @@ struct Guild {
|
||||
|
||||
// * - documentation says only sent in GUILD_CREATE, but these can be sent anyways in the READY event
|
||||
|
||||
friend void from_json(const nlohmann::json &j, Guild &m);
|
||||
friend void from_json(const nlohmann::json &j, GuildData &m);
|
||||
void update_from_json(const nlohmann::json &j);
|
||||
|
||||
bool HasIcon() const;
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
|
||||
class Invite {
|
||||
public:
|
||||
std::string Code; //
|
||||
Guild Guild; // opt
|
||||
Channel Channel; // opt
|
||||
User Inviter; // opt
|
||||
int Members = -1; // opt
|
||||
std::string Code; //
|
||||
GuildData Guild; // opt
|
||||
ChannelData Channel; // opt
|
||||
UserData Inviter; // opt
|
||||
int Members = -1; // opt
|
||||
|
||||
friend void from_json(const nlohmann::json &j, Invite &m);
|
||||
};
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#include <vector>
|
||||
|
||||
struct GuildMember {
|
||||
std::optional<User> User; // only reliable to access id. only opt in MESSAGE_*
|
||||
std::string Nickname; // null
|
||||
std::optional<UserData> User; // only reliable to access id. only opt in MESSAGE_*
|
||||
std::string Nickname; // null
|
||||
std::vector<Snowflake> Roles;
|
||||
std::string JoinedAt;
|
||||
std::optional<std::string> PremiumSince; // null
|
||||
|
||||
@@ -145,7 +145,7 @@ struct MessageReferenceData {
|
||||
struct ReactionData {
|
||||
int Count;
|
||||
bool HasReactedWith;
|
||||
Emoji Emoji;
|
||||
EmojiData Emoji;
|
||||
|
||||
friend void from_json(const nlohmann::json &j, ReactionData &m);
|
||||
friend void to_json(nlohmann::json &j, const ReactionData &m);
|
||||
@@ -166,15 +166,15 @@ struct Message {
|
||||
Snowflake ID;
|
||||
Snowflake ChannelID;
|
||||
std::optional<Snowflake> GuildID;
|
||||
User Author;
|
||||
UserData Author;
|
||||
// std::optional<GuildMember> Member;
|
||||
std::string Content;
|
||||
std::string Timestamp;
|
||||
std::string EditedTimestamp; // null
|
||||
bool IsTTS;
|
||||
bool DoesMentionEveryone;
|
||||
std::vector<User> Mentions; // full user accessible
|
||||
// std::vector<Role> MentionRoles;
|
||||
std::vector<UserData> Mentions; // full user accessible
|
||||
// std::vector<RoleData> MentionRoles;
|
||||
// std::optional<std::vector<ChannelMentionData>> MentionChannels;
|
||||
std::vector<AttachmentData> Attachments;
|
||||
std::vector<EmbedData> Embeds;
|
||||
@@ -183,11 +183,11 @@ struct Message {
|
||||
bool IsPinned;
|
||||
std::optional<Snowflake> WebhookID;
|
||||
MessageType Type;
|
||||
// std::optional<MessageActivityData> Activity;
|
||||
// std::optional<MessageActivityData> ActivityData;
|
||||
std::optional<MessageApplicationData> Application;
|
||||
std::optional<MessageReferenceData> MessageReference;
|
||||
std::optional<MessageFlags> Flags = MessageFlags::NONE;
|
||||
std::optional<std::vector<Sticker>> Stickers;
|
||||
std::optional<std::vector<StickerData>> Stickers;
|
||||
std::optional<std::shared_ptr<Message>> ReferencedMessage; // has_value && null means deleted
|
||||
|
||||
friend void from_json(const nlohmann::json &j, Message &m);
|
||||
|
||||
@@ -95,7 +95,7 @@ void from_json(const nlohmann::json &j, ReadyEventData &m) {
|
||||
JS_D("session_id", m.SessionID);
|
||||
JS_O("analytics_token", m.AnalyticsToken);
|
||||
JS_O("friend_suggestion_count", m.FriendSuggestionCount);
|
||||
JS_D("user_settings", m.UserSettings);
|
||||
JS_D("user_settings", m.Settings);
|
||||
JS_D("private_channels", m.PrivateChannels);
|
||||
JS_O("users", m.Users);
|
||||
}
|
||||
@@ -178,9 +178,9 @@ void from_json(const nlohmann::json &j, ClientStatus &m) {
|
||||
void from_json(const nlohmann::json &j, PresenceUpdateMessage &m) {
|
||||
m.User = j.at("user");
|
||||
JS_O("guild_id", m.GuildID);
|
||||
JS_D("status", m.Status);
|
||||
JS_D("status", m.StatusMessage);
|
||||
// JS_D("activities", m.Activities);
|
||||
JS_D("client_status", m.ClientStatus);
|
||||
JS_D("client_status", m.Status);
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json &j, const CreateDMObject &m) {
|
||||
|
||||
@@ -99,7 +99,7 @@ struct GuildMemberListUpdateMessage {
|
||||
};
|
||||
|
||||
struct MemberItem : Item {
|
||||
User User; //
|
||||
UserData User; //
|
||||
std::vector<Snowflake> Roles; //
|
||||
// PresenceData Presence; //
|
||||
std::string PremiumSince; // opt
|
||||
@@ -147,23 +147,23 @@ struct LazyLoadRequestMessage {
|
||||
};
|
||||
|
||||
struct UpdateStatusMessage {
|
||||
Presence Presence;
|
||||
PresenceData Presence;
|
||||
|
||||
friend void to_json(nlohmann::json &j, const UpdateStatusMessage &m);
|
||||
};
|
||||
|
||||
struct ReadyEventData {
|
||||
int GatewayVersion;
|
||||
User SelfUser;
|
||||
std::vector<Guild> Guilds;
|
||||
UserData SelfUser;
|
||||
std::vector<GuildData> Guilds;
|
||||
std::string SessionID;
|
||||
std::vector<Channel> PrivateChannels;
|
||||
std::vector<ChannelData> PrivateChannels;
|
||||
|
||||
// undocumented
|
||||
std::optional<std::vector<User>> Users;
|
||||
std::optional<std::vector<UserData>> Users;
|
||||
std::optional<std::string> AnalyticsToken;
|
||||
std::optional<int> FriendSuggestionCount;
|
||||
UserSettings UserSettings;
|
||||
UserSettings Settings;
|
||||
// std::vector<Unknown> ConnectedAccounts; // opt
|
||||
// std::map<std::string, Unknown> Consents; // opt
|
||||
// std::vector<Unknown> Experiments; // opt
|
||||
@@ -208,7 +208,7 @@ struct ClientStateProperties {
|
||||
struct IdentifyMessage : GatewayMessage {
|
||||
std::string Token;
|
||||
IdentifyProperties Properties;
|
||||
Presence Presence;
|
||||
PresenceData Presence;
|
||||
ClientStateProperties ClientState;
|
||||
bool DoesSupportCompression = false;
|
||||
int Capabilities;
|
||||
@@ -239,7 +239,7 @@ struct MessageEditObject {
|
||||
struct GuildMemberUpdateMessage {
|
||||
Snowflake GuildID; //
|
||||
std::vector<Snowflake> Roles; //
|
||||
User User; //
|
||||
UserData User; //
|
||||
std::string Nick; // opt, null
|
||||
std::string JoinedAt;
|
||||
std::string PremiumSince; // opt, null
|
||||
@@ -258,9 +258,9 @@ struct ClientStatus {
|
||||
struct PresenceUpdateMessage {
|
||||
nlohmann::json User; // the client updates an existing object from this data
|
||||
Snowflake GuildID; // opt
|
||||
std::string Status;
|
||||
// std::vector<Activity> Activities;
|
||||
ClientStatus ClientStatus;
|
||||
std::string StatusMessage;
|
||||
// std::vector<ActivityData> Activities;
|
||||
ClientStatus Status;
|
||||
|
||||
friend void from_json(const nlohmann::json &j, PresenceUpdateMessage &m);
|
||||
};
|
||||
@@ -281,14 +281,14 @@ struct ResumeMessage : GatewayMessage {
|
||||
|
||||
struct GuildRoleUpdateObject {
|
||||
Snowflake GuildID;
|
||||
Role Role;
|
||||
RoleData Role;
|
||||
|
||||
friend void from_json(const nlohmann::json &j, GuildRoleUpdateObject &m);
|
||||
};
|
||||
|
||||
struct GuildRoleCreateObject {
|
||||
Snowflake GuildID;
|
||||
Role Role;
|
||||
RoleData Role;
|
||||
|
||||
friend void from_json(const nlohmann::json &j, GuildRoleCreateObject &m);
|
||||
};
|
||||
@@ -306,7 +306,7 @@ struct MessageReactionAddObject {
|
||||
Snowflake MessageID;
|
||||
std::optional<Snowflake> GuildID;
|
||||
std::optional<GuildMember> Member;
|
||||
Emoji Emoji;
|
||||
EmojiData Emoji;
|
||||
|
||||
friend void from_json(const nlohmann::json &j, MessageReactionAddObject &m);
|
||||
};
|
||||
@@ -316,20 +316,20 @@ struct MessageReactionRemoveObject {
|
||||
Snowflake ChannelID;
|
||||
Snowflake MessageID;
|
||||
std::optional<Snowflake> GuildID;
|
||||
Emoji Emoji;
|
||||
EmojiData Emoji;
|
||||
|
||||
friend void from_json(const nlohmann::json &j, MessageReactionRemoveObject &m);
|
||||
};
|
||||
|
||||
struct ChannelRecipientAdd {
|
||||
User User;
|
||||
UserData User;
|
||||
Snowflake ChannelID;
|
||||
|
||||
friend void from_json(const nlohmann::json &j, ChannelRecipientAdd &m);
|
||||
};
|
||||
|
||||
struct ChannelRecipientRemove {
|
||||
User User;
|
||||
UserData User;
|
||||
Snowflake ChannelID;
|
||||
|
||||
friend void from_json(const nlohmann::json &j, ChannelRecipientRemove &m);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "role.hpp"
|
||||
|
||||
void from_json(const nlohmann::json &j, Role &m) {
|
||||
void from_json(const nlohmann::json &j, RoleData &m) {
|
||||
JS_D("id", m.ID);
|
||||
JS_D("name", m.Name);
|
||||
JS_D("color", m.Color);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
struct Role {
|
||||
struct RoleData {
|
||||
Snowflake ID;
|
||||
std::string Name;
|
||||
int Color;
|
||||
@@ -16,5 +16,5 @@ struct Role {
|
||||
bool IsManaged;
|
||||
bool IsMentionable;
|
||||
|
||||
friend void from_json(const nlohmann::json &j, Role &m);
|
||||
friend void from_json(const nlohmann::json &j, RoleData &m);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "sticker.hpp"
|
||||
|
||||
void to_json(nlohmann::json &j, const Sticker &m) {
|
||||
void to_json(nlohmann::json &j, const StickerData &m) {
|
||||
j["id"] = m.ID;
|
||||
j["pack_id"] = m.PackID;
|
||||
j["name"] = m.Name;
|
||||
@@ -11,7 +11,7 @@ void to_json(nlohmann::json &j, const Sticker &m) {
|
||||
j["format_type"] = m.FormatType;
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json &j, Sticker &m) {
|
||||
void from_json(const nlohmann::json &j, StickerData &m) {
|
||||
JS_D("id", m.ID);
|
||||
JS_D("pack_id", m.PackID);
|
||||
JS_D("name", m.Name);
|
||||
@@ -22,7 +22,7 @@ void from_json(const nlohmann::json &j, Sticker &m) {
|
||||
JS_D("format_type", m.FormatType);
|
||||
}
|
||||
|
||||
std::string Sticker::GetURL() const {
|
||||
std::string StickerData::GetURL() const {
|
||||
if (!AssetHash.has_value()) return "";
|
||||
if (FormatType == StickerFormatType::PNG || FormatType == StickerFormatType::APNG)
|
||||
return "https://media.discordapp.net/stickers/" + std::to_string(ID) + "/" + *AssetHash + ".png?size=256";
|
||||
|
||||
@@ -12,7 +12,7 @@ enum class StickerFormatType {
|
||||
LOTTIE = 3,
|
||||
};
|
||||
|
||||
struct Sticker {
|
||||
struct StickerData {
|
||||
Snowflake ID;
|
||||
Snowflake PackID;
|
||||
std::string Name;
|
||||
@@ -22,8 +22,8 @@ struct Sticker {
|
||||
std::optional<std::string> PreviewAssetHash;
|
||||
StickerFormatType FormatType;
|
||||
|
||||
friend void to_json(nlohmann::json &j, const Sticker &m);
|
||||
friend void from_json(const nlohmann::json &j, Sticker &m);
|
||||
friend void to_json(nlohmann::json &j, const StickerData &m);
|
||||
friend void from_json(const nlohmann::json &j, StickerData &m);
|
||||
|
||||
std::string GetURL() const;
|
||||
};
|
||||
|
||||
@@ -51,7 +51,7 @@ bool Store::IsValid() const {
|
||||
return m_db_err == SQLITE_OK;
|
||||
}
|
||||
|
||||
void Store::SetChannel(Snowflake id, const Channel &chan) {
|
||||
void Store::SetChannel(Snowflake id, const ChannelData &chan) {
|
||||
Bind(m_set_chan_stmt, 1, id);
|
||||
Bind(m_set_chan_stmt, 2, static_cast<int>(chan.Type));
|
||||
Bind(m_set_chan_stmt, 3, chan.GuildID);
|
||||
@@ -86,7 +86,7 @@ void Store::SetChannel(Snowflake id, const Channel &chan) {
|
||||
m_channels.insert(id);
|
||||
}
|
||||
|
||||
void Store::SetEmoji(Snowflake id, const Emoji &emoji) {
|
||||
void Store::SetEmoji(Snowflake id, const EmojiData &emoji) {
|
||||
Bind(m_set_emote_stmt, 1, id);
|
||||
Bind(m_set_emote_stmt, 2, emoji.Name);
|
||||
|
||||
@@ -109,7 +109,7 @@ void Store::SetEmoji(Snowflake id, const Emoji &emoji) {
|
||||
fprintf(stderr, "emoji insert failed: %s\n", sqlite3_errstr(m_db_err));
|
||||
}
|
||||
|
||||
void Store::SetGuild(Snowflake id, const Guild &guild) {
|
||||
void Store::SetGuild(Snowflake id, const GuildData &guild) {
|
||||
Bind(m_set_guild_stmt, 1, id);
|
||||
Bind(m_set_guild_stmt, 2, guild.Name);
|
||||
Bind(m_set_guild_stmt, 3, guild.Icon);
|
||||
@@ -239,7 +239,7 @@ void Store::SetPermissionOverwrite(Snowflake channel_id, Snowflake id, const Per
|
||||
fprintf(stderr, "permission insert failed: %s\n", sqlite3_errstr(m_db_err));
|
||||
}
|
||||
|
||||
void Store::SetRole(Snowflake id, const Role &role) {
|
||||
void Store::SetRole(Snowflake id, const RoleData &role) {
|
||||
Bind(m_set_role_stmt, 1, id);
|
||||
Bind(m_set_role_stmt, 2, role.Name);
|
||||
Bind(m_set_role_stmt, 3, role.Color);
|
||||
@@ -253,7 +253,7 @@ void Store::SetRole(Snowflake id, const Role &role) {
|
||||
fprintf(stderr, "role insert failed: %s\n", sqlite3_errstr(m_db_err));
|
||||
}
|
||||
|
||||
void Store::SetUser(Snowflake id, const User &user) {
|
||||
void Store::SetUser(Snowflake id, const UserData &user) {
|
||||
Bind(m_set_user_stmt, 1, id);
|
||||
Bind(m_set_user_stmt, 2, user.Username);
|
||||
Bind(m_set_user_stmt, 3, user.Discriminator);
|
||||
@@ -273,7 +273,7 @@ void Store::SetUser(Snowflake id, const User &user) {
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<Channel> Store::GetChannel(Snowflake id) const {
|
||||
std::optional<ChannelData> Store::GetChannel(Snowflake id) const {
|
||||
Bind(m_get_chan_stmt, 1, id);
|
||||
if (!FetchOne(m_get_chan_stmt)) {
|
||||
if (m_db_err != SQLITE_DONE)
|
||||
@@ -282,7 +282,7 @@ std::optional<Channel> Store::GetChannel(Snowflake id) const {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
Channel ret;
|
||||
ChannelData ret;
|
||||
ret.ID = id;
|
||||
int tmpi;
|
||||
Get(m_get_chan_stmt, 1, tmpi);
|
||||
@@ -313,7 +313,7 @@ std::optional<Channel> Store::GetChannel(Snowflake id) const {
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::optional<Emoji> Store::GetEmoji(Snowflake id) const {
|
||||
std::optional<EmojiData> Store::GetEmoji(Snowflake id) const {
|
||||
Bind(m_get_emote_stmt, 1, id);
|
||||
if (!FetchOne(m_get_emote_stmt)) {
|
||||
if (m_db_err != SQLITE_DONE)
|
||||
@@ -322,7 +322,7 @@ std::optional<Emoji> Store::GetEmoji(Snowflake id) const {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
Emoji ret;
|
||||
EmojiData ret;
|
||||
ret.ID = id;
|
||||
Get(m_get_emote_stmt, 1, ret.Name);
|
||||
|
||||
@@ -333,7 +333,7 @@ std::optional<Emoji> Store::GetEmoji(Snowflake id) const {
|
||||
}
|
||||
|
||||
if (!IsNull(m_get_emote_stmt, 3)) {
|
||||
ret.Creator = std::optional<User>(User());
|
||||
ret.Creator = std::optional<UserData>(UserData());
|
||||
Get(m_get_emote_stmt, 3, ret.Creator->ID);
|
||||
}
|
||||
Get(m_get_emote_stmt, 4, ret.NeedsColons);
|
||||
@@ -346,7 +346,7 @@ std::optional<Emoji> Store::GetEmoji(Snowflake id) const {
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::optional<Guild> Store::GetGuild(Snowflake id) const {
|
||||
std::optional<GuildData> Store::GetGuild(Snowflake id) const {
|
||||
Bind(m_get_guild_stmt, 1, id);
|
||||
if (!FetchOne(m_get_guild_stmt)) {
|
||||
if (m_db_err != SQLITE_DONE)
|
||||
@@ -355,7 +355,7 @@ std::optional<Guild> Store::GetGuild(Snowflake id) const {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
Guild ret;
|
||||
GuildData ret;
|
||||
ret.ID = id;
|
||||
Get(m_get_guild_stmt, 1, ret.Name);
|
||||
Get(m_get_guild_stmt, 2, ret.Icon);
|
||||
@@ -481,7 +481,7 @@ std::optional<Message> Store::GetMessage(Snowflake id) const {
|
||||
|
||||
Get(m_get_msg_stmt, 18, tmps);
|
||||
if (tmps != "")
|
||||
ret.Stickers = nlohmann::json::parse(tmps).get<std::vector<Sticker>>();
|
||||
ret.Stickers = nlohmann::json::parse(tmps).get<std::vector<StickerData>>();
|
||||
|
||||
Get(m_get_msg_stmt, 19, tmps);
|
||||
if (tmps != "")
|
||||
@@ -532,7 +532,7 @@ std::optional<PermissionOverwrite> Store::GetPermissionOverwrite(Snowflake chann
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::optional<Role> Store::GetRole(Snowflake id) const {
|
||||
std::optional<RoleData> Store::GetRole(Snowflake id) const {
|
||||
Bind(m_get_role_stmt, 1, id);
|
||||
if (!FetchOne(m_get_role_stmt)) {
|
||||
if (m_db_err != SQLITE_DONE)
|
||||
@@ -541,7 +541,7 @@ std::optional<Role> Store::GetRole(Snowflake id) const {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
Role ret;
|
||||
RoleData ret;
|
||||
ret.ID = id;
|
||||
Get(m_get_role_stmt, 1, ret.Name);
|
||||
Get(m_get_role_stmt, 2, ret.Color);
|
||||
@@ -558,7 +558,7 @@ std::optional<Role> Store::GetRole(Snowflake id) const {
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::optional<User> Store::GetUser(Snowflake id) const {
|
||||
std::optional<UserData> Store::GetUser(Snowflake id) const {
|
||||
Bind(m_get_user_stmt, 1, id);
|
||||
if (!FetchOne(m_get_user_stmt)) {
|
||||
if (m_db_err != SQLITE_DONE)
|
||||
@@ -567,7 +567,7 @@ std::optional<User> Store::GetUser(Snowflake id) const {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
User ret;
|
||||
UserData ret;
|
||||
Get(m_get_user_stmt, 0, ret.ID);
|
||||
Get(m_get_user_stmt, 1, ret.Username);
|
||||
Get(m_get_user_stmt, 2, ret.Discriminator);
|
||||
|
||||
@@ -18,37 +18,37 @@ public:
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
void SetUser(Snowflake id, const User &user);
|
||||
void SetChannel(Snowflake id, const Channel &chan);
|
||||
void SetGuild(Snowflake id, const Guild &guild);
|
||||
void SetRole(Snowflake id, const Role &role);
|
||||
void SetUser(Snowflake id, const UserData &user);
|
||||
void SetChannel(Snowflake id, const ChannelData &chan);
|
||||
void SetGuild(Snowflake id, const GuildData &guild);
|
||||
void SetRole(Snowflake id, const RoleData &role);
|
||||
void SetMessage(Snowflake id, const Message &message);
|
||||
void SetGuildMember(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);
|
||||
void SetEmoji(Snowflake id, const EmojiData &emoji);
|
||||
|
||||
// slap const on everything even tho its not *really* const
|
||||
|
||||
std::optional<Channel> GetChannel(Snowflake id) const;
|
||||
std::optional<Emoji> GetEmoji(Snowflake id) const;
|
||||
std::optional<Guild> GetGuild(Snowflake id) const;
|
||||
std::optional<ChannelData> GetChannel(Snowflake id) const;
|
||||
std::optional<EmojiData> GetEmoji(Snowflake id) const;
|
||||
std::optional<GuildData> GetGuild(Snowflake id) const;
|
||||
std::optional<GuildMember> GetGuildMember(Snowflake guild_id, Snowflake user_id) const;
|
||||
std::optional<Message> GetMessage(Snowflake id) const;
|
||||
std::optional<PermissionOverwrite> GetPermissionOverwrite(Snowflake channel_id, Snowflake id) const;
|
||||
std::optional<Role> GetRole(Snowflake id) const;
|
||||
std::optional<User> GetUser(Snowflake id) const;
|
||||
std::optional<RoleData> GetRole(Snowflake id) const;
|
||||
std::optional<UserData> GetUser(Snowflake id) const;
|
||||
|
||||
void ClearGuild(Snowflake id);
|
||||
void ClearChannel(Snowflake id);
|
||||
|
||||
using users_type = std::unordered_map<Snowflake, User>;
|
||||
using channels_type = std::unordered_map<Snowflake, Channel>;
|
||||
using guilds_type = std::unordered_map<Snowflake, Guild>;
|
||||
using roles_type = std::unordered_map<Snowflake, Role>;
|
||||
using users_type = std::unordered_map<Snowflake, UserData>;
|
||||
using channels_type = std::unordered_map<Snowflake, ChannelData>;
|
||||
using guilds_type = std::unordered_map<Snowflake, GuildData>;
|
||||
using roles_type = std::unordered_map<Snowflake, RoleData>;
|
||||
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>;
|
||||
using emojis_type = std::unordered_map<Snowflake, EmojiData>;
|
||||
|
||||
const std::unordered_set<Snowflake> &GetChannels() const;
|
||||
const std::unordered_set<Snowflake> &GetGuilds() const;
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
#include "user.hpp"
|
||||
#include "../abaddon.hpp"
|
||||
|
||||
bool User::HasAvatar() const {
|
||||
bool UserData::HasAvatar() const {
|
||||
return Avatar.size() > 0;
|
||||
}
|
||||
|
||||
bool User::HasAnimatedAvatar() const {
|
||||
bool UserData::HasAnimatedAvatar() const {
|
||||
return Avatar.size() > 0 && Avatar[0] == 'a' && Avatar[1] == '_';
|
||||
}
|
||||
|
||||
std::string User::GetAvatarURL(std::string ext, std::string size) const {
|
||||
std::string UserData::GetAvatarURL(std::string ext, std::string size) const {
|
||||
return "https://cdn.discordapp.com/avatars/" + std::to_string(ID) + "/" + Avatar + "." + ext + "?size=" + size;
|
||||
}
|
||||
|
||||
Snowflake User::GetHoistedRole(Snowflake guild_id, bool with_color) const {
|
||||
Snowflake UserData::GetHoistedRole(Snowflake guild_id, bool with_color) const {
|
||||
return Abaddon::Get().GetDiscordClient().GetMemberHoistedRole(guild_id, ID, with_color);
|
||||
}
|
||||
|
||||
std::string User::GetMention() const {
|
||||
std::string UserData::GetMention() const {
|
||||
return "<@" + std::to_string(ID) + ">";
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json &j, User &m) {
|
||||
void from_json(const nlohmann::json &j, UserData &m) {
|
||||
JS_D("id", m.ID);
|
||||
JS_D("username", m.Username);
|
||||
JS_D("discriminator", m.Discriminator);
|
||||
@@ -41,7 +41,7 @@ void from_json(const nlohmann::json &j, User &m) {
|
||||
JS_ON("phone", m.Phone);
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json &j, const User &m) {
|
||||
void to_json(nlohmann::json &j, const UserData &m) {
|
||||
j["id"] = m.ID;
|
||||
j["username"] = m.Username;
|
||||
j["discriminator"] = m.Discriminator;
|
||||
@@ -64,7 +64,7 @@ void to_json(nlohmann::json &j, const User &m) {
|
||||
JS_IF("phone", m.Phone);
|
||||
}
|
||||
|
||||
void User::update_from_json(const nlohmann::json &j, User &m) {
|
||||
void UserData::update_from_json(const nlohmann::json &j, UserData &m) {
|
||||
JS_RD("username", m.Username);
|
||||
JS_RD("discriminator", m.Discriminator);
|
||||
JS_RD("avatar", m.Avatar);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "json.hpp"
|
||||
#include <string>
|
||||
|
||||
struct User {
|
||||
struct UserData {
|
||||
Snowflake ID;
|
||||
std::string Username;
|
||||
std::string Discriminator;
|
||||
@@ -24,9 +24,9 @@ struct User {
|
||||
std::optional<bool> IsNSFWAllowed; // null
|
||||
std::optional<std::string> Phone; // null?
|
||||
|
||||
friend void from_json(const nlohmann::json &j, User &m);
|
||||
friend void to_json(nlohmann::json &j, const User &m);
|
||||
static void update_from_json(const nlohmann::json &j, User &m);
|
||||
friend void from_json(const nlohmann::json &j, UserData &m);
|
||||
friend void to_json(nlohmann::json &j, const UserData &m);
|
||||
static void update_from_json(const nlohmann::json &j, UserData &m);
|
||||
|
||||
bool HasAvatar() const;
|
||||
bool HasAnimatedAvatar() const;
|
||||
|
||||
Reference in New Issue
Block a user