PtokaX forum

Archive => Archived 5.1 boards => Finished Scripts => Topic started by: CrazyGuy on 09 April, 2007, 15:24:29

Title: Self-Redirection script
Post by: CrazyGuy on 09 April, 2007, 15:24:29

--[[
HubJumper
LUA 5.1.x
A redirect-self script
By CrazyGuy
On request by D??k][W?z??d?
Last updated April 8th 2007
]]--

sBotname = "Hub-Jumper"

cmdAddHub = "addhub"
cmdDelHub = "delhub"
cmdShowHubs = "showhubs"
cmdHelp = "redirhelp"
cmdRD = "jump"

tAddDelProfiles = { -- set which profiles can add/remove hubs
[0] = 1, -- use 1 for allowed, 0 for not allowed
[1] = 1,
[2] = 1,
[3] = 0,
[4] = 0,
[5] = 1,
[-1] = 0,
}

tShowProfiles = { -- set which profiles can see redirect hubs
[0] = 1, -- use 1 for allowed, 0 for not allowed
[1] = 1,
[2] = 1,
[3] = 1,
[4] = 1,
[5] = 1,
[-1] = 1,
}

tRDProfiles = { -- set which profiles can redirect themselves
[0] = 0, -- use 1 for allowed, 0 for not allowed
[1] = 1,
[2] = 1,
[3] = 1,
[4] = 1,
[5] = 0,
[-1] = 1,
}

tRDHubs = {
[1] = "wizardsandgoblins.myftp.org:411",
[2] = "bitcheshideout.no-ip.info:666",
[3] = "bluesplace.no-ip.info:411",
[4] = "supanova2.no-ip.org:411",
[5] = "charliesplayroom.no-ip.info:23",
[6] = "agonyaunt.no-ip.org:777",
}

tCMD = {
[cmdHelp] = function(sNick,iProf,sArg)
local sHelp = "Available commands:\n\n\t\t!"..cmdHelp.."\t\t\t-Shows this help file\n"
if tAddDelProfiles[iProf] == 1 then
sHelp = sHelp.."\n\t\t!"..cmdAddHub.." <address:port>\t-Add a hub to the list\n"
.."\t\t!"..cmdDelHub.." <address:port>\t-Delete a hub from the list\n"
end
if tShowProfiles[iProf] == 1 then
sHelp = sHelp.."\n\t\t!"..cmdShowHubs.."\t\t-Shows all hubs in the list\n"
end
if tRDProfiles[iProf] == 1 then
sHelp = sHelp.."\n\t\t!"..cmdRD.." <address:port>\t-Redirect yourself to the specified hub\n"
end
return sHelp
end,
[cmdRD] = function(sNick,iProf,sArg)
if sArg then
if tRDProfiles[iProf] == 1 then
return 1
else
return "You are not allowed to use this command"
end
else
return "Please specify an address -> !"..cmdRD.." <address:port>"
end
end,
[cmdShowHubs] = function(sNick,iProf,sArg)
if tShowProfiles[iProf] == 1 then
local sHubs = "Current hubs to redirect to:\n\n"
for k in pairs(tRDHubs) do
sHubs = sHubs.."\t\t"..tRDHubs[k].."\n"
end
return sHubs
else
return "You are not allowed to use this command"
end
end,
[cmdAddHub] = function(sNick,iProf,sArg)
if sArg then -- if address is specified
if tAddDelProfiles[iProf] == 1 then
table.insert(tRDHubs, sArg) -- add hub
return sArg.." has been added to the list"
else
return "You are not allowed to use this command"
end
else
return "Please specify an address -> !"..cmdAddHub.." <address:port>"
end
end,
[cmdDelHub] = function(sNick,iProf,sArg)
if sArg then
if tAddDelProfiles[iProf] == 1 then
for k in pairs(tRDHubs) do
if tRDHubs[k] == sArg then
table.remove(tRDHubs, k) -- remove hub
break
end
end
return sArg.." has been removed from the list"
else
return "You are not allowed to use this command"
end
else
return "Please specify an address -> !"..cmdDelHub.." <address:port>"
end
end,
}

Main = function()
frmHub:RegBot(sBotname)
end

ChatArrival = function(User,Data)
local _,_,cmd,sArgs = string.find(Data, "%b<>%s%p(%S+)%s(.*)|")
if sArgs then
if tCMD[cmd] then
local sReturn = tCMD[cmd](User.sName,User.iProfile,sArgs)
if sReturn == 1 then
-- user will be redirected
User:SendData(sBotname, "You will now be redirected to "..sArgs)
User:Redirect(sArgs, "You have choosen to be redirected to this hub. Enjoy your stay there")
else
-- return the message
User:SendData(sBotname,sReturn)
end
return 1
end
else
-- no arguments, could be show or help command
local _,_,sCmd = string.find(Data, "%b<>%s%p(%S+)|")
if tCMD[sCmd] then
User:SendData(sBotname, tCMD[sCmd](User.sName,User.iProfile,nil))
return 1
end
end
end

ToArrival = function(User,Data)
local _,_,cmd,sArgs = string.find(Data, "%b<>%s%p(%S+)%s(.*)|")
if sArgs then
if tCMD[cmd] then
local sReturn = tCMD[cmd](User.sName,User.iProfile,sArgs)
if sReturn == 1 then
-- user will be redirected
User:SendPM(sBotname, "You will now be redirected to "..sArgs)
User:Redirect(sArgs, "You have choosen to be redirected to this hub. Enjoy your stay there")
else
-- return the message
User:SendData(sBotname,sReturn)
end
return 1
end
else
-- no arguments, could be show or help command
local _,_,sCmd = string.find(Data, "%b<>%s%p(%S+)|")
if tCMD[sCmd] then
User:SendPM(sBotname, tCMD[sCmd](User.sName,User.iProfile,nil))
return 1
end
end
end

NewUserConnected = function(User)
local sMenu = frmHub:GetHubName()
User:SendData("$UserCommand 1 3 "..sMenu.."\\"..sBotname.."\\Help$<%[mynick]> !"..cmdHelp.."&#124;|")
if tAddDelProfiles[User.iProfile] == 1 then
User:SendData("$UserCommand 0 3 &#124;|")
User:SendData("$UserCommand 1 3 "..sMenu.."\\"..sBotname.."\\Add Hub$<%[mynick]> !"..cmdAddHub.." %[line:Address]&#124;|")
User:SendData("$UserCommand 1 3 "..sMenu.."\\"..sBotname.."\\Delete Hub$<%[mynick]> !"..cmdDelHub.." %[line:Address]&#124;|")
end
if tShowProfiles[User.iProfile] == 1 then
User:SendData("$UserCommand 0 3 &#124;|")
User:SendData("$UserCommand 1 3 "..sMenu.."\\"..sBotname.."\\Show Hubs$<%[mynick]> !"..cmdShowHubs.."&#124;|")
end
if tRDProfiles[User.iProfile] == 1 then
User:SendData("$UserCommand 0 3 &#124;|")
User:SendData("$UserCommand 1 3 "..sMenu.."\\"..sBotname.."\\Redirect Self$<%[mynick]> !"..cmdRD.." %[line:Address]&#124;|")
end
end
OpConnected = NewUserConnected