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); }
public async Task CmdLive(bool hasTwitterInfo) { try { RootStreamJSON streamJSON = await _twitchInfo.GetBroadcasterStream(); if (streamJSON.Stream == null) { _irc.SendPublicChatMessage("This channel is not streaming right now"); } else if (!_botConfig.EnableTweets) { _irc.SendPublicChatMessage("Tweets are disabled at the moment"); } else if (_botConfig.EnableTweets && hasTwitterInfo) { string tweetResult = _twitter.SendTweet($"Live on Twitch playing {streamJSON.Stream.Game} " + $"\"{streamJSON.Stream.Channel.Status}\" twitch.tv/{_botConfig.Broadcaster}"); _irc.SendPublicChatMessage($"{tweetResult} @{_botConfig.Broadcaster}"); } } catch (Exception ex) { await _errHndlrInstance.LogError(ex, "CmdBrdCstr", "CmdLive(bool)", false, "!live"); } }
private async void Run() { while (true) { RootStreamJSON streamJSON = await _twitchInfo.GetBroadcasterStream(); 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) { _irc.SendPublicChatMessage($"Live on Twitch playing {CurrentCategory} \"{CurrentTitle}\""); } IsLive = true; } Thread.Sleep(15000); // check every 15 seconds } }
private async Task <DateTime> PromoteStreamerAsync(TwitchChatter chatter) { try { string streamerUsername = ParseChatterMessageUsername(chatter); RootUserJSON userInfo = await _twitchInfo.GetUsersByLoginNameAsync(streamerUsername); if (userInfo.Users == null || userInfo.Users.Count == 0) { _irc.SendPublicChatMessage($"Cannot find the requested user @{chatter.DisplayName}"); return(DateTime.Now); } string userId = userInfo.Users.First().Id; string promotionMessage = $"Hey everyone! Check out {streamerUsername}'s channel at https://www.twitch.tv/" + $"{streamerUsername} and slam that follow button!"; RootStreamJSON userStreamInfo = await _twitchInfo.GetUserStreamAsync(userId); if (userStreamInfo.Stream == null) { ChannelJSON channelInfo = await _twitchInfo.GetUserChannelByIdAsync(userId); if (!string.IsNullOrEmpty(channelInfo.Game)) { promotionMessage += $" They were last seen playing \"{channelInfo.Game}\""; } } else { if (!string.IsNullOrEmpty(userStreamInfo.Stream.Game)) { promotionMessage += $" Right now, they're playing \"{userStreamInfo.Stream.Game}\""; } } _irc.SendPublicChatMessage(promotionMessage); } catch (Exception ex) { await _errHndlrInstance.LogError(ex, "Vip", "PromoteStreamer(TwitchChatter)", false, "!streamer"); } return(DateTime.Now); }
public async Task CmdPromoteStreamer(TwitchChatter chatter) { try { string streamerUsername = chatter.Message.Substring(chatter.Message.IndexOf("@") + 1).ToLower(); RootUserJSON userInfo = await _twitchInfo.GetUsersByLoginName(streamerUsername); if (userInfo.Users.Count == 0) { _irc.SendPublicChatMessage($"Cannot find the requested user @{chatter.Username}"); return; } string userId = userInfo.Users.First().Id; string promotionMessage = $"Hey everyone! Check out {streamerUsername}'s channel at https://www.twitch.tv/" + $"{streamerUsername} and slam that follow button!"; RootStreamJSON userStreamInfo = await _twitchInfo.GetUserStream(userId); if (userStreamInfo.Stream == null) { ChannelJSON channelInfo = await _twitchInfo.GetUserChannelById(userId); if (!string.IsNullOrEmpty(channelInfo.Game)) { promotionMessage += $" They were last seen playing \"{channelInfo.Game}\""; } } else { if (!string.IsNullOrEmpty(userStreamInfo.Stream.Game)) { promotionMessage += $" Right now, they're playing \"{userStreamInfo.Stream.Game}\""; } } _irc.SendPublicChatMessage(promotionMessage); } catch (Exception ex) { await _errHndlrInstance.LogError(ex, "CmdMod", "CmdResetGotNextGame(TwitchChatter)", false, "!streamer"); } }
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 } }