🔖 Update to v1.1.4

This commit is contained in:
xtaodada 2022-06-30 14:49:03 +08:00
parent bdccfa0be2
commit dd6957f239
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
6 changed files with 61 additions and 9 deletions

View File

@ -14,7 +14,7 @@ import pyromod.listen
from pyrogram import Client
import sys
pgm_version = "1.1.3"
pgm_version = "1.1.4"
CMD_LIST = {}
module_dir = __path__[0]
working_dir = getcwd()

View File

@ -16,7 +16,7 @@ from pyrogram.handlers import MessageHandler, EditedMessageHandler
from pagermaid import help_messages, logs, Config, bot, read_context, all_permissions
from pagermaid.group_manager import Permission
from pagermaid.single_utils import Message, AlreadyInConversationError, TimeoutConversationError
from pagermaid.single_utils import Message, AlreadyInConversationError, TimeoutConversationError, ListenerCanceled
from pagermaid.utils import lang, attach_report, sudo_filter, alias_command, get_permission_name, process_exit
from pagermaid.utils import client as httpx_client
from pagermaid.hook import Hook
@ -146,6 +146,12 @@ def listener(**args):
)
with contextlib.suppress(BaseException):
await message.edit(lang("conversation_timed_out_error"))
except ListenerCanceled:
logs.warning(
"Listener Canceled While Processing Commands.."
)
with contextlib.suppress(BaseException):
await message.edit(lang("reload_des"))
except UserNotParticipant:
pass
except ContinuePropagation as e:
@ -225,6 +231,12 @@ def raw_listener(filter_s):
)
with contextlib.suppress(BaseException):
await message.edit(lang("conversation_timed_out_error"))
except ListenerCanceled:
logs.warning(
"Listener Canceled While Processing Commands.."
)
with contextlib.suppress(BaseException):
await message.edit(lang("reload_des"))
except SystemExit:
await process_exit(start=False, _client=client, message=message)
await Hook.shutdown()

View File

@ -1,3 +1,4 @@
import contextlib
import importlib
import pagermaid.config
import pagermaid.modules
@ -10,6 +11,8 @@ from pagermaid.utils import lang, Message
def reload_all():
bot.dispatcher.remove_all_handlers()
bot.job.remove_all_jobs()
with contextlib.suppress(RuntimeError):
bot.cancel_all_listener()
loaded_plugins = list(pagermaid.modules.plugin_list)
loaded_plugins.extend(iter(pagermaid.modules.module_list))
# init

View File

@ -9,7 +9,7 @@ from pyrogram import Client
from pyrogram.types import Message
from pyromod.utils.conversation import Conversation
from pyromod.utils.errors import AlreadyInConversationError, TimeoutConversationError
from pyromod.utils.errors import AlreadyInConversationError, TimeoutConversationError, ListenerCanceled
from sqlitedict import SqliteDict

View File

@ -29,12 +29,7 @@ from pagermaid.scheduler import add_delete_message_job
from ..utils import patch, patchable
from ..utils.conversation import Conversation
from ..utils.errors import TimeoutConversationError
class ListenerCanceled(Exception):
pass
from ..utils.errors import TimeoutConversationError, ListenerCanceled
pyrogram.errors.ListenerCanceled = ListenerCanceled
@ -128,6 +123,37 @@ class MessageHandler:
)
@patch(pyrogram.handlers.edited_message_handler.EditedMessageHandler)
class EditedMessageHandler:
@patchable
def __init__(self, callback: callable, filters=None):
self.user_callback = callback
self.old__init__(self.resolve_listener, filters)
@patchable
async def resolve_listener(self, client, message, *args):
listener = client.listening.get(message.chat.id)
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
async def check(self, client, update):
listener = client.listening.get(update.chat.id)
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)
class Chat(pyrogram.types.Chat):
@patchable

View File

@ -17,3 +17,14 @@ class TimeoutConversationError(Exception):
super().__init__(
"Response read timed out"
)
class ListenerCanceled(Exception):
"""
Occurs when the listener is canceled.
"""
def __init__(self):
super().__init__(
"Listener was canceled"
)