Exemple #1
0
        public async Task SearchPasta(EventContext e)
        {
            Locale locale = Locale.GetEntity(e.Channel.Id.ToDbLong());

            if (string.IsNullOrWhiteSpace(e.arguments))
            {
                await Utils.ErrorEmbed(locale, e.GetResource("searchpasta_error_no_arg"))
                .QueueToChannel(e.Channel.Id);

                return;
            }

            List <string> arguments = e.arguments.Split(' ').ToList();
            int           page      = 0;

            if (arguments.Count > 1)
            {
                if (int.TryParse(arguments[arguments.Count - 1], out page))
                {
                    page -= 1;
                }
            }

            string query = arguments[0];

            using (var context = new MikiContext())
            {
                var pastasFound = await context.Pastas.Where(x => x.Id.ToLower().Contains(query.ToLower()))
                                  .OrderByDescending(x => x.Id)
                                  .Skip(25 * page)
                                  .Take(25)
                                  .ToListAsync();


                var totalCount = await context.Pastas.Where(x => x.Id.Contains(query))
                                 .CountAsync();

                if (pastasFound?.Count > 0)
                {
                    string resultString = "";

                    pastasFound.ForEach(x => { resultString += "`" + x.Id + "` "; });

                    IDiscordEmbed embed = Utils.Embed;
                    embed.Title       = e.GetResource("miki_module_pasta_search_header");
                    embed.Description = resultString;
                    embed.CreateFooter();
                    embed.Footer.Text = e.GetResource("page_index", page + 1, (Math.Ceiling((double)totalCount / 25)).ToString());

                    await embed.QueueToChannel(e.Channel);

                    return;
                }

                await Utils.ErrorEmbed(locale, e.GetResource("miki_module_pasta_search_error_no_results", arguments[0]))
                .QueueToChannel(e.Channel);
            }
        }
Exemple #2
0
        public async Task SearchPasta(EventContext e)
        {
            Locale locale = Locale.GetEntity(e.Guild.Id.ToDbLong());

            if (string.IsNullOrWhiteSpace(e.arguments))
            {
                await Utils.ErrorEmbed(locale, "Please specify the terms you want to search.")
                .SendToChannel(e.Channel.Id);

                return;
            }

            List <string> arguments = e.arguments.Split(' ').ToList();
            int           page      = 0;

            if (arguments.Count > 1)
            {
                if (int.TryParse(arguments[arguments.Count - 1], out page))
                {
                    page -= 1;
                }
            }

            using (var context = MikiContext.CreateNoCache())
            {
                context.Set <GlobalPasta>().AsNoTracking();
                var pastasFound = context.Database.SqlQuery <PastaSearchResult>("select [GlobalPastas].Id, count(*) OVER() AS total_count from [GlobalPastas] where Id like @p0 ORDER BY id OFFSET @p1 ROWS FETCH NEXT 25 ROWS ONLY;",
                                                                                "%" + arguments[0] + "%", page * 25).ToList();

                if (pastasFound?.Count > 0)
                {
                    string resultString = "";

                    pastasFound.ForEach(x => { resultString += "`" + x.Id + "` "; });

                    IDiscordEmbed embed = Utils.Embed;
                    embed.Title       = "🔎 I found these pastas";
                    embed.Description = resultString;
                    embed.CreateFooter();
                    embed.Footer.Text = $"page {page + 1} of {(Math.Ceiling((double)pastasFound[0].Total_Count / 25)).ToString()}";

                    await e.Channel.SendMessage(embed);

                    return;
                }
                await e.Channel.SendMessage(Utils.ErrorEmbed(locale, $"Sorry, but we couldn't find a pasta with `{arguments[0]}`"));
            }
        }
        public async Task SearchUser(EventContext e)
        {
            string[]                 arg   = e.arguments.Split(' ');
            IDiscordEmbed            embed = Utils.Embed;
            RocketLeagueSearchResult user  = await api.SearchUsersAsync(arg[0], (arg.Length >= 2)?int.Parse(arg[1]) : 0);

            embed.Title = $"Found {user.TotalResults} users with the name `{arg[0]}`";
            embed.CreateFooter();
            embed.Footer.Text = $"Page {user.Page} of ${(int)Math.Ceiling((double)user.TotalResults / user.MaxResultsPerPage)}";

            List <string> names = new List <string>();

            user.Data.ForEach(z => { names.Add(z.DisplayName); });

            embed.Description = string.Join(", ", names);

            embed.QueueToChannel(e.Channel);
        }
Exemple #4
0
        public async Task MyPasta(EventContext e)
        {
            Locale locale = Locale.GetEntity(e.Guild.Id.ToDbLong());

            int page = 0;

            if (!string.IsNullOrWhiteSpace(e.arguments))
            {
                if (int.TryParse(e.arguments, out page))
                {
                    page -= 1;
                }
            }

            long authorId = e.Author.Id.ToDbLong();

            using (var context = MikiContext.CreateNoCache())
            {
                context.Set <GlobalPasta>().AsNoTracking();

                var pastasFound = context.Database.SqlQuery <PastaSearchResult>("select [GlobalPastas].id, count(*) OVER() AS total_count from [GlobalPastas] where CreatorID = @p0 ORDER BY id OFFSET @p1 ROWS FETCH NEXT 25 ROWS ONLY;",
                                                                                authorId, page * 25).ToList();

                if (pastasFound?.Count > 0)
                {
                    string resultString = "";

                    pastasFound.ForEach(x => { resultString += "`" + x.Id + "` "; });

                    IDiscordEmbed embed = Utils.Embed;
                    embed.Title       = e.Author.Username + "'s pastas";
                    embed.Description = resultString;
                    embed.CreateFooter();
                    embed.Footer.Text = $"page {page + 1} of {(Math.Ceiling((double)pastasFound[0].Total_Count / 25)).ToString()}";

                    await e.Channel.SendMessage(embed);

                    return;
                }
                await e.Channel.SendMessage(Utils.ErrorEmbed(locale, $"Sorry, but you don't have any pastas yet.."));
            }
        }