LifeTime Bot
 

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

LifeTime Bot

Started by jiten, 30 September, 2006, 19:57:46

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jiten

--[[

	LifeTime Bot 1.03 - LUA 5.0/5.1 version by jiten
	????????????????????????????????????????????????

	DESCRIPTION:

	- Get Hub's current uptime;
	- Determine how old is the hub

	CHANGELOG:

	Added: Missing LUA 5.1 compatibility - reported by NorthWind;
	Added: Support for years - requested by Psycho_Chihuahua (9/16/2006)
	Changed: LUA 5.1 compatibility vars
	Added: Lifetime topic updater - requested by NorthWind;
	Added: Leviathan profiles (9/30/2006)

]]--

tSettings = {

	-- Bot Name
	sBot = frmHub:GetHubBotName(),

	-- RightClick Menu
	sMenu = "LifeTime",

	-- Hub's 'birth' date
	iSetup = {
		year = 2006,
		month = 3,
		day = 28,
		hour = 21,
		min = 00,
		sec = 00
	},

	-- Update topic [true = on, false = off]
	bUpdateTopic = false,
		-- Topic update delay (in hours)
		iTime = 6,
}

Main = function()
	-- Topic Timer
	SetTimer(tSettings.iTime*60*60*1000); StartTimer()
end

OnTimer = function()
	-- Update Topic
	if tSettings.bUpdateTopic then
		local iDiff = os.difftime(os.time(os.date("!*t")), os.time(tSettings.iSetup))
		if iDiff > 0 then
			local tTopic = {
				"We exist for [TIME]",
				"Our hub is [TIME] old",
				"Alive and kickin' for [TIME]",
				"Hub's was born [TIME] ago",
				"Look at our hub's lifetime: [TIME] and counting",
			}
			local sTopic = string.gsub(tTopic[math.random(1, table.getn(tTopic))], "%[TIME%]", SecondsToTime(iDiff, true))
			frmHub:SetHubTopic(sTopic)
		end
	end
	-- Collect garbage
	collectgarbage(gc); io.flush()
end

ChatArrival = function(user, data)
	local _,_, to = string.find(data, "^$To:%s(%S+)%s+From:")
	local _,_, msg = string.find(data, "%b<>%s(.*)|$") 
	-- Message sent to Bot or in Main
	if (to and to == tSettings.sBot) 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] and tCommands[cmd].tLevels[user.iProfile] == 1 then
				return tCommands[cmd].fFunction(user, msg), 1
			else
				return user:SendData(tSettings.sBot, "*** Error: You are not allowed to use this command!"), 1
			end
		end
	end
end

ToArrival = ChatArrival

NewUserConnected = function(user)
	-- Supports UserCommands
	if user.bUserCommand then
		-- For each entry in table
		for i, v in pairs(tCommands) do
			-- If member
			if v.tLevels[user.iProfile] then
				-- Send
				user:SendData("$UserCommand 1 3 "..tSettings.sMenu.."\\"..v.tRC[1]..
				"$<%[mynick]> !"..i..v.tRC[2].."&#124;")
			end
		end
	end
	user:SendData(tSettings.sBot, "*** Welcome to "..(frmHub:GetHubName() or "Unknown").."!"); tCommands["lifetime"].fFunction(user)
end

OpConnected = NewUserConnected

tCommands = {
	lifetime = {
		fFunction = function(user)
			local iDiff = os.difftime( os.time(os.date("!*t")), os.time(tSettings.iSetup))
			if iDiff > 0 then
				user:SendData(tSettings.sBot, "*** This hub is "..
				SecondsToTime(iDiff).." old and current uptime is "..SecondsToTime(frmHub:GetUpTime(), true).."!")
			else
				user:SendData(tSettings.sBot, "*** Error: You must enter a valid Hub Birthday!")
			end
		end,
		tLevels = {
			[-1] = 0, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1, [6] = 1,
		},
		tRC = { "Show hub's age and uptime", "" }
	},
}

SecondsToTime = function(iTime, bSmall)
	-- LUA 5.0/5.1 compatibility
	string.gmatch = (string.gmatch or string.gfind)
	-- Build table with time fields
	local T = os.date("!*t", tonumber(iTime)); 
	-- Format to string
	local sTime = string.format("%i year(s), %i month(s), %i day(s), %i hour(s), %i minute(s)", T.year-1970, T.month-1, T.day-1, T.hour, T.min)
	-- Small stat?
	if bSmall then
		-- For each digit
		for i in string.gmatch(sTime, "%d+") do
			-- Reduce if is preceeded by 0
			if tonumber(i) == 0 then sTime = string.gsub(sTime, "^"..i.."%s(%S+),%s", "") end
		end
	end
	-- Return
	return sTime
end

SMF spam blocked by CleanTalk