ShareChecker
 

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

ShareChecker

Started by Dreams, 24 March, 2010, 23:04:21

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dreams

Im in need of a script like this script --> ShareCheck 1.01 - LUA 5.1 by Herman
Can get that script to work on the newest ptokax.. is there a script like that one or can i get the ShareCheck script somewhere working?

It would be so simple to clean others share if i had that script.

Regards //

DeAn

What does this script do ?



Thanks,
DeAn
Thanks,

DeAn

Dreams

#2
Dean: in this script you can add a list with users whos share hasnt been cleaned so that every OP can se it, so that every OP on the hub doesnt send clean to the same user all the time, and the users who has gotten cleaned can be added to a cleaned user list.. im not that good at explaining but i hope you understod.

Mutor: So then that is what i will post..

http://forum.ptokax.org/index.php?topic=8199.0

DeAn

Quote from: Dreams on 25 March, 2010, 22:09:30
Dean: in this script you can add a list with users whos share hasnt been cleaned so that every OP can se it, so that every OP on the hub doesnt send clean to the same user all the time, and the users who has gotten cleaned can be added to a cleaned user list.. im not that good at explaining but i hope you understod.

Sorry Dreams, but I didn't get it. Clean in what sense ?



Thanks,
DeAn
Thanks,

DeAn

Dreams

Every user on the hub is listed on one list, cause they havnt been cleaned by an OP, but when an OP has sent them clean, they appear on a list where all OPs has sent clean to users, so they wont have to be cleaned anymore for example a week, then they apear on the non cleaned user list again and so on.. This script is for the OP/Owners who has a large hub, you just cant clean everyone and do a good job when you have around some hundreds/thousends of users =) this is a must to have if you have a private large hub.

Dreams

#5
So i did find a script for this, that i translated into english.. But i have some requests, that i wish could be done.

First, a little fix. When restarting the script, the tSC_list should only be in script/Sharecheck but it gets but in a folder under ptokax too.

And second, if someone has the time, would be nice with a sorted RC.

Have tested it a little bit and it works fine except for this little fix i requested.

--[[

	ShareCheck 2.03 - LUA 5.11   [API 2]  by Herman
	???????????????????????????????????????
	To get control over what users share in Private Hubbs.
	
	--Content
		Best idea on which user to check at the moment.
		Info on when a users last got checked.
		Statistics and lists.
		And more...
	
	--Short help on how it works
		You can get a proposal on a user in the RC and put the user in "pulled".
		When the user is checked and done you put the user under "done".
		You can put a user under "check" if you dont have time right now but the users share has to be checked.
	
	-----------------------------------------
	1.01 - changelog
		added clean mem function
		changed some formating
		changed  the way to upgrade the sorted list
		fixed a few small bugs
		added some more things on show info on user
		added new RC "myinfo"
	-----------------------------------------
	-----------------------------------------
	1.02 - changelog
		added option to change opname
		added hub info
		fixed so exlude works on checked users
		some changes in myinfo
		formating and optimization
	-----------------------------------------
	2.01 - changelog
		upgrade to -API 2-
	-----------------------------------------
	2.02 - changelog
		Bugfix - forgott to upgrade a part
	-----------------------------------------
	2.03 - changelog
		Bugfix - To much copy and paste when upgrading
		Bugfix - Found a problem with makelist that should have happend in the future
		
	-----------------------------------------
	-------------------------------------------------
	---Not Added functions. maybe later--- 
	-------------------------------------------------
		RC remove "Done"
		cleanup of database
	----------------------------------------------
]]--

tSettings = {

-- Bot Name
	sBot_I = "-Informer-",

	-- Who will get the errormessages
	AdminNick = "Herman",
	
	-- Max amount for the sorted list of users who will get checked. 
	-- 1000 should work for most. But if you have a really large hub (increase) or if you want to save resources (decrease) the amount of users in the list
	iMaxList = 1000,

	-- Day of start of the week check, if you have a requirement on the amount of filelists per week 
	-- (as a decimal number with Sunday as 0 (0-6) )
	iDay = 5,
	
	-- RightClick Menu
	sMenu = "?  Commands\\Share Check Commands",

	-- Directory for files
	filedir = "Sharecheck\\",
	
	-- User DB
	fuserDB = "tSC_user.tbl",
	
	-- OP DB
	fopDB = "tSC_op.tbl",
	
	-- Check DB
	fcheckDB = "tSC_check.tbl",
	
	-- Pulled DB
	fpulledDB = "tSC_pulled.tbl",
	
	-- Sorted List With Users Who Has To Get Checked
	flistDB = "tSC_list.tbl",
	
	-- Log with users that is done
	fdoneLOG = "tSC_done.log",
	
	-- Profils who will see admin commands.
	tAdminRCcmds = {[0] = 1, [1] = 0, [2] = 0, [3] = 0},
	
	-- Exlude people in the list of users to check = flistDB
	-- Profiles that will be exluded ( = 1 ) 
	tProfiles = { [0] = 1, [1] = 1, [2] = 0, [3] = 0 },
	
	-- User that will not be checked -- Use lowercase
	tUser = {[""] = 1,[""] = 1},
	
	-- Prefix that not will be checked -- Use lowercase
	tPrefix = {	
				"[Crew]",
				"[]"
						}
}

--===============================================================================================================
--     Edit below this on your own risk.                 No support if you do :P
--===============================================================================================================

-- username <> times checked, last check, op checked
tuserDB = {} --  ( iCounter, iTime, sOP )

-- opname <> filelist checked, first time checked, last week 
topDB = {} --( iCounter, iTime )

-- username <> op reported, time 
tcheckDB = {} --( iTime, sOP )

-- username <> op checked, time
tpulledDB = {} --( iTime, sOP )

-- username
tlistDB = {}

-- static numbers
statWeek = 604800
statDay = 86400
statHour = 3600

OnStartup = function()
	-- Register BotName if not registered
	if tSettings.sBot_I ~= SetMan.GetString(21) then Core.RegBot(tSettings.sBot_I,"","",true) end
	-- Load DB content
	--os.execute("mkdir "..tSettings.filedir)
	local r,e = os.rename("web","web")
	if e then
		if not e:find("Permission denied") then
			os.execute("mkdir "..tSettings.filedir)
		end
	end
	if loadfile(tSettings.filedir..tSettings.flistDB) then dofile(tSettings.filedir..tSettings.flistDB) end
	if loadfile(tSettings.filedir..tSettings.fpulledDB) then dofile(tSettings.filedir..tSettings.fpulledDB) end
	if loadfile(tSettings.filedir..tSettings.fcheckDB) then dofile(tSettings.filedir..tSettings.fcheckDB) end
	if loadfile(tSettings.filedir..tSettings.fuserDB) then dofile(tSettings.filedir..tSettings.fuserDB) end
	if loadfile(tSettings.filedir..tSettings.fopDB) then dofile(tSettings.filedir..tSettings.fopDB) end
	
	
	-- Make a sorted list of users who shall be checked if it not exist or is to small
	if not next(tlistDB) then
		MakeCheckList()
	end
end 

NewUserConnected = function(user)

	local tRealNick = GetRealNick(user.sNick,tpulledDB)
	if tRealNick then
		Core.SendPmToNick(tpulledDB[tRealNick].sOP, tSettings.sBot_I, "ShareCheck: User: "..user.sNick.." has connected. Can be found in your pulled")
	end
	
	--tAdmin = 1,
	--tAdminRCcmds = {[0]
	if Core.GetUserAllData(user) then
		-- Supports UserCommands
		if user.bUserCommand and user.bOperator then
			-- For each entry in table
			for i, v in pairs(tCommands) do
				-- If member
				if v.tAdmin == 1 then
					if tSettings.tAdminRCcmds[user.iProfile] == 1 then
						-- For each type
						for n in ipairs(v.tRC) do
							-- Send
							Core.SendToNick(user.sNick,"$UserCommand 1 3 "..tSettings.sMenu.."\\"..v.tRC[n][1]..
							"$<%[mynick]> !"..i..v.tRC[n][2].."&#124;")
						end
					end
				
				else
					for n in ipairs(v.tRC) do
						-- Send
						Core.SendToNick(user.sNick,"$UserCommand 1 3 "..tSettings.sMenu.."\\"..v.tRC[n][1]..
						"$<%[mynick]> !"..i..v.tRC[n][2].."&#124;")
					end
				end
			end
			for i, v in pairs(tCommands2) do
				-- If member
				if v.tAdmin == 1 then
					if tSettings.tAdminRCcmds[user.iProfile] == 1 then
						-- For each type
						for n in ipairs(v.tRC) do
							-- Send
							Core.SendToNick(user.sNick,"$UserCommand 1 3 "..tSettings.sMenu.."\\"..v.tRC[n][1]..
							"$<%[mynick]> !"..i..v.tRC[n][2].."&#124;")
						end
					end
				else
					for n in ipairs(v.tRC) do
						-- Send
						Core.SendToNick(user.sNick,"$UserCommand 1 3 "..tSettings.sMenu.."\\"..v.tRC[n][1]..
						"$<%[mynick]> !"..i..v.tRC[n][2].."&#124;")
					end
				end
			end
		end
	end
end

OpConnected = NewUserConnected

ChatArrival = function(user, data)
	local _,_, to = string.find(data, "^$To:%s(%S+)%s+From:")
	local _,_, msg = string.find(data, "%b<>%s(.*)|$") 
	-- Message sent to Bot or in Main
	if (to and to == tSettings.sBot_I) or not to then
		-- Parse command
		local _,_, cmd = string.find(msg, "^%p(%S+)")
		-- Exists
		if cmd and tCommands[string.lower(cmd)] then
			
			if Core.GetUserAllData(user) and user.bOperator then
			
				cmd, user.SendPM = string.lower(cmd), user.SendData
				-- PM
				if to == tSettings.sBot_I then user.SendPM = user.SendPM end
				
				if tCommands[cmd].tAdmin == 1 then
					if tSettings.tAdminRCcmds[user.iProfile] == 1 then
						return tCommands[cmd].fFunction(user, msg), true
					else
						return Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: You are not allowed to use this command!"), true
					end
				else
					return tCommands[cmd].fFunction(user, msg), true
				end
			else
				return Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: You are not allowed to use this command!"), true
			end
			
		elseif cmd and tCommands2[string.lower(cmd)] then
			if Core.GetUserAllData(user) and user.bOperator then
				cmd, user.SendPM = string.lower(cmd), user.SendData
				-- PM
				if to == tSettings.sBot_I then user.SendPM = user.SendPM end
				-- If user has permission
				if tCommands2[cmd].tAdmin == 1 then
					if tSettings.tAdminRCcmds[user.iProfile] == 1 then
						return tCommands2[cmd].fFunction(user, msg), true
					else
						return Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: You are not allowed to use this command!"), true
					end
					
				else
					return tCommands2[cmd].fFunction(user, msg), true
				end			
			else
				return Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: You are not allowed to use this command!"), true
			end
		end
	end
end

ToArrival = ChatArrival

tCommands2 = {
	suggestiononuser = {
		fFunction = function(user, data)
			--loops through check first to see if someone is online
			if next(tcheckDB) then
				for i, v in pairs(tcheckDB) do
					if Core.GetUser(i) then
						Core.SendPmToNick(user.sNick,tSettings.sBot_I, "ShareCheck: The most recommended user to check right now -->  "..i)
						Core.SendPmToNick(user.sNick,tSettings.sBot_I, "ShareCheck: Remember to add the user to the pulled list before you begin")
						return true
					end
				end
			end
			--if there is no hits in check list the other list loops through and takes the first person online
			if next(tlistDB) then
				for i = 1, table.maxn(tlistDB), 1 do
					if Core.GetUser(tlistDB[i]) then
						Core.SendPmToNick(user.sNick,tSettings.sBot_I, "ShareCheck: The most recommended user to check right now -->  "..tlistDB[i])
						Core.SendPmToNick(user.sNick,tSettings.sBot_I, "ShareCheck: Remember to add the user to the pulled list before you begin")
						return true
					end
				end
			end
			Core.SendPmToNick(user.sNick,tSettings.sBot_I, "ShareCheck: Has no one to recommend right now, but will update the database, so try again later.")
			MakeCheckList()
			
		end,
		tAdmin = 0,
		tRC = { { "Best Idea On User To Check", "" } }
	},
	sharecheck = {
		fFunction = function(user, data)
			local _,_, nick,typ = string.find(data, "^%S+%s+(%S+)%s+(%S+)$")

			if nick and typ then
				
				if typ == "pulled" then
					if GetRealNick(nick,tpulledDB) then
						Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: "..nick.." is already in the pulled list.")
					else
					
						local sText = ""
						for i, v in pairs(RegMan.GetRegs()) do
							if string.lower(v.sNick)==string.lower(nick) then	
								tpulledDB[v.sNick] ={iTime=os.time(os.date("*t")),sOP=user.sNick}
								local hFile = io.open(tSettings.filedir..tSettings.fpulledDB, "w+") Serialize(tpulledDB, "tpulledDB", hFile); hFile:close()
								sText = "*** Was successful:"
							end
						end
						if sText == "" then
							Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Failed: "..nick.." isn't a registered user! Check the nick again")
						else
							Core.SendPmToNick(user.sNick, tSettings.sBot_I, "ShareCheck: Added "..nick.." to the pulled list")
							
							-- Remove the user from sorted check list
							if next(tlistDB) then
								for i = 1, table.maxn(tlistDB), 1 do
									if string.lower(tlistDB[i]) == string.lower(nick)  then
										--tlistDB[i] = nil
										table.remove (tlistDB , i)
										local hFile = io.open(tSettings.filedir..tSettings.flistDB, "w+") Serialize(tlistDB, "tlistDB", hFile); hFile:close()
										break
									end
								end
							end
							
							-- Remove the user from check
							local tRealNick = GetRealNick(nick,tcheckDB)
							if tRealNick then
								tcheckDB[tRealNick] = nil
								local hFile = io.open(tSettings.filedir..tSettings.fcheckDB, "w+") Serialize(tcheckDB, "tcheckDB", hFile); hFile:close()
							end
						end						
					end				
				elseif typ == "check"  then
					if GetRealNick(nick,tcheckDB) then
						Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: "..nick.." is already in the check list.")
					else	
						local sText = ""
						for i, v in pairs(RegMan.GetRegs()) do
							if string.lower(v.sNick)==string.lower(nick) then	
								tcheckDB[v.sNick] ={iTime=os.time(os.date("*t")),sOP=user.sNick}
								local hFile = io.open(tSettings.filedir..tSettings.fcheckDB, "w+") Serialize(tcheckDB, "tcheckDB", hFile); hFile:close()
								sText = "*** Was successful:"
							end
						end
						if sText == "" then
							Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Failed: "..nick.." isn't a registered user! Check the nick again")
						else
							Core.SendPmToNick(user.sNick, tSettings.sBot_I, "ShareCheck: Added "..nick.." to the check list")
						end						
					end
				elseif typ == "done" then	
					
-- Check if the user is avalible
					local iIsReg = 0
					for i, v in pairs(RegMan.GetRegs()) do
						if string.lower(v.sNick)==string.lower(nick) then		
						
							-- Add to done logfile
							local hFile = io.open(tSettings.filedir..tSettings.fdoneLOG, "a+")
							local tTime = os.time(os.date("*t"))
							
							hFile:write(os.date("%Y-%m-%d %H:%M ",tTime)..nick.." "..user.sNick.." ".."\r\n")
							hFile:close()					
							
							-- Remove the user from pulled
							local tRealNick = GetRealNick(nick,tpulledDB)
							if tpulledDB[tRealNick] then
								tpulledDB[tRealNick] = nil
								local hFile = io.open(tSettings.filedir..tSettings.fpulledDB, "w+") Serialize(tpulledDB, "tpulledDB", hFile); hFile:close()
							end
							
							-- Remove the user from check
							local tRealNick = GetRealNick(nick,tcheckDB)
							if tRealNick then
								tcheckDB[tRealNick] = nil
								local hFile = io.open(tSettings.filedir..tSettings.fcheckDB, "w+") Serialize(tcheckDB, "tcheckDB", hFile); hFile:close()
							end
							
							-- Remove the user from sorted check list
							if next(tlistDB) then
								for i = 1, table.maxn(tlistDB), 1 do
									if string.lower(tlistDB[i]) == string.lower(nick)  then
										--tlistDB[i] = nil
										table.remove (tlistDB , i)
										local hFile = io.open(tSettings.filedir..tSettings.flistDB, "w+") Serialize(tlistDB, "tlistDB", hFile); hFile:close()
										break
									end
								end
							end
							
							-- Add to stat to opDB
							local tRealNick = GetRealNick(user.sNick,topDB)
							if tRealNick then
								topDB[tRealNick].iCounter = topDB[tRealNick].iCounter + 1
							else
								topDB[user.sNick] ={iTime=os.time(os.date("*t")),iCounter = 1}
							end
							local hFile = io.open(tSettings.filedir..tSettings.fopDB, "w+") Serialize(topDB, "topDB", hFile); hFile:close()					
							
							
							-- Add to userDB
							local tRealNick = GetRealNick(nick,tuserDB)							
							if tRealNick then
								tuserDB[tRealNick].iTime = os.time(os.date("*t"))
								tuserDB[tRealNick].sOP = user.sNick
								tuserDB[tRealNick].iCounter = tuserDB[tRealNick].iCounter + 1
							else
								tuserDB[nick] ={iTime=os.time(os.date("*t")),sOP=user.sNick,iCounter = 1}
							end
							local hFile = io.open(tSettings.filedir..tSettings.fuserDB, "w+") Serialize(tuserDB, "tuserDB", hFile); hFile:close()
			
							-- Send info to all ops in main					
							Core.SendPmToOps(tSettings.sBot_I, "ShareCheck: "..user.sNick.." Added "..nick.." to the done list")
													-- 
							iIsReg = 1

						end
					end
					-- Check if the person excisted or not	
					if iIsReg == 0 then Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Failed: "..nick.." isn't a registered user! Check the nick again") end
						
					
				else
					Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Syntax Error: You have to choose \"pulled\" , \"done\" or \"check\" ")
				end
			else
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Syntax Error: No nickname or type")
			end
			--clean Memory
			CleanMem()
		end,
		tAdmin = 0,
		tRC = { { "Add User", " %[line:Full Nickname] %[line:Type: pulled, done, check]" }, { "Add This User", " %[nick] %[line:Type: pulled, done, check]" } }
	},
}


tCommands = {
	sc_showuser = {
		fFunction = function(user, data)
			-- Return
			local _,_, nick = string.find(data, "^%S+%s+(%S+)$")
		
			if nick then
			
				local msg = "\r\n\r"..string.rep("-", 60).."\r\nUserInfo For "..nick..":\r\n"..string.rep("-", 60).."\r\n"
				--msg = msg.."Username:      \t"..nick.."\r\n"
				
				
				local tRealNick = GetRealNick(nick,tuserDB)
				if tRealNick then
					msg = msg.."Last Check:    \t"..os.date("%Y-%m-%d %H:%M",tuserDB[tRealNick].iTime).."\r\n"
					msg = msg.."By Who:        \t"..tuserDB[tRealNick].sOP.."\r\n"
					msg = msg.."Times checked: \t"..tuserDB[tRealNick].iCounter.."\r\n"
				else
					msg = msg.."Last Check:    \tNever\r\n"
				end
					
				local tRealNick1 = GetRealNick(nick,tpulledDB)
				if tRealNick1 then
					msg = msg.."In \"Pulled\":      \tYes by "..tpulledDB[tRealNick1].sOP.."\r\n"
				else
					msg = msg.."In \"Pulled\":      \tNo\r\n"
				end
				local tRealNick2 = GetRealNick(nick,tcheckDB)
				if tRealNick2 then
					msg = msg.."In \"Check\": \tYes\r\n"
				else
					msg = msg.."In \"Check\": \tNo\r\n"
				end

				msg = msg..string.rep("-", 60)
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")

			end
		end,
		tAdmin = 0,
		tRC = { { "Check Info\\Show Info On A User", " %[line:Full Nickname]" }, { "Check Info\\Show Info On This User", " %[nick]" } }
	},
	sc_showinfo = {
		fFunction = function(user)
					
				local msg = "\r\n\r"..string.rep("=", 40).."\r\nInformation On "..user.sNick..":\r\n"..string.rep("=", 40).."\r\n"
				--msg = msg.."Username:      \t"..nick.."\r\n"

				
				local tRealNick = GetRealNick(user.sNick,topDB)
				if tRealNick then
					
					--Weeklists
					local tempDay = tonumber(os.date("%w"))
					if tSettings.iDay > tempDay then tempDay = tempDay + 7 end
					tempDay = tempDay - tSettings.iDay +7
					local tWList = WeekList(0,1,tRealNick)
					local tWListNow = WeekList(0,0,tRealNick)
					--If you havnt done one yet you have to fill the values
					if tWList[tRealNick] == nil then
						tWList[tRealNick]={iCounter=0,iUsers="no users"}
					end
					if tWListNow[tRealNick] == nil then
						tWListNow[tRealNick]={iCounter=0,iUsers="no users"}
					end
					--Average
					local iDays = (os.time(os.date("*t")) - topDB[tRealNick].iTime)/statDay
					local iAmount =string.format("%.2f", ((topDB[tRealNick].iCounter/iDays)*7))	
					

					--Pulled
					--local iCount = 0
					local sPulled ="\r\nPulled users:\r\n"
					for i, v in pairs(tpulledDB) do
						if string.lower(v.sOP)==string.lower(user.sNick) then
							sPulled = sPulled..os.date("%Y-%m-%d %H:%M",v.iTime).."\t"..i.."\r\n"
							--iCount = iCount + 1
						end
					end
			
					msg = msg.."First filelist checked at:      \t"..os.date("%Y-%m-%d",topDB[tRealNick].iTime).."\r\n"				
					msg = msg.."Amount of lists checked:      \t"..topDB[tRealNick].iCounter.."\r\n"
					msg = msg.."Average checked (week): \t"..iAmount.."\r\n\r\n"
					msg = msg.."Checked present week: \t"..tWListNow[tRealNick].iCounter.." st\r\n"
					msg = msg..tWListNow[tRealNick].iUsers.."\r\n\r"
					msg = msg.."Checked the last "..tempDay.." days: \t"..tWList[tRealNick].iCounter.." st\r\n"
					msg = msg..tWList[tRealNick].iUsers.."\r\n"
					msg = msg..sPulled..""
					
				else
					msg = msg.."Your not in the database. You have to add a done filelist first\r\n"
				end
					


				msg = msg..string.rep("-", 80)
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
				--clean Memory
				CleanMem()

			
		end,
		tAdmin = 0,
		tRC = { { "Check Info\\Show My Info", "" } }
	},
	sc_showhubinfo = {
		fFunction = function(user)
					
				local msg = "\r\n\r"..string.rep("=", 50).."\r\nStatistics On Filechecking Control In The Hub\r\n"..string.rep("=", 50).."\r\n"
				--msg = msg.."Username:      \t"..nick.."\r\n"

				
				
				--Amount checked
				--Average checked
				--First list checked
				--Amount of OP
				--OP whos checked the most - amount + name
				-----------------------------------------
				--Amount of users thats never been checked
				--The most checked user - amount + person
				--A users average times checked
				
				
			if next(topDB) then
				local iAchecked,iFirstChecked,iAmountOp,iMostOpAmount,sMostOp =0,0,0,0,""

				-- Loop through hubbers
				for i, v in pairs(topDB) do
					
					iAChecked = iAchecked + v.iCounter
					
					if iFirstChecked == 0 or v.iTime < iFirstChecked then
						iFirstChecked = v.iTime
					end
					
					iAmountOp = iAmountOp + 1
					
					if iMostOpAmount == 0 or v.iCounter > iMostOpAmount then
						iMostOpAmount = v.iCounter
						sMostOp = i
					end
					

				end
				
				-- Average
				local iDays = (os.time(os.date("*t")) - iFirstChecked)/statDay
				local iAverageAmount =string.format("%.1f", ((iAchecked/iDays)*7))	
						
				
				
				
				msg = msg.."First filelist checked at:      \t\t"..os.date("%Y-%m-%d",iFirstChecked).."\r\n"				
				msg = msg.."Amount of lists checked:      \t\t"..iAchecked.." st\r\n"
				msg = msg.."Average amount (week): \t\t"..iAverageAmount.." st\r\n"
				msg = msg.."Amount of OP that has checked lists:\t"..iAmountOp.." st\r\n"
				msg = msg.."OP whos checked the most lists: \t"..sMostOp.." , "..iMostOpAmount.." st\r\n\r\n"
				
				
				
				local iAUser,iUserChecked,iNotChecked,iMostChecked,sMostChecked,iAverage = 0,0,0,0,"",0
				
				for i, v in pairs(tuserDB) do
					
					iAUser = iAUser +1
					iUserChecked = iUserChecked + v.iCounter
					
					if iMostChecked == 0 or v.iCounter > iMostChecked then
						iMostChecked = v.iCounter
						sMostChecked = i
					end
				end
								
				iNotChecked = table.maxn(RegMan.GetRegs()) - iAUser
				iAverage = string.format("%.2f",iUserChecked/table.maxn(RegMan.GetRegs()))
				
				msg = msg.."Users thats been checked:\t\t"..iAUser.." st\r\n"
				msg = msg.."Users thats never been checked:\t"..iNotChecked.." st\r\n"
				msg = msg.."The most checked user: \t\t"..sMostChecked.." , "..iMostChecked.." ggr\r\n"
				msg = msg.."Amount of times users been checked:\t"..iAverage.." ggr\r\n"


					
			else
				msg = msg.."There is no OPdatabase\r\n"
			end
				
			msg = msg..string.rep("-", 100)
			Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
			--clean Memory
			CleanMem()
			
		end,
		tAdmin = 0,
		tRC = { { "Check Info\\Show Hub Info", "" } }
	},
	scop_delpulled = {
		fFunction = function(user, data)
			local _,_, nick = string.find(data, "^%S+%s+(%S+)$")
			
			if nick then
				local tRealNick = GetRealNick(nick,tpulledDB)
				if tRealNick then
					tpulledDB[tRealNick] = nil
					local hFile = io.open(tSettings.filedir..tSettings.fpulledDB, "w+") Serialize(tpulledDB, "tpulledDB", hFile); hFile:close()
					Core.SendPmToNick(user.sNick,tSettings.sBot_I, "ShareCheck: "..nick.." is removed from the pulled list")
				else
					Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: "..nick.." isn't found in the pulled list")
				end
			else
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Syntax Error: Add nickname")
			end
						
		end,
		tAdmin = 1,
		tRC = { { "Owners List\\Remove User From The Pulled List", " %[line:Nick]" } }
	},
	scop_delcheck = {
		fFunction = function(user, data)
			-- Return
			local _,_, nick = string.find(data, "^%S+%s+(%S+)$")
			if nick then
				local tRealNick = GetRealNick(nick,tcheckDB)
				if tRealNick then
						tcheckDB[tRealNick] = nil
						local hFile = io.open(tSettings.filedir..tSettings.fcheckDB, "w+") Serialize(tcheckDB, "tcheckDB", hFile); hFile:close()
						Core.SendPmToNick(user.sNick,tSettings.sBot_I, "ShareCheck: "..nick.." is removed from the check list")
				else
					Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: "..nick.." isn't found in the check list")
				end
			else
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Syntax Error: Add nickname")
			end
						
		end,
		tAdmin = 1,
		tRC = { { "Owners List\\Remove User From The Check List", " %[line:Nick]" } }
	},
	sc_donelist = {
		fFunction = function(user)
			local f = io.open(tSettings.filedir..tSettings.fdoneLOG,"r") --if f then f:close()
			if f then
				local msg = "\r\n\r"..string.rep("=", 47).."\r\nUsers That "..user.sNick.." Has Done\r\n"..string.rep("-", 94).."\r\n"
				msg = msg.."Checked At\tOP Who Added \tUser\r\n"..string.rep("-", 94).."\r\n"
				
				for line in f:lines() do
					local _,_, iTime,sUser,sOp = string.find(line, "(%S+%s%S+)%s(%S+)%s(%S+)")
					if string.lower(sOp) == string.lower(user.sNick) then
						msg = msg..iTime.."\t"..sOp.."  \t"..sUser.."\r\n"
					end
				end
				
				msg = msg..string.rep("-", 94)
				-- Send
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
							
				f:close()
			else
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: There's no done logfile")
			end
		end,
		tAdmin = 0,
		tRC = { { "Check List\\Users I Have Done", " %[Nick]" } }
	},
	sc_pulledlist = {
		fFunction = function(user, data)
			-- Table isn't empty
			if next(tpulledDB) then
				local _,_, tVar = string.find(data, "^%S+%s+(%S+)$")

				local msg = "\r\n\r"..string.rep("=", 47).."\r\nUsers In The Pulled List:\r\n"..string.rep("-", 94).."\r\n"
				msg = msg.."Added At\t\tOP Who Added\tUser\r\n"..string.rep("-", 94).."\r\n"	
				local tCopy ={}
				-- Loop through hubbers
				
				for i, v in pairs(tpulledDB) do
					-- Insert stats to temp table
					if tVar == "me" and string.lower(v.sOP)==string.lower(user.sNick) then
						table.insert(tCopy, { sUser = i, iTime = v.iTime, sOP =v.sOP } )
					elseif tVar == "all" then
						table.insert(tCopy, { sUser = i, iTime = v.iTime, sOP =v.sOP } )
					end
				end
				-- Sort by total time
				table.sort(tCopy, function(a, b) return (a.iTime < b.iTime) end)
				-- Loop through temp table
				
				for i, v in pairs(tCopy) do
					msg = msg..os.date("%Y-%m-%d %H:%M",v.iTime).."\t"..v.sOP.."  \t"..v.sUser.."\r\n"
				end
						
				msg = msg..string.rep("-", 94)
				-- Send
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
			else
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: Pulled list is empty")
			end
		end,
		tAdmin = 0,
		tRC = { { "Check List\\All Users Whos Filelists Has Been Pulled", " all" }, { "Check List\\All Users Whos Filelists I Have Pulled", " me" } }
	},
	sc_checklist = {
		fFunction = function(user)
			-- Table isn't empty
			if next(tcheckDB) then

				local msg = "\r\n\r"..string.rep("=", 47).."\r\nUsers In The Check List:\r\n"..string.rep("-", 94).."\r\n"
				msg = msg.."Added At\t\tUser\t\tOP Who Added\r\n"..string.rep("-", 94).."\r\n"	
				local tCopy ={}
				-- Loop through hubbers
				
				for i, v in pairs(tcheckDB) do
					-- Insert stats to temp table
					table.insert(tCopy, { sUser = i, iTime = v.iTime, sOP =v.sOP } )
				end
				-- Sort by total time
				table.sort(tCopy, function(a, b) return (a.iTime < b.iTime) end)
				-- Loop through temp table
				
				for i, v in pairs(tCopy) do
					msg = msg..os.date("%Y-%m-%d %H:%M",v.iTime).."\t"..v.sUser.."\t"..v.sOP.."\r\n"
				end
						
				msg = msg..string.rep("-", 94)
				-- Send
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
			else
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: Check list is empty")
			end
		end,
		tAdmin = 0,
		tRC = { { "Check List\\Users Who Has To Be Checked", "" } }
	},
	sc_toplist = {
		fFunction = function(user)
			if next(topDB) then

				local msg = "\r\n\r"..string.rep("=", 40).."\r\nTop Filelist Checker:\r\n"..string.rep("-", 80).."\r\n"
				msg = msg.."Amount\t\tOp\r\n"..string.rep("-", 80).."\r\n"	
				local tCopy ={}
				-- Loop through hubbers
				for i, v in pairs(topDB) do
					-- Insert stats to temp table
					table.insert(tCopy, { sOp = i, iAmount = v.iCounter } )
				end
				-- Sort by total time
				table.sort(tCopy, function(a, b) return (a.iAmount > b.iAmount) end)
				-- Loop through temp table
				for i, v in pairs(tCopy) do
					msg = msg..""..v.iAmount.."\t\t"..v.sOp.."\r\n"
				end
						
				msg = msg..string.rep("-", 80)
				-- Send
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
			else
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: There is no OPstats list")
			end
		end,
		tAdmin = 0,
		tRC = { { "Check List\\Total Amount Done", "" }}
	},
	scop_donelistowner = {
		fFunction = function(user, data)
			local _,_, nick = string.find(data, "^%S+%s+(%S+)$")
			if nick then
				local f = io.open(tSettings.filedir..tSettings.fdoneLOG,"r")
				if f then
					local msg = "\r\n\r"..string.rep("=", 47).."\r\nUsers Who Is Done\r\n"..string.rep("-", 94).."\r\n"
					msg = msg.."Checked At\tOP Who Added\tUser\r\n"..string.rep("-", 94).."\r\n"
					
					if nick == "all" then
						for line in f:lines() do
							local _,_, iTime,sUser,sOp = string.find(line, "(%S+%s%S+)%s(%S+)%s(%S+)")
							msg = msg..iTime.."\t"..sOp.."\t"..sUser.."\r\n"
						end			
					else
						for line in f:lines() do
							local _,_, iTime,sUser,sOp = string.find(line, "(%S+%s%S+)%s(%S+)%s(%S+)")
							if string.lower(sOp) == string.lower(nick) then
								msg = msg..iTime.."\t"..sOp.."\t"..sUser.."\r\n"
							end
						end
					end
					msg = msg..string.rep("-", 94)
					-- Send
					Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
								
					f:close()
				else
					Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: There is no done logfile")
				end
			end
		end,
		tAdmin = 1,
		tRC = { { "Owners List\\Show Users An OP Done", " %[line:OpNick]" }, { "Owners List\\Show All Done Users", " all" } }
	},
	scop_toplistaverage = {
		fFunction = function(user)
			-- Table isn't empty
			if next(topDB) then

				local msg = "\r\n\r"..string.rep("=", 40).."\r\nAverage Per Week:\r\n"..string.rep("-", 80).."\r\n"
				msg = msg.."Average\tOP\r\n"..string.rep("-", 80).."\r\n"	
				local tCopy ={}
				
				 --iCounter, iTime )
				local iNow = os.time(os.date("*t"))
				local iDays, iAmount
				 -- Loop through hubbers
				for i, v in pairs(topDB) do
				
					iDays = (iNow - v.iTime)/statDay
					iAmount =string.format("%.2f", ((v.iCounter/iDays)*7))	
				
				
					--iWeeks = math.ceil((iNow - v.iTime)/statWeek)
					--iAmount =string.format("<%.2f>", (v.iCounter/iWeeks))	
					
					--local _,_,iAmount = string.find((v.iCounter/iWeeks),"(%d+%.?%d?)")
							
					
					
					
					-- Insert stats to temp table
					table.insert(tCopy, { sOp = i, iAverage = tonumber(iAmount) } )
				end
				-- Sort by total time
				table.sort(tCopy, function(a, b) return (a.iAverage > b.iAverage) end)
				-- Loop through temp table
				
				for i, v in pairs(tCopy) do
					msg = msg..""..v.iAverage.."\t"..v.sOp.."\r\n"
				end
						
				msg = msg..string.rep("-", 80)
				-- Send
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
			else
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: There is no one in the OPstats list")
			end
		end,
		tAdmin = 1,
		tRC = { { "Owners List\\Show The Average Amount Of Checked Users", "" }}
	},
	scop_weeklist = {
		fFunction = function(user, data)
			local _,_, tNumber = string.find(data, "^%S+%s+(%d+)$")
			local _,_, tStartW,tStopW = string.find(data, "^%S+%s+(%d+)%-(%d+)$")
			if tNumber or tStartW then		

					
					-- check what weeks user want to see
					local iStartWeek,iStopWeek
						
					if tStartW then
						iStartWeek = tStartW
						iStopWeek = tStopW
						tNumber = tStartW.."-"..tStopW
					else
						iStartWeek = tNumber
						iStopWeek = tNumber
					end				
					
					local tWList = WeekList(iStartWeek,iStopWeek,nil)
					
					-- Printing the list
					local msg = "\r\n\r"..string.rep("=", 30).."\r\nShow Info On The Week/Weeks: "..tNumber.."\r\n"..string.rep("=", 30).."\r\n"
					for i, v in pairs(tWList) do
						msg = msg..""..i.." has done "..v.iCounter.." users.\r\n\r\n"..v.iUsers.."\r\n"..string.rep("-", 60).."\r\n"
					end
					
					Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
					tWList ={}

			end
		end,
		tAdmin = 1,
		tRC = {{ "Owners List\\Show How Many Users Is Done - A Week", " %[line:0=present, 1=former, 0-4=several weeks]" } }
	},
}

MakeCheckList = function()
	local iCounter = 0
	local tBol
	tlistDB = {}

	for i, v in pairs(RegMan.GetRegs()) do
		--not checked before
		if not GetRealNick(v.sNick,tuserDB) then
			-- allowed profile
			if tSettings.tProfiles[v.iProfile] and tSettings.tProfiles[v.iProfile] == 1 then

			else
			--allowed user
				if not tSettings.tUser[string.lower(v.sNick)] then
					--allowed prefix 
					tBol = 0
					for key, tFix in pairs(tSettings.tPrefix) do
						if string.sub(string.lower(v.sNick),1,string.len(tFix)) == string.lower(tFix) then
							tBol = 1
						end
					end				
					if tBol == 0 then
					
						table.insert(tlistDB,v.sNick)
						iCounter = iCounter + 1
						
						if iCounter >= tSettings.iMaxList then 
							break
						end
					end		
				end
			end
		end
	end


	if iCounter < tSettings.iMaxList then 
		local tCopy = {}
		for i, v in pairs(tuserDB) do		
			if not tSettings.tUser[string.lower(i)] then
				--allowed prefix 
				tBol = 0
				for key, tFix in pairs(tSettings.tPrefix) do
					if string.sub(string.lower(i),1,string.len(tFix)) == string.lower(tFix) then
						tBol = 1
					end
				end				
				if tBol == 0 then
					table.insert(tCopy, { sUser = i, iTime = v.iTime} )
				end
			end
		end
		-- Sort by total time
		table.sort(tCopy, function(a, b) return (a.iTime < b.iTime) end)
		-- Loop through temp table
		for i = 1, table.maxn(tCopy), 1 do
			-- i exists
			if tCopy[i] then
				-- Populate
				table.insert(tlistDB,tCopy[i].sUser)
				iCounter = iCounter + 1
				if iCounter >= tSettings.iMaxList then 
					break
				end
			end
		end	
		tCopy = {}
	end
	--save the list
	local hFile = io.open(tSettings.filedir..tSettings.flistDB, "w+") Serialize(tlistDB, "tlistDB", hFile); hFile:close()
	CleanMem()
end


function WeekList(startw,stopw,user)
	local tTempW = {}
	local f = io.open(tSettings.filedir..tSettings.fdoneLOG,"r") --if f then f:close()
	if f then
		-- calculate time in seconds to the last "check time"
		local iNow = os.time(os.date("*t"))
		local tempDay = tonumber(os.date("%w",iNow))
		if tSettings.iDay > tempDay then tempDay = tempDay + 7 end
		tempDay = tempDay - tSettings.iDay
		local iDiffSec = tempDay*statDay + os.date("%H",iNow)*statHour + os.date("%M",iNow)*60 + os.date("%S",iNow)
		local iCheckStart = iNow - iDiffSec
			
		for line in f:lines() do
			local _,_, iY,iM,iD,iMin,iS,sUser,sOp = string.find(line, "(%d+)%-(%d+)%-(%d+)%s(%d+)%:(%d+)%s(%S+)%s(%S+)")
			
			if user and string.lower(user) == string.lower(sOp) or not user then 
			
				local iTime = os.time({ year = iY, month = iM, day = iD, hour = iH, min = iMin, sec = iS})
				local iStop = iCheckStart - (statWeek*stopw)    
				local iStart = iCheckStart - (statWeek*startw) + statWeek            
						
				if tonumber(iTime) < tonumber(iStart) and tonumber(iTime) > tonumber(iStop) then
					if tTempW[sOp] then
						tTempW[sOp].iCounter=tTempW[sOp].iCounter+1
						tTempW[sOp].iUsers=tTempW[sOp].iUsers..sUser.." , "
					else
						tTempW[sOp]={iCounter=1,iUsers=sUser.." , "}
					end
				end
			end
		end
		f:close()
	end	
	return tTempW

end

-- Clean the memory
function CleanMem()
	collectgarbage()
	io.flush()
end

OnError = function(msg)
	Core.SendPmToNick("Herman", tSettings.sBot_I ,"<"..tSettings.sBot_I.."> "..msg)
	Core.SendPmToNick(tSettings.AdminNick, tSettings.sBot_I ,"<"..tSettings.sBot_I.."> "..msg)
	--OnError("----")
end

GetRealNick = function(user,db)
	-- For each hubber
	for i, v in pairs(db) do
		-- Compare
		if string.lower(i) == string.lower(user) then
			-- Return
			return i
		end
	end
end

Serialize = function(tTable, sTableName, hFile, sTab)
	sTab = sTab or "";
	hFile:write(sTab..sTableName.." = {\n");
	for key, value in pairs(tTable) do
		if (type(value) ~= "function") then
			local sKey = (type(key) == "string") and string.format("[%q]", key) or string.format("[%d]", key);
			if(type(value) == "table") then
				Serialize(value, sKey, hFile, sTab.."\t");
			else
				local sValue = (type(value) == "string") and string.format("%q", value) or tostring(value);
				hFile:write(sTab.."\t"..sKey.." = "..sValue);
			end
			hFile:write(",\n");
		end
	end
	hFile:write(sTab.."}");
end


Maybe not the best translated, but i think the most of you will understand it.

And to you Herman, hope you dont mind i translated it, its still your script and many thanks to you for creating it.

TZB

Is the conversion of script done using Lua Convertor?

Dreams

Not Converted, just translated from Swedish to English so that more people can use and enjoy this script.

TZB

What kind of changes you need in Right Click.
If you can give it in more details it can be done in minutes.

Dreams

If you look at the script there are these ---> Owners List, Check List and Check Info.
Under thoose three there are some buttons, would be nice if thoose buttons could be sorted by name.

TZB

#10
Those Unsorted Right Click options belonged to Check List According to me so added them up there.
The problem regarding the file getting saved under ptokax folder and Share Check i haven't come across it.May be you are using any Settings saving script and it makes a backup of all the .tbl file.
--[[

	ShareCheck 2.03 - LUA 5.11   [API 2]  by Herman
	???????????????????????????????????????
	To get control over what users share in Private Hubbs.
	
	--Content
		Best idea on which user to check at the moment.
		Info on when a users last got checked.
		Statistics and lists.
		And more...
	
	--Short help on how it works
		You can get a proposal on a user in the RC and put the user in "pulled".
		When the user is checked and done you put the user under "done".
		You can put a user under "check" if you dont have time right now but the users share has to be checked.
	
	-----------------------------------------
	1.01 - changelog
		added clean mem function
		changed some formating
		changed  the way to upgrade the sorted list
		fixed a few small bugs
		added some more things on show info on user
		added new RC "myinfo"
	-----------------------------------------
	-----------------------------------------
	1.02 - changelog
		added option to change opname
		added hub info
		fixed so exlude works on checked users
		some changes in myinfo
		formating and optimization
	-----------------------------------------
	2.01 - changelog
		upgrade to -API 2-
	-----------------------------------------
	2.02 - changelog
		Bugfix - forgott to upgrade a part
	-----------------------------------------
	2.03 - changelog
		Bugfix - To much copy and paste when upgrading
		Bugfix - Found a problem with makelist that should have happend in the future
		
	-----------------------------------------
	-------------------------------------------------
	---Not Added functions. maybe later--- 
	-------------------------------------------------
		RC remove "Done"
		cleanup of database
	----------------------------------------------
        
        13/04/2010
        Fixed Right Click Requested:Dreams By ||-T-z-B-||
]]--

tSettings = {

-- Bot Name
	sBot_I = "-Informer-",

	-- Who will get the errormessages
	AdminNick = "Herman",
	
	-- Max amount for the sorted list of users who will get checked. 
	-- 1000 should work for most. But if you have a really large hub (increase) or if you want to save resources (decrease) the amount of users in the list
	iMaxList = 1000,

	-- Day of start of the week check, if you have a requirement on the amount of filelists per week 
	-- (as a decimal number with Sunday as 0 (0-6) )
	iDay = 5,
	
	-- RightClick Menu
	sMenu = "?  Commands\\Share Check Commands",

	-- Directory for files
	filedir = "Sharecheck\\",
	
	-- User DB
	fuserDB = "tSC_user.tbl",
	
	-- OP DB
	fopDB = "tSC_op.tbl",
	
	-- Check DB
	fcheckDB = "tSC_check.tbl",
	
	-- Pulled DB
	fpulledDB = "tSC_pulled.tbl",
	
	-- Sorted List With Users Who Has To Get Checked
	flistDB = "tSC_list.tbl",
	
	-- Log with users that is done
	fdoneLOG = "tSC_done.log",
	
	-- Profils who will see admin commands.
	tAdminRCcmds = {[0] = 1, [1] = 0, [2] = 0, [3] = 0},
	
	-- Exlude people in the list of users to check = flistDB
	-- Profiles that will be exluded ( = 1 ) 
	tProfiles = { [0] = 1, [1] = 1, [2] = 0, [3] = 0 },
	
	-- User that will not be checked -- Use lowercase
	tUser = {[""] = 1,[""] = 1},
	
	-- Prefix that not will be checked -- Use lowercase
	tPrefix = {	
				"[Crew]",
				"[]"
						}
}

--===============================================================================================================
--     Edit below this on your own risk.                 No support if you do :P
--===============================================================================================================

-- username <> times checked, last check, op checked
tuserDB = {} --  ( iCounter, iTime, sOP )

-- opname <> filelist checked, first time checked, last week 
topDB = {} --( iCounter, iTime )

-- username <> op reported, time 
tcheckDB = {} --( iTime, sOP )

-- username <> op checked, time
tpulledDB = {} --( iTime, sOP )

-- username
tlistDB = {}

-- static numbers
statWeek = 604800
statDay = 86400
statHour = 3600

OnStartup = function()
	-- Register BotName if not registered
	if tSettings.sBot_I ~= SetMan.GetString(21) then Core.RegBot(tSettings.sBot_I,"","",true) end
	-- Load DB content
	--os.execute("mkdir "..tSettings.filedir)
	local r,e = os.rename("web","web")
	if e then
		if not e:find("Permission denied") then
			os.execute("mkdir "..tSettings.filedir)
		end
	end
	if loadfile(tSettings.filedir..tSettings.flistDB) then dofile(tSettings.filedir..tSettings.flistDB) end
	if loadfile(tSettings.filedir..tSettings.fpulledDB) then dofile(tSettings.filedir..tSettings.fpulledDB) end
	if loadfile(tSettings.filedir..tSettings.fcheckDB) then dofile(tSettings.filedir..tSettings.fcheckDB) end
	if loadfile(tSettings.filedir..tSettings.fuserDB) then dofile(tSettings.filedir..tSettings.fuserDB) end
	if loadfile(tSettings.filedir..tSettings.fopDB) then dofile(tSettings.filedir..tSettings.fopDB) end
	
	
	-- Make a sorted list of users who shall be checked if it not exist or is to small
	if not next(tlistDB) then
		MakeCheckList()
	end
end 

NewUserConnected = function(user)

	local tRealNick = GetRealNick(user.sNick,tpulledDB)
	if tRealNick then
		Core.SendPmToNick(tpulledDB[tRealNick].sOP, tSettings.sBot_I, "ShareCheck: User: "..user.sNick.." has connected. Can be found in your pulled")
	end
	
	--tAdmin = 1,
	--tAdminRCcmds = {[0]
	if Core.GetUserAllData(user) then
		-- Supports UserCommands
		if user.bUserCommand and user.bOperator then
			-- For each entry in table
			for i, v in pairs(tCommands) do
				-- If member
				if v.tAdmin == 1 then
					if tSettings.tAdminRCcmds[user.iProfile] == 1 then
						-- For each type
						for n in ipairs(v.tRC) do
							-- Send
							Core.SendToNick(user.sNick,"$UserCommand 1 3 "..tSettings.sMenu.."\\"..v.tRC[n][1]..
							"$<%[mynick]> !"..i..v.tRC[n][2].."&#124;")
						end
					end
				
				else
					for n in ipairs(v.tRC) do
						-- Send
						Core.SendToNick(user.sNick,"$UserCommand 1 3 "..tSettings.sMenu.."\\"..v.tRC[n][1]..
						"$<%[mynick]> !"..i..v.tRC[n][2].."&#124;")
					end
				end
			end
			for i, v in pairs(tCommands2) do
				-- If member
				if v.tAdmin == 1 then
					if tSettings.tAdminRCcmds[user.iProfile] == 1 then
						-- For each type
						for n in ipairs(v.tRC) do
							-- Send
							Core.SendToNick(user.sNick,"$UserCommand 1 3 "..tSettings.sMenu.."\\"..v.tRC[n][1]..
							"$<%[mynick]> !"..i..v.tRC[n][2].."&#124;")
						end
					end
				else
					for n in ipairs(v.tRC) do
						-- Send
						Core.SendToNick(user.sNick,"$UserCommand 1 3 "..tSettings.sMenu.."\\"..v.tRC[n][1]..
						"$<%[mynick]> !"..i..v.tRC[n][2].."&#124;")
					end
				end
			end
		end
	end
end

OpConnected = NewUserConnected

ChatArrival = function(user, data)
	local _,_, to = string.find(data, "^$To:%s(%S+)%s+From:")
	local _,_, msg = string.find(data, "%b<>%s(.*)|$") 
	-- Message sent to Bot or in Main
	if (to and to == tSettings.sBot_I) or not to then
		-- Parse command
		local _,_, cmd = string.find(msg, "^%p(%S+)")
		-- Exists
		if cmd and tCommands[string.lower(cmd)] then
			
			if Core.GetUserAllData(user) and user.bOperator then
			
				cmd, user.SendPM = string.lower(cmd), user.SendData
				-- PM
				if to == tSettings.sBot_I then user.SendPM = user.SendPM end
				
				if tCommands[cmd].tAdmin == 1 then
					if tSettings.tAdminRCcmds[user.iProfile] == 1 then
						return tCommands[cmd].fFunction(user, msg), true
					else
						return Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: You are not allowed to use this command!"), true
					end
				else
					return tCommands[cmd].fFunction(user, msg), true
				end
			else
				return Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: You are not allowed to use this command!"), true
			end
			
		elseif cmd and tCommands2[string.lower(cmd)] then
			if Core.GetUserAllData(user) and user.bOperator then
				cmd, user.SendPM = string.lower(cmd), user.SendData
				-- PM
				if to == tSettings.sBot_I then user.SendPM = user.SendPM end
				-- If user has permission
				if tCommands2[cmd].tAdmin == 1 then
					if tSettings.tAdminRCcmds[user.iProfile] == 1 then
						return tCommands2[cmd].fFunction(user, msg), true
					else
						return Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: You are not allowed to use this command!"), true
					end
					
				else
					return tCommands2[cmd].fFunction(user, msg), true
				end			
			else
				return Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: You are not allowed to use this command!"), true
			end
		end
	end
end

ToArrival = ChatArrival

tCommands2 = {
	suggestiononuser = {
		fFunction = function(user, data)
			--loops through check first to see if someone is online
			if next(tcheckDB) then
				for i, v in pairs(tcheckDB) do
					if Core.GetUser(i) then
						Core.SendPmToNick(user.sNick,tSettings.sBot_I, "ShareCheck: The most recommended user to check right now -->  "..i)
						Core.SendPmToNick(user.sNick,tSettings.sBot_I, "ShareCheck: Remember to add the user to the pulled list before you begin")
						return true
					end
				end
			end
			--if there is no hits in check list the other list loops through and takes the first person online
			if next(tlistDB) then
				for i = 1, table.maxn(tlistDB), 1 do
					if Core.GetUser(tlistDB[i]) then
						Core.SendPmToNick(user.sNick,tSettings.sBot_I, "ShareCheck: The most recommended user to check right now -->  "..tlistDB[i])
						Core.SendPmToNick(user.sNick,tSettings.sBot_I, "ShareCheck: Remember to add the user to the pulled list before you begin")
						return true
					end
				end
			end
			Core.SendPmToNick(user.sNick,tSettings.sBot_I, "ShareCheck: Has no one to recommend right now, but will update the database, so try again later.")
			MakeCheckList()
			
		end,
		tAdmin = 0,
		tRC = { { "Check List\\Best Idea On User To Check", "" } }
	},
	sharecheck = {
		fFunction = function(user, data)
			local _,_, nick,typ = string.find(data, "^%S+%s+(%S+)%s+(%S+)$")

			if nick and typ then
				
				if typ == "pulled" then
					if GetRealNick(nick,tpulledDB) then
						Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: "..nick.." is already in the pulled list.")
					else
					
						local sText = ""
						for i, v in pairs(RegMan.GetRegs()) do
							if string.lower(v.sNick)==string.lower(nick) then	
								tpulledDB[v.sNick] ={iTime=os.time(os.date("*t")),sOP=user.sNick}
								local hFile = io.open(tSettings.filedir..tSettings.fpulledDB, "w+") Serialize(tpulledDB, "tpulledDB", hFile); hFile:close()
								sText = "*** Was successful:"
							end
						end
						if sText == "" then
							Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Failed: "..nick.." isn't a registered user! Check the nick again")
						else
							Core.SendPmToNick(user.sNick, tSettings.sBot_I, "ShareCheck: Added "..nick.." to the pulled list")
							
							-- Remove the user from sorted check list
							if next(tlistDB) then
								for i = 1, table.maxn(tlistDB), 1 do
									if string.lower(tlistDB[i]) == string.lower(nick)  then
										--tlistDB[i] = nil
										table.remove (tlistDB , i)
										local hFile = io.open(tSettings.filedir..tSettings.flistDB, "w+") Serialize(tlistDB, "tlistDB", hFile); hFile:close()
										break
									end
								end
							end
							
							-- Remove the user from check
							local tRealNick = GetRealNick(nick,tcheckDB)
							if tRealNick then
								tcheckDB[tRealNick] = nil
								local hFile = io.open(tSettings.filedir..tSettings.fcheckDB, "w+") Serialize(tcheckDB, "tcheckDB", hFile); hFile:close()
							end
						end						
					end				
				elseif typ == "check"  then
					if GetRealNick(nick,tcheckDB) then
						Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: "..nick.." is already in the check list.")
					else	
						local sText = ""
						for i, v in pairs(RegMan.GetRegs()) do
							if string.lower(v.sNick)==string.lower(nick) then	
								tcheckDB[v.sNick] ={iTime=os.time(os.date("*t")),sOP=user.sNick}
								local hFile = io.open(tSettings.filedir..tSettings.fcheckDB, "w+") Serialize(tcheckDB, "tcheckDB", hFile); hFile:close()
								sText = "*** Was successful:"
							end
						end
						if sText == "" then
							Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Failed: "..nick.." isn't a registered user! Check the nick again")
						else
							Core.SendPmToNick(user.sNick, tSettings.sBot_I, "ShareCheck: Added "..nick.." to the check list")
						end						
					end
				elseif typ == "done" then	
					
-- Check if the user is avalible
					local iIsReg = 0
					for i, v in pairs(RegMan.GetRegs()) do
						if string.lower(v.sNick)==string.lower(nick) then		
						
							-- Add to done logfile
							local hFile = io.open(tSettings.filedir..tSettings.fdoneLOG, "a+")
							local tTime = os.time(os.date("*t"))
							
							hFile:write(os.date("%Y-%m-%d %H:%M ",tTime)..nick.." "..user.sNick.." ".."\r\n")
							hFile:close()					
							
							-- Remove the user from pulled
							local tRealNick = GetRealNick(nick,tpulledDB)
							if tpulledDB[tRealNick] then
								tpulledDB[tRealNick] = nil
								local hFile = io.open(tSettings.filedir..tSettings.fpulledDB, "w+") Serialize(tpulledDB, "tpulledDB", hFile); hFile:close()
							end
							
							-- Remove the user from check
							local tRealNick = GetRealNick(nick,tcheckDB)
							if tRealNick then
								tcheckDB[tRealNick] = nil
								local hFile = io.open(tSettings.filedir..tSettings.fcheckDB, "w+") Serialize(tcheckDB, "tcheckDB", hFile); hFile:close()
							end
							
							-- Remove the user from sorted check list
							if next(tlistDB) then
								for i = 1, table.maxn(tlistDB), 1 do
									if string.lower(tlistDB[i]) == string.lower(nick)  then
										--tlistDB[i] = nil
										table.remove (tlistDB , i)
										local hFile = io.open(tSettings.filedir..tSettings.flistDB, "w+") Serialize(tlistDB, "tlistDB", hFile); hFile:close()
										break
									end
								end
							end
							
							-- Add to stat to opDB
							local tRealNick = GetRealNick(user.sNick,topDB)
							if tRealNick then
								topDB[tRealNick].iCounter = topDB[tRealNick].iCounter + 1
							else
								topDB[user.sNick] ={iTime=os.time(os.date("*t")),iCounter = 1}
							end
							local hFile = io.open(tSettings.filedir..tSettings.fopDB, "w+") Serialize(topDB, "topDB", hFile); hFile:close()					
							
							
							-- Add to userDB
							local tRealNick = GetRealNick(nick,tuserDB)							
							if tRealNick then
								tuserDB[tRealNick].iTime = os.time(os.date("*t"))
								tuserDB[tRealNick].sOP = user.sNick
								tuserDB[tRealNick].iCounter = tuserDB[tRealNick].iCounter + 1
							else
								tuserDB[nick] ={iTime=os.time(os.date("*t")),sOP=user.sNick,iCounter = 1}
							end
							local hFile = io.open(tSettings.filedir..tSettings.fuserDB, "w+") Serialize(tuserDB, "tuserDB", hFile); hFile:close()
			
							-- Send info to all ops in main					
							Core.SendPmToOps(tSettings.sBot_I, "ShareCheck: "..user.sNick.." Added "..nick.." to the done list")
													-- 
							iIsReg = 1

						end
					end
					-- Check if the person excisted or not	
					if iIsReg == 0 then Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Failed: "..nick.." isn't a registered user! Check the nick again") end
						
					
				else
					Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Syntax Error: You have to choose \"pulled\" , \"done\" or \"check\" ")
				end
			else
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Syntax Error: No nickname or type")
			end
			--clean Memory
			CleanMem()
		end,
		tAdmin = 0,
		tRC = { { "Check List\\Add User", " %[line:Full Nickname] %[line:Type: pulled, done, check]" }, { "Check List\\Add This User", " %[nick] %[line:Type: pulled, done, check]" } }
	},
}


tCommands = {
	sc_showuser = {
		fFunction = function(user, data)
			-- Return
			local _,_, nick = string.find(data, "^%S+%s+(%S+)$")
		
			if nick then
			
				local msg = "\r\n\r"..string.rep("-", 60).."\r\nUserInfo For "..nick..":\r\n"..string.rep("-", 60).."\r\n"
				--msg = msg.."Username:      \t"..nick.."\r\n"
				
				
				local tRealNick = GetRealNick(nick,tuserDB)
				if tRealNick then
					msg = msg.."Last Check:    \t"..os.date("%Y-%m-%d %H:%M",tuserDB[tRealNick].iTime).."\r\n"
					msg = msg.."By Who:        \t"..tuserDB[tRealNick].sOP.."\r\n"
					msg = msg.."Times checked: \t"..tuserDB[tRealNick].iCounter.."\r\n"
				else
					msg = msg.."Last Check:    \tNever\r\n"
				end
					
				local tRealNick1 = GetRealNick(nick,tpulledDB)
				if tRealNick1 then
					msg = msg.."In \"Pulled\":      \tYes by "..tpulledDB[tRealNick1].sOP.."\r\n"
				else
					msg = msg.."In \"Pulled\":      \tNo\r\n"
				end
				local tRealNick2 = GetRealNick(nick,tcheckDB)
				if tRealNick2 then
					msg = msg.."In \"Check\": \tYes\r\n"
				else
					msg = msg.."In \"Check\": \tNo\r\n"
				end

				msg = msg..string.rep("-", 60)
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")

			end
		end,
		tAdmin = 0,
		tRC = { { "Check Info\\Show Info On A User", " %[line:Full Nickname]" }, { "Check Info\\Show Info On This User", " %[nick]" } }
	},
	sc_showinfo = {
		fFunction = function(user)
					
				local msg = "\r\n\r"..string.rep("=", 40).."\r\nInformation On "..user.sNick..":\r\n"..string.rep("=", 40).."\r\n"
				--msg = msg.."Username:      \t"..nick.."\r\n"

				
				local tRealNick = GetRealNick(user.sNick,topDB)
				if tRealNick then
					
					--Weeklists
					local tempDay = tonumber(os.date("%w"))
					if tSettings.iDay > tempDay then tempDay = tempDay + 7 end
					tempDay = tempDay - tSettings.iDay +7
					local tWList = WeekList(0,1,tRealNick)
					local tWListNow = WeekList(0,0,tRealNick)
					--If you havnt done one yet you have to fill the values
					if tWList[tRealNick] == nil then
						tWList[tRealNick]={iCounter=0,iUsers="no users"}
					end
					if tWListNow[tRealNick] == nil then
						tWListNow[tRealNick]={iCounter=0,iUsers="no users"}
					end
					--Average
					local iDays = (os.time(os.date("*t")) - topDB[tRealNick].iTime)/statDay
					local iAmount =string.format("%.2f", ((topDB[tRealNick].iCounter/iDays)*7))	
					

					--Pulled
					--local iCount = 0
					local sPulled ="\r\nPulled users:\r\n"
					for i, v in pairs(tpulledDB) do
						if string.lower(v.sOP)==string.lower(user.sNick) then
							sPulled = sPulled..os.date("%Y-%m-%d %H:%M",v.iTime).."\t"..i.."\r\n"
							--iCount = iCount + 1
						end
					end
			
					msg = msg.."First filelist checked at:      \t"..os.date("%Y-%m-%d",topDB[tRealNick].iTime).."\r\n"				
					msg = msg.."Amount of lists checked:      \t"..topDB[tRealNick].iCounter.."\r\n"
					msg = msg.."Average checked (week): \t"..iAmount.."\r\n\r\n"
					msg = msg.."Checked present week: \t"..tWListNow[tRealNick].iCounter.." st\r\n"
					msg = msg..tWListNow[tRealNick].iUsers.."\r\n\r"
					msg = msg.."Checked the last "..tempDay.." days: \t"..tWList[tRealNick].iCounter.." st\r\n"
					msg = msg..tWList[tRealNick].iUsers.."\r\n"
					msg = msg..sPulled..""
					
				else
					msg = msg.."Your not in the database. You have to add a done filelist first\r\n"
				end
					


				msg = msg..string.rep("-", 80)
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
				--clean Memory
				CleanMem()

			
		end,
		tAdmin = 0,
		tRC = { { "Check Info\\Show My Info", "" } }
	},
	sc_showhubinfo = {
		fFunction = function(user)
					
				local msg = "\r\n\r"..string.rep("=", 50).."\r\nStatistics On Filechecking Control In The Hub\r\n"..string.rep("=", 50).."\r\n"
				--msg = msg.."Username:      \t"..nick.."\r\n"

				
				
				--Amount checked
				--Average checked
				--First list checked
				--Amount of OP
				--OP whos checked the most - amount + name
				-----------------------------------------
				--Amount of users thats never been checked
				--The most checked user - amount + person
				--A users average times checked
				
				
			if next(topDB) then
				local iAchecked,iFirstChecked,iAmountOp,iMostOpAmount,sMostOp =0,0,0,0,""

				-- Loop through hubbers
				for i, v in pairs(topDB) do
					
					iAChecked = iAchecked + v.iCounter
					
					if iFirstChecked == 0 or v.iTime < iFirstChecked then
						iFirstChecked = v.iTime
					end
					
					iAmountOp = iAmountOp + 1
					
					if iMostOpAmount == 0 or v.iCounter > iMostOpAmount then
						iMostOpAmount = v.iCounter
						sMostOp = i
					end
					

				end
				
				-- Average
				local iDays = (os.time(os.date("*t")) - iFirstChecked)/statDay
				local iAverageAmount =string.format("%.1f", ((iAchecked/iDays)*7))	
						
				
				
				
				msg = msg.."First filelist checked at:      \t\t"..os.date("%Y-%m-%d",iFirstChecked).."\r\n"				
				msg = msg.."Amount of lists checked:      \t\t"..iAchecked.." st\r\n"
				msg = msg.."Average amount (week): \t\t"..iAverageAmount.." st\r\n"
				msg = msg.."Amount of OP that has checked lists:\t"..iAmountOp.." st\r\n"
				msg = msg.."OP whos checked the most lists: \t"..sMostOp.." , "..iMostOpAmount.." st\r\n\r\n"
				
				
				
				local iAUser,iUserChecked,iNotChecked,iMostChecked,sMostChecked,iAverage = 0,0,0,0,"",0
				
				for i, v in pairs(tuserDB) do
					
					iAUser = iAUser +1
					iUserChecked = iUserChecked + v.iCounter
					
					if iMostChecked == 0 or v.iCounter > iMostChecked then
						iMostChecked = v.iCounter
						sMostChecked = i
					end
				end
								
				iNotChecked = table.maxn(RegMan.GetRegs()) - iAUser
				iAverage = string.format("%.2f",iUserChecked/table.maxn(RegMan.GetRegs()))
				
				msg = msg.."Users thats been checked:\t\t"..iAUser.." st\r\n"
				msg = msg.."Users thats never been checked:\t"..iNotChecked.." st\r\n"
				msg = msg.."The most checked user: \t\t"..sMostChecked.." , "..iMostChecked.." ggr\r\n"
				msg = msg.."Amount of times users been checked:\t"..iAverage.." ggr\r\n"


					
			else
				msg = msg.."There is no OPdatabase\r\n"
			end
				
			msg = msg..string.rep("-", 100)
			Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
			--clean Memory
			CleanMem()
			
		end,
		tAdmin = 0,
		tRC = { { "Check Info\\Show Hub Info", "" } }
	},
	scop_delpulled = {
		fFunction = function(user, data)
			local _,_, nick = string.find(data, "^%S+%s+(%S+)$")
			
			if nick then
				local tRealNick = GetRealNick(nick,tpulledDB)
				if tRealNick then
					tpulledDB[tRealNick] = nil
					local hFile = io.open(tSettings.filedir..tSettings.fpulledDB, "w+") Serialize(tpulledDB, "tpulledDB", hFile); hFile:close()
					Core.SendPmToNick(user.sNick,tSettings.sBot_I, "ShareCheck: "..nick.." is removed from the pulled list")
				else
					Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: "..nick.." isn't found in the pulled list")
				end
			else
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Syntax Error: Add nickname")
			end
						
		end,
		tAdmin = 1,
		tRC = { { "Owners List\\Remove User From The Pulled List", " %[line:Nick]" } }
	},
	scop_delcheck = {
		fFunction = function(user, data)
			-- Return
			local _,_, nick = string.find(data, "^%S+%s+(%S+)$")
			if nick then
				local tRealNick = GetRealNick(nick,tcheckDB)
				if tRealNick then
						tcheckDB[tRealNick] = nil
						local hFile = io.open(tSettings.filedir..tSettings.fcheckDB, "w+") Serialize(tcheckDB, "tcheckDB", hFile); hFile:close()
						Core.SendPmToNick(user.sNick,tSettings.sBot_I, "ShareCheck: "..nick.." is removed from the check list")
				else
					Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: "..nick.." isn't found in the check list")
				end
			else
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Syntax Error: Add nickname")
			end
						
		end,
		tAdmin = 1,
		tRC = { { "Owners List\\Remove User From The Check List", " %[line:Nick]" } }
	},
	sc_donelist = {
		fFunction = function(user)
			local f = io.open(tSettings.filedir..tSettings.fdoneLOG,"r") --if f then f:close()
			if f then
				local msg = "\r\n\r"..string.rep("=", 47).."\r\nUsers That "..user.sNick.." Has Done\r\n"..string.rep("-", 94).."\r\n"
				msg = msg.."Checked At\tOP Who Added \tUser\r\n"..string.rep("-", 94).."\r\n"
				
				for line in f:lines() do
					local _,_, iTime,sUser,sOp = string.find(line, "(%S+%s%S+)%s(%S+)%s(%S+)")
					if string.lower(sOp) == string.lower(user.sNick) then
						msg = msg..iTime.."\t"..sOp.."  \t"..sUser.."\r\n"
					end
				end
				
				msg = msg..string.rep("-", 94)
				-- Send
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
							
				f:close()
			else
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: There's no done logfile")
			end
		end,
		tAdmin = 0,
		tRC = { { "Check List\\Users I Have Done", " %[Nick]" } }
	},
	sc_pulledlist = {
		fFunction = function(user, data)
			-- Table isn't empty
			if next(tpulledDB) then
				local _,_, tVar = string.find(data, "^%S+%s+(%S+)$")

				local msg = "\r\n\r"..string.rep("=", 47).."\r\nUsers In The Pulled List:\r\n"..string.rep("-", 94).."\r\n"
				msg = msg.."Added At\t\tOP Who Added\tUser\r\n"..string.rep("-", 94).."\r\n"	
				local tCopy ={}
				-- Loop through hubbers
				
				for i, v in pairs(tpulledDB) do
					-- Insert stats to temp table
					if tVar == "me" and string.lower(v.sOP)==string.lower(user.sNick) then
						table.insert(tCopy, { sUser = i, iTime = v.iTime, sOP =v.sOP } )
					elseif tVar == "all" then
						table.insert(tCopy, { sUser = i, iTime = v.iTime, sOP =v.sOP } )
					end
				end
				-- Sort by total time
				table.sort(tCopy, function(a, b) return (a.iTime < b.iTime) end)
				-- Loop through temp table
				
				for i, v in pairs(tCopy) do
					msg = msg..os.date("%Y-%m-%d %H:%M",v.iTime).."\t"..v.sOP.."  \t"..v.sUser.."\r\n"
				end
						
				msg = msg..string.rep("-", 94)
				-- Send
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
			else
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: Pulled list is empty")
			end
		end,
		tAdmin = 0,
		tRC = { { "Check List\\All Users Whos Filelists Has Been Pulled", " all" }, { "Check List\\All Users Whos Filelists I Have Pulled", " me" } }
	},
	sc_checklist = {
		fFunction = function(user)
			-- Table isn't empty
			if next(tcheckDB) then

				local msg = "\r\n\r"..string.rep("=", 47).."\r\nUsers In The Check List:\r\n"..string.rep("-", 94).."\r\n"
				msg = msg.."Added At\t\tUser\t\tOP Who Added\r\n"..string.rep("-", 94).."\r\n"	
				local tCopy ={}
				-- Loop through hubbers
				
				for i, v in pairs(tcheckDB) do
					-- Insert stats to temp table
					table.insert(tCopy, { sUser = i, iTime = v.iTime, sOP =v.sOP } )
				end
				-- Sort by total time
				table.sort(tCopy, function(a, b) return (a.iTime < b.iTime) end)
				-- Loop through temp table
				
				for i, v in pairs(tCopy) do
					msg = msg..os.date("%Y-%m-%d %H:%M",v.iTime).."\t"..v.sUser.."\t"..v.sOP.."\r\n"
				end
						
				msg = msg..string.rep("-", 94)
				-- Send
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
			else
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: Check list is empty")
			end
		end,
		tAdmin = 0,
		tRC = { { "Check List\\Users Who Has To Be Checked", "" } }
	},
	sc_toplist = {
		fFunction = function(user)
			if next(topDB) then

				local msg = "\r\n\r"..string.rep("=", 40).."\r\nTop Filelist Checker:\r\n"..string.rep("-", 80).."\r\n"
				msg = msg.."Amount\t\tOp\r\n"..string.rep("-", 80).."\r\n"	
				local tCopy ={}
				-- Loop through hubbers
				for i, v in pairs(topDB) do
					-- Insert stats to temp table
					table.insert(tCopy, { sOp = i, iAmount = v.iCounter } )
				end
				-- Sort by total time
				table.sort(tCopy, function(a, b) return (a.iAmount > b.iAmount) end)
				-- Loop through temp table
				for i, v in pairs(tCopy) do
					msg = msg..""..v.iAmount.."\t\t"..v.sOp.."\r\n"
				end
						
				msg = msg..string.rep("-", 80)
				-- Send
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
			else
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: There is no OPstats list")
			end
		end,
		tAdmin = 0,
		tRC = { { "Check List\\Total Amount Done", "" }}
	},
	scop_donelistowner = {
		fFunction = function(user, data)
			local _,_, nick = string.find(data, "^%S+%s+(%S+)$")
			if nick then
				local f = io.open(tSettings.filedir..tSettings.fdoneLOG,"r")
				if f then
					local msg = "\r\n\r"..string.rep("=", 47).."\r\nUsers Who Is Done\r\n"..string.rep("-", 94).."\r\n"
					msg = msg.."Checked At\tOP Who Added\tUser\r\n"..string.rep("-", 94).."\r\n"
					
					if nick == "all" then
						for line in f:lines() do
							local _,_, iTime,sUser,sOp = string.find(line, "(%S+%s%S+)%s(%S+)%s(%S+)")
							msg = msg..iTime.."\t"..sOp.."\t"..sUser.."\r\n"
						end			
					else
						for line in f:lines() do
							local _,_, iTime,sUser,sOp = string.find(line, "(%S+%s%S+)%s(%S+)%s(%S+)")
							if string.lower(sOp) == string.lower(nick) then
								msg = msg..iTime.."\t"..sOp.."\t"..sUser.."\r\n"
							end
						end
					end
					msg = msg..string.rep("-", 94)
					-- Send
					Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
								
					f:close()
				else
					Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: There is no done logfile")
				end
			end
		end,
		tAdmin = 1,
		tRC = { { "Owners List\\Show Users An OP Done", " %[line:OpNick]" }, { "Owners List\\Show All Done Users", " all" } }
	},
	scop_toplistaverage = {
		fFunction = function(user)
			-- Table isn't empty
			if next(topDB) then

				local msg = "\r\n\r"..string.rep("=", 40).."\r\nAverage Per Week:\r\n"..string.rep("-", 80).."\r\n"
				msg = msg.."Average\tOP\r\n"..string.rep("-", 80).."\r\n"	
				local tCopy ={}
				
				 --iCounter, iTime )
				local iNow = os.time(os.date("*t"))
				local iDays, iAmount
				 -- Loop through hubbers
				for i, v in pairs(topDB) do
				
					iDays = (iNow - v.iTime)/statDay
					iAmount =string.format("%.2f", ((v.iCounter/iDays)*7))	
				
				
					--iWeeks = math.ceil((iNow - v.iTime)/statWeek)
					--iAmount =string.format("<%.2f>", (v.iCounter/iWeeks))	
					
					--local _,_,iAmount = string.find((v.iCounter/iWeeks),"(%d+%.?%d?)")
							
					
					
					
					-- Insert stats to temp table
					table.insert(tCopy, { sOp = i, iAverage = tonumber(iAmount) } )
				end
				-- Sort by total time
				table.sort(tCopy, function(a, b) return (a.iAverage > b.iAverage) end)
				-- Loop through temp table
				
				for i, v in pairs(tCopy) do
					msg = msg..""..v.iAverage.."\t"..v.sOp.."\r\n"
				end
						
				msg = msg..string.rep("-", 80)
				-- Send
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
			else
				Core.SendPmToNick(user.sNick, tSettings.sBot_I, "*** Error: There is no one in the OPstats list")
			end
		end,
		tAdmin = 1,
		tRC = { { "Owners List\\Show The Average Amount Of Checked Users", "" }}
	},
	scop_weeklist = {
		fFunction = function(user, data)
			local _,_, tNumber = string.find(data, "^%S+%s+(%d+)$")
			local _,_, tStartW,tStopW = string.find(data, "^%S+%s+(%d+)%-(%d+)$")
			if tNumber or tStartW then		

					
					-- check what weeks user want to see
					local iStartWeek,iStopWeek
						
					if tStartW then
						iStartWeek = tStartW
						iStopWeek = tStopW
						tNumber = tStartW.."-"..tStopW
					else
						iStartWeek = tNumber
						iStopWeek = tNumber
					end				
					
					local tWList = WeekList(iStartWeek,iStopWeek,nil)
					
					-- Printing the list
					local msg = "\r\n\r"..string.rep("=", 30).."\r\nShow Info On The Week/Weeks: "..tNumber.."\r\n"..string.rep("=", 30).."\r\n"
					for i, v in pairs(tWList) do
						msg = msg..""..i.." has done "..v.iCounter.." users.\r\n\r\n"..v.iUsers.."\r\n"..string.rep("-", 60).."\r\n"
					end
					
					Core.SendPmToNick(user.sNick, tSettings.sBot_I, msg.."\r\n")
					tWList ={}

			end
		end,
		tAdmin = 1,
		tRC = {{ "Owners List\\Show How Many Users Is Done - A Week", " %[line:0=present, 1=former, 0-4=several weeks]" } }
	},
}

MakeCheckList = function()
	local iCounter = 0
	local tBol
	tlistDB = {}

	for i, v in pairs(RegMan.GetRegs()) do
		--not checked before
		if not GetRealNick(v.sNick,tuserDB) then
			-- allowed profile
			if tSettings.tProfiles[v.iProfile] and tSettings.tProfiles[v.iProfile] == 1 then

			else
			--allowed user
				if not tSettings.tUser[string.lower(v.sNick)] then
					--allowed prefix 
					tBol = 0
					for key, tFix in pairs(tSettings.tPrefix) do
						if string.sub(string.lower(v.sNick),1,string.len(tFix)) == string.lower(tFix) then
							tBol = 1
						end
					end				
					if tBol == 0 then
					
						table.insert(tlistDB,v.sNick)
						iCounter = iCounter + 1
						
						if iCounter >= tSettings.iMaxList then 
							break
						end
					end		
				end
			end
		end
	end


	if iCounter < tSettings.iMaxList then 
		local tCopy = {}
		for i, v in pairs(tuserDB) do		
			if not tSettings.tUser[string.lower(i)] then
				--allowed prefix 
				tBol = 0
				for key, tFix in pairs(tSettings.tPrefix) do
					if string.sub(string.lower(i),1,string.len(tFix)) == string.lower(tFix) then
						tBol = 1
					end
				end				
				if tBol == 0 then
					table.insert(tCopy, { sUser = i, iTime = v.iTime} )
				end
			end
		end
		-- Sort by total time
		table.sort(tCopy, function(a, b) return (a.iTime < b.iTime) end)
		-- Loop through temp table
		for i = 1, table.maxn(tCopy), 1 do
			-- i exists
			if tCopy[i] then
				-- Populate
				table.insert(tlistDB,tCopy[i].sUser)
				iCounter = iCounter + 1
				if iCounter >= tSettings.iMaxList then 
					break
				end
			end
		end	
		tCopy = {}
	end
	--save the list
	local hFile = io.open(tSettings.filedir..tSettings.flistDB, "w+") Serialize(tlistDB, "tlistDB", hFile); hFile:close()
	CleanMem()
end


function WeekList(startw,stopw,user)
	local tTempW = {}
	local f = io.open(tSettings.filedir..tSettings.fdoneLOG,"r") --if f then f:close()
	if f then
		-- calculate time in seconds to the last "check time"
		local iNow = os.time(os.date("*t"))
		local tempDay = tonumber(os.date("%w",iNow))
		if tSettings.iDay > tempDay then tempDay = tempDay + 7 end
		tempDay = tempDay - tSettings.iDay
		local iDiffSec = tempDay*statDay + os.date("%H",iNow)*statHour + os.date("%M",iNow)*60 + os.date("%S",iNow)
		local iCheckStart = iNow - iDiffSec
			
		for line in f:lines() do
			local _,_, iY,iM,iD,iMin,iS,sUser,sOp = string.find(line, "(%d+)%-(%d+)%-(%d+)%s(%d+)%:(%d+)%s(%S+)%s(%S+)")
			
			if user and string.lower(user) == string.lower(sOp) or not user then 
			
				local iTime = os.time({ year = iY, month = iM, day = iD, hour = iH, min = iMin, sec = iS})
				local iStop = iCheckStart - (statWeek*stopw)    
				local iStart = iCheckStart - (statWeek*startw) + statWeek            
						
				if tonumber(iTime) < tonumber(iStart) and tonumber(iTime) > tonumber(iStop) then
					if tTempW[sOp] then
						tTempW[sOp].iCounter=tTempW[sOp].iCounter+1
						tTempW[sOp].iUsers=tTempW[sOp].iUsers..sUser.." , "
					else
						tTempW[sOp]={iCounter=1,iUsers=sUser.." , "}
					end
				end
			end
		end
		f:close()
	end	
	return tTempW

end

-- Clean the memory
function CleanMem()
	collectgarbage()
	io.flush()
end

OnError = function(msg)
	Core.SendPmToNick("Herman", tSettings.sBot_I ,"<"..tSettings.sBot_I.."> "..msg)
	Core.SendPmToNick(tSettings.AdminNick, tSettings.sBot_I ,"<"..tSettings.sBot_I.."> "..msg)
	--OnError("----")
end

GetRealNick = function(user,db)
	-- For each hubber
	for i, v in pairs(db) do
		-- Compare
		if string.lower(i) == string.lower(user) then
			-- Return
			return i
		end
	end
end

Serialize = function(tTable, sTableName, hFile, sTab)
	sTab = sTab or "";
	hFile:write(sTab..sTableName.." = {\n");
	for key, value in pairs(tTable) do
		if (type(value) ~= "function") then
			local sKey = (type(key) == "string") and string.format("[%q]", key) or string.format("[%d]", key);
			if(type(value) == "table") then
				Serialize(value, sKey, hFile, sTab.."\t");
			else
				local sValue = (type(value) == "string") and string.format("%q", value) or tostring(value);
				hFile:write(sTab.."\t"..sKey.." = "..sValue);
			end
			hFile:write(",\n");
		end
	end
	hFile:write(sTab.."}");
end

Dreams

#11
Yes, im using automatic configuration saver and i will check if it is that one who is doing that.
When you posted the script, you did a lot of spaces and other stuff, cause there are a lot of syntax errors in the script now. =)

tested it but it wasnt the config saver script that did it.. and i saw that it was created on ptokax startup to, dont really know why

TZB

Yep. My bad Pasted directly from notebook. Now edited the above post try again.

Dreams

This time it works without syntax errors, but cant se that its sorted by name and i have double of everything in the rc now =)

TZB

Please Check your script again i am using the same script i have no issues.

Dreams

Dont know why but i did get it to work without double in the rc, but it still isnt sorted by name, and the add user,add this user and best idea on user to check is put under Check list button.

TZB

Sorted By name? Please provide a clear idea of where exactly you want what king of commands.

Dreams

As i said before but i will do it more detailed this time.

Share Check Commands
                             Owners List
                                       Show Users An OP Done
                                                 Show All Done Users         and so on...

                             Check List
                                       Users I Have Done
                                                 Users Who Has To Be Checked         and so on...   

                             Check Info
                                      Show My Info
                                                Show Hub Info         and so on...


I want those with bold text to be sorted by name..
that was all, except for the fix for the tSC_list i requested.. =)

Dreams

Anyone up for the challenge?

TZB

Well it's not a challenge.
You can Do it yourself.
QuoteCore.SendToNick(user.sNick,"$UserCommand 1 3 "..tSettings.sMenu.."\\"..v.tRC[n][1]..
                     "$<%[mynick]> !"..i..v.tRC[n][2].."&#124;")
Here it Sends The Right Click using Settings Menu and "RC"
And here after every command RC is defined eg.
QuotetRC = { { "Check List\\Best Idea On User To Check", "" } }

Dreams

#20
well, i dont know what to change it into too make it sort by name.. that my problem :) what lines to change into what.

If i could get helpt with that, it would be great. =)

SMF spam blocked by CleanTalk