From 99b28a0aa7cb136c3f83d9e5d85160d36fa3c78e Mon Sep 17 00:00:00 2001
From: Uko Kokņevičs
Date: Tue, 22 Jul 2025 14:42:51 +0300
Subject: Add disallowed bots that don't notify devgroup
---
src/main.zig | 46 ++++++++++++++++++++++++----------------------
1 file changed, 24 insertions(+), 22 deletions(-)
(limited to 'src/main.zig')
diff --git a/src/main.zig b/src/main.zig
index 52f9c9c..a29774b 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -118,46 +118,48 @@ const allowed_inline_bots = [_]i64{
7904498194, // @tanstiktokbot
};
+const disallowed_inline_bots = [_]i64{
+ 6465471545, // @DickGrowerBot
+ 7759097490, // @CookieGrowerBot
+};
+
+inline fn isSorted(arr: []const i64) bool {
+ return std.sort.isSorted(i64, arr, {}, std.sort.asc(i64));
+}
+
comptime {
- std.testing.expect(std.sort.isSorted(
- i64,
- &allowed_inline_bots,
- {},
- std.sort.asc(i64),
- )) catch unreachable;
+ std.testing.expect(isSorted(&allowed_inline_bots)) catch unreachable;
+ std.testing.expect(isSorted(&disallowed_inline_bots)) catch unreachable;
}
fn orderI64(a: i64, b: i64) std.math.Order {
return std.math.order(a, b);
}
-fn isAllowedInlineBot(id: i64) bool {
- return std.sort.binarySearch(
- i64,
- &allowed_inline_bots,
- id,
- orderI64,
- ) != null;
+inline fn isIn(val: i64, arr: []const i64) bool {
+ return std.sort.binarySearch(i64, arr, val, orderI64) != null;
}
fn onMessage(bot: *Bot, msg: types.Message) !void {
if (msg.via_bot) |via| {
- if (!isAllowedInlineBot(via.id)) {
+ if (!isIn(via.id, &allowed_inline_bots)) {
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,
});
- const text = try std.fmt.allocPrint(bot.allocator, "Deleted a message sent by inline bot @{?s} {}", .{ via.username, via.id });
- defer bot.allocator.free(text);
-
- try bot.sendMessage_(.{
- .chat_id = bot.config.dev_group,
- .text = text,
- .parse_mode = .html,
- });
+ if (!isIn(via.id, &disallowed_inline_bots)) {
+ // Notify dev group, perhaps this bot should be allowed?
+ const text = try std.fmt.allocPrint(bot.allocator, "Deleted a message sent by inline bot @{?s} {}", .{ via.username, via.id });
+ defer bot.allocator.free(text);
+ try bot.sendMessage_(.{
+ .chat_id = bot.config.dev_group,
+ .text = text,
+ .parse_mode = .html,
+ });
+ }
return;
}
}
--
cgit v1.2.3