1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
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} <code>{}</code>",
.{ 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;
}
|