/// <inheritdoc />
        public override async System.Threading.Tasks.Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
        {
            switch (context.Client.TokenType)
            {
            case TokenType.Bot:
                RestApplication application = (RestApplication)await context.Client.GetApplicationInfoAsync().ConfigureAwait(false);

                if (!Global.IsDev((SocketUser)context.User))
                {
                    if (Global.clientCommands == true && context.User.Id == context.Client.CurrentUser.Id)
                    {
                        return(PreconditionResult.FromSuccess());
                    }

                    return(PreconditionResult.FromError(ErrorMessage ?? "Command can only be run by a listed developer of the bot."));
                }

                return(PreconditionResult.FromSuccess());

            default:
                return(PreconditionResult.FromError($"{nameof(RequireDeveloperAttribute)} is not supported by this {nameof(TokenType)}."));
            }
        }
Beispiel #2
0
        public override async Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IDependencyMap map)
        {
            var user   = context.User as IGuildUser;
            var dbUser = UserRepository.FetchUser(context as SocketCommandContext);
            var guild  = GuildRepository.FetchGuild(context.Guild.Id);

            foreach (var attribute in attributes)
            {
                switch (attribute)
                {
                case Attributes.BotOwner:
                    if (!DEABot.Credentials.OwnerIds.Any(x => x == context.User.Id))
                    {
                        return(PreconditionResult.FromError("Only an owner of this bot may use this command."));
                    }
                    break;

                case Attributes.ServerOwner:
                    if (user.Guild.OwnerId != user.Id && guild.ModRoles != null && !user.RoleIds.Any(x => guild.ModRoles.Any(y => y.Name == x.ToString() && y.Value.AsInt32 >= 3)))
                    {
                        return(PreconditionResult.FromError("Only the owners of this server may use this command."));
                    }
                    break;

                case Attributes.Admin:
                    if (!(context.User as IGuildUser).GuildPermissions.Administrator && guild.ModRoles != null && !user.RoleIds.Any(x => guild.ModRoles.Any(y => y.Name == x.ToString() && y.Value.AsInt32 >= 2)))
                    {
                        return(PreconditionResult.FromError("The administrator permission is required to use this command."));
                    }
                    break;

                case Attributes.Moderator:
                    if (guild.ModRoles != null && !user.RoleIds.Any(x => guild.ModRoles.Any(y => y.Name == x.ToString())))
                    {
                        return(PreconditionResult.FromError("Only a moderator may use this command."));
                    }
                    break;

                case Attributes.Nsfw:
                    if (!guild.Nsfw)
                    {
                        return(PreconditionResult.FromError($"This command may not be used while NSFW is disabled. An administrator may enable with the " +
                                                            $"`{guild.Prefix}ChangeNSFWSettings` command."));
                    }
                    var nsfwChannel = await context.Guild.GetChannelAsync(guild.NsfwId);

                    if (nsfwChannel != null && context.Channel.Id != guild.NsfwId)
                    {
                        return(PreconditionResult.FromError($"You may only use this command in {(nsfwChannel as ITextChannel).Mention}."));
                    }
                    var nsfwRole = context.Guild.GetRole(guild.NsfwRoleId);
                    if (nsfwRole != null && (context.User as IGuildUser).RoleIds.All(x => x != guild.NsfwRoleId))
                    {
                        return(PreconditionResult.FromError($"You do not have permission to use this command.\nRequired role: {nsfwRole.Mention}"));
                    }
                    break;

                case Attributes.InGang:
                    if (!GangRepository.InGang(context.User.Id, context.Guild.Id))
                    {
                        return(PreconditionResult.FromError("You must be in a gang to use this command."));
                    }
                    break;

                case Attributes.NoGang:
                    if (GangRepository.InGang(context.User.Id, context.Guild.Id))
                    {
                        return(PreconditionResult.FromError("You may not use this command while in a gang."));
                    }
                    break;

                case Attributes.GangLeader:
                    if (GangRepository.FetchGang(context.User.Id, context.Guild.Id).LeaderId != context.User.Id)
                    {
                        return(PreconditionResult.FromError("You must be the leader of a gang to use this command."));
                    }
                    break;

                case Attributes.Jump:
                    if (dbUser.Cash < guild.JumpRequirement)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {guild.JumpRequirement.ToString("C", Config.CI)}."));
                    }
                    break;

                case Attributes.Steal:
                    if (dbUser.Cash < guild.StealRequirement)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {guild.StealRequirement.ToString("C", Config.CI)}."));
                    }
                    break;

                case Attributes.Bully:
                    if (dbUser.Cash < guild.BullyRequirement)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {guild.BullyRequirement.ToString("C", Config.CI)}."));
                    }
                    break;

                case Attributes.Rob:
                    if (dbUser.Cash < guild.RobRequirement)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {guild.RobRequirement.ToString("C", Config.CI)}."));
                    }
                    break;

                case Attributes.FiftyX2:
                    if (dbUser.Cash < guild.FiftyX2Requirement)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {guild.FiftyX2Requirement.ToString("C", Config.CI)}."));
                    }
                    break;

                default:
                    throw new Exception($"ERROR: The {attribute} attribute does not exist!");
                }
            }
            return(PreconditionResult.FromSuccess());
        }
Beispiel #3
0
        public async Task <ParseResult> ParseAsync(ICommandContext context, int startIndex, SearchResult searchResult, PreconditionResult preconditionResult = null, IServiceProvider services = null)
        {
            services = services ?? EmptyServiceProvider.Instance;

            if (!searchResult.IsSuccess)
            {
                return(ParseResult.FromError(searchResult));
            }
            if (preconditionResult != null && !preconditionResult.IsSuccess)
            {
                return(ParseResult.FromError(preconditionResult));
            }

            string input = searchResult.Text.Substring(startIndex);

            return(await CommandParser.ParseArgsAsync(this, context, _commandService._ignoreExtraArgs, services, input, 0).ConfigureAwait(false));
        }
Beispiel #4
0
 public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
 {
     if (context.Channel is ITextChannel text && text.IsNsfw)
     {
         return(Task.FromResult(PreconditionResult.FromSuccess()));
     }
Beispiel #5
0
 public Task <ParseResult> ParseAsync(ICommandContext context, SearchResult searchResult, PreconditionResult preconditionResult = null, IServiceProvider services = null)
 => Command.ParseAsync(context, Alias.Length, searchResult, preconditionResult, services);