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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
62
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     1
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     2
-- MALICIOUS STANZAS (XEP-0076)
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     3
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     4
-- library
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     5
66
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
     6
local lm = require 'lm'
64
bf7521ed96eb Rewrite of ibb in object style
Myhailo Danylenko <isbear@ukrpost.net>
parents: 63
diff changeset
     7
local iq = require 'iq'
62
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     8
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     9
-- public
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    10
66
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    11
local O = {
62
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    12
	handler =
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    13
		function ( mess )
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    14
			return false
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    15
		end,
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    16
}
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    17
66
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    18
local F = { }
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    19
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    20
function F.handler ( handler )
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    21
	O.handler = handler
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    22
end
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    23
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    24
function F.message ( conn, to, mtype, message )
62
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    25
	conn:send ( lm.message.create { mtype = 'message-' .. mtype, to = to,
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    26
			body = { message },
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    27
			evil = { xmlns = 'http://jabber.org/protocol/evil' },
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    28
		} )
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    29
end
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    30
66
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    31
function F.presence ( conn, to, status, message )
62
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    32
	local mtype = 'presence-available'
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    33
	if status == 'unavailable' then
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    34
		mtype = 'presence-unavailable'
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    35
		status = ''
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    36
	end
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    37
	conn:send ( lm.message.create { mtype = mtype, from = conn:jid (), to = to,
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    38
			show   = { status },
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    39
			status = { message },
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    40
			evil   = { xmlns = 'http://jabber.org/protocol/evil' },
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    41
		} )
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    42
end
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    43
66
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    44
function F.iq ( conn, to, action, contents, success, fail )
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    45
	contents.evil = { xmlns = 'http://jabber.org/protocol/evil' }
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    46
	iq.send ( conn, to, action, contents, success, fail )
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    47
end
62
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    48
66
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    49
function F.stanza_handler ( conn, mess )
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    50
	local e = mess:child ( 'evil' )
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    51
	if e and e:attribute ( 'xmlns' ) == 'http://jabber.org/protocol/evil' then
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    52
		return O.handler ( mess )
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    53
	end
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    54
end
62
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    55
66
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 64
diff changeset
    56
return F
62
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    57
fb81aeb45e00 Vcard and Evil
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    58
-- vim: se ts=4: --