plugins/ping.lua

Wed, 23 Dec 2009 01:00:13 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 23 Dec 2009 01:00:13 +0000
changeset 4
1eaa469140e9
parent 0
7d84f4403d67
child 16
ae69cea97598
permissions
-rw-r--r--

plugins.ping: Update to handle errors passed from Verse

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)
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local jid = command.param;
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 if jid then
4
1eaa469140e9 plugins.ping: Update to handle errors passed from Verse
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
7 bot.stream:ping(jid, function (time, jid, error)
1eaa469140e9 plugins.ping: Update to handle errors passed from Verse
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
8 if time then
1eaa469140e9 plugins.ping: Update to handle errors passed from Verse
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
9 command:reply(string.format("Pong from %s in %0.3f seconds", jid, time));
1eaa469140e9 plugins.ping: Update to handle errors passed from Verse
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
10 else
1eaa469140e9 plugins.ping: Update to handle errors passed from Verse
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
11 command:reply("Ping failed ("..(error.condition or "unknown reason")..")"..(error.text and (": "..error.text) or ""));
1eaa469140e9 plugins.ping: Update to handle errors passed from Verse
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
12 end
0
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 end);
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 return true;
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 end
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 return "pong";
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 end);
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 end

mercurial