And the last script
-- This script is converted with PtokaX LUA API Converter v0.9 at 03/04/08 09:33:25
--[[
User Log 1.0 LUA 5.0/5.11
By Mutor 08/19/06
Перевод:
By NRJ 08/21/06
User Log Помощь по командам
Команда Описание
????????????????????????????????????????
+check Проверить лог юзера...
+listlog Посмотреть User Log
+loghelp Помощь по командам
????????????????????????????????????????
]]
LogCfg = {
-- Бот возьмет имя с хаба или же вы зададите емус свое имя?
Bot = SetMan.GetString(21),
-- Назание хаба
Hub = SetMan.GetString(0),
-- Будет ли у бота ключик
BotIsOp = 1,
-- Описание бота
BotDesc = "User Log",
-- Email бота
BotMail = "user@domain.com",
-- В каком файле все будет храниться
File = "UserLog.txt",
-- Название менюшки
SubMenu = "Лог юзеров",
-- Ник админа для статуc-сообщений и сообщениях об ошибках
OpNick = "NRJ",
-- Уровень доступа к командам
--[профиль#] = {0/1 (0=Команды/меню отключено / 1=Команды/меню включено),"Название профиля"},
Profiles = {
[-1] = {0,"Незарегистрированный пользователь"},
[0] = {1,"Мастер"},
[1] = {1,"Оператор"},
[2] = {0,"VIP"},
[3] = {0,"Зарегестрированный пользователь"},
[4] = {1,"Moderator"}, --для RoboCop'a
[5] = {1,"NetFounder"}, --для RoboCop'a
},
-- Таблица логов
UserLog = {},
}
OnStartup = function()
gc,no = nil,table.getn
if _VERSION == "Lua 5.1" then
gc,no = "collect",table.maxn
end
if loadfile(LogCfg.File) then
dofile(LogCfg.File)
else
for i,v in ipairs(Core.GetOnlineUsers(true)) do
user = GetItemByName(v.sNick)
Log(user)
end
Save_File(LogCfg.File,LogCfg,"LogCfg")
end
if LogCfg.Bot ~= SetMan.GetString(21) or
LogCfg.Bot == SetMan.GetString(21) and not (SetMan.GetBool(17) and 1 or 0) then
Core.RegBot(LogCfg.Bot,LogCfg.BotDesc,LogCfg.BotMail,false)
end
collectgarbage(gc)
OnError("User Log 1.0 LUA версии ".._VERSION.." от Mutor'a стартовал. Задействовано памяти: "..collectgarbage(count).." Кб.")
end
OnExit = function()
OnError("User Log 1.0 LUA версии ".._VERSION.." от Mutor'a остановлен.")
--Save_File(LogCfg.File,LogCfg,"LogCfg")
end
OnError = function(msg)
Core.SendToNick(LogCfg.OpNick,"<"..LogCfg.Bot.."> "..msg)
end
function NewUserConnected(user, data)
Log(user)
if LogCfg.Profiles[user.iProfile] and LogCfg.Profiles[user.iProfile][1] == 1 then
SendLogCmds(user)
Core.SendToNick(user.sNick,"<"..LogCfg.Bot.."> Добро пожаловать, "..user.sNick..", "..(ProfMan.GetProfile(user.iProfile) and ProfMan.GetProfile(user.iProfile).sProfileName)..
"'s User Log команды доступны нажатием правой кнопки мыши на любого пользователя.")
end
end
OpConnected = UserConnected
ChatArrival = function(user,data)
Core.GetUserAllData(user)
data = string.sub(data,1,-2)
if LogCfg.Profiles[user.iProfile] and LogCfg.Profiles[user.iProfile][1] == 1 then
local s,e,cmd = string.find( data, "%b<>%s%p(%w+)")
local s,e,to = string.find(data,"^$To:%s(%S+)%sFrom:")
if cmd and LogCmds[cmd] then
if to and to == LogCfg.Bot then
Core.SendPmToNick(user.sNick,LogCfg.Bot,LogCmds[cmd](user,data))
else
Core.SendToNick(user.sNick,"<"..LogCfg.Bot.."> "..LogCmds[cmd](user,data))
end
collectgarbage(gc)
return true
end
end
end
ToArrival = ChatArrival
Log = function(user)
local nick,profile,time,exists = user.sNick,(ProfMan.GetProfile(user.iProfile) and ProfMan.GetProfile(user.iProfile).sProfileName) or "Unregistered User",os.date("*t"),nil
for i,v in ipairs(LogCfg.UserLog) do
if v[1] == user.sNick then
exists = true
v[2],v[3] = profile,time
break
end
end
if not exists then
local t = {nick,profile,time}
table.insert(LogCfg.UserLog,t)
end
Save_File(LogCfg.File,LogCfg,"LogCfg")
collectgarbage(gc)
end
GetLog = function(nick)
if nick then
local msg = nil
for i,v in ipairs(LogCfg.UserLog) do
if v[1] == nick then
msg = {v[1],v[2],v[3]}
break
end
end
collectgarbage(gc)
return msg
end
end
LogCmds = {
check = function(user,data)
if user then
local s,e,nick = string.find( data, "%b<>%s%p%w+%s(%S+)")
if not nick then
function getcmdprefixarray() local p = {} for i=1,#SetMan.GetString(29) do table.insert(p,SetMan.GetString(29):sub(i,i)) end end
return "Ошибка!, Используйте: "..getcmdprefixarray()[1]..
"check <ник>"
else
local msg,prof = "Пользователь: ",(ProfMan.GetProfile((RegMan.GetReg(nick) and RegMan.GetReg(nick).iProfile)) and ProfMan.GetProfile((RegMan.GetReg(nick) and RegMan.GetReg(nick).iProfile)).sProfileName) or "Unregistered"
local usr,on = GetItemByName(nick)," в оффлайне"
if GetLog(nick) then
local t = GetLog(nick)
if usr then
on = "онлайн"
end
msg = msg..t[1]..". Последнее появление на хабе: "..
t[3]["day"].."."..t[3]["month"].."."..t[3]["year"]..
" - "..t[3]["hour"]..":"..t[3]["min"].." В данный момент "..on
else
msg = msg..nick.." имеет профиль "..prof.." и не существует в логе "..
"and is currently "..on
end
return msg
end
else
return "Проверить лог юзера..."," %[line:Ник]"," %[nick]"
end
end,
listlog = function(user,data)
if user then
local reply = "Список User Log\r\n\r\n\tUser\t\t\tПосл. посещение\t\tСтатус\r\n"..
"\t????????????????????????????????????????????????????????????\r\n"
for i,v in ipairs(LogCfg.UserLog) do
local usr,on = GetItemByName(v[1]),"- Оффлайн -"
if usr then
on = "+ Онлайн +"
end
reply = reply.."\t"..string.format("%-30s",v[1]).."\t"..
string.format("%-16s",v[3]["day"].."."..v[3]["month"].."."..v[3]["year"]..
" - "..v[3]["hour"]..":"..v[3]["min"]).."\t\t"..on.."\r\n"
end
return reply.."\n\t????????????????????????????????????????????????????????????\r\n\r\n"
else
return "Показать лог юзера","",""
end
end,
loghelp = function(user,data)
if user then
local reply = "User Log Помощь по командам\r\n\r\n\tКоманда\t\tОписание\r\n"..
"\t????????????????????????????????????????\r\n"
for i,v in pairs(LogCmds) do
local desc,args = LogCmds[i]()
reply = reply.."\t+"..string.format("%-15s",i).."\t"..desc.."\r\n"
end
return reply.."\n\t????????????????????????????????????????\r\n\r\n"
else
return "Помощь по командам","",""
end
end,
}
SendLogCmds = function(user)
for i,v in pairs(LogCmds) do
local desc,arg1,arg2 = LogCmds[i]()
Core.SendToNick(user.sNick,"$UserCommand 1 1 "..LogCfg.SubMenu.."\\"..
desc.."$<%[mynick]> +"..i..arg1.."|")
Core.SendToNick(user.sNick,"$UserCommand 1 2 "..LogCfg.SubMenu.."\\"..
desc.."$$To: "..LogCfg.Bot.." From: %[mynick] $<%[mynick]> +"..i..arg2.."|")
collectgarbage(gc)
end
end
Save_Serialize = function(tTable, sTableName, hFile, sTab)
sTab = sTab or ""
hFile:write(sTab..sTableName.." = {\n" )
for key, value in pairs(tTable) do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key)
if(type(value) == "table") then
Save_Serialize(value, sKey, hFile, sTab.."\t")
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value)
hFile:write( sTab.."\t"..sKey.." = "..sValue)
end
hFile:write( ",\n")
end
hFile:write( sTab.."}")
end
Save_File = function(file,table, tablename )
local hFile = io.open (file , "wb")
Save_Serialize(table, tablename, hFile)
io.flush()
hFile:close()
collectgarbage(gc)
end
RegConnected = UserConnected