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.

PreconditionAttribute.Overwrites.md 3.5 kB

Squashed commit of the following: commit dece19d89505342e5f8c51317b54be8ce69336c9 Merge: fdaa689a e764dafe Author: Still Hsu <341464@gmail.com> Date: Mon May 21 11:47:47 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit e764dafe083bf5db62091ac1f6b3d438eee38882 Author: Quahu <quahuu@gmail.com> Date: Sun May 13 15:34:40 2018 +0200 Add ViewChannel to Voice channel permissions (#1059) Previously, Voice channels did not have ViewChannel in their "all" permissions commit 32fc2df21b1840fd913ccce80c0686e8e853b43d Author: Alex Gravely <tcbskater@hotmail.com> Date: Sat May 12 20:47:44 2018 -0400 Remove unused field in EmbedFieldBuilder. (#1018) commit 39dffe858584d0e9eed750bff6426e9562db4262 Author: Finite Reality <FiniteReality@users.noreply.github.com> Date: Sun May 13 01:46:07 2018 +0100 Audit Logs implementation (#1055) * Copy audit logs impl from old branch and clean up I suck at using git, so I'm gonna use brute force. * Remove unnecessary TODOs Category channels do not provide any new information, and the other I forgot to remove beforehand * Add invite update data, clean up after feedback * Remove TODOs, add WebhookType enum for future use WebhookType is a future-use type, as currently audit logs are the only thing which may return it. commit fdaa689ae8be8e9d2ff5190b6cfed5af244b805b Author: Still Hsu <341464@gmail.com> Date: Wed May 9 06:04:59 2018 +0800 Add explanation for RunMode commit ea82c2537e64d4b75f85d9369e90cb55cfcadcc7 Author: Still Hsu <341464@gmail.com> Date: Tue May 8 16:30:48 2018 +0800 Initial proofread of the articles commit 124f1a267c663fbbb0f2dc23367dd910ae3ba4cc Merge: 25557218 97c89310 Author: Still Hsu <341464@gmail.com> Date: Tue May 8 05:02:01 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit 97c893107b51de24a38ea03c2f8260030c8fc7f5 Author: Still Hsu <341464@gmail.com> Date: Mon May 7 06:22:49 2018 +0800 Implement GetBanAsync (#1056) commit 25557218dbc9390dbeac108afc153776f52dc26f Author: Still Hsu <341464@gmail.com> Date: Sun May 6 16:11:19 2018 +0800 Add details to SpotifyGame commit c7b236ddf5d7324dd8c1513ccd528a7a45d0031f Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:58:23 2018 +0800 Add more IGuild docs commit 1bb06cc37b7c2312b0ab111da63026a01da01e42 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:40:31 2018 +0800 Replace all langword placements with code block commit ac47d84ea74c81e136434dcc33967fe4cd95c1e6 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:22:17 2018 +0800 Replace langword null to code block null instead - Because DocFX sucks at rendering langword commit 0b15bbc54d15c036f770bab818712956c527b4ee Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:20:34 2018 +0800 Add XML docs commit 65d4e4360eb88e3bc5cc8f0da6135e5ee997af6c Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:57:53 2018 +0800 Add BaseSocketClient docs commit 8f64c045999c1bb0440bdc818f082e7459756b36 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:37:55 2018 +0800 Replace note block commit d8bb9e7aaa1e908ceb9227285c0cebec9add5280 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:31:50 2018 +0800 Add warning for bulk-delete endpoint commit adae5ffc9e42343f170d6c869644637587330b59 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:07:28 2018 +0800 Fix missing Username prop commit 3e591972cafdffb6692a1b94cf9a63251188df8b Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:01:34 2018 +0800 Add properties examples to overwrite commit 0ad66f6765addf6d4d25dfbddadeaa542d461403 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 04:55:15 2018 +0800 Fix minor consistencies & redundant impl commit 124efdf7e66ee070fbcdde07ed4f20c717c9c1c0 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 04:40:14 2018 +0800 XML Docs commit 3aa5d363de335444558fdb4bf1bf48a5743bc917 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 18:22:46 2018 +0800 Add 'last modified' plugin Source: https://github.com/Still34/DocFx.Plugin.LastModified Licensed under MIT License commit 2014870dc05dedb6171338d8ae4329eaa4c73f90 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:57:40 2018 +0800 Fix letter-casing for files commit f27d659ebeb88348e24e759308933e3983831ad7 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:50:00 2018 +0800 Document exposed TypeReaders commit 5a824a5695d72a62e28e0a307a5be446557291be Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:44:15 2018 +0800 Add missing exceptions commit c2de0c055f3894c795ea7d7da774fb006c752898 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:40:16 2018 +0800 Fix seealso for preconditions and add missing descriptions commit 3a7d7ee9552a2c6fea1c32b6f3cd91f6efdd29f5 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:36:22 2018 +0800 Minor fixes in documentations + Fix unescaped '<' + Fix typo commit 45839bd982a822dd9da10ceb48989fdb2cd8cd85 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:29:47 2018 +0800 Add XML Docs commit 9e6254600cd7bb5b7626025492223717f92501f9 Merge: aea06788 bb4bb138 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 14:48:13 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit aea067884c81832ad6cd910ff56c550cf3ecad75 Merge: 27dc4831 9ddd7090 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:51:07 2018 +0800 Merge branch 'docs/faq-n-patches-offline' of https://github.com/Still34/Discord.Net into docs/faq-n-patches-offline commit 27dc4831e88c952f3ea1f68b18434e16197fdfa9 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:50:27 2018 +0800 Add XML Docs commit baa8beb3824ed59fb50d269b9e13721fa9f5a04e Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:49:42 2018 +0800 Add XML Docs commit 089f97a0101a4ef9194f65b2d4435c0c69dfa87c Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:43:04 2018 +0800 Add details regarding userbot support commit bb4bb138460cc1e6bac53b4e838893dcfd812ce7 Author: Finite Reality <FiniteReality@users.noreply.github.com> Date: Fri May 4 11:42:54 2018 +0100 Fix issues with #984, remove extraneous whitespace (#1051) - Removed unnecessary parameter in SocketVoiceServer - Moved SocketVoiceServer into Entities/Voice - Fixed a bug where trying to download the cached guild would throw - Fixed a potential bug where Discord might not give us a port when connecting to voice commit 9ddd70906aa01015fc76bc2401868e044c4c7cc1 Merge: f197174f 7cfed7ff Author: Still Hsu <341464@gmail.com> Date: Fri May 4 09:37:04 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit f197174fcc2df1e092b26cd2c8087b602ffb1960 Author: Still Hsu <341464@gmail.com> Date: Fri May 4 09:36:53 2018 +0800 Fix embed docs consistency commit 7cfed7ff67ac9aee517de4130d9ccf504791ed61 Author: Alex Gravely <tcbskater@hotmail.com> Date: Thu May 3 21:30:13 2018 -0400 Fix nullref when passing null to GetShardIdFor. (#1049) commit e775853b1b26eaf80e6e76c295b44ca6241eaee7 Author: Luke <dev@crimsonxv.pro> Date: Fri May 4 02:29:51 2018 +0100 Expose VoiceServerUpdate events (#984) * Expose VoiceServerUpdate events * Amend based on feedback * Move this out of guild entity * Fix namespace issue * Adjust based on feedback #2 * Use cacheable instead * Change based on feedback commit 157acc46955d52809b959b52fb1a04404a6df3a5 Author: Still Hsu <341464@gmail.com> Date: Thu May 3 23:03:35 2018 +0800 Add tag examples commit 57ea571a8115f4b768c2dbbe1f2ef807b0cfd647 Author: Still Hsu <341464@gmail.com> Date: Thu May 3 22:48:33 2018 +0800 Fix sample link & add missing pictures commit 6769c37ad7e664845948c50ce403217a9951ef07 Author: Still Hsu <341464@gmail.com> Date: Thu May 3 22:39:26 2018 +0800 Compress some assets & add OAuth2 URL generator
7 years ago
Squashed commit of the following: commit dece19d89505342e5f8c51317b54be8ce69336c9 Merge: fdaa689a e764dafe Author: Still Hsu <341464@gmail.com> Date: Mon May 21 11:47:47 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit e764dafe083bf5db62091ac1f6b3d438eee38882 Author: Quahu <quahuu@gmail.com> Date: Sun May 13 15:34:40 2018 +0200 Add ViewChannel to Voice channel permissions (#1059) Previously, Voice channels did not have ViewChannel in their "all" permissions commit 32fc2df21b1840fd913ccce80c0686e8e853b43d Author: Alex Gravely <tcbskater@hotmail.com> Date: Sat May 12 20:47:44 2018 -0400 Remove unused field in EmbedFieldBuilder. (#1018) commit 39dffe858584d0e9eed750bff6426e9562db4262 Author: Finite Reality <FiniteReality@users.noreply.github.com> Date: Sun May 13 01:46:07 2018 +0100 Audit Logs implementation (#1055) * Copy audit logs impl from old branch and clean up I suck at using git, so I'm gonna use brute force. * Remove unnecessary TODOs Category channels do not provide any new information, and the other I forgot to remove beforehand * Add invite update data, clean up after feedback * Remove TODOs, add WebhookType enum for future use WebhookType is a future-use type, as currently audit logs are the only thing which may return it. commit fdaa689ae8be8e9d2ff5190b6cfed5af244b805b Author: Still Hsu <341464@gmail.com> Date: Wed May 9 06:04:59 2018 +0800 Add explanation for RunMode commit ea82c2537e64d4b75f85d9369e90cb55cfcadcc7 Author: Still Hsu <341464@gmail.com> Date: Tue May 8 16:30:48 2018 +0800 Initial proofread of the articles commit 124f1a267c663fbbb0f2dc23367dd910ae3ba4cc Merge: 25557218 97c89310 Author: Still Hsu <341464@gmail.com> Date: Tue May 8 05:02:01 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit 97c893107b51de24a38ea03c2f8260030c8fc7f5 Author: Still Hsu <341464@gmail.com> Date: Mon May 7 06:22:49 2018 +0800 Implement GetBanAsync (#1056) commit 25557218dbc9390dbeac108afc153776f52dc26f Author: Still Hsu <341464@gmail.com> Date: Sun May 6 16:11:19 2018 +0800 Add details to SpotifyGame commit c7b236ddf5d7324dd8c1513ccd528a7a45d0031f Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:58:23 2018 +0800 Add more IGuild docs commit 1bb06cc37b7c2312b0ab111da63026a01da01e42 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:40:31 2018 +0800 Replace all langword placements with code block commit ac47d84ea74c81e136434dcc33967fe4cd95c1e6 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:22:17 2018 +0800 Replace langword null to code block null instead - Because DocFX sucks at rendering langword commit 0b15bbc54d15c036f770bab818712956c527b4ee Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:20:34 2018 +0800 Add XML docs commit 65d4e4360eb88e3bc5cc8f0da6135e5ee997af6c Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:57:53 2018 +0800 Add BaseSocketClient docs commit 8f64c045999c1bb0440bdc818f082e7459756b36 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:37:55 2018 +0800 Replace note block commit d8bb9e7aaa1e908ceb9227285c0cebec9add5280 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:31:50 2018 +0800 Add warning for bulk-delete endpoint commit adae5ffc9e42343f170d6c869644637587330b59 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:07:28 2018 +0800 Fix missing Username prop commit 3e591972cafdffb6692a1b94cf9a63251188df8b Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:01:34 2018 +0800 Add properties examples to overwrite commit 0ad66f6765addf6d4d25dfbddadeaa542d461403 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 04:55:15 2018 +0800 Fix minor consistencies & redundant impl commit 124efdf7e66ee070fbcdde07ed4f20c717c9c1c0 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 04:40:14 2018 +0800 XML Docs commit 3aa5d363de335444558fdb4bf1bf48a5743bc917 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 18:22:46 2018 +0800 Add 'last modified' plugin Source: https://github.com/Still34/DocFx.Plugin.LastModified Licensed under MIT License commit 2014870dc05dedb6171338d8ae4329eaa4c73f90 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:57:40 2018 +0800 Fix letter-casing for files commit f27d659ebeb88348e24e759308933e3983831ad7 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:50:00 2018 +0800 Document exposed TypeReaders commit 5a824a5695d72a62e28e0a307a5be446557291be Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:44:15 2018 +0800 Add missing exceptions commit c2de0c055f3894c795ea7d7da774fb006c752898 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:40:16 2018 +0800 Fix seealso for preconditions and add missing descriptions commit 3a7d7ee9552a2c6fea1c32b6f3cd91f6efdd29f5 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:36:22 2018 +0800 Minor fixes in documentations + Fix unescaped '<' + Fix typo commit 45839bd982a822dd9da10ceb48989fdb2cd8cd85 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:29:47 2018 +0800 Add XML Docs commit 9e6254600cd7bb5b7626025492223717f92501f9 Merge: aea06788 bb4bb138 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 14:48:13 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit aea067884c81832ad6cd910ff56c550cf3ecad75 Merge: 27dc4831 9ddd7090 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:51:07 2018 +0800 Merge branch 'docs/faq-n-patches-offline' of https://github.com/Still34/Discord.Net into docs/faq-n-patches-offline commit 27dc4831e88c952f3ea1f68b18434e16197fdfa9 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:50:27 2018 +0800 Add XML Docs commit baa8beb3824ed59fb50d269b9e13721fa9f5a04e Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:49:42 2018 +0800 Add XML Docs commit 089f97a0101a4ef9194f65b2d4435c0c69dfa87c Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:43:04 2018 +0800 Add details regarding userbot support commit bb4bb138460cc1e6bac53b4e838893dcfd812ce7 Author: Finite Reality <FiniteReality@users.noreply.github.com> Date: Fri May 4 11:42:54 2018 +0100 Fix issues with #984, remove extraneous whitespace (#1051) - Removed unnecessary parameter in SocketVoiceServer - Moved SocketVoiceServer into Entities/Voice - Fixed a bug where trying to download the cached guild would throw - Fixed a potential bug where Discord might not give us a port when connecting to voice commit 9ddd70906aa01015fc76bc2401868e044c4c7cc1 Merge: f197174f 7cfed7ff Author: Still Hsu <341464@gmail.com> Date: Fri May 4 09:37:04 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit f197174fcc2df1e092b26cd2c8087b602ffb1960 Author: Still Hsu <341464@gmail.com> Date: Fri May 4 09:36:53 2018 +0800 Fix embed docs consistency commit 7cfed7ff67ac9aee517de4130d9ccf504791ed61 Author: Alex Gravely <tcbskater@hotmail.com> Date: Thu May 3 21:30:13 2018 -0400 Fix nullref when passing null to GetShardIdFor. (#1049) commit e775853b1b26eaf80e6e76c295b44ca6241eaee7 Author: Luke <dev@crimsonxv.pro> Date: Fri May 4 02:29:51 2018 +0100 Expose VoiceServerUpdate events (#984) * Expose VoiceServerUpdate events * Amend based on feedback * Move this out of guild entity * Fix namespace issue * Adjust based on feedback #2 * Use cacheable instead * Change based on feedback commit 157acc46955d52809b959b52fb1a04404a6df3a5 Author: Still Hsu <341464@gmail.com> Date: Thu May 3 23:03:35 2018 +0800 Add tag examples commit 57ea571a8115f4b768c2dbbe1f2ef807b0cfd647 Author: Still Hsu <341464@gmail.com> Date: Thu May 3 22:48:33 2018 +0800 Fix sample link & add missing pictures commit 6769c37ad7e664845948c50ce403217a9951ef07 Author: Still Hsu <341464@gmail.com> Date: Thu May 3 22:39:26 2018 +0800 Compress some assets & add OAuth2 URL generator
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. ---
  2. uid: Discord.Commands.PreconditionAttribute
  3. remarks: *content
  4. ---
  5. This precondition attribute can be applied on module-level or
  6. method-level for a command.
  7. [!include[Additional Remarks](PreconditionAttribute.Remarks.Inclusion.md)]
  8. ---
  9. uid: Discord.Commands.ParameterPreconditionAttribute
  10. remarks: *content
  11. ---
  12. This precondition attribute can be applied on parameter-level for a
  13. command.
  14. [!include[Additional Remarks](PreconditionAttribute.Remarks.Inclusion.md)]
  15. ---
  16. uid: Discord.Commands.PreconditionAttribute
  17. example: [*content]
  18. ---
  19. The following example creates a precondition to see if the user has
  20. sufficient role required to access the command.
  21. ```cs
  22. public class RequireRoleAttribute : PreconditionAttribute
  23. {
  24. private readonly ulong _roleId;
  25. public RequireRoleAttribute(ulong roleId)
  26. {
  27. _roleId = roleId;
  28. }
  29. public override async Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context,
  30. CommandInfo command, IServiceProvider services)
  31. {
  32. var guildUser = context.User as IGuildUser;
  33. if (guildUser == null)
  34. return PreconditionResult.FromError("This command cannot be executed outside of a guild.");
  35. var guild = guildUser.Guild;
  36. if (guild.Roles.All(r => r.Id != _roleId))
  37. return PreconditionResult.FromError(
  38. $"The guild does not have the role ({_roleId}) required to access this command.");
  39. return guildUser.RoleIds.Any(rId => rId == _roleId)
  40. ? PreconditionResult.FromSuccess()
  41. : PreconditionResult.FromError("You do not have the sufficient role required to access this command.");
  42. }
  43. }
  44. ```
  45. ---
  46. uid: Discord.Commands.ParameterPreconditionAttribute
  47. example: [*content]
  48. ---
  49. The following example creates a precondition on a parameter-level to
  50. see if the targeted user has a lower hierarchy than the user who
  51. executed the command.
  52. ```cs
  53. public class RequireHierarchyAttribute : ParameterPreconditionAttribute
  54. {
  55. public override async Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context,
  56. ParameterInfo parameter, object value, IServiceProvider services)
  57. {
  58. // Hierarchy is only available under the socket variant of the user.
  59. if (!(context.User is SocketGuildUser guildUser))
  60. return PreconditionResult.FromError("This command cannot be used outside of a guild.");
  61. SocketGuildUser targetUser;
  62. switch (value)
  63. {
  64. case SocketGuildUser targetGuildUser:
  65. targetUser = targetGuildUser;
  66. break;
  67. case ulong userId:
  68. targetUser = await context.Guild.GetUserAsync(userId).ConfigureAwait(false) as SocketGuildUser;
  69. break;
  70. default:
  71. throw new ArgumentOutOfRangeException();
  72. }
  73. if (targetUser == null)
  74. return PreconditionResult.FromError("Target user not found.");
  75. if (guildUser.Hierarchy < targetUser.Hierarchy)
  76. return PreconditionResult.FromError("You cannot target anyone else whose roles are higher than yours.");
  77. var currentUser = await context.Guild.GetCurrentUserAsync().ConfigureAwait(false) as SocketGuildUser;
  78. if (currentUser?.Hierarchy < targetUser.Hierarchy)
  79. return PreconditionResult.FromError("The bot's role is lower than the targeted user.");
  80. return PreconditionResult.FromSuccess();
  81. }
  82. }
  83. ```