Beispiel #1
0
        public static CakeEmbedBuilder ReturnUserProfile(OsuJsonUser user, int mode)
        {
            var embedProfile = new CakeEmbedBuilder();

            embedProfile.WithAuthor(author =>
            {
                author
                .WithName($"User stats of { user.username }")
                .WithUrl($"{ user.url }")
                .WithIconUrl($"{ user.flag }");
            })
            .WithThumbnailUrl($"https://a.ppy.sh/{user.user_id}_1512645682.png")
            .WithFooter($"{ (OsuModeEnum)mode }")
            .WithDescription(
                $"**Ranked Score: **{ user.ranked_score }\n" +
                $"**Total Score: **{ user.total_score }\n" +
                $"**Rank: **{ user.pp_rank } ({ user.country } : { user.pp_country_rank })\n" +
                $"**PP: **{ Math.Round(user.pp_raw, 1) }\n" +
                $"**Accuracy: **{ user.accuracy }%\n" +
                $"**Play Count: **{ user.playcount }\n" +
                $"**Level: **{ user.level }\n" +
                $"**Creation Date: ** { user.join_date.ToShortDateString() }")
            .AddField("Links",
                      $"[osu!chan]({ user.osuchan }) [osu!Skills]({ user.osuskills }) [osu!track]({ user.osutrack })\n");
            return(embedProfile);
        }
Beispiel #2
0
        public static CakeEmbedBuilder ReturnUserBest(OsuJsonUser user, string thumbnail, List <Tuple <string, string> > fields, int mode)
        {
            var embedTop = new CakeEmbedBuilder();

            embedTop.WithAuthor(author =>
            {
                author
                .WithName($"Top play(s) of {user.username}")
                .WithUrl($"{user.url}")
                .WithIconUrl($"{user.image}");
            })
            .WithFooter($"{(OsuModeEnum)mode}")
            .WithThumbnailUrl(thumbnail);

            //data of fields.
            foreach (var field in fields)
            {
                embedTop.AddField(x =>
                {
                    x.Name  = field.Item1;
                    x.Value = field.Item2;
                });
            }

            return(embedTop);
        }
Beispiel #3
0
        public static CakeEmbedBuilder ReturnStatusEmbed(IGuild guild)
        {
            CakeEmbedBuilder statusEmbedBuilder = new CakeEmbedBuilder();

            statusEmbedBuilder.WithAuthor($"{Main.GetClient().CurrentUser.Username}");
            statusEmbedBuilder.WithTitle($"Status of {Main.GetClient().CurrentUser.Username}");
            statusEmbedBuilder.WithDescription($"Version: ``{Json.CakeJson.GetConfig().Version}``");

            statusEmbedBuilder.WithFields(GetStatusFields());

            statusEmbedBuilder.WithFooter(GetUptimeAsString());

            return(statusEmbedBuilder);

            #region Local_Function
            string GetUptimeAsString()
            {
                TimeSpan upTimeSpan = DateTime.UtcNow.Subtract(Process.GetCurrentProcess().StartTime.ToUniversalTime());

                StringBuilder message = new StringBuilder(string.Empty);

                int days   = upTimeSpan.Days;
                int months = GetEstimatedMonthFromSubtractingDays(ref days);
                int years  = GetYearsFromSubtractingMonths(ref months);

                // TODO: Possible refactor?
                AppendTimeToStringIfPositive(ref message, "Year", years);
                AppendTimeToStringIfPositive(ref message, "Month", months);
                AppendTimeToStringIfPositive(ref message, "Day", days);
                AppendTimeToStringIfPositive(ref message, "Hour", upTimeSpan.Hours);
                AppendTimeToStringIfPositive(ref message, "Minute", upTimeSpan.Minutes);

                var upTimeString = message.ToString();

                RemoveLastCommaIfExists(ref upTimeString);

                return(upTimeString);
            }

            void RemoveLastCommaIfExists(ref string str)
            {
                int lastCommaIndex = str.LastIndexOf(",");

                if (lastCommaIndex != -1)
                {
                    str = str.Substring(0, lastCommaIndex);
                }
            }

            void AppendTimeToStringIfPositive(ref StringBuilder str, string timeText, int time)
            {
                if (time > 0)
                {
                    str.Append($"{time} {timeText}{GivePluralIfNeeded(time)}, ");
                }
            }

            string GivePluralIfNeeded(int test)
            {
                if (test > 1)
                {
                    return("s");
                }
                return(string.Empty);
            }

            int GetEstimatedMonthFromSubtractingDays(ref int days)
            {
                int month = 0;

                while (days >= 30)
                {
                    ++month;
                    days -= 30;
                }
                return(month);
            }

            int GetYearsFromSubtractingMonths(ref int months)
            {
                int years = 0;

                while (months >= 12)
                {
                    ++years;
                    months -= 12;
                }
                return(years);
            }

            EmbedFieldBuilder[] GetStatusFields()
            {
                List <EmbedFieldBuilder> statusFields = new List <EmbedFieldBuilder>();

                statusFields.Add(
                    new EmbedFieldBuilder().WithName("Discord Latency")
                    .WithValue($"{Main.GetClient().Latency}ms")
                    );

                statusFields.Add(
                    new EmbedFieldBuilder().WithName("Guild Shards / Total Shards")
                    .WithValue($"{Main.GetClient().GetShardIdFor(guild) + 1} / {Main.GetClient().Shards.Count}")
                    );

                return(statusFields.ToArray());
            }

            #endregion
        }