Chat to Notepad.

Posted by Shigs on Wed 30 Jan 2008 08:02 PM — 22 posts, 84,082 views.

#0
Right, I'm catching * <chat> * via a trigger and then sending %0 to notepad, but if a \n is held in the line it will only send the text before \n to notepad and the rest is shown in my screen, ANSI colours and all.

Any ideas of a workaround for this?
Australia Forum Administrator #1
How have you done that? Like this?


SendToNotepad ("Chats", "%0")


The line breaks inside the %0 will throw things out. Try:


SendToNotepad ("Chats", [[%0]])


In Lua [[ ... ]] is a multi-line string.
Amended on Wed 30 Jan 2008 08:11 PM by Nick Gammon
#2
I actually just had "append to notepad" as my location and was just passing %0 back.
Australia Forum Administrator #3
Try "send to script" and the line of script I had above.
#4
ok that works, but all the lines are running on with each other.

and
<send>AppendToNotepad ("Chats", [[%0]]."\r\n")</send>

dosen't work, how do I add a newline at the end of the string?
#5
Here's my Plugin file .


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Friday, February 01, 2008, 10:55 AM -->
<!-- MuClient version 4.14 -->

<!-- Plugin "chat_to_notepad" generated by Plugin Wizard -->

<muclient>
<plugin
   name="chat_to_notepad"
   author="Blaise"
   id="1ff1158d248784be2a84430e"
   language="Lua"
   purpose="Sends All Chat Messages to Notepad"
   date_written="2008-02-01 10:54:54"
   requires="4.00"
   version="1.0"
   >

</plugin>


<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   ignore_case="y"
   match="&lt;chat&gt; *"
   omit_from_output="y"
   sequence="100"
  >
  <send>AppendToNotepad ("Chats", [[%0]],"\r\n")</send>
  </trigger>
  <trigger
   enabled="y"
   ignore_case="y"
   match="* &lt;chat&gt; *"
   omit_from_output="y"
   send_to="12"
   sequence="100"
  >
  <send>AppendToNotepad ("Chats", [[%0]],"\r\n")</send>
  </trigger>
</triggers>

</muclient>

USA #6
That should be:

AppendToNotepad ("Chats", [[%0]].."\n")

Lua uses two periods to concatenate strings, not a comma.
#7
Ok, Is there any reason why %0 wouldn't contain the whole string?

My problem is,

Quote:

[[Blaise <CHAT> I'm sure there's a good excuse.]]
[[Tanak <CHAT> Blaise, fix that script?]]
[[Alexi <CHAT> Yeah, like sleeping.]]
[[Elas <CHAT> and dont let him lie to you]]
[[Alexi <CHAT> I have to be BACK here, on duty at noon. I need to go home and sleep. And he knows that.]]
[[Tanak <CHAT> Alexi in the army too?]]
[[Alexi <CHAT> No, I'm in the Lazy Asses Who Get Payed well field. I'm a security guard.]]
[[Tanak <CHAT> Hahaha. We're pretty lazy too.]]
[[Tanak <CHAT> Ok not really, but I like to act like I am.]]
[[Elas <CHAT> it lazy sometimes i have done it....]]
[[Tanak <CHAT> The lazy part is watching your CO watch porn on your computer.]]
[[Elas <CHAT> lol]]
[[Blaise <CHAT> No I didn't fix the script.. I went out last night straight after work and got very very drunk]]
[[Tanak <CHAT> Niiiice, what made it break? (DLed your other mod, very nifty)]]
[[Taladorn <CHAT> and now you have hangover?]]
[[> Taladorn <CHAT> best way of curing hangover is drink more]]
[[Blaise <CHAT> No, I don't have a hangover.]]
[[> Tanak <CHAT> I always used vinigar and tomato juice.]]
[[Elas <CHAT> are you a armed guard?]]
[[Taladorn <CHAT> wow, you are lucky, i always get hangover no matter what]]
[[Blaise <CHAT> Fortunatly, I drank all the right drinks, got my head down at]]
[[> Tanak <CHAT> hahaha]]
[[Tanak <CHAT> Like that alakzeler commercia.]]
[[Elas <CHAT> it lazy sometimes i have done it....]]
[[Tanak <CHAT> The lazy part is watching your CO watch porn on your computer.]]
[[Elas <CHAT> lol]]
[[Blaise <CHAT> No I didn't fix the script.. I went out last night straight after work and got very very drunk]]
[[Tanak <CHAT> Niiiice, what made it break? (DLed your other mod, very nifty)]]
[[Taladorn <CHAT> and now you have hangover?]]
[[Taladorn <CHAT> best way of curing hangover is drink more]]
[[Blaise <CHAT> No, I don't have a hangover.]]
[[Tanak <CHAT> I always used vinigar and tomato juice.]]
[[Elas <CHAT> are you a armed guard?]]
[[Taladorn <CHAT> wow, you are lucky, i always get hangover no matter what]]
[[Blaise <CHAT> Fortunatly, I drank all the right drinks, got my head down at about 3am and I'm awake now at 11:15, fresh and fine to go and be horrible to the people who'll be in work with hangovers]]
[[Tanak <CHAT> hahaha]]
[[Tanak <CHAT> Like that alakzeler commercia.]]



Quote:
[[Blaise <CHAT> Fortunatly, I drank all the right drinks, got my head down at about 3am and I'm awake now at 11:15, fresh and fine to go and be horrible to the people who'll be in work with hangovers]]


That cut off at
Quote:
Blaise <CHAT> Fortunatly, I drank all the right drinks, got my head down at about 3am


and the rest of the string still came through on my output, So.. I'm under the impression that the trigger dosen't register it as all being part of the same string or perhaps it isn't for all intents and purposes and therefor only omits and appends to notepad, the part that seems to be apart of that 'line'


The problem is, I need to catch all of it.

Any ideas Gents?
USA #8
It might be better to use a regex trigger, but they have to be case sensative. You have to match the exact text that is shown.

<triggers>
  <trigger
   enabled="y"
   regexp="y"
   match="^\[\[(\w+) <CHAT> (.*)\]\]$"
   omit_from_output="y"
   sequence="100"
   send_to="12"
  >
  <send>AppendToNotepad ("Chats", "%0")</send>
  </trigger>
</triggers>


Edit: I will be able to convert this with forum codes at SOME point...
Amended on Sat 02 Feb 2008 05:23 PM by Shaun Biggs
Australia Forum Administrator #9
Quote:

So.. I'm under the impression that the trigger dosen't register it as all being part of the same string or perhaps it isn't for all intents and purposes and therefor only omits and appends to notepad, the part that seems to be apart of that 'line'


Unless you use a multi-line trigger, and they can be fiddly to get right, a trigger only matches a single line.

One simple solution might be to configure the MUD to have a long "line width". Some MUDs let you specify something like 0 as the line width, which means "let the client wrap" rather than the server wrapping. Then the trigger will catch it all.

See if that is possible before we go down the multi-line path.
#10
I think I've discovered the true problem here and it's one that I'm struggling to think of a way around.

When someone uses a channel it sends out


NAME <CHANNEL> TEXT
or

<CHANNEL> NAME EMOTE

now I've got triggers to match both of them as you can see above.. but there's no way for me to tell the client when a line ends...

What I want to know is, Am I missing something? or can I use ANSI codes? each line is coloured in purple and thus has the RESET code at the end, can Mushclient match up ANSI codes in triggers? what sort of alias would I be looking at if it does to match up

NAME <CHANNEL> TEXT %RESET^

<CHANNEL> NAME EMOTE %RESET%


and if it can't match them in triggers is there some way it could be implemented?

Thanks
Liam
Australia Forum Administrator #11
Are the square brackets you posted earlier part of the chat? Or did you add that?
#12
No I added them.
Australia Forum Administrator #13
I think it can be done fairly easily, if the chat lines are a distinctive colour. You are going to need two triggers (or more if you count the emotes). The first one detects the start of a chat sequence, eg.

NAME <CHANNEL> TEXT


The second one, which is normally disabled, matches anything (ie. matches "*") so it can pick up subsequent lines. I would also make it a lower sequence number (eg. 50).

Now what will happen is:

  • Main trigger matches, saves the matching text in a variable. It also enables the secondary (match everything) trigger, and sets the "match all" trigger to NOT keep evaluating. Clearing "keep evaluating" stops the new line from being processed by other trigger handlers.
  • When the secondary trigger matches (that is, on the next line), it checks two things:

    1. Is this new line in purple? If not, we have reached the end of the multi-line chat. We can send the saved chat line to the notepad, disable ourselves, and set "keep evaluating" for ourselves. You can detect the style runs in the line ( and hence the colours) by using GetStyleInfo for the last line in the output buffer.
    2. Is this new line the start of a new chat? (That is, two chats in a row). Again we send the saved line(s) to the notepad window, disable ourselves and set "keep evaluating" so the real chat trigger will handle it.
    3. If neither of the above, it is a continuation chat line. Leave ourselves enabled and concatenate this line with the previously saved chat line.



I imagine the secondary trigger (which I have named "match_all") will look something like this:


<triggers>
  <trigger
   match="*"
   name="match_all"
   send_to="12"
   sequence="50"
  >
  <send>
saved_chat_line = saved_chat_line or ""

-- get text colour of first style in last line in buffer
colour = GetStyleInfo (GetLinesInBufferCount (), 1, 14)

if colour ~= ColourNameToRGB ("magenta") or
   string.match ("%0", "^.+ &lt;.+&gt; .+") then
  EnableTrigger ("match_all", 0)
  SetTriggerOption ("match_all", "keep_evaluating", "1")
  SendToNotepad ("chats", saved_chat_line)
else
  saved_chat_line = saved_chat_line .. " %0"
end -- if
</send>
  </trigger>
</triggers>


I assume that the main matching trigger (that matches the first chat line) will put the matching text into saved_chat_line, ready for the rest to be appended to it.

Notice how the trigger is not currently enabled - it is the job of the first trigger to do that. Also when it finds a line not in magenta, or in magenta but starting a new chat, it disables itself, sets keep_evaluating, and sends the matching chat to the notepad window.


Amended on Sun 03 Feb 2008 08:50 PM by Nick Gammon
#14
And what would the first trigger look like?
#15
<triggers>
<trigger
enabled="y"
ignore_case="y"
match="* &lt;chat&gt; *"
name="match_chat"
send_to="12"
sequence="100"
>
<send>
saved_chat_line = %0
EnableTrigger("match_all", true) -- enable trigger
SetTriggerOption ("match_chat", "keep_evaluating", "0")
</send>
</trigger>
</triggers>

I gave it a go, but I don't know where I'm going wrong.
#16
I'd also like to thank you both Nick and Shaun for your continued support, concise and well thought out responses to my questions.

The level of support and commitment to the product and its users is outstanding and one I'm yet to found rivaled by anyone else.
Australia Forum Administrator #17
Quote:

saved_chat_line = %0


See http://www.mushclient.com/faq point 32. You need quotes.

Quote:

I don't know where I'm going wrong.


It always helps to say what went wrong. Was there an error message? If so, what was it?

Quote:

SetTriggerOption ("match_chat", "keep_evaluating", "0")


The trigger that needs to not keep evaluating is "match_all" not "match_chat".
#18
I thought the quotes for a string where only needed when making a comparasion, not when doing an assignment as I am?


Also, why would I enable a trigger and then set it to stop evaluating?
#19
Right now I got it to work, but its not including any of the \n data, meaning all the text runs onto each other.

I tried doing,


...
  saved_chat_line = "saved_chat_line \n"
  AppendToNotepad ("chats", saved_chat_line)
...


but it chucks out a unfinished line error
and I tried

 
  AppendToNotepad ("chats", saved_chat_line .. "\n")


and got the same thing
USA #20
This is a somewhat random guess, but try \\n. There might be several levels of escape processing here.
Australia Forum Administrator #21
Quote:

I thought the quotes for a string where only needed when making a comparasion, not when doing an assignment as I am?


The principle is the same. MUSHclient expands out the %0 literally, so that line in your script will look like:


saved_chat_line = Ok not really, but I like to act like I am


Can you see that will give a syntax error?

It should read:


saved_chat_line = "Ok not really, but I like to act like I am"


That is why you put the quotes there.

Quote:

and I tried

AppendToNotepad ("chats", saved_chat_line .. "\n")



I agree with David here. MUSHclient expands out escape sequences before they even hit the script engine. I would do:


   AppendToNotepad ("chats", saved_chat_line .. "\\r\\n")


Quote:

saved_chat_line = "saved_chat_line \n"


This is wrong because here you are putting the word "saved_chat_line" into your variable. You need to keep track of what variables are, and what the contents are.

Quote:

why would I enable a trigger and then set it to stop evaluating?


Please read the help file entry which appears when you hit F1 whilst editing a trigger. The entry is not "evaluating" but "keep_evaluating".

As I mentioned earlier in this thread, "keep evaluating" stops other triggers from processing the line. So, you want this trigger to evaluate but not others with a higher sequence number.

However at the moment when your script decides that a line is no longer a chat line (based on the colour) we want keep_evaluating to be active in case we want some other trigger to match it.