Skip to content

Commit

Permalink
Give ponies a cooldown.
Browse files Browse the repository at this point in the history
  • Loading branch information
mythmon committed Jul 24, 2011
1 parent a0cbeb2 commit 9da3c46
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions hamper/plugins/friendly.py
@@ -1,5 +1,6 @@
import random import random
import re import re
from datetime import datetime


from zope.interface import implements from zope.interface import implements


Expand All @@ -17,13 +18,14 @@ def __init__(self):
self.greetings = ['hi', 'hello', 'hey'] self.greetings = ['hi', 'hello', 'hey']


def process(self, bot, comm): def process(self, bot, comm):
if not comm['directed']:
return

if comm['message'].strip() in self.greetings: if comm['message'].strip() in self.greetings:
bot.say('{0} {1[user]}' bot.say('{0} {1[user]}'
.format(random.choice(self.greetings), comm)) .format(random.choice(self.greetings), comm))
return True return True


return False



class OmgPonies(object): class OmgPonies(object):
"""The classics never die.""" """The classics never die."""
Expand All @@ -32,9 +34,22 @@ class OmgPonies(object):
name = 'ponies' name = 'ponies'
priority = 3 priority = 3


cooldown = 30 #seconds

def __init__(self):
self.last_pony_time = datetime.now()

def process(self, bot, comm): def process(self, bot, comm):
if re.match(r'.*pon(y|ies).*', comm['message']): if re.match(r'.*pon(y|ies).*', comm['message'], re.I):
bot.say('OMG!!! PONIES!!!') 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 return False




Expand Down

0 comments on commit 9da3c46

Please sign in to comment.