So users
are the ones giving this input. You seem to have excluded a lot of relevant information from this discussion. I really don't care about a difference between viewers and mods, the only thing that matters is the input to this alias and where it originates (you or elsewhere). To confuse things even more you're referring to three different things all as commands.
This is what I've gotten from your explanation:
1. A user types !profile nick
2.
Some other person crafts a user friendly
message3. This message is sent to you, evaluated, and sent to the channel
That doesn't provide a use for @target@ though.
But here's a new thought I've had based on past experience with twitch requests and
not at all from what you've explained:
1. A mod can craft a new "command" which consists of a "command" part and "response" part.
2. You expose something like !addcom to privileged users and store these in an ini file or hash table.
3. You have a catch-all text event which checks if a user has said a "command" present in your data structure.
4. The corresponding response is evaluated by the alias we've been discussing and sent to the channel. This
does allow a stored @target@[1] to refer to the original text of the !profile command.
I hope that's correct, because I've amended the script to pass the original user text in order to facilitate @target@[]. I've also slightly modified the regex to allow omission of brackets which got messed up before (@pi@).
Edit: Calling %command %args %user.text causes problems with spaces and I've had to use evaluation brackets [ ] to call it as $command(%args,%user.text). Using these brackets introduces the possibility of an injection but I believe I've coded appropriately to avoid them and have tested input and each of the %command %args and %user.text variables with a mixture of text containing $day $!day @$day@ with brackets [ ] and pipes | as well.
alias test {
writeini -c test.ini commands !plug @target@[1] @underline@[is another streamer] and everyone should go give a follow! @profile@[@bold@[@lower@[@target@[1]]]]
tokenize 32 !plug BOBROSS
var %command = $1, %user.text = $2-
if ($readini(test.ini,n,commands,%command) != $null) {
var %message = $v1
}
else return
var %regex = /(@[^@\s]+@(?:\[(?:[^\[\]]|(?R))*\])?)/g
echo -ag $regsubex(recurse,%message,%regex,$twitch.sub($regml(recurse,\n),%user.text))
}
alias twitch.sub {
var %message = $1, %user.text = $2
var %regex = /^@(\S+?)@(?:\[(.*?)\])?$/iS
if (!$regex(%message,%regex)) return
var %command = $regml(1)
var %args = $regml(2)
if (%args != $null) && ($regex(%args ,%regex)) {
%args = $twitch.sub.recurse(%args,%user.text)
}
%command = twitch.val. $+ %command
if ($isalias(%command)) {
return $ [ $+ [ %command ] $+ ] ( $(%args,0) , $(%user.text,0) )
}
}
alias twitch.sub.recurse return $twitch.sub($1,$2)
alias twitch.val.target return $gettok($2,$1,32)
alias twitch.val.profile return http://twitch.tv/ $+ $1
alias twitch.val.upper return $upper($1)
alias twitch.val.lower return $lower($1)
alias twitch.val.underline return $+ $1 $+
alias twitch.val.bold return $+ $1 $+
alias twitch.val.pi return $pi