# Copyright (c) 2011 by Stephan Huebner # # Intended use: # # save a list of recently joined rooms or queried users # # TODO: - possibly save all open rooms when the script is loaded ? # - save join-date ? # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # History: SCR_NAME = "rbstr" SCR_AUTHOR = "Stephan Huebner " SCR_VERSION = "0.1.0" SCR_LICENSE = "GPL3" SCR_DESC = "save/show recently joined rooms/queries" SCR_COMMAND = "rbstr" import_ok = True b_list = [] try: import weechat except: print "Script must be run under weechat. http://wwweechat.weechat.org" import_ok = False settings = { "bcount" : 15, # number of buffers to save "buffers" : "" # buffers you entered (including servers?) } def alert(myString): weechat.prnt("", myString) return def errMsg(myMsg): alert("ERR: " + myMsg) return def fn_command(data, buffer, args): args = args.split() if len(args)==0: fn_list() return weechat.WEECHAT_RC_OK def fn_list(): global b_list if len(b_list)>0: alert("List of recently opened rooms/queries (max. " + str(settings["bcount"]) + " shown):") b_list.reverse() for listIndex in range(len(b_list)): alert(str(listIndex+1) + ": " + b_list[listIndex]) b_list.reverse() else: alert("No recent buffers savd!") return weechat.WEECHAT_RC_OK def fn_createBufferString(): global b_list myString = "" for lEntry in b_list: myString += "{'" + lEntry + "'}" return myString def fn_configchange(data, option, value): global settings fields = option.split(".") myOption = fields[-1] try: settings[myOption] = value alert("Option {0} has been changed to {1}".format(myOption, settings[myOption])) except KeyError: errMsg("There is no option named %s" %myOption) return weechat.WEECHAT_RC_OK def fn_join_signal(data, signal, signal_data): global b_list global settings b_name = weechat.buffer_get_string(signal_data, "name") for listIndex in range(len(b_list)): if b_list[listIndex] == b_name: b_list.pop(listIndex) break b_list.append(b_name) # List-comprehension instead? if len(b_list) > int(settings["bcount"]): b_list.pop(0) weechat.config_set_plugin("buffers", fn_createBufferString()) #fn_list() return weechat.WEECHAT_RC_OK if __name__ == "__main__" and import_ok: if weechat.register(SCR_NAME, SCR_AUTHOR, SCR_VERSION, SCR_LICENSE, SCR_DESC, "", ""): # synchronize weechat- and scriptsettings for option, default_value in settings.items(): if weechat.config_is_set_plugin(option): alert("opton " + option + " is set to " + weechat.config_get_plugin(option)) settings[option] = weechat.config_get_plugin(option) if option == "buffers": # need to set buffers seperately alert(settings["buffers"]) myBuffers = settings[option][2:-2] # remove beginning and end try: myBuffers = myBuffers.split("'}{'") alert(len(myBuffers)) for bufname in myBuffers: b_list.append(bufname) except: myBuffers = "" else: weechat.config_set_plugin(option, str(default_value)) # catch "channel opened" weechat.hook_signal("irc_channel_opened", "fn_join_signal", "") # catch "query opened" weechat.hook_signal("irc_pv_opened", "fn_join_signal", "") weechat.hook_config("plugins.var.python." + SCR_NAME + ".*", "fn_configchange", "") # catch configchanges weechat.hook_command( # help-text SCR_COMMAND, SCR_DESC, "", "Attention:" + """ * This script shows recently joined/opened rooms and queries. They are added automatically as soon as you join them. NOTES: * if you join a room/query that is already in the list, it just changes its position * if you try to join a room/query you are in at present, nothing is changed (the script only reacts to exectuted join/query-messages) Available options are: bcount: maximum number to save Commands: - no commands available. Just lust "/rbstr" to show a list of recently joined rooms/queries""","", "fn_command", "") fn_list()