Script what counts days,hours,minutes,seconds
We give hubs startingday
Hubborn = "24.4.2005"
Scripts will say:
Welcome to <hubname>. Hub is <counted days,hrs,mins,sec> old and current uptime is <uptime>
thanks again folsk you're the best :)
Quote from: Northwind on 10 September, 2006, 22:50:13
Script what counts days,hours,minutes,seconds
We give hubs startingday
Hubborn = "24.4.2005"
Scripts will say:
Welcome to <hubname>. Hub is <counted days,hrs,mins,sec> old and current uptime is <uptime>
thanks again folsk you're the best :)
Hint:
Top Hubbers,
Birthday Man and
Countdown Bot would help you with this.
well as im not a scripter and i wanted a script to what shows only those after motd not other what those scripts can offer... i try to keep my hub clean and simply..:P
Quote from: Northwind on 14 September, 2006, 23:33:49
well as im not a scripter and i wanted a script to what shows only those after motd not other what those scripts can offer... i try to keep my hub clean and simply..:P
Well, I wasn't forcing you to use one [or more] of them.
It's just that their code would suit perfectly for this request, though with small modifications.
As previously stated, those bot's codes could be perfectly used altogether to fill your request, and here goes a quick [and mixed] attempt:
--[[
LifeTime Bot 1.02 - LUA 5.0/5.1 version by jiten
????????????????????????????????????????????????
DESCRIPTION:
- Get Hub's current uptime;
- Determine how old is the hub
CHANGELOG:
Added: Missing LUA 5.1 compatibility - reported by NorthWind;
Added: Support for years - requested by Psycho_Chihuahua (9/16/2006)
Changed: LUA 5.1 compatibility vars
]]--
tSettings = {
-- Bot Name
sBot = frmHub:GetHubBotName(),
-- RightClick Menu
sMenu = "LifeTime",
-- Hub's 'birth' date
iSetup = {
year = 2006,
month = 3,
day = 28,
hour = 21,
min = 00,
sec = 00
},
}
ChatArrival = function(user, data)
local _,_, to = string.find(data, "^$To:%s(%S+)%s+From:")
local _,_, msg = string.find(data, "%b<>%s(.*)|$")
-- Message sent to Bot or in Main
if (to and to == tSettings.sBot) or not to then
-- Parse command
local _,_, cmd = string.find(msg, "^%p(%S+)")
-- Exists
if cmd and tCommands[string.lower(cmd)] then
cmd = string.lower(cmd)
-- If user has permission
if tCommands[cmd].tLevels[user.iProfile] and tCommands[cmd].tLevels[user.iProfile] == 1 then
return tCommands[cmd].fFunction(user, msg), 1
else
return user:SendData(tSettings.sBot, "*** Error: You are not allowed to use this command!"), 1
end
end
end
end
ToArrival = ChatArrival
NewUserConnected = function(user)
-- Supports UserCommands
if user.bUserCommand then
-- For each entry in table
for i, v in pairs(tCommands) do
-- If member
if v.tLevels[user.iProfile] then
-- Send
user:SendData("$UserCommand 1 3 "..tSettings.sMenu.."\\"..v.tRC[1]..
"$<%[mynick]> !"..i..v.tRC[2].."|")
end
end
end
user:SendData(tSettings.sBot, "*** Welcome to "..(frmHub:GetHubName() or "Unknown").."!"); tCommands["lifetime"].fFunction(user)
end
OpConnected = NewUserConnected
tCommands = {
lifetime = {
fFunction = function(user)
local iDiff = os.difftime( os.time(os.date("!*t")), os.time(tSettings.iSetup))
if iDiff > 0 then
user:SendData(tSettings.sBot, "*** This hub is "..
SecondsToTime(iDiff).." old and current uptime is "..SecondsToTime(frmHub:GetUpTime(), true).."!")
else
user:SendData(tSettings.sBot, "*** Error: You must enter a valid Hub Birthday!")
end
end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tRC = { "Show hub's age and uptime", "" }
},
}
SecondsToTime = function(iTime, bSmall)
-- LUA 5.0/5.1 compatibility
string.gmatch = (string.gmatch or string.gfind)
-- Build table with time fields
local T = os.date("!*t", tonumber(iTime));
-- Format to string
local sTime = string.format("%i year(s), %i month(s), %i day(s), %i hour(s), %i minute(s)", T.year-1970, T.month-1, T.day-1, T.hour, T.min)
-- Small stat?
if bSmall then
-- For each digit
for i in string.gmatch(sTime, "%d+") do
-- Reduce if is preceeded by 0
if tonumber(i) == 0 then sTime = string.gsub(sTime, "^"..i.."%s(%S+),%s", "") end
end
end
-- Return
return sTime
end
if (to and to == tSettings.sBot) or not to then
Maybe i'm tierd... but isn't that like... if (find to and to is botname) or if not find to then
I think the or should be removed.. or am i wrong?
[17:21] Syntax D:\HUBIX\scripts\lifetime.lua:97: 'string.gfind' was renamed to 'string.gmatch'
stack traceback:
[C]: in function 'gfind'
D:\HUBIX\scripts\lifetime.lua:97: in function 'SecondsToTime'
D:\HUBIX\scripts\lifetime.lua:77: in function 'fFunction'
D:\HUBIX\scripts\lifetime.lua:66: in function <D:\HUBIX\scripts\lifetime.lua:53>
well it works nicely the way jiten had it in his last post - only thing missing is the amount of years :(
Quote from: Madman on 16 September, 2006, 03:53:06
if (to and to == tSettings.sBot) or not to then
Maybe i'm tierd... but isn't that like... if (find to and to is botname) or if not find to then
I think the or should be removed.. or am i wrong?
If we remove the
or not to part, then that function will only
deal with messages sent in PM to the bot.
Thus, those typed in main chat will be ignored.
So, it's really necessary to have it here, mate.
Quote from: Northwind on 16 September, 2006, 16:17:54
[17:21] Syntax D:\HUBIX\scripts\lifetime.lua:97: 'string.gfind' was renamed to 'string.gmatch'
Thank you for your report. I missed the function that dealt with the LUA 5.0/5.1 compatibility.
Quote from: Psycho_Chihuahua on 16 September, 2006, 19:40:37
well it works nicely the way jiten had it in his last post - only thing missing is the amount of years :(
I've also added 'years' support to the updated script :P
[22:21] Syntax ...\TestHub Leviathan Lua 5.11\scripts\LifeTime Bot.lua:105: attempt to call a string value
stack traceback:
...\TestHub Leviathan Lua 5.11\scripts\LifeTime Bot.lua:105: in function 'SecondsToTime'
...\TestHub Leviathan Lua 5.11\scripts\LifeTime Bot.lua:83: in function 'fFunction'
...\TestHub Leviathan Lua 5.11\scripts\LifeTime Bot.lua:72: in function <...\TestHub Leviathan Lua 5.11\scripts\LifeTime Bot.lua:59>
First post has been updated once more.
Could you add one more thing :)
possibility to add hublifetime in topic every xx min
update topic every = 6 hours
random choose topic 1 to 5
--topic profiles--
[1]"We have been exist [days-hours]"
[2]"Our hub is [days-hours] old"
[3]"Alive and kickin' [days-hours]"
[4]"Hub's has born [days-hours] a go"
[5]"Look at our hubs lifetime, [days-hours] and counting"
--topic profile end--
Quote from: Northwind on 20 September, 2006, 04:27:42
Could you add one more thing :)
possibility to add hublifetime in topic every xx min
Yes, it can and will be added.
Check this thread for the updated version: http://forum.ptokax.org/index.php?topic=6450.0