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

54 lines
1.7 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 IEnumerable<DiscordRole> Roles => client.RoleManager.Server(Server).Where(x => HasRole(x.Id));
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)
{
using (WebRequest wr = new WebRequest(HttpMethod.PUT, RestEndpoints.GuildMemberRole(Server.Id, User.Id, role.Id)))
wr.Perform();
this.roles.Add(role.Id);
}
}
}
}