コード例 #1
0
        private async Task AnnounceNewMatches()
        {
            foreach (var match in Database.Matches.Where(x => !x.Announced))
            {
                var challongeTournament = await ChallongeTournaments.getTournament(match.Tournament.ShortName);

                var challongeMatch = await ChallongeMatches.GetMatch(match.Tournament.ChallongeIDWithSubdomain, match.ID);

                if (!challongeMatch.MatchMarkedAsActive)
                {
                    continue;
                }

                var team1 = await Database.Participants.FindAsync(ParticipantIDCache.Instance.GetParticipantID(challongeMatch.player1_id.Value));

                var team2 = await Database.Participants.FindAsync(ParticipantIDCache.Instance.GetParticipantID(challongeMatch.player2_id.Value));

                var args = new OnNewMatchStartedArgs
                {
                    Match            = challongeMatch,
                    Tournament       = challongeTournament,
                    Team1DiscordName = team1?.DiscordMentionName,
                    Team1SeatNum     = team1?.SeatNum,
                    Team2DiscordName = team2?.DiscordMentionName,
                    Team2SeatNum     = team2?.SeatNum
                };
                OnNewMatchStarted?.Invoke(this, args);

                match.Announced = true;
            }
            await Database.SaveChangesAsync();
        }
コード例 #2
0
        private async void OnOnNewMatchStarted(object sender, OnNewMatchStartedArgs args)
        {
            IParticipant team1 = await args.Match.player1;
            IParticipant team2 = await args.Match.player2;

            var teamNameGenerator = new Func <string, string, int?, string>((t, u, p) => "(" + t + (!string.IsNullOrWhiteSpace(u) ? $" {u}" : "") + (p.HasValue ? $" pladsnr.: {p}" : "") + ")");

            string message = $":gun:** {teamNameGenerator(team1.name, args.Team1DiscordName, args.Team1SeatNum)} vs {teamNameGenerator(team2.name, args.Team2DiscordName, args.Team2SeatNum)} **:gun:" +
                             $"{Environment.NewLine}Kampen er klar til at blive spillet!";

            if (!string.IsNullOrWhiteSpace(args.Match.Location))
            {
                message += $"{Environment.NewLine}Server: {args.Match.Location}";
            }

            DiscordBot.SendMessage(message, args.Tournament.URL);
            Console.WriteLine($"Match {team1.name} vs {team2.name} is ready");
        }