unitycoders / uc_pircbotx

A bot for #unity-coders using pircbotx
GNU General Public License v3.0
3 stars 2 forks source link

Allow complex aliases #20

Closed webpigeon closed 8 years ago

webpigeon commented 12 years ago

While the command processing system allows for multiple keywords. There are some plugins which have slightly different requirements. For example being able to [thing]++ and have it translate into karma add [thing]. The creation of a system capable of recognising these aliases and redirecting the command would be a useful feature to have.

javax-swing commented 11 years ago

Perhaps some type of command expander? Could be configured from a file, and use replacements to map from one to another

E.g.) [?1]++ = karma add ?1

Pattern matching could be used to determine whether the command fits

webpigeon commented 11 years ago

I was thinking that we could precompile regular expressions in order to do this, but I'm not sure how they can be done neatly (not sure if you can use the \1 ... ect groups for matches). If we can read these in from the configuration file, it should be relatively trivial to scan though each line in another listener and pass the rewritten line to the command parser.

javax-swing commented 11 years ago

Yes thats exactly what I was thinking, the basis could be that in the properties file we could write [\1]++=karma add \1

This is then read and converted into a regex (simply by replacing all parameters with [.]+ and escaping all special characters such as []++.

This pattern can be compiled and then stored in an object with the original string. These objects can be stored in a list and the processor can iterate over them for every line (that is using commands) and pass it too the command processor as you said.

Each of these objects will be matched against the command and those that match added to a list. To get the appropriate match we may need some weighting algorithm for each regex. I think the number of literals in the sequence and the position of the [.]+'s would suffice.

The object would look like this:

class CommandPreProcessor Implements comparable { String replacementString; Pattern regex; Int literalCount; boolean startsWithAny; boolean endsWithAny;

int compareTo (c) { Int x = c.literalCount- literalCount; if (x ==0) { // todo stuff with starts with and ends with conditions } return x; } }

After that it would simply be a case of sorting the list and doing replacements on the string. Unless it would be preferable to execute mutliple matching commands On 30 Oct 2013 23:23, "Joseph Walton-Rivers" notifications@github.com wrote:

I was thinking that we could precompile regular expressions in order to do this, but I'm not sure how they can be done neatly (not sure if you can use the \1 ... ect groups for matches). If we can read these in from the configuration file, it should be relatively trivial to scan though each line in another listener and pass the rewritten line to the command parser.

— Reply to this email directly or view it on GitHubhttps://github.com/unitycoders/uc_pircbotx/issues/20#issuecomment-27448773 .

webpigeon commented 9 years ago

I have implemented this in af9bb5351256148a254448cdb52d4458e1ecd4a5

webpigeon commented 8 years ago

This can be closed as it's in master :).