Esempio n. 1
0
 static Features()
 {
     PublishResults      = true;
     AnnouncePairings    = true;
     JoinGames           = true;
     CreateVoiceChannels = true;
     ConnectToDiscord    = true;
     try
     {
         var stats = LogsiteApi.GetStatsAsync().GetAwaiter().GetResult();
         if (DateTimeOffset.UtcNow.Subtract(stats.LastSwitcheroo).TotalHours < 6)
         {
             PublishResults = false;
         }
     }
     catch (Exception c)
     {
         Console.WriteLine(c);
         if (c is WebException we)
         {
             if (we.Status == WebExceptionStatus.ProtocolError)
             {
                 return;
             }
         }
         SentrySdk.CaptureException(c);
     }
 }
Esempio n. 2
0
        public async static Task DoPDHRoleAsync()
        {
            var stats = await LogsiteApi.GetStatsAsync();

            var pdh     = stats.Formats[MagicFormat.PennyDreadfulCommander.ToString()];
            var players = await GetDiscordIDsAsync(pdh.LastMonth.Players);

            await DiscordService.SyncRoleAsync(PENNY_DREADFUL_GUILD_ID, "PDH", players);
        }
Esempio n. 3
0
        public async Task TestStats()
        {
            var stats = await LogsiteApi.GetStatsAsync();

            Assert.That(stats, Is.Not.Null);
            foreach (var f in stats.Formats)
            {
                Assert.That(f.Value.Name, Is.Not.Null.Or.Empty);
            }

            Assert.That(stats.LastSwitcheroo < DateTime.Now);
        }
Esempio n. 4
0
        public async Task TestSwitcheroo()
        {
            var stats = await LogsiteApi.GetStatsAsync();

            if (DateTimeOffset.UtcNow.Subtract(stats.LastSwitcheroo).TotalHours < 6)
            {
                Assert.That(!Features.PublishResults);
            }
            else
            {
                Assert.That(Features.PublishResults);
            }
        }
Esempio n. 5
0
        public async static Task WeeklyRecapAsync()
        {
            if (await DiscordService.CheckForPinnedMessageAsync())
            {
                return;
            }
            var stats = await LogsiteApi.GetStatsAsync();

            var PdGames  = stats.Formats[MagicFormat.PennyDreadful.ToString()].LastWeek.NumMatches;
            var PdhGames = stats.Formats[MagicFormat.PennyDreadfulCommander.ToString()]?.LastWeek?.NumMatches ?? 0;

            var prevPdGames  = stats.Formats[MagicFormat.PennyDreadful.ToString()].LastLastWeek?.NumMatches ?? 0;
            var prevPdhGames = stats.Formats[MagicFormat.PennyDreadfulCommander.ToString()].LastLastWeek?.NumMatches ?? 0;

            var players = stats.Formats[MagicFormat.PennyDreadful.ToString()].LastWeek.Players.Union(stats.Formats[MagicFormat.PennyDreadfulCommander.ToString()]?.LastWeek?.Players ?? new string[0]);

            var sb = new StringBuilder();

            sb.Append($"In the last week, I saw {players.Count()} people from the Penny Dreadful community play {PdGames} Penny Dreadful matches");
            if (prevPdGames > 0)
            {
                var percent = ((PdGames - prevPdGames) / (double)prevPdGames);
                var pstr    = Math.Abs(percent).ToString("p0");
                pstr = percent >= 0 ? $"up {pstr}" : $"down {pstr}";
                sb.Append($" ({pstr} from last week)");
            }

            sb.Append($" and {PdhGames} PDH games");
            if (prevPdhGames > 0)
            {
                var    percent = ((PdhGames - prevPdhGames) / (double)prevPdhGames);
                string pstr;
                if (percent >= 0)
                {
                    pstr = $"up {percent.ToString("p0")}";
                }
                else
                {
                    pstr = $"down {Math.Abs(percent).ToString("p0")}";
                }
                sb.Append($" ({pstr} from last week)");
            }
            sb.Append(".");
            await DiscordService.SendToGeneralAsync(sb.ToString().Replace(" %", "%"), true);
        }