using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; using System.Threading.Tasks; using Model = Discord.API.User; namespace Discord.WebSocket { /// /// Represents a WebSocket-based webhook user. /// [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class SocketWebhookUser : SocketUser, IWebhookUser { /// Gets the guild of this webhook. public SocketGuild Guild { get; } /// public ulong WebhookId { get; } /// public override string Username { get; internal set; } /// public override ushort DiscriminatorValue { get; internal set; } /// public override string AvatarId { get; internal set; } /// public override bool IsBot { get; internal set; } /// public override bool IsWebhook => true; /// internal override SocketPresence Presence { get { return new SocketPresence(UserStatus.Offline, null, null, null); } set { } } internal override SocketGlobalUser GlobalUser => throw new NotSupportedException(); internal SocketWebhookUser(SocketGuild guild, ulong id, ulong webhookId) : base(guild.Discord, id) { Guild = guild; WebhookId = webhookId; } internal static SocketWebhookUser Create(SocketGuild guild, ClientState state, Model model, ulong webhookId) { var entity = new SocketWebhookUser(guild, model.Id, webhookId); entity.Update(state, model); return entity; } private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Webhook)"; internal new SocketWebhookUser Clone() => MemberwiseClone() as SocketWebhookUser; //IGuildUser /// IGuild IGuildUser.Guild => Guild; /// ulong IGuildUser.GuildId => Guild.Id; /// IReadOnlyCollection IGuildUser.RoleIds => ImmutableArray.Create(); /// DateTimeOffset? IGuildUser.JoinedAt => null; /// string IGuildUser.Nickname => null; /// DateTimeOffset? IGuildUser.PremiumSince => null; /// GuildPermissions IGuildUser.GuildPermissions => GuildPermissions.Webhook; /// ChannelPermissions IGuildUser.GetPermissions(IGuildChannel channel) => Permissions.ToChannelPerms(channel, GuildPermissions.Webhook.RawValue); /// /// Webhook users cannot be kicked. Task IGuildUser.KickAsync(string reason, RequestOptions options) => throw new NotSupportedException("Webhook users cannot be kicked."); /// /// Webhook users cannot be modified. Task IGuildUser.ModifyAsync(Action func, RequestOptions options) => throw new NotSupportedException("Webhook users cannot be modified."); /// /// Roles are not supported on webhook users. Task IGuildUser.AddRoleAsync(IRole role, RequestOptions options) => throw new NotSupportedException("Roles are not supported on webhook users."); /// /// Roles are not supported on webhook users. Task IGuildUser.AddRolesAsync(IEnumerable roles, RequestOptions options) => throw new NotSupportedException("Roles are not supported on webhook users."); /// /// Roles are not supported on webhook users. Task IGuildUser.RemoveRoleAsync(IRole role, RequestOptions options) => throw new NotSupportedException("Roles are not supported on webhook users."); /// /// Roles are not supported on webhook users. Task IGuildUser.RemoveRolesAsync(IEnumerable roles, RequestOptions options) => throw new NotSupportedException("Roles are not supported on webhook users."); //IVoiceState /// bool IVoiceState.IsDeafened => false; /// bool IVoiceState.IsMuted => false; /// bool IVoiceState.IsSelfDeafened => false; /// bool IVoiceState.IsSelfMuted => false; /// bool IVoiceState.IsSuppressed => false; /// IVoiceChannel IVoiceState.VoiceChannel => null; /// string IVoiceState.VoiceSessionId => null; /// bool IVoiceState.IsStreaming => false; } }