Beispiel #1
0
        private static async Task CallsAsync()
        {
            await StreamFollower.UpdateFollowers();

            foreach (string streamNotification in StreamNotifications)
            {
                if (_lastStreamStatus.ContainsKey(streamNotification))
                {
                    var kvp = _lastStreamStatus.FirstOrDefault(x => x.Key == streamNotification);

                    var user = await _api.V5.Users.GetUserByNameAsync(streamNotification.ToLower());

                    if (user.Total == 0)
                    {
                        continue;
                    }

                    bool isStreaming = await _api.V5.Streams.BroadcasterOnlineAsync(user.Matches[0].Id);

                    if (isStreaming != kvp.Value)
                    {
                        if (isStreaming)
                        {
                            Console.WriteLine($"{user.Matches[0].DisplayName} is streaming!");
                        }

                        _lastStreamStatus.Remove(streamNotification);
                        _lastStreamStatus.Add(streamNotification, isStreaming);
                    }
                }
                else
                {
                    var user = await _api.V5.Users.GetUserByNameAsync(streamNotification.ToLower());

                    if (user.Total == 0)
                    {
                        continue;
                    }

                    bool isStreaming = await _api.V5.Streams.BroadcasterOnlineAsync(user.Matches[0].Id);

                    if (isStreaming)
                    {
                        Console.WriteLine($"{user.Matches[0].DisplayName} is streaming!");
                    }

                    _lastStreamStatus.Add(streamNotification, isStreaming);
                }
            }

            return;
        }
Beispiel #2
0
        public static void StartApi()
        {
            //TwitchApi api = new TwitchApi();

            string streamNotificationsPath = $"{Program.LocalFilePath}/StreamNotifications.json";

            bool streamNotificationFileExists = File.Exists(streamNotificationsPath);

            if (!streamNotificationFileExists)
            {
                StreamNotifications = new List <string>
                {
                    Settings.Default.TwitchUsername.ToLower()
                };

                File.WriteAllText(streamNotificationsPath, JsonConvert.SerializeObject(StreamNotifications, Formatting.Indented));
            }
            else
            {
                using (StreamReader sr = new StreamReader(streamNotificationsPath))
                {
                    string fileContents = sr.ReadToEnd();

                    StreamNotifications = JsonConvert.DeserializeObject <List <string> >(fileContents);
                }
            }
            Console.WriteLine($"You have notifications for {StreamNotifications.Count} streamers!");

            StreamFollower.InitFollowers();

            Task.Run(async() =>
            {
                while (true)
                {
                    await CallsAsync();
                }
            });
        }