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 41 kB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
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)
8 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
9 years ago
7 years ago
7 years ago
7 years ago
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)
8 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
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)
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)
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)
8 years ago
7 years ago
7 years ago
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)
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)
8 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
7 years ago
7 years ago
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)
8 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
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)
8 years ago
7 years ago
7 years ago
7 years ago
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)
8 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  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. /// <summary>
  13. /// Represents a REST-based guild/server.
  14. /// </summary>
  15. [DebuggerDisplay(@"{DebuggerDisplay,nq}")]
  16. public class RestGuild : RestEntity<ulong>, IGuild, IUpdateable
  17. {
  18. private ImmutableDictionary<ulong, RestRole> _roles;
  19. private ImmutableArray<GuildEmote> _emotes;
  20. private ImmutableArray<string> _features;
  21. /// <inheritdoc />
  22. public string Name { get; private set; }
  23. /// <inheritdoc />
  24. public int AFKTimeout { get; private set; }
  25. /// <inheritdoc />
  26. public bool IsEmbeddable { get; private set; }
  27. /// <inheritdoc />
  28. public VerificationLevel VerificationLevel { get; private set; }
  29. /// <inheritdoc />
  30. public MfaLevel MfaLevel { get; private set; }
  31. /// <inheritdoc />
  32. public DefaultMessageNotifications DefaultMessageNotifications { get; private set; }
  33. /// <inheritdoc />
  34. public ulong? AFKChannelId { get; private set; }
  35. /// <inheritdoc />
  36. public ulong? EmbedChannelId { get; private set; }
  37. /// <inheritdoc />
  38. public ulong? SystemChannelId { get; private set; }
  39. /// <inheritdoc />
  40. public ulong OwnerId { get; private set; }
  41. /// <inheritdoc />
  42. public string VoiceRegionId { get; private set; }
  43. /// <inheritdoc />
  44. public string IconId { get; private set; }
  45. /// <inheritdoc />
  46. public string SplashId { get; private set; }
  47. internal bool Available { get; private set; }
  48. /// <inheritdoc />
  49. public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
  50. [Obsolete("DefaultChannelId is deprecated, use GetDefaultChannelAsync")]
  51. public ulong DefaultChannelId => Id;
  52. /// <inheritdoc />
  53. public string IconUrl => CDN.GetGuildIconUrl(Id, IconId);
  54. /// <inheritdoc />
  55. public string SplashUrl => CDN.GetGuildSplashUrl(Id, SplashId);
  56. /// <summary>
  57. /// Gets the built-in role containing all users in this guild.
  58. /// </summary>
  59. public RestRole EveryoneRole => GetRole(Id);
  60. /// <summary>
  61. /// Gets a collection of all roles in this guild.
  62. /// </summary>
  63. public IReadOnlyCollection<RestRole> Roles => _roles.ToReadOnlyCollection();
  64. /// <inheritdoc />
  65. public IReadOnlyCollection<GuildEmote> Emotes => _emotes;
  66. /// <inheritdoc />
  67. public IReadOnlyCollection<string> Features => _features;
  68. internal RestGuild(BaseDiscordClient client, ulong id)
  69. : base(client, id)
  70. {
  71. }
  72. internal static RestGuild Create(BaseDiscordClient discord, Model model)
  73. {
  74. var entity = new RestGuild(discord, model.Id);
  75. entity.Update(model);
  76. return entity;
  77. }
  78. internal void Update(Model model)
  79. {
  80. AFKChannelId = model.AFKChannelId;
  81. EmbedChannelId = model.EmbedChannelId;
  82. SystemChannelId = model.SystemChannelId;
  83. AFKTimeout = model.AFKTimeout;
  84. IsEmbeddable = model.EmbedEnabled;
  85. IconId = model.Icon;
  86. Name = model.Name;
  87. OwnerId = model.OwnerId;
  88. VoiceRegionId = model.Region;
  89. SplashId = model.Splash;
  90. VerificationLevel = model.VerificationLevel;
  91. MfaLevel = model.MfaLevel;
  92. DefaultMessageNotifications = model.DefaultMessageNotifications;
  93. if (model.Emojis != null)
  94. {
  95. var emotes = ImmutableArray.CreateBuilder<GuildEmote>(model.Emojis.Length);
  96. for (int i = 0; i < model.Emojis.Length; i++)
  97. emotes.Add(model.Emojis[i].ToEntity());
  98. _emotes = emotes.ToImmutableArray();
  99. }
  100. else
  101. _emotes = ImmutableArray.Create<GuildEmote>();
  102. if (model.Features != null)
  103. _features = model.Features.ToImmutableArray();
  104. else
  105. _features = ImmutableArray.Create<string>();
  106. var roles = ImmutableDictionary.CreateBuilder<ulong, RestRole>();
  107. if (model.Roles != null)
  108. {
  109. for (int i = 0; i < model.Roles.Length; i++)
  110. roles[model.Roles[i].Id] = RestRole.Create(Discord, this, model.Roles[i]);
  111. }
  112. _roles = roles.ToImmutable();
  113. Available = true;
  114. }
  115. internal void Update(EmbedModel model)
  116. {
  117. EmbedChannelId = model.ChannelId;
  118. IsEmbeddable = model.Enabled;
  119. }
  120. //General
  121. /// <inheritdoc />
  122. public async Task UpdateAsync(RequestOptions options = null)
  123. => Update(await Discord.ApiClient.GetGuildAsync(Id, options).ConfigureAwait(false));
  124. /// <inheritdoc />
  125. public Task DeleteAsync(RequestOptions options = null)
  126. => GuildHelper.DeleteAsync(this, Discord, options);
  127. /// <inheritdoc />
  128. /// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception>
  129. public async Task ModifyAsync(Action<GuildProperties> func, RequestOptions options = null)
  130. {
  131. var model = await GuildHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false);
  132. Update(model);
  133. }
  134. /// <inheritdoc />
  135. /// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception>
  136. public async Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null)
  137. {
  138. var model = await GuildHelper.ModifyEmbedAsync(this, Discord, func, options).ConfigureAwait(false);
  139. Update(model);
  140. }
  141. /// <inheritdoc />
  142. /// <exception cref="ArgumentNullException"><paramref name="args" /> is <c>null</c>.</exception>
  143. public async Task ReorderChannelsAsync(IEnumerable<ReorderChannelProperties> args, RequestOptions options = null)
  144. {
  145. var arr = args.ToArray();
  146. await GuildHelper.ReorderChannelsAsync(this, Discord, arr, options).ConfigureAwait(false);
  147. }
  148. /// <inheritdoc />
  149. public async Task ReorderRolesAsync(IEnumerable<ReorderRoleProperties> args, RequestOptions options = null)
  150. {
  151. var models = await GuildHelper.ReorderRolesAsync(this, Discord, args, options).ConfigureAwait(false);
  152. foreach (var model in models)
  153. {
  154. var role = GetRole(model.Id);
  155. role?.Update(model);
  156. }
  157. }
  158. /// <inheritdoc />
  159. public Task LeaveAsync(RequestOptions options = null)
  160. => GuildHelper.LeaveAsync(this, Discord, options);
  161. //Bans
  162. //Bans
  163. /// <summary>
  164. /// Gets a collection of all users banned in this guild.
  165. /// </summary>
  166. /// <param name="options">The options to be used when sending the request.</param>
  167. /// <returns>
  168. /// A task that represents the asynchronous get operation. The task result contains a read-only collection of
  169. /// ban objects that this guild currently possesses, with each object containing the user banned and reason
  170. /// behind the ban.
  171. /// </returns>
  172. public Task<IReadOnlyCollection<RestBan>> GetBansAsync(RequestOptions options = null)
  173. => GuildHelper.GetBansAsync(this, Discord, options);
  174. /// <summary>
  175. /// Gets a ban object for a banned user.
  176. /// </summary>
  177. /// <param name="user">The banned user.</param>
  178. /// <param name="options">The options to be used when sending the request.</param>
  179. /// <returns>
  180. /// A task that represents the asynchronous get operation. The task result contains a ban object, which
  181. /// contains the user information and the reason for the ban; <c>null</c> if the ban entry cannot be found.
  182. /// </returns>
  183. public Task<RestBan> GetBanAsync(IUser user, RequestOptions options = null)
  184. => GuildHelper.GetBanAsync(this, Discord, user.Id, options);
  185. /// <summary>
  186. /// Gets a ban object for a banned user.
  187. /// </summary>
  188. /// <param name="userId">The snowflake identifier for the banned user.</param>
  189. /// <param name="options">The options to be used when sending the request.</param>
  190. /// <returns>
  191. /// A task that represents the asynchronous get operation. The task result contains a ban object, which
  192. /// contains the user information and the reason for the ban; <c>null</c> if the ban entry cannot be found.
  193. /// </returns>
  194. public Task<RestBan> GetBanAsync(ulong userId, RequestOptions options = null)
  195. => GuildHelper.GetBanAsync(this, Discord, userId, options);
  196. /// <inheritdoc />
  197. public Task AddBanAsync(IUser user, int pruneDays = 0, string reason = null, RequestOptions options = null)
  198. => GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, reason, options);
  199. /// <inheritdoc />
  200. public Task AddBanAsync(ulong userId, int pruneDays = 0, string reason = null, RequestOptions options = null)
  201. => GuildHelper.AddBanAsync(this, Discord, userId, pruneDays, reason, options);
  202. /// <inheritdoc />
  203. public Task RemoveBanAsync(IUser user, RequestOptions options = null)
  204. => GuildHelper.RemoveBanAsync(this, Discord, user.Id, options);
  205. /// <inheritdoc />
  206. public Task RemoveBanAsync(ulong userId, RequestOptions options = null)
  207. => GuildHelper.RemoveBanAsync(this, Discord, userId, options);
  208. //Channels
  209. /// <summary>
  210. /// Gets a collection of all channels in this guild.
  211. /// </summary>
  212. /// <param name="options">The options to be used when sending the request.</param>
  213. /// <returns>
  214. /// A task that represents the asynchronous get operation. The task result contains a read-only collection of
  215. /// generic channels found within this guild.
  216. /// </returns>
  217. public Task<IReadOnlyCollection<RestGuildChannel>> GetChannelsAsync(RequestOptions options = null)
  218. => GuildHelper.GetChannelsAsync(this, Discord, options);
  219. /// <summary>
  220. /// Gets a channel in this guild.
  221. /// </summary>
  222. /// <param name="id">The snowflake identifier for the channel.</param>
  223. /// <param name="options">The options to be used when sending the request.</param>
  224. /// <returns>
  225. /// A task that represents the asynchronous get operation. The task result contains the generic channel
  226. /// associated with the specified <paramref name="id"/>; <c>null</c> if none is found.
  227. /// </returns>
  228. public Task<RestGuildChannel> GetChannelAsync(ulong id, RequestOptions options = null)
  229. => GuildHelper.GetChannelAsync(this, Discord, id, options);
  230. /// <summary>
  231. /// Gets a text channel in this guild.
  232. /// </summary>
  233. /// <param name="id">The snowflake identifier for the text channel.</param>
  234. /// <param name="options">The options to be used when sending the request.</param>
  235. /// <returns>
  236. /// A task that represents the asynchronous get operation. The task result contains the text channel
  237. /// associated with the specified <paramref name="id"/>; <c>null</c> if none is found.
  238. /// </returns>
  239. public async Task<RestTextChannel> GetTextChannelAsync(ulong id, RequestOptions options = null)
  240. {
  241. var channel = await GuildHelper.GetChannelAsync(this, Discord, id, options).ConfigureAwait(false);
  242. return channel as RestTextChannel;
  243. }
  244. /// <summary>
  245. /// Gets a collection of all text channels in this guild.
  246. /// </summary>
  247. /// <param name="mode">The <see cref="CacheMode"/> that determines whether the object should be fetched from cache.</param>
  248. /// <param name="options">The options to be used when sending the request.</param>
  249. /// <returns>
  250. /// A task that represents the asynchronous get operation. The task result contains a read-only collection of
  251. /// message channels found within this guild.
  252. /// </returns>
  253. public async Task<IReadOnlyCollection<RestTextChannel>> GetTextChannelsAsync(RequestOptions options = null)
  254. {
  255. var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false);
  256. return channels.Select(x => x as RestTextChannel).Where(x => x != null).ToImmutableArray();
  257. }
  258. /// <summary>
  259. /// Gets a voice channel in this guild.
  260. /// </summary>
  261. /// <param name="id">The snowflake identifier for the voice channel.</param>
  262. /// <param name="options">The options to be used when sending the request.</param>
  263. /// <returns>
  264. /// A task that represents the asynchronous get operation. The task result contains the voice channel associated
  265. /// with the specified <paramref name="id"/>; <c>null</c> if none is found.
  266. /// </returns>
  267. public async Task<RestVoiceChannel> GetVoiceChannelAsync(ulong id, RequestOptions options = null)
  268. {
  269. var channel = await GuildHelper.GetChannelAsync(this, Discord, id, options).ConfigureAwait(false);
  270. return channel as RestVoiceChannel;
  271. }
  272. /// <summary>
  273. /// Gets a collection of all voice channels in this guild.
  274. /// </summary>
  275. /// <param name="options">The options to be used when sending the request.</param>
  276. /// <returns>
  277. /// A task that represents the asynchronous get operation. The task result contains a read-only collection of
  278. /// voice channels found within this guild.
  279. /// </returns>
  280. public async Task<IReadOnlyCollection<RestVoiceChannel>> GetVoiceChannelsAsync(RequestOptions options = null)
  281. {
  282. var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false);
  283. return channels.Select(x => x as RestVoiceChannel).Where(x => x != null).ToImmutableArray();
  284. }
  285. /// <summary>
  286. /// Gets a collection of all category channels in this guild.
  287. /// </summary>
  288. /// <param name="options">The options to be used when sending the request.</param>
  289. /// <returns>
  290. /// A task that represents the asynchronous get operation. The task result contains a read-only collection of
  291. /// category channels found within this guild.
  292. /// </returns>
  293. public async Task<IReadOnlyCollection<RestCategoryChannel>> GetCategoryChannelsAsync(RequestOptions options = null)
  294. {
  295. var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false);
  296. return channels.Select(x => x as RestCategoryChannel).Where(x => x != null).ToImmutableArray();
  297. }
  298. /// <summary>
  299. /// Gets the AFK voice channel in this guild.
  300. /// </summary>
  301. /// <param name="options">The options to be used when sending the request.</param>
  302. /// <returns>
  303. /// A task that represents the asynchronous get operation. The task result contains the voice channel that the
  304. /// AFK users will be moved to after they have idled for too long; <c>null</c> if none is set.
  305. /// </returns>
  306. public async Task<RestVoiceChannel> GetAFKChannelAsync(RequestOptions options = null)
  307. {
  308. var afkId = AFKChannelId;
  309. if (afkId.HasValue)
  310. {
  311. var channel = await GuildHelper.GetChannelAsync(this, Discord, afkId.Value, options).ConfigureAwait(false);
  312. return channel as RestVoiceChannel;
  313. }
  314. return null;
  315. }
  316. /// <summary>
  317. /// Gets the first viewable text channel in this guild.
  318. /// </summary>
  319. /// <param name="options">The options to be used when sending the request.</param>
  320. /// <returns>
  321. /// A task that represents the asynchronous get operation. The task result contains the first viewable text
  322. /// channel in this guild; <c>null</c> if none is found.
  323. /// </returns>
  324. public async Task<RestTextChannel> GetDefaultChannelAsync(RequestOptions options = null)
  325. {
  326. var channels = await GetTextChannelsAsync(options).ConfigureAwait(false);
  327. var user = await GetCurrentUserAsync(options).ConfigureAwait(false);
  328. return channels
  329. .Where(c => user.GetPermissions(c).ViewChannel)
  330. .OrderBy(c => c.Position)
  331. .FirstOrDefault();
  332. }
  333. /// <summary>
  334. /// Gets the embed channel (i.e. the channel set in the guild's widget settings) in this guild.
  335. /// </summary>
  336. /// <param name="options">The options to be used when sending the request.</param>
  337. /// <returns>
  338. /// A task that represents the asynchronous get operation. The task result contains the embed channel set
  339. /// within the server's widget settings; <c>null</c> if none is set.
  340. /// </returns>
  341. public async Task<RestGuildChannel> GetEmbedChannelAsync(RequestOptions options = null)
  342. {
  343. var embedId = EmbedChannelId;
  344. if (embedId.HasValue)
  345. return await GuildHelper.GetChannelAsync(this, Discord, embedId.Value, options).ConfigureAwait(false);
  346. return null;
  347. }
  348. /// <summary>
  349. /// Gets the first viewable text channel in this guild.
  350. /// </summary>
  351. /// <param name="options">The options to be used when sending the request.</param>
  352. /// <returns>
  353. /// A task that represents the asynchronous get operation. The task result contains the first viewable text
  354. /// channel in this guild; <c>null</c> if none is found.
  355. /// </returns>
  356. public async Task<RestTextChannel> GetSystemChannelAsync(RequestOptions options = null)
  357. {
  358. var systemId = SystemChannelId;
  359. if (systemId.HasValue)
  360. {
  361. var channel = await GuildHelper.GetChannelAsync(this, Discord, systemId.Value, options).ConfigureAwait(false);
  362. return channel as RestTextChannel;
  363. }
  364. return null;
  365. }
  366. /// <summary>
  367. /// Creates a text channel with the provided name.
  368. /// </summary>
  369. /// <param name="name">The name of the new channel.</param>
  370. /// <param name="options">The options to be used when sending the request.</param>
  371. /// <param name="func">The delegate containing the properties to be applied to the channel upon its creation.</param>
  372. /// <exception cref="ArgumentNullException"><paramref name="name" /> is <c>null</c>.</exception>
  373. /// <returns>
  374. /// The created text channel.
  375. /// </returns>
  376. public Task<RestTextChannel> CreateTextChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null)
  377. => GuildHelper.CreateTextChannelAsync(this, Discord, name, options, func);
  378. /// <summary>
  379. /// Creates a voice channel with the provided name.
  380. /// </summary>
  381. /// <param name="name">The name of the new channel.</param>
  382. /// <param name="func">The delegate containing the properties to be applied to the channel upon its creation.</param>
  383. /// <param name="options">The options to be used when sending the request.</param>
  384. /// <exception cref="ArgumentNullException"><paramref name="name" /> is <c>null</c>.</exception>
  385. /// <returns>
  386. /// The created voice channel.
  387. /// </returns>
  388. public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func = null, RequestOptions options = null)
  389. => GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options, func);
  390. /// <summary>
  391. /// Creates a category channel with the provided name.
  392. /// </summary>
  393. /// <param name="name">The name of the new channel.</param>
  394. /// <param name="options">The options to be used when sending the request.</param>
  395. /// <exception cref="ArgumentNullException"><paramref name="name" /> is <c>null</c>.</exception>
  396. /// <returns>
  397. /// The created category channel.
  398. /// </returns>
  399. public Task<RestCategoryChannel> CreateCategoryChannelAsync(string name, RequestOptions options = null)
  400. => GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options);
  401. //Integrations
  402. public Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(RequestOptions options = null)
  403. => GuildHelper.GetIntegrationsAsync(this, Discord, options);
  404. public Task<RestGuildIntegration> CreateIntegrationAsync(ulong id, string type, RequestOptions options = null)
  405. => GuildHelper.CreateIntegrationAsync(this, Discord, id, type, options);
  406. //Invites
  407. /// <summary>
  408. /// Gets a collection of all invites in this guild.
  409. /// </summary>
  410. /// <param name="options">The options to be used when sending the request.</param>
  411. /// <returns>
  412. /// A task that represents the asynchronous get operation. The task result contains a read-only collection of
  413. /// invite metadata, each representing information for an invite found within this guild.
  414. /// </returns>
  415. public Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
  416. => GuildHelper.GetInvitesAsync(this, Discord, options);
  417. /// <summary>
  418. /// Gets the vanity invite URL of this guild.
  419. /// </summary>
  420. /// <param name="options">The options to be used when sending the request.</param>
  421. /// <returns>
  422. /// A partial metadata of the vanity invite found within this guild.
  423. /// </returns>
  424. public Task<RestInviteMetadata> GetVanityInviteAsync(RequestOptions options = null)
  425. => GuildHelper.GetVanityInviteAsync(this, Discord, options);
  426. //Roles
  427. /// <summary>
  428. /// Gets a role in this guild.
  429. /// </summary>
  430. /// <param name="id">The snowflake identifier for the role.</param>
  431. /// <returns>
  432. /// A role that is associated with the specified <paramref name="id"/>; <c>null</c> if none is found.
  433. /// </returns>
  434. public RestRole GetRole(ulong id)
  435. {
  436. if (_roles.TryGetValue(id, out RestRole value))
  437. return value;
  438. return null;
  439. }
  440. /// <summary>
  441. /// Creates a new role with the provided name.
  442. /// </summary>
  443. /// <param name="name">The new name for the role.</param>
  444. /// <param name="permissions">The guild permission that the role should possess.</param>
  445. /// <param name="color">The color of the role.</param>
  446. /// <param name="isHoisted">Whether the role is separated from others on the sidebar.</param>
  447. /// <param name="options">The options to be used when sending the request.</param>
  448. /// <returns>
  449. /// A task that represents the asynchronous creation operation. The task result contains the newly created
  450. /// role.
  451. /// </returns>
  452. public async Task<RestRole> CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?),
  453. bool isHoisted = false, RequestOptions options = null)
  454. {
  455. var role = await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, options).ConfigureAwait(false);
  456. _roles = _roles.Add(role.Id, role);
  457. return role;
  458. }
  459. //Users
  460. /// <summary>
  461. /// Gets a collection of all users in this guild.
  462. /// </summary>
  463. /// <remarks>
  464. /// This method retrieves all users found within this guild.
  465. /// </remarks>
  466. /// <param name="options">The options to be used when sending the request.</param>
  467. /// <returns>
  468. /// A task that represents the asynchronous get operation. The task result contains a collection of guild
  469. /// users found within this guild.
  470. /// </returns>
  471. public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(RequestOptions options = null)
  472. => GuildHelper.GetUsersAsync(this, Discord, null, null, options);
  473. /// <summary>
  474. /// Gets a user from this guild.
  475. /// </summary>
  476. /// <remarks>
  477. /// This method retrieves a user found within this guild.
  478. /// </remarks>
  479. /// <param name="id">The snowflake identifier of the user.</param>
  480. /// <param name="options">The options to be used when sending the request.</param>
  481. /// <returns>
  482. /// A task that represents the asynchronous get operation. The task result contains the guild user
  483. /// associated with the specified <paramref name="id"/>; <c>null</c> if none is found.
  484. /// </returns>
  485. public Task<RestGuildUser> GetUserAsync(ulong id, RequestOptions options = null)
  486. => GuildHelper.GetUserAsync(this, Discord, id, options);
  487. /// <summary>
  488. /// Gets the current user for this guild.
  489. /// </summary>
  490. /// <param name="options">The options to be used when sending the request.</param>
  491. /// <returns>
  492. /// A task that represents the asynchronous get operation. The task result contains the currently logged-in
  493. /// user within this guild.
  494. /// </returns>
  495. public Task<RestGuildUser> GetCurrentUserAsync(RequestOptions options = null)
  496. => GuildHelper.GetUserAsync(this, Discord, Discord.CurrentUser.Id, options);
  497. /// <summary>
  498. /// Gets the owner of this guild.
  499. /// </summary>
  500. /// <param name="options">The options to be used when sending the request.</param>
  501. /// <returns>
  502. /// A task that represents the asynchronous get operation. The task result contains the owner of this guild.
  503. /// </returns>
  504. public Task<RestGuildUser> GetOwnerAsync(RequestOptions options = null)
  505. => GuildHelper.GetUserAsync(this, Discord, OwnerId, options);
  506. /// <inheritdoc />
  507. /// <summary>
  508. /// Prunes inactive users.
  509. /// </summary>
  510. /// <remarks>
  511. /// <para>
  512. /// This method removes all users that have not logged on in the provided number of <paramref name="days"/>.
  513. /// </para>
  514. /// <para>
  515. /// If <paramref name="simulate" /> is <c>true</c>, this method will only return the number of users that
  516. /// would be removed without kicking the users.
  517. /// </para>
  518. /// </remarks>
  519. /// <param name="days">The number of days required for the users to be kicked.</param>
  520. /// <param name="simulate">Whether this prune action is a simulation.</param>
  521. /// <param name="options">The options to be used when sending the request.</param>
  522. /// <returns>
  523. /// A task that represents the asynchronous prune operation. The task result contains the number of users to
  524. /// be or has been removed from this guild.
  525. /// </returns>
  526. public Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null)
  527. => GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options);
  528. //Audit logs
  529. /// <summary>
  530. /// Gets the specified number of audit log entries for this guild.
  531. /// </summary>
  532. /// <param name="limit">The number of audit log entries to fetch.</param>
  533. /// <param name="options">The options to be used when sending the request.</param>
  534. /// <returns>
  535. /// A task that represents the asynchronous get operation. The task result contains a read-only collection
  536. /// of the requested audit log entries.
  537. /// </returns>
  538. public IAsyncEnumerable<IReadOnlyCollection<RestAuditLogEntry>> GetAuditLogsAsync(int limit, RequestOptions options = null)
  539. => GuildHelper.GetAuditLogsAsync(this, Discord, null, limit, options);
  540. //Webhooks
  541. /// <summary>
  542. /// Gets a webhook found within this guild.
  543. /// </summary>
  544. /// <param name="id">The identifier for the webhook.</param>
  545. /// <param name="options">The options to be used when sending the request.</param>
  546. /// <returns>
  547. /// A task that represents the asynchronous get operation. The task result contains the webhook with the
  548. /// specified <paramref name="id"/>; <c>null</c> if none is found.
  549. /// </returns>
  550. public Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null)
  551. => GuildHelper.GetWebhookAsync(this, Discord, id, options);
  552. /// <summary>
  553. /// Gets a collection of all webhook from this guild.
  554. /// </summary>
  555. /// <param name="options">The options to be used when sending the request.</param>
  556. /// <returns>
  557. /// A task that represents the asynchronous get operation. The task result contains a read-only collection
  558. /// of webhooks found within the guild.
  559. /// </returns>
  560. public Task<IReadOnlyCollection<RestWebhook>> GetWebhooksAsync(RequestOptions options = null)
  561. => GuildHelper.GetWebhooksAsync(this, Discord, options);
  562. /// <summary>
  563. /// Returns the name of the guild.
  564. /// </summary>
  565. /// <returns>
  566. /// The name of the guild.
  567. /// </returns>
  568. public override string ToString() => Name;
  569. private string DebuggerDisplay => $"{Name} ({Id})";
  570. //Emotes
  571. /// <inheritdoc />
  572. public Task<GuildEmote> GetEmoteAsync(ulong id, RequestOptions options = null)
  573. => GuildHelper.GetEmoteAsync(this, Discord, id, options);
  574. /// <inheritdoc />
  575. public Task<GuildEmote> CreateEmoteAsync(string name, Image image, Optional<IEnumerable<IRole>> roles = default(Optional<IEnumerable<IRole>>), RequestOptions options = null)
  576. => GuildHelper.CreateEmoteAsync(this, Discord, name, image, roles, options);
  577. /// <inheritdoc />
  578. /// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception>
  579. public Task<GuildEmote> ModifyEmoteAsync(GuildEmote emote, Action<EmoteProperties> func, RequestOptions options = null)
  580. => GuildHelper.ModifyEmoteAsync(this, Discord, emote.Id, func, options);
  581. /// <inheritdoc />
  582. public Task DeleteEmoteAsync(GuildEmote emote, RequestOptions options = null)
  583. => GuildHelper.DeleteEmoteAsync(this, Discord, emote.Id, options);
  584. //IGuild
  585. /// <inheritdoc />
  586. bool IGuild.Available => Available;
  587. /// <inheritdoc />
  588. IAudioClient IGuild.AudioClient => null;
  589. /// <inheritdoc />
  590. IRole IGuild.EveryoneRole => EveryoneRole;
  591. /// <inheritdoc />
  592. IReadOnlyCollection<IRole> IGuild.Roles => Roles;
  593. /// <inheritdoc />
  594. async Task<IReadOnlyCollection<IBan>> IGuild.GetBansAsync(RequestOptions options)
  595. => await GetBansAsync(options).ConfigureAwait(false);
  596. /// <inheritdoc/>
  597. async Task<IBan> IGuild.GetBanAsync(IUser user, RequestOptions options)
  598. => await GetBanAsync(user, options).ConfigureAwait(false);
  599. /// <inheritdoc/>
  600. async Task<IBan> IGuild.GetBanAsync(ulong userId, RequestOptions options)
  601. => await GetBanAsync(userId, options).ConfigureAwait(false);
  602. /// <inheritdoc />
  603. async Task<IReadOnlyCollection<IGuildChannel>> IGuild.GetChannelsAsync(CacheMode mode, RequestOptions options)
  604. {
  605. if (mode == CacheMode.AllowDownload)
  606. return await GetChannelsAsync(options).ConfigureAwait(false);
  607. else
  608. return ImmutableArray.Create<IGuildChannel>();
  609. }
  610. /// <inheritdoc />
  611. async Task<IGuildChannel> IGuild.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options)
  612. {
  613. if (mode == CacheMode.AllowDownload)
  614. return await GetChannelAsync(id, options).ConfigureAwait(false);
  615. else
  616. return null;
  617. }
  618. /// <inheritdoc />
  619. async Task<IReadOnlyCollection<ITextChannel>> IGuild.GetTextChannelsAsync(CacheMode mode, RequestOptions options)
  620. {
  621. if (mode == CacheMode.AllowDownload)
  622. return await GetTextChannelsAsync(options).ConfigureAwait(false);
  623. else
  624. return ImmutableArray.Create<ITextChannel>();
  625. }
  626. /// <inheritdoc />
  627. async Task<ITextChannel> IGuild.GetTextChannelAsync(ulong id, CacheMode mode, RequestOptions options)
  628. {
  629. if (mode == CacheMode.AllowDownload)
  630. return await GetTextChannelAsync(id, options).ConfigureAwait(false);
  631. else
  632. return null;
  633. }
  634. /// <inheritdoc />
  635. async Task<IReadOnlyCollection<IVoiceChannel>> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions options)
  636. {
  637. if (mode == CacheMode.AllowDownload)
  638. return await GetVoiceChannelsAsync(options).ConfigureAwait(false);
  639. else
  640. return ImmutableArray.Create<IVoiceChannel>();
  641. }
  642. /// <inheritdoc />
  643. async Task<IReadOnlyCollection<ICategoryChannel>> IGuild.GetCategoriesAsync(CacheMode mode, RequestOptions options)
  644. {
  645. if (mode == CacheMode.AllowDownload)
  646. return await GetCategoryChannelsAsync(options).ConfigureAwait(false);
  647. else
  648. return null;
  649. }
  650. /// <inheritdoc />
  651. async Task<IVoiceChannel> IGuild.GetVoiceChannelAsync(ulong id, CacheMode mode, RequestOptions options)
  652. {
  653. if (mode == CacheMode.AllowDownload)
  654. return await GetVoiceChannelAsync(id, options).ConfigureAwait(false);
  655. else
  656. return null;
  657. }
  658. /// <inheritdoc />
  659. async Task<IVoiceChannel> IGuild.GetAFKChannelAsync(CacheMode mode, RequestOptions options)
  660. {
  661. if (mode == CacheMode.AllowDownload)
  662. return await GetAFKChannelAsync(options).ConfigureAwait(false);
  663. else
  664. return null;
  665. }
  666. /// <inheritdoc />
  667. async Task<ITextChannel> IGuild.GetDefaultChannelAsync(CacheMode mode, RequestOptions options)
  668. {
  669. if (mode == CacheMode.AllowDownload)
  670. return await GetDefaultChannelAsync(options).ConfigureAwait(false);
  671. else
  672. return null;
  673. }
  674. /// <inheritdoc />
  675. async Task<IGuildChannel> IGuild.GetEmbedChannelAsync(CacheMode mode, RequestOptions options)
  676. {
  677. if (mode == CacheMode.AllowDownload)
  678. return await GetEmbedChannelAsync(options).ConfigureAwait(false);
  679. else
  680. return null;
  681. }
  682. /// <inheritdoc />
  683. async Task<ITextChannel> IGuild.GetSystemChannelAsync(CacheMode mode, RequestOptions options)
  684. {
  685. if (mode == CacheMode.AllowDownload)
  686. return await GetSystemChannelAsync(options).ConfigureAwait(false);
  687. else
  688. return null;
  689. }
  690. /// <inheritdoc />
  691. async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, Action<TextChannelProperties> func, RequestOptions options)
  692. => await CreateTextChannelAsync(name, func, options).ConfigureAwait(false);
  693. /// <inheritdoc />
  694. async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func, RequestOptions options)
  695. => await CreateVoiceChannelAsync(name, func, options).ConfigureAwait(false);
  696. /// <inheritdoc />
  697. async Task<ICategoryChannel> IGuild.CreateCategoryAsync(string name, RequestOptions options)
  698. => await CreateCategoryChannelAsync(name, options).ConfigureAwait(false);
  699. /// <inheritdoc />
  700. async Task<IReadOnlyCollection<IGuildIntegration>> IGuild.GetIntegrationsAsync(RequestOptions options)
  701. => await GetIntegrationsAsync(options).ConfigureAwait(false);
  702. /// <inheritdoc />
  703. async Task<IGuildIntegration> IGuild.CreateIntegrationAsync(ulong id, string type, RequestOptions options)
  704. => await CreateIntegrationAsync(id, type, options).ConfigureAwait(false);
  705. /// <inheritdoc />
  706. async Task<IReadOnlyCollection<IInviteMetadata>> IGuild.GetInvitesAsync(RequestOptions options)
  707. => await GetInvitesAsync(options).ConfigureAwait(false);
  708. /// <inheritdoc />
  709. async Task<IInviteMetadata> IGuild.GetVanityInviteAsync(RequestOptions options)
  710. => await GetVanityInviteAsync(options).ConfigureAwait(false);
  711. /// <inheritdoc />
  712. IRole IGuild.GetRole(ulong id)
  713. => GetRole(id);
  714. /// <inheritdoc />
  715. async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options)
  716. => await CreateRoleAsync(name, permissions, color, isHoisted, options).ConfigureAwait(false);
  717. /// <inheritdoc />
  718. async Task<IGuildUser> IGuild.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
  719. {
  720. if (mode == CacheMode.AllowDownload)
  721. return await GetUserAsync(id, options).ConfigureAwait(false);
  722. else
  723. return null;
  724. }
  725. /// <inheritdoc />
  726. async Task<IGuildUser> IGuild.GetCurrentUserAsync(CacheMode mode, RequestOptions options)
  727. {
  728. if (mode == CacheMode.AllowDownload)
  729. return await GetCurrentUserAsync(options).ConfigureAwait(false);
  730. else
  731. return null;
  732. }
  733. /// <inheritdoc />
  734. async Task<IGuildUser> IGuild.GetOwnerAsync(CacheMode mode, RequestOptions options)
  735. {
  736. if (mode == CacheMode.AllowDownload)
  737. return await GetOwnerAsync(options).ConfigureAwait(false);
  738. else
  739. return null;
  740. }
  741. /// <inheritdoc />
  742. async Task<IReadOnlyCollection<IGuildUser>> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options)
  743. {
  744. if (mode == CacheMode.AllowDownload)
  745. return (await GetUsersAsync(options).FlattenAsync().ConfigureAwait(false)).ToImmutableArray();
  746. else
  747. return ImmutableArray.Create<IGuildUser>();
  748. }
  749. /// <inheritdoc />
  750. /// <exception cref="NotSupportedException">Downloading users is not supported for a REST-based guild.</exception>
  751. Task IGuild.DownloadUsersAsync() =>
  752. throw new NotSupportedException();
  753. async Task<IReadOnlyCollection<IAuditLogEntry>> IGuild.GetAuditLogsAsync(int limit, CacheMode cacheMode, RequestOptions options)
  754. {
  755. if (cacheMode == CacheMode.AllowDownload)
  756. return (await GetAuditLogsAsync(limit, options).FlattenAsync().ConfigureAwait(false)).ToImmutableArray();
  757. else
  758. return ImmutableArray.Create<IAuditLogEntry>();
  759. }
  760. /// <inheritdoc />
  761. async Task<IWebhook> IGuild.GetWebhookAsync(ulong id, RequestOptions options)
  762. => await GetWebhookAsync(id, options).ConfigureAwait(false);
  763. /// <inheritdoc />
  764. async Task<IReadOnlyCollection<IWebhook>> IGuild.GetWebhooksAsync(RequestOptions options)
  765. => await GetWebhooksAsync(options).ConfigureAwait(false);
  766. }
  767. }