This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

detect channel advertising

Old posts that have not been replied to for several years.
Locked
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

detect channel advertising

Post by ProXy »

Hello, I just use Nosense to protect my chan against channel advertising. Theres only a little error in nosense: It doesn`t match Channel like ## oder ###. these are valid qnet chans, so i wanted to rewrite the regexp.

I want to check if one or more char is after # and save the channel in a var called $match.

I tried to match using this source:

Code: Select all

[regexp -nocase {#.+} $text match]
But this does not work, because my regexp doesn`t stop before the next space. If the string is "i am on #htp and you are not", $match only should have the value "#htp". Could anyone please tell me how to use regexp to match the right part of the string?

ProXy
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

foreach word [split $text] {
if {![string match "*#*" $word] || [string match "#" $word] || [string compare -nocase $word $chan] == 0} { continue }
rest of the code
}

This way will see if someones uses a #something and will compare the #somehting with the channel that #something was said in and if it's the same will continue, if not will do your proc. Hope this helps you..
Once the game is over, the king and the pawn go back in the same box.
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

Code: Select all

regexp {((#)+([a-zA-Z0-9])+)} $text match
$match will then contain "#blafblsfbljd" or "##afjhfef34" or whatever =)
Elen sila lúmenn' omentielvo
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

But i guess this will not match ##, right?
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Few test examples, by using "tclsh"
proc tm {in} {
regexp {((#)+([a-zA-Z0-9])+)} $in match
return $match
}

tm "hello to #all out there"
#all

tm "Funny old ##world"
##world

tm "##"
can't read "match": no such variable

tm "hello ## all"
can't read "match": no such variable
As such, it causes error when ## is on it's own
proc tm {in} {
regexp {((#)+([\#a-zA-Z0-9]{0,})+)} $in match
return $match
}

tm "##"
##

tm "hello ## all"
##
The regexpr works by looking for a #, followed by and uper/lower case letter or numbers, until the next non-matched char.

Because the # wasn't matched within it, it coudln't pick it up.

At the same time, it didn't allow you to check for single #'s. The {0,} means 0 or more matches.

As a # doesn't mean a spam (usualy), you can change the {0,} to {1,} requiring at leave one character after the #.

Aditionaly, you will find that you need more characters in the name matching, as channel names can contain other charcters.

Objects to add may be -, _, !, colour character, bold, underline, reverse, normal, ctcp, and many many more (best to see the IRC RFC).
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

Well I think it`s better to catch EVERYTHINK against the # and just split the result string to get the channel. This will also work for every speacial char...
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

just a little sidenot... :) instead of using {0,} you can just use *, or + instead of {1,} ... this will do exactly the same thing
Elen sila lúmenn' omentielvo
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

How about matching anything but space?

eg: regexp {#[^ ]*} $the_string chan
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

user wrote:How about matching anything but space?

eg: regexp {#[^ ]*} $the_string chan
even better =)
Elen sila lúmenn' omentielvo
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

Well if i use this, also bla#bla ist detected as channel advertising... :(
T
TsT
Voice
Posts: 16
Joined: Tue Mar 04, 2003 11:03 am
Location: Strasbourg, France
Contact:

Post by TsT »

Code: Select all

# returns channel name if found,
# else return nothing
proc getchannelname_ifexists {text} {
    if {[regexp {(#[^, ]+)} $arg _ chan]} {
        return $chan
    }
}
:D
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

regexp {(?:^|[ ])(#[^, ]*)} $text chan chan

Notice the *, not +, because "#" is a valid channel name.

The first part of the rule is to make shure there's a space before the # (or that # is the first char in the text)
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

Sorry, use rbut your source even detects abc#abc as a channel ad...that`s not want i`m looking for.

Allowed:
bla#bla
bla##
bla#

NOT allowed:
#
##
#bla
#bla#
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

This is a nearly Solution: regexp -all -nocase -- {^(#.*)} $text match

The last problem. If someone say "#abc abc abc", then not only "#abc" is saved to $match, but the whole string
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

ProXy wrote:Solution: regexp -all -nocase -- {^(#.*)} $text match
^ matches the start of a line, so for your rule to match the channel name must be the first word in the text, the * quantifier is greedy, so you'll get the complete line :) try my previous suggestion...
Locked