|
Joined: Dec 2002
Posts: 94
Babel fish
|
OP
Babel fish
Joined: Dec 2002
Posts: 94 |
whats the quicker way?
if (*swearword* iswm $1-) { kick bah }
or
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
|
|
|
|
Joined: Dec 2002
Posts: 1,321
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,321 |
iswm is faster than the loop.
DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
|
|
|
|
Joined: Dec 2002
Posts: 271
Fjord artisan
|
Fjord artisan
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
|
|
|
|
Joined: Dec 2002
Posts: 1,321
Hoopy frood
|
Hoopy frood
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
|
|
|
|
Joined: Dec 2002
Posts: 2,985
Hoopy frood
|
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?
|
|
|
|
Joined: Dec 2002
Posts: 191
Vogon poet
|
Vogon poet
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.
|
|
|
|
Joined: Dec 2002
Posts: 2,985
Hoopy frood
|
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.
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
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()
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)
|
|
|
|
Joined: Dec 2002
Posts: 1,321
Hoopy frood
|
Hoopy frood
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.
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
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
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.
|
|
|
|
Joined: Dec 2002
Posts: 1,321
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,321 |
Geez. Three typos on one little line. I should retire. :tongue:
on *:START:{
hmake DirtyWords $iif($lines(DirtyWords.dat) > 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! 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
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 699 |
-> shweet! <- 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
|
|
|
|
|