plugins/version.lua

Thu, 14 Oct 2010 13:21:55 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 14 Oct 2010 13:21:55 +0100
changeset 33
37caf7bd2021
parent 16
ae69cea97598
child 37
85b3f2a96edb
permissions
-rw-r--r--

plugins.version, plugins.command: Remove obsolete require 'util.xstanza'

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{
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 name = "Riddim";
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 version = "alpha";
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 };
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 bot:hook("commands/version", function (command)
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local who, param = bot.stream.jid, command.param or (command.room and command.room.nick);
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 if param then
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 if command.room and command.room.occupants[param] then
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 who = command.room.occupants[param].jid;
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 elseif command.room and command.room.occupants[param:gsub("%s$", "")] then
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 who = command.room.occupants[param:gsub("%s$", "")].jid;
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 else
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 who = param;
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 end
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 end
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
24 bot.stream:query_version(who, function (reply)
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
25 if not reply.error then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
26 local saywho = (who == command.sender.jid and "You are") or (param.." is");
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
27 command:reply(saywho.." running "..(reply.name or "something")
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
28 .." version "..(reply.version or "unknown")
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
29 .." on "..(reply.platform or "an unknown platform"));
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
30 else
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
31 local type, condition, text = reply.type, reply.condition, reply.text;
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
32 local r = "There was an error requesting "..param.."'s version";
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
33 if condition == "service-unavailable" then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
34 r = param.." doesn't reply to version requests";
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
35 elseif condition == "feature-not-implemented" then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
36 r = param.." doesn't support feature requests";
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
37 elseif condition == "remote-server-not-found" then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
38 r = param.." can't be reached via XMPP";
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
39 elseif condition and not text then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
40 r = r..": "..condition;
0
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 end
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
42 if text then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
43 r = r .. " ("..text..")";
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
44 end
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
45 command:reply(r);
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
46 end
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
47 end);
0
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 return true;
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 end);
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 end

mercurial