Code: Select all
--[[
etc_motd.lua v0.04 by ATAG
- this script sends a message stored in a file to connecting users
- this version allows replacing of variables:
%[nick] - user nick
%[ip] - user IP
%[desc] - user description
%[email] - user e-mail address
%[share] - user share
%[slots] - user slots
%[class] - user class (based on script levels)
%[hubname] - name of the hub
%[users] - online users
based on etc_motd.lua v0.03 by blastbeat
]]--
--// settings begin //--
local motd = [[Üdv a %[hubname] hubon. Online felhasználók: %[users]
Ha megtetszett a hub, felveheted a kedvencek közé a /fav paranccsal.
!help - Segítség
!rules - Szabályzat
!faq - Gyakran Ismérelt Kérdések (Gy.I.K)
A hub biztonságos címen is elérhető: adcs://finalstage.no-ip.org:19177
Információid:
Név: %[nick]
Class: %[class]
Megosztás: %[share]
Slotok: %[slots]
IP: %[ip]
]]
--// settings end //--
local cfg_get = cfg.get
local hub_getbot = hub.getbot
local hub_getusers = hub.getusers
local hub_escapefrom = hub.escapefrom
local string_format = string.format
local online = 0
local getusers = function( )
online = 0
for i in pairs( hub_getusers( ) ) do
online = online + 1
end
end
local function getclass( level )
local tClass = {
[0] = "Unreg",
[10] = "Guest",
[20] = "Reg",
[30] = "VIP",
[40] = "SVIP",
[60] = "Operator",
[80] = "Admin",
[100] = "Owner"
}
return tClass[ level ] or tClass[0]
end
local size = function( int )
local t, i = { "B", "KB", "MB", "GB", "TB", "PB" }, 1
while i < #t and int >= 1024 do
int = int / 1024
i = i + 1
end
return string_format( "%.2f", int ) .. " " .. t[ i ]
end
local tReplace = {
["%[nick]"] = function( user ) return hub_escapefrom( user:nick( ) ) end,
["%[ip]"] = function( user ) return user:ip( ) end,
["%[desc]"] = function( user ) return user:description( ) or "" end,
["%[email]"] = function( user ) return user:email( ) or "" end,
["%[share]"] = function( user ) return size( user:share( ) ) end,
["%[slots]"] = function( user ) return user:slots( ) end,
["%[class]"] = function( user ) return getclass( user:level( ) ) end,
["%[hubname]"] = function( ) return cfg_get( "hub_name" ) end,
["%[users]"] = function( ) return online end
}
hub.setlistener( "onLogin", { },
function( user )
local msg = motd:gsub( "(%%%b[])", function( s ) return tReplace[ s ] and tReplace[ s ]( user ) or s end )
user:reply( msg, hub_getbot( ) )
return nil
end
)
hub.setlistener( "onTimer", { },
function( )
getusers( )
return nil
end
)
hub.debug( "** Loaded etc_motd.lua **" )