-- -- 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 lua script sample -- This script uses whole WeeChat API functions, it may be used for -- testing purposes. weechat.register("wlusample", "0.3", "wluend", "WeeChat lua script sample") -- some command handlers weechat.add_command_handler("wlunothing", "wlunothing") weechat.add_command_handler("wlutest", "wlutest", "test command", "channel", "a channel name", "%C") weechat.add_command_handler("wluinfo", "wluinfo", "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("wlucommand", "wlucommand", "execute a WeeChat comand", "weechat_cmd | text") weechat.add_command_handler("wludcc", "wludcc", "display DCC", "", "", "") weechat.add_command_handler("wluserver", "wluserver", "display server list", "", "", "") weechat.add_command_handler("wluchannel", "wluchannel", "display channel list", "", "", "") weechat.add_command_handler("wlunick", "wlunick", "display nick list", "", "", "") weechat.add_command_handler("wluwindow", "wluwindow", "display window list", "", "", "") weechat.add_command_handler("wlubuffer", "wlubuffer", "display buffer list", "", "", "") weechat.add_command_handler("wlubufferdata", "wlubufferdata", "display current buffer content", "", "", "") weechat.add_command_handler("wlugetconfig", "wlugetconfig", "get a config option value", "option", "", "") weechat.add_command_handler("wlusetconfig", "wlusetconfig", "set a config option value", "option value", "", "") weechat.add_command_handler("wlugetplugin", "wlugetplugin", "get a plugin config option value", "option", "", "") weechat.add_command_handler("wlusetplugin", "wlusetplugin", "set a plugin config option value", "option value", "", "") -- timer handler weechat.add_timer_handler(60*5, "wlutimer"); -- keyboard handler weechat.add_keyboard_handler("wlukeyboard"); -- message handler weechat.add_message_handler("privmsg", "wluprivmsg") -- modifiers weechat.add_modifier("irc_in", "privmsg", "wlumodin") weechat.add_modifier("irc_user", "", "wlumoduser") weechat.add_modifier("irc_out", "privmsg", "wlumodout") -- command handlers for removing some handlers weechat.add_command_handler("wludelmsg", "wludelmsg", "delete privmsg message handler", "", "", "") weechat.add_command_handler("wludelcmd", "wludelcmd", "delete wlunothing command handler", "", "", "") weechat.add_command_handler("wludeltimer", "wludeltimer", "delete wlutimer timer handler", "", "", "") weechat.add_command_handler("wludelkeyboard", "wludelkeyboard", "delete wlukeyboard keyboard handler", "", "", "") weechat.add_command_handler("wludelmod", "wludelmod", "delete all modifiers", "", "", "") -- command handler for clearing infobar weechat.add_command_handler("wludelinfo", "wludelinfo", "remove infobar message(s)", "", "", "") function wlunothing(server, args) weechat.print("wlunothing: nothing done there!") return weechat.PLUGIN_RC_OK() end function wlutest(server, args) weechat.print("wlutest: server = '#{server}', args = '#{args}'") weechat.print_infobar(10, "wlutest: test infobar") weechat.log("wlutest: test log on photon/#abc", "#abc", "photon") weechat.log("wlutest: test log on photon", "", "photon") return weechat.PLUGIN_RC_OK() end function wluinfo(server, args) if args then value = Weechat.get_info(args) weechat.print("get_info("..args..") = "..value) else weechat.print("wluinfo: missing info argument") end return weechat.PLUGIN_RC_OK() end function wlucommand(server, args) if args then weechat.command(args) else weechat.print("wlucommand: missing command argument") end return weechat.PLUGIN_RC_OK() end function wludcc(server, args) dccs = weechat.get_dcc_info() if dccs ~= nil then if dccs then dcc, dccinfos = next (dccs, nil) while (dcc) do key, value = next (dccinfos, nil) while (key) do weechat.print(key.." = "..value) key, value = next (dccinfos, key) end dcc, dccinfos = next (dccs, dcc) end else weechat.print("wludcc: no DCC") end else weechat.print("wludcc: error reading DCC") end return weechat.PLUGIN_RC_OK() end function wluserver(server, args) servers = weechat.get_server_info() if servers ~= nil then if servers then srv, srvinfos = next (servers, nil) while (srv) do key, value = next (srvinfos, nil) while (key) do weechat.print(srv.." -> "..key.." = '"..value.."'") key, value = next (srvinfos, key) end srv, srvinfos = next (servers, srv) end else weechat.print("wluserver: no server") end else weechat.print("wluserver: error reading servers") end return weechat.PLUGIN_RC_OK() end function wluchannel(server, args) chans = weechat.get_channel_info(server) if chans ~= nil then if chans then chan, chaninfos = next (chans, nil) while (chan) do key, value = next (chaninfos, nil) while (key) do weechat.print(chan.." -> "..key.." = '"..value.."'") key, value = next (chaninfos, key) end chan, chaninfos = next (chans, chan) end else weechat.print("wluchannel: no channel") end else weechat.print("wluchannel: error reading channels") end return weechat.PLUGIN_RC_OK() end function wlunick(server, args) chans = weechat.get_channel_info(server) if chans ~= nil then if chans then chan, chaninfos = next (chans, nil) while (chan) do nicks = weechat.get_nick_info(server, chan) if nicks ~= nil then if nicks then nick, nickinfos = next (nicks, nil) while (nick) do key, value = next (nickinfos, nil) while (key) do weechat.print(chan.." -> "..nick .. " -> " ..key.." = '"..value.."'") key, value = next (nickinfos, key) end nick, nickinfos = next (nicks, nick) end else weechat.print("wlunick: no nick") end else weechat.print("wlunick: error reading nicks") end chan, chaninfos = next (chans, chan) end else weechat.print("wlunick: no channel") end else weechat.print("wlunick: error reading channels") end return weechat.PLUGIN_RC_OK() end function wluwindow(server, args) wf = weechat.get_window_info() if wf then weechat.print ("**** windows infos ****") w, winfos = next (wf, nil) while (w) do key, value = next (winfos, nil) while (key) do weechat.print(" > " .. key .. " => " .. value) key, value = next (winfos, key) end weechat.print ("----------------------") w, winfos = next (wf, w) end else weechat.print("wluwindow: no window info") end return weechat.PLUGIN_RC_OK() end function wlubuffer(server, args) bf = weechat.get_buffer_info() if bf then b, binfos = next (bf, nil) while (b) do weechat.print("**** info for buffer no " .. b .. " ****") key, value = next (binfos, nil) while (key) do weechat.print(" > " .. key .. " => " .. value) key, value = next (binfos, key) end weechat.print ("----------------------") b, infos = next (bf, b) end else weechat.print("wlubuffer: no buffer info") end return weechat.PLUGIN_RC_OK() end function wlubufferdata(server, args) srv = weechat.get_info("server") channel = weechat.get_info("channel") bc = weechat.get_buffer_data(srv, channel) if bc then b, bdatas = next (bc, nil) weechat.print("**** buffer data for '" .. channel .. "'@'" .. server .. "' ****") while (b) do key, value = next (bdatas, nil) while (key) do weechat.print(" > " .. key .. " => " .. value) key, value = next (bdatas, key) end weechat.print ("----------------------") b, bdatas = next (bc, b) end else weechat.print("wlubufferdata: no buffer data") end return weechat.PLUGIN_RC_OK() end function wlugetconfig(server, option) if option ~= "" then value = weechat.get_config(option) weechat.print(option.." = "..value) else weechat.print("wlugetconfig: missing option") end return weechat.PLUGIN_RC_OK() end function wlusetconfig(server, args) if args ~= "" then option = string.sub(args, 0, string.find(args, " ") - 1) value = string.sub(args, string.find(args, " ") + 1) weechat.set_config(option, value) else weechat.print("wlusetconfig: missing option/value") end return weechat.PLUGIN_RC_OK() end function wlugetplugin(server, option) if option ~= "" then value = weechat.get_plugin_config(option) weechat.print(option.." = "..value) else weechat.print("wlugetconfig: missing option") end return weechat.PLUGIN_RC_OK() end function wlusetplugin(server, args) if args ~= "" then option = string.sub(args, 0, string.find(args, " ") - 1) value = string.sub(args, string.find(args, " ") + 1) weechat.set_plugin_config(option, value) else weechat.print("wlusetplugin: missing option/value") end return weechat.PLUGIN_RC_OK() end function wlutimer() weechat.print("wlutimer: this is the timer handler") return weechat.PLUGIN_RC_OK() end function wlukeyboard(server, input_before, input_after) -- nothing here return weechat.PLUGIN_RC_OK() end function wluprivmsg(server, args) weechat.print("wluprivmsg: privmsg received: server = '"..server.."', args = '"..args.."'") return weechat.PLUGIN_RC_OK() end function wlumodin(server, args) return args .. " [modifier IN]" end function wlumoduser(server, args) -- return message as-is return args end function wlumodout(server, args) return args .. " [modifier OUT]" end function wludelmsg(server, args) weechat.remove_handler("privmsg", "wluprivmsg") weechat.print("wludelmsg: privmsg handler removed") return weechat.PLUGIN_RC_OK() end function wludelcmd(server, args) weechat.remove_handler("wlunothing", "wlunothing") weechat.print("wludelcmd: wlunothing command handler removed") return weechat.PLUGIN_RC_OK() end function wludeltimer(server, args) weechat.remove_timer_handler("wlutimer") weechat.print("wludeltimer: wlutimer timer handler removed") return weechat.PLUGIN_RC_OK() end function wludelkeyboard(server, args) weechat.remove_keyboard_handler("wlukeyboard") weechat.print("wludeltimer: wlukeyboard keyboard handler removed") return weechat.PLUGIN_RC_OK() end function wludelmod(server, args) weechat.remove_modifier("irc_in", "privmsg", "wlumodin") weechat.remove_modifier("irc_user", "", "wlumoduser") weechat.remove_modifier("irc_out", "privmsg", "wlumodout") weechat.print("wludelmod: modifiers removed") return weechat.PLUGIN_RC_OK() end function wludelinfo(server, args) if args ~= "" then weechat.remove_infobar(args) else weechat.remove_infobar() end weechat.print("wludelinfo: infobar message(s) removed") return weechat.PLUGIN_RC_OK() end function wluend(server, args) weechat.print("wlusample: ending...") return weechat.PLUGIN_RC_OK() end