From e5185f65051f881bf61e88542a1acd4957f8383b Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Sun, 3 Aug 2025 12:54:12 +0300 Subject: Move bot configuration to SQL land --- src/inline_bots.zig | 60 ++++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 33 deletions(-) (limited to 'src/inline_bots.zig') 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"); const Bot = @import("Bot.zig"); -const whitelist = [_]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 blacklist = [_]i64{ - 6465471545, // @DickGrowerBot - 7759097490, // @CookieGrowerBot -}; - -comptime { - std.testing.expect(utils.isSorted(i64, &whitelist)) catch unreachable; - std.testing.expect(utils.isSorted(i64, &blacklist)) catch unreachable; +pub inline fn blacklistBot(bot: *Bot, inline_bot_id: i64) !void { + return bot.db.setInlineBotType(inline_bot_id, .blacklisted); } -inline fn isWhitelisted(bot: types.User) bool { - return utils.isIn(i64, bot.id, &whitelist); -} - -inline fn isBlacklisted(bot: types.User) bool { - return utils.isIn(i64, bot.id, &blacklist); +pub inline fn whitelistBot(bot: *Bot, inline_bot_id: i64) !void { + return bot.db.setInlineBotType(inline_bot_id, .whitelisted); } // Returns true if processing of message should continue pub fn onInlineBot(bot: *Bot, msg: types.Message, via: types.User) !bool { - if (isWhitelisted(via)) { + const ty = try bot.db.getInlineBotType(via.id); + if (ty == .whitelisted) { return true; } @@ -51,7 +25,7 @@ pub fn onInlineBot(bot: *Bot, msg: types.Message, via: types.User) !bool { .message_id = msg.message_id, }); - if (!isBlacklisted(via)) { + if (ty != .blacklisted) { // Not explicitly blacklisted, notify dev group const text = try std.fmt.allocPrint( bot.allocator, @@ -60,10 +34,30 @@ pub fn onInlineBot(bot: *Bot, msg: types.Message, via: types.User) !bool { ); defer bot.allocator.free(text); + const whitelist_cb = try std.fmt.allocPrint( + bot.allocator, + "bwl:{}", + .{ via.id }, + ); + defer bot.allocator.free(whitelist_cb); + + const blacklist_cb = try std.fmt.allocPrint( + bot.allocator, + "bbl:{}", + .{ via.id }, + ); + defer bot.allocator.free(blacklist_cb); + try bot.sendMessage_(.{ .chat_id = bot.config.dev_group, .text = text, .parse_mode = .html, + .reply_markup = .{ + .inline_keyboard = &.{&.{ + .{ .text = "Whitelist", .callback_data = whitelist_cb }, + .{ .text = "Blacklist", .callback_data = blacklist_cb }, + }}, + }, }); } -- cgit v1.2.3