plugins/ping.lua

Thu, 22 Oct 2020 15:37:43 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 22 Oct 2020 15:37:43 +0100
changeset 161
c4df517edbc1
parent 144
68dc84e72bef
permissions
-rw-r--r--

config.docker.lua: Require RIDDIM_DEBUG=1 to enable debug mode

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");
105
4234c8789cc6 plugins.{ping,version,resolvejid}: Break nickname/jid resolving into a common plugin
Kim Alvefur <zash@zash.se>
parents: 16
diff changeset
4 bot:add_plugin("resolvejid");
0
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 bot:hook("commands/ping", function (command)
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
6 local jid = command.param;
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
7 if jid then
105
4234c8789cc6 plugins.{ping,version,resolvejid}: Break nickname/jid resolving into a common plugin
Kim Alvefur <zash@zash.se>
parents: 16
diff changeset
8 jid = bot:resolvejid(jid, command.room);
144
68dc84e72bef riddim.plugins.ping: Handle JID being unknown after "resolving"
Kim Alvefur <zash@zash.se>
parents: 105
diff changeset
9 end
68dc84e72bef riddim.plugins.ping: Handle JID being unknown after "resolving"
Kim Alvefur <zash@zash.se>
parents: 105
diff changeset
10 if jid then
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
11 bot.stream:ping(jid, function (time, jid, error)
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
12 if time then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
13 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
14 else
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
15 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
16 end
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
17 end);
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
18 return true;
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
19 end
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
20 return "pong";
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 4
diff changeset
21 end);
0
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 end

mercurial