[API2] SimpleHistory v1
 

[API2] SimpleHistory v1

Started by Herodes, 07 May, 2008, 23:06:20

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Herodes

Good to be back,... here is a script for getting me warmed up.

Code: lua
--[[
	SimpleHistory.v1.lua by Herodes
	 7/5/2008 @ 11:58
	 plop based (tm)
	- logs last HowMany lines of chat takes into 
	   consideration the noise and the commands
	- avoid logging with prefixes + and -
]]

local HowMany = 25 -- specify how many lines to keep at max...
local tSkipLines = { 
	"^%+", 
	"^-", 
	"^[^ ]+ is kicking [^ ]+ because:" 
}
local tChatLines = {}

ChatArrival = function (user, data)

	local _,_,cmd = data:find("%b<> %p(%w+)")

	local tCmds = {
		history = function()
			if #tChatLines == 0 then return "nothing has been recorded yet... check back later" end
			return "Last "..(#tChatLines).." chat history:\n"..table.concat(tChatLines, "\n")
		end,
		historyhelp = function()
			return "!history - view last "..HowMany.." lines of chat.\n"
		end
	}

	if cmd and cmd ~= "me" and tCmds[cmd] then 
		return Core.SendToNick(user.sNick, tCmds[cmd]()), true
	end

	local _,_,msg = data:find("%b<> (.*)")
	
	local CheckLine = function ( str )
		for i,v in ipairs(tSkipLines) do
			if string.find(str, v) then return end
		end
		return true
	end
	
	if CheckLine(msg) then 
		if #tChatLines >= HowMany then table.remove(tChatLines, 1) end
		table.insert( tChatLines, os.date("[%H:%M:%S] :: ")..string.sub(data, 1,-2))
	end

end


you can find me in my hub,... her0.sytes.net

SMF spam blocked by CleanTalk