Changeset

4807:2999f0fd1347

mod_admin_telnet: Add muc:room(jid) command to get the MUC room object
author Matthew Wild <mwild1@gmail.com>
date Wed, 02 May 2012 18:21:47 +0100
parents 4806:27a99c289b90
children 4808:07d0a3a75c8a
files plugins/mod_admin_telnet.lua
diffstat 1 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_admin_telnet.lua	Mon Apr 30 01:20:13 2012 +0100
+++ b/plugins/mod_admin_telnet.lua	Wed May 02 18:21:47 2012 +0100
@@ -17,7 +17,8 @@
 
 local iterators = require "util.iterators";
 local keys, values = iterators.keys, iterators.values;
-local jid_bare = require "util.jid".bare;
+local jid = require "util.jid";
+local jid_bare, jid_split = jid.bare, jid.split;
 local set, array = require "util.set", require "util.array";
 local cert_verify_identity = require "util.x509".verify_identity;
 
@@ -832,6 +833,29 @@
 	return true, "Closed "..n_closed.." ports";
 end
 
+def_env.muc = {};
+
+local console_room_mt = {
+	__index = function (self, k) return self.room[k]; end;
+	__tostring = function (self)
+		return "MUC room <"..self.room.jid..">";
+	end;
+};
+
+function def_env.muc:room(room_jid)
+	local room_name, host = jid_split(room_jid);
+	if not hosts[host] then
+		return nil, "No such host: "..host;
+	elseif not hosts[host].modules.muc then
+		return nil, "Host '"..host.."' is not a MUC service";
+	end
+	local room_obj = hosts[host].modules.muc.rooms[room_jid];
+	if not room_obj then
+		return nil, "No such room: "..room_jid;
+	end
+	return setmetatable({ room = room_obj }, console_room_mt);
+end
+
 -------------
 
 function printbanner(session)