mIRC Home    About    Download    Register    News    Help

Print Thread
#12853 24/02/03 06:05 PM
Joined: Dec 2002
Posts: 94
K
krunch Offline OP
Babel fish
OP Offline
Babel fish
K
Joined: Dec 2002
Posts: 94
whats the quicker way?
Code:
if (*swearword* iswm $1-) { kick bah }

or
Code:
var %word = swearword1.swearword2, %i = 1
while (%i <= $numtok($1-,32)) {
if ($gettok(%word,%i,46) == $gettok($1-,%i,32)) { bah}
inc %i
}


i have not tested either of these just wanted to know whats quicker and uses less system res's
cheers


Lets get dirty
#12854 24/02/03 06:20 PM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
iswm is faster than the loop.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#12855 24/02/03 07:04 PM
Joined: Dec 2002
Posts: 271
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
i myself would use $regex in this case, you can specify many different words to watch for:

if ($regex($1-,/\b(word|word1|word2|word3|word4|word5)\b/gi)) { kick $chan.... }

the \\b parameter is used to match within word boundries only, you can remove that to match ANYWHERE withing text, which is the //g, and the //i signifies that match does not have to be case sensitive..... enjoy playing with that wink

#12856 25/02/03 07:39 AM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
How about this idea:

Create a text file called DirtyWords.dat.

*snot*
*booger*
*mud*
*filth*
*flatulence*

var %buckets = $int($calc($lines(DirtyWords.dat) / 10))
hmake DirtyWords %buckets
hload -n DirtyWords DirtyWords.dat

on @*:TEXT:*:#: if ($hfind(DirtyWords, $string($1-), 1, W) kickban $chan $nick So's yer mom!


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#12857 25/02/03 12:40 PM
Joined: Dec 2002
Posts: 2,985
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 2,985
var %buckets = $int($calc($lines(DirtyWords.dat) / 10))

Just out of curiosity, what does the 10 represent?

#12858 25/02/03 01:51 PM
Joined: Dec 2002
Posts: 191
N
Vogon poet
Offline
Vogon poet
N
Joined: Dec 2002
Posts: 191
/hmake -s <name> <N>
Creates a new hash table with N slots.

A hash table can store an unlimited number of items regardless of the N you choose, however the bigger N is, the faster it will work, depending on the number of items stored.

eg. if you expect that you'll be storing 1000 items in the table, a table of N set to 100 is quite sufficient.

The -s switch makes the command display the result.


#12859 25/02/03 02:13 PM
Joined: Dec 2002
Posts: 2,985
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 2,985
Ahhh thankyou. I am used to starting hash tables with .hadd -sm blah blah blah and it seems that I overlooked this way of doing it. Thanks again. grin

#12860 25/02/03 03:24 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
var %buckets = $int($calc($lines(DirtyWords.dat) / 10))
- Why not just include the calculation directly into the /hmake? Also, you'll want a "+ 1" in that $calc otherwise anything under 10 words will return 0.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#12861 25/02/03 03:59 PM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
on @*:TEXT:*:#: if ($hfind(DirtyWords, $strip($1-), 1, W)) kickban $chan $nick So's yer mom!
I take it "$string($1-)" was a typo and meant to be $strip()
Code:
Items		Data
 
*snot*		*booger*
*mud*		*filth*
*flatulence*

Every second word, (the data (plus the odd word; *flatulence*) won't be found by $hfind(table,string,1,W)

#12862 25/02/03 05:16 PM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
[*] Just out of curiosity, what does the 10 represent?

The general rule of thumb I go by when "optimizing" (if you will) the number of buckets is the maximum number divided by 10...-ish. This is just a quick way to get near that value quickly because the number of lines in the file will be my "max" value.

[*] Why not just include the calculation directly into the /hmake? Also, you'll want a "+ 1" in that $calc otherwise anything under 10 words will return 0.

This was a quickie thought I fired off the top of my head. There's nothing wrong with doing the calculation in the hmake, but as you suggested, you might want to make a minumum number of buckets (such as 10). Also, I assumed (bad, I know) that the file would contain LOTS of bad words/phrases, certainly more than 10. There are more than 10 just in English; multiply that times all the languages that are regularly spoken in your channels.

[*] I take it "$string($1-)" was a typo and meant to be $strip()

* Hammer blushes furiously at his typo. Yup, definitely a typo and meant to be $strip($1-)

From /help /hload

/hload -sbni <name> <filename> [section]
...
You can use -n to load or save files as data only, with no items. When loading with -n each line of data is assigned an N item value, starting at N = 1.

I have not tested this idea, I haven't even tried it yet. However, it SHOULD work like this.
Code:

Items   Data
  1     *snot*
  2     *booger*
  3     *mud*
  4     *filth*
  5     *flatulence*

where $hfind(htable, $1-, 1, W).data would search match the wildcarded data against $1-. If it finds ANY match, then a bad word has been detected.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#12863 25/02/03 05:31 PM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
Hm yep ok I missed the -n, fair enough :tongue:
"on @*:TEXT:*:#: if ($hfind(DirtyWords, $string($1-), 1, W) kickban $chan $nick So's yer mom!"
That doesn't specify the .data prop, and does have a missing parenthesis. smile

#12864 25/02/03 06:36 PM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Geez. Three typos on one little line. I should retire. :tongue:
Code:

on *:START:{
  hmake DirtyWords $iif($lines(DirtyWords.dat) &gt; 11, $int($calc($lines(DirtyWords.dat) / 10)), 10)
  hload -n DirtyWords DirtyWords.dat
}
 
on *:DISCONNECT: hsave -n DirtyWords DirtyWords.dat
 
on @*:TEXT:*:#:{
  if $hfind(DirtyWords, $strip($1-), 1, W).data {
    ban $chan $nick 2
    kick $chan $nick Oh, yeah? So's yer mom!
  }
}

There might even be a way to put that $hfind() into the :matchtext: field; it's returning a wildcarded string that it would match. That would cut out the additional if (). Maybe something like

on @*:TEXT:$($hfind(DirtyWords, $strip($1-), 1, W).data):#: kickban $chan $nick I know you are, but what am I?

Wouldn't that be shweet! cool I don't have a clue if it would work though. (Typos or no typos!)


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#12865 26/02/03 06:06 AM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
laugh-> shweet! cool <-laugh
It's good to be reminded about the -n switch, I've never used it, and forgot about it after reading it 'till this post laugh


Link Copied to Clipboard