--- BirthdayMan v 3 --- by Herodes -- Update 3/10/2004 --- --- --- --- --- --- -- v2.5 --- When Users are connected if there is a birthday it informs --- When a Birhtday-User connect it plays surprise and informs the Hub -- v2.6 --- Fix from ... comment for the display age -- v 3 --- ability to display the Birthday nicks in the topic of the hub ... ( all of them ... the Ofline ones are in parentheses like (Herodes)) --- added agecmd to get exact age --- added bhelpcmd --- added display of birthdays in the findcmd --- added ability for pm or main cmds .. ;) --- --- --- --- --- --- ----- do not edit these four lines sec = 1000 minutes = 1000*60 hours = 1000*(60^2) TxtSend = nil ----- Edit at will bBot = "Surprise" timecheck = 12*hours --- how much time before checking for birthdays ... TopicShow = 1 --- to display the birthday nicks in the Hub's Topic ... ( 1/0 : enabled / disabled ) tProfiles = { ---- profile rights to commands, 0 cant use the bot at all, 1 can use listcmd/addcmd/findcmd/agecmd/agecmd/bhelpcmd , 2 can also use delcmd and addbircmd... ["-1"] = 1, --- Unregs ["0"] = 2, --- Masters ["1"] = 2, --- Operators ["2"] = 1, --- VIPs ["3"] = 1, --- Regs ["4"] = 0, --- CustomProf1 ["5"] = 0, --- CustomProf2 } --- ( carry on typing your profiles in the right format : ["profile_number"] = value (0/1/2) addcmd = "!mybirthday" --- !mybirthday dd/mm/yyyy dd = day , mm = month , yyyy = year .... Sets your birthday! delcmd = "!delbirthday" --- !delbirthday is needed ... deletes 's birthday from the list listcmd = "!birthdays" --- !birthdays Lists the birthdays stored addbircmd = "!addbirth" --- !addbirth same as addcmd findcmd = "!bornon" --- !bornon Shows a nice list of the ppl you share dates with ;) agecmd = "!myage" --- !myage Shows you your age :) bhelpcmd = "!bhelp" --- !bhelp Shows the cmds for the bot and some short explaination birthdayfile = "cake.txt" --- The file that will be displayed on Birthday oldestyear = 1900 --- !mybirthday 0/0/0000 situations are avoided ( lol ) allowedage = 6 --- !mybirthday situations are avoided (in years) birthlog = "birthdays.tbl" --- The file where we'll be storing the birthdays ... << has to be in your scripts folder --- // --- Script-Starts tBirthdays = {} tCalendar = { [1] = { 31, "January", }, [2] = { 28, "February", }, [3] = { 31, "March", }, [4] = { 30, "April", }, [5] = { 31, "May", }, [6] = { 30, "June", }, [7] = { 31, "July", }, [8] = { 31, "August", }, [9] = { 30, "September", }, [10] = { 31, "October", }, [11] = { 30, "November", }, [12] = { 31, "December", }, } function Main() LoadFile(birthlog) tCalendar[2][1] = FixFebruary(tonumber(date("%Y"))) local hr = tonumber(date("%H"))*60*60*1000 local mins = 0 if tonumber(date("%M")) == 0 then mins = 1 else mins = tonumber(date("%M"))*60*1000 end fixTime(hr+mins) frmHub:UnregBot(bBot) frmHub:RegBot(bBot) end function OnTimer() CheckBirthdays() TxtSend = nil end function NewUserConnected(user) for i, v in tBirthdays do if tBirthdays[i][2] == tonumber(date("%m")) and tBirthdays[i][1] == tonumber(date("%d")) then if user.sName ~= i then local msg = "Its "..i.."'s birhtday today .. ;D Turning "..(tonumber(date("%Y"))-tBirthdays[i][3] ).." today,... give a wish :)" if GetItemByName(i) then user:SendData(bBot, msg) else user:SendData(bBot, msg.." when he comes online") end else user:SendData(bBot, "Hey I know !!! YOU HAVE YOUR BIRTHDAY TODAY !!! HAPPIEST OF BIRTHDAYS !!!! ") SendToAll(bBot, "Guys !! "..user.sName.." is here! What do we say ?? : )") end end end end OpConnected = NewUserConnected function CheckBirthdays() tNow = {} local count = 0 local yeah = nil for i, v in tBirthdays do if tBirthdays[i][2] == tonumber(date("%m")) then if tBirthdays[i][1] == tonumber(date("%d")) then if GetItemByName(i) then local happy = GetItemByName(i) DoHappyBirthday(happy) yeah = 1 end count = count + 1 if yeah == nil then tNow[count] = "("..i..")" else tNow[count] = i end end end yeah = nil end local tit = "" local ct = 0 for i,v in tNow do if ct == 0 then tit = " "..v else tit = tit..", "..v end ct = ct +1 end if ct > 1 then tit = "s "..tit end topic = frmHub:GetHubName() frmHub:SetHubName(topic.." - Today is the birthday of the following user"..tit) end function FixFebruary(y) local value = 0 if (tonumber(y)/4) - (floor(tonumber(y)/4)) == 0 then value = 29 else value = 28 end return value end function fixTime(now) if now < timecheck then now = timecheck-now elseif now > timecheck then now = now-timecheck else now = timecheck end SetTimer(now) StartTimer() end function DataArrival(user, data) prof = user.iProfile local how = nil if prof == nil then prof = "-1" end if tProfiles[""..prof..""] >= 1 then if strsub(data, 1,1) == "<" then data = strsub(data, 1, strlen(data)-1) s,e,cmd,args = strfind(data, "%b<>%s+(%S+)%s*(.*)") DoCmds(user, cmd, args, how) elseif strsub(data, 1,4 ) == "$To:" then data = strsub(data, 1, strlen(data)-1) s,e,cmd,args = strfind(data, "%b<>%s+(%S+)%s*(.*)") how = "pm" DoCmds(user, cmd, args, how) end end end function DoCmds(user, cmd, args, how) if cmd == addcmd then CheckBirthdays() AddBirthDay(user, args, how) return 1 elseif cmd == addbircmd and tProfiles[""..prof..""] == 2 then CheckBirthdays() AddBirthDay(user, args, how) return 1 elseif cmd == delcmd and tProfiles[""..prof..""] == 2 then DelBirth(user, args, how) return 1 elseif cmd == listcmd then ListBirths(user, how) return 1 elseif cmd == findcmd then BornOn(user, how) return 1 elseif cmd == agecmd then ExactAge(user, how) elseif cmd == bhelpcmd then BHelp(user, how) end end function BornOn(user, how) if tBirthdays[user.sName] then local msg = "\r\n These are the people that are born the same number-day as you\r\n" msg = msg..FindSame(tBirthdays, tBirthdays[user.sName][1] , "day", user.sName).."\r\n" msg = msg.." These are the people that are born the same month as you\r\n" msg = msg..FindSame(tBirthdays, tBirthdays[user.sName][2] , "month", user.sName).."\r\n" msg = msg.." These are the people that are born the same year as you\r\n" msg = msg..FindSame(tBirthdays, tBirthdays[user.sName][3] , "year", user.sName).."\r\n" msg = msg.." These are the people that are born the same month and day with you \r\n" msg = msg..FindSame(tBirthdays, tBirthdays[user.sName][1].."/"..tBirthdays[user.sName][2] , "monthday", user.sName).."\r\n" msg = msg.." These are the people that have the same birthday as yours\r\n" msg = msg..FindSame(tBirthdays, tBirthdays[user.sName][1].."/"..tBirthdays[user.sName][2].." - "..tBirthdays[user.sName][3] , "all", user.sName).."\r\n" SendBack(msg, user, how) end end function DelBirth(user, args, how) if args ~= nil then if tBirthdays[args] then if GetItemByName(args) then GetItemByName(args):SendPM(bBot, ">>>> "..user.sName.." has deleted your birthday from my list .. ;( <<<<") end tBirthdays[args] = nil SendBack("You deleted "..args.." bithday ...", user, how) SaveFile(tBirthdays , "tBirthdays", birthlog) else SendBack(args.." is not in my birthday list ...", user, how) end else SendBack("You need to give me a name ...", user, how) end end function SendBack(what, user, how) if how == nil then user:SendData(bBot, what) else user:SendPM(bBot, what) end end function ListBirths(user, how) local str = "The Birthday List of the users of this Hub" local msg = "\r\n ..-*'~ "..str.." ~'*-..\r\n"..strrep("^", strlen(str)+2).."\r\n\t" local c = 0 local status = "" for i, v in tBirthdays do if GetItemByName(i) then status = "online" else status = "offline" end c = c + 1 tip = ". - "..tBirthdays[i][1].."/"..tBirthdays[i][2].."/"..tBirthdays[i][3].."\t- \t"..i.."\t ( "..status.." )" if tBirthdays[i][1].."/"..tBirthdays[i][2].."/"..tBirthdays[i][3] == date("%d/%m/%Y") then tip = tip.."-+-" end msg = msg..c..tip.."\r\n\t" end SendBack(msg, user, how) end function AddBirthDay(user, args, how) local pers = "" if args ~= nil then local s,e,name,day,month,year = strfind(args, "(%S+)%s+(%d+)/(%d+)/(%d+)") if name == nil then name = user.sName pers = "you" s,e,day,month,year = strfind(args, "(%d+)/(%d+)/(%d+)") else pers = name end if month ~= nil and day ~= nil and year ~= nil and (tonumber(month) >= 1) and (tonumber(month) <= 12) then day = tonumber(day) month = tonumber(month) year = tonumber(year) if year > oldestyear then if year < (tonumber(date("%Y")) - allowedage) then if month == 2 then daylimit = FixFebruary(year) else daylimit = tCalendar[month][1] end if day <= daylimit and day >= 1 then if tBirthdays[name] then month = tBirthdays[name][2] if user.sName == name then SendBack("I have your birthday already ... its on the "..tBirthdays[name][1].." of "..tCalendar[month][2], user, how) else SendBack("I have "..name.."'s birthday already ... its on the "..tBirthdays[name][1].." of "..tCalendar[month][2] , user, how) end local profstr = "" for i,v in tProfiles do if tProfiles[i] == 2 then profstr = GetProfileName(tonumber(i)).."s" break end end SendBack("If you dont think this is correct ... then talk to one of our "..profstr , user, how) else tBirthdays[name] = {} tBirthdays[name][1] = day tBirthdays[name][2] = month tBirthdays[name][3] = year SaveFile(tBirthdays , "tBirthdays", birthlog) if user.sName == name then SendBack("Your birthday is on the "..tBirthdays[name][1].." of "..tCalendar[month][2] , user, how) SendBack("I didnt know you are "..FindCorrectAge(tBirthdays[name])..". I'll keep that in mind ;)" , user, how) else SendBack(name.."'s birthday is on the "..tBirthdays[name][1].." of "..tCalendar[month][2] , user, how) SendBack("I didnt know "..name.." is "..FindCorrectAge(tBirthdays[name])..". I'll keep that in mind ;)" , user, how) end if user.sName == name then SendBack("New birthday added by "..user.sName.." his/her is on the "..tBirthdays[name][1].." of "..tCalendar[month][2] , user, how) else SendBack(user.sName.." added "..name.."'s birthday, which is on the "..tBirthdays[name][1].." of "..tCalendar[month][2] , user, how) end end end else SendBack("Come ON! "..pers.." cant be less than "..allowedage.." years old !!! LIAR >:(" , user, how) end else SendBack("Come ON! "..pers.." cant be more than "..(year-oldestyear).." years old !!! LIAR >:(" , user, how) end else SendBack("The date you provided was not valid ... ( syntax example : 14/5/1981 )" , user, how) end else SendBack("Please enter your birthday after the command ..." , user, how) end end function FindCorrectAge(table) if table[2] > tonumber(date("%m")) then return ( tonumber(date("%Y")) - table[3] ) - 1 elseif table[2] < tonumber(date("%m")) then return tonumber(date("%Y")) - table[3] elseif table[2] == tonumber(date("%m")) then if table[1] <= tonumber(date("%d")) then return tonumber(date("%Y")) - table[3] else return ( tonumber(date("%Y")) - table[3] ) - 1 end end end function FindSame(tTab, val , var, name) local tTmp = {} local msg = "" if var == "day" then for i, v in tTab do if val == v[1] and i ~= name then tTmp[i] = v[1].."/"..v[2].." - "..v[3] end end elseif var == "month" then for i, v in tTab do if val == v[2] and i ~= name then tTmp[i] = v[1].."/"..v[2].." - "..v[3] end end elseif var == "year" then for i, v in tTab do if val == v[3] and i ~= name then tTmp[i] = v[1].."/"..v[2].." - "..v[3] end end elseif var == "monthday" then for i, v in tTab do if val == v[1].."/"..v[2] and i ~= name then tTmp[i] = v[1].."/"..v[2].." - "..v[3] end end elseif var == "all" then for i, v in tTab do if val == v[1].."/"..v[2].." - "..v[3] and i ~= name then tTmp[i] = v[1].."/"..v[2].." - "..v[3] end end end for i,v in tTmp do msg = msg.."\t - "..i.."\t("..v..")\r\n" end if msg == "" then msg = "\t - noone\r\n" end return msg end function DoHappyBirthday(nick) if TxtSend == nil then SendToAll(ReadTextFile(birthdayfile)) TxtSend = 1 end local age = tonumber(date("%Y")) - tBirthdays[nick.sName][3] local tSurpises = { nick.sName.." is gonna have a PAAARTY, today he is turning "..age.." Happy Birthday !!!!", "All of you spam "..nick.sName.." with Birthday messages ;), ...turning "..age.." today !!!", "Who's turning "..age.." today ?? :D... The day AND the night belongs to "..nick.sName, "Happy Birthday to you, Happy Birthday dear "..nick.sName..", we all wish you your "..age.." will be better than your "..(age-1).." !! :)", " I think Mr"..nick.sName.." has his/her birthday today ... he/she should be turning "..age.." today ;D", }; SendToAll( bBot , tSurpises[random(1, getn(tSurpises)) ] ) end function ExactAge(user, how) local table = tBirthdays[user.sName] if table == nil then SendBack("I dont have your birthday,... please use the "..addcmd.." dd/mm/yyyy command to enter your birthday", user, how) return 1 else local curAge = FindCorrectAge(table) local finMonth = 0 if tonumber(date("%m")) < table[2] then finMonth = ( table[2] - tonumber(date("%m")) ) - 1 elseif tonumber(date("%m")) > table[2] then finMonth = ( tonumber(date("%m")) - table[2] ) end local finDays = 0 if tonumber(date("%d")) < table[1] then finMonth = finMonth - 1 local tempMonth = table[2] - 1 finDays = ( tCalendar[tempMonth][1] + ( tonumber(date("%d")) - table[1] ) ) if tonumber(date("%d")) > tCalendar[tonumber(date("%m"))][1] then finMonth = finMonth + 1 finDays = tCalendar[tonumber(date("%m"))][1] - finDays end else finDays = tonumber(date("%d")) - table[1] end if finMonth <= 0 then finMonth = 12 + finMonth if curAge == tonumber(date("%Y")) - table[3] then SendToAll("yeah") curAge = curAge - 1 end end if finMonth == 12 then curAge = curAge + 1 finMonth = 0 end SendBack("You are "..finDays.." days, "..finMonth.." months and "..curAge.." years old (that according to the Hub's clock :)", user, how) end end function BHelp(user, how) if tProfiles[""..prof..""] ~= 0 then local msg = "\r\n\t\t You can use the following commands for "..bBot.."\r\n" if tProfiles[""..prof..""] >= 1 then msg = msg.."\t - "..bhelpcmd.." \t\t\t\t- this text :)\r\n" msg = msg.."\t - "..listcmd.." \t\t\t- this will list the birthdays in store\r\n" msg = msg.."\t - "..addcmd.." dd/mm/yyyy \t\t- put your own birthday :)\r\n" msg = msg.."\t - "..findcmd.." \t\t\t- this will display the people that have similar birthday to yours\r\n" msg = msg.."\t - "..agecmd.." \t\t\t\t- this shows you your exact age ( days months years )\r\n" if tProfiles[""..prof..""] == 2 then msg = msg.."\t - "..delcmd.." \t\t- this deletes the birthday of \r\n" msg = msg.."\t - "..addbircmd.." dd/mm/yyyy \t- this adds the birthday of " end end SendBack(msg, user, how) end end --- // --- Table Serialization --- Thanks NL function Serialize(savTable, sTableName, hFile, sTab) assert(savTable, "savTable equals nil"); assert(sTableName, "sTableName equals nil"); assert(hFile, "hFile equals nil"); assert(type(savTable) == "table", "savTable must be a table!"); assert(type(sTableName) == "string", "sTableName must be a string!"); sTab = sTab or ""; write(hFile, sTab..sTableName.." = {\n" ); for key, value in savTable do local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key); if(type(value) == "table") then Serialize(value, sKey, hFile, sTab.."\t"); else local sValue = (type(value) == "string") and format("%q",value) or tostring(value); write(hFile, sTab.."\t"..sKey.." = "..sValue); end write(hFile, ",\n"); end write(hFile, sTab.."}"); end function LoadFile(file) assert(readfrom(file),file.." is not found.") dostring(read("*all")) readfrom() end function SaveFile(table , tablename, file) local hFile = openfile(file, "w"); Serialize(table, tablename, hFile); closefile(hFile); end function ReadTextFile(file) local message = "\r\n" readfrom(file, "r") while 1 do local line = read() if ( line == nil ) then break else message = message.."\t"..line.."\r\n" end end readfrom() return message end