diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-03-16 20:27:59 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-03-16 20:27:59 -0400 |
commit | b83bf2a622ecfb667cc89909ebae9180ed5ac117 (patch) | |
tree | 5e4ec1fc115f403bb61e57688eb79235d007a8de /src/discord/store.cpp | |
parent | 0e1e15eaeb662ae0f078428af84f3720d48a5b24 (diff) | |
download | abaddon-portaudio-b83bf2a622ecfb667cc89909ebae9180ed5ac117.tar.gz abaddon-portaudio-b83bf2a622ecfb667cc89909ebae9180ed5ac117.zip |
handle role mentions
Diffstat (limited to 'src/discord/store.cpp')
-rw-r--r-- | src/discord/store.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/discord/store.cpp b/src/discord/store.cpp index 8393322..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); @@ -988,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; @@ -1437,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, @@ -1556,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; @@ -2119,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 ( ?, ?, ?, ?, ?, ?, ?, ? |