|
|
Joined: Jul 2014
Posts: 316
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Jul 2014
Posts: 316 |
Hi guys, I need to add a condition to some code I have to add aliases to the channel access list via ChanServ. When I add a nickname, if the nickname format is: nick* or nick!, I need it to return the following: nick* -- returns: nick*!*@ nick! -- returns: nick!*@* But I'm having a small problem. If I type:/addnick nick!* -- returns: nick*!*@ or /addnick nick*! -- returns: nick!*@* What I want is for it to read the first character on the right and not the last.
alias addnick {
if ($1) {
if ($right($1,1) == $chr(42)) { echo -sg Returns: $remove($1,$chr(42),$chr(33)) $+ *!*@* }
elseif ($right($1,1) == $chr(33)) { echo -sg Returns: $remove($1,$chr(33),$chr(42)) $+ !*@* }
else { echo -sg Returns: $1 }
}
}
I would appreciate any help anyone can give me.
TECO irc.PTirc.org (Co-Admin)
|
|
|
|
|
Joined: Jan 2012
Posts: 380
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Jan 2012
Posts: 380 |
Try using this code:
alias addnick {
if ($1) {
var %nick $remove($1,*,!), %chars $remove($1,%nick)
if ($left(%chars,1) == *) { echo -ag Return 1: $+(%nick,*!*@*) }
elseif ($left(%chars,1) == !) { echo -ag Return 2: $+(%nick,!*@*) }
else { echo -ag Return 3: $1 }
}
}
|
|
|
|
|
Joined: Jul 2014
Posts: 316
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Jul 2014
Posts: 316 |
Try using this code:
alias addnick {
if ($1) {
var %nick $remove($1,*,!), %chars $remove($1,%nick)
if ($left(%chars,1) == *) { echo -ag Return 1: $+(%nick,*!*@*) }
elseif ($left(%chars,1) == !) { echo -ag Return 2: $+(%nick,!*@*) }
else { echo -ag Return 3: $1 }
}
}
I tested it and there's a problem. If I want to add a vHost or a mask, for example: /addnick *!*@127.1.1.1 -- Return 1: @127.1.1.1*!*@* My code: Returns: cs access #portugal add 1271.1.1.1*!*@* 3
TECO irc.PTirc.org (Co-Admin)
|
|
|
|
|
Joined: Jan 2012
Posts: 380
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Jan 2012
Posts: 380 |
The code works correctly according to the description and examples provided in the first post of your request. The description did not mention that in addition to the nick, it was also planned to use a full mask with the host/IP address. Ok, I made a few additional changes to the code. Try using this:
alias addnick {
if ($1) {
if ($numtok($1,64) == 2) { echo -ag Return 1: $1 }
else {
var %nick $remove($1,*,!,@), %chars $remove($1,%nick)
if ($left(%chars,1) == *) { echo -ag Return 2: $+(%nick,*!*@*) }
elseif ($left(%chars,1) == !) { echo -ag Return 3: $+(%nick,!*@*) }
else { echo -ag Return 4: $1 }
}
}
}
Note: This code probably won't be able to cover and correctly recognize all possible input data variants, so I would recommend splitting the functionality into several aliases, creating several commands: /addnick and /addhost. In the first case, the mask check will be performed based on the nick, and in the second case, based on the host/IP address.
|
|
|
|
|
Joined: Jul 2014
Posts: 316
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Jul 2014
Posts: 316 |
Note: This code probably won't be able to cover and correctly recognize all possible input data variants, so I would recommend splitting the functionality into several aliases, creating several commands: /addnick and /addhost. In the first case, the mask check will be performed based on the nick, and in the second case, based on the host/IP address. I can't split it because this small piece of code will be implemented in another dialog box, so I can't differentiate one command from another in the dialog box's edit box.
TECO irc.PTirc.org (Co-Admin)
|
|
|
|
|
Joined: Jan 2012
Posts: 380
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Jan 2012
Posts: 380 |
Ok. If this question is still remains relevant and you were unable to complete the code yourself, you can create a detailed list of all the required input data variants with an address mask and indicate what the return result of the response should be for each command separately/individually, to better understanding of how this can be implemented in code. For example: /addnick nick* ➔ Return: nick*!*@*/addnick nick*! ➔ Return: nick*!*@*/addnick nick! ➔ Return: nick!*@*/addnick nick!* ➔ Return: nick!*@*/addnick *@127.0.1.2 ➔ Return: *!*@127.0.1.2/addnick *!*@127.0. ➔ Return: *!*@127.0.*/addnick @127.0 ➔ Return: *!*@127.0*/addnick @127. ➔ Return: *!*@127.*/addnick @127.0.1.2 ➔ Return: *!*@127.0.1.2- ...
Note: To ensure that host/IP addresses are correctly identified, I would recommend always adding/using/specifying before them the " @" symbol.
|
|
|
|
|
Joined: Jul 2014
Posts: 316
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Jul 2014
Posts: 316 |
The list below shows the possible outcomes I would like to see the code return: /addnick nick* ➔ Return: nick*!*@*/addnick nick*! ➔ Return: nick*!*@*/addnick nick*!@ ➔ Return: nick*!*@*/addnick nick! ➔ Return: nick!*@*/addnick nick!* ➔ Return: nick!*@*/addnick nick!@? ➔ Return: nick!*@?/addnick nick!*@? ➔ Return: nick!*@?/addnick nick!*! ➔ Return: nick!*!@*/addnick nick!@127.1.1.1 ➔ Return: nick!*@127.1.1.1/addnick nick@ ➔ Return: *!nick@*/addnick nick@! ➔ Return: *!nick@!/addnick nick@? ➔ Return: *!nick@?/addnick nick@*! ➔ Return: *!nick@*!/addnick *!*@127.1.1.2 ➔ Return: *!*@127.1.1.2/addnick *!*@*.1.1.2 ➔ Return: *!*@*.1.1.2/addnick *@127.0.1.2 ➔ Return: *!*@127.0.1.2/addnick *!*@127.0. ➔ Return: *!*@127.0.*/addnick @127.0 ➔ Return: *!*@127.0*/addnick @127. ➔ Return: *!*@127.*/addnick @127.0.1.2 ➔ Return: *!*@127.0.1.2
Thank you once again for your willingness to help 
TECO irc.PTirc.org (Co-Admin)
|
|
|
|
|
Joined: Jan 2012
Posts: 380
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Jan 2012
Posts: 380 |
Well... it looks like I've managed to create code that returns all the required results specified in your list. I had little free time for further optimization, but I hope this will be enough and everything will work good. Try testing this script code:
alias addnick {
if ($1) {
if (@ !isin $1) {
var %nick $remove($1,*,!), %chars $remove($1,%nick)
if ($left(%chars,1) == *) { echo -ag Return: $+(%nick,*!*@*) }
elseif ($left(%chars,1) == !) {
if ($istok(! !*,%chars,32)) { echo -ag Return: $+(%nick,!*@*) }
elseif (%chars == !*!) { echo -ag Return: $+(%nick,!*!@*) }
}
else { echo -ag Return: $1 }
}
else {
if ($left($1,1) == @) { var %nickident *!*, %host $remove($1,@) }
else { var %nickident $gettok($1,1,64), %host $gettok($1,2,64) }
var %nick $remove(%nickident,*,!), %chars $remove($1,%nick)
;----------
if ($istok(!@? !*@?,%chars,32)) { echo -ag Return: $+(%nick,!*@?) | return }
elseif ($istok(@! @? @*!,%chars,32)) { echo -ag Return: $+(*!,%nick,@,%host) | return }
;----------
if ($numtok(%host,46) < 4) { var %host $+(%host,*) }
if ($left($1,1) == @) || ($left(%nickident,1) == *) { echo -ag Return: $+(*!*@,%host) }
elseif ($left(%chars,1) == *) { echo -ag Return: $+(%nick,*!*@*) }
elseif ($left(%chars,1) == !) { echo -ag Return: $+(%nick,!*@,%host) }
elseif (%chars == @) { echo -ag Return: $+(*!,%nick,@*) }
else { echo -ag Return: $1 }
}
}
}
|
|
|
|
|
Joined: Jul 2014
Posts: 316
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Jul 2014
Posts: 316 |
Thank you Epic for your help 
TECO irc.PTirc.org (Co-Admin)
|
|
|
|
|