2
from random import choice
1
3
from time import sleep
3
6
from ibid.plugins import Processor, match
4
7
from ibid.config import IntOption
5
8
from ibid.utils import ibid_version
11
log = logging.getLogger('plugins.misc')
9
13
help['coffee'] = u"Times coffee brewing and reserves cups for people"
10
14
class Coffee(Processor):
11
15
u"""coffee (on|please)"""
16
20
time = IntOption('coffee_time', u'Brewing time in seconds', 240)
17
21
cups = IntOption('coffee_cups', u'Maximum number of cups', 4)
23
def coffee_announce(self, event):
24
event.addresponse(u"Coffee's ready for %s!", u', '.join(self.pots[(event.source, event.channel)]))
25
del self.pots[(event.source, event.channel)]
19
27
@match(r'^coffee\s+on$')
20
28
def coffee_on(self, event):
21
# Hi ... race condition.
23
event.addresponse(u"There's already a pot on")
29
if (event.source, event.channel) in self.pots:
30
if len(self.pots[(event.source, event.channel)]) >= self.cups:
31
event.addresponse(u"There's already a pot on, and it's all reserved")
32
elif event.sender['nick'] in self.pots[(event.source, event.channel)]:
33
event.addresponse(u"You already have a pot on the go")
35
event.addresponse(u"There's already a pot on. If you ask nicely, maybe you can have a cup")
26
self.pot = [event.sender['nick']]
28
event.addresponse(u"Coffee's ready for %s!", u', '.join(self.pot))
38
self.pots[(event.source, event.channel)] = [event.sender['nick']]
39
ibid.dispatcher.call_later(self.time, self.coffee_announce, event)
44
u'puts the kettle on',
45
u'starts grinding coffee',
46
u'flips the salt-timer',
31
51
@match('^coffee\s+(?:please|pls)$')
32
52
def coffee_accept(self, event):
53
if (event.source, event.channel) not in self.pots:
34
54
event.addresponse(u"There isn't a pot on")
36
elif len(self.pot) >= self.cups:
56
elif len(self.pots[(event.source, event.channel)]) >= self.cups:
37
57
event.addresponse(u"Sorry, there aren't any more cups left")
59
elif event.sender['nick'] in self.pots[(event.source, event.channel)]:
60
event.addresponse(u"Now now, we don't want anyone getting caffine overdoses")
40
self.pot.append(event.sender['nick'])
63
self.pots[(event.source, event.channel)].append(event.sender['nick'])
41
64
event.addresponse(True)
43
66
help['version'] = u"Show the Ibid version currently running"