plugins/version.lua

Sun, 06 Jul 2014 15:36:18 +0200

author
Kim Alvefur <zash@zash.se>
date
Sun, 06 Jul 2014 15:36:18 +0200
changeset 113
5f2418fb8b19
parent 105
4234c8789cc6
child 125
2c570064f582
permissions
-rw-r--r--

plugins.version: example.com doesn't support *version* requests, not feature requests

0
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local st = require "util.stanza";
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local xmlns_version = "jabber:iq:version";
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 function riddim.plugins.version(bot)
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 bot.stream:add_plugin("version");
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 bot.stream.version:set{
76
cecdfba8e625 plugins/version improvements
mva <mva@mva.name>
parents: 37
diff changeset
8 name = bot.config.bot_name or "Riddim";
cecdfba8e625 plugins/version improvements
mva <mva@mva.name>
parents: 37
diff changeset
9 version = bot.config.bot_version or "alpha";
cecdfba8e625 plugins/version improvements
mva <mva@mva.name>
parents: 37
diff changeset
10 platform = bot.config.bot_platform or _VERSION;
0
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 };
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12
105
4234c8789cc6 plugins.{ping,version,resolvejid}: Break nickname/jid resolving into a common plugin
Kim Alvefur <zash@zash.se>
parents: 76
diff changeset
13 bot:add_plugin("resolvejid");
0
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 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
15 local who, param = bot.stream.jid, command.param;
0
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 if param then
105
4234c8789cc6 plugins.{ping,version,resolvejid}: Break nickname/jid resolving into a common plugin
Kim Alvefur <zash@zash.se>
parents: 76
diff changeset
17 who = bot:resolvejid(param, command.room);
0
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 end
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
20 bot.stream:query_version(who, function (reply)
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
21 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
22 local saywho = (who == command.sender.jid and "You are") or (param and param.." is" or "I am");
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
23 command:reply(saywho.." running "..(reply.name or "something")
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
24 .." version "..(reply.version or "unknown")
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
25 .." on "..(reply.platform or "an unknown platform"));
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
26 else
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
27 local type, condition, text = reply.type, reply.condition, reply.text;
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
28 local r = "There was an error requesting "..param.."'s version";
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
29 if condition == "service-unavailable" then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
30 r = param.." doesn't reply to version requests";
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
31 elseif condition == "feature-not-implemented" then
113
5f2418fb8b19 plugins.version: example.com doesn't support *version* requests, not feature requests
Kim Alvefur <zash@zash.se>
parents: 105
diff changeset
32 r = param.." doesn't support version requests";
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
33 elseif condition == "remote-server-not-found" then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
34 r = param.." can't be reached via XMPP";
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
35 elseif condition and not text then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
36 r = r..": "..condition;
0
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 end
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
38 if text then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
39 r = r .. " ("..text..")";
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
40 end
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
41 command:reply(r);
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
42 end
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
43 end);
0
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 return true;
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 end);
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 end

mercurial