Skip to content

Commit

Permalink
Pyrogram 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
usernein committed Oct 25, 2020
1 parent 7194a13 commit cb88922
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 37 deletions.
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ I separated the patches between packages to allow you to import only what you wa
Just import it, it will automatically do the monkeypatch and you'll get these new methods:
- `await pyrogram.Client.listen(chat_id, filters=None, timeout=30)`
Awaits for a new message in the specified chat and returns it
You can pass Update Filters to the filters parameter just like you do for the update handlers. e.g. `filters=Filters.photo & Filters.bot`
You can pass Update Filters to the filters parameter just like you do for the update handlers. e.g. `filters=filters.photo & filters.bot`

- `await pyrogram.Client.ask(text, chat_id, filters=None, timeout=30)`
Same of `.listen()` above, but sends a message before awaiting
Expand All @@ -47,16 +47,11 @@ client = Client(...)
```

### `pyromod.filters`
Import it and the following Update Filters will be monkeypatched to `pyrogram.Filters`:
Import it and the following Update Filters will be monkeypatched to `pyrogram.filters`:

- `Filters.dice`
- `filters.dice`
A dice message.

- `Filters.callback_regex(pattern, flags: int = 0)`
Same of `Filters.regex`, but for CallbackQuery updates
The CallbackQuery object will hold the matches on the new `CallbackQuery.matches` attribute (just like `Message.matches`)


### Copyright & License
This project may include snippets of Pyrogram code
- Pyrogram - Telegram MTProto API Client Library for Python. Copyright (C) 2017-2020 Dan <<https://github.com/delivrance>>
Expand Down
2 changes: 1 addition & 1 deletion pyromod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
along with pyromod. If not, see <https://www.gnu.org/licenses/>.
"""

__version__ = "0.3.2"
__version__ = "1.0"
2 changes: 1 addition & 1 deletion pyromod/filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
along with pyromod. If not, see <https://www.gnu.org/licenses/>.
"""

from .filters import Filters
from .filters import dice
18 changes: 3 additions & 15 deletions pyromod/filters/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,7 @@
"""

import pyrogram
import re

from ..utils import patch, patchable

# To allow Filters.callback_regex to exist:
pyrogram.client.types.bots_and_keyboards.callback_query.CallbackQuery.matches = None

@patch(pyrogram.client.filters.filters.Filters)
class Filters:
create = pyrogram.client.filters.filters.Filters.create

@patchable
@create
@staticmethod
def dice(ctx, message):
return hasattr(message, 'dice') and message.dice
def dice(ctx, message):
return hasattr(message, 'dice') and message.dice
pyrogram.filters.dice = dice
2 changes: 1 addition & 1 deletion pyromod/helpers/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyrogram import InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup

def ikb(rows = []):
lines = []
Expand Down
19 changes: 9 additions & 10 deletions pyromod/listen/listen.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ListenerCanceled(Exception):
pass
pyrogram.errors.ListenerCanceled = ListenerCanceled

@patch(pyrogram.client.client.Client)
@patch(pyrogram.client.Client)
class Client():
@patchable
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -75,7 +75,7 @@ def cancel_listener(self, chat_id):
listener['future'].set_exception(ListenerCanceled())
self.clear_listener(chat_id, listener['future'])

@patch(pyrogram.client.handlers.message_handler.MessageHandler)
@patch(pyrogram.handlers.message_handler.MessageHandler)
class MessageHandler():
@patchable
def __init__(self, callback: callable, filters=None):
Expand All @@ -93,21 +93,20 @@ async def resolve_listener(self, client, message, *args):
await self.user_callback(client, message, *args)

@patchable
def check(self, update):
client = update._client
async def check(self, client, update):
listener = client.listening.get(update.chat.id)

if listener and not listener['future'].done():
return listener['filters'](update) if callable(listener['filters']) else True
return await listener['filters'](client, update) if callable(listener['filters']) else True

return (
self.filters(update)
await self.filters(client, update)
if callable(self.filters)
else True
)

@patch(pyrogram.client.types.user_and_chats.chat.Chat)
class Chat(pyrogram.Chat):
@patch(pyrogram.types.user_and_chats.chat.Chat)
class Chat(pyrogram.types.Chat):
@patchable
def listen(self, *args, **kwargs):
return self._client.listen(self.id, *args, **kwargs)
Expand All @@ -118,8 +117,8 @@ def ask(self, *args, **kwargs):
def cancel_listener(self):
return self._client.cancel_listener(self.id)

@patch(pyrogram.client.types.user_and_chats.user.User)
class User(pyrogram.User):
@patch(pyrogram.types.user_and_chats.user.User)
class User(pyrogram.types.User):
@patchable
def listen(self, *args, **kwargs):
return self._client.listen(self.id, *args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@

pyrogram>=1.0.0

0 comments on commit cb88922

Please sign in to comment.