view libs/utils.lua @ 0:0d4d8b432980 default tip master

Initial commit.
author Kooda <kooda@upyum.com>
date Fri, 27 Aug 2010 17:00:32 +0200
parents
children
line wrap: on
line source

--
--------------------------------------------------------------------------------
--         FILE:  utils.lua
--        USAGE:  ./utils.lua 
--  DESCRIPTION:  A couple of functions
--      OPTIONS:  ---
-- REQUIREMENTS:  ---
--         BUGS:  ---
--        NOTES:  ---
--       AUTHOR:  Adrien Ramos (M), <adrien.ramos@upyum.com>
--      COMPANY:  
--      VERSION:  1.0
--      CREATED:  07/08/2010 23:40:24 CEST
--     REVISION:  ---
--------------------------------------------------------------------------------
--

local verse = require("verse");
local st = require("util.stanza");

-- Lit le fichier de configuration (par défaut config.lua) et stocke la configuration
-- dans la table config
function config_load(filename)
	local filename = filename or "config.lua"
	-- Config loading
	local chunk, err = loadfile(filename);
	if not chunk then
		print("File or syntax error:", err);
		return 1;
	end

	local config = {};
	setfenv(chunk, setmetatable(config, {__index = _G}));
	local ok, err = pcall(chunk);
	if not ok then
		print("Error while processing config:", err);
		return 1;
	end
	setmetatable(config, nil)
	return config;
end

function room_join(stream, room, nick)
	if not nick or not room or not stream then
		error("room_join needs the following arguments : stream room nick");
	end
	s = st.presence{from=stream.username.."@"..stream.host.."/"..stream.resource, to = room.jid.."/"..nick};
	s:tag("x", {xmlns="http://jabber.org/protocol/muc"});
	if room.password then
		s:tag("password"):text(room.password);
	end
	print("XML OUT:", s);
	stream:send(s);
end