RegCleaner
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

RegCleaner

Started by Andoz, 26 April, 2005, 21:56:38

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andoz

--------------------------------------------------------------------- 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 then
               if not cl.no then
                  local s, e, month, day, year = string.find(cl.user, "(%d+)%/(%d+)%/(%d+)");
                  local julian = cl.funcs.jdate( tonumber(day), tonumber(month), tonumber("20"..year) )
                  if ((juliannow - julian) > oldest) then cl.user = nil; DelRegUser(b); clnd = clnd + 1; end;
               end
         else cl.user = 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
--------------------------------------------------------
Is it possible to fix that this scripts send PM to specified user or in mainchatt witch users that has ben delregged?
I hade that before in old lua4
[ADSL]-HALMSTAD-[BBB]
            andoz.no-ip.com:6969

Dessamator

function cl.funcs.clean() 
local delnicks = "These are the deleted users".."\r\n"
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 
					delnicks=delnicks..b.sName.."\r\n"
					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; 
SendToAll(delnicks)
end
 
done!(untested)
that should work, ;)
Ignorance is Bliss.

Andoz

--------------------------------
done!(untested)
that should work, ;)
--------------------------------

Syntax ...z\Skrivbord\Hubgrejs\Hubbar ig?ng\Nya Ptokax ? RC\scripts\RegCleaner.lua:110: `end' expected (to close `function' at line 86) near `SendToAll'

No get error :(
[ADSL]-HALMSTAD-[BBB]
            andoz.no-ip.com:6969

jiten

Maybe this:
function cl.funcs.clean() 
	local delnicks = "These are the deleted users".."\r\n"
	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 
						delnicks=delnicks..b.sName.."\r\n"
						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; 
	if clnd == nil then
		SendToAll(cl.sets.bot ,"Nobody to clean :(");
	else
		SendToAll(delnicks);
	end
	return 1;
end
Cheers

Dessamator

hmm yah, might work, but its hard to do without seeing the entire script,
Ignorance is Bliss.

Psycho_Chihuahua

using the above...
-- 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 = 1 -- every1 older then x weeks is deleted
cl.sets.bot = "Helvetia" -- 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, Verwende: !showusers "); return 1; end
		tbl = GetUsersByProfile(Profile); txt = "registrierte user mit 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 Dies sind die "..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, "Es gibt keine "..txt);cl.funcs.cls();return 1;
end


--------------------------------------------------------------------- cleanup old users
function cl.funcs.clean() 
	local delnicks = "These are the deleted users".."\r\n"
	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 
						delnicks=delnicks..b.sName.."\r\n"
						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; 
	if clnd == nil then
		SendToAll(cl.sets.bot ,"Nobody to clean :(");
	else
		SendToAll(delnicks);
	end
	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.." ist bereits auf der Immunliste.");return 1; end;
				cl.no[who] = 1; cl.funcs.save(cl.files.no, cl.no);
				user:SendData(cl.sets.bot , who.." wurde der Immunliste hinzugef?gt und wird nicht gel?scht.");return 1;
			elseif addrem == "remove" then
				if not cl.no[who] then user:SendData(cl.sets.bot , who.." war nicht in der Immunlist.");return 1; end
				cl.no[who] = nil; cl.funcs.save(cl.files.no, cl.no);
				user:SendData(cl.sets.bot , who.." wurde von der Immunlist gel?scht.");return 1;
			end; user:SendData(cl.sets.bot , "Syntax Error, Verwende: !noclean  ");return 1;
		end; user:SendData(cl.sets.bot , who.." ist kein registrierter User.");return 1;
	end; user:SendData(cl.sets.bot , "Syntax Error, Verwende: !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.." war zuletzt hier am "..cl.user[who]);return 1; end
				user:SendData( cl.sets.bot, "Woher soll ich wissen wann "..who.." zuletzt hier war ?");return 1;
			end; user:SendData( cl.sets.bot, who.." ist Online... ?ffne deine Augen..");return 1;
		end; user:SendData( cl.sets.bot, "bist nicht DU dieser User?");return 1;
	end; user:SendData( cl.sets.bot, "Syntax Error, Verwende: !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

works fine as long as it doesnt need to delete anyone- But if there r Users to delete then this is givin out
...scripts\regcleaner.lua:100: attempt to index local `b' (a string value)
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

jiten

#6
Try this one then:
function cl.funcs.clean() 
	local delnicks = "These are the deleted users:".."\r\n"
	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 
						delnicks=delnicks..b..", "
						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.");
		if clnd ~= 0 then
			SendToAll(cl.sets.bot,delnicks);
		end
		return 1;
	end; 
	SendToAll(cl.sets.bot ,"Nobody to clean :(");
	return 1;
end

*EDIT* Now sends deleted nicks like: nick1, nick2 ...
Cheers

Andoz

Ill see if it works tonight or the day after maby!
I am writing here if works when i know,
for other that may be intrested!
[ADSL]-HALMSTAD-[BBB]
            andoz.no-ip.com:6969

Andoz

Sorry i cant tell if works or not!
Upgraded RoboCop and its inbuild in that.
[ADSL]-HALMSTAD-[BBB]
            andoz.no-ip.com:6969

Psycho_Chihuahua

#9
runs just fine now  :D

Example (changed messages to German)

[08:02]  Der Cleaner wurde gerufen. Alle User die l?nger als 4 Wochen abwesend sind werden gel?scht.  
[08:02]  (Kontaktiere einen Operator falls du mal l?nger weg sein wirst) 
[08:02]  131 User wurden bearbeitet, 103 wurden gel?scht ( 78.63% ) innert: 0.6880 sekunden. 
[08:02]  Diese User wurden gel?scht 
andreas 
aquaship 
badboysani 
Benny 
Bernd 
bisc 
Boomer 
Burghart 
CelineHagbard 
christian 
cihan 
crazygirl 
david 
Dennis 
Dicker 
dietmar 
Dorodusi 
Earthquake 
ervino 
Felix 
Fifler 
Florian 
flow 
frank 
Fritz 
Gerry 
ghazii 
gti 
G?nther 
Hubby 
James 
Jenny 
Jerry 
JohnP 
Jonny35 
j?rgen 
J?rgen2 
Kater1960 
Kay 
kira 
Klaus 
Kleini 
KubanischesGetr?nk 
Larissa 
Lars 
Lill_A 
Lovelygirl 
Lukas 
Maik 
Manka 
Martin 
Martin1 
Master_of_Evil 
Matthias 
Melanie 
Mendo 
Michael 
michi 
Mike 
Mirage 
MisterX 
MixmasterA 
Moon 
Mr.Paranoia 
Nachtelfe 
Nightliner? 
niti 
Oli 
Pain 
Patrik 
Paul 
phil 
r?uber_hotzenplotz 
Regioschreck 
Rolf 
Ronny 
sarah 
Scheini 
sebastian 
shizzo 
Silk 
stefan 
Stefl 
Stephan 
Sven 
SvenP 
Tatankaiotanka 
testbaer 
Tilja 
Timmey 
Tjark 
Tobi 
Tobias 
Tom 
Traumtaenzer2002 
Trinitie 
Tyson 
Uwe 
Valentin 
Valleyman 
Vito 
Vossi 
ZackZack
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

jiten


Typhoon

as seen above many could be deleted at the same time so a  setting for a amx show could/should be added :) not funny when 10+ users get deleted and shown in main..

Typhoon?



jiten

First post updated.
Now it sends the deleted nicks like this: nick1, nick2, nick3, etc....

Cheers

jiten

#13
This one has the iMax thingy (by Dessamator):
-- 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)
--- modded by jiten to list deleted users in main
--- Max users shown on main by Dessamator

-- !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 = 1 -- every1 older then x weeks is deleted
cl.sets.bot = "Helvetia" -- 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 = {}
cl.iMax = 4 -- Max deleted users to show in Main
--------------------------------------------------------------------- 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, Verwende: !showusers "); return 1; end
		tbl = GetUsersByProfile(Profile); txt = "registrierte user mit 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 Dies sind die "..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, "Es gibt keine "..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() 
	local i,delnick = 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+)"); 
					local julian = cl.funcs.jdate( tonumber(day), tonumber(month), tonumber("20"..year) )
					if ((juliannow - julian) > oldest) then 
						if i < cl.iMax then
							i = i + 1
							delnick=delnick..b.."\r\n"
						end
						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.");
		if clnd ~= 0 then
			SendToAll(cl.sets.bot,"These are the deleted users (showing "..cl.iMax.."/"..clnd..") - ( "..string.format("%0.2f",((cl.iMax*100)/clnd)).."% ):")
			SendToAll("\r\n"..delnick)
		end
		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.." ist bereits auf der Immunliste.");return 1; end;
				cl.no[who] = 1; cl.funcs.save(cl.files.no, cl.no);
				user:SendData(cl.sets.bot , who.." wurde der Immunliste hinzugef?gt und wird nicht gel?scht.");return 1;
			elseif addrem == "remove" then
				if not cl.no[who] then user:SendData(cl.sets.bot , who.." war nicht in der Immunlist.");return 1; end
				cl.no[who] = nil; cl.funcs.save(cl.files.no, cl.no);
				user:SendData(cl.sets.bot , who.." wurde von der Immunlist gel?scht.");return 1;
			end; user:SendData(cl.sets.bot , "Syntax Error, Verwende: !noclean  ");return 1;
		end; user:SendData(cl.sets.bot , who.." ist kein registrierter User.");return 1;
	end; user:SendData(cl.sets.bot , "Syntax Error, Verwende: !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.." war zuletzt hier am "..cl.user[who]);return 1; end
				user:SendData( cl.sets.bot, "Woher soll ich wissen wann "..who.." zuletzt hier war ?");return 1;
			end; user:SendData( cl.sets.bot, who.." ist Online... ?ffne deine Augen..");return 1;
		end; user:SendData( cl.sets.bot, "bist nicht DU dieser User?");return 1;
	end; user:SendData( cl.sets.bot, "Syntax Error, Verwende: !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

*EDIT* Added show/cleaned ratio
Cheers

PS: Yikes eheheh

Dessamator

lol, yikes indeed, so simple and yet so complex, :D
Ignorance is Bliss.

jiten

QuoteOriginally posted by Dessamator
lol, yikes indeed, so simple and yet so complex, :D
Indeed... yesterday I was KO :D
Btw, changed the first script so that it shows the (iMax/cleaned users) ratio.

Best regards,

jiten

Dessamator

hmm, looks good mate, keep it up!!
Ignorance is Bliss.

Andoz

#17
Ok that looks very good But maby you can modify it better you script-people :)
As it maby spaam main-chat can you get it to send it in Op-Chatt or even better to specified user.
Example to [SU]Andoz and [OP]Kalle and maby [VIP]Nisse
If that can be done it would be great:)
Sorry for my bad english:(
[ADSL]-HALMSTAD-[BBB]
            andoz.no-ip.com:6969

jiten

QuoteOriginally posted by Andoz
Ok that looks very good But maby you can modify it better you script-people :)
As it maby spaam main-chat can you get it to send it in Op-Chatt or even better to specified user.
Example to [SU]Andoz and [OP]Kalle and maby [VIP]Nisse
If that can be done it would be great:)
Sorry for my bad english:(
Ok, I'll have a look at it tomorrow and add those requests.

Cheers

jiten

Here you go (not tested):
-- 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)
--- modded by jiten to list deleted users in main
--- added: (iMax/cleaned users) ratio
--- added: option to send to users/main/opchat
--- Max users shown on main by Dessamator

-- !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 = 1 -- every1 older then x weeks is deleted
cl.sets.bot = "Helvetia" -- the bot Name...
cl.sets.opchat = frmHub:GetOpChatName() -- OpChat bot
cl.sets.auto = 1 -- 0:disables / 1:enables , automatic mode ( if disabled use !cleanusers to clean )
cl.sets.send = 2 -- 0:Main / 1:OpChat / 2:Users in cl.send (send deleted users to)
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 = {}
cl.iMax = 3 -- Max deleted users to show in Main
cl.send = { "jiten", "user2", "user3", } -- users to send the deleted user list
--------------------------------------------------------------------- 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, Verwende: !showusers "); return 1; end
		tbl = GetUsersByProfile(Profile); txt = "registrierte user mit 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 Dies sind die "..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, "Es gibt keine "..txt);cl.funcs.cls();return 1;
end


--------------------------------------------------------------------- cleanup old users
function cl.funcs.clean() 
	local delnicks = "\r\n"
	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() 
	local i,delnick = 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+)"); 
					local julian = cl.funcs.jdate( tonumber(day), tonumber(month), tonumber("20"..year) )
					if ((juliannow - julian) > oldest) then 
						if i < cl.iMax then
							i = i + 1
							delnick=delnick..b.."\r\n"
						end
						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
		sSend = function(m,iBot)
			m(iBot , chkd.." users were processed, "..clnd.." were deleted ( "..string.format("%0.2f",((clnd*100)/chkd)).."% ) in: "..string.format("%0.4f", os.clock()-x ).." seconds.");
			if clnd ~= 0 then
				m(iBot,"These are the deleted users (showing "..cl.iMax.."/"..clnd..") - ( "..string.format("%0.2f",((cl.iMax*100)/clnd)).."% ):")
				m(iBot,"\r\n"..delnick)
			end
			return 1
		end
		if cl.sets.send == 0 then
			sSend(SendToAll,cl.sets.bot)
		elseif cl.sets.send == 1 then
			sSend(SendPmToOps,cl.sets.opchat)
		else
			for i, nick in cl.send do
				if (GetItemByName(nick) ~= nil) then
					GetItemByName(nick):SendPM(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.");
					if clnd ~= 0 then
						GetItemByName(nick):SendPM(cl.sets.bot,"These are the deleted users (showing "..cl.iMax.."/"..clnd..") - ( "..string.format("%0.2f",((cl.iMax*100)/clnd)).."% ):")
						GetItemByName(nick):SendPM(cl.sets.bot,"\r\n"..delnick)
					end
					return 1;
				end
			end
		end
	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.." ist bereits auf der Immunliste.");return 1; end;
				cl.no[who] = 1; cl.funcs.save(cl.files.no, cl.no);
				user:SendData(cl.sets.bot , who.." wurde der Immunliste hinzugef?gt und wird nicht gel?scht.");return 1;
			elseif addrem == "remove" then
				if not cl.no[who] then user:SendData(cl.sets.bot , who.." war nicht in der Immunlist.");return 1; end
				cl.no[who] = nil; cl.funcs.save(cl.files.no, cl.no);
				user:SendData(cl.sets.bot , who.." wurde von der Immunlist gel?scht.");return 1;
			end; user:SendData(cl.sets.bot , "Syntax Error, Verwende: !noclean  ");return 1;
		end; user:SendData(cl.sets.bot , who.." ist kein registrierter User.");return 1;
	end; user:SendData(cl.sets.bot , "Syntax Error, Verwende: !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.." war zuletzt hier am "..cl.user[who]);return 1; end
				user:SendData( cl.sets.bot, "Woher soll ich wissen wann "..who.." zuletzt hier war ?");return 1;
			end; user:SendData( cl.sets.bot, who.." ist Online... ?ffne deine Augen..");return 1;
		end; user:SendData( cl.sets.bot, "bist nicht DU dieser User?");return 1;
	end; user:SendData( cl.sets.bot, "Syntax Error, Verwende: !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
Best regards,

jiten

Andoz

Originally posted by jiten
Here you go (not tested)

Thanks m8 ill try it  8)
[ADSL]-HALMSTAD-[BBB]
            andoz.no-ip.com:6969

jiten

QuoteOriginally posted by Andoz
Originally posted by jiten
Here you go (not tested)

Thanks m8 ill try it  8)
Goody...

SMF spam blocked by CleanTalk