Hey Guys ..
My mission is to put all commands in a table like this:
tCmds = {
["Master"] = {
["test"] = "DoTest",
["test2"] = "DoTest2",
["test3"] = "DoTest3",
}
}
}
where ["Master"] is GetProfileName(user.iProfile) and ["test"] is the command written - "DoTest" is the command executed..
The problem is "DoTest" is returned as tring :(
Any help will be appreciated..
Snooze
here's (http://jaras.nd.e-wro.pl/SAW.rar) one of my old bots, which isn't exactly what you ask for, "very chaotic" =], but may help.
Dunno if this works, but this is how I would do it.
tCmds = {
["Master"] = {
["test"] = {DoTest, {param1,param2,param3}} -- an array with the function and a nested array with function params - f(a,b,c)
["test2"] = {DoTest2,{}}
["test3"] = {DoTest3,{param}}
}
}
}
-- and you just do:
return tCmds["Master"]["test"][1](unpack(tCmds["Master"]["test"][2]))
Thanks bastya_elvtars!
It looks like what i need, though im having a hard time creating a working example.. Could i get you to create one small example for me ?
Snooze
In order 2 make others learn, I post the result here. No warranties! :)
Bot = "Bot"
function ChatArrival(user, data)
if string.sub(data, 1, 1) == "<" or (string.sub(data,1,5+string.len(Bot))=="$To: "..Bot) or (string.sub(data,1,5+string.len(SuChat))=="$To: "..SuChat) or (string.sub(data,1,5+string.len(OpChat))=="$To: "..OpChat) then
local data = string.sub(data,1,string.len(data)-1)
s,e,prefix,cmd,cmdData = string.find(data,"%b<> (%S)(%S+)(.*)")
if tPrefix[prefix] ~= nil then
ParseCmds(user,data,cmd)
-- this must go to ToArrival, and Bot has to be string.find-ed IMHO
-- if string.sub(data,1,5+string.len(Bot))=="$To: "..Bot then SendPmToNick(sUser["sUser"],Bot, doReturn) clearArs() elseif string.sub(data,1,5+string.len(SuChat))=="$To: "..SuChat then SendPmToNick(sUser["sUser"],SuChat, doReturn) clearArs() elseif string.sub(data,1,5+string.len(OpChat))=="$To: "..OpChat then SendPmToOps(OpChat, doReturn) clearArs() else user:SendData(doReturn) clearArs() return 1 end
end
end
end
function DoTest(user,data)
SendToAll(Bot, "hey hey hey")
end
function ParseCmds(user,data,cmd)
local SKCMD = {
["Owner"] = {
["test"] = {DoTest,{user,data}}
}
}
local tmpArr=SKCMD[GetProfileName(user.iProfile)][cmd]
if not tmpArr then
user:SendData(Bot, "*** Error! - [ "..cmd.." ] is not a valid command. Type "..SKCONF["BotPrefix"].."help to get a list of available commands.")
else
return tmpArr[1](unpack(tmpArr[2]))
end
end