diff --git a/telethon/_client/auth.py b/telethon/_client/auth.py index 2a3e3af3..ff03d92d 100644 --- a/telethon/_client/auth.py +++ b/telethon/_client/auth.py @@ -267,7 +267,7 @@ async def sign_up( result = await self(_tl.fn.auth.SignUp( phone_number=phone, - phone_code_hash=phone_code_hash, + phone_code_hash=self._phone_code_hash, first_name=first_name, last_name=last_name )) diff --git a/telethon/_client/updates.py b/telethon/_client/updates.py index 9882cf0a..d86c3e09 100644 --- a/telethon/_client/updates.py +++ b/telethon/_client/updates.py @@ -2,6 +2,7 @@ import asyncio import inspect import itertools import random +import functools import sys import time import traceback @@ -225,7 +226,7 @@ class Entities: self._client = client self._entities = {e.id: e for e in itertools.chain( (User._new(client, u) for u in users), - (Chat._new(client, c) for u in chats), + (Chat._new(client, c) for c in chats), )} def get(self, peer): diff --git a/telethon/_events/chataction.py b/telethon/_events/chataction.py index 435ab459..c8a6f849 100644 --- a/telethon/_events/chataction.py +++ b/telethon/_events/chataction.py @@ -13,6 +13,7 @@ class ChatAction(EventBuilder): * Whenever a new message is pinned. * Whenever a user scores in a game. * Whenever a user joins or is added to the group. + * Whenever a new chat join request is sent. * Whenever a user is removed or leaves a group if it has less than 50 members or the removed user was a bot. @@ -48,6 +49,9 @@ class ChatAction(EventBuilder): `True` if the user's join request was approved. along with `user_joined` will be also True. + new_join_request (:tl:`ExportedChatInvite`, optional): + Chat Invite, if the new chat join request was sent (Only Bots get this Update). + created (`bool`, optional): `True` if this chat was just created. @@ -80,6 +84,7 @@ class ChatAction(EventBuilder): kicked_by = None created = None from_approval = None + new_join_request = None users = None new_title = None pin_ids = None @@ -109,6 +114,11 @@ class ChatAction(EventBuilder): kicked_by = True users = update.user_id + elif isinstance(update, _tl.UpdateBotChatInviteRequester): + users = update.user_id + where = _tl.PeerChat(update.chat_id) + new_join_request = update.invite + # UpdateChannel is sent if we leave a channel, and the update._entities # set by _process_update would let us make some guesses. However it's # better not to rely on this. Rely only in MessageActionChatDeleteUser. @@ -161,11 +171,14 @@ class ChatAction(EventBuilder): new_photo = True elif isinstance(action, _tl.MessageActionPinMessage) and msg.reply_to: where = msg - pin_ids=[msg.reply_to_msg_id] + pin_ids=[msg.reply_to.reply_to_msg_id] elif isinstance(action, _tl.MessageActionGameScore): where = msg new_score = action.score - + else: + return + else: + return self = cls.__new__(cls) self._client = client @@ -196,6 +209,7 @@ class ChatAction(EventBuilder): self.user_added = True self._added_by = added_by self.user_approved = from_approval + self.new_join_request = new_join_request # If `from_id` was not present (it's `True`) or the affected # user was "kicked by itself", then it left. Else it was kicked. @@ -290,6 +304,17 @@ class ChatAction(EventBuilder): return self._pinned_messages + async def approve_user(self, approved: bool = True): + """ + Approve or disapprove chat join request of user. + """ + if self.new_join_request: + return await self._client(_tl.fn.messages.HideChatJoinRequest( + await self.get_input_chat(), + user_id=self.user_id, + approved=approved + )) + @property def added_by(self): """ diff --git a/telethon/types/_custom/chat.py b/telethon/types/_custom/chat.py index f5056eff..2e4ac14c 100644 --- a/telethon/types/_custom/chat.py +++ b/telethon/types/_custom/chat.py @@ -2,6 +2,8 @@ from typing import Optional, List, TYPE_CHECKING from datetime import datetime from dataclasses import dataclass import mimetypes + +from ..._sessions.types import Entity from .chatgetter import ChatGetter from .sendergetter import SenderGetter from .messagebutton import MessageButton