|
30 | 30 | BOT_TOKEN = os.getenv("BOT_TOKEN") |
31 | 31 | REDIS = os.getenv("REDIS", "localhost") |
32 | 32 | app = Client("captchabot", APP_ID, API_HASH, bot_token=BOT_TOKEN) |
33 | | -redis_client = aioredis.StrictRedis(host=REDIS, decode_responses=True, db=8) |
| 33 | +redis_client = aioredis.StrictRedis(host=REDIS, decode_responses=True, db=0) |
34 | 34 | image = ImageCaptcha() |
35 | 35 | PREDEFINED_STR = re.sub(r"[1l0oOI]", "", string.ascii_letters + string.digits) |
36 | 36 | IDLE_SECONDS = 60 |
@@ -95,6 +95,7 @@ async def new_chat(client: "Client", message: "types.Message"): |
95 | 95 | # deleting service message and ignoring error |
96 | 96 | with contextlib.suppress(Exception): |
97 | 97 | await message.delete() |
| 98 | + logging.info("add queue %s in group %s", message_id, group_id) |
98 | 99 | await redis_client.hset("queue", f"{group_id},{message_id}", str(time.time())) |
99 | 100 | # TODO sleep and then delete or maybe create_task |
100 | 101 | # await asyncio.sleep(30) |
@@ -216,42 +217,19 @@ async def check_idle_verification(): |
216 | 217 | await delete_captcha(group_id) |
217 | 218 |
|
218 | 219 |
|
219 | | -# captcha-1 | 2025-07-23 21:07:32,595 - root - INFO - message to be deleted: { |
220 | | -# captcha-1 | "_": "Message", |
221 | | -# captcha-1 | "id": 293901, |
222 | | -# captcha-1 | "empty": true |
223 | | -# captcha-1 | } |
224 | | -# captcha-1 | 2025-07-23 21:07:32,595 - root - ERROR - error in deleting captcha -1001139287285,293901 |
225 | | -# captcha-1 | Traceback (most recent call last): |
226 | | -# captcha-1 | File "/CaptchaBot/main.py", line 209, in check_idle_verification |
227 | | -# captcha-1 | await delete_captcha(group_id) |
228 | | -# captcha-1 | File "/CaptchaBot/main.py", line 223, in delete_captcha |
229 | | -# captcha-1 | await msg.delete() |
230 | | -# captcha-1 | File "/usr/local/lib/python3.10/site-packages/pyrogram/types/messages_and_media/message.py", line 5655, in delete |
231 | | -# captcha-1 | chat_id=self.chat.id, |
232 | | -# captcha-1 | AttributeError: 'NoneType' object has no attribute 'id' |
233 | | - |
234 | | - |
235 | 220 | async def delete_captcha(gu): |
236 | 221 | chat_id, msg_id = [int(i) for i in gu.split(",")] |
237 | 222 | try: |
238 | 223 | msg = await app.get_messages(chat_id, msg_id) |
239 | | - logging.info("Fetched message %s in chat %s", msg_id, chat_id) |
240 | | - |
241 | | - if msg.empty: |
242 | | - logging.warning("Message %s is empty – likely deleted already", msg_id) |
243 | | - return |
244 | | - |
| 224 | + logging.info("Fetched message %s in chat %s, detail: %s", msg_id, chat_id, msg) |
245 | 225 | await msg.delete() |
246 | 226 | logging.info("Deleted message %s", msg_id) |
247 | | - |
248 | 227 | if msg.caption_entities and msg.caption_entities[0].user: |
249 | 228 | target_user = msg.caption_entities[0].user.id |
250 | 229 | await ban_user(chat_id, target_user) |
251 | 230 | logging.info("Banned user %s from chat %s", target_user, chat_id) |
252 | 231 | else: |
253 | 232 | logging.warning("No user found in caption_entities of message %s", msg_id) |
254 | | - |
255 | 233 | except Exception as e: |
256 | 234 | logging.error("Failed to delete/ban for message %s in chat %s: %s", msg_id, chat_id, e) |
257 | 235 | finally: |
|
0 commit comments