LogBot 1.0d LUA 5.1x [Strict] mod By sphinx_spb
 

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

LogBot 1.0d LUA 5.1x [Strict] mod By sphinx_spb

Started by sphinx_spb, 02 March, 2008, 00:12:23

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

sphinx_spb

Well, I found and fixed another few bugs (for old API), so I decide to post it here.

--[[

	LogBot 1.0d LUA 5.1x [Strict] [API 1 only!]

	By Mutor	12/17/07

	Logs user kicks/bans/redirections/registrations etc. to file(s) with timestamp.
	-Structure allows for additional commands/groups.
	-Creates all required files.
	-Logs kicks / redirects by whom and with reason.
	-Provides logfile size limit.


	+Changes from 1.0	12/17/07
		+Added support for old API

	+Changes from 1.0b	12/19/07
		+Added logging for:
			+Registrations
			+CTM/RCTM/MCTM requests
			+Logins/Logouts/Disconnects
			+Script Errors
			+All hub commands
			+Hublist pingers

	+Changes from 1.0c	01/06/07
		+Added context menu [right click]

]]
local F = {}


-- Admins Nick for status/error messages ["" = disable"]
local AdminNick = ""
-- Name for Bot ["" = default hub bot]
local Bot = ""
-- Path to log files ["" = default scripts folder]
local Path = "Logs"
-- Menu name
local Menu = "Hub"
-- Submenu
local SubMenu = "Hub Logs"
-- Command prefix ["" = default 1st prefix from the hub]
local Prefix = ""
-- Filename for commands data
F.CmdFile = "Cmds.log"
-- Filename for ban data
F.BanFile = "Bans.log"
-- Filename for kick data
F.KickFile = "Kicks.log"
-- Filename for redirect data
F.RedirFile = "Redirs.log"
-- Filename for register data
F.RegFile = "Regs.log"
-- Filename for joins/parts data
F.JoinFile = "Joins.log"
-- Filename for RCTM/CTM request data
F.XferFile = "Xfers.log"
-- Filename for hub pinger data
F.PingFile = "Pingers.log"
-- Filename for error data
F.ErrFile = "Errors.log"

--Maximum allowable size of log files, in bytes [10*1024 = 10Kb]
local MaxLog = 100*1024
-- Enable Menus/Commands
-- [#] = true/false (true = commands/menus enabled / false = commands/menus disabled)
local Profiles  = {
	[-1] = false,	--Unregistered User
	[0] = true,	--Master
	[1] = true,	--Operator
	[2] = true,	--Vip
	[3] = false,	--Registered User
	}
local Hub,Pfs = ""

OnStartup = function()
	Cmds = ""
		Hub = frmHub:GetHubName()
		Pfs = GetProfiles()
		if Bot == "" then
			Bot = frmHub:GetHubBotName()
		else
			frmHub:RegBot(Bot, 1, "", "")
		end
		if Menu == "" then
			Menu = frmHub:GetHubName()
		end
		if Prefix == "" then
			Prefix = frmHub:GetPrefixes()[1]
		end

	if Path ~= "" then
		if not os.rename(Path,Path) then
			os.execute("md "..Path)
		end
	end
	for i,v in pairs(F) do
		v = Path.."/"..v
		local ren,err = os.rename(v,v)
		if err then
			local f,e = io.open(v,"w")
			f:write("[ "..os.date().." ] Log file "..string.format("%q",v)..
			" created for "..Hub.."\n") f:close()
		end
	end
	local u,p,m,s,c = "$UserCommand 1 3",Prefix,Menu,SubMenu,""
	for i,v in pairs(F) do
		local x = v:gsub("[%w]-%[%w]-$","")
		c = c..u.." "..m.."\\"..s.."\\"..x.."$<%[mynick]> "..p.."readlog "..x.."&#124;|"
	end
	collectgarbage("collect")
	if c:len() > 0 then
		Cmds = c
	end
end
Main = OnStartup

OnError = function(msg,arg)
	if AdminNick ~= "" then
		local user = GetItemByName(AdminNick)
		if user then
			SendPmToNick(AdminNick,Bot,msg)
		end
	end
	if not arg then
		Logger(F.ErrFile,msg)
	end
end

UserConnected = function(user)
	if Profiles[user.iProfile] then
		local s = "<"..Bot.."> LogBot 1.0d commands enabled. Right click hub tab or user list for menu.|"
        	user:SendData(s..Cmds)
	end
	local nick = user.sName
	local log = "+ "..ProfName(nick).." "..nick.." connected."
	Logger(F.JoinFile,log)
end
OpConnected,RegConnected,NewUserConnected = UserConnected,UserConnected,UserConnected

UserDisconnected = function(user)
	local nick = user.sName
	local log = "- "..ProfName(nick).." "..nick.." disconnected."
	Logger(F.JoinFile,log)
end
OpDisconnected,RegDisconnected = UserDisconnected,UserDisconnected

ChatArrival = function(user,data)
	local t = {}
	-- Listen for these ban commands
	t.bans = {{"ban","unban","banip","fullban","fullbanip","nickban","tempban",
	"tempbanip","fulltempban","fulltempbanip","nicktempban"},F.BanFile}
	-- Listen for these scripted kick commands
	t.kicks = {{"kick","drop","gag","ungag"},F.KickFile}
	-- Listen for these registration commands
	t.regs = {{"addreguser","delreguser","op"},F.RegFile}
	local _,_,cmd = data:find("%b<> [!+](%w+)")

	if cmd then
		for _,grp in pairs(t) do
			for _,v in ipairs(grp[1]) do
				if cmd:lower() == v:lower() then
					Logger(grp[2],data:sub(1,-2))
					break
				end
			end
		end
		Logger(F.CmdFile,data:sub(1,-2))

		if Profiles[user.iProfile] and cmd:lower() == "readlog" then
			local _,_,file = data:find("%b<> [!+]%w+ ([^|]+)|")
			if file then
				file=Path.."/"..file
				local f,e = io.open(file)
				if f then
					local s = f:read("*a")
					if s and s:len() > 0 then
						return user:SendPM(Bot,"\n\n"..s),1
					end
				end
			end
		end
	end
end

ToArrival = function(user,data)
	local nick = user.sNick or user.sName
	local _,_,to,from,rsn = data:find("$To: (%S+) From: (%S+) $<%S+> You are being kicked because: (.+)|")
	if to and from and rsn then
		local log = nick.." is kicking "..to.." for: "..rsn
		SendToAll (Bot,log)
		Logger(F.KickFile,log)
	end
end

ConnectToMeArrival = function(user,data)
	local nick,log = user.sNick or user.sName,""
	Ctms = {
	[1] = {"^$ConnectToMe ([^ ]-) ",nick.." requested active connection to #"},
	[2] = {"^$RevConnectToMe [^ ]- (.+)",nick.." requested reverse connection from #"},
	[3] = {"^$MultiConnectToMe [^ ]- [^:]-%:[^ ]- ([^:]-%:.+)",nick.." from server: # requested multi-connection"},
	}
	for i,v in ipairs(Ctms) do
		local _,_,s = data:sub(1,-2):find(v[1])
		if s then
			local log = v[2]:gsub("#",s)
			Logger(F.XferFile,log)
			break
		end
	end

end
RevConnectToMeArrival,MultiConnectToMeArrival = ConnectToMeArrival,ConnectToMeArrival

KickArrival = function(user,data)
	local nick = user.sNick or user.sName
	Logger(F.KickFile,"<"..nick.."> "..data:sub(1,-2))
end
CloseArrival = KickArrival

OpForceMoveArrival = function(user,data)
	local _,_,vic,add,rsn = data:find("$OpForceMove $Who:(%S+)$Where:([^$]+)$Msg:(.+)|")
	if vic and add and rsn then
		local nick = user.sNick or user.sName
		local log = nick.." is redirecting "..vic.." to "..add.." because: "..rsn
		Logger(F.RedirFile,log)
	end
end

BotINFOArrival = function(user,data)
	local nick = user.sNick or user.sName
	local _,_,desc = data:sub(1,-2):find("$BotINFO (.+)")
	if nick and desc then
		local log = "BotINFO received from hublist pinger: "..nick..". Description: "..desc
		Logger(F.PingFile,log)
	end
end

UnknownArrival = function(user,data)
	local nick = user.sNick or user.sName
	local log = nick.." sent unknown command. Data received: "..data:sub(1,-2)
	Logger(F.ErrFile,log)
end

ProfName = function(user)
	local p = GetUserProfile(user)
	if p and p ~= nil then
		prof = GetProfileName(p)
	else
		prof = "Unreg"
	end
	return prof
end

Logger = function(file,str)
	file=Path.."/"..file
	local f,e = io.open(file,"rb")
	if f then
		local sz = f:seek("end")
		f:close()
		if sz > MaxLog then
			f,e = io.open(file,"w")
			f:write("[ "..os.date().." ] Log file "..file..
			" flushed and recreated for "..Hub.."\n") f:close()
		end
	else
		OnError(e:sub(1,-2))
	end
	f,e = io.open(file,"a+")
	if f then
		str = "[ "..os.date().." ] "..str.."\n"
		f:write(str) f:flush() f:close()
	else
		OnError(e:sub(1,-2))
	end
end

SMF spam blocked by CleanTalk