plugins/ping.lua

Thu, 20 May 2010 14:33:41 +0100

author
Chris <jugg@hotmail.com>
date
Thu, 20 May 2010 14:33:41 +0100
changeset 16
ae69cea97598
parent 4
1eaa469140e9
child 105
4234c8789cc6
permissions
-rw-r--r--

Formatting, indentation and cleanup

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