diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-04-13 16:29:56 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-04-13 16:29:56 -0400 |
commit | c084230767053e942b29941a8728f421e256cf1d (patch) | |
tree | ae58dc5d3978930ec5ed1fb0e65d108b56369d42 /src/discord/store.cpp | |
parent | 7b5dc8a86532cf00ab49a1922dbd4ce21cdaf01f (diff) | |
parent | 44ab35dfd591c4c357673cc2ce3cb3a6964a1fff (diff) | |
download | abaddon-portaudio-c084230767053e942b29941a8728f421e256cf1d.tar.gz abaddon-portaudio-c084230767053e942b29941a8728f421e256cf1d.zip |
Merge branch 'master' of https://github.com/uowuo/abaddon into voice
Diffstat (limited to 'src/discord/store.cpp')
-rw-r--r-- | src/discord/store.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/discord/store.cpp b/src/discord/store.cpp index 7f674c4..41b2069 100644 --- a/src/discord/store.cpp +++ b/src/discord/store.cpp @@ -346,6 +346,15 @@ void Store::SetMessage(Snowflake id, const Message &message) { s->Reset(); } + for (const auto &r : message.MentionRoles) { + auto &s = m_stmt_set_role_mention; + s->Bind(1, id); + s->Bind(2, r); + if (!s->Insert()) + fprintf(stderr, "message role mention insert failed for %" PRIu64 "/%" PRIu64 ": %s\n", static_cast<uint64_t>(id), static_cast<uint64_t>(r), m_db.ErrStr()); + s->Reset(); + } + for (const auto &a : message.Attachments) { auto &s = m_stmt_set_attachment; s->Bind(1, id); @@ -779,6 +788,7 @@ std::optional<GuildData> Store::GetGuild(Snowflake id) const { s->Get(1, r.Name); s->Get(2, r.Icon); s->Get(5, r.OwnerID); + s->Get(11, r.DefaultMessageNotifications); s->Get(20, r.IsUnavailable); s->Get(27, r.PremiumTier); @@ -987,6 +997,17 @@ Message Store::GetMessageBound(std::unique_ptr<Statement> &s) const { } { + auto &s = m_stmt_get_role_mentions; + s->Bind(1, r.ID); + while (s->FetchOne()) { + Snowflake id; + s->Get(0, id); + r.MentionRoles.push_back(id); + } + s->Reset(); + } + + { auto &s = m_stmt_get_reactions; s->Bind(1, r.ID); std::map<size_t, ReactionData> tmp; @@ -1436,6 +1457,14 @@ bool Store::CreateTables() { ) )"; + const char *create_mention_roles = R"( + CREATE TABLE IF NOT EXISTS mention_roles ( + message INTEGER NOT NULL, + role INTEGER NOT NULL, + PRIMARY KEY(message, role) + ) + )"; + const char *create_attachments = R"( CREATE TABLE IF NOT EXISTS attachments ( message INTEGER NOT NULL, @@ -1555,6 +1584,11 @@ bool Store::CreateTables() { return false; } + if (m_db.Execute(create_mention_roles) != SQLITE_OK) { + fprintf(stderr, "failed to create role mentions table: %s\n", m_db.ErrStr()); + return false; + } + if (m_db.Execute(create_attachments) != SQLITE_OK) { fprintf(stderr, "failed to create attachments table: %s\n", m_db.ErrStr()); return false; @@ -2118,6 +2152,24 @@ bool Store::CreateStatements() { return false; } + m_stmt_set_role_mention = std::make_unique<Statement>(m_db, R"( + REPLACE INTO mention_roles VALUES ( + ?, ? + ) + )"); + if (!m_stmt_set_role_mention->OK()) { + fprintf(stderr, "failed to prepare set role mention statement: %s\n", m_db.ErrStr()); + return false; + } + + m_stmt_get_role_mentions = std::make_unique<Statement>(m_db, R"( + SELECT role FROM mention_roles WHERE message = ? + )"); + if (!m_stmt_get_role_mentions->OK()) { + fprintf(stderr, "failed to prepare get role mentions statement: %s\n", m_db.ErrStr()); + return false; + } + m_stmt_set_attachment = std::make_unique<Statement>(m_db, R"( REPLACE INTO attachments VALUES ( ?, ?, ?, ?, ?, ?, ?, ? |