News:

Happy New Year! Yes, the current one, not a previous one; this is a new post, we swear!

Main Menu

Wildcard kick and ban

Started by Lance, July 08, 2008, 02:04:17 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Lance

Let's say "somenoob" is in the channel.
If I -kick some I'd like it to kick anyone's name that starts with some (kicking "somenoob")
How can this be coded? I'd like to use that type of string function for other things too.
Thanks
Quote from: Joe
[23:55:31] [william@enterprise ~/Documents/Programming/javaop2]$ svn commit -m 'Tried to fix StayConnected. Again.'
Committed revision 63.
StayConnected strikes back!

iago

That's already written in my moderation plugin, look at how I did it there.

Basically, loop through every username in the channel and check if it's a match.

Camel

Quote from: iago on July 08, 2008, 02:36:08 PM
That's already written in my moderation plugin, look at how I did it there.

Basically, loop through every username in the channel and check if it's a match.


I believe that function has position complexity O(GTFO)

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

iago

Quote from: Camel on July 08, 2008, 04:38:33 PM
Quote from: iago on July 08, 2008, 02:36:08 PM
That's already written in my moderation plugin, look at how I did it there.

Basically, loop through every username in the channel and check if it's a match.


I believe that function has position complexity O(GTFO)

The complexity is boxed by the number of users in the channel (max = 40, iirc) and the number of characters in their usernames (max = 14, iirc). So, worst case, you're checking 560 characters which takes approximately 0ms.

rabbit

15 Characters, plus realms and character names (if D2/LoD).

Lance

Quote from: iago on July 08, 2008, 02:36:08 PM
That's already written in my moderation plugin, look at how I did it there.

Basically, loop through every username in the channel and check if it's a match.


Thanks  ;D
Quote from: Joe
[23:55:31] [william@enterprise ~/Documents/Programming/javaop2]$ svn commit -m 'Tried to fix StayConnected. Again.'
Committed revision 63.
StayConnected strikes back!

iago

Quote from: rabbit on July 08, 2008, 05:40:10 PM
15 Characters, plus realms and character names (if D2/LoD).
Still manageable. :P

Camel

#7
Quote from: iago on July 08, 2008, 04:50:05 PM
Quote from: Camel on July 08, 2008, 04:38:33 PM
I believe that function has position complexity O(GTFO)

The complexity is boxed by the number of users in the channel (max = 40, iirc) and the number of characters in their usernames (max = 14, iirc). So, worst case, you're checking 560 characters which takes approximately 0ms.

iago ~= s/lol/math/g;

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Lance

Is there a way to do this without adding a star "*" or is that how the function is coded?
Actually, I can append the string with a star so nevermind.
Quote from: Joe
[23:55:31] [william@enterprise ~/Documents/Programming/javaop2]$ svn commit -m 'Tried to fix StayConnected. Again.'
Committed revision 63.
StayConnected strikes back!

iago

Quote from: SarCaSTiC on July 10, 2008, 07:57:11 PM
Is there a way to do this without adding a star "*" or is that how the function is coded?
Actually, I can append the string with a star so nevermind.
Should be simple:

foreach user in list
  if (user contains pattern)
    ban;

Lance

got it working beautifully
Thanks  :)
Quote from: Joe
[23:55:31] [william@enterprise ~/Documents/Programming/javaop2]$ svn commit -m 'Tried to fix StayConnected. Again.'
Committed revision 63.
StayConnected strikes back!

Joe

Is there an easy way to perform wildcard checking with regex?
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


Camel

Quote from: Joe on July 22, 2008, 07:30:18 AM
Is there an easy way to perform wildcard checking with regex?

Not directly, but you could transform a wildcard string in to a regex. Alternatively, you could just use this class which I already wrote. :)

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

iago

Quote from: Joe on July 22, 2008, 07:30:18 AM
Is there an easy way to perform wildcard checking with regex?
Camel's right, there's no easy way.

What you have to do is:
1) escape special characters that break regexes (and there are a bunch!)
2) replace * with .*
3) replace ? with .

I vaguely remember doing that for javaop2 somewhere.

Camel

It doesn't make much sense to use regexps when they're clearly undesirable. They are pretty slow just to compile, and then you have to match them to your input string on top of that. Just do something like the link I posted; it has a much lower runtime than a regexp.

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!