You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

SocketWebhookUser.cs 3.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.Immutable;
  4. using System.Diagnostics;
  5. using System.Threading.Tasks;
  6. using Model = Discord.API.User;
  7. namespace Discord.WebSocket
  8. {
  9. [DebuggerDisplay(@"{DebuggerDisplay,nq}")]
  10. public class SocketWebhookUser : SocketUser, IWebhookUser
  11. {
  12. public SocketGuild Guild { get; }
  13. public ulong WebhookId { get; }
  14. public override string Username { get; internal set; }
  15. public override ushort DiscriminatorValue { get; internal set; }
  16. public override string AvatarId { get; internal set; }
  17. public override bool IsBot { get; internal set; }
  18. public override bool IsWebhook => true;
  19. internal override SocketPresence Presence { get { return new SocketPresence(UserStatus.Offline, null); } set { } }
  20. internal override SocketGlobalUser GlobalUser { get { throw new NotSupportedException(); } }
  21. internal SocketWebhookUser(SocketGuild guild, ulong id, ulong webhookId)
  22. : base(guild.Discord, id)
  23. {
  24. Guild = guild;
  25. WebhookId = webhookId;
  26. }
  27. internal static SocketWebhookUser Create(SocketGuild guild, ClientState state, Model model, ulong webhookId)
  28. {
  29. var entity = new SocketWebhookUser(guild, model.Id, webhookId);
  30. entity.Update(state, model);
  31. return entity;
  32. }
  33. internal new SocketWebhookUser Clone() => MemberwiseClone() as SocketWebhookUser;
  34. //IGuildUser
  35. IGuild IGuildUser.Guild => Guild;
  36. ulong IGuildUser.GuildId => Guild.Id;
  37. IReadOnlyCollection<ulong> IGuildUser.RoleIds => ImmutableArray.Create<ulong>();
  38. DateTimeOffset? IGuildUser.JoinedAt => null;
  39. string IGuildUser.Nickname => null;
  40. GuildPermissions IGuildUser.GuildPermissions => GuildPermissions.Webhook;
  41. ChannelPermissions IGuildUser.GetPermissions(IGuildChannel channel) => Permissions.ToChannelPerms(channel, GuildPermissions.Webhook.RawValue);
  42. Task IGuildUser.KickAsync(string reason, RequestOptions options)
  43. {
  44. throw new NotSupportedException("Webhook users cannot be kicked.");
  45. }
  46. Task IGuildUser.ModifyAsync(Action<GuildUserProperties> func, RequestOptions options)
  47. {
  48. throw new NotSupportedException("Webhook users cannot be modified.");
  49. }
  50. Task IGuildUser.AddRoleAsync(IRole role, RequestOptions options)
  51. {
  52. throw new NotSupportedException("Roles are not supported on webhook users.");
  53. }
  54. Task IGuildUser.AddRolesAsync(IEnumerable<IRole> roles, RequestOptions options)
  55. {
  56. throw new NotSupportedException("Roles are not supported on webhook users.");
  57. }
  58. Task IGuildUser.RemoveRoleAsync(IRole role, RequestOptions options)
  59. {
  60. throw new NotSupportedException("Roles are not supported on webhook users.");
  61. }
  62. Task IGuildUser.RemoveRolesAsync(IEnumerable<IRole> roles, RequestOptions options)
  63. {
  64. throw new NotSupportedException("Roles are not supported on webhook users.");
  65. }
  66. //IVoiceState
  67. bool IVoiceState.IsDeafened => false;
  68. bool IVoiceState.IsMuted => false;
  69. bool IVoiceState.IsSelfDeafened => false;
  70. bool IVoiceState.IsSelfMuted => false;
  71. bool IVoiceState.IsSuppressed => false;
  72. IVoiceChannel IVoiceState.VoiceChannel => null;
  73. string IVoiceState.VoiceSessionId => null;
  74. }
  75. }