Ejemplo n.º 1
0
        public override ValueTask <CheckResult> CheckAsync(ScrapContext context)
        {
            IGuildUser guildUser = context.Guild.CurrentUser;

            if (GuildPermission.HasValue)
            {
                if (!guildUser.GuildPermissions.Has(GuildPermission.Value))
                {
                    return(CheckResult.Unsuccessful($"I'm missing the {GuildPermission.Value} guild permission :scream:"));
                }
            }

            if (ChannelPermission.HasValue)
            {
                IGuildChannel guildChannel = context.Channel;
                var           perms        = guildUser.GetPermissions(guildChannel);

                if (!perms.Has(ChannelPermission.Value))
                {
                    return(CheckResult.Unsuccessful($"I'm missing the {ChannelPermission.Value} channel permission :scream:"));
                }
            }

            return(CheckResult.Successful);
        }
Ejemplo n.º 2
0
        public override async ValueTask <CheckResult> CheckAsync(ScrapContext context)
        {
            var appInfo = await context.Client.GetApplicationInfoAsync();

            return(appInfo.Owner.Id != context.User.Id
                ? CheckResult.Unsuccessful("This command is restricted to the Owner!")
                : CheckResult.Successful);
        }
Ejemplo n.º 3
0
        public override ValueTask <TypeParserResult <ITextChannel> > ParseAsync(Parameter param, string value, ScrapContext context)
        {
            var          channels = context.Guild.Channels.OfType <ITextChannel>().ToList();
            ITextChannel channel  = null;

            if (ulong.TryParse(value, out ulong id) || MentionUtils.TryParseChannel(value, out id))
            {
                channel = context.Client.GetChannel(id) as ITextChannel;
            }

            if (channel is null)
            {
                var match = channels.Where(x =>
                                           x.Name.EqualsIgnoreCase(value));
                if (match.Count() > 1)
                {
                    return(TypeParserResult <ITextChannel> .Unsuccessful(
                               "Multiple channels found, try mentioning the channel or using its ID."));
                }

                channel = match.FirstOrDefault();
            }
            return(channel is null
                ? TypeParserResult <ITextChannel> .Unsuccessful("User not found.")
                : TypeParserResult <ITextChannel> .Successful(channel));
        }
Ejemplo n.º 4
0
        public override ValueTask <TypeParserResult <IUser> > ParseAsync(Parameter param, string value, ScrapContext context)
        {
            var   users = context.Guild.Users.OfType <IUser>().ToList();
            IUser user  = null;

            if (ulong.TryParse(value, out ulong id) || MentionUtils.TryParseUser(value, out id))
            {
                user = context.Client.GetUser(id);
            }

            if (user is null)
            {
                var match = users.Where(x =>
                                        x.Username.EqualsIgnoreCase(value) ||
                                        (x as SocketGuildUser).Nickname.EqualsIgnoreCase(value)).ToList();
                if (match.Count() > 1)
                {
                    return(TypeParserResult <IUser> .Unsuccessful(
                               "Multiple users found, try mentioning the user or using their ID."));
                }

                user = match.FirstOrDefault();
            }
            return(user is null
                ? TypeParserResult <IUser> .Unsuccessful("User not found.")
                : TypeParserResult <IUser> .Successful(user));
        }
Ejemplo n.º 5
0
        public override async ValueTask <TypeParserResult <IMessage> > ParseAsync(Parameter parameter, string value, ScrapContext context)
        {
            var      messages = context.Channel.CachedMessages;
            IMessage message  = null;

            if (ulong.TryParse(value, out ulong id))
            {
                message = await context.Channel.GetMessageAsync(id);
            }

            if (message is null)
            {
                var match = messages.Where(x =>
                                           x.Content.EqualsIgnoreCase(value));
                if (match.Count() > 1)
                {
                    return(TypeParserResult <IMessage> .Unsuccessful(
                               "Multiple messages found, try using its ID."));
                }

                message = match.FirstOrDefault();
            }
            return(message is null
                ? TypeParserResult <IMessage> .Unsuccessful("Message not found.")
                : TypeParserResult <IMessage> .Successful(message));
        }
Ejemplo n.º 6
0
        public override ValueTask <TypeParserResult <Command> > ParseAsync(Parameter parameter, string value, ScrapContext context)
        {
            var _commands = context.ServiceProvider.GetService <CommandService>();

            var command = _commands.FindCommands(value).FirstOrDefault()?.Command;

            return(command == null
                ? TypeParserResult <Command> .Unsuccessful("Could not find a command matching your input!")
                : TypeParserResult <Command> .Successful(command));
        }
Ejemplo n.º 7
0
 public abstract ValueTask <CheckResult> CheckAsync(ScrapContext context);
Ejemplo n.º 8
0
        public override ValueTask <TypeParserResult <IRole> > ParseAsync(Parameter param, string value, ScrapContext context)
        {
            var   roles = context.Guild.Roles.ToList();
            IRole role  = null;

            if (ulong.TryParse(value, out ulong id) || MentionUtils.TryParseRole(value, out id))
            {
                role = context.Guild.GetRole(id) as IRole;
            }

            if (role is null)
            {
                var match = roles.Where(x =>
                                        x.Name.EqualsIgnoreCase(value));
                if (match.Count() > 1)
                {
                    return(TypeParserResult <IRole> .Unsuccessful(
                               "Multiple roles found, try mentioning the role or using its ID."));
                }

                role = match.FirstOrDefault();
            }
            return(role is null
                ? TypeParserResult <IRole> .Unsuccessful("Role not found.")
                : TypeParserResult <IRole> .Successful(role));
        }
Ejemplo n.º 9
0
 public override ValueTask <CheckResult> CheckAsync(ScrapContext context)
 => UserIds.Contains(context.User.Id)
         ? CheckResult.Successful
         : CheckResult.Unsuccessful("You do not have access to this command!");
Ejemplo n.º 10
0
 public abstract ValueTask <TypeParserResult <T> > ParseAsync(Parameter parameter, string value, ScrapContext context);