PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: nEgativE on 15 March, 2005, 11:51:57

Title: Idle Script
Post by: nEgativE on 15 March, 2005, 11:51:57
Hi there, anyone could convert this idle script to 5 ?
Tks in advance


--###############################################--
-- Idle - Users -- By NightLitch 2004-12-23 --
--###############################################--
BotName = "InfoBot"
TableCommand = "!whois"
--###############################################--
IdleTimers = {}
--###############################################--
function DataArrival(sUser,sData)
if strsub(sData, 1,1) == "<" then
local _,_,Cmd,Arg = strfind(sData, "%b<>%s+(%S+)%s*(.*)%|")
if Command[Cmd] and sUser.bOperator then
return Command[Cmd](sUser,Arg)
end
IdleTimers[sUser.sName] = clock()
elseif strsub(sData,1,4) == "$To:" then
local s,e,WhoTo,From,Msg = strfind(sData,"%$To:%s+(%S+)%s+From:%s+(%S+)%s+%$%b<>%s+(.*)%|")
IdleTimers[From] = clock()
end

end--###############################################--
Command = {}
Command[TableCommand] = function(sUser,sArg)
local _,_,Nickname = strfind(sArg, "(%S+)")
if Nickname == nil then sUser:SendData(BotName, "Syntax: !table ") return 1 end
local tUser = GetItemByName(Nickname)
if tUser == nil then sUser:SendData(BotName, "User "..Nickname.." is not online or wrong username.") return 1 end
if IdleTimers[tUser.sName] then
iTime = clock() - IdleTimers[tUser.sName]
sUser:SendData(BotName, "User "..tUser.sName.." has been idle for "..TimeUnits(iTime))
else
sUser:SendData(BotName, "User "..tUser.sName.." haven't typed anything at all...")
end
return 1
end
--###############################################--
TimeUnits = function(time)
local time = time*1000
local msg = ""
local tO = {
[1] = { 86400000, 0, "days"},
[2] = { 3600000, 0, "hours"},
[3] = { 60000, 0, "minutes"},
[4] = { 1000, 0, "seconds"},
};
for i , v in (tO) do
if time >= tO[i][1] then
repeat
tO[i][2] = tO[i][2] + 1
time = time - tO[i][1]
until time < tO[i][1]
end
end
for i,v in tO do
if tO[i][2] ~= 0 then
msg = msg.." "..tO[i][2].." "..tO[i][3]
end
end
if msg == "" then msg = "0 minutes" end
return msg
end
--###############################################--
--// NightLitch 2004-12-23

Title:
Post by: jiten on 15 March, 2005, 12:10:18
Try this:

--###############################################--
-- Idle - Users -- By NightLitch 2004-12-23 --
-- converted to LUA 5 by jiten
--###############################################--
BotName = "InfoBot"
TableCommand = "!whois"
--###############################################--
IdleTimers = {}
--###############################################--
function ChatArrival(sUser,sData)
if string.sub(sData, 1,1) == "<" then
local _,_,Cmd,Arg = string.find(sData, "%b<>%s+(%S+)%s*(.*)%|")
if Command[Cmd] and sUser.bOperator then
return Command[Cmd](sUser,Arg)
end
IdleTimers[sUser.sName] = os.clock()
end
end

function ToArrival(sUser,sData)
if string.sub(sData,1,4) == "$To:" then
local s,e,WhoTo,From,Msg = string.find(sData,"%$To:%s+(%S+)%s+From:%s+(%S+)%s+%$%b<>%s+(.*)%|")
IdleTimers[From] = os.clock()
end

end
--###############################################--
Command = {}
Command[TableCommand] = function(sUser,sArg)
local _,_,Nickname = string.find(sArg, "(%S+)")
if Nickname == nil then sUser:SendData(BotName, "Syntax: !table ") return 1 end
local tUser = GetItemByName(Nickname)
if tUser == nil then sUser:SendData(BotName, "User "..Nickname.." is not online or wrong username.") return 1 end
if IdleTimers[tUser.sName] then
iTime = os.clock() - IdleTimers[tUser.sName]
sUser:SendData(BotName, "User "..tUser.sName.." has been idle for "..TimeUnits(iTime))
else
sUser:SendData(BotName, "User "..tUser.sName.." haven't typed anything at all...")
end
return 1
end
--###############################################--
TimeUnits = function(time)
local time = time*1000
local msg = ""
local tO = {
[1] = { 86400000, 0, "days"},
[2] = { 3600000, 0, "hours"},
[3] = { 60000, 0, "minutes"},
[4] = { 1000, 0, "seconds"},
};
for i , v in (tO) do
if time >= tO[i][1] then
repeat
tO[i][2] = tO[i][2] + 1
time = time - tO[i][1]
until time < tO[i][1]
end
end
for i,v in tO do
if tO[i][2] ~= 0 then
msg = msg.." "..tO[i][2].." "..tO[i][3]
end
end
if msg == "" then msg = "0 minutes" end
return msg
end
--###############################################--
--// NightLitch 2004-12-23

Title:
Post by: nEgativE on 15 March, 2005, 12:22:58
works fine :) tks
Title:
Post by: jiten on 15 March, 2005, 13:51:21
yw, Luso  :]