From ebad34cbc76bf8931714ec1af20439fbe33b81bc Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 16 Aug 2019 22:47:31 +0200 Subject: [PATCH 1/4] Fix smart-plugins.rst docs --- docs/source/topics/smart-plugins.rst | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/docs/source/topics/smart-plugins.rst b/docs/source/topics/smart-plugins.rst index 5131f27b..7cfed47d 100644 --- a/docs/source/topics/smart-plugins.rst +++ b/docs/source/topics/smart-plugins.rst @@ -291,10 +291,9 @@ Load/Unload Plugins at Runtime In the previous section we've explained how to specify which plugins to load and which to ignore before your Client starts. Here we'll show, instead, how to unload and load again a previously registered plugin at runtime. -Each function decorated with the usual ``on_message`` decorator (or any other decorator that deals with Telegram updates -) will be modified in such a way that, 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: +Each function decorated with the usual ``on_message`` decorator (or any other decorator that deals with Telegram +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. - ``plugins/handlers.py`` @@ -306,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 ^^^^^^^^^ From 8d700239d94e4dc2ae46194c8845593a11b3051a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 17 Aug 2019 13:12:13 +0200 Subject: [PATCH 2/4] Update PDF fonts --- docs/source/conf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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} """ } From 74ecd2bb33b1cf316b5dc11dd08440e3e09d8118 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 17 Aug 2019 22:22:28 +0200 Subject: [PATCH 3/4] Add missing members_count attribute when parsing chats --- pyrogram/client/types/user_and_chats/chat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/types/user_and_chats/chat.py b/pyrogram/client/types/user_and_chats/chat.py index b32dc3e7..f6e938df 100644 --- a/pyrogram/client/types/user_and_chats/chat.py +++ b/pyrogram/client/types/user_and_chats/chat.py @@ -170,6 +170,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 +189,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 ) @@ -715,7 +717,6 @@ class Chat(Object): return self._client.leave_chat(self.id) - def export_invite_link(self): """Bound method *export_invite_link* of :obj:`Chat`. From 95051d7fb1946c7718e6b56e9154f29233bbc871 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 17 Aug 2019 22:23:34 +0200 Subject: [PATCH 4/4] Add get_nearby_chats method --- compiler/docs/compiler.py | 1 + pyrogram/client/methods/chats/__init__.py | 4 +- .../client/methods/chats/get_nearby_chats.py | 71 +++++++++++++++++++ pyrogram/client/types/user_and_chats/chat.py | 8 ++- 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 pyrogram/client/methods/chats/get_nearby_chats.py 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/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..7f9e3614 --- /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): + 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 = 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 f6e938df..64507cb5 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":