summaryrefslogtreecommitdiff
path: root/src/stream.cpp
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2024-05-09 14:54:22 +0500
committerilotterytea <iltsu@alright.party>2024-05-09 14:54:22 +0500
commit124727ef65b66a5b706d29cca5722f36ff545a90 (patch)
treed1b110f46a3d3b6c0388bf08b348ddd2bac56a2f /src/stream.cpp
parent9d81978d4c875899d1493b7047895db8c7528292 (diff)
feat: update ids in stream listener client
Diffstat (limited to 'src/stream.cpp')
-rw-r--r--src/stream.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/stream.cpp b/src/stream.cpp
index 2fa1a34..4868995 100644
--- a/src/stream.cpp
+++ b/src/stream.cpp
@@ -39,6 +39,7 @@ namespace bot::stream {
}
void StreamListenerClient::run() {
while (true) {
+ this->update_channel_ids();
this->check();
std::this_thread::sleep_for(std::chrono::seconds(5));
}
@@ -159,4 +160,25 @@ namespace bot::stream {
conn.close();
}
}
+ void StreamListenerClient::update_channel_ids() {
+ pqxx::connection conn(GET_DATABASE_CONNECTION_URL(this->configuration));
+ pqxx::work work(conn);
+
+ pqxx::result ids =
+ work.exec("SELECT target_alias_id FROM events WHERE event_type < 99");
+
+ for (const auto &row : ids) {
+ int id = row[0].as<int>();
+
+ if (std::any_of(this->ids.begin(), this->ids.end(),
+ [&](const auto &x) { return x == id; })) {
+ continue;
+ }
+
+ this->ids.push_back(id);
+ }
+
+ work.commit();
+ conn.close();
+ }
}