Esempio n. 1
0
        public override ValueTask <CheckResult> CheckAsync(object argument, DiscordGuildCommandContext context)
        {
            if (context.Guild == null)
            {
                throw new InvalidOperationException($"{GetType().Name} requires a non-null guild.");
            }

            var(targetName, target) = GetTarget(context);
            if (argument is IMember member)
            {
                if (GetHierarchy(context.Guild, target) > GetHierarchy(context.Guild, member))
                {
                    return(Success());
                }
            }
            else
            {
                var role = argument as IRole;
                if (GetHierarchy(context.Guild, target) > role.Position)
                {
                    return(Success());
                }
            }

            return(Failure($"The provided {(argument is IMember ? "member" : "role")} must be below the {targetName} in role hierarchy."));
        }
Esempio n. 2
0
        public override ValueTask <CheckResult> CheckAsync(DiscordGuildCommandContext context)
        {
            if (context.Author.Id == context.Guild.OwnerId)
            {
                return(Success());
            }

            return(Failure("This can only be executed by the guild owner."));
        }
Esempio n. 3
0
        public override ValueTask <CheckResult> CheckAsync(DiscordGuildCommandContext context)
        {
            if (context.Author.RoleIds.Any(x => x == Id))
            {
                return(Success());
            }

            return(Failure($"This can only be executed by members with the role ID {Id}."));
        }
        public override ValueTask <CheckResult> CheckAsync(DiscordGuildCommandContext context)
        {
            if (context.CurrentMember.RoleIds.Any(x => x == Id))
            {
                return(Success());
            }

            return(Failure($"The bot requires the role with ID {Id}."));
        }
        public override ValueTask <CheckResult> CheckAsync(DiscordGuildCommandContext context)
        {
            if (Id == null || Id == context.GuildId)
            {
                return(Success());
            }

            return(Failure($"This can only be executed in the guild with the ID {Id}."));
        }
        public override ValueTask <CheckResult> CheckAsync(DiscordGuildCommandContext context)
        {
            var permissions = context.Author.GetPermissions(context.Channel);

            if (permissions.Has(Permissions))
            {
                return(Success());
            }

            return(Failure($"You lack the necessary channel permissions ({Permissions - permissions}) to execute this."));
        }
Esempio n. 7
0
        public override ValueTask <CheckResult> CheckAsync(DiscordGuildCommandContext context)
        {
            var permissions = context.CurrentMember.GetPermissions();

            if (permissions.Has(Permissions))
            {
                return(Success());
            }

            return(Failure($"The bot lacks the necessary guild permissions ({Permissions & ~permissions}) to execute this."));
        }
Esempio n. 8
0
        public override ValueTask <CheckResult> CheckAsync(DiscordGuildCommandContext context)
        {
            if (context.Channel is null)
            {
                throw new InvalidOperationException($"{nameof(RequireNsfwAttribute)} requires the context channel.");
            }

            var isNsfw = context.Channel switch
            {
                CachedTextChannel textChannel => textChannel.IsNsfw,
                CachedThreadChannel threadChannel => threadChannel.GetChannel()?.IsNsfw ?? false,
                _ => false
            };

            if (isNsfw)
            {
                return(Success());
            }

            return(Failure("This can only be executed in a NSFW channel."));
        }
    }
Esempio n. 9
0
 public abstract ValueTask <CheckResult> CheckAsync(DiscordGuildCommandContext context);
Esempio n. 10
0
 protected abstract (string Name, IMember Member) GetTarget(DiscordGuildCommandContext context);
 public abstract ValueTask <CheckResult> CheckAsync(object argument, DiscordGuildCommandContext context);
Esempio n. 12
0
 /// <inheritdoc cref="ParseAsync(Parameter, string, DiscordCommandContext)"/>
 public abstract ValueTask <TypeParserResult <T> > ParseAsync(Parameter parameter, string value, DiscordGuildCommandContext context);