plugins/ping.lua

Tue, 12 Jul 2011 15:39:25 +0200

author
Kim Alvefur <zash@zash.se>
date
Tue, 12 Jul 2011 15:39:25 +0200
changeset 82
ec22d6deb6c0
parent 16
ae69cea97598
child 105
4234c8789cc6
permissions
-rw-r--r--

plugins.invited: Move xmlns-es to variables.

0
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 function riddim.plugins.ping(bot)
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 bot.stream:add_plugin("ping");
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 bot:hook("commands/ping", function (command)
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
5 local jid = command.param;
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
6 if jid then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
7 bot.stream:ping(jid, function (time, jid, error)
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
8 if time then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
9 command:reply(string.format("Pong from %s in %0.3f seconds", jid, time));
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
10 else
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
11 command:reply("Ping failed ("..(error.condition or "unknown reason")..")"..(error.text and (": "..error.text) or ""));
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
12 end
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
13 end);
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
14 return true;
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
15 end
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
16 return "pong";
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
17 end);
0
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 end

mercurial