mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-07 15:34:52 +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
7 changed files with 24 additions and 11 deletions
|
|
@ -72,7 +72,7 @@ class Dispatcher:
|
||||||
|
|
||||||
self.update_parsers = {
|
self.update_parsers = {
|
||||||
Dispatcher.MESSAGE_UPDATES: message_parser,
|
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,
|
Dispatcher.CALLBACK_QUERY_UPDATES: callback_query_parser,
|
||||||
(types.UpdateUserStatus,): user_status_parser
|
(types.UpdateUserStatus,): user_status_parser
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,10 @@
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
import sys
|
||||||
from base64 import b64decode, b64encode
|
from base64 import b64decode, b64encode
|
||||||
|
from concurrent.futures.thread import ThreadPoolExecutor
|
||||||
|
|
||||||
from ...api import types
|
from ...api import types
|
||||||
|
|
||||||
|
|
@ -57,6 +60,15 @@ def encode(s: bytes) -> str:
|
||||||
return b64encode(r, b"-_").decode().rstrip("=")
|
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:
|
def get_peer_id(input_peer) -> int:
|
||||||
return (
|
return (
|
||||||
input_peer.user_id if isinstance(input_peer, types.InputPeerUser)
|
input_peer.user_id if isinstance(input_peer, types.InputPeerUser)
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,6 @@ class GetMessages(BaseClient):
|
||||||
else:
|
else:
|
||||||
rpc = functions.messages.GetMessages(id=ids)
|
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]
|
return messages if is_iterable else messages.messages[0]
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,9 @@ class GetMe(BaseClient):
|
||||||
"""
|
"""
|
||||||
return pyrogram.User._parse(
|
return pyrogram.User._parse(
|
||||||
self,
|
self,
|
||||||
await self.send(
|
(await self.send(
|
||||||
functions.users.GetFullUser(
|
functions.users.GetFullUser(
|
||||||
types.InputPeerSelf()
|
types.InputPeerSelf()
|
||||||
)
|
)
|
||||||
).user
|
)).user
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ class CallbackQuery(PyrogramType):
|
||||||
self.game_short_name = game_short_name
|
self.game_short_name = game_short_name
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse(client, callback_query, users) -> "CallbackQuery":
|
async def _parse(client, callback_query, users) -> "CallbackQuery":
|
||||||
message = None
|
message = None
|
||||||
inline_message_id = None
|
inline_message_id = None
|
||||||
|
|
||||||
|
|
@ -92,7 +92,7 @@ class CallbackQuery(PyrogramType):
|
||||||
else:
|
else:
|
||||||
peer_id = int("-100" + str(peer.channel_id))
|
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):
|
elif isinstance(callback_query, types.UpdateInlineBotCallbackQuery):
|
||||||
inline_message_id = b64encode(
|
inline_message_id = b64encode(
|
||||||
pack(
|
pack(
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,10 @@
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from functools import lru_cache
|
|
||||||
from struct import pack
|
from struct import pack
|
||||||
|
|
||||||
|
from async_lru import alru_cache
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import types, functions
|
from pyrogram.api import types, functions
|
||||||
from pyrogram.api.errors import StickersetInvalid
|
from pyrogram.api.errors import StickersetInvalid
|
||||||
|
|
@ -92,14 +93,14 @@ class Sticker(PyrogramType):
|
||||||
# self.mask_position = mask_position
|
# self.mask_position = mask_position
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@lru_cache(maxsize=256)
|
@alru_cache(maxsize=256)
|
||||||
async def get_sticker_set_name(send, input_sticker_set_id):
|
async def get_sticker_set_name(send, input_sticker_set_id):
|
||||||
try:
|
try:
|
||||||
return await send(
|
return (await send(
|
||||||
functions.messages.GetStickerSet(
|
functions.messages.GetStickerSet(
|
||||||
types.InputStickerSetID(*input_sticker_set_id)
|
types.InputStickerSetID(*input_sticker_set_id)
|
||||||
)
|
)
|
||||||
).set.short_name
|
)).set.short_name
|
||||||
except StickersetInvalid:
|
except StickersetInvalid:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
pyaes==1.6.1
|
pyaes==1.6.1
|
||||||
pysocks==1.6.8
|
pysocks==1.6.8
|
||||||
typing==3.6.6
|
async_lru==1.0.1
|
||||||
Loading…
Reference in a new issue