exclam: Add edit (!ed) command to modify already sent messages
patch 74e097435eeb72086c6ed3f43a98ce3f5463d1c6
Author: E. Bosch <presidev@AT@gmail.com>
Date: Tue Jul 11 01:48:40 CEST 2023
* exclam: Add edit (!ed) command to modify already sent messages
hunk ./exclam.py 9
+from telethon.errors.rpcerrorlist import MessageNotModifiedError, MessageAuthorRequiredError
+
hunk ./exclam.py 18
+ '!ed': (self.handle_command_ed, 2, 2, 2),
hunk ./exclam.py 33
+
+ async def check_msg(self, cid):
+ id = self.tg.mid.id_to_num_offset(self.tmp_telegram_id, cid)
+ chk_msg = await self.tg.telegram_client.get_messages(entity=self.tmp_telegram_id, ids=id)
+ return id, chk_msg
hunk ./exclam.py 41
- id = self.tg.mid.id_to_num_offset(self.tmp_telegram_id, cid)
- chk_msg = await self.tg.telegram_client.get_messages(entity=self.tmp_telegram_id, ids=id)
+ id, chk_msg = await self.check_msg(cid)
hunk ./exclam.py 55
+ )
+ return reply
+
+ async def handle_command_ed(self, cid=None, new_msg=None, help=None):
+ if not help:
+ id, ed_msg = await self.check_msg(cid)
+ if ed_msg is not None:
+ try:
+ self.tmp_tg_msg = await self.tg.telegram_client.edit_message(ed_msg, new_msg)
+ except MessageNotModifiedError:
+ self.tmp_tg_msg = ed_msg
+ reply = True
+ except MessageAuthorRequiredError:
+ reply = ('Not the author of the message to edit',)
+ else:
+ reply = True
+ else:
+ reply = ('Unknown message to edit',)
+ else: # HELP.brief or HELP.desc (first line)
+ reply = (' !ed Edit a message',)
+ if help == HELP.desc: # rest of HELP.desc
+ reply += \
+ (
+ ' !ed <compact_id> <new_message>',
+ 'Edit a message with <compact_id> on current channel/chat,',
+ '<new_message> replaces the current message.'