PtokaX forum

Archive => Archived 5.0 boards => Finished Scripts => Topic started by: Herodes on 30 March, 2005, 17:51:29

Title: Regcleaner by plop, :: PtokaX[16.09]
Post by: Herodes on 30 March, 2005, 17:51:29
okie .. this is it, core stuff done by [_XStaTiC_] ... optimisations by me ..
-- 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? :)

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

cl = {}
cl.sets = {}
--------------------------------------------------------------------- config
cl.sets.weeks = 2 -- every1 older then x weeks is deleted
cl.sets.bot = "plop" -- the bot Name...
cl.sets.auto = 1 -- 0:disables / 1:enables , automatic mode ( if disabled use !cleanusers to clean )
cl.levels = { [3]=1, [2]=1} -- levels it needs 2 clean 3=reg 2=vip
cl.files = { no = "logs/NoClean.lst", user = "logs/CleanUser.lst" } -- these are the files..
--------------------------------------------------------------------- the needed tables // pls dont edit anything here..
cl.user = {}
cl.no = {}
cl.funcs = {}

--------------------------------------------------------------------- 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()
SendToAll(cl.sets.bot , "The_Cleaner has been called. Every registered user who hasn't been in the hub for "..cl.sets.weeks.." weeks will be deleted. ")
SendToAll(cl.sets.bot , "(contact the OP's if your gone be away for a period longer then that)")
local juliannow = cl.funcs.jdate(tonumber(os.date("%d")), tonumber(os.date("%m")), tonumber(os.date("%Y")))
local oldest = cl.sets.weeks*7
local chkd, clnd = 0,0
for prof, v in cl.levels do
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
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] == 1) 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
Title:
Post by: TiMeTrAVelleR on 30 March, 2005, 18:52:38
2 thing   i used command !cleanusers

got a error
Syntax ...eaublad\-=(TrAnCe)=- Hub\scripts\New UserCleaner.lua:100: attempt to index global `CleanUser' (a nil value)

and  i see command  in main
18:48:52] The_Cleaner has been called. Every registered user who hasn't been in the hub for 2 weeks will be deleted.
[18:48:52] (contact the OP's if your gone be away for a period longer then that)
[18:48:52] <-T??--T?M??r?V?ll?R> !cleanusers


Greetzz TT
Title:
Post by: Anna on 30 March, 2005, 18:55:06
I'm pretty sure it actually does clean the users, but there's a couple things I'd like to tell..

when doin a !noclean or !cleanusers command its visible to all, I would prefere if it wasnt, can this be fixed? (the respons from bot aint seen when doin a no clean though)

When doin !shownoclean or !showreg, the sender of the pm with the info is my own nick, would prefer the bot to be sender... (botnick is shown in the pm, my nick is shown on the tab) theese dont show all what the command for it was so no users can tell I did this...

the !seen command however dont show command in main and sends back info in main from bot

edit after seeing post above: I've had thoose syntax errors as well, but not every attempt to do a !cleanusers
Title:
Post by: [_XStaTiC_] on 30 March, 2005, 19:56:28
btw Herodes thanks for optimisation tsunami  hehehe LoL
Title:
Post by: TiMeTrAVelleR on 30 March, 2005, 20:20:24
Thanks [_XStaTiC_]  that did it      works  fine now

0:18:51] The_Cleaner has been called. Every registered user who hasn't been in the hub for 2 weeks will be deleted.
[20:18:51] (contact the OP's if your gone be away for a period longer then that)
[20:18:51] 1352 users were procest, 0 of them were deleted.


Greetzzz TT
Title:
Post by: TiMeTrAVelleR on 30 March, 2005, 20:53:59
New error found  
Syntax ...eaublad\-=(TrAnCe)=- Hub\scripts\New UserCleaner.lua:134: attempt to index field `file' (a nil value)

Greetzz TT
Title:
Post by: Herodes on 30 March, 2005, 21:25:58
oki.. sry about the above errors.. and sincere thx for reporting them.. My first post has now been edited ..
Title:
Post by: TiMeTrAVelleR on 30 March, 2005, 21:32:14
Oki running  this version  i added a user  to imune list   used commands  show noclean     got this

21:29:29]
 Here are the who aren't cleaned
=====================================
  1
=====================================
number there   but no username  

Greetz  TT
Title:
Post by: Herodes on 30 March, 2005, 21:53:13
wow tt! ,... that ability of yours we have to take advantage ;)
its sorted I believe .. ( post edited once more ;)
Title:
Post by: TiMeTrAVelleR on 30 March, 2005, 22:01:35
Used command
21:58:53] <-T??--T?M??r?V?ll?R> !shownoclean

Got this now  

Syntax ...eaublad\-=(TrAnCe)=- Hub\scripts\New UserCleaner.lua:84: attempt to call local `info' (a nil value)


Greetzz TT
Title:
Post by: Herodes on 31 March, 2005, 01:31:25
sry for being a pain .. it should be ok now .. re-edited my post again
Title:
Post by: Psycho_Chihuahua on 31 March, 2005, 01:51:52
Message working fine but  when i checked the hub i got this after using "!cleanusers"

Syntax ...\scripts\regcleaner.lua:56: attempt to index local `f' (a nil value)
PtokaX Build 16.09
Title:
Post by: Nada@WTB on 31 March, 2005, 02:04:35
Thanks guys, it works great :D
Title:
Post by: Herodes on 31 March, 2005, 02:07:31
QuoteOriginally posted by Psycho_Chihuahua
Message working fine but  when i checked the hub i got this after using "!cleanusers"

Syntax ...\scripts\regcleaner.lua:56: attempt to index local `f' (a nil value)
PtokaX Build 16.09
be sure that you have a folder named 'logs' in the scripts folder ...
Title:
Post by: Psycho_Chihuahua on 31 March, 2005, 02:20:29
that was it ^^ thnx m8 running fine now
Title:
Post by: TiMeTrAVelleR on 31 March, 2005, 04:47:39
Sorry to be a pain whit using command !shownoclean   i got this

Syntax ...eaublad\-=(TrAnCe)=- Hub\scripts\New UserCleaner.lua:76: bad argument #1 to `insert' (table expected, got nil)


Greetzz TT
Title:
Post by: Cid on 31 March, 2005, 10:20:11
maybe some cosmetic changes to the messages would be nice too so that I dont have to change them myself everytime the script gets updated :P

procest... that should be "processed"
imune... that's "immune"

Except for those little typos this script is very nice and useful.

Thanks a lot to you people who make it possible to have such nice things :)
Title:
Post by: jiten on 31 March, 2005, 10:26:41
QuoteOriginally posted by Cid
maybe some cosmetic changes to the messages would be nice too so that I dont have to change them myself everytime the script gets updated :P

procest... that should be "processed"
imune... that's "immune"

Except for those little typos this script is very nice and useful.

Thanks a lot to you people who make it possible to have such nice things :)

That's would be quite simple for u just by using the Replace function in notepad...  ;)
Title:
Post by: Cid on 31 March, 2005, 11:06:48
sure. but doing it everytime when it only has to be done here once. and if you change it here... everybody will have a corrected version.
Title:
Post by: jiten on 31 March, 2005, 12:00:00
That's a point too  :]
Title:
Post by: UwV on 31 March, 2005, 12:34:03
QuoteSyntax ...eaublad\-=(TrAnCe)=- Hub\scripts\New UserCleaner.lua:76: bad argument #1 to `insert' (table expected, got nil)
i get this error too what to do ? ..


and spelling imo (if it count as any .. ;0)
.. it is a thing to keep in mind for our children....
but dont we all use our own lines anyway ? .. i know do.
Quotefrom my old version..
   info = info.."  Here are the dirty old "..CleanProfiles.."'s who aren't cleaned\r\n"
 :D

more important is the "real" bugs.. the ones that spell "syntax error" .. ;)
Title:
Post by: imby on 31 March, 2005, 16:00:57
[pedant on]

(contact the OP's if your gone be away for a period longer then that

Here's the correct grammar:

contact an Op if you're going to be away for a longer period than that

[/pedant off]
Title:
Post by: Herodes on 31 March, 2005, 16:43:10
I'll check on the error about the nil l8r today. Sry to keep you waiting ..

As far as the other 'bugs' being discussed in here, I will not change the strings in any later realeases. This is because 'its plop's words',... that meands 'holy' Looool
Title: should be final I think
Post by: Herodes on 31 March, 2005, 18:25:34
This one should be the final ;) the chances for bugs are minimal now .. if someone finds a bug he wins a custom script ;P,..
and for those that are interested, the typos are fixed too..
there you go ppl ;)
-- 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? :)
--- should be working flawlessly now. 15:18 - 31/3/2005
--- ( before you doubt the above line be sure that you have a 'logs' folder in 'scripts' folder)

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

cl = {}
cl.sets = {}
--------------------------------------------------------------------- config
cl.sets.weeks = 2 -- every1 older then x weeks is deleted
cl.sets.bot = "plop" -- the bot Name...
cl.sets.auto = 1 -- 0:disables / 1:enables , automatic mode ( if disabled use !cleanusers to clean )
cl.levels = { [3]=1, [2]=1} -- levels it needs 2 clean 3=reg 2=vip
cl.files = { no = "logs/NoClean.lst", user = "logs/CleanUser.lst" } -- these are the files..
--------------------------------------------------------------------- the needed tables // pls dont edit anything here..
cl.user = {}
cl.no = {}
cl.funcs = {}

--------------------------------------------------------------------- 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, tbl)
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 tbl[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, sep = {}, "users who aren't cleaned", string.rep("=", 40);
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 , "Syntax Error, Use: !showusers "); return 1; end
tbl = GetUsersByProfile(Profile); txt = "registered users with Profile ("..Profile..")";
else
local c=1; for i,v in data do tbl[c] = i; c=c+1;end;
end
local c = table.getn(tbl);
if (c > 0) then
local info = "\r\n Here are the "..txt.."\r\n "..sep.."\r\n"
for i=1,c do info = info.."   ? "..tbl[i].."\r\n "; end
user:SendData( "$To: "..user.sName.." From: "..user.sName.." $<"..cl.sets.bot.."> "..info..sep.."\r\n");
cl.funcs.cls();return 1;
end
user:SendData( cl.sets.bot, "There are no "..txt);cl.funcs.cls();return 1;
end


--------------------------------------------------------------------- cleanup old users
function cl.funcs.clean()
SendToAll(cl.sets.bot , "The Cleaner has been called. Every registered user who hasn't been in the hub for "..cl.sets.weeks.." weeks will be deleted. ")
SendToAll(cl.sets.bot , "(contact an Operator if you are going to be away for a longer period than that)")
local juliannow = cl.funcs.jdate(tonumber(os.date("%d")), tonumber(os.date("%m")), tonumber(os.date("%Y")))
local oldest, chkd, clnd,x = (cl.sets.weeks*7),0,0,os.clock()
for prof, v in cl.levels do
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+)");
local julian = cl.funcs.jdate( tonumber(day), tonumber(month), tonumber("20"..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
cl.funcs.save(cl.files.user, cl.user);
if (chkd > 0) then SendToAll(cl.sets.bot , chkd.." users were processed, "..clnd.." were deleted ( "..string.format("%0.2f",((clnd*100)/chkd)).."% ) in: "..string.format("%0.4f", os.clock()-x ).." seconds.");return 1; end;
SendToAll(cl.sets.bot ,"Nobody to clean :(");return 1;
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 already on the immune list.");return 1; end;
cl.no[who] = 1; cl.funcs.save(cl.files.no, cl.no);
user:SendData(cl.sets.bot , who.." is added to the immune list and won't be cleaned.");return 1;
elseif addrem == "remove" then
if not cl.no[who] then user:SendData(cl.sets.bot , who.." was not on the immune list.");return 1; end
cl.no[who] = nil; cl.funcs.save(cl.files.no, cl.no);
user:SendData(cl.sets.bot , who.." is removed from the immune list.");return 1;
end; user:SendData(cl.sets.bot , "Syntax Error, Use: !noclean ");return 1;
end; user:SendData(cl.sets.bot , who.." isn't a registered user.");return 1;
end; user:SendData(cl.sets.bot , "Syntax Error, Use: !noclean ");return 1;
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]);return 1; end
user:SendData( cl.sets.bot, "How should I know when "..who.." was last seen ?");return 1;
end; user:SendData( cl.sets.bot, who.." is online... open those eyes of yours..");return 1;
end; user:SendData( cl.sets.bot, "aren't you that guy?");return 1;
end; user:SendData( cl.sets.bot, "Syntax Error, Use: !seen ");return 1;
end
--------------------------------------------------------------------- do i need 2 explain this ?????
function ChatArrival(user, data)
if ( (cl.sets.auto == 1) and (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
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 return cl.funcs.addnocl(user, data);
elseif (cmd == "!seen") then return cl.funcs.seen(user, data);
elseif (cmd == "!showusers") then return cl.funcs.showusers( user, data );
elseif (cmd == "!shownoclean") then return cl.funcs.showusers( user, cl.no );
elseif (cmd =="!cleanusers") then return cl.funcs.clean();
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] == 1) 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.no);
cl.funcs.load(cl.files.user, cl.user);
cl.day = os.date("%x")
end
Title:
Post by: Pothead on 31 March, 2005, 18:47:20
Probably makes no difference, but wouldn't it be better to have :
io.flush() before collectgarbage() instead of after it ?
Title:
Post by: Cid on 31 March, 2005, 19:30:25
Awww:)
Very cool and appreciated!
Thanx a lot.
Title:
Post by: TiMeTrAVelleR on 31 March, 2005, 19:37:44
Seems to work just fine  ;)

Greetzz TT
Title:
Post by: UwV on 31 March, 2005, 22:55:02
yup works fine indeed :0)

damn.. ;0)
i wanted that customscript ..  hehe
well i'll just request a feature for future releases .. (did i spell that right ?)..
if not too much trouble can we have different cleaning times for different userlevels ? would be very neat ..
Title:
Post by: Herodes on 01 April, 2005, 00:06:28
QuoteOriginally posted by Pothead
Probably makes no difference, but wouldn't it be better to have :
io.flush() before collectgarbage() instead of after it ?
read the docs. :) It is the same thing. The collectgarbage() is forcing the garbage-collection ( that means all dead objects in memory are gone ) and the second is flushing-throwing_n_deleting from mem away any data in the standard ouput,
Title: not worth it ..
Post by: UwV on 01 April, 2005, 00:16:03
found one .. but .. not worth claiming the prize over really .. ;0)

scenario is like this ..

new user regs him/herself...
or gets regged ..
user logs off ..  user does not log in again ..
user will not be cleaned.

in my situation just a litle annoying .. i have a selfreg script running.. and users "forget" to read the rules before registering themselves .. i.e. the are not allowed back in afte regging a lot of the time ..
Title:
Post by: ??????Hawk?????? on 01 April, 2005, 00:30:36
QuoteOriginally posted by UwV
found one .. but .. not worth claiming the prize over really .. ;0)

scenario is like this ..

new user regs him/herself...
or gets regged ..
user logs off ..  user does not log in again ..
user will not be cleaned.

in my situation just a litle annoying .. i have a selfreg script running.. and users "forget" to read the rules before registering themselves .. i.e. the are not allowed back in afte regging a lot of the time ..


The list is updated directly from the HUB's  Registered users list   so it should still get them ..  

??????Hawk??????
Title:
Post by: Herodes on 01 April, 2005, 00:35:13
QuoteOriginally posted by UwV
new user regs him/herself...
or gets regged ..
user logs off ..  user does not log in again ..
user will not be cleaned.
as you said,.. It is not a bug,.. the objective of the scirpt is very precise... it says in the initial comments. ;)
Title:
Post by: UwV on 01 April, 2005, 01:09:28
QuoteOriginally posted by ??????Hawk??????

The list is updated directly from the HUB's  Registered users list   so it should still get them ..  

??????Hawk??????

sure but only after a full reboot (when does ptokax updatethe regusers i am not sure actually..?)..
in the "ideal" situation ...  a hub is up longer then the time set as max. awaytime and so would this script be (so it would not reload them anyway)....

and as i said .. its not a bug ..

but my testuser has not been seen .. has not been logged and threfore would not been cleaned unless i restart he script.. that's all there was to it.
Title:
Post by: Cid on 01 April, 2005, 10:28:39
all newly regged users will get on the list the next time the users are cleaned manually or automatically. at least in the versions before it was like that.
Title:
Post by: Yorkie on 01 April, 2005, 22:13:14
Hi all
Can someone tell me why i get this?

Syntax [string "code:
..."]:38: function arguments expected near `='


Cheers
Title:
Post by: Herodes on 01 April, 2005, 22:29:05
QuoteOriginally posted by Yorkie
Hi all
Can someone tell me why i get this?

Syntax [string "code:
..."]:38: function arguments expected near `='
I think you grabbed the code in a bad way. try copy pasting again ..
Title:
Post by: Yorkie on 02 April, 2005, 01:38:05
Yep that sorted it.lol
copied too much and didn't notice.

Cheers
Title:
Post by: Herodes on 02 April, 2005, 01:45:31
QuoteOriginally posted by Yorkie
Yep that sorted it.lol
copied too much and didn't notice.

Cheers
you are welcome,...
Tip2All: The best way to copy a script from a thread is by hitting the 'quote' button on the specific post and then select just after the [ code] until just before the [/code ]
That way, you will have the script as the author has posted it. This helps when reporting errors,... I have noticed many error reports like: (example for a script with 50 lines)
Syntax Error line 80: ...

This is due to the way the board is display code. ( it inserts an empty line after each code line. )
Title:
Post by: bastya_elvtars on 02 April, 2005, 02:49:01
Or paste to editplus, hit CTRL+A then CTRL+SHIFT+J. :)
Title:
Post by: Optimus on 09 April, 2005, 13:07:31
GetRegisterdUsers = function()
if CleanerTable.tBigTable.Enable == 1 then
for id,who in frmHub:GetRegisteredUsers() do
if tCleanProfiles[who.iProfile] then
if tBigTable[who.sNick] == nil then
tBigTable[who.sNick] = { ["Leave"] = os.date("%c") }
end
end
end
end saveTableToFile(bigtablefile, tBigTable, "tBigTable")
end
Nice trick that can be used for usercleaner only works for PtokaX 16.09a and above

- Optimus
Title: BUG?
Post by: Honey on 30 July, 2005, 11:31:37
Hello guys,

 I use this super script! :)

But I have problem, PtokaX write this in Script Editor:[11:26] Syntax scripts\Regcleaner.lua:127: attempt to index local `f' (a nil value)

in this line in the script:
for a,b in tbl do f:write(a.."$"..b.."\n"); end; f:close()
What is wrong?

 Thank you in advance for help!
Title:
Post by: James on 30 July, 2005, 11:50:54
[11:56] No syntax errors in script file topic.lua
[11:56] No syntax errors in script file regcleaner.lua


use PtokaX 0.3.3.1  :))

PS. Maybe is your PtokaX to old.
Title:
Post by: Honey on 30 July, 2005, 12:09:05
I use PtokaX 0.3.3.1 too :))

So if I start PtokaX: [12:02] No syntax errors in script file regcleaner.lua
But for some time running hub, will be occurs this problem:
[12:08] Syntax scripts\Regcleaner.lua:127: attempt to index local `f ' (a nil value)
[12:09] Syntax scripts\Regcleaner.lua:127: attempt to index local `f ' (a nil value)
[12:11] Syntax scripts\Regcleaner.lua:127: attempt to index local `f ' (a nil value)
[12:14] Syntax scripts\Regcleaner.lua:127: attempt to index local `f ' (a nil value)
:(

Edit:
Please, can anybody help me?
I want use this script! But I don't know, what is wrong in line 127 :(
Title:
Post by: TiMeTrAVelleR on 03 August, 2005, 00:40:04
Same prob here happens  when usercleaner is called

greetzz TT
Title:
Post by: TiMeTrAVelleR on 03 August, 2005, 23:32:56
nobody ?
Title:
Post by: Dessamator on 04 August, 2005, 01:06:01
ill have a look at it tomorrow
Title:
Post by: TiMeTrAVelleR on 04 August, 2005, 09:14:49
I am so stupid  sorry to bother you all  working on a differnt script what has nog  folder called logs

you guess it  that was the prob  dident think of that  thought it went to loggs   from root ptokax

thanks aniway mutor and Dessamator



greetzzz  TT







stupid stupid me  ;(
Title:
Post by: Dessamator on 04 August, 2005, 10:24:11
ur welcome
Title:
Post by: Pothead on 28 September, 2005, 16:52:37
QuoteOriginally posted by T?M??r?V?ll?R
you guess it  that was the prob  dident think of that  thought it went to loggs   from root ptokax
hehe, when i originally updated it to LUA 5 i did move the the files to the PtokaX\logs directory.  Someone else changed it back.  :(
Anyway, little update for the script.  You can now have a different cleaning schedule for different profiles.
-- 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

*** Edited script, to include bastya_elvtars fix, a few posts down ***
Title:
Post by: exlepra on 07 October, 2005, 21:04:17
I still have this error with !shownoclean

scripts\usercleaner.lua:73: bad argument #1 to `insert' (table expected, got nil)

the NoClean.lst isnt empty, I can see the names with a text editor.
Title:
Post by: bastya_elvtars on 07 October, 2005, 21:06:35
Maybe you wanna change
local function to_array(t) local r; for i , v in t do table.insert(r, i); end; return r; end
to

local function to_array(t) local r={}; for i , v in t do table.insert(r, i); end; return r; end
?
Title:
Post by: exlepra on 08 October, 2005, 09:55:59
Better now, thank you.


If I restart the scripts/hub the !shownoclean shows no users even if the noclean.lst isnt empty.

EDIT:

now I have this for !cleanusers command

\usercleaner.lua:97: attempt to concatenate local `year' (a nil value)
Title:
Post by: exlepra on 02 November, 2005, 18:32:36
Any idea?