Exemplo n.º 1
0
        public async Task GetUserInfoAsync(
            [Summary("The unique Discord snowflake ID of the guild to retrieve information about, if any.")]
            ulong?guildId = null)
        {
            var timer = Stopwatch.StartNew();

            var resolvedGuildId = guildId ?? Context.Guild.Id;

            var guildResult = await GuildService.GetGuildInformationAsync(resolvedGuildId);

            if (guildResult.IsError)
            {
                var errorDescription = guildResult.IsError
                    ? guildResult.Error
                    : "Sorry, we don't have any data for that guild - and we couldn't find any, either.";

                await ReplyAsync(embed : new EmbedBuilder()
                                 .WithTitle("Retrieval Error")
                                 .WithColor(Color.Red)
                                 .WithDescription(errorDescription)
                                 .AddField("Guild Id", resolvedGuildId)
                                 .Build());

                return;
            }

            var embedBuilder = new EmbedBuilder()
                               .WithAuthor(guildResult.Guild.Name, guildResult.Guild.IconUrl)
                               .WithThumbnailUrl(guildResult.Guild.IconUrl)
                               .WithTimestamp(_utcNow);

            await WithDominantColorAsync(embedBuilder, guildResult.Guild);

            var stringBuilder = new StringBuilder();

            AppendGuildInformation(stringBuilder, guildResult.Guild);

            if (guildResult.Guild is SocketGuild socketGuild)
            {
                await AppendGuildParticipationAsync(stringBuilder, socketGuild);

                AppendMemberInformation(stringBuilder, socketGuild);
            }

            AppendRoleInformation(stringBuilder, guildResult.Guild);

            embedBuilder.WithDescription(stringBuilder.ToString());

            timer.Stop();
            embedBuilder.WithFooter($"Completed after {timer.ElapsedMilliseconds} ms");

            await ReplyAsync(embed : embedBuilder.Build());
        }