service: Add "get" command to retrieve a specific message
patch 3fe74b2337a9d66bddd47052220c413836cb05f9
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sun May 14 00:39:42 CEST 2023
* service: Add "get" command to retrieve a specific message
hunk ./service.py 18
+ 'get': (self.handle_command_get, 2, 2),
hunk ./service.py 116
+ )
+ 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 <peer> <compact_id>',
+ 'Get one message from peer with the compact ID',
hunk ./telegram.py 765
+
+ 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