time.lua

Created: 2022/12/18 00:56:25 America/Chicago
By: admin
Modified: 2022/12/31 06:09:44 America/Chicago
By: admin

Small lua script that will show current server time in user list of your hub.

Save this script in your hub's scripts directory as time.lua and use following commands to enable/disable it.

// enable script
!luaload /PATH/TO/HUB/scripts/time.lua

// disable script
!luaunload /PATH/TO/HUB/scripts/time.lua

time.lua

name = '' 
class = 3
description = 'Time Bot: US'
speed = '100'
email = ''
share = '0'
prefix = '!_US_'
postfix = ''
interval = 10
counter = 0
format = "%I:%M:%S%p"
offset = -5

function GetTime()
    return os.date(format, os.time() + offset * 60 * 60)
end

function GetName()
    time = GetTime()
    return prefix..time..postfix
end

function Main()
    name = GetName()
    VH:RegBot(name, class, description, speed, email, share)
end

function VH_OnTimer()
    counter = counter + 1

    if counter > interval then
        counter = 0
        old = name
        name = GetName()

        if not (name == old) then
            VH:UnRegBot(old)
            VH:RegBot(name, class, description, speed, email, share)
        end
    end
end

function UnLoad()
    VH:UnRegBot(name)
end