using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Model = Discord.API.ThreadMember; using System.Collections.Immutable; namespace Discord.WebSocket { /// /// Represents a thread user received over the gateway. /// public class SocketThreadUser : SocketUser, IThreadUser, IGuildUser { /// /// Gets the this user is in. /// public SocketThreadChannel Thread { get; private set; } /// public DateTimeOffset ThreadJoinedAt { get; private set; } /// /// Gets the guild this user is in. /// public SocketGuild Guild { get; private set; } /// public DateTimeOffset? JoinedAt => GuildUser.JoinedAt; /// public string Nickname => GuildUser.Nickname; /// public DateTimeOffset? PremiumSince => GuildUser.PremiumSince; /// public DateTimeOffset? TimedOutUntil => GuildUser.TimedOutUntil; /// public bool? IsPending => GuildUser.IsPending; /// public int Hierarchy => GuildUser.Hierarchy; /// public override string AvatarId { get => GuildUser.AvatarId; internal set => GuildUser.AvatarId = value; } /// public string GuildAvatarId => GuildUser.GuildAvatarId; /// public override ushort DiscriminatorValue { get => GuildUser.DiscriminatorValue; internal set => GuildUser.DiscriminatorValue = value; } /// public override bool IsBot { get => GuildUser.IsBot; internal set => GuildUser.IsBot = value; } /// public override bool IsWebhook => GuildUser.IsWebhook; /// public override string Username { get => GuildUser.Username; internal set => GuildUser.Username = value; } /// public bool IsDeafened => GuildUser.IsDeafened; /// public bool IsMuted => GuildUser.IsMuted; /// public bool IsSelfDeafened => GuildUser.IsSelfDeafened; /// public bool IsSelfMuted => GuildUser.IsSelfMuted; /// public bool IsSuppressed => GuildUser.IsSuppressed; /// public IVoiceChannel VoiceChannel => GuildUser.VoiceChannel; /// public string VoiceSessionId => GuildUser.VoiceSessionId; /// public bool IsStreaming => GuildUser.IsStreaming; /// public DateTimeOffset? RequestToSpeakTimestamp => GuildUser.RequestToSpeakTimestamp; private SocketGuildUser GuildUser { get; set; } internal SocketThreadUser(SocketGuild guild, SocketThreadChannel thread, SocketGuildUser member, ulong userId) : base(guild.Discord, userId) { Thread = thread; Guild = guild; GuildUser = member; } internal static SocketThreadUser Create(SocketGuild guild, SocketThreadChannel thread, Model model, SocketGuildUser member) { var entity = new SocketThreadUser(guild, thread, member, model.UserId.Value); entity.Update(model); return entity; } internal void Update(Model model) { ThreadJoinedAt = model.JoinTimestamp; } /// public ChannelPermissions GetPermissions(IGuildChannel channel) => GuildUser.GetPermissions(channel); /// public Task KickAsync(string reason = null, RequestOptions options = null) => GuildUser.KickAsync(reason, options); /// public Task ModifyAsync(Action func, RequestOptions options = null) => GuildUser.ModifyAsync(func, options); /// public Task AddRoleAsync(ulong roleId, RequestOptions options = null) => GuildUser.AddRoleAsync(roleId, options); /// public Task AddRoleAsync(IRole role, RequestOptions options = null) => GuildUser.AddRoleAsync(role, options); /// public Task AddRolesAsync(IEnumerable roleIds, RequestOptions options = null) => GuildUser.AddRolesAsync(roleIds, options); /// public Task AddRolesAsync(IEnumerable roles, RequestOptions options = null) => GuildUser.AddRolesAsync(roles, options); /// public Task RemoveRoleAsync(ulong roleId, RequestOptions options = null) => GuildUser.RemoveRoleAsync(roleId, options); /// public Task RemoveRoleAsync(IRole role, RequestOptions options = null) => GuildUser.RemoveRoleAsync(role, options); /// public Task RemoveRolesAsync(IEnumerable roleIds, RequestOptions options = null) => GuildUser.RemoveRolesAsync(roleIds, options); /// public Task RemoveRolesAsync(IEnumerable roles, RequestOptions options = null) => GuildUser.RemoveRolesAsync(roles, options); /// public Task SetTimeOutAsync(TimeSpan span, RequestOptions options = null) => GuildUser.SetTimeOutAsync(span, options); /// public Task RemoveTimeOutAsync(RequestOptions options = null) => GuildUser.RemoveTimeOutAsync(options); /// IThreadChannel IThreadUser.Thread => Thread; /// IGuild IThreadUser.Guild => Guild; /// IGuild IGuildUser.Guild => Guild; /// ulong IGuildUser.GuildId => Guild.Id; /// GuildPermissions IGuildUser.GuildPermissions => GuildUser.GuildPermissions; /// IReadOnlyCollection IGuildUser.RoleIds => GuildUser.Roles.Select(x => x.Id).ToImmutableArray(); string IGuildUser.GetGuildAvatarUrl(ImageFormat format, ushort size) => GuildUser.GetGuildAvatarUrl(format, size); internal override SocketGlobalUser GlobalUser => GuildUser.GlobalUser; internal override SocketPresence Presence { get => GuildUser.Presence; set => GuildUser.Presence = value; } /// /// Gets the guild user of this thread user. /// /// public static explicit operator SocketGuildUser(SocketThreadUser user) => user.GuildUser; } }