Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Working with the line
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1 2
3
Posted by
| Tesagk
(52 posts) 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. | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) 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:
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 | Top |
|
Posted by
| Tesagk
(52 posts) 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. | Top |
|
Posted by
| Tesagk
(52 posts) 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. | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #4 on Tue 06 Sep 2016 10:26 PM (UTC) |
Message
| See:
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 | Top |
|
Posted by
| Tesagk
(52 posts) 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. | Top |
|
Posted by
| Tesagk
(52 posts) 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+)\})?(?:<\-\(#([\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. | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) 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 | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) 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+)\})?(?:<\-\(#([\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 | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) 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 | Top |
|
Posted by
| Tesagk
(52 posts) 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! | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) 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 | Top |
|
Posted by
| Tesagk
(52 posts) 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). | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) 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 | Top |
|
Posted by
| Tesagk
(52 posts) 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)
| 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.
97,710 views.
This is page 1, subject is 3 pages long: 1 2
3
It is now over 60 days since the last post. This thread is closed.
Refresh page
top