summaryrefslogtreecommitdiff
path: root/discord/store.cpp
blob: fb0bec1d6494650e1a600f1c8efecdb1d7bbb6fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "store.hpp"

void Store::SetUser(Snowflake id, const User &user) {
    m_users[id] = user;
}

void Store::SetChannel(Snowflake id, const Channel &channel) {
    m_channels[id] = channel;
}

void Store::SetGuild(Snowflake id, const Guild &guild) {
    m_guilds[id] = guild;
}

void Store::SetRole(Snowflake id, const Role &role) {
    m_roles[id] = role;
}

void Store::SetMessage(Snowflake id, const Message &message) {
    m_messages[id] = message;
}

void Store::SetGuildMemberData(Snowflake guild_id, Snowflake user_id, const GuildMember &data) {
    m_members[guild_id][user_id] = data;
}

User *Store::GetUser(Snowflake id) {
    auto it = m_users.find(id);
    if (it == m_users.end())
        return nullptr;
    return &it->second;
}

const User *Store::GetUser(Snowflake id) const {
    auto it = m_users.find(id);
    if (it == m_users.end())
        return nullptr;
    return &it->second;
}

Channel *Store::GetChannel(Snowflake id) {
    auto it = m_channels.find(id);
    if (it == m_channels.end())
        return nullptr;
    return &it->second;
}

const Channel *Store::GetChannel(Snowflake id) const {
    auto it = m_channels.find(id);
    if (it == m_channels.end())
        return nullptr;
    return &it->second;
}

Guild *Store::GetGuild(Snowflake id) {
    auto it = m_guilds.find(id);
    if (it == m_guilds.end())
        return nullptr;
    return &it->second;
}

const Guild *Store::GetGuild(Snowflake id) const {
    auto it = m_guilds.find(id);
    if (it == m_guilds.end())
        return nullptr;
    return &it->second;
}

Role *Store::GetRole(Snowflake id) {
    auto it = m_roles.find(id);
    if (it == m_roles.end())
        return nullptr;
    return &it->second;
}

const Role *Store::GetRole(Snowflake id) const {
    auto it = m_roles.find(id);
    if (it == m_roles.end())
        return nullptr;
    return &it->second;
}

Message *Store::GetMessage(Snowflake id) {
    auto it = m_messages.find(id);
    if (it == m_messages.end())
        return nullptr;
    return &it->second;
}

const Message *Store::GetMessage(Snowflake id) const {
    auto it = m_messages.find(id);
    if (it == m_messages.end())
        return nullptr;
    return &it->second;
}

GuildMember *Store::GetGuildMemberData(Snowflake guild_id, Snowflake user_id) {
    auto git = m_members.find(guild_id);
    if (git == m_members.end())
        return nullptr;
    auto mit = git->second.find(user_id);
    if (mit == git->second.end())
        return nullptr;
    return &mit->second;
}

const GuildMember *Store::GetGuildMemberData(Snowflake guild_id, Snowflake user_id) const {
    auto git = m_members.find(guild_id);
    if (git == m_members.end())
        return nullptr;
    auto mit = git->second.find(user_id);
    if (mit == git->second.end())
        return nullptr;
    return &mit->second;
}

const Store::channels_type &Store::GetChannels() const {
    return m_channels;
}

const Store::guilds_type &Store::GetGuilds() const {
    return m_guilds;
}

void Store::ClearAll() {
    m_channels.clear();
    m_guilds.clear();
    m_messages.clear();
    m_roles.clear();
    m_users.clear();
}