|
1 local st = require "util.stanza"; |
|
2 require "util.xstanza"; |
|
3 |
|
4 local xmlns_version = "jabber:iq:version"; |
|
5 |
|
6 function riddim.plugins.version(bot) |
|
7 bot.stream:add_plugin("version"); |
|
8 bot.stream.version:set{ |
|
9 name = "Riddim"; |
|
10 version = "alpha"; |
|
11 }; |
|
12 |
|
13 bot:hook("commands/version", function (command) |
|
14 local who, param = bot.stream.jid, command.param or (command.room and command.room.nick); |
|
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 |
|
25 bot.stream:query_version(who, |
|
26 function (reply) |
|
27 if not reply.error then |
|
28 local saywho = (who == command.sender.jid and "You are") or (param.." is"); |
|
29 command:reply(saywho.." running "..(reply.name or "something") |
|
30 .." version "..(reply.version or "unknown") |
|
31 .." on "..(reply.platform or "an unknown platform")); |
|
32 else |
|
33 local type, condition, text = reply.type, reply.condition, reply.text; |
|
34 local r = "There was an error requesting "..param.."'s version"; |
|
35 if condition == "service-unavailable" then |
|
36 r = param.." doesn't reply to version 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; |
|
41 end |
|
42 if text then |
|
43 r = r .. " ("..text..")"; |
|
44 end |
|
45 command:reply(r); |
|
46 end |
|
47 end); |
|
48 return true; |
|
49 end); |
|
50 end |