patch 873004141f83b60da113e8967a2148d9d33008be Author: E. Bosch Date: Thu Oct 10 23:11:40 CEST 2024 * exclam: Add reaction (!react) command to send emoticon->emoji as Telegram reaction diff -rN -u old-irgramd/emoji2emoticon.py new-irgramd/emoji2emoticon.py --- old-irgramd/emoji2emoticon.py 2024-11-22 10:13:15.267851236 +0100 +++ new-irgramd/emoji2emoticon.py 2024-11-22 10:13:15.267851236 +0100 @@ -86,9 +86,13 @@ '\U0001f644': '"o o,"', '\U0001f914': '":-L"', '\U0001f92b': '":-o-m"', - '\U0001f970': '":)e>"' + '\U0001f970': '":)e>"', } +emo_inv = {} +for k in emo: + emo_inv[emo[k][1:-1]] = k + def replace_mult(line, emo): for utf_emo in emo: if utf_emo in line: diff -rN -u old-irgramd/exclam.py new-irgramd/exclam.py --- old-irgramd/exclam.py 2024-11-22 10:13:15.267851236 +0100 +++ new-irgramd/exclam.py 2024-11-22 10:13:15.271851229 +0100 @@ -7,9 +7,12 @@ # can be found in the LICENSE file included in this project. import os -from telethon.errors.rpcerrorlist import MessageNotModifiedError, MessageAuthorRequiredError +from telethon.tl.functions.messages import SendReactionRequest +from telethon import types as tgty +from telethon.errors.rpcerrorlist import MessageNotModifiedError, MessageAuthorRequiredError, ReactionInvalidError from utils import command, HELP +from emoji2emoticon import emo_inv class exclam(command): def __init__(self, telegram): @@ -21,6 +24,7 @@ '!fwd': (self.handle_command_fwd, 2, 2, -1), '!upl': (self.handle_command_upl, 1, 2, 2), '!reupl': (self.handle_command_reupl, 2, 3, 3), + '!react': (self.handle_command_react, 2, 2, -1), } self.tg = telegram self.irc = telegram.irc @@ -188,3 +192,32 @@ 'HTTP/HTTPS URL.', ) return reply + + async def handle_command_react(self, cid=None, act=None, help=None): + if not help: + id, chk_msg = await self.check_msg(cid) + if chk_msg is not None: + if act in emo_inv: + utf8_emo = emo_inv[act] + reaction = [ tgty.ReactionEmoji(emoticon=utf8_emo) ] + try: + update = await self.tg.telegram_client(SendReactionRequest(self.tmp_telegram_id, id, reaction=reaction)) + except ReactionInvalidError: + reply = ('!react: Reaction not allowed',) + else: + self.tmp_tg_msg = update.updates[0].message + reply = True + else: + reply = ('!react: Unknown reaction',) + else: + reply = ('!react: Unknown message to react',) + else: # HELP.brief or HELP.desc (first line) + reply = (' !react React to a message',) + if help == HELP.desc: # rest of HELP.desc + reply += \ + ( + ' !react ', + 'React with to a message with ,', + 'irgramd will translate emoticon to closest emoji.', + ) + return reply