plugins/ping.lua

Tue, 21 Oct 2014 19:27:57 +0200

author
Kim Alvefur <zash@zash.se>
date
Tue, 21 Oct 2014 19:27:57 +0200
changeset 115
6498ca5ed831
parent 105
4234c8789cc6
child 144
68dc84e72bef
permissions
-rw-r--r--

plugins.{trac,urltitle,xeps,xkcd,xkcd2,youtube}: Remove net.httpclient_listener, no longer required since verse:8e9f44ecb95b


function riddim.plugins.ping(bot)
	bot.stream:add_plugin("ping");
	bot:add_plugin("resolvejid");
	bot:hook("commands/ping", function (command)
		local jid = command.param;
		if jid then
			jid = bot:resolvejid(jid, command.room);
			bot.stream:ping(jid, function (time, jid, error)
				if time then
					command:reply(string.format("Pong from %s in %0.3f seconds", jid, time));
				else
					command:reply("Ping failed ("..(error.condition or "unknown reason")..")"..(error.text and (": "..error.text) or ""));
				end
			end);
			return true;
		end
		return "pong";
	end);
end

mercurial