summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2013-12-27 19:50:41 (GMT)
committerRemko Tronçon <git@el-tramo.be>2014-01-03 11:09:07 (GMT)
commita260aa27ab2af0c71d29b3e18cfa30569d3bcd7d (patch)
tree3629bd64f53e8e2f355725ddd07ee5e8e9815f02 /Sluift/Examples
parent9d787c6337d7080cb32af800a96cf64d43373514 (diff)
downloadswift-a260aa27ab2af0c71d29b3e18cfa30569d3bcd7d.zip
swift-a260aa27ab2af0c71d29b3e18cfa30569d3bcd7d.tar.bz2
Sluift: Add with() function
Change-Id: Ife0a7748c2b354017bec5cfdddb0d096950dd15b
Diffstat (limited to 'Sluift/Examples')
-rw-r--r--Sluift/Examples/EchoBot_With.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/Sluift/Examples/EchoBot_With.lua b/Sluift/Examples/EchoBot_With.lua
new file mode 100644
index 0000000..1f7d0bb
--- /dev/null
+++ b/Sluift/Examples/EchoBot_With.lua
@@ -0,0 +1,32 @@
+--[[
+ Copyright (c) 2010-2013 Remko Tronçon
+ Licensed under the GNU General Public License v3.
+ See Documentation/Licenses/GPLv3.txt for more information.
+--]]
+
+--[[
+
+ Alternative version of EchoBot that uses with()
+
+ This script logs into an XMPP server, sends initial presence,
+ and then waits for incoming messages, and echoes them back.
+
+ 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
+
+client = sluift.new_client(os.getenv("SLUIFT_JID"), os.getenv("SLUIFT_PASS"))
+sluift.with(client, function ()
+ connect()
+ set_version{name = "EchoBot", version = "0.1"}
+ send_presence("Send me a message")
+ for message in messages() do
+ send_message{to = message["from"], body = message["body"]}
+ end
+end)