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


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);
		end
		if jid then
			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