telegram: Fix recognition of Telegram user, group, channel types
patch 7f549d8b7544443878875c310fea6f1fb6385364
Author: E. Bosch <presidev@AT@gmail.com>
Date: Wed Apr 12 00:43:22 CEST 2023
* telegram: Fix recognition of Telegram user, group, channel types
diff -rN -u old-irgramd/service.py new-irgramd/service.py
--- old-irgramd/service.py 2024-11-22 16:51:54.029821827 +0100
+++ new-irgramd/service.py 2024-11-22 16:51:54.029821827 +0100
@@ -76,14 +76,14 @@
reply = \
(
'Dialogs:',
- ' {:<11} {:<9} {:<9} {:4} {:<3} {:<4} {:<6} {}'.format(
+ ' {:<11} {:<9} {:<9} {:5} {:<3} {:<4} {:<6} {}'.format(
'Id', 'Unread', 'Mentions', 'Type', 'Pin', 'Arch', 'Last', 'Name'),
)
async for dialog in self.tg.telegram_client.iter_dialogs():
id, type = tgutils.resolve_id(dialog.id)
unr = dialog.unread_count
men = dialog.unread_mentions_count
- ty = 'User' if dialog.is_user else 'Chat' if dialog.is_group else 'Chan'
+ ty = self.tg.get_entity_type(dialog.entity, format='short')
pin = 'Yes' if dialog.pinned else 'No'
arch = 'Yes' if dialog.archived else 'No'
last = compact_date(dialog.date)
@@ -94,7 +94,7 @@
name_in_irc = self.tg.tid_to_iid[id]
else:
name_in_irc = '<Unknown>'
- reply += (' {:<11d} {:<9d} {:<9d} {:4} {:<3} {:<4} {:<6} {}'.format(
+ reply += (' {:<11d} {:<9d} {:<9d} {:5} {:<3} {:<4} {:<6} {}'.format(
id, unr, men, ty, pin, arch, last, name_in_irc),
)
diff -rN -u old-irgramd/telegram.py new-irgramd/telegram.py
--- old-irgramd/telegram.py 2024-11-22 16:51:54.029821827 +0100
+++ new-irgramd/telegram.py 2024-11-22 16:51:54.033821821 +0100
@@ -263,7 +263,7 @@
else:
entity = await self.telegram_client.get_entity(tid)
entity_cache[0] = entity
- entity_type = self.get_entity_type(entity)
+ entity_type = self.get_entity_type(entity, format='long')
return 'Telegram ' + entity_type + ' ' + str(tid) + ': ' + entity.title
async def get_channel_creation(self, channel, entity_cache):
@@ -291,8 +291,24 @@
tid = self.id
return tid
- def get_entity_type(self, entity):
- return type(entity).__name__
+ def get_entity_type(self, entity, format):
+ if isinstance(entity, tgty.User):
+ short = long = 'User'
+ elif isinstance(entity, tgty.Chat):
+ short = 'Chat'
+ long = 'Chat/Basic Group'
+ elif isinstance(entity, tgty.Channel):
+ if entity.broadcast:
+ short = 'Broad'
+ long = 'Broadcast Channel'
+ elif entity.megagroup:
+ short = 'Mega'
+ long = 'Super/Megagroup Channel'
+ elif entity.gigagroup:
+ short = 'Giga'
+ long = 'Broadcast Gigagroup Channel'
+
+ return short if format == 'short' else long
def add_to_cache(self, id, mid, message, user, chan):
if len(self.cache) >= 10000: