plugins/presence.lua

Wed, 27 Jun 2018 19:13:27 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 27 Jun 2018 19:13:27 +0100
changeset 419
bf2fe3fc2f73
parent 406
3c732f1d990c
child 476
c34b263499be
permissions
-rw-r--r--

Makefile: Use configured squish path

local verse = require "verse";

function verse.plugins.presence(stream)
	stream.last_presence = nil;

	stream:hook("presence-out", function (presence)
		if not presence.attr.to then
			stream.last_presence = presence; -- Cache non-directed presence
		end
	end, 1);

	function stream:resend_presence()
		if self.last_presence then
			stream:send(self.last_presence);
		end
	end

	function stream:set_status(opts)
		local p = verse.presence();
		if type(opts) == "table" then
			if opts.show then
				p:tag("show"):text(opts.show):up();
			end
			if opts.priority or opts.prio then
				p:tag("priority"):text(tostring(opts.priority or opts.prio)):up();
			end
			if opts.status or opts.msg then
				p:tag("status"):text(opts.status or opts.msg):up();
			end
		elseif type(opts) == "string" then
			p:tag("status"):text(opts):up();
		end

		stream:send(p);
	end
end

mercurial