Merge lp:~stefanor/ibid/morse-339514 into lp:~ibid-core/ibid/old-trunk-pack-0.92

Proposed by Stefano Rivera
Status: Merged
Approved by: Jonathan Hitchcock
Approved revision: 574
Merged at revision: 579
Proposed branch: lp:~stefanor/ibid/morse-339514
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/morse-339514
Reviewer Review Type Date Requested Status
Jonathan Hitchcock Approve
Michael Gorven Approve
Review via email: mp+4368@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Stefano Rivera (stefanor) wrote :

I think this is a reasonable workaround (and output cleanup)

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

Fix looks fine. Could do with some improvements though, like generating rtable in setup() and compiling the regex.

review: Approve
lp:~stefanor/ibid/morse-339514 updated
573. By Stefano Rivera

Clean up morse

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

"Could do with some improvements though, like generating rtable in setup() and compiling the regex."

r573 fixes that

Revision history for this message
Jonathan Hitchcock (vhata) wrote :

What will this do if somebody says "morse" by itself to the bot?

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

Hi Jonathan (2009.03.12_18:44:41_+0200)
> What will this do if somebody says "morse" by itself to the bot?

Good point. I'm sure I meant to do something about that...

r574

SR

lp:~stefanor/ibid/morse-339514 updated
574. By Stefano Rivera

Handle the case of 'morse'

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/plugins/morse.py'
2--- ibid/plugins/morse.py 2009-03-08 13:16:28 +0000
3+++ ibid/plugins/morse.py 2009-03-11 10:07:15 +0000
4@@ -1,3 +1,5 @@
5+import re
6+
7 from ibid.plugins import Processor, match
8
9 help = {}
10@@ -8,7 +10,7 @@
11 u"""morse (text|morsecode)"""
12 feature = 'morse'
13
14- @match(r'^morse\s+(.+)$')
15+ @match(r'^morse\s*(.*)$')
16 def morse(self, event, message):
17
18 table = {
19@@ -64,6 +66,8 @@
20 '=': "-...-",
21 }
22
23+ if "message_raw" in event:
24+ message = re.match(r'^.*?morse\s+(.+)$', event.message_raw).group(1)
25
26 def text2morse(text):
27 return u" ".join(table.get(c.upper(), c) for c in text)
28@@ -71,9 +75,9 @@
29 def morse2text(morse):
30 rtable = dict((v, k) for k, v in table.items())
31 toks = morse.split(u' ')
32- return u" ".join(rtable.get(t, t) for t in toks)
33+ return u"".join(rtable.get(t, u' ') for t in toks)
34
35- if message.replace('-', '').replace('.', '').isspace():
36+ if message.replace(u'-', u'').replace(u'.', u'').strip() == u'':
37 event.addresponse(u'Decodes as %s', morse2text(message))
38 else:
39 event.addresponse(u'Encodes as %s', text2morse(message))

Subscribers

People subscribed via source and target branches