52 lines
1.8 KiB
C#
52 lines
1.8 KiB
C#
using Maki.Rest;
|
|
using Maki.Structures.Guilds;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Maki
|
|
{
|
|
public class DiscordMember
|
|
{
|
|
public readonly DiscordUser User;
|
|
public readonly DiscordServer Server;
|
|
private readonly Discord client;
|
|
|
|
public DiscordRole[] Roles => client.roles.Where(x => HasRole(x.Id) || x.Id == Server.Id).OrderByDescending(x => x.Position).ToArray();
|
|
|
|
public DateTime Joined { get; internal set; }
|
|
public string Nickname { get; internal set; }
|
|
public bool IsDeaf { get; internal set; }
|
|
public bool IsMute { get; internal set; }
|
|
|
|
public string Name => string.IsNullOrEmpty(Nickname) ? User.Username : Nickname;
|
|
public string NameWithTag => $"{Name}#{User.Tag:0000}";
|
|
|
|
public override string ToString() => $@"<@!{User.Id}>";
|
|
|
|
internal List<ulong> roles = new List<ulong>();
|
|
|
|
internal DiscordMember(Discord discord, GuildMember member, DiscordUser user, DiscordServer server)
|
|
{
|
|
client = discord;
|
|
User = user;
|
|
Server = server;
|
|
Nickname = member.Nickname;
|
|
Joined = member.JoinedAt ?? DateTime.MinValue;
|
|
IsDeaf = member.IsDeafened == true;
|
|
IsMute = member.IsMuted == true;
|
|
roles.AddRange(member.Roles);
|
|
}
|
|
|
|
public bool HasRole(ulong id) => roles.Contains(id);
|
|
|
|
public void AddRoles(params DiscordRole[] roles)
|
|
{
|
|
foreach (DiscordRole role in roles)
|
|
{
|
|
client.RestClient.Request<object>(RestRequestMethod.PUT, RestEndpoints.GuildMemberRole(Server.Id, User.Id, role.Id));
|
|
this.roles.Add(role.Id);
|
|
}
|
|
}
|
|
}
|
|
}
|