Time 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

Time Bot

Started by speedX, 05 October, 2006, 08:41:22

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

speedX

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....
Thanking You,

speedX

Herodes

#1
You could have tried a bit harder finding out the UTC meaning!
There is no time to give info on everything...
UTC in Wikipedia!

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

Psycho_Chihuahua

\scripts\time.lua:14: `)' expected near `['


got an error in there somewhere m8 ^^
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

Herodes

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

Psycho_Chihuahua

hehe runs fine untill i enter "!time"  ;)

\scripts\time.lua:12: attempt to call field `modf' (a nil value)
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

Herodes

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 :)

Psycho_Chihuahua

oh yeah just noticed lol

thought it was 5/5.1 ^^
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

speedX

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
Thanking You,

speedX

Herodes

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

speedX

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........
Thanking You,

speedX

SMF spam blocked by CleanTalk