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.

SocketSelfUser.cs 3.1 kB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Discord.Rest;
  2. using System;
  3. using System.Diagnostics;
  4. using System.Threading.Tasks;
  5. using Model = Discord.API.User;
  6. namespace Discord.WebSocket
  7. {
  8. /// <summary>
  9. /// Represents the logged-in WebSocket-based user.
  10. /// </summary>
  11. [DebuggerDisplay(@"{DebuggerDisplay,nq}")]
  12. public class SocketSelfUser : SocketUser, ISelfUser
  13. {
  14. /// <inheritdoc />
  15. public string Email { get; private set; }
  16. /// <inheritdoc />
  17. public bool IsVerified { get; private set; }
  18. /// <inheritdoc />
  19. public bool IsMfaEnabled { get; private set; }
  20. internal override SocketGlobalUser GlobalUser { get; }
  21. /// <inheritdoc />
  22. public override bool IsBot { get { return GlobalUser.IsBot; } internal set { GlobalUser.IsBot = value; } }
  23. /// <inheritdoc />
  24. public override string Username { get { return GlobalUser.Username; } internal set { GlobalUser.Username = value; } }
  25. /// <inheritdoc />
  26. public override ushort DiscriminatorValue { get { return GlobalUser.DiscriminatorValue; } internal set { GlobalUser.DiscriminatorValue = value; } }
  27. /// <inheritdoc />
  28. public override string AvatarId { get { return GlobalUser.AvatarId; } internal set { GlobalUser.AvatarId = value; } }
  29. /// <inheritdoc />
  30. internal override SocketPresence Presence { get { return GlobalUser.Presence; } set { GlobalUser.Presence = value; } }
  31. /// <inheritdoc />
  32. public override bool IsWebhook => false;
  33. internal SocketSelfUser(DiscordSocketClient discord, SocketGlobalUser globalUser)
  34. : base(discord, globalUser.Id)
  35. {
  36. GlobalUser = globalUser;
  37. }
  38. internal static SocketSelfUser Create(DiscordSocketClient discord, ClientState state, Model model)
  39. {
  40. var entity = new SocketSelfUser(discord, discord.GetOrCreateSelfUser(state, model));
  41. entity.Update(state, model);
  42. return entity;
  43. }
  44. internal override bool Update(ClientState state, Model model)
  45. {
  46. bool hasGlobalChanges = base.Update(state, model);
  47. if (model.Email.IsSpecified)
  48. {
  49. Email = model.Email.Value;
  50. hasGlobalChanges = true;
  51. }
  52. if (model.Verified.IsSpecified)
  53. {
  54. IsVerified = model.Verified.Value;
  55. hasGlobalChanges = true;
  56. }
  57. if (model.MfaEnabled.IsSpecified)
  58. {
  59. IsMfaEnabled = model.MfaEnabled.Value;
  60. hasGlobalChanges = true;
  61. }
  62. return hasGlobalChanges;
  63. }
  64. /// <inheritdoc />
  65. public Task ModifyAsync(Action<SelfUserProperties> func, RequestOptions options = null)
  66. => UserHelper.ModifyAsync(this, Discord, func, options);
  67. private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Self)";
  68. internal new SocketSelfUser Clone() => MemberwiseClone() as SocketSelfUser;
  69. }
  70. }