PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: NeiSep on 28 January, 2004, 20:32:01

Title: Script needed to inactive users
Post by: NeiSep on 28 January, 2004, 20:32:01
Hi i got a private DC hub is there any script that cold delete inactive users or send a pm to opchat or something that the user is inactive
Title:
Post by: SaintSinner on 28 January, 2004, 21:22:44
try this



-- 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

--------------------------------------------------------------------- config
WEEKS = 4    -- every1 older then x weeks is deleted
Bot = "The_Cleaner"
AUTO = 1   -- use 1 for automode, 0 for manual
CleanLevels = {[3]=1,[4]=1,[5]=1} -- levels it needs 2 clean

---------------------------------------------------------------------  the needed tables
UsersTable = {}
Seen = {}
NoClean = {}


--------------------------------------------------------------------- julian day function 2 calcute the time users spend in the hub
function 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 database
function 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 date
function SaveSeen()
   writeto("userinfo/lastseen.lst")
   for a,b in Seen do
      Seen[a]=b
      write(a.."$"..b.."\n")
   end
   writeto()
end

--------------------------------------------------------------------- call the garbage man
function Clear()
   collectgarbage()
   flush()
end

--------------------------------------------------------------------- opening the registered users file from ptokax and inserting the users into the table
function 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 database
function 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|")
   end
end

--------------------------------------------------------------------- shows all the nicks of all registered users
function 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 list
function 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 users
function 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/removing
function 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.|")
   end
end

--------------------------------------------------------------------- save no clean users 2 file
function SaveNoClean()
   writeto("userinfo/noclean.lst")
   for a,b in NoClean do
      write(a.."\n")
   end
   writeto()
end

--------------------------------------------------------------------- load no clean users from file
function 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
   end
end

--------------------------------------------------------------------- stuff done when a user/vip leaves
function UserDisconnected(user)
if UsersTable[user.sName] then
      Seen[user.sName]=date("%x")
      SaveSeen()
   end
end

--------------------------------------------------------------------- do the same stuff for op's if needed
function OpDisconnected(user)
if UsersTable[user.sName] then
      Seen[user.sName]=date("%x")
      SaveSeen()
   end
end

--------------------------------------------------------------------- stuff done on bot startup
function Main()
   OpenRegisterdUsersFile()
   LoadNoClean()
   LoadLastSeen()
   CleanDay = date("%x")
end




Title:
Post by: exlepra on 04 October, 2005, 18:11:04
Does  it work with new ptokax?
Title:
Post by: 6Marilyn6Manson6 on 04 October, 2005, 20:22:21
QuoteOriginally posted by exlepra
Does  it work with new ptokax?

Hi exlepra. Post of SaintSinner is in Lua4 and not work for new ptokax, you can use this:


-- 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 = {}
--------------------------------------------------------------------- config
cl.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 hub
function 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 file
function 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()
end
end
--------------------------------------------------------------------- Save to file
function 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 man
function cl.funcs.cls()
collectgarbage()
io.flush()
end
--------------------------------------------------------------------- Display some table
function 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 users
function 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/removing
function 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 ")
end
end
--------------------------------------------------------------------- Respond to a !seen
function 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 ")
end
end
--------------------------------------------------------------------- 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
end
end
--------------------------------------------------------------------- stuff done when a user/vip leaves or come
function NewUserConnected(user)
if cl.user[user.sName] then
cl.user[user.sName] = nil;
cl.funcs.save(cl.files.user, cl.user);
end
end

OpConnected = NewUserConnected

function UserDisconnected(user)
if (cl.levels[user.iProfile] ~= nil) then
cl.user[user.sName] = os.date("%x");
cl.funcs.save(cl.files.user, cl.user);
end
end

OpDisconnected = UserDisconnected
--------------------------------------------------------------------- stuff done on bot startup
function Main()
cl.funcs.load(cl.files.no)
cl.funcs.load(cl.files.user)
cl.day = os.date("%x")
end

c ya :)
Title:
Post by: exlepra on 05 October, 2005, 08:58:09
Thx, I will try it.
Title:
Post by: 6Marilyn6Manson6 on 05 October, 2005, 10:08:18
QuoteOriginally posted by exlepra
Thx, I will try it.

Welcome :)
Title:
Post by: exlepra on 07 October, 2005, 14:56:42
I have a few errors:

adding someone to noclean:

\scripts\aaccountpruner.lua:55: attempt to index local `f' (a nil value)




using !shownoclean

\scripts\aaccountpruner.lua:79: attempt to call local `info' (a nil value)

\scripts\aaccountpruner.lua:73: bad argument #1 to `insert' (table expected, got nil)
Title:
Post by: 6Marilyn6Manson6 on 07 October, 2005, 21:19:19
Post update. C ya