mIRC Home    About    Download    Register    News    Help

Print Thread
#106960 05/01/05 06:02 PM
Joined: Jan 2005
Posts: 9
R
Ravich Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
R
Joined: Jan 2005
Posts: 9
I have a problem with my addon...it just doesn't want to punish "#". I'll explain it clearly smile When I add a spamword like these : "#usa , #germany , etc " everything is all right when I got the message "Please join #usa , #germany ..." But when I add only "#" as a spamword, because I want all #channels to be ignored by my addon, it just does't work frown
So I was wondering...could you help me smile

code:

==================================================

};Anti Spam

#spamdetect on
on *:open:?:*:{
if (%total-spam == $null) { set %total-spam 0 }
var %i = 1
while (%i <= $lines(spamwords.txt)) {
if ($read(spamwords.txt,%i) isin $strip($1-)) {
inc %total-spam 1
.notice $nick 12Za takiva Spammeri kato tebe si imam Spam Protections %logo !!!
echo < $+ $nick $+ > $1-
close -m $nick
halt
}
inc %i 1
}
}
#spamdetect end
Menu channel {
Anti-Spam
.on/off (now| %spamonoff $+ ) :{
if (%spamonoff == on) { spamoff }
else { spamon }
}

.Add Spam Word:dialog -m spamdetect spamdetect

}
dialog spamdetect {
title "Anti-Spam"
size -1 -1 100 149
option dbu
list 1, 4 55 94 77, sort size
edit "", 2, 4 44 71 10
button "Add", 3, 76 44 21 10, default
radio "On", 4, 21 20 15 10, push
radio "Off", 5, 54 20 15 10, push
box "Spam Words", 6, 1 35 100 113
box "", 7, 1 -1 100 36
button "Remove", 8, 5 133 92 12
button "!", 10, 3 4 9 9, hide cancel

}
alias spamon { set %spamonoff on | .enable #spamdetect | }
alias spamoff { set %spamonoff off | .disable #spamdetect | }
on *:dialog:spamdetect:sclick:4:spamon
on *:dialog:spamdetect:sclick:5:spamoff
on *:dialog:spamdetect:sclick:8:write -ds" $+ $did(1).seltext $+ " spamwords.txt | did -r $dname 1 | loadbuf 0 -o spamdetect 1 spamwords.txt
on *:dialog:spamdetect:init:0:loadbuf 0 -o spamdetect 1 spamwords.txt | if (%spamonoff == on) { did -c $dname 4 } | else { did -c $dname 5 }
on *:dialog:spamdetect:sclick:3:did -r $dname 1 | write spamwords.txt $did(2) | did -r $dname 2 | loadbuf 0 -o spamdetect 1 spamwords.txt
on *:dialog:spamdetect:sclick:9:splay spam.mp3 | showspamabout
on *:dialog:spamdetect:sclick:12:hidespamabout
alias showspamabout {
did -v spamdetect 12
did -h spamdetect 1
did -h spamdetect 2
did -h spamdetect 3
did -h spamdetect 4
did -h spamdetect 5
did -h spamdetect 6
did -h spamdetect 7
did -h spamdetect 8
did -h spamdetect 9
}
alias hidespamabout {
did -h spamdetect 12
did -v spamdetect 1
did -v spamdetect 2
did -v spamdetect 3
did -v spamdetect 4
did -v spamdetect 5
did -v spamdetect 6
did -v spamdetect 7
did -v spamdetect 8
did -v spamdetect 9

}

Last edited by Ravich; 05/01/05 06:04 PM.
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
There are some things that might be of interest to you, in order to make your script more efficient.
  • The reason you can't get a single # to work in your text file, is because # is a special character in mIRC, it evaluates to the channel where the code was triggered on. Or if its not triggered from a channel, like in your case, it will evaluate to nothing ($null)

    You can test this by doing the following:

    Put # on the first line of a file named test.txt, then in a channel, type: //echo -a $read(test.txt,1) it will echo the name of the channel you are in.

    If you do it from a pm window, it will give you the * /echo: insufficient parameters error message, or echo nothing at all, depending on which echo switch you use.

    You need to use the "n" switch in $read, so that read-in text isn't evaluated.

    //echo -a $read(test.txt,n,1) will echo "#"

  • Word of advice: it is very innefficient to loop with $lines(spamwords.txt) in your while condition, as with every iteration, it has to look up this value. It is far better to put the amount of lines in a variable, and dec that variable instead. Or to inc an iteration variable, and have the $read in the while condition.

    So from:

    var %i = 1
    while (%i <= $lines(spamwords.txt)) {
    if ($read(spamwords.txt,%i) isin $strip($1-)) {
    ...
    }
    inc %i

    we go to:

    var %lines = $lines(spamwords.txt), %string = $strip($1-)
    while (%lines) {
    if ($read(spamwords.txt,n,%lines) isin %string) {
    ...
    }
    dec %lines


  • You are looping through all lines with $read for each incoming message, that's really not good, as reading from a text file like that gets slow, and there are much better ways to achieve the same thing.

    If you get a lot of pm's, then it will be a lot better to use hash tables for storing spamwords, hash tables are loaded in memory, and are accessed a lot faster than opening/looping/closing a text file. If you want to see an example of a hash tabled based script that does the same as you wish, just say the word.
  • on *:open:?:*:{
    ...
    close -m $nick
    halt
    }

    If you put the ^ as event prefix in this event, it will trigger before visually opening the window. If you put halt at the end of your event (like you did), then the close -m $nick is obsolete, as it will halt the visual opening of the window.

    on ^*:open:?:*:{
    ...
    halt
    }

  • inc %total-spam 1

    The default value that is used with inc, if no number is specified, is 1. So inc %total-spam 1 is the same as inc %total-spam

  • There could be more remarks, but these are the ones that were very apparent to me.

    Good luck!


Gone.
Joined: Mar 2003
Posts: 612
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Mar 2003
Posts: 612
in addition to hammers post, from the helpfile
Quote:

If you want to modify several controls at the same time, you can specify multiple id numbers separated by commas, eg. /did -b name 2,12,14,16 etc.

So all your did -v lines could be incorporated into one line.


billythekid
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
I'm not Hammer o.O

Good remark about the did thing, it'll shorten his code a lot smile

Greets


Gone.
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
I think he probably assumed it was hammer because of the large post you just made. wink While the cats away, the mice will.....continue in the cats tradition, hehe. smile

Joined: Mar 2003
Posts: 612
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Mar 2003
Posts: 612
oops, yeah just assumed it was hammer with the way the post was laid out! lol many apologies FiberObtics nice post still


billythekid
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Lol no problem,

I don't mind, he's a great scripter so I don't think anybody would mind being called Hammer laugh

Cya around!


Gone.
Joined: Jan 2005
Posts: 9
R
Ravich Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
R
Joined: Jan 2005
Posts: 9
Hey tnx all grin grinEverything is perfect now smile tnx again

Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
I'm the real Hammer. cool


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
* Andy laughs.


Link Copied to Clipboard