Merge lp:~stefanor/ibid/translation-334764 into lp:~ibid-core/ibid/old-trunk-pack-0.92
- translation-334764
- Merge into 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 |
Related bugs: | |
Related blueprints: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jonathan Hitchcock | Approve | ||
Michael Gorven | Approve | ||
Review via email: mp+4287@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Stefano Rivera (stefanor) wrote : | # |
Revision history for this message
Michael Gorven (mgorven) : | # |
review:
Approve
- 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
1 | === modified file 'ibid/event.py' | |||
2 | --- ibid/event.py 2009-02-23 20:29:44 +0000 | |||
3 | +++ ibid/event.py 2009-03-08 10:57:45 +0000 | |||
4 | @@ -14,8 +14,11 @@ | |||
5 | 14 | def __setattr__(self, name, value): | 14 | def __setattr__(self, name, value): |
6 | 15 | self[name] = value | 15 | self[name] = value |
7 | 16 | 16 | ||
10 | 17 | def addresponse(self, response, processed=True): | 17 | def addresponse(self, response, params={}, processed=True): |
11 | 18 | self.responses.append(response) | 18 | if isinstance(response, unicode): |
12 | 19 | self.responses.append(response % params) | ||
13 | 20 | else: | ||
14 | 21 | self.responses.append(response) | ||
15 | 19 | 22 | ||
16 | 20 | if processed: | 23 | if processed: |
17 | 21 | self.processed = True | 24 | self.processed = True |
18 | 22 | 25 | ||
19 | === modified file 'ibid/plugins/admin.py' | |||
20 | --- ibid/plugins/admin.py 2009-03-02 09:21:35 +0000 | |||
21 | +++ ibid/plugins/admin.py 2009-03-08 13:16:28 +0000 | |||
22 | @@ -17,7 +17,7 @@ | |||
23 | 17 | if processor.name not in plugins: | 17 | if processor.name not in plugins: |
24 | 18 | plugins.append(processor.name) | 18 | plugins.append(processor.name) |
25 | 19 | 19 | ||
27 | 20 | event.addresponse(', '.join(plugins)) | 20 | event.addresponse(u'Plugins: %s', u', '.join(sorted(plugins))) |
28 | 21 | 21 | ||
29 | 22 | help['core'] = u'Reloads core modules.' | 22 | help['core'] = u'Reloads core modules.' |
30 | 23 | class ReloadCoreModules(Processor): | 23 | class ReloadCoreModules(Processor): |
31 | @@ -36,7 +36,7 @@ | |||
32 | 36 | else: | 36 | else: |
33 | 37 | result = getattr(ibid.reloader, 'reload_%s' % module)() | 37 | result = getattr(ibid.reloader, 'reload_%s' % module)() |
34 | 38 | 38 | ||
36 | 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) |
37 | 40 | 40 | ||
38 | 41 | class LoadModules(Processor): | 41 | class LoadModules(Processor): |
39 | 42 | u"""(load|unload|reload) <plugin|processor>""" | 42 | u"""(load|unload|reload) <plugin|processor>""" |
40 | @@ -49,13 +49,13 @@ | |||
41 | 49 | def load(self, event, plugin): | 49 | def load(self, event, plugin): |
42 | 50 | result = ibid.reloader.unload_processor(plugin) | 50 | result = ibid.reloader.unload_processor(plugin) |
43 | 51 | result = ibid.reloader.load_processor(plugin) | 51 | result = ibid.reloader.load_processor(plugin) |
45 | 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) |
46 | 53 | 53 | ||
47 | 54 | @match(r'^unload\s+(\S+)$') | 54 | @match(r'^unload\s+(\S+)$') |
48 | 55 | @authorise | 55 | @authorise |
49 | 56 | def unload(self, event, plugin): | 56 | def unload(self, event, plugin): |
50 | 57 | result = ibid.reloader.unload_processor(plugin) | 57 | result = ibid.reloader.unload_processor(plugin) |
52 | 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) |
53 | 59 | 59 | ||
54 | 60 | help['die'] = u'Terminates the bot' | 60 | help['die'] = u'Terminates the bot' |
55 | 61 | class Die(Processor): | 61 | class Die(Processor): |
56 | 62 | 62 | ||
57 | === modified file 'ibid/plugins/apt.py' | |||
58 | --- ibid/plugins/apt.py 2009-03-02 09:38:47 +0000 | |||
59 | +++ ibid/plugins/apt.py 2009-03-08 13:16:28 +0000 | |||
60 | @@ -29,7 +29,7 @@ | |||
61 | 29 | 29 | ||
62 | 30 | for word in self.bad_search_strings: | 30 | for word in self.bad_search_strings: |
63 | 31 | if word in term: | 31 | if word in term: |
65 | 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") |
66 | 33 | return False | 33 | return False |
67 | 34 | 34 | ||
68 | 35 | if term.strip().startswith("-"): | 35 | if term.strip().startswith("-"): |
69 | @@ -52,14 +52,17 @@ | |||
70 | 52 | if output: | 52 | if output: |
71 | 53 | output = unicode_output(output.strip()) | 53 | output = unicode_output(output.strip()) |
72 | 54 | output = [line.strip() for line in output.splitlines()] | 54 | output = [line.strip() for line in output.splitlines()] |
74 | 55 | event.addresponse(u"Found %i packages: %s" % (len(output), u', '.join(output))) | 55 | event.addresponse(u'Found %(num)i packages: %(names)s', { |
75 | 56 | 'num': len(output), | ||
76 | 57 | 'names': u', '.join(output), | ||
77 | 58 | }) | ||
78 | 56 | else: | 59 | else: |
79 | 57 | event.addresponse(u'No packages found') | 60 | event.addresponse(u'No packages found') |
80 | 58 | else: | 61 | else: |
81 | 59 | error = unicode_output(error.strip()) | 62 | error = unicode_output(error.strip()) |
82 | 60 | if error.startswith(u"E: "): | 63 | if error.startswith(u"E: "): |
83 | 61 | error = error[3:] | 64 | error = error[3:] |
85 | 62 | event.addresponse(u"Couldn't search: %s" % error) | 65 | event.addresponse(u"Couldn't search: %s", error) |
86 | 63 | 66 | ||
87 | 64 | @match(r'(?:apt|aptitude|apt-get)\s+show\s+(.+)$') | 67 | @match(r'(?:apt|aptitude|apt-get)\s+show\s+(.+)$') |
88 | 65 | def show(self, event, term): | 68 | def show(self, event, term): |
89 | @@ -73,27 +76,30 @@ | |||
90 | 73 | 76 | ||
91 | 74 | if code == 0: | 77 | if code == 0: |
92 | 75 | description = None | 78 | description = None |
93 | 79 | provided = None | ||
94 | 76 | output = unicode_output(output) | 80 | output = unicode_output(output) |
95 | 77 | for line in output.splitlines(): | 81 | for line in output.splitlines(): |
96 | 78 | if not description: | 82 | if not description: |
97 | 79 | if line.startswith(u'Description:'): | 83 | if line.startswith(u'Description:'): |
98 | 80 | description = u'%s:' % line.split(None, 1)[1] | 84 | description = u'%s:' % line.split(None, 1)[1] |
99 | 81 | elif line.startswith(u'Provided by:'): | 85 | elif line.startswith(u'Provided by:'): |
101 | 82 | description = u'Virtual package provided by %s' % line.split(None, 2)[2] | 86 | provided = line.split(None, 2)[2] |
102 | 83 | elif line != "": | 87 | elif line != "": |
103 | 84 | description += u' ' + line.strip() | 88 | description += u' ' + line.strip() |
104 | 85 | else: | 89 | else: |
105 | 86 | # More than one package listed | 90 | # More than one package listed |
106 | 87 | break | 91 | break |
109 | 88 | if description: | 92 | if provided: |
110 | 89 | event.addresponse(description) | 93 | event.addresponse(u'Virtual package provided by %s', provided) |
111 | 94 | elif description: | ||
112 | 95 | event.addresponse(u'%s', description) | ||
113 | 90 | else: | 96 | else: |
114 | 91 | raise Exception("We couldn't successfully parse aptitude's output") | 97 | raise Exception("We couldn't successfully parse aptitude's output") |
115 | 92 | else: | 98 | else: |
116 | 93 | error = unicode_output(error.strip()) | 99 | error = unicode_output(error.strip()) |
117 | 94 | if error.startswith(u"E: "): | 100 | if error.startswith(u"E: "): |
118 | 95 | error = error[3:] | 101 | error = error[3:] |
120 | 96 | event.addresponse(u"Couldn't find package: %s" % error) | 102 | event.addresponse(u"Couldn't find package: %s", error) |
121 | 97 | 103 | ||
122 | 98 | help['apt-file'] = u'Searches for packages containing the specified file' | 104 | help['apt-file'] = u'Searches for packages containing the specified file' |
123 | 99 | class AptFile(Processor): | 105 | class AptFile(Processor): |
124 | @@ -116,13 +122,16 @@ | |||
125 | 116 | if output: | 122 | if output: |
126 | 117 | output = unicode_output(output.strip()) | 123 | output = unicode_output(output.strip()) |
127 | 118 | output = [line.split(u':')[0] for line in output.splitlines()] | 124 | output = [line.split(u':')[0] for line in output.splitlines()] |
129 | 119 | event.addresponse(u"Found %i packages: %s" % (len(output), u', '.join(output))) | 125 | event.addresponse(u'Found %(num)i packages: %(names)s', { |
130 | 126 | 'num': len(output), | ||
131 | 127 | 'names': u', '.join(output), | ||
132 | 128 | }) | ||
133 | 120 | else: | 129 | else: |
135 | 121 | event.addresponse(u'No packages found.') | 130 | event.addresponse(u'No packages found') |
136 | 122 | else: | 131 | else: |
137 | 123 | error = unicode_output(error.strip()) | 132 | error = unicode_output(error.strip()) |
138 | 124 | if u"The cache directory is empty." in error: | 133 | if u"The cache directory is empty." in error: |
140 | 125 | event.addresponse(u'Search error: apt-file cache empty.') | 134 | event.addresponse(u'Search error: apt-file cache empty') |
141 | 126 | else: | 135 | else: |
142 | 127 | event.addresponse(u'Search error') | 136 | event.addresponse(u'Search error') |
143 | 128 | raise Exception("apt-file: %s" % error) | 137 | raise Exception("apt-file: %s" % error) |
144 | 129 | 138 | ||
145 | === modified file 'ibid/plugins/auth.py' | |||
146 | --- ibid/plugins/auth.py 2009-03-01 23:01:30 +0000 | |||
147 | +++ ibid/plugins/auth.py 2009-03-08 13:16:28 +0000 | |||
148 | @@ -36,7 +36,7 @@ | |||
149 | 36 | return | 36 | return |
150 | 37 | account = session.query(Account).filter_by(username=user).first() | 37 | account = session.query(Account).filter_by(username=user).first() |
151 | 38 | if not account: | 38 | if not account: |
153 | 39 | event.addresponse(u"I don't know who %s is" % user) | 39 | event.addresponse(u"I don't know who %s is", user) |
154 | 40 | session.close() | 40 | session.close() |
155 | 41 | return | 41 | return |
156 | 42 | 42 | ||
157 | @@ -55,7 +55,7 @@ | |||
158 | 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) |
159 | 56 | session.close() | 56 | session.close() |
160 | 57 | 57 | ||
162 | 58 | event.addresponse(u'Okay') | 58 | event.addresponse(True) |
163 | 59 | 59 | ||
164 | 60 | permission_values = {'no': '-', 'yes': '+', 'auth': ''} | 60 | permission_values = {'no': '-', 'yes': '+', 'auth': ''} |
165 | 61 | class Permissions(Processor): | 61 | class Permissions(Processor): |
166 | @@ -73,7 +73,7 @@ | |||
167 | 73 | session = ibid.databases.ibid() | 73 | session = ibid.databases.ibid() |
168 | 74 | account = session.query(Account).filter_by(username=username).first() | 74 | account = session.query(Account).filter_by(username=username).first() |
169 | 75 | if not account: | 75 | if not account: |
171 | 76 | event.addresponse(u"I don't know who %s is" % username) | 76 | event.addresponse(u"I don't know who %s is", username) |
172 | 77 | session.close() | 77 | session.close() |
173 | 78 | return | 78 | return |
174 | 79 | 79 | ||
175 | @@ -82,7 +82,7 @@ | |||
176 | 82 | if permission: | 82 | if permission: |
177 | 83 | session.delete(permission) | 83 | session.delete(permission) |
178 | 84 | else: | 84 | else: |
180 | 85 | event.addresponse(u"%s doesn't have that permission anyway" % username) | 85 | event.addresponse(u"%s doesn't have that permission anyway", username) |
181 | 86 | return | 86 | return |
182 | 87 | 87 | ||
183 | 88 | else: | 88 | else: |
184 | @@ -97,7 +97,11 @@ | |||
185 | 97 | value = 'yes' | 97 | value = 'yes' |
186 | 98 | 98 | ||
187 | 99 | if permission.value == value: | 99 | if permission.value == value: |
189 | 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', { |
190 | 101 | 'permission': name, | ||
191 | 102 | 'user': username, | ||
192 | 103 | 'value': value, | ||
193 | 104 | }) | ||
194 | 101 | return | 105 | return |
195 | 102 | 106 | ||
196 | 103 | permission.value = value | 107 | permission.value = value |
197 | @@ -122,10 +126,11 @@ | |||
198 | 122 | return | 126 | return |
199 | 123 | account = session.query(Account).filter_by(username=username).first() | 127 | account = session.query(Account).filter_by(username=username).first() |
200 | 124 | if not account: | 128 | if not account: |
202 | 125 | event.addresponse(u"I don't know who %s is" % username) | 129 | event.addresponse(u"I don't know who %s is", username) |
203 | 126 | return | 130 | return |
204 | 127 | 131 | ||
206 | 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) |
207 | 133 | event.addresponse(u'Permissions: %s', u', '.join(permissions)) | ||
208 | 129 | 134 | ||
209 | 130 | @match(r'^list\s+permissions$') | 135 | @match(r'^list\s+permissions$') |
210 | 131 | def list_permissions(self, event): | 136 | def list_permissions(self, event): |
211 | @@ -138,7 +143,7 @@ | |||
212 | 138 | if permission not in permissions: | 143 | if permission not in permissions: |
213 | 139 | permissions.append(permission) | 144 | permissions.append(permission) |
214 | 140 | 145 | ||
216 | 141 | event.addresponse(', '.join(permissions)) | 146 | event.addresponse(u'Permissions: %s', u', '.join(sorted(permissions))) |
217 | 142 | 147 | ||
218 | 143 | class Auth(Processor): | 148 | class Auth(Processor): |
219 | 144 | u"""auth <credential>""" | 149 | u"""auth <credential>""" |
220 | 145 | 150 | ||
221 | === modified file 'ibid/plugins/basic.py' | |||
222 | --- ibid/plugins/basic.py 2009-03-02 09:21:35 +0000 | |||
223 | +++ ibid/plugins/basic.py 2009-03-08 13:16:28 +0000 | |||
224 | @@ -64,6 +64,6 @@ | |||
225 | 64 | 64 | ||
226 | 65 | @match(r'^(?:choose|choice|pick)\s+(.+)$') | 65 | @match(r'^(?:choose|choice|pick)\s+(.+)$') |
227 | 66 | def choose(self, event, choices): | 66 | def choose(self, event, choices): |
229 | 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))) |
230 | 68 | 68 | ||
231 | 69 | # vi: set et sta sw=4 ts=4: | 69 | # vi: set et sta sw=4 ts=4: |
232 | 70 | 70 | ||
233 | === modified file 'ibid/plugins/bzr.py' | |||
234 | --- ibid/plugins/bzr.py 2009-03-02 09:21:35 +0000 | |||
235 | +++ ibid/plugins/bzr.py 2009-03-08 13:16:28 +0000 | |||
236 | @@ -66,7 +66,8 @@ | |||
237 | 66 | 66 | ||
238 | 67 | @match(r'^(?:repos|repositories)$') | 67 | @match(r'^(?:repos|repositories)$') |
239 | 68 | def handle_repositories(self, event): | 68 | def handle_repositories(self, event): |
241 | 69 | event.addresponse(', '.join(self.branches.keys())) | 69 | repositories = self.branches.keys() |
242 | 70 | event.addresponse(u'I know about: %s', u', '.join(sorted(repositories))) | ||
243 | 70 | 71 | ||
244 | 71 | def remote_committed(self, repository, start, end=None): | 72 | def remote_committed(self, repository, start, end=None): |
245 | 72 | commits = self.get_commits(repository, start, end) | 73 | commits = self.get_commits(repository, start, end) |
246 | @@ -83,7 +84,7 @@ | |||
247 | 83 | 84 | ||
248 | 84 | for commit in commits: | 85 | for commit in commits: |
249 | 85 | if commit: | 86 | if commit: |
251 | 86 | event.addresponse(unicode(commit.strip())) | 87 | event.addresponse(u'%s', commit.strip()) |
252 | 87 | 88 | ||
253 | 88 | def get_commits(self, repository, start, end=None, full=None): | 89 | def get_commits(self, repository, start, end=None, full=None): |
254 | 89 | branch = None | 90 | branch = None |
255 | 90 | 91 | ||
256 | === modified file 'ibid/plugins/config.py' | |||
257 | --- ibid/plugins/config.py 2009-03-02 09:21:35 +0000 | |||
258 | +++ ibid/plugins/config.py 2009-03-08 13:16:28 +0000 | |||
259 | @@ -24,8 +24,8 @@ | |||
260 | 24 | ibid.config.reload() | 24 | ibid.config.reload() |
261 | 25 | ibid.config.merge(FileConfig(join(ibid.options['base'], 'local.ini'))) | 25 | ibid.config.merge(FileConfig(join(ibid.options['base'], 'local.ini'))) |
262 | 26 | ibid.reloader.reload_config() | 26 | ibid.reloader.reload_config() |
265 | 27 | event.addresponse(u"Configuration reread") | 27 | event.addresponse(u'Configuration reread') |
266 | 28 | log.info(u"Reread configuration file") | 28 | log.info(u'Reread configuration file') |
267 | 29 | 29 | ||
268 | 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.*?)$') |
269 | 31 | @authorise | 31 | @authorise |
270 | @@ -51,6 +51,6 @@ | |||
271 | 51 | event.addresponse(u'No such option') | 51 | event.addresponse(u'No such option') |
272 | 52 | return | 52 | return |
273 | 53 | config = config[part] | 53 | config = config[part] |
275 | 54 | event.addresponse(unicode(config)) | 54 | event.addresponse(u'%s', config) |
276 | 55 | 55 | ||
277 | 56 | # vi: set et sta sw=4 ts=4: | 56 | # vi: set et sta sw=4 ts=4: |
278 | 57 | 57 | ||
279 | === modified file 'ibid/plugins/core.py' | |||
280 | --- ibid/plugins/core.py 2009-03-02 09:21:35 +0000 | |||
281 | +++ ibid/plugins/core.py 2009-03-08 13:16:28 +0000 | |||
282 | @@ -116,7 +116,7 @@ | |||
283 | 116 | 116 | ||
284 | 117 | priority = 950 | 117 | priority = 950 |
285 | 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?')) |
287 | 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")) |
288 | 120 | 120 | ||
289 | 121 | @handler | 121 | @handler |
290 | 122 | def complain(self, event): | 122 | def complain(self, event): |
291 | @@ -141,7 +141,7 @@ | |||
292 | 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]) |
293 | 142 | if len(self.messages[event.identity]) > self.limit_messages: | 142 | if len(self.messages[event.identity]) > self.limit_messages: |
294 | 143 | if event.public: | 143 | if event.public: |
296 | 144 | event.addresponse({'reply': u"Geez, give me some time to think!"}) | 144 | event.addresponse({'reply': u'Geez, give me some time to think!'}) |
297 | 145 | else: | 145 | else: |
298 | 146 | event.processed = True | 146 | event.processed = True |
299 | 147 | 147 | ||
300 | @@ -159,6 +159,6 @@ | |||
301 | 159 | for value in object: | 159 | for value in object: |
302 | 160 | self.process(value) | 160 | self.process(value) |
303 | 161 | elif isinstance(object, str): | 161 | elif isinstance(object, str): |
305 | 162 | self.log.warning(u"Found a non-unicode string: %s" % object) | 162 | self.log.warning(u'Found a non-unicode string: %s' % object) |
306 | 163 | 163 | ||
307 | 164 | # vi: set et sta sw=4 ts=4: | 164 | # vi: set et sta sw=4 ts=4: |
308 | 165 | 165 | ||
309 | === modified file 'ibid/plugins/crypto.py' | |||
310 | --- ibid/plugins/crypto.py 2009-03-01 23:01:30 +0000 | |||
311 | +++ ibid/plugins/crypto.py 2009-03-08 13:16:28 +0000 | |||
312 | @@ -14,11 +14,11 @@ | |||
313 | 14 | 14 | ||
314 | 15 | @match(r'^(md5|sha1|sha224|sha256|sha384|sha512)\s+(.+?)$') | 15 | @match(r'^(md5|sha1|sha224|sha256|sha384|sha512)\s+(.+?)$') |
315 | 16 | def hash(self, event, hash, string): | 16 | def hash(self, event, hash, string): |
317 | 17 | event.addresponse(unicode(eval('hashlib.%s' % hash.lower())(string).hexdigest())) | 17 | event.addresponse(u'%s', eval('hashlib.%s' % hash.lower())(string).hexdigest()) |
318 | 18 | 18 | ||
319 | 19 | @match(r'^crypt\s+(.+)\s+(\S+)$') | 19 | @match(r'^crypt\s+(.+)\s+(\S+)$') |
320 | 20 | def handle_crypt(self, event, string, salt): | 20 | def handle_crypt(self, event, string, salt): |
322 | 21 | event.addresponse(unicode(crypt(string, salt))) | 21 | event.addresponse(u'%s', crypt(string, salt)) |
323 | 22 | 22 | ||
324 | 23 | help['base64'] = u'Encodes and decodes base 16, 32 and 64.' | 23 | help['base64'] = u'Encodes and decodes base 16, 32 and 64.' |
325 | 24 | class Base64(Processor): | 24 | class Base64(Processor): |
326 | @@ -27,7 +27,7 @@ | |||
327 | 27 | 27 | ||
328 | 28 | @match(r'^b(16|32|64)(enc|dec)(?:ode)?\s+(.+?)$') | 28 | @match(r'^b(16|32|64)(enc|dec)(?:ode)?\s+(.+?)$') |
329 | 29 | def base64(self, event, base, operation, string): | 29 | def base64(self, event, base, operation, string): |
331 | 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)) |
332 | 31 | 31 | ||
333 | 32 | help['rot13'] = u'Transforms a string with ROT13.' | 32 | help['rot13'] = u'Transforms a string with ROT13.' |
334 | 33 | class Rot13(Processor): | 33 | class Rot13(Processor): |
335 | @@ -36,6 +36,6 @@ | |||
336 | 36 | 36 | ||
337 | 37 | @match(r'^rot13\s+(.+)$') | 37 | @match(r'^rot13\s+(.+)$') |
338 | 38 | def rot13(self, event, string): | 38 | def rot13(self, event, string): |
340 | 39 | event.addresponse(unicode(string.encode('rot13'))) | 39 | event.addresponse(u'%s', string.encode('rot13')) |
341 | 40 | 40 | ||
342 | 41 | # vi: set et sta sw=4 ts=4: | 41 | # vi: set et sta sw=4 ts=4: |
343 | 42 | 42 | ||
344 | === modified file 'ibid/plugins/dict.py' | |||
345 | --- ibid/plugins/dict.py 2009-03-02 08:33:02 +0000 | |||
346 | +++ ibid/plugins/dict.py 2009-03-08 13:16:28 +0000 | |||
347 | @@ -22,32 +22,39 @@ | |||
348 | 22 | @match(r'^define\s+(.+?)(?:\s+using\s+(.+))?$') | 22 | @match(r'^define\s+(.+?)(?:\s+using\s+(.+))?$') |
349 | 23 | def define(self, event, word, dictionary): | 23 | def define(self, event, word, dictionary): |
350 | 24 | definitions = self.connection.define(dictionary or '*', word) | 24 | definitions = self.connection.define(dictionary or '*', word) |
352 | 25 | event.addresponse(u', '.join([d.getdefstr() for d in definitions])) | 25 | event.addresponse(u'%s', u', '.join([d.getdefstr() for d in definitions])) |
353 | 26 | 26 | ||
354 | 27 | @match(r'spell\s+(.+?)(?:\s+using\s+(.+))?$') | 27 | @match(r'spell\s+(.+?)(?:\s+using\s+(.+))?$') |
355 | 28 | def handle_spell(self, event, word, strategy): | 28 | def handle_spell(self, event, word, strategy): |
358 | 29 | suggestions = self.connection.match('*', strategy or 'soundex', word) | 29 | correct = self.connection.match('*', 'exact', word) |
359 | 30 | event.addresponse(u', '.join([d.getword() for d in suggestions])) | 30 | if correct: |
360 | 31 | event.addresponse(u'That seems correct. Carry on') | ||
361 | 32 | return | ||
362 | 33 | suggestions = self.connection.match('*', strategy or 'lev', word) | ||
363 | 34 | if suggestions: | ||
364 | 35 | event.addresponse(u'Suggestions: %s', u', '.join([d.getword() for d in suggestions])) | ||
365 | 36 | else: | ||
366 | 37 | event.addresponse(u"That doesn't seem correct, but I can't find anything to suggest") | ||
367 | 31 | 38 | ||
368 | 32 | @match(r'^dictionaries$') | 39 | @match(r'^dictionaries$') |
369 | 33 | def handle_dictionaries(self, event): | 40 | def handle_dictionaries(self, event): |
371 | 34 | event.addresponse(u', '.join(self.dictionaries.keys())) | 41 | event.addresponse(u'Dictionaries: %s', u', '.join(sorted(self.dictionaries.keys()))) |
372 | 35 | 42 | ||
373 | 36 | @match(r'^strater?gies$') | 43 | @match(r'^strater?gies$') |
374 | 37 | def handle_strategies(self, event): | 44 | def handle_strategies(self, event): |
376 | 38 | event.addresponse(u', '.join(self.strategies.keys())) | 45 | event.addresponse(u'Strategies: %s', u', '.join(sorted(self.strategies.keys()))) |
377 | 39 | 46 | ||
378 | 40 | @match(r'^dictionary\s+(.+?)$') | 47 | @match(r'^dictionary\s+(.+?)$') |
379 | 41 | def handle_dictionary(self, event, dictionary): | 48 | def handle_dictionary(self, event, dictionary): |
380 | 42 | if dictionary in self.dictionaries: | 49 | if dictionary in self.dictionaries: |
382 | 43 | event.addresponse(unicode(self.dictionaries[dictionary])) | 50 | event.addresponse(u'%s', self.dictionaries[dictionary]) |
383 | 44 | else: | 51 | else: |
384 | 45 | event.addresponse(u"I don't have that dictionary") | 52 | event.addresponse(u"I don't have that dictionary") |
385 | 46 | 53 | ||
386 | 47 | @match(r'^strater?gy\s+(.+?)$') | 54 | @match(r'^strater?gy\s+(.+?)$') |
387 | 48 | def handle_strategy(self, event, strategy): | 55 | def handle_strategy(self, event, strategy): |
388 | 49 | if strategy in self.strategies: | 56 | if strategy in self.strategies: |
390 | 50 | event.addresponse(unicode(self.strategies[strategy])) | 57 | event.addresponse(u'%s', self.strategies[strategy]) |
391 | 51 | else: | 58 | else: |
392 | 52 | event.addresponse(u"I don't have that strategy") | 59 | event.addresponse(u"I don't have that strategy") |
393 | 53 | 60 | ||
394 | 54 | 61 | ||
395 | === modified file 'ibid/plugins/eval.py' | |||
396 | --- ibid/plugins/eval.py 2009-03-05 16:33:12 +0000 | |||
397 | +++ ibid/plugins/eval.py 2009-03-08 13:16:28 +0000 | |||
398 | @@ -27,10 +27,10 @@ | |||
399 | 27 | exec('import sys', globals) | 27 | exec('import sys', globals) |
400 | 28 | exec('import re', globals) | 28 | exec('import re', globals) |
401 | 29 | exec('import time', globals) | 29 | exec('import time', globals) |
403 | 30 | result = unicode(eval(code, globals, {})) | 30 | result = eval(code, globals, {}) |
404 | 31 | except Exception, e: | 31 | except Exception, e: |
407 | 32 | result = unicode(e) | 32 | result = e |
408 | 33 | event.addresponse(result) | 33 | event.addresponse(u'%s', result) |
409 | 34 | 34 | ||
410 | 35 | class Perl(Processor): | 35 | class Perl(Processor): |
411 | 36 | u"""pl <code>""" | 36 | u"""pl <code>""" |
412 | @@ -46,7 +46,7 @@ | |||
413 | 46 | except Exception, e: | 46 | except Exception, e: |
414 | 47 | result = e | 47 | result = e |
415 | 48 | 48 | ||
417 | 49 | event.addresponse(unicode(result)) | 49 | event.addresponse(u'%s', result) |
418 | 50 | 50 | ||
419 | 51 | class Lua(Processor): | 51 | class Lua(Processor): |
420 | 52 | u"""lua <code>""" | 52 | u"""lua <code>""" |
421 | @@ -62,6 +62,6 @@ | |||
422 | 62 | except Exception, e: | 62 | except Exception, e: |
423 | 63 | result = e | 63 | result = e |
424 | 64 | 64 | ||
426 | 65 | event.addresponse(unicode(result)) | 65 | event.addresponse(u'%s', result) |
427 | 66 | 66 | ||
428 | 67 | # vi: set et sta sw=4 ts=4: | 67 | # vi: set et sta sw=4 ts=4: |
429 | 68 | 68 | ||
430 | === modified file 'ibid/plugins/factoid.py' | |||
431 | --- ibid/plugins/factoid.py 2009-03-01 23:01:30 +0000 | |||
432 | +++ ibid/plugins/factoid.py 2009-03-08 13:16:28 +0000 | |||
433 | @@ -96,7 +96,7 @@ | |||
434 | 96 | session = ibid.databases.ibid() | 96 | session = ibid.databases.ibid() |
435 | 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() |
436 | 98 | if factoid: | 98 | if factoid: |
438 | 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:]])) |
439 | 100 | 100 | ||
440 | 101 | session.close() | 101 | session.close() |
441 | 102 | 102 | ||
442 | @@ -120,7 +120,7 @@ | |||
443 | 120 | 120 | ||
444 | 121 | if (number or pattern): | 121 | if (number or pattern): |
445 | 122 | if len(factoids) > 1: | 122 | if len(factoids) > 1: |
447 | 123 | event.addresponse(u"Pattern matches multiple factoids, please be more specific") | 123 | event.addresponse(u'Pattern matches multiple factoids, please be more specific') |
448 | 124 | return | 124 | return |
449 | 125 | 125 | ||
450 | 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: |
451 | @@ -152,7 +152,7 @@ | |||
452 | 152 | session.close() | 152 | session.close() |
453 | 153 | event.addresponse(True) | 153 | event.addresponse(True) |
454 | 154 | else: | 154 | else: |
456 | 155 | event.addresponse(u"I didn't know about %s anyway" % name) | 155 | event.addresponse(u"I didn't know about %s anyway", name) |
457 | 156 | 156 | ||
458 | 157 | @match(r'^(.+)\s+is\s+the\s+same\s+as\s+(.+)$') | 157 | @match(r'^(.+)\s+is\s+the\s+same\s+as\s+(.+)$') |
459 | 158 | @authorise | 158 | @authorise |
460 | @@ -172,7 +172,7 @@ | |||
461 | 172 | event.addresponse(True) | 172 | event.addresponse(True) |
462 | 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']) |
463 | 174 | else: | 174 | else: |
465 | 175 | event.addresponse(u"I don't know about %s" % name) | 175 | event.addresponse(u"I don't know about %s", name) |
466 | 176 | 176 | ||
467 | 177 | class Search(Processor): | 177 | class Search(Processor): |
468 | 178 | u"""(search|scan) for <pattern> [from <start>]""" | 178 | u"""(search|scan) for <pattern> [from <start>]""" |
469 | @@ -196,7 +196,7 @@ | |||
470 | 196 | matches = query[start:start+limit] | 196 | matches = query[start:start+limit] |
471 | 197 | 197 | ||
472 | 198 | if matches: | 198 | if matches: |
474 | 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)) |
475 | 200 | else: | 200 | else: |
476 | 201 | event.addresponse(u"I couldn't find anything with that name") | 201 | event.addresponse(u"I couldn't find anything with that name") |
477 | 202 | 202 | ||
478 | @@ -264,7 +264,7 @@ | |||
479 | 264 | if count: | 264 | if count: |
480 | 265 | return {'reply': reply} | 265 | return {'reply': reply} |
481 | 266 | 266 | ||
483 | 267 | reply = '%s %s' % (fname.name.replace('_%', '$arg').replace('\\%', '%').replace('\\_', '_'), reply) | 267 | reply = u'%s %s' % (fname.name.replace('_%', '$arg').replace('\\%', '%').replace('\\_', '_'), reply) |
484 | 268 | return reply | 268 | return reply |
485 | 269 | 269 | ||
486 | 270 | class Set(Processor): | 270 | class Set(Processor): |
487 | @@ -294,7 +294,7 @@ | |||
488 | 294 | session.delete(fvalue) | 294 | session.delete(fvalue) |
489 | 295 | session.flush() | 295 | session.flush() |
490 | 296 | elif not addition: | 296 | elif not addition: |
492 | 297 | event.addresponse(u"I already know stuff about %s" % name) | 297 | event.addresponse(u'I already know stuff about %s', name) |
493 | 298 | return | 298 | return |
494 | 299 | else: | 299 | else: |
495 | 300 | factoid = Factoid() | 300 | factoid = Factoid() |
496 | 301 | 301 | ||
497 | === modified file 'ibid/plugins/feeds.py' | |||
498 | --- ibid/plugins/feeds.py 2009-03-01 23:01:30 +0000 | |||
499 | +++ ibid/plugins/feeds.py 2009-03-08 13:16:28 +0000 | |||
500 | @@ -58,7 +58,7 @@ | |||
501 | 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() |
502 | 59 | 59 | ||
503 | 60 | if feed: | 60 | if feed: |
505 | 61 | event.addresponse(u"I already have the %s feed" % name) | 61 | event.addresponse(u'I already have the %s feed', name) |
506 | 62 | else: | 62 | else: |
507 | 63 | feed = Feed(unicode(name), unicode(url), event.identity) | 63 | feed = Feed(unicode(name), unicode(url), event.identity) |
508 | 64 | 64 | ||
509 | @@ -68,7 +68,10 @@ | |||
510 | 68 | event.addresponse(True) | 68 | event.addresponse(True) |
511 | 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)) |
512 | 70 | else: | 70 | else: |
514 | 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', { |
515 | 72 | 'name': name, | ||
516 | 73 | 'url': url, | ||
517 | 74 | }) | ||
518 | 72 | 75 | ||
519 | 73 | session.close() | 76 | session.close() |
520 | 74 | 77 | ||
521 | @@ -77,7 +80,7 @@ | |||
522 | 77 | session = ibid.databases.ibid() | 80 | session = ibid.databases.ibid() |
523 | 78 | feeds = session.query(Feed).all() | 81 | feeds = session.query(Feed).all() |
524 | 79 | if feeds: | 82 | if feeds: |
526 | 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]))) |
527 | 81 | else: | 84 | else: |
528 | 82 | event.addresponse(u"I don't know about any feeds") | 85 | event.addresponse(u"I don't know about any feeds") |
529 | 83 | 86 | ||
530 | @@ -88,7 +91,7 @@ | |||
531 | 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() |
532 | 89 | 92 | ||
533 | 90 | if not feed: | 93 | if not feed: |
535 | 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) |
536 | 92 | else: | 95 | else: |
537 | 93 | session.delete(feed) | 96 | session.delete(feed) |
538 | 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) |
539 | @@ -112,7 +115,7 @@ | |||
540 | 112 | session.close() | 115 | session.close() |
541 | 113 | 116 | ||
542 | 114 | if not feed: | 117 | if not feed: |
544 | 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) |
545 | 116 | return | 119 | return |
546 | 117 | 120 | ||
547 | 118 | feed.update() | 121 | feed.update() |
548 | @@ -120,7 +123,9 @@ | |||
549 | 120 | event.addresponse(u"I can't access that feed") | 123 | event.addresponse(u"I can't access that feed") |
550 | 121 | return | 124 | return |
551 | 122 | 125 | ||
553 | 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] |
554 | 127 | articles = ['%s: "%s"' % (feed.entries.index(entry), html2text_file(entry.title, None).strip()) for entry in articles] | ||
555 | 128 | event.addresponse(u'%s', u', '.join(articles)) | ||
556 | 124 | 129 | ||
557 | 125 | @match(r'^article\s+(?:(\d+)|/(.+?)/)\s+from\s+(.+?)$') | 130 | @match(r'^article\s+(?:(\d+)|/(.+?)/)\s+from\s+(.+?)$') |
558 | 126 | def article(self, event, number, pattern, name): | 131 | def article(self, event, number, pattern, name): |
559 | @@ -129,7 +134,7 @@ | |||
560 | 129 | session.close() | 134 | session.close() |
561 | 130 | 135 | ||
562 | 131 | if not feed: | 136 | if not feed: |
564 | 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) |
565 | 133 | return | 138 | return |
566 | 134 | 139 | ||
567 | 135 | feed.update() | 140 | feed.update() |
568 | @@ -152,7 +157,7 @@ | |||
569 | 152 | break | 157 | break |
570 | 153 | 158 | ||
571 | 154 | if not article: | 159 | if not article: |
573 | 155 | event.addresponse(u"Are you making up news again?") | 160 | event.addresponse(u'Are you making up news again?') |
574 | 156 | return | 161 | return |
575 | 157 | 162 | ||
576 | 158 | if 'summary' in article: | 163 | if 'summary' in article: |
577 | @@ -163,6 +168,10 @@ | |||
578 | 163 | else: | 168 | else: |
579 | 164 | summary = article.content[0].value | 169 | summary = article.content[0].value |
580 | 165 | 170 | ||
582 | 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', { |
583 | 172 | 'title': html2text_file(article.title, None).strip(), | ||
584 | 173 | 'link': article.link, | ||
585 | 174 | 'summary': summary, | ||
586 | 175 | }) | ||
587 | 167 | 176 | ||
588 | 168 | # vi: set et sta sw=4 ts=4: | 177 | # vi: set et sta sw=4 ts=4: |
589 | 169 | 178 | ||
590 | === modified file 'ibid/plugins/google.py' | |||
591 | --- ibid/plugins/google.py 2009-03-05 15:03:20 +0000 | |||
592 | +++ ibid/plugins/google.py 2009-03-08 13:16:28 +0000 | |||
593 | @@ -61,17 +61,26 @@ | |||
594 | 61 | results.append(u'"%s" %s' % (de_entity(title), item["unescapedUrl"])) | 61 | results.append(u'"%s" %s' % (de_entity(title), item["unescapedUrl"])) |
595 | 62 | 62 | ||
596 | 63 | if results: | 63 | if results: |
598 | 64 | event.addresponse(u', '.join(results)) | 64 | event.addresponse(u'%s', u', '.join(results)) |
599 | 65 | else: | 65 | else: |
601 | 66 | event.addresponse(u"Wow! Google couldn't find anything.") | 66 | event.addresponse(u"Wow! Google couldn't find anything") |
602 | 67 | 67 | ||
603 | 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+(.+?)$') |
604 | 69 | def googlefight(self, event, term1, term2): | 69 | def googlefight(self, event, term1, term2): |
605 | 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)) |
606 | 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)) |
610 | 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', |
611 | 73 | (count1 > count2 and (term1, count1, term2, count2) or (term2, count2, term1, count1)) | 73 | (count1 > count2 and { |
612 | 74 | ) | 74 | 'firstterm': term1, |
613 | 75 | 'firsthits': count1, | ||
614 | 76 | 'secondterm': term2, | ||
615 | 77 | 'secondhits': count2, | ||
616 | 78 | } or { | ||
617 | 79 | 'firstterm': term2, | ||
618 | 80 | 'firsthits': count2, | ||
619 | 81 | 'secondterm': term1, | ||
620 | 82 | 'secondhits': count1, | ||
621 | 83 | })) | ||
622 | 75 | 84 | ||
623 | 76 | # Unfortunatly google API search doesn't support all of google search's | 85 | # Unfortunatly google API search doesn't support all of google search's |
624 | 77 | # features. | 86 | # features. |
625 | @@ -103,7 +112,7 @@ | |||
626 | 103 | if not font: | 112 | if not font: |
627 | 104 | event.addresponse(u'No result') | 113 | event.addresponse(u'No result') |
628 | 105 | else: | 114 | else: |
630 | 106 | event.addresponse(font.b.string) | 115 | event.addresponse(u'%s', font.b.string) |
631 | 107 | 116 | ||
632 | 108 | @match(r'^gdefine\s+(.+)$') | 117 | @match(r'^gdefine\s+(.+)$') |
633 | 109 | def define(self, event, term): | 118 | def define(self, event, term): |
634 | @@ -114,9 +123,9 @@ | |||
635 | 114 | definitions.append(de_entity(li.contents[0].strip())) | 123 | definitions.append(de_entity(li.contents[0].strip())) |
636 | 115 | 124 | ||
637 | 116 | if definitions: | 125 | if definitions: |
639 | 117 | event.addresponse(u' :: '.join(definitions)) | 126 | event.addresponse(u'%s', u' :: '.join(definitions)) |
640 | 118 | else: | 127 | else: |
642 | 119 | event.addresponse(u"Are you making up words again?") | 128 | event.addresponse(u'Are you making up words again?') |
643 | 120 | 129 | ||
644 | 121 | # Not supported by Google API: http://code.google.com/p/google-ajax-apis/issues/detail?id=24 | 130 | # Not supported by Google API: http://code.google.com/p/google-ajax-apis/issues/detail?id=24 |
645 | 122 | @match(r'^google(?:\.com?)?\.([a-z]{2})(?:\s+for)?\s+(.*)$') | 131 | @match(r'^google(?:\.com?)?\.([a-z]{2})(?:\s+for)?\s+(.*)$') |
646 | @@ -138,8 +147,8 @@ | |||
647 | 138 | break | 147 | break |
648 | 139 | 148 | ||
649 | 140 | if results: | 149 | if results: |
651 | 141 | event.addresponse(u", ".join(results)) | 150 | event.addresponse('%s', u', '.join(results)) |
652 | 142 | else: | 151 | else: |
654 | 143 | event.addresponse(u"Wow! Google couldn't find anything.") | 152 | event.addresponse(u"Wow! Google couldn't find anything") |
655 | 144 | 153 | ||
656 | 145 | # vi: set et sta sw=4 ts=4: | 154 | # vi: set et sta sw=4 ts=4: |
657 | 146 | 155 | ||
658 | === modified file 'ibid/plugins/help.py' | |||
659 | --- ibid/plugins/help.py 2009-03-05 16:33:12 +0000 | |||
660 | +++ ibid/plugins/help.py 2009-03-08 13:16:28 +0000 | |||
661 | @@ -27,7 +27,7 @@ | |||
662 | 27 | if feature not in features: | 27 | if feature not in features: |
663 | 28 | features.append(feature) | 28 | features.append(feature) |
664 | 29 | 29 | ||
666 | 30 | event.addresponse(u' '.join(features)) | 30 | event.addresponse(u'Features: %s', u' '.join(sorted(features))) |
667 | 31 | 31 | ||
668 | 32 | @match(r'^help\s+(.+)$') | 32 | @match(r'^help\s+(.+)$') |
669 | 33 | def help(self, event, feature): | 33 | def help(self, event, feature): |
670 | @@ -39,7 +39,7 @@ | |||
671 | 39 | event.addresponse(module.help[feature]) | 39 | event.addresponse(module.help[feature]) |
672 | 40 | return | 40 | return |
673 | 41 | 41 | ||
675 | 42 | event.addresponse(u"I can't help you with %s" % feature) | 42 | event.addresponse(u"I can't help you with %s", feature) |
676 | 43 | 43 | ||
677 | 44 | @match(r'^(?:usage|how\s+do\s+I\s+use)\s+(.+)$') | 44 | @match(r'^(?:usage|how\s+do\s+I\s+use)\s+(.+)$') |
678 | 45 | def usage(self, event, feature): | 45 | def usage(self, event, feature): |
679 | @@ -49,9 +49,9 @@ | |||
680 | 49 | for name, klass in inspect.getmembers(processor, inspect.isclass): | 49 | for name, klass in inspect.getmembers(processor, inspect.isclass): |
681 | 50 | if hasattr(klass, 'feature') and klass.feature == feature and klass.__doc__: | 50 | if hasattr(klass, 'feature') and klass.feature == feature and klass.__doc__: |
682 | 51 | for line in klass.__doc__.splitlines(): | 51 | for line in klass.__doc__.splitlines(): |
684 | 52 | event.addresponse('Usage: %s' % line.strip()) | 52 | event.addresponse(u'Usage: %s', line.strip()) |
685 | 53 | 53 | ||
686 | 54 | if not event.responses: | 54 | if not event.responses: |
688 | 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) |
689 | 56 | 56 | ||
690 | 57 | # vi: set et sta sw=4 ts=4: | 57 | # vi: set et sta sw=4 ts=4: |
691 | 58 | 58 | ||
692 | === modified file 'ibid/plugins/http.py' | |||
693 | --- ibid/plugins/http.py 2009-03-07 16:10:50 +0000 | |||
694 | +++ ibid/plugins/http.py 2009-03-08 13:16:28 +0000 | |||
695 | @@ -52,7 +52,8 @@ | |||
696 | 52 | if action == 'GET': | 52 | if action == 'GET': |
697 | 53 | match = title.search(data) | 53 | match = title.search(data) |
698 | 54 | if match: | 54 | if match: |
702 | 55 | reply = u'%s "%s"' % (reply, match.groups()[0].strip()) | 55 | reply += u' "%s"' % match.groups()[0].strip() |
703 | 56 | 56 | ||
704 | 57 | event.addresponse(reply) | 57 | event.addresponse('%s', reply) |
705 | 58 | |||
706 | 58 | # vi: set et sta sw=4 ts=4: | 59 | # vi: set et sta sw=4 ts=4: |
707 | 59 | 60 | ||
708 | === modified file 'ibid/plugins/identity.py' | |||
709 | --- ibid/plugins/identity.py 2009-03-01 23:01:30 +0000 | |||
710 | +++ ibid/plugins/identity.py 2009-03-08 13:16:28 +0000 | |||
711 | @@ -29,12 +29,12 @@ | |||
712 | 29 | admin = True | 29 | admin = True |
713 | 30 | else: | 30 | else: |
714 | 31 | account = session.query(Account).filter_by(id=event.account).first() | 31 | account = session.query(Account).filter_by(id=event.account).first() |
716 | 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) |
717 | 33 | return | 33 | return |
718 | 34 | 34 | ||
719 | 35 | account = session.query(Account).filter_by(username=username).first() | 35 | account = session.query(Account).filter_by(username=username).first() |
720 | 36 | if account: | 36 | if account: |
722 | 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) |
723 | 38 | return | 38 | return |
724 | 39 | 39 | ||
725 | 40 | account = Account(username) | 40 | account = Account(username) |
726 | @@ -51,7 +51,7 @@ | |||
727 | 51 | 51 | ||
728 | 52 | identify_cache.clear() | 52 | identify_cache.clear() |
729 | 53 | session.close() | 53 | session.close() |
731 | 54 | event.addresponse(u'Done') | 54 | event.addresponse(True) |
732 | 55 | 55 | ||
733 | 56 | chars = string.letters + string.digits | 56 | chars = string.letters + string.digits |
734 | 57 | 57 | ||
735 | @@ -78,7 +78,8 @@ | |||
736 | 78 | username = event.sender['id'] | 78 | username = event.sender['id'] |
737 | 79 | account = session.query(Account).filter_by(username=username).first() | 79 | account = session.query(Account).filter_by(username=username).first() |
738 | 80 | if account: | 80 | if account: |
740 | 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. ' |
741 | 82 | u"Please use 'create account <name>'", username) | ||
742 | 82 | return | 83 | return |
743 | 83 | account = Account(username) | 84 | account = Account(username) |
744 | 84 | session.save_or_update(account) | 85 | session.save_or_update(account) |
745 | @@ -88,7 +89,7 @@ | |||
746 | 88 | session.save_or_update(currentidentity) | 89 | session.save_or_update(currentidentity) |
747 | 89 | session.flush() | 90 | session.flush() |
748 | 90 | identify_cache.clear() | 91 | identify_cache.clear() |
750 | 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) |
751 | 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']) |
752 | 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) |
753 | 94 | 95 | ||
754 | @@ -98,16 +99,16 @@ | |||
755 | 98 | admin = True | 99 | admin = True |
756 | 99 | account = session.query(Account).filter_by(username=username).first() | 100 | account = session.query(Account).filter_by(username=username).first() |
757 | 100 | if not account: | 101 | if not account: |
759 | 101 | event.addresponse(u"I don't know who %s is" % username) | 102 | event.addresponse(u"I don't know who %s is", username) |
760 | 102 | return | 103 | return |
761 | 103 | 104 | ||
762 | 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() |
763 | 105 | if ident and ident.account: | 106 | if ident and ident.account: |
765 | 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) |
766 | 107 | return | 108 | return |
767 | 108 | 109 | ||
768 | 109 | if source.lower() not in ibid.sources: | 110 | if source.lower() not in ibid.sources: |
770 | 110 | event.addresponse(u"I am not connected to %s" % source) | 111 | event.addresponse(u'I am not connected to %s', source) |
771 | 111 | else: | 112 | else: |
772 | 112 | source = ibid.sources[source.lower()].name | 113 | source = ibid.sources[source.lower()].name |
773 | 113 | 114 | ||
774 | @@ -136,7 +137,10 @@ | |||
775 | 136 | session = ibid.databases.ibid() | 137 | session = ibid.databases.ibid() |
776 | 137 | (account_id, user, source) = self.tokens[token] | 138 | (account_id, user, source) = self.tokens[token] |
777 | 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(): |
779 | 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', { |
780 | 141 | 'name': user, | ||
781 | 142 | 'source': source, | ||
782 | 143 | }) | ||
783 | 140 | return | 144 | return |
784 | 141 | 145 | ||
785 | 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() |
786 | @@ -163,7 +167,7 @@ | |||
787 | 163 | return | 167 | return |
788 | 164 | account = session.query(Account).filter_by(username=username).first() | 168 | account = session.query(Account).filter_by(username=username).first() |
789 | 165 | if not account: | 169 | if not account: |
791 | 166 | event.addresponse(u"I don't know who %s is" % username) | 170 | event.addresponse(u"I don't know who %s is", username) |
792 | 167 | return | 171 | return |
793 | 168 | 172 | ||
794 | 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() |
795 | @@ -193,7 +197,7 @@ | |||
796 | 193 | return | 197 | return |
797 | 194 | account = session.query(Account).filter_by(id=event.account).first() | 198 | account = session.query(Account).filter_by(id=event.account).first() |
798 | 195 | if not account: | 199 | if not account: |
800 | 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) |
801 | 197 | return | 201 | return |
802 | 198 | 202 | ||
803 | 199 | else: | 203 | else: |
804 | @@ -201,14 +205,14 @@ | |||
805 | 201 | return | 205 | return |
806 | 202 | account = session.query(Account).filter_by(username=username).first() | 206 | account = session.query(Account).filter_by(username=username).first() |
807 | 203 | if not account: | 207 | if not account: |
809 | 204 | event.addresponse(u"I don't know who %s is" % username) | 208 | event.addresponse(u"I don't know who %s is", username) |
810 | 205 | return | 209 | return |
811 | 206 | 210 | ||
812 | 207 | account.attributes.append(Attribute(name, value)) | 211 | account.attributes.append(Attribute(name, value)) |
813 | 208 | session.save_or_update(account) | 212 | session.save_or_update(account) |
814 | 209 | session.flush() | 213 | session.flush() |
815 | 210 | session.close() | 214 | session.close() |
817 | 211 | event.addresponse(u'Done') | 215 | event.addresponse(True) |
818 | 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']) |
819 | 213 | 217 | ||
820 | 214 | class Describe(Processor): | 218 | class Describe(Processor): |
821 | @@ -221,17 +225,23 @@ | |||
822 | 221 | if username.upper() == 'I': | 225 | if username.upper() == 'I': |
823 | 222 | if not event.account: | 226 | if not event.account: |
824 | 223 | identity = session.query(Identity).get(event.identity) | 227 | identity = session.query(Identity).get(event.identity) |
826 | 224 | event.addresponse(u"%s on %s" % (identity.identity, identity.source)) | 228 | event.addresponse(u"%(name)s on %(source)s", { |
827 | 229 | 'name': identity.identity, | ||
828 | 230 | 'source': identity.source, | ||
829 | 231 | }) | ||
830 | 225 | return | 232 | return |
831 | 226 | account = session.query(Account).get(event.account) | 233 | account = session.query(Account).get(event.account) |
832 | 227 | 234 | ||
833 | 228 | else: | 235 | else: |
834 | 229 | account = session.query(Account).filter_by(username=username).first() | 236 | account = session.query(Account).filter_by(username=username).first() |
835 | 230 | if not account: | 237 | if not account: |
837 | 231 | event.addresponse(u"I don't know who %s is" % username) | 238 | event.addresponse(u"I don't know who %s is", username) |
838 | 232 | return | 239 | return |
839 | 233 | 240 | ||
841 | 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', { |
842 | 242 | 'accountname': account.username, | ||
843 | 243 | 'identities': u', '.join(u'%s on %s' % (identity.identity, identity.source) for identity in account.identities), | ||
844 | 244 | }) | ||
845 | 235 | session.close() | 245 | session.close() |
846 | 236 | 246 | ||
847 | 237 | class Identify(Processor): | 247 | class Identify(Processor): |
848 | 238 | 248 | ||
849 | === modified file 'ibid/plugins/imdb.py' | |||
850 | --- ibid/plugins/imdb.py 2009-03-01 23:01:30 +0000 | |||
851 | +++ ibid/plugins/imdb.py 2009-03-08 13:16:28 +0000 | |||
852 | @@ -50,25 +50,28 @@ | |||
853 | 50 | self.imdb.update(result) | 50 | self.imdb.update(result) |
854 | 51 | 51 | ||
855 | 52 | except IMDbDataAccessError, e: | 52 | except IMDbDataAccessError, e: |
857 | 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"]) |
858 | 54 | raise | 54 | raise |
859 | 55 | 55 | ||
860 | 56 | except IMDbError, e: | 56 | except IMDbError, e: |
862 | 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)') |
863 | 58 | raise | 58 | raise |
864 | 59 | 59 | ||
865 | 60 | if result is not None: | 60 | if result is not None: |
867 | 61 | event.addresponse(u"Found " + getattr(self, "display_" + search_type)(result)) | 61 | event.addresponse(u'Found %s', getattr(self, 'display_' + search_type)(result)) |
868 | 62 | return | 62 | return |
869 | 63 | 63 | ||
870 | 64 | if len(results) == 0: | 64 | if len(results) == 0: |
872 | 65 | event.addresponse(u"Sorry, couldn't find that.") | 65 | event.addresponse(u"Sorry, couldn't find that") |
873 | 66 | else: | 66 | else: |
874 | 67 | results = [x[self.name_keys[search_type]] for x in results] | 67 | results = [x[self.name_keys[search_type]] for x in results] |
875 | 68 | results = enumerate(results) | 68 | results = enumerate(results) |
876 | 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] |
879 | 70 | more = (u"", u">")[len(results) == 20] | 70 | event.addresponse(u'Found %(greaterthan)s%(num)i matches: %(results)s', { |
880 | 71 | event.addresponse(u"Found %s%i matches: %s" % (more, len(results), u", ".join(results))) | 71 | 'greaterthan': (u'', u'>')[len(results) == 20], |
881 | 72 | 'num': len(results), | ||
882 | 73 | 'results': u', '.join(results), | ||
883 | 74 | }) | ||
884 | 72 | 75 | ||
885 | 73 | def display_character(self, character): | 76 | def display_character(self, character): |
886 | 74 | desc = u"%s: %s." % (character.characterID, character["long imdb name"]) | 77 | desc = u"%s: %s." % (character.characterID, character["long imdb name"]) |
887 | 75 | 78 | ||
888 | === modified file 'ibid/plugins/info.py' | |||
889 | --- ibid/plugins/info.py 2009-03-02 09:38:47 +0000 | |||
890 | +++ ibid/plugins/info.py 2009-03-08 13:16:28 +0000 | |||
891 | @@ -26,7 +26,11 @@ | |||
892 | 26 | 26 | ||
893 | 27 | @match(r'^fortune$') | 27 | @match(r'^fortune$') |
894 | 28 | def handler(self, event): | 28 | def handler(self, event): |
896 | 29 | event.addresponse(self.remote_fortune() or u"Couldn't execute fortune") | 29 | fortune = self.remote_fortune() |
897 | 30 | if fortune: | ||
898 | 31 | event.addresponse(u'%s', fortune) | ||
899 | 32 | else: | ||
900 | 33 | event.addresponse(u"Couldn't execute fortune") | ||
901 | 30 | 34 | ||
902 | 31 | def remote_fortune(self): | 35 | def remote_fortune(self): |
903 | 32 | fortune = Popen(self.fortune, stdout=PIPE, stderr=PIPE) | 36 | fortune = Popen(self.fortune, stdout=PIPE, stderr=PIPE) |
904 | @@ -49,9 +53,12 @@ | |||
905 | 49 | def handle_nickometer(self, event, nick, wreasons): | 53 | def handle_nickometer(self, event, nick, wreasons): |
906 | 50 | nick = nick or event.sender['nick'] | 54 | nick = nick or event.sender['nick'] |
907 | 51 | score, reasons = nickometer(str(nick)) | 55 | score, reasons = nickometer(str(nick)) |
909 | 52 | event.addresponse(u"%s is %s%% lame" % (nick, score)) | 56 | event.addresponse(u"%(nick)s is %(score)s%% lame", { |
910 | 57 | 'nick': nick, | ||
911 | 58 | 'score': score, | ||
912 | 59 | }) | ||
913 | 53 | if wreasons: | 60 | if wreasons: |
915 | 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])) |
916 | 55 | 62 | ||
917 | 56 | help['man'] = u'Retrieves information from manpages.' | 63 | help['man'] = u'Retrieves information from manpages.' |
918 | 57 | class Man(Processor): | 64 | class Man(Processor): |
919 | @@ -88,9 +95,9 @@ | |||
920 | 88 | output = output.splitlines() | 95 | output = output.splitlines() |
921 | 89 | index = output.index('NAME') | 96 | index = output.index('NAME') |
922 | 90 | if index: | 97 | if index: |
924 | 91 | event.addresponse(output[index+1].strip()) | 98 | event.addresponse(u'%s', output[index+1].strip()) |
925 | 92 | index = output.index('SYNOPSIS') | 99 | index = output.index('SYNOPSIS') |
926 | 93 | if index: | 100 | if index: |
928 | 94 | event.addresponse(output[index+1].strip()) | 101 | event.addresponse(u'%s', output[index+1].strip()) |
929 | 95 | 102 | ||
930 | 96 | # vi: set et sta sw=4 ts=4: | 103 | # vi: set et sta sw=4 ts=4: |
931 | 97 | 104 | ||
932 | === modified file 'ibid/plugins/irc.py' | |||
933 | --- ibid/plugins/irc.py 2009-03-01 23:01:30 +0000 | |||
934 | +++ ibid/plugins/irc.py 2009-03-08 13:16:28 +0000 | |||
935 | @@ -25,21 +25,21 @@ | |||
936 | 25 | channel = event.channel | 25 | channel = event.channel |
937 | 26 | 26 | ||
938 | 27 | if source.lower() not in ibid.sources: | 27 | if source.lower() not in ibid.sources: |
940 | 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()) |
941 | 29 | return | 29 | return |
942 | 30 | 30 | ||
943 | 31 | source = ibid.sources[source.lower()] | 31 | source = ibid.sources[source.lower()] |
944 | 32 | 32 | ||
945 | 33 | if not hasattr(source, 'join'): | 33 | if not hasattr(source, 'join'): |
947 | 34 | event.addresponse(u"%s cannot join/part channels" % (source.name,)) | 34 | event.addresponse(u'%s cannot join/part channels', source.name) |
948 | 35 | return | 35 | return |
949 | 36 | 36 | ||
950 | 37 | if action == 'join': | 37 | if action == 'join': |
951 | 38 | source.join(channel) | 38 | source.join(channel) |
953 | 39 | event.addresponse(u"Joining %s" % channel) | 39 | event.addresponse(u'Joining %s', channel) |
954 | 40 | else: | 40 | else: |
955 | 41 | source.part(channel) | 41 | source.part(channel) |
957 | 42 | event.addresponse(u"Parting %s" % channel) | 42 | event.addresponse(u'Parting %s', channel) |
958 | 43 | 43 | ||
959 | 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+))?$') |
960 | 45 | @authorise | 45 | @authorise |
961 | @@ -49,15 +49,15 @@ | |||
962 | 49 | source = event.source | 49 | source = event.source |
963 | 50 | 50 | ||
964 | 51 | if source.lower() not in ibid.sources: | 51 | if source.lower() not in ibid.sources: |
966 | 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()) |
967 | 53 | return | 53 | return |
968 | 54 | 54 | ||
969 | 55 | source = ibid.sources[source.lower()] | 55 | source = ibid.sources[source.lower()] |
970 | 56 | 56 | ||
971 | 57 | if not hasattr(source, 'change_nick'): | 57 | if not hasattr(source, 'change_nick'): |
973 | 58 | event.addresponse(u"%s cannot change nicks" % source) | 58 | event.addresponse(u'%s cannot change nicks', source) |
974 | 59 | else: | 59 | else: |
975 | 60 | source.change_nick(nick) | 60 | source.change_nick(nick) |
977 | 61 | event.addresponse(u'Changing nick to %s' % nick) | 61 | event.addresponse(u'Changing nick to %s', nick) |
978 | 62 | 62 | ||
979 | 63 | # vi: set et sta sw=4 ts=4: | 63 | # vi: set et sta sw=4 ts=4: |
980 | 64 | 64 | ||
981 | === modified file 'ibid/plugins/karma.py' | |||
982 | --- ibid/plugins/karma.py 2009-03-01 23:01:30 +0000 | |||
983 | +++ ibid/plugins/karma.py 2009-03-08 13:16:28 +0000 | |||
984 | @@ -50,7 +50,7 @@ | |||
985 | 50 | @authorise | 50 | @authorise |
986 | 51 | def set(self, event, subject, adjust, reason): | 51 | def set(self, event, subject, adjust, reason): |
987 | 52 | if self.public and not event.public: | 52 | if self.public and not event.public: |
989 | 53 | event.addresponse(u"Karma must be done in public") | 53 | event.addresponse(u'Karma must be done in public') |
990 | 54 | return | 54 | return |
991 | 55 | 55 | ||
992 | 56 | if subject.lower() in self.ignore: | 56 | if subject.lower() in self.ignore: |
993 | @@ -97,16 +97,19 @@ | |||
994 | 97 | session = ibid.databases.ibid() | 97 | session = ibid.databases.ibid() |
995 | 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() |
996 | 99 | if not karma: | 99 | if not karma: |
998 | 100 | event.addresponse(u"%s has neutral karma" % subject) | 100 | event.addresponse(u'%s has neutral karma', subject) |
999 | 101 | else: | 101 | else: |
1001 | 102 | event.addresponse(u"%s has karma of %s" % (subject, karma.value)) | 102 | event.addresponse(u'%(subject)s has karma of %(value)s', { |
1002 | 103 | 'subject': subject, | ||
1003 | 104 | 'value': karma.value, | ||
1004 | 105 | }) | ||
1005 | 103 | session.close() | 106 | session.close() |
1006 | 104 | 107 | ||
1007 | 105 | @match(r'^(reverse\s+)?karmaladder$') | 108 | @match(r'^(reverse\s+)?karmaladder$') |
1008 | 106 | def ladder(self, event, reverse): | 109 | def ladder(self, event, reverse): |
1009 | 107 | session = ibid.databases.ibid() | 110 | session = ibid.databases.ibid() |
1010 | 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() |
1012 | 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])) |
1013 | 110 | session.close() | 113 | session.close() |
1014 | 111 | 114 | ||
1015 | 112 | # vi: set et sta sw=4 ts=4: | 115 | # vi: set et sta sw=4 ts=4: |
1016 | 113 | 116 | ||
1017 | === modified file 'ibid/plugins/lookup.py' | |||
1018 | --- ibid/plugins/lookup.py 2009-03-08 08:00:10 +0000 | |||
1019 | +++ ibid/plugins/lookup.py 2009-03-08 13:21:32 +0000 | |||
1020 | @@ -28,15 +28,15 @@ | |||
1021 | 28 | 28 | ||
1022 | 29 | if quote.lower() == "random": | 29 | if quote.lower() == "random": |
1023 | 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) |
1025 | 31 | event.addresponse(u"%s:" % number) | 31 | event.addresponse(u'%s:', number) |
1026 | 32 | 32 | ||
1027 | 33 | quote = soup.find('p', attrs={'class': 'qt'}) | 33 | quote = soup.find('p', attrs={'class': 'qt'}) |
1028 | 34 | if not quote: | 34 | if not quote: |
1030 | 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") |
1031 | 36 | else: | 36 | else: |
1032 | 37 | for line in quote.contents: | 37 | for line in quote.contents: |
1033 | 38 | if str(line) != '<br />': | 38 | if str(line) != '<br />': |
1035 | 39 | event.addresponse(unicode(line).strip()) | 39 | event.addresponse(u'%s', line.strip()) |
1036 | 40 | 40 | ||
1037 | 41 | help['lastfm'] = u'Lists the tracks last listened to by the specified user.' | 41 | help['lastfm'] = u'Lists the tracks last listened to by the specified user.' |
1038 | 42 | class LastFm(Processor): | 42 | class LastFm(Processor): |
1039 | @@ -46,11 +46,11 @@ | |||
1040 | 46 | 46 | ||
1041 | 47 | @match(r'^last\.?fm\s+for\s+(\S+?)\s*$') | 47 | @match(r'^last\.?fm\s+for\s+(\S+?)\s*$') |
1042 | 48 | def listsongs(self, event, username): | 48 | def listsongs(self, event, username): |
1044 | 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())) |
1045 | 50 | if songs['bozo']: | 50 | if songs['bozo']: |
1047 | 51 | event.addresponse(u"No such user") | 51 | event.addresponse(u'No such user') |
1048 | 52 | else: | 52 | else: |
1050 | 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'])) |
1051 | 54 | 54 | ||
1052 | 55 | help['lotto'] = u"Gets the latest lotto results from the South African National Lottery." | 55 | help['lotto'] = u"Gets the latest lotto results from the South African National Lottery." |
1053 | 56 | class Lotto(Processor): | 56 | class Lotto(Processor): |
1054 | @@ -58,40 +58,37 @@ | |||
1055 | 58 | 58 | ||
1056 | 59 | feature = 'lotto' | 59 | feature = 'lotto' |
1057 | 60 | 60 | ||
1058 | 61 | errors = { | ||
1059 | 62 | 'open': 'Something went wrong getting to the Lotto site', | ||
1060 | 63 | 'balls': 'I expected to get %s balls, but found %s. They were: %s', | ||
1061 | 64 | } | ||
1062 | 65 | |||
1063 | 66 | za_url = 'http://www.nationallottery.co.za/' | 61 | za_url = 'http://www.nationallottery.co.za/' |
1064 | 67 | za_re = re.compile(r'images/balls/ball_(\d+).gif') | 62 | za_re = re.compile(r'images/balls/ball_(\d+).gif') |
1065 | 68 | za_text = u'Latest lotto results for South Africa, Lotto: ' | ||
1066 | 69 | 63 | ||
1067 | 70 | @match(r'lotto(\s+for\s+south\s+africa)?') | 64 | @match(r'lotto(\s+for\s+south\s+africa)?') |
1068 | 71 | def za(self, event, za): | 65 | def za(self, event, za): |
1069 | 72 | try: | 66 | try: |
1070 | 73 | f = urlopen(self.za_url) | 67 | f = urlopen(self.za_url) |
1071 | 74 | except Exception, e: | 68 | except Exception, e: |
1073 | 75 | event.addresponse(self.errors['open']) | 69 | event.addresponse(u'Something went wrong getting to the Lotto site') |
1074 | 76 | return | 70 | return |
1075 | 77 | 71 | ||
1076 | 78 | s = "".join(f) | 72 | s = "".join(f) |
1077 | 79 | f.close() | 73 | f.close() |
1078 | 80 | 74 | ||
1079 | 81 | r = self.za_text | ||
1080 | 82 | |||
1081 | 83 | balls = self.za_re.findall(s) | 75 | balls = self.za_re.findall(s) |
1082 | 84 | 76 | ||
1083 | 85 | if len(balls) != 14: | 77 | if len(balls) != 14: |
1086 | 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', { |
1087 | 87 | (14, len(balls), ", ".join(balls))) | 79 | 'expected': 14, |
1088 | 80 | 'found': len(balls), | ||
1089 | 81 | 'balls': u', '.join(balls), | ||
1090 | 82 | }) | ||
1091 | 88 | return | 83 | return |
1092 | 89 | 84 | ||
1098 | 90 | r += u" ".join(balls[:6]) | 85 | event.addresponse(u'Latest lotto results for South Africa, ' |
1099 | 91 | r += u" (Bonus: %s), Lotto Plus: " % (balls[6], ) | 86 | u'Lotto: %(lottoballs)s (Bonus: %(lottobonus)s), Lotto Plus: %(plusballs)s (Bonus: %(plusbonus)s)', { |
1100 | 92 | r += u" ".join(balls[7:13]) | 87 | 'lottoballs': u" ".join(balls[:6]), |
1101 | 93 | r += u" (Bonus: %s)" % (balls[13], ) | 88 | 'lottobonus': balls[6], |
1102 | 94 | event.addresponse(r) | 89 | 'plusballs': u" ".join(balls[7:13]), |
1103 | 90 | 'plusbonus': balls[13], | ||
1104 | 91 | }) | ||
1105 | 95 | 92 | ||
1106 | 96 | help['fml'] = u'Retrieves quotes from fmylife.com.' | 93 | help['fml'] = u'Retrieves quotes from fmylife.com.' |
1107 | 97 | class FMyLife(Processor): | 94 | class FMyLife(Processor): |
1108 | @@ -109,7 +106,11 @@ | |||
1109 | 109 | 106 | ||
1110 | 110 | @match(r'^(?:fml\s+|http://www\.fmylife\.com/\S+/)(\d+|random)$') | 107 | @match(r'^(?:fml\s+|http://www\.fmylife\.com/\S+/)(\d+|random)$') |
1111 | 111 | def fml(self, event, id): | 108 | def fml(self, event, id): |
1113 | 112 | event.addresponse(self.remote_get(id) or u"No such quote") | 109 | quote = self.remote_get(id) |
1114 | 110 | if quote: | ||
1115 | 111 | event.addresponse(u'%s', quote) | ||
1116 | 112 | else: | ||
1117 | 113 | event.addresponse(u'No such quote') | ||
1118 | 113 | 114 | ||
1119 | 114 | help["microblog"] = u"Looks up messages on microblogging services like twitter and identica." | 115 | help["microblog"] = u"Looks up messages on microblogging services like twitter and identica." |
1120 | 115 | class Twitter(Processor): | 116 | class Twitter(Processor): |
1121 | @@ -134,7 +135,7 @@ | |||
1122 | 134 | status = loads(f.read()) | 135 | status = loads(f.read()) |
1123 | 135 | f.close() | 136 | f.close() |
1124 | 136 | 137 | ||
1126 | 137 | return u'%s: "%s"' % (status['user']['screen_name'], status['text']) | 138 | return {'screen_name': status['user']['screen_name'], 'text': status['text']} |
1127 | 138 | 139 | ||
1128 | 139 | def remote_latest(self, service, user): | 140 | def remote_latest(self, service, user): |
1129 | 140 | service_url = self.services[service] | 141 | service_url = self.services[service] |
1130 | @@ -148,25 +149,27 @@ | |||
1131 | 148 | elif service_url.endswith("/api/"): | 149 | elif service_url.endswith("/api/"): |
1132 | 149 | url = "%s/notice/%i" % (service_url[:-5], latest["id"]) | 150 | url = "%s/notice/%i" % (service_url[:-5], latest["id"]) |
1133 | 150 | 151 | ||
1137 | 151 | when = ago(datetime.utcnow() - datetime.strptime(latest["created_at"], '%a %b %d %H:%M:%S +0000 %Y'), 1) | 152 | return { |
1138 | 152 | 153 | 'text': latest['text'], | |
1139 | 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), |
1140 | 155 | 'url': url, | ||
1141 | 156 | } | ||
1142 | 154 | 157 | ||
1143 | 155 | @handler | 158 | @handler |
1144 | 156 | def update(self, event, service, id): | 159 | def update(self, event, service, id): |
1146 | 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))) |
1147 | 158 | 161 | ||
1148 | 159 | @handler | 162 | @handler |
1149 | 160 | def latest(self, event, service, user): | 163 | def latest(self, event, service, user): |
1151 | 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)) |
1152 | 162 | 165 | ||
1153 | 163 | @match(r'^https?://(?:www\.)?twitter\.com/[^/ ]+/statuse?s?/(\d+)$') | 166 | @match(r'^https?://(?:www\.)?twitter\.com/[^/ ]+/statuse?s?/(\d+)$') |
1154 | 164 | def twitter(self, event, id): | 167 | def twitter(self, event, id): |
1156 | 165 | event.addresponse(self.remote_update('twitter', int(id))) | 168 | event.addresponse(u'%(screen_name)s: "%(text)s"', self.remote_update('twitter', int(id))) |
1157 | 166 | 169 | ||
1158 | 167 | @match(r'^https?://(?:www\.)?identi.ca/notice/(\d+)$') | 170 | @match(r'^https?://(?:www\.)?identi.ca/notice/(\d+)$') |
1159 | 168 | def identica(self, event, id): | 171 | def identica(self, event, id): |
1161 | 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))) |
1162 | 170 | 173 | ||
1163 | 171 | help['currency'] = u'Converts amounts between currencies.' | 174 | help['currency'] = u'Converts amounts between currencies.' |
1164 | 172 | class Currency(Processor): | 175 | class Currency(Processor): |
1165 | @@ -199,7 +202,7 @@ | |||
1166 | 199 | soup = BeautifulSoup(f.read()) | 202 | soup = BeautifulSoup(f.read()) |
1167 | 200 | f.close() | 203 | f.close() |
1168 | 201 | 204 | ||
1170 | 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]) |
1171 | 203 | 206 | ||
1172 | 204 | @match(r'^(?:currency|currencies)\s+for\s+(?:the\s+)?(.+)$') | 207 | @match(r'^(?:currency|currencies)\s+for\s+(?:the\s+)?(.+)$') |
1173 | 205 | def currency(self, event, place): | 208 | def currency(self, event, place): |
1174 | @@ -210,10 +213,10 @@ | |||
1175 | 210 | results = [] | 213 | results = [] |
1176 | 211 | for code, place, name in self.currencies: | 214 | for code, place, name in self.currencies: |
1177 | 212 | if search.search(place): | 215 | if search.search(place): |
1179 | 213 | results.append('%s uses %s (%s)' % (place, name, code)) | 216 | results.append(u'%s uses %s (%s)' % (place, name, code)) |
1180 | 214 | 217 | ||
1181 | 215 | if results: | 218 | if results: |
1183 | 216 | event.addresponse(u', '.join(results)) | 219 | event.addresponse(u'%s', u', '.join(results)) |
1184 | 217 | else: | 220 | else: |
1185 | 218 | event.addresponse(u'No currencies found') | 221 | event.addresponse(u'No currencies found') |
1186 | 219 | 222 | ||
1187 | @@ -279,7 +282,7 @@ | |||
1188 | 279 | for td in soup.findAll('table')[2].findAll('td', align='left'): | 282 | for td in soup.findAll('table')[2].findAll('td', align='left'): |
1189 | 280 | day = td.b.string | 283 | day = td.b.string |
1190 | 281 | forecast = td.contents[2] | 284 | forecast = td.contents[2] |
1192 | 282 | forecasts.append('%s: %s' % (day, self._text(forecast))) | 285 | forecasts.append(u'%s: %s' % (day, self._text(forecast))) |
1193 | 283 | 286 | ||
1194 | 284 | return forecasts | 287 | return forecasts |
1195 | 285 | 288 | ||
1196 | @@ -287,19 +290,25 @@ | |||
1197 | 287 | def weather(self, event, place): | 290 | def weather(self, event, place): |
1198 | 288 | try: | 291 | try: |
1199 | 289 | values = self.remote_weather(place) | 292 | values = self.remote_weather(place) |
1201 | 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) |
1202 | 291 | except Weather.TooManyPlacesException, e: | 294 | except Weather.TooManyPlacesException, e: |
1204 | 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', { |
1205 | 296 | 'place': place, | ||
1206 | 297 | 'exception': u'; '.join(e.message), | ||
1207 | 298 | }) | ||
1208 | 293 | except Weather.WeatherException, e: | 299 | except Weather.WeatherException, e: |
1210 | 294 | event.addresponse(e.message) | 300 | event.addresponse(u'%s', e.message) |
1211 | 295 | 301 | ||
1212 | 296 | @match(r'^forecast\s+(?:for\s+)?(.+)$') | 302 | @match(r'^forecast\s+(?:for\s+)?(.+)$') |
1213 | 297 | def forecast(self, event, place): | 303 | def forecast(self, event, place): |
1214 | 298 | try: | 304 | try: |
1216 | 299 | event.addresponse(u', '.join(self.remote_forecast(place))) | 305 | event.addresponse(u'%s', u', '.join(self.remote_forecast(place))) |
1217 | 300 | except Weather.TooManyPlacesException, e: | 306 | except Weather.TooManyPlacesException, e: |
1219 | 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', { |
1220 | 308 | 'place': place, | ||
1221 | 309 | 'exception': u'; '.join(e.message), | ||
1222 | 310 | }) | ||
1223 | 302 | except Weather.WeatherException, e: | 311 | except Weather.WeatherException, e: |
1225 | 303 | event.addresponse(e.message) | 312 | event.addresponse(u'%s', e.message) |
1226 | 304 | 313 | ||
1227 | 305 | # vi: set et sta sw=4 ts=4: | 314 | # vi: set et sta sw=4 ts=4: |
1228 | 306 | 315 | ||
1229 | === modified file 'ibid/plugins/math.py' | |||
1230 | --- ibid/plugins/math.py 2009-03-02 09:38:47 +0000 | |||
1231 | +++ ibid/plugins/math.py 2009-03-08 13:16:28 +0000 | |||
1232 | @@ -30,12 +30,12 @@ | |||
1233 | 30 | if output: | 30 | if output: |
1234 | 31 | output = unicode_output(output.strip()) | 31 | output = unicode_output(output.strip()) |
1235 | 32 | output = output.replace('\\\n', '') | 32 | output = output.replace('\\\n', '') |
1237 | 33 | event.addresponse(output) | 33 | event.addresponse(u'%s', output) |
1238 | 34 | else: | 34 | else: |
1239 | 35 | error = unicode_output(error.strip()) | 35 | error = unicode_output(error.strip()) |
1240 | 36 | error = error.split(":", 1)[1].strip() | 36 | error = error.split(":", 1)[1].strip() |
1241 | 37 | error = error[0].lower() + error[1:] | 37 | error = error[0].lower() + error[1:] |
1243 | 38 | event.addresponse(u"You can't %s" % error) | 38 | event.addresponse(u"You can't %s", error) |
1244 | 39 | else: | 39 | else: |
1245 | 40 | event.addresponse(u"Error running bc") | 40 | event.addresponse(u"Error running bc") |
1246 | 41 | error = unicode_output(error.strip()) | 41 | error = unicode_output(error.strip()) |
1247 | @@ -70,17 +70,17 @@ | |||
1248 | 70 | event.addresponse(u"I can't divide by zero.") | 70 | event.addresponse(u"I can't divide by zero.") |
1249 | 71 | return | 71 | return |
1250 | 72 | except ArithmeticError, e: | 72 | except ArithmeticError, e: |
1252 | 73 | event.addresponse(u"I can't do that: %s" % e.message) | 73 | event.addresponse(u"I can't do that: %s", e.message) |
1253 | 74 | return | 74 | return |
1254 | 75 | except ValueError, e: | 75 | except ValueError, e: |
1255 | 76 | if e.message == "math domain error": | 76 | if e.message == "math domain error": |
1257 | 77 | event.addresponse(u"I can't do that: %s" % e.message) | 77 | event.addresponse(u"I can't do that: %s", e.message) |
1258 | 78 | return | 78 | return |
1259 | 79 | except Exception, e: | 79 | except Exception, e: |
1260 | 80 | return | 80 | return |
1261 | 81 | 81 | ||
1262 | 82 | if isinstance(result, (int, long, float, complex)): | 82 | if isinstance(result, (int, long, float, complex)): |
1264 | 83 | event.addresponse(unicode(result)) | 83 | event.addresponse(u'%s', result) |
1265 | 84 | 84 | ||
1266 | 85 | help['base'] = 'Convert numbers between bases (radixes)' | 85 | help['base'] = 'Convert numbers between bases (radixes)' |
1267 | 86 | class BaseConvert(Processor): | 86 | class BaseConvert(Processor): |
1268 | @@ -197,17 +197,19 @@ | |||
1269 | 197 | base_to = self._parse_base(base_to) | 197 | base_to = self._parse_base(base_to) |
1270 | 198 | 198 | ||
1271 | 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: |
1273 | 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') |
1274 | 201 | return | 201 | return |
1275 | 202 | 202 | ||
1276 | 203 | try: | 203 | try: |
1277 | 204 | number = self._from_base(number, base_from) | 204 | number = self._from_base(number, base_from) |
1278 | 205 | except ValueError, e: | 205 | except ValueError, e: |
1280 | 206 | event.addresponse(e.message) | 206 | event.addresponse(u'%s', e.message) |
1281 | 207 | return | 207 | return |
1282 | 208 | 208 | ||
1285 | 209 | event.addresponse(u"That is %s in %s." % | 209 | event.addresponse(u'That is %(result)s in %(base)s', { |
1286 | 210 | (self._in_base(number, base_to), self._base_name(base_to))) | 210 | 'result': self._in_base(number, base_to), |
1287 | 211 | 'base': self._base_name(base_to), | ||
1288 | 212 | }) | ||
1289 | 211 | 213 | ||
1290 | 212 | @handler | 214 | @handler |
1291 | 213 | def ascii_decode(self, event, text, base_to): | 215 | def ascii_decode(self, event, text, base_to): |
1292 | @@ -222,16 +224,19 @@ | |||
1293 | 222 | for char in text: | 224 | for char in text: |
1294 | 223 | code_point = ord(char) | 225 | code_point = ord(char) |
1295 | 224 | if code_point > 255: | 226 | if code_point > 255: |
1297 | 225 | output += u"U%s " % self._in_base(code_point, base_to) | 227 | output += u'U%s ' % self._in_base(code_point, base_to) |
1298 | 226 | else: | 228 | else: |
1299 | 227 | output += self._in_base(code_point, base_to) + u" " | 229 | output += self._in_base(code_point, base_to) + u" " |
1300 | 228 | 230 | ||
1301 | 229 | output = output.strip() | 231 | output = output.strip() |
1302 | 230 | 232 | ||
1304 | 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', { |
1305 | 234 | 'result': output, | ||
1306 | 235 | 'base': self._base_name(base_to), | ||
1307 | 236 | }) | ||
1308 | 232 | 237 | ||
1311 | 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']: |
1312 | 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') |
1313 | 235 | 240 | ||
1314 | 236 | @handler | 241 | @handler |
1315 | 237 | def ascii_encode(self, event, source, base_from): | 242 | def ascii_encode(self, event, source, base_from): |
1316 | @@ -266,11 +271,11 @@ | |||
1317 | 266 | if len(buf) > 0: | 271 | if len(buf) > 0: |
1318 | 267 | output += process_buf(buf) | 272 | output += process_buf(buf) |
1319 | 268 | except ValueError, e: | 273 | except ValueError, e: |
1321 | 269 | event.addresponse(e.message) | 274 | event.addresponse(u'%s', e.message) |
1322 | 270 | return | 275 | return |
1323 | 271 | 276 | ||
1327 | 272 | event.addresponse(u'That is "%s".' % output) | 277 | event.addresponse(u'That is "%s"', output) |
1328 | 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']: |
1329 | 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') |
1330 | 275 | 280 | ||
1331 | 276 | # vi: set et sta sw=4 ts=4: | 281 | # vi: set et sta sw=4 ts=4: |
1332 | 277 | 282 | ||
1333 | === modified file 'ibid/plugins/memo.py' | |||
1334 | --- ibid/plugins/memo.py 2009-03-01 23:01:30 +0000 | |||
1335 | +++ ibid/plugins/memo.py 2009-03-08 13:16:28 +0000 | |||
1336 | @@ -60,11 +60,11 @@ | |||
1337 | 60 | if not identity: | 60 | if not identity: |
1338 | 61 | identity = account.identities[0] | 61 | identity = account.identities[0] |
1339 | 62 | if not to: | 62 | if not to: |
1341 | 63 | event.addresponse(u"I don't know who %s is" % who) | 63 | event.addresponse(u"I don't know who %s is", who) |
1342 | 64 | return | 64 | return |
1343 | 65 | 65 | ||
1344 | 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': |
1346 | 67 | event.addresponse(u'Just tell %s yourself' % who) | 67 | event.addresponse(u'Just tell %s yourself', who) |
1347 | 68 | return | 68 | return |
1348 | 69 | 69 | ||
1349 | 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')) |
1350 | @@ -95,11 +95,22 @@ | |||
1351 | 95 | memos = get_memos(session, event) | 95 | memos = get_memos(session, event) |
1352 | 96 | 96 | ||
1353 | 97 | for memo in memos: | 97 | for memo in memos: |
1354 | 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)) | ||
1355 | 99 | if memo.private: | 98 | if memo.private: |
1356 | 99 | message = u'By the way, %(sender)s on %(source)s told me to tell you %(message)s %(ago)s ago' % { | ||
1357 | 100 | 'sender': memo.sender.identity, | ||
1358 | 101 | 'source': memo.sender.source, | ||
1359 | 102 | 'message': memo.memo, | ||
1360 | 103 | 'ago': ago(datetime.now()-memo.time), | ||
1361 | 104 | } | ||
1362 | 100 | event.addresponse({'reply': message, 'target': event.sender['id']}) | 105 | event.addresponse({'reply': message, 'target': event.sender['id']}) |
1363 | 101 | else: | 106 | else: |
1365 | 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', { |
1366 | 108 | 'recipient': event.sender['nick'], | ||
1367 | 109 | 'sender': memo.sender.identity, | ||
1368 | 110 | 'source': memo.sender.source, | ||
1369 | 111 | 'message': memo.memo, | ||
1370 | 112 | 'ago': ago(datetime.now()-memo.time), | ||
1371 | 113 | }) | ||
1372 | 103 | 114 | ||
1373 | 104 | memo.delivered = True | 115 | memo.delivered = True |
1374 | 105 | session.save_or_update(memo) | 116 | session.save_or_update(memo) |
1375 | @@ -128,7 +139,7 @@ | |||
1376 | 128 | memos = get_memos(session, event) | 139 | memos = get_memos(session, event) |
1377 | 129 | 140 | ||
1378 | 130 | if len(memos) > 0: | 141 | if len(memos) > 0: |
1380 | 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']}) |
1381 | 132 | else: | 143 | else: |
1382 | 133 | memo_cache[event.identity] = None | 144 | memo_cache[event.identity] = None |
1383 | 134 | 145 | ||
1384 | @@ -145,7 +156,7 @@ | |||
1385 | 145 | def messages(self, event): | 156 | def messages(self, event): |
1386 | 146 | session = ibid.databases.ibid() | 157 | session = ibid.databases.ibid() |
1387 | 147 | memos = get_memos(session, event, True) | 158 | memos = get_memos(session, event, True) |
1389 | 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])) |
1390 | 149 | session.close() | 160 | session.close() |
1391 | 150 | 161 | ||
1392 | 151 | @match(r'message\s+(\d+)$') | 162 | @match(r'message\s+(\d+)$') |
1393 | @@ -153,7 +164,12 @@ | |||
1394 | 153 | session = ibid.databases.ibid() | 164 | session = ibid.databases.ibid() |
1395 | 154 | memos = get_memos(session, event, True) | 165 | memos = get_memos(session, event, True) |
1396 | 155 | memo = memos[int(number)] | 166 | memo = memos[int(number)] |
1398 | 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", { |
1399 | 168 | 'sender': memo.sender.identity, | ||
1400 | 169 | 'source': memo.sender.source, | ||
1401 | 170 | 'time': memo.time.strftime(self.datetime_format), | ||
1402 | 171 | 'message': memo.memo, | ||
1403 | 172 | }) | ||
1404 | 157 | session.close() | 173 | session.close() |
1405 | 158 | 174 | ||
1406 | 159 | 175 | ||
1407 | 160 | 176 | ||
1408 | === modified file 'ibid/plugins/misc.py' | |||
1409 | --- ibid/plugins/misc.py 2009-03-03 22:52:47 +0000 | |||
1410 | +++ ibid/plugins/misc.py 2009-03-08 13:16:28 +0000 | |||
1411 | @@ -25,13 +25,13 @@ | |||
1412 | 25 | 25 | ||
1413 | 26 | self.pot = [event.sender['nick']] | 26 | self.pot = [event.sender['nick']] |
1414 | 27 | sleep(self.time) | 27 | sleep(self.time) |
1416 | 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)) |
1417 | 29 | self.pot = None | 29 | self.pot = None |
1418 | 30 | 30 | ||
1419 | 31 | @match('^coffee\s+(?:please|pls)$') | 31 | @match('^coffee\s+(?:please|pls)$') |
1420 | 32 | def coffee_accept(self, event): | 32 | def coffee_accept(self, event): |
1421 | 33 | if not self.pot: | 33 | if not self.pot: |
1423 | 34 | event.addresponse(u"There isn't a pot on.") | 34 | event.addresponse(u"There isn't a pot on") |
1424 | 35 | 35 | ||
1425 | 36 | elif len(self.pot) >= self.cups: | 36 | elif len(self.pot) >= self.cups: |
1426 | 37 | event.addresponse(u"Sorry, there aren't any more cups left") | 37 | event.addresponse(u"Sorry, there aren't any more cups left") |
1427 | @@ -47,7 +47,10 @@ | |||
1428 | 47 | 47 | ||
1429 | 48 | @match(r'^version$') | 48 | @match(r'^version$') |
1430 | 49 | def show_version(self, event): | 49 | def show_version(self, event): |
1432 | 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(): |
1433 | 51 | event.addresponse(u'I am version %s', ibid_version()) | ||
1434 | 52 | else: | ||
1435 | 53 | event.addresponse(u"I don't know what version I am :-(") | ||
1436 | 51 | 54 | ||
1437 | 52 | help['dvorak'] = u"Makes text typed on a QWERTY keyboard as if it was Dvorak work, and vice-versa" | 55 | help['dvorak'] = u"Makes text typed on a QWERTY keyboard as if it was Dvorak work, and vice-versa" |
1438 | 53 | class Dvorak(Processor): | 56 | class Dvorak(Processor): |
1439 | @@ -65,10 +68,10 @@ | |||
1440 | 65 | 68 | ||
1441 | 66 | @match(r'(?:asdf|dvorak)\s+(.+)') | 69 | @match(r'(?:asdf|dvorak)\s+(.+)') |
1442 | 67 | def convert_from_qwerty(self, event, text): | 70 | def convert_from_qwerty(self, event, text): |
1444 | 68 | event.addresponse(text.translate(self.typed_on_qwerty)) | 71 | event.addresponse(u'%s', text.translate(self.typed_on_qwerty)) |
1445 | 69 | 72 | ||
1446 | 70 | @match(r'(?:aoeu|qwerty)\s+(.+)') | 73 | @match(r'(?:aoeu|qwerty)\s+(.+)') |
1447 | 71 | def convert_from_dvorak(self, event, text): | 74 | def convert_from_dvorak(self, event, text): |
1449 | 72 | event.addresponse(text.translate(self.typed_on_dvorak)) | 75 | event.addresponse(u'%s', text.translate(self.typed_on_dvorak)) |
1450 | 73 | 76 | ||
1451 | 74 | # vi: set et sta sw=4 ts=4: | 77 | # vi: set et sta sw=4 ts=4: |
1452 | 75 | 78 | ||
1453 | === modified file 'ibid/plugins/morse.py' | |||
1454 | --- ibid/plugins/morse.py 2009-03-05 16:33:12 +0000 | |||
1455 | +++ ibid/plugins/morse.py 2009-03-08 13:16:28 +0000 | |||
1456 | @@ -70,12 +70,12 @@ | |||
1457 | 70 | 70 | ||
1458 | 71 | def morse2text(morse): | 71 | def morse2text(morse): |
1459 | 72 | rtable = dict((v, k) for k, v in table.items()) | 72 | rtable = dict((v, k) for k, v in table.items()) |
1461 | 73 | toks = morse.split(' ') | 73 | toks = morse.split(u' ') |
1462 | 74 | return u" ".join(rtable.get(t, t) for t in toks) | 74 | return u" ".join(rtable.get(t, t) for t in toks) |
1463 | 75 | 75 | ||
1464 | 76 | if message.replace('-', '').replace('.', '').isspace(): | 76 | if message.replace('-', '').replace('.', '').isspace(): |
1466 | 77 | event.addresponse(morse2text(message)) | 77 | event.addresponse(u'Decodes as %s', morse2text(message)) |
1467 | 78 | else: | 78 | else: |
1469 | 79 | event.addresponse(text2morse(message)) | 79 | event.addresponse(u'Encodes as %s', text2morse(message)) |
1470 | 80 | 80 | ||
1471 | 81 | # vi: set et sta sw=4 ts=4: | 81 | # vi: set et sta sw=4 ts=4: |
1472 | 82 | 82 | ||
1473 | === modified file 'ibid/plugins/network.py' | |||
1474 | --- ibid/plugins/network.py 2009-03-02 09:38:47 +0000 | |||
1475 | +++ ibid/plugins/network.py 2009-03-08 13:16:28 +0000 | |||
1476 | @@ -35,17 +35,20 @@ | |||
1477 | 35 | try: | 35 | try: |
1478 | 36 | answers = resolver.query(host, str(record)) | 36 | answers = resolver.query(host, str(record)) |
1479 | 37 | except NoAnswer: | 37 | except NoAnswer: |
1481 | 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", { |
1482 | 39 | 'type': record, | ||
1483 | 40 | 'host': host, | ||
1484 | 41 | }) | ||
1485 | 39 | return | 42 | return |
1486 | 40 | except NXDOMAIN: | 43 | except NXDOMAIN: |
1488 | 41 | event.addresponse(u"I couldn't find the domain %s" % host) | 44 | event.addresponse(u"I couldn't find the domain %s", host) |
1489 | 42 | return | 45 | return |
1490 | 43 | 46 | ||
1491 | 44 | responses = [] | 47 | responses = [] |
1492 | 45 | for rdata in answers: | 48 | for rdata in answers: |
1493 | 46 | responses.append(unicode(rdata)) | 49 | responses.append(unicode(rdata)) |
1494 | 47 | 50 | ||
1496 | 48 | event.addresponse(u', '.join(responses)) | 51 | event.addresponse(u'Records: %s', u', '.join(responses)) |
1497 | 49 | 52 | ||
1498 | 50 | help['ping'] = u'ICMP pings the specified host.' | 53 | help['ping'] = u'ICMP pings the specified host.' |
1499 | 51 | class Ping(Processor): | 54 | class Ping(Processor): |
1500 | @@ -69,11 +72,12 @@ | |||
1501 | 69 | code = ping.wait() | 72 | code = ping.wait() |
1502 | 70 | 73 | ||
1503 | 71 | if code == 0: | 74 | if code == 0: |
1506 | 72 | output = unicode_output(' '.join(output.splitlines()[-2:])) | 75 | output = unicode_output(output) |
1507 | 73 | event.addresponse(output) | 76 | output = u' '.join(output.splitlines()[-2:]) |
1508 | 77 | event.addresponse(u'%s', output) | ||
1509 | 74 | else: | 78 | else: |
1512 | 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() |
1513 | 76 | event.addresponse(error) | 80 | event.addresponse(u'Error: %s', error) |
1514 | 77 | 81 | ||
1515 | 78 | help['tracepath'] = u'Traces the path to the given host.' | 82 | help['tracepath'] = u'Traces the path to the given host.' |
1516 | 79 | class Tracepath(Processor): | 83 | class Tracepath(Processor): |
1517 | @@ -96,10 +100,10 @@ | |||
1518 | 96 | if code == 0: | 100 | if code == 0: |
1519 | 97 | output = unicode_output(output) | 101 | output = unicode_output(output) |
1520 | 98 | for line in output.splitlines(): | 102 | for line in output.splitlines(): |
1522 | 99 | event.addresponse(line) | 103 | event.addresponse(u'%s', line) |
1523 | 100 | else: | 104 | else: |
1524 | 101 | error = unicode_output(error.strip()) | 105 | error = unicode_output(error.strip()) |
1526 | 102 | event.addresponse(error.replace('\n', ' ')) | 106 | event.addresponse(u'Error: %s', error.replace(u'\n', u' ')) |
1527 | 103 | 107 | ||
1528 | 104 | help['ipcalc'] = u'IP address calculator' | 108 | help['ipcalc'] = u'IP address calculator' |
1529 | 105 | class IPCalc(Processor): | 109 | class IPCalc(Processor): |
1530 | @@ -133,14 +137,14 @@ | |||
1531 | 133 | 137 | ||
1532 | 134 | if code == 0: | 138 | if code == 0: |
1533 | 135 | output = unicode_output(output) | 139 | output = unicode_output(output) |
1535 | 136 | if output.startswith("INVALID ADDRESS"): | 140 | if output.startswith(u"INVALID ADDRESS"): |
1536 | 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") |
1537 | 138 | else: | 142 | else: |
1538 | 139 | for line in output.splitlines(): | 143 | for line in output.splitlines(): |
1539 | 140 | if line.strip(): | 144 | if line.strip(): |
1541 | 141 | event.addresponse(line) | 145 | event.addresponse(u'%s', line) |
1542 | 142 | else: | 146 | else: |
1543 | 143 | error = unicode_output(error.strip()) | 147 | error = unicode_output(error.strip()) |
1545 | 144 | event.addresponse(error.replace('\n', ' ')) | 148 | event.addresponse(u'%s', error.replace(u'\n', u' ')) |
1546 | 145 | 149 | ||
1547 | 146 | # vi: set et sta sw=4 ts=4: | 150 | # vi: set et sta sw=4 ts=4: |
1548 | 147 | 151 | ||
1549 | === modified file 'ibid/plugins/rfc.py' | |||
1550 | --- ibid/plugins/rfc.py 2009-03-05 12:23:21 +0000 | |||
1551 | +++ ibid/plugins/rfc.py 2009-03-08 13:16:28 +0000 | |||
1552 | @@ -157,9 +157,12 @@ | |||
1553 | 157 | 157 | ||
1554 | 158 | number = int(number) | 158 | number = int(number) |
1555 | 159 | if number in rfcs: | 159 | if number in rfcs: |
1557 | 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", { |
1558 | 161 | 'record': rfcs[number].record, | ||
1559 | 162 | 'number': number, | ||
1560 | 163 | }) | ||
1561 | 161 | else: | 164 | else: |
1563 | 162 | event.addresponse(u"Sorry, no such RFC.") | 165 | event.addresponse(u"Sorry, no such RFC") |
1564 | 163 | 166 | ||
1565 | 164 | @match(r'^rfc\s+(?:for\s+)?(.+)$') | 167 | @match(r'^rfc\s+(?:for\s+)?(.+)$') |
1566 | 165 | def search(self, event, terms): | 168 | def search(self, event, terms): |
1567 | @@ -188,14 +191,16 @@ | |||
1568 | 188 | pool.reverse() | 191 | pool.reverse() |
1569 | 189 | 192 | ||
1570 | 190 | if pool: | 193 | if pool: |
1571 | 191 | response = u"Found %i matching RFC%s. Listing %i: " % (len(pool), len(pool) > 1 and u"s" or u"", min(len(pool), 5)) | ||
1572 | 192 | results = [] | 194 | results = [] |
1573 | 193 | for result in pool[:5]: | 195 | for result in pool[:5]: |
1574 | 194 | result.parse() | 196 | result.parse() |
1575 | 195 | results.append("%04i: %s" % (result.number, result.summary)) | 197 | results.append("%04i: %s" % (result.number, result.summary)) |
1578 | 196 | response += u", ".join(results) | 198 | event.addresponse(u'Found %(found)i matching RFCs. Listing %(listing)i: %(results)', { |
1579 | 197 | event.addresponse(response) | 199 | 'found': len(pool), |
1580 | 200 | 'listing': min(len(pool), 5), | ||
1581 | 201 | 'results': u', '.join(results), | ||
1582 | 202 | }) | ||
1583 | 198 | else: | 203 | else: |
1585 | 199 | event.addresponse(u"Sorry, can't find anything.") | 204 | event.addresponse(u"Sorry, can't find anything") |
1586 | 200 | 205 | ||
1587 | 201 | # vi: set et sta sw=4 ts=4: | 206 | # vi: set et sta sw=4 ts=4: |
1588 | 202 | 207 | ||
1589 | === modified file 'ibid/plugins/roshambo.py' | |||
1590 | --- ibid/plugins/roshambo.py 2009-03-02 09:21:35 +0000 | |||
1591 | +++ ibid/plugins/roshambo.py 2009-03-08 13:16:28 +0000 | |||
1592 | @@ -17,12 +17,12 @@ | |||
1593 | 17 | bchoice = randint(0, 2) | 17 | bchoice = randint(0, 2) |
1594 | 18 | 18 | ||
1595 | 19 | if uchoice == bchoice: | 19 | if uchoice == bchoice: |
1597 | 20 | reply = u'We drew! I also chose %s' % choices[bchoice] | 20 | reply = u'We drew! I also chose %s' |
1598 | 21 | elif (uchoice + 1) % 3 == bchoice: | 21 | elif (uchoice + 1) % 3 == bchoice: |
1600 | 22 | reply = u'You win! I chose %s :-(' % choices[bchoice] | 22 | reply = u'You win! I chose %s :-(' |
1601 | 23 | else: | 23 | else: |
1603 | 24 | reply = u'I win! I chose %s' % choices[bchoice] | 24 | reply = u'I win! I chose %s' |
1604 | 25 | 25 | ||
1606 | 26 | event.addresponse(reply) | 26 | event.addresponse(reply, choices[bchoice]) |
1607 | 27 | 27 | ||
1608 | 28 | # vi: set et sta sw=4 ts=4: | 28 | # vi: set et sta sw=4 ts=4: |
1609 | 29 | 29 | ||
1610 | === modified file 'ibid/plugins/seen.py' | |||
1611 | --- ibid/plugins/seen.py 2009-03-02 09:21:35 +0000 | |||
1612 | +++ ibid/plugins/seen.py 2009-03-08 13:16:28 +0000 | |||
1613 | @@ -82,7 +82,7 @@ | |||
1614 | 82 | account = session.query(Account).filter_by(username=who).first() | 82 | account = session.query(Account).filter_by(username=who).first() |
1615 | 83 | 83 | ||
1616 | 84 | if not identity and not account: | 84 | if not identity and not account: |
1618 | 85 | event.addresponse(u"I don't know who %s is" % who) | 85 | event.addresponse(u"I don't know who %s is", who) |
1619 | 86 | return | 86 | return |
1620 | 87 | 87 | ||
1621 | 88 | messages = [] | 88 | messages = [] |
1622 | @@ -102,26 +102,26 @@ | |||
1623 | 102 | states.append(sighting) | 102 | states.append(sighting) |
1624 | 103 | 103 | ||
1625 | 104 | if len(messages) == 0 and len(states) == 0: | 104 | if len(messages) == 0 and len(states) == 0: |
1627 | 105 | event.addresponse(u"I haven't seen %s" % who) | 105 | event.addresponse(u"I haven't seen %s", who) |
1628 | 106 | return | 106 | return |
1629 | 107 | 107 | ||
1630 | 108 | messages.sort(key=lambda x: x.time, reverse=True) | 108 | messages.sort(key=lambda x: x.time, reverse=True) |
1631 | 109 | states.sort(key=lambda x: x.time, reverse=True) | 109 | states.sort(key=lambda x: x.time, reverse=True) |
1632 | 110 | 110 | ||
1634 | 111 | reply = '' | 111 | reply = u'' |
1635 | 112 | if len(messages) > 0: | 112 | if len(messages) > 0: |
1636 | 113 | sighting = messages[0] | 113 | sighting = messages[0] |
1637 | 114 | delta = datetime.now() - sighting.time | 114 | delta = datetime.now() - sighting.time |
1638 | 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) |
1640 | 116 | reply = u'%s [%s]' % (reply, sighting.time.strftime(self.datetime_format)) | 116 | reply += u' [%s]' % sighting.time.strftime(self.datetime_format) |
1641 | 117 | 117 | ||
1642 | 118 | if len(states) > 0: | 118 | if len(states) > 0: |
1643 | 119 | sighting = states[0] | 119 | sighting = states[0] |
1644 | 120 | if reply: | 120 | if reply: |
1646 | 121 | reply = reply + u', and' | 121 | reply += u', and' |
1647 | 122 | else: | 122 | else: |
1648 | 123 | reply = who | 123 | reply = who |
1650 | 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)) |
1651 | 125 | 125 | ||
1652 | 126 | event.addresponse(reply) | 126 | event.addresponse(reply) |
1653 | 127 | session.close() | 127 | session.close() |
1654 | 128 | 128 | ||
1655 | === modified file 'ibid/plugins/sources.py' | |||
1656 | --- ibid/plugins/sources.py 2009-03-01 23:01:30 +0000 | |||
1657 | +++ ibid/plugins/sources.py 2009-03-08 13:16:28 +0000 | |||
1658 | @@ -15,26 +15,26 @@ | |||
1659 | 15 | def connect(self, event, source): | 15 | def connect(self, event, source): |
1660 | 16 | 16 | ||
1661 | 17 | if ibid.sources[source.lower()].connect(): | 17 | if ibid.sources[source.lower()].connect(): |
1663 | 18 | event.addresponse(u'Connecting to %s' % source) | 18 | event.addresponse(u'Connecting to %s', source) |
1664 | 19 | else: | 19 | else: |
1666 | 20 | event.addresponse(u"I couldn't connect to %s" % source) | 20 | event.addresponse(u"I couldn't connect to %s", source) |
1667 | 21 | 21 | ||
1668 | 22 | @match(r'^disconnect\s+(?:from\s+)?(\S+)$') | 22 | @match(r'^disconnect\s+(?:from\s+)?(\S+)$') |
1669 | 23 | @authorise | 23 | @authorise |
1670 | 24 | def disconnect(self, event, source): | 24 | def disconnect(self, event, source): |
1671 | 25 | 25 | ||
1672 | 26 | if ibid.sources[source.lower()].disconnect(): | 26 | if ibid.sources[source.lower()].disconnect(): |
1674 | 27 | event.addresponse(u'Disconnecting from %s' % source) | 27 | event.addresponse(u'Disconnecting from %s', source) |
1675 | 28 | else: | 28 | else: |
1677 | 29 | event.addresponse(u"I couldn't disconnect from %s" % source) | 29 | event.addresponse(u"I couldn't disconnect from %s", source) |
1678 | 30 | 30 | ||
1679 | 31 | @match(r'^(?:re)?load\s+(\S+)\s+source$') | 31 | @match(r'^(?:re)?load\s+(\S+)\s+source$') |
1680 | 32 | @authorise | 32 | @authorise |
1681 | 33 | def load(self, event, source): | 33 | def load(self, event, source): |
1682 | 34 | if ibid.reloader.load_source(source, ibid.service): | 34 | if ibid.reloader.load_source(source, ibid.service): |
1684 | 35 | event.addresponse(u"%s source loaded" % source) | 35 | event.addresponse(u"%s source loaded", source) |
1685 | 36 | else: | 36 | else: |
1687 | 37 | event.addresponse(u"Couldn't load %s source" % source) | 37 | event.addresponse(u"Couldn't load %s source", source) |
1688 | 38 | 38 | ||
1689 | 39 | class Info(Processor): | 39 | class Info(Processor): |
1690 | 40 | u"""(sources|list configured sources)""" | 40 | u"""(sources|list configured sources)""" |
1691 | @@ -45,11 +45,11 @@ | |||
1692 | 45 | sources = [] | 45 | sources = [] |
1693 | 46 | for name, source in ibid.sources.items(): | 46 | for name, source in ibid.sources.items(): |
1694 | 47 | url = source.url() | 47 | url = source.url() |
1697 | 48 | sources.append(url and '%s (%s)' % (name, url) or name) | 48 | sources.append(url and u'%s (%s)' % (name, url) or name) |
1698 | 49 | event.addresponse(u', '.join(sources)) | 49 | event.addresponse(u'Sources: %s', u', '.join(sorted(sources))) |
1699 | 50 | 50 | ||
1700 | 51 | @match(r'^list\s+configured\s+sources$') | 51 | @match(r'^list\s+configured\s+sources$') |
1701 | 52 | def listall(self, event): | 52 | def listall(self, event): |
1703 | 53 | event.addresponse(', '.join(ibid.config.sources.keys())) | 53 | event.addresponse(u'Configured sources: %s', u', '.join(sorted(ibid.config.sources.keys()))) |
1704 | 54 | 54 | ||
1705 | 55 | # vi: set et sta sw=4 ts=4: | 55 | # vi: set et sta sw=4 ts=4: |
1706 | 56 | 56 | ||
1707 | === modified file 'ibid/plugins/test.py' | |||
1708 | --- ibid/plugins/test.py 2009-03-01 14:29:51 +0000 | |||
1709 | +++ ibid/plugins/test.py 2009-03-08 13:16:28 +0000 | |||
1710 | @@ -8,7 +8,7 @@ | |||
1711 | 8 | @match(r'^delay\s+(\d+\.?\d*)$') | 8 | @match(r'^delay\s+(\d+\.?\d*)$') |
1712 | 9 | def handler(self, event, delay): | 9 | def handler(self, event, delay): |
1713 | 10 | sleep(float(delay)) | 10 | sleep(float(delay)) |
1715 | 11 | event.addresponse('Done') | 11 | event.addresponse(True) |
1716 | 12 | 12 | ||
1717 | 13 | class Authorise(Processor): | 13 | class Authorise(Processor): |
1718 | 14 | 14 | ||
1719 | @@ -23,14 +23,14 @@ | |||
1720 | 23 | 23 | ||
1721 | 24 | @match(r'^email\s+(.+)$') | 24 | @match(r'^email\s+(.+)$') |
1722 | 25 | def email(self, event, address): | 25 | def email(self, event, address): |
1725 | 26 | event.addresponse({'reply': 'Test message', 'source': 'email', 'target': unicode(address)}) | 26 | event.addresponse({'reply': u'Test message', 'source': 'email', 'target': unicode(address)}) |
1726 | 27 | event.addresponse(u"I've emailed %s" % address) | 27 | event.addresponse(u"I've emailed %s", address) |
1727 | 28 | 28 | ||
1728 | 29 | class Except(Processor): | 29 | class Except(Processor): |
1729 | 30 | 30 | ||
1730 | 31 | @match(r'^raise\s+exception$') | 31 | @match(r'^raise\s+exception$') |
1731 | 32 | def handler(self, event): | 32 | def handler(self, event): |
1733 | 33 | event.addresponse("I'll except in a moment") | 33 | event.addresponse(u"I'll except in a moment") |
1734 | 34 | raise Exception("Ow, that hurt.") | 34 | raise Exception("Ow, that hurt.") |
1735 | 35 | 35 | ||
1736 | 36 | # vi: set et sta sw=4 ts=4: | 36 | # vi: set et sta sw=4 ts=4: |
1737 | 37 | 37 | ||
1738 | === modified file 'ibid/plugins/tools.py' | |||
1739 | --- ibid/plugins/tools.py 2009-03-02 09:38:47 +0000 | |||
1740 | +++ ibid/plugins/tools.py 2009-03-08 13:16:28 +0000 | |||
1741 | @@ -25,11 +25,11 @@ | |||
1742 | 25 | @match('^rand(?:om)?(?:\s+(\d+)(?:\s+(\d+))?)?$') | 25 | @match('^rand(?:om)?(?:\s+(\d+)(?:\s+(\d+))?)?$') |
1743 | 26 | def random(self, event, begin, end): | 26 | def random(self, event, begin, end): |
1744 | 27 | if not begin and not end: | 27 | if not begin and not end: |
1746 | 28 | event.addresponse(unicode(random())) | 28 | event.addresponse(u'I always liked %f', random()) |
1747 | 29 | else: | 29 | else: |
1748 | 30 | begin = int(begin) | 30 | begin = int(begin) |
1749 | 31 | end = end and int(end) or 0 | 31 | end = end and int(end) or 0 |
1751 | 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))) |
1752 | 33 | 33 | ||
1753 | 34 | help['units'] = 'Converts values between various units.' | 34 | help['units'] = 'Converts values between various units.' |
1754 | 35 | class Units(Processor): | 35 | class Units(Processor): |
1755 | @@ -91,13 +91,20 @@ | |||
1756 | 91 | result = output.splitlines()[0].strip() | 91 | result = output.splitlines()[0].strip() |
1757 | 92 | 92 | ||
1758 | 93 | if code == 0: | 93 | if code == 0: |
1760 | 94 | event.addresponse(result) | 94 | event.addresponse(u'%s', result) |
1761 | 95 | elif code == 1: | 95 | elif code == 1: |
1762 | 96 | if result == "conformability error": | 96 | if result == "conformability error": |
1764 | 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", { |
1765 | 98 | 'from': frm, | ||
1766 | 99 | 'to': to, | ||
1767 | 100 | }) | ||
1768 | 98 | elif result.startswith("conformability error"): | 101 | elif result.startswith("conformability error"): |
1770 | 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", { |
1771 | 103 | 'from': frm, | ||
1772 | 104 | 'to': to, | ||
1773 | 105 | 'error': result.split(":", 1)[1], | ||
1774 | 106 | }) | ||
1775 | 100 | else: | 107 | else: |
1777 | 101 | event.addresponse(u"I can't do that: %s" % result) | 108 | event.addresponse(u"I can't do that: %s", result) |
1778 | 102 | 109 | ||
1779 | 103 | # vi: set et sta sw=4 ts=4: | 110 | # vi: set et sta sw=4 ts=4: |
1780 | 104 | 111 | ||
1781 | === modified file 'ibid/plugins/trac.py' | |||
1782 | --- ibid/plugins/trac.py 2009-03-06 13:50:19 +0000 | |||
1783 | +++ ibid/plugins/trac.py 2009-03-08 13:16:28 +0000 | |||
1784 | @@ -77,7 +77,19 @@ | |||
1785 | 77 | ticket = self.get_ticket(int(number)) | 77 | ticket = self.get_ticket(int(number)) |
1786 | 78 | 78 | ||
1787 | 79 | if ticket: | 79 | if ticket: |
1789 | 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) ' |
1790 | 81 | u'reported %(ago)s ago assigned to %(owner)s: "%(summary)s" %(url)sticket/%(id)s', { | ||
1791 | 82 | 'id': ticket.id, | ||
1792 | 83 | 'status': ticket.status, | ||
1793 | 84 | 'priority': ticket.priority, | ||
1794 | 85 | 'type': ticket.type, | ||
1795 | 86 | 'component': ticket.component, | ||
1796 | 87 | 'milestone': ticket.milestone, | ||
1797 | 88 | 'ago': ago(datetime.now() - datetime.fromtimestamp(ticket.time), 2), | ||
1798 | 89 | 'owner': ticket.owner, | ||
1799 | 90 | 'summary': ticket.summary, | ||
1800 | 91 | 'url': self.url, | ||
1801 | 92 | }) | ||
1802 | 81 | else: | 93 | else: |
1803 | 82 | event.addresponse(u"No such ticket") | 94 | event.addresponse(u"No such ticket") |
1804 | 83 | 95 | ||
1805 | @@ -108,7 +120,7 @@ | |||
1806 | 108 | tickets = query.order_by(Ticket.id).all() | 120 | tickets = query.order_by(Ticket.id).all() |
1807 | 109 | 121 | ||
1808 | 110 | if len(tickets) > 0: | 122 | if len(tickets) > 0: |
1810 | 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])) |
1811 | 112 | else: | 124 | else: |
1812 | 113 | event.addresponse(u"No tickets found") | 125 | event.addresponse(u"No tickets found") |
1813 | 114 | 126 | ||
1814 | 115 | 127 | ||
1815 | === modified file 'ibid/plugins/url.py' | |||
1816 | --- ibid/plugins/url.py 2009-03-01 23:01:30 +0000 | |||
1817 | +++ ibid/plugins/url.py 2009-03-08 13:16:28 +0000 | |||
1818 | @@ -56,7 +56,7 @@ | |||
1819 | 56 | shortened = f.read() | 56 | shortened = f.read() |
1820 | 57 | f.close() | 57 | f.close() |
1821 | 58 | 58 | ||
1823 | 59 | event.addresponse(unicode(shortened)) | 59 | event.addresponse(u'That reduces to: %s', shortened) |
1824 | 60 | 60 | ||
1825 | 61 | class NullRedirect(HTTPRedirectHandler): | 61 | class NullRedirect(HTTPRedirectHandler): |
1826 | 62 | 62 | ||
1827 | @@ -83,7 +83,7 @@ | |||
1828 | 83 | f = opener.open(url) | 83 | f = opener.open(url) |
1829 | 84 | except HTTPError, e: | 84 | except HTTPError, e: |
1830 | 85 | if e.code in (301, 302, 303, 307): | 85 | if e.code in (301, 302, 303, 307): |
1832 | 86 | event.addresponse(unicode(e.hdrs['location'])) | 86 | event.addresponse(u'That expands to: %s', e.hdrs['location']) |
1833 | 87 | return | 87 | return |
1834 | 88 | 88 | ||
1835 | 89 | f.close() | 89 | f.close() |
My take on https:/ /code.edge. launchpad. net/~bradwhitti ngton/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.