Trigger help - channels

Posted by Jeffrey F. Pia on Sun 22 Feb 2004 09:03 AM — 17 posts, 69,078 views.

#0
I have trigs which send lines from various channels to different notepad windows (nice feature btw, just wish color codes could be logged as well). I run into a problem when I try to skip text from certain mobs that use that same syntax.

I want to log any tells I get. This is the expression I use:
^.*You tell (?!the CLAN).+$|^(!?the golden dragon|The Father of CHAoS|Questor).+ tells you .+$
It logs all outgoing tells just fine, but skips incoming tells completely. Any idea why?

Here is the syntax for the text I'm trying to catch:
Xxx tells you 'Hi!' Or
22 Feb 02:52 - Xxx tells you 'Hi!'

Syntax for the text I'm trying to skip:
the golden dragon tells you 'blah blah'
Questor tells you 'blah blah'
The Father of CHAoS tells you 'blah blah'
Australia Forum Administrator #1
You have reversed ?! in the second part of the trigger as !?.

If you change it to how I have it below, it seems to work ...


^.*You tell (?!the CLAN).+$|^(?!the golden dragon|The Father of CHAoS|Questor).+ tells you .+$
#2
*thwap self*

Thanks... :)

In an effort to not make this thread so pointless, here's another prob I've been having. Sometimes when I spam commands, the MUD output comes after my prompt:
< 25103/28300 2400/5820 6321/6322 Dbl: 2 0QT 431tnl NS 1000 > Xxx tells you 'Hi!'
Is there a way to mod the regular expression so that the prompt is not logged, or would it be better to parse the text with a script?
Amended on Mon 23 Feb 2004 11:26 PM by Jeffrey F. Pia
Australia Forum Administrator #3
Yes, with judicious use of brackets.

Something like this:



^(?:\<.*\>)? ... and the rest of it ...


However a little testing has revealed it is hard to get it right.

I think I would make two triggers, to save some confusion (one for "you tell" and one for "tells you"), then the first part above should strip out the prompt, and then the rest can be returned in %2 or %3 or wherever it shows up. :)
#4
I currently use the Send to: Notepad (append) option. Is it possible to have 2 trigs logging to the same notepad? Seemed like the distinguishing variable was the trig's name.

Also, I think I read somewhere that you had a plugin which was able to push raw color codes to an open log file. Maybe I can mod my trigs a little to open a specific channel's log file, then use code from your plugin to push the text and color code to the respective log? Dunno how much overhead that would add though.
Australia Forum Administrator #5
It is true that would be a problem, but instead of "send to notepad (append)" do "send to script" and have both append to the same notepad, eg.

world.AppendToNotepad "Clan talk", "%0" & vbCrLf

See:

http://www.gammon.com.au/scripts/doc.php?function=AppendToNotepad
#6
I've been trying to log chat messages with no luck. My prefix for chat is "[] " without the quotation marks. Not sure if it's even possible because chat isn't part of output from the mud. Thanks for any help/explanation.
Greece #7
By the way, I have also found that the expression (([A-Za-z]+) tells you|You tell (.*?)) '(.*?)' works nicely, it only matches letters before "tells you", so the prompt or spaces will not match... That's what I always use, and I make it match on color too, just to be safe.
USA #8
Rinor, I assume youre talking about Chat via MC chat?

If so, theyre world.notes, and might log normally, but I woulnt be surprised if they dont.
If they dont, you can just use the plugin callbacks to write your chats to a log file.

However you wont be using a trigger, which is what I think youve been trying.
Australia Forum Administrator #9
You can log chats by amending the chat plugin, assuming you are using it, and if not, I suggest you install it.

Having done that click on the Edit button in the plugins window, scroll down to the OnPluginChatDisplay part, and amend as follows...




' OnPluginChatDisplay
' ------------------
'
'  MUSHclient is about to display message: type, text
'  Return TRUE to use the default display, FALSE to not display
'
'  Note - the message type number, which groups types
'         of messages, as follows:
'

'   0 Connection attempt    
'   1 Session start, end          
'   2 Name Change        
'   3 Message           
'   4 Incoming Personal  
'   5 Incoming Everybody 
'   6 Incoming Group     
'   7 Outgoing Personal  
'   8 Outgoing Everybody 
'   9 Outgoing Group     
'  10 Peek List          
'  11 Connection List    
'  12 Ping              
'  13 Information       
'  14 File              
'  15 Snoop Data         
'  16 Command

Function OnPluginChatDisplay (message, sText)

  OnPluginChatDisplay = vbTrue  ' display it

  If message >= 3 And message <= 10 Then
    if IsLogOpen Then
       WriteLog StripANSI (sText)
    End If
  End If 
  
End Function



The first "If" in the script there just suppresses some message (like snoop data) which you may not want to log.

Then it checks if a log file is open, and if so, strips the ANSI codes (colours) from the chat message, and logs it. You could, of course put a prefix on it if you wanted.
#10
I want to put the chat messages into a notepad file, not a log. Sorry for the confusion.
#11
Okay, I couldn't get the Send to: Script to work write... probably something in the syntax of my script was off... but what I did get to work was Send to: World with an empty Send: box, sending the entire trig line to a script and using:
World.AppendToNotepad "Trigger: " & sTrigname, sVariable(10) + vbCrLf


That lets me append log files opened by my other triggers.

Now since my end goal was to update saved log files instead of open ones, I may as well use my script to do it. I plan on using this code:
world.openlog sPath & sLogName & ".txt", TRUE
  World.writelog sVariable(10)
  world.closelog


Do you think opening and closing log files w/ each channel trig will cause a lot of overhead? Or would it be better to just leave the log files open and use AppendToNotepad?

Thanks for being so helpful btw. This has been very educational for me. :-)
Amended on Wed 25 Feb 2004 03:39 AM by Jeffrey F. Pia
Australia Forum Administrator #12
Quote:

I want to put the chat messages into a notepad file, not a log. Sorry for the confusion.


Instead of WriteLog, do AppendToNotepad, like this:


AppendToNotepad "Chats log", StripANSI (sText)


Quote:

Okay, I couldn't get the Send to: Script to work write... probably something in the syntax of my script was off... but what I did get to work was Send to: World with an empty Send: box, sending the entire trig line to a script and using:

World.AppendToNotepad "Trigger: " & sTrigname, sVariable(10) + vbCrLf


It might help to say what you did. I don't see how that helps, as you still have the trigger name in the notepad window.

Sending this to script should work:

AppendToNotepad "My notepad name", "%0" & vbCrLf

As for closing and opening for every line, why do that? It is needlessly slow. The whole reason operating systems separate open and close from read and write is that the open and close are usually much slower.

Why not just leave the log file open and do a WriteLog whenever you need to?



#13
Yeah, sorry I don't really know what I did... I just tweaked it until I got it to work. As for keeping the log file open... I log each channel in a separate .txt file. How can I specify which log to write to with WriteLog? Or would I use AppendToNotepad for that...?
Australia Forum Administrator #14
I think the simple thing would be to AppendToNotepad - the log writing is intended for a single log file at once. Alternatively you could use the FileSystemObject object and have multiple output files open at one.

If you use AppendToNotepad you might set up a timer (say, every 5 minutes) to save the notepad(s) to disk, so you don't lose the lot.
USA #15
If you were to do that, you might be better off using FSO, its a little bit of scripting, but you dont have the extra windows floting around, and you wont accidentally delete something and whatnot.
I would think it would also be easier on your system, especially with numerous large notepad files.

As well as the fact that you could use the same file and append to it on numerous sessions.
Australia Forum Administrator #16
Yes, the FileSystemObject I mentioned is the same as FSO. You could with notepad open an existing file, which would affectively append, but yes, once they got big they would get slow.

Probably a quick script to append to an open file would be the way to go.