diff options
| author | ilotterytea <iltsu@alright.party> | 2024-05-16 21:58:52 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2024-05-16 21:58:52 +0500 |
| commit | 4ebfa4f82679b5edafca70b2da1646d5d1b2decc (patch) | |
| tree | a7fb2a89954cb23a712816d491b2a3163668ffcd /src | |
| parent | 49e41eaff5c219e4e8452188f19974bf019c33e4 (diff) | |
upd: send nothing if the channel is opted out
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands/request_util.cpp | 5 | ||||
| -rw-r--r-- | src/stream.cpp | 11 | ||||
| -rw-r--r-- | src/timer.cpp | 8 |
3 files changed, 17 insertions, 7 deletions
diff --git a/src/commands/request_util.cpp b/src/commands/request_util.cpp index 3d44054..90750e5 100644 --- a/src/commands/request_util.cpp +++ b/src/commands/request_util.cpp @@ -65,6 +65,11 @@ namespace bot::command { schemas::Channel channel(query[0]); + if (channel.get_opted_out_at().has_value()) { + delete work; + return std::nullopt; + } + query = work->exec("SELECT * FROM channel_preferences WHERE channel_id = " + std::to_string(channel.get_id())); diff --git a/src/stream.cpp b/src/stream.cpp index 4868995..ad7df68 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -87,9 +87,14 @@ namespace bot::stream { " AND target_alias_id = " + std::to_string(stream.user_id)); for (const auto &event : events) { - pqxx::row channel = - work.exec1("SELECT alias_id, alias_name FROM channels WHERE id = " + - std::to_string(event[1].as<int>())); + pqxx::row channel = work.exec1( + "SELECT alias_id, alias_name, opted_out_at FROM channels WHERE id " + "= " + + std::to_string(event[1].as<int>())); + + if (!channel[2].is_null()) { + continue; + } pqxx::result subs = work.exec( "SELECT user_id FROM event_subscriptions WHERE event_id = " + diff --git a/src/timer.cpp b/src/timer.cpp index ccdf176..055dde0 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -38,11 +38,11 @@ namespace bot { now - last_executed_at); if (difference.count() > interval_sec) { - pqxx::result channels = - work->exec("SELECT alias_name FROM channels WHERE id = " + - std::to_string(channel_id)); + pqxx::result channels = work->exec( + "SELECT alias_name, opted_out_at FROM channels WHERE id = " + + std::to_string(channel_id)); - if (!channels.empty()) { + if (!channels.empty() && channels[0][1].is_null()) { std::string alias_name = channels[0][0].as<std::string>(); irc_client->say(alias_name, message); |
