Chatstats V3
 

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

Chatstats V3

Started by Madman, 29 March, 2006, 15:00:08

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Madman

Another update on this great script... =)
More flavours can be found here
-- ChatStats v3 Made By Optimus
-- Based on Tezlo chats
-- Added Send Commands By TiMeTrAVelleR
-- Madman fixed some in commands
-- Converted to lua5 by Madman with very little help by Jelf
-- with some help by ?
-- fixed stats saving on exit by jiten
---- Modded by Madman
-- Added so it's creates ChatStatsFile, if it's missing
-- Fixed so it dont counts commands
-- Added a IgnoreTable, users in that wont be counted
---- Madman Return's
-- Changed: New ChatArrival
-- Changed: Some Commands
-- Changed: Some small code...
-- Changed: Modded 4 my hub
---- Madman strikes again
-- Added: a lowerchatter cmd, use it to lower someones chatstats post

sBot = frmHub:GetHubBotName()		-- Name of Bot
SendComm = 1 			-- Send UserCommands 1 = On? 0 = Off
pMenu = "-=( ChatStats )=-" 	-- Name of Menu

Chatstats = {}

Sortstats = 2	-- 1=words / 2=posts

ChatStatsFile = "chatstats.tbl"

IgnoreTable = {
-- 0=dont ignore/1=ignore
	["-=FakeKiller=-"] = 1,
}

EnableChatStats = {
	[0] = 1, -- Master
	[1] = 1, -- Operators
	[2] = 1, -- Vips
	[3] = 1, -- Regs
	[-1] = 1, -- Users (UnRegged)
}

AllowedProfiles = { 
	[0] = 1,? ?-- Masters
	[1] = 0,? ?-- Operators
}

function Main()
	frmHub:RegBot(sBot)
	local file = io.open(ChatStatsFile, "r")
	if file then
		file:close()
	else
		local file = io.open(ChatStatsFile, "w+")
		file:write()
		file:close()
	end
	dofile(ChatStatsFile)
end

function NewUserConnected(user)
	if SendComm == 1 and EnableChatStats[user.iProfile] == 1 then
		if Chatstats[user.sName] then
			user:SendData(sBot, "---===[ Your Chat Stats:? You Made "..Chatstats[user.sName]["post"].." Posts In Main Used "..Chatstats[user.sName]["chars"].." Characters, And "..Chatstats[user.sName]["words"].." Words ]===---")
		end
		user:SendData("$UserCommand 1 3 "..pMenu.."\\Chat stats$<%[mynick]> !chatstats&#124;")
		user:SendData("$UserCommand 1 3 "..pMenu.."\\My Chat Stat$<%[mynick]> !mystats&#124;")
		if AllowedProfiles[user.iProfile] == 1 then
			user:SendData("$UserCommand 1 3 "..pMenu.."\\Op menu\\Del Chatter$<%[mynick]> !delchatter %[line:Nick]&#124;")
			user:SendData("$UserCommand 1 3 "..pMenu.."\\Op Menu\\Lower Chatter$<%[mynick]> !lowerchatter %[line:Nick] %[line:New posts]&#124;")
			user:SendData("$UserCommand 1 3 "..pMenu.."\\Op Menu\\Clear Chat Stats$<%[mynick]> !clearstats&#124;")
		end
		if user.bOperator then
			user:SendData("$UserCommand 1 3 "..pMenu.."\\Op Menu\\TopChatters in Main$<%[mynick]> !topchat&#124;")
		end
	end
end

OpConnected = NewUserConnected

function OnExit()
	if isEmpty(Chatstats) then
	else
		saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
	end
end

function IsCmd(str)
	return string.sub(str, 1, 1) == "!" or string.sub(str, 1, 1) == "?" or string.sub(str, 1, 1) == "+" or string.sub(str, 1, 1) == "$"
end

function ChatArrival(user, data)
	if EnableChatStats[user.iProfile] == 1 then
		local s,e,cmd = string.find(data,"%b<>%s+(%S+)")
		if IsCmd(cmd) then
		elseif IgnoreTable[user.sName] == 1 then
		else
			local s,e,str = string.find(data, "%b<>%s+(.*)%|")
			updStats(user.sName, str)
		end
	end
	local data = string.sub(data,1, -2)
	local s,e,cmd = string.find(data, "%b<>%s+[%!%+%?](%S+)")
	if cmd then
		cmd = string.lower(cmd)
		local tCmds = {
		["mystats"] = function(user, data)
			if Chatstats[user.sName] then
				user:SendData(sBot, "---===[ Your Chat Stats:? You Made "..Chatstats[user.sName]["post"].." Posts In Main Used "..Chatstats[user.sName]["chars"].." Characters, And "..Chatstats[user.sName]["words"].." Words ]===---")
			else
				user:SendData(sBot, "*** No chat statics found!") 
			end
			return 1
		end,
		["chatstats"] = function(user, data)
			TCopy={}
			if Chatstats then
				for i,v in Chatstats do
					table.insert(TCopy,{i,v.post,v.chars,v.words})
				end
				table.sort(TCopy,function(a,b) return (a[Sortstats] > b[Sortstats]) end)
				local chat = "Current Top Chatters:\r\n\r\n"
				chat = chat.."\t ------------------------------------------------------------------------\r\n"
				chat = chat.."\t Nr.\tPosts:\tChars:\tWords:\tName:\r\n"
				chat = chat.."\t ------------------------------------------------------------------------\r\n"
				for i = 1,25 do 
					if TCopy[i] then
						chat = chat.."\t "..i..".\t "..TCopy[i][2].."\t "..TCopy[i][3].."\t "..TCopy[i][4].."\t"..TCopy[i][1].."\r\n"
					end
				end
				user:SendPM(sBot, chat)
				TCopy={}
			end
			return 1
		end,
		["topchat"] = function(user, data)
			if user.bOperator then
				TCopy={}
					if Chatstats then
					for i,v in Chatstats do
						table.insert(TCopy,{i,v.post,v.chars,v.words})
					end
					table.sort(TCopy,function(a,b) return (a[Sortstats] > b[Sortstats]) end)
					local chat = "Current Top Chatters:\r\n\r\n"
					chat = chat.."\t ------------------------------------------------------------------------\r\n"
					chat = chat.."\t Nr.\tPosts:\tChars:\tWords:\tName:\r\n"
					chat = chat.."\t ------------------------------------------------------------------------\r\n"
					for i = 1,25 do 
						if TCopy[i] then
							chat = chat.."\t "..i..".\t "..TCopy[i][2].."\t "..TCopy[i][3].."\t "..TCopy[i][4].."\t"..TCopy[i][1].."\r\n"
						end
					end
					SendToAll(sBot, chat)
					TCopy={}
				end
				return 1
			end
		end,
		["lowerchatter"] = function(user, data)
			if AllowedProfiles[user.iProfile] == 1 then
				local s,e,name,chat = string.find(data, "%b<>%s+%S+%s+(%S+)%s+(%d+)")
				if name and chat then
					if Chatstats[name] then
						chat = tonumber(chat)
						if Chatstats[name]["post"] <= chat then
							user:SendData(sBot, "*** You can not raise the stats!")
						else
							local OldChat = Chatstats[name]["post"]
							Chatstats[name]["post"] = chat
							SendToOps(sBot, "*** Chatstats posts for " ..name.. " has been lowered to " ..chat.. " from " ..OldChat.. " by " ..user.sName)
							saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
						end
					else
						user:SendData(sBot, "*** " ..name.. " is not in chatstats")
					end
				else
					user:SendData(sBot, "*** Usage: !lowerchatter <name> <new posts>")
				end
				return 1
			end
		end,
		["delchatter"] = function(user, data)
			if AllowedProfiles[user.iProfile] == 1 then
				local s,e,name = string.find(data, "%b<>%s+%S+%s+(%S+)" )
				if name then
					if Chatstats[name] then
						Chatstats[name] = nil
						SendToOps(sBot, "Chatstats from user "..name.." are now removed!")
						saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
					else
						user:SendData(sBot, "*** Chatstats from user "..name.." not found!")
					end
				else
					user:SendData(sBot, "*** Usage: !delchatter <name>")
				end
				return 1
			end
		end,
		["clearstats"] = function(user, data)
			if AllowedProfiles[user.iProfile] == 1 then
				Chatstats = {}
				saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
				SendToAll(sBot, "Chatstats are cleared by "..user.sName)
				return 1
			end
		end,
		}
		if tCmds[cmd] then
			return tCmds[cmd](user, data)
		end
	end
end

function updStats(nick, str)
	local tmp = Chatstats[nick] or {["post"]=0, ["chars"]=0, ["words"]=0, ["time"]=os.date("%x")}
	tmp["post"], tmp["chars"], tmp["words"], tmp["time"] = tmp["post"]+1, tmp["chars"]+string.len(str), tmp["words"]+cntargs(str,"(%a+)"), os.date("%x")
	Chatstats[nick] = tmp
	saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
end

function cntargs(str, rule)
	local s,n = string.gsub(str, rule, "")
	return n
end

----------------------------------------------
-- load & save Tables
----------------------------------------------
function Serialize(tTable, sTableName, sTab)
	assert(tTable, "tTable equals nil");
	assert(sTableName, "sTableName equals nil");
	assert(type(tTable) == "table", "tTable must be a table!");
	assert(type(sTableName) == "string", "sTableName must be a string!");
	sTab = sTab or "";
	sTmp = ""
	sTmp = sTmp..sTab..sTableName.." = {\n"
	for key, value in tTable do
		local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
		if(type(value) == "table") then
			sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
		else
			local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
			sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
		end
		sTmp = sTmp..",\n"
	end
	sTmp = sTmp..sTab.."}"
	return sTmp
end

-----------------------------------------------------------
function saveTableToFile(file, table, tablename)
	local handle = io.open(file,"w+")
	handle:write(Serialize(table, tablename))
	handle:flush()
	handle:close()
end
-----------------------------------------------------------
function loadTableFromFile(file)
	local handle = io.open(file,"r")
	if (handle ~= nil) then
		loadstring(handle:read("*all"))
		handle:flush()
		handle:close()
	end
end

-------------table checker by herodes
--- for an associative table, like ["smth"] = "smth else",
function isEmpty(t)
	for i,v in t do
		return false;
	end
	return true;
end;
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

TiMeTrAVelleR

Lua 5.1 version
-- ChatStats v3 Made By Optimus
-- Based on Tezlo chats
-- Added Send Commands By TiMeTrAVelleR
-- Madman fixed some in commands
-- Converted to lua5 by Madman with very little help by Jelf
-- with some help by ?
-- fixed stats saving on exit by jiten
---- Modded by Madman
-- Added so it's creates ChatStatsFile, if it's missing
-- Fixed so it dont counts commands
-- Added a IgnoreTable, users in that wont be counted
---- Madman Return's
-- Changed: New ChatArrival
-- Changed: Some Commands
-- Changed: Some small code...
-- Changed: Modded 4 my hub
---- Madman strikes again
-- Added: a lowerchatter cmd, use it to lower someones chatstats post
-- Changed to lua 5.1 by TT

sBot = frmHub:GetHubBotName()		-- Name of Bot
SendComm = 1 			-- Send UserCommands 1 = On? 0 = Off
pMenu = "-=( ChatStats )=-" 	-- Name of Menu

Chatstats = {}

Sortstats = 2	-- 1=words / 2=posts

ChatStatsFile = "chatstats.tbl"

IgnoreTable = {
-- 0=dont ignore/1=ignore
	["-=FakeKiller=-"] = 1,
}

EnableChatStats = {
	[0] = 1, -- Master
	[1] = 1, -- Operators
	[2] = 1, -- Vips
	[3] = 1, -- Regs
	[-1] = 1, -- Users (UnRegged)
}

AllowedProfiles = { 
	[0] = 1,? ?-- Masters
	[1] = 0,? ?-- Operators
}

function Main()
	frmHub:RegBot(sBot)
	local file = io.open(ChatStatsFile, "r")
	if file then
		file:close()
	else
		local file = io.open(ChatStatsFile, "w+")
		file:write()
		file:close()
	end
	dofile(ChatStatsFile)
end

function NewUserConnected(user)
	if SendComm == 1 and EnableChatStats[user.iProfile] == 1 then
		if Chatstats[user.sName] then
			user:SendData(sBot, "---===[ Your Chat Stats:? You Made "..Chatstats[user.sName]["post"].." Posts In Main Used "..Chatstats[user.sName]["chars"].." Characters, And "..Chatstats[user.sName]["words"].." Words ]===---")
		end
		user:SendData("$UserCommand 1 3 "..pMenu.."\\Chat stats$<%[mynick]> !chatstats&#124;")
		user:SendData("$UserCommand 1 3 "..pMenu.."\\My Chat Stat$<%[mynick]> !mystats&#124;")
		if AllowedProfiles[user.iProfile] == 1 then
			user:SendData("$UserCommand 1 3 "..pMenu.."\\Op menu\\Del Chatter$<%[mynick]> !delchatter %[line:Nick]&#124;")
			user:SendData("$UserCommand 1 3 "..pMenu.."\\Op Menu\\Lower Chatter$<%[mynick]> !lowerchatter %[line:Nick] %[line:New posts]&#124;")
			user:SendData("$UserCommand 1 3 "..pMenu.."\\Op Menu\\Clear Chat Stats$<%[mynick]> !clearstats&#124;")
		end
		if user.bOperator then
			user:SendData("$UserCommand 1 3 "..pMenu.."\\Op Menu\\TopChatters in Main$<%[mynick]> !topchat&#124;")
		end
	end
end

OpConnected = NewUserConnected

function OnExit()
	if isEmpty(Chatstats) then
	else
		saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
	end
end

function IsCmd(str)
	return string.sub(str, 1, 1) == "!" or string.sub(str, 1, 1) == "?" or string.sub(str, 1, 1) == "+" or string.sub(str, 1, 1) == "$"
end

function ChatArrival(user, data)
	if EnableChatStats[user.iProfile] == 1 then
		local s,e,cmd = string.find(data,"%b<>%s+(%S+)")
		if IsCmd(cmd) then
		elseif IgnoreTable[user.sName] == 1 then
		else
			local s,e,str = string.find(data, "%b<>%s+(.*)%|")
			updStats(user.sName, str)
		end
	end
	local data = string.sub(data,1, -2)
	local s,e,cmd = string.find(data, "%b<>%s+[%!%+%?](%S+)")
	if cmd then
		cmd = string.lower(cmd)
		local tCmds = {
		["mystats"] = function(user, data)
			if Chatstats[user.sName] then
				user:SendData(sBot, "---===[ Your Chat Stats:? You Made "..Chatstats[user.sName]["post"].." Posts In Main Used "..Chatstats[user.sName]["chars"].." Characters, And "..Chatstats[user.sName]["words"].." Words ]===---")
			else
				user:SendData(sBot, "*** No chat statics found!") 
			end
			return 1
		end,
		["chatstats"] = function(user, data)
			TCopy={}
			if Chatstats then
				for i,v in pairs(Chatstats) do
					table.insert(TCopy,{i,v.post,v.chars,v.words})
				end
				table.sort(TCopy,function(a,b) return (a[Sortstats] > b[Sortstats]) end)
				local chat = "Current Top Chatters:\r\n\r\n"
				chat = chat.."\t ------------------------------------------------------------------------\r\n"
				chat = chat.."\t Nr.\tPosts:\tChars:\tWords:\tName:\r\n"
				chat = chat.."\t ------------------------------------------------------------------------\r\n"
				for i = 1,25 do 
					if TCopy[i] then
						chat = chat.."\t "..i..".\t "..TCopy[i][2].."\t "..TCopy[i][3].."\t "..TCopy[i][4].."\t"..TCopy[i][1].."\r\n"
					end
				end
				user:SendPM(sBot, chat)
				TCopy={}
			end
			return 1
		end,
		["topchat"] = function(user, data)
			if user.bOperator then
				TCopy={}
					if Chatstats then
					for i,v in pairs(Chatstats) do
						table.insert(TCopy,{i,v.post,v.chars,v.words})
					end
					table.sort(TCopy,function(a,b) return (a[Sortstats] > b[Sortstats]) end)
					local chat = "Current Top Chatters:\r\n\r\n"
					chat = chat.."\t ------------------------------------------------------------------------\r\n"
					chat = chat.."\t Nr.\tPosts:\tChars:\tWords:\tName:\r\n"
					chat = chat.."\t ------------------------------------------------------------------------\r\n"
					for i = 1,25 do 
						if TCopy[i] then
							chat = chat.."\t "..i..".\t "..TCopy[i][2].."\t "..TCopy[i][3].."\t "..TCopy[i][4].."\t"..TCopy[i][1].."\r\n"
						end
					end
					SendToAll(sBot, chat)
					TCopy={}
				end
				return 1
			end
		end,
		["lowerchatter"] = function(user, data)
			if AllowedProfiles[user.iProfile] == 1 then
				local s,e,name,chat = string.find(data, "%b<>%s+%S+%s+(%S+)%s+(%d+)")
				if name and chat then
					if Chatstats[name] then
						chat = tonumber(chat)
						if Chatstats[name]["post"] <= chat then
							user:SendData(sBot, "*** You can not raise the stats!")
						else
							local OldChat = Chatstats[name]["post"]
							Chatstats[name]["post"] = chat
							SendToOps(sBot, "*** Chatstats posts for " ..name.. " has been lowered to " ..chat.. " from " ..OldChat.. " by " ..user.sName)
							saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
						end
					else
						user:SendData(sBot, "*** " ..name.. " is not in chatstats")
					end
				else
					user:SendData(sBot, "*** Usage: !lowerchatter <name> <new posts>")
				end
				return 1
			end
		end,
		["delchatter"] = function(user, data)
			if AllowedProfiles[user.iProfile] == 1 then
				local s,e,name = string.find(data, "%b<>%s+%S+%s+(%S+)" )
				if name then
					if Chatstats[name] then
						Chatstats[name] = nil
						SendToOps(sBot, "Chatstats from user "..name.." are now removed!")
						saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
					else
						user:SendData(sBot, "*** Chatstats from user "..name.." not found!")
					end
				else
					user:SendData(sBot, "*** Usage: !delchatter <name>")
				end
				return 1
			end
		end,
		["clearstats"] = function(user, data)
			if AllowedProfiles[user.iProfile] == 1 then
				Chatstats = {}
				saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
				SendToAll(sBot, "Chatstats are cleared by "..user.sName)
				return 1
			end
		end,
		}
		if tCmds[cmd] then
			return tCmds[cmd](user, data)
		end
	end
end

function updStats(nick, str)
	local tmp = Chatstats[nick] or {["post"]=0, ["chars"]=0, ["words"]=0, ["time"]=os.date("%x")}
	tmp["post"], tmp["chars"], tmp["words"], tmp["time"] = tmp["post"]+1, tmp["chars"]+string.len(str), tmp["words"]+cntargs(str,"(%a+)"), os.date("%x")
	Chatstats[nick] = tmp
	saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
end

function cntargs(str, rule)
	local s,n = string.gsub(str, rule, "")
	return n
end

----------------------------------------------
-- load & save Tables
----------------------------------------------
function Serialize(tTable, sTableName, sTab)
	assert(tTable, "tTable equals nil");
	assert(sTableName, "sTableName equals nil");
	assert(type(tTable) == "table", "tTable must be a table!");
	assert(type(sTableName) == "string", "sTableName must be a string!");
	sTab = sTab or "";
	sTmp = ""
	sTmp = sTmp..sTab..sTableName.." = {\n"
	for key, value in pairs(tTable) do
		local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
		if(type(value) == "table") then
			sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
		else
			local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
			sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
		end
		sTmp = sTmp..",\n"
	end
	sTmp = sTmp..sTab.."}"
	return sTmp
end

-----------------------------------------------------------
function saveTableToFile(file, table, tablename)
	local handle = io.open(file,"w+")
	handle:write(Serialize(table, tablename))
	handle:flush()
	handle:close()
end
-----------------------------------------------------------
function loadTableFromFile(file)
	local handle = io.open(file,"r")
	if (handle ~= nil) then
		loadstring(handle:read("*all"))
		handle:flush()
		handle:close()
	end
end

-------------table checker by herodes
--- for an associative table, like ["smth"] = "smth else",
function isEmpty(t)
	for i,v in pairs(t) do
		return false;
	end
	return true;
end;


greetzz TT

Madman

TT...Move your version to the 5.1 section...
That's why it's there you kno... ;p
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

TiMeTrAVelleR


SMF spam blocked by CleanTalk