mirror of
https://github.com/TeamPGM/PagerMaid-Pyro.git
synced 2024-11-21 13:38:21 +00:00
🐛 Fix client ask and listen check
This commit is contained in:
parent
299c8db5dd
commit
f75fb07f44
28
.git-blame-ignore-revs
Normal file
28
.git-blame-ignore-revs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# This file contains a list of commits with
|
||||||
|
# mass changes for exclusion by `git blame`.
|
||||||
|
#
|
||||||
|
# Passing `--ignore-revs-file .git-blame-ignore-revs` as a flag will
|
||||||
|
# tell git to "ignore changes made by the revision when assigning
|
||||||
|
# blame, as if the change never happened".
|
||||||
|
#
|
||||||
|
# For example:
|
||||||
|
# git blame --ignore-revs-file .git-blame-ignore-revs ...
|
||||||
|
#
|
||||||
|
# For extra hot sauce, ignore white space changes too:
|
||||||
|
# git blame -w --ignore-revs-file .git-blame-ignore-revs ...
|
||||||
|
#
|
||||||
|
# You can make this a default for your repo using:
|
||||||
|
# git config blame.ignoreRevsFile .git-blame-ignore-revs
|
||||||
|
#
|
||||||
|
# Also, if you use the GitLens extension for Visual Studio Code, you
|
||||||
|
# can add "-w" as a value to "gitlens.advanced.blame.customArguments".
|
||||||
|
#
|
||||||
|
# Note that `git blame` does not use any file by default, and
|
||||||
|
# the filename `.git-blame-ignore-revs` is just a convention.
|
||||||
|
|
||||||
|
299c8db5dd9b59cfe450cb7dc425205406acf015
|
||||||
|
# Author: xtaodada <xtao@xtaolink.cn>
|
||||||
|
# Date: Tue Aug 13 18:38:13 2024 +0800
|
||||||
|
#
|
||||||
|
# :lipstick: Format with black 24.x.x
|
||||||
|
#
|
@ -38,6 +38,8 @@ from ..utils.conversation import Conversation
|
|||||||
from ..utils.errors import TimeoutConversationError, ListenerCanceled
|
from ..utils.errors import TimeoutConversationError, ListenerCanceled
|
||||||
|
|
||||||
pyrogram.errors.ListenerCanceled = ListenerCanceled # noqa
|
pyrogram.errors.ListenerCanceled = ListenerCanceled # noqa
|
||||||
|
LOCK = asyncio.Lock()
|
||||||
|
DONE = []
|
||||||
|
|
||||||
|
|
||||||
@patch(pyrogram.client.Client)
|
@patch(pyrogram.client.Client)
|
||||||
@ -108,34 +110,50 @@ class Client:
|
|||||||
|
|
||||||
|
|
||||||
@patch(pyrogram.handlers.message_handler.MessageHandler)
|
@patch(pyrogram.handlers.message_handler.MessageHandler)
|
||||||
class MessageHandler:
|
class MessageHandler(pyrogram.handlers.message_handler.MessageHandler):
|
||||||
@patchable
|
@patchable
|
||||||
def __init__(self, callback: callable, filters=None):
|
def __init__(self, callback: callable, filters=None):
|
||||||
self.user_callback = callback
|
self.user_callback = callback
|
||||||
self.old__init__(self.resolve_listener, filters)
|
self.old__init__(self.resolve_listener, filters)
|
||||||
|
|
||||||
@patchable
|
@staticmethod
|
||||||
async def resolve_listener(self, client, message, *args):
|
async def resolve_listener_(self, client, message, *args):
|
||||||
listener = client.listening.get(message.chat.id)
|
global LOCK, DONE
|
||||||
if listener and not listener["future"].done():
|
async with LOCK:
|
||||||
listener["future"].set_result(message)
|
listener = client.listening.get(message.chat.id)
|
||||||
else:
|
if 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():
|
if listener and listener["future"].done():
|
||||||
client.clear_listener(message.chat.id, listener["future"])
|
client.clear_listener(message.chat.id, listener["future"])
|
||||||
await self.user_callback(client, message, *args)
|
await self.user_callback(client, message, *args)
|
||||||
|
|
||||||
|
@patchable
|
||||||
|
async def resolve_listener(self, client, message, *args):
|
||||||
|
await MessageHandler.resolve_listener_(self, client, message, *args)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def check_(self, client, update):
|
||||||
|
global LOCK, DONE
|
||||||
|
async with LOCK:
|
||||||
|
listener = client.listening.get(update.chat.id)
|
||||||
|
if listener and (listener not in DONE) and (not listener["future"].done()):
|
||||||
|
if callable(listener["filters"]):
|
||||||
|
result = await listener["filters"](client, update)
|
||||||
|
if result:
|
||||||
|
DONE.append(listener)
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
DONE.append(listener)
|
||||||
|
return True
|
||||||
|
return await self.filters(client, update) if callable(self.filters) else True
|
||||||
|
|
||||||
@patchable
|
@patchable
|
||||||
async def check(self, client, update):
|
async def check(self, client, update):
|
||||||
listener = client.listening.get(update.chat.id)
|
return await MessageHandler.check_(self, client, update)
|
||||||
|
|
||||||
if listener and not listener["future"].done():
|
|
||||||
return (
|
|
||||||
await listener["filters"](client, update)
|
|
||||||
if callable(listener["filters"])
|
|
||||||
else True
|
|
||||||
)
|
|
||||||
|
|
||||||
return await self.filters(client, update) if callable(self.filters) else True
|
|
||||||
|
|
||||||
|
|
||||||
@patch(pyrogram.handlers.edited_message_handler.EditedMessageHandler)
|
@patch(pyrogram.handlers.edited_message_handler.EditedMessageHandler)
|
||||||
@ -147,26 +165,11 @@ class EditedMessageHandler:
|
|||||||
|
|
||||||
@patchable
|
@patchable
|
||||||
async def resolve_listener(self, client, message, *args):
|
async def resolve_listener(self, client, message, *args):
|
||||||
listener = client.listening.get(message.chat.id)
|
await MessageHandler.resolve_listener_(self, client, message, *args)
|
||||||
if listener and not listener["future"].done():
|
|
||||||
listener["future"].set_result(message)
|
|
||||||
else:
|
|
||||||
if listener and listener["future"].done():
|
|
||||||
client.clear_listener(message.chat.id, listener["future"])
|
|
||||||
await self.user_callback(client, message, *args)
|
|
||||||
|
|
||||||
@patchable
|
@patchable
|
||||||
async def check(self, client, update):
|
async def check(self, client, update):
|
||||||
listener = client.listening.get(update.chat.id)
|
return await MessageHandler.check_(self, client, update)
|
||||||
|
|
||||||
if listener and not listener["future"].done():
|
|
||||||
return (
|
|
||||||
await listener["filters"](client, update)
|
|
||||||
if callable(listener["filters"])
|
|
||||||
else True
|
|
||||||
)
|
|
||||||
|
|
||||||
return await self.filters(client, update) if callable(self.filters) else True
|
|
||||||
|
|
||||||
|
|
||||||
@patch(pyrogram.types.user_and_chats.chat.Chat)
|
@patch(pyrogram.types.user_and_chats.chat.Chat)
|
||||||
|
Loading…
Reference in New Issue
Block a user