Пример #1
0
        public async Task GetBenchesAsync(int pageIndex = 1)
        {
            /*await ReplyAsync("Not implemented yet");
             * return;*/

            using (var context = new RaidContext())
            {
                await context.Database.EnsureCreatedAsync();

                var guild = await context.Guilds
                            .Include(x => x.Benches)
                            .SingleOrDefaultAsync(x => x.DBDiscordID == Context.Guild.Id.ToString());

                if (guild is null)
                {
                    await ReplyAsync("Guild not found.\nRun startup command first.");

                    return;
                }

                var paging = new Pager <IRaidBench>(guild.Benches.ToList(), 5);

                await ReplyAsync(embed : EmbedUtils.CreateBenchEmbed(paging.GetPage(pageIndex - 1), pageIndex, paging.PageCount));
            }
        }
Пример #2
0
        public async Task GetPlayerDPSProfileAsync()
        {
            using (var raidContext = new RaidContext())
                using (var guildContext = new GuildContext())
                {
                    await raidContext.Database.EnsureCreatedAsync();

                    await guildContext.Database.EnsureCreatedAsync();

                    var user = await raidContext.Users
                               .Include(x => x.Records)
                               .SingleOrDefaultAsync(x => x.DBDiscordID == Context.User.Id.ToString() && x.Guild.DBDiscordID == Context.Guild.Id.ToString());

                    var guildUser = await guildContext.Users
                                    .AsQueryable()
                                    .SingleOrDefaultAsync(x => x.DBDiscordID == Context.User.Id.ToString() && x.Guild.DBDiscordID == Context.Guild.Id.ToString());

                    if (user is null || guildUser is null)
                    {
                        await ReplyAsync(embed : EmbedUtils.CreatePlayerNotFoundEmbed());

                        return;
                    }

                    var benches = raidContext.RaidBenches
                                  .AsQueryable()
                                  .Where(x => x.Guild.DBDiscordID == Context.Guild.Id.ToString())
                                  .AsAsyncEnumerable();
                    await user.Records.UpdateRecordStatusesAsync(benches);

                    guildUser.AvatarUrl = guildUser.GetAvatarUrl(Context);
                    user.AccountName    = guildUser.GetName(Context);

                    var profilePic = await guildUser.DownloadAvatarAsync(Services.GetRequiredService <HttpClient>());

                    System.Drawing.Image.FromStream(profilePic).Save($"{AppDomain.CurrentDomain.BaseDirectory}Data/Temp/{user.DBDiscordID}.jpg");

                    try
                    {
                        string imgPath = await RaidProfile.CreateRaidProfileImageAsync(user, $"{AppDomain.CurrentDomain.BaseDirectory}Data/Temp/{user.DBDiscordID}.jpg");

                        await Context.Channel.SendFileAsync(imgPath);

                        System.IO.File.Delete(imgPath);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        var paging  = new Pager <IRaidRecord>(user.Records.ToList(), 5);
                        var records = paging.GetPage(0).ToList();
                        await records.UpdateRecordStatusesAsync(benches);

                        await Context.Channel.SendMessageAsync(embed : EmbedUtils.CreateDPSProfileEmbed(records, 1, paging.PageCount));
                    }
                }
        }
Пример #3
0
        public async Task GetPlayerDPSProfileAsync(int pageIndex)
        {
            using (var context = new RaidContext())
            {
                await context.Database.EnsureCreatedAsync();

                var guild = await context.Guilds
                            .Include(x => x.Links)
                            .SingleOrDefaultAsync(x => x.DBDiscordID == Context.Guild.Id.ToString());

                if (guild is null)
                {
                    await ReplyAsync("Guild was not found in the database.");

                    return;
                }

                var user = await context.Users
                           .Include(x => x.Records)
                           .SingleOrDefaultAsync(x => x.DBDiscordID == Context.User.Id.ToString() && x.Guild == guild);

                var benches = context.RaidBenches
                              .AsQueryable()
                              .Where(x => x.Guild.DBDiscordID == guild.DBDiscordID)
                              .AsAsyncEnumerable();
                if (user is null)
                {
                    await ReplyAsync(embed : EmbedUtils.CreatePlayerNotFoundEmbed());

                    return;
                }

                //user.Records.UpdateRecordStatuses(guild.Benches);
                var paging  = new Pager <IRaidRecord>(user.Records.ToList(), 5);
                var records = paging.GetPage(pageIndex - 1).ToList();
                await records.UpdateRecordStatusesAsync(benches);

                await ReplyAsync(embed : EmbedUtils.CreateDPSProfileEmbed(records, pageIndex, paging.PageCount));
            }
        }