Example #1
0
        public void Connect(TwitchCredentials twitchCredentials)
        {
            ConnectionCredentials credentials = twitchCredentials.ToTwitchLib(_dataProtection);

            Client.Initialize(credentials, twitchCredentials.Channel.ToLowerInvariant());

            Client.Connect();
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IChatConnectionService ccs, IWebSocketEventService wse,
                             ITwitchPubSubService pss)
        {
            //Title = "OakBot - YATB";
            Title = "Kelex";

            // Set dependency injection references
            _ccs = ccs;
            _wse = wse;
            _pss = pss;

            // Register for chat connection service events
            _ccs.Authenticated += _ccs_Authenticated;
            _ccs.Disconnected  += _ccs_Disconnected;

            // Load settings
            var loaded = BinaryFile.ReadEncryptedBinFile("LoginSettings");

            if (loaded != null && loaded is MainSettings)
            {
                // Success, set last saved settings
                _mainSettings = (MainSettings)loaded;

                // Set loaded settings values through properties for UI
                ChannelName    = _mainSettings.Channel;
                BotUsername    = _mainSettings.BotUsername;
                CasterUsername = _mainSettings.CasterUsername;
                IsUsingSSL     = _mainSettings.UseSecureConnection;

                // Set bot credentials
                if (!string.IsNullOrWhiteSpace(_mainSettings.BotOauthKey))
                {
                    IsBotOauthSet   = true;
                    _botCredentials = new TwitchCredentials(
                        _mainSettings.BotUsername, _mainSettings.BotOauthKey, false);
                }

                // Set caster credentials
                if (!string.IsNullOrWhiteSpace(_mainSettings.CasterOauthKey))
                {
                    IsCasterOauthSet   = true;
                    _casterCredentials = new TwitchCredentials(
                        _mainSettings.CasterUsername, _mainSettings.CasterOauthKey, true);

                    // Try connection PubSub
                    _pss.Connect(_casterCredentials);
                }
            }
            else
            {
                // Failure, load defaults
                _mainSettings = new MainSettings();
            }

            // Start WebSocket Event Service
            _wse.StartService(1337, "oakbotapitest");
        }
Example #3
0
        // TODO: #28 Replace CredentialsExtensions with AutoMapper profiles.
        public static ConnectionCredentials ToTwitchLib(this TwitchCredentials credentials, IDataProtection dataProtection)
        {
            if (credentials.AuthToken == null)
            {
                throw new System.ArgumentException("Unable to convert null AuthToken", nameof(credentials));
            }

            return(new ConnectionCredentials(credentials.Username, dataProtection.Unprotect(credentials.AuthToken).BytesToString()));
        }
        public TwitchWhisperConnection(TwitchCredentials connectingUser, MainWindow window)
        {
            _mW = window;
            //delegateMessage = new MainWindow.delegateMessage(_mW.ResolveDispatchToUI);
            _connectedUser = connectingUser;

            // Connect and login into the whisper server
            ircClient = new BotIrcClient("199.9.253.119", 6667, connectingUser);

            // Request whispers
            ircClient.WriteLineThrottle("CAP REQ :twitch.tv/commands");
        }
        public TwitchWhisperConnection(TwitchCredentials connectingUser, MainWindow window)
        {
            _mW = window;
            //delegateMessage = new MainWindow.delegateMessage(_mW.ResolveDispatchToUI);
            _connectedUser = connectingUser;

            // Connect and login into the whisper server
            ircClient = new BotIrcClient("199.9.253.119", 6667, connectingUser);

            // Request whispers
            ircClient.WriteLineThrottle("CAP REQ :twitch.tv/commands");
        }
        public TwitchChatClient(ITwitchClient client)
        {
            twitchCredentials = TwitchCredentials.Instance;
            ConnectionCredentials credentials = new ConnectionCredentials(twitchCredentials.twitchUsername, twitchCredentials.twitchOAuth);

            twitchClient = client;
            twitchClient.Initialize(credentials);

            twitchClient.OnJoinedChannel       += onJoinedChannel;
            twitchClient.OnMessageReceived     += onMessageReceived;
            twitchClient.OnChatCommandReceived += OnChatCommandReceived;
        }
Example #7
0
    public bool Connect(TwitchCredentials credentials)
    {
        twitchClient = new TcpClient("irc.chat.twitch.tv", 6667);
        reader       = new StreamReader(twitchClient.GetStream());
        writer       = new StreamWriter(twitchClient.GetStream());

        writer.WriteLine("PASS " + credentials.Password);
        writer.WriteLine("NICK " + credentials.Username);
        writer.WriteLine("USER " + credentials.Username + " 8 * :" + credentials.Username);
        writer.WriteLine("JOIN #" + credentials.ChannelName);
        writer.Flush();
        return(testConnect());
    }
        public void Setup()
        {
            mockTwitchClient = new Mock <ITwitchClient>();

            mockTwitchClient.Setup(s => s.Initialize(It.IsAny <ConnectionCredentials>(), It.IsAny <string>(), It.IsAny <char>(), It.IsAny <char>(), It.IsAny <bool>())).Verifiable();
            mockTwitchClient.Setup(s => s.Connect()).Verifiable();
            mockTwitchCredentialFileReader = new Mock <TwitchCredentials>();
            TwitchCredentials twitchCredentials = new TwitchCredentials
            {
                twitchUsername = "******",
                twitchOAuth    = "raw/erwakjrhak;ew"
            };

            //mockTwitchCredentialFileReader.Setup(s => s.readTwitchCredentials(It.IsAny<string>())).Returns(twitchCredentials);

            twitchChatClient = new TwitchChatClient(mockTwitchClient.Object);
        }