examples/evil.lua
author Myhailo Danylenko <isbear@ukrpost.net>
Fri, 27 Mar 2009 12:06:19 +0200
changeset 66 542f61e113cb
parent 64 bf7521ed96eb
child 68 742878c74b8e
permissions -rw-r--r--
Modularization, I * activity * attention * avatar * disco * evil * geoloc * ibb * iq * mood * oob * ping * pubsub * tune * mpd * pep


-- MALICIOUS STANZAS (XEP-0076)

-- library

local lm = require 'lm'
local iq = require 'iq'

-- public

local O = {
	handler =
		function ( mess )
			return false
		end,
}

local F = { }

function F.handler ( handler )
	O.handler = handler
end

function F.message ( conn, to, mtype, message )
	conn:send ( lm.message.create { mtype = 'message-' .. mtype, to = to,
			body = { message },
			evil = { xmlns = 'http://jabber.org/protocol/evil' },
		} )
end

function F.presence ( conn, to, status, message )
	local mtype = 'presence-available'
	if status == 'unavailable' then
		mtype = 'presence-unavailable'
		status = ''
	end
	conn:send ( lm.message.create { mtype = mtype, from = conn:jid (), to = to,
			show   = { status },
			status = { message },
			evil   = { xmlns = 'http://jabber.org/protocol/evil' },
		} )
end

function F.iq ( conn, to, action, contents, success, fail )
	contents.evil = { xmlns = 'http://jabber.org/protocol/evil' }
	iq.send ( conn, to, action, contents, success, fail )
end

function F.stanza_handler ( conn, mess )
	local e = mess:child ( 'evil' )
	if e and e:attribute ( 'xmlns' ) == 'http://jabber.org/protocol/evil' then
		return O.handler ( mess )
	end
end

return F

-- vim: se ts=4: --