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

55 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;
2017-10-13 20:05:50 +00:00
public IEnumerable<DiscordRole> Roles => client.RoleManager.Server(Server).Where(x => HasRole(x.Id));
2017-05-14 12:02:51 +00:00
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);
}
2017-05-21 01:08:34 +00:00
public bool HasRole(ulong id) => roles.Contains(id);
2017-05-14 12:02:51 +00:00
public void AddRoles(params DiscordRole[] roles)
{
foreach (DiscordRole role in roles)
{
2017-05-31 21:02:38 +00:00
using (WebRequest wr = new WebRequest(HttpMethod.PUT, RestEndpoints.GuildMemberRole(Server.Id, User.Id, role.Id)))
wr.Perform();
2017-05-14 12:02:51 +00:00
this.roles.Add(role.Id);
}
}
}
}