Archived
1
0
Fork 0
This repository has been archived on 2024-05-21. You can view files and clone it, but cannot push or open issues or pull requests.
maki/Maki/DiscordMember.cs

56 lines
1.7 KiB
C#
Raw Normal View History

2017-05-14 12:02:51 +00:00
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)).ToArray();
public DateTime Joined { get; internal set; }
public string Nickname { get; internal set; }
2017-05-17 22:33:09 +00:00
public bool IsDeaf { get; internal set; }
public bool IsMute { get; internal set; }
2017-05-14 12:02:51 +00:00
public string Name => string.IsNullOrEmpty(Nickname) ? User.Username : Nickname;
public string NameWithTag => $"{Name}#{User.Tag:0000}";
2017-05-17 22:33:09 +00:00
public override string ToString() => $@"<@!{User.Id}>";
internal List<ulong> roles = new List<ulong>();
2017-05-14 12:02:51 +00:00
internal DiscordMember(Discord discord, GuildMember member, DiscordUser user, DiscordServer server)
{
client = discord;
User = user;
Server = server;
Nickname = member.Nickname;
Joined = member.JoinedAt ?? DateTime.MinValue;
2017-05-17 22:33:09 +00:00
IsDeaf = member.IsDeafened == true;
IsMute = member.IsMuted == true;
2017-05-14 12:02:51 +00:00
roles.AddRange(member.Roles);
}
public bool HasRole(ulong id)
{
return 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);
}
}
}
}