mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
Joined: Sep 2012
Posts: 12
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Sep 2012
Posts: 12
Hello - I have a functional banned nickwords script, but I've been trying to make this easier on myself when adding more words. It reads from a list in a text file.
The Problem is: It only works if the nicks are exactly the words listed in the text file.
Unfortunately no matter how hard I've tried, I cannot get it to work if the words listed are anywhere within the nick. Obviously I'm trying to avoid having to manually add (every_word_I_need_to_add isin $nick). I have tried everything I know with adding $+, [eval brackets] and $Chr(42) for the wildcard, and no matter what I try it stops the script from working. There's got to be a simple solution that I can't realize, like maybe using a var? Any help would be appreciated. Thanks.

if ($read(G:\pathway\bannednickwords.txt, w, $newnick) iswm $newnick) || (badword isin $nick) <--trying to avoid dozens of these {
var %i = 0
while (%i < $comchan($newnick,0)) {
inc %i
if ($newnick isop $comchan($newnick,%i)) || ($newnick ishelp $comchan($newnick,%i)){ return }
if ($me isop $comchan($newnick,%i)) {
ban -u30 $comchan($newnick,%i) $newnick 11
kick $comchan($newnick,%i) $newnick Not allowed!
}

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
A couple of things:

1) You are using a wildcard search without using wildcards. That means you want an exact match, so it wouldn't look within anything.

2) You are searching the text file for the entire nick, which means it won't ever match unless the entire nick is in the text file (you're basically checking this backwards).

Using the text file method you have, you'd need to stop searching the text file and instead you would loop through the text file and check every line and compare it to the $newnick using isin/iswm. That would work fine, but isn't the most efficient method. However, if you have a small number of words in the text file and people aren't changing their nicks regularly, then it won't really matter and it's easy to manage. If you have a lot of words or people change nicks regularly, you would be better off keeping the words in a hash table. It will be more efficient that way.

There are other ways as well, but those are two that are easy enough to do.


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2012
Posts: 12
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Sep 2012
Posts: 12
Alright. I have tried your advice and nothing I'm trying is working so apparently what I'm doing is wrong. Is the while loop incomplete or improperly placed? I've tried isin as well. Any ideas?


var %i = 0
while (%i < $comchan($newnick,0)) {
inc %i
if ($newnick isop $comchan($newnick,%i)) || ($newnick ishelp $comchan($newnick,%i)){ return }
if ($me isop $comchan($newnick,%i)) && ($read(G:\pathway\bannednickwords.txt, w, $newnick) iswm $newnick) {
ban -u30 $comchan($newnick,%i) $newnick 11
kick $comchan($newnick,%i) $newnick Not allowed!
}

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Code:
var %i = 1, %c
while ($comchan($newnick,%i)) { 
%c = $v1
if (!$nick(%c,$newnick,oh)) && ($me isop %c) && ($read(G:\pathway\bannednickwords.txt,nw,$+(*,$newnick,*))) {
ban -ku30 %c $newnick 2 $newnick Not Allowed!
}
inc %i 
}

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Like I mentioned, you can't do a $read search like that because it is backwards. Doing it that way, you're checking if the entire new nick is part of a bad word. You aren't checking if a bad work is part of the new nick. You'd have to loop through all of the bad words to do the check that is needed.

Code:
var %i = 1, %t = $lines(filename.txt)
while (%i <= %t) {
  if ($read(filename.txt,nt,%i) isin $newnick) {
    ban -ku30 #channel 2 $newnick Not Allowed!
    return
  }
  inc %i
}


Note that this is just a really quick example as I don't have time to do more right now and it would only work for one channel. It can be expanded upon to work in multiple channels. Also, as I mentioned, if you're going to have a lot of words, it's going to be more efficient to have the words in a hash table and loop through that instead of the text file. Also, if you're going to loop through a text file, $fread may be faster. And there may even be a good regex method that can check all parts of a newnick and search for those in the text file, but I don't know how that would be written.


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
I'd believe that using the /filter will be more efficient. Thank you, Riamus2...I wasn't paying close attention to the matter at hand. Or perhaps make use of the $fline() identifier to check against the nicklist.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Yeah, /filter is probably faster. I had only a few minutes to type that up this morning and that was easier to type quickly than /filter, which I don't use regularly, so would have to remember the correct syntax.


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2012
Posts: 12
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Sep 2012
Posts: 12
Thanks so much for your help guys, I really appreciate it. Unfortunately, I can't seem to get this to work for me. I have nested the coding that Riamus2 posted into my on:nick events at the top, and I can't get it to catch at all. I even put a 'kick # $nick' in there for quick confirmation of it working. I've also tried iswm too. I even put a if ($chan == #mychannelname) above this as well with brackets to no avail.
It's still just a small simple thing away from working, isn't it? Thanks again for the efforts here.

var %i = 1, %t = $lines(G:\filepath\bannednickwords.txt)
while (%i <= %t) {
if ($read(G:\filepath\bannednickwords.txt,nt,%i) isin $newnick) {
ban -ku3 # 2 $newnick Not Allowed!
kick # $nick test <--added
return
}
inc %i
}

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
The on nick event does not have a $chan, so you have to specify the actual channel name or else use $comchan. If you think it's not triggering, try putting an /echo in there to see where it isn't working. Keep in mind that this will read a text file that has words in it like:

these
are
bad
words

Then, if the word on the line is within the $newnick (such as Iambad), it will trigger the ban.


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2012
Posts: 12
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Sep 2012
Posts: 12
Yes, I know it doesn't. I was trying this nested at the top of my on *:NICK: and using another instance of mirc with a non-opered version of myself in testchannel, trying nick changes to the badwords listed.
It also will not work when tried in the on *:join: as one of the badnickwords either. No luck at all, but thanks though.

if ($chan == #mytestchannel) {
var %i = 1, %t = $lines(G:\filepath\bannednickwords.txt)
while (%i <= %t) {
if ($read(G:\filepath\bannednickwords.txt,nt,%i) isin $newnick) {
ban -ku3 # 2 $newnick Not Allowed!
kick # $nick testing
return
}
inc %i
}
}

Last edited by displayname; 21/09/12 02:24 AM.
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
I think it'd be better that you use a hash table in this fashion as what Riamus2 has suggested initially:
Code:
/hadd -m bad *badnick*
/hadd -m bad *badnick2*
/hadd -m bad *badnick3*
etc...
then simply use:
Code:
on *:exit:{
  hsave bad bad.hsh
}
on *:start:{
  if (!$hget(bad)) hmake bad 100
  hload bad bad.hsh
}
on *:nick:{
  if ($hfind(bad,$newnick,1,W)) { 
    ban -k #chan $v1 2 Bad Nick Not Allowed!
  }
}
Replace #chan with the actual channel name.

This will match new nicknames against the main bad ones you've added. The asterisk symbol on both ends will match within a changed nickname as per your wish.

This is only to check on a single channel basis. If you want it to take care of all the channels that you're opped and on, you need to modify it using $comchan($newnick,N)

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Nice trick with the *'s. Much better than looping. I didn't know that would work. smile


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Thanks for the mention of hash table Riamus2. wink

Joined: Sep 2012
Posts: 12
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Sep 2012
Posts: 12
Thanks so much again for the reply on this. It didn't work for me right away because I must've gotten onto it right after when you first posted it Tomao and it had said 'badnick' within the brackets, which thankfully I soon figured out should be bad, (edited now) then it fired but still didn't work correctly so I changed "Bad Nick" in the banline to $newnick and also dropped the "2" based on the status msgs I was seeing. It works great now! Many many thanks for this!
The following code works perfectly fine for me:
Code:
on *:nick:{
  if ($hfind(bad,$newnick,1,W)) { 
    ban -ku30 #chan $v1 $newnick Not Allowed!
  }
}
Working just fine in the "on *:join:" event as well. Awesome idea overall Tomao, and yes, even better with the *'s in the entries.
Code:
on *:join:#mychannel:{
  if ($hfind(bad,$nick,1,W)) { 
    ban -ku30 #mychannel $v1 $nick Not Allowed!
  }
} 

Questions: It works with or without the $v1 in the banline, should I just disregard. Will that be as issue?
Is there any way to read or view the hash table to revisit what you have entered, or is that impossible and I'll have to keep a masterlist?
Seriously, thank you so very much for this! laugh

Last edited by displayname; 21/09/12 10:26 PM.
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
You're most certainly welcome, displayname. I'm glad that the code provided has worked to your standards and expectations.

Actually the $v1 identifier returns the matched bad nicknames, along with the asterisks. That is the reason why it wasn't working quite right as intended. And yes, it's a good idea that you disregard or delete it in favor of using the $newnick instead. Pardon me for not thinking correctly. :$

You may change the number 1 to 0 in the $hfind() since 1 returns the whole, exact bad nicknames, which in this case isn't necessary. By changing it to 0, $v1 returns 1 if found, and 0 if not vice versa.

Joined: Sep 2012
Posts: 12
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Sep 2012
Posts: 12
Except, I'd better figure out how to make this channel specific because I just retried the nickchange to a badnickword in my test room, and it banned the badnick in the object room without being in there, by my coding of course. It shouldn't ban in that room unless the nickchange took place in that room. Hmm.

Last edited by displayname; 21/09/12 10:42 PM.
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Originally Posted By: displayname
I'd better figure out how to make this channel specific
Code:
on *:nick:{
  var %s = #chan1 #chan2 #chan3 #chan4 #chan5
  if ($hfind(bad,$newnick,0,W)) { 
    var %c = 1, %cc
    while ($comchan($newnick,%c)) {
      %cc = $v1
      if ($istok(%s,%cc,32)) {
        ban -ku30 %cc $newnick 2 Not Allowed!
      }
      inc %c
    }
  }
}
Substitute #chan1, #chan2, etc..with the ones where you want the code to work on.

P.S. I've re-added the 2 because it bans offenders' hosts. Without specifying it, mIRC uses the whole nick!*user@host to do the ban. This is perfectly optional to you.

Last edited by Tomao; 21/09/12 10:46 PM.
Joined: Sep 2012
Posts: 12
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Sep 2012
Posts: 12
Thanks again for the efforts. I tried what you posted and unfortunately had no luck with making that work. I ended up putting it in a while loop and it's doing what I want now. I also prefer your idea of using 2 to shorten the Ban, it keeps the badword from being repeated. smile
Code:
  var %i = 0
  while (%i < $comchan($newnick,0)) { 
    inc %i 
  if ($newnick isop $comchan($newnick,%i)) || ($newnick ishelp $comchan($newnick,%i)){ return }
  if ($hfind(bad,$newnick,1,W)) {
    ban -ku30 $comchan($newnick,%i) $newnick 2 Not Allowed!
}
Oh yes, and courtesy of Tomao this one works as well, and is very channel specific. Thanks Tomao! grin
Code:
  var %s = #testchannel
  if ($hfind(bad,$newnick,0,W)) { 
    var %c = 1
    while (%c <= $comchan($newnick,0)) {
      if ($istok(%s,$comchan($newnick,%c),32)) {
        if ($newnick isop $comchan($newnick,%c)) || ($newnick ishelp $comchan($newnick,%c)) return  ; <--added by me for obvious reasons
        ban -ku30 $comchan($newnick,%c) $newnick 2 Not Allowed!
      }
      inc %c
    }
  }

Last edited by displayname; 24/09/12 01:25 AM.
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Code:
if ($newnick isop $comchan($newnick,%c)) || ($newnick ishelp $comchan($newnick,%c)){ return }
Can be shortened a bit to:
Code:
if ($nick($comchan($newnick,%c),$newnick,oh)) { return }

Joined: Dec 2010
Posts: 23
N
Ameglian cow
Offline
Ameglian cow
N
Joined: Dec 2010
Posts: 23
one i use
on *:TEXT:*:#channel:{
if ($nick isop $chan) { halt }
var %badword = $strip($1-,burc)
if (*word1* iswm %badword) || (*word2* iswm %badword) || (*word3* iswm %badword) {
ban -u60 $chan $nick 13 | kick $chan $nick 11 You Can't Use Those Words Here, 1 Minute ban You said --> > 1,2|12,2|2,12|10,12|12,10|11,10|10,11|0,11|11,0| 1,0 %badword 11,0|0,11|10,11|11,10|12,10|10,12|2,12|12,2|1,2| 11 in $ifmatch  }
}

Page 1 of 2 1 2

Link Copied to Clipboard