コード例 #1
0
        public override string TryToExecute(CommandReceivedEventArgs eventArgs)
        {
            string commandWord = eventArgs?.Arguments?.ElementAtOrDefault(1);

            ChatUser chatUser = eventArgs.ChatUser;

            try
            {
                if (!chatUser.IsInThisRoleOrHigher(UserRole.Mod))
                {
                    return("You need to be a moderator to delete a command.");
                }

                SimpleCommand command = _repository.Single(SimpleCommandPolicy.ByCommandText(commandWord));
                if (command == null)
                {
                    return($"I didn't find a !{commandWord} command.");
                }

                IBotCommand botCommand = _allCommands.SingleOrDefault(x => x.ShouldExecute(commandWord, out _));
                if (botCommand != null)
                {
                    _allCommands.Remove(botCommand);
                }

                _repository.Remove(command);
                return($"Removing the !{commandWord} command.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return("");
            }
        }
コード例 #2
0
        public static ContainerBuilder AddSimpleCommandsFromRepository(
            this ContainerBuilder builder,
            IRepository repository)
        {
            List <SimpleCommand> simpleCommands = repository.List(SimpleCommandPolicy.All());

            foreach (SimpleCommand simpleCommand in simpleCommands)
            {
                builder.RegisterInstance(simpleCommand).As <IBotCommand>();
            }

            return(builder);
        }
コード例 #3
0
        public override string TryToExecute(CommandReceivedEventArgs eventArgs)
        {
            if (eventArgs?.ChatUser.IsInThisRoleOrHigher(UserRole.Mod) == false)
            {
                return("You need to be a moderator to add a command.");
            }

            string commandWord    = eventArgs?.Arguments?.ElementAtOrDefault(1);
            string staticResponse = eventArgs?.Arguments?.ElementAtOrDefault(2);
            string roleText       = eventArgs?.Arguments?.ElementAtOrDefault(3);

            if (!Enum.TryParse(roleText, true, out UserRole role))
            {
                role = UserRole.Everyone;
            }

            var command = new SimpleCommand(commandWord, staticResponse, role);

            try
            {
                if (_repository.Single(SimpleCommandPolicy.ByCommandText(command.CommandText)) != null)
                {
                    return($"There's already a command using !{command.CommandText}");
                }

                _repository.Create(command);
                _allCommands.Add(command);

                return($"Adding a !{command.CommandText} command for {command.RoleRequired}. It will respond with {command.StaticResponse}.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return("");
            }
        }