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

Proposed by Stefano Rivera
Status: Superseded
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
Ibid Core Team Pending
Review via email: mp+6923@code.launchpad.net

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

This proposal has been superseded by 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 :

Resubmitted with decent delayed infrastructure

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

Unicodeism

649. By Stefano Rivera

Return the IDelayedCall instance, so the delayed call can be cancelled

650. By Stefano Rivera

Logging typo + comment

651. By Stefano Rivera

A wider set of coffee starting responses

652. By Stefano Rivera

More "pot on" responses

Unmerged revisions

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

Subscribers

People subscribed via source and target branches