mIRC Homepage
Posted By: Babystone ban chatter swearing in op pm - 24/12/09 03:48 PM
can anyone teach me how to write a script to ban a chatter swearing in op pm?
Posted By: gooshie Re: ban chatter swearing in op pm - 24/12/09 04:35 PM
Code:
on @$*:TEXT:/\bword1\b|\bword2\b|\bword3\b/iS:#:ban -ku600 # $nick 2 Ten minute kick/ban for language!
on @$*:ACTION:/\bword1\b|\bword2\b|\bword3\b/iS:#:ban -ku600 # $nick 2 Ten minute kick/ban for language!
Posted By: Tomao Re: ban chatter swearing in op pm - 24/12/09 10:08 PM
gooshie, the op meant pm, not the active channel. So the # should have been ? don't you think?
Code:
on @$*:TEXT:/\bword1\b|\bword2\b|\bword3\b/iS:?:ban -ku600 #YourChannel $nick 2 Ten minute kick/ban for language!
on @$*:ACTION:/\bword1\b|\bword2\b|\bword3\b/iS:?:ban -ku600 #YourChannel $nick 2 Ten minute kick/ban for language!
Change #YourChannel to your real channel. This, I believe, can only work on a single channel basis. If you want this to work on all, a while loop needs to be used with $comchan()...as there's no $chan in pm.
Posted By: Babystone Re: ban chatter swearing in op pm - 25/12/09 04:30 AM
is there anything i should change in this addons?

on *:text:*:?:{
if ($me isop #) {
var %f = $strip($1-)
if (*bitch* iswm %f) || (* bastard * iswm %f) || (cunt* iswm %f) || (*cunt* iswm %f) || (* cock * iswm %f) || (*cock-* iswm %f) || (cock iswm %f) || (*fuk* iswm %f) || (*fuck* iswm %f) || (*fucker* iswm %f) || (*fucking* iswm %f) || (* horny * iswm %f) || (* nigger * iswm %f) || (* nigger iswm %f) || (nigger iswm %f) || (*penis* iswm %f) || (* pussy iswm %f) || (*pussy- * iswm %f) || (* pussy * iswm %f) || (pussy iswm %f) || (*slut* iswm %f) || (*whore* iswm %f) || (*di ck* iswm %f) || (*fck* iswm %f) || (*fak you * iswm %f) || (* dick * iswm %f) || (* cibai * iswm %f) || (<censored> iswm %f) || (<censored> * iswm %f) || (* <censored> iswm %f) || (* <censored> * iswm %f) || (* horny * iswm %f) || (* horny iswm %f) || (horny * iswm %f) || (* bitch * iswm %f) || (* bitch iswm %f) || (bitch * iswm %f) {
kick $chan $nick Swearing Detected, DONT SWEAR In My Private!
Ban -u180 $chan $nick 2
}
}
}
Posted By: Wims Re: ban chatter swearing in op pm - 25/12/09 04:48 AM
The on text event trigger in private so $chan is $null and kb the nick in private makes no sense, what do you want to do ?
.
Posted By: DJ_Sol Re: ban chatter swearing in op pm - 25/12/09 04:58 AM
This code will not work because there is no $chan in a query event. Either have this feature on or off. Same goes for your ban. You can use $comchan($nick,1) for the 1st channel in the your channel list that you both are in. Or you can write the channel name in.
Posted By: Babystone Re: ban chatter swearing in op pm - 25/12/09 05:09 AM
what i wan to do is kb chatter if they swear in my private
Posted By: gooshie Re: ban chatter swearing in op pm - 25/12/09 05:42 AM
Code:
on ^*:OPEN:?:pmkban $1-
on *:TEXT:*:?:pmkban $1-
on *:ACTION:*:?:pmkban $1-
alias -l pmkban {
  if $regex($1-,/word1|word2|word3/iS) {
    var %c,%i 1
    while $comchan($nick,%i) {
      %c = $v1
      if $nick(%c,$me,~&@%) {
        ban -ku600 %c $nick 2 Ten minute ban for language in private message!
      }
      inc %i
    }
    .ignore -u600 $nick 2
  }
}
Posted By: Tomao Re: ban chatter swearing in op pm - 25/12/09 08:23 AM
The regex match range can get real long if there's a lot of bad words to add. It may also get cut off. Using $count() for bad word matching is pretty much the same as the regex you use in your script. You can use the line break $& identifier to break up a single line to multiple ones. But you can't use the $& for regex...because it won't work.
Posted By: Babystone Re: ban chatter swearing in op pm - 25/12/09 10:02 AM
lol so wats the easier way?
Posted By: Tomao Re: ban chatter swearing in op pm - 25/12/09 11:57 AM
Use the $count() with the line break identifier like this:
Code:
on ^*:OPEN:?:pmkban $1-
on *:TEXT:*:?:pmkban $1-
on *:ACTION:*:?:pmkban $1-
on *:NOTICE:*:?:pmkban $1-
alias -l pmkban {
  if $count($strip($1-),bitch,bastard,cunt,cock,fuk,[censored],horny,nigger,whore,penis,$&
    shithead,badword,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,$&
    36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,$&
    ) {
    var %c,%i 1
    while $comchan($nick,%i) {
      %c = $v1
      if $nick(%c,$me,~&@%) {
        ban -ku600 %c $nick 2 Ten minute ban for foul language in private message!
      }
      inc %i
    }
  }
}
Replace the numbers with the bad words. You do the same with $& identifier when the line add gets long enough.
Posted By: gooshie Re: ban chatter swearing in op pm - 27/12/09 01:51 PM
Code:
on ^*:OPEN:?:pmkban $1-
on *:TEXT:*:?:pmkban $1-
on *:ACTION:*:?:pmtkban $1-
on *:NOTICE:*:?:pmkban $1-
alias -l pmkban {
  var %r /bitch|bastard|cunt|cock|fuc?k|<censored>| $&
    h(0|o)rn(ie|y)|nigger|\btwat\b|whore|penis|shit| $&
    \bcibai\b|di ?ck|pussy-?|fak you|fck|slut/iS
  if $regex($1-,%r) {
    var %c,%i 1
    while $comchan($nick,%i) {
      %c = $v1
      if $nick(%c,$me,~&@%) {
       ban -ku600 %c $nick 2 Ten minute ban for foul language in private message!
      }
      inc %i
    }
    .ignore -u600 $nick 2
  }
}
Posted By: Tomao Re: ban chatter swearing in op pm - 27/12/09 08:29 PM
Fair enough. I overlooked the fact that a local var would've done the trick. tired
Posted By: Tomao Re: ban chatter swearing in op pm - 27/12/09 09:00 PM
gooshie, one matter is found. I'm not sure if you've noticed an issue that the bad word after $& won't work, but the rest will.
Posted By: gooshie Re: ban chatter swearing in op pm - 27/12/09 09:26 PM
Code:
on ^*:OPEN:?:pmkban $1-
on *:TEXT:*:?:pmkban $1-
on *:ACTION:*:?:pmtkban $1-
on *:NOTICE:*:?:pmkban $1-
alias -l pmkban {
  var %c,%i 1,%r /bitch|bastard|cunt|cock|fuc?k|<censored>| $&
  $+ h(0|o)rn(ie|y)|nigger|\btwat\b|whore|penis|shit| $&
    $+ \bcibai\b|di ?ck|pussy-?|fak you|fck|slut/iS
  if $regex($1-,%r) {
    while $comchan($nick,%i) {
      %c = $v1
      if $nick(%c,$me,~&@%) {
        ban -ku600 %c $nick 2 Ten minute ban for foul language in private message!
      }
      inc %i
    }
    .ignore -u600 $nick 2
  }
}
Posted By: Horstl Re: ban chatter swearing in op pm - 28/12/09 01:41 AM
In case you don't want to deal with regular expressions, but want to manage a variable list - allowing for a mix of both badWORDS (like pussy in your example) and badSTRINGS (like *slut* in your example), you could alternatively use $wildtok. It's not as fast as single-lined regular expression, but a flawed regex may be worse... laugh

Example:
Code:
; your list of badwords and badstrings
var %bad = badword1 *badstring* anotherbadword anotherb*string

var %n = 1
; loop the badwords and -strings
while ($gettok(%bad,%n,32)) {
  ; check for occurences of this badword/-string in <TEXT>
  if ($wildtok(<TEXT>,$v1,1,32)) {
    ; your action here
    echo -ag word $v1 in <TEXT> matches badword definition: $gettok(%bad,%n,32)
    break
  }
  inc %n
}

To combine the variability/legibility of a list and the speed/flexibility of regular expressions, a hash table in combination with $hfind(,R) could be of use (with no need for a while-loop).
Posted By: gooshie Re: ban chatter swearing in op pm - 28/12/09 04:53 AM
Horstl
I'll look foward to seeing your
script that does all that..
Posted By: Tomao Re: ban chatter swearing in op pm - 28/12/09 08:53 AM
It'd be nice if you could show us an example of how to use $hfind() with the r switch to match for bad words.
Posted By: Wims Re: ban chatter swearing in op pm - 28/12/09 09:16 AM
He said R, not r, here is quick example of what he meant
Quote:
alias testR {
tokenize 32 this is the test sentence : plop.
hadd -m badword .*test.*
hadd badword plop
hadd badword .*is\sthe.*
echo -a > $hfind(badword,$1-,0,R)
hfree badword
}
In regex, \s is a space and .* is used to represent the * wildcard (in order to have an item name where spaces can exists).
Then, mirc compare (using regex) each item (that represent regex pattern) with $1- (like if ($regex($1-,itemN)) { })
Posted By: gooshie Re: ban chatter swearing in op pm - 28/12/09 01:17 PM
I'm confused.. are you using regex in the hash table
to solve some percieved problem with $regex???

Also, could you make a full script to do what the
other script already does so we can compare size
and sorta guess which is faster or easier to edit
or whatever it is you are trying to improve upon...
Posted By: Horstl Re: ban chatter swearing in op pm - 28/12/09 02:20 PM
The main idea is that a set of seperate expressions is far more easy to read and edit than a single, condensed regular expression - in case you want to find/remove/add/... a specific bad-definition.
It would further allow for different switches per expression, or for example to script some kind of dialog-GUI arround it (for viewing/editing of the current bad-definitions).

For the actual checking routine, you'd need one single "if $hfind"-check like in Wims example, which is on par with the single "if $regex"-check in your examples. (The items may be added to the table e.g. on start.)
Altogh mIRC will loop the hash'd items internally of course, this will process faster than e.g. a $*tok-based check on a token list which requires a custom loop.

If you got the idea by now, you can easily modify your script for benching purposes... it won't process faster than your last script, but rather add some flexibility to it. And as stated, this is only a suggestion - to be of use if speed isn't everything to you. smile
Posted By: gooshie Re: ban chatter swearing in op pm - 28/12/09 02:36 PM
Yeah I see the main idea but what I'm not seeing
is a functional script yet.. I'm thinking in the
time it takes you to script up the fancy dialog box
/hsave /hload and all the supporting structure we
could just as easily go ahead and add the fifty or
so words we want to check for and be done.. after
you do all that with the dialog and all in the end
after you add all the words it will just be sitting
there hogging up space with nothing to do.. But,
please proceed..
Posted By: DJ_Sol Re: ban chatter swearing in op pm - 28/12/09 07:59 PM
Hey I think you lost sight of the intention of this post. Person has a script and needs help with it.
Posted By: gooshie Re: ban chatter swearing in op pm - 28/12/09 08:11 PM
I haven't lost sight.. I solved the problem
seven or eight post back.. this is all about
some theoritical improvement on some percieved
problem that has yet to make sense to me...
Posted By: Tomao Re: ban chatter swearing in op pm - 28/12/09 09:38 PM
gooshie, I think I sort of got what Horstl meant by storing the $regex to the hash table and use the R switch to reference to the $regml(1):

Basically add the whole regex string to a hash table:
Code:
/hadd -m pmban pmban /(bitch|bastard|cunt|cock|fuc?k|<censored>|h(0|o)rn(ie|y)|nigger|\btwat\b|whore|penis|shit|\bcibai\b|di ?ck|pussy-?|fak you|fck|slut)/iS
Then use:
Code:
on *:EXIT: {
  hsave pmban pmban.hsh
}
on *:START: {
  if (!$hget(pmban)) hmake pmban 100
  if ($isfile(pmban.hsh)) hload pmban pmban.hsh
}
on @*:TEXT:*:#: {
  if ($hfind(pmban,$1-,0,R).data) {
    ban -ku600 # $nick 2 Ten minute ban for saying the foul language consists of $regml(1)
  }
}
The use of a hash table should be able to store an unlimited amount of regex matches into its data, without the worry of long add of words, compared to that of the script remote.
Posted By: DJ_Sol Re: ban chatter swearing in op pm - 29/12/09 03:26 AM
From my experiences, variables are actually faster than a hash table when storing a small value such as an integer.

However when storing and accessing large amounts of data, hash tables are better.
Posted By: Tomao Re: ban chatter swearing in op pm - 29/12/09 04:19 AM
While hash tables have no limit as to how many info you can store, variables, on the contrary, have limit.
Nevertheless I agree with you about using vars when it comes to storing small integers.
Posted By: Horstl Re: ban chatter swearing in op pm - 29/12/09 02:39 PM
The length limit per item is alike the length limit of a variable (name of table + name of item + data <= ~4140; name of variable + data <= ~4140).

My suggestion was about versatility only - not using a "block"-expression. And I rather wouldn't use backreferences (as they will slow down processing, whatever method you use).
Maybe you don't have 20 but 200 bad"words"... The length limit put aside, if you have a block-expression and there's e.g. some misfire it may be hard to find the erroneous chunk - especially without backreferences - in a multilined, $&-combined huddle-muddle.
If on the other hand side your items are discrete expressions (or manageable "chunks"), you can loop $hfind(table,<text>,N,R) for debugging. Depending on your regex skills, this can be quite handy - even if you don't intend to add/modify the expression(s) frequently, and don't intend to create a dialogue or the like.

It's no suggestion for those who cannot aford to spend a few kB of memory (*sniff*) or sacrifice one or two $ticks... (*whimper*) smirk
Posted By: s00p Re: ban chatter swearing in op pm - 29/12/09 04:44 PM
Please explain what makes you think hash tables have no limit, Tomao. Hashtables are, as everything, inherently limited by implementation. If your OS has no swap file, then it's limited by your available RAM. If your machine has no swap file and no available RAM, then I assume it will fail to add new items. The items within hashtables appear to be limited to 4096 bytes, much like variables.

I would suggest gooshie's first solution, alongside Tomao's suggestion, with the addition of a second file which stores the words, one to each line. Words would be added using /add_badword function, and removed by hand (I can't be bothered!). If speed becomes an issue (thooouuusands of items here), one could then quite easily then take the TRE regular expression module (which can compile regular expressions at runtime), write a cheap & dirty wrapper and compile. The resulting code would be fine for millions of items, assuming enough system resources are present smile. I was tempted to write code for this, but this message is getting lengthy and it would be a good learning experience for others... and hey, I'm here if anyone who wants to give it a shot runs into any problems smile

Code:
alias conf_badword {
  set %badwords_plaintext badwords.txt
  set %badwords_table badwords.tab
}

alias add_badword {
  var %item = $hget(badwords,0).item, %data = $mid($hget(badwords,%item).data,2,-2)

  conf_badword  

  ; leave more than enough space for the max 4096 per anything...
  if ($len(%data) >= 2048) {
    hadd -m badwords $calc(%item + 1) $+(/,$1,/iS)
  }
  else {
    hadd -m badwords %item $+(/,%data,|,$1,/iS)
  }

  write %badwords_plaintext $1
  hsave badwords %badwords_table
}

on 1:OPEN: conf_badword | hload %badwords_table
on ^*:OPEN:?:pmkban $1-
on *:TEXT:*:?:pmkban $1-
on *:ACTION:*:?:pmkban $1-
alias -l pmkban {
  if ($hfind(badwords,$1-,0,R).data != $null) {
    var %c,%i 1
    while $comchan($nick,%i) {
      %c = $v1
      if $nick(%c,$me,~&@%) {
        ban -ku600 %c $nick 2 Ten minute ban for language in private message!
      }
      inc %i
    }
    .ignore -u600 $nick 2
  }
}
Posted By: Tomao Re: ban chatter swearing in op pm - 29/12/09 10:22 PM
I'm afraid I've been ill-informed or misunderstood of the hash tables being able to store an unlimited number of items regardless of the N you choose. I didn't think of the OS swap file or RAM involved when I posted...
Posted By: s00p Re: ban chatter swearing in op pm - 30/12/09 11:33 AM
that's ok mate... The help file makes the same mistake so I understand where you might get this idea from wink I'd put it in the suggestions but I don't think it'd make it anywhere because... well the help file is a low priority thing I guess
Posted By: Riamus2 Re: ban chatter swearing in op pm - 30/12/09 03:26 PM
(Not specifically to you, Horstl)

Although you have a limit on size in a hash table, you can store a binary value to the hash table if you need more data on each item. This does, however, limit searching if you don't know which item to look in ($hfind doesn't help if you're using binary values). I didn't go through the entire thread, but just from the last posts, I don't think this was mentioned. Whether or not that's any use here, or if it's faster to split the items, I'm not sure. Just thought I'd throw it out for anyone who didn't know they can do that.
© mIRC Discussion Forums