public async Task Custom_Command_And_Alternates_Gets_Deleted_Properly() { var commandContainer = new Lazy <CommandContainer>(() => new CommandContainer(Enumerable.Empty <Command>())); var deleteCmd = new DeleteCommand(commandContainer); commandContainer.Value.Commands.Add(deleteCmd); const string alternateName = "!yo"; var commandToDelete = new Command() { Name = "!hi", Response = "hi :)", AlternateName = new List <string> { alternateName } }; commandContainer.Value.Commands.Add(commandToDelete); var messageParams = $"{deleteCmd.Name} {commandToDelete.Name}".Split(); var response = await deleteCmd.Handle(new CommandParameter <IrcMessage>(messageParams, new IrcMessage(""))); Assert.DoesNotContain(commandContainer.Value.Commands, x => x.Key == "!hi" || x.Key == alternateName); Assert.Equal($"Deleted command '{commandToDelete.Name}'", response); }
public static void HandleChat(Player sender, string message) { // Check if message is empty. message = message.Trim(); if (message.Length == 0) { return; } bool isAdmin = sender.GetAccessLevel() > 99; string lowercaseMessage = message.ToLowerInvariant().Replace("\\s{2,}", " "); // Also remove all double spaces. if (lowercaseMessage.Equals(COMMAND_LOCATION)) { LocCommand.Handle(sender); } else if (lowercaseMessage.Equals(COMMAND_RETURN)) { ReturnCommand.Handle(sender); } else if (lowercaseMessage.StartsWith(COMMAND_PERSONAL_MESSAGE)) { TellCommand.Handle(sender, lowercaseMessage, message); } else if (isAdmin && lowercaseMessage.StartsWith(COMMAND_SPAWN)) { SpawnCommand.Handle(sender, lowercaseMessage); } else if (isAdmin && lowercaseMessage.Equals(COMMAND_DELETE)) { DeleteCommand.Handle(sender); } else // Normal message. { sender.ChannelSend(new ChatResult(CHAT_TYPE_NORMAL, sender.GetName(), message)); List <Player> players = WorldManager.GetVisiblePlayers(sender); for (int i = 0; i < players.Count; i++) { players[i].ChannelSend(new ChatResult(CHAT_TYPE_NORMAL, sender.GetName(), message)); } // Log chat. if (Config.LOG_CHAT) { StringBuilder sb = new StringBuilder(); sb.Append("["); sb.Append(sender.GetName()); sb.Append("] "); sb.Append(message); LogManager.LogChat(sb.ToString()); } } }