Esempio n. 1
0
        public OkResult(IEnumerable <EmbedBuilder> pages, uint pageSplit = 0, Color?color = null, IGuildUser author = null,
                        VolteContext ctx = null, string title = null, PaginatedAppearanceOptions options            = null)
        {
            _pager = PaginatedMessage.Builder.New
                     .WithPages(pages);

            if (color.HasValue)
            {
                _pager.WithColor(color.Value);
            }
            if (author != null)
            {
                _pager.WithAuthor(author);
            }
            if (ctx != null)
            {
                _pager.WithDefaults(ctx);
            }
            if (title != null)
            {
                _pager.WithTitle(title);
            }
            if (options != null)
            {
                _pager.WithOptions(options);
            }
            if (pageSplit > 0)
            {
                _pager.SplitPages(pageSplit);
            }
        }
Esempio n. 2
0
        public override ValueTask <TypeParserResult <Tag> > ParseAsync(string value, VolteContext ctx)
        {
            if (ctx.GuildData.Extras.Tags.AnyGet(x => x.Name.EqualsIgnoreCase(value), out var tag))
            {
                return(Success(tag));
            }

            return(Failure($"The tag **{value}** doesn't exist in this guild. " +
                           $"Try using the `{CommandHelper.FormatUsage(ctx, ctx.Services.Get<CommandService>().GetCommand("Tags List"))}` command to see all tags in this guild."));
        }
Esempio n. 3
0
        public override async ValueTask <ResultCompletionData> ExecuteResultAsync(VolteContext ctx)
        {
            if (_after is null)
            {
                return(new ResultCompletionData());
            }

            if (_awaitCallback)
            {
                await _after();
            }
            else
            {
                _ = _after();
            }
            return(new ResultCompletionData());
        }
Esempio n. 4
0
 public override ValueTask <TypeParserResult <IEmote> > ParseAsync(string value, VolteContext _)
 => Emote.TryParse(value, out var emote)
         ? Success(emote)
         : Regex.Match(value, "[^\u0000-\u007F]+", RegexOptions.IgnoreCase).Success
             ? Success(new Emoji(value))
             : Failure("Emote not found.");
Esempio n. 5
0
        public override ValueTask <TypeParserResult <bool> > ParseAsync(string value, VolteContext _)
        {
            if (_trueValues.ContainsIgnoreCase(value))
            {
                return(Success(true));
            }

            if (_falseValues.ContainsIgnoreCase(value))
            {
                return(Success(false));
            }

            return(bool.TryParse(value, out var result)
                ? Success(result)
                : Failure($"Failed to parse a {typeof(bool)} (true/false) value. Try using true or false."));
        }
Esempio n. 6
0
 public override ValueTask <TypeParserResult <Dictionary <string, string> > > ParseAsync(string value, VolteContext _)
 => UnixHelper.TryParseNamedArguments(value, out var result)
     ? Success(result.Parsed)
     : Failure(result.Error.Message);
Esempio n. 7
0
        public override ValueTask <TypeParserResult <SocketRole> > ParseAsync(string value, VolteContext ctx)
        {
            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(Failure(
                               "Multiple roles found. Try mentioning the role or using its ID."));
                }

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

            return(role is null
                ? Failure($"Role {Format.Code(value)} not found.")
                : Success(role));
        }
Esempio n. 8
0
        public override ValueTask <TypeParserResult <TimeSpan> > ParseAsync(string value, VolteContext _)
        {
            if (!TimeSpanRegex.IsMatch(value, out var match))
            {
                return(Failure("Content contained no valid TimeSpan expressions."));
            }

            var r      = ..^ 1;
            var result = new TimeSpan();

            if (match.Groups["Years"].Success && int.TryParse(match.Groups["Years"].Value[r], out var years))
            {
                result = result.Add((years * 365).Days());
            }

            if (match.Groups["Weeks"].Success && int.TryParse(match.Groups["Weeks"].Value[r], out var weeks))
            {
                result = result.Add((weeks * 7).Days());
            }

            if (match.Groups["Days"].Success && int.TryParse(match.Groups["Days"].Value[r], out var days))
            {
                result = result.Add(days.Days());
            }

            if (match.Groups["Hours"].Success && int.TryParse(match.Groups["Hours"].Value[r], out var hours))
            {
                result = result.Add(hours.Hours());
            }

            if (match.Groups["Minutes"].Success && int.TryParse(match.Groups["Minutes"].Value[r], out var minutes))
            {
                result = result.Add(minutes.Minutes());
            }

            if (match.Groups["Seconds"].Success && int.TryParse(match.Groups["Seconds"].Value[r], out var seconds))
            {
                result = result.Add(seconds.Seconds());
            }

            return(Success(result));
        }
Esempio n. 9
0
 public abstract ValueTask <ResultCompletionData> ExecuteResultAsync(VolteContext ctx);
Esempio n. 10
0
        public override async ValueTask <TypeParserResult <RestGuildUser> > ParseAsync(string value, VolteContext ctx)
        {
            RestGuildUser user = null;

            if (ulong.TryParse(value, out var id) || MentionUtils.TryParseUser(value, out id))
            {
                user = await ctx.Client.Rest.GetGuildUserAsync(ctx.Guild.Id, id);
            }

            return(user is null
                ? Failure("User not found.")
                : Success(user));
        }
Esempio n. 11
0
        public override ValueTask <TypeParserResult <SocketGuildUser> > ParseAsync(string value, VolteContext ctx)
        {
            var users = ctx.Guild.Users.ToList();

            SocketGuildUser user = null;

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

            user ??= users.FirstOrDefault(x => x.ToString().EqualsIgnoreCase(value));

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

                user = match.FirstOrDefault();
            }

            return(user is null
                ? Failure("User not found.")
                : Success(user));
        }
Esempio n. 12
0
        public override ValueTask <TypeParserResult <SocketGuild> > ParseAsync(string value, VolteContext ctx)
        {
            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(Failure(
                               "Multiple guilds found with that name, try using its ID."));
                }

                guild = match.FirstOrDefault();
            }

            return(guild is null
                ? Failure("Guild not found.")
                : Success(guild));
        }
Esempio n. 13
0
        public override ValueTask <TypeParserResult <Color> > ParseAsync(string value, VolteContext _)
        {
            Color?c = null;

            if (uint.TryParse(value.StartsWith("#") ? value[1..] : value, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out var colorInt))
Esempio n. 14
0
        public override ValueTask <TypeParserResult <SocketTextChannel> > ParseAsync(string value, VolteContext ctx)
        {
            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(Failure(
                               "Multiple channels found. Try mentioning the channel or using its ID."));
                }
                channel = match.First();
            }

            return(channel is null
                ? Failure("Channel not found.")
                : Success(channel));
        }
Esempio n. 15
0
 public abstract ValueTask <TypeParserResult <T> > ParseAsync(string value, VolteContext ctx);