exclam: Add delete (!del) command to delete messages
patch ee2b02319b5759d67df9fcc08fdafbd57a8fcc80
Author: E. Bosch <presidev@AT@gmail.com>
Date: Mon Jul 17 02:37:21 CEST 2023
* exclam: Add delete (!del) command to delete messages
diff -rN -u old-irgramd/exclam.py new-irgramd/exclam.py
--- old-irgramd/exclam.py 2024-11-25 15:11:29.545835805 +0100
+++ new-irgramd/exclam.py 2024-11-25 15:11:29.549835799 +0100
@@ -16,6 +16,7 @@
{ # Command Handler Arguments Min Max Maxsplit
'!re': (self.handle_command_re, 2, 2, 2),
'!ed': (self.handle_command_ed, 2, 2, 2),
+ '!del': (self.handle_command_del, 1, 1, -1),
}
self.tg = telegram
self.irc = telegram.irc
@@ -33,7 +34,10 @@
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)
+ if id is None:
+ chk_msg = None
+ else:
+ chk_msg = await self.tg.telegram_client.get_messages(entity=self.tmp_telegram_id, ids=id)
return id, chk_msg
async def handle_command_re(self, cid=None, msg=None, help=None):
@@ -80,3 +84,25 @@
'<new_message> replaces the current message.'
)
return reply
+
+ async def handle_command_del(self, cid=None, help=None):
+ if not help:
+ id, del_msg = await self.check_msg(cid)
+ if del_msg is not None:
+ deleted = await self.tg.telegram_client.delete_messages(self.tmp_telegram_id, del_msg)
+ if deleted[0].pts_count == 0:
+ reply = ('Not possible to delete',)
+ else:
+ self.tmp_tg_msg = None
+ reply = None
+ else:
+ reply = ('Unknown message to delete',)
+ else: # HELP.brief or HELP.desc (first line)
+ reply = (' !del Delete a message',)
+ if help == HELP.desc: # rest of HELP.desc
+ reply += \
+ (
+ ' !del <compact_id>',
+ 'Delete a message with <compact_id> on current channel/chat'
+ )
+ return reply