Mon, 21 Feb 2011 16:12:13 +0100
plugins.xkcd: Escape parentheses in search queries
0 | 1 | local st = require "util.stanza"; |
2 | ||
3 | local xmlns_version = "jabber:iq:version"; | |
4 | ||
5 | function riddim.plugins.version(bot) | |
6 | bot.stream:add_plugin("version"); | |
7 | bot.stream.version:set{ | |
8 | name = "Riddim"; | |
9 | version = "alpha"; | |
10 | }; | |
11 | ||
12 | bot:hook("commands/version", function (command) | |
37
85b3f2a96edb
plugins.version: Report own version in first person, and don't crash if it's not in a room
Kim Alvefur <zash@zash.se>
parents:
33
diff
changeset
|
13 | local who, param = bot.stream.jid, command.param; |
0 | 14 | if param then |
15 | if command.room and command.room.occupants[param] then | |
16 | who = command.room.occupants[param].jid; | |
17 | elseif command.room and command.room.occupants[param:gsub("%s$", "")] then | |
18 | who = command.room.occupants[param:gsub("%s$", "")].jid; | |
19 | else | |
20 | who = param; | |
21 | end | |
22 | end | |
23 | ||
16 | 24 | bot.stream:query_version(who, function (reply) |
25 | if not reply.error then | |
37
85b3f2a96edb
plugins.version: Report own version in first person, and don't crash if it's not in a room
Kim Alvefur <zash@zash.se>
parents:
33
diff
changeset
|
26 | local saywho = (who == command.sender.jid and "You are") or (param and param.." is" or "I am"); |
16 | 27 | command:reply(saywho.." running "..(reply.name or "something") |
28 | .." version "..(reply.version or "unknown") | |
29 | .." on "..(reply.platform or "an unknown platform")); | |
30 | else | |
31 | local type, condition, text = reply.type, reply.condition, reply.text; | |
32 | local r = "There was an error requesting "..param.."'s version"; | |
33 | if condition == "service-unavailable" then | |
34 | r = param.." doesn't reply to version requests"; | |
35 | elseif condition == "feature-not-implemented" then | |
36 | r = param.." doesn't support feature requests"; | |
37 | elseif condition == "remote-server-not-found" then | |
38 | r = param.." can't be reached via XMPP"; | |
39 | elseif condition and not text then | |
40 | r = r..": "..condition; | |
0 | 41 | end |
16 | 42 | if text then |
43 | r = r .. " ("..text..")"; | |
44 | end | |
45 | command:reply(r); | |
46 | end | |
47 | end); | |
0 | 48 | return true; |
49 | end); | |
50 | end |