summaryrefslogtreecommitdiff
path: root/src/inline_bots.zig
diff options
context:
space:
mode:
authorGravatar Uko Kokņevičs2025-08-03 12:54:12 +0300
committerGravatar Uko Kokņevičs2025-08-03 12:54:12 +0300
commite5185f65051f881bf61e88542a1acd4957f8383b (patch)
treea030a8b32cd13ed6a7d9ed736f8fc626501c2749 /src/inline_bots.zig
parentMoved inline bot handling to a new file (diff)
downloadukkobot-e5185f65051f881bf61e88542a1acd4957f8383b.tar.gz
ukkobot-e5185f65051f881bf61e88542a1acd4957f8383b.tar.xz
ukkobot-e5185f65051f881bf61e88542a1acd4957f8383b.zip
Move bot configuration to SQL land
Diffstat (limited to 'src/inline_bots.zig')
-rw-r--r--src/inline_bots.zig60
1 files changed, 27 insertions, 33 deletions
diff --git a/src/inline_bots.zig b/src/inline_bots.zig
index c6fa2b7..29824eb 100644
--- a/src/inline_bots.zig
+++ b/src/inline_bots.zig
@@ -4,44 +4,18 @@ const utils = @import("utils.zig");
4 4
5const Bot = @import("Bot.zig"); 5const Bot = @import("Bot.zig");
6 6
7const whitelist = [_]i64{ 7pub inline fn blacklistBot(bot: *Bot, inline_bot_id: i64) !void {
8 90832338, // @vid 8 return bot.db.setInlineBotType(inline_bot_id, .blacklisted);
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} 9}
33 10
34inline fn isWhitelisted(bot: types.User) bool { 11pub inline fn whitelistBot(bot: *Bot, inline_bot_id: i64) !void {
35 return utils.isIn(i64, bot.id, &whitelist); 12 return bot.db.setInlineBotType(inline_bot_id, .whitelisted);
36}
37
38inline fn isBlacklisted(bot: types.User) bool {
39 return utils.isIn(i64, bot.id, &blacklist);
40} 13}
41 14
42// Returns true if processing of message should continue 15// Returns true if processing of message should continue
43pub fn onInlineBot(bot: *Bot, msg: types.Message, via: types.User) !bool { 16pub fn onInlineBot(bot: *Bot, msg: types.Message, via: types.User) !bool {
44 if (isWhitelisted(via)) { 17 const ty = try bot.db.getInlineBotType(via.id);
18 if (ty == .whitelisted) {
45 return true; 19 return true;
46 } 20 }
47 21
@@ -51,7 +25,7 @@ pub fn onInlineBot(bot: *Bot, msg: types.Message, via: types.User) !bool {
51 .message_id = msg.message_id, 25 .message_id = msg.message_id,
52 }); 26 });
53 27
54 if (!isBlacklisted(via)) { 28 if (ty != .blacklisted) {
55 // Not explicitly blacklisted, notify dev group 29 // Not explicitly blacklisted, notify dev group
56 const text = try std.fmt.allocPrint( 30 const text = try std.fmt.allocPrint(
57 bot.allocator, 31 bot.allocator,
@@ -60,10 +34,30 @@ pub fn onInlineBot(bot: *Bot, msg: types.Message, via: types.User) !bool {
60 ); 34 );
61 defer bot.allocator.free(text); 35 defer bot.allocator.free(text);
62 36
37 const whitelist_cb = try std.fmt.allocPrint(
38 bot.allocator,
39 "bwl:{}",
40 .{ via.id },
41 );
42 defer bot.allocator.free(whitelist_cb);
43
44 const blacklist_cb = try std.fmt.allocPrint(
45 bot.allocator,
46 "bbl:{}",
47 .{ via.id },
48 );
49 defer bot.allocator.free(blacklist_cb);
50
63 try bot.sendMessage_(.{ 51 try bot.sendMessage_(.{
64 .chat_id = bot.config.dev_group, 52 .chat_id = bot.config.dev_group,
65 .text = text, 53 .text = text,
66 .parse_mode = .html, 54 .parse_mode = .html,
55 .reply_markup = .{
56 .inline_keyboard = &.{&.{
57 .{ .text = "Whitelist", .callback_data = whitelist_cb },
58 .{ .text = "Blacklist", .callback_data = blacklist_cb },
59 }},
60 },
67 }); 61 });
68 } 62 }
69 63