4 Replies - 6541 Views - Last Post: 18 March 2010 - 07:12 AM Rate Topic: -----

#1 AngryJesus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 29-November 09

IRC Bot Flood Protection [Python]

Posted 17 March 2010 - 02:22 PM

Hello all. I've started coding an IRC bot, and it's coming along quite nicely. However, we need some additional flood protection, so I want to add it in as a feature of the bot. I was thinking of doing something like this:

Check what nick posts a message.
Make a counter [Nickposts = Nickposts + 1] or something similar
Then clear this every second or so.

If the number gets to high, the bot kicks the Nick. I'm a bit stumped here though. Because while it's doing this, I still want the bot to be able to process all the other lines of text coming in, so I don't want to make this a long process that would stop the bot from processing the data that's coming in. The channel I'm writing this for isn't very busy, but still, I'd like the bot to be efficient as well as being able to complete it's task.

Thanks for any help/suggestions!

Is This A Good Question/Topic? 0
  • +

Replies To: IRC Bot Flood Protection [Python]

#2 programble  Icon User is offline

  • (cons :dic :head)

Reputation: 49
  • View blog
  • Posts: 1,315
  • Joined: 21-February 09

Re: IRC Bot Flood Protection [Python]

Posted 17 March 2010 - 03:54 PM

I would use a dict, of nick -> line count.
flood = {}


When a user says something,
# Add 1 if nick is already in dict, otherwise set to 1
if flood.has_key(nick):
    flood[nick] += 1
else:
    flood[nick] = 1


In a separate thread,
# Threaded so as to not interfere with the bot's other stuff
while True:
    flood = {} # Clear counter
    time.sleep(3) # Wait 3 seconds, then do it again


Was This Post Helpful? 1
  • +
  • -

#3 AngryJesus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 29-November 09

Re: IRC Bot Flood Protection [Python]

Posted 17 March 2010 - 07:41 PM

Hey, thanks for the response.

I tried to implement what you said, because it makes perfect sense. However, I have a problem.

class MyThread(Thread):

	def run(self):
		while 1:
			flood = {}
			time.sleep(2)



This is how I created the thread to run alongside the bot.

Later on in the bot I have this statement:

		
	if flood.has_key(nick):
		
		flood[nick] += 1
		if flood[nick] > 4:
			
			s.send("KICK %s\r\n" % "#channel,%(nick)s" % locals())
	else:
		flood[nick] = 1



I tried to initiate the second thread with MyThread().start() . However, I don't think it's started. This is because the bot kicks me from the channel as soon as I have typed 4 lines, no matter how quickly or slowly I have done this. Earlier on in the program, I declared flood as a global variable, so the two threads in my program should be able to use them together yes?

Thanks for the suggestion, and once again, can someone help me out here?
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5363
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: IRC Bot Flood Protection [Python]

Posted 17 March 2010 - 07:42 PM

Rather than just the nick, can you grab the ip from the action? I would drop packets based on the ip rather than the nick.
Was This Post Helpful? 0
  • +
  • -

#5 AngryJesus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 29-November 09

Re: IRC Bot Flood Protection [Python]

Posted 18 March 2010 - 07:12 AM

Probably not, since 90% of the users of the server use the ssl port, and their IP's are masked by the server. However, my main problem is that the threading is not working properly.

I'm going to go try to figure this out by myself, but still, I'd appreciate some tips on how to get this threading working.

Or, at least a comment about what I'm doing wrong with it.

Thanks :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1