private async Task HandleClearMock(ChatMessage msg) { if (!CommandUtils.HasAdvancePermissions(msg.UserId)) { await CommandUtils.SendAccessDenied(m_firehose, msg.ChannelId, msg.UserName); return; } // Clear all. m_mockDict.Clear(); await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, "I'm not mocking anyone anymore. 😢", msg.IsWhisper); }
private async Task HandleExit(ChatMessage msg) { if (!CommandUtils.HasAdvancePermissions(msg.UserId)) { await CommandUtils.SendAccessDenied(m_firehose, msg); return; } await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, $"👋 Later! Powering down.", msg.IsWhisper); // Give the message time to send. await Task.Delay(1000); Environment.Exit(-1); }
private async Task HandleEcho(ChatMessage msg) { if (!CommandUtils.HasAdvancePermissions(msg.UserId)) { await CommandUtils.SendAccessDenied(m_firehose, msg.ChannelId, msg.UserName); return; } string body = CommandUtils.GetCommandBody(msg.Text); if (!String.IsNullOrWhiteSpace(body)) { await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, body, msg.IsWhisper); } }
public async void OnChatMessage(ChatMessage msg) { if (msg.Text.StartsWith("^") || msg.IsWhisper) { // Get the raw command. string command = msg.Text; int firstSpace = msg.Text.IndexOf(' '); if (firstSpace != -1) { command = msg.Text.Substring(0, firstSpace); } if (command.StartsWith("^")) { command = command.Substring(1); } command = command.ToLower(); // Filter short commands. if (command.Length < 3) { return; } // See if we can handle it internally. if (command.Equals("help") || command.Equals("command") || command.Equals("commands")) { string response = $"Hello @{msg.UserName}! You can talk to me in any Mixer channel by entering '^<command>' or whispering a command. Commands: "; if (CommandUtils.HasAdvancePermissions(msg.UserId)) { response += $"hello, whisper, summon, find, friend, lurk, ping, echo, mock, pmock, cmock, userstats, msgstats, exit, about"; } else { response = $"hello, whisper, summon, find, friend, lurk, userstats, msgstats, about"; } await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, response, CommandUtils.ShouldForceIsWhisper(msg)); } if (command.Equals("about")) { await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, "Hey there! I'm Karl! 🤗 I'm an experimental global chat observer created by @Quinninator and @BoringNameHere. To see what I can do, try whispering me ^commands.", CommandUtils.ShouldForceIsWhisper(msg)); } else if (command.Equals("hello") | command.Equals("hi")) { await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, $"👋 @{msg.UserName}", CommandUtils.ShouldForceIsWhisper(msg)); } else if (command.Equals("ping")) { await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, "Pong!", CommandUtils.ShouldForceIsWhisper(msg)); } else if (command.Equals("exit")) { await HandleExit(msg); } else if (command.Equals("echo")) { await HandleEcho(msg); } else if (command.Equals("find")) { await HandleFindCommand(msg); } else if (command.Equals("whisper")) { await HandleWhisperCommand(msg); } else if (command.Equals("summon")) { await HandleSummon(msg); } else if (command.Equals("mock")) { await HandleMockToggle(msg, true); } else if (command.Equals("pmock")) { await HandleMockToggle(msg, false); } else if (command.Equals("cmock")) { await HandleClearMock(msg); } else { // If we can't handle it internally, fire it to the others. m_commandCallback.OnCommand(command, msg); } } else { // Check if we need to mock. CheckForMock(msg); } }
private async Task HandleMockToggle(ChatMessage msg, bool isPrivate) { if (!CommandUtils.HasAdvancePermissions(msg.UserId)) { await CommandUtils.SendAccessDenied(m_firehose, msg.ChannelId, msg.UserName); return; } // Find the user name. string userName = CommandUtils.GetSingleWordArgument(msg.Text); if (userName == null) { await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, "I need a user name.", true); return; } // Get the user id. int?userId = await MixerUtils.GetUserId(userName); if (!userId.HasValue || userName.Length == 0) { await CommandUtils.SendMixerUserNotFound(m_firehose, msg, userName); return; } // Update the map. bool removed = false; bool currentValue; if (m_mockDict.TryGetValue(userId.Value, out currentValue)) { // Remove if it's the same toggle. if (currentValue == isPrivate) { removed = true; m_mockDict.TryRemove(userId.Value, out currentValue); } // Otherwise, toggle it else { m_mockDict.TryUpdate(userId.Value, isPrivate, currentValue); currentValue = isPrivate; } } else { // If they are not in the map, add them. m_mockDict.TryAdd(userId.Value, isPrivate); currentValue = isPrivate; } string output; if (removed) { output = $"I'm no longer mocking {await MixerUtils.GetProperUserName(userName)}. Lucky them."; } else { output = $"I'm now {(currentValue ? "privately" : "publically")} mocking {await MixerUtils.GetProperUserName(userName)} 😮"; } await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, output, msg.IsWhisper); return; }