Sun, 24 Jul 2011 19:16:40 +0700
plugins/version improvements
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{ | |
76 | 8 | name = bot.config.bot_name or "Riddim"; |
9 | version = bot.config.bot_version or "alpha"; | |
10 | platform = bot.config.bot_platform or _VERSION; | |
0 | 11 | }; |
12 | ||
13 | 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
|
14 | local who, param = bot.stream.jid, command.param; |
0 | 15 | if param then |
16 | if command.room and command.room.occupants[param] then | |
17 | who = command.room.occupants[param].jid; | |
18 | elseif command.room and command.room.occupants[param:gsub("%s$", "")] then | |
19 | who = command.room.occupants[param:gsub("%s$", "")].jid; | |
20 | else | |
21 | who = param; | |
22 | end | |
23 | end | |
24 | ||
16 | 25 | bot.stream:query_version(who, function (reply) |
26 | 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
|
27 | local saywho = (who == command.sender.jid and "You are") or (param and param.." is" or "I am"); |
16 | 28 | command:reply(saywho.." running "..(reply.name or "something") |
29 | .." version "..(reply.version or "unknown") | |
30 | .." on "..(reply.platform or "an unknown platform")); | |
31 | else | |
32 | local type, condition, text = reply.type, reply.condition, reply.text; | |
33 | local r = "There was an error requesting "..param.."'s version"; | |
34 | if condition == "service-unavailable" then | |
35 | r = param.." doesn't reply to version requests"; | |
36 | elseif condition == "feature-not-implemented" then | |
37 | r = param.." doesn't support feature requests"; | |
38 | elseif condition == "remote-server-not-found" then | |
39 | r = param.." can't be reached via XMPP"; | |
40 | elseif condition and not text then | |
41 | r = r..": "..condition; | |
0 | 42 | end |
16 | 43 | if text then |
44 | r = r .. " ("..text..")"; | |
45 | end | |
46 | command:reply(r); | |
47 | end | |
48 | end); | |
0 | 49 | return true; |
50 | end); | |
51 | end |