summaryrefslogtreecommitdiff
path: root/src/inline_bots.zig
diff options
context:
space:
mode:
authorGravatar Uko Kokņevičs2025-08-03 03:23:26 +0300
committerGravatar Uko Kokņevičs2025-08-03 03:23:26 +0300
commit0a0cff51b27ce35c4fa5d8fd56f60d2b7a89c90a (patch)
tree6724a6204584153044301489a6dae364886c7867 /src/inline_bots.zig
parentAdd @crabravebot to the list of allowed inline bots (diff)
downloadukkobot-0a0cff51b27ce35c4fa5d8fd56f60d2b7a89c90a.tar.gz
ukkobot-0a0cff51b27ce35c4fa5d8fd56f60d2b7a89c90a.tar.xz
ukkobot-0a0cff51b27ce35c4fa5d8fd56f60d2b7a89c90a.zip
Moved inline bot handling to a new file
Diffstat (limited to 'src/inline_bots.zig')
-rw-r--r--src/inline_bots.zig71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/inline_bots.zig b/src/inline_bots.zig
new file mode 100644
index 0000000..c6fa2b7
--- /dev/null
+++ b/src/inline_bots.zig
@@ -0,0 +1,71 @@
1const std = @import("std");
2const types = @import("types.zig");
3const utils = @import("utils.zig");
4
5const Bot = @import("Bot.zig");
6
7const whitelist = [_]i64{
8 90832338, // @vid
9 109158646, // @bing
10 114528005, // @pic
11 136269978, // @ImageFetcherBot
12 140267078, // @gif
13 154595593, // @wiki
14 184730458, // @UnitConversionBot
15 223493268, // @minroobot
16 296635833, // @lastfmrobot
17 473587803, // @LyBot
18 595898211, // @DeezerMusicBot
19 733460033, // @crabravebot
20 870410041, // @HowGayBot
21 7904498194, // @tanstiktokbot
22};
23
24const blacklist = [_]i64{
25 6465471545, // @DickGrowerBot
26 7759097490, // @CookieGrowerBot
27};
28
29comptime {
30 std.testing.expect(utils.isSorted(i64, &whitelist)) catch unreachable;
31 std.testing.expect(utils.isSorted(i64, &blacklist)) catch unreachable;
32}
33
34inline fn isWhitelisted(bot: types.User) bool {
35 return utils.isIn(i64, bot.id, &whitelist);
36}
37
38inline fn isBlacklisted(bot: types.User) bool {
39 return utils.isIn(i64, bot.id, &blacklist);
40}
41
42// Returns true if processing of message should continue
43pub fn onInlineBot(bot: *Bot, msg: types.Message, via: types.User) !bool {
44 if (isWhitelisted(via)) {
45 return true;
46 }
47
48 std.log.info("Deleting an unallowed inline bot message from {?s} {}", .{ via.username, via.id });
49 try bot.deleteMessage(.{
50 .chat_id = msg.chat.id,
51 .message_id = msg.message_id,
52 });
53
54 if (!isBlacklisted(via)) {
55 // Not explicitly blacklisted, notify dev group
56 const text = try std.fmt.allocPrint(
57 bot.allocator,
58 "Deleted a message sent via inline bot @{?s} <code>{}</code>",
59 .{ via.username, via.id },
60 );
61 defer bot.allocator.free(text);
62
63 try bot.sendMessage_(.{
64 .chat_id = bot.config.dev_group,
65 .text = text,
66 .parse_mode = .html,
67 });
68 }
69
70 return false;
71}