READ THE RULES
0 Members and 1 Guest are viewing this topic.
-- auto/manual registered user cleaner if user hasn't been in the hub for x weeks-- made by plop-- julian day function made by the guru tezlo-- code stripped from artificial insanety bot-- !noclean add/remove - adds/removes users from/to the list which aren't cleaned-- !showusers - shows all registered users-- !seen - shows the last time the user left the hub-- !shownoclean - shows all names wich are on the noclean list-- !cleanusers - manualy start the usercleaner-- a folder named userinfo is needed for this bot 2 work--------------------------------------------------------------------- configWEEKS = 4 -- every1 older then x weeks is deletedBot = "The_Cleaner"AUTO = 1 -- use 1 for automode, 0 for manualCleanLevels = {[3]=1,[4]=1,[5]=1} -- levels it needs 2 clean--------------------------------------------------------------------- the needed tablesUsersTable = {}Seen = {}NoClean = {}--------------------------------------------------------------------- julian day function 2 calcute the time users spend in the hubfunction jdate(d, m, y) local a, b, c = 0, 0, 0 if m <= 2 then y = y - 1 m = m + 12 end if (y*10000 + m*100 + d) >= 15821015 then a = floor(y/100) b = 2 - a + floor(a/4) end if y <= 0 then c = 0.75 end return floor(365.25*y - c) + floor(30.6001*(m+1) + d + 1720994 + b)end--------------------------------------------------------------------- loading the last seen databasefunction LoadLastSeen() readfrom("userinfo/lastseen.lst") while 1 do local line = read() if line == nil then break end local s,e,name,date = strfind(line, "(.+)$(.+)") if name ~= nil then Seen[name]=date end end readfrom()end--------------------------------------------------------------------- saving last seen datefunction SaveSeen() writeto("userinfo/lastseen.lst") for a,b in Seen do Seen[a]=b write(a.."$"..b.."\n") end writeto()end--------------------------------------------------------------------- call the garbage manfunction Clear() collectgarbage() flush() end--------------------------------------------------------------------- opening the registered users file from ptokax and inserting the users into the tablefunction OpenRegisterdUsersFile() readfrom("../RegisteredUsers.dat") UsersTable = nil Clear() UsersTable = {} while 1 do local line = read() local name, level if line == nil then readfrom() break end s,e,name,level = strfind(line,"(.+)|.+|(.+)") if CleanLevels[tonumber(level)] then UsersTable[name] = 1 end end end--------------------------------------------------------------------- extracting the time/date when a user was last seen from the databasefunction SeenUser(user, data) s,e,who = strfind(data, "%b<>%s%S+%s(.+)") if who == nil then user:SendPM(Bot, "Syntax error, can't read your mind, pls tell me wich user you wanne check|") elseif Seen[who] then user:SendPM(Bot, who.." was last seen on: "..Seen[who].."|") else user:SendPM(Bot, who.." is a unknown user|") endend--------------------------------------------------------------------- shows all the nicks of all registered usersfunction NewShowUsers(user) local lines = {} local info = "\r\n\r\n" info = info.." Here are the registered users\r\n" info = info.."=====================================\r\n" for a,b in UsersTable do tinsert(lines, a) end sort(lines) for i=1,getn(lines) do info = info.." "..lines[i].."\r\n" end info = info.."=====================================\r\n" user:SendPM(Bot, info.." |") Clear()end--------------------------------------------------------------------- shows all the nicks on the no clean listfunction ShowNoClean(user) local lines = {} local info = "\r\n\r\n" info = info.." Here are the users who aren't cleaned\r\n" info = info.."=====================================\r\n" for a,b in NoClean do tinsert(lines, a) end sort(lines) for i=1,getn(lines) do info = info.." "..lines[i].."\r\n" end info = info.."=====================================\r\n" user:SendPM(Bot, info.." |") Clear()end--------------------------------------------------------------------- cleanup old usersfunction CleanUsers() SendToAll(Bot, "The cleaner has been called. Every registered user who hasn't been in the hub for "..WEEKS.." weeks will be deleted. (contact the OP's if your gone be away for a period longer then that)|") OpenRegisterdUsersFile() local s,e,month,day,year = strfind(date("%x"), "(%d+)%/(%d+)%/(%d+)") year = "20"..year local juliannow = jdate(tonumber(day), tonumber(month), tonumber(year)) local oldest = WEEKS*7 local Count2,Count = 0,0 for a,b in UsersTable do Count = Count+1 if Seen[a] then if NoClean[a]== nil then local s,e,monthu,dayu,yearu = strfind(Seen[a], "(%d+)%/(%d+)%/(%d+)") yearu = "20"..yearu local julianu = jdate(tonumber(dayu), tonumber(monthu), tonumber(yearu)) if (juliannow - julianu) > oldest then Count2 = Count2 +1 Seen[a] = nil DelRegUser(a) end end else Seen[a] = date("%x") end end if Count ~= 0 then SendToAll(Bot, Count.." users were procest, "..Count2.." of them were deleted.|") end SaveSeen() OpenRegisterdUsersFile()end--------------------------------------------------------------------- don't clean this users adding/removingfunction NoCleanUser(user, data) local s,e,who, addrem = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(%S+)%s*") if (who or addrem) == nil then user:SendData(Bot, "RTFM ;). it's !noclean |") elseif UsersTable[who] then if addrem == "add" then if NoClean[who] then user:SendData(Bot, who.." is allready on the imune list.|") else NoClean[who] = 1 user:SendData(Bot, who.." is added to the imune list and won't be cleaned.|") SaveNoClean() end elseif addrem == "remove" then if NoClean[who] then NoClean[who] = nil user:SendData(Bot, who.." is removed from the imune list.|") SaveNoClean() else user:SendData(Bot, who.." was not on the imune list.|") end else user:SendData(Bot, "RTFM ;). it's !noclean |") end else user:SendData(Bot, who.." isn't a registered user.|") endend--------------------------------------------------------------------- save no clean users 2 filefunction SaveNoClean() writeto("userinfo/noclean.lst") for a,b in NoClean do write(a.."\n") end writeto()end--------------------------------------------------------------------- load no clean users from filefunction LoadNoClean() readfrom("userinfo/noclean.lst") while 1 do local line = read() if line == nil then readfrom() break end NoClean[line] = 1 end end--------------------------------------------------------------------- do i need 2 explain this ?????function DataArrival(user, data) if AUTO == 1 then if CleanDay ~= date("%x") then -- user cleaning trigger, works as a timer without a timer CleanDay = date("%x") CleanUsers() end end if( strsub(data, 1, 1) == "<" ) then if user.bOperator then data=strsub(data,1,strlen(data)-1) s,e,cmd = strfind(data,"%b<>%s+(%S+)") if cmd == "!noclean" then NoCleanUser(user, data) return 1 elseif cmd == "!showusers" then NewShowUsers(user) return 1 elseif cmd == "!shownoclean" then ShowNoClean(user) return 1 elseif cmd == "!seen" then SeenUser(user, data) return 1 elseif cmd =="!cleanusers" then CleanUsers() return 1 end end endend--------------------------------------------------------------------- stuff done when a user/vip leavesfunction UserDisconnected(user) if UsersTable[user.sName] then Seen[user.sName]=date("%x") SaveSeen() endend--------------------------------------------------------------------- do the same stuff for op's if neededfunction OpDisconnected(user) if UsersTable[user.sName] then Seen[user.sName]=date("%x") SaveSeen() endend--------------------------------------------------------------------- stuff done on bot startupfunction Main() OpenRegisterdUsersFile() LoadNoClean() LoadLastSeen() CleanDay = date("%x")end
Originally posted by exlepra Does it work with new ptokax?
-- auto/manual registered user cleaner if user hasn't been in the hub for x weeks-- made by plop-- julian day function made by the guru tezlo-- code stripped from artificial insanety bot-- updated to LUA 5 by Pothead-- updated to PtokaX 16.09 by [_XStaTiC_] Removed the seen part sorry :) i don't use it :)-- touched by Herodes (optimisation tsunami, and added !seen again)-- thx to god for giving TimeTraveler the ability to discover those bugs.. notice the plural? :)-- Pothead changed to allow different profiles to have a different cleaning time-- !noclean add/remove - adds/removes users from/to the list which aren't cleaned-- !showusers - shows all registered users-- !seen - shows the last time the user left the hub-- !shownoclean - shows all names wich are on the noclean list-- !cleanusers - manualy start the usercleaner--------------------------------------------------------------------- the needed tables // pls dont edit anything here..cl = {}cl.sets = {}cl.levels = {}cl.user = {}cl.no = {}cl.funcs = {}--------------------------------------------------------------------- configcl.sets.bot = frmHub:GetHubBotName() -- the bot Name...cl.sets.auto = 1 -- 0:disables / 1:enables , automatic mode ( if disabled use !cleanusers to clean )cl.files = { no = "logs/NoClean.lst", user = "logs/CleanUser.lst" } -- these are the files..cl.levels = { [3]=2, [2]=24} -- levels it needs to clean 3=reg 2=vip , then = the amount of weeks to clean them in--------------------------------------------------------------------- julian day function 2 calcute the time users spend in the hubfunction cl.funcs.jdate(d, m, y) local a, b, c = 0, 0, 0 if m <= 2 then y = y - 1; m = m + 12; end if (y*10000 + m*100 + d) >= 15821015 then a = math.floor(y/100); b = 2 - a + math.floor(a/4) end if y <= 0 then c = 0.75 end return math.floor(365.25*y - c) + math.floor(30.6001*(m+1) + d + 1720994 + b)end--------------------------------------------------------------------- Load a filefunction cl.funcs.load(file) local f = io.open(file, "r") if f then for line in f:lines() do local s,e,name,date = string.find(line, "(.+)$(.+)") if name then cl.user[name] = date; end end f:close() endend--------------------------------------------------------------------- Save to filefunction cl.funcs.save(file, tbl) local f = io.open(file, "w+") for a,b in tbl do f:write(a.."$"..b.."\n") end f:close()end--------------------------------------------------------------------- call the garbage manfunction cl.funcs.cls() collectgarbage() io.flush()end--------------------------------------------------------------------- Display some tablefunction cl.funcs.showusers( user, data ) local tbl, txt; if (type(data) == "string") then local s,e,Profile = string.find(data, "%b<>%s+%S+%s+(%S+)") if not Profile then user:SendData(cl.sets.bot , "RTFM ;). It's !showusers "); return 1; end tbl = GetUsersByProfile(Profile); txt = "registered users with Profile ("..Profile..")" else local function to_array(t) local r={}; for i , v in t do table.insert(r, i); end; return r; end tbl = to_array(data) txt = "users who aren't cleaned" end local info = "\n Here are the "..txt.."\n" info = info.."=====================================\n" for i,nick in tbl do info = info.." "..nick.."\n"; end info = info.."=====================================\n" user:SendData( "$To: "..user.sName.." From: "..user.sName.." $<"..cl.sets.bot.."> "..info) cl.funcs.cls()end--------------------------------------------------------------------- cleanup old usersfunction cl.funcs.clean() local juliannow = cl.funcs.jdate(tonumber(os.date("%d")), tonumber(os.date("%m")), tonumber(os.date("%Y"))) local chkd, clnd = 0,0 local msg = "The_Cleaner has just ran." for prof, v in cl.levels do msg = msg.."\r\nEvery "..GetProfileName(prof).." user who hasn't been in the hub for "..cl.levels[prof].." weeks was deleted." local oldest = cl.levels[prof] * 7 for a, b in GetUsersByProfile(GetProfileName(prof)) do chkd = chkd + 1 if cl.user[b] then if not cl.no[b] then local s, e, month, day, year = string.find(cl.user[b], "(%d+)%/(%d+)%/(%d+)"); year = "20"..year local julian = cl.funcs.jdate( tonumber(day), tonumber(month), tonumber(year) ) if ((juliannow - julian) > oldest) then cl.user[b] = nil; DelRegUser(b); clnd = clnd + 1; end end else cl.user[b] = os.date("%x") end end end msg = msg.. "\r\n(contact the OP's if your gone be away for a period longer then that)" SendToAll(cl.sets.bot , msg) if chkd ~= 0 then SendToAll(cl.sets.bot , chkd.." users were procest, "..clnd.." of them were deleted.") else SendToAll(cl.sets.bot ,"Nobody to clean :(") end cl.funcs.save(cl.files.user, cl.user);end--------------------------------------------------------------------- don't clean this users adding/removingfunction cl.funcs.addnocl( user, data ) local s,e,who, addrem = string.find(data, "%b<>%s+%S+%s+(%S+)%s+(%S+)%s*") if who and addrem then if frmHub:isNickRegged(who) then if (addrem == "add") then if cl.no[who] then user:SendData(cl.sets.bot , who.." is allready on the imune list.") else cl.no[who] = 1 user:SendData(cl.sets.bot , who.." is added to the imune list and won't be cleaned.") cl.funcs.save(cl.files.no, cl.no) end elseif addrem == "remove" then if cl.no[who] then cl.no[who] = nil user:SendData(cl.sets.bot , who.." is removed from the imune list.") cl.funcs.save(cl.file.no, cl.no) else user:SendData(cl.sets.bot , who.." was not on the imune list.") end else user:SendData(cl.sets.bot , "RTFM ;). it's !noclean ") end else user:SendData(cl.sets.bot , who.." isn't a registered user.") end else user:SendData(cl.sets.bot , "Syntax Error, Use: !noclean ") endend--------------------------------------------------------------------- Respond to a !seenfunction cl.funcs.seen( user, data ) local s,e,who = string.find( data, "%b<>%s+%S+%s+(%S+)" ) if who then if who ~= user.sName then if not GetItemByName(who) then if cl.user[who] then user:SendData( cl.sets.bot, who.." was last seen on the "..cl.user[who]) else user:SendData( cl.sets.bot, "How should I know when "..who.." was last seen ?") end else user:SendData( cl.sets.bot, who.." is online ... open those eyes of yours..") end else user:SendData( cl.sets.bot, "aren't you that guy ?") end else user:SendData( cl.sets.bot, "Syntax Error, Use: !seen ") endend--------------------------------------------------------------------- do i need 2 explain this ?????function ChatArrival(user, data) if (cl.sets.auto == 1) then if cl.day ~= os.date("%x") then -- user cleaning trigger, works as a timer without a timer cl.day = os.date("%x") cl.funcs.clean() end end if (user.bOperator) then data = string.sub(data,1,-2) local s,e,cmd = string.find(data,"%b<>%s+(%S+)") if cmd then if (cmd == "!noclean") then cl.funcs.addnocl(user, data); return 1; elseif (cmd == "!seen") then cl.funcs.seen(user, data); return 1; elseif (cmd == "!showusers") then cl.funcs.showusers( user, data ); return 1; elseif (cmd == "!shownoclean") then cl.funcs.showusers( user, cl.no ); return 1; elseif (cmd =="!cleanusers") then cl.funcs.clean(); return 1; end end endend--------------------------------------------------------------------- stuff done when a user/vip leaves or comefunction NewUserConnected(user) if cl.user[user.sName] then cl.user[user.sName] = nil; cl.funcs.save(cl.files.user, cl.user); endendOpConnected = NewUserConnectedfunction UserDisconnected(user) if (cl.levels[user.iProfile] ~= nil) then cl.user[user.sName] = os.date("%x"); cl.funcs.save(cl.files.user, cl.user); endendOpDisconnected = UserDisconnected--------------------------------------------------------------------- stuff done on bot startupfunction Main() cl.funcs.load(cl.files.no) cl.funcs.load(cl.files.user) cl.day = os.date("%x")end
Originally posted by exlepra Thx, I will try it.