Here is the script....
Quote
--By Mutor
sBot = "Time-Bot"
ChatArrival = function(user,data)
local sBot,h,m = "Time-Bot",math.modf((os.time()-os.time(os.date"!*t"))/ 3600)
local s,e,cmd = string.find(data,"%b<>%s%p(%w+)")
if cmd and cmd == "time" then
return user:SendData(sBot,os.date("Today is %A, %B %d, %Y Time: %I:%M:%S %p")..
" "..string.format("%+d UTC",(h + (60 * m)))),1
end
end
ToArrival = ChatArrival
when a user type !time it gives the following result..
Quote
Today is Thursday, October 05, 2006 Time: 12:00:57 PM +35 UTC
What is the meaning of UTC and how can I remove it ???
and i would like two more additions.....
1) When 1 user type's !time all shud be able to see tht command along wid the result.....and i would if the command comes b4 the result......
2) And can a message be added to this according to time....like:
(if the time is between 4am - 12pm thn)
Quote
<speedX>!time
<Time-Bot> Good Morning speedX :
Today is Thursday, October 05, 2006 Time: 07:00:57 AM
(if time is between 12pm - 4pm thn)
<speedX>!time
<Time-Bot> Good Afternoon speedX :
Today is Thursday, October 05, 2006 Time: 02:45:57 PM
if possible.....thank u....
You could have tried a bit harder finding out the UTC meaning!
There is no time to give info on everything...
UTC in Wikipedia! (http://en.wikipedia.org/wiki/Coordinated_Universal_Time)
Try this for a request fulfilling..
Haven't checked this one at all, no time...
--## Simple Time Bot
--## Requested by SteffJay
--## Made by nErBoS
--## Converted in LUA 5 by 6Marilyn6Manson6
--## Commands:
--## !time - Gives the current time
--- touched by Herodes
-- added the afternoon/morning greeting, some code cleanup
sBot = "Time-Bot"
ChatArrival = function(user,data)
local h,m = math.modf((os.time()-os.time(os.date"!*t"))/ 3600)
if string.find(data,"%b<>%s%ptime%s?") then
user:SendData( sBot, "Good "..({["am"] = "Morning", ["pm"] = "Afternoon" })[string.lower(os.date("%p"))].." "..user.sName.."\r\n\r\n\t"..os.date("Today is %A, %B %d, %Y Time: %I:%M:%S %p").." "..string.format("%+d UTC",(h + (60 * m))).."\r\n")
end
end
ToArrival = ChatArrival
\scripts\time.lua:14: `)' expected near `['
got an error in there somewhere m8 ^^
Quote from: Psycho_Chihuahua on 05 October, 2006, 10:05:51
\scripts\time.lua:14: `)' expected near `['
got an error in there somewhere m8 ^^
Many thx psycho,... wrong parenthesis
({["a"] = 1, ["b"] = 2 }[i]) -- this is wrong, will give error...
({["a"] = 1, ["b"] = 2 })[i] -- this is good, will work ;)
my post is now updated, grab again ;)
hehe runs fine untill i enter "!time" ;)
\scripts\time.lua:12: attempt to call field `modf' (a nil value)
Quote from: Psycho_Chihuahua on 05 October, 2006, 11:13:36
hehe runs fine untill i enter "!time" ;)
\scripts\time.lua:12: attempt to call field `modf' (a nil value)
its for Lua 5.1 :)
oh yeah just noticed lol
thought it was 5/5.1 ^^
ya gr8 it works thx.....but could make it in such a way tht the command comes b4 the result??
and can u add one more evening time ....between 6pm - 12am ?? if possible....lastly could u plzz remove tht UTC....plzzz
Quote from: speedX on 05 October, 2006, 13:57:58
ya gr8 it works thx.....but could make it in such a way tht the command comes b4 the result??
and can u add one more evening time ....between 6pm - 12am ?? if possible....lastly could u plzz remove tht UTC....plzzz
Sorry.............can't change the way PtokaX sends.........or proccesses data......
I could do it.........with a timer,..... but...........I am not going through this trouble,...... for this kind of a bot and this kind of a ,... request post................... or should I call it a thread???
(notice how annoying the series of dots and question marks are, pls respect the forum and don't post like its a chat)There is your code
--## Simple Time Bot
--## Requested by SteffJay
--## Made by nErBoS
--## Converted in LUA 5 by 6Marilyn6Manson6
--## Commands:
--## !time - Gives the current time
--- touched by Herodes
-- added the afternoon/morning greeting, some code cleanup
-- added customised time gaps and the ability to set a greeting for the respective time gap
-- remove UTC showing,.. although it should be left there cause the hubs are global. ( blame speedX )
sBot = "Time-Bot"
tTimes = {
{ seg = { "00:00", "11:30" }, msg = "Good Morning! [name]", },
{ seg = { "11:31", "15:00" }, msg = "Good Afternoon! [name]", },
{ seg = { "15:01", "23:59" }, msg = "Good Evening, [name]", }
}
function Main()
local function makeInt(x)
local h, m = string.match( x , "(%d+)%:(%d+)" )
return {tonumber(h),tonumber(m)}
end
for i,v in pairs(tTimes) do
v.seg[1] = makeInt(v.seg[1])
v.seg[2] = makeInt(v.seg[2])
end
end
function ChatArrival( user, data )
if string.find(string.sub(data, 1, -2),"%b<>%s%ptime%s?") then
SendTime( user )
end
end
function ToArrival(user, data )
if string.find(string.sub(data, 1, -2),"%b<>%s%ptime%s?") then
SendTime( user, true )
end
end
function SendTime(user, how)
local function FindMessage ()
local curHour, curMinute = tonumber(os.date("%H")), tonumber(os.date("%M"))
for i,v in pairs(tTimes) do
if (v.seg[1][1] <= curHour and v.seg[2][1] >= curHour) and (v.seg[1][2] <= curMinute and v.seg[2][2] >= curMinute) then
return v.msg
end
end
return "Hello"
end
local msg = string.gsub( FindMessage(), "%[name%]", user.sName).."\r\n\r\n\t"..os.date("Today is %A, %B %d, %Y Time: %I:%M:%S %p\r\n")
if how then user:SendPM( sBot, msg ); else user:SendData( sBot, msg ); end;
end
Quote from: Herodes on 05 October, 2006, 14:54:46
(notice how annoying the series of dots and question marks are, pls respect the forum and don't post like its a chat)
yup sorry........