# # Copyright (c) 2006-2007 by FlashCode # # 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 2 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, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # WeeChat python script sample # This script uses whole WeeChat API functions, it may be used for # testing purposes. import weechat weechat.register("wpysample", "0.3", "wpyend", "WeeChat python script sample") # some command handlers weechat.add_command_handler("wpynothing", "wpynothing") weechat.add_command_handler("wpytest", "wpytest", "test command", "channel", "a channel name", "%C") weechat.add_command_handler("wpyinfo", "wpyinfo", "display info with get_info()", "version | nick | channel | server | away | weechat_dir | weechat_libdir | weechat_sharedir", "info to read", "version|nick|channel|server|away|weechat_dir|weechat_libdir|weechat_sharedir") weechat.add_command_handler("wpycommand", "wpycommand", "execute a WeeChat comand", "weechat_cmd | text") weechat.add_command_handler("wpydcc", "wpydcc", "display DCC", "", "", "") weechat.add_command_handler("wpyserver", "wpyserver", "display server list", "", "", "") weechat.add_command_handler("wpychannel", "wpychannel", "display channel list", "", "", "") weechat.add_command_handler("wpynick", "wpynick", "display nick list", "", "", "") weechat.add_command_handler("wpywindow", "wpywindow", "display window list", "", "", "") weechat.add_command_handler("wpybuffer", "wpybuffer", "display buffer list", "", "", "") weechat.add_command_handler("wpybufferdata", "wpybufferdata", "display current buffer content", "", "", "") weechat.add_command_handler("wpygetconfig", "wpygetconfig", "get a config option value", "option", "", "") weechat.add_command_handler("wpysetconfig", "wpysetconfig", "set a config option value", "option value", "", "") weechat.add_command_handler("wpygetplugin", "wpygetplugin", "get a plugin config option value", "option", "", "") weechat.add_command_handler("wpysetplugin", "wpysetplugin", "set a plugin config option value", "option value", "", "") # timer handler weechat.add_timer_handler(60*5, "wpytimer"); # keyboard handler weechat.add_keyboard_handler("wpykeyboard"); # message handler weechat.add_message_handler("privmsg", "wpyprivmsg") # modifiers weechat.add_modifier("irc_in", "privmsg", "wpymodin") weechat.add_modifier("irc_user", "", "wpymoduser") weechat.add_modifier("irc_out", "privmsg", "wpymodout") # command handlers for removing some handlers weechat.add_command_handler("wpydelmsg", "wpydelmsg", "delete privmsg message handler", "", "", ""); weechat.add_command_handler("wpydelcmd", "wpydelcmd", "delete wpynothing command handler", "", "", "") weechat.add_command_handler("wpydeltimer", "wpydeltimer", "delete wpytimer timer handler", "", "", "") weechat.add_command_handler("wpydelkeyboard", "wpydelkeyboard", "delete wpykeyboard keyboard handler", "", "", "") weechat.add_command_handler("wpydelmod", "wpydelmod", "delete all modifiers", "", "", "") # command handler for clearing infobar weechat.add_command_handler("wpydelinfo", "wpydelinfo", "remove infobar message(s)", "", "", ""); def wpynothing(server, args): weechat.prnt("wpynothing: nothing done there!") return weechat.PLUGIN_RC_OK def wpytest(server, args): weechat.prnt("wpytest: server = '%s', args = '%s'" %(server, args)) weechat.print_infobar(10, "wpytest: test infobar") weechat.log("wpytest: test log on photon/#abc", "#abc", "photon") weechat.log("wpytest: test log on photon", "", "photon") return weechat.PLUGIN_RC_OK def wpyinfo(server, args): if args != "": weechat.prnt("get_info(%s) = %s" %(args, weechat.get_info(args))) else: weechat.prnt("wpyinfo: missing info argument") return weechat.PLUGIN_RC_OK def wpycommand(server, args): if args != "": weechat.command(args) else: weechat.prnt("wpycommand: missing command argument") return weechat.PLUGIN_RC_OK def wpydcc(server, args): dccs = weechat.get_dcc_info() if dccs != None: if dccs == []: weechat.prnt("wpydcc: no DCC") else: for d in dccs: for b in d.keys(): weechat.prnt("%s = %s" %(b, d[b])) else: weechat.prnt("wpydcc: error reading DCC") return weechat.PLUGIN_RC_OK def wpyserver(server, args): servers = weechat.get_server_info() if servers != None: if servers == {}: weechat.prnt("wpyserver: no server") else: for s in servers: for i in servers[s]: weechat.prnt("%s -> %s = '%s'" %(s, i, str(servers[s][i]))) else: weechat.prnt("wpyserver: error reading servers") return weechat.PLUGIN_RC_OK def wpychannel(server, args): chans = weechat.get_channel_info(weechat.get_info("server")) if chans != None: if chans == {}: weechat.prnt("wpychannel: no channel") else: for s in chans: for i in chans[s]: weechat.prnt("%s -> %s = '%s'" %(s, i, str(chans[s][i]))) else: weechat.prnt("wpychannel: error reading channels") return weechat.PLUGIN_RC_OK def wpynick(server, args): chans = weechat.get_channel_info(weechat.get_info("server")) if chans != None: if chans == {}: weechat.prnt("wpynick: no nick") else: for c in chans: nicks = weechat.get_nick_info(weechat.get_info("server"), c) if nicks != None: if nicks == {}: weechat.prnt("wpynick: no nick") else: for n in nicks: for f in nicks[n]: weechat.prnt("%s -> %s -> %s = '%s'" %(c, n, f, str(nicks[n][f]))) else: weechat.prnt("wpynick: error reading nicks") else: weechat.prnt("wpynick: error reading channels") return weechat.PLUGIN_RC_OK def wpywindow(server, args): wf = weechat.get_window_info() if wf != None and wf != []: weechat.prnt ("**** windows infos ****") for w in wf: for i in w: weechat.prnt (" > %s => %s" % (i, w[i])) weechat.prnt ("----------------------") else: weechat.prnt ("wpywindow: no window info") return weechat.PLUGIN_RC_OK def wpybuffer(server, args): bf = weechat.get_buffer_info() if bf != None and bf != {}: for b in bf: weechat.prnt ("**** info for buffer no %d ****" % b) for c in bf[b]: weechat.prnt (" > %s => %s" % (c, bf[b][c])) weechat.prnt ("----------------------") else: weechat.prnt ("wpybuffer: no buffer info") return weechat.PLUGIN_RC_OK def wpybufferdata(server, args): server = weechat.get_info("server") channel = weechat.get_info("channel") bc = weechat.get_buffer_data(server, channel) if bc != None and bc != []: weechat.prnt ("**** buffer data for '%s'@'%s' ****" % (channel, server)) for l in bc: for i in l: weechat.prnt (" > %s => %s" % (i, l[i])) weechat.prnt ("----------------------") else: weechat.prnt ("wpybufferdata: no buffer data") return weechat.PLUGIN_RC_OK def wpygetconfig(server, option): if args != "": weechat.prnt("%s = %s" %(option, weechat.get_config(option))) else: weechat.prnt("wpygetconfig: missing option") return weechat.PLUGIN_RC_OK def wpysetconfig(server, args): if args != "": option = args[:args.find(" ")] value = args[args.find(" "):] weechat.set_config(option, value) else: weechat.prnt("wpysetconfig: missing option/value") return weechat.PLUGIN_RC_OK def wpygetplugin(server, option): if args != "": weechat.prnt("%s = %s" %(option, weechat.get_plugin_config(option))) else: weechat.prnt("wpygetconfig: missing option") return weechat.PLUGIN_RC_OK def wpysetplugin(server, args): if args != "": option = args[:args.find(" ")] value = args[args.find(" "):] weechat.set_plugin_config(option, value) else: weechat.prnt("wpysetplugin: missing option/value") return weechat.PLUGIN_RC_OK def wpytimer(): weechat.prnt("wpytimer: this is the timer handler") return weechat.PLUGIN_RC_OK def wpykeyboard(key, input_before, input_after): # nothing here return weechat.PLUGIN_RC_OK def wpyprivmsg(server, args): weechat.prnt("wpyprivmsg: privmsg received: server = '%s', args = '%s'" %(server, args)) return weechat.PLUGIN_RC_OK def wpymodin(server, args): return args + " [modifier IN]" def wpymoduser(server, args): # return message as-is return args def wpymodout(server, args): return args + " [modifier OUT]" def wpydelmsg(server, args): weechat.remove_handler("privmsg", "wpyprivmsg") weechat.prnt("wpydelmsg: privmsg handler removed") return weechat.PLUGIN_RC_OK def wpydelcmd(server, args): weechat.remove_handler("wpynothing", "wpynothing") weechat.prnt("wpydelcmd: wpynothing command handler removed") return weechat.PLUGIN_RC_OK def wpydeltimer(server, args): weechat.remove_timer_handler("wpytimer") weechat.prnt("wpydeltimer: wpytimer timer handler removed") return weechat.PLUGIN_RC_OK def wpydelkeyboard(server, args): weechat.remove_keyboard_handler("wpykeyboard") weechat.prnt("wpydelkeyboard: wpykeyboard keyboard handler removed") return weechat.PLUGIN_RC_OK def wpydelmod(server, args): weechat.remove_modifier("irc_in", "privmsg", "wpymodin"); weechat.remove_modifier("irc_user", "", "wpymoduser"); weechat.remove_modifier("irc_out", "privmsg", "wpymodout"); weechat.prnt("wpydelmod: modifiers removed"); return weechat.PLUGIN_RC_OK def wpydelinfo(server, args): if args != "": weechat.remove_infobar(args) else: weechat.remove_infobar() weechat.prnt("wpydelinfo: infobar message(s) removed"); return weechat.PLUGIN_RC_OK def wpyend(server, args): weechat.prnt("wpysample: ending...") return weechat.PLUGIN_RC_OK