patch 2e88501e2cdbf503df49404f4b4fffeed574658b
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sat Mar 19 23:26:56 CET 2022
* service: Add dialog command (only with list subcommand by now)
hunk ./irc.py 383
- reply = await self.service.parse_command(message)
+ reply = await self.service.parse_command(message, user.irc_nick)
hunk ./service.py 9
+from utils import compact_date
+
hunk ./service.py 16
+ 'dialog': (self.handle_command_dialog, 1, 2),
hunk ./service.py 21
-
- async def parse_command(self, line):
+ self.tmp_ircnick = None
+
+ async def parse_command(self, line, nick):
hunk ./service.py 27
+ self.tmp_ircnick = nick
hunk ./service.py 65
+ )
+ return reply
+
+ async def handle_command_dialog(self, command=None, id=None, help=None):
+ if not help:
+ if command == 'archive':
+ pass
+ elif command == 'delete':
+ pass
+ elif command == 'list':
+ reply = \
+ (
+ 'Dialogs:',
+ ' {:<11} {:<9} {:<9} {:4} {:<3} {:<4} {:<6} {}'.format(
+ 'Id', 'Unread', 'Mentions', 'Type', 'Pin', 'Arch', 'Last', 'Name'),
+ )
+ async for dialog in self.tg.telegram_client.iter_dialogs():
+ 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'
+ pin = 'Yes' if dialog.pinned else 'No'
+ arch = 'Yes' if dialog.archived else 'No'
+ last = compact_date(dialog.date)
+ name_in_irc = self.tmp_ircnick if id == self.tg.id else self.tg.tid_to_iid[id]
+ reply += (' {:<11d} {:<9d} {:<9d} {:4} {:<3} {:<4} {:<6} {}'.format(
+ id, unr, men, ty, pin, arch, last, name_in_irc),
+ )
+
+ else: # HELP.brief or HELP.desc (first line)
+ reply = (' dialog Manage conversations (dialogs)',)
+ if help == HELP.desc: # rest of HELP.desc
+ reply += \
+ (
+ ' dialog <subcommand> [id]',
+ 'Manage conversations (dialogs) established in Telegram, the',
+ 'following subcommands are available:',
+ ' archive <id> Archive the dialog specified by id',
+ ' delete <id> Delete the dialog specified by id',
+ ' list Show all dialogs',
hunk ./telegram.py 145
- self.tid_to_iid[chat.id] = channel
- self.irc.iid_to_tid[channel.lower()] = chat.id
+ self.tid_to_iid[-chat.id] = channel
+ self.irc.iid_to_tid[channel.lower()] = -chat.id
hunk ./utils.py 13
+import datetime
hunk ./utils.py 112
+
+def compact_date(date):
+ delta = datetime.datetime.now(datetime.timezone.utc) - date
+
+ if delta.days < 1:
+ compact_date = date.strftime('%H:%M')
+ elif delta.days < 366:
+ compact_date = date.strftime('%d-%b')
+ else:
+ compact_date = date.strftime('%Y')
+
+ return compact_date