mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2010
Posts: 17
E
Pikka bird
OP Offline
Pikka bird
E
Joined: Mar 2010
Posts: 17
Hey there, I have been trying to do a remote script where if someone stupidly changes nick to one that is forbidden to use in channel (like a profanity nick), and the script for some reason is not working. This is what I have where user level 6 contains all forbidden nicks.

Code:
on *:NICK:{
  if ($ulevel($address($newnick,5)) == 6) { kick $newnick Attempting to use a profanity nick is forbidden in this channel }
  else { halt }
}

Last edited by ErikMouse; 11/09/10 07:46 AM.
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
You have to either manually specify the channel name in the kick command, or loop through the common channels kicking from each.

In either case, I also recommend that you include a check to ensure you are opped in that channel.

One other thing I'd like to point out, is the fact that the user levels are using $address(<nick>,5) which is in the format of nick!user@host where none of those items are wildcarded.


Joined: Mar 2010
Posts: 17
E
Pikka bird
OP Offline
Pikka bird
E
Joined: Mar 2010
Posts: 17
I went in and included the missing #channel to the kick part, something I missed. And it still does not work even when OPed in channel.

Joined: Feb 2003
Posts: 3,432
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
did you try debug?
Code:
on *:NICK:{
  echo -a nick change, $nick > $newnick
  echo -a userlevel, $ulevel($address($newnick,5))
  if ($ulevel($address($newnick,5)) == 6) { kick $chan $newnick Attempting to use a profanity nick is forbidden in this channel } 
 else { halt }
}

and then look at the echo and see if it's a match, the $ulevel would be the part i guessing dont work for you.


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Joined: Mar 2010
Posts: 17
E
Pikka bird
OP Offline
Pikka bird
E
Joined: Mar 2010
Posts: 17
I put that in and I ended up seeing this
Quote:
nick change, Testing54321 > FuckOffAndDiePlease
userlevel,

And no userlevel number showing.

Joined: Feb 2003
Posts: 3,432
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
try change $ulevel to $level instead..


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Joined: Mar 2010
Posts: 17
E
Pikka bird
OP Offline
Pikka bird
E
Joined: Mar 2010
Posts: 17
Seems that changing $ulevel to $level instead seems to have worked, but then I kept getting "FuckOffAndDiePlease No such channel" which has me thinking that for some reason it is ignoring $chan as it worked when I replaced that with the name of the channel I am testing this in. Not sure why "kick $chan $newnick" isn't working.

Joined: Feb 2003
Posts: 3,432
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
add channel to a %var, then call it when it's time for the kicking part.. kick %var $newnick


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Joined: Aug 2010
Posts: 134
T
Vogon poet
Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Code:
on *:NICK:{
  if ($ulevel($address($newnick,5)) == 6) { kick $newnick Attempting to use a profanity nick is forbidden in this channel }
  else { halt }
}


Your code makes my head hurt.

Code:
on *:NICK:{
  if ($ulevel($address($newnick,5)) == 6) {


$ulevel doesn't take parameters. You should write:

Code:
on *:NICK:{
  if $ulevel == 6 { kick $newnick Attempting to use a profanity nick is forbidden in this channel }
  else { halt }
}


Or even faster:

Code:
on 6:NICK:{
  kick $newnick Attempting to use a profanity nick is forbidden in this channel
}


Also, why is the halt even there? It means it would prevent all other nick changes from displaying. Unless that is what you were after, remove the entire else line.

Secondly, you need to issue a channel to kick the user in. NICK is not a channel event, so $chan is equal to $null. You must either check a specific channel, or check all channels the user is on.

If you only want to monitor a specific channel:

Code:
on 6:nick: {
  if $newnick ison #mychannel {
    if $me isop #mychannel || $me ishop #mychannel {
      kick #mychannel $newnick blah blah blah
    }
  }
}


If you want to monitor all channels you are on:

Code:
on 6:nick: {
  var %chancount 0
  while %chancount < $comchan($newnick, 0) {
    var %chancount $calc(%chancount + 1)
    var %chan $comchan($newnick, %chancount)
    if $me isop %chan || $me ishop %chan {
      kick %chan $newnick blah blah blah
    }
  }
}


Learning something new every day.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Thels, /var should use = when being set and there's no reason to use $calc to increment a variable. Use /inc %chancount, or if you really want to use +1, then just put /var %chancount = %chancount + 1. It doesn't need $calc.


Invision Support
#Invision on irc.irchighway.net
Joined: Aug 2010
Posts: 134
T
Vogon poet
Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Originally Posted By: Riamus2
Thels, /var should use = when being set and there's no reason to use $calc to increment a variable. Use /inc %chancount, or if you really want to use +1, then just put /var %chancount = %chancount + 1. It doesn't need $calc.


Doesn't inc make something a global variable?

As for the =, that's just whatever style you prefer. In some cases (such as when you use [ $+ [ ] ] for arrays), you can't even use =.


Learning something new every day.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
/inc doesn't make a var global as long as the var was set up previously.

The use of []'s like that isn't really the best way to script it anyhow. That's similar to using GOTO instead of WHILE. Although it works, WHILE (or $+() in your example) is the better choice. = is just a better way to script it. It makes it clear that it's not a global variable and clearly shows what part is the data being put into the variable. Much better if you're showing someone who is new to scripting how to do it.

What it comes down to is that when you're teaching someone (most answers on this forum will be teaching the OP how to script something), you should keep the code as clean as possible and stick to normal scripting practices rather than shortcuts unless you're also taking time to explain that it is a shortcut and why you're using it.

In all learning, shortcuts should come after learning how to do it the normal way. It prevents confusion later. It's one thing if you're teaching a shortcut that makes a major difference in speed. It's quite another if you're showing a preference in how the script should look.

For example, some people prefer to script everything on one line using |'s. Although that will work, if you're teaching someone how to do something, you should show it on multiple lines. Although one line coding is a preference and can be used by anyone who likes that method, it's not the way to teach scripting. Using or not using ='s and using or not using $+() are also preferences and even if they don't confuse the issue as much as one line scripting, it's better to stick to a normal method to avoid confusing a new scripter. Just something to keep in mind.

It's up to you what you want to do. But you definitely don't need to use $calc() there instead of either /inc or just +1. Just trying to point out that using = is how /var is meant to be used.


Invision Support
#Invision on irc.irchighway.net
Joined: Aug 2010
Posts: 134
T
Vogon poet
Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Originally Posted By: Riamus2
/inc doesn't make a var global as long as the var was set up previously.


I wasn't aware of this. Ok, then "/inc" is indeed nicer.

Originally Posted By: Riamus2
The use of []'s like that isn't really the best way to script it anyhow. That's similar to using GOTO instead of WHILE. Although it works, WHILE (or $+() in your example) is the better choice. = is just a better way to script it. It makes it clear that it's not a global variable and clearly shows what part is the data being put into the variable. Much better if you're showing someone who is new to scripting how to do it.


Ain't %x [ $+ [ %y ] ] the way to use arrays? That doesn't work with $+(), does it?

Originally Posted By: Riamus2
What it comes down to is that when you're teaching someone (most answers on this forum will be teaching the OP how to script something), you should keep the code as clean as possible and stick to normal scripting practices rather than shortcuts unless you're also taking time to explain that it is a shortcut and why you're using it.

In all learning, shortcuts should come after learning how to do it the normal way. It prevents confusion later. It's one thing if you're teaching a shortcut that makes a major difference in speed. It's quite another if you're showing a preference in how the script should look.

For example, some people prefer to script everything on one line using |'s. Although that will work, if you're teaching someone how to do something, you should show it on multiple lines. Although one line coding is a preference and can be used by anyone who likes that method, it's not the way to teach scripting. Using or not using ='s and using or not using $+() are also preferences and even if they don't confuse the issue as much as one line scripting, it's better to stick to a normal method to avoid confusing a new scripter. Just something to keep in mind.

It's up to you what you want to do. But you definitely don't need to use $calc() there instead of either /inc or just +1. Just trying to point out that using = is how /var is meant to be used.


I'm trying to keep my code as clean and simple as I can when posting it here. However, I'm unaware of what is 'standard' for some cases.

Inc is definitely a nicer way to increase a variable by 1. I simply was under the assumption that it would make it a global variable, and I dislike the use of global variables where they are not required.

The "/var %x = 1" or "/var %x 1", they both work. In my opinion, the 2nd one looks 'cleaner', since it's more conform all other commands, also works for arrays, and it makes sure that there's never a single '=' in my code. It makes it easier to spot mistakes like a single '=' in if statements.

Nonetheless, if the "/var %x = 1" is really a standard, I could use it on here. Still won't use it in my own code, though :P


Learning something new every day.
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
Originally Posted By: Thels

Ain't %x [ $+ [ %y ] ] the way to use arrays? That doesn't work with $+(), does it?


i wouldn't call them 'arrays', [] allows you to control the order of evaluation and also modifies the behaviour of $+ in ways that make it more useful in certain situations. in case you're interested, i have a tutorial on evaluation brackets up at:

http://www.xise.nl/mirc/wiki/doku.php?id=eval

it's a bit old but the information should still be accurate


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Aug 2010
Posts: 134
T
Vogon poet
Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Originally Posted By: jaytea
Originally Posted By: Thels

Ain't %x [ $+ [ %y ] ] the way to use arrays? That doesn't work with $+(), does it?


i wouldn't call them 'arrays', [] allows you to control the order of evaluation and also modifies the behaviour of $+ in ways that make it more useful in certain situations. in case you're interested, i have a tutorial on evaluation brackets up at:

http://www.xise.nl/mirc/wiki/doku.php?id=eval

it's a bit old but the information should still be accurate


I've read it before. It's informative. smile

Yeah, they're technically not arrays, but you could use them to resemble arrays, which is what I use them for on occasion (for variables within a routine. Outside of that I prefer using hash tables). I use $+( ) anywhere else than for 'arrays'.


Learning something new every day.

Link Copied to Clipboard