PtokaX forum

Archive => Archived 5.1 boards => Help with scripts => Topic started by: jay-dee on 12 January, 2007, 13:17:13

Title: Chathistory
Post by: jay-dee on 12 January, 2007, 13:17:13
im using this script:

--Chat History On Entry 1.02 LUA 5
--By Mutor The Ugly     4/14/04
--
--Based on a script by Tezlo     1/17/04
--Send chat history to PM on entry
--
-- +Converted to LUA 5 2/22/05
-- Lua 5.1.1 fix 01/05/07 by C??o?y??

-----------------------------------------------------------
chatfile = "chathistory.dat"
maxhistory = 20  -- maximum lines of chat to cache
botname = "[Historian]"
BadChars = {".","?","!","+","-",}   --disallow command prefixes

function Main()
   chathistory = dofile(chatfile) or {}
   frmHub:RegBot(botname)   -- Comment this line to not have bot appear in user list. Note: If botname is not registered, default dc++ settings will not allow pm's to pop up
            -- Enable Pop up messages from offline users / Disable ingnore messages from offline in client 'advanced dc settings'. To allow pop from unregistered botname.
end

function OnExit()
savehistory()
end

function NewUserConnected(user)
   local n = table.getn(chathistory)
   local str = "<----------------------------------------------------------------------[ Last ( "..n.." ) chat messages ]----------->\r\n"
   for i = 1, n do str = str.."\r\n"..chathistory[i] end
   user:SendPM(botname,str.."\r\n")
   user:SendPM(botname,"<--------------------------------------------------------------------------[ End of chat history ]--------------->")
end

OpConnected = NewUserConnected

function ChatArrival(user, data)
   if string.sub(data, 1, 1) ~= "<" then end
   local s,e,pre = string.find(data, "^%b<> (.)")
   local when = os.date("[%H:%M] ")
   local chat = string.sub(data, 1, -2)
   for k,v in pairs(BadChars) do -- cenofix (missing pairs part)
      if pre == v then     -- disallow command input to cached chat
            return
        end
    end
   table.insert(chathistory,when..chat)
   if table.getn(chathistory) > maxhistory then table.remove(chathistory, 1) end
   savehistory()
end

function savehistory()
   local f,e = io.open( chatfile, "w+" )
   if f then
      f:write( "return {\n" )
        for i = 1, table.getn(chathistory) do
            f:write( "\t"..string.format("%q", chathistory[i])..",\r\n" )
        end
      f:write( "}" )
      f:close()
      return 1
   else
      return nil,"savehistory failed: "..e

   end
end

function loadfile(chatfile)
   local f,e = io.open( chatfile, "r" )
   if f then
      local r = f:read( "*a" )
      f:close()
      return r
   else
      return nil,"loadfile failed: "..e
   end
end


when i start the script:

Syntax chathistory.dat:2: unexpected symbol near '<eof>'


it makes a second line in DAT file ???
like this:

1:return {
2:

but if i backspace the line 2 and save it, it still makes the second line....
--------------------------------------------
and when i typ in main and reconnect:

chathistory.lua:46: bad argument #1 to 'insert' (table expected, got nil)

who can help me???
Title: Re: Chathistory
Post by: jay-dee on 12 January, 2007, 23:18:04
 ;D
TNX Mutor, but what was the error??? ???
Title: Re: Chathistory
Post by: jay-dee on 14 January, 2007, 19:33:05
 ;D nice script mutor !!!! i really like it!!! ;D

if its possible..

to create the history on dates?

if im 3 days away, that i can read 3 days like:

Sat 13 jan:
blablabla
Sun 14 jan:
blablabla


and in a rightclick:
!readhistory--------- in pm
!cleanhistory------First 2 days
!cleanhistoryall

that on arrival the pm is off..........
and clean after 5 days, the first day........
(the mainchat isnt 24/7 talking so not much kb)

:-[ is it maybe to much to asked??

regards jay
Title: Re: Chathistory
Post by: jay-dee on 14 January, 2007, 20:29:04
 ;) ok too much  :P

but ,
PM on arrival on/off

and in a rightclick:
!readhistory--------- in pm
!cleanhistory-------- all

can you make that please??
Title: Re: Chathistory
Post by: BrotherBear on 26 January, 2007, 09:29:04
Testing away :)

Thanks Mutor, you will here from me ;)
Hi Mutor!

How is this script supose to work?

Is it my own Chat history that I'll get when I login again or should it be
the last in mainchat?
Title: Chathistory by Mutor
Post by: Stormbringer on 26 January, 2007, 12:04:26
Brotherbear, normaly the last lines on main chat, by you or another user.
But I found a problem, the script works ok, but there is a problem, the table is created, all the lines are logged on the tables, this part of code is ok, but on loggin, it display the first lines written in main and not the latest as it's supposed to be.
IE: I write ten lines with word: "test" in main, and ten with word "test1" after.
I reconnect, pm is send correctly but the pm show the lines with test and not test1 as it should be, could you fixed this problem Mutor please?
Thx a lot
Title: Re: Chathistory
Post by: Stormbringer on 26 January, 2007, 20:20:16
I take your example and something is not ok, or I'm retard:

The last message in main is: [07:36:05] [ 71.247.228.148 ] <Mutor> 10

in the PM sent by the bot the last message is:     10 01/26/07 07:36a <[OP]Enforcer> 9

It should be 10 01/26/07 07:36a  <Mutor> 10
Cause you wrote in main at the end
I'm wrong?



Title: Re: Chathistory
Post by: Snooze on 26 January, 2007, 22:40:53
Quote from: Mutor on 26 January, 2007, 13:48:00
I do see the need for a small change but here are the current results.

I could be the change Mutor is refering to.. :-)

-Snooze
Title: Re: Chathistory
Post by: BrotherBear on 31 January, 2007, 21:06:06
Thanks Stormbringer and Mutor :)