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.

SocketCustomSticker.cs 2.4 KiB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Discord.Rest;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Model = Discord.API.Sticker;
  8. namespace Discord.WebSocket
  9. {
  10. public class SocketCustomSticker : SocketSticker, ICustomSticker
  11. {
  12. /// <summary>
  13. /// Gets the user that uploaded the guild sticker.
  14. /// </summary>
  15. /// <remarks>
  16. /// <note>
  17. /// This may return <see langword="null"/> in the WebSocket implementation due to incomplete user collection in
  18. /// large guilds, or the bot doesnt have the MANAGE_EMOJIS_AND_STICKERS permission.
  19. /// </note>
  20. /// </remarks>
  21. public SocketGuildUser Author
  22. => this.AuthorId.HasValue ? Guild.GetUser(this.AuthorId.Value) : null;
  23. /// <summary>
  24. /// Gets the guild the sticker lives in.
  25. /// </summary>
  26. public SocketGuild Guild { get; }
  27. /// <inheritdoc/>
  28. public ulong? AuthorId { get; set; }
  29. internal SocketCustomSticker(DiscordSocketClient client, ulong id, SocketGuild guild, ulong? authorId = null)
  30. : base(client, id)
  31. {
  32. this.Guild = guild;
  33. this.AuthorId = authorId;
  34. }
  35. internal static SocketCustomSticker Create(DiscordSocketClient client, Model model, SocketGuild guild, ulong? authorId = null)
  36. {
  37. var entity = new SocketCustomSticker(client, model.Id, guild, authorId);
  38. entity.Update(model);
  39. return entity;
  40. }
  41. /// <inheritdoc/>
  42. public async Task ModifyAsync(Action<StickerProperties> func, RequestOptions options = null)
  43. {
  44. if(!Guild.CurrentUser.GuildPermissions.Has(GuildPermission.ManageEmojisAndStickers))
  45. throw new InvalidOperationException($"Missing permission {nameof(GuildPermission.ManageEmojisAndStickers)}");
  46. var model = await GuildHelper.ModifyStickerAsync(this.Discord, this.Guild, this, func, options);
  47. this.Update(model);
  48. }
  49. /// <inheritdoc/>
  50. public async Task DeleteAsync(RequestOptions options = null)
  51. {
  52. await GuildHelper.DeleteStickerAsync(Discord, Guild, this, options);
  53. Guild.RemoveSticker(this.Id);
  54. }
  55. // ICustomSticker
  56. ulong? ICustomSticker.AuthorId
  57. => this.AuthorId;
  58. IGuild ICustomSticker.Guild
  59. => this.Guild;
  60. }
  61. }