Skip to content

Commit 391fd68

Browse files
committed
add more logs
1 parent 98c8800 commit 391fd68

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

main.py

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
BOT_TOKEN = os.getenv("BOT_TOKEN")
3131
REDIS = os.getenv("REDIS", "localhost")
3232
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)
3434
image = ImageCaptcha()
3535
PREDEFINED_STR = re.sub(r"[1l0oOI]", "", string.ascii_letters + string.digits)
3636
IDLE_SECONDS = 60
@@ -95,6 +95,7 @@ async def new_chat(client: "Client", message: "types.Message"):
9595
# deleting service message and ignoring error
9696
with contextlib.suppress(Exception):
9797
await message.delete()
98+
logging.info("add queue %s in group %s", message_id, group_id)
9899
await redis_client.hset("queue", f"{group_id},{message_id}", str(time.time()))
99100
# TODO sleep and then delete or maybe create_task
100101
# await asyncio.sleep(30)
@@ -216,42 +217,19 @@ async def check_idle_verification():
216217
await delete_captcha(group_id)
217218

218219

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-
235220
async def delete_captcha(gu):
236221
chat_id, msg_id = [int(i) for i in gu.split(",")]
237222
try:
238223
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)
245225
await msg.delete()
246226
logging.info("Deleted message %s", msg_id)
247-
248227
if msg.caption_entities and msg.caption_entities[0].user:
249228
target_user = msg.caption_entities[0].user.id
250229
await ban_user(chat_id, target_user)
251230
logging.info("Banned user %s from chat %s", target_user, chat_id)
252231
else:
253232
logging.warning("No user found in caption_entities of message %s", msg_id)
254-
255233
except Exception as e:
256234
logging.error("Failed to delete/ban for message %s in chat %s: %s", msg_id, chat_id, e)
257235
finally:

0 commit comments

Comments
 (0)