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.

RestApplication.cs 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Diagnostics;
  3. using System.Threading.Tasks;
  4. using Model = Discord.API.Application;
  5. namespace Discord.Rest
  6. {
  7. [DebuggerDisplay(@"{DebuggerDisplay,nq}")]
  8. public class RestApplication : RestEntity<ulong>, IApplication
  9. {
  10. protected string _iconId;
  11. public string Name { get; private set; }
  12. public string Description { get; private set; }
  13. public string[] RPCOrigins { get; private set; }
  14. public ulong Flags { get; private set; }
  15. public IUser Owner { get; private set; }
  16. public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
  17. public string IconUrl => CDN.GetApplicationIconUrl(Id, _iconId);
  18. internal RestApplication(BaseDiscordClient discord, ulong id)
  19. : base(discord, id)
  20. {
  21. }
  22. internal static RestApplication Create(BaseDiscordClient discord, Model model)
  23. {
  24. var entity = new RestApplication(discord, model.Id);
  25. entity.Update(model);
  26. return entity;
  27. }
  28. internal void Update(Model model)
  29. {
  30. Description = model.Description;
  31. RPCOrigins = model.RPCOrigins;
  32. Name = model.Name;
  33. _iconId = model.Icon;
  34. if (model.Flags.IsSpecified)
  35. Flags = model.Flags.Value; //TODO: Do we still need this?
  36. if (model.Owner.IsSpecified)
  37. Owner = RestUser.Create(Discord, model.Owner.Value);
  38. }
  39. public async Task UpdateAsync()
  40. {
  41. var response = await Discord.ApiClient.GetMyApplicationAsync().ConfigureAwait(false);
  42. if (response.Id != Id)
  43. throw new InvalidOperationException("Unable to update this object from a different application token.");
  44. Update(response);
  45. }
  46. public override string ToString() => Name;
  47. private string DebuggerDisplay => $"{Name} ({Id})";
  48. }
  49. }