LifeTime Bot 1.04 (New API)
 

LifeTime Bot 1.04 (New API)

Started by Tw?sT?d-d?v, 14 October, 2007, 22:12:20

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Tw?sT?d-d?v

Tried to convert the following script  ... All seems ok ( no errors ) , but command appears in main Where have i gone wrong

ERROR FIXED


--[[

	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)

        LifeTime Bot 1.04
        Converted to New API by Tw?sT?d-d?v?l (14/10/2007)

]]--

tSettings = {

	-- Bot Name
	sBot = SetMan.GetString(21),

	-- RightClick Menu
	sMenu = "-[-=={LIFETIME}==-]-",

	-- Hub's 'birth' date
	iSetup = {
		year = 2006,
		month = 6,
		day = 1,
		hour = 08,
		min = 30,
		sec = 00
	},

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

OnStartup = function()
	-- Topic Timer

end

OnTimer = function(tmr)
	-- 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 since [TIME]",
				"Our hub is [TIME] old",
				"Running since [TIME]",
			}
			local sTopic = string.gsub(tTopic[math.random(1, #tTopic)], "%[TIME%]", SecondsToTime(iDiff, true))
			SetMan.SetString(10,sTopic)
		end
	end
	-- Collect garbage
	collectgarbage(gc); io.flush()
end

ChatArrival = function(user,data)
	Core.GetUserAllData(user)
	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] == true then
				return tCommands[cmd].fFunction(user, msg), true
			else
				return Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** Error: You are not allowed to use this command!"), true
			end
		end
	end
end

ToArrival = ChatArrival

UserConnected = function(user)
	Core.GetUserAllData(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
				Core.SendToNick(user.sNick,"$UserCommand 1 3 "..tSettings.sMenu.."\\"..v.tRC[1]..
				"$<%[mynick]> !"..i..v.tRC[2].."&#124;")
			end
		end
	end
	Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** Welcome to "..(SetMan.GetString(0) or "Unknown").." !"); tCommands["lifetime"].fFunction(user)
end

OpConnected = UserConnected

tCommands = {
	lifetime = {
		fFunction = function(user)
			local iDiff = os.difftime( os.time(os.date("!*t")), os.time(tSettings.iSetup))
			if iDiff > 0 then
				Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** This Hub is "..
				SecondsToTime(iDiff).." old and the latest uptime is "..SecondsToTime(Core.GetUpTime(), true).."\r\n\t\t\t\t\t\t Today is the "..os.date("%d. %B %Y and it is now %X o'clock").."!")
			else
				Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** Error: You must enter a valid Hub Birthday!")
			end
		end,
		tLevels = {
			[-1] = false, [0] = true, [1] = true, [2] = true, [3] = true, [4] = true, [5] = true, [6] = true,
		},
		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
RegConnected = UserConnected

Tw?sT?d-d?v

Thx Mutor      Error fixed and first post updated ... 
I was going to post in finished section but i cant make new posts there    :)

SMF spam blocked by CleanTalk