public override void Handle() { Regex channelPattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\s\w+"); Stream?stream; Response = $"{ChatMessage.Username}, "; if (channelPattern.IsMatch(ChatMessage.Message)) { stream = TwitchApi.GetStream(ChatMessage.Split[1]); } else { stream = TwitchApi.GetStream(ChatMessage.ChannelId); } if (stream is null) { Response += "this channel is currently not streaming"; return; } Response += $"{stream.UserName} is currently streaming {stream.GameName} with {stream.ViewerCount} viewer{(stream.ViewerCount > 1 ? 's' : string.Empty)} for "; TimeSpan streamSpan = stream.StartedAt.Subtract(DateTime.Now); long milliseconds = streamSpan.TotalMilliseconds.ToLong() + TimeHelper.Now(); if (!DateTime.Now.IsDaylightSavingTime()) { milliseconds += new Hour().Milliseconds; } string streamTime = TimeHelper.GetUnixDifference(milliseconds).ToString(); Response += streamTime; return; }
private async void button21_Click(object sender, EventArgs e) { TwitchLib.Models.API.Stream stream = null; try { stream = await TwitchApi.GetStream(textBox25.Text); } catch (StreamOfflineException) { MessageBox.Show($"The stream for the channel '{textBox25.Text}' is currently offline."); } catch (BadResourceException) { MessageBox.Show($"The channel '{textBox25.Text}' is an invalid channel."); } if (stream != null) { MessageBox.Show(string.Format("average fps: {0}\nchannel name: {1}\ncreated at: {2}\ndelay: {3}\ngame: {4}\nid: {5}\nplaylist: {6}\npreview large: {7}\nvideo height: {8}\n viewers: {9}", stream.AverageFps, stream.Channel.Name, stream.CreatedAt.Second, stream.Delay, stream.Game, stream.Id, stream.IsPlaylist, stream.Preview.Large, stream.VideoHeight, stream.Viewers)); } }