示例#1
0
        public override void ExecuteCommand(EvtChatCommandArgs args)
        {
            List <string> arguments = args.Command.ArgumentsAsList;

            //Ignore with incorrect number of arguments
            if (arguments.Count != 1)
            {
                QueueMessage(UsageMessage);
                return;
            }

            string commandName = arguments[0].ToLowerInvariant();

            bool removed = CmdHandler.RemoveCommand(commandName);

            if (removed == true)
            {
                //Remove this command from the database
                using (BotDBContext context = DatabaseManager.OpenContext())
                {
                    CommandData cmdData = context.Commands.FirstOrDefault((cmd) => cmd.Name == commandName);
                    if (cmdData != null)
                    {
                        context.Commands.Remove(cmdData);

                        context.SaveChanges();
                    }
                    else
                    {
                        QueueMessage($"Error: Command \"{commandName}\" was not removed from the database because it cannot be found.");
                        return;
                    }
                }

                QueueMessage($"Successfully removed command \"{commandName}\"!");
            }
            else
            {
                QueueMessage($"Failed to remove command \"{commandName}\". It likely does not exist.");
            }
        }