--[[ 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 = frmHub:GetHubBotName(), -- Назание хаба Hub = frmHub:GetHubName(), -- Будет ли у бота ключик 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 = {}, } Main = 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(frmHub:GetOnlineUsers()) do user = GetItemByName(v.sName) Log(user) end Save_File(LogCfg.File,LogCfg,"LogCfg") end if LogCfg.Bot ~= frmHub:GetHubBotName() or LogCfg.Bot == frmHub:GetHubBotName() and not frmHub:GetHubBot() then frmHub:RegBot(LogCfg.Bot, LogCfg.BotIsOp, LogCfg.BotDesc, LogCfg.BotMail) end collectgarbage(gc) OnError("User Log 1.0 LUA версии ".._VERSION.." от Mutor'a стартовал. Задействовано памяти: "..gcinfo().." Кб.") end OnExit = function() OnError("User Log 1.0 LUA версии ".._VERSION.." от Mutor'a остановлен.") --Save_File(LogCfg.File,LogCfg,"LogCfg") end OnError = function(msg) 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) user:SendData(LogCfg.Bot,"Добро пожаловать, "..user.sName..", "..GetProfileName(user.iProfile).. "'s User Log команды доступны нажатием правой кнопки мыши на любого пользователя.") end end OpConnected = NewUserConnected ChatArrival = function(user, data) 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 user:SendPM(LogCfg.Bot,LogCmds[cmd](user,data)) else user:SendData(LogCfg.Bot,LogCmds[cmd](user,data)) end collectgarbage(gc) return 1 end end end ToArrival = ChatArrival Log = function(user) local nick,profile,time,exists = user.sName,GetProfileName(user.iProfile) or "Unregistered User",os.date("*t"),nil for i,v in ipairs(LogCfg.UserLog) do if v[1] == user.sName 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 return "Ошибка!, Используйте: "..frmHub:GetPrefixes()[1].. "check <ник>" else local msg,prof = "Пользователь: ",GetProfileName(GetUserProfile(nick)) 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]() user:SendData("$UserCommand 1 1 "..LogCfg.SubMenu.."\\".. desc.."$<%[mynick]> +"..i..arg1.."|") user:SendData("$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