Alias request: prefix/suffix, /g and matches[]

Zanthis
Posts: 23
Joined: Mon Dec 09, 2013 8:35 pm

Alias request: prefix/suffix, /g and matches[]

Post by Zanthis »

I've got some issues with aliases and I'm pondering if this set of requests is what I need or not. Any feedback would be appreciated. My other alternative is to write an entirely separate alias system where I match every line and process it against a custom table of aliases. I'd hate to do that because I'd really like for users of this package to be able to add aliases in the logical place...under aliases.

REQUEST 1:
If Alias Groups could have a prefix and suffix string that is added to the front and back of all aliases under them.

EXAMPLE:
The MUD I'm working with allows compound commands separated by | characters. As a result, if I want to add a simple alias to change "bandage" into "bandage self" I need to use this:
Code: [show] | [select all] lua
(?:^|\|)\s*(bandage\b[^|]*?)\s*(?=$|\|)
Which is ugly and has the potential for errors when lots of aliases are being created. Especially because the MUD also uses implicit command completion, and so the bandage command can be "band", "banda", "bandag" or "bandage" which results in a final matching string of:
Code: [show] | [select all] lua
(?:^|\|)\s*(band(?:a(?:ge?)?)?\b[^|]*?)\s*(?=$|\|)
If I could pull out the prefix and suffix in the Alias Group, it would be much cleaner:
Code: [show] | [select all] lua
(?:^|\|)\s* -- Prefix
\b[^|]*?)\s*(?=$|\|) -- Suffix
(band(?:a(?:ge?)?)?)  --Actual alias
BENEFIT
Basic alias regexs are really easy to create for users of the package.

PROBLEM
To actually apply the alias, the combined regex is still needed to iterate over the command string. EDIT: Which I can't even do because I don't have pcre in Lua :(

REQUEST 2:
This is a two part request. First, a /g option for aliases, and to really make use of that, changes to matches are written back into command.

EXAMPLE:
With the above example, I would be able to make an alias with just the below, using the above prefix/suffix request:
Regex:(band(?:a(?:ge?)?)?)
Script:matches[2] = matches[2] .. " self"

PROBLEM
It is a little tricky to combine matches[] writing to command with /g matching.

REQUEST 1 alternate
An alternate would be to allow a Type: Custom for aliases. Then have an event that fired whenever the Custom aliases are changed. During that event scripting could modify the regex of the alias, which for Type:Custom aliases would be separate and not manually modifiable. With this I could add the prefix and suffix via script to the string the user entered and build the actual regex that way. I'd also be able to handle the implicit command completion for the user. I could translate something like band((age)) into band(?:a(?:ge?)?)? in addition to adding the prefix and suffix.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Alias request: prefix/suffix, /g and matches[]

Post by Vadi »

You do have pcre in Lua - both Lua's patterns with are simpler and quicker, and PCRE - we include lrexlib PCRE version in Mudlet (see http://rrthomas.github.io/lrexlib/manual.html). So you could match on a simpler aliases and do any kind of post-processing after in the script.

It hasn't clicked to me how your request 2 will work and how it doesn't work now between optimzing (or just parsing) the pipe characters and dealing with the MUDs autocompletion. You can either be trying to mimic autocompletion on the players side and send the full command to the game, trying to optimize your stuff to send it together with pipes or simply parsing them so the aliases would work.

Zanthis
Posts: 23
Joined: Mon Dec 09, 2013 8:35 pm

Re: Alias request: prefix/suffix, /g and matches[]

Post by Zanthis »

The main issue is I want to provide a package to players such that they can quickly and easily create aliases. If I don't have request 2, then the body of each alias they create needs to do parsing work. I can do that, sure, no problem. But I'm then adding this expectation to users who may have very limited Lua and Regex experience. I'd probably create a set of functions they can use, but that still put some burden on them to learn how to use my functions, rather than using normal Mudlet aliases that I'm magically fixing to work in all corner cases for this MUD.

I'm not saying the current system is impossible to work with, I'm just saying I wish I could provide a cleaner solution. I've had to pulled a lot of my aliases out in favor of a global .* alias that processes everything, which I feel isn't really in the spirit of an alias system.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Alias request: prefix/suffix, /g and matches[]

Post by Vadi »

Yeah, I understand your case for the user experience but not how you'd like it to work and how the MUD works.

There is also http://wiki.mudlet.org/w/Manual:Event_E ... endRequest which would avoid a .* alias that captures everything and allows you to rewrite input via script, which might be cleaner. It might or might not allow the creation of aliases from the UI for the users still - but like I mentioned, I don't know how you'd like it to work and how the game mechanics work.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Alias request: prefix/suffix, /g and matches[]

Post by Vadi »

I guess I'm trying to wrap my head around this:

- if the MUD accepts pipes, why do you need to handle decoding the pipes in the client? Wouldn't the users be creating aliases that do send("one|two|three")?
- I'd sort of understand if you wanted to optimize your systems commands to be sent all at once with pipes, but then that would require a quite different approach to the one you're taking.

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Alias request: prefix/suffix, /g and matches[]

Post by Jor'Mox »

I'm guessing the issue is allowing for more than one "alias" to be applied to a a single line sent by the user, due to a desire to use an alias for a command in both its normal, stand alone usage, and as one of several commands divided by pipes.

Using the event that fires when a command is sent would be a passable work around. If there is a pipe in the command, split it using pipes as dividers, and then send each resulting string through expandAlias. It wouldn't use the server parsing of pipes at all, but it would mimic the behavior you are looking to create, while still allowing for simple alias creation by the end user.

Zanthis
Posts: 23
Joined: Mon Dec 09, 2013 8:35 pm

Re: Alias request: prefix/suffix, /g and matches[]

Post by Zanthis »

I considered that, but I'd need to them combine the commands back together which I'm not certain I can cleanly do. For example, suppose someone sent the command: "drop hammer | get mushroom | eat mushroom | get hammer". That's four commands, and if I break them apart and expandAlias() each separately so that instead of a combined command going to the server, four separate commands are sent, there is a chance of a lag delay appearing between commands. Sent as a combined command with pipes, all the commands arrive at the server at the same moment, which insures minimum delay in execution time between them. So in this example, the hammer is on the ground for the shortest period of time.

Another option would be a variant of expandAlias() that instead of sending it to the MUD just returns what would have been sent to the MUD (or nil if nothing would have been sent). Then I could use this command, feedAlias() or whatever, on each command of the pipe and reassemble the command variable.

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: Alias request: prefix/suffix, /g and matches[]

Post by Jor'Mox »

You can't combine them together again right now in the way you are suggesting. What I suggested is essentially the only way to make what you are talking about work with Mudlet in its current state. Obviously if some additional functionality is added, then more options would become available.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Alias request: prefix/suffix, /g and matches[]

Post by Vadi »

When you use expandAlias() within sysDataSendRequest, you still trigger sysDataSendRequest.

Still not really sure why would you make people use pipes and make them setup aliases as well. I'd understand if those were system aliases you wanted the user's to trigger in their pipes, but their own aliases as well? Why not make aliases to begin with and use something that'll auto-pipe?

Zanthis
Posts: 23
Joined: Mon Dec 09, 2013 8:35 pm

Re: Alias request: prefix/suffix, /g and matches[]

Post by Zanthis »

Ok, the MUD itself processes pipes as command separators. This isn't a feature I'm adding, it's all coming from the MUD. So if I send "n|n|e|d" over even a basic telnet client, the MUD will queue up 4 movement commands. Because my scripting needs to know exactly what commands are being executed when, and it knows that each time it sees a prompt no more than one command has been executed, I need to manually track all commands that the player sends. This works fine when they don't use a pipe. But if they do, I need to account for that. Which I can do pretty easily.

Until the player wants to create a mudlet alias like gototrainer which expands into "s|w|s|w|w|w|s|d". Now imagine the player types this at the command prompt: "n|n|gototrainer". I need to expand gototrainer via Mudlet's aliases, then count and queue up each individual resulting movement command. And gototrainer might appear more than once, so I have to globally find/replace it. Which makes the gototrainer alias a user creates suddenly very non-trivial.

Post Reply