Exemplo n.º 1
0
 private void CreateFollowerService(TwitchConfiguration twitchConfiguration, TwitchAPI api)
 {
     followerService = new FollowerService(api, 10);
     followerService.SetChannelsByName(new List <string> {
         twitchConfiguration.Username
     });                                                                                   // TODO ändern!
 }
Exemplo n.º 2
0
        public async Task InitializeAsync(string userName, string oauthToken, string channel)
        {
            var credentials = new ConnectionCredentials(userName, oauthToken);

            _client = new TwitchClient();
            _client.Initialize(credentials, channel);

            _client.OnLog             += OnLog;
            _client.OnConnectionError += OnConnectionError;
            _client.OnConnected       += OnConnected;
            _client.OnJoinedChannel   += OnJoinedChannel;
            _client.OnNewSubscriber   += OnNewSubscriber;
            //_client.OnMessageReceived += OnMessageReceived;

            _twitchAPI.Settings.ClientId    = _options.TwitchClientId;
            _twitchAPI.Settings.AccessToken = _options.TwitchSecret;
            _service = new FollowerService(_twitchAPI);
            _service.SetChannelsByName(new List <string> {
                "SpyderHunter03"
            });
            _service.OnServiceStarted       += OnServiceStarted;
            _service.OnServiceTick          += OnServiceTick;
            _service.OnNewFollowersDetected += OnNewFollowersDetected;

            await Task.Run(() => _client.Connect());

            _logger.LogInformation($"Got passed Connect");
            await Task.Run(() => _service.Start());

            _logger.LogInformation($"Got passed Start");
        }
        internal void Connect()
        {
            Console.WriteLine("Connecting...");

            client = new TwitchClient();
            client.Initialize(credentials, TwitchInfo.ChannelName);

            //Client Events
            client.OnLog             += Client_OnLog;
            client.OnConnectionError += Client_OnConnectionError;
            client.OnMessageReceived += Client_OnMessageReceived;
            client.OnNewSubscriber   += Client_OnNewSubscriber;

            client.Connect();

            api = new TwitchAPI();
            api.Settings.ClientId    = TwitchInfo.ClientID;
            api.Settings.AccessToken = TwitchInfo.BotToken;


            //API Events
            monitor = new LiveStreamMonitorService(api, int.Parse(TwitchInfo.UpdateInterval));
            List <string> channels = new List <string>();

            channels.Add(TwitchInfo.ChannelName);
            monitor.SetChannelsByName(channels);
            monitor.OnStreamOffline += Monitor_OnStreamOffline;
            monitor.OnStreamOnline  += Monitor_OnStreamOnline;
            monitor.Start();

            fservice = new FollowerService(api, int.Parse(TwitchInfo.UpdateInterval));
            fservice.SetChannelsByName(channels);
            fservice.OnNewFollowersDetected += Fservice_OnNewFollowersDetected;
            fservice.Start();

            //Excel Stuff
            excel         = new Application();
            excel.Visible = true;
            wb            = excel.Workbooks.Open(TwitchInfo.ExcelPath);

            foreach (Worksheet sheet in wb.Sheets)
            {
                if (sheet.Name == TwitchInfo.ChannelName)
                {
                    Console.WriteLine("Found exisiting channel...");
                    ws = sheet;
                    break;
                }
            }

            if (ws == null)
            {
                //Create/copy a new worksheet from base worksheet
                Console.WriteLine("New channel detected, creating a new sheet...");
                ws      = (Worksheet)excel.Worksheets.Add();
                ws.Name = TwitchInfo.ChannelName;
            }
        }
Exemplo n.º 4
0
            public async void KnownFollowers_Contains_UserId_When_ServiceUpdated()
            {
                var usersFollowsResponseJson = JMock.Of <GetUsersFollowsResponse>(o =>
                                                                                  o.Follows == new[]
                {
                    Mock.Of <Follow>(u => u.FromUserId == "UserId" && u.ToUserId == "Id")
                }
                                                                                  );

                _api = TwitchLibMock.TwitchApi(
                    ("https://api.twitch.tv/helix/users/follows", usersFollowsResponseJson)
                    );

                _followerService = new FollowerService(_api);
                _followerService.SetChannelsById(Utils.CreateListWithEmptyString());

                await _followerService.UpdateLatestFollowersAsync();

                Assert.NotNull(_followerService.KnownFollowers[string.Empty].FirstOrDefault(f => f.FromUserId == "UserId"));

                //Same check for SetChannelsByName
                var usersResponseJson = JMock.Of <GetUsersResponse>(o =>
                                                                    o.Users == new[]
                {
                    Mock.Of <User>(u => u.Id == "Id" && u.DisplayName == "DisplayName"),
                });

                _api = TwitchLibMock.TwitchApi(
                    ("https://api.twitch.tv/helix/users", usersResponseJson),
                    ("https://api.twitch.tv/helix/users/follows", usersFollowsResponseJson)
                    );

                _followerService = new FollowerService(_api);
                _followerService.SetChannelsByName(Utils.CreateListWithEmptyString());

                await _followerService.UpdateLatestFollowersAsync();

                Assert.NotNull(_followerService.KnownFollowers[string.Empty].FirstOrDefault(f => f.FromUserId == "UserId"));
            }
Exemplo n.º 5
0
            public void SetChannelsByName_Throws_ArgumentException_When_ChannelsArgumentEmpty()
            {
                _followerService = new FollowerService(_api);

                AssertException.Throws <ArgumentException>(ChannelListEmptyExceptionMessage, () => _followerService.SetChannelsByName(new List <string>()));
            }
Exemplo n.º 6
0
            public void SetChannelsByName_Throws_ArgumentNullException_When_ChannelsArgumentNull()
            {
                _followerService = new FollowerService(_api);

                AssertException.Throws <ArgumentNullException>(() => _followerService.SetChannelsByName(null));
            }
Exemplo n.º 7
0
        public void ConnectToTwitch()
        {
            try
            {
                if (string.IsNullOrWhiteSpace(Settings.Username))
                {
                    ShowMessage("Twitch Benutzername ist in den Einstellungen nicht gesetzt", new NotificationSetting(false, true));
                    return;
                }

                if (string.IsNullOrWhiteSpace(Settings.OAuthToken))
                {
                    ShowMessage("Twitch O Auth Token ist in den Einstellungen nicht gesetzt", new NotificationSetting(false, true));
                    return;
                }

                if (Settings.CheckForNewFollowers)
                {
                    if (string.IsNullOrWhiteSpace(Settings.ClientId))
                    {
                        ShowMessage("Twitch Api Client ID ist in den Einstellungen nicht gesetzt", new NotificationSetting(false, true));
                        return;
                    }

                    if (string.IsNullOrWhiteSpace(Settings.AccessToken))
                    {
                        ShowMessage("Twitch Api Access Token ist in den Einstellungen nicht gesetzt", new NotificationSetting(false, true));
                        return;
                    }
                }

                var loggerfactory = new LoggerFactory()
                                    .AddSerilog(
                    new LoggerConfiguration()
                    .WriteTo.File("logs\\twitch.log")
                    .CreateLogger());

                twitchAPI = new TwitchAPI(loggerfactory);
                twitchAPI.Settings.ClientId    = Settings.ClientId;
                twitchAPI.Settings.AccessToken = Settings.AccessToken;
                twitchAPI.Settings.Secret      = Settings.OAuthToken;
                twitchClient                     = new TwitchClient(logger: loggerfactory.CreateLogger <TwitchClient>());
                twitchClient.OnConnected        += TwitchClient_OnConnected;
                twitchClient.OnNewSubscriber    += TwitchClient_OnNewSubscriber;
                twitchClient.OnRaidNotification += TwitchClient_OnRaidNotification;
                twitchClient.OnUserJoined       += TwitchClient_OnUserJoined;
                twitchClient.OnUserLeft         += TwitchClient_OnUserLeft;
                twitchClient.OnBeingHosted      += TwitchClient_OnBeingHosted;
                twitchClient.OnMessageReceived  += TwitchClient_OnMessageReceived;

                twitchClient.Initialize(new ConnectionCredentials(Settings.Username, Settings.OAuthToken), Settings.ChannelToJoin);
                twitchClient.Connect();

                if (Settings.CheckForNewFollowers)
                {
                    followerService = new FollowerService(twitchAPI, checkIntervalInSeconds: 5);
                    followerService.SetChannelsByName(new List <string>()
                    {
                        Settings.ChannelToJoin
                    });
                    followerService.OnNewFollowersDetected += FollowerService_OnNewFollowersDetected;
                    followerService.UpdateLatestFollowersAsync(false);
                    followerService.Start();
                }

                IsTwitchConnected = true;
            }
            catch (Exception ex)
            {
                mainViewModel.ShowError(ex);
            }
        }