From e0fd6d457783ea949570b6b676b08a198a42373c Mon Sep 17 00:00:00 2001 From: totem4 Date: Sun, 4 Oct 2020 11:42:52 +0200 Subject: [PATCH] decode entire mex with autocompletion --- prof-banana.py | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/prof-banana.py b/prof-banana.py index 935f585..8b969fb 100644 --- a/prof-banana.py +++ b/prof-banana.py @@ -5,6 +5,9 @@ Import or export from dec to banana or from banana to dec. Thx to itec (https:// import prof import re +_links = {} +_lastlink = {} + def dec2banana(num, dictstart = None, shiftend = None, minlength = None, dictionary = None): #defaults if dictstart is None: dictstart = 0 @@ -74,7 +77,7 @@ def text2dec(text): return text def callback(x): - return " %s " % dec2banana(int(x[0], base=10)).upper() + return "%s" % dec2banana(int(x[0], base=10)).upper() def text2banana(text): text = re.sub(r"[0-9][0-9]*", callback, text) @@ -98,12 +101,41 @@ def _cmd_banana(cmd=None,text=None): recipient = prof.get_current_recipient() room = prof.get_current_muc() if recipient: - prof.send_line(proc) + prof.chat_show(recipient, proc) elif room: - prof.send_line(proc) + prof.room_show(room, proc) elif prof.current_win_is_console(): prof.cons_show(proc) +def _process_message(jid, current_jid, message): + links = re.search(r'[A-Z][A-Z]*',message).string.split('\n') + if links: + if jid not in _links: + _links[jid] = [] + + for link in links: + if link not in _links[jid]: + _links[jid].append(link) + + if current_jid == jid: + prof.completer_add("/banana dec", _links[jid]) + + _lastlink[jid] = links[len(links)-1] + + + +def prof_post_chat_message_display(jid, resource, message): + current_jid = prof.get_current_recipient() + _process_message(jid, current_jid, message) + +def prof_post_room_message_display(room, nick, message): + current_jid = prof.get_current_muc() + _process_message(jid, current_jid, message) + +def prof_on_room_history_message(room, nick, message, timestamp): + current_jid = prof.get_current_muc() + _process_message(jid, current_jid, message) + def prof_init(version, status, account_name, fulljid): synopsis = [ "/banana enc " @@ -114,7 +146,7 @@ def prof_init(version, status, account_name, fulljid): [ "", "The message to be bananified or debananified" ] ] examples = [ - "/banana dec 7467986 \n/banana enc GESUCANE" + "/banana enc 7467986 \n/banana dec GESUCANE" ] prof.register_command("/banana", 0, 2, synopsis, description, args, examples, _cmd_banana)