Merge lp:~stefanor/ibid/translation-334764 into lp:~ibid-core/ibid/old-trunk-pack-0.92

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

My take on https://code.edge.launchpad.net/~bradwhittington/ibid/translation/+merge/3962

While I was at it, I tweaked a few responses.

Note, if you want to call addresponse with an arbitrary string, you now have to use addresponse(u'%s', string). We could work around this, by checking if len(attrs) > 0, but I think the way it is will promote good response style.

Also note, addresponse will only format unicode strings. Again, we could work around this, but I don't know if that's necessary.

Revision history for this message
Michael Gorven (mgorven) :
review: Approve
lp:~stefanor/ibid/translation-334764 updated
566. By Stefano Rivera

Unicode errors

567. By Stefano Rivera

OT: No memos response

568. By Stefano Rivera

OT: Unicode

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

"Note, if you want to call addresponse with an arbitrary string, you now have to use addresponse(u'%s', string). We could work around this, by checking if len(attrs) > 0, but I think the way it is will promote good response style."

I'm having second thoughts about this:

I often forget to type the u. It's really naughty, and I should be punished, but the result is that the bot says something like "tumbleweed: Sorry, I don't know about a currency called %s", rather than doing the right thing and logging a warning. What do we prefer to do?

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/event.py'
--- ibid/event.py 2009-02-23 20:29:44 +0000
+++ ibid/event.py 2009-03-08 10:57:45 +0000
@@ -14,8 +14,11 @@
14 def __setattr__(self, name, value):14 def __setattr__(self, name, value):
15 self[name] = value15 self[name] = value
1616
17 def addresponse(self, response, processed=True):17 def addresponse(self, response, params={}, processed=True):
18 self.responses.append(response)18 if isinstance(response, unicode):
19 self.responses.append(response % params)
20 else:
21 self.responses.append(response)
1922
20 if processed:23 if processed:
21 self.processed = True24 self.processed = True
2225
=== modified file 'ibid/plugins/admin.py'
--- ibid/plugins/admin.py 2009-03-02 09:21:35 +0000
+++ ibid/plugins/admin.py 2009-03-08 13:16:28 +0000
@@ -17,7 +17,7 @@
17 if processor.name not in plugins:17 if processor.name not in plugins:
18 plugins.append(processor.name)18 plugins.append(processor.name)
1919
20 event.addresponse(', '.join(plugins))20 event.addresponse(u'Plugins: %s', u', '.join(sorted(plugins)))
2121
22help['core'] = u'Reloads core modules.'22help['core'] = u'Reloads core modules.'
23class ReloadCoreModules(Processor):23class ReloadCoreModules(Processor):
@@ -36,7 +36,7 @@
36 else:36 else:
37 result = getattr(ibid.reloader, 'reload_%s' % module)()37 result = getattr(ibid.reloader, 'reload_%s' % module)()
3838
39 event.addresponse(result and u'%s reloaded' % module or u"Couldn't reload %s" % module)39 event.addresponse(result and u'%s reloaded' or u"Couldn't reload %s", module)
4040
41class LoadModules(Processor):41class LoadModules(Processor):
42 u"""(load|unload|reload) <plugin|processor>"""42 u"""(load|unload|reload) <plugin|processor>"""
@@ -49,13 +49,13 @@
49 def load(self, event, plugin):49 def load(self, event, plugin):
50 result = ibid.reloader.unload_processor(plugin)50 result = ibid.reloader.unload_processor(plugin)
51 result = ibid.reloader.load_processor(plugin)51 result = ibid.reloader.load_processor(plugin)
52 event.addresponse(result and u'%s reloaded' % plugin or u"Couldn't reload %s" % plugin)52 event.addresponse(result and u'%s reloaded' or u"Couldn't reload %s", plugin)
5353
54 @match(r'^unload\s+(\S+)$')54 @match(r'^unload\s+(\S+)$')
55 @authorise55 @authorise
56 def unload(self, event, plugin):56 def unload(self, event, plugin):
57 result = ibid.reloader.unload_processor(plugin)57 result = ibid.reloader.unload_processor(plugin)
58 event.addresponse(result and u'%s unloaded' % plugin or u"Couldn't unload %s" % plugin)58 event.addresponse(result and u'%s unloaded' or u"Couldn't unload %s", plugin)
5959
60help['die'] = u'Terminates the bot'60help['die'] = u'Terminates the bot'
61class Die(Processor):61class Die(Processor):
6262
=== modified file 'ibid/plugins/apt.py'
--- ibid/plugins/apt.py 2009-03-02 09:38:47 +0000
+++ ibid/plugins/apt.py 2009-03-08 13:16:28 +0000
@@ -29,7 +29,7 @@
2929
30 for word in self.bad_search_strings:30 for word in self.bad_search_strings:
31 if word in term:31 if word in term:
32 event.addresponse(u"I can't tell you about my host system. Sorry.")32 event.addresponse(u"I can't tell you about my host system. Sorry")
33 return False33 return False
3434
35 if term.strip().startswith("-"):35 if term.strip().startswith("-"):
@@ -52,14 +52,17 @@
52 if output:52 if output:
53 output = unicode_output(output.strip())53 output = unicode_output(output.strip())
54 output = [line.strip() for line in output.splitlines()]54 output = [line.strip() for line in output.splitlines()]
55 event.addresponse(u"Found %i packages: %s" % (len(output), u', '.join(output)))55 event.addresponse(u'Found %(num)i packages: %(names)s', {
56 'num': len(output),
57 'names': u', '.join(output),
58 })
56 else:59 else:
57 event.addresponse(u'No packages found')60 event.addresponse(u'No packages found')
58 else:61 else:
59 error = unicode_output(error.strip())62 error = unicode_output(error.strip())
60 if error.startswith(u"E: "):63 if error.startswith(u"E: "):
61 error = error[3:]64 error = error[3:]
62 event.addresponse(u"Couldn't search: %s" % error)65 event.addresponse(u"Couldn't search: %s", error)
6366
64 @match(r'(?:apt|aptitude|apt-get)\s+show\s+(.+)$')67 @match(r'(?:apt|aptitude|apt-get)\s+show\s+(.+)$')
65 def show(self, event, term):68 def show(self, event, term):
@@ -73,27 +76,30 @@
7376
74 if code == 0:77 if code == 0:
75 description = None78 description = None
79 provided = None
76 output = unicode_output(output)80 output = unicode_output(output)
77 for line in output.splitlines():81 for line in output.splitlines():
78 if not description:82 if not description:
79 if line.startswith(u'Description:'):83 if line.startswith(u'Description:'):
80 description = u'%s:' % line.split(None, 1)[1]84 description = u'%s:' % line.split(None, 1)[1]
81 elif line.startswith(u'Provided by:'):85 elif line.startswith(u'Provided by:'):
82 description = u'Virtual package provided by %s' % line.split(None, 2)[2]86 provided = line.split(None, 2)[2]
83 elif line != "":87 elif line != "":
84 description += u' ' + line.strip()88 description += u' ' + line.strip()
85 else:89 else:
86 # More than one package listed90 # More than one package listed
87 break91 break
88 if description:92 if provided:
89 event.addresponse(description)93 event.addresponse(u'Virtual package provided by %s', provided)
94 elif description:
95 event.addresponse(u'%s', description)
90 else:96 else:
91 raise Exception("We couldn't successfully parse aptitude's output")97 raise Exception("We couldn't successfully parse aptitude's output")
92 else:98 else:
93 error = unicode_output(error.strip())99 error = unicode_output(error.strip())
94 if error.startswith(u"E: "):100 if error.startswith(u"E: "):
95 error = error[3:]101 error = error[3:]
96 event.addresponse(u"Couldn't find package: %s" % error)102 event.addresponse(u"Couldn't find package: %s", error)
97 103
98help['apt-file'] = u'Searches for packages containing the specified file'104help['apt-file'] = u'Searches for packages containing the specified file'
99class AptFile(Processor):105class AptFile(Processor):
@@ -116,13 +122,16 @@
116 if output:122 if output:
117 output = unicode_output(output.strip())123 output = unicode_output(output.strip())
118 output = [line.split(u':')[0] for line in output.splitlines()]124 output = [line.split(u':')[0] for line in output.splitlines()]
119 event.addresponse(u"Found %i packages: %s" % (len(output), u', '.join(output)))125 event.addresponse(u'Found %(num)i packages: %(names)s', {
126 'num': len(output),
127 'names': u', '.join(output),
128 })
120 else:129 else:
121 event.addresponse(u'No packages found.')130 event.addresponse(u'No packages found')
122 else:131 else:
123 error = unicode_output(error.strip())132 error = unicode_output(error.strip())
124 if u"The cache directory is empty." in error:133 if u"The cache directory is empty." in error:
125 event.addresponse(u'Search error: apt-file cache empty.')134 event.addresponse(u'Search error: apt-file cache empty')
126 else:135 else:
127 event.addresponse(u'Search error')136 event.addresponse(u'Search error')
128 raise Exception("apt-file: %s" % error)137 raise Exception("apt-file: %s" % error)
129138
=== modified file 'ibid/plugins/auth.py'
--- ibid/plugins/auth.py 2009-03-01 23:01:30 +0000
+++ ibid/plugins/auth.py 2009-03-08 13:16:28 +0000
@@ -36,7 +36,7 @@
36 return36 return
37 account = session.query(Account).filter_by(username=user).first()37 account = session.query(Account).filter_by(username=user).first()
38 if not account:38 if not account:
39 event.addresponse(u"I don't know who %s is" % user)39 event.addresponse(u"I don't know who %s is", user)
40 session.close()40 session.close()
41 return41 return
4242
@@ -55,7 +55,7 @@
55 log.info(u"Added %s credential %s for account %s (%s) on %s by account %s", method, credential.credential, account.id, account.username, source, event.account)55 log.info(u"Added %s credential %s for account %s (%s) on %s by account %s", method, credential.credential, account.id, account.username, source, event.account)
56 session.close()56 session.close()
5757
58 event.addresponse(u'Okay')58 event.addresponse(True)
5959
60permission_values = {'no': '-', 'yes': '+', 'auth': ''}60permission_values = {'no': '-', 'yes': '+', 'auth': ''}
61class Permissions(Processor):61class Permissions(Processor):
@@ -73,7 +73,7 @@
73 session = ibid.databases.ibid()73 session = ibid.databases.ibid()
74 account = session.query(Account).filter_by(username=username).first()74 account = session.query(Account).filter_by(username=username).first()
75 if not account:75 if not account:
76 event.addresponse(u"I don't know who %s is" % username)76 event.addresponse(u"I don't know who %s is", username)
77 session.close()77 session.close()
78 return78 return
7979
@@ -82,7 +82,7 @@
82 if permission:82 if permission:
83 session.delete(permission)83 session.delete(permission)
84 else:84 else:
85 event.addresponse(u"%s doesn't have that permission anyway" % username)85 event.addresponse(u"%s doesn't have that permission anyway", username)
86 return86 return
8787
88 else:88 else:
@@ -97,7 +97,11 @@
97 value = 'yes'97 value = 'yes'
9898
99 if permission.value == value:99 if permission.value == value:
100 event.addresponse(u"%s permission for %s is already %s" % (name, username, value))100 event.addresponse(u'%(permission)s permission for %(user)s is already %(value)s', {
101 'permission': name,
102 'user': username,
103 'value': value,
104 })
101 return105 return
102106
103 permission.value = value107 permission.value = value
@@ -122,10 +126,11 @@
122 return126 return
123 account = session.query(Account).filter_by(username=username).first()127 account = session.query(Account).filter_by(username=username).first()
124 if not account:128 if not account:
125 event.addresponse(u"I don't know who %s is" % username)129 event.addresponse(u"I don't know who %s is", username)
126 return130 return
127131
128 event.addresponse(', '.join(['%s%s' % (permission_values[perm.value], perm.name) for perm in account.permissions]))132 permissions = sorted(u'%s%s' % (permission_values[perm.value], perm.name) for perm in account.permissions)
133 event.addresponse(u'Permissions: %s', u', '.join(permissions))
129134
130 @match(r'^list\s+permissions$')135 @match(r'^list\s+permissions$')
131 def list_permissions(self, event):136 def list_permissions(self, event):
@@ -138,7 +143,7 @@
138 if permission not in permissions:143 if permission not in permissions:
139 permissions.append(permission)144 permissions.append(permission)
140145
141 event.addresponse(', '.join(permissions))146 event.addresponse(u'Permissions: %s', u', '.join(sorted(permissions)))
142147
143class Auth(Processor):148class Auth(Processor):
144 u"""auth <credential>"""149 u"""auth <credential>"""
145150
=== modified file 'ibid/plugins/basic.py'
--- ibid/plugins/basic.py 2009-03-02 09:21:35 +0000
+++ ibid/plugins/basic.py 2009-03-08 13:16:28 +0000
@@ -64,6 +64,6 @@
6464
65 @match(r'^(?:choose|choice|pick)\s+(.+)$')65 @match(r'^(?:choose|choice|pick)\s+(.+)$')
66 def choose(self, event, choices):66 def choose(self, event, choices):
67 event.addresponse(u'I choose %s' % choice(self.choose_re.split(choices)))67 event.addresponse(u'I choose %s', choice(self.choose_re.split(choices)))
6868
69# vi: set et sta sw=4 ts=4:69# vi: set et sta sw=4 ts=4:
7070
=== modified file 'ibid/plugins/bzr.py'
--- ibid/plugins/bzr.py 2009-03-02 09:21:35 +0000
+++ ibid/plugins/bzr.py 2009-03-08 13:16:28 +0000
@@ -66,7 +66,8 @@
6666
67 @match(r'^(?:repos|repositories)$')67 @match(r'^(?:repos|repositories)$')
68 def handle_repositories(self, event):68 def handle_repositories(self, event):
69 event.addresponse(', '.join(self.branches.keys()))69 repositories = self.branches.keys()
70 event.addresponse(u'I know about: %s', u', '.join(sorted(repositories)))
7071
71 def remote_committed(self, repository, start, end=None):72 def remote_committed(self, repository, start, end=None):
72 commits = self.get_commits(repository, start, end)73 commits = self.get_commits(repository, start, end)
@@ -83,7 +84,7 @@
8384
84 for commit in commits:85 for commit in commits:
85 if commit:86 if commit:
86 event.addresponse(unicode(commit.strip()))87 event.addresponse(u'%s', commit.strip())
8788
88 def get_commits(self, repository, start, end=None, full=None):89 def get_commits(self, repository, start, end=None, full=None):
89 branch = None90 branch = None
9091
=== modified file 'ibid/plugins/config.py'
--- ibid/plugins/config.py 2009-03-02 09:21:35 +0000
+++ ibid/plugins/config.py 2009-03-08 13:16:28 +0000
@@ -24,8 +24,8 @@
24 ibid.config.reload()24 ibid.config.reload()
25 ibid.config.merge(FileConfig(join(ibid.options['base'], 'local.ini')))25 ibid.config.merge(FileConfig(join(ibid.options['base'], 'local.ini')))
26 ibid.reloader.reload_config()26 ibid.reloader.reload_config()
27 event.addresponse(u"Configuration reread")27 event.addresponse(u'Configuration reread')
28 log.info(u"Reread configuration file")28 log.info(u'Reread configuration file')
2929
30 @match(r'^set\s+config\s+(\S+?)(?:\s+to\s+|\s*=\s*)(\S.*?)$')30 @match(r'^set\s+config\s+(\S+?)(?:\s+to\s+|\s*=\s*)(\S.*?)$')
31 @authorise31 @authorise
@@ -51,6 +51,6 @@
51 event.addresponse(u'No such option')51 event.addresponse(u'No such option')
52 return52 return
53 config = config[part]53 config = config[part]
54 event.addresponse(unicode(config))54 event.addresponse(u'%s', config)
55 55
56# vi: set et sta sw=4 ts=4:56# vi: set et sta sw=4 ts=4:
5757
=== modified file 'ibid/plugins/core.py'
--- ibid/plugins/core.py 2009-03-02 09:21:35 +0000
+++ ibid/plugins/core.py 2009-03-08 13:16:28 +0000
@@ -116,7 +116,7 @@
116116
117 priority = 950117 priority = 950
118 complaints = Option('complaints', 'Complaint responses', (u'Huh?', u'Sorry...', u'?', u'Excuse me?', u'*blink*', u'What?'))118 complaints = Option('complaints', 'Complaint responses', (u'Huh?', u'Sorry...', u'?', u'Excuse me?', u'*blink*', u'What?'))
119 notauthed = Option('notauthed', 'Complaint responses for auth failures', (u"I'm not your bitch", u"Just do it yourself", u"I'm not going to listen to you", u"You're not the boss of me"))119 notauthed = Option('notauthed', 'Complaint responses for auth failures', (u"I'm not your bitch", u'Just do it yourself', u"I'm not going to listen to you", u"You're not the boss of me"))
120120
121 @handler121 @handler
122 def complain(self, event):122 def complain(self, event):
@@ -141,7 +141,7 @@
141 self.messages[event.identity] = filter(lambda x: event.time-x < self.limit_time, self.messages[event.identity])141 self.messages[event.identity] = filter(lambda x: event.time-x < self.limit_time, self.messages[event.identity])
142 if len(self.messages[event.identity]) > self.limit_messages:142 if len(self.messages[event.identity]) > self.limit_messages:
143 if event.public:143 if event.public:
144 event.addresponse({'reply': u"Geez, give me some time to think!"})144 event.addresponse({'reply': u'Geez, give me some time to think!'})
145 else:145 else:
146 event.processed = True146 event.processed = True
147147
@@ -159,6 +159,6 @@
159 for value in object:159 for value in object:
160 self.process(value)160 self.process(value)
161 elif isinstance(object, str):161 elif isinstance(object, str):
162 self.log.warning(u"Found a non-unicode string: %s" % object)162 self.log.warning(u'Found a non-unicode string: %s' % object)
163163
164# vi: set et sta sw=4 ts=4:164# vi: set et sta sw=4 ts=4:
165165
=== modified file 'ibid/plugins/crypto.py'
--- ibid/plugins/crypto.py 2009-03-01 23:01:30 +0000
+++ ibid/plugins/crypto.py 2009-03-08 13:16:28 +0000
@@ -14,11 +14,11 @@
1414
15 @match(r'^(md5|sha1|sha224|sha256|sha384|sha512)\s+(.+?)$')15 @match(r'^(md5|sha1|sha224|sha256|sha384|sha512)\s+(.+?)$')
16 def hash(self, event, hash, string):16 def hash(self, event, hash, string):
17 event.addresponse(unicode(eval('hashlib.%s' % hash.lower())(string).hexdigest()))17 event.addresponse(u'%s', eval('hashlib.%s' % hash.lower())(string).hexdigest())
1818
19 @match(r'^crypt\s+(.+)\s+(\S+)$')19 @match(r'^crypt\s+(.+)\s+(\S+)$')
20 def handle_crypt(self, event, string, salt):20 def handle_crypt(self, event, string, salt):
21 event.addresponse(unicode(crypt(string, salt)))21 event.addresponse(u'%s', crypt(string, salt))
2222
23help['base64'] = u'Encodes and decodes base 16, 32 and 64.'23help['base64'] = u'Encodes and decodes base 16, 32 and 64.'
24class Base64(Processor):24class Base64(Processor):
@@ -27,7 +27,7 @@
2727
28 @match(r'^b(16|32|64)(enc|dec)(?:ode)?\s+(.+?)$')28 @match(r'^b(16|32|64)(enc|dec)(?:ode)?\s+(.+?)$')
29 def base64(self, event, base, operation, string):29 def base64(self, event, base, operation, string):
30 event.addresponse(unicode(eval('base64.b%s%sode' % (base, operation.lower()))(string)))30 event.addresponse(u'%s', eval('base64.b%s%sode' % (base, operation.lower()))(string))
3131
32help['rot13'] = u'Transforms a string with ROT13.'32help['rot13'] = u'Transforms a string with ROT13.'
33class Rot13(Processor):33class Rot13(Processor):
@@ -36,6 +36,6 @@
3636
37 @match(r'^rot13\s+(.+)$')37 @match(r'^rot13\s+(.+)$')
38 def rot13(self, event, string):38 def rot13(self, event, string):
39 event.addresponse(unicode(string.encode('rot13')))39 event.addresponse(u'%s', string.encode('rot13'))
4040
41# vi: set et sta sw=4 ts=4:41# vi: set et sta sw=4 ts=4:
4242
=== modified file 'ibid/plugins/dict.py'
--- ibid/plugins/dict.py 2009-03-02 08:33:02 +0000
+++ ibid/plugins/dict.py 2009-03-08 13:16:28 +0000
@@ -22,32 +22,39 @@
22 @match(r'^define\s+(.+?)(?:\s+using\s+(.+))?$')22 @match(r'^define\s+(.+?)(?:\s+using\s+(.+))?$')
23 def define(self, event, word, dictionary):23 def define(self, event, word, dictionary):
24 definitions = self.connection.define(dictionary or '*', word)24 definitions = self.connection.define(dictionary or '*', word)
25 event.addresponse(u', '.join([d.getdefstr() for d in definitions]))25 event.addresponse(u'%s', u', '.join([d.getdefstr() for d in definitions]))
2626
27 @match(r'spell\s+(.+?)(?:\s+using\s+(.+))?$')27 @match(r'spell\s+(.+?)(?:\s+using\s+(.+))?$')
28 def handle_spell(self, event, word, strategy):28 def handle_spell(self, event, word, strategy):
29 suggestions = self.connection.match('*', strategy or 'soundex', word)29 correct = self.connection.match('*', 'exact', word)
30 event.addresponse(u', '.join([d.getword() for d in suggestions]))30 if correct:
31 event.addresponse(u'That seems correct. Carry on')
32 return
33 suggestions = self.connection.match('*', strategy or 'lev', word)
34 if suggestions:
35 event.addresponse(u'Suggestions: %s', u', '.join([d.getword() for d in suggestions]))
36 else:
37 event.addresponse(u"That doesn't seem correct, but I can't find anything to suggest")
3138
32 @match(r'^dictionaries$')39 @match(r'^dictionaries$')
33 def handle_dictionaries(self, event):40 def handle_dictionaries(self, event):
34 event.addresponse(u', '.join(self.dictionaries.keys()))41 event.addresponse(u'Dictionaries: %s', u', '.join(sorted(self.dictionaries.keys())))
3542
36 @match(r'^strater?gies$')43 @match(r'^strater?gies$')
37 def handle_strategies(self, event):44 def handle_strategies(self, event):
38 event.addresponse(u', '.join(self.strategies.keys()))45 event.addresponse(u'Strategies: %s', u', '.join(sorted(self.strategies.keys())))
3946
40 @match(r'^dictionary\s+(.+?)$')47 @match(r'^dictionary\s+(.+?)$')
41 def handle_dictionary(self, event, dictionary):48 def handle_dictionary(self, event, dictionary):
42 if dictionary in self.dictionaries:49 if dictionary in self.dictionaries:
43 event.addresponse(unicode(self.dictionaries[dictionary]))50 event.addresponse(u'%s', self.dictionaries[dictionary])
44 else:51 else:
45 event.addresponse(u"I don't have that dictionary")52 event.addresponse(u"I don't have that dictionary")
4653
47 @match(r'^strater?gy\s+(.+?)$')54 @match(r'^strater?gy\s+(.+?)$')
48 def handle_strategy(self, event, strategy):55 def handle_strategy(self, event, strategy):
49 if strategy in self.strategies:56 if strategy in self.strategies:
50 event.addresponse(unicode(self.strategies[strategy]))57 event.addresponse(u'%s', self.strategies[strategy])
51 else:58 else:
52 event.addresponse(u"I don't have that strategy")59 event.addresponse(u"I don't have that strategy")
5360
5461
=== modified file 'ibid/plugins/eval.py'
--- ibid/plugins/eval.py 2009-03-05 16:33:12 +0000
+++ ibid/plugins/eval.py 2009-03-08 13:16:28 +0000
@@ -27,10 +27,10 @@
27 exec('import sys', globals)27 exec('import sys', globals)
28 exec('import re', globals)28 exec('import re', globals)
29 exec('import time', globals)29 exec('import time', globals)
30 result = unicode(eval(code, globals, {}))30 result = eval(code, globals, {})
31 except Exception, e:31 except Exception, e:
32 result = unicode(e)32 result = e
33 event.addresponse(result)33 event.addresponse(u'%s', result)
3434
35class Perl(Processor):35class Perl(Processor):
36 u"""pl <code>"""36 u"""pl <code>"""
@@ -46,7 +46,7 @@
46 except Exception, e:46 except Exception, e:
47 result = e47 result = e
4848
49 event.addresponse(unicode(result))49 event.addresponse(u'%s', result)
5050
51class Lua(Processor):51class Lua(Processor):
52 u"""lua <code>"""52 u"""lua <code>"""
@@ -62,6 +62,6 @@
62 except Exception, e:62 except Exception, e:
63 result = e63 result = e
6464
65 event.addresponse(unicode(result))65 event.addresponse(u'%s', result)
6666
67# vi: set et sta sw=4 ts=4:67# vi: set et sta sw=4 ts=4:
6868
=== modified file 'ibid/plugins/factoid.py'
--- ibid/plugins/factoid.py 2009-03-01 23:01:30 +0000
+++ ibid/plugins/factoid.py 2009-03-08 13:16:28 +0000
@@ -96,7 +96,7 @@
96 session = ibid.databases.ibid()96 session = ibid.databases.ibid()
97 factoid = session.query(Factoid).options(eagerload('values')).join('names').filter(func.lower(FactoidName.name)==escape_name(name).lower()).order_by(FactoidValue.id).first()97 factoid = session.query(Factoid).options(eagerload('values')).join('names').filter(func.lower(FactoidName.name)==escape_name(name).lower()).order_by(FactoidValue.id).first()
98 if factoid:98 if factoid:
99 event.addresponse(', '.join(['%s: %s' % (factoid.values.index(value), value.value) for value in factoid.values[start:]]))99 event.addresponse(u'%s', u', '.join(['%s: %s' % (factoid.values.index(value), value.value) for value in factoid.values[start:]]))
100100
101 session.close()101 session.close()
102102
@@ -120,7 +120,7 @@
120120
121 if (number or pattern):121 if (number or pattern):
122 if len(factoids) > 1:122 if len(factoids) > 1:
123 event.addresponse(u"Pattern matches multiple factoids, please be more specific")123 event.addresponse(u'Pattern matches multiple factoids, please be more specific')
124 return124 return
125125
126 if factoids[0][2].identity_id not in identities and not factoidadmin:126 if factoids[0][2].identity_id not in identities and not factoidadmin:
@@ -152,7 +152,7 @@
152 session.close()152 session.close()
153 event.addresponse(True)153 event.addresponse(True)
154 else:154 else:
155 event.addresponse(u"I didn't know about %s anyway" % name)155 event.addresponse(u"I didn't know about %s anyway", name)
156156
157 @match(r'^(.+)\s+is\s+the\s+same\s+as\s+(.+)$')157 @match(r'^(.+)\s+is\s+the\s+same\s+as\s+(.+)$')
158 @authorise158 @authorise
@@ -172,7 +172,7 @@
172 event.addresponse(True)172 event.addresponse(True)
173 log.info(u"Added name '%s' to factoid %s by %s/%s (%s)", name.name, factoid.id, event.account, event.identity, event.sender['connection'])173 log.info(u"Added name '%s' to factoid %s by %s/%s (%s)", name.name, factoid.id, event.account, event.identity, event.sender['connection'])
174 else:174 else:
175 event.addresponse(u"I don't know about %s" % name)175 event.addresponse(u"I don't know about %s", name)
176176
177class Search(Processor):177class Search(Processor):
178 u"""(search|scan) for <pattern> [from <start>]"""178 u"""(search|scan) for <pattern> [from <start>]"""
@@ -196,7 +196,7 @@
196 matches = query[start:start+limit]196 matches = query[start:start+limit]
197197
198 if matches:198 if matches:
199 event.addresponse(u'; '.join('%s [%s]' % (fname.name, values) for factoid, values, fname in matches))199 event.addresponse(u'%s', u'; '.join('%s [%s]' % (fname.name, values) for factoid, values, fname in matches))
200 else:200 else:
201 event.addresponse(u"I couldn't find anything with that name")201 event.addresponse(u"I couldn't find anything with that name")
202202
@@ -264,7 +264,7 @@
264 if count:264 if count:
265 return {'reply': reply}265 return {'reply': reply}
266266
267 reply = '%s %s' % (fname.name.replace('_%', '$arg').replace('\\%', '%').replace('\\_', '_'), reply)267 reply = u'%s %s' % (fname.name.replace('_%', '$arg').replace('\\%', '%').replace('\\_', '_'), reply)
268 return reply268 return reply
269269
270class Set(Processor):270class Set(Processor):
@@ -294,7 +294,7 @@
294 session.delete(fvalue)294 session.delete(fvalue)
295 session.flush()295 session.flush()
296 elif not addition:296 elif not addition:
297 event.addresponse(u"I already know stuff about %s" % name)297 event.addresponse(u'I already know stuff about %s', name)
298 return298 return
299 else:299 else:
300 factoid = Factoid()300 factoid = Factoid()
301301
=== modified file 'ibid/plugins/feeds.py'
--- ibid/plugins/feeds.py 2009-03-01 23:01:30 +0000
+++ ibid/plugins/feeds.py 2009-03-08 13:16:28 +0000
@@ -58,7 +58,7 @@
58 feed = session.query(Feed).filter(func.lower(Feed.name)==name.lower()).first()58 feed = session.query(Feed).filter(func.lower(Feed.name)==name.lower()).first()
5959
60 if feed:60 if feed:
61 event.addresponse(u"I already have the %s feed" % name)61 event.addresponse(u'I already have the %s feed', name)
62 else:62 else:
63 feed = Feed(unicode(name), unicode(url), event.identity)63 feed = Feed(unicode(name), unicode(url), event.identity)
6464
@@ -68,7 +68,10 @@
68 event.addresponse(True)68 event.addresponse(True)
69 log.info(u"Added feed '%s' by %s/%s (%s): %s (Found %s entries)", name, event.account, event.identity, event.sender['connection'], url, len(feed.entries))69 log.info(u"Added feed '%s' by %s/%s (%s): %s (Found %s entries)", name, event.account, event.identity, event.sender['connection'], url, len(feed.entries))
70 else:70 else:
71 event.addresponse(u"Sorry, I could not add the %s feed. %s is not a valid feed" % (name,url))71 event.addresponse(u'Sorry, I could not add the %(name)s feed. %(url)s is not a valid feed', {
72 'name': name,
73 'url': url,
74 })
7275
73 session.close()76 session.close()
7477
@@ -77,7 +80,7 @@
77 session = ibid.databases.ibid()80 session = ibid.databases.ibid()
78 feeds = session.query(Feed).all()81 feeds = session.query(Feed).all()
79 if feeds:82 if feeds:
80 event.addresponse(u', '.join([feed.name for feed in feeds]))83 event.addresponse(u'I know about: %s', u', '.join(sorted([feed.name for feed in feeds])))
81 else:84 else:
82 event.addresponse(u"I don't know about any feeds")85 event.addresponse(u"I don't know about any feeds")
8386
@@ -88,7 +91,7 @@
88 feed = session.query(Feed).filter(func.lower(Feed.name)==name.lower()).first()91 feed = session.query(Feed).filter(func.lower(Feed.name)==name.lower()).first()
8992
90 if not feed:93 if not feed:
91 event.addresponse(u"I don't have the %s feed anyway" % name)94 event.addresponse(u"I don't have the %s feed anyway", name)
92 else:95 else:
93 session.delete(feed)96 session.delete(feed)
94 log.info(u"Deleted feed '%s' by %s/%s (%s): %s", name, event.account, event.identity, event.sender['connection'], feed.url)97 log.info(u"Deleted feed '%s' by %s/%s (%s): %s", name, event.account, event.identity, event.sender['connection'], feed.url)
@@ -112,7 +115,7 @@
112 session.close()115 session.close()
113116
114 if not feed:117 if not feed:
115 event.addresponse(u"I don't know about the %s feed" % name)118 event.addresponse(u"I don't know about the %s feed", name)
116 return119 return
117120
118 feed.update()121 feed.update()
@@ -120,7 +123,9 @@
120 event.addresponse(u"I can't access that feed")123 event.addresponse(u"I can't access that feed")
121 return124 return
122125
123 event.addresponse(u', '.join(['%s: "%s"' % (feed.entries.index(entry), html2text_file(entry.title, None).strip()) for entry in feed.entries[start:number+start]]))126 articles = feed.entries[start:number+start]
127 articles = ['%s: "%s"' % (feed.entries.index(entry), html2text_file(entry.title, None).strip()) for entry in articles]
128 event.addresponse(u'%s', u', '.join(articles))
124129
125 @match(r'^article\s+(?:(\d+)|/(.+?)/)\s+from\s+(.+?)$')130 @match(r'^article\s+(?:(\d+)|/(.+?)/)\s+from\s+(.+?)$')
126 def article(self, event, number, pattern, name):131 def article(self, event, number, pattern, name):
@@ -129,7 +134,7 @@
129 session.close()134 session.close()
130135
131 if not feed:136 if not feed:
132 event.addresponse(u"I don't know about the %s feed" % name)137 event.addresponse(u"I don't know about the %s feed", name)
133 return138 return
134139
135 feed.update() 140 feed.update()
@@ -152,7 +157,7 @@
152 break157 break
153158
154 if not article:159 if not article:
155 event.addresponse(u"Are you making up news again?")160 event.addresponse(u'Are you making up news again?')
156 return161 return
157162
158 if 'summary' in article:163 if 'summary' in article:
@@ -163,6 +168,10 @@
163 else:168 else:
164 summary = article.content[0].value169 summary = article.content[0].value
165170
166 event.addresponse(u'"%s" %s : %s' % (html2text_file(article.title, None).strip(), article.link, summary))171 event.addresponse(u'"%(title)s" %(link)s : %(summary)s', {
172 'title': html2text_file(article.title, None).strip(),
173 'link': article.link,
174 'summary': summary,
175 })
167176
168# vi: set et sta sw=4 ts=4:177# vi: set et sta sw=4 ts=4:
169178
=== modified file 'ibid/plugins/google.py'
--- ibid/plugins/google.py 2009-03-05 15:03:20 +0000
+++ ibid/plugins/google.py 2009-03-08 13:16:28 +0000
@@ -61,17 +61,26 @@
61 results.append(u'"%s" %s' % (de_entity(title), item["unescapedUrl"]))61 results.append(u'"%s" %s' % (de_entity(title), item["unescapedUrl"]))
62 62
63 if results:63 if results:
64 event.addresponse(u', '.join(results))64 event.addresponse(u'%s', u', '.join(results))
65 else:65 else:
66 event.addresponse(u"Wow! Google couldn't find anything.")66 event.addresponse(u"Wow! Google couldn't find anything")
6767
68 @match(r'^(?:rank|(?:google(?:fight|compare|cmp)))\s+(?:for\s+)?(.+?)\s+and\s+(.+?)$')68 @match(r'^(?:rank|(?:google(?:fight|compare|cmp)))\s+(?:for\s+)?(.+?)\s+and\s+(.+?)$')
69 def googlefight(self, event, term1, term2):69 def googlefight(self, event, term1, term2):
70 count1 = int(self._google_api_search(term1, "small")["responseData"]["cursor"].get("estimatedResultCount", 0))70 count1 = int(self._google_api_search(term1, "small")["responseData"]["cursor"].get("estimatedResultCount", 0))
71 count2 = int(self._google_api_search(term2, "small")["responseData"]["cursor"].get("estimatedResultCount", 0))71 count2 = int(self._google_api_search(term2, "small")["responseData"]["cursor"].get("estimatedResultCount", 0))
72 event.addresponse(u'%s wins with %i hits, %s had %i hits' % 72 event.addresponse(u'%(firstterm)s wins with %(firsthits)i hits, %(secondterm)s had %(secondhits)i hits',
73 (count1 > count2 and (term1, count1, term2, count2) or (term2, count2, term1, count1))73 (count1 > count2 and {
74 )74 'firstterm': term1,
75 'firsthits': count1,
76 'secondterm': term2,
77 'secondhits': count2,
78 } or {
79 'firstterm': term2,
80 'firsthits': count2,
81 'secondterm': term1,
82 'secondhits': count1,
83 }))
7584
76# Unfortunatly google API search doesn't support all of google search's85# Unfortunatly google API search doesn't support all of google search's
77# features.86# features.
@@ -103,7 +112,7 @@
103 if not font:112 if not font:
104 event.addresponse(u'No result')113 event.addresponse(u'No result')
105 else:114 else:
106 event.addresponse(font.b.string)115 event.addresponse(u'%s', font.b.string)
107116
108 @match(r'^gdefine\s+(.+)$')117 @match(r'^gdefine\s+(.+)$')
109 def define(self, event, term):118 def define(self, event, term):
@@ -114,9 +123,9 @@
114 definitions.append(de_entity(li.contents[0].strip()))123 definitions.append(de_entity(li.contents[0].strip()))
115124
116 if definitions:125 if definitions:
117 event.addresponse(u' :: '.join(definitions))126 event.addresponse(u'%s', u' :: '.join(definitions))
118 else:127 else:
119 event.addresponse(u"Are you making up words again?")128 event.addresponse(u'Are you making up words again?')
120129
121 # Not supported by Google API: http://code.google.com/p/google-ajax-apis/issues/detail?id=24130 # Not supported by Google API: http://code.google.com/p/google-ajax-apis/issues/detail?id=24
122 @match(r'^google(?:\.com?)?\.([a-z]{2})(?:\s+for)?\s+(.*)$')131 @match(r'^google(?:\.com?)?\.([a-z]{2})(?:\s+for)?\s+(.*)$')
@@ -138,8 +147,8 @@
138 break147 break
139148
140 if results:149 if results:
141 event.addresponse(u", ".join(results))150 event.addresponse('%s', u', '.join(results))
142 else:151 else:
143 event.addresponse(u"Wow! Google couldn't find anything.")152 event.addresponse(u"Wow! Google couldn't find anything")
144153
145# vi: set et sta sw=4 ts=4:154# vi: set et sta sw=4 ts=4:
146155
=== modified file 'ibid/plugins/help.py'
--- ibid/plugins/help.py 2009-03-05 16:33:12 +0000
+++ ibid/plugins/help.py 2009-03-08 13:16:28 +0000
@@ -27,7 +27,7 @@
27 if feature not in features:27 if feature not in features:
28 features.append(feature)28 features.append(feature)
2929
30 event.addresponse(u' '.join(features))30 event.addresponse(u'Features: %s', u' '.join(sorted(features)))
3131
32 @match(r'^help\s+(.+)$')32 @match(r'^help\s+(.+)$')
33 def help(self, event, feature):33 def help(self, event, feature):
@@ -39,7 +39,7 @@
39 event.addresponse(module.help[feature])39 event.addresponse(module.help[feature])
40 return40 return
4141
42 event.addresponse(u"I can't help you with %s" % feature)42 event.addresponse(u"I can't help you with %s", feature)
4343
44 @match(r'^(?:usage|how\s+do\s+I\s+use)\s+(.+)$')44 @match(r'^(?:usage|how\s+do\s+I\s+use)\s+(.+)$')
45 def usage(self, event, feature):45 def usage(self, event, feature):
@@ -49,9 +49,9 @@
49 for name, klass in inspect.getmembers(processor, inspect.isclass):49 for name, klass in inspect.getmembers(processor, inspect.isclass):
50 if hasattr(klass, 'feature') and klass.feature == feature and klass.__doc__:50 if hasattr(klass, 'feature') and klass.feature == feature and klass.__doc__:
51 for line in klass.__doc__.splitlines():51 for line in klass.__doc__.splitlines():
52 event.addresponse('Usage: %s' % line.strip())52 event.addresponse(u'Usage: %s', line.strip())
5353
54 if not event.responses:54 if not event.responses:
55 event.addresponse(u"I don't know how to use %s either" % feature)55 event.addresponse(u"I don't know how to use %s either", feature)
5656
57# vi: set et sta sw=4 ts=4:57# vi: set et sta sw=4 ts=4:
5858
=== modified file 'ibid/plugins/http.py'
--- ibid/plugins/http.py 2009-03-07 16:10:50 +0000
+++ ibid/plugins/http.py 2009-03-08 13:16:28 +0000
@@ -52,7 +52,8 @@
52 if action == 'GET':52 if action == 'GET':
53 match = title.search(data)53 match = title.search(data)
54 if match:54 if match:
55 reply = u'%s "%s"' % (reply, match.groups()[0].strip())55 reply += u' "%s"' % match.groups()[0].strip()
5656
57 event.addresponse(reply)57 event.addresponse('%s', reply)
58
58# vi: set et sta sw=4 ts=4:59# vi: set et sta sw=4 ts=4:
5960
=== modified file 'ibid/plugins/identity.py'
--- ibid/plugins/identity.py 2009-03-01 23:01:30 +0000
+++ ibid/plugins/identity.py 2009-03-08 13:16:28 +0000
@@ -29,12 +29,12 @@
29 admin = True29 admin = True
30 else:30 else:
31 account = session.query(Account).filter_by(id=event.account).first()31 account = session.query(Account).filter_by(id=event.account).first()
32 event.addresponse(u'You already have an account called "%s".' % account.username)32 event.addresponse(u'You already have an account called "%s"', account.username)
33 return33 return
3434
35 account = session.query(Account).filter_by(username=username).first()35 account = session.query(Account).filter_by(username=username).first()
36 if account:36 if account:
37 event.addresponse(u'There is already an account called "%s". Please choose a different name.' % account.username)37 event.addresponse(u'There is already an account called "%s". Please choose a different name', account.username)
38 return38 return
3939
40 account = Account(username)40 account = Account(username)
@@ -51,7 +51,7 @@
5151
52 identify_cache.clear()52 identify_cache.clear()
53 session.close()53 session.close()
54 event.addresponse(u'Done')54 event.addresponse(True)
5555
56chars = string.letters + string.digits56chars = string.letters + string.digits
5757
@@ -78,7 +78,8 @@
78 username = event.sender['id']78 username = event.sender['id']
79 account = session.query(Account).filter_by(username=username).first()79 account = session.query(Account).filter_by(username=username).first()
80 if account:80 if account:
81 event.addresponse(u"I tried to create the account %s for you, but it already exists. Please use 'create account <name>'." % username)81 event.addresponse(u'I tried to create the account %s for you, but it already exists. '
82 u"Please use 'create account <name>'", username)
82 return83 return
83 account = Account(username)84 account = Account(username)
84 session.save_or_update(account)85 session.save_or_update(account)
@@ -88,7 +89,7 @@
88 session.save_or_update(currentidentity)89 session.save_or_update(currentidentity)
89 session.flush()90 session.flush()
90 identify_cache.clear()91 identify_cache.clear()
91 event.addresponse(u"I've created the account %s for you" % username)92 event.addresponse(u"I've created the account %s for you", username)
92 log.info(u"Created account %s (%s) by %s/%s (%s)", account.id, account.username, event.account, event.identity, event.sender['connection'])93 log.info(u"Created account %s (%s) by %s/%s (%s)", account.id, account.username, event.account, event.identity, event.sender['connection'])
93 log.info(u"Attached identity %s (%s on %s) to account %s (%s)", currentidentity.id, currentidentity.identity, currentidentity.source, account.id, account.username)94 log.info(u"Attached identity %s (%s on %s) to account %s (%s)", currentidentity.id, currentidentity.identity, currentidentity.source, account.id, account.username)
9495
@@ -98,16 +99,16 @@
98 admin = True99 admin = True
99 account = session.query(Account).filter_by(username=username).first()100 account = session.query(Account).filter_by(username=username).first()
100 if not account:101 if not account:
101 event.addresponse(u"I don't know who %s is" % username)102 event.addresponse(u"I don't know who %s is", username)
102 return103 return
103104
104 ident = session.query(Identity).filter(func.lower(Identity.identity)==identity.lower()).filter(func.lower(Identity.source)==source.lower()).first()105 ident = session.query(Identity).filter(func.lower(Identity.identity)==identity.lower()).filter(func.lower(Identity.source)==source.lower()).first()
105 if ident and ident.account:106 if ident and ident.account:
106 event.addresponse(u'This identity is already attached to account %s' % ident.account.username)107 event.addresponse(u'This identity is already attached to account %s', ident.account.username)
107 return108 return
108109
109 if source.lower() not in ibid.sources:110 if source.lower() not in ibid.sources:
110 event.addresponse(u"I am not connected to %s" % source)111 event.addresponse(u'I am not connected to %s', source)
111 else:112 else:
112 source = ibid.sources[source.lower()].name113 source = ibid.sources[source.lower()].name
113114
@@ -136,7 +137,10 @@
136 session = ibid.databases.ibid()137 session = ibid.databases.ibid()
137 (account_id, user, source) = self.tokens[token]138 (account_id, user, source) = self.tokens[token]
138 if event.source.lower() != source.lower() or event.sender['id'].lower() != user.lower():139 if event.source.lower() != source.lower() or event.sender['id'].lower() != user.lower():
139 event.addresponse(u'You need to send me this token from %s on %s' % (user, source))140 event.addresponse(u'You need to send me this token from %(name)s on %(source)s', {
141 'name': user,
142 'source': source,
143 })
140 return144 return
141145
142 identity = session.query(Identity).filter(func.lower(Identity.identity)==user.lower()).filter(func.lower(Identity.source)==source.lower()).first()146 identity = session.query(Identity).filter(func.lower(Identity.identity)==user.lower()).filter(func.lower(Identity.source)==source.lower()).first()
@@ -163,7 +167,7 @@
163 return167 return
164 account = session.query(Account).filter_by(username=username).first()168 account = session.query(Account).filter_by(username=username).first()
165 if not account:169 if not account:
166 event.addresponse(u"I don't know who %s is" % username)170 event.addresponse(u"I don't know who %s is", username)
167 return171 return
168172
169 identity = session.query(Identity).filter_by(account_id=account.id).filter(func.lower(Identity.identity)==user.lower()).filter(func.lower(Identity.source)==source.lower()).first()173 identity = session.query(Identity).filter_by(account_id=account.id).filter(func.lower(Identity.identity)==user.lower()).filter(func.lower(Identity.source)==source.lower()).first()
@@ -193,7 +197,7 @@
193 return197 return
194 account = session.query(Account).filter_by(id=event.account).first()198 account = session.query(Account).filter_by(id=event.account).first()
195 if not account:199 if not account:
196 event.addresponse(u"%s doesn't exist. Please use 'add account' first" % username)200 event.addresponse(u"%s doesn't exist. Please use 'add account' first", username)
197 return201 return
198202
199 else:203 else:
@@ -201,14 +205,14 @@
201 return205 return
202 account = session.query(Account).filter_by(username=username).first()206 account = session.query(Account).filter_by(username=username).first()
203 if not account:207 if not account:
204 event.addresponse(u"I don't know who %s is" % username)208 event.addresponse(u"I don't know who %s is", username)
205 return209 return
206210
207 account.attributes.append(Attribute(name, value))211 account.attributes.append(Attribute(name, value))
208 session.save_or_update(account)212 session.save_or_update(account)
209 session.flush()213 session.flush()
210 session.close()214 session.close()
211 event.addresponse(u'Done')215 event.addresponse(True)
212 log.info(u"Added attribute '%s' = '%s' to account %s (%s) by %s/%s (%s)", name, value, account.id, account.username, event.account, event.identity, event.sender['connection'])216 log.info(u"Added attribute '%s' = '%s' to account %s (%s) by %s/%s (%s)", name, value, account.id, account.username, event.account, event.identity, event.sender['connection'])
213217
214class Describe(Processor):218class Describe(Processor):
@@ -221,17 +225,23 @@
221 if username.upper() == 'I':225 if username.upper() == 'I':
222 if not event.account:226 if not event.account:
223 identity = session.query(Identity).get(event.identity)227 identity = session.query(Identity).get(event.identity)
224 event.addresponse(u"%s on %s" % (identity.identity, identity.source))228 event.addresponse(u"%(name)s on %(source)s", {
229 'name': identity.identity,
230 'source': identity.source,
231 })
225 return232 return
226 account = session.query(Account).get(event.account)233 account = session.query(Account).get(event.account)
227234
228 else:235 else:
229 account = session.query(Account).filter_by(username=username).first()236 account = session.query(Account).filter_by(username=username).first()
230 if not account:237 if not account:
231 event.addresponse(u"I don't know who %s is" % username)238 event.addresponse(u"I don't know who %s is", username)
232 return239 return
233240
234 event.addresponse(u'%s is %s' % (account.username, ', '.join('%s on %s' % (identity.identity, identity.source) for identity in account.identities)))241 event.addresponse(u'%(accountname)s is %(identities)s', {
242 'accountname': account.username,
243 'identities': u', '.join(u'%s on %s' % (identity.identity, identity.source) for identity in account.identities),
244 })
235 session.close()245 session.close()
236246
237class Identify(Processor):247class Identify(Processor):
238248
=== modified file 'ibid/plugins/imdb.py'
--- ibid/plugins/imdb.py 2009-03-01 23:01:30 +0000
+++ ibid/plugins/imdb.py 2009-03-08 13:16:28 +0000
@@ -50,25 +50,28 @@
50 self.imdb.update(result)50 self.imdb.update(result)
5151
52 except IMDbDataAccessError, e:52 except IMDbDataAccessError, e:
53 event.addresponse(u"IMDb doesn't like me today. It said '%s'" % e[0]["errmsg"])53 event.addresponse(u"IMDb doesn't like me today. It said '%s'", e[0]["errmsg"])
54 raise54 raise
5555
56 except IMDbError, e:56 except IMDbError, e:
57 event.addresponse(u"IMDb must be having a bad day (or you are asking it silly things)")57 event.addresponse(u'IMDb must be having a bad day (or you are asking it silly things)')
58 raise58 raise
5959
60 if result is not None:60 if result is not None:
61 event.addresponse(u"Found " + getattr(self, "display_" + search_type)(result))61 event.addresponse(u'Found %s', getattr(self, 'display_' + search_type)(result))
62 return62 return
6363
64 if len(results) == 0:64 if len(results) == 0:
65 event.addresponse(u"Sorry, couldn't find that.")65 event.addresponse(u"Sorry, couldn't find that")
66 else:66 else:
67 results = [x[self.name_keys[search_type]] for x in results]67 results = [x[self.name_keys[search_type]] for x in results]
68 results = enumerate(results)68 results = enumerate(results)
69 results = [u"%i: %s" % (x[0] + 1, x[1]) for x in results]69 results = [u"%i: %s" % (x[0] + 1, x[1]) for x in results]
70 more = (u"", u">")[len(results) == 20]70 event.addresponse(u'Found %(greaterthan)s%(num)i matches: %(results)s', {
71 event.addresponse(u"Found %s%i matches: %s" % (more, len(results), u", ".join(results)))71 'greaterthan': (u'', u'>')[len(results) == 20],
72 'num': len(results),
73 'results': u', '.join(results),
74 })
7275
73 def display_character(self, character):76 def display_character(self, character):
74 desc = u"%s: %s." % (character.characterID, character["long imdb name"])77 desc = u"%s: %s." % (character.characterID, character["long imdb name"])
7578
=== modified file 'ibid/plugins/info.py'
--- ibid/plugins/info.py 2009-03-02 09:38:47 +0000
+++ ibid/plugins/info.py 2009-03-08 13:16:28 +0000
@@ -26,7 +26,11 @@
2626
27 @match(r'^fortune$')27 @match(r'^fortune$')
28 def handler(self, event):28 def handler(self, event):
29 event.addresponse(self.remote_fortune() or u"Couldn't execute fortune")29 fortune = self.remote_fortune()
30 if fortune:
31 event.addresponse(u'%s', fortune)
32 else:
33 event.addresponse(u"Couldn't execute fortune")
3034
31 def remote_fortune(self):35 def remote_fortune(self):
32 fortune = Popen(self.fortune, stdout=PIPE, stderr=PIPE)36 fortune = Popen(self.fortune, stdout=PIPE, stderr=PIPE)
@@ -49,9 +53,12 @@
49 def handle_nickometer(self, event, nick, wreasons):53 def handle_nickometer(self, event, nick, wreasons):
50 nick = nick or event.sender['nick']54 nick = nick or event.sender['nick']
51 score, reasons = nickometer(str(nick))55 score, reasons = nickometer(str(nick))
52 event.addresponse(u"%s is %s%% lame" % (nick, score))56 event.addresponse(u"%(nick)s is %(score)s%% lame", {
57 'nick': nick,
58 'score': score,
59 })
53 if wreasons:60 if wreasons:
54 event.addresponse(u', '.join(['%s (%s)' % reason for reason in reasons]))61 event.addresponse(u'Because: %s', u', '.join(['%s (%s)' % reason for reason in reasons]))
5562
56help['man'] = u'Retrieves information from manpages.'63help['man'] = u'Retrieves information from manpages.'
57class Man(Processor):64class Man(Processor):
@@ -88,9 +95,9 @@
88 output = output.splitlines()95 output = output.splitlines()
89 index = output.index('NAME')96 index = output.index('NAME')
90 if index:97 if index:
91 event.addresponse(output[index+1].strip())98 event.addresponse(u'%s', output[index+1].strip())
92 index = output.index('SYNOPSIS')99 index = output.index('SYNOPSIS')
93 if index:100 if index:
94 event.addresponse(output[index+1].strip())101 event.addresponse(u'%s', output[index+1].strip())
95102
96# vi: set et sta sw=4 ts=4:103# vi: set et sta sw=4 ts=4:
97104
=== modified file 'ibid/plugins/irc.py'
--- ibid/plugins/irc.py 2009-03-01 23:01:30 +0000
+++ ibid/plugins/irc.py 2009-03-08 13:16:28 +0000
@@ -25,21 +25,21 @@
25 channel = event.channel25 channel = event.channel
2626
27 if source.lower() not in ibid.sources:27 if source.lower() not in ibid.sources:
28 event.addresponse(u"I don't have a source called %s" % source.lower())28 event.addresponse(u"I don't have a source called %s", source.lower())
29 return29 return
3030
31 source = ibid.sources[source.lower()]31 source = ibid.sources[source.lower()]
3232
33 if not hasattr(source, 'join'):33 if not hasattr(source, 'join'):
34 event.addresponse(u"%s cannot join/part channels" % (source.name,))34 event.addresponse(u'%s cannot join/part channels', source.name)
35 return35 return
3636
37 if action == 'join':37 if action == 'join':
38 source.join(channel)38 source.join(channel)
39 event.addresponse(u"Joining %s" % channel)39 event.addresponse(u'Joining %s', channel)
40 else:40 else:
41 source.part(channel)41 source.part(channel)
42 event.addresponse(u"Parting %s" % channel)42 event.addresponse(u'Parting %s', channel)
4343
44 @match(r'^change\s+nick\s+to\s+(\S+)(?:\s+on\s+(\S+))?$')44 @match(r'^change\s+nick\s+to\s+(\S+)(?:\s+on\s+(\S+))?$')
45 @authorise45 @authorise
@@ -49,15 +49,15 @@
49 source = event.source49 source = event.source
5050
51 if source.lower() not in ibid.sources:51 if source.lower() not in ibid.sources:
52 event.addresponse(u"I don't have a source called %s" % source.lower())52 event.addresponse(u"I don't have a source called %s", source.lower())
53 return53 return
5454
55 source = ibid.sources[source.lower()]55 source = ibid.sources[source.lower()]
5656
57 if not hasattr(source, 'change_nick'):57 if not hasattr(source, 'change_nick'):
58 event.addresponse(u"%s cannot change nicks" % source)58 event.addresponse(u'%s cannot change nicks', source)
59 else:59 else:
60 source.change_nick(nick)60 source.change_nick(nick)
61 event.addresponse(u'Changing nick to %s' % nick)61 event.addresponse(u'Changing nick to %s', nick)
6262
63# vi: set et sta sw=4 ts=4:63# vi: set et sta sw=4 ts=4:
6464
=== modified file 'ibid/plugins/karma.py'
--- ibid/plugins/karma.py 2009-03-01 23:01:30 +0000
+++ ibid/plugins/karma.py 2009-03-08 13:16:28 +0000
@@ -50,7 +50,7 @@
50 @authorise50 @authorise
51 def set(self, event, subject, adjust, reason):51 def set(self, event, subject, adjust, reason):
52 if self.public and not event.public:52 if self.public and not event.public:
53 event.addresponse(u"Karma must be done in public")53 event.addresponse(u'Karma must be done in public')
54 return54 return
5555
56 if subject.lower() in self.ignore:56 if subject.lower() in self.ignore:
@@ -97,16 +97,19 @@
97 session = ibid.databases.ibid()97 session = ibid.databases.ibid()
98 karma = session.query(Karma).filter(func.lower(Karma.subject)==subject.lower()).first()98 karma = session.query(Karma).filter(func.lower(Karma.subject)==subject.lower()).first()
99 if not karma:99 if not karma:
100 event.addresponse(u"%s has neutral karma" % subject)100 event.addresponse(u'%s has neutral karma', subject)
101 else:101 else:
102 event.addresponse(u"%s has karma of %s" % (subject, karma.value))102 event.addresponse(u'%(subject)s has karma of %(value)s', {
103 'subject': subject,
104 'value': karma.value,
105 })
103 session.close()106 session.close()
104107
105 @match(r'^(reverse\s+)?karmaladder$')108 @match(r'^(reverse\s+)?karmaladder$')
106 def ladder(self, event, reverse):109 def ladder(self, event, reverse):
107 session = ibid.databases.ibid()110 session = ibid.databases.ibid()
108 karmas = session.query(Karma).order_by(reverse and Karma.value.asc() or Karma.value.desc()).limit(30).all()111 karmas = session.query(Karma).order_by(reverse and Karma.value.asc() or Karma.value.desc()).limit(30).all()
109 event.addresponse(', '.join(['%s: %s (%s)' % (karmas.index(karma), karma.subject, karma.value) for karma in karmas]))112 event.addresponse('%s', ', '.join(['%s: %s (%s)' % (karmas.index(karma), karma.subject, karma.value) for karma in karmas]))
110 session.close()113 session.close()
111114
112# vi: set et sta sw=4 ts=4:115# vi: set et sta sw=4 ts=4:
113116
=== modified file 'ibid/plugins/lookup.py'
--- ibid/plugins/lookup.py 2009-03-08 08:00:10 +0000
+++ ibid/plugins/lookup.py 2009-03-08 13:21:32 +0000
@@ -28,15 +28,15 @@
2828
29 if quote.lower() == "random":29 if quote.lower() == "random":
30 number = u"".join(soup.find('p', attrs={'class': 'quote'}).find('b').contents)30 number = u"".join(soup.find('p', attrs={'class': 'quote'}).find('b').contents)
31 event.addresponse(u"%s:" % number)31 event.addresponse(u'%s:', number)
3232
33 quote = soup.find('p', attrs={'class': 'qt'})33 quote = soup.find('p', attrs={'class': 'qt'})
34 if not quote:34 if not quote:
35 event.addresponse(u"There's no such quote, but if you keep talking like that maybe there will be.")35 event.addresponse(u"There's no such quote, but if you keep talking like that maybe there will be")
36 else:36 else:
37 for line in quote.contents:37 for line in quote.contents:
38 if str(line) != '<br />':38 if str(line) != '<br />':
39 event.addresponse(unicode(line).strip())39 event.addresponse(u'%s', line.strip())
4040
41help['lastfm'] = u'Lists the tracks last listened to by the specified user.'41help['lastfm'] = u'Lists the tracks last listened to by the specified user.'
42class LastFm(Processor):42class LastFm(Processor):
@@ -46,11 +46,11 @@
4646
47 @match(r'^last\.?fm\s+for\s+(\S+?)\s*$')47 @match(r'^last\.?fm\s+for\s+(\S+?)\s*$')
48 def listsongs(self, event, username):48 def listsongs(self, event, username):
49 songs = feedparser.parse("http://ws.audioscrobbler.com/1.0/user/%s/recenttracks.rss?%s" % (username, time()))49 songs = feedparser.parse('http://ws.audioscrobbler.com/1.0/user/%s/recenttracks.rss?%s' % (username, time()))
50 if songs['bozo']:50 if songs['bozo']:
51 event.addresponse(u"No such user")51 event.addresponse(u'No such user')
52 else:52 else:
53 event.addresponse(u', '.join(u'%s (%s ago)' % (e.title, ago(datetime.utcnow() - datetime.strptime(e.updated, '%a, %d %b %Y %H:%M:%S +0000'), 1)) for e in songs['entries']))53 event.addresponse(u'%s', u', '.join(u'%s (%s ago)' % (e.title, ago(datetime.utcnow() - datetime.strptime(e.updated, '%a, %d %b %Y %H:%M:%S +0000'), 1)) for e in songs['entries']))
5454
55help['lotto'] = u"Gets the latest lotto results from the South African National Lottery."55help['lotto'] = u"Gets the latest lotto results from the South African National Lottery."
56class Lotto(Processor):56class Lotto(Processor):
@@ -58,40 +58,37 @@
5858
59 feature = 'lotto'59 feature = 'lotto'
60 60
61 errors = {
62 'open': 'Something went wrong getting to the Lotto site',
63 'balls': 'I expected to get %s balls, but found %s. They were: %s',
64 }
65
66 za_url = 'http://www.nationallottery.co.za/'61 za_url = 'http://www.nationallottery.co.za/'
67 za_re = re.compile(r'images/balls/ball_(\d+).gif')62 za_re = re.compile(r'images/balls/ball_(\d+).gif')
68 za_text = u'Latest lotto results for South Africa, Lotto: '
69 63
70 @match(r'lotto(\s+for\s+south\s+africa)?')64 @match(r'lotto(\s+for\s+south\s+africa)?')
71 def za(self, event, za):65 def za(self, event, za):
72 try:66 try:
73 f = urlopen(self.za_url)67 f = urlopen(self.za_url)
74 except Exception, e:68 except Exception, e:
75 event.addresponse(self.errors['open'])69 event.addresponse(u'Something went wrong getting to the Lotto site')
76 return70 return
77 71
78 s = "".join(f)72 s = "".join(f)
79 f.close()73 f.close()
80 74
81 r = self.za_text
82
83 balls = self.za_re.findall(s)75 balls = self.za_re.findall(s)
84 76
85 if len(balls) != 14:77 if len(balls) != 14:
86 event.addresponse(self.errors['balls'] % \78 event.addresponse(u'I expected to get %(expected)s balls, but found %(found)s. They were: %(balls)s', {
87 (14, len(balls), ", ".join(balls)))79 'expected': 14,
80 'found': len(balls),
81 'balls': u', '.join(balls),
82 })
88 return83 return
89 84
90 r += u" ".join(balls[:6])85 event.addresponse(u'Latest lotto results for South Africa, '
91 r += u" (Bonus: %s), Lotto Plus: " % (balls[6], )86 u'Lotto: %(lottoballs)s (Bonus: %(lottobonus)s), Lotto Plus: %(plusballs)s (Bonus: %(plusbonus)s)', {
92 r += u" ".join(balls[7:13])87 'lottoballs': u" ".join(balls[:6]),
93 r += u" (Bonus: %s)" % (balls[13], )88 'lottobonus': balls[6],
94 event.addresponse(r)89 'plusballs': u" ".join(balls[7:13]),
90 'plusbonus': balls[13],
91 })
9592
96help['fml'] = u'Retrieves quotes from fmylife.com.'93help['fml'] = u'Retrieves quotes from fmylife.com.'
97class FMyLife(Processor):94class FMyLife(Processor):
@@ -109,7 +106,11 @@
109106
110 @match(r'^(?:fml\s+|http://www\.fmylife\.com/\S+/)(\d+|random)$')107 @match(r'^(?:fml\s+|http://www\.fmylife\.com/\S+/)(\d+|random)$')
111 def fml(self, event, id):108 def fml(self, event, id):
112 event.addresponse(self.remote_get(id) or u"No such quote")109 quote = self.remote_get(id)
110 if quote:
111 event.addresponse(u'%s', quote)
112 else:
113 event.addresponse(u'No such quote')
113114
114help["microblog"] = u"Looks up messages on microblogging services like twitter and identica."115help["microblog"] = u"Looks up messages on microblogging services like twitter and identica."
115class Twitter(Processor):116class Twitter(Processor):
@@ -134,7 +135,7 @@
134 status = loads(f.read())135 status = loads(f.read())
135 f.close()136 f.close()
136137
137 return u'%s: "%s"' % (status['user']['screen_name'], status['text'])138 return {'screen_name': status['user']['screen_name'], 'text': status['text']}
138139
139 def remote_latest(self, service, user):140 def remote_latest(self, service, user):
140 service_url = self.services[service]141 service_url = self.services[service]
@@ -148,25 +149,27 @@
148 elif service_url.endswith("/api/"):149 elif service_url.endswith("/api/"):
149 url = "%s/notice/%i" % (service_url[:-5], latest["id"])150 url = "%s/notice/%i" % (service_url[:-5], latest["id"])
150151
151 when = ago(datetime.utcnow() - datetime.strptime(latest["created_at"], '%a %b %d %H:%M:%S +0000 %Y'), 1)152 return {
152153 'text': latest['text'],
153 return u'"%s" %s ago, %s' % (latest['text'], when, url)154 'ago': ago(datetime.utcnow() - datetime.strptime(latest["created_at"], '%a %b %d %H:%M:%S +0000 %Y'), 1),
155 'url': url,
156 }
154157
155 @handler158 @handler
156 def update(self, event, service, id):159 def update(self, event, service, id):
157 event.addresponse(self.remote_update(service.lower(), int(id)))160 event.addresponse(u'%(screen_name)s: "%(text)s"', self.remote_update(service.lower(), int(id)))
158161
159 @handler162 @handler
160 def latest(self, event, service, user):163 def latest(self, event, service, user):
161 event.addresponse(self.remote_latest(service.lower(), user))164 event.addresponse(u'"%(text)s" %(ago)s ago, %(url)s', self.remote_latest(service.lower(), user))
162165
163 @match(r'^https?://(?:www\.)?twitter\.com/[^/ ]+/statuse?s?/(\d+)$')166 @match(r'^https?://(?:www\.)?twitter\.com/[^/ ]+/statuse?s?/(\d+)$')
164 def twitter(self, event, id):167 def twitter(self, event, id):
165 event.addresponse(self.remote_update('twitter', int(id)))168 event.addresponse(u'%(screen_name)s: "%(text)s"', self.remote_update('twitter', int(id)))
166169
167 @match(r'^https?://(?:www\.)?identi.ca/notice/(\d+)$')170 @match(r'^https?://(?:www\.)?identi.ca/notice/(\d+)$')
168 def identica(self, event, id):171 def identica(self, event, id):
169 event.addresponse(self.remote_update('identi.ca', int(id)))172 event.addresponse(u'%(screen_name)s: "%(text)s"', self.remote_update('identi.ca', int(id)))
170173
171help['currency'] = u'Converts amounts between currencies.'174help['currency'] = u'Converts amounts between currencies.'
172class Currency(Processor):175class Currency(Processor):
@@ -199,7 +202,7 @@
199 soup = BeautifulSoup(f.read())202 soup = BeautifulSoup(f.read())
200 f.close()203 f.close()
201204
202 event.addresponse(soup.findAll('span', attrs={'class': 'XEsmall'})[1].contents[0])205 event.addresponse(u'%s', soup.findAll('span', attrs={'class': 'XEsmall'})[1].contents[0])
203206
204 @match(r'^(?:currency|currencies)\s+for\s+(?:the\s+)?(.+)$')207 @match(r'^(?:currency|currencies)\s+for\s+(?:the\s+)?(.+)$')
205 def currency(self, event, place):208 def currency(self, event, place):
@@ -210,10 +213,10 @@
210 results = []213 results = []
211 for code, place, name in self.currencies:214 for code, place, name in self.currencies:
212 if search.search(place):215 if search.search(place):
213 results.append('%s uses %s (%s)' % (place, name, code))216 results.append(u'%s uses %s (%s)' % (place, name, code))
214217
215 if results:218 if results:
216 event.addresponse(u', '.join(results))219 event.addresponse(u'%s', u', '.join(results))
217 else:220 else:
218 event.addresponse(u'No currencies found')221 event.addresponse(u'No currencies found')
219222
@@ -279,7 +282,7 @@
279 for td in soup.findAll('table')[2].findAll('td', align='left'):282 for td in soup.findAll('table')[2].findAll('td', align='left'):
280 day = td.b.string283 day = td.b.string
281 forecast = td.contents[2]284 forecast = td.contents[2]
282 forecasts.append('%s: %s' % (day, self._text(forecast)))285 forecasts.append(u'%s: %s' % (day, self._text(forecast)))
283286
284 return forecasts287 return forecasts
285288
@@ -287,19 +290,25 @@
287 def weather(self, event, place):290 def weather(self, event, place):
288 try:291 try:
289 values = self.remote_weather(place)292 values = self.remote_weather(place)
290 event.addresponse(u'In %(place)s at %(time)s: %(temp)s; Humidity: %(humidity)s; Wind: %(wind)s; Conditions: %(conditions)s; Sunrise/set: %(sunrise)s/%(sunset)s; Moonrise/set: %(moonrise)s/%(moonset)s' % values)293 event.addresponse(u'In %(place)s at %(time)s: %(temp)s; Humidity: %(humidity)s; Wind: %(wind)s; Conditions: %(conditions)s; Sunrise/set: %(sunrise)s/%(sunset)s; Moonrise/set: %(moonrise)s/%(moonset)s', values)
291 except Weather.TooManyPlacesException, e:294 except Weather.TooManyPlacesException, e:
292 event.addresponse(u'Too many places match %s: %s' % (place, '; '.join(e.message)))295 event.addresponse(u'Too many places match %(place)s: %(exception)s', {
296 'place': place,
297 'exception': u'; '.join(e.message),
298 })
293 except Weather.WeatherException, e:299 except Weather.WeatherException, e:
294 event.addresponse(e.message)300 event.addresponse(u'%s', e.message)
295301
296 @match(r'^forecast\s+(?:for\s+)?(.+)$')302 @match(r'^forecast\s+(?:for\s+)?(.+)$')
297 def forecast(self, event, place):303 def forecast(self, event, place):
298 try:304 try:
299 event.addresponse(u', '.join(self.remote_forecast(place)))305 event.addresponse(u'%s', u', '.join(self.remote_forecast(place)))
300 except Weather.TooManyPlacesException, e:306 except Weather.TooManyPlacesException, e:
301 event.addresponse(u'Too many places match %s: %s' % (place, '; '.join(e.message)))307 event.addresponse(u'Too many places match %(place)s: %(exception)s', {
308 'place': place,
309 'exception': u'; '.join(e.message),
310 })
302 except Weather.WeatherException, e:311 except Weather.WeatherException, e:
303 event.addresponse(e.message)312 event.addresponse(u'%s', e.message)
304313
305# vi: set et sta sw=4 ts=4:314# vi: set et sta sw=4 ts=4:
306315
=== modified file 'ibid/plugins/math.py'
--- ibid/plugins/math.py 2009-03-02 09:38:47 +0000
+++ ibid/plugins/math.py 2009-03-08 13:16:28 +0000
@@ -30,12 +30,12 @@
30 if output:30 if output:
31 output = unicode_output(output.strip())31 output = unicode_output(output.strip())
32 output = output.replace('\\\n', '')32 output = output.replace('\\\n', '')
33 event.addresponse(output)33 event.addresponse(u'%s', output)
34 else:34 else:
35 error = unicode_output(error.strip())35 error = unicode_output(error.strip())
36 error = error.split(":", 1)[1].strip()36 error = error.split(":", 1)[1].strip()
37 error = error[0].lower() + error[1:]37 error = error[0].lower() + error[1:]
38 event.addresponse(u"You can't %s" % error)38 event.addresponse(u"You can't %s", error)
39 else:39 else:
40 event.addresponse(u"Error running bc")40 event.addresponse(u"Error running bc")
41 error = unicode_output(error.strip())41 error = unicode_output(error.strip())
@@ -70,17 +70,17 @@
70 event.addresponse(u"I can't divide by zero.")70 event.addresponse(u"I can't divide by zero.")
71 return71 return
72 except ArithmeticError, e:72 except ArithmeticError, e:
73 event.addresponse(u"I can't do that: %s" % e.message)73 event.addresponse(u"I can't do that: %s", e.message)
74 return74 return
75 except ValueError, e:75 except ValueError, e:
76 if e.message == "math domain error":76 if e.message == "math domain error":
77 event.addresponse(u"I can't do that: %s" % e.message)77 event.addresponse(u"I can't do that: %s", e.message)
78 return78 return
79 except Exception, e:79 except Exception, e:
80 return80 return
8181
82 if isinstance(result, (int, long, float, complex)):82 if isinstance(result, (int, long, float, complex)):
83 event.addresponse(unicode(result))83 event.addresponse(u'%s', result)
8484
85help['base'] = 'Convert numbers between bases (radixes)'85help['base'] = 'Convert numbers between bases (radixes)'
86class BaseConvert(Processor):86class BaseConvert(Processor):
@@ -197,17 +197,19 @@
197 base_to = self._parse_base(base_to)197 base_to = self._parse_base(base_to)
198 198
199 if min(base_from, base_to) < 2 or max(base_from, base_to) > 64:199 if min(base_from, base_to) < 2 or max(base_from, base_to) > 64:
200 event.addresponse(u"Sorry, valid bases are between 2 and 64, inclusive.")200 event.addresponse(u'Sorry, valid bases are between 2 and 64, inclusive')
201 return201 return
202 202
203 try:203 try:
204 number = self._from_base(number, base_from)204 number = self._from_base(number, base_from)
205 except ValueError, e:205 except ValueError, e:
206 event.addresponse(e.message)206 event.addresponse(u'%s', e.message)
207 return207 return
208 208
209 event.addresponse(u"That is %s in %s." %209 event.addresponse(u'That is %(result)s in %(base)s', {
210 (self._in_base(number, base_to), self._base_name(base_to)))210 'result': self._in_base(number, base_to),
211 'base': self._base_name(base_to),
212 })
211213
212 @handler214 @handler
213 def ascii_decode(self, event, text, base_to):215 def ascii_decode(self, event, text, base_to):
@@ -222,16 +224,19 @@
222 for char in text:224 for char in text:
223 code_point = ord(char)225 code_point = ord(char)
224 if code_point > 255:226 if code_point > 255:
225 output += u"U%s " % self._in_base(code_point, base_to)227 output += u'U%s ' % self._in_base(code_point, base_to)
226 else:228 else:
227 output += self._in_base(code_point, base_to) + u" "229 output += self._in_base(code_point, base_to) + u" "
228 230
229 output = output.strip()231 output = output.strip()
230232
231 event.addresponse(u"That is %s in %s." % (output, self._base_name(base_to)))233 event.addresponse(u'That is %(result)s in %(base)s', {
234 'result': output,
235 'base': self._base_name(base_to),
236 })
232237
233 if base_to == 64 and [True for plugin in ibid.processors if getattr(plugin, "feature", None) == "base64"]:238 if base_to == 64 and [True for plugin in ibid.processors if getattr(plugin, 'feature', None) == 'base64']:
234 event.addresponse(u'If you want a base64 encoding, use the "base64" feature.')239 event.addresponse(u'If you want a base64 encoding, use the "base64" feature')
235240
236 @handler241 @handler
237 def ascii_encode(self, event, source, base_from):242 def ascii_encode(self, event, source, base_from):
@@ -266,11 +271,11 @@
266 if len(buf) > 0:271 if len(buf) > 0:
267 output += process_buf(buf)272 output += process_buf(buf)
268 except ValueError, e:273 except ValueError, e:
269 event.addresponse(e.message)274 event.addresponse(u'%s', e.message)
270 return275 return
271 276
272 event.addresponse(u'That is "%s".' % output)277 event.addresponse(u'That is "%s"', output)
273 if base_from == 64 and [True for plugin in ibid.processors if getattr(plugin, "feature", None) == "base64"]:278 if base_from == 64 and [True for plugin in ibid.processors if getattr(plugin, 'feature', None) == 'base64']:
274 event.addresponse(u'If you want a base64 encoding, use the "base64" feature.')279 event.addresponse(u'If you want a base64 encoding, use the "base64" feature')
275280
276# vi: set et sta sw=4 ts=4:281# vi: set et sta sw=4 ts=4:
277282
=== modified file 'ibid/plugins/memo.py'
--- ibid/plugins/memo.py 2009-03-01 23:01:30 +0000
+++ ibid/plugins/memo.py 2009-03-08 13:16:28 +0000
@@ -60,11 +60,11 @@
60 if not identity:60 if not identity:
61 identity = account.identities[0]61 identity = account.identities[0]
62 if not to:62 if not to:
63 event.addresponse(u"I don't know who %s is" % who)63 event.addresponse(u"I don't know who %s is", who)
64 return64 return
6565
66 if permission(u'recvmemo', to.account and to.account.id or None, to.source) != 'yes':66 if permission(u'recvmemo', to.account and to.account.id or None, to.source) != 'yes':
67 event.addresponse(u'Just tell %s yourself' % who)67 event.addresponse(u'Just tell %s yourself', who)
68 return68 return
6969
70 memo = Memo(event.identity, to.id, memo, how.lower() in ('pm', 'privmsg', 'msg'))70 memo = Memo(event.identity, to.id, memo, how.lower() in ('pm', 'privmsg', 'msg'))
@@ -95,11 +95,22 @@
95 memos = get_memos(session, event)95 memos = get_memos(session, event)
9696
97 for memo in memos:97 for memo in memos:
98 message = '%s: By the way, %s on %s told me to tell you %s %s ago' % (event.sender['nick'], memo.sender.identity, memo.sender.source, memo.memo, ago(datetime.now()-memo.time))
99 if memo.private:98 if memo.private:
99 message = u'By the way, %(sender)s on %(source)s told me to tell you %(message)s %(ago)s ago' % {
100 'sender': memo.sender.identity,
101 'source': memo.sender.source,
102 'message': memo.memo,
103 'ago': ago(datetime.now()-memo.time),
104 }
100 event.addresponse({'reply': message, 'target': event.sender['id']})105 event.addresponse({'reply': message, 'target': event.sender['id']})
101 else:106 else:
102 event.addresponse(message)107 event.addresponse(u'%(recipient)s: By the way, %(sender)s on %(source)s told me to tell you %(message)s %(ago)s ago', {
108 'recipient': event.sender['nick'],
109 'sender': memo.sender.identity,
110 'source': memo.sender.source,
111 'message': memo.memo,
112 'ago': ago(datetime.now()-memo.time),
113 })
103114
104 memo.delivered = True115 memo.delivered = True
105 session.save_or_update(memo)116 session.save_or_update(memo)
@@ -128,7 +139,7 @@
128 memos = get_memos(session, event)139 memos = get_memos(session, event)
129140
130 if len(memos) > 0:141 if len(memos) > 0:
131 event.addresponse({'reply': 'You have %s messages' % len(memos), 'target': event.sender['id']})142 event.addresponse({'reply': u'You have %s messages' % len(memos), 'target': event.sender['id']})
132 else:143 else:
133 memo_cache[event.identity] = None144 memo_cache[event.identity] = None
134145
@@ -145,7 +156,7 @@
145 def messages(self, event):156 def messages(self, event):
146 session = ibid.databases.ibid()157 session = ibid.databases.ibid()
147 memos = get_memos(session, event, True)158 memos = get_memos(session, event, True)
148 event.addresponse(', '.join(['%s: %s (%s)' % (memos.index(memo), memo.sender.identity, memo.time.strftime(self.datetime_format)) for memo in memos]))159 event.addresponse(u'%s', u', '.join(['%s: %s (%s)' % (memos.index(memo), memo.sender.identity, memo.time.strftime(self.datetime_format)) for memo in memos]))
149 session.close()160 session.close()
150161
151 @match(r'message\s+(\d+)$')162 @match(r'message\s+(\d+)$')
@@ -153,7 +164,12 @@
153 session = ibid.databases.ibid()164 session = ibid.databases.ibid()
154 memos = get_memos(session, event, True)165 memos = get_memos(session, event, True)
155 memo = memos[int(number)]166 memo = memos[int(number)]
156 event.addresponse(u"From %s on %s at %s: %s" % (memo.sender.identity, memo.sender.source, memo.time.strftime(self.datetime_format), memo.memo))167 event.addresponse(u"From %(sender)s on %(source)s at %(time)s: %(message)s", {
168 'sender': memo.sender.identity,
169 'source': memo.sender.source,
170 'time': memo.time.strftime(self.datetime_format),
171 'message': memo.memo,
172 })
157 session.close()173 session.close()
158174
159175
160176
=== modified file 'ibid/plugins/misc.py'
--- ibid/plugins/misc.py 2009-03-03 22:52:47 +0000
+++ ibid/plugins/misc.py 2009-03-08 13:16:28 +0000
@@ -25,13 +25,13 @@
25 25
26 self.pot = [event.sender['nick']]26 self.pot = [event.sender['nick']]
27 sleep(self.time)27 sleep(self.time)
28 event.addresponse(u"Coffee's ready for %s!" % u', '.join(self.pot))28 event.addresponse(u"Coffee's ready for %s!", u', '.join(self.pot))
29 self.pot = None29 self.pot = None
30 30
31 @match('^coffee\s+(?:please|pls)$')31 @match('^coffee\s+(?:please|pls)$')
32 def coffee_accept(self, event):32 def coffee_accept(self, event):
33 if not self.pot:33 if not self.pot:
34 event.addresponse(u"There isn't a pot on.")34 event.addresponse(u"There isn't a pot on")
3535
36 elif len(self.pot) >= self.cups:36 elif len(self.pot) >= self.cups:
37 event.addresponse(u"Sorry, there aren't any more cups left")37 event.addresponse(u"Sorry, there aren't any more cups left")
@@ -47,7 +47,10 @@
4747
48 @match(r'^version$')48 @match(r'^version$')
49 def show_version(self, event):49 def show_version(self, event):
50 event.addresponse(ibid_version() and u"I am version %s" % ibid_version() or u"I don't know what version I am :-(")50 if ibid_version():
51 event.addresponse(u'I am version %s', ibid_version())
52 else:
53 event.addresponse(u"I don't know what version I am :-(")
5154
52help['dvorak'] = u"Makes text typed on a QWERTY keyboard as if it was Dvorak work, and vice-versa"55help['dvorak'] = u"Makes text typed on a QWERTY keyboard as if it was Dvorak work, and vice-versa"
53class Dvorak(Processor):56class Dvorak(Processor):
@@ -65,10 +68,10 @@
65 68
66 @match(r'(?:asdf|dvorak)\s+(.+)')69 @match(r'(?:asdf|dvorak)\s+(.+)')
67 def convert_from_qwerty(self, event, text):70 def convert_from_qwerty(self, event, text):
68 event.addresponse(text.translate(self.typed_on_qwerty))71 event.addresponse(u'%s', text.translate(self.typed_on_qwerty))
69 72
70 @match(r'(?:aoeu|qwerty)\s+(.+)')73 @match(r'(?:aoeu|qwerty)\s+(.+)')
71 def convert_from_dvorak(self, event, text):74 def convert_from_dvorak(self, event, text):
72 event.addresponse(text.translate(self.typed_on_dvorak))75 event.addresponse(u'%s', text.translate(self.typed_on_dvorak))
7376
74# vi: set et sta sw=4 ts=4:77# vi: set et sta sw=4 ts=4:
7578
=== modified file 'ibid/plugins/morse.py'
--- ibid/plugins/morse.py 2009-03-05 16:33:12 +0000
+++ ibid/plugins/morse.py 2009-03-08 13:16:28 +0000
@@ -70,12 +70,12 @@
70 70
71 def morse2text(morse):71 def morse2text(morse):
72 rtable = dict((v, k) for k, v in table.items())72 rtable = dict((v, k) for k, v in table.items())
73 toks = morse.split(' ')73 toks = morse.split(u' ')
74 return u" ".join(rtable.get(t, t) for t in toks)74 return u" ".join(rtable.get(t, t) for t in toks)
7575
76 if message.replace('-', '').replace('.', '').isspace():76 if message.replace('-', '').replace('.', '').isspace():
77 event.addresponse(morse2text(message))77 event.addresponse(u'Decodes as %s', morse2text(message))
78 else:78 else:
79 event.addresponse(text2morse(message))79 event.addresponse(u'Encodes as %s', text2morse(message))
8080
81# vi: set et sta sw=4 ts=4:81# vi: set et sta sw=4 ts=4:
8282
=== modified file 'ibid/plugins/network.py'
--- ibid/plugins/network.py 2009-03-02 09:38:47 +0000
+++ ibid/plugins/network.py 2009-03-08 13:16:28 +0000
@@ -35,17 +35,20 @@
35 try:35 try:
36 answers = resolver.query(host, str(record))36 answers = resolver.query(host, str(record))
37 except NoAnswer:37 except NoAnswer:
38 event.addresponse(u"I couldn't find any %s records for %s" % (record, host))38 event.addresponse(u"I couldn't find any %(type)s records for %(host)s", {
39 'type': record,
40 'host': host,
41 })
39 return42 return
40 except NXDOMAIN:43 except NXDOMAIN:
41 event.addresponse(u"I couldn't find the domain %s" % host)44 event.addresponse(u"I couldn't find the domain %s", host)
42 return45 return
4346
44 responses = []47 responses = []
45 for rdata in answers:48 for rdata in answers:
46 responses.append(unicode(rdata))49 responses.append(unicode(rdata))
4750
48 event.addresponse(u', '.join(responses))51 event.addresponse(u'Records: %s', u', '.join(responses))
4952
50help['ping'] = u'ICMP pings the specified host.'53help['ping'] = u'ICMP pings the specified host.'
51class Ping(Processor):54class Ping(Processor):
@@ -69,11 +72,12 @@
69 code = ping.wait()72 code = ping.wait()
7073
71 if code == 0:74 if code == 0:
72 output = unicode_output(' '.join(output.splitlines()[-2:]))75 output = unicode_output(output)
73 event.addresponse(output)76 output = u' '.join(output.splitlines()[-2:])
77 event.addresponse(u'%s', output)
74 else:78 else:
75 error = unicode_output(error.replace('\n', ' ').replace('ping:', '', 1).strip())79 error = unicode_output(error).replace(u'\n', u' ').replace(u'ping:', u'', 1).strip()
76 event.addresponse(error)80 event.addresponse(u'Error: %s', error)
7781
78help['tracepath'] = u'Traces the path to the given host.'82help['tracepath'] = u'Traces the path to the given host.'
79class Tracepath(Processor):83class Tracepath(Processor):
@@ -96,10 +100,10 @@
96 if code == 0:100 if code == 0:
97 output = unicode_output(output)101 output = unicode_output(output)
98 for line in output.splitlines():102 for line in output.splitlines():
99 event.addresponse(line)103 event.addresponse(u'%s', line)
100 else:104 else:
101 error = unicode_output(error.strip())105 error = unicode_output(error.strip())
102 event.addresponse(error.replace('\n', ' '))106 event.addresponse(u'Error: %s', error.replace(u'\n', u' '))
103107
104help['ipcalc'] = u'IP address calculator'108help['ipcalc'] = u'IP address calculator'
105class IPCalc(Processor):109class IPCalc(Processor):
@@ -133,14 +137,14 @@
133137
134 if code == 0:138 if code == 0:
135 output = unicode_output(output)139 output = unicode_output(output)
136 if output.startswith("INVALID ADDRESS"):140 if output.startswith(u"INVALID ADDRESS"):
137 event.addresponse(u"That's an invalid address. Try something like 192.168.1.0/24")141 event.addresponse(u"That's an invalid address. Try something like 192.168.1.0/24")
138 else:142 else:
139 for line in output.splitlines():143 for line in output.splitlines():
140 if line.strip():144 if line.strip():
141 event.addresponse(line)145 event.addresponse(u'%s', line)
142 else:146 else:
143 error = unicode_output(error.strip())147 error = unicode_output(error.strip())
144 event.addresponse(error.replace('\n', ' '))148 event.addresponse(u'%s', error.replace(u'\n', u' '))
145149
146# vi: set et sta sw=4 ts=4:150# vi: set et sta sw=4 ts=4:
147151
=== modified file 'ibid/plugins/rfc.py'
--- ibid/plugins/rfc.py 2009-03-05 12:23:21 +0000
+++ ibid/plugins/rfc.py 2009-03-08 13:16:28 +0000
@@ -157,9 +157,12 @@
157157
158 number = int(number)158 number = int(number)
159 if number in rfcs:159 if number in rfcs:
160 event.addresponse(u"%s http://www.rfc-editor.org/rfc/rfc%i.txt " % (rfcs[number].record, number))160 event.addresponse(u"%(record)s http://www.rfc-editor.org/rfc/rfc%(number)i.txt", {
161 'record': rfcs[number].record,
162 'number': number,
163 })
161 else:164 else:
162 event.addresponse(u"Sorry, no such RFC.")165 event.addresponse(u"Sorry, no such RFC")
163166
164 @match(r'^rfc\s+(?:for\s+)?(.+)$')167 @match(r'^rfc\s+(?:for\s+)?(.+)$')
165 def search(self, event, terms):168 def search(self, event, terms):
@@ -188,14 +191,16 @@
188 pool.reverse()191 pool.reverse()
189192
190 if pool:193 if pool:
191 response = u"Found %i matching RFC%s. Listing %i: " % (len(pool), len(pool) > 1 and u"s" or u"", min(len(pool), 5))
192 results = []194 results = []
193 for result in pool[:5]:195 for result in pool[:5]:
194 result.parse()196 result.parse()
195 results.append("%04i: %s" % (result.number, result.summary))197 results.append("%04i: %s" % (result.number, result.summary))
196 response += u", ".join(results)198 event.addresponse(u'Found %(found)i matching RFCs. Listing %(listing)i: %(results)', {
197 event.addresponse(response)199 'found': len(pool),
200 'listing': min(len(pool), 5),
201 'results': u', '.join(results),
202 })
198 else:203 else:
199 event.addresponse(u"Sorry, can't find anything.")204 event.addresponse(u"Sorry, can't find anything")
200205
201# vi: set et sta sw=4 ts=4:206# vi: set et sta sw=4 ts=4:
202207
=== modified file 'ibid/plugins/roshambo.py'
--- ibid/plugins/roshambo.py 2009-03-02 09:21:35 +0000
+++ ibid/plugins/roshambo.py 2009-03-08 13:16:28 +0000
@@ -17,12 +17,12 @@
17 bchoice = randint(0, 2)17 bchoice = randint(0, 2)
18 18
19 if uchoice == bchoice:19 if uchoice == bchoice:
20 reply = u'We drew! I also chose %s' % choices[bchoice]20 reply = u'We drew! I also chose %s'
21 elif (uchoice + 1) % 3 == bchoice:21 elif (uchoice + 1) % 3 == bchoice:
22 reply = u'You win! I chose %s :-(' % choices[bchoice]22 reply = u'You win! I chose %s :-('
23 else:23 else:
24 reply = u'I win! I chose %s' % choices[bchoice]24 reply = u'I win! I chose %s'
25 25
26 event.addresponse(reply)26 event.addresponse(reply, choices[bchoice])
2727
28# vi: set et sta sw=4 ts=4:28# vi: set et sta sw=4 ts=4:
2929
=== modified file 'ibid/plugins/seen.py'
--- ibid/plugins/seen.py 2009-03-02 09:21:35 +0000
+++ ibid/plugins/seen.py 2009-03-08 13:16:28 +0000
@@ -82,7 +82,7 @@
82 account = session.query(Account).filter_by(username=who).first()82 account = session.query(Account).filter_by(username=who).first()
8383
84 if not identity and not account:84 if not identity and not account:
85 event.addresponse(u"I don't know who %s is" % who)85 event.addresponse(u"I don't know who %s is", who)
86 return86 return
8787
88 messages = []88 messages = []
@@ -102,26 +102,26 @@
102 states.append(sighting)102 states.append(sighting)
103103
104 if len(messages) == 0 and len(states) == 0:104 if len(messages) == 0 and len(states) == 0:
105 event.addresponse(u"I haven't seen %s" % who)105 event.addresponse(u"I haven't seen %s", who)
106 return106 return
107107
108 messages.sort(key=lambda x: x.time, reverse=True)108 messages.sort(key=lambda x: x.time, reverse=True)
109 states.sort(key=lambda x: x.time, reverse=True)109 states.sort(key=lambda x: x.time, reverse=True)
110110
111 reply = ''111 reply = u''
112 if len(messages) > 0:112 if len(messages) > 0:
113 sighting = messages[0]113 sighting = messages[0]
114 delta = datetime.now() - sighting.time114 delta = datetime.now() - sighting.time
115 reply = u"%s was last seen %s ago in %s on %s" % (who, ago(delta), sighting.channel or 'private', sighting.identity.source)115 reply = u"%s was last seen %s ago in %s on %s" % (who, ago(delta), sighting.channel or 'private', sighting.identity.source)
116 reply = u'%s [%s]' % (reply, sighting.time.strftime(self.datetime_format))116 reply += u' [%s]' % sighting.time.strftime(self.datetime_format)
117117
118 if len(states) > 0:118 if len(states) > 0:
119 sighting = states[0]119 sighting = states[0]
120 if reply:120 if reply:
121 reply = reply + u', and'121 reply += u', and'
122 else:122 else:
123 reply = who123 reply = who
124 reply = reply + u" has been %s on %s since %s" % (sighting.value, sighting.identity.source, sighting.time.strftime(self.datetime_format))124 reply += u" has been %s on %s since %s" % (sighting.value, sighting.identity.source, sighting.time.strftime(self.datetime_format))
125125
126 event.addresponse(reply)126 event.addresponse(reply)
127 session.close()127 session.close()
128128
=== modified file 'ibid/plugins/sources.py'
--- ibid/plugins/sources.py 2009-03-01 23:01:30 +0000
+++ ibid/plugins/sources.py 2009-03-08 13:16:28 +0000
@@ -15,26 +15,26 @@
15 def connect(self, event, source):15 def connect(self, event, source):
1616
17 if ibid.sources[source.lower()].connect():17 if ibid.sources[source.lower()].connect():
18 event.addresponse(u'Connecting to %s' % source)18 event.addresponse(u'Connecting to %s', source)
19 else:19 else:
20 event.addresponse(u"I couldn't connect to %s" % source)20 event.addresponse(u"I couldn't connect to %s", source)
2121
22 @match(r'^disconnect\s+(?:from\s+)?(\S+)$')22 @match(r'^disconnect\s+(?:from\s+)?(\S+)$')
23 @authorise23 @authorise
24 def disconnect(self, event, source):24 def disconnect(self, event, source):
2525
26 if ibid.sources[source.lower()].disconnect():26 if ibid.sources[source.lower()].disconnect():
27 event.addresponse(u'Disconnecting from %s' % source)27 event.addresponse(u'Disconnecting from %s', source)
28 else:28 else:
29 event.addresponse(u"I couldn't disconnect from %s" % source)29 event.addresponse(u"I couldn't disconnect from %s", source)
3030
31 @match(r'^(?:re)?load\s+(\S+)\s+source$')31 @match(r'^(?:re)?load\s+(\S+)\s+source$')
32 @authorise32 @authorise
33 def load(self, event, source):33 def load(self, event, source):
34 if ibid.reloader.load_source(source, ibid.service):34 if ibid.reloader.load_source(source, ibid.service):
35 event.addresponse(u"%s source loaded" % source)35 event.addresponse(u"%s source loaded", source)
36 else:36 else:
37 event.addresponse(u"Couldn't load %s source" % source)37 event.addresponse(u"Couldn't load %s source", source)
3838
39class Info(Processor):39class Info(Processor):
40 u"""(sources|list configured sources)"""40 u"""(sources|list configured sources)"""
@@ -45,11 +45,11 @@
45 sources = []45 sources = []
46 for name, source in ibid.sources.items():46 for name, source in ibid.sources.items():
47 url = source.url()47 url = source.url()
48 sources.append(url and '%s (%s)' % (name, url) or name)48 sources.append(url and u'%s (%s)' % (name, url) or name)
49 event.addresponse(u', '.join(sources))49 event.addresponse(u'Sources: %s', u', '.join(sorted(sources)))
5050
51 @match(r'^list\s+configured\s+sources$')51 @match(r'^list\s+configured\s+sources$')
52 def listall(self, event):52 def listall(self, event):
53 event.addresponse(', '.join(ibid.config.sources.keys()))53 event.addresponse(u'Configured sources: %s', u', '.join(sorted(ibid.config.sources.keys())))
5454
55# vi: set et sta sw=4 ts=4:55# vi: set et sta sw=4 ts=4:
5656
=== modified file 'ibid/plugins/test.py'
--- ibid/plugins/test.py 2009-03-01 14:29:51 +0000
+++ ibid/plugins/test.py 2009-03-08 13:16:28 +0000
@@ -8,7 +8,7 @@
8 @match(r'^delay\s+(\d+\.?\d*)$')8 @match(r'^delay\s+(\d+\.?\d*)$')
9 def handler(self, event, delay):9 def handler(self, event, delay):
10 sleep(float(delay))10 sleep(float(delay))
11 event.addresponse('Done')11 event.addresponse(True)
1212
13class Authorise(Processor):13class Authorise(Processor):
1414
@@ -23,14 +23,14 @@
2323
24 @match(r'^email\s+(.+)$')24 @match(r'^email\s+(.+)$')
25 def email(self, event, address):25 def email(self, event, address):
26 event.addresponse({'reply': 'Test message', 'source': 'email', 'target': unicode(address)})26 event.addresponse({'reply': u'Test message', 'source': 'email', 'target': unicode(address)})
27 event.addresponse(u"I've emailed %s" % address)27 event.addresponse(u"I've emailed %s", address)
2828
29class Except(Processor):29class Except(Processor):
3030
31 @match(r'^raise\s+exception$')31 @match(r'^raise\s+exception$')
32 def handler(self, event):32 def handler(self, event):
33 event.addresponse("I'll except in a moment")33 event.addresponse(u"I'll except in a moment")
34 raise Exception("Ow, that hurt.")34 raise Exception("Ow, that hurt.")
3535
36# vi: set et sta sw=4 ts=4:36# vi: set et sta sw=4 ts=4:
3737
=== modified file 'ibid/plugins/tools.py'
--- ibid/plugins/tools.py 2009-03-02 09:38:47 +0000
+++ ibid/plugins/tools.py 2009-03-08 13:16:28 +0000
@@ -25,11 +25,11 @@
25 @match('^rand(?:om)?(?:\s+(\d+)(?:\s+(\d+))?)?$')25 @match('^rand(?:om)?(?:\s+(\d+)(?:\s+(\d+))?)?$')
26 def random(self, event, begin, end):26 def random(self, event, begin, end):
27 if not begin and not end:27 if not begin and not end:
28 event.addresponse(unicode(random()))28 event.addresponse(u'I always liked %f', random())
29 else:29 else:
30 begin = int(begin)30 begin = int(begin)
31 end = end and int(end) or 031 end = end and int(end) or 0
32 event.addresponse(unicode(randint(min(begin,end), max(begin,end))))32 event.addresponse(u'I always liked %i', randint(min(begin,end), max(begin,end)))
3333
34help['units'] = 'Converts values between various units.'34help['units'] = 'Converts values between various units.'
35class Units(Processor):35class Units(Processor):
@@ -91,13 +91,20 @@
91 result = output.splitlines()[0].strip()91 result = output.splitlines()[0].strip()
9292
93 if code == 0:93 if code == 0:
94 event.addresponse(result)94 event.addresponse(u'%s', result)
95 elif code == 1:95 elif code == 1:
96 if result == "conformability error":96 if result == "conformability error":
97 event.addresponse(u"I don't think %s can be converted to %s." % (frm, to))97 event.addresponse(u"I don't think %(from)s can be converted to %(to)s", {
98 'from': frm,
99 'to': to,
100 })
98 elif result.startswith("conformability error"):101 elif result.startswith("conformability error"):
99 event.addresponse(u"I don't think %s can be converted to %s: %s" % (frm, to, result.split(":", 1)[1]))102 event.addresponse(u"I don't think %(from)s can be converted to %(to)s: %(error)s", {
103 'from': frm,
104 'to': to,
105 'error': result.split(":", 1)[1],
106 })
100 else:107 else:
101 event.addresponse(u"I can't do that: %s" % result)108 event.addresponse(u"I can't do that: %s", result)
102109
103# vi: set et sta sw=4 ts=4:110# vi: set et sta sw=4 ts=4:
104111
=== modified file 'ibid/plugins/trac.py'
--- ibid/plugins/trac.py 2009-03-06 13:50:19 +0000
+++ ibid/plugins/trac.py 2009-03-08 13:16:28 +0000
@@ -77,7 +77,19 @@
77 ticket = self.get_ticket(int(number))77 ticket = self.get_ticket(int(number))
7878
79 if ticket:79 if ticket:
80 event.addresponse(u'Ticket %s (%s %s %s in %s for %s) reported %s ago assigned to %s: "%s" %sticket/%s' % (ticket.id, ticket.status, ticket.priority, ticket.type, ticket.component, ticket.milestone, ago(datetime.now() - datetime.fromtimestamp(ticket.time), 2), ticket.owner, ticket.summary, self.url, ticket.id))80 event.addresponse(u'Ticket %(id)s (%(status)s %(priority)s %(type)s in %(component)s for %(milestone)s) '
81 u'reported %(ago)s ago assigned to %(owner)s: "%(summary)s" %(url)sticket/%(id)s', {
82 'id': ticket.id,
83 'status': ticket.status,
84 'priority': ticket.priority,
85 'type': ticket.type,
86 'component': ticket.component,
87 'milestone': ticket.milestone,
88 'ago': ago(datetime.now() - datetime.fromtimestamp(ticket.time), 2),
89 'owner': ticket.owner,
90 'summary': ticket.summary,
91 'url': self.url,
92 })
81 else:93 else:
82 event.addresponse(u"No such ticket")94 event.addresponse(u"No such ticket")
8395
@@ -108,7 +120,7 @@
108 tickets = query.order_by(Ticket.id).all()120 tickets = query.order_by(Ticket.id).all()
109121
110 if len(tickets) > 0:122 if len(tickets) > 0:
111 event.addresponse(', '.join(['%s (%s): "%s"' % (ticket.id, ticket.owner, ticket.summary) for ticket in tickets]))123 event.addresponse(u'%s', u', '.join(['%s (%s): "%s"' % (ticket.id, ticket.owner, ticket.summary) for ticket in tickets]))
112 else:124 else:
113 event.addresponse(u"No tickets found")125 event.addresponse(u"No tickets found")
114126
115127
=== modified file 'ibid/plugins/url.py'
--- ibid/plugins/url.py 2009-03-01 23:01:30 +0000
+++ ibid/plugins/url.py 2009-03-08 13:16:28 +0000
@@ -56,7 +56,7 @@
56 shortened = f.read()56 shortened = f.read()
57 f.close()57 f.close()
5858
59 event.addresponse(unicode(shortened))59 event.addresponse(u'That reduces to: %s', shortened)
6060
61class NullRedirect(HTTPRedirectHandler):61class NullRedirect(HTTPRedirectHandler):
6262
@@ -83,7 +83,7 @@
83 f = opener.open(url)83 f = opener.open(url)
84 except HTTPError, e:84 except HTTPError, e:
85 if e.code in (301, 302, 303, 307):85 if e.code in (301, 302, 303, 307):
86 event.addresponse(unicode(e.hdrs['location']))86 event.addresponse(u'That expands to: %s', e.hdrs['location'])
87 return87 return
8888
89 f.close()89 f.close()

Subscribers

People subscribed via source and target branches