mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 20:59:29 +00:00
- Fix small glitches introduced when merging.
- Remove typing requirement, asyncio branch already needs Python 3.5+. - Add async_lru as extra requirement because the standard lru_cache doesn't work in asyncio world.
This commit is contained in:
parent
e6667be10b
commit
f5ce49b7b2
@ -72,7 +72,7 @@ class Dispatcher:
|
||||
|
||||
self.update_parsers = {
|
||||
Dispatcher.MESSAGE_UPDATES: message_parser,
|
||||
Dispatcher.DELETE_MESSAGE_UPDATES: deleted_messages_parser,
|
||||
Dispatcher.DELETE_MESSAGES_UPDATES: deleted_messages_parser,
|
||||
Dispatcher.CALLBACK_QUERY_UPDATES: callback_query_parser,
|
||||
(types.UpdateUserStatus,): user_status_parser
|
||||
}
|
||||
|
@ -16,7 +16,10 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
from base64 import b64decode, b64encode
|
||||
from concurrent.futures.thread import ThreadPoolExecutor
|
||||
|
||||
from ...api import types
|
||||
|
||||
@ -57,6 +60,15 @@ def encode(s: bytes) -> str:
|
||||
return b64encode(r, b"-_").decode().rstrip("=")
|
||||
|
||||
|
||||
async def ainput(prompt: str = ""):
|
||||
print(prompt, end="", flush=True)
|
||||
|
||||
with ThreadPoolExecutor(1) as executor:
|
||||
return (await asyncio.get_event_loop().run_in_executor(
|
||||
executor, sys.stdin.readline
|
||||
)).rstrip()
|
||||
|
||||
|
||||
def get_peer_id(input_peer) -> int:
|
||||
return (
|
||||
input_peer.user_id if isinstance(input_peer, types.InputPeerUser)
|
||||
|
@ -78,6 +78,6 @@ class GetMessages(BaseClient):
|
||||
else:
|
||||
rpc = functions.messages.GetMessages(id=ids)
|
||||
|
||||
messages = await pyrogram.Messages._parse(self, self.send(rpc))
|
||||
messages = await pyrogram.Messages._parse(self, await self.send(rpc))
|
||||
|
||||
return messages if is_iterable else messages.messages[0]
|
||||
|
@ -33,9 +33,9 @@ class GetMe(BaseClient):
|
||||
"""
|
||||
return pyrogram.User._parse(
|
||||
self,
|
||||
await self.send(
|
||||
(await self.send(
|
||||
functions.users.GetFullUser(
|
||||
types.InputPeerSelf()
|
||||
)
|
||||
).user
|
||||
)).user
|
||||
)
|
||||
|
@ -78,7 +78,7 @@ class CallbackQuery(PyrogramType):
|
||||
self.game_short_name = game_short_name
|
||||
|
||||
@staticmethod
|
||||
def _parse(client, callback_query, users) -> "CallbackQuery":
|
||||
async def _parse(client, callback_query, users) -> "CallbackQuery":
|
||||
message = None
|
||||
inline_message_id = None
|
||||
|
||||
@ -92,7 +92,7 @@ class CallbackQuery(PyrogramType):
|
||||
else:
|
||||
peer_id = int("-100" + str(peer.channel_id))
|
||||
|
||||
message = client.get_messages(peer_id, callback_query.msg_id)
|
||||
message = await client.get_messages(peer_id, callback_query.msg_id)
|
||||
elif isinstance(callback_query, types.UpdateInlineBotCallbackQuery):
|
||||
inline_message_id = b64encode(
|
||||
pack(
|
||||
|
@ -16,9 +16,10 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from functools import lru_cache
|
||||
from struct import pack
|
||||
|
||||
from async_lru import alru_cache
|
||||
|
||||
import pyrogram
|
||||
from pyrogram.api import types, functions
|
||||
from pyrogram.api.errors import StickersetInvalid
|
||||
@ -92,14 +93,14 @@ class Sticker(PyrogramType):
|
||||
# self.mask_position = mask_position
|
||||
|
||||
@staticmethod
|
||||
@lru_cache(maxsize=256)
|
||||
@alru_cache(maxsize=256)
|
||||
async def get_sticker_set_name(send, input_sticker_set_id):
|
||||
try:
|
||||
return await send(
|
||||
return (await send(
|
||||
functions.messages.GetStickerSet(
|
||||
types.InputStickerSetID(*input_sticker_set_id)
|
||||
)
|
||||
).set.short_name
|
||||
)).set.short_name
|
||||
except StickersetInvalid:
|
||||
return None
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
pyaes==1.6.1
|
||||
pysocks==1.6.8
|
||||
typing==3.6.6
|
||||
async_lru==1.0.1
|
Loading…
Reference in New Issue
Block a user