diff --git a/hamper/plugins/friendly.py b/hamper/plugins/friendly.py index 96a5b3c..dd14a94 100644 --- a/hamper/plugins/friendly.py +++ b/hamper/plugins/friendly.py @@ -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