mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Add get_nearby_chats method
This commit is contained in:
parent
74ecd2bb33
commit
95051d7fb1
@ -202,6 +202,7 @@ def pyrogram_api():
|
|||||||
get_dialogs_count
|
get_dialogs_count
|
||||||
update_chat_username
|
update_chat_username
|
||||||
get_common_chats
|
get_common_chats
|
||||||
|
get_nearby_chats
|
||||||
archive_chats
|
archive_chats
|
||||||
unarchive_chats
|
unarchive_chats
|
||||||
add_chat_members
|
add_chat_members
|
||||||
|
@ -47,6 +47,7 @@ from .unarchive_chats import UnarchiveChats
|
|||||||
from .unban_chat_member import UnbanChatMember
|
from .unban_chat_member import UnbanChatMember
|
||||||
from .unpin_chat_message import UnpinChatMessage
|
from .unpin_chat_message import UnpinChatMessage
|
||||||
from .update_chat_username import UpdateChatUsername
|
from .update_chat_username import UpdateChatUsername
|
||||||
|
from .get_nearby_chats import GetNearbyChats
|
||||||
|
|
||||||
|
|
||||||
class Chats(
|
class Chats(
|
||||||
@ -80,6 +81,7 @@ class Chats(
|
|||||||
CreateChannel,
|
CreateChannel,
|
||||||
AddChatMembers,
|
AddChatMembers,
|
||||||
DeleteChannel,
|
DeleteChannel,
|
||||||
DeleteSupergroup
|
DeleteSupergroup,
|
||||||
|
GetNearbyChats
|
||||||
):
|
):
|
||||||
pass
|
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):
|
||||||
|
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
|
@ -93,6 +93,10 @@ class Chat(Object):
|
|||||||
|
|
||||||
permissions (:obj:`ChatPermissions` *optional*):
|
permissions (:obj:`ChatPermissions` *optional*):
|
||||||
Default chat member permissions, for groups and supergroups.
|
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__(
|
def __init__(
|
||||||
@ -117,7 +121,8 @@ class Chat(Object):
|
|||||||
can_set_sticker_set: bool = None,
|
can_set_sticker_set: bool = None,
|
||||||
members_count: int = None,
|
members_count: int = None,
|
||||||
restriction_reason: str = None,
|
restriction_reason: str = None,
|
||||||
permissions: "pyrogram.ChatPermissions" = None
|
permissions: "pyrogram.ChatPermissions" = None,
|
||||||
|
distance: int = None
|
||||||
):
|
):
|
||||||
super().__init__(client)
|
super().__init__(client)
|
||||||
|
|
||||||
@ -140,6 +145,7 @@ class Chat(Object):
|
|||||||
self.members_count = members_count
|
self.members_count = members_count
|
||||||
self.restriction_reason = restriction_reason
|
self.restriction_reason = restriction_reason
|
||||||
self.permissions = permissions
|
self.permissions = permissions
|
||||||
|
self.distance = distance
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_user_chat(client, user: types.User) -> "Chat":
|
def _parse_user_chat(client, user: types.User) -> "Chat":
|
||||||
|
Loading…
Reference in New Issue
Block a user