summaryrefslogtreecommitdiffstats
blob: f196f84996cee353049a0f653cab8d8917978449 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
--[[
	Copyright (c) 2010-2013 Remko Tronçon
	Licensed under the GNU General Public License v3.
	See Documentation/Licenses/GPLv3.txt for more information.
--]]

--[[

	PEP Listener

	Listens to a series of PEP events of all contacts.

	The following environment variables are used:
	- SLUIFT_JID, SWIFT_PASS: JID and password to log in with
	- SLUIFT_DEBUG: Sets whether debugging should be turned on

--]]

require "sluift"

sluift.debug = os.getenv("SLUIFT_DEBUG") or false

pep_protocols = {
	[sluift.disco.features.USER_LOCATION] = true,
	[sluift.disco.features.USER_TUNE] = true,
	[sluift.disco.features.USER_ACTIVITY] = true,
	[sluift.disco.features.USER_AVATAR_METADATA] = true,
	[sluift.disco.features.USER_PROFILE] = true,
}

client = sluift.new_client(os.getenv("SLUIFT_JID"), os.getenv("SLUIFT_PASS"))
client:connect(function (c) 
	features = {sluift.disco.features.DISCO_INFO}
	for protocol in pairs(pep_protocols) do
		features[#features+1] = protocol .. '+notify'
	end

	c:set_caps_node("http://swift.im/PEPListener")
	c:set_disco_info({identities = {{name = 'PEPListener'}}, features = features})
	c:send_presence()
	for event in c:pubsub_events() do
		if event._type == 'pubsub_event_items' and pep_protocols[event.node] then
			print("<" .. event.from .. "> " .. tostring(event.item))
		end
	end
end)