2323from . import mixins
2424from datetime import datetime as dt
2525from time import mktime
26-
27-
2826from .media import Photo
2927
3028
@@ -41,7 +39,11 @@ class User(BaseObject, mixins.ChatMixin):
4139 optional = {
4240 "last_name" : str ,
4341 "username" : str ,
44- "is_bot" : bool
42+ "language_code" : str ,
43+ "is_bot" : bool ,
44+ }
45+ replace_keys = {
46+ "language_code" : "lang" ,
4547 }
4648 _check_equality_ = "id"
4749
@@ -114,6 +116,9 @@ class Chat(BaseObject, mixins.ChatMixin):
114116 "sticker_set_name" : str ,
115117 "can_set_sticker_set" : bool
116118 }
119+ replace_keys = {
120+ "invite_link" : "_invite_link" ,
121+ }
117122 _check_equality_ = "id"
118123
119124 def _to_user (self ):
@@ -294,6 +299,70 @@ def kick(self, user, time=None):
294299 def permissions (self , user ):
295300 return Permissions (user , self )
296301
302+ def set_description (self , description = "" ):
303+ if self .type != "private" :
304+ """Set the new chat description. Leave empty to delete it."""
305+ if len (description ) <= 255 :
306+ self ._api .call ("setChatDescription" , {
307+ "chat_id" : self .id ,
308+ "description" : description
309+ }, expect = bool )
310+ else :
311+ raise ValueError ("The new description must be below 255 characters." )
312+ else :
313+ raise RuntimeError ("This method works only with non-private chats." )
314+
315+ @mixins ._require_api
316+ def revoke_invite_link (self ):
317+ """Revoke and generate a new invike link for this chat"""
318+ if self .type not in ("supergroup" , "channel" ):
319+ raise RuntimeError ("You can revoke the invite link only in a supergroup or a channel" )
320+
321+ link = self ._api .call ("exportChatInviteLink" , {
322+ "chat_id" : self .id ,
323+ }).get ('result' , None )
324+ self ._cache_invite_link = link
325+ return link
326+
327+ @property
328+ @mixins ._require_api
329+ def invite_link (self ):
330+ """Get the invite link of this chat"""
331+ if self .type not in ("supergroup" , "channel" ):
332+ raise RuntimeError ("You can get the invite link only in a supergroup or a channel" )
333+
334+ if hasattr (self , "_cache_invite_link" ):
335+ return self ._cache_invite_link
336+
337+ chat = self ._api .call ("getChat" , {
338+ "chat_id" : self .id ,
339+ }, expect = Chat )
340+ if not chat ._invite_link :
341+ return self .revoke_invite_link ()
342+
343+ self ._cache_invite_link = chat ._invite_link
344+ return self ._cache_invite_link
345+
346+ def pin_message (self , message , notify = True ):
347+ """Pin a message"""
348+ # Check if the chat is a supergroup
349+ if self .type not in ("supergroup" , "channel" ):
350+ raise RuntimeError ("This chat is nota a supergroup or channel!" )
351+
352+ if isinstance (message , Message ):
353+ message = message .id
354+
355+ return self ._api .call ("pinChatMessage" , {
356+ "chat_id" : self .id ,
357+ "message_id" : message ,
358+ "disable_notification" : not notify
359+ }, expect = bool )
360+
361+ def unpin_message (self ):
362+ return self ._api .call ("unpinChatMessage" , {
363+ "chat_id" : self .id ,
364+ }, expect = bool )
365+
297366
298367class Permissions :
299368 def __init__ (self , user , chat ):
0 commit comments