mirror of
https://github.com/pyrogram/pyrogram
synced 2025-09-03 07:45:14 +00:00
Merge branch 'develop' into asyncio
# Conflicts: # pyrogram/__init__.py # pyrogram/client/methods/chats/export_chat_invite_link.py # pyrogram/client/parser/html.py
This commit is contained in:
@@ -48,18 +48,15 @@ class ExportChatInviteLink(BaseClient):
|
||||
|
||||
Raises:
|
||||
RPCError: In case of a Telegram RPC error.
|
||||
ValueError: In case the chat_id belongs to a user.
|
||||
"""
|
||||
peer = await self.resolve_peer(chat_id)
|
||||
|
||||
if isinstance(peer, types.InputPeerChat):
|
||||
if isinstance(peer, (types.InputPeerChannel, types.InputPeerChat)):
|
||||
return await self.send(
|
||||
functions.messages.ExportChatInvite(
|
||||
peer=peer
|
||||
)
|
||||
).link
|
||||
elif isinstance(peer, types.InputPeerChannel):
|
||||
return await self.send(
|
||||
functions.channels.ExportInvite(
|
||||
channel=peer
|
||||
)
|
||||
).link
|
||||
else:
|
||||
raise ValueError('The chat_id "{}" belongs to a user'.format(chat_id))
|
||||
|
@@ -108,7 +108,7 @@ class HTML:
|
||||
self.client = client
|
||||
|
||||
async def parse(self, text: str):
|
||||
text = utils.add_surrogates(str(text or "").strip())
|
||||
text = utils.add_surrogates(text)
|
||||
|
||||
parser = Parser(self.client)
|
||||
parser.feed(text)
|
||||
|
@@ -31,6 +31,8 @@ class Parser:
|
||||
self.markdown = Markdown(client)
|
||||
|
||||
def parse(self, text: str, mode: str = ""):
|
||||
text = str(text or "").strip()
|
||||
|
||||
if mode is None:
|
||||
return OrderedDict([
|
||||
("message", text),
|
||||
|
@@ -59,8 +59,8 @@ class MemoryStorage(Storage):
|
||||
(1, None, None, 0, None, None)
|
||||
)
|
||||
|
||||
def _import_session_string(self, string_session: str):
|
||||
decoded = base64.urlsafe_b64decode(string_session + "=" * (-len(string_session) % 4))
|
||||
def _import_session_string(self, session_string: str):
|
||||
decoded = base64.urlsafe_b64decode(session_string + "=" * (-len(session_string) % 4))
|
||||
return struct.unpack(self.SESSION_STRING_FMT, decoded)
|
||||
|
||||
def export_session_string(self):
|
||||
@@ -86,8 +86,6 @@ class MemoryStorage(Storage):
|
||||
self.dc_id, self.test_mode, self.auth_key, self.user_id, self.is_bot = imported_session_string
|
||||
self.date = 0
|
||||
|
||||
self.name = ":memory:" + str(self.user_id or "<unknown>")
|
||||
|
||||
# noinspection PyAttributeOutsideInit
|
||||
def save(self):
|
||||
self.date = int(time.time())
|
||||
@@ -132,7 +130,7 @@ class MemoryStorage(Storage):
|
||||
access_hash=access_hash
|
||||
)
|
||||
|
||||
raise ValueError("Invalid peer type")
|
||||
raise ValueError("Invalid peer type: {}".format(peer_type))
|
||||
|
||||
def get_peer_by_id(self, peer_id: int):
|
||||
r = self.conn.execute(
|
||||
@@ -141,7 +139,7 @@ class MemoryStorage(Storage):
|
||||
).fetchone()
|
||||
|
||||
if r is None:
|
||||
raise KeyError("ID not found")
|
||||
raise KeyError("ID not found: {}".format(peer_id))
|
||||
|
||||
return self._get_input_peer(*r)
|
||||
|
||||
@@ -152,10 +150,10 @@ class MemoryStorage(Storage):
|
||||
).fetchone()
|
||||
|
||||
if r is None:
|
||||
raise KeyError("Username not found")
|
||||
raise KeyError("Username not found: {}".format(username))
|
||||
|
||||
if abs(time.time() - r[3]) > self.USERNAME_TTL:
|
||||
raise KeyError("Username expired")
|
||||
raise KeyError("Username expired: {}".format(username))
|
||||
|
||||
return self._get_input_peer(*r[:3])
|
||||
|
||||
@@ -166,7 +164,7 @@ class MemoryStorage(Storage):
|
||||
).fetchone()
|
||||
|
||||
if r is None:
|
||||
raise KeyError("Phone number not found")
|
||||
raise KeyError("Phone number not found: {}".format(phone_number))
|
||||
|
||||
return self._get_input_peer(*r)
|
||||
|
||||
|
@@ -16,6 +16,8 @@
|
||||
# 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 html
|
||||
|
||||
import pyrogram
|
||||
from pyrogram.api import types
|
||||
|
||||
@@ -135,6 +137,12 @@ class User(Object):
|
||||
self.photo = photo
|
||||
self.restriction_reason = restriction_reason
|
||||
|
||||
def __format__(self, format_spec):
|
||||
if format_spec == "mention":
|
||||
return '<a href="tg://user?id={0}">{1}</a>'.format(self.id, html.escape(self.first_name))
|
||||
|
||||
return html.escape(str(self))
|
||||
|
||||
@staticmethod
|
||||
def _parse(client, user: types.User) -> "User" or None:
|
||||
if user is None:
|
||||
|
Reference in New Issue
Block a user