PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: EXNET OWNER on 12 August, 2004, 14:35:50

Title: me ... again
Post by: EXNET OWNER on 12 August, 2004, 14:35:50
I also would like a bot which displays the time on request insted of by a timer when i use the command

+time

I cant do it i have been workin on it but cant seem to make it work, it has no errors but will not display the time and date
Title: Clock
Post by: monnie on 12 August, 2004, 21:13:30
Greetings

I have this one working fine...
The Autor is Malukito Jr..

Bot = "Rel?gio"

function Main()
   frmHub:RegBot(Bot)
end

function DataArrival(user, data)
   if (strsub(data,1,1)=="<") or (strsub(data,1,5+strlen(Bot))=="$To: "..Bot) then
   data=strsub(data,1,strlen(data)-1)
   s,e,cmd = strfind(data,"%b<>%s+(%S+)")
      if (cmd=="+horas") then
         horas = date("%H")
         minutos = date("%M")
         user:SendPM(Bot, "S?o "..horas..":"..minutos)
         return 1
      end
   end
end


If you rather like it in english...

Bot = "Clock"

function Main()
   frmHub:RegBot(Bot)
end

function DataArrival(user, data)
   if (strsub(data,1,1)=="<") or (strsub(data,1,5+strlen(Bot))=="$To: "..Bot) then
   data=strsub(data,1,strlen(data)-1)
   s,e,cmd = strfind(data,"%b<>%s+(%S+)")
      if (cmd=="+time") then
         hours = date("%H")
         minutes = date("%M")
         user:SendPM(Bot, "It's "..hours..":"..minutes)
         return 1
      end
   end
end


Hope you've got served...


                                           monnie
Title:
Post by: plop on 12 August, 2004, 22:58:57
no need 2 waste 3 globals on that.
beside using hours and minutes on seperate calls can cause faulty results.
Bot = "Clock"

function Main()
   frmHub:RegBot(Bot)
end

function DataArrival(user, data)
   if (strsub(data,1,1)=="<") or (strsub(data,1,5+strlen(Bot))=="$To: "..Bot) then
      data=strsub(data,1,strlen(data)-1)
      local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
      if (cmd=="+time") then
         user:SendPM(Bot, "It's "..date("%X").."|")
         return 1
      end
   end
end
plop
Title:
Post by: BottledHate on 12 August, 2004, 23:08:26
a little spin on plops for more customization in the time/date output....

Bot = "Clock"

function Main()
   frmHub:RegBot(Bot)
end

function GetTime()
a = date("%a")
I = date("%I")
M = date("%M")
S = date("%S")
b = date("%b")
d = date("%d")
z = date("%z")
y = date("%y")
p = date("%p")
Date = a..", "..I..":"..M..":"..S.." "..p..", "..b.."/"..d.."/"..y.." "..z
return Date
end

function DataArrival(user, data)
   if (strsub(data,1,1)=="<") or (strsub(data,1,5+strlen(Bot))=="$To: "..Bot) then
      data=strsub(data,1,strlen(data)-1)
      local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
      if (cmd=="+time") then
         user:SendPM(Bot, "It's "..GetTime().."|")
         return 1
      end
   end
end


more codes:
| %a   abbreviated weekday name   "Mon"...
| %A   full weekday name      "Monday"...
| %b   abbreviated month name      "Jan"...
| %B   full month name         "January"...
| %c   locale-specific date and time
| %d   day of the month as integer   01-31
| %H   hour (24-hour clock)      00-23
| %I   hour (12-hour clock)      01-12
| %j   day of the year as integer   001-366
| %m   month as integer      01-12
| %M   minute as integer      00-59
| %p   locale AM/PM designation
| %S   second as integer      00-61 (allow for up to 2 leap seconds)
| %U   week number of the year      00-53 (week number 1 has 1st sunday)
| %w   weekday as integer      (0-6, sunday=0)
| %W   week number of the year      00-53 (week number 1 has 1st monday)
| %x   locale specific date
| %X   locale specific time
| %y   year without century      00-99
| %Y   year with century      1900...
| %z   time zone name


-BH
Title:
Post by: ??????Hawk?????? on 13 August, 2004, 00:16:55
hi EXNET OWNER

   click on my sig for another time script   :))
Title:
Post by: plop on 13 August, 2004, 01:13:03
@BottledHate: re-read my previous post really carefully.
you make the same mistake which i fixed on the script monnie posted.
never do multiple calls 2 the date, use 1 and splitt it when needed with a strfind.

plop
Title:
Post by: BottledHate on 13 August, 2004, 03:09:36
thanks plop!


Bot = "Clock"

function Main()
   frmHub:RegBot(Bot)
end

function GetTime()
   local _,_,a, A, b, B, c, d, H, I, j, m, M, p, S, U, w, W, x, y, Y, z = strfind(date(
      "|%a|%A|%b|%B|%c|%d|%H|%I|%j|%m|%M|%p|%S|%U|%w|%W|%x|%y|%Y|%z|"),
      "|(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|")
   local Date = a..", "..I..":"..M..":"..S.." "..p..", "..b.."/"..d.."/"..y.." "..z --Example formating... output: Thu, 04:05:23 PM, Aug/12/04 Pacific Daylight Time
   return Date
end

function DataArrival(user, data)
   if (strsub(data,1,1)=="<") or (strsub(data,1,5+strlen(Bot))=="$To: "..Bot) then
      data=strsub(data,1,strlen(data)-1)
      local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
      if (cmd=="+time") then
         user:SendPM(Bot, "It's "..GetTime().."|")
         return 1
      end
   end
end


plop rules.. if it wasn't for him i'd wouldn't have learned shit!

-BH
Title:
Post by: plop on 13 August, 2004, 06:42:04
the best way is 2 use 1 call, date().
the resulting string can be splitted and processed into the format you want it 2 show.
a good example is hidden away in a.i..
[06:45] !time
[06:45] <-Bure-> It is quarter before seven on Friday the thirthteenth of August twothousend and four (hubtime/date, not your local time/date)
it uses 1 single call 2 date() without arguments and it's fully formatted as you can see.

plop