Update Telegram user info automatically
This commit is contained in:
@@ -66,7 +66,7 @@ class Puppet:
|
||||
@staticmethod
|
||||
def get_displayname(info, format=True):
|
||||
data = {
|
||||
"phone number": info.phone,
|
||||
"phone number": info.phone if hasattr(info, "phone") else None,
|
||||
"username": info.username,
|
||||
"full name": " ".join([info.first_name or "", info.last_name or ""]).strip(),
|
||||
"full name reversed": " ".join([info.first_name or "", info.last_name or ""]).strip(),
|
||||
|
||||
@@ -161,6 +161,8 @@ class User:
|
||||
portal = po.Portal.get_by_tgid(update.channel_id, peer_type="channel")
|
||||
if portal and portal.mxid:
|
||||
portal.update_telegram_pin(self, update.id)
|
||||
elif isinstance(update, (UpdateUserName, UpdateUserPhoto)):
|
||||
self.update_others_info(update)
|
||||
else:
|
||||
self.log.debug("Unhandled update: %s", update)
|
||||
|
||||
@@ -181,6 +183,15 @@ class User:
|
||||
sender = pu.Puppet.get(update.user_id)
|
||||
return portal.handle_telegram_typing(sender, update)
|
||||
|
||||
def update_others_info(self, update):
|
||||
puppet = pu.Puppet.get(update.user_id)
|
||||
if isinstance(update, UpdateUserName):
|
||||
if puppet.update_displayname(self, update):
|
||||
puppet.save()
|
||||
elif isinstance(update, UpdateUserPhoto):
|
||||
if puppet.update_avatar(self, update.photo.photo_big):
|
||||
puppet.save()
|
||||
|
||||
def update_status(self, update):
|
||||
puppet = pu.Puppet.get(update.user_id)
|
||||
if isinstance(update.status, UserStatusOnline):
|
||||
|
||||
Reference in New Issue
Block a user