mIRC Home    About    Download    Register    News    Help

Print Thread
#198571 01/05/08 01:56 PM
Joined: Oct 2007
Posts: 102
B
bcancer Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Oct 2007
Posts: 102
I would like to replace this code with regex if possible??

alias BA.op return $qt($mircdirsys\BA.op)

on *:start:{
if (!$isdir($mircdirsys)) mkdir $qt($mircdirsys)
if !$hget(BA) { .hmake BA 100 }
if $isfile($BA.op) { .hload BA $BA.op }
}

on *:exit:{
.hsave -o BA $BA.op
}

on *:disconnect:{
.hsave -o BA $BA.op
}

raw 301:*:{
if (%away != off) && ($nick !isop #chat) {
var %a = 1, %b = $numtok($3-,32)
while %a <= %b {
if $hget(BA,$gettok($3-,%b,32)) {
ban -ku60 #chat $2 2 14Offensive Away Msg
%a = %b
}
inc %a
}
return $regsubex($1-,/\b( $+ %away $+ )\b/gi,$str(*,$len(\t)))
}
haltdef
}

menu status {
-
Add Bad Away
.Add Bad Away : away $?= "Add bad away" | echo $asctime([HH:nn]) * 4Bad Away Added.
.-
.Remove Bad Away : away $?= "Remove bad away" | echo $asctime([HH:nn]) * 4Bad Away Removed.
.-
.View Bad Away List: .hsave -o BA $BA.op | run $BA.op
.-
.Clear Bad Away List: .hfree BA | $iif($exists(BA.op),remove BA.op)
}
alias away {
if !$1 { .notice $nick No word specified }
else { .hadd -m BA $1 $iif($hget(BA,$1),$false,$true) }
}

bcancer #198572 01/05/08 02:13 PM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Nothing in that code can be changed to regex.

Regex is used to search for a specific format of characters (letters, numbers, symbols, spaces, etc) within a string of text.

-genius_at_work

Joined: Oct 2007
Posts: 102
B
bcancer Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Oct 2007
Posts: 102
I see, then I cant use regex to ban bad ircname and bad away msg on join?

Last edited by bcancer; 01/05/08 02:18 PM.
bcancer #198574 01/05/08 02:54 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Well, if your hash table items aren't badwords but regular expressions (for badwords), you could use:
if ($hfind(BA,$3-,1,R).item) { echo -a do stuff, as regular expression $v1 matched text $3- }

As a side note, I woudn't name a custom alias "away", as /away is a mirc command - bad scripting habbit smile

Last edited by Horstl; 01/05/08 03:03 PM.
Horstl #198578 01/05/08 05:57 PM
Joined: Oct 2007
Posts: 102
B
bcancer Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Oct 2007
Posts: 102
I wanted to replace all with regex code like in not using hash at all. Exemple:

On @*:Join:#chat: {
if ( %aaway == off ) || ( %aaway == $null ) { return }
if ($regex($nick,/^[fuck]{2}_[sex]+_[a-z]{2}!)) { ban -ku60 $chan $nick 2 14Bad Away Msg Detected }
}

bcancer #198585 01/05/08 07:17 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Wouldn't that be a step backwards:

using a 'hard coded' regex (or an if-elseif-elseif-chain of multiple regular expressions)

compared to:

a configurable set/list of regular expressions/badwords in a hash table and a check with $hfind(table,text,N,R)?
(I assume you have more than one badword/bad"expression" to check for)

hfind(R) works sufficiently fast, and it matches the text like $regex() would do.

Last edited by Horstl; 01/05/08 07:32 PM.
Horstl #198588 01/05/08 07:32 PM
Joined: Oct 2007
Posts: 102
B
bcancer Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Oct 2007
Posts: 102
Ok thx ill keep my original code then.


Link Copied to Clipboard