Merge develop -> asyncio
This commit is contained in:
commit
a829f74a16
@ -202,6 +202,7 @@ def pyrogram_api():
|
||||
get_dialogs_count
|
||||
update_chat_username
|
||||
get_common_chats
|
||||
get_nearby_chats
|
||||
archive_chats
|
||||
unarchive_chats
|
||||
add_chat_members
|
||||
|
@ -73,8 +73,8 @@ latex_logo = "_images/pyrogram.png"
|
||||
latex_elements = {
|
||||
"pointsize": "12pt",
|
||||
"fontpkg": r"""
|
||||
\setmainfont{Noto Sans}
|
||||
\setsansfont{Roboto Slab}
|
||||
\setmainfont{Open Sans}
|
||||
\setsansfont{Bitter}
|
||||
\setmonofont{Ubuntu Mono}
|
||||
"""
|
||||
}
|
||||
|
@ -295,10 +295,6 @@ Each function decorated with the usual ``on_message`` decorator (or any other de
|
||||
updates) will be modified in such a way that a special ``handler`` attribute pointing to a tuple of
|
||||
*(handler: Handler, group: int)* is attached to the function object itself.
|
||||
|
||||
when you reference them later on, they will be actually pointing to a tuple of
|
||||
*(handler: Handler, group: int)*. The actual callback function is therefore stored inside the handler's *callback*
|
||||
attribute. Here's an example:
|
||||
|
||||
- ``plugins/handlers.py``
|
||||
|
||||
.. code-block:: python
|
||||
@ -309,12 +305,12 @@ attribute. Here's an example:
|
||||
message.reply(message.text)
|
||||
|
||||
print(echo)
|
||||
print(echo[0].callback)
|
||||
print(echo.handler)
|
||||
|
||||
- Printing ``echo`` will show something like ``(<MessageHandler object at 0x10e3abc50>, 0)``.
|
||||
- Printing ``echo`` will show something like ``<function echo at 0x10e3b6598>``.
|
||||
|
||||
- Printing ``echo[0].callback``, that is, the *callback* attribute of the first element of the tuple, which is an
|
||||
Handler, will reveal the actual callback ``<function echo at 0x10e3b6598>``.
|
||||
- Printing ``echo.handler`` will reveal the handler, that is, a tuple containing the actual handler and the group it
|
||||
was registered on ``(<MessageHandler object at 0x10e3abc50>, 0)``.
|
||||
|
||||
Unloading
|
||||
^^^^^^^^^
|
||||
|
@ -47,6 +47,7 @@ from .unarchive_chats import UnarchiveChats
|
||||
from .unban_chat_member import UnbanChatMember
|
||||
from .unpin_chat_message import UnpinChatMessage
|
||||
from .update_chat_username import UpdateChatUsername
|
||||
from .get_nearby_chats import GetNearbyChats
|
||||
|
||||
|
||||
class Chats(
|
||||
@ -80,6 +81,7 @@ class Chats(
|
||||
CreateChannel,
|
||||
AddChatMembers,
|
||||
DeleteChannel,
|
||||
DeleteSupergroup
|
||||
DeleteSupergroup,
|
||||
GetNearbyChats
|
||||
):
|
||||
pass
|
||||
|
71
pyrogram/client/methods/chats/get_nearby_chats.py
Normal file
71
pyrogram/client/methods/chats/get_nearby_chats.py
Normal file
@ -0,0 +1,71 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# 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 typing import List
|
||||
|
||||
import pyrogram
|
||||
from pyrogram.api import functions, types
|
||||
from ...ext import BaseClient, utils
|
||||
|
||||
|
||||
class GetNearbyChats(BaseClient):
|
||||
async def get_nearby_chats(
|
||||
self,
|
||||
latitude: float,
|
||||
longitude: float
|
||||
) -> List["pyrogram.Chat"]:
|
||||
"""Get nearby chats.
|
||||
|
||||
Parameters:
|
||||
latitude (``float``):
|
||||
Latitude of the location.
|
||||
|
||||
longitude (``float``):
|
||||
Longitude of the location.
|
||||
|
||||
Returns:
|
||||
List of :obj:`Chat`: On success, a list of nearby chats is returned.
|
||||
|
||||
Example:
|
||||
.. code-block:: python
|
||||
|
||||
chats = app.get_nearby_chats(51.500729, -0.124583)
|
||||
print(chats)
|
||||
"""
|
||||
|
||||
r = await self.send(
|
||||
functions.contacts.GetLocated(
|
||||
geo_point=types.InputGeoPoint(
|
||||
lat=latitude,
|
||||
long=longitude
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
chats = pyrogram.List([pyrogram.Chat._parse_chat(self, chat) for chat in r.chats])
|
||||
peers = r.updates[0].peers
|
||||
|
||||
for peer in peers:
|
||||
chat_id = utils.get_channel_id(peer.peer.channel_id)
|
||||
|
||||
for chat in chats:
|
||||
if chat.id == chat_id:
|
||||
chat.distance = peer.distance
|
||||
break
|
||||
|
||||
return chats
|
@ -93,6 +93,10 @@ class Chat(Object):
|
||||
|
||||
permissions (:obj:`ChatPermissions` *optional*):
|
||||
Default chat member permissions, for groups and supergroups.
|
||||
|
||||
distance (``int``, *optional*):
|
||||
Distance in meters of this group chat from your location.
|
||||
Returned only in :meth:`~Client.get_nearby_chats`.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
@ -117,7 +121,8 @@ class Chat(Object):
|
||||
can_set_sticker_set: bool = None,
|
||||
members_count: int = None,
|
||||
restriction_reason: str = None,
|
||||
permissions: "pyrogram.ChatPermissions" = None
|
||||
permissions: "pyrogram.ChatPermissions" = None,
|
||||
distance: int = None
|
||||
):
|
||||
super().__init__(client)
|
||||
|
||||
@ -140,6 +145,7 @@ class Chat(Object):
|
||||
self.members_count = members_count
|
||||
self.restriction_reason = restriction_reason
|
||||
self.permissions = permissions
|
||||
self.distance = distance
|
||||
|
||||
@staticmethod
|
||||
def _parse_user_chat(client, user: types.User) -> "Chat":
|
||||
@ -170,6 +176,7 @@ class Chat(Object):
|
||||
title=chat.title,
|
||||
photo=ChatPhoto._parse(client, getattr(chat, "photo", None), peer_id),
|
||||
permissions=ChatPermissions._parse(getattr(chat, "default_banned_rights", None)),
|
||||
members_count=getattr(chat, "participants_count", None),
|
||||
client=client
|
||||
)
|
||||
|
||||
@ -188,6 +195,7 @@ class Chat(Object):
|
||||
photo=ChatPhoto._parse(client, getattr(channel, "photo", None), peer_id),
|
||||
restriction_reason=getattr(channel, "restriction_reason", None),
|
||||
permissions=ChatPermissions._parse(getattr(channel, "default_banned_rights", None)),
|
||||
members_count=getattr(channel, "participants_count", None),
|
||||
client=client
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user