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
66
67
68
69
70
71
|
const std = @import("std");
const types = @import("types.zig");
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;
}
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);
}
// Returns true if processing of message should continue
pub fn onInlineBot(bot: *Bot, msg: types.Message, via: types.User) !bool {
if (isWhitelisted(via)) {
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 (!isBlacklisted(via)) {
// 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);
try bot.sendMessage_(.{
.chat_id = bot.config.dev_group,
.text = text,
.parse_mode = .html,
});
}
return false;
}
|