[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Working with the line
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Working with the line

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Pages: 1 2  3  

Posted by Tesagk   (51 posts)  [Biography] bio
Date Mon 05 Sep 2016 07:50 PM (UTC)
Message
I'm having trouble finding out if there is a global "line" variable in MUSHclient accessible by Lua. In pursuit of that, I have also tried to find a "lua alias" to allow me to run simple scripts from the command-line, but have been unable to locate that as well.

What I am trying to accomplish is to use a trigger to replace text in the line using the "Replace" function, that way I can gather information from the line to store into a variable, and then replace a portion of that line so that I can effectively gag it.

In specific concept, there are two scenarios I am trying to work with:

1) Capture nospoof data, save it, and then remove the nospoof from the line so that I see it as though I didn't have nospoof on at all.

2) To take a prompt from a MUD, parse what I gather into a table, and then replace it with a neater version of the prompt, or with nothing at all.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Mon 05 Sep 2016 08:40 PM (UTC)

Amended on Mon 05 Sep 2016 08:42 PM (UTC) by Nick Gammon

Message
Quote:

In pursuit of that, I have also tried to find a "lua alias" to allow me to run simple scripts from the command-line, but have been unable to locate that as well.


In Scripting configuration, put something in the "Script Prefix" box. I usually use "/", others use something like "\\\".

Then you can type in the command window:


/ print "hello"





Quote:

I'm having trouble finding out if there is a global "line" variable in MUSHclient accessible by Lua.


The current line in the output window? Not as such. See http://www.gammon.com.au/scripts/doc.php?function=GetLineInfo - you can get the most recent line easily enough.

Quote:

1) Capture nospoof data, save it, and then remove the nospoof from the line so that I see it as though I didn't have nospoof on at all.


What you usually do here is make a trigger to capture the line. Set the trigger to omit it from output. Then Note or ColourNote the line after making desired modifications.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Tesagk   (51 posts)  [Biography] bio
Date Reply #2 on Mon 05 Sep 2016 09:42 PM (UTC)
Message
Nick Gammon said:

What you usually do here is make a trigger to capture the line. Set the trigger to omit it from output. Then Note or ColourNote the line after making desired modifications.


I was worried about this option because it would strip all of the ansi in the line, no? I'd prefer to preserve the line without cutting up too much.
[Go to top] top

Posted by Tesagk   (51 posts)  [Biography] bio
Date Reply #3 on Tue 06 Sep 2016 10:35 AM (UTC)
Message
In attempting what was suggested, I discovered the following issues:

+ Using either Note() or print() had an output which, since it is from the client, as opposed to the MU*, that was highlighted in blue. Is there a function for displaying as if by the MU*?

+ Having difficulty parsing the nospoof stuff out of it, but this is mostly my own lack of expertise. I've been trying to use the capture information to remove content from the whole line string. I may need to simply use a different pattern altogether.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Tue 06 Sep 2016 10:26 PM (UTC)
Message
See:

Template:faq=23 Please read the MUSHclient FAQ - point 23.


That doesn't directly answer you, but it is possible to keep the style runs (colours) from the input line. Trigger scripts have access to the table of style runs, and using code similar to that FAQ you can output them again. Of course, you need to make changes as required (the spoofing stuff) and it would be helpful if it doesn't cross a style run.

Here is one example from a recent post:

http://www.gammon.com.au/forum/?id=13417&reply=3#reply3

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Tesagk   (51 posts)  [Biography] bio
Date Reply #5 on Tue 06 Sep 2016 11:41 PM (UTC)
Message
Thanks. I will take a look at it and see what I can do.
[Go to top] top

Posted by Tesagk   (51 posts)  [Biography] bio
Date Reply #6 on Wed 07 Sep 2016 12:39 AM (UTC)

Amended on Wed 07 Sep 2016 04:09 AM (UTC) by Nick Gammon

Message

<triggers>
  <trigger
   group="global"
   keep_evaluating="y"
   match="(\[([\w'\-\s\d]+)\(#(\d+)\)(?:\{(\w+)\})?(?:&lt;\-\(#([\d-]+)\))?(?:,(\w+))?\]\s)"
   name="triNoSpoofCapture"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="100"
  >
  <send>local noSpoof = "%1"
for k,v in ipairs(TriggerStyleRuns) do
  text = string.gsub(v.text, noSpoof, "")
  ColourTell(RGBColourToName(v.textcolour),RGBColourToName(v.backcolour),text)
end
Note(text)</send>
  </trigger>
</triggers>


So, in attempting to do what you suggested...

This:

[Barrabus(#9443){Shawn}<-(#10322)] As you enter, Barrabus lifts a hand in greeting. "Welcome t' th' Fighters Guild! If yer new here, I c'n answer some questions! (OOC: Information is available via '+fg/info'. '+fg/help' will give you help on commands that work on the Guild grounds).


turns into this:


[Barrabus(#9443){Shawn}<-(#10322)] Ayoenter, Barrabulifthand igreeting. "Welcome t' th' FighterGuild! If yenehere, I c'answesome questions! (OOC: Informatioiavailable vi'+fg/info'. '+fg/help' will give yohelp ocommandthat work othe Guild grounds).' will give yohelp ocommandthat work othe Guild grounds).


[EDIT] Fixed up square brackets.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Wed 07 Sep 2016 04:04 AM (UTC)
Message
What is in the "noSpoof" variable?

Never mind, I spotted it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Wed 07 Sep 2016 04:22 AM (UTC)

Amended on Wed 07 Sep 2016 06:18 AM (UTC) by Nick Gammon

Message
You had me going for a minute because "enabled" was not set to "y".

Testing it at Regular Expressions 101 I get:


Match information

1.	[0-35]	`[Barrabus(#9443){Shawn}<-(#10322)] `
2.	[1-9]	`Barrabus`
3.	[11-15]	`9443`
4.	[17-22]	`Shawn`
5.	[27-32]	`10322`


Now match 1 there (which you are using for noSpoof) is considered a (Lua) regular expression, so it looks like something that matches any of the things inside the square brackets, not the whole thing.

So, you need to fixup the %1 pattern first, using another string.gsub, like this:


<triggers>
  <trigger
   enabled="y"
   group="global"
   keep_evaluating="y"
   match="(\[([\w'\-\s\d]+)\(#(\d+)\)(?:\{(\w+)\})?(?:&lt;\-\(#([\d-]+)\))?(?:,(\w+))?\]\s)"
   name="triNoSpoofCapture"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="100"
  >
  <send>

local noSpoof = string.gsub ("%1", "[%%^%%$%%(%%)%%%%%%.%%[%%]%%*%%+%%-%%?]", "%%%%%%1")

for k,v in ipairs(TriggerStyleRuns) do
  text = string.gsub(v.text, noSpoof, "")
  ColourTell(RGBColourToName(v.textcolour),RGBColourToName(v.backcolour),text)
end

Note("")  -- finish off line

</send>
  </trigger>
</triggers>



I had to double the % symbols because of the way they work inside triggers (sigh). If you used a script file instead you wouldn't need as many percents.

Basically the string.gsub finds the following things and puts a % in front of them:

Quote:

Magic characters

There are some "magic characters" (such as %) that have special meanings. These are:

^ $ ( ) % . [ ] * + - ?


A debugging print (since removed) shows the noSpoof variable is now:


%[Barrabus%(#9443%){Shawn}<%-%(#10322%)%] 


Now that correctly matches. My output from your test string was:


As you enter, Barrabus lifts a hand in greeting. "Welcome t' th' Fighters Guild! If yer new here, I c'n answer some questions!
(OOC: Information is available via '+fg/info'. '+fg/help' will give you help on commands that work on the Guild grounds).


(Added a newline to make the post look better).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Wed 07 Sep 2016 04:26 AM (UTC)
Message
Note that this assumes that the nospoof stuff is all inside one style run.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Tesagk   (51 posts)  [Biography] bio
Date Reply #10 on Wed 07 Sep 2016 09:49 AM (UTC)
Message
I do need to work with script files more, so, cutting down on the % escapes is definitely a motivator.

Sorry about the "not-enabled" bit. Because of how it was garbling things, I needed it off to read anything.

Thanks for the help!
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #11 on Wed 07 Sep 2016 08:40 PM (UTC)

Amended on Wed 07 Sep 2016 08:41 PM (UTC) by Nick Gammon

Message
This is that line with the %s halved:


local noSpoof = string.gsub ("%1", "[%^%$%(%)%%%.%[%]%*%+%-%?]", "%%%1")


It is basically a "%" in front of each of the magic characters (including % itself which is why you see 3 in a row at one point). Then the replacement is another % (which has to be doubled) followed by %1 (which is the character it found).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Tesagk   (51 posts)  [Biography] bio
Date Reply #12 on Thu 08 Sep 2016 12:36 PM (UTC)
Message
Quick follow-up question: How do I interact with triggers through a script file? Do I utilize callbacks? I would like to turn this into a script file so that I can get started on that process, as well as extending the script to its full purpose (gathering and sometimes displaying nospoof information).
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #13 on Thu 08 Sep 2016 08:17 PM (UTC)
Message
Don't "send to script" (send to world and leave the send box empty).

Put a function in your script file.

Put its name in the "Script" box.

The function looks like this:


function myTriggerHandler (name, line, wildcards, styles)

end -- function


In that function wildcards [1] will contain what %1 previously did.

"styles" will be a table of styles, like TriggerStyleRuns.

You don't need to double "%" symbols.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Tesagk   (51 posts)  [Biography] bio
Date Reply #14 on Fri 09 Sep 2016 02:31 PM (UTC)
Message
When I put the function in the script box, do I pass the parameters? If so, how? Do I just pass them with the values in your example?


dslpnp.statusbar.promptHandler(name, line, wildcards, styles) ?


Or, do I do:

dslpnp.statusbar.promptHandler(trigger_label, ??, ??, TriggerRunStyles)
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


8,893 views.

This is page 1, subject is 3 pages long: 1 2  3  [Next page]

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]