Ejemplo n.º 1
0
        public override async ValueTask Process(MatchesContext matchesContext)
        {
            IAsyncEnumerable <Match> matches = matchesContext.GetMatchesByRoleAsync(Role);

            if (!await matches.AnyAsync())
            {
                Console.WriteLine("No historic match data.");
            }
            else
            {
                using IXLWorkbook workbook = ConstructSpreadsheet(await matches.ToListAsync());

                string filePath = Path.GetFullPath($"{Name}_{Role}.xlsx");
                workbook.SaveAs(filePath);
                Console.WriteLine($"Successfully exported match data to \"{filePath}\"");
            }
        }
Ejemplo n.º 2
0
 private async Task CheckPostsQuery(IAsyncEnumerable <IPost> posts)
 {
     Assert.True(
         await posts
         .AnyAsync(post => post.Message.Contains(Config.DefaultPostQuery)));
 }
Ejemplo n.º 3
0
        public async Task <CommandResult> InviteNextPlayerAsync(Invite invite)
        {
            IAsyncEnumerable <UserInGuild> list = guildData.GetSortedList().ToAsyncEnumerable();

            if (invite.InviteRole is ulong roleId)
            {
                list = list.WhereAwait(async x =>
                {
                    var restGuildUser = await restClient.GetGuildUserAsync(guildId, x.UserId);

                    var hasRole = restGuildUser.RoleIds.Contains(roleId);

                    return(hasRole == invite.IsInviteRolePositive);
                });
            }

            if (!await list.AnyAsync())
            {
                return(CommandResult.FromError($"Could not invite additional player. List is empty."));
            }

            string message;

            try
            {
                message = string.Format(guildData.DMMessageFormat, invite.FormatData);
            }
            catch (Exception)
            {
                return(CommandResult.FromError("The arguments had the wrong format"));
            }

            StringBuilder warnings = new StringBuilder();

            // Send invites
            var player = await list.FirstAsync();

            player.IsInWaitingList = false;
            player.PlayCount++;

            dataContext.Update(player);
            dataContext.SaveChanges();

            var restGuildUser = await restClient.GetGuildUserAsync(guildId, player.UserId);

            try
            {
                ComponentBuilder componentBuilder = new ComponentBuilder();
                componentBuilder.WithButton("Yes", customId: $"joinYes;{invite.Id}");
                componentBuilder.WithButton("No", customId: $"joinNo;{invite.Id}");


                var userMessage = await restGuildUser.SendMessageAsync($"Are you ready to join? You have 1 minute to respond.", component : componentBuilder.Build());


                invite.InvitedUsers.Add(new InvitedUser
                {
                    Invite              = invite,
                    InviteTime          = DateTime.Now,
                    DmQuestionMessageId = userMessage.Id,
                    User = player
                });

                dataContext.Update(invite);
                dataContext.SaveChanges();
            }
            catch (Exception ex)
            {
                warnings.AppendLine($"Could not invite {restGuildUser.Mention}. Exception: {ex.Message}");
            }

            await this.dataContext.SaveChangesAsync();

            return(CommandResult.FromSuccess("Players have been invited." + (warnings.Length > 0 ? "\r\n" + warnings.ToString() : "")));
        }