summaryrefslogtreecommitdiff
path: root/src/discord/store.cpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-11-28 22:42:55 -0500
committerouwou <26526779+ouwou@users.noreply.github.com>2021-11-28 22:42:55 -0500
commite02107feea8214a045e6faa969f00dcbc0d2b072 (patch)
tree1be2da1e6704dbc2b8fe4f40047b24d09d2a936f /src/discord/store.cpp
parent192b043e7ac60bb06fbb25b2e46ef096b48c16fd (diff)
downloadabaddon-portaudio-e02107feea8214a045e6faa969f00dcbc0d2b072.tar.gz
abaddon-portaudio-e02107feea8214a045e6faa969f00dcbc0d2b072.zip
actually retrieve roles for guilds
FetchRoles isnt needed anymore cuz full roles are fetched now
Diffstat (limited to 'src/discord/store.cpp')
-rw-r--r--src/discord/store.cpp30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/discord/store.cpp b/src/discord/store.cpp
index 63fb5f7..1cb7231 100644
--- a/src/discord/store.cpp
+++ b/src/discord/store.cpp
@@ -765,6 +765,16 @@ std::optional<GuildData> Store::GetGuild(Snowflake id) const {
s->Reset();
}
+ {
+ auto &s = m_stmt_get_guild_roles;
+ s->Bind(1, id);
+ r.Roles.emplace();
+ while (s->FetchOne()) {
+ r.Roles->push_back(GetRoleBound(s));
+ }
+ s->Reset();
+ }
+
return r;
}
@@ -961,9 +971,17 @@ std::optional<RoleData> Store::GetRole(Snowflake id) const {
return {};
}
+ auto role = GetRoleBound(s);
+
+ s->Reset();
+
+ return role;
+}
+
+RoleData Store::GetRoleBound(std::unique_ptr<Statement> &s) const {
RoleData r;
- r.ID = id;
+ s->Get(0, r.ID);
//s->Get(1, guild id);
s->Get(2, r.Name);
s->Get(3, r.Color);
@@ -973,8 +991,6 @@ std::optional<RoleData> Store::GetRole(Snowflake id) const {
s->Get(7, r.IsManaged);
s->Get(8, r.IsMentionable);
- s->Reset();
-
return r;
}
@@ -1726,6 +1742,14 @@ bool Store::CreateStatements() {
return false;
}
+ m_stmt_get_guild_roles = std::make_unique<Statement>(m_db, R"(
+ SELECT * FROM roles WHERE guild = ?
+ )");
+ if (!m_stmt_get_guild_roles->OK()) {
+ fprintf(stderr, "failed to prepare get guild roles statement: %s\n", m_db.ErrStr());
+ return false;
+ }
+
m_stmt_set_emoji = std::make_unique<Statement>(m_db, R"(
REPLACE INTO emojis VALUES (
?, ?, ?, ?, ?, ?, ?