From d2fb2856fc724dd8ef3400d944eabcc61fb0ea26 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Wed, 8 Aug 2018 20:20:19 -0400 Subject: looooots of weechat --- weechat/.weechat/python/autojoin.py | 43 ++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'weechat/.weechat/python/autojoin.py') diff --git a/weechat/.weechat/python/autojoin.py b/weechat/.weechat/python/autojoin.py index 3fe4b6b..61449ff 100644 --- a/weechat/.weechat/python/autojoin.py +++ b/weechat/.weechat/python/autojoin.py @@ -43,6 +43,9 @@ # 2014-05-22, Nathaniel Wesley Filardo # version 0.2.5: Fix keyed channel support # +# 2016-01-13, The fox in the shell +# version 0.2.6: Support keeping chan list as secured data +# # @TODO: add options to ignore certain buffers # @TODO: maybe add an option to enable autosaving on part/join messages @@ -51,7 +54,7 @@ import re SCRIPT_NAME = "autojoin" SCRIPT_AUTHOR = "xt " -SCRIPT_VERSION = "0.2.5" +SCRIPT_VERSION = "0.2.6" SCRIPT_LICENSE = "GPL3" SCRIPT_DESC = "Configure autojoin for all servers according to currently joined channels" SCRIPT_COMMAND = "autojoin" @@ -89,9 +92,7 @@ def autosave_channels_on_quit(signal, callback, callback_data): # print/execute commands for server, channels in items.iteritems(): - channels = channels.rstrip(',') - command = "/set irc.server.%s.autojoin '%s'" % (server, channels) - w.command('', command) + process_server(server, channels) return w.WEECHAT_RC_OK @@ -111,10 +112,7 @@ def autosave_channels_on_activity(signal, callback, callback_data): match = re.match(pattern, callback_data) if match: # check if nick is my nick. In that case: save - channel = match.group(2) - channels = channels.rstrip(',') - command = "/set irc.server.%s.autojoin '%s'" % (server, channels) - w.command('', command) + process_server(server, channels) else: # someone else: ignore continue @@ -126,19 +124,38 @@ def autojoin_cb(data, buffer, args): """But I can't believe somebody would want that behaviour""" items = find_channels() + if args == '--run': + run = True + else: + run = False + # print/execute commands for server, channels in items.iteritems(): + process_server(server, channels, run) + + return w.WEECHAT_RC_OK + +def process_server(server, channels, run=True): + option = "irc.server.%s.autojoin" % server channels = channels.rstrip(',') + oldchans = w.config_string(w.config_get(option)) + if not channels: # empty channel list - continue - command = '/set irc.server.%s.autojoin %s' % (server, channels) - if args == '--run': + return + + # Note: re already caches the result of regexp compilation + sec = re.match('^\${sec\.data\.(.*)}$', oldchans) + if sec: + secvar = sec.group(1) + command = "/secure set %s %s" % (secvar, channels) + else: + command = "/set irc.server.%s.autojoin '%s'" % (server, channels) + + if run: w.command('', command) else: w.prnt('', command) - return w.WEECHAT_RC_OK - def find_channels(): """Return list of servers and channels""" #@TODO: make it return a dict with more options like "nicks_count etc." -- cgit 1.4.1