diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index ca49538f..212cf370 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -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 diff --git a/docs/source/conf.py b/docs/source/conf.py index b0313901..47d0107e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -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} """ } diff --git a/docs/source/topics/smart-plugins.rst b/docs/source/topics/smart-plugins.rst index 68ea9f51..7cfed47d 100644 --- a/docs/source/topics/smart-plugins.rst +++ b/docs/source/topics/smart-plugins.rst @@ -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 ``(, 0)``. +- Printing ``echo`` will show something like ````. -- 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 ````. +- Printing ``echo.handler`` will reveal the handler, that is, a tuple containing the actual handler and the group it + was registered on ``(, 0)``. Unloading ^^^^^^^^^ diff --git a/pyrogram/client/methods/chats/__init__.py b/pyrogram/client/methods/chats/__init__.py index fddb48ce..13829029 100644 --- a/pyrogram/client/methods/chats/__init__.py +++ b/pyrogram/client/methods/chats/__init__.py @@ -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 diff --git a/pyrogram/client/methods/chats/get_nearby_chats.py b/pyrogram/client/methods/chats/get_nearby_chats.py new file mode 100644 index 00000000..0b590d13 --- /dev/null +++ b/pyrogram/client/methods/chats/get_nearby_chats.py @@ -0,0 +1,71 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2019 Dan Tès +# +# 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 . + +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 diff --git a/pyrogram/client/types/user_and_chats/chat.py b/pyrogram/client/types/user_and_chats/chat.py index 54c1df68..f208bae0 100644 --- a/pyrogram/client/types/user_and_chats/chat.py +++ b/pyrogram/client/types/user_and_chats/chat.py @@ -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 )