| 1 | function riddim.plugins.ping(bot) |
| 2 | bot.stream:add_plugin("ping"); |
| 3 | bot:add_plugin("resolvejid"); |
| 4 | bot:hook("commands/ping", function (command) |
| 5 | local jid = command.param; |
| 6 | if jid then |
| 7 | jid = bot:resolvejid(jid, command.room); |
| 8 | end |
| 9 | if jid then |
| 10 | bot.stream:ping(jid, function (time, jid, error) |
| 11 | if time then |
| 12 | command:reply(string.format("Pong from %s in %0.3f seconds", jid, time)); |
| 13 | else |
| 14 | command:reply("Ping failed ("..(error.condition or "unknown reason")..")"..(error.text and (": "..error.text) or "")); |
| 15 | end |
| 16 | end); |
| 17 | return true; |
| 18 | end |
| 19 | return "pong"; |
| 20 | end); |
| 21 | end |