Attachment 'CleanReg_API2.lua'

Download

   1 --[[
   2 
   3 	CleanReg 1.1 LUA 5.1x [Strict] [API 2]
   4 	By Mutor	01/18/08
   5 	Requested by Gnuff™
   6 	translated by KauH
   7 
   8 	×èñòêà ðåãèñòðàöèé çàðåãèñòðèðîâàííûõ þçåðîâ äëÿ API2
   9 	*Óäàëåíèå àêêàóíòîâ þçåðîâ ïîñëå 'x' äíåé of inactivity.
  10 
  11 	-íàñòðîéêè èíòåðâàëà äëÿ ïðîôèëÿ
  12 	-èñêëþ÷åíèå äëÿ íèêà
  13 	-êîíòåêñòíîå ìåíþ [right click]
  14 	-îïöèÿ äëÿ ñîîáùåíèé òîëüêî â ëè÷êó
  15 	-ðåïîðò OpNick èëè Îï×àò
  16 	-Äàííûå ñêðèïòà ñîõðàíÿþòñÿ â ôàéë ïðè ïåðåçàãðóçêå õàáà/ñêðèïòà
  17 	-Non-excluded users are reminded of account purge time at disconnect.
  18 
  19 	+èçìåíåíèÿ îò âåðñèè 1.0	10/10/08
  20 		+Äîáàâëåíû êîìàíäû / îñòàâøååñÿ âðåìÿ ðåãèñòðàöèè þçåðà / îñòàâøååñÿ âðåìÿ ðåãèñòðàöèè âñåõ þçåðîâ  by quicky2g
  21 
  22 ]]
  23 
  24 -- -- "èìÿáîòà" ["" = áîò õàáà]
  25 local Bot = ""
  26 -- Íèê äëÿ ðåïîðòà ["" = â îï÷àò]
  27 local ReportNick = ""
  28 -- Åñëè  true  òî òîëüêî â ëè÷êó
  29 local PmOnly = false
  30 -- User data
  31 local File = "RegUser.dat"
  32 -- Excluded nicks
  33 local ExcFile = "ExcUser.dat"
  34 -- Profile data
  35 local ProfFile = "Profiles.dat"
  36 -- Command prefix ["" = first char set in PtokaX]
  37 local Prefix = ""
  38 -- Èíòåðâàë [â ìèíóòàõ] äëÿ ïðîâåðêè þçåðîâ
  39 local Mins = 30
  40 -- Èíòåðâàë ðåãèñòðàöèè [â äíÿõ] äî òîãî êàê þçåð óäàëèòñÿ èç ñïèñêà çàðåãèñòðèðîâàííûõ þçåðîâ [0 = disable]
  41 -- [#] = days,
  42 local Profiles  = {
  43 	[0] = 365,	--Master
  44 	[1] = 180,	--Operator
  45 	[2] = 90,	--VIP
  46 	[3] = 30,	--Registered User
  47 	[4] = 180,	--Server
  48 	}
  49 
  50 -- Íèê,ïàðîëü è ïðîôèëü äëÿ òåñòèðîâàíèÿ ôóíêöèé ñêðèïòà [óêàæèòå TestNick = "" äëÿ âûêëþ÷åíèÿ]
  51 local TestNick,TestPass,TestProf = "","",3 --"TestNick","Password",3
  52 --//--
  53 
  54 local Cmds,Tmr = {},0
  55 OnStartup = function()
  56 	local chg
  57 	Mins = math.max(Mins,1)
  58 	Tmr = TmrMan.AddTimer(Mins*60000)
  59 	if Bot == "" then Bot = SetMan.GetString(21) end
  60 	if Prefix == "" then Prefix = SetMan.GetString(29):sub(1,1) end
  61 	local Path = Core.GetPtokaXPath().."scripts/"
  62 	if not ProfFile:find("^"..Path,1,true) then ProfFile = Path..ProfFile end
  63 	if loadfile(ProfFile) then dofile(ProfFile) else SaveFile(ProfFile,Profiles,"Profiles") end
  64 	if not ExcFile:find("^"..Path,1,true) then ExcFile = Path..ExcFile end
  65 	if loadfile(ExcFile) then dofile(ExcFile) else Exclude = {"NewUser"} SaveFile(ExcFile,Exclude,"Exclude") end
  66 	if not File:find("^"..Path,1,true) then File = Path..File end
  67 	if loadfile(File) then
  68 		dofile(File)
  69 	else
  70 		RegUsers = {}
  71 		local tab,t = RegMan.GetRegs(),os.time()
  72 		if next(tab) then
  73 			for _,user in ipairs(tab) do
  74 				local p,i,n = user.iProfile,Profiles[user.iProfile],user.sNick
  75 				if not Exclude[n] then if i and i > 0 then RegUsers[n] = {t,p} chg = true end end
  76 			end
  77 		end
  78 	end
  79 	for k,v in pairs(RegUsers) do if not RegMan.GetReg(k) then RegUsers[k] = nil chg = true end end
  80 	if TestNick:len() > 0 then
  81 		local usr,pwd,prf,tm = TestNick,TestPass,TestProf,(os.time() - ((Profiles[TestProf]+1)*86400))
  82 		if not RegMan.GetReg(TestNick) then RegMan.AddReg(usr,pwd,prf) RegUsers[usr] = {tm,prf} chg = true end
  83 	end
  84 	if chg then SaveFile(File,RegUsers,"RegUsers") end
  85 	OnTimer(Tmr)
  86 end
  87 
  88 OnExit = function()
  89 	SaveFile(File,RegUsers,"RegUsers")
  90 end
  91 
  92 ChatArrival = function(user,data)
  93 	local _,_,cmd = data:find("^%b<> ["..SetMan.GetString(29).."](%a+)")
  94 	if cmd then
  95 		cmd = cmd:lower()
  96 		if Cmds[cmd] and Cmds[cmd][2][user.iProfile] then
  97 			return Core.SendToUser(user,"<"..Bot.."> "..Cmds[cmd][1](user,data,cmd).."|"),true
  98 		end
  99 	end
 100 end
 101 
 102 OnTimer = function(Id)
 103 	if Id == Tmr then
 104 		local cur,cnt,ru,chg = os.time(),0,#RegMan.GetRegs()
 105 		for key,tab in pairs(RegUsers) do
 106 			local user = Core.GetUser(key)
 107 			if user then
 108 				if Profiles[user.iProfile] then
 109 					if not RegMan.GetReg(user.sNick) then
 110 						RegUsers[user.sNick] = nil
 111 					else
 112 						RegUsers[user.sNick] = {os.time(),user.iProfile}
 113 					end
 114 				end
 115 			else
 116 				local td = os.difftime(os.time(),tab[1])/86400
 117 				if Profiles[tab[2]] > 0 and td > Profiles[tab[2]] then
 118 					cnt = cnt + 1
 119 					Report(key.." íå ïîñåùàë õàá â òå÷åíèè "..Profiles[tab[2]]..
 120 					" äíåé. ("..string.format("%.0f",(td))..")  "..key..
 121 					" áûë óäàë¸í èç ñïèñêà çàðåãèñòðèðîâàííûõ þçåðîâ.")
 122 					RegMan.DelReg(key)
 123 					RegUsers[key] = nil
 124 					chg = true
 125 				end
 126 			end
 127 		end
 128 		if chg then
 129 			SaveFile(File,RegUsers,"RegUsers")
 130 			Report(tostring(cnt).." èç "..tostring(ru).." áûë óäàë¸í èç ñïèñêà çàðåãèñòðèðîâàííûõ þçåðîâ çà <"..
 131 			string.format("%.2f seconds.",os.difftime(os.time(),cur)+.01))
 132 		end
 133 	end
 134 end
 135 
 136 UserConnected = function(user,data)
 137 	if Profiles[user.iProfile] and Profiles[user.iProfile] > 0 and not Exclude[user.sNick] then
 138 		if RegUsers[user.sNick] then
 139 			local td = os.difftime(os.time(),RegUsers[user.sNick][1])/86400
 140 			if td >= 1 then
 141 				Core.SendToUser(user,"<"..Bot.."> Hey "..user.sNick..
 142 				", we've missed you for the last "..td.." days.|")
 143 			end
 144 		end
 145 		RegUsers[user.sNick] = {os.time(),user.iProfile}
 146 		SaveFile(File,RegUsers,"RegUsers")
 147 	end
 148 	local s,h  = "","Ìåíþ õàáà"
 149 	for i,v in pairs(Cmds) do
 150 		if v[2][user.iProfile] then
 151 			local d,a = v[3][1],v[3][2]
 152 			s = s.."$UserCommand 1 1 "..h.."\\×èñòêà ðåãèñòðàöèé\\"..
 153 			d.."$<%[mynick]> "..Prefix..i..a.."&#124;|"
 154 		end
 155 	end
 156 	if s:len() > 0 then Core.SendToUser(user,s) end
 157 end
 158 OpConnected,RegConnected = UserConnected,UserConnected
 159 
 160 UserDisconnected = function(user,data)
 161 	if Profiles[user.iProfile] and Profiles[user.iProfile] > 0 and not Exclude[user.sNick] then
 162 		local t = os.date("%c",os.time() + (86400 * Profiles[user.iProfile]))
 163 		Core.SendToUser(user,"<"..Bot.."> Äî Ñâèäàíèÿ  "..user.sNick..". Âàøà ðåãèñòðàöèÿ "..
 164 		"áóäåò àêòèâíà åù¸ "..Profiles[user.iProfile].." äíåé.|")
 165 		Core.SendToUser(user,"<"..Bot.."> After which it will be purged, be sure to return before "..t.."|")
 166 		RegUsers[user.sNick] = {os.time(),user.iProfile}
 167 		SaveFile(File,RegUsers,"RegUsers")
 168 	end
 169 end
 170 RegDisconnected,OpDisconnected = UserDisconnected,UserDisconnected
 171 
 172 Report = function(msg)
 173 	if ReportNick:len() > 0 then
 174 		local op = Core.GetUser(ReportNick)
 175 		if msg and op then
 176 			if PmOnly then
 177 				Core.SendPmToUser(op,Bot,msg.."|")
 178 			else
 179 				Core.SendToUser(op,"<"..Bot.."> "..msg.."|")
 180 			end
 181 		end
 182 	end
 183 end
 184 
 185 Cmds = {
 186 	excuser = {function(user,data,cmd)
 187 		if user then
 188 			local _,_,nick = data:find("^%b<> %S+ (%S+)|")
 189 			if nick then
 190 				if RegMan.GetReg(nick) then
 191 					for i,v in ipairs(Exclude) do
 192 						if nick:lower() == v:lower() then
 193 							table.remove(Exclude,i)
 194 							SaveFile(ExcFile,Exclude,"Exclude")
 195 							return nick.." èñêëþ÷¸í èç èñêëþ÷åíèé."
 196 						end
 197 					end
 198 					table.insert(Exclude,nick)
 199 					SaveFile(ExcFile,Exclude,"Exclude")
 200 					return nick.." âêëþ÷¸í â èñêëþ÷åíèÿ."
 201 				else
 202 					return " Îøèáêà ! Èñïîëüçóéòå: "..Prefix..cmd.." <çàðåãèñòðèðîâàííûé íèê>"
 203 				end
 204 			else
 205 				return " Îøèáêà ! Èñïîëüçóéòå: "..Prefix..cmd.." <íèê>"
 206 			end
 207 		end
 208 	end,{[-1] = false,[0] = true,[1] = true,[2] = false,[3] = false,[4] = true},
 209 	{"Èñêëþ÷åíèÿ / âêëþ÷èòü â èñêëþ÷åíèÿ"," %[line:Ââåäèòå íèê]"}
 210 	},
 211 	usertime = {function(user,data,cmd)
 212 		if user then
 213 			local _,_,nick = data:find("^%b<> %S+ (%S+)|")
 214 			if nick then
 215 				if RegUsers[nick] then
 216 					local remaining = Convert(RegUsers[nick][1] + (86400 * Profiles[RegUsers[nick][2]]))
 217 					return " Îñòàâøååñÿ âðåìÿ ðåãèñòðàöèè  "..nick..": "..remaining
 218 				else
 219 					return " Îøèáêà ! íèê "..nick.." íå íàéäåí."
 220 				end
 221 			else
 222 				return " Îøèáêà ! Èñïîëüçóéòå: "..Prefix..cmd.." <íèê>"
 223 			end
 224 		end
 225 	end,{[-1] = false,[0] = true,[1] = true,[2] = false,[3] = false,[4] = true},
 226 	{"Ïîêàçàòü îñòàâøååñÿ âðåìÿ ðåãèñòðàöèè þçåðà"," %[line:Ââåäèòå íèê]"}
 227 	},
 228 	regtimes = {function(user,data,cmd)
 229 		if user then
 230 			if RegUsers ~= {} then
 231 				local s = ""
 232 				for nick,tab in pairs(RegUsers) do
 233 					local remaining = Convert(tab[1] + (86400 * Profiles[tab[2]]))
 234 					s = s.."\t"..string.format("%-30.50s",nick).."\t\t\t"..remaining.."\r\n"
 235 				end
 236 				if s ~= "" then
 237 					return "\r\n\r\n\tÎñòàâøååñÿ âðåìÿ ðåãèñòðàöèè:\r\n\r\n"..s
 238 				end
 239 			else
 240 				return " Íåò þçåðîâ â ñïèñêå."
 241 			end
 242 		end
 243 	end,{[-1] = false,[0] = true,[1] = true,[2] = false,[3] = false,[4] = true},
 244 	{"Ïîêàçàòü îñòàâøååñÿ âðåìÿ ðåãèñòðàöèè âñåõ þçåðîâ",""}
 245 	},
 246 	setprof = {function(user,data,cmd)
 247 		local _,_,pnumb,days = data:find("^%b<> ["..SetMan.GetString(29).."]"..cmd.." (%d+) (%d+)|")
 248 		if pnumb and days then
 249 			if not Profiles[tonumber(pnumb)] then
 250 				return " Îøèáêà ! "..pnumb.." íåïðàâèëüíûé íîìåð ïðîôèëÿ."
 251 			else
 252 				local x,p = Profiles[tonumber(pnumb)],ProfMan.GetProfile(tonumber(pnumb)).sProfileName
 253 				Profiles[tonumber(pnumb)] = tonumber(days)
 254 				SaveFile(ProfFile,Profiles,"Profiles")
 255 				return p.."'s âðåìÿ ÷èñòêè óñïåøíî èçìåíåíî ñ "..x.." íà "..days.." äíåé."
 256 			end
 257 		else
 258 			return " Îøèáêà ! Èñïîëüçóéòå: "..Prefix..cmd.." <íîìåð ïðîôèëÿ> <êîë-âî äíåé>"
 259 		end
 260 	end,{[-1] = false,[0] = true,[1] = false,[2] = false,[3] = false,[4] = false},
 261 	{"Óñòàíîâêà âðåìåíè ÷èñòêè ïðîôèëÿ"," %[line:Íîìåð ïðîôèëÿ] %[line:Èíòåðâàë â äíÿõ]"}
 262 	},
 263 }
 264 
 265 Convert = function(time)
 266 	if time then
 267 		local s,x,n = "",0,os.time()
 268 		local tab = {{31556926,"ëåò"},{2592000,"ìåñÿöà"},{604800,"íåäåëè"},
 269 		{86400,"äíåé"},{3600,"÷àñîâ"},{60,"ìèíóò"},{1,"ñåêóíä"}}
 270 		if time > 0 then
 271 			if time < 2145876659 then
 272 				if n > time then
 273 					time = n - time
 274 				elseif n < time then
 275 					time = time - n
 276 				end
 277 				for i,v in ipairs(tab) do
 278 					if time > v[1] then
 279 						x = math.floor(time/v[1])
 280 						if x > 1 then v[2] = v[2].."" end
 281 						if x > 0 then
 282 							s = s..x.." "..v[2]..", "
 283 							time = time-x*v[1]
 284 						end
 285 					end
 286 				end
 287 				collectgarbage("collect")
 288 				return s:sub(1,-3)
 289 			else
 290 				return " Íåïðàâèëüíûå äàòà èëè âðåìÿ. [äîëæíî áûòü äî 12/31/2037]"
 291 			end
 292 		else
 293 			return " Íåïðàâèëüíûå äàòà èëè âðåìÿ. [äîëæíî áûòü ïîñëå 01/01/1970]"
 294 		end
 295 	else
 296 		return " Íåïðàâèëüíûå äàòà èëè âðåìÿ."
 297 	end
 298 end
 299 
 300 Serialize = function(tTable, sTableName, hFile, sTab)
 301 	sTab = sTab or "";
 302 	hFile:write(sTab..sTableName.." = {\n" )
 303 	for key, value in pairs(tTable) do
 304 		local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key)
 305 		if(type(value) == "table") then
 306 			Serialize(value, sKey, hFile, sTab.."\t")
 307 		else
 308 			local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value)
 309 			hFile:write( sTab.."\t"..sKey.." = "..sValue)
 310 		end
 311 		hFile:write( ",\n")
 312 	end
 313 	hFile:write( sTab.."}")
 314 end
 315 
 316 SaveFile = function(file,table, tablename )
 317 	local hFile = io.open (file , "wb")
 318 	Serialize(table, tablename, hFile)
 319 	hFile:close()
 320 	collectgarbage("collect")
 321 end

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-12-23 18:07:56, 10.4 KB) [[attachment:CleanReg_API2.lua]]
  • [get | view] (2009-12-23 18:59:52, 7.0 KB) [[attachment:RegBot.by.NRJv.1.2_api2.lua]]
  • [get | view] (2009-12-23 18:38:41, 66.5 KB) [[attachment:RegMe_v1.5.lua]]
  • [get | view] (2009-12-23 18:42:58, 12.0 KB) [[attachment:Registration.v2.0.lua]]
  • [get | view] (2009-12-23 17:59:58, 7.9 KB) [[attachment:Registrator_1.00_beta.rar]]
  • [get | view] (2009-12-23 19:19:13, 8.3 KB) [[attachment:_NewAPI_RegBot.zip]]
  • [get | view] (2009-12-23 19:09:47, 4.2 KB) [[attachment:reguser.zip]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.