summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Uko Kokņevičs2025-07-22 14:42:51 +0300
committerGravatar Uko Kokņevičs2025-07-22 14:42:51 +0300
commit99b28a0aa7cb136c3f83d9e5d85160d36fa3c78e (patch)
tree08f4b68500e99fd059ff6c2f9bea7bb6cd53e544
parentAdd more allowed bots (diff)
downloadukkobot-99b28a0aa7cb136c3f83d9e5d85160d36fa3c78e.tar.gz
ukkobot-99b28a0aa7cb136c3f83d9e5d85160d36fa3c78e.tar.xz
ukkobot-99b28a0aa7cb136c3f83d9e5d85160d36fa3c78e.zip
Add disallowed bots that don't notify devgroup
-rw-r--r--src/main.zig46
1 files changed, 24 insertions, 22 deletions
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{
118 7904498194, // @tanstiktokbot 118 7904498194, // @tanstiktokbot
119}; 119};
120 120
121const disallowed_inline_bots = [_]i64{
122 6465471545, // @DickGrowerBot
123 7759097490, // @CookieGrowerBot
124};
125
126inline fn isSorted(arr: []const i64) bool {
127 return std.sort.isSorted(i64, arr, {}, std.sort.asc(i64));
128}
129
121comptime { 130comptime {
122 std.testing.expect(std.sort.isSorted( 131 std.testing.expect(isSorted(&allowed_inline_bots)) catch unreachable;
123 i64, 132 std.testing.expect(isSorted(&disallowed_inline_bots)) catch unreachable;
124 &allowed_inline_bots,
125 {},
126 std.sort.asc(i64),
127 )) catch unreachable;
128} 133}
129 134
130fn orderI64(a: i64, b: i64) std.math.Order { 135fn orderI64(a: i64, b: i64) std.math.Order {
131 return std.math.order(a, b); 136 return std.math.order(a, b);
132} 137}
133 138
134fn isAllowedInlineBot(id: i64) bool { 139inline fn isIn(val: i64, arr: []const i64) bool {
135 return std.sort.binarySearch( 140 return std.sort.binarySearch(i64, arr, val, orderI64) != null;
136 i64,
137 &allowed_inline_bots,
138 id,
139 orderI64,
140 ) != null;
141} 141}
142 142
143fn onMessage(bot: *Bot, msg: types.Message) !void { 143fn onMessage(bot: *Bot, msg: types.Message) !void {
144 if (msg.via_bot) |via| { 144 if (msg.via_bot) |via| {
145 if (!isAllowedInlineBot(via.id)) { 145 if (!isIn(via.id, &allowed_inline_bots)) {
146 std.log.info("Deleting an unallowed inline bot message from {?s} {}", .{ via.username, via.id }); 146 std.log.info("Deleting an unallowed inline bot message from {?s} {}", .{ via.username, via.id });
147 try bot.deleteMessage(.{ 147 try bot.deleteMessage(.{
148 .chat_id = msg.chat.id, 148 .chat_id = msg.chat.id,
149 .message_id = msg.message_id, 149 .message_id = msg.message_id,
150 }); 150 });
151 151
152 const text = try std.fmt.allocPrint(bot.allocator, "Deleted a message sent by inline bot @{?s} <code>{}</code>", .{ via.username, via.id }); 152 if (!isIn(via.id, &disallowed_inline_bots)) {
153 defer bot.allocator.free(text); 153 // Notify dev group, perhaps this bot should be allowed?
154 154 const text = try std.fmt.allocPrint(bot.allocator, "Deleted a message sent by inline bot @{?s} <code>{}</code>", .{ via.username, via.id });
155 try bot.sendMessage_(.{ 155 defer bot.allocator.free(text);
156 .chat_id = bot.config.dev_group,
157 .text = text,
158 .parse_mode = .html,
159 });
160 156
157 try bot.sendMessage_(.{
158 .chat_id = bot.config.dev_group,
159 .text = text,
160 .parse_mode = .html,
161 });
162 }
161 return; 163 return;
162 } 164 }
163 } 165 }