Birthdayman LUA 5
 

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

Birthdayman LUA 5

Started by TiMeTrAVelleR, 08 March, 2005, 21:43:54

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TiMeTrAVelleR

[code]

--- BirthdayMan v 2.6   LUA_5.0
--- by Herodes -- Update 22/9/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 Skyhawk comment for the display age
--- --- --- --- --- ---
----- 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 ...
tProfiles = {  ---- profile rights to commands, 0 cant use the bot at all, 1 can use listcmd and addcmd, 2 can also use delcmd and addbircmd...   
         ["-1"] = 0,    --- Unregs
         ["0"] = 2,     --- Masters
         ["1"] = 2,     --- Operators
         ["2"] = 1,    --- VIPs
         ["3"] = 1,    --- Regs
         ["4"] = 1,    --- CustomProf1
         ["5"] = 2,   --- 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 ;)
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()
   dofile(birthlog)
   tCalendar[2][1] = FixFebruary(tonumber(os.date("%Y")))

   local hr = tonumber(os.date("%H"))*60*60*1000
   local mins = 0
   if tonumber(os.date("%M")) == 0 then
      mins = 1
   else
      mins = tonumber(os.date("%M"))*60*1000
   end
   fixTime(hr+mins)
end

function OnTimer()
   CheckBirthdays()
   TxtSend = nil
end

function NewUserConnected(user)
   for i, v in tBirthdays do
      if tBirthdays[2] == tonumber(os.date("%m")) and tBirthdays[1] == tonumber(os.date("%d")) then
         if user.sName ~= i then
            local msg = "Its "..i.."'s birhtday today .. ;D Turning "..(tonumber(os.date("%Y"))-tBirthdays[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()
for i, v in tBirthdays do
   if tBirthdays[2] == tonumber(os.date("%m")) then
      if tBirthdays[1] == tonumber(os.date("%d")) then
         if GetItemByName(i) then
            happy = GetItemByName(i)
            DoHappyBirthday(happy)
         end
      end
   end
end
end

function FixFebruary(y)
   local value = 0
   if (tonumber(y)/4) - (math.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 ChatArrival(user, data)
if tProfiles[""..user.iProfile..""] ~= 0 then
   if string.sub(data, 1,1) == "<" then
      data = string.sub(data, 1, string.len(data)-1)
      local s,e,cmd,args = string.find(data, "%b<>%s+(%S+)%s*(.*)")
      if cmd == addcmd or cmd == addbircmd and tProfiles[""..user.iProfile..""] >= 1 then
         CheckBirthdays()
         AddBirthDay(user, args)
         return 1
      elseif cmd == delcmd and tProfiles[""..user.iProfile..""] == 2 then
         if args ~= nil then
            if tBirthdays[args] then
               if GetItemByName(args) then
                  nick = GetItemByName(args)
                  nick:SendPM(bBot, user.sName.." has deleted your birthday from my list .. ;(")
               end
               tBirthdays[args] = nil
               user:SendData(bBot, "You deleted "..args.." bithday ...")
               SaveFile(tBirthdays , "tBirthdays", birthlog)
            else user:SendData(bBot, args.." is not in my birthday list ...")
            end
         else user:SendData(bBot , "You need to give me a name ...")
         end
         return 1
      elseif cmd == listcmd and tProfiles[""..user.iProfile..""] >= 1 then
         local str = "The Birthday List of the users of "..frmHub:GetHubName()
         local msg = "\r\n    ..-*'~ "..str.." ~'*-..\r\n"..string.rep("^", string.len(str)).."\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
            msg = msg..c..". - "..tBirthdays[1].."/"..tBirthdays[2].."/"..tBirthdays[3].." - \t"..i.."\t ( "..status.." )\r\n\t"
         end
         user:SendData(bBot , msg)
         return 1
      elseif cmd == findcmd then
         if tBirthdays[user.sName] then
            local msg = " 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"
            user:SendData(bBot, msg)
            return 1
         end
      end
   end
end
end

function AddBirthDay(user, args)
   local pers = ""
   if args ~= nil then
      local s,e,name,day,month,year = string.find(args, "(%S+)%s+(%d+)/(%d+)/(%d+)")
      if name == nil then
         name = user.sName
         pers = "you"
         s,e,day,month,year = string.find(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(os.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
                        user:SendData(bBot, "I have your birthday already ... its on the "..tBirthdays[name][1].." of "..tCalendar[month][2])
                     else user:SendData(bBot, "I have "..name.."'s birthday already ... its on the "..tBirthdays[name][1].." of "..tCalendar[month][2])
                     end
                     local profstr = ""
                        for i,v in tProfiles do
                           if tProfiles == 2 then
                              profstr = GetProfileName(tonumber(i)).."s"
                              break
                           end
                        end
                     user:SendData(bBot, "If you dont think this is correct ... then talk to one of our "..profstr)
                  else tBirthdays[name] = {}
                     tBirthdays[name][1] = day
                     tBirthdays[name][2] = month
                     tBirthdays[name][3] = year
                     SaveFile(tBirthdays , "tBirthdays", birthlog)
                     if user.sName == name then
                        user:SendData(bBot, "Your birthday is on the "..tBirthdays[name][1].." of "..tCalendar[month][2])
                        user:SendData(bBot, "I didnt know you are "..FindCorrectAge(tBirthdays[name])..". I'll keep that in mind ;)")
                     else
                        user:SendData(bBot, name.."'s birthday is on the "..tBirthdays[name][1].." of "..tCalendar[month][2])
                        user:SendData(bBot, "I didnt know "..name.." is "..FindCorrectAge(tBirthdays[name])..". I'll keep that in mind ;)")
                     end
                     if user.sName == name then
                        SendToAll(bBot, "New birthday added by "..user.sName.." his is on the "..tBirthdays[name][1].." of "..tCalendar[month][2])
                     else SendToAll(bBot, user.sName.." added "..name.."'s birthday, which is on the "..tBirthdays[name][1].." of "..tCalendar[month][2])
                     end
                  end
               end
            else user:SendData(bBot, "Come ON! "..pers.." cant be less than "..allowedage.." years old !!!  LIAR >:(")
            end
         else user:SendData(bBot, "Come ON! "..pers.." cant be more than "..(year-oldestyear).." years old !!!  LIAR >:(")
         end
      else user:SendData(bBot, "The date you provided was not valid ... ( syntax example : 14/5/1981 )")
      end
   else user:SendData(bBot , "Please enter your birthday after the command ...")
   end
end

function FindCorrectAge(table)
   if table[2] > tonumber(os.date("%m")) then
      if table[1] >= tonumber(os.date("%d")) then
         return tonumber(os.date("%Y"))-table[3]
      else
         return (tonumber(os.date("%Y"))-table[3])-1
      end
   elseif table[2] <= tonumber(os.date("%Y")) then
      if table[1] >= tonumber(os.date("%d")) then
         return tonumber(os.date("%Y"))-table[3]
      else
         return (tonumber(os.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 = 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 = 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 = 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 = 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 = v[1].."/"..v[2].." - "..v[3]
         end
      end
   end
   for i,v in tTmp do
      msg = msg.."\t - "..i.."\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(os.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 birthday today ... he should be turning "..age.." today ;D",
         };
   SendToAll( bBot , tSurpises[random(1, getn(tSurpises)) ] )
end

[code/]

the script runs   but   when  i add   birthday  and    restart scripts  it delites  it   so prob is   what  is wrong whit saving part

TiMeTrAVelleR

TiMeTrAVelleR

Part 2
[code]

--- // --- 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 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);
         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

[code/]

Jelf

#2
Here you go....
--- BirthdayMan v 2.6 LUA_5.0 with little help by Jelf
--- by Herodes -- Update 22/9/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 Skyhawk comment for the display age
--- --- --- --- --- ---
----- 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 ...
tProfiles = { ---- profile rights to commands, 0 cant use the bot at all, 1 can use listcmd and addcmd, 2 can also use delcmd and addbircmd...
["-1"] = 0, --- Unregs
["0"] = 2, --- Masters
["1"] = 2, --- Operators
["2"] = 1, --- VIPs
["3"] = 1, --- Regs
["4"] = 1, --- CustomProf1
["5"] = 2, --- 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 ;)
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
local f,e = io.open( birthlog, "a+" ) --//Error handle.. makes sure save file and dir exist...
f,e = io.open( birthlog, "a+" )
if f then
f:write("" )
f:close() --// file and path did not exist.. now they do.
else
birthlog = "birthdays.tbl"--//this is only if the path provided is invalid to winblows. defaults to a file in the scripts dir.
end
require(birthlog)
--- // --- 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()
 
dofile(birthlog)
tCalendar[2][1] = FixFebruary(tonumber(os.date("%Y")))
local hr = tonumber(os.date("%H"))*60*60*1000
local mins = 0
if tonumber(os.date("%M")) == 0 then
mins = 1
else
mins = tonumber(os.date("%M"))*60*1000
end
fixTime(hr+mins)
end
-----------------------------
function OnTimer()
CheckBirthdays()
TxtSend = nil
end
-------------------------------
function NewUserConnected(user)
for i, v in tBirthdays do
if tBirthdays[i][2] == tonumber(os.date("%m")) and tBirthdays[i][1] == tonumber(os.date("%d")) then
if user.sName ~= i then
local msg = "Its "..i.."'s birthday today .. ;D Turning "..(tonumber(os.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()
for i, v in tBirthdays do
if tBirthdays[i][2] == tonumber(os.date("%m")) then
if tBirthdays[i][1] == tonumber(os.date("%d")) then
if GetItemByName(i) then
happy = GetItemByName(i)
DoHappyBirthday(happy)
end
end
end
end
end
-------------------------------------
function FixFebruary(y)
 
local value = 0
if (tonumber(y)/4) - (math.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 ChatArrival(user, data)
if tProfiles[""..user.iProfile..""] ~= 0 then
if string.sub(data, 1,1) == "<" then
data = string.sub(data, 1, string.len(data)-1)
local s,e,cmd,args = string.find(data, "%b<>%s+(%S+)%s*(.*)")
if cmd == addcmd or cmd == addbircmd and tProfiles[""..user.iProfile..""] >= 1 then
CheckBirthdays()
AddBirthDay(user, args)
return 1
elseif cmd == delcmd and tProfiles[""..user.iProfile..""] == 2 then
if args ~= nil then
if tBirthdays[args] then
if GetItemByName(args) then
nick = GetItemByName(args)
nick:SendPM(bBot, user.sName.." has deleted your birthday from my list .. ;(")
end
tBirthdays[args] = nil
user:SendData(bBot, "You deleted "..args.." bithday ...")
SaveFile(birthlog, tBirthdays, "tBirthdays")
else user:SendData(bBot, args.." is not in my birthday list ...")
end
else user:SendData(bBot , "You need to give me a name ...")
end
return 1
elseif cmd == listcmd and tProfiles[""..user.iProfile..""] >= 1 then
local str = "The Birthday List of the users of "..frmHub:GetHubName()
local msg = "\r\n ..-*'~ "..str.." ~'*-..\r\n"..string.rep("^", string.len(str)).."\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
msg = msg..c..". - "..tBirthdays[i][1].."/"..tBirthdays[i][2].."/"..tBirthdays[i][3].." - \t"..i.."\t ( "..status.." )\r\n\t"
end
user:SendData(bBot , msg)
return 1
elseif cmd == findcmd then
if tBirthdays[user.sName] then
local msg = " 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"
user:SendData(bBot, msg)
return 1
end
end
end
end
end
--------------------------
function AddBirthDay(user, args)
 
local pers = ""
if args ~= nil then
local s,e,name,day,month,year = string.find(args, "(%S+)%s+(%d+)/(%d+)/(%d+)")
if name == nil then
name = user.sName
pers = "you"
s,e,day,month,year = string.find(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(os.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
user:SendData(bBot, "I have your birthday already ... its on the "..tBirthdays[name][1].." of "..tCalendar[month][2])
else user:SendData(bBot, "I have "..name.."'s birthday already ... its on the "..tBirthdays[name][1].." of "..tCalendar[month][2])
end
local profstr = ""
for i,v in tProfiles do
if tProfiles[i] == 2 then
profstr = GetProfileName(tonumber(i)).."s"
break
end
end
user:SendData(bBot, "If you dont think this is correct ... then talk to one of our "..profstr)
else tBirthdays[name] = {}
tBirthdays[name][1] = day
tBirthdays[name][2] = month
tBirthdays[name][3] = year
SaveFile(birthlog, tBirthdays, "tBirthdays")
if user.sName == name then
user:SendData(bBot, "Your birthday is on the "..tBirthdays[name][1].." of "..tCalendar[month][2])
user:SendData(bBot, "I didnt know you are "..FindCorrectAge(tBirthdays[name])..". I'll keep that in mind ;)")
else
user:SendData(bBot, name.."'s birthday is on the "..tBirthdays[name][1].." of "..tCalendar[month][2])
user:SendData(bBot, "I didnt know "..name.." is "..FindCorrectAge(tBirthdays[name])..". I'll keep that in mind ;)")
end
if user.sName == name then
SendToAll(bBot, "New birthday added by "..user.sName.." his is on the "..tBirthdays[name][1].." of "..tCalendar[month][2])
else SendToAll(bBot, user.sName.." added "..name.."'s birthday, which is on the "..tBirthdays[name][1].." of "..tCalendar[month][2])
end
end
end
else user:SendData(bBot, "Come ON! "..pers.." cant be less than "..allowedage.." years old !!! LIAR >:(")
end
else user:SendData(bBot, "Come ON! "..pers.." cant be more than "..(year-oldestyear).." years old !!! LIAR >:(")
end
else user:SendData(bBot, "The date you provided was not valid ... ( syntax example : 14/5/1981 )")
end
else user:SendData(bBot , "Please enter your birthday after the command ...")
end
end
-------------------------
function FindCorrectAge(table)
if table[2] > tonumber(os.date("%m")) then
if table[1] >= tonumber(os.date("%d")) then
return tonumber(os.date("%Y"))-table[3]
else
return (tonumber(os.date("%Y"))-table[3])-1
end
elseif table[2] <= tonumber(os.date("%Y")) then
if table[1] >= tonumber(os.date("%d")) then
return tonumber(os.date("%Y"))-table[3]
else
return (tonumber(os.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.."\r\n"
end
if msg == "" then
msg = "\t - noone\r\n"
end
return msg
end

Jelf

Part 2
--------------------------
function DoHappyBirthday(nick)
 
if TxtSend == nil then
SendToAll(ReadTextFile(birthdayfile))
TxtSend = 1
end
local age = tonumber(os.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 birthday today ... he should be turning "..age.." today ;D",
};
SendToAll( bBot , tSurpises[random(1, getn(tSurpises)) ] )
end
------------------------------
--- // --- Table Serialization --- Thanks NL
function Serialize(tTable, sTableName, sTab)
        assert(tTable, "tTable equals nil");
        assert(sTableName, "sTableName equals nil");
        assert(type(tTable) == "table", "tTable must be a table!");
        assert(type(sTableName) == "string", "sTableName must be a string!");
        sTab = sTab or "";
        sTmp = ""
        sTmp = sTmp..sTab..sTableName.." = {\n"
        for key, value in tTable do
                local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
                if(type(value) == "table") then
                        sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
                else
                        local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
                        sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
                end
                sTmp = sTmp..",\n"
        end
        sTmp = sTmp..sTab.."}"
        return sTmp
end
---------------------------
function LoadFile(file)
local handle = io.open(file,"r")
if (handle ~= nil) then
loadstring(handle:read("*all"))
handle:flush()
handle:close()
end
end
----------------------------
function SaveFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
--------------------------
function ReadTextFile(file)
local message = "\r\n"
local handle = io.open(file, "r")
while 1 do
local line = handle:read()
if ( line == nil ) then break
else message = message.."\t"..line.."\r\n"
end
end
handle:close()
return message
end

TiMeTrAVelleR

#4
Thank  you    wil   try it as soon as i am home from work  

:))

Jorgo

Just curious.. why do you use 2.6 and not 3.5?
Sigh... I could have marked another script as done  :P

Yahoo

can any make this script for LUA 5.1

and one more change if possible i.e
when a user type the command !birthdays it must display only those users having birthdays on tht day
for eg
if the date is 15th november and a user type the command !birthdays the users must see birthdays of users on 15th nov only
"BoRN FIGhTEr"

bastya_elvtars

Please file a request in the appropriate section with linking to this topic. Thanks.
Everything could have been anything else and it would have just as much meaning.

rEALx


Birthday Man v.4.07 is compatible with Lua 5.1

already available @ http://board.ptokax.ath.cx/index.php?topic=5863.msg59035#msg59035

rEALx


Yahoo

"BoRN FIGhTEr"

 
SMF spam blocked by CleanTalk