PtokaX forum

Archive => Archived 5.1 boards => Conversion Requests => Topic started by: speedX on 26 February, 2008, 07:36:02

Title: Problem converting Showreg script
Post by: speedX on 26 February, 2008, 07:36:02
Hello,
I am having some probs in converting this script to the NEW API, please if possible someone help me converting it.
I have converted some part of the script to which i was familiar but some code bits in tCommands are left to be converted.

Here is the code:

--[[

Registered Users per Profile - LUA 5.0/5.1 by jiten (8/9/2006)

]]--

tSettings = {
-- Bot Name
sName = SetMan.GetString(21),

-- Command Name
sCommand = "showprof"
}

ChatArrival = function(user, data)
local _,_, to = string.find(data,"^$To:%s(%S+)%sFrom:")
local _,_, msg = string.find(data,"%b<>%s(.*)|$")
-- Message sent to Bot or in Main
if (to and to == tSettings.sName) or not to then
-- Parse command
local _,_, cmd = string.find(msg, "^%p(%S+)")
-- Exists
if cmd and tCommands[string.lower(cmd)] then
cmd = string.lower(cmd)
-- If user has permission
if tCommands[cmd].tLevels[user.iProfile] then
return tCommands[cmd].fFunction(user, msg), true
else
return Core.SendToNick(user.sNick,"<"..tSettings.sName.."> *** Error: You are not allowed to use this command!"), true
end
end
end
end

ToArrival = ChatArrival

tCommands = {
[tSettings.sCommand] = {
fFunction = function(user, data)
-- Search for profile
local _,_, profile = string.find(data, "^%S+%s(%S+)$")
-- Exists
if profile then
-- Temporary table
local tProfiles = {}
-- Loop through profiles
for i, v in ipairs(ProfMan.GetProfiles()) do
-- Add to custom table
tProfiles[string.lower(v)] = GetProfileIdx(v)
end
-- Profile Exists
if tProfiles[string.lower(profile)] then
-- Header
local sMsg, n = "\r\n\r\n\t"..string.rep("=", 35).."\r\n\t\tUsers by Profile - "..
GetProfileName(tProfiles[string.lower(profile)])..":\r\n\t"..string.rep("-", 70).."\r\n\t", 0
-- Loop through registered users
for i, v in ipairs(RegMan.GetRegs()) do
local sStatus = "off"
-- Look for users with same profile
if v.iProfile == GetProfileIdx(profile) then
-- Sum + If online
n = n + 1; if Core.GetUser(v.sNick) then sStatus = "on" end
-- Add content
sMsg = sMsg.."\t"..n..". ["..sStatus.."line] "..v.sNick.."\r\n\t"
end
end
-- Send
Core.SendPmToNick(user.sNick,tSettings.sName, sMsg)
else
Core.SendToNick(user.sNick,"<"..tSettings.sName.."> *** Error: There isn't such profile!")
end
else
Core.SendToNick(user.sNick,"<"..tSettings.sName.."> *** Syntax Error: !"..tSettings.sCommand.." <profile name>")
end
end,
tLevels = { [0] = 1, [1] = 1, },
},
}


Thank you.....