Exemple #1
0
        public async Task StatsAsync(
            [Summary("The user for which to retrieve statistics. If no user is specified, the invoking user is used.")]
            SocketUser user = null)
        {
            user = user ?? Context.User;

            CommandUse[] commands = await DataBaseUtil.GetCommandsAsync(user.Id);

            Shitpost[] shitposts = await DataBaseUtil.GetShitpostsAsync(user.Id);

            Mute[] mutes = await DataBaseUtil.GetMutesAsync(user.Id);

            EmbedBuilder embed = new EmbedBuilder().WithAuthor($"Stats for {user}", user.GetAvatarUrl());

            if (commands.Any())
            {
                string fav      = commands.GroupBy(r => r.command).OrderByDescending(g => g.Count()).Select(g => g.Key).First();
                int    favCount = commands.Count(c => c.command == fav);

                embed.AddField("Command Usage", $"Total: `{commands.Length}`\nFavorite: `{fav}` ({favCount})");
            }

            if (shitposts.Any())
            {
                string fav      = shitposts.GroupBy(r => r.shitpost).OrderByDescending(g => g.Count()).Select(g => g.Key).First();
                int    favCount = shitposts.Count(c => c.shitpost == fav);

                embed.AddField("Shitpost Usage", $"Total: `{shitposts.Length}`\nFavorite: `{fav}` ({favCount})");
            }

            if (mutes.Any())
            {
                Mute   mute  = mutes.First();
                string value = $"Total: {mutes.Length}\nTimestamp: `{mute.Timestamp:yyyy-MM-ddTHH:mm:ssZ}`\nDuration: `";

                if (mute.Duration.HasValue)
                {
                    value += mute.Duration + (mute.Duration == 1 ? "` minute" : "` minutes");
                }
                else
                {
                    value += "indefinite`";
                }

                if (mute.Reason != null)
                {
                    value += $"\nReason: `{mute.Reason}`";
                }

                embed.AddField("Latest Mute Information", value);
            }

            await ReplyAsync(string.Empty, embed : embed.Build());

            await DataBaseUtil.AddCommandAsync("Stats", Context);
        }
Exemple #2
0
        public async Task MuteHistoryAsync(
            [Summary("The user for which to retrieve mute history.")] SocketGuildUser user,
            [RequireBoundaries(1, 25)] int quantity = 10)
        {
            Mute[] mutes = await DataBaseUtil.GetMutesAsync(user.Id, quantity);

            int total = mutes.Length;
            var pages = new List <EmbedBuilder>();

            await DataBaseUtil.AddCommandAsync("MuteHistory", Context);

            if (mutes.Any())
            {
                await BuildPage();
            }
            else
            {
                var embed = new EmbedBuilder
                {
                    ThumbnailUrl = user.GetAvatarUrl(),
                    Color        = new Color(243, 128, 72)
                };

                embed.WithAuthor($"No mutes for {user}!");
                embed.Description = "Who knew we have users that could behave!";

                await ReplyAsync(string.Empty, embed : embed.Build());

                return;
            }

            async Task BuildPage(EmbedFieldBuilder firstField = null)
            {
                var embed = new EmbedBuilder
                {
                    ThumbnailUrl = user.GetAvatarUrl(),
                    Color        = new Color(243, 128, 72)
                };

                embed.WithAuthor($"{user}'s Most Recent Mutes");

                if (firstField != null)
                {
                    embed.AddField(firstField);
                }

                foreach (Mute mute in mutes)
                {
                    string timestamp = mute.Timestamp.ToString("yyyy-MM-ddTHH:mm:ssZ");
                    string value     = $"Muted by: `{mute.MuterName}`";
                    string valueEnd;

                    if (mute.Duration.HasValue)
                    {
                        string         units   = mute.Duration > 1 ? "minutes" : "minute";
                        DateTimeOffset unmuted = mute.Timestamp.AddMinutes(mute.Duration.Value);
                        valueEnd = $"\nDuration: `{mute.Duration}` {units}\nUnmuted at: `{unmuted:yyyy-MM-ddTHH:mm:ssZ}`";
                    }
                    else
                    {
                        valueEnd = "\nDuration: `indefinite`";
                    }

                    string reason = null;

                    if (mute.Reason != null)
                    {
                        value   += "\nReason: `";
                        valueEnd = "`" + valueEnd;
                        reason   = mute.Reason.Truncate(1024 - value.Length - valueEnd.Length, true);
                    }

                    embed.AddField(timestamp, value + reason + valueEnd);

                    if (embed.Length() > 6000 - 26)                   // Total char limit - maximum possible footer length.
                    {
                        EmbedFieldBuilder field = embed.Fields.Pop(); // Re-use the field in the next embed.
                        pages.Add(embed);

                        mutes = mutes.Skip(embed.Fields.Count + 1).ToArray(); // Skips already processed records.
                        await BuildPage(field);                               // Process the remaining records.

                        return;
                    }
                }

                pages.Add(embed);
            }

            // Sets the footer text and sends each embed.
            if (pages.Count > 1)
            {
                for (var i = 0; i < pages.Count;)
                {
                    EmbedBuilder embed = pages[i];
                    embed.WithFooter($"{total} Results | Page {++i} of {pages.Count}");

                    await ReplyAsync(string.Empty, embed : embed.Build());
                }
            }
            else
            {
                await ReplyAsync(string.Empty, embed : pages.Single().Build());
            }
        }