From: Stefan Huber Date: Fri, 8 Nov 2013 20:48:35 +0000 (+0100) Subject: postpone: add match_prefix setting X-Git-Url: https://git.sthu.org/?p=shutils.git;a=commitdiff_plain;h=81b6254cb5584003514bd19aedece666573f2fa0 postpone: add match_prefix setting --- diff --git a/weechat/postpone.py b/weechat/postpone.py index 3224242..5702204 100644 --- a/weechat/postpone.py +++ b/weechat/postpone.py @@ -20,6 +20,8 @@ # (this script requires WeeChat 0.3.0 or newer) # # History: +# 2013-11-08, Stefan Huber +# version 0.2.2: add match_prefix setting # 2012-12-29, Stefan Huber # version 0.2.1: fix channel determination in join_cb # 2010-05-20, Alexander Schremmer @@ -32,13 +34,16 @@ import re SCRIPT_NAME = "postpone" SCRIPT_AUTHOR = "Alexander Schremmer " -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" - 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 @@ -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') + 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)) + save = nick + ": " + message 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 @@ -82,6 +89,14 @@ def command_run_input(data, buffer, command): 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', '')