Thu, 20 May 2010 13:45:53 +0100
plugins.tell: Change responses (thanks Flo)
0 | 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"; | |
7
59129c1e4e07
plugins.version: Friendly message for feature-not-implemented
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
37 | elseif condition == "feature-not-implemented" then |
59129c1e4e07
plugins.version: Friendly message for feature-not-implemented
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
38 | r = param.." doesn't support feature requests"; |
0 | 39 | elseif condition == "remote-server-not-found" then |
7
59129c1e4e07
plugins.version: Friendly message for feature-not-implemented
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
40 | r = param.." can't be reached via XMPP"; |
0 | 41 | elseif condition and not text then |
42 | r = r..": "..condition; | |
43 | end | |
44 | if text then | |
45 | r = r .. " ("..text..")"; | |
46 | end | |
47 | command:reply(r); | |
48 | end | |
49 | end); | |
50 | return true; | |
51 | end); | |
52 | end |