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.

RestGuild.cs 23 kB

Add support for channel categories (#907) commit a85c5814a74e473e95fe172f0379cbc7f9f951d8 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:25:48 2018 -0500 Code cleanup commit 4b243fd3dd99152b4ebc7ee01d704bd8e57eeee1 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:08:28 2018 -0500 Add support for channel categories (#907) commit 41ed9106f2b05530acbf06b245c9aa618011d815 Author: mrspits4ever <spits.lucas@gmail.com> Date: Thu Dec 14 20:02:57 2017 +0100 removed mentioning support for RestCategoryChannel, added channels property to SocketCategoryChannel commit 71142c310847886dff80c49e9357dd0786d67a1b Merge: 4589d731 678a7238 Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:53 2017 +0100 Merge branch 'dev' of https://github.com/RogueException/Discord.Net into feature/channel-categories commit 4589d73187871c98485ed25c6d223706927af7ec Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:46 2017 +0100 adressed requested changes commit d59b038efa048b2279602e2015ddd2c185e58d63 Author: pegasy <pegasy@users.noreply.github.com> Date: Mon Sep 25 18:53:23 2017 +0200 Renamed classes / properties / methods to use CategoryChannel instead of ChannelCategory to be consistant with how text / voice channels are named. commit 5c4777dc8cc443108f2e7e4afae98824c9a32b1f Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 19:08:25 2017 +0200 removed Guild from class name for ChannelCategory Renamed all properties to use Category instead of Parent Throw exception on GetUsers / GetInvites etc for categories commit e18bd8c799d2327270021c05866cb2e97ad4671b Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 15:49:51 2017 +0200 Add support for channel categories (as its own channel type)
7 years ago
8 years ago
Add support for channel categories (#907) commit a85c5814a74e473e95fe172f0379cbc7f9f951d8 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:25:48 2018 -0500 Code cleanup commit 4b243fd3dd99152b4ebc7ee01d704bd8e57eeee1 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:08:28 2018 -0500 Add support for channel categories (#907) commit 41ed9106f2b05530acbf06b245c9aa618011d815 Author: mrspits4ever <spits.lucas@gmail.com> Date: Thu Dec 14 20:02:57 2017 +0100 removed mentioning support for RestCategoryChannel, added channels property to SocketCategoryChannel commit 71142c310847886dff80c49e9357dd0786d67a1b Merge: 4589d731 678a7238 Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:53 2017 +0100 Merge branch 'dev' of https://github.com/RogueException/Discord.Net into feature/channel-categories commit 4589d73187871c98485ed25c6d223706927af7ec Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:46 2017 +0100 adressed requested changes commit d59b038efa048b2279602e2015ddd2c185e58d63 Author: pegasy <pegasy@users.noreply.github.com> Date: Mon Sep 25 18:53:23 2017 +0200 Renamed classes / properties / methods to use CategoryChannel instead of ChannelCategory to be consistant with how text / voice channels are named. commit 5c4777dc8cc443108f2e7e4afae98824c9a32b1f Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 19:08:25 2017 +0200 removed Guild from class name for ChannelCategory Renamed all properties to use Category instead of Parent Throw exception on GetUsers / GetInvites etc for categories commit e18bd8c799d2327270021c05866cb2e97ad4671b Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 15:49:51 2017 +0200 Add support for channel categories (as its own channel type)
7 years ago
Add support for channel categories (#907) commit a85c5814a74e473e95fe172f0379cbc7f9f951d8 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:25:48 2018 -0500 Code cleanup commit 4b243fd3dd99152b4ebc7ee01d704bd8e57eeee1 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:08:28 2018 -0500 Add support for channel categories (#907) commit 41ed9106f2b05530acbf06b245c9aa618011d815 Author: mrspits4ever <spits.lucas@gmail.com> Date: Thu Dec 14 20:02:57 2017 +0100 removed mentioning support for RestCategoryChannel, added channels property to SocketCategoryChannel commit 71142c310847886dff80c49e9357dd0786d67a1b Merge: 4589d731 678a7238 Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:53 2017 +0100 Merge branch 'dev' of https://github.com/RogueException/Discord.Net into feature/channel-categories commit 4589d73187871c98485ed25c6d223706927af7ec Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:46 2017 +0100 adressed requested changes commit d59b038efa048b2279602e2015ddd2c185e58d63 Author: pegasy <pegasy@users.noreply.github.com> Date: Mon Sep 25 18:53:23 2017 +0200 Renamed classes / properties / methods to use CategoryChannel instead of ChannelCategory to be consistant with how text / voice channels are named. commit 5c4777dc8cc443108f2e7e4afae98824c9a32b1f Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 19:08:25 2017 +0200 removed Guild from class name for ChannelCategory Renamed all properties to use Category instead of Parent Throw exception on GetUsers / GetInvites etc for categories commit e18bd8c799d2327270021c05866cb2e97ad4671b Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 15:49:51 2017 +0200 Add support for channel categories (as its own channel type)
7 years ago
Add support for channel categories (#907) commit a85c5814a74e473e95fe172f0379cbc7f9f951d8 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:25:48 2018 -0500 Code cleanup commit 4b243fd3dd99152b4ebc7ee01d704bd8e57eeee1 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:08:28 2018 -0500 Add support for channel categories (#907) commit 41ed9106f2b05530acbf06b245c9aa618011d815 Author: mrspits4ever <spits.lucas@gmail.com> Date: Thu Dec 14 20:02:57 2017 +0100 removed mentioning support for RestCategoryChannel, added channels property to SocketCategoryChannel commit 71142c310847886dff80c49e9357dd0786d67a1b Merge: 4589d731 678a7238 Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:53 2017 +0100 Merge branch 'dev' of https://github.com/RogueException/Discord.Net into feature/channel-categories commit 4589d73187871c98485ed25c6d223706927af7ec Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:46 2017 +0100 adressed requested changes commit d59b038efa048b2279602e2015ddd2c185e58d63 Author: pegasy <pegasy@users.noreply.github.com> Date: Mon Sep 25 18:53:23 2017 +0200 Renamed classes / properties / methods to use CategoryChannel instead of ChannelCategory to be consistant with how text / voice channels are named. commit 5c4777dc8cc443108f2e7e4afae98824c9a32b1f Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 19:08:25 2017 +0200 removed Guild from class name for ChannelCategory Renamed all properties to use Category instead of Parent Throw exception on GetUsers / GetInvites etc for categories commit e18bd8c799d2327270021c05866cb2e97ad4671b Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 15:49:51 2017 +0200 Add support for channel categories (as its own channel type)
7 years ago
Add support for channel categories (#907) commit a85c5814a74e473e95fe172f0379cbc7f9f951d8 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:25:48 2018 -0500 Code cleanup commit 4b243fd3dd99152b4ebc7ee01d704bd8e57eeee1 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:08:28 2018 -0500 Add support for channel categories (#907) commit 41ed9106f2b05530acbf06b245c9aa618011d815 Author: mrspits4ever <spits.lucas@gmail.com> Date: Thu Dec 14 20:02:57 2017 +0100 removed mentioning support for RestCategoryChannel, added channels property to SocketCategoryChannel commit 71142c310847886dff80c49e9357dd0786d67a1b Merge: 4589d731 678a7238 Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:53 2017 +0100 Merge branch 'dev' of https://github.com/RogueException/Discord.Net into feature/channel-categories commit 4589d73187871c98485ed25c6d223706927af7ec Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:46 2017 +0100 adressed requested changes commit d59b038efa048b2279602e2015ddd2c185e58d63 Author: pegasy <pegasy@users.noreply.github.com> Date: Mon Sep 25 18:53:23 2017 +0200 Renamed classes / properties / methods to use CategoryChannel instead of ChannelCategory to be consistant with how text / voice channels are named. commit 5c4777dc8cc443108f2e7e4afae98824c9a32b1f Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 19:08:25 2017 +0200 removed Guild from class name for ChannelCategory Renamed all properties to use Category instead of Parent Throw exception on GetUsers / GetInvites etc for categories commit e18bd8c799d2327270021c05866cb2e97ad4671b Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 15:49:51 2017 +0200 Add support for channel categories (as its own channel type)
7 years ago
Add support for channel categories (#907) commit a85c5814a74e473e95fe172f0379cbc7f9f951d8 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:25:48 2018 -0500 Code cleanup commit 4b243fd3dd99152b4ebc7ee01d704bd8e57eeee1 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:08:28 2018 -0500 Add support for channel categories (#907) commit 41ed9106f2b05530acbf06b245c9aa618011d815 Author: mrspits4ever <spits.lucas@gmail.com> Date: Thu Dec 14 20:02:57 2017 +0100 removed mentioning support for RestCategoryChannel, added channels property to SocketCategoryChannel commit 71142c310847886dff80c49e9357dd0786d67a1b Merge: 4589d731 678a7238 Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:53 2017 +0100 Merge branch 'dev' of https://github.com/RogueException/Discord.Net into feature/channel-categories commit 4589d73187871c98485ed25c6d223706927af7ec Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:46 2017 +0100 adressed requested changes commit d59b038efa048b2279602e2015ddd2c185e58d63 Author: pegasy <pegasy@users.noreply.github.com> Date: Mon Sep 25 18:53:23 2017 +0200 Renamed classes / properties / methods to use CategoryChannel instead of ChannelCategory to be consistant with how text / voice channels are named. commit 5c4777dc8cc443108f2e7e4afae98824c9a32b1f Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 19:08:25 2017 +0200 removed Guild from class name for ChannelCategory Renamed all properties to use Category instead of Parent Throw exception on GetUsers / GetInvites etc for categories commit e18bd8c799d2327270021c05866cb2e97ad4671b Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 15:49:51 2017 +0200 Add support for channel categories (as its own channel type)
7 years ago
Add support for channel categories (#907) commit a85c5814a74e473e95fe172f0379cbc7f9f951d8 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:25:48 2018 -0500 Code cleanup commit 4b243fd3dd99152b4ebc7ee01d704bd8e57eeee1 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:08:28 2018 -0500 Add support for channel categories (#907) commit 41ed9106f2b05530acbf06b245c9aa618011d815 Author: mrspits4ever <spits.lucas@gmail.com> Date: Thu Dec 14 20:02:57 2017 +0100 removed mentioning support for RestCategoryChannel, added channels property to SocketCategoryChannel commit 71142c310847886dff80c49e9357dd0786d67a1b Merge: 4589d731 678a7238 Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:53 2017 +0100 Merge branch 'dev' of https://github.com/RogueException/Discord.Net into feature/channel-categories commit 4589d73187871c98485ed25c6d223706927af7ec Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:46 2017 +0100 adressed requested changes commit d59b038efa048b2279602e2015ddd2c185e58d63 Author: pegasy <pegasy@users.noreply.github.com> Date: Mon Sep 25 18:53:23 2017 +0200 Renamed classes / properties / methods to use CategoryChannel instead of ChannelCategory to be consistant with how text / voice channels are named. commit 5c4777dc8cc443108f2e7e4afae98824c9a32b1f Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 19:08:25 2017 +0200 removed Guild from class name for ChannelCategory Renamed all properties to use Category instead of Parent Throw exception on GetUsers / GetInvites etc for categories commit e18bd8c799d2327270021c05866cb2e97ad4671b Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 15:49:51 2017 +0200 Add support for channel categories (as its own channel type)
7 years ago
Add support for channel categories (#907) commit a85c5814a74e473e95fe172f0379cbc7f9f951d8 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:25:48 2018 -0500 Code cleanup commit 4b243fd3dd99152b4ebc7ee01d704bd8e57eeee1 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:08:28 2018 -0500 Add support for channel categories (#907) commit 41ed9106f2b05530acbf06b245c9aa618011d815 Author: mrspits4ever <spits.lucas@gmail.com> Date: Thu Dec 14 20:02:57 2017 +0100 removed mentioning support for RestCategoryChannel, added channels property to SocketCategoryChannel commit 71142c310847886dff80c49e9357dd0786d67a1b Merge: 4589d731 678a7238 Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:53 2017 +0100 Merge branch 'dev' of https://github.com/RogueException/Discord.Net into feature/channel-categories commit 4589d73187871c98485ed25c6d223706927af7ec Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:46 2017 +0100 adressed requested changes commit d59b038efa048b2279602e2015ddd2c185e58d63 Author: pegasy <pegasy@users.noreply.github.com> Date: Mon Sep 25 18:53:23 2017 +0200 Renamed classes / properties / methods to use CategoryChannel instead of ChannelCategory to be consistant with how text / voice channels are named. commit 5c4777dc8cc443108f2e7e4afae98824c9a32b1f Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 19:08:25 2017 +0200 removed Guild from class name for ChannelCategory Renamed all properties to use Category instead of Parent Throw exception on GetUsers / GetInvites etc for categories commit e18bd8c799d2327270021c05866cb2e97ad4671b Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 15:49:51 2017 +0200 Add support for channel categories (as its own channel type)
7 years ago
Add support for channel categories (#907) commit a85c5814a74e473e95fe172f0379cbc7f9f951d8 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:25:48 2018 -0500 Code cleanup commit 4b243fd3dd99152b4ebc7ee01d704bd8e57eeee1 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:08:28 2018 -0500 Add support for channel categories (#907) commit 41ed9106f2b05530acbf06b245c9aa618011d815 Author: mrspits4ever <spits.lucas@gmail.com> Date: Thu Dec 14 20:02:57 2017 +0100 removed mentioning support for RestCategoryChannel, added channels property to SocketCategoryChannel commit 71142c310847886dff80c49e9357dd0786d67a1b Merge: 4589d731 678a7238 Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:53 2017 +0100 Merge branch 'dev' of https://github.com/RogueException/Discord.Net into feature/channel-categories commit 4589d73187871c98485ed25c6d223706927af7ec Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:46 2017 +0100 adressed requested changes commit d59b038efa048b2279602e2015ddd2c185e58d63 Author: pegasy <pegasy@users.noreply.github.com> Date: Mon Sep 25 18:53:23 2017 +0200 Renamed classes / properties / methods to use CategoryChannel instead of ChannelCategory to be consistant with how text / voice channels are named. commit 5c4777dc8cc443108f2e7e4afae98824c9a32b1f Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 19:08:25 2017 +0200 removed Guild from class name for ChannelCategory Renamed all properties to use Category instead of Parent Throw exception on GetUsers / GetInvites etc for categories commit e18bd8c799d2327270021c05866cb2e97ad4671b Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 15:49:51 2017 +0200 Add support for channel categories (as its own channel type)
7 years ago
Add support for channel categories (#907) commit a85c5814a74e473e95fe172f0379cbc7f9f951d8 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:25:48 2018 -0500 Code cleanup commit 4b243fd3dd99152b4ebc7ee01d704bd8e57eeee1 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:08:28 2018 -0500 Add support for channel categories (#907) commit 41ed9106f2b05530acbf06b245c9aa618011d815 Author: mrspits4ever <spits.lucas@gmail.com> Date: Thu Dec 14 20:02:57 2017 +0100 removed mentioning support for RestCategoryChannel, added channels property to SocketCategoryChannel commit 71142c310847886dff80c49e9357dd0786d67a1b Merge: 4589d731 678a7238 Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:53 2017 +0100 Merge branch 'dev' of https://github.com/RogueException/Discord.Net into feature/channel-categories commit 4589d73187871c98485ed25c6d223706927af7ec Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:46 2017 +0100 adressed requested changes commit d59b038efa048b2279602e2015ddd2c185e58d63 Author: pegasy <pegasy@users.noreply.github.com> Date: Mon Sep 25 18:53:23 2017 +0200 Renamed classes / properties / methods to use CategoryChannel instead of ChannelCategory to be consistant with how text / voice channels are named. commit 5c4777dc8cc443108f2e7e4afae98824c9a32b1f Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 19:08:25 2017 +0200 removed Guild from class name for ChannelCategory Renamed all properties to use Category instead of Parent Throw exception on GetUsers / GetInvites etc for categories commit e18bd8c799d2327270021c05866cb2e97ad4671b Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 15:49:51 2017 +0200 Add support for channel categories (as its own channel type)
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. using Discord.Audio;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.Immutable;
  5. using System.Diagnostics;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using EmbedModel = Discord.API.GuildEmbed;
  9. using Model = Discord.API.Guild;
  10. namespace Discord.Rest
  11. {
  12. [DebuggerDisplay(@"{DebuggerDisplay,nq}")]
  13. public class RestGuild : RestEntity<ulong>, IGuild, IUpdateable
  14. {
  15. private ImmutableDictionary<ulong, RestRole> _roles;
  16. private ImmutableArray<GuildEmote> _emotes;
  17. private ImmutableArray<string> _features;
  18. public string Name { get; private set; }
  19. public int AFKTimeout { get; private set; }
  20. public bool IsEmbeddable { get; private set; }
  21. public VerificationLevel VerificationLevel { get; private set; }
  22. public MfaLevel MfaLevel { get; private set; }
  23. public DefaultMessageNotifications DefaultMessageNotifications { get; private set; }
  24. public ulong? AFKChannelId { get; private set; }
  25. public ulong? EmbedChannelId { get; private set; }
  26. public ulong? SystemChannelId { get; private set; }
  27. public ulong OwnerId { get; private set; }
  28. public string VoiceRegionId { get; private set; }
  29. public string IconId { get; private set; }
  30. public string SplashId { get; private set; }
  31. internal bool Available { get; private set; }
  32. public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
  33. [Obsolete("DefaultChannelId is deprecated, use GetDefaultChannelAsync")]
  34. public ulong DefaultChannelId => Id;
  35. public string IconUrl => CDN.GetGuildIconUrl(Id, IconId);
  36. public string SplashUrl => CDN.GetGuildSplashUrl(Id, SplashId);
  37. public RestRole EveryoneRole => GetRole(Id);
  38. public IReadOnlyCollection<RestRole> Roles => _roles.ToReadOnlyCollection();
  39. public IReadOnlyCollection<GuildEmote> Emotes => _emotes;
  40. public IReadOnlyCollection<string> Features => _features;
  41. internal RestGuild(BaseDiscordClient client, ulong id)
  42. : base(client, id)
  43. {
  44. }
  45. internal static RestGuild Create(BaseDiscordClient discord, Model model)
  46. {
  47. var entity = new RestGuild(discord, model.Id);
  48. entity.Update(model);
  49. return entity;
  50. }
  51. internal void Update(Model model)
  52. {
  53. AFKChannelId = model.AFKChannelId;
  54. EmbedChannelId = model.EmbedChannelId;
  55. SystemChannelId = model.SystemChannelId;
  56. AFKTimeout = model.AFKTimeout;
  57. IsEmbeddable = model.EmbedEnabled;
  58. IconId = model.Icon;
  59. Name = model.Name;
  60. OwnerId = model.OwnerId;
  61. VoiceRegionId = model.Region;
  62. SplashId = model.Splash;
  63. VerificationLevel = model.VerificationLevel;
  64. MfaLevel = model.MfaLevel;
  65. DefaultMessageNotifications = model.DefaultMessageNotifications;
  66. if (model.Emojis != null)
  67. {
  68. var emotes = ImmutableArray.CreateBuilder<GuildEmote>(model.Emojis.Length);
  69. for (int i = 0; i < model.Emojis.Length; i++)
  70. emotes.Add(model.Emojis[i].ToEntity());
  71. _emotes = emotes.ToImmutableArray();
  72. }
  73. else
  74. _emotes = ImmutableArray.Create<GuildEmote>();
  75. if (model.Features != null)
  76. _features = model.Features.ToImmutableArray();
  77. else
  78. _features = ImmutableArray.Create<string>();
  79. var roles = ImmutableDictionary.CreateBuilder<ulong, RestRole>();
  80. if (model.Roles != null)
  81. {
  82. for (int i = 0; i < model.Roles.Length; i++)
  83. roles[model.Roles[i].Id] = RestRole.Create(Discord, this, model.Roles[i]);
  84. }
  85. _roles = roles.ToImmutable();
  86. Available = true;
  87. }
  88. internal void Update(EmbedModel model)
  89. {
  90. EmbedChannelId = model.ChannelId;
  91. IsEmbeddable = model.Enabled;
  92. }
  93. //General
  94. public async Task UpdateAsync(RequestOptions options = null)
  95. => Update(await Discord.ApiClient.GetGuildAsync(Id, options).ConfigureAwait(false));
  96. public Task DeleteAsync(RequestOptions options = null)
  97. => GuildHelper.DeleteAsync(this, Discord, options);
  98. public async Task ModifyAsync(Action<GuildProperties> func, RequestOptions options = null)
  99. {
  100. var model = await GuildHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false);
  101. Update(model);
  102. }
  103. public async Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null)
  104. {
  105. var model = await GuildHelper.ModifyEmbedAsync(this, Discord, func, options).ConfigureAwait(false);
  106. Update(model);
  107. }
  108. public async Task ReorderChannelsAsync(IEnumerable<ReorderChannelProperties> args, RequestOptions options = null)
  109. {
  110. var arr = args.ToArray();
  111. await GuildHelper.ReorderChannelsAsync(this, Discord, arr, options);
  112. }
  113. public async Task ReorderRolesAsync(IEnumerable<ReorderRoleProperties> args, RequestOptions options = null)
  114. {
  115. var models = await GuildHelper.ReorderRolesAsync(this, Discord, args, options).ConfigureAwait(false);
  116. foreach (var model in models)
  117. {
  118. var role = GetRole(model.Id);
  119. if (role != null)
  120. role.Update(model);
  121. }
  122. }
  123. public Task LeaveAsync(RequestOptions options = null)
  124. => GuildHelper.LeaveAsync(this, Discord, options);
  125. //Bans
  126. public Task<IReadOnlyCollection<RestBan>> GetBansAsync(RequestOptions options = null)
  127. => GuildHelper.GetBansAsync(this, Discord, options);
  128. public Task<RestBan> GetBanAsync(IUser user, RequestOptions options = null)
  129. => GuildHelper.GetBanAsync(this, Discord, user.Id, options);
  130. public Task<RestBan> GetBanAsync(ulong userId, RequestOptions options = null)
  131. => GuildHelper.GetBanAsync(this, Discord, userId, options);
  132. public Task AddBanAsync(IUser user, int pruneDays = 0, string reason = null, RequestOptions options = null)
  133. => GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, reason, options);
  134. public Task AddBanAsync(ulong userId, int pruneDays = 0, string reason = null, RequestOptions options = null)
  135. => GuildHelper.AddBanAsync(this, Discord, userId, pruneDays, reason, options);
  136. public Task RemoveBanAsync(IUser user, RequestOptions options = null)
  137. => GuildHelper.RemoveBanAsync(this, Discord, user.Id, options);
  138. public Task RemoveBanAsync(ulong userId, RequestOptions options = null)
  139. => GuildHelper.RemoveBanAsync(this, Discord, userId, options);
  140. //Channels
  141. public Task<IReadOnlyCollection<RestGuildChannel>> GetChannelsAsync(RequestOptions options = null)
  142. => GuildHelper.GetChannelsAsync(this, Discord, options);
  143. public Task<RestGuildChannel> GetChannelAsync(ulong id, RequestOptions options = null)
  144. => GuildHelper.GetChannelAsync(this, Discord, id, options);
  145. public async Task<RestTextChannel> GetTextChannelAsync(ulong id, RequestOptions options = null)
  146. {
  147. var channel = await GuildHelper.GetChannelAsync(this, Discord, id, options).ConfigureAwait(false);
  148. return channel as RestTextChannel;
  149. }
  150. public async Task<IReadOnlyCollection<RestTextChannel>> GetTextChannelsAsync(RequestOptions options = null)
  151. {
  152. var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false);
  153. return channels.Select(x => x as RestTextChannel).Where(x => x != null).ToImmutableArray();
  154. }
  155. public async Task<RestVoiceChannel> GetVoiceChannelAsync(ulong id, RequestOptions options = null)
  156. {
  157. var channel = await GuildHelper.GetChannelAsync(this, Discord, id, options).ConfigureAwait(false);
  158. return channel as RestVoiceChannel;
  159. }
  160. public async Task<IReadOnlyCollection<RestVoiceChannel>> GetVoiceChannelsAsync(RequestOptions options = null)
  161. {
  162. var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false);
  163. return channels.Select(x => x as RestVoiceChannel).Where(x => x != null).ToImmutableArray();
  164. }
  165. public async Task<IReadOnlyCollection<RestCategoryChannel>> GetCategoryChannelsAsync(RequestOptions options = null)
  166. {
  167. var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false);
  168. return channels.Select(x => x as RestCategoryChannel).Where(x => x != null).ToImmutableArray();
  169. }
  170. public async Task<RestVoiceChannel> GetAFKChannelAsync(RequestOptions options = null)
  171. {
  172. var afkId = AFKChannelId;
  173. if (afkId.HasValue)
  174. {
  175. var channel = await GuildHelper.GetChannelAsync(this, Discord, afkId.Value, options).ConfigureAwait(false);
  176. return channel as RestVoiceChannel;
  177. }
  178. return null;
  179. }
  180. public async Task<RestTextChannel> GetDefaultChannelAsync(RequestOptions options = null)
  181. {
  182. var channels = await GetTextChannelsAsync(options).ConfigureAwait(false);
  183. var user = await GetCurrentUserAsync(options).ConfigureAwait(false);
  184. return channels
  185. .Where(c => user.GetPermissions(c).ViewChannel)
  186. .OrderBy(c => c.Position)
  187. .FirstOrDefault();
  188. }
  189. public async Task<RestGuildChannel> GetEmbedChannelAsync(RequestOptions options = null)
  190. {
  191. var embedId = EmbedChannelId;
  192. if (embedId.HasValue)
  193. return await GuildHelper.GetChannelAsync(this, Discord, embedId.Value, options).ConfigureAwait(false);
  194. return null;
  195. }
  196. public async Task<RestTextChannel> GetSystemChannelAsync(RequestOptions options = null)
  197. {
  198. var systemId = SystemChannelId;
  199. if (systemId.HasValue)
  200. {
  201. var channel = await GuildHelper.GetChannelAsync(this, Discord, systemId.Value, options).ConfigureAwait(false);
  202. return channel as RestTextChannel;
  203. }
  204. return null;
  205. }
  206. public Task<RestTextChannel> CreateTextChannelAsync(string name, RequestOptions options = null)
  207. => GuildHelper.CreateTextChannelAsync(this, Discord, name, options);
  208. public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null)
  209. => GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options);
  210. public Task<RestCategoryChannel> CreateCategoryChannelAsync(string name, RequestOptions options = null)
  211. => GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options);
  212. //Integrations
  213. public Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(RequestOptions options = null)
  214. => GuildHelper.GetIntegrationsAsync(this, Discord, options);
  215. public Task<RestGuildIntegration> CreateIntegrationAsync(ulong id, string type, RequestOptions options = null)
  216. => GuildHelper.CreateIntegrationAsync(this, Discord, id, type, options);
  217. //Invites
  218. public Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
  219. => GuildHelper.GetInvitesAsync(this, Discord, options);
  220. //Roles
  221. public RestRole GetRole(ulong id)
  222. {
  223. if (_roles.TryGetValue(id, out RestRole value))
  224. return value;
  225. return null;
  226. }
  227. public async Task<RestRole> CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?),
  228. bool isHoisted = false, RequestOptions options = null)
  229. {
  230. var role = await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, options).ConfigureAwait(false);
  231. _roles = _roles.Add(role.Id, role);
  232. return role;
  233. }
  234. //Users
  235. public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(RequestOptions options = null)
  236. => GuildHelper.GetUsersAsync(this, Discord, null, null, options);
  237. public Task<RestGuildUser> GetUserAsync(ulong id, RequestOptions options = null)
  238. => GuildHelper.GetUserAsync(this, Discord, id, options);
  239. public Task<RestGuildUser> GetCurrentUserAsync(RequestOptions options = null)
  240. => GuildHelper.GetUserAsync(this, Discord, Discord.CurrentUser.Id, options);
  241. public Task<RestGuildUser> GetOwnerAsync(RequestOptions options = null)
  242. => GuildHelper.GetUserAsync(this, Discord, OwnerId, options);
  243. public Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null)
  244. => GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options);
  245. //Audit logs
  246. public IAsyncEnumerable<IReadOnlyCollection<RestAuditLogEntry>> GetAuditLogsAsync(int limit, RequestOptions options = null)
  247. => GuildHelper.GetAuditLogsAsync(this, Discord, null, limit, options);
  248. //Webhooks
  249. public Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null)
  250. => GuildHelper.GetWebhookAsync(this, Discord, id, options);
  251. public Task<IReadOnlyCollection<RestWebhook>> GetWebhooksAsync(RequestOptions options = null)
  252. => GuildHelper.GetWebhooksAsync(this, Discord, options);
  253. public override string ToString() => Name;
  254. private string DebuggerDisplay => $"{Name} ({Id})";
  255. //Emotes
  256. public Task<GuildEmote> GetEmoteAsync(ulong id, RequestOptions options = null)
  257. => GuildHelper.GetEmoteAsync(this, Discord, id, options);
  258. public Task<GuildEmote> CreateEmoteAsync(string name, Image image, Optional<IEnumerable<IRole>> roles = default(Optional<IEnumerable<IRole>>), RequestOptions options = null)
  259. => GuildHelper.CreateEmoteAsync(this, Discord, name, image, roles, options);
  260. public Task<GuildEmote> ModifyEmoteAsync(GuildEmote emote, Action<EmoteProperties> func, RequestOptions options = null)
  261. => GuildHelper.ModifyEmoteAsync(this, Discord, emote.Id, func, options);
  262. public Task DeleteEmoteAsync(GuildEmote emote, RequestOptions options = null)
  263. => GuildHelper.DeleteEmoteAsync(this, Discord, emote.Id, options);
  264. //IGuild
  265. bool IGuild.Available => Available;
  266. IAudioClient IGuild.AudioClient => null;
  267. IRole IGuild.EveryoneRole => EveryoneRole;
  268. IReadOnlyCollection<IRole> IGuild.Roles => Roles;
  269. async Task<IReadOnlyCollection<IBan>> IGuild.GetBansAsync(RequestOptions options)
  270. => await GetBansAsync(options).ConfigureAwait(false);
  271. /// <inheritdoc/>
  272. async Task<IBan> IGuild.GetBanAsync(IUser user, RequestOptions options)
  273. => await GetBanAsync(user, options).ConfigureAwait(false);
  274. /// <inheritdoc/>
  275. async Task<IBan> IGuild.GetBanAsync(ulong userId, RequestOptions options)
  276. => await GetBanAsync(userId, options).ConfigureAwait(false);
  277. async Task<IReadOnlyCollection<IGuildChannel>> IGuild.GetChannelsAsync(CacheMode mode, RequestOptions options)
  278. {
  279. if (mode == CacheMode.AllowDownload)
  280. return await GetChannelsAsync(options).ConfigureAwait(false);
  281. else
  282. return ImmutableArray.Create<IGuildChannel>();
  283. }
  284. async Task<IGuildChannel> IGuild.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options)
  285. {
  286. if (mode == CacheMode.AllowDownload)
  287. return await GetChannelAsync(id, options).ConfigureAwait(false);
  288. else
  289. return null;
  290. }
  291. async Task<IReadOnlyCollection<ITextChannel>> IGuild.GetTextChannelsAsync(CacheMode mode, RequestOptions options)
  292. {
  293. if (mode == CacheMode.AllowDownload)
  294. return await GetTextChannelsAsync(options).ConfigureAwait(false);
  295. else
  296. return ImmutableArray.Create<ITextChannel>();
  297. }
  298. async Task<ITextChannel> IGuild.GetTextChannelAsync(ulong id, CacheMode mode, RequestOptions options)
  299. {
  300. if (mode == CacheMode.AllowDownload)
  301. return await GetTextChannelAsync(id, options).ConfigureAwait(false);
  302. else
  303. return null;
  304. }
  305. async Task<IReadOnlyCollection<IVoiceChannel>> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions options)
  306. {
  307. if (mode == CacheMode.AllowDownload)
  308. return await GetVoiceChannelsAsync(options).ConfigureAwait(false);
  309. else
  310. return ImmutableArray.Create<IVoiceChannel>();
  311. }
  312. async Task<IReadOnlyCollection<ICategoryChannel>> IGuild.GetCategoriesAsync(CacheMode mode, RequestOptions options)
  313. {
  314. if (mode == CacheMode.AllowDownload)
  315. return await GetCategoryChannelsAsync(options).ConfigureAwait(false);
  316. else
  317. return null;
  318. }
  319. async Task<IVoiceChannel> IGuild.GetVoiceChannelAsync(ulong id, CacheMode mode, RequestOptions options)
  320. {
  321. if (mode == CacheMode.AllowDownload)
  322. return await GetVoiceChannelAsync(id, options).ConfigureAwait(false);
  323. else
  324. return null;
  325. }
  326. async Task<IVoiceChannel> IGuild.GetAFKChannelAsync(CacheMode mode, RequestOptions options)
  327. {
  328. if (mode == CacheMode.AllowDownload)
  329. return await GetAFKChannelAsync(options).ConfigureAwait(false);
  330. else
  331. return null;
  332. }
  333. async Task<ITextChannel> IGuild.GetDefaultChannelAsync(CacheMode mode, RequestOptions options)
  334. {
  335. if (mode == CacheMode.AllowDownload)
  336. return await GetDefaultChannelAsync(options).ConfigureAwait(false);
  337. else
  338. return null;
  339. }
  340. async Task<IGuildChannel> IGuild.GetEmbedChannelAsync(CacheMode mode, RequestOptions options)
  341. {
  342. if (mode == CacheMode.AllowDownload)
  343. return await GetEmbedChannelAsync(options).ConfigureAwait(false);
  344. else
  345. return null;
  346. }
  347. async Task<ITextChannel> IGuild.GetSystemChannelAsync(CacheMode mode, RequestOptions options)
  348. {
  349. if (mode == CacheMode.AllowDownload)
  350. return await GetSystemChannelAsync(options).ConfigureAwait(false);
  351. else
  352. return null;
  353. }
  354. async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, RequestOptions options)
  355. => await CreateTextChannelAsync(name, options).ConfigureAwait(false);
  356. async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options)
  357. => await CreateVoiceChannelAsync(name, options).ConfigureAwait(false);
  358. async Task<ICategoryChannel> IGuild.CreateCategoryAsync(string name, RequestOptions options)
  359. => await CreateCategoryChannelAsync(name, options).ConfigureAwait(false);
  360. async Task<IReadOnlyCollection<IGuildIntegration>> IGuild.GetIntegrationsAsync(RequestOptions options)
  361. => await GetIntegrationsAsync(options).ConfigureAwait(false);
  362. async Task<IGuildIntegration> IGuild.CreateIntegrationAsync(ulong id, string type, RequestOptions options)
  363. => await CreateIntegrationAsync(id, type, options).ConfigureAwait(false);
  364. async Task<IReadOnlyCollection<IInviteMetadata>> IGuild.GetInvitesAsync(RequestOptions options)
  365. => await GetInvitesAsync(options).ConfigureAwait(false);
  366. IRole IGuild.GetRole(ulong id)
  367. => GetRole(id);
  368. async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options)
  369. => await CreateRoleAsync(name, permissions, color, isHoisted, options).ConfigureAwait(false);
  370. async Task<IGuildUser> IGuild.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
  371. {
  372. if (mode == CacheMode.AllowDownload)
  373. return await GetUserAsync(id, options).ConfigureAwait(false);
  374. else
  375. return null;
  376. }
  377. async Task<IGuildUser> IGuild.GetCurrentUserAsync(CacheMode mode, RequestOptions options)
  378. {
  379. if (mode == CacheMode.AllowDownload)
  380. return await GetCurrentUserAsync(options).ConfigureAwait(false);
  381. else
  382. return null;
  383. }
  384. async Task<IGuildUser> IGuild.GetOwnerAsync(CacheMode mode, RequestOptions options)
  385. {
  386. if (mode == CacheMode.AllowDownload)
  387. return await GetOwnerAsync(options).ConfigureAwait(false);
  388. else
  389. return null;
  390. }
  391. async Task<IReadOnlyCollection<IGuildUser>> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options)
  392. {
  393. if (mode == CacheMode.AllowDownload)
  394. return (await GetUsersAsync(options).FlattenAsync().ConfigureAwait(false)).ToImmutableArray();
  395. else
  396. return ImmutableArray.Create<IGuildUser>();
  397. }
  398. Task IGuild.DownloadUsersAsync() { throw new NotSupportedException(); }
  399. async Task<IReadOnlyCollection<IAuditLogEntry>> IGuild.GetAuditLogAsync(int limit, CacheMode cacheMode, RequestOptions options)
  400. {
  401. if (cacheMode == CacheMode.AllowDownload)
  402. return (await GetAuditLogsAsync(limit, options).FlattenAsync().ConfigureAwait(false)).ToImmutableArray();
  403. else
  404. return ImmutableArray.Create<IAuditLogEntry>();
  405. }
  406. async Task<IWebhook> IGuild.GetWebhookAsync(ulong id, RequestOptions options)
  407. => await GetWebhookAsync(id, options);
  408. async Task<IReadOnlyCollection<IWebhook>> IGuild.GetWebhooksAsync(RequestOptions options)
  409. => await GetWebhooksAsync(options);
  410. }
  411. }