Permalink
Browse files

Give ponies a cooldown.

  • Loading branch information...
1 parent a0cbeb2 commit 9da3c46b5cb6cf639225095e5683824ce32d992b @mythmon mythmon committed Jul 24, 2011
Showing with 19 additions and 4 deletions.
  1. +19 −4 hamper/plugins/friendly.py
View
@@ -1,5 +1,6 @@
import random
import re
+from datetime import datetime
from zope.interface import implements
@@ -17,13 +18,14 @@ def __init__(self):
self.greetings = ['hi', 'hello', 'hey']
def process(self, bot, comm):
+ if not comm['directed']:
+ return
+
if comm['message'].strip() in self.greetings:
bot.say('{0} {1[user]}'
.format(random.choice(self.greetings), comm))
return True
- return False
-
class OmgPonies(object):
"""The classics never die."""
@@ -32,9 +34,22 @@ class OmgPonies(object):
name = 'ponies'
priority = 3
+ cooldown = 30 #seconds
+
+ def __init__(self):
+ self.last_pony_time = datetime.now()
+
def process(self, bot, comm):
- if re.match(r'.*pon(y|ies).*', comm['message']):
- bot.say('OMG!!! PONIES!!!')
+ if re.match(r'.*pon(y|ies).*', comm['message'], re.I):
+ now = datetime.now()
+ since_last_pony = now - self.last_pony_time
+ if since_last_pony.total_seconds() >= self.cooldown:
+ bot.say('OMG!!! PONIES!!!')
+ self.last_pony_time = now
+ else:
+ print('too many ponies')
+
+ # Always let the other plugins run
return False

0 comments on commit 9da3c46

Please sign in to comment.