mIRC Home    About    Download    Register    News    Help

Print Thread
What is missing in that code? #266852 21/02/20 08:38 PM
Joined: Nov 2019
Posts: 32
A
An0o Offline OP
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Nov 2019
Posts: 32
This code reads the newnick from the text
but does not banned the newnick
What is missing to be banned newnick ?
Code
on *:NiCK:{
  var %e 1
  var %c $newnick
  var %d $lines(bads.txt)
  while (%d >= %e) {
    if ($read(bads.txt, w, *, %d) isin %c) {
      ban -ku77200 # %a
      dec %d
    }
    else {
      dec %d
    }
  }
}

Re: What is missing in that code? [Re: An0o] #266854 22/02/20 02:51 AM
Joined: Jan 2004
Posts: 1,283
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,283
%e doesn't change from being 1, so just use 1 instead of %e in your if() statement. Likewise for %c not changing, don't mess with creating that variable and just use $newnick instead of %c. I can't find where you've defined %a, so it's not clear what you're trying to do there. Try putting an echo statement above your ban command, where you "echo -s ban -ku77200 # %a" to see what command is actually be sent.

Also, your code keeps reading the entire text file even when you have matched. This means wasteful looping after someone's already banned, or even banning someone multiple times should they match several lines somehow. Better would be to have a /break command after the ban so you can escape the while() loop before it counts down to 1.

Re: What is missing in that code? [Re: maroon] #266856 22/02/20 12:14 PM
Joined: Nov 2019
Posts: 32
A
An0o Offline OP
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Nov 2019
Posts: 32
iam sorry i insert %a by mistake

Ok you mean this edition?

Code
on *:NiCK:{
  var %d $lines(bads.txt)
  while (%d >= 1) {
    if ($read(bads.txt, w, *, %d) isin $newnick) {
//echo -s ban -ku77200 # $newnick
      ban -ku77200 # $newnick
      dec %d
    }
    else {
      dec %d
    }
  }
}



And add /break command

Code
on *:NiCK:{
  var %d $lines(bads.txt)
  while (%d >= 1) {
    if ($read(bads.txt, w, *, %d) isin $newnick) {
//echo -s ban -ku77200 # $newnick
      ban -ku77200 # $newnick
      dec %d
Break
    }
    else {
      dec %d
    }
  }
}

How to apply this and /break command?

Last edited by An0o; 22/02/20 02:11 PM.
Re: What is missing in that code? [Re: An0o] #266857 22/02/20 04:11 PM
Joined: Jan 2004
Posts: 1,283
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,283
Read the /help about the n and t switches, which should always be used unless you want it to try to evaluate $word and %word within the text file, and want it to check if line 1 is a number which replaces the true number of lines in a file. Also, what you're doing is telling it to search the entire file beginning at line %d for a match with *. Instead, just read the line text verbatim.

The echo was just a debugging tool to show yourself why something isnt working, and can be removed when you solve that issue. The echo would have shown you that, not only was the %a not defined correctly, but the # is not filled with a value either. Just like in the ON QUIT event, the ON NICK event does not define a channel name. ON NICK is triggered for any nick changing nick in any of your channels. If you want this to ban people from all channels, then you need to include a layer where you ban that person from each channel they share with you.

The /break is just a quick way to immediately exit the while() loop, and is the equivalent of jumping to the line following the while { } code, and you want it to break ONLY if there is a ban.

Since BAN can only be done by a nick who is halfop or higher, you should check if you've got the correct status in that channel, as well as whether that nick is in that channel too. I assume you don't want to get in a war by kicking them, including not wanting to kick yourself, so you want to make sure the newnick is either a regular user or a voice in that channel. Assuming the channelname is #foo:

Code
on *:NiCK:{
if ( (!$nick(#foo,$newnick,rv)) || (!$nick(#foo,$me,oh&~))) return
  var %d $lines(bads.txt)
  while (%d >= 1) {
    if ($read(bads.txt, nt,%d) isin $newnick) {
    ban -ku77200 #foo $newnick kick message goes here
    Break
    }
      dec %d
    }
    else { dec %d }
  }
}

Re: What is missing in that code? [Re: maroon] #266861 23/02/20 12:55 AM
Joined: Nov 2019
Posts: 32
A
An0o Offline OP
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Nov 2019
Posts: 32
Nice it work thanks maroon
But not wark in all channels, work in #foo only
I needed working in all channels

Re: What is missing in that code? [Re: An0o] #267038 26/03/20 12:19 PM
Joined: May 2013
Posts: 121
R
raycomp Offline
Vogon poet
Offline
Vogon poet
R
Joined: May 2013
Posts: 121
change #foo to # only

Re: What is missing in that code? [Re: raycomp] #267042 26/03/20 09:52 PM
Joined: Nov 2019
Posts: 32
A
An0o Offline OP
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Nov 2019
Posts: 32
not wark in all channels