telegram, irc: Add conversion of mentions for self @username as well as
patch 7300fb2b6fde17386971ea497343afae8526fb4c
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sat Jun 10 22:31:22 CEST 2023
* telegram, irc: Add conversion of mentions for self @username as well as
other mentions in self messages [saved messages]
diff -rN -u old-irgramd/irc.py new-irgramd/irc.py
--- old-irgramd/irc.py 2024-10-23 02:32:49.379326692 +0200
+++ new-irgramd/irc.py 2024-10-23 02:32:49.379326692 +0200
@@ -468,6 +468,9 @@
tgt = target if target else user.irc_nick
if self.tg.refwd_me:
msg = msg.format(user.irc_nick)
+ # replace self @username and other mentions for self messages sent by this instance of irgramd
+ msg = self.tg.replace_mentions(msg, user.irc_nick)
+
await self.send_irc_command(user, ':{} PRIVMSG {} :{}'.format(src_mask, tgt, msg))
async def reply_command(self, user, prfx, comm, params):
diff -rN -u old-irgramd/telegram.py new-irgramd/telegram.py
--- old-irgramd/telegram.py 2024-10-23 02:32:49.379326692 +0200
+++ new-irgramd/telegram.py 2024-10-23 02:32:49.383326686 +0200
@@ -395,17 +395,22 @@
'media': media
}
- def replace_mentions(self, text):
- def repl_mentioned(text):
+ def replace_mentions(self, text, me_nick=''):
+ def repl_mentioned(text, me_nick):
if text and text[0] == '@':
part = text[1:].lower()
+ if me_nick and part == self.tg_username:
+ return replacement(me_nick)
if part in self.irc.users:
- return '{}{}{}'.format('~', self.irc.users[part].irc_nick, '~')
+ return replacement(self.irc.users[part].irc_nick)
return text
+ def replacement(nick):
+ return '{}{}{}'.format('~',nick, '~')
+
if text.find('@') != -1:
words = text.split(' ')
- words_replaced = [repl_mentioned(elem) for elem in words]
+ words_replaced = [repl_mentioned(elem, me_nick) for elem in words]
text_replaced = ' '.join(words_replaced)
else:
text_replaced = text