Countdown from Plop to Lua 5.1
 

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

Countdown from Plop to Lua 5.1

Started by TiMeTrAVelleR, 23 March, 2006, 22:28:11

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TiMeTrAVelleR

------------------------------------------------------------------------------
------- Lua 5 version by jiten? ?Lua 5.1 version by TiMeTrAVelleR? ? ? ? ? ? ? ? ? ? ? ?-------
-------? ? ? ? ? ? ? ? ? countdown bot by plop? ? ? ? ? ? ? ? ? ? ? ? ?-------
-------? ? ? ? ? ? ?original julian day made by tezlo? ? ? ? ? ? ? ? ? -------
-------? ? ? modifyd by chilla 2 also handle hours, mins, seconds? ? ? -------
------------------------------------------------------------------------------

------------------------------------------------------------------------------
-------? ? ? ? ? ?THE TEXT FILE LOADS ON BOT START? ? ? ? ? ? ? ? ? ? ?-------
------------------------------------------------------------------------------
------- this may sound weird but this 2 make sure it shows on time,? ? -------
-------? ? ? as i allready seen some big ascii's come by? ? ? ? ? ? ? ?-------
------------------------------------------------------------------------------


------------------------------------------------------------------------------
Bot = "-T?M????-"

--This the date the timer has 2 stop @ midnight
-- year (2 numbers), month, day
SylYear,SylMonth,SylDay = 06,3,23
-- this is the file 2 be shown 
file = "happynewyear.txt"
------------------------------------------------------------------------------
------------------------------------------------------------------------------
function OnTimer()
	if last == 0 then
		SendToAll(Bot, TimeLeft())
		Sync()
	elseif last == 1 then
		SendAscii() -- send the msg
		StopTimer() -- kill the timer
	end
end
------------------------------------------------------------------------------
function jdatehms(d, m, y,ho,mi,se)
	local a, b, c = 0, 0, 0
	if m <= 2 then y = y - 1 m = m + 12 end
	if (y*10000 + m*100 + d) >= 15821015 then a = math.floor(y/100) b = 2 - a + math.floor(a/4) end
	if y <= 0 then c = 0.75 end
	return math.floor(365.25*y - c) + math.floor(30.6001*(m+1) + d + 1720994 + b),ho*3600+mi*60+se
end
------------------------------------------------------------------------------
function TimeLeft()
	local curday,cursec = jdatehms(tonumber(os.date("%d")),tonumber(os.date("%m")),tonumber(os.date("%y")),tonumber(os.date("%H")),tonumber(os.date("%M")),tonumber(os.date("%S")))
	local sylday,sylsec = jdatehms(SylDay,SylMonth,SylYear,21,00,0)
	local tmp = sylsec-cursec
	local hours, minutes,seconds = math.floor(math.fmod(tmp/3600, 60)), math.floor(math.fmod(tmp/60, 60)), math.floor(math.fmod(tmp/1, 60))
	local day = sylday-curday
	if day >= 0 then
		line = "LiVe SeT FroM TiMeTrAVelleR At: http://stream01.pcextreme.nl:8035/stream In "
		if day ~= 0 then line = line.." "..day.." Days" end
		if hours ~= 0 then line = line.." "..hours.." Hours" end
		if minutes ~= 0 then line = line.." "..minutes.." Minutes" end
		if seconds ~= 0 then line = line.." "..seconds.." Seconds ;) " end
		return line
	end
end
------------------------------------------------------------------------------
function ShowAscii()
	local f = io.open(file)
	if f then 
		text = f:read("*all")
		f:close()
		return string.gsub( text, "\n", "\r\n" )
	end 
end
------------------------------------------------------------------------------
function SendAscii()
	SendToAll(Bot, "Oki Here We Go? ? ;)|")
end
------------------------------------------------------------------------------
function ChatArrival(user, data) 
	data=string.sub(data,1,-2) 
	s,e,cmd = string.find(data,"%b<>%s+(%S+)") 
	if cmd == "!daysleft" then
		local tmp = TimeLeft()
		if tonumber(tmp) == nil then user:SendData(Bot, tmp.."|") end
		return 1
	end
end
------------------------------------------------------------------------------
function NewUserConnected(user)
	local tmp = TimeLeft()
	if tonumber(tmp) == nil then user:SendData(Bot, tmp.."|") end
end
------------------------------------------------------------------------------
OpConnected = NewUserConnected
------------------------------------------------------------------------------
function Main()
	SetTimer(100 * 1000) 
	StartTimer()
	local tmp = TimeLeft()
	if tonumber(tmp) == nil then SendToAll(Bot, tmp.."|") end
	Sync() ShowAscii() last = 0
end
------------------------------------------------------------------------------
function Sync()
	local curday,cursec = jdatehms(tonumber(os.date("%d")),tonumber(os.date("%m")),tonumber(os.date("%y")),tonumber(os.date("%H")),tonumber(os.date("%M")),tonumber(os.date("%S")))
	local sylday,sylsec = jdatehms(SylDay,SylMonth,SylYear,21,00,0)
	local tmp = sylsec-cursec
	local hours, minutes,seconds = math.floor(math.fmod(tmp/3600, 60)), math.floor(math.fmod(tmp/60, 60)), math.floor(math.fmod(tmp/1, 60))
	local day = sylday-curday
	if day ~= 0 then
		adjust = (math.floor(math.fmod(minutes, 60))*60)+seconds
		if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(3600 * 1000) end
	else
		if tmp > 3600 then? --- every hours a msg
			adjust = (math.floor(math.fmod(minutes, 60))*60)+seconds
			if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(3600 * 1000) end
		elseif tmp > 900 then? -- every 15 mins a msg
			adjust = (math.floor(math.fmod(minutes, 15))*60)+seconds
			if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(900 * 1000) end
		elseif tmp > 300 then? -- every 5 mins a msg
			adjust = (math.floor(math.fmod(minutes, 5))*60)+seconds
			if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(300 * 1000) end
		elseif tmp > 60 then? -- every min a msg
			adjust = (math.floor(math.fmod(minutes, 1))*60)+seconds
			if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(60 * 1000) end
		elseif tmp > 15 then? -- every 15 secs a msg
			adjust = math.floor(math.fmod(seconds, 15))
			if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(15 * 1000) end
		elseif tmp > 10 then? -- every 10 secs a msg
			adjust = math.floor(math.fmod(seconds, 10))
			if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(5 * 1000) end
		elseif tmp > 1 then
			SetTimer(1 * 1000) 
		else
			last = 1
			SetTimer(1 * 1000)
		end
	end
end


greetzz TT

jiten

#1
--[[

	------------------------------------------------------------------------------
	------- Lua 5 version by jiten   Lua 5.1 version by TiMeTrAVelleR      -------
	-------                  countdown bot by plop                         -------
	-------             original julian day made by tezlo                  -------
	-------      modifyd by chilla 2 also handle hours, mins, seconds      -------
	------------------------------------------------------------------------------

	------------------------------------------------------------------------------
	-------           THE TEXT FILE LOADS ON BOT START                     -------
	------------------------------------------------------------------------------
	------- this may sound weird but this 2 make sure it shows on time,    -------
	-------      as i allready seen some big ascii's come by               -------
	------------------------------------------------------------------------------

	Changelog:

	Added: Customizable countdown;
	Changed: Small stuff;
	Added: RightClick (3/28/2006);
	Added: Start and Stop Timer (3/30/2006);
	Added: Customizable message (3/31/2006);
	Changed: !setmsg now parses all message (3/31/2006);
	Added: OnExit function (4/1/2006)

]]--

Settings = {
	-- Bot Name
	sBot = "-T?M????-",
	-- First Timer for this bot (2 digits)
	-- After first setup, has to be changed with command
	iSetup = {
		iYear = 06,
		iMonth = 3,
		iDay = 28,
		iHour = 21,
		iMinute = 00,
		iSecond = 00,
	},
	-- Start timer automatically (true/false)
	bStart = false,
	-- Timer DB
	fTime = "tTime.tbl",
	-- Send txt content to Main (true/false)
	bSend = false,
	-- Custom message sent on timer
	sMsg = "LiVe SeT FroM TiMeTrAVelleR At: http://stream01.pcextreme.nl:8035/stream In",
	-- CountDown file to be shown
	fCountDown = "happynewyear.txt",
}

Main = function()
	if loadfile(Settings.fTime) then dofile(Settings.fTime) end
	SetTimer(100 * 1000); 
	if Settings.bStart then
		StartTimer(); Sync() 
		local tmp = TimeLeft()
		if tmp then SendToAll(Settings.sBot,tmp) end;
	end
end

ChatArrival = function(user, data) 
	local s,e,cmd = string.find(data,"^%b<>%s+[%!%+](%S+).*|$") 
	if cmd then
		if tCommands[string.lower(cmd)] then
			cmd = string.lower(cmd)
			if tCommands[cmd].tLevels[user.iProfile] then
				return tCommands[cmd].tFunc(user, data), 1
			else
				return user:SendData(Settings.sBot,"*** Error: You are not allowed to use this command!"), 1
			end
		end
	end
end

OnExit = function()
	local hFile = io.open(Settings.fTime,"w+") Serialize(Settings,"Settings",hFile); hFile:close()
end

tCommands = {
	setmsg = {
		tFunc = function(user,data)
			local s,e,msg = string.find(data,"^%b<>%s+%S+%s+(.*)|$")
			if msg then
				Settings.sMsg = msg;
				user:SendData(Settings.sBot,"*** CountDown Bot's message has been changed to: "..msg)
			end
		end,
		tLevels = {
			[0] = 1, [1] = 1, [4] = 1, [5] = 1,
		},
		tRC = "Set Message$<%[mynick]> !{} %[line:Message]"
	},
	starttimer = {
		tFunc = function(user)
			StartTimer(); Sync();
			user:SendData(Settings.sBot,"*** CountDown Bot's timer has been started!")
		end,
		tLevels = {
			[0] = 1, [1] = 1, [4] = 1, [5] = 1,
		},
		tRC = "Start Timer$<%[mynick]> !{}"
	},
	stopttimer = {
		tFunc = function(user)
			StopTimer()
			user:SendData(Settings.sBot,"*** CountDown Bot's timer has been started!")
		end,
		tLevels = {
			[0] = 1, [1] = 1, [4] = 1, [5] = 1,
		},
		tRC = "Stop Timer$<%[mynick]> !{}"
	},
	daysleft = {
		tFunc = function(user)
			local tmp = TimeLeft()
			if tmp then user:SendData(Settings.sBot,tmp) end
		end,
		tLevels = {
			[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
		},
		tRC = "Time Left$<%[mynick]> !{}"
	},
	settimer = {
		tFunc = function(user,data)
			local s,e,args = string.find(data,"^%b<>%s+%S+%s+(.*)|$")
			local s,e,d,m,y,H,M,S = string.find(args,"^(%d%d)\/(%d%d)\/(%d%d)%s(%d%d)%:(%d%d)%:(%d%d)$")
			if d and m and y and H and M and S then
				Settings.iSetup = { 
					iDay = tonumber(d), iMonth = tonumber(m), iYear = tonumber(y),
					iHour = tonumber(H), iMinute = tonumber(M), iSecond = tonumber(S),
				}
				user:SendData(Settings.sBot,"*** CountDown Bot has been successfully set to: "..args); OnExit()
			else
				user:SendData(Settings.sBot,"*** Syntax Error: Type !settimer dd/mm/yy hh:mm:ss")
			end
		end,
		tLevels = {
			[0] = 1, [1] = 1, [4] = 1, [5] = 1,
		},
		tRC = "Set Timer$<%[mynick]> !{} %[line:dd/mm/yy hh:mm:ss]"
	}
}

NewUserConnected = function(user)
	for i,v in pairs(tCommands) do
		local sRC = string.gsub(v.tRC,"{}",i)
		user:SendData("$UserCommand 1 3 CountDown Bot\\"..sRC.."&#124;")
	end
	local tmp = TimeLeft()
	if tmp then user:SendData(Settings.sBot,tmp) end
end

OpConnected = NewUserConnected

OnTimer = function()
	if last then
		-- Send message and kill timer
		SendAscii(); StopTimer()
	else
		SendToAll(Settings.sBot, TimeLeft()); Sync()
	end
end

jdatehms = function(d, m, y,ho,mi,se)
	local a, b, c = 0, 0, 0
	if m <= 2 then y = y - 1 m = m + 12 end
	if (y*10000 + m*100 + d) >= 15821015 then a = math.floor(y/100) b = 2 - a + math.floor(a/4) end
	if y <= 0 then c = 0.75 end
	return math.floor(365.25*y - c) + math.floor(30.6001*(m+1) + d + 1720994 + b),ho*3600+mi*60+se
end

TimeLeft = function()
	local tmp = Settings.iSetup
	local curday,cursec = jdatehms(tonumber(os.date("%d")),tonumber(os.date("%m")),tonumber(os.date("%y")),tonumber(os.date("%H")),tonumber(os.date("%M")),tonumber(os.date("%S")))
	local iday,isec = jdatehms(tmp.iDay,tmp.iMonth,tmp.iYear,tmp.iHour,tmp.iMinute,tmp.iSecond)
	local tmp = isec-cursec
	local hours, minutes,seconds = math.floor(math.mod(tmp/3600, 60)), math.floor(math.mod(tmp/60, 60)), math.floor(math.mod(tmp/1, 60))
	local day = iday-curday
	if day >= 0 then
		local line = Settings.sMsg
		if day ~= 0 then line = line.." "..day.." Days" end
		if hours ~= 0 then line = line.." "..hours.." Hours" end
		if minutes ~= 0 then line = line.." "..minutes.." Minutes" end
		if seconds ~= 0 then line = line.." "..seconds.." Seconds ;) " end
		return line
	end
end

SendAscii = function()
	if Settings.bSend then
		local text
		local f = io.open(Settings.fCountDown)
		if f then text = f:read("*all"); f:close(); return string.gsub( text, "\n", "\r\n" ) end 
		SendToAll(Settings.sBot,text)
	end
	SendToAll(Settings.sBot, "Oki Here We Go    ;)")
end

Sync = function()
	local tmp = Settings.iSetup
	local curday,cursec = jdatehms(tonumber(os.date("%d")),tonumber(os.date("%m")),tonumber(os.date("%y")),tonumber(os.date("%H")),tonumber(os.date("%M")),tonumber(os.date("%S")))
	local iday,isec = jdatehms(tmp.iDay,tmp.iMonth,tmp.iYear,tmp.iHour,tmp.iMinute,tmp.iSecond)
	local tmp = isec-cursec
	local hours, minutes,seconds = math.floor(math.mod(tmp/3600, 60)), math.floor(math.mod(tmp/60, 60)), math.floor(math.mod(tmp/1, 60))
	local day = iday-curday
	if day ~= 0 then
		adjust = (math.floor(math.mod(minutes, 60))*60)+seconds
		if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(3600 * 1000) end
	else
		if tmp > 3600 then  --- every hours a msg
			adjust = (math.floor(math.mod(minutes, 60))*60)+seconds
			if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(3600 * 1000) end
		elseif tmp > 900 then  -- every 15 mins a msg
			adjust = (math.floor(math.mod(minutes, 15))*60)+seconds
			if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(900 * 1000) end
		elseif tmp > 300 then  -- every 5 mins a msg
			adjust = (math.floor(math.mod(minutes, 5))*60)+seconds
			if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(300 * 1000) end
		elseif tmp > 60 then  -- every min a msg
			adjust = (math.floor(math.mod(minutes, 1))*60)+seconds
			if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(60 * 1000) end
		elseif tmp > 15 then  -- every 15 secs a msg
			adjust = math.floor(math.mod(seconds, 15))
			if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(15 * 1000) end
		elseif tmp > 10 then  -- every 10 secs a msg
			adjust = math.floor(math.mod(seconds, 10))
			if adjust ~= 0 then SetTimer(adjust * 1000) else SetTimer(5 * 1000) end
		elseif tmp > 1 then
			SetTimer(1 * 1000) 
		else
			last = true
			SetTimer(1 * 1000)
		end
	end
end

Serialize = function(tTable,sTableName,hFile,sTab)
	sTab = sTab or "";
	hFile:write(sTab..sTableName.." = {\n");
	for key,value in pairs(tTable) do
		if (type(value) ~= "function") then
			local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
			if(type(value) == "table") then
				Serialize(value,sKey,hFile,sTab.."\t");
			else
				local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
				hFile:write(sTab.."\t"..sKey.." = "..sValue);
			end
			hFile:write(",\n");
		end
	end
	hFile:write(sTab.."}");
end

jiten

First post updated with rightclick commands.

plop

hints:

tTime = os.date("*t") returns a table with the current date.
stuff the table in
iJdate = os.time(tTime) and you get the julian date.
now if you stuff iJdate in
os.date("*t", iJdate) you get tTime again.
and next os.date("%c", iJdate) returns the time string.
but there's more.
os.difftime( iNow , iThen) and you get the time between 2 julian date's.

plop

(ps. timetraveller: check a.i. v2, i'm using all this in it)
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

bastya_elvtars

Everything could have been anything else and it would have just as much meaning.

jiten

Thank you for your hints.
In fact, initially, I modified the script by request only to make the countdown more customizable. But, will try implement this when I get some spare time.

Cheers

jiten

First post updated with a quick mod upon request.

Best regards

jiten

First updated once more with another request.

Best regards

jiten

First post updated with customizable message and related stuff.

TiMeTrAVelleR

Great job jiten thanks  :D

Greetzz TT

philoum

Hello, I use this script, it's run but at the time the file  happynewyear.txt  doen't run !
Have you a solution ?
merci

respectfuuly

SMF spam blocked by CleanTalk