示例#1
0
        private async Task AddMemberInformationToEmbedAsync(EphemeralUser member, StringBuilder builder, EmbedBuilder embedBuilder)
        {
            builder.AppendLine();
            builder.AppendLine("**\u276F Member Information**");

            if (!string.IsNullOrEmpty(member.Nickname))
            {
                builder.AppendLine("Nickname: " + member.Nickname);
            }

            builder.AppendLine($"Created: {FormatUtilities.FormatTimeAgo(_utcNow, member.CreatedAt)}");

            if (member.JoinedAt is DateTimeOffset joinedAt)
            {
                builder.AppendLine($"Joined: {FormatUtilities.FormatTimeAgo(_utcNow, joinedAt)}");
            }

            if (member.RoleIds?.Count > 0)
            {
                var roles = member.RoleIds.Select(x => member.Guild.Roles.Single(y => y.Id == x))
                            .Where(x => x.Id != x.Guild.Id) // @everyone role always has same ID than guild
                            .ToArray();

                if (roles.Length > 0)
                {
                    Array.Sort(roles);    // Sort by position: lowest positioned role is first
                    Array.Reverse(roles); // Reverse the sort: highest positioned role is first

                    builder.Append("Role".ToQuantity(roles.Length, ShowQuantityAs.None));
                    builder.Append(": ");
                    builder.AppendLine(roles.Select(r => r.Mention).Humanize());
                }
            }

            if ((member.GetAvatarUrl(size: 16) ?? member.GetDefaultAvatarUrl()) is string avatarUrl)
            {
                using (var httpStream = await HttpClientFactory.CreateClient().GetStreamAsync(avatarUrl))
                {
                    using (var avatarStream = new MemoryStream())
                    {
                        await httpStream.CopyToAsync(avatarStream);

                        var avatar = new Image(avatarStream);

                        embedBuilder.WithColor(FormatUtilities.GetDominantColor(avatar));
                    }
                }
            }
        }
示例#2
0
        public async Task WithDominantColorAsync(EmbedBuilder embedBuilder, IGuild guild)
        {
            if (guild.IconUrl is string iconUrl)
            {
                using (var httpStream = await HttpClientFactory.CreateClient().GetStreamAsync(iconUrl))
                    using (var iconStream = new MemoryStream())
                    {
                        await httpStream.CopyToAsync(iconStream);

                        var icon = new Image(iconStream);

                        embedBuilder.WithColor(FormatUtilities.GetDominantColor(icon));
                    }
            }
        }