Beispiel #1
0
        public override ValueTask <TypeParserResult <SocketRole> > ParseAsync(
            Parameter param,
            string value,
            CommandContext context)
        {
            var        ctx  = context.Cast <VolteContext>();
            SocketRole role = default;

            if (ulong.TryParse(value, out var id) || MentionUtils.TryParseRole(value, out id))
            {
                role = ctx.Guild.GetRole(id).Cast <SocketRole>();
            }

            if (role is null)
            {
                var match = ctx.Guild.Roles.Where(x => x.Name.EqualsIgnoreCase(value)).ToList();
                if (match.Count > 1)
                {
                    return(TypeParserResult <SocketRole> .Failed(
                               "Multiple roles found. Try mentioning the role or using its ID."));
                }

                role = match.FirstOrDefault().Cast <SocketRole>();
            }

            return(role is null
                ? TypeParserResult <SocketRole> .Failed($"Role `{value}` not found.")
                : TypeParserResult <SocketRole> .Successful(role));
        }
Beispiel #2
0
        public override ValueTask <TypeParserResult <SocketTextChannel> > ParseAsync(
            Parameter param,
            string value,
            CommandContext context)
        {
            var ctx = context.Cast <VolteContext>();
            SocketTextChannel channel = default;

            if (ulong.TryParse(value, out var id) || MentionUtils.TryParseChannel(value, out id))
            {
                channel = ctx.Client.GetChannel(id).Cast <SocketTextChannel>();
            }

            if (channel is null)
            {
                var match = ctx.Guild.TextChannels.Where(x => x.Name.EqualsIgnoreCase(value))
                            .ToList();
                if (match.Count > 1)
                {
                    return(TypeParserResult <SocketTextChannel> .Failed(
                               "Multiple channels found. Try mentioning the channel or using its ID."));
                }
            }

            return(channel is null
                ? TypeParserResult <SocketTextChannel> .Failed("Channel not found.")
                : TypeParserResult <SocketTextChannel> .Successful(channel));
        }
Beispiel #3
0
        public override ValueTask <TypeParserResult <SocketGuild> > ParseAsync(
            Parameter parameter,
            string value,
            CommandContext context,
            IServiceProvider provider)
        {
            var         ctx   = context.Cast <VolteContext>();
            SocketGuild guild = default;

            var guilds = ctx.Client.Guilds;

            if (ulong.TryParse(value, out var id))
            {
                guild = guilds.FirstOrDefault(x => x.Id == id);
            }

            if (guild is null)
            {
                var match = guilds.Where(x =>
                                         x.Name.EqualsIgnoreCase(value)).ToList();
                if (match.Count > 1)
                {
                    return(TypeParserResult <SocketGuild> .Unsuccessful(
                               "Multiple guilds found with that name, try using its ID."));
                }

                guild = match.FirstOrDefault();
            }

            return(guild is null
                ? TypeParserResult <SocketGuild> .Unsuccessful("Guild not found.")
                : TypeParserResult <SocketGuild> .Successful(guild));
        }
        public override ValueTask <CheckResult> CheckAsync(object argument, CommandContext context, IServiceProvider provider)
        {
            var u   = argument.Cast <SocketGuildUser>();
            var ctx = context.Cast <VolteContext>() ?? throw new Exception($"Cannot use the CheckHierarchy attribute on a type that isn't {typeof(SocketGuildUser)}.");

            return(new ValueTask <CheckResult>(ctx.User.Hierarchy > u.Hierarchy
                                              ? CheckResult.Successful
                                              : CheckResult.Unsuccessful("Cannot ban someone in a higher, or equal, hierarchy position than yourself.")));
        }
Beispiel #5
0
        public override ValueTask <CheckResult> CheckAsync(object argument, CommandContext context)
        {
            var u   = argument.Cast <SocketGuildUser>() ?? throw new ArgumentException($"Cannot use the CheckHierarchy attribute on a type that isn't {typeof(SocketGuildUser)}.");
            var ctx = context.Cast <VolteContext>();

            return(ctx.User.Id != u.Id
                ? CheckResult.Successful
                : CheckResult.Failed("You cannot run this command on yourself."));
        }
        public override ValueTask <CheckResult> CheckAsync(CommandContext context)
        {
            var ctx = context.Cast <VolteContext>();

            if (ctx.IsModerator(ctx.User))
            {
                return(CheckResult.Successful);
            }

            return(CheckResult.Failed("Insufficient permission."));
        }
Beispiel #7
0
        public override ValueTask <CheckResult> CheckAsync(object argument, CommandContext context)
        {
            var u = argument.Cast <SocketGuildUser>() ?? throw new ArgumentException(
                              $"Cannot use the CheckHierarchy attribute on a type that isn't {typeof(SocketGuildUser)}.");
            var ctx = context.Cast <VolteContext>();

            return(ctx.IsAdmin(u)
                ? CheckResult.Failed("Cannot ban someone with the configured Admin role.")
                : ctx.User.Hierarchy > u.Hierarchy
                    ? CheckResult.Successful
                    : CheckResult.Failed("Cannot ban someone in a higher, or equal, hierarchy position than yourself."));
        }
Beispiel #8
0
 public CommandCalledEventArgs(IResult res, CommandContext context, Stopwatch sw)
 {
     Result    = res;
     Context   = context.Cast <VolteContext>();
     Stopwatch = sw;
     Command   = Context.Message.Content.Split(" ")[0];
     Arguments = Context.Message.Content.Replace($"{Command}", "").Trim();
     if (string.IsNullOrEmpty(Arguments))
     {
         Arguments = "None";
     }
 }
        public override async ValueTask <CheckResult> CheckAsync(CommandContext context, IServiceProvider provider)
        {
            var ctx = context.Cast <VolteContext>();

            if (ctx.User.IsAdmin(provider))
            {
                return(CheckResult.Successful);
            }

            await ctx.ReactFailureAsync();

            return(CheckResult.Unsuccessful(string.Empty));
        }
Beispiel #10
0
        public override ValueTask <TypeParserResult <Tag> > ParseAsync(
            Parameter parameter,
            string value,
            CommandContext context)
        {
            var ctx = context.Cast <VolteContext>();
            var tag = ctx.GuildData.Extras.Tags.FirstOrDefault(x => x.Name.EqualsIgnoreCase(value));

            return(tag is null
                ? TypeParserResult <Tag> .Failed($"The tag **{value}** doesn't exist in this guild. " +
                                                 $"Try using the `{ctx.GuildData.Configuration.CommandPrefix}tags` command to see all tags in this guild.")
                : TypeParserResult <Tag> .Successful(tag));
        }
        public override async ValueTask <CheckResult> CheckAsync(CommandContext context, IServiceProvider services)
        {
            var ctx = context.Cast <VolteContext>();

            if (ctx.User.IsBotOwner())
            {
                return(CheckResult.Successful);
            }

            await ctx.ReactFailureAsync();

            return(CheckResult.Unsuccessful("Insufficient permission."));
        }
Beispiel #12
0
        public override async ValueTask <TypeParserResult <RestUser> > ParseAsync(
            Parameter parameter,
            string value,
            CommandContext context)
        {
            var ctx = context.Cast <VolteContext>();

            RestUser user = default;

            if (ulong.TryParse(value, out var id) || MentionUtils.TryParseUser(value, out id))
            {
                user = await ctx.Client.Shards.First().Rest.GetUserAsync(id);
            }



            return(user is null
                ? TypeParserResult <RestUser> .Failed("User not found.")
                : TypeParserResult <RestUser> .Successful(user));
        }
Beispiel #13
0
        public override ValueTask <TypeParserResult <SocketGuildUser> > ParseAsync(
            Parameter param,
            string value,
            CommandContext context,
            IServiceProvider provider)
        {
            var ctx   = context.Cast <VolteContext>();
            var users = ctx.Guild.Users.ToList();

            SocketGuildUser user = default;

            if (ulong.TryParse(value, out var id) || MentionUtils.TryParseUser(value, out id))
            {
                user = users.FirstOrDefault(x => x.Id == id);
            }

            if (user is null)
            {
                user = users.FirstOrDefault(x => x.ToString().EqualsIgnoreCase(value));
            }

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

                user = match.FirstOrDefault();
            }

            return(user is null
                ? TypeParserResult <SocketGuildUser> .Unsuccessful("User not found.")
                : TypeParserResult <SocketGuildUser> .Successful(user));
        }
Beispiel #14
0
 public CommandCalledEventArgs(IResult res, CommandContext context, Stopwatch sw)
 {
     Result    = res;
     Context   = context.Cast <VolteContext>();
     Stopwatch = sw;
 }
Beispiel #15
0
 public override ValueTask <TypeParserResult <T> > ParseAsync(Parameter _, string value,
                                                              CommandContext context) => ParseAsync(value, context.Cast <VolteContext>());