|
|
|
@ -5,7 +5,7 @@ using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace DiscordChatExporter.Core.Models
|
|
|
|
|
{
|
|
|
|
|
// https://discordapp.string.IsNullOrWhiteSpace(com/developers/docs/resources/guild#guild-object
|
|
|
|
|
// https://discordapp.com/developers/docs/resources/guild#guild-object
|
|
|
|
|
|
|
|
|
|
public partial class Guild : IHasId
|
|
|
|
|
{
|
|
|
|
@ -38,21 +38,20 @@ namespace DiscordChatExporter.Core.Models
|
|
|
|
|
public partial class Guild
|
|
|
|
|
{
|
|
|
|
|
public static string GetUserColor(Guild guild, User user) =>
|
|
|
|
|
guild.Members.GetValueOrDefault(user.Id, null)?.Roles
|
|
|
|
|
?.Select(r => guild.Roles
|
|
|
|
|
.Where(role => r == role.Id)
|
|
|
|
|
.FirstOrDefault()
|
|
|
|
|
)?.Where(r => r.Color != Color.Black)?
|
|
|
|
|
.Aggregate<Role, Role?>(null, (a, b) => (a?.Position ?? 0) > b.Position? a : b)?
|
|
|
|
|
.ColorAsHex ?? "";
|
|
|
|
|
guild.Members.GetValueOrDefault(user.Id, null)
|
|
|
|
|
?.Roles
|
|
|
|
|
.Select(r => guild.Roles.FirstOrDefault(role => r == role.Id))
|
|
|
|
|
.Where(r => r != null)
|
|
|
|
|
.Where(r => r.Color != Color.Black)
|
|
|
|
|
.Aggregate<Role, Role?>(null, (a, b) => (a?.Position ?? 0) > b.Position ? a : b)
|
|
|
|
|
?.ColorAsHex ?? "";
|
|
|
|
|
|
|
|
|
|
public static string GetUserNick(Guild guild, User user) => guild.Members.GetValueOrDefault(user.Id)?.Nick ?? user.Name;
|
|
|
|
|
|
|
|
|
|
public static string GetIconUrl(string id, string? iconHash)
|
|
|
|
|
{
|
|
|
|
|
return !string.IsNullOrWhiteSpace(iconHash)
|
|
|
|
|
public static string GetIconUrl(string id, string? iconHash) =>
|
|
|
|
|
!string.IsNullOrWhiteSpace(iconHash)
|
|
|
|
|
? $"https://cdn.discordapp.com/icons/{id}/{iconHash}.png"
|
|
|
|
|
: "https://cdn.discordapp.com/embed/avatars/0.png";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Guild DirectMessages { get; } = new Guild("@me", "Direct Messages", Array.Empty<Role>(), null);
|
|
|
|
|
}
|
|
|
|
|