diff options
Diffstat (limited to 'src/inline_bots.zig')
| -rw-r--r-- | src/inline_bots.zig | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/inline_bots.zig b/src/inline_bots.zig new file mode 100644 index 0000000..c6fa2b7 --- /dev/null +++ b/src/inline_bots.zig | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | const std = @import("std"); | ||
| 2 | const types = @import("types.zig"); | ||
| 3 | const utils = @import("utils.zig"); | ||
| 4 | |||
| 5 | const Bot = @import("Bot.zig"); | ||
| 6 | |||
| 7 | const whitelist = [_]i64{ | ||
| 8 | 90832338, // @vid | ||
| 9 | 109158646, // @bing | ||
| 10 | 114528005, // @pic | ||
| 11 | 136269978, // @ImageFetcherBot | ||
| 12 | 140267078, // @gif | ||
| 13 | 154595593, // @wiki | ||
| 14 | 184730458, // @UnitConversionBot | ||
| 15 | 223493268, // @minroobot | ||
| 16 | 296635833, // @lastfmrobot | ||
| 17 | 473587803, // @LyBot | ||
| 18 | 595898211, // @DeezerMusicBot | ||
| 19 | 733460033, // @crabravebot | ||
| 20 | 870410041, // @HowGayBot | ||
| 21 | 7904498194, // @tanstiktokbot | ||
| 22 | }; | ||
| 23 | |||
| 24 | const blacklist = [_]i64{ | ||
| 25 | 6465471545, // @DickGrowerBot | ||
| 26 | 7759097490, // @CookieGrowerBot | ||
| 27 | }; | ||
| 28 | |||
| 29 | comptime { | ||
| 30 | std.testing.expect(utils.isSorted(i64, &whitelist)) catch unreachable; | ||
| 31 | std.testing.expect(utils.isSorted(i64, &blacklist)) catch unreachable; | ||
| 32 | } | ||
| 33 | |||
| 34 | inline fn isWhitelisted(bot: types.User) bool { | ||
| 35 | return utils.isIn(i64, bot.id, &whitelist); | ||
| 36 | } | ||
| 37 | |||
| 38 | inline fn isBlacklisted(bot: types.User) bool { | ||
| 39 | return utils.isIn(i64, bot.id, &blacklist); | ||
| 40 | } | ||
| 41 | |||
| 42 | // Returns true if processing of message should continue | ||
| 43 | pub fn onInlineBot(bot: *Bot, msg: types.Message, via: types.User) !bool { | ||
| 44 | if (isWhitelisted(via)) { | ||
| 45 | return true; | ||
| 46 | } | ||
| 47 | |||
| 48 | std.log.info("Deleting an unallowed inline bot message from {?s} {}", .{ via.username, via.id }); | ||
| 49 | try bot.deleteMessage(.{ | ||
| 50 | .chat_id = msg.chat.id, | ||
| 51 | .message_id = msg.message_id, | ||
| 52 | }); | ||
| 53 | |||
| 54 | if (!isBlacklisted(via)) { | ||
| 55 | // Not explicitly blacklisted, notify dev group | ||
| 56 | const text = try std.fmt.allocPrint( | ||
| 57 | bot.allocator, | ||
| 58 | "Deleted a message sent via inline bot @{?s} <code>{}</code>", | ||
| 59 | .{ via.username, via.id }, | ||
| 60 | ); | ||
| 61 | defer bot.allocator.free(text); | ||
| 62 | |||
| 63 | try bot.sendMessage_(.{ | ||
| 64 | .chat_id = bot.config.dev_group, | ||
| 65 | .text = text, | ||
| 66 | .parse_mode = .html, | ||
| 67 | }); | ||
| 68 | } | ||
| 69 | |||
| 70 | return false; | ||
| 71 | } | ||