PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Finished Scripts => Topic started by: Herodes on 07 May, 2008, 23:06:20

Title: [API2] SimpleHistory v1
Post by: Herodes on 07 May, 2008, 23:06:20
Good to be back,... here is a script for getting me warmed up.

Code (lua) Select
--[[
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 (http://dchub://her0.sytes.net)