summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2013-08-25 16:39:06 (GMT)
committerRemko Tronçon <git@el-tramo.be>2013-08-27 19:47:48 (GMT)
commit1bb607f96e79845ce30dd5590b0d53cc394ac150 (patch)
tree6156622ddd1b3238aec73536e0dc25b632965a71 /Sluift/Examples/CollectVersions.lua
parentc4431ee90f3f1daac0a12b35bfa3378d5c570eaa (diff)
downloadswift-1bb607f96e79845ce30dd5590b0d53cc394ac150.zip
swift-1bb607f96e79845ce30dd5590b0d53cc394ac150.tar.bz2
PubSub implementation & Sluift refactoring.
Change-Id: I04ff7111b73565c00bff6db183451774a633344f
Diffstat (limited to 'Sluift/Examples/CollectVersions.lua')
-rw-r--r--Sluift/Examples/CollectVersions.lua36
1 files changed, 18 insertions, 18 deletions
diff --git a/Sluift/Examples/CollectVersions.lua b/Sluift/Examples/CollectVersions.lua
index c93c8c8..38bf6ac 100644
--- a/Sluift/Examples/CollectVersions.lua
+++ b/Sluift/Examples/CollectVersions.lua
@@ -1,22 +1,22 @@
---
--- Copyright (c) 2010 Remko Tronçon
--- Licensed under the GNU General Public License v3.
--- See Documentation/Licenses/GPLv3.txt for more information.
---
+--[[
+
+ Copyright (c) 2010-2013 Remko Tronçon
+ Licensed under the GNU General Public License v3.
+ See Documentation/Licenses/GPLv3.txt for more information.
--- This script logs into an XMPP server, and collects statistics about
--- the server software of all contacts in your roster
+ This script logs into an XMPP server, and collects statistics about
+ the server software of all contacts in your roster
-require "sluift"
+--]]
-c = sluift.new_client(os.getenv("SLUIFT_JID"), os.getenv("SLUIFT_PASS"))
-c:connect()
+require 'sluift'
-versions = {}
-for jid, _ in pairs(c:get_contacts()) do
- v = c:get_version(sluift.jid_domain(jid))
- if v then versions[v["name"]] = (versions[v["name"]] or 0) + 1 end
-end
-for name, count in pairs(versions) do print(name .. ": " .. count) end
-
-c:disconnect()
+c = sluift.new_client(os.getenv('SLUIFT_JID'), os.getenv('SLUIFT_PASS'))
+c:connect(function ()
+ versions = {}
+ for jid in pairs(c:get_contacts()) do
+ local v = c:get_software_version {to = sluift.jid.domain(jid), timeout = 3000} or {name = 'Unknown'}
+ versions[v['name']] = (versions[v['name']] or 0) + 1
+ end
+ for name, count in pairs(versions) do print(name .. ': ' .. count) end
+end)