Author Topic: Wildcard kick and ban  (Read 9894 times)

0 Members and 1 Guest are viewing this topic.

Offline Lance

  • Full Member
  • ***
  • Posts: 129
    • View Profile
Wildcard kick and ban
« on: July 08, 2008, 02:04:17 pm »
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!

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: Wildcard kick and ban
« Reply #1 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.

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: Wildcard kick and ban
« Reply #2 on: July 08, 2008, 04:38:33 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!

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: Wildcard kick and ban
« Reply #3 on: July 08, 2008, 04:50:05 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.

Offline rabbit

  • x86
  • Hero Member
  • *****
  • Posts: 8092
  • I speak for the entire clan (except Joe)
    • View Profile
Re: Wildcard kick and ban
« Reply #4 on: July 08, 2008, 05:40:10 pm »
15 Characters, plus realms and character names (if D2/LoD).

Offline Lance

  • Full Member
  • ***
  • Posts: 129
    • View Profile
Re: Wildcard kick and ban
« Reply #5 on: July 08, 2008, 06:10:10 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!

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: Wildcard kick and ban
« Reply #6 on: July 08, 2008, 11:36:59 pm »
15 Characters, plus realms and character names (if D2/LoD).
Still manageable. :P

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: Wildcard kick and ban
« Reply #7 on: July 09, 2008, 12:41:05 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;
« Last Edit: July 09, 2008, 12:43:18 pm by Camel »

<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!

Offline Lance

  • Full Member
  • ***
  • Posts: 129
    • View Profile
Re: Wildcard kick and ban
« Reply #8 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.
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!

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: Wildcard kick and ban
« Reply #9 on: July 10, 2008, 10:33:55 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;

Offline Lance

  • Full Member
  • ***
  • Posts: 129
    • View Profile
Re: Wildcard kick and ban
« Reply #10 on: July 11, 2008, 12:00:17 am »
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!

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: Wildcard kick and ban
« Reply #11 on: July 22, 2008, 07:30:18 am »
Is there an easy way to perform wildcard checking with regex?
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: Wildcard kick and ban
« Reply #12 on: July 22, 2008, 01:47:32 pm »
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!

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: Wildcard kick and ban
« Reply #13 on: July 22, 2008, 11:47:03 pm »
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.

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: Wildcard kick and ban
« Reply #14 on: July 23, 2008, 12:06:51 pm »
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!