patch 3fe74b2337a9d66bddd47052220c413836cb05f9 Author: E. Bosch Date: Sun May 14 00:39:42 CEST 2023 * service: Add "get" command to retrieve a specific message diff -rN -u old-irgramd/service.py new-irgramd/service.py --- old-irgramd/service.py 2024-10-23 04:30:42.395534228 +0200 +++ new-irgramd/service.py 2024-10-23 04:30:42.395534228 +0200 @@ -15,6 +15,7 @@ { # Command Handler Arguments Min Max 'code': (self.handle_command_code, 1, 1), 'dialog': (self.handle_command_dialog, 1, 2), + 'get': (self.handle_command_get, 2, 2), 'help': (self.handle_command_help, 0, 1), 'history': (self.handle_command_history, 1, 3), 'mark_read': (self.handle_command_mark_read, 1, 1), @@ -115,6 +116,30 @@ ) return reply + async def handle_command_get(self, peer=None, mid=None, help=None): + if not help: + id = self.tg.mid.id_to_num_offset(mid) + peer_id, reply = self.get_peer_id(peer.lower()) + if reply: return reply + + msg = await self.tg.telegram_client.get_messages(entity=peer_id, ids=id) + if msg is None: + reply = ('Message not found',) + return reply + await self.tg.handle_telegram_message(event=None, message=msg, history=True) + reply = () + return reply + + else: # HELP.brief or HELP.desc (first line) + reply = (' get Get a message by id and peer',) + if help == HELP.desc: # rest of HELP.desc + reply += \ + ( + ' get ', + 'Get one message from peer with the compact ID', + ) + return reply + async def handle_command_help(self, help_command=None, help=None): start_help = ('*** Telegram Service Help ***',) diff -rN -u old-irgramd/telegram.py new-irgramd/telegram.py --- old-irgramd/telegram.py 2024-10-23 04:30:42.395534228 +0200 +++ new-irgramd/telegram.py 2024-10-23 04:30:42.395534228 +0200 @@ -762,3 +762,11 @@ return sum + aux else: return 0 + + def id_to_num_offset(self, mid): + if self.mesg_base is not None: + id_rel = self.id_to_num(mid) + id = id_rel + self.mesg_base + else: + id = None + return id