Idle Script
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Idle Script

Started by nEgativE, 15 March, 2005, 11:51:57

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

nEgativE

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

jiten

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

nEgativE

works fine :) tks

jiten


SMF spam blocked by CleanTalk