public override async Task <bool> ExecuteCheckAsync(CommandContext ctx, bool help)
        {
            CannotBeUsedInDMAttribute checkDM = new CannotBeUsedInDMAttribute();

            if (!await checkDM.ExecuteCheckAsync(ctx, help))
            {
                return(false);
            }

            var app = ctx.Client.CurrentApplication;

            if (app != null)
            {
                bool success = help || ctx.Member == ctx.Guild.Owner || app.Owners.Any(x => x.Id == ctx.User.Id);
                if (!success && !string.IsNullOrWhiteSpace(failMessage))
                {
                    await CTX.RespondSanitizedAsync(ctx, failMessage);
                }

                return(success);
            }

            var me = ctx.Client.CurrentUser;

            return(ctx.User.Id == me.Id);
        }
        public override async Task <bool> ExecuteCheckAsync(CommandContext ctx, bool help)
        {
            CannotBeUsedInDMAttribute checkDM = new CannotBeUsedInDMAttribute();

            if (!await checkDM.ExecuteCheckAsync(ctx, help))
            {
                return(false);
            }

            var user = ctx.Member;

            if (user == null)
            {
                return(false);
            }
            var pUser = ctx.Channel.PermissionsFor(user);

            var bot = await ctx.Guild.GetMemberAsync(ctx.Client.CurrentUser.Id).ConfigureAwait(false);

            if (bot == null)
            {
                return(false);
            }

            if (help)
            {
                return(true);
            }

            var pBot = ctx.Channel.PermissionsFor(bot);

            var userSuccess = user.Id == ctx.Guild.Owner.Id ||
                              ((pUser & Permissions.Administrator) != 0 || (pUser & permissions) == permissions);
            var botSuccess = (pBot & Permissions.Administrator) != 0 || (pBot & permissions) == permissions;

            string failMessage = "";

            if (!userSuccess)
            {
                failMessage += $"**Permissions missing for {user.DisplayName}:** " +
                               $"{((pUser & permissions) ^ permissions).ToPermissionString()}\n";
            }
            if (!botSuccess)
            {
                failMessage += $"**Permissions missing for {bot.DisplayName}:** " +
                               $"{((pBot & permissions) ^ permissions).ToPermissionString()}";
            }

            if (!string.IsNullOrWhiteSpace(failMessage))
            {
                await CTX.RespondSanitizedAsync(ctx, failMessage);
            }
            return(userSuccess && botSuccess);
        }
Beispiel #3
0
        public override async Task <bool> ExecuteCheckAsync(CommandContext ctx, bool help)
        {
            CannotBeUsedInDMAttribute checkDM =
                skipDMMessage ? new CannotBeUsedInDMAttribute("") : new CannotBeUsedInDMAttribute();

            if (!await checkDM.ExecuteCheckAsync(ctx, help))
            {
                return(false);
            }

            var user = ctx.Member;

            if (user == null)
            {
                return(false);
            }

            var app = ctx.Client.CurrentApplication;

            if (app == null)
            {
                return(false);
            }

            if (help || user.Id == ctx.Guild.Owner.Id || app.Owners.Any(x => x.Id == ctx.User.Id))
            {
                return(true);
            }

            var pUser = ctx.Channel.PermissionsFor(user);

            if ((pUser & Permissions.Administrator) != 0)
            {
                return(true);
            }

            if (!string.IsNullOrWhiteSpace(failMessage))
            {
                await CTX.RespondSanitizedAsync(ctx, failMessage);
            }

            return(false);
        }