telegram, irc: Add conversion of "mention:" (IRC style) to "@mention" in sent messages
patch 3ec451218b80bdd3c409b4aec91ae94ef4fa5c38
Author: E. Bosch <presidev@AT@gmail.com>
Date: Thu Jun 15 20:08:03 CEST 2023
* telegram, irc: Add conversion of "mention:" (IRC style) to "@mention" in sent messages
hunk ./irc.py 409
+ message = self.tg.replace_mentions(message, me_nick='', received=False)
hunk ./telegram.py 398
- def replace_mentions(self, text, me_nick=''):
- def repl_mentioned(text, me_nick):
- if text and text[0] == '@':
- part = text[1:].lower()
+ def replace_mentions(self, text, me_nick='', received=True):
+ # For received replace @mention to ~mention~
+ # For sent replace mention: to @mention
+ rargs = {}
+ def repl_mentioned(text, me_nick, received, mark, index, rargs):
+ if text and text[index] == mark:
+ if received:
+ subtext = text[1:]
+ else:
+ subtext = text[:-1]
+ part = subtext.lower()
hunk ./telegram.py 410
- return replacement(me_nick)
+ return replacement(me_nick, **rargs)
hunk ./telegram.py 412
- return replacement(self.irc.users[part].irc_nick)
+ return replacement(self.irc.users[part].irc_nick, **rargs)
hunk ./telegram.py 415
- def replacement(nick):
- return '{}{}{}'.format('~',nick, '~')
-
- if text.find('@') != -1:
+ def replacement(nick, repl_pref, repl_suff):
+ return '{}{}{}'.format(repl_pref, nick, repl_suff)
+
+ if received:
+ mark = '@'
+ index = 0
+ rargs['repl_pref'] = '~'
+ rargs['repl_suff'] = '~'
+ else:
+ mark = ':'
+ index = -1
+ rargs['repl_pref'] = '@'
+ rargs['repl_suff'] = ''
+
+ if text.find(mark) != -1:
hunk ./telegram.py 431
- words_replaced = [repl_mentioned(elem, me_nick) for elem in words]
+ words_replaced = [repl_mentioned(elem, me_nick, received, mark, index, rargs) for elem in words]