postpone: add match_prefix setting
authorStefan Huber <shuber@sthu.org>
Fri, 8 Nov 2013 20:48:35 +0000 (21:48 +0100)
committerStefan Huber <shuber@sthu.org>
Sat, 9 Nov 2013 15:25:41 +0000 (16:25 +0100)
weechat/postpone.py

index 3224242340769f382c1549622190d6302405e422..57022046ecfc9dcdc4e90ac3de0099df449f19b7 100644 (file)
@@ -20,6 +20,8 @@
 # (this script requires WeeChat 0.3.0 or newer)
 #
 # History:
 # (this script requires WeeChat 0.3.0 or newer)
 #
 # History:
+# 2013-11-08, Stefan Huber <shuber@sthu.org>
+#   version 0.2.2: add match_prefix setting
 # 2012-12-29, Stefan Huber <shuber@sthu.org>
 #   version 0.2.1: fix channel determination in join_cb
 # 2010-05-20, Alexander Schremmer <alex@alexanderweb.de>
 # 2012-12-29, Stefan Huber <shuber@sthu.org>
 #   version 0.2.1: fix channel determination in join_cb
 # 2010-05-20, Alexander Schremmer <alex@alexanderweb.de>
@@ -32,13 +34,16 @@ import re
 
 SCRIPT_NAME    = "postpone"
 SCRIPT_AUTHOR  = "Alexander Schremmer <alex@alexanderweb.de>"
 
 SCRIPT_NAME    = "postpone"
 SCRIPT_AUTHOR  = "Alexander Schremmer <alex@alexanderweb.de>"
-SCRIPT_VERSION = "0.2.1"
+SCRIPT_VERSION = "0.2.2"
 SCRIPT_LICENSE = "GPL3"
 SCRIPT_DESC    = "Postpones written messages for later dispatching if target nick is not on channel"
 
 SCRIPT_LICENSE = "GPL3"
 SCRIPT_DESC    = "Postpones written messages for later dispatching if target nick is not on channel"
 
-
 postpone_data = {}
 
 postpone_data = {}
 
+settings = {
+        'match_prefix': ('', 'Postpone message if prefix before "nick:" is matched.')
+}
+
 
 def join_cb(data, signal, signal_data):
     server = signal.split(',')[0] # EFNet,irc_in_JOIN
 
 def join_cb(data, signal, signal_data):
     server = signal.split(',')[0] # EFNet,irc_in_JOIN
@@ -63,14 +68,16 @@ def command_run_input(data, buffer, command):
         input_s = w.buffer_get_string(buffer, 'input')
         server = w.buffer_get_string(buffer, 'localvar_server')
         channel = w.buffer_get_string(buffer, 'localvar_channel')
         input_s = w.buffer_get_string(buffer, 'input')
         server = w.buffer_get_string(buffer, 'localvar_server')
         channel = w.buffer_get_string(buffer, 'localvar_channel')
+        match_prefix = w.config_get_plugin('match_prefix')
 
 
-        match = re.match(r'([\w-]+?): (.*)$', input_s)
+        match = re.match(match_prefix + r'([\w-]+?): (.*)$', input_s)
         if match:
             nick, message = match.groups()
             if not channel_has_nick(server, channel, nick):
                 w.prnt(buffer, "| Enqueued message for %s: %s" % (nick, message))
         if match:
             nick, message = match.groups()
             if not channel_has_nick(server, channel, nick):
                 w.prnt(buffer, "| Enqueued message for %s: %s" % (nick, message))
+                save = nick + ": " + message
                 postpone_data.setdefault(server, {}).setdefault(channel,
                 postpone_data.setdefault(server, {}).setdefault(channel,
-                        {}).setdefault(nick.lower(), []).append(input_s)
+                        {}).setdefault(nick.lower(), []).append(save)
                 w.buffer_set(buffer, 'input', "")
                 # XXX why doesn't this work? i want to have the typed text
                 # in the history
                 w.buffer_set(buffer, 'input', "")
                 # XXX why doesn't this work? i want to have the typed text
                 # in the history
@@ -82,6 +89,14 @@ def command_run_input(data, buffer, command):
 
 if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
                     SCRIPT_DESC, "", ""):
 
 if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
                     SCRIPT_DESC, "", ""):
+
+    version = w.info_get('version_number', '') or 0
+    for option, default_desc in settings.iteritems():
+        if not w.config_is_set_plugin(option):
+            w.config_set_plugin(option, default_desc[0])
+        if int(version) >= 0x00030500:
+            w.config_set_desc_plugin(option, default_desc[1])
+
     w.hook_command_run("/input return", "command_run_input", "")
     w.hook_signal('*,irc_in2_join', 'join_cb', '')
 
     w.hook_command_run("/input return", "command_run_input", "")
     w.hook_signal('*,irc_in2_join', 'join_cb', '')