Example #1
0
        public BotClientConnection(IBot bot, IClientConnection connection, MessageHandler messageHandler, 
            ConnectionData data)
        {
            Bot = bot;
            Connection = connection;
            _messageHandler = messageHandler;
            _data = data;

            // Subscribe to received messages.
            _messageSubscription = Connection.ReceivedMessages
                .Where(m => !m.Sender.Equals(connection.Me))
                .Where(m => m.Type == ReceiveType.Message || m.Type == ReceiveType.Notice ||
                    m.Type == ReceiveType.Action)
                .Where(m => m.Sender.Type == MessageTargetType.User || m.Sender.Type == MessageTargetType.ChannelUser)
                .Subscribe(_messageHandler.ReceivedMessage);
        }
Example #2
0
File: Bot.cs Project: Gohla/Veda
        private IClientConnection Connect(ConnectionData data, bool store)
        {
            // Prevent duplicate connections
            if(!Connections
                .Where(x => x.Address.Equals(data.Address))
                .Where(x => x.Port.Equals(data.Port))
                .IsEmpty())
                return null;

            // Create and store objects.
            IClientConnection connection = _client.CreateClientConnection(data.Address, data.Port, null);
            BotClientConnection botConnection = new BotClientConnection(this, connection, _messsageHandler, data);
            _botConnections.Add(botConnection);
            if(store)
                _data.Connections.Add(data);

            // Create connection
            connection.Connect().Subscribe(
                _ => { },
                e => _logger.ErrorException("Unable to connect.", e),
                () => connection.Login(data.Nickname, data.Username, data.Realname, data.Password).Subscribe()
            );

            return connection;
        }