Triggering on imput from chat plugin snoop

Posted by RichKK on Thu 21 Aug 2008 01:45 AM — 10 posts, 33,773 views.

#0
I really enjoy the chat.xml plugin and the built in chat session feature and make a lot of use out of #snoop %name and #command %name functions.

I'd like to know how I can have triggers on my client side match strings of snooped output from another computer.

I went over the chat.xml plugin but am unsure what needs to be done to. If necessary I can modify the chat.xml plugin on my MUSHclient and or the MUSHclient I'm snooping.

edit: would I be able to make use of

the world.ChatMessage function for triggering purposes?
Amended on Thu 21 Aug 2008 01:55 AM by RichKK
Australia Forum Administrator #1
Have you read this?

http://www.gammon.com.au/mushclient/chat.htm

There is a description down near the bottom about making one chat client inform another one - if that doesn't answer your question let us know.
#2
Are you referring to "Using a custom message number"?

My understanding is that still requires a trigger to capture strings and to send them with a custom message number?

Australia Forum Administrator #3
OK, so you want to match on incoming snoops? That won't be a trigger because it is not MUD output. Check out Lua_Chat.xml plugin (or the VB one) and look for the function OnPluginChatMessage. That handles incoming chat messages.

You will want to detect message type 30 or 31 (snoop) and then use something like an if test or a regular expression to match on it.
#4
That's exactly what I wanted to do, thanks as always.
#5
I don't understand how I can match a string with a wildcard here from snoop_data.

Example of a received Chat plugin message:

1500[37m[40mYou roll a [33m7[37m.


I chose not to strip the ANSI since in my game that is the best means I know to confirm the string is legitimately sourced from the gameplay and not simulated by a player.


This was my approach:

 if message == 31 and sText == "1500[37m[40mYou roll a [33m(?P<roll>.+)[37m." then -- Match on that text. 31 is the message number for snoop_data
SetVariable ("roll", "%<roll>") -- Store the %<roll> variable
return true
end


The aim is to be able to match snoop_data strings against regular expression. I tried working with string.match, rex functions but the wildcard is still my impasse.
Amended on Mon 09 Mar 2009 01:56 AM by RichKK
Australia Forum Administrator #6
You can't do this:


sText == "1500[37m[40mYou roll a [33m(?P<roll>.+)[37m."


... because that is simply looking for a literal match, brackets and all.

With variable text you need string.match, and also convert the escape sequences. Things like [37m are really <esc>37m, which in a Lua literal would be: "\02737m" - where \027 is an "escape" character.

So, something like this would be required:



if message == 31 then  -- 31 is the message number for snoop_data
  local roll = string.match (sText, "1500\02737m\02740mYou roll a \02733m(%d+)\02737m%.")
  
  -- if matched, roll will not be nil
  
  if roll then 
   SetVariable ("roll", roll) -- Store the %<roll> variable
   return true
  end  -- matched on roll
  
end -- if message 31


I haven't tested this, but it is closer to what you want. The sequence \027 where it appears above in bold is the escape character. The regular expression has a single wildcard which is (%d+), which will be returned in the "roll" variable.
#7
Thanks as always. I can now get a match with the ANSI stripped but not with. I won't give up on it :D
Australia Forum Administrator #8
Oops. I missed the square bracket. Check out this page for example:

http://www.gammon.com.au/scripts/doc.php?function=ANSI

So really, instead of:

\02737m

you need

\027[37m
#9
ha, awesome. much appreciated.