MyrTheMoth / Guard-Bot-Plugins

A collection of plug-ins for Telegram Group Administration Bot, Guard Bot.
MIT License
10 stars 4 forks source link

issue with captcha crashing #1

Open Mrs-Feathers opened 2 years ago

Mrs-Feathers commented 2 years ago

Hello! the issue i'm having with this code is that it crashes the bot if one of the chats the bot is in doesn't have the bot as admin. This isn't super bad when the bot comes back online because of systemd and still responds to all commands and stuff, but i guess it wouldn't hurt to capture the error rather than to let it cause the entire bot to fail.

MyrTheMoth commented 2 years ago

Hello! the issue i'm having with this code is that it crashes the bot if one of the chats the bot is in doesn't have the bot as admin. This isn't super bad when the bot comes back online because of systemd and still responds to all commands and stuff, but i guess it wouldn't hurt to capture the error rather than to let it cause the entire bot to fail.

Thanks for the report, I'll look into it when possible, hadn't considered people would use an admin bot in a non-admin environment, so never really made checks for such an use case, to better understand the use case, why do your groups use Guard Bot as a non-admin?

Mrs-Feathers commented 2 years ago

in our administration group that is just a few people, it is only in there to provide logs and output. we dont allow it admin permissions because we don't need it there. only the creator has admin there and the rest of us don't. in all other chats, we all have admin status including the bot. i do also believe some chats in the network (its like 30 or so chats that use this single instance of the bot) the owner(s) don't want to use the bot for admining their group or adhearing to blanket bans for the rest of our network.. but instead want to use other plugins like XKCD comics and whatever other plugins they use from our bot.

Mrs-Feathers commented 2 years ago

so, for a more frank answer, i just host it and other servers for a chat network, and other people/admins/chat owners use it as they want to use it.

MyrTheMoth commented 2 years ago

@Mrs-Feathers I've been trying to replicate the issue, but the captcha module just throws an exception without crashing for me in chats without admin permissions, may I ask for logs when it happens to you?

Mrs-Feathers commented 2 years ago

Here's the errors. It doesn't say it directly but it only started doing this after captcha was installed, so i can only assume its because of it or one of the requirements that can be updated?

TelegramError: 400: Bad Request: message can't be deleted at Telegram.callApi (/root/the-guard-bot/node_modules/telegraf/lib/core/network/client.js:265:19) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async Telegram.ctx.telegram.deleteMessage (/root/the-guard-bot/handlers/middlewares/monkeyPatch.js:11:11) { response: { ok: false, error_code: 400, description: "Bad Request: message can't be deleted" }, on: { method: 'deleteMessage', payload: { chat_id: -1001061022508, message_id: 72712 } } }

MyrTheMoth commented 2 years ago

@Mrs-Feathers is there more? If it was the captcha plugin the logs should point to a line of code in the captcha plugin file, failing to delete a message shouldn't by itself cause a crash either, I'm pretty sure I put error catching and logging for critical parts such at that, any logs that start with "[captcha]" perhaps?

Mrs-Feathers commented 2 years ago

i'm sorry, but that's the entirety of the log output from booting the bot up to purposefully causing it to fatally error out.

MyrTheMoth commented 2 years ago

@Mrs-Feathers Unfortunately, I couldn't reproduce the issue, is it the captcha.ts or imagecaptcha.ts plugin specifically?

I've tried both, bot in non-admin, restarted, added people, removed people, worst that happened were unhandled exceptions that were caught and didn't crash the bot, so after that I reviewed the code, there's one instance of potentially unsafe ctx.deleteMessage() but that one wouldn't cause issues because that's the bot deleting their own message rather than an user's message, so no idea what's causing your issue until I get more logs or a way to replicate the issue consistently.