const std = @import("std"); const types = @import("types.zig"); const utils = @import("utils.zig"); const Bot = @import("Bot.zig"); pub inline fn blacklistBot(bot: *Bot, inline_bot_id: i64) !void { return bot.db.setInlineBotType(inline_bot_id, .blacklisted); } 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 { const ty = try bot.db.getInlineBotType(via.id); if (ty == .whitelisted) { return true; } 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 (ty != .blacklisted) { // Not explicitly blacklisted, notify dev group const text = try std.fmt.allocPrint( bot.allocator, "Deleted a message sent via inline bot @{?s} {}", .{ via.username, via.id }, ); 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 }, }}, }, }); } return false; }