Пример #1
0
        public async Task GetWinnerAsync([Remainder] string prizes)
        {
            if (string.IsNullOrEmpty(prizes))
            {
                await ReplyAsync("Error");

                return;
            }

            var splitPrizes = new List <string>(prizes.Split(','));

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

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

                if (guild is null)
                {
                    await ReplyAsync("Guild not found.");

                    return;
                }

                var users        = guild.LotteryUsers.ToList();
                var savedChannel = guild.GetChannel("Lottery");
                var channel      = Context.Guild.GetTextChannel(savedChannel.DiscordID);
                var savedLink    = guild.GetLink("LotteryWinner");

                var lotteryGame = new LotteryGame(users, splitPrizes);
                var winners     = lotteryGame.GetWinners(splitPrizes.Count, true);

                winners.ForEach(x => x.Name = x.User.GetName(Context));
                await channel.SendMessageAsync(embed : EmbedUtils.CreateWinnerEmbed(winners, splitPrizes, savedLink.URL));

                guild.LotteryUsers.Clear();
                await context.SaveChangesAsync();
            }
        }
Пример #2
0
        public async Task UpdateTicketsAsync()
        {
            bool finished = false;

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

                var guild = await context.Guilds
                            .Include(x => x.LotteryUsers)
                            .ThenInclude(x => x.User)
                            .Include(x => x.Channels)
                            .Include(x => x.Messages)
                            .SingleOrDefaultAsync(x => x.DBDiscordID == Context.Guild.Id.ToString());

                var users        = guild.LotteryUsers.ToList();
                var savedChannel = guild.GetChannel("Lottery");
                var channel      = Context.Guild.GetTextChannel(savedChannel.DiscordID);

                var savedMessage = guild.GetMessage("LotteryMessage");

                var message = await channel.GetMessageAsync(savedChannel.DiscordID);

                if (message is SocketUserMessage socketMessage)
                {
                    users.ForEach(x => x.Name = x.User.GetName(Context));
                    await socketMessage.ModifyAsync(x => x.Embed = EmbedUtils.CreateParticipantEmbed(users));

                    finished = true;
                }

                if (finished)
                {
                    return;
                }

                await channel.SendMessageAsync(embed : EmbedUtils.CreateParticipantEmbed(users));
            }
        }