-- -- $Id$ -- $Revision$ -- $Date$ -- local name = "whois.lua" local desc = "Vetinari's whois.lua" -- AKA: print the whois info to the tab/window where it was called and not -- to the server tab/window... local version = "0.3" pending = {} request = {} function xchat_register() return name, desc, version end function xchat_init() xchat.hook_command("WHOIS", xchat.PRI_NORM, "cmd_whois", nil, nil) xchat.hook_print("WhoIs Authenticated", xchat.PRI_NORM, "handle_whois_auth") xchat.hook_print("WhoIs Away Line", xchat.PRI_NORM, "handle_whois_away") xchat.hook_print("WhoIs Channel/Oper Line", xchat.PRI_NORM, "handle_whois_chan") xchat.hook_print("WhoIs End", xchat.PRI_NORM, "handle_whois_end") xchat.hook_print("WhoIs Identified", xchat.PRI_NORM, "handle_whois_ident") xchat.hook_print("WhoIs Idle Line with Signon", xchat.PRI_NORM, "handle_whois_idle_singon") xchat.hook_print("WhoIs Idle Line", xchat.PRI_NORM, "handle_whois_idle") xchat.hook_print("WhoIs Name Line", xchat.PRI_NORM, "handle_whois_name") xchat.hook_print("WhoIs Real Host", xchat.PRI_NORM, "handle_whois_host") xchat.hook_print("WhoIs Server Line", xchat.PRI_NORM, "handle_whois_server") xchat.hook_print("WhoIs Special", xchat.PRI_NORM, "handle_whois_special") end function cmd_whois(word, word_eol, data) local nick = word[2] local target = word[3] if target == nil then target = nick end local server = xchat.get_info("server") local ctx = xchat.get_context() table.insert(pending, { ["server"] = server, ["nick"] = nick, ["ctx"] = ctx, } ) xchat.command(string.format("QUOTE WHOIS %s %s", nick, target)) return xchat.EAT_ALL end function pending_ctx(nick, server) local ctx = table.foreach(pending, function(i, list) if xchat.nickcmp(list.nick, nick) == 0 and xchat.nickcmp(list.server, server) == 0 then return list.ctx end end ) return ctx end function context_set(nick) local server = xchat.get_info("server") local ctx = pending_ctx(nick, server) if ctx ~= nil then xchat.set_context(ctx) end return ctx end function print_emit(name, func, word) -- disable the print hook... else we'd run in an endless -- print/print_emit loop xchat.unhook(name) -- emit the print event xchat.emit_print(name, unpack(word)) -- and re-enable the hook xchat.hook_print(name, xchat.PRI_NORM, string.format("handle_whois_%s", func)) end function handle_whois_auth(word, data) if not context_set(word[1]) then return xchat.EAT_NONE end print_emit("WhoIs Authenticated", "auth", word) return xchat.EAT_XCHAT end function handle_whois_away(word, data) if not context_set(word[1]) then return xchat.EAT_NONE end print_emit("WhoIs Away Line", "away", word) return xchat.EAT_XCHAT end function handle_whois_chan(word, data) if not context_set(word[1]) then return xchat.EAT_NONE end print_emit("WhoIs Channel/Oper Line", "chan", word) return xchat.EAT_XCHAT end function handle_whois_end(word, data) if not context_set(word[1]) then return xchat.EAT_NONE end print_emit("WhoIs End", "end", word) local i = table.foreach(pending, function(n, list) if list.ctx == ctx then return n end end ) table.remove(pending, i) return xchat.EAT_XCHAT end function handle_whois_ident(word, data) if not context_set(word[1]) then return xchat.EAT_NONE end print_emit("WhoIs Identified", "ident", word) return xchat.EAT_XCHAT end function handle_whois_idle_singon(word, data) if not context_set(word[1]) then return xchat.EAT_NONE end print_emit("WhoIs Idle Line with Signon", "idle_singon", word) return xchat.EAT_XCHAT end function handle_whois_idle(word, data) if not context_set(word[1]) then return xchat.EAT_NONE end print_emit("WhoIs Idle Line", "idle", word) return xchat.EAT_XCHAT end function handle_whois_name(word, data) if not context_set(word[1]) then return xchat.EAT_NONE end print_emit("WhoIs Name Line", "name", word) return xchat.EAT_XCHAT end function handle_whois_host(word, data) if not context_set(word[1]) then return xchat.EAT_NONE end print_emit("WhoIs Real Host", "host", word) return xchat.EAT_XCHAT end function handle_whois_server(word, data) if not context_set(word[1]) then return xchat.EAT_NONE end print_emit("WhoIs Server Line", "server", word) return xchat.EAT_XCHAT end function handle_whois_special(word, data) if not context_set(word[1]) then return xchat.EAT_NONE end print_emit("WhoIs Special", "special", word) return xchat.EAT_XCHAT end -- vim: ts=4 sw=4 expandtab syn=lua