Example #1
0
        private async Task <DateTime> UptimeAsync()
        {
            try
            {
                RootStreamJSON streamJson = await _twitchInfo.GetBroadcasterStreamAsync();

                // Check if the channel is live
                if (streamJson.Stream != null)
                {
                    string   duration       = streamJson.Stream.CreatedAt;
                    TimeSpan ts             = DateTime.UtcNow - DateTime.Parse(duration, new DateTimeFormatInfo(), DateTimeStyles.AdjustToUniversal);
                    string   resultDuration = string.Format("{0:h\\:mm\\:ss}", ts);
                    _irc.SendPublicChatMessage($"This channel's current uptime (length of current stream) is {resultDuration}");
                }
                else
                {
                    _irc.SendPublicChatMessage("This channel is not streaming right now");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "GeneralFeature", "Uptime()", false, "!uptime");
            }

            return(DateTime.Now);
        }
        private async void Run()
        {
            while (true)
            {
                RootStreamJSON streamJSON = await _twitchInfo.GetBroadcasterStreamAsync();

                if (streamJSON.Stream == null)
                {
                    if (IsLive)
                    {
                        // ToDo: Clear greeted user list
                    }

                    IsLive = false;
                }
                else
                {
                    CurrentCategory = streamJSON.Stream.Game;
                    CurrentTitle    = streamJSON.Stream.Channel.Status;

                    // tell the chat the stream is now live
                    if (!IsLive)
                    {
                        // ToDo: Add setting if user wants preset reminder
                        _delayedMessagesInstance.DelayedMessages.Add(new DelayedMessage
                        {
                            Message  = $"Did you remind Twitter you're \"!live\"? @{_broadcasterName}",
                            SendDate = DateTime.Now.AddMinutes(5)
                        });

                        _irc.SendPublicChatMessage($"Live on Twitch playing {CurrentCategory} \"{CurrentTitle}\"");
                    }

                    IsLive = true;
                }

                Thread.Sleep(15000); // check every 15 seconds
            }
        }