private void AddRoom(Channel channel) { _rooms.Add(channel); Rooms.Add(channel.Name); if (_logRooms.Contains(channel.Name, StringComparer.InvariantCultureIgnoreCase)) { LogRooms.Add(channel.Name); } }
public override async Task Run() { if (!_isConfigured) { throw new AdapterNotConfiguredException(); } Logger.Info(string.Format("Logging into JabbR...")); SetupJabbrClient(); var result = await _client.Connect(_nick, _password); _client.StateChanged += OnClientStateChanged; Logger.Info(string.Format("Logged on successfully. {0} is currently in the following rooms:", _nick)); foreach (var room in result.Rooms) { Logger.Info(string.Format(" - " + room.Name + (room.Private ? " (private)" : string.Empty) + (_logRooms.Contains(room.Name) ? " (logging)" : string.Empty))); Rooms.Add(room.Name); if (_logRooms.Contains(room.Name)) { LogRooms.Add(room.Name); } } foreach (var room in _rooms.Union(_logRooms).Distinct().Where(room => !result.Rooms.Select(r => r.Name).Contains(room))) { try { await _client.JoinRoom(room); Rooms.Add(room); Logger.Info(string.Format("Successfully joined room {0}", room)); } catch (Exception e) { Logger.Info(string.Format("Could not join room {0}: {1}", room, e.Message)); } } foreach (var logRoom in _logRooms) { if (!LogRooms.Contains(logRoom)) { LogRooms.Add(logRoom); } } }
private void OnClientLogin(object sender) { var mucManager = new MucManager(_client); foreach (string room in _rooms.Union(_logRooms).Distinct()) { var jid = new Jid(room + "@" + _confhost); mucManager.JoinRoom(jid, _roomNick); Rooms.Add(room); Logger.Info(string.Format("Joined Room '{0}'", room)); } foreach (string logRoom in _logRooms) { LogRooms.Add(logRoom); } }
private void OnClientLogin(object sender) { var mucManager = new MucManager(_client); var rooms = _api.GetAllRooms(); foreach (var room in rooms.Items) { var roomInfo = _api.GetRoom(room.Id); var jid = new Jid(roomInfo.XmppJid); mucManager.JoinRoom(jid, _botUser.Name); Rooms.Add(room.Name); LogRooms.Add(room.Name); Logger.Info(string.Format("Joined Room '{0}'", room.Name)); } }
private void OnClientLogin(object sender) { var mucManager = new MucManager(_client); var rooms = _api.GetAllRooms(); foreach (var room in rooms.Items.Where(r => _roomList.Count == 0 || r.Name != null && _roomList.Contains(r.Name.ToUpper()))) { var roomInfo = _api.GetRoom(room.Id); _roomMap.Add(roomInfo.XmppJid, room.Id); var jid = new Jid(roomInfo.XmppJid); mucManager.JoinRoom(jid, _botUser.Name); Rooms.Add(room.Name); LogRooms.Add(room.Name); Logger.Info(string.Format("Joined Room '{0}'", room.Name)); } }
public override Task Run() { _loginTcs = new TaskCompletionSource <bool>(); Task <bool> connect = _loginTcs.Task; if (_xmppConnection != null) { _xmppConnection.Close(); _xmppConnection = null; } _xmppConnection = new XmppClientConnection { Server = _host, ConnectServer = _connectHost, AutoResolveConnectServer = true, Username = _username, Password = _password }; if (_port > 0) { _xmppConnection.Port = _port; } _xmppConnection.KeepAlive = true; _xmppConnection.OnLogin += OnLogin; _xmppConnection.OnError += OnError; _xmppConnection.OnMessage += OnMessage; _xmppConnection.OnPresence += XmppConnectionOnOnPresence; _xmppConnection.OnRosterItem += OnClientRosterItem; _xmppConnection.OnXmppConnectionStateChanged += OnXmppConnectionStateChanged; Task.Factory.StartNew(() => { _xmppConnection.Open(); Thread.Sleep(CONNECT_TIMEOUT); _loginTcs.TrySetResult(false); }); if (!connect.Result) { throw new TimeoutException("XMPP adapter timed out while trying to login"); } else { MucManager muc = new MucManager(_xmppConnection); foreach (var room in _rooms) { try { muc.JoinRoom(string.Format("{0}@{1}", room, _confServer), _username, _password, true); Logger.Info(string.Format("Successfully joined room {0}", room)); Rooms.Add(string.Format("{0}@{1}", room, _confServer)); } catch (Exception ex) { Logger.Error("Failed to join room - " + ex.Message); } } foreach (var logroom in _logRooms) { try { muc.JoinRoom(string.Format("{0}@{1}", logroom, _confServer), _username, _password, true); Logger.Info(string.Format("Successfully joined room {0}", logroom)); LogRooms.Add(string.Format("{0}@{1}", logroom, _confServer)); } catch (Exception ex) { Logger.Error("Failed to join room - " + ex.Message); } } } return(_loginTcs.Task); }