0
|
1 --
|
|
2 --------------------------------------------------------------------------------
|
|
3 -- FILE: utils.lua
|
|
4 -- USAGE: ./utils.lua
|
|
5 -- DESCRIPTION: A couple of functions
|
|
6 -- OPTIONS: ---
|
|
7 -- REQUIREMENTS: ---
|
|
8 -- BUGS: ---
|
|
9 -- NOTES: ---
|
|
10 -- AUTHOR: Adrien Ramos (M), <adrien.ramos@upyum.com>
|
|
11 -- COMPANY:
|
|
12 -- VERSION: 1.0
|
|
13 -- CREATED: 07/08/2010 23:40:24 CEST
|
|
14 -- REVISION: ---
|
|
15 --------------------------------------------------------------------------------
|
|
16 --
|
|
17
|
|
18 local verse = require("verse");
|
|
19 local st = require("util.stanza");
|
|
20
|
|
21 -- Lit le fichier de configuration (par défaut config.lua) et stocke la configuration
|
|
22 -- dans la table config
|
|
23 function config_load(filename)
|
|
24 local filename = filename or "config.lua"
|
|
25 -- Config loading
|
|
26 local chunk, err = loadfile(filename);
|
|
27 if not chunk then
|
|
28 print("File or syntax error:", err);
|
|
29 return 1;
|
|
30 end
|
|
31
|
|
32 local config = {};
|
|
33 setfenv(chunk, setmetatable(config, {__index = _G}));
|
|
34 local ok, err = pcall(chunk);
|
|
35 if not ok then
|
|
36 print("Error while processing config:", err);
|
|
37 return 1;
|
|
38 end
|
|
39 setmetatable(config, nil)
|
|
40 return config;
|
|
41 end
|
|
42
|
|
43 function room_join(stream, room, nick)
|
|
44 if not nick or not room or not stream then
|
|
45 error("room_join needs the following arguments : stream room nick");
|
|
46 end
|
|
47 s = st.presence{from=stream.username.."@"..stream.host.."/"..stream.resource, to = room.jid.."/"..nick};
|
|
48 s:tag("x", {xmlns="http://jabber.org/protocol/muc"});
|
|
49 if room.password then
|
|
50 s:tag("password"):text(room.password);
|
|
51 end
|
|
52 print("XML OUT:", s);
|
|
53 stream:send(s);
|
|
54 end
|