mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-10 08:53:06 +00:00
Fix bugs in previous PR
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -3,9 +3,12 @@ using System.Linq;
|
||||
|
||||
namespace DiscordChatExporter.Core.Models
|
||||
{
|
||||
// https://discordapp.com/developers/docs/resources/guild#guild-member-object
|
||||
|
||||
public class Member
|
||||
{
|
||||
public string UserId { get; }
|
||||
|
||||
public string? Nick { get; }
|
||||
|
||||
public IReadOnlyList<string> Roles { get; }
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
using System.Drawing;
|
||||
using System.Drawing;
|
||||
|
||||
namespace DiscordChatExporter.Core.Models
|
||||
{
|
||||
@@ -13,7 +12,8 @@ namespace DiscordChatExporter.Core.Models
|
||||
|
||||
public Color Color { get; }
|
||||
|
||||
public string ColorAsHex => $"#{(Color.ToArgb() & 0xffffff):X6}";
|
||||
public string ColorAsHex => $"#{Color.ToArgb() & 0xffffff:X6}";
|
||||
|
||||
public string ColorAsRgb => $"{Color.R}, {Color.G}, {Color.B}";
|
||||
|
||||
public int Position { get; }
|
||||
|
||||
Reference in New Issue
Block a user