mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-10 08:53:06 +00:00
Add support for Guild Member object & included data (#279)
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
namespace DiscordChatExporter.Core.Models
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
|
||||
namespace DiscordChatExporter.Core.Models
|
||||
{
|
||||
// https://discordapp.string.IsNullOrWhiteSpace(com/developers/docs/resources/guild#guild-object
|
||||
|
||||
@@ -10,13 +15,19 @@
|
||||
|
||||
public string? IconHash { get; }
|
||||
|
||||
public IReadOnlyList<Role> Roles { get; }
|
||||
|
||||
public Dictionary<string, Member?> Members { get; }
|
||||
|
||||
public string IconUrl { get; }
|
||||
|
||||
public Guild(string id, string name, string? iconHash)
|
||||
public Guild(string id, string name, IReadOnlyList<Role> roles, string? iconHash)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
IconHash = iconHash;
|
||||
Roles = roles;
|
||||
Members = new Dictionary<string, Member?>();
|
||||
|
||||
IconUrl = GetIconUrl(id, iconHash);
|
||||
}
|
||||
@@ -26,6 +37,16 @@
|
||||
|
||||
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 ?? "";
|
||||
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)
|
||||
@@ -33,6 +54,6 @@
|
||||
: "https://cdn.discordapp.com/embed/avatars/0.png";
|
||||
}
|
||||
|
||||
public static Guild DirectMessages { get; } = new Guild("@me", "Direct Messages", null);
|
||||
public static Guild DirectMessages { get; } = new Guild("@me", "Direct Messages", Array.Empty<Role>(), null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user