Ejemplo n.º 1
0
 public static OperatorType GetOperatorTypeByText(string operatorText)
 {
     return(OperatorTexts.First(x => x.Value == operatorText).Key);
 }
Ejemplo n.º 2
0
 public static int GetOperatorPriority(OperatorType operatorType)
 {
     return(OperatorPriorities.First(x => x.Key == operatorType).Value);
 }
 public static TrigonometricFunctionType GetTrigonometricFunctionTypeByText(string value)
 {
     return(TrigonometricFunctionTexts.First(x => x.Value == value).Key);
 }
Ejemplo n.º 4
0
 public FactionsInteractionManager(IEnumerable <FactionUnityObject> factionUnities)
 {
     _factions     = CreateFactionInteractions(factionUnities);
     ActiveFaction = _factions.First().Value.Faction;
 }
Ejemplo n.º 5
0
 public T ResolveRequired <T>(params IResolverParameter[] parameters) where T : class
 => (T)_instances.First(t => _typeComparer.Equals(t.Key, typeof(T))).Value;
Ejemplo n.º 6
0
        private async Task DiscordOnMessageReceived(MessageReceivedEventArgs e)
        {
            var db    = _serviceProvider.GetRequiredService <AatroxDbContext>();
            var repo  = db.RequestRepository <IGetOrAddRepository <GuildEntity> >();
            var guild = await repo.GetOrAddAsync(e.Message.Guild.Id);

            if (!guild.ResolveOsuUrls)
            {
                return;
            }

            if (!Uri.TryCreate(e.Message.Content, UriKind.Absolute, out var uri))
            {
                return;
            }

            if (uri.Host != "osu.ppy.sh")
            {
                return;
            }

            var url   = uri.AbsoluteUri;
            var split = url.Split('/', StringSplitOptions.RemoveEmptyEntries);
            var mode  = split[3].Split('#')[1];

            mode = mode switch
            {
                "fruits" => "catch",
                "osu" => "standard",
                "taiko" => "taiko",
                _ => "standard"
            };

            var beatmapId = split[4];

            var beatmap = await Osu.GetBeatmapByIdAsync(long.Parse(beatmapId),
                                                        (GameMode)Enum.Parse(typeof(GameMode), mode, true), true);

            ReadOnlyDictionary <float, PerformanceData>?pps = null;

            if (beatmap == null)
            {
                _log.Warn("Beatmap null?");
                return;
            }

            var gc         = (CachedGuildChannel)e.Message.Channel;
            var permission = gc.Guild.CurrentMember.GetPermissionsFor(gc);

            if (permission.Has(Permission.Administrator) || permission.Has(Permission.ManageMessages))
            {
                await((CachedUserMessage)e.Message).ModifyAsync(x => x.Flags = MessageFlags.SuppressedEmbeds);
            }

            try
            {
                pps = await OppaiClient.GetPPAsync(long.Parse(beatmapId), new float[] { 100, 99, 98, 97, 95 });
            }
            catch (Exception ex)
            {
                _log.Error("Attempting to get PP for a converted beatmap. It failed.", ex);
            }

            var successRate = 0.0;

            if (beatmap.PassCount.HasValue && beatmap.PlayCount.HasValue)
            {
                successRate = Math.Round((double)beatmap.PassCount.Value / beatmap.PlayCount.Value, 2) * 100;
            }

            var embed = new LocalEmbedBuilder
            {
                Color  = _config.DefaultEmbedColor,
                Author = new LocalEmbedAuthorBuilder
                {
                    Name    = $"{beatmap.Title} - {beatmap.Artist} [{beatmap.Difficulty}] | {beatmap.GameMode}",
                    Url     = uri.ToString(),
                    IconUrl = beatmap.ThumbnailUri.ToString()
                },
                Description = $"This beatmap was made by `{beatmap.Author}` (`{beatmap.AuthorId}`). It has an average BPM of `{beatmap.Bpm}`.",
                Footer      = new LocalEmbedFooterBuilder
                {
                    Text = $"{beatmap.State} since {beatmap.LastUpdate:g} | {beatmap.FavoriteCount} favs | {successRate}% success rate"
                },
                ThumbnailUrl = beatmap.ThumbnailUri.ToString()
            };

            var str = $"CS: `{beatmap.CircleSize}` | AR: `{beatmap.ApproachRate}`" +
                      $"\nOD: `{beatmap.OverallDifficulty}` | HP: `{beatmap.HpDrain}`";

            if (beatmap.MaxCombo.HasValue)
            {
                str += $"\nMax combo: `{beatmap.MaxCombo}`";
            }
            else if (pps != null)
            {
                str += $"\nMax combo: `{pps.First().Value.MaxCombo}`";
            }

            if (pps != null)
            {
                str += $"\n`{Math.Round(pps.First().Value.Stars, 2)}` stars";
            }

            embed.AddField("Difficulties", str, true);

            embed.AddField("Lengths", $"Length: `{beatmap.TotalLength:g}`" +
                           $"\nHit Length: `{beatmap.HitLength:g}`", true);

            if (pps != null)
            {
                var lines = pps.Select(x => $"`{Math.Round(x.Key)}%: {Math.Round(x.Value.Pp)}`");
                embed.AddField("Performance Points", string.Join(" | ", lines));
            }

            if (beatmap.GameMode == GameMode.Catch || beatmap.GameMode == GameMode.Mania)
            {
                embed.AddField("Not supported!",
                               $"**`{beatmap.GameMode}` is not supported. Star rating and performance points cannot be calculated.**");
            }

            await e.Message.Channel.SendMessageAsync(embed : embed.Build());

            AddOrUpdateValue(e.Message.Channel.Id, beatmap.BeatmapId);
        }
    }