diff options
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 60 |
1 files changed, 3 insertions, 57 deletions
diff --git a/src/main.zig b/src/main.zig index d534296..942fd90 100644 --- a/src/main.zig +++ b/src/main.zig | |||
| @@ -8,6 +8,8 @@ const Bot = @import("Bot.zig"); | |||
| 8 | const Config = @import("Config.zig"); | 8 | const Config = @import("Config.zig"); |
| 9 | const GPA = std.heap.GeneralPurposeAllocator(.{}); | 9 | const GPA = std.heap.GeneralPurposeAllocator(.{}); |
| 10 | 10 | ||
| 11 | const onInlineBot = @import("inline_bots.zig").onInlineBot; | ||
| 12 | |||
| 11 | pub fn main() !void { | 13 | pub fn main() !void { |
| 12 | defer std.log.info("We're done", .{}); | 14 | defer std.log.info("We're done", .{}); |
| 13 | 15 | ||
| @@ -102,65 +104,9 @@ fn wrappedMain(bot: *Bot) !void { | |||
| 102 | }); | 104 | }); |
| 103 | } | 105 | } |
| 104 | 106 | ||
| 105 | const allowed_inline_bots = [_]i64{ | ||
| 106 | 90832338, // @vid | ||
| 107 | 109158646, // @bing | ||
| 108 | 114528005, // @pic | ||
| 109 | 136269978, // @ImageFetcherBot | ||
| 110 | 140267078, // @gif | ||
| 111 | 154595593, // @wiki | ||
| 112 | 184730458, // @UnitConversionBot | ||
| 113 | 223493268, // @minroobot | ||
| 114 | 296635833, // @lastfmrobot | ||
| 115 | 473587803, // @LyBot | ||
| 116 | 595898211, // @DeezerMusicBot | ||
| 117 | 733460033, // @crabravebot | ||
| 118 | 870410041, // @HowGayBot | ||
| 119 | 7904498194, // @tanstiktokbot | ||
| 120 | }; | ||
| 121 | |||
| 122 | const disallowed_inline_bots = [_]i64{ | ||
| 123 | 6465471545, // @DickGrowerBot | ||
| 124 | 7759097490, // @CookieGrowerBot | ||
| 125 | }; | ||
| 126 | |||
| 127 | inline fn isSorted(arr: []const i64) bool { | ||
| 128 | return std.sort.isSorted(i64, arr, {}, std.sort.asc(i64)); | ||
| 129 | } | ||
| 130 | |||
| 131 | comptime { | ||
| 132 | std.testing.expect(isSorted(&allowed_inline_bots)) catch unreachable; | ||
| 133 | std.testing.expect(isSorted(&disallowed_inline_bots)) catch unreachable; | ||
| 134 | } | ||
| 135 | |||
| 136 | fn orderI64(a: i64, b: i64) std.math.Order { | ||
| 137 | return std.math.order(a, b); | ||
| 138 | } | ||
| 139 | |||
| 140 | inline fn isIn(val: i64, arr: []const i64) bool { | ||
| 141 | return std.sort.binarySearch(i64, arr, val, orderI64) != null; | ||
| 142 | } | ||
| 143 | |||
| 144 | fn onMessage(bot: *Bot, msg: types.Message) !void { | 107 | fn onMessage(bot: *Bot, msg: types.Message) !void { |
| 145 | if (msg.via_bot) |via| { | 108 | if (msg.via_bot) |via| { |
| 146 | if (!isIn(via.id, &allowed_inline_bots)) { | 109 | if (!try onInlineBot(bot, msg, via)) { |
| 147 | std.log.info("Deleting an unallowed inline bot message from {?s} {}", .{ via.username, via.id }); | ||
| 148 | try bot.deleteMessage(.{ | ||
| 149 | .chat_id = msg.chat.id, | ||
| 150 | .message_id = msg.message_id, | ||
| 151 | }); | ||
| 152 | |||
| 153 | if (!isIn(via.id, &disallowed_inline_bots)) { | ||
| 154 | // Notify dev group, perhaps this bot should be allowed? | ||
| 155 | const text = try std.fmt.allocPrint(bot.allocator, "Deleted a message sent by inline bot @{?s} <code>{}</code>", .{ via.username, via.id }); | ||
| 156 | defer bot.allocator.free(text); | ||
| 157 | |||
| 158 | try bot.sendMessage_(.{ | ||
| 159 | .chat_id = bot.config.dev_group, | ||
| 160 | .text = text, | ||
| 161 | .parse_mode = .html, | ||
| 162 | }); | ||
| 163 | } | ||
| 164 | return; | 110 | return; |
| 165 | } | 111 | } |
| 166 | } | 112 | } |