mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jun 2017
Posts: 3
B
Self-satisified door
OP Offline
Self-satisified door
B
Joined: Jun 2017
Posts: 3
I have written this script but i cannot seem to get the commands to add words and delete words correct, this is what i have please can you advise me where i have gone wrong? I really have no idea and am fairly new to this

on *:TEXT:*:#yellowcrayon: {
set %text $1-
set %s 1
badword
}
alias badword {
set %lines $lines(badwords.txt)
while ( %s <= %lines ) {
if ($read(badwords.txt, %s ) isin %text ) {
/kick # $nick Watch your language!
unset %s
halt
}
else inc %s
}
}

on $*:TEXT:/^[!@.]addbadwords?/Si:#: {
var %x = 1
while ($gettok($2-,%x,32)) {
if (!$read(badwords.txt,w,$gettok($2-,%x,32))) {
write badwords.txt $gettok($2-,%x,32)
var %added = %added $gettok($2-,%x,32)
}
inc %x
}
.msg $chan 0,4 $iif(!%added,No new words added.,Words added: $replace(%added,$chr(32),$chr(44)))
}
on $*:TEXT:/^[!@.](rem(ove)?|del(ete)?)badwords?/Si:#: {
if ($nick isop $chan) {
var %x = 1
while ($gettok($2-,%x,32)) {
if ($read(badwords.txt,w,$gettok($2-,%x,32))) {
var %deleted = %deleted $gettok($2-,%x,32)
write $+(-dl,$readn) badwords.txt
}
inc %x
}
.msg $chan 0,4 $iif(!%deleted,None of those words were in the file.,Words deleted: $replace(%deleted,$chr(32),$chr(44)))
}
else { .notice $nick Access denied. }
}

I really have no idea where i have gone wrong please can you help me or suggest an easier way to allow my mods to add and del words from the badwords.txt

Thanks

Last edited by BabyBear; 22/06/17 05:51 AM.
Joined: Jun 2016
Posts: 1
D
Mostly harmless
Offline
Mostly harmless
D
Joined: Jun 2016
Posts: 1
I believe the problem is that if you're testing this script in #yellowcrayon, that the first ON TEXT event is trapping all incoming text from the channel, so a !addbadword trigger in #yellowcrayon will never reach the second ON TEXT event. If you used the !addbadwords trigger in another channel besides #yellowcrayon, it would work because it's not being trapped by the first ON TEXT event reached. So, you can't have multiple matching events firing for an incoming line; it'll do the first one it finds and disregard any further events.

A solution would be to use one generic ON TEXT event and then pare it down by channel or trigger. (I'd be interested in hearing reasons from more experienced mIRC scripters why this relatively global method of checking is bad practice, this is the way I do most of my scripts.) The following example would check all text for bad words in #yellowcrayon but the !addbadwords and !delbadwords triggers would be available in ANY channel since they're outside of the #yellowcrayon checking block.

Code:
on *:TEXT:*:#: {

  if ($chan == #yellowcrayon) {
    set %text $1-
    set %s 1
    badword
  }  

  if ($regex(,%text,/^[!@.]addbadwords?/Si) > 0) {
    var %x = 1
    while ($gettok($2-,%x,32)) {
      if (!$read(badwords.txt,w,$gettok($2-,%x,32))) {
        write badwords.txt $gettok($2-,%x,32)
        var %added = %added $gettok($2-,%x,32)
      }
      inc %x
    }
    .msg $chan 0,4 $iif(!%added,No new words added.,Words added: $replace(%added,$chr(32),$chr(44)))
  } 

  if ($regex(,%text,/^[!@.](rem(ove)?|del(ete)?)badwords?/Si) > 0) {
    if ($nick isop $chan) {
      var %x = 1
      while ($gettok($2-,%x,32)) {
        if ($read(badwords.txt,w,$gettok($2-,%x,32))) {
          var %deleted = %deleted $gettok($2-,%x,32)
          write $+(-dl,$readn) badwords.txt
        }
        inc %x
      }
      .msg $chan 0,4 $iif(!%deleted,None of those words were in the file.,Words deleted: $replace(%deleted,$chr(32),$chr(44)))
    }
    else { .notice $nick Access denied. }
  }

}

alias badword {
  set %lines $lines(badwords.txt)
  while ( %s <= %lines ) {
    if ($read(badwords.txt, %s ) isin %text ) {
      echo -st kick # $nick Watch your language!
      unset %s
      halt
    }
    else inc %s
  }
}

Last edited by dole; 23/06/17 04:34 PM.
Joined: Jun 2017
Posts: 3
B
Self-satisified door
OP Offline
Self-satisified door
B
Joined: Jun 2017
Posts: 3
Hey thankyou so much for your help, sorry it took so long for me to reply. However the !addbadwords command works but the delete one doesnt? any thoughts on this please?
Also one more thing do u know where i have gone wrong in my script it is kicking people out for normal words like password bacause it says ass in it?

BabyBear


Link Copied to Clipboard