Code: Select all
--Author: M_D_K
local script_name = "auto_invite.lua"
local script_desc = "Author: M_D_K|Automatically invite you to channels that are invite only (you need to be on the access list though)"
local script_ver = "1.0"
--store channels we're waiting an invite for
wait_list = {}
function find(needle, haystack)
if haystack == nil or needle == nil then
return false, -1;
end
for k, v in pairs(haystack) do
if v == needle then
return true, k
end
end
return false, -1
end
function safe_invite(channels)
--run through every index in channels check if we're already waiting and insert if not
--really horrible performance on large data sets
for k, v in pairs(channels) do
local present, loc = find(v, wait_list)
if not present then
table.insert(wait_list, v)
xchat.commandf("msg ChanServ invite %s", v)
end
end
end
function handle(word, word_eol)
if #word < 2 then
return xchat.EAT_ALL
end
local chans = word
table.remove(chans, 1) --eat the first entry (always "ajoin")
safe_invite(chans)
return xchat.EAT_ALL
end
--gets called every time there is an invited event
--looks like this:
-- You have been invited to #channel by someone (network)
function invite(word)
local present, loc = find(word[1], wait_list)
if present then
table.remove(wait_list, loc)
xchat.commandf("join %s", word[1])
end
return xchat.EAT_NONE
end
function xchat_register()
return script_name, script_desc, script_ver;
end
function xchat_init()
xchat.hook_command("ajoin", "handle", xchat.PRI_NORM, "Usage: AJOIN <channel>");
xchat.hook_print("Invited", "invite", xchat.PRI_NORM);
end