mirror of
https://github.com/Xtao-Labs/sticker-captcha-bot.git
synced 2024-11-24 00:31:29 +00:00
fix: delete service message
This commit is contained in:
parent
18b57480a4
commit
18a12f3242
@ -1,6 +1,5 @@
|
||||
import asyncio
|
||||
import contextlib
|
||||
from asyncio import sleep
|
||||
from time import time
|
||||
from typing import Dict
|
||||
|
||||
@ -62,7 +61,7 @@ async def start_verify(client: "Client", chat, user):
|
||||
)
|
||||
msg = await cache.get(key2)
|
||||
if msg:
|
||||
add_delete_message_id_job(chat.id, msg)
|
||||
add_delete_message_id_job(chat.id, msg, 1)
|
||||
await msg_.delay_delete(1)
|
||||
if not msg_.sticker:
|
||||
add_ban_chat_member_job(chat.id, user.id)
|
||||
@ -74,7 +73,7 @@ async def start_verify(client: "Client", chat, user):
|
||||
except TimeoutConversationError:
|
||||
msg = await cache.get(key2)
|
||||
if msg:
|
||||
add_delete_message_id_job(chat.id, msg)
|
||||
add_delete_message_id_job(chat.id, msg, 1)
|
||||
add_ban_chat_member_job(chat.id, user.id)
|
||||
await log(chat, user, LogAction.FAIL_TIMEOUT)
|
||||
await ServiceMessage.try_delete(user.id, chat.id)
|
||||
|
@ -1,15 +1,12 @@
|
||||
from pyrogram import filters
|
||||
from pyrogram.enums import MessageServiceType
|
||||
|
||||
from sticker import bot
|
||||
from sticker.functions.service_message import ServiceMessage
|
||||
from sticker.single_utils import Client, Message
|
||||
|
||||
|
||||
@bot.on_message(filters.service)
|
||||
@bot.on_message(filters.new_chat_members, group=2)
|
||||
async def service_message_handle(_: Client, message: Message):
|
||||
if message.service != MessageServiceType.NEW_CHAT_MEMBERS:
|
||||
return
|
||||
cid = message.chat.id
|
||||
if message.new_chat_members:
|
||||
for i in message.new_chat_members:
|
||||
|
@ -31,6 +31,7 @@ from ..utils.errors import ListenerCanceled, TimeoutConversationError
|
||||
pyrogram.errors.ListenerCanceled = ListenerCanceled
|
||||
LOCK = asyncio.Lock()
|
||||
DONE = []
|
||||
DONE_MAP = {}
|
||||
|
||||
|
||||
@patch(pyrogram.client.Client)
|
||||
@ -96,14 +97,15 @@ class MessageHandler:
|
||||
global LOCK, DONE
|
||||
async with LOCK:
|
||||
listener = client.listening.get(message.chat.id)
|
||||
if listener:
|
||||
if listener and DONE_MAP.get(id(self)) == id(listener):
|
||||
with contextlib.suppress(ValueError):
|
||||
DONE.remove(listener)
|
||||
if listener and not listener["future"].done():
|
||||
listener["future"].set_result(message)
|
||||
return
|
||||
if listener and listener["future"].done():
|
||||
client.clear_listener(message.chat.id, listener["future"])
|
||||
del DONE_MAP[id(self)]
|
||||
if not listener["future"].done():
|
||||
listener["future"].set_result(message)
|
||||
return
|
||||
if listener["future"].done():
|
||||
client.clear_listener(message.chat.id, listener["future"])
|
||||
await self.user_callback(client, message, *args)
|
||||
|
||||
@patchable
|
||||
@ -116,9 +118,11 @@ class MessageHandler:
|
||||
result = await listener["filters"](client, update)
|
||||
if result:
|
||||
DONE.append(listener)
|
||||
return result
|
||||
DONE_MAP[id(self)] = id(listener)
|
||||
return True
|
||||
else:
|
||||
DONE.append(listener)
|
||||
DONE_MAP[id(self)] = id(listener)
|
||||
return True
|
||||
return await self.filters(client, update) if callable(self.filters) else True
|
||||
|
||||
|
@ -21,7 +21,7 @@ root_logger = getLogger()
|
||||
root_logger.setLevel(DEBUG if Config.DEBUG else CRITICAL)
|
||||
root_logger.addHandler(logging_handler)
|
||||
pyro_logger = getLogger("pyrogram")
|
||||
pyro_logger.setLevel(CRITICAL)
|
||||
pyro_logger.setLevel(INFO if Config.DEBUG else CRITICAL)
|
||||
pyro_logger.addHandler(logging_handler)
|
||||
basicConfig(level=DEBUG if Config.DEBUG else INFO)
|
||||
logs.setLevel(DEBUG if Config.DEBUG else INFO)
|
||||
|
@ -1,9 +1,8 @@
|
||||
import contextlib
|
||||
from typing import List
|
||||
|
||||
from cashews import cache
|
||||
|
||||
from sticker import bot
|
||||
from sticker.scheduler import add_delete_message_id_job
|
||||
|
||||
|
||||
class ServiceMessage:
|
||||
@ -22,5 +21,4 @@ class ServiceMessage:
|
||||
async def try_delete(uid: int, cid: int):
|
||||
mid = await ServiceMessage.get_cache(uid, cid)
|
||||
if mid:
|
||||
with contextlib.suppress(Exception):
|
||||
await bot.delete_messages(cid, list(mid))
|
||||
add_delete_message_id_job(cid, list(mid), 1)
|
||||
|
@ -1,5 +1,6 @@
|
||||
import contextlib
|
||||
import datetime
|
||||
from typing import Union, List
|
||||
|
||||
import pytz
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
@ -18,7 +19,7 @@ async def delete_message(message: Message) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
async def delete_message_id(chat_id: int, message_id: int) -> bool:
|
||||
async def delete_message_id(chat_id: int, message_id: Union[int, List[int]]) -> bool:
|
||||
with contextlib.suppress(Exception):
|
||||
from sticker.bot import bot
|
||||
|
||||
@ -45,7 +46,9 @@ async def ban_chat_member(chat_id: int, user_id: int):
|
||||
return False
|
||||
|
||||
|
||||
def add_delete_message_id_job(chat_id: int, message_id: int, delete_seconds: int = 60):
|
||||
def add_delete_message_id_job(
|
||||
chat_id: int, message_id: Union[int, List[int]], delete_seconds: int = 60
|
||||
):
|
||||
scheduler.add_job(
|
||||
delete_message_id,
|
||||
"date",
|
||||
|
Loading…
Reference in New Issue
Block a user