private async Task TestRaidHandler(IRC.TwitchChatter chatter, string[] remainingCommand) { if (chatter.User.AuthorizationLevel < AuthorizationLevel.Admin) { communication.SendPublicChatMessage($"You are not authorized to test raid notifications, @{chatter.User.TwitchUserName}."); return; } string userId = botConfig.BroadcasterId; int userCount = 100; //Optional Raider Name if (remainingCommand.Length > 0) { Database.User raider = await userHelper.GetUserByTwitchLogin(remainingCommand[0]); if (raider is not null) { userId = raider.TwitchUserId; } } //Optional Raider Count if (remainingCommand.Length > 1 && int.TryParse(remainingCommand[1], out int newUserCount)) { userCount = newUserCount; } raidHandler.HandleRaid(userId, userCount, true); return; }
private string HandleTTSHelpRequest(IRC.TwitchChatter chatter, string[] remainingCommand) { if (chatter.User.AuthorizationLevel < AuthorizationLevel.Elevated) { return($"Looks like you're not authorized to use the TTS system, {chatter.User.TwitchUserName}"); } if (remainingCommand == null || remainingCommand.Length == 0) { return("TTS Command - Send text as spoken audio to the stream with: !tts <text> For more information, visit info.tas.wtf/twitchBotFeatures/tts.html"); } else if (remainingCommand[0].ToLower() == "voice") { return("TTS Voice - Set your personal TTS Voice with !set tts voice <Voice>. Eg justin, joanna, brian, or en-US-Standard-B. For more information, visit info.tas.wtf/twitchBotFeatures/tts.html#tts-voice-personalization"); } else if (remainingCommand[0].ToLower() == "pitch") { return("TTS Pitch - Set your personal TTS Voice pitch with !set tts pitch <Pitch>. Eg normal, x-low, low, high, x-high. For more information, visit info.tas.wtf/twitchBotFeatures/tts.html#supported-tts-pitches"); } else if (remainingCommand[0].ToLower() == "sounds") { return("TTS Sounds - Add sounds to your TTS with commands like /bao, /midway, /jump, /kick, /pipe, /powerup. For more information, visit info.tas.wtf/twitchBotFeatures/tts.html#tts-sound-effects-extension"); } else { return($"No TTS subcommand found: {string.Join(' ', remainingCommand)}"); } }
private async Task TestCheerHandler(IRC.TwitchChatter chatter, string[] remainingCommand) { if (chatter.User.AuthorizationLevel < AuthorizationLevel.Admin) { communication.SendPublicChatMessage($"You are not authorized to test cheer notifications, @{chatter.User.TwitchUserName}."); return; } if (remainingCommand.Length < 4) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, error in testing cheer notification. Syntax is !testcheer <user> <cheertype> <bits> <message>."); } else { Database.User cheerer = await userHelper.GetUserByTwitchLogin(remainingCommand[0].ToLower(), false); if (cheerer == null) { communication.SendWarningMessage($"Requested user {remainingCommand[0]} not found in database. Substituting broadcaster."); cheerer = await userHelper.GetUserByTwitchId(botConfig.BroadcasterId, false); } if (!int.TryParse(remainingCommand[2], out int quantity)) { quantity = 1000; } string message = string.Join(' ', remainingCommand[3..]) + $" {remainingCommand[1]}{remainingCommand[2]}";
private async Task HandleFakeTTSRequest(IRC.TwitchChatter chatter, string[] remainingCommand) { if (!enabled && chatter.User.AuthorizationLevel != AuthorizationLevel.Admin) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, I'm afraid the TTS system is currently disabled."); return; } if (chatter.User.AuthorizationLevel < AuthorizationLevel.Admin) { communication.SendPublicChatMessage($"I'm afraid I can't let you do that, @{chatter.User.TwitchUserName}."); return; } if (remainingCommand is null || remainingCommand.Length == 0) { //TTS Error communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, missing a username to fake a TTS from."); return; } string username = remainingCommand[0].ToLower(); using IServiceScope scope = scopeFactory.CreateScope(); BaseDatabaseContext db = scope.ServiceProvider.GetRequiredService <BaseDatabaseContext>(); User fakeTTSUser = db.Users.FirstOrDefault(x => x.TwitchUserName.ToLower() == username); if (fakeTTSUser is null) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, unable to find \"{username}\" in db."); return; } remainingCommand = remainingCommand[1..];
/// <summary> /// Handle accepting or rejecting pending TTS /// </summary> private Task HandlePendingTTS(IRC.TwitchChatter chatter, string[] remainingCommand, bool accept) { if (chatter.User.AuthorizationLevel < AuthorizationLevel.Moderator) { communication.SendPublicChatMessage($"You are not authorized to replay notifcations, @{chatter.User.TwitchUserName}."); return(Task.CompletedTask); } if (remainingCommand.Length != 1) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, incorrectly formatted {(accept ? "accept" : "reject")} request."); return(Task.CompletedTask); } if (!int.TryParse(remainingCommand[0], out int updateIndex)) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, unable to parse updateIndex \"{remainingCommand[0]}\"."); return(Task.CompletedTask); } bool success = activityDispatcher.UpdatePendingRequest(updateIndex, accept); if (success) { messageAccumulator.RemovePendingNotification(updateIndex); } else { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, unable to {(accept ? "accept" : "reject")} TTS {updateIndex}."); } return(Task.CompletedTask); }
private async Task QuoteCommandHandler(IRC.TwitchChatter chatter, string[] remainingCommand) { if (remainingCommand == null || remainingCommand.Length == 0) { //Get Random Quote await GetRandomQuote(chatter.User); } else if (remainingCommand[0].StartsWith('#') && remainingCommand[0].Length > 1 && int.TryParse(remainingCommand[0][1..], out int quoteId))
private string ShoutOutHelpHandler(IRC.TwitchChatter chatter, string[] remainingCommand) { if (remainingCommand == null || remainingCommand.Length == 0) { return("Send a shout-out message about another user."); } else { return($"No shout out subcommand found: {string.Join(' ', remainingCommand)}"); } }
/// <summary> /// End current notification /// </summary> private Task SkipNotification(IRC.TwitchChatter chatter, string[] remainingCommand) { if (chatter.User.AuthorizationLevel < AuthorizationLevel.Moderator) { communication.SendPublicChatMessage($"You are not authorized to do that, @{chatter.User.TwitchUserName}."); return(Task.CompletedTask); } activityDispatcher.Skip(); return(Task.CompletedTask); }
private async Task QuitHandler(IRC.TwitchChatter chatter, string[] remainingCommand) { if (chatter.User.AuthorizationLevel < AuthorizationLevel.Admin) { communication.SendPublicChatMessage($"You are not authorized to disconnect me, @{chatter.User.TwitchUserName}."); return; } communication.SendPublicChatMessage($"Alright @{chatter.User.TwitchUserName}, I'm heading out. Goodbye!"); await Task.Delay(2000); applicationManagement.TriggerExit(); }
public async Task HandleCommand(IRC.TwitchChatter chatter) { if (chatter.User.AuthorizationLevel == AuthorizationLevel.Restricted) { //Restricted users get NOTHING return; } string cleanMessage = chatter.Message.Trim(); string[] splitMessage = cleanMessage.Split(' ', options: StringSplitOptions.RemoveEmptyEntries); string command = splitMessage[0][1..].ToLowerInvariant();
private string QuoteHelpHandler(IRC.TwitchChatter chatter, string[] remainingCommand) { if (remainingCommand == null || remainingCommand.Length == 0) { return("Quote commands: !quote add <quote> [user], !quote, !quote <phrase>"); } else if (remainingCommand.Length == 1 && remainingCommand[0].ToLowerInvariant() == "add") { return($"Quote Add syntax: !quote add \"Quote\" [optional username]. Quote Add example: !quote add \"Here is an example quote\" {botConfig.Broadcaster}"); } else { return($"No quote subcommand found: {string.Join(' ', remainingCommand)}"); } }
private async Task AddCommand(IRC.TwitchChatter chatter, string[] remainingCommand) { if (chatter.User.AuthorizationLevel < AuthorizationLevel.Moderator) { //Only Admins and Mods can Add commands communication.SendPublicChatMessage($"I'm afraid I can't let you do that, @{chatter.User.TwitchUserName}."); return; } if (remainingCommand == null || remainingCommand.Length < 2) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, Add requires a command followed by text."); return; } string command = remainingCommand[0].ToLowerInvariant(); string message = string.Join(' ', remainingCommand[1..]).Trim();
private async void HandleChatMessage(IRC.TwitchChatter chatter) { try { if (chatter.Whisper) { await HandleWhisper(chatter); } else if (IsCommand(chatter.Message)) { await HandleCommand(chatter); } } catch (Exception ex) { errorHandler.LogSystemException(ex); } }
private async Task TestSubHandler(IRC.TwitchChatter chatter, string[] remainingCommand) { if (chatter.User.AuthorizationLevel < AuthorizationLevel.Admin) { communication.SendPublicChatMessage($"You are not authorized to test sub notifications, @{chatter.User.TwitchUserName}."); return; } string user = "******"; string submessage = "This is my sub message"; if (remainingCommand.Length >= 1) { user = remainingCommand[0]; submessage = ""; } Database.User subUser = await userHelper.GetUserByTwitchLogin(user.ToLower(), false); if (subUser == null) { communication.SendWarningMessage($"Requested user {user} not found in database. Substituting broadcaster."); subUser = await userHelper.GetUserByTwitchId(botConfig.BroadcasterId, false); } if (remainingCommand.Length < 2 || !int.TryParse(remainingCommand[1], out int months)) { months = 1; } if (remainingCommand.Length < 3 || !int.TryParse(remainingCommand[2], out int tier)) { tier = 1; } subscriptionHandler.HandleSubscription( userId: subUser.TwitchUserId, message: submessage, monthCount: months, tier: tier, approved: true); }
private async Task ShoutOutCommandHandler(IRC.TwitchChatter chatter, string[] remainingCommand) { if (chatter.User.AuthorizationLevel < AuthorizationLevel.Moderator) { communication.SendPublicChatMessage($"I'm afraid I can't let you do that, @{chatter.User.TwitchUserName}."); return; } if (remainingCommand == null || remainingCommand.Length == 0) { //Get Random Quote communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, no user specified for Shout-Out command."); return; } string userName = remainingCommand[0].ToLowerInvariant(); if (userName[0] == '@') { //strip off superfluous @ signs userName = userName[1..];
/// <summary> /// Replay a notification /// </summary> private Task ReplayNotification(IRC.TwitchChatter chatter, string[] remainingCommand) { if (chatter.User.AuthorizationLevel < AuthorizationLevel.Moderator) { communication.SendPublicChatMessage($"You are not authorized to replay notifcations, @{chatter.User.TwitchUserName}."); return(Task.CompletedTask); } if (remainingCommand.Length > 1) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, incorrectly formatted replay request."); return(Task.CompletedTask); } int replayIndex = -1; if (remainingCommand.Length == 1) { if (!int.TryParse(remainingCommand[0], out replayIndex)) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, unable to parse replayIndex \"{remainingCommand[0]}\"."); return(Task.CompletedTask); } } if (!activityDispatcher.ReplayNotification(replayIndex)) { if (replayIndex == -1) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, no notifications to replay."); } else { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, unable to replay notification {replayIndex}."); } } return(Task.CompletedTask); }
public virtual async void HandleChatMessage(IRC.IRCMessage message) { if (message.ircCommand != IRC.IRCCommand.PrivMsg && message.ircCommand != IRC.IRCCommand.Whisper) { communication.SendDebugMessage($"Error: Passing forward non-chat message:\n {message}"); return; } IRC.TwitchChatter chatter = await IRC.TwitchChatter.FromIRCMessage(message, communication, scopeFactory); if (chatter == null) { return; } communication.DispatchChatMessage(chatter); if (chatter.Bits != 0 && chatter.Bits >= botConfig.BitTTSThreshold) { cheerHandler.HandleCheer(chatter.User, chatter.Message, chatter.Bits, true); } }
private async Task RestrictUser(IRC.TwitchChatter chatter, string[] remainingCommand) { if (chatter.User.AuthorizationLevel < AuthorizationLevel.Moderator) { //Only Admins and Mods and restrict users communication.SendPublicChatMessage($"I'm afraid I can't let you do that, @{chatter.User.TwitchUserName}."); return; } if (remainingCommand == null || remainingCommand.Length == 0) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, Restrict who?"); return; } string lowerUser = remainingCommand[0].ToLower(); if (string.IsNullOrWhiteSpace(lowerUser)) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, Restrict who?"); return; } using IServiceScope scope = scopeFactory.CreateScope(); BaseDatabaseContext db = scope.ServiceProvider.GetRequiredService <BaseDatabaseContext>(); IEnumerable <User> matchingUsers = db.Users.Where(x => x.TwitchUserName.ToLower() == lowerUser); if (!matchingUsers.Any()) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {remainingCommand[0]} not found."); return; } if (matchingUsers.Count() > 1) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {remainingCommand[0]} found multiple times."); return; } User matchingUser = matchingUsers.First(); if (matchingUser.AuthorizationLevel == AuthorizationLevel.Admin) { //Failed - No one can restrict admins communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, no one can restrict the admin!"); } else if (matchingUser.AuthorizationLevel == AuthorizationLevel.Moderator) { //Attempt to restrict a mod if (chatter.User.AuthorizationLevel == AuthorizationLevel.Admin) { //Only admins can restrict mods matchingUser.AuthorizationLevel = AuthorizationLevel.Restricted; await db.SaveChangesAsync(); communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} has been restricted!"); } else { //Failed - Mods can't restrict other mods communication.SendPublicChatMessage($"I'm afraid I can't let you do that, @{chatter.User.TwitchUserName}."); } } else { //Restriction of normal user matchingUser.AuthorizationLevel = AuthorizationLevel.Restricted; await db.SaveChangesAsync(); communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} has been restricted!"); } }
private async Task ModUser(IRC.TwitchChatter chatter, string[] remainingCommand, bool mod) { if (chatter.User.AuthorizationLevel != AuthorizationLevel.Admin) { //Only Admins can mod users communication.SendPublicChatMessage($"I'm afraid I can't let you do that, @{chatter.User.TwitchUserName}."); return; } if (remainingCommand == null || remainingCommand.Length == 0) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, {(mod ? "Mod" : "Unmod")} who?"); return; } string lowerUser = remainingCommand[0].ToLower(); if (string.IsNullOrWhiteSpace(lowerUser)) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, {(mod ? "Mod" : "Unmod")} who?"); return; } using IServiceScope scope = scopeFactory.CreateScope(); BaseDatabaseContext db = scope.ServiceProvider.GetRequiredService <BaseDatabaseContext>(); IEnumerable <User> matchingUsers = db.Users.Where(x => x.TwitchUserName.ToLower() == lowerUser); if (!matchingUsers.Any()) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {remainingCommand[0]} not found."); return; } if (matchingUsers.Count() > 1) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {remainingCommand[0]} found multiple times."); return; } User matchingUser = matchingUsers.First(); if (mod) { if (matchingUser.AuthorizationLevel < AuthorizationLevel.Moderator) { matchingUser.AuthorizationLevel = AuthorizationLevel.Moderator; await db.SaveChangesAsync(); communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} has been modded!"); } else { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} is already too powerful."); } } else { if (matchingUser.AuthorizationLevel == AuthorizationLevel.Moderator) { matchingUser.AuthorizationLevel = AuthorizationLevel.None; await db.SaveChangesAsync(); communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} has been unmodded!"); } else if (matchingUser.AuthorizationLevel < AuthorizationLevel.Moderator) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} is already not a mod. Mission accomplished?"); } else { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} cannot be demoded."); } } }
private void WriteIncomingMessage(IRC.TwitchChatter chatter) { lineChannel.Writer.TryWrite(chatter.ToLogString()); }
protected virtual string GetUnrecognizedCommandMessage(IRC.TwitchChatter chatter, string[] splitMessage) => $"@{chatter.User.TwitchUserName}, You wot m8‽ ({splitMessage[0]})";
private async Task AdjustUser(IRC.TwitchChatter chatter, string[] remainingCommand, bool elevate) { if (chatter.User.AuthorizationLevel < AuthorizationLevel.Moderator) { //Moderators and Admins can adjust users communication.SendPublicChatMessage($"I'm afraid I can't let you do that, @{chatter.User.TwitchUserName}."); return; } if (remainingCommand == null || remainingCommand.Length == 0) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, {(elevate ? "Elevate" : "Demote")} who?"); return; } string lowerUser = remainingCommand[0].ToLower(); if (string.IsNullOrWhiteSpace(lowerUser)) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, {(elevate ? "Elevate" : "Demote")} who?"); return; } using IServiceScope scope = scopeFactory.CreateScope(); BaseDatabaseContext db = scope.ServiceProvider.GetRequiredService <BaseDatabaseContext>(); IEnumerable <User> matchingUsers = db.Users.Where(x => x.TwitchUserName.ToLower() == lowerUser); if (!matchingUsers.Any()) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {remainingCommand[0]} not found."); return; } if (matchingUsers.Count() > 1) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {remainingCommand[0]} found multiple times."); return; } User matchingUser = matchingUsers.First(); if (elevate) { if (matchingUser.AuthorizationLevel == AuthorizationLevel.Restricted) { //Unrestricting a user matchingUser.AuthorizationLevel = AuthorizationLevel.None; await db.SaveChangesAsync(); communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} no longer restricted."); } else if (matchingUser.AuthorizationLevel == AuthorizationLevel.None) { matchingUser.AuthorizationLevel = AuthorizationLevel.Elevated; await db.SaveChangesAsync(); communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} has been elevated!"); } else { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} is already fully elevated."); } } else { if (matchingUser.AuthorizationLevel == AuthorizationLevel.Elevated) { matchingUser.AuthorizationLevel = AuthorizationLevel.None; await db.SaveChangesAsync(); communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} has been demoted!"); } else if (matchingUser.AuthorizationLevel == AuthorizationLevel.None) { matchingUser.AuthorizationLevel = AuthorizationLevel.Restricted; await db.SaveChangesAsync(); communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} has been restricted!"); } else { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, user {matchingUser.TwitchUserName} can't be further demoted."); } } }
private void ReceiveChatter(IRC.TwitchChatter chatter) { chatBuffer.AddMessage(new SimpleMessage($"<span style=\"color: {chatter.User.Color}\">{HttpUtility.HtmlEncode(chatter.User.TwitchUserName)}</span>: {HttpUtility.HtmlEncode(chatter.Message)}")); }
private void ReceiveMessageHandler(IRC.TwitchChatter chatter) { Console.WriteLine($"Chat {chatter.User.TwitchUserName}: {chatter.Message}"); }