public async Task CmdRefreshBossFight() { try { // Check if any fighters are queued or fighting if (_bossFightSettingsInstance.Fighters.Count > 0) { _irc.SendPublicChatMessage($"A boss fight is either queued or in progress @{_botConfig.Broadcaster}"); return; } // Get current game name ChannelJSON json = await _twitchInfo.GetBroadcasterChannelById(); string gameTitle = json.Game; // Grab game id in order to find party member TwitchGameCategory game = await _gameDirectory.GetGameId(gameTitle); // During refresh, make sure no fighters can join _bossFightSettingsInstance.RefreshBossFight = true; await _bossFightSettingsInstance.LoadSettings(_broadcasterInstance.DatabaseId, game?.Id, _botConfig.TwitchBotApiLink); _bossFightSettingsInstance.RefreshBossFight = false; _irc.SendPublicChatMessage($"Boss fight settings refreshed @{_botConfig.Broadcaster}"); } catch (Exception ex) { await _errHndlrInstance.LogError(ex, "CmdBrdCstr", "CmdRefreshBossFight()", false, "!refreshbossfight"); } }
/// <summary> /// Removes first party memeber in queue of party up requests /// </summary> public async Task CmdPopPartyUpRequest() { try { // get current game info ChannelJSON json = await _twitchInfo.GetBroadcasterChannelById(); string gameTitle = json.Game; TwitchGameCategory game = await _gameDirectory.GetGameId(gameTitle); if (string.IsNullOrEmpty(gameTitle)) { _irc.SendPublicChatMessage("I cannot see the name of the game. It's currently set to either NULL or EMPTY. " + "Please have the chat verify that the game has been set for this stream. " + $"If the error persists, please have @{_botConfig.Broadcaster.ToLower()} retype the game in their Twitch Live Dashboard. " + "If this error shows up again and your chat can see the game set for the stream, please contact my master with !support in this chat"); } else if (game?.Id > 0) { _irc.SendPublicChatMessage(await _partyUp.PopRequestedPartyMember(game.Id, _broadcasterId)); } else { _irc.SendPublicChatMessage("This game is not part of the \"Party Up\" system"); } } catch (Exception ex) { await _errHndlrInstance.LogError(ex, "CmdMod", "CmdPopPartyUpRequest()", false, "!poppartyuprequest"); } }
private async void Run() { await LoadReminderContext(); // initial load DateTime midnightNextDay = DateTime.Today.AddDays(1); while (true) { ChannelJSON channelJSON = await _twitchInfo.GetBroadcasterChannelById(); string gameTitle = channelJSON.Game; TwitchGameCategory game = await _gameDirectory.GetGameId(gameTitle); if (game == null || game.Id == 0) { _gameId = null; } else { _gameId = game.Id; } // remove pending reminders Program.DelayedMessages.RemoveAll(r => r.ReminderId > 0); foreach (RemindUser reminder in _reminders.OrderBy(m => m.RemindEveryMin)) { if (IsEveryMinReminder(reminder)) { continue; } else if (IsCountdownEvent(reminder)) { continue; } else { AddDayOfReminder(reminder); } } if (_refreshReminders) { _irc.SendPublicChatMessage("Reminders refreshed!"); } // reset refresh midnightNextDay = DateTime.Today.AddDays(1); _refreshReminders = false; // wait until midnight to check reminders // unless a manual refresh was called while (DateTime.Now < midnightNextDay && !_refreshReminders) { Thread.Sleep(1000); // 1 second } } }
public async Task LoadChannelInfo() { ChannelJSON channelJSON = await _twitchInfo.GetBroadcasterChannelById(); if (channelJSON != null) { CurrentCategory = channelJSON.Game; CurrentTitle = channelJSON.Status; } }
/// <summary> /// Removes first party memeber in queue of party up requests /// </summary> public async Task CmdPopPartyUpRequest() { try { // get current game info ChannelJSON json = await _twitchInfo.GetBroadcasterChannelById(); string gameTitle = json.Game; GameList game = await _gameDirectory.GetGameId(gameTitle); _irc.SendPublicChatMessage(await _partyUp.PopRequestedPartyMember(game.Id, _broadcasterId)); } catch (Exception ex) { await _errHndlrInstance.LogError(ex, "CmdMod", "CmdPopPartyUpRequest()", false, "!poppartyuprequest"); } }
/// <summary> /// Removes first party memeber in queue of party up requests /// </summary> public async Task CmdPopPartyUpRequest() { try { // get current game info ChannelJSON json = await _twitchInfo.GetBroadcasterChannelById(); string gameTitle = json.Game; TwitchGameCategory game = await _gameDirectory.GetGameId(gameTitle); if (game?.Id > 0) { _irc.SendPublicChatMessage(await _partyUp.PopRequestedPartyMember(game.Id, _broadcasterId)); } else { _irc.SendPublicChatMessage("This game is not part of the \"Party Up\" system"); } } catch (Exception ex) { await _errHndlrInstance.LogError(ex, "CmdMod", "CmdPopPartyUpRequest()", false, "!poppartyuprequest"); } }
/// <summary> /// Check broadcaster's info via API for newest followers or subscribers /// </summary> /// <returns></returns> private async Task CheckNewFollowersSubscribers() { try { // Get broadcaster type and check if they can have subscribers ChannelJSON channelJson = await _twitchInfo.GetBroadcasterChannelById(); string broadcasterType = channelJson.BroadcasterType; if (broadcasterType.Equals("partner") || broadcasterType.Equals("affiliate")) { // Check for new subscribers RootSubscriptionJSON rootSubscriptionJson = await _twitchInfo.GetSubscribersByChannel(); IEnumerable <string> freshSubscribers = rootSubscriptionJson.Subscriptions ?.Where(u => Convert.ToDateTime(u.CreatedAt).ToLocalTime() > DateTime.Now.AddSeconds(-60)) .Select(u => u.User.Name); if (freshSubscribers?.Count() > 0) { string subscriberUsername = ""; string subscriberRoleplayName = ""; if (freshSubscribers.Count() == 1) { subscriberUsername = $"@{freshSubscribers.First()}"; subscriberRoleplayName = "a NaCl agent"; } else if (freshSubscribers.Count() > 1) { subscriberRoleplayName = "NaCl agents"; foreach (string subscriber in freshSubscribers) { subscriberUsername += $"{subscriber}, "; } subscriberUsername = subscriberUsername.ReplaceLastOccurrence(", ", ""); // replace trailing "," subscriberUsername = subscriberUsername.ReplaceLastOccurrence(", ", " & "); // replacing joining "," } string welcomeMessage = $"Thank you so much {subscriberUsername} on becoming {subscriberRoleplayName}! " + $"That dedication will give @{_botConfig.Broadcaster} the edge they need to lead the charge " + "into the seven salty seas of Twitch! SwiftRage"; _irc.SendPublicChatMessage(welcomeMessage); } } // Check for new followers RootFollowerJSON rootFollowerJson = await _twitchInfo.GetFollowersByChannel(); IEnumerable <string> freshFollowers = rootFollowerJson.Followers ?.Where(u => Convert.ToDateTime(u.CreatedAt).ToLocalTime() > DateTime.Now.AddSeconds(-60)) .Select(u => u.User.Name); if (freshFollowers?.Count() > 0) { string followerUsername = ""; if (freshFollowers.Count() == 1) { followerUsername = $"@{freshFollowers.First()}"; } else if (freshFollowers.Count() > 1) { foreach (string follower in freshFollowers) { followerUsername += $"{follower}, "; } followerUsername = followerUsername.ReplaceLastOccurrence(", ", ""); // replace trailing "," followerUsername = followerUsername.ReplaceLastOccurrence(", ", " & "); // replacing joining "," } _irc.SendPublicChatMessage($"Welcome {followerUsername} to the Salt Army! " + $"With @{_botConfig.Broadcaster} we will pillage the seven salty seas of Twitch together!"); } } catch (Exception ex) { Console.WriteLine("Error inside FollowerSubscriberListener.CheckNewFollowersSubscribers(): " + ex.Message); if (ex.InnerException != null) { Console.WriteLine($"Inner Exception: {ex.InnerException.Message}"); } } }
/// <summary> /// Check broadcaster's info via API for newest followers or subscribers /// </summary> /// <returns></returns> private async Task CheckNewFollowersSubscribers() { try { // Get broadcaster type and check if they can have subscribers ChannelJSON channelJson = await _twitchInfo.GetBroadcasterChannelById(); string broadcasterType = channelJson.BroadcasterType; if (broadcasterType == "partner" || broadcasterType == "affiliate") { /* Check for new subscribers */ RootSubscriptionJSON rootSubscriptionJson = await _twitchInfo.GetSubscribersByChannel(); IEnumerable <string> freshSubscribers = rootSubscriptionJson.Subscriptions ?.Where(u => Convert.ToDateTime(u.CreatedAt).ToLocalTime() > DateTime.Now.AddSeconds(-60)) .Select(u => u.User.Name); if (freshSubscribers?.Count() > 0) { string subscriberUsername = ""; string subscriberRoleplayName = ""; if (freshSubscribers.Count() == 1) { subscriberUsername = $"@{freshSubscribers.First()}"; subscriberRoleplayName = "a NaCl agent"; } else if (freshSubscribers.Count() > 1) { subscriberRoleplayName = "NaCl agents"; foreach (string subscriber in freshSubscribers) { subscriberUsername += $"{subscriber}, "; } subscriberUsername = subscriberUsername.ReplaceLastOccurrence(", ", ""); // replace trailing "," subscriberUsername = subscriberUsername.ReplaceLastOccurrence(", ", " & "); // replace last "," } string welcomeMessage = $"Congrats {subscriberUsername} on becoming @{_botConfig.Broadcaster} 's {subscriberRoleplayName}!"; // Break up welcome message if it's too big if (welcomeMessage.Count() > 500) { string[] separators = new string[] { ", ", " & " }; List <string> subscribers = subscriberUsername.Split(separators, StringSplitOptions.RemoveEmptyEntries).ToList(); while (subscribers.Count > 0) { int popCount = 14; if (subscribers.Count < popCount) { popCount = subscribers.Count; } subscriberUsername = string.Join(", ", subscribers.Take(popCount)); subscriberUsername = subscriberUsername.ReplaceLastOccurrence(", ", ""); // replace trailing "," subscriberUsername = subscriberUsername.ReplaceLastOccurrence(", ", " & "); // replace last "," subscribers.RemoveRange(0, popCount); _irc.SendPublicChatMessage($"Congrats {subscriberUsername} on becoming @{_botConfig.Broadcaster} 's {subscriberRoleplayName}!"); await Task.Delay(750); } } else { _irc.SendPublicChatMessage(welcomeMessage); } } } /* Check for new followers */ RootFollowerJSON rootFollowerJson = await _twitchInfo.GetFollowersByChannel(); IEnumerable <string> freshFollowers = rootFollowerJson.Followers ?.Where(u => Convert.ToDateTime(u.CreatedAt).ToLocalTime() > DateTime.Now.AddSeconds(-60)) .Select(u => u.User.Name); if (freshFollowers?.Count() > 0) { string followerUsername = ""; if (freshFollowers.Count() == 1) { followerUsername = $"@{freshFollowers.First()}"; } else if (freshFollowers.Count() > 1) { foreach (string follower in freshFollowers) { followerUsername += $"{follower}, "; } followerUsername = followerUsername.ReplaceLastOccurrence(", ", ""); // replace trailing "," followerUsername = followerUsername.ReplaceLastOccurrence(", ", " & "); // replacing joining "," } _irc.SendPublicChatMessage($"Welcome {followerUsername} to the Salt Army! " + $"With @{_botConfig.Broadcaster} we will pillage the seven salty seas of Twitch together!"); } } catch (Exception ex) { Console.WriteLine("Error inside FollowerSubscriberListener.CheckNewFollowersSubscribers(): " + ex.Message); if (ex.InnerException != null) { Console.WriteLine($"Inner Exception: {ex.InnerException.Message}"); } } }