Merge lp:~stefanor/ibid/coffee-374028 into lp:~ibid-core/ibid/old-trunk-pack-0.92

Proposed by Stefano Rivera
Status: Merged
Approved by: Jonathan Hitchcock
Approved revision: 652
Merged at revision: 649
Proposed branch: lp:~stefanor/ibid/coffee-374028
Merge into: lp:~ibid-core/ibid/old-trunk-pack-0.92
Diff against target: None lines
To merge this branch: bzr merge lp:~stefanor/ibid/coffee-374028
Reviewer Review Type Date Requested Status
Jonathan Hitchcock Approve
Michael Gorven Approve
Review via email: mp+6926@code.launchpad.net

This proposal supersedes a proposal from 2009-05-31.

To post a comment you must log in.
Revision history for this message
Stefano Rivera (stefanor) wrote : Posted in a previous version of this proposal

Removed russell's coffee hack

Revision history for this message
Stefano Rivera (stefanor) wrote : Posted in a previous version of this proposal

Removed russell's coffee hack.

Excuse first merge request - had a bad commit

Revision history for this message
Michael Gorven (mgorven) wrote : Posted in a previous version of this proposal

 review approve

review: Approve
Revision history for this message
Stefano Rivera (stefanor) wrote : Posted in a previous version of this proposal

Resubmitted with decent delayed infrastructure

Revision history for this message
Stefano Rivera (stefanor) wrote :

No reviews, 3 fixes, might as well resubmit

Revision history for this message
Stefano Rivera (stefanor) wrote :

> No reviews, 3 fixes, might as well resubmit

And another one, but I'm getting tired of resubmitting. So read 652 by hand

lp:~stefanor/ibid/coffee-374028 updated
652. By Stefano Rivera

More "pot on" responses

Revision history for this message
Michael Gorven (mgorven) wrote :

 review approve

review: Approve
Revision history for this message
Jonathan Hitchcock (vhata) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ibid/core.py'
--- ibid/core.py 2009-05-05 07:58:29 +0000
+++ ibid/core.py 2009-05-31 11:11:45 +0000
@@ -10,6 +10,8 @@
10from sqlalchemy.exceptions import IntegrityError10from sqlalchemy.exceptions import IntegrityError
1111
12import ibid12import ibid
13from ibid.event import Event
14
13import auth15import auth
1416
15class Dispatcher(object):17class Dispatcher(object):
@@ -79,6 +81,28 @@
7981
80 return threads.deferToThread(self._process, event)82 return threads.deferToThread(self._process, event)
8183
84 def call_later(self, delay, callable, oldevent, *args, **kw):
85 "Run callable after delay seconds. Pass args and kw to it"
86
87 event = Event(oldevent.source, u'delayed')
88 event.sender = oldevent.sender
89 event.channel = oldevent.channel
90 event.public = oldevent.public
91 return reactor.callLater(delay, threads.deferToThread, self.delayed_call, callable, event, *args, **kw)
92
93 def delayed_call(self, callable, event, *args, **kw):
94 # Twisted doesn't catch exceptions here, so we must do it ourselves
95 try:
96 callable(event, *args, **kw)
97 self._process(event)
98 reactor.callFromThread(self.delayed_response, event)
99 except:
100 self.log.exception(u'Call Later')
101
102 def delayed_response(self, event):
103 for response in event.responses:
104 ibid.sources[event.source].send(response)
105
82class Reloader(object):106class Reloader(object):
83107
84 def __init__(self):108 def __init__(self):
85109
=== modified file 'ibid/plugins/misc.py'
--- ibid/plugins/misc.py 2009-05-01 12:17:57 +0000
+++ ibid/plugins/misc.py 2009-05-31 11:18:46 +0000
@@ -1,43 +1,61 @@
1import logging
2from random import choice
1from time import sleep3from time import sleep
24
5import ibid
3from ibid.plugins import Processor, match6from ibid.plugins import Processor, match
4from ibid.config import IntOption7from ibid.config import IntOption
5from ibid.utils import ibid_version8from ibid.utils import ibid_version
69
7help = {}10help = {}
11log = logging.getLogger('plugins.misc')
812
9help['coffee'] = u"Times coffee brewing and reserves cups for people"13help['coffee'] = u"Times coffee brewing and reserves cups for people"
10class Coffee(Processor):14class Coffee(Processor):
11 u"""coffee (on|please)"""15 u"""coffee (on|please)"""
12 feature = 'coffee'16 feature = 'coffee'
1317
14 pot = None18 pots = {}
1519
16 time = IntOption('coffee_time', u'Brewing time in seconds', 240)20 time = IntOption('coffee_time', u'Brewing time in seconds', 240)
17 cups = IntOption('coffee_cups', u'Maximum number of cups', 4)21 cups = IntOption('coffee_cups', u'Maximum number of cups', 4)
18 22
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)]
26
19 @match(r'^coffee\s+on$')27 @match(r'^coffee\s+on$')
20 def coffee_on(self, event):28 def coffee_on(self, event):
21 # Hi ... race condition.29 if (event.source, event.channel) in self.pots:
22 if self.pot:
23 event.addresponse(u"There's already a pot on")30 event.addresponse(u"There's already a pot on")
24 return31 return
25 32
26 self.pot = [event.sender['nick']]33 self.pots[(event.source, event.channel)] = [event.sender['nick']]
27 sleep(self.time)34 ibid.dispatcher.call_later(self.time, self.coffee_announce, event)
28 event.addresponse(u"Coffee's ready for %s!", u', '.join(self.pot))35
29 self.pot = None36 event.addresponse({
37 'action': True,
38 'reply': choice((
39 u'puts the kettle on',
40 u'starts grinding coffee',
41 u'flips the salt-timer',
42 u'washes some mugs',
43 )),
44 })
30 45
31 @match('^coffee\s+(?:please|pls)$')46 @match('^coffee\s+(?:please|pls)$')
32 def coffee_accept(self, event):47 def coffee_accept(self, event):
33 if not self.pot:48 if (event.source, event.channel) not in self.pots:
34 event.addresponse(u"There isn't a pot on")49 event.addresponse(u"There isn't a pot on")
3550
36 elif len(self.pot) >= self.cups:51 elif len(self.pots[(event.source, event.channel)]) >= self.cups:
37 event.addresponse(u"Sorry, there aren't any more cups left")52 event.addresponse(u"Sorry, there aren't any more cups left")
3853
54 elif event.sender['nick'] in self.pots[(event.source, event.channel)]:
55 event.addresponse(u"Now now, we don't want anyone getting caffine overdoses")
56
39 else:57 else:
40 self.pot.append(event.sender['nick'])58 self.pots[(event.source, event.channel)].append(event.sender['nick'])
41 event.addresponse(True)59 event.addresponse(True)
4260
43help['version'] = u"Show the Ibid version currently running"61help['version'] = u"Show the Ibid version currently running"
4462
=== modified file 'scripts/ibid-plugin'
--- scripts/ibid-plugin 2009-05-05 07:58:29 +0000
+++ scripts/ibid-plugin 2009-05-30 22:07:09 +0000
@@ -52,6 +52,7 @@
52class TestSource(dict):52class TestSource(dict):
53 type = 'test'53 type = 'test'
54 permissions = []54 permissions = []
55 supports = []
5556
56ibid.sources[u'test_source'] = TestSource()57ibid.sources[u'test_source'] = TestSource()
5758

Subscribers

People subscribed via source and target branches