From 0a0cff51b27ce35c4fa5d8fd56f60d2b7a89c90a Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Sun, 3 Aug 2025 03:23:26 +0300 Subject: Moved inline bot handling to a new file --- src/main.zig | 60 +++--------------------------------------------------------- 1 file changed, 3 insertions(+), 57 deletions(-) (limited to 'src/main.zig') diff --git a/src/main.zig b/src/main.zig index d534296..942fd90 100644 --- a/src/main.zig +++ b/src/main.zig @@ -8,6 +8,8 @@ const Bot = @import("Bot.zig"); const Config = @import("Config.zig"); const GPA = std.heap.GeneralPurposeAllocator(.{}); +const onInlineBot = @import("inline_bots.zig").onInlineBot; + pub fn main() !void { defer std.log.info("We're done", .{}); @@ -102,65 +104,9 @@ fn wrappedMain(bot: *Bot) !void { }); } -const allowed_inline_bots = [_]i64{ - 90832338, // @vid - 109158646, // @bing - 114528005, // @pic - 136269978, // @ImageFetcherBot - 140267078, // @gif - 154595593, // @wiki - 184730458, // @UnitConversionBot - 223493268, // @minroobot - 296635833, // @lastfmrobot - 473587803, // @LyBot - 595898211, // @DeezerMusicBot - 733460033, // @crabravebot - 870410041, // @HowGayBot - 7904498194, // @tanstiktokbot -}; - -const disallowed_inline_bots = [_]i64{ - 6465471545, // @DickGrowerBot - 7759097490, // @CookieGrowerBot -}; - -inline fn isSorted(arr: []const i64) bool { - return std.sort.isSorted(i64, arr, {}, std.sort.asc(i64)); -} - -comptime { - std.testing.expect(isSorted(&allowed_inline_bots)) catch unreachable; - std.testing.expect(isSorted(&disallowed_inline_bots)) catch unreachable; -} - -fn orderI64(a: i64, b: i64) std.math.Order { - return std.math.order(a, b); -} - -inline fn isIn(val: i64, arr: []const i64) bool { - return std.sort.binarySearch(i64, arr, val, orderI64) != null; -} - fn onMessage(bot: *Bot, msg: types.Message) !void { if (msg.via_bot) |via| { - if (!isIn(via.id, &allowed_inline_bots)) { - std.log.info("Deleting an unallowed inline bot message from {?s} {}", .{ via.username, via.id }); - try bot.deleteMessage(.{ - .chat_id = msg.chat.id, - .message_id = msg.message_id, - }); - - if (!isIn(via.id, &disallowed_inline_bots)) { - // Notify dev group, perhaps this bot should be allowed? - const text = try std.fmt.allocPrint(bot.allocator, "Deleted a message sent by inline bot @{?s} {}", .{ via.username, via.id }); - defer bot.allocator.free(text); - - try bot.sendMessage_(.{ - .chat_id = bot.config.dev_group, - .text = text, - .parse_mode = .html, - }); - } + if (!try onInlineBot(bot, msg, via)) { return; } } -- cgit v1.2.3