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

9 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. [DebuggerDisplay(@"{DebuggerDisplay,nq}")]
  9. public class SocketSelfUser : SocketUser, ISelfUser
  10. {
  11. public string Email { get; private set; }
  12. public bool IsVerified { get; private set; }
  13. public bool IsMfaEnabled { get; private set; }
  14. internal override SocketGlobalUser GlobalUser { get; }
  15. public override bool IsBot { get { return GlobalUser.IsBot; } internal set { GlobalUser.IsBot = value; } }
  16. public override string Username { get { return GlobalUser.Username; } internal set { GlobalUser.Username = value; } }
  17. public override ushort DiscriminatorValue { get { return GlobalUser.DiscriminatorValue; } internal set { GlobalUser.DiscriminatorValue = value; } }
  18. public override string AvatarId { get { return GlobalUser.AvatarId; } internal set { GlobalUser.AvatarId = value; } }
  19. internal override SocketPresence Presence { get { return GlobalUser.Presence; } set { GlobalUser.Presence = value; } }
  20. public override bool IsWebhook => false;
  21. internal SocketSelfUser(DiscordSocketClient discord, SocketGlobalUser globalUser)
  22. : base(discord, globalUser.Id)
  23. {
  24. GlobalUser = globalUser;
  25. }
  26. internal static SocketSelfUser Create(DiscordSocketClient discord, ClientState state, Model model)
  27. {
  28. var entity = new SocketSelfUser(discord, discord.GetOrCreateSelfUser(state, model));
  29. entity.Update(state, model);
  30. return entity;
  31. }
  32. internal override bool Update(ClientState state, Model model)
  33. {
  34. bool hasGlobalChanges = base.Update(state, model);
  35. if (model.Email.IsSpecified)
  36. {
  37. Email = model.Email.Value;
  38. hasGlobalChanges = true;
  39. }
  40. if (model.Verified.IsSpecified)
  41. {
  42. IsVerified = model.Verified.Value;
  43. hasGlobalChanges = true;
  44. }
  45. if (model.MfaEnabled.IsSpecified)
  46. {
  47. IsMfaEnabled = model.MfaEnabled.Value;
  48. hasGlobalChanges = true;
  49. }
  50. return hasGlobalChanges;
  51. }
  52. public Task ModifyAsync(Action<SelfUserProperties> func, RequestOptions options = null)
  53. => UserHelper.ModifyAsync(this, Discord, func, options);
  54. Task IUser.AddFriendAsync(RequestOptions options) =>
  55. throw new InvalidOperationException("You can't friend yourself!");
  56. Task IUser.BlockUserAsync(RequestOptions options) =>
  57. throw new InvalidOperationException("You can't block yourself!");
  58. Task IUser.RemoveRelationshipAsync(RequestOptions options) =>
  59. throw new InvalidOperationException("You don't have any relations with yourself!");
  60. internal new SocketSelfUser Clone() => MemberwiseClone() as SocketSelfUser;
  61. }
  62. }