Reminder or alarm 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

Reminder or alarm bot

Started by Dessamator, 22 March, 2005, 12:16:22

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dessamator

-- Reminder Bot v1.5
-- By Dessamator
-- Ideas from Post Bot by Nerbos(and some functions aswell), 
-- (Mutor, Plop thx for the hints/help, jiten(thnx for the debugging/help))
-- added dates, for reminders in diferent days.
-- Small bugfix in adding reminders reported by xeonfx
-- Fixed some small bugs (Getitembyname & checking time), thnx bastya and Mutor
--## Most recent changes & fixes on : 14/01/2006

fAlarm = "fAlarm.dat"			
tAlarm = 
{ 	["tReminders"]={}, 
  	["Cfg"]=
	{		    -- Cfg Table
			--## Configuration ##--
		["sBot"] = "Reminder", --BotName
	},
}
			    --## END ##--
tCmds = {
	["time"] =  {function (sBot,sUser)
		sUser:SendData(sBot,os.date("Today is the %dth %B %Y & The time is %X" ))	
	end,"$UserCommand 1 3 Reminder\\Time$<%[mynick]> !time&#124;"},
	["alarm"]  = {function(sBot,sUser,sTime,sReminder,sDate)
		if not(tAlarm["tReminders"][sUser.sName]) then tAlarm["tReminders"][sUser.sName] = {} end
		if next(tAlarm) and tAlarm["tReminders"][sUser.sName] then
			for i=1,table.getn(tAlarm["tReminders"][sUser.sName]) do
				if tAlarm["tReminders"][sUser.sName][i] and (tAlarm["tReminders"][sUser.sName][i]["sReminder"] == sReminders) then
					sUser:SendData(sBot,"The Reminder already exists")
					return 1
				end
			end 
		end
		if sTime~="" and sReminder~="" and string.find(sTime,"%d+%d+:%d+%d+") then 
			local _,_,sDate= string.find(sDate,"(%d%d/%d%d/%d%d)" )
			if sDate and (sDate<=os.date("%m/%d/%y")) then sUser:SendData(sBot,"Incorrect Time. Try Again!") return 1 end 
			sDate=sDate or os.date("%m/%d/%y")
			local tStore ={
					["sReminder"] = sReminder,
					["sCtime"]=  os.date("%H:%M"),
					["sAtime"] = sTime,
					["sCdate"] = os.date("%m/%d/%y"),
					["sAdate"] = sDate
					--["alerts"] = 0
					}
			table.insert(tAlarm["tReminders"][sUser.sName], tStore)
			sUser:SendData(sBot,"Your Reminder has been set.")
		else	
			sUser:SendData(sBot,"Syntax Error, !alarm <time: ex.: 19:19> <reminder> <date>(optional (MM/DD/YY ) Default is Today")
		end  
		OnExit()
	end,"$UserCommand 1 3 Reminder\\Set Reminder$<%[mynick]> !alarm %[line:time ex.:"..os.date("%H:%M").."] %[line:Reminder] %[line:Date(MM/DD/YY) e.g.:"..os.date("%m/%d/%y").."]&#124;",},
	["aread"] ={ function(sBot,sUser)
		if not(SendReminder(sBot,sUser.sName,1)) then
			sUser:SendData(sBot,"No Scheduled apointments")		
		end
	end,"$UserCommand 1 3 Reminder\\View Reminder$<%[mynick]> !aread&#124;"},
	["delalarm"] = {function (sBot,sUser,iID)
		if iID == nil or tonumber(iID)==nil then
			 sUser:SendData(sBot,"Syntax Error, !delalarm <ID> , the ID must be specified!")
		elseif (tAlarm["tReminders"][(sUser.sName)][tonumber(iID)] == nil) then
			 sUser:SendData(sBot,"That post doesnt exist!")
		elseif  tAlarm["tReminders"][(sUser.sName)][tonumber(iID)] then
			 table.remove(tAlarm["tReminders"][sUser.sName],tonumber(iID))
			 sUser:SendData(sBot,"The post has been deleted!" )
		         SaveToFile(fAlarm , tAlarm , "tAlarm")
		else
			 sUser:SendData(sBot,"You are not authorized to delete the post !")
		end
	OnExit()
	end,"$UserCommand 1 3 Reminder\\Remove Reminder$<%[mynick]> !delalarm %[line:Reminder <id> ex.: 1]&#124;",},	
}

function Main()
	frmHub:RegBot(tAlarm["Cfg"]["sBot"])
	if loadfile(fAlarm) then dofile(fAlarm) end 	
	SetTimer(60*1000);
	StartTimer()
end

-- right clicks command
function NewUserConnected(sUser)
	sUser:SendData("$UserCommand 255 3 |")
	sUser:SendData("$UserCommand 0 3 |") 
	for i,v in pairs(tCmds) do
		sUser:SendData(v[2])
	end
end
OpConnected=NewUserConnected
--

function ChatArrival(sUser, data)
	local s,e,sCmd,sArg1,sArg2,sArg3 = string.find(data,"%b<>%s+!(%S*)%s*(%S*)%s*(%S*)%s*(.*)|")
	if sCmd and tCmds[sCmd] then
		return 1,tCmds[sCmd][1](tAlarm["Cfg"]["sBot"],sUser,sArg1,sArg2,sArg3)
	end	
end

ToArrival=ChatArrival

function OnTimer()
	for sUser,iID in pairs(tAlarm["tReminders"]) do
		if tAlarm["tReminders"][sUser] and next(tAlarm["tReminders"][sUser]) then		
			SendReminder(tAlarm["Cfg"]["sBot"],sUser)
			if tAlarm["tReminders"][sUser] and table.getn(tAlarm["tReminders"][sUser])==0 then
				tAlarm["tReminders"][sUser] =nil OnExit()
			end
		end
	end
end	

function SendReminder(sBot,sUser,status)
	local sTmp,tRemind,bFound,iATime,iADate = "\r\n\Your reminder(s) :\r\n\ID\t\Created on:\t\Scheduled for\t\t\Reminder\r\n"..string.rep("==",30).."\r\n"
	if tAlarm["tReminders"][sUser] and next(tAlarm["tReminders"][sUser]) then
		for i=1,table.getn(tAlarm["tReminders"][sUser]) do	
			tRemind =tAlarm["tReminders"][sUser][i]
			if tRemind then
				iATime = (string.gsub(tRemind.sAtime,"%:",""))
				iADate = (string.gsub(tRemind.sAdate,"/",""))
				if status or  tonumber(os.date("%H%M"))==tonumber(iATime) and tonumber(os.date("%m%d%y"))==tonumber(iADate) then
					sTmp = sTmp
					..i.."\t"..tRemind.sCtime.." "..tRemind["sCdate"].."\t"
					..tRemind.sAtime.." "..tRemind["sAdate"].."\t"	
					.."\t"..tRemind["sReminder"].."\r\n"
					if GetItemByName(sUser) then
						GetItemByName(sUser):SendPM(sBot,sTmp)
					end
				end
				if tonumber(os.date("%H%M"))>tonumber(iATime)  and tonumber(os.date("%m%d%y"))>=tonumber(iADate)then
					table.remove(tAlarm["tReminders"][sUser],i)
				end
			end	
		end
	return tRemind
	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

SaveToFile = function(file,table,tablename) 
	local hFile = io.open(file,"w+") Serialize(table,tablename,hFile); hFile:close()  
end

function OnExit()
	SaveToFile(fAlarm , tAlarm , "tAlarm")
end


Ignorance is Bliss.

bastya_elvtars

Very good idea! You won't mind me to grab and rewrite later, will you? ;)
Everything could have been anything else and it would have just as much meaning.

Dessamator

QuoteOriginally posted by bastya_elvtars
Very good idea! You won't mind me to grab and rewrite later, will you? ;)

ooh yes i do, no thieves, hehhe, just kidding use it the way u want to, rewrite change it, whatever, no probs here,  :D
Ignorance is Bliss.

Oz

hi

have this error

0.3.3.21.nt.dbg\scripts\alarmbot.lua:253: attempt to perform arithmetic on a nil value

if u can, plzzz correct this error

tnx

Dessamator

i just tested it, and it worked perfectly, when did that error happen?
Ignorance is Bliss.

Oz

#5
wgat do u min (when did that error happen?)

i'm make notice that this error show up every minute.

- [07:56] Syntax ...ings\Oz\Desktop\0.3.3.21.nt.dbg\scripts\alarmbot.lua:253: attempt to perform arithmetic on a nil value
- [07:57] Syntax ...ings\Oz\Desktop\0.3.3.21.nt.dbg\scripts\alarmbot.lua:253: attempt to perform arithmetic on a nil value
- [07:58] Syntax ...ings\Oz\Desktop\0.3.3.21.nt.dbg\scripts\alarmbot.lua:253: attempt to perform arithmetic on a nil value
- [07:59] Syntax ...ings\Oz\Desktop\0.3.3.21.nt.dbg\scripts\alarmbot.lua:253: attempt to perform arithmetic on a nil value
- [08:00] Syntax ...ings\Oz\Desktop\0.3.3.21.nt.dbg\scripts\alarmbot.lua:253: attempt to perform arithmetic on a nil value
- [08:01] Syntax
...ings\Oz\Desktop\0.3.3.21.nt.dbg\scripts\alarmbot.lua:253: attempt to perform arithmetic on a nil value

line 253:     local hour = tonumber(hour2) - tonumber(hour1)

Dessamator

Well, try this :

1. Stop the script.
2. Delete fAlarm.dat from ur scripts folder.
3. Start the script.
Ignorance is Bliss.

speedX

hey Dessamator, nice script...but can u add a clock to it.....i mean wen a user type !time it displays the date & time....
like this
Quote
            Today is 10th August 2006 & Time is 16:16

I kno there is already such script wich displays time...but i would like both in one script only....

thank u...
Thanking You,

speedX

bastya_elvtars

Bit OT, but the European style is not that common, in Hungary we use YYYY. MM. DD. (perhaps string.gsub(mydate,"%.%S+","/") whatever).
Everything could have been anything else and it would have just as much meaning.

Dessamator

Sorry for the late reply, but anyways SpeedX, thats a simple request that can be added, and mutor, yah i noticed it returned a string, trying to convert it to a number was bothering some calculations(if i recall correctly) I havent touched that script in a while so im not even sure of the implications of changing it to a number, anyway I'll check it out.
Ignorance is Bliss.

Dessamator

Quote from: Mutor on 26 August, 2006, 20:55:22
It will happen when attempting to perform arithmetic on a nil value
once nil error  corrected it will then report
attempt to perform arithmetic on a string value
os.date() returns a string not an integer Dessamator.

Great script but needs a little love.

You could easily convert the time to a number,
tonumber(os.date("%H")..os.date("%M"))
as well as convert the date.

One problem I see in converting the date from a string to an
integer is the European style of date you use, which I never
understood listing the day of the month first.
dd/mm/yy will impede the math although the American style
mm/dd/yy wont, this is why Americans are both cooler and look
better in tight pants.

82606 vs 26806  if you see my point.

Well there was an error with the script but it wasnt really related to arithmetic, SpeedX was using an older version of the script which did indeed have an error, the only error it really had was sending a that the script tried to send a pm to a nick even if it wasnt online.

But anyways for the sake of preventing other bugs i changed it to "Tonumber", and used ur advise on dates.
Ignorance is Bliss.

Dessamator

Indeed I did use some math logic, but somehow it worked :). I guess it compared the Values of the strings, and if one was indeed bigger than the other the code went along fine, but well, except for the auto cleaner, which checked if one string was greater than the other, the rest of the script's logic was fine, at least it seemed that way to me.
Ignorance is Bliss.

Dessamator

Well, i believe the string value isnt always really 1 if it contains something, for a simple reason, as the code was before, it would check if a string was greater than the other string.Since neither string was  nil, both would have to be 1 according to your theory, and if that happened the cleaner would never have worked.

Unless it never worked and i didnt notice :).
Ignorance is Bliss.

speedX

Quote from: Dessamator on 25 September, 2006, 21:06:13
Sorry for the late reply, but anyways SpeedX, thats a simple request that can be added

Well is it done ??
Thanking You,

speedX

Psycho_Chihuahua

just add something like

..os.date("Today is %dth %B %Y & the Time is %X")..


wherever you need it in the script
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

speedX

hi guys....is it possible to create a reminder wich is of one line(more than one word) instead of only one word ??
Thanking You,

speedX

SMF spam blocked by CleanTalk