Author Topic: [API2] SimpleHistory v1  (Read 1863 times)

0 Members and 1 Guest are viewing this topic.

Offline Herodes

  • Newbie
  • *
  • Posts: 8
  • Karma: +1/-0
[API2] SimpleHistory v1
« on: 07 May, 2008, 23:06:20 »
Good to be back,... here is a script for getting me warmed up.

Code: Lua
  1. --[[
  2.         SimpleHistory.v1.lua by Herodes
  3.          7/5/2008 @ 11:58
  4.          plop based (tm)
  5.         - logs last HowMany lines of chat takes into
  6.            consideration the noise and the commands
  7.         - avoid logging with prefixes + and -
  8. ]]
  9.  
  10. local HowMany = 25 -- specify how many lines to keep at max...
  11. local tSkipLines = {
  12.         "^%+",
  13.         "^-",
  14.         "^[^ ]+ is kicking [^ ]+ because:"
  15. }
  16. local tChatLines = {}
  17.  
  18. ChatArrival = function (user, data)
  19.  
  20.         local _,_,cmd = data:find("%b<> %p(%w+)")
  21.  
  22.         local tCmds = {
  23.                 history = function()
  24.                         if #tChatLines == 0 then return "nothing has been recorded yet... check back later" end
  25.                         return "Last "..(#tChatLines).." chat history:\n"..table.concat(tChatLines, "\n")
  26.                 end,
  27.                 historyhelp = function()
  28.                         return "!history - view last "..HowMany.." lines of chat.\n"
  29.                 end
  30.         }
  31.  
  32.         if cmd and cmd ~= "me" and tCmds[cmd] then
  33.                 return Core.SendToNick(user.sNick, tCmds[cmd]()), true
  34.         end
  35.  
  36.         local _,_,msg = data:find("%b<> (.*)")
  37.        
  38.         local CheckLine = function ( str )
  39.                 for i,v in ipairs(tSkipLines) do
  40.                         if string.find(str, v) then return end
  41.                 end
  42.                 return true
  43.         end
  44.        
  45.         if CheckLine(msg) then
  46.                 if #tChatLines >= HowMany then table.remove(tChatLines, 1) end
  47.                 table.insert( tChatLines, os.date("[%H:%M:%S] :: ")..string.sub(data, 1,-2))
  48.         end
  49.  
  50. end

you can find me in my hub,... her0.sytes.net
« Last Edit: 07 May, 2008, 23:28:51 by Herodes »

PtokaX forum

[API2] SimpleHistory v1
« on: 07 May, 2008, 23:06:20 »