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
1=== modified file 'ibid/core.py'
2--- ibid/core.py 2009-05-05 07:58:29 +0000
3+++ ibid/core.py 2009-05-31 11:11:45 +0000
4@@ -10,6 +10,8 @@
5 from sqlalchemy.exceptions import IntegrityError
6
7 import ibid
8+from ibid.event import Event
9+
10 import auth
11
12 class Dispatcher(object):
13@@ -79,6 +81,28 @@
14
15 return threads.deferToThread(self._process, event)
16
17+ def call_later(self, delay, callable, oldevent, *args, **kw):
18+ "Run callable after delay seconds. Pass args and kw to it"
19+
20+ event = Event(oldevent.source, u'delayed')
21+ event.sender = oldevent.sender
22+ event.channel = oldevent.channel
23+ event.public = oldevent.public
24+ return reactor.callLater(delay, threads.deferToThread, self.delayed_call, callable, event, *args, **kw)
25+
26+ def delayed_call(self, callable, event, *args, **kw):
27+ # Twisted doesn't catch exceptions here, so we must do it ourselves
28+ try:
29+ callable(event, *args, **kw)
30+ self._process(event)
31+ reactor.callFromThread(self.delayed_response, event)
32+ except:
33+ self.log.exception(u'Call Later')
34+
35+ def delayed_response(self, event):
36+ for response in event.responses:
37+ ibid.sources[event.source].send(response)
38+
39 class Reloader(object):
40
41 def __init__(self):
42
43=== modified file 'ibid/plugins/misc.py'
44--- ibid/plugins/misc.py 2009-05-01 12:17:57 +0000
45+++ ibid/plugins/misc.py 2009-05-31 11:18:46 +0000
46@@ -1,43 +1,61 @@
47+import logging
48+from random import choice
49 from time import sleep
50
51+import ibid
52 from ibid.plugins import Processor, match
53 from ibid.config import IntOption
54 from ibid.utils import ibid_version
55
56 help = {}
57+log = logging.getLogger('plugins.misc')
58
59 help['coffee'] = u"Times coffee brewing and reserves cups for people"
60 class Coffee(Processor):
61 u"""coffee (on|please)"""
62 feature = 'coffee'
63
64- pot = None
65+ pots = {}
66
67 time = IntOption('coffee_time', u'Brewing time in seconds', 240)
68 cups = IntOption('coffee_cups', u'Maximum number of cups', 4)
69
70+ def coffee_announce(self, event):
71+ event.addresponse(u"Coffee's ready for %s!", u', '.join(self.pots[(event.source, event.channel)]))
72+ del self.pots[(event.source, event.channel)]
73+
74 @match(r'^coffee\s+on$')
75 def coffee_on(self, event):
76- # Hi ... race condition.
77- if self.pot:
78+ if (event.source, event.channel) in self.pots:
79 event.addresponse(u"There's already a pot on")
80 return
81
82- self.pot = [event.sender['nick']]
83- sleep(self.time)
84- event.addresponse(u"Coffee's ready for %s!", u', '.join(self.pot))
85- self.pot = None
86+ self.pots[(event.source, event.channel)] = [event.sender['nick']]
87+ ibid.dispatcher.call_later(self.time, self.coffee_announce, event)
88+
89+ event.addresponse({
90+ 'action': True,
91+ 'reply': choice((
92+ u'puts the kettle on',
93+ u'starts grinding coffee',
94+ u'flips the salt-timer',
95+ u'washes some mugs',
96+ )),
97+ })
98
99 @match('^coffee\s+(?:please|pls)$')
100 def coffee_accept(self, event):
101- if not self.pot:
102+ if (event.source, event.channel) not in self.pots:
103 event.addresponse(u"There isn't a pot on")
104
105- elif len(self.pot) >= self.cups:
106+ elif len(self.pots[(event.source, event.channel)]) >= self.cups:
107 event.addresponse(u"Sorry, there aren't any more cups left")
108
109+ elif event.sender['nick'] in self.pots[(event.source, event.channel)]:
110+ event.addresponse(u"Now now, we don't want anyone getting caffine overdoses")
111+
112 else:
113- self.pot.append(event.sender['nick'])
114+ self.pots[(event.source, event.channel)].append(event.sender['nick'])
115 event.addresponse(True)
116
117 help['version'] = u"Show the Ibid version currently running"
118
119=== modified file 'scripts/ibid-plugin'
120--- scripts/ibid-plugin 2009-05-05 07:58:29 +0000
121+++ scripts/ibid-plugin 2009-05-30 22:07:09 +0000
122@@ -52,6 +52,7 @@
123 class TestSource(dict):
124 type = 'test'
125 permissions = []
126+ supports = []
127
128 ibid.sources[u'test_source'] = TestSource()
129

Subscribers

People subscribed via source and target branches