diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 000000000..84ee6e5a1 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +open_collective: discordnet diff --git a/.gitignore b/.gitignore index d72e0b5ea..654370842 100644 --- a/.gitignore +++ b/.gitignore @@ -127,7 +127,7 @@ publish/ # Publish Web Output *.[Pp]ublish.xml *.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings +# TODO: Comment the next line if you want to checkin your web deploy settings # but database connection strings (with potential passwords) will be unencrypted *.pubxml *.publishproj @@ -151,7 +151,6 @@ AppPackages/ # Others *.[Cc]ache ClientBin/ -[Ss]tyle[Cc]op.* ~$* *~ *.dbmdl @@ -206,4 +205,4 @@ docs/api/\.manifest \.idea/ # Codealike UID -codealike.json \ No newline at end of file +codealike.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 886754052..7ca46be59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,246 @@ # Changelog +## [3.1.0] - 2021-12-24 + +### Added + +- #1996 Add nullable type converter to Interaction service (ccc365e) +- #1998 Add before and after execute async (9f124b2) +- #2001 Add MaxUploadLimit to guilds (7745558) +- #2002 Add RTCRegion to voice channels (2a416a3) +- #2003 Add Guilduser timeouts and MODERATE_MEMBERS permission (144741e) + +### Fixed + +- #1976 fix guild scheduled events update (8daa0b6) +- #1977 fix thread member nre (5d43fe6) +- #1980 fix requireRole attribute of interaction service (a2f57f8) +- #1990 Fix images path for select menu section (a8b5506) +- #1992 fix images; fix closing brace on cs ref (fb52525) +- #1993 Fix CommandExecuted not invoked on failed parse (82bb3e4) +- #1995 Fixed file being disposed on upload (ad20e03) +- #1999 Fix SocketGuildUser being changed to SocketGlobalUser in UserLeft (5446bfe) +- Fix voice codes namespace (768a0a9) + +### Misc + +- #1994 Make HasResponded public and add it to IDiscordInteraction (1fbcbb8) +- #1997 Make module service scopes optional (cb1aad3) + +## [3.0.0] - 2021-12-13 + +### Added + +- #1152 Add characters commonly use in links to Sanitize (b9274d1) +- #1518 Add default nullable enum typereader (f7a07ae) +- #1700 Added Implementation of ValidateAndGetBestMatch (3cd9f39) +- #1767 Add method to clear guild user cache (19a66bf) +- #1847 Bump API version to 9 (06a64b7) +- #1848 Remove obsolete sync voice regions methods and properties (ed8e573) +- #1851 Remove DM cache and fix references (7a201e9) +- #1860 Remove /users/@me call for socket and rework sharded client a bit (384ad85) +- #1863 Change GuildMemberUpdate before state to cacheable (c2e87f5) +- #1666 Added negative TimeSpan handling (6abdfcb) +- #1861 Add MaxBitrate to the interface (e0dbe7c) +- #1865 Add null check to AllowedMentions.ToModel() (3cb662f) +- #1879 Add Name property to Teams (c5b4b64) +- #1890 Add default avatar to WithAuthor extension (c200861) +- #1896 IVoiceChannel implements IMentionable (3395700) +- #1923 Add Interaction Support (933ea42) +- #1923 Add Application commands (933ea42) +- #1923 Add Message Components (933ea42) +- #1923 Add Thread Channels (933ea42) +- #1923 Add Stage Channels (933ea42) +- #1923 Add Guild Events (933ea42) +- #1923 Revamped Stickers (933ea42) +- #1923 Add TimestampTag (933ea42) +- #1923 Add name property to teams (933ea42) +- #1923 Add url validation on embeds (933ea42) +- #1923 Add NsfwLevel to Guilds (933ea42) +- #1923 Add helpers to Emoji for parsing (933ea42) +- #1923 Add banner and accent color to guild users (933ea42) +- #1923 Add RatelimitCallback to RequestOptions (933ea42) +- #1923 Add Emoji to roles (933ea42) +- #1923 Add UseInteractionSnowflakeDate to config (933ea42) +- #1923 Add checks for gateway intent in some methods (933ea42) +- #1923 Add SendFilesAsync to channels (933ea42) +- #1923 Add Attachments property to MessageProperties (933ea42) +- #1942 Add multi-file upload to webhooks (bc440ab) +- #1943 Handle bidirectional usernames (10afd96) +- #1945 Updated socket presence and add new presence event (9d6dc62) +- #1948 Added warnings on invalid gateway intents (51e06e9) +- #1949 Add default application games (82276e3) +- #1950 Add custom setter to Group property of ModuleBuilder to automatically invoke AddAliases (ba656e9) +- #1958 Add Discord.Interactions framework (aa6bb5e) + +### Fixed + +- #1832 Grab correct Uses value for vanity urls (8ed8714) +- #1849 Remove obsolete methods and properties (70aab6c) +- #1850 Create DM channel with id and author alone (95bae78) +- #1853 Fire GuildMemberUpdated without cached user (d176fef) +- #1854 Gateway events for DMs (a7ff6ce) +- #1858 MessageUpdated without author (8b29e0f) +- #1859 Fix missing AddRef and related (de7f9b5) +- #1862 Message update without author (fabe034) +- #1864 ApiClient.CurrentUser being null (08507c0) +- #1871 Fix empty role list if not present (f47001a) +- #1872 Connection deadlock when trying to Send and Disconnect (97d90b9) +- #1873 Remove OperationCanceledException handling in connecting logic (7cf8499) +- #1876 Fix SocketMessage type always being default (ac52a11) +- #1877 Fix RestMessage type always being default (22bb1b0) +- #1886 Change embed description max length to 4096 (8349cd7) +- #1923 Fix ReactionAdded cached parameters (933ea42) +- #1923 Fixed GuildMemberUpdated cached parameters (933ea42) +- #1923 Fixed UserIsTypeing cached parameters (933ea42) +- #1941 Fix Emote.TryParse (900c1f4) +- #1946 Fix NRE when adding parameters in ModuleBuilders (143ca6d) +- #1947 ShardedClient's CurrentUser interface property being null (d5f5ae1) + +### Misc + +- #1852 Internal change to GetOrCreateUser (dfaaa21) +- #1923 Make Hierarchy a IGuildUser property (933ea42) +- #1923 Fixed gateway serialization to include nulls for API v9 (933ea42) +- #1923 Removed error log for gateway reconnects (933ea42) + +## [2.4.0] - 2021-05-22 + +### Added + +- #1726 Add stickers (91a9063) +- #1753 Webhook message edit & delete functionality (f67cd8e) +- #1757 Add ability to add/remove roles by id (4c9910c) +- #1781 Add GetEmotesAsync to IGuild (df23d57) +- #1801 Add missing property to MESSAGE_REACTION_ADD event (0715d7d) +- #1828 Add methods to interact with reactions without a message object (5b244f2) +- #1830 Add ModifyMessageAsync to IMessageChannel (365a848) +- #1844 Add Discord Certified Moderator user flag (4b8d444) + +### Fixed + +- #1486 Add type reader when entity type reader exists (c46daaa) +- #1835 Cached message emoji cleanup at MESSAGE_REACTION_REMOVE_EMOJI (8afef82) + +### Misc + +- #1778 Remove URI check from EmbedBuilder (25b04c4) +- #1800 Fix spelling in SnowflakeUtils.FromSnowflake (6aff419) + +## [2.3.1] - 2021-03-10 + +### Fixed + +- #1761 Deadlock in DiscordShardedClient when Ready is never received (73e5cc2) +- #1773 Private methods aren't added as commands (0fc713a) +- #1780 NullReferenceException in pin/unpin audit logs (f794163) +- #1786 Add ChannelType property to ChannelInfo audit log (6ac5ea1) +- #1791 Update Webhook ChannelId from model change (d2518db) +- #1794 Audit log UserId can be null (d41aeee) + +### Misc + +- #1774 Add remark regarding CustomStatus as the activity (51b7afe) + +## [2.3.0] - 2021-01-28 + +### Added + +- #1491 Add INVITE_CREATE and INVITE_DELETE events (1ab670b) +- #1520 Support reading multiple activities (421a0c1) +- #1521 Allow for inherited commands in modules (a51cdf6) +- #1526 Add Direction.Around to GetMessagesAsync (f2130f8) +- #1537 Implement gateway ratelimit (ec673e1) +- #1544 Add MESSAGE_REACTION_REMOVE_EMOJI and RemoveAllReactionsForEmoteAsync (a89f076) +- #1549 Add GetUsersAsync to SocketGuild (30b5a83) +- #1566 Support Gateway Intents (d5d10d3) +- #1573 Add missing properties to Guild and deprecate GuildEmbed (ec212b1) +- #1581 Add includeRoleIds to PruneUsersAsync (a80e5ff) +- #1588 Add GetStreams to AudioClient (1e012ac) +- #1596 Add missing channel properties (2d80037) +- #1604 Add missing application properties (including Teams) (10fcde0) +- #1619 Add "View Guild Insights" to GuildPermission (2592264) +- #1637 Added CultureInvariant RegexOption to WebhookUrlRegex (e3925a7) +- #1659 Add inline replies (e3850e1) +- #1688 Send presence on Identify payload (25d5d36) +- #1721 Add role tags (6a62c47) +- #1722 Add user public flags (c683b29) +- #1724 Add MessageFlags and AllowedMentions to message modify (225550d) +- #1731 Add GuildUser IsPending property (8b25c9b) +- #1690 Add max bitrate value to SocketGuild (aacfea0) + +### Fixed + +- #1244 Missing AddReactions permission for DM channels. (e40ca4a) +- #1469 unsupported property causes an exception (468f826) +- #1525 AllowedMentions and AllowedMentionTypes (3325031) +- #1531 Add AllowedMentions to SendFileAsync (ab32607) +- #1532 GuildEmbed.ChannelId as nullable per API documentation (971d519) +- #1546 Different ratelimits for the same route (implement discord buckets) (2f6c017) +- #1548 Incomplete Ready, DownloadUsersAsync, and optimize AlwaysDownloadUsers (dc8c959) +- #1555 InvalidOperationException at MESSAGE_CREATE (bd4672a) +- #1557 Sending 2 requests instead of 1 to create a Guild role. (5430cc8) +- #1571 Not using the new domain name. (df8a0f7) +- #1578 Trim token before passing it to the authorization header (42ba372) +- #1580 Stop TaskCanceledException from bubbling up (b8fa464) +- #1599 Invite audit log without inviter (b95b95b) +- #1602 Add AllowedMentions to webhooks (bd4516b) +- #1603 Cancel reconnection when 4014 (f396cd9) +- #1608 Voice overwrites and CategoryId remarks (43c8fc0) +- #1614 Check error 404 and return null for GetBanAsync (ae9fff6) +- #1621 Parse mentions from message payload (366ca9a) +- #1622 Do not update overwrite cache locally (3860da0) +- #1623 Invoke UserUpdated from GuildMemberUpdated if needed (3085e88) +- #1624 Handle null PreferredLocale in rare cases (c1d04b4) +- #1639 Invite and InviteMetadata properties (dd2e524) +- #1642 Add missing permissions (4b389f3) +- #1647 handicap member downloading for verified bots (fa5ef5e) +- #1652 Update README.MD to reflect new discord domain (03b831e) +- #1667 Audio stream dispose (a2af985) +- #1671 Crosspost throwing InvalidOperationException (9134443) +- #1672 Team is nullable, not optional (be60d81) +- #1681 Emoji url encode (04389a4) +- #1683 SocketGuild.HasAllMembers is false if a user left a guild (47f571e) +- #1686 Revert PremiumSubscriptionCount type (97e71cd) +- #1695 Possible NullReferenceException when receiving InvalidSession (5213916) +- #1702 Rollback Activities to Game (9d7cb39) +- #1727 Move and fix internal AllowedMentions object (4a7f8fe) +- limit request members batch size (084db25) +- UserMentions throwing NullRef (5ed01a3) +- Wrong author for SocketUserMessage.ReferencedMessage (1e9b252) +- Discord sends null when there's no team (05a1f0a) +- IMessage.Embeds docs remarks (a4d32d3) +- Missing MessageReference when sending files (2095701) + +### Misc + +- #1545 MutualGuilds optimization (323a677) +- #1551 Update webhook regex to support discord.com (7585789) +- #1556 Add SearchUsersAsync (57880de) +- #1561 Minor refactor to switch expression (42826df) +- #1576 Updating comments for privileged intents (c42bfa6) +- #1678 Change ratelimit messages (47ed806) +- #1714 Update summary of SocketVoiceChannel.Users (e385c40) +- #1720 VoiceRegions and related changes (5934c79) +- Add updated libraries for LastModified (d761846) +- Add alternative documentation link (accd351) +- Temporarily disable StyleCops until all the fixes are impl'd (36de7b2) +- Remove redundant CreateGuildRoleParams (3df0539) +- Add minor tweaks to DiscordSocketConfig docs strings (2cd1880) +- Fix MaxWaitBetweenGuildAvailablesBeforeReady docs string (e31cdc7) +- Missing summary tag for GatewayIntents (3a10018) +- Add new method of role ID copy (857ef77) +- Resolve inheritdocs for IAttachment (9ea3291) +- Mark null as a specific langword in summary (13a41f8) +- Cleanup GatewayReconnectException docs (833ee42) +- Update Docfx.Plugins.LastModified to v1.2.4 (28a6f97) +- Update framework version for tests to Core 3.1 to comply with LTS (4988a07) +- Move bulk deletes remarks from to (62539f0) + ## [2.2.0] - 2020-04-16 + ### Added + - #1247 Implement Client Status Support (9da11b4) - #1310 id overload for RemoveReactionAsync (c88b1da) - #1319 BOOST (faf23de) @@ -24,6 +263,7 @@ - suppress messages (cd28892) ### Fixed + - #1318 #1314 Don't parse tags within code blocks (c977f2e) - #1333 Remove null coalescing on ToEmbedBuilder Color (120c0f7) - #1337 Fixed attempting to access a non-present optional value (4edda5b) @@ -39,11 +279,13 @@ - include MessageFlags and SuppressEmbedParams (d6d4429) ### Changed + - #1368 Update ISystemMessage interface to allow reactions (07f4d5f) - #1417 fix #1415 Re-add support for overwrite permissions for news channels (e627f07) - use millisecond precision by default (bcb3534) ### Misc + - #1290 Split Unit and Integration tests into separate projects (a797be9) - #1328 Fix #1327 Color.ToString returns wrong value (1e8aa08) - #1329 Fix invalid cref values in docs (363d1c6) @@ -68,14 +310,16 @@ - 2.2.0 (4b602b4) - target the Process env-var scope (3c6b376) - fix metapackage build (1794f95) -- copy only _site to docs-static (a8cdadc) +- copy only \_site to docs-static (a8cdadc) - do not exit on failed robocopy (fd204ee) - add idn debugger (91aec9f) - rename IsStream to IsStreaming (dcd9cdd) - feature (40844b9) ## [2.1.1] - 2019-06-08 + ### Fixed + - #994: Remainder parameters now ignore character escaping, as there is no reason to escape characters here (2e95c49) - #1316: `Emote.Equals` now pays no respect to the Name property, since Discord's API does not care about an emote's name (abf3e90) - #1317: `Emote.GetHashCode` now pays no respect to the Name property, see above (1b54883) @@ -84,16 +328,20 @@ - News embeds will be processed as `EmbedType.Unknown`, rather than throwing an error and dropping the message (d287ed1) ### Changed + - #1311: Members may now be disconnected from voice channels by passing `null` as `GuildUserProperties.Channel` (fc48c66) - #1313: `IMessage.Tags` now includes the EveryoneRole on @everyone and @here mentions (1f55f01) - #1320: The maximum value for setting slow-mode has been updated to 6 hours, per the new API limit (4433ca7) ### Misc + - This library's compatibility with Semantic Versioning has been clarified. Please see the README (4d7de17) - The depency on System.Interactive.Async has been bumped to `3.2.0` (3e65e03) ## [2.1.0] - 2019-05-18 + ### Added + - #1236: Bulk deletes (for messages) may now be accessed via the `MessagesBulkDeleted` event (dec353e) - #1240: OAuth applications utilizing the `guilds.join` scope may now add users to guilds through any client (1356ea9) - #1255: Message and attachment spoilers may now be set or detected (f3b20b2) @@ -105,9 +353,11 @@ - `ExclusiveBulkDelete` configuration setting can be used to control bulk delete event behavior (03e6401) ### Removed + - #1294: The `IGuildUser` overload of `EmbedBuilder.WithAuthor` no longer exists (b52b54d) ### Fixed + - #1256: Fetching audit logs no longer raises null reference exceptions when a webhook has been deleted (049b014) - #1268: Null reference exceptions on `MESSAGE_CREATE` concerning partial member objects no longer occur (377622b) - #1278: The token validator now internally pads tokens to the proper length (48b327b) @@ -116,9 +366,11 @@ - Exceptions in event handlers are now always logged (f6e3200) ### Changed + - #1305: Token validation will fail when tokens contain whitespace (bb61efa) ### Misc + - #1241: Added documentation samples for Webhooks (655a006) - #1243: Happy new year 🎉 (0275f7d) - #1257: Improved clarity in comments in the command samples (2473619) @@ -129,16 +381,20 @@ - IDisposableAnalyzers should now be a development dependency (8003ac8) ## [2.0.1] - 2019-01-04 + ### Fixed + - #1226: Only escape the closing quotation mark of non-remainder strings (65b8c09) - Commands with async RunModes will now propagate exceptions up to CommandExecuted (497918e) ### Misc + - #1225: Commands sample no longer hooks the log event twice (552f34c) - #1227: The logo on the docs index page should scale responsively (d39bf6e) - #1230: Replaced precondition sample on docs (feed4fd) ## [2.0.0] - 2018-12-28 + ### Added - #747: `CommandService` now has a `CommandExecuted` event (e991715) @@ -194,6 +450,7 @@ - Reactions can now be added to messages in bulk (5421df1) ### Fixed + - #742: `DiscordShardedClient#GetGuildFor` will now direct null guilds to Shard 0 (d5e9d6f) - #743: Various issues with permissions and inheritance of permissions (f996338) - #755: `IRole.Mention` will correctly tag the @everyone role (6b5a6e7) @@ -241,6 +498,7 @@ - The default WebSocket will now close correctly (ac389f5) ### Changed + - #731: `IUserMessage#GetReactionUsersAsync` now takes an `IEmote` instead of a `string` (5d7f2fc) - #744: IAsyncEnumerable has been redesigned (5bbd9bb) - #777: `IGuild#DefaultChannel` will now resolve the first accessible channel, per changes to Discord (1ffcd4b) @@ -275,14 +533,15 @@ - The socket client will now use additional fields to fill in member/guild information on messages (8fb2c71) - The Audio Client now uses Voice WS v3 (9ba38d7) - ### Removed + - #790: Redundant overloads for `AddField` removed from EmbedBuilder (479361b) - #925: RPC is no longer being maintained nor packaged (b30af57) - #958: Remove support for user tokens (2fd4f56) - User logins (including selfbots) are no longer supported (fc5adca) ### Misc + - #786: Unit tests for the Color structure (22b969c) - #828: We now include a contributing guide (cd82a0f) - #876: We now include a standard editorconfig (5c8c784) @@ -303,11 +562,13 @@ - Fixed documentation layout for the logo (bafdce4) ## [1.0.2] - 2017-09-09 + ### Fixed - Guilds utilizing Channel Categories will no longer crash bots on the `READY` event. ## [1.0.1] - 2017-07-05 + ### Fixed - #732: Fixed parameter preconditions not being loaded from class-based modules (b6dcc9e) @@ -316,4 +577,5 @@ - Fixed module auto-detection for nested modules (d2afb06) ### Changed + - ShardedCommandContext now inherits from SocketCommandContext (8cd99be) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 752b40931..840650cf8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,7 +17,7 @@ any member of the community. We prefer pull-requests that are descriptive of the changes being made and highlight any potential benefits/drawbacks of the change, but these -types of write-ups are not required. See this [merge request](https://github.com/RogueException/Discord.Net/pull/793) +types of write-ups are not required. See this [merge request](https://github.com/discord-net/Discord.Net/pull/793) for an example of a well-written description. ## Semantic Versioning @@ -28,7 +28,7 @@ that are SemVer compliant with the latest version of the library in development. The working release should be the latest build off of the `dev` branch, -but can also be found on the [development board](https://github.com/RogueException/Discord.Net/projects/1). +but can also be found on the [development board](https://github.com/discord-net/Discord.Net/projects/1). We follow the .NET Foundation's [Breaking Change Rules](https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/breaking-change-rules.md) when determining the SemVer compliance of a change. @@ -59,4 +59,4 @@ The length of the documentation should also follow the ruler as suggested by our #### Recommended Reads * [Official Microsoft Documentation](https://docs.microsoft.com) -* [Sandcastle User Manual](https://ewsoftware.github.io/XMLCommentsGuide/html/4268757F-CE8D-4E6D-8502-4F7F2E22DDA3.htm) \ No newline at end of file +* [Sandcastle User Manual](https://ewsoftware.github.io/XMLCommentsGuide/html/4268757F-CE8D-4E6D-8502-4F7F2E22DDA3.htm) diff --git a/Discord.Net.sln b/Discord.Net.sln index 1a32f1270..c22d91e27 100644 --- a/Discord.Net.sln +++ b/Discord.Net.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.28407.52 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.31903.286 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Core", "src\Discord.Net.Core\Discord.Net.Core.csproj", "{91E9E7BD-75C9-4E98-84AA-2C271922E5C2}" EndProject @@ -12,16 +12,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Commands", "src EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.WebSocket", "src\Discord.Net.WebSocket\Discord.Net.WebSocket.csproj", "{688FD1D8-7F01-4539-B2E9-F473C5D699C7}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Providers", "Providers", "{B0657AAE-DCC5-4FBF-8E5D-1FB578CF3012}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Providers.WS4Net", "src\Discord.Net.Providers.WS4Net\Discord.Net.Providers.WS4Net.csproj", "{6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extensions", "Extensions", "{CC3D4B1C-9DE0-448B-8AE7-F3F1F3EC5C3A}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Webhook", "src\Discord.Net.Webhook\Discord.Net.Webhook.csproj", "{9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Analyzers", "src\Discord.Net.Analyzers\Discord.Net.Analyzers.csproj", "{BBA8E7FB-C834-40DC-822F-B112CB7F0140}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{BB59D5B5-E7B0-4BF4-8F82-D14431B2799B}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "01_basic_ping_bot", "samples\01_basic_ping_bot\01_basic_ping_bot.csproj", "{F2FF84FB-F6AD-47E5-9EE5-18206CAE136E}" @@ -40,7 +34,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Analyzers.Tests EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Examples", "src\Discord.Net.Examples\Discord.Net.Examples.csproj", "{47820065-3CFB-401C-ACEA-862BD564A404}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "idn", "samples\idn\idn.csproj", "{4A03840B-9EBE-47E3-89AB-E0914DF21AFB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "idn", "samples\idn\idn.csproj", "{4A03840B-9EBE-47E3-89AB-E0914DF21AFB}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Interactions", "src\Discord.Net.Interactions\Discord.Net.Interactions.csproj", "{137DB209-B357-4EE8-A6EE-4B6127F6DEE9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "04_interactions_framework", "samples\04_interactions_framework\04_interactions_framework.csproj", "{A23E46D2-1610-4AE5-820F-422D34810887}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Analyzers", "src\Discord.Net.Analyzers\Discord.Net.Analyzers.csproj", "{24C231FD-8CF3-444A-9E7C-45C18BAD4A0D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -100,18 +100,6 @@ Global {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x64.Build.0 = Release|Any CPU {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x86.ActiveCfg = Release|Any CPU {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x86.Build.0 = Release|Any CPU - {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7}.Debug|x64.ActiveCfg = Debug|Any CPU - {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7}.Debug|x64.Build.0 = Debug|Any CPU - {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7}.Debug|x86.ActiveCfg = Debug|Any CPU - {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7}.Debug|x86.Build.0 = Debug|Any CPU - {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7}.Release|Any CPU.Build.0 = Release|Any CPU - {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7}.Release|x64.ActiveCfg = Release|Any CPU - {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7}.Release|x64.Build.0 = Release|Any CPU - {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7}.Release|x86.ActiveCfg = Release|Any CPU - {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7}.Release|x86.Build.0 = Release|Any CPU {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30}.Debug|Any CPU.Build.0 = Debug|Any CPU {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -124,18 +112,6 @@ Global {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30}.Release|x64.Build.0 = Release|Any CPU {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30}.Release|x86.ActiveCfg = Release|Any CPU {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30}.Release|x86.Build.0 = Release|Any CPU - {BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Debug|x64.ActiveCfg = Debug|Any CPU - {BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Debug|x64.Build.0 = Debug|Any CPU - {BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Debug|x86.ActiveCfg = Debug|Any CPU - {BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Debug|x86.Build.0 = Debug|Any CPU - {BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Release|Any CPU.Build.0 = Release|Any CPU - {BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Release|x64.ActiveCfg = Release|Any CPU - {BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Release|x64.Build.0 = Release|Any CPU - {BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Release|x86.ActiveCfg = Release|Any CPU - {BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Release|x86.Build.0 = Release|Any CPU {F2FF84FB-F6AD-47E5-9EE5-18206CAE136E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F2FF84FB-F6AD-47E5-9EE5-18206CAE136E}.Debug|Any CPU.Build.0 = Debug|Any CPU {F2FF84FB-F6AD-47E5-9EE5-18206CAE136E}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -232,6 +208,42 @@ Global {4A03840B-9EBE-47E3-89AB-E0914DF21AFB}.Release|x64.Build.0 = Release|Any CPU {4A03840B-9EBE-47E3-89AB-E0914DF21AFB}.Release|x86.ActiveCfg = Release|Any CPU {4A03840B-9EBE-47E3-89AB-E0914DF21AFB}.Release|x86.Build.0 = Release|Any CPU + {137DB209-B357-4EE8-A6EE-4B6127F6DEE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {137DB209-B357-4EE8-A6EE-4B6127F6DEE9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {137DB209-B357-4EE8-A6EE-4B6127F6DEE9}.Debug|x64.ActiveCfg = Debug|Any CPU + {137DB209-B357-4EE8-A6EE-4B6127F6DEE9}.Debug|x64.Build.0 = Debug|Any CPU + {137DB209-B357-4EE8-A6EE-4B6127F6DEE9}.Debug|x86.ActiveCfg = Debug|Any CPU + {137DB209-B357-4EE8-A6EE-4B6127F6DEE9}.Debug|x86.Build.0 = Debug|Any CPU + {137DB209-B357-4EE8-A6EE-4B6127F6DEE9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {137DB209-B357-4EE8-A6EE-4B6127F6DEE9}.Release|Any CPU.Build.0 = Release|Any CPU + {137DB209-B357-4EE8-A6EE-4B6127F6DEE9}.Release|x64.ActiveCfg = Release|Any CPU + {137DB209-B357-4EE8-A6EE-4B6127F6DEE9}.Release|x64.Build.0 = Release|Any CPU + {137DB209-B357-4EE8-A6EE-4B6127F6DEE9}.Release|x86.ActiveCfg = Release|Any CPU + {137DB209-B357-4EE8-A6EE-4B6127F6DEE9}.Release|x86.Build.0 = Release|Any CPU + {A23E46D2-1610-4AE5-820F-422D34810887}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A23E46D2-1610-4AE5-820F-422D34810887}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A23E46D2-1610-4AE5-820F-422D34810887}.Debug|x64.ActiveCfg = Debug|Any CPU + {A23E46D2-1610-4AE5-820F-422D34810887}.Debug|x64.Build.0 = Debug|Any CPU + {A23E46D2-1610-4AE5-820F-422D34810887}.Debug|x86.ActiveCfg = Debug|Any CPU + {A23E46D2-1610-4AE5-820F-422D34810887}.Debug|x86.Build.0 = Debug|Any CPU + {A23E46D2-1610-4AE5-820F-422D34810887}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A23E46D2-1610-4AE5-820F-422D34810887}.Release|Any CPU.Build.0 = Release|Any CPU + {A23E46D2-1610-4AE5-820F-422D34810887}.Release|x64.ActiveCfg = Release|Any CPU + {A23E46D2-1610-4AE5-820F-422D34810887}.Release|x64.Build.0 = Release|Any CPU + {A23E46D2-1610-4AE5-820F-422D34810887}.Release|x86.ActiveCfg = Release|Any CPU + {A23E46D2-1610-4AE5-820F-422D34810887}.Release|x86.Build.0 = Release|Any CPU + {24C231FD-8CF3-444A-9E7C-45C18BAD4A0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {24C231FD-8CF3-444A-9E7C-45C18BAD4A0D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {24C231FD-8CF3-444A-9E7C-45C18BAD4A0D}.Debug|x64.ActiveCfg = Debug|Any CPU + {24C231FD-8CF3-444A-9E7C-45C18BAD4A0D}.Debug|x64.Build.0 = Debug|Any CPU + {24C231FD-8CF3-444A-9E7C-45C18BAD4A0D}.Debug|x86.ActiveCfg = Debug|Any CPU + {24C231FD-8CF3-444A-9E7C-45C18BAD4A0D}.Debug|x86.Build.0 = Debug|Any CPU + {24C231FD-8CF3-444A-9E7C-45C18BAD4A0D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {24C231FD-8CF3-444A-9E7C-45C18BAD4A0D}.Release|Any CPU.Build.0 = Release|Any CPU + {24C231FD-8CF3-444A-9E7C-45C18BAD4A0D}.Release|x64.ActiveCfg = Release|Any CPU + {24C231FD-8CF3-444A-9E7C-45C18BAD4A0D}.Release|x64.Build.0 = Release|Any CPU + {24C231FD-8CF3-444A-9E7C-45C18BAD4A0D}.Release|x86.ActiveCfg = Release|Any CPU + {24C231FD-8CF3-444A-9E7C-45C18BAD4A0D}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -240,9 +252,7 @@ Global {BFC6DC28-0351-4573-926A-D4124244C04F} = {288C363D-A636-4EAE-9AC1-4698B641B26E} {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C} = {CC3D4B1C-9DE0-448B-8AE7-F3F1F3EC5C3A} {688FD1D8-7F01-4539-B2E9-F473C5D699C7} = {288C363D-A636-4EAE-9AC1-4698B641B26E} - {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7} = {B0657AAE-DCC5-4FBF-8E5D-1FB578CF3012} {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30} = {CC3D4B1C-9DE0-448B-8AE7-F3F1F3EC5C3A} - {BBA8E7FB-C834-40DC-822F-B112CB7F0140} = {CC3D4B1C-9DE0-448B-8AE7-F3F1F3EC5C3A} {F2FF84FB-F6AD-47E5-9EE5-18206CAE136E} = {BB59D5B5-E7B0-4BF4-8F82-D14431B2799B} {4E1F1F40-B1DD-40C9-A4B1-A2046A4C9C76} = {BB59D5B5-E7B0-4BF4-8F82-D14431B2799B} {9B4C4AFB-3D15-44C6-9E36-12ED625AAA26} = {BB59D5B5-E7B0-4BF4-8F82-D14431B2799B} @@ -251,6 +261,9 @@ Global {FC67057C-E92F-4E1C-98BE-46F839C8AD71} = {C7CF5621-7D36-433B-B337-5A2E3C101A71} {47820065-3CFB-401C-ACEA-862BD564A404} = {BB59D5B5-E7B0-4BF4-8F82-D14431B2799B} {4A03840B-9EBE-47E3-89AB-E0914DF21AFB} = {BB59D5B5-E7B0-4BF4-8F82-D14431B2799B} + {137DB209-B357-4EE8-A6EE-4B6127F6DEE9} = {CC3D4B1C-9DE0-448B-8AE7-F3F1F3EC5C3A} + {A23E46D2-1610-4AE5-820F-422D34810887} = {BB59D5B5-E7B0-4BF4-8F82-D14431B2799B} + {24C231FD-8CF3-444A-9E7C-45C18BAD4A0D} = {CC3D4B1C-9DE0-448B-8AE7-F3F1F3EC5C3A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D2404771-EEC8-45F2-9D71-F3373F6C1495} diff --git a/Discord.Net.targets b/Discord.Net.targets index adb42f7a9..f69a858d3 100644 --- a/Discord.Net.targets +++ b/Discord.Net.targets @@ -1,15 +1,14 @@ - 2.3.0 - dev + 3.1.0 latest Discord.Net Contributors discord;discordapp - https://github.com/RogueException/Discord.Net + https://github.com/Discord-Net/Discord.Net http://opensource.org/licenses/MIT - https://github.com/RogueException/Discord.Net/raw/dev/docs/marketing/logo/PackageLogo.png + https://github.com/Discord-Net/Discord.Net/raw/dev/docs/marketing/logo/PackageLogo.png git - git://github.com/RogueException/Discord.Net + git://github.com/Discord-Net/Discord.Net $(VersionSuffix)-dev diff --git a/LICENSE b/LICENSE index 3765bf39c..fb9480169 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015-2019 Discord.Net Contributors +Copyright (c) 2015-2021 Discord.Net Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index f4bc5811e..cf0293359 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,71 @@ # Discord.Net -[![NuGet](https://img.shields.io/nuget/vpre/Discord.Net.svg?maxAge=2592000?style=plastic)](https://www.nuget.org/packages/Discord.Net) -[![MyGet](https://img.shields.io/myget/discord-net/vpre/Discord.Net.svg)](https://www.myget.org/feed/Packages/discord-net) -[![Build Status](https://dev.azure.com/discord-net/Discord.Net/_apis/build/status/discord-net.Discord.Net?branchName=dev)](https://dev.azure.com/discord-net/Discord.Net/_build/latest?definitionId=1&branchName=dev) -[![Discord](https://discordapp.com/api/guilds/81384788765712384/widget.png)](https://discord.gg/jkrBmQR) - -An unofficial .NET API Wrapper for the Discord client (http://discordapp.com). - -Check out the [documentation](https://discord.foxbot.me/) or join the [Discord API Chat](https://discord.gg/jkrBmQR). +

+ + Logo + +
+
+ + NuGet + + + MyGet + + + Build Status + + + Discord + +

+Discord NET is an unofficial .NET API Wrapper for the Discord client (https://discord.com). + +## Documentation + +- [Nightly](https://discordnet.dev) ## Installation + ### Stable (NuGet) + Our stable builds available from NuGet through the Discord.Net metapackage: + - [Discord.Net](https://www.nuget.org/packages/Discord.Net/) The individual components may also be installed from NuGet: + - [Discord.Net.Commands](https://www.nuget.org/packages/Discord.Net.Commands/) - [Discord.Net.Rest](https://www.nuget.org/packages/Discord.Net.Rest/) - [Discord.Net.WebSocket](https://www.nuget.org/packages/Discord.Net.WebSocket/) - [Discord.Net.Webhook](https://www.nuget.org/packages/Discord.Net.Webhook/) ### Unstable (MyGet) + Nightly builds are available through our MyGet feed (`https://www.myget.org/F/discord-net/api/v3/index.json`). +### Unstable (Labs) + +Labs builds are available on nuget (`https://www.nuget.org/packages/Discord.Net.Labs/`) and myget (`https://www.myget.org/F/discord-net-labs/api/v3/index.json`). + ## Compiling + In order to compile Discord.Net, you require the following: ### Using Visual Studio + - [Visual Studio 2017](https://www.microsoft.com/net/core#windowsvs2017) - [.NET Core SDK](https://www.microsoft.com/net/download/core) The .NET Core workload must be selected during Visual Studio installation. ### Using Command Line + - [.NET Core SDK](https://www.microsoft.com/net/download/core) ## Known Issues ### WebSockets (Win7 and earlier) + .NET Core 1.1 does not support WebSockets on Win7 and earlier. This issue has been fixed since the release of .NET Core 2.1. It is recommended to target .NET Core 2.1 or above for your project if you wish to run your bot on legacy platforms; alternatively, you may choose to install the [Discord.Net.Providers.WS4Net](https://www.nuget.org/packages/Discord.Net.Providers.WS4Net/) package. ## Versioning Guarantees diff --git a/StyleAnalyzer.targets b/StyleAnalyzer.targets new file mode 100644 index 000000000..0794cfacb --- /dev/null +++ b/StyleAnalyzer.targets @@ -0,0 +1,9 @@ + + + + diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5a1d48082..9aa0e5788 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -14,25 +14,20 @@ trigger: jobs: - job: Linux pool: - vmImage: 'ubuntu-16.04' + vmImage: 'ubuntu-latest' steps: - - task: UseDotNet@2 - displayName: 'Use .NET Core sdk' - inputs: - packageType: 'sdk' - version: '3.x' - template: azure/build.yml - job: Windows_build pool: - vmImage: 'windows-2019' + vmImage: 'windows-latest' condition: ne(variables['Build.SourceBranch'], 'refs/heads/dev') steps: - template: azure/build.yml - job: Windows_deploy pool: - vmImage: 'windows-2019' + vmImage: 'windows-latest' condition: | and ( succeeded(), @@ -44,4 +39,3 @@ jobs: steps: - template: azure/build.yml - template: azure/deploy.yml - - template: azure/docs.yml diff --git a/azure/build.yml b/azure/build.yml index 412e4a823..a4646ad73 100644 --- a/azure/build.yml +++ b/azure/build.yml @@ -1,5 +1,17 @@ steps: -- script: dotnet restore -v minimal Discord.Net.sln +- task: UseDotNet@2 + displayName: 'Use .NET Core sdk' + inputs: + packageType: 'sdk' + version: '6.0.x' + includePreviewVersions: true + +- task: DotNetCoreCLI@2 + inputs: + command: 'restore' + projects: 'Discord.Net.sln' + feedsToUse: 'select' + verbosityRestore: 'Minimal' displayName: Restore packages - script: dotnet build "Discord.Net.sln" --no-restore -v minimal -c $(buildConfiguration) /p:BuildNumber=$(buildNumber) /p:IsTagBuild=$(buildTag) diff --git a/azure/deploy.yml b/azure/deploy.yml index 61994299e..4742da3c8 100644 --- a/azure/deploy.yml +++ b/azure/deploy.yml @@ -7,6 +7,7 @@ steps: dotnet pack "src\Discord.Net.Webhook\Discord.Net.Webhook.csproj" --no-restore --no-build -v minimal -c $(buildConfiguration) -o "$(Build.ArtifactStagingDirectory)" /p:BuildNumber=$(buildNumber) /p:IsTagBuild=$(buildTag) dotnet pack "src\Discord.Net.Providers.WS4Net\Discord.Net.Providers.WS4Net.csproj" --no-restore --no-build -v minimal -c $(buildConfiguration) -o "$(Build.ArtifactStagingDirectory)" /p:BuildNumber=$(buildNumber) /p:IsTagBuild=$(buildTag) dotnet pack "src\Discord.Net.Analyzers\Discord.Net.Analyzers.csproj" --no-restore --no-build -v minimal -c $(buildConfiguration) -o "$(Build.ArtifactStagingDirectory)" /p:BuildNumber=$(buildNumber) /p:IsTagBuild=$(buildTag) + dotnet pack "src\Discord.Net.Interactions\Discord.Net.Interactions.csproj" --no-restore --no-build -v minimal -c $(buildConfiguration) -o "$(Build.ArtifactStagingDirectory)" /p:BuildNumber=$(buildNumber) /p:IsTagBuild=$(buildTag) displayName: Pack projects - task: NuGetCommand@2 diff --git a/docs/_overwrites/Commands/ICommandContext.Inclusion.md b/docs/_overwrites/Commands/ICommandContext.Inclusion.md index 4c1257b23..a5eaeeab6 100644 --- a/docs/_overwrites/Commands/ICommandContext.Inclusion.md +++ b/docs/_overwrites/Commands/ICommandContext.Inclusion.md @@ -1,5 +1,5 @@ An example of how this class is used the command system can be seen below: -[!code[Sample module](../../guides/commands/samples/intro/empty-module.cs)] -[!code[Command handler](../../guides/commands/samples/intro/command_handler.cs)] \ No newline at end of file +[!code[Sample module](../../guides/text_commands/samples/intro/empty-module.cs)] +[!code[Command handler](../../guides/text_commands/samples/intro/command_handler.cs)] diff --git a/docs/_overwrites/Common/EmbedBuilder.Overwrites.md b/docs/_overwrites/Common/EmbedBuilder.Overwrites.md index 409a78e94..85c292dd2 100644 --- a/docs/_overwrites/Common/EmbedBuilder.Overwrites.md +++ b/docs/_overwrites/Common/EmbedBuilder.Overwrites.md @@ -28,7 +28,7 @@ public async Task SendRichEmbedAsync() var embed = new EmbedBuilder { // Embed property can be set within object initializer - Title = "Hello world!" + Title = "Hello world!", Description = "I am a description set by initializer." }; // Or with methods diff --git a/docs/_overwrites/Common/EmbedObjectBuilder.Inclusion.md b/docs/_overwrites/Common/EmbedObjectBuilder.Inclusion.md index eac0d9ca5..a9d3539ed 100644 --- a/docs/_overwrites/Common/EmbedObjectBuilder.Inclusion.md +++ b/docs/_overwrites/Common/EmbedObjectBuilder.Inclusion.md @@ -4,10 +4,10 @@ field, and 2 normal fields using an @Discord.EmbedBuilder: ```cs var exampleAuthor = new EmbedAuthorBuilder() .WithName("I am a bot") - .WithIconUrl("https://discordapp.com/assets/e05ead6e6ebc08df9291738d0aa6986d.png"); + .WithIconUrl("https://discord.com/assets/e05ead6e6ebc08df9291738d0aa6986d.png"); var exampleFooter = new EmbedFooterBuilder() .WithText("I am a nice footer") - .WithIconUrl("https://discordapp.com/assets/28174a34e77bb5e5310ced9f95cb480b.png"); + .WithIconUrl("https://discord.com/assets/28174a34e77bb5e5310ced9f95cb480b.png"); var exampleField = new EmbedFieldBuilder() .WithName("Title of Another Field") .WithValue("I am an [example](https://example.com).") @@ -22,4 +22,4 @@ var embed = new EmbedBuilder() .WithAuthor(exampleAuthor) .WithFooter(exampleFooter) .Build(); -``` \ No newline at end of file +``` diff --git a/docs/_template/description-generator/plugins/DocFX.Plugin.DescriptionGenerator.dll b/docs/_template/description-generator/plugins/DocFX.Plugin.DescriptionGenerator.dll index 095ea46ef..6e8839796 100644 Binary files a/docs/_template/description-generator/plugins/DocFX.Plugin.DescriptionGenerator.dll and b/docs/_template/description-generator/plugins/DocFX.Plugin.DescriptionGenerator.dll differ diff --git a/docs/_template/description-generator/plugins/LICENSE b/docs/_template/description-generator/plugins/LICENSE index eb92c0a03..d74703f3d 100644 --- a/docs/_template/description-generator/plugins/LICENSE +++ b/docs/_template/description-generator/plugins/LICENSE @@ -19,3 +19,11 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +============================================================================== + +Humanizer (https://github.com/Humanizr/Humanizer) +The MIT License (MIT) +Copyright (c) .NET Foundation and Contributors + +============================================================================== \ No newline at end of file diff --git a/docs/_template/last-modified/plugins/LastModifiedPostProcessor.dll b/docs/_template/last-modified/plugins/LastModifiedPostProcessor.dll index dd790e55e..be36969c9 100644 Binary files a/docs/_template/last-modified/plugins/LastModifiedPostProcessor.dll and b/docs/_template/last-modified/plugins/LastModifiedPostProcessor.dll differ diff --git a/docs/_template/last-modified/plugins/LibGit2Sharp.dll b/docs/_template/last-modified/plugins/LibGit2Sharp.dll index 82f214846..5b3568103 100644 Binary files a/docs/_template/last-modified/plugins/LibGit2Sharp.dll and b/docs/_template/last-modified/plugins/LibGit2Sharp.dll differ diff --git a/docs/_template/last-modified/plugins/LibGit2Sharp.dll.config b/docs/_template/last-modified/plugins/LibGit2Sharp.dll.config index ddc821b29..c93e4cc22 100644 --- a/docs/_template/last-modified/plugins/LibGit2Sharp.dll.config +++ b/docs/_template/last-modified/plugins/LibGit2Sharp.dll.config @@ -1,4 +1,4 @@ - - - + + + diff --git a/docs/_template/last-modified/plugins/lib/alpine-x64/libgit2-ef5a385.so b/docs/_template/last-modified/plugins/lib/alpine-x64/libgit2-ef5a385.so new file mode 100644 index 000000000..793f4483a Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/alpine-x64/libgit2-ef5a385.so differ diff --git a/docs/_template/last-modified/plugins/lib/alpine.3.9-x64/libgit2-ef5a385.so b/docs/_template/last-modified/plugins/lib/alpine.3.9-x64/libgit2-ef5a385.so new file mode 100644 index 000000000..49186df25 Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/alpine.3.9-x64/libgit2-ef5a385.so differ diff --git a/docs/_template/last-modified/plugins/lib/debian-arm64/libgit2-ef5a385.so b/docs/_template/last-modified/plugins/lib/debian-arm64/libgit2-ef5a385.so new file mode 100644 index 000000000..11ef799ab Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/debian-arm64/libgit2-ef5a385.so differ diff --git a/docs/_template/last-modified/plugins/lib/debian.9-x64/libgit2-ef5a385.so b/docs/_template/last-modified/plugins/lib/debian.9-x64/libgit2-ef5a385.so new file mode 100644 index 000000000..5cd5e46b0 Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/debian.9-x64/libgit2-ef5a385.so differ diff --git a/docs/_template/last-modified/plugins/lib/fedora-x64/libgit2-ef5a385.so b/docs/_template/last-modified/plugins/lib/fedora-x64/libgit2-ef5a385.so new file mode 100644 index 000000000..be1be9322 Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/fedora-x64/libgit2-ef5a385.so differ diff --git a/docs/_template/last-modified/plugins/lib/linux-arm/libgit2-6777db8.so b/docs/_template/last-modified/plugins/lib/linux-arm/libgit2-6777db8.so new file mode 100644 index 000000000..4324c2ad9 Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/linux-arm/libgit2-6777db8.so differ diff --git a/docs/_template/last-modified/plugins/lib/linux-arm64/libgit2-6777db8.so b/docs/_template/last-modified/plugins/lib/linux-arm64/libgit2-6777db8.so new file mode 100644 index 000000000..a72d7419d Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/linux-arm64/libgit2-6777db8.so differ diff --git a/docs/_template/last-modified/plugins/lib/linux-musl-x64/libgit2-6777db8.so b/docs/_template/last-modified/plugins/lib/linux-musl-x64/libgit2-6777db8.so new file mode 100644 index 000000000..a1f59dfb3 Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/linux-musl-x64/libgit2-6777db8.so differ diff --git a/docs/_template/last-modified/plugins/lib/linux-x64/libgit2-6777db8.so b/docs/_template/last-modified/plugins/lib/linux-x64/libgit2-6777db8.so new file mode 100644 index 000000000..b47f83e21 Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/linux-x64/libgit2-6777db8.so differ diff --git a/docs/_template/last-modified/plugins/lib/linux-x64/libgit2-ef5a385.so b/docs/_template/last-modified/plugins/lib/linux-x64/libgit2-ef5a385.so new file mode 100644 index 000000000..1ec4b01f5 Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/linux-x64/libgit2-ef5a385.so differ diff --git a/docs/_template/last-modified/plugins/lib/osx/libgit2-6777db8.dylib b/docs/_template/last-modified/plugins/lib/osx/libgit2-6777db8.dylib new file mode 100644 index 000000000..cb1e7eb8c Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/osx/libgit2-6777db8.dylib differ diff --git a/docs/_template/last-modified/plugins/lib/osx/libgit2-ef5a385.dylib b/docs/_template/last-modified/plugins/lib/osx/libgit2-ef5a385.dylib new file mode 100644 index 000000000..81f71d6ea Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/osx/libgit2-ef5a385.dylib differ diff --git a/docs/_template/last-modified/plugins/lib/rhel-x64/libgit2-ef5a385.so b/docs/_template/last-modified/plugins/lib/rhel-x64/libgit2-ef5a385.so new file mode 100644 index 000000000..3d194a97f Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/rhel-x64/libgit2-ef5a385.so differ diff --git a/docs/_template/last-modified/plugins/lib/ubuntu.16.04-arm64/libgit2-ef5a385.so b/docs/_template/last-modified/plugins/lib/ubuntu.16.04-arm64/libgit2-ef5a385.so new file mode 100644 index 000000000..a3282b0d2 Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/ubuntu.16.04-arm64/libgit2-ef5a385.so differ diff --git a/docs/_template/last-modified/plugins/lib/ubuntu.18.04-x64/libgit2-ef5a385.so b/docs/_template/last-modified/plugins/lib/ubuntu.18.04-x64/libgit2-ef5a385.so new file mode 100644 index 000000000..0360ce3e0 Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/ubuntu.18.04-x64/libgit2-ef5a385.so differ diff --git a/docs/_template/last-modified/plugins/lib/win32/x64/git2-6777db8.dll b/docs/_template/last-modified/plugins/lib/win32/x64/git2-6777db8.dll new file mode 100644 index 000000000..af7d32a6d Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/win32/x64/git2-6777db8.dll differ diff --git a/docs/_template/last-modified/plugins/lib/win32/x64/git2-ef5a385.dll b/docs/_template/last-modified/plugins/lib/win32/x64/git2-ef5a385.dll new file mode 100644 index 000000000..7ffcdf97f Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/win32/x64/git2-ef5a385.dll differ diff --git a/docs/_template/last-modified/plugins/lib/win32/x86/git2-6777db8.dll b/docs/_template/last-modified/plugins/lib/win32/x86/git2-6777db8.dll new file mode 100644 index 000000000..c680911e2 Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/win32/x86/git2-6777db8.dll differ diff --git a/docs/_template/last-modified/plugins/lib/win32/x86/git2-ef5a385.dll b/docs/_template/last-modified/plugins/lib/win32/x86/git2-ef5a385.dll new file mode 100644 index 000000000..9fe2e3e01 Binary files /dev/null and b/docs/_template/last-modified/plugins/lib/win32/x86/git2-ef5a385.dll differ diff --git a/docs/_template/light-dark-theme/partials/affix.tmpl.partial b/docs/_template/light-dark-theme/partials/affix.tmpl.partial index aafcdf05b..b3ce60b5c 100644 --- a/docs/_template/light-dark-theme/partials/affix.tmpl.partial +++ b/docs/_template/light-dark-theme/partials/affix.tmpl.partial @@ -27,7 +27,8 @@ {{/_disableContribution}} diff --git a/docs/_template/light-dark-theme/partials/head.tmpl.partial b/docs/_template/light-dark-theme/partials/head.tmpl.partial index c214e7548..8a01b48cf 100644 --- a/docs/_template/light-dark-theme/partials/head.tmpl.partial +++ b/docs/_template/light-dark-theme/partials/head.tmpl.partial @@ -10,7 +10,7 @@ - + diff --git a/docs/docfx.json b/docs/docfx.json index 759dc174f..3fac4ff0b 100644 --- a/docs/docfx.json +++ b/docs/docfx.json @@ -1,19 +1,22 @@ { - "metadata": [{ - "src": [{ - "src": "../src", - "files": [ - "**.csproj" - ] - }], - "dest": "api", - "filter": "filterConfig.yml", - "properties": { - "TargetFramework": "netstandard2.0" + "metadata": [ + { + "src": [ + { + "src": "../src", + "files": ["**.csproj"] + } + ], + "dest": "api", + "filter": "filterConfig.yml", + "properties": { + "TargetFramework": "net5.0" + } } - }], + ], "build": { - "content": [{ + "content": [ + { "files": ["api/**.yml", "api/index.md"] }, { @@ -27,19 +30,21 @@ }, { "src": "../", - "files": [ "CHANGELOG.md" ] + "files": ["CHANGELOG.md"] + } + ], + "resource": [ + { + "files": [ + "**/images/**", + "**/samples/**", + "langwordMapping.yml", + "marketing/logo/**.svg", + "marketing/logo/**.png", + "favicon.ico" + ] } ], - "resource": [{ - "files": [ - "**/images/**", - "**/samples/**", - "langwordMapping.yml", - "marketing/logo/**.svg", - "marketing/logo/**.png", - "favicon.ico" - ] - }], "dest": "_site", "template": [ "default", @@ -47,17 +52,19 @@ "_template/last-modified", "_template/description-generator" ], - "postProcessors": ["ExtractSearchIndex", "LastModifiedPostProcessor", "DescriptionPostProcessor"], + "postProcessors": [ + "ExtractSearchIndex", + "LastModifiedPostProcessor", + "DescriptionPostProcessor" + ], "overwrite": "_overwrites/**/**.md", "globalMetadata": { "_appTitle": "Discord.Net Documentation", - "_appFooter": "Discord.Net (c) 2015-2020 2.2.0", + "_appFooter": "Discord.Net (c) 2015-2021 3.1.0", "_enableSearch": true, "_appLogoPath": "marketing/logo/SVG/Logomark Purple.svg", - "_appFaviconPath": "favicon.ico" + "_appFaviconPath": "favicon.ico" }, - "xrefService": [ - "https://xref.docs.microsoft.com/query?uid={uid}" - ] + "xrefService": ["https://xref.docs.microsoft.com/query?uid={uid}"] } } diff --git a/docs/faq/basics/basic-operations.md b/docs/faq/basics/basic-operations.md index 35c71709f..d6121dbb0 100644 --- a/docs/faq/basics/basic-operations.md +++ b/docs/faq/basics/basic-operations.md @@ -13,7 +13,7 @@ language-specific tips when using this library. > [!WARNING] > Direct casting (e.g., `(Type)type`) is **the least recommended** -> way of casting, as it *can* throw an [InvalidCastException] +> way of casting, as it _can_ throw an [InvalidCastException] > when the object isn't the desired type. > > Please refer to [this post] for more details. @@ -26,7 +26,7 @@ A good and safe casting example: [!code-csharp[Casting](samples/cast.cs)] -[InvalidCastException]: https://docs.microsoft.com/en-us/dotnet/api/system.invalidcastexception +[invalidcastexception]: https://docs.microsoft.com/en-us/dotnet/api/system.invalidcastexception [this post]: https://docs.microsoft.com/en-us/dotnet/csharp/how-to/safely-cast-using-pattern-matching-is-and-as-operators ## How do I send a message? @@ -45,15 +45,15 @@ means casting is your friend. You should attempt to cast the channel as an [IMessageChannel] or any other entity that implements it to be able to message. -[SendMessageAsync]: xref:Discord.IMessageChannel.SendMessageAsync* -[GetChannel]: xref:Discord.WebSocket.DiscordSocketClient.GetChannel* +[sendmessageasync]: xref:Discord.IMessageChannel.SendMessageAsync* +[getchannel]: xref:Discord.WebSocket.DiscordSocketClient.GetChannel* ## How can I tell if a message is from X, Y, Z channel? You may check the message channel type. Visit [Glossary] to see the various types of channels. -[Glossary]: xref:FAQ.Glossary#message-channels +[glossary]: xref:FAQ.Glossary#message-channels ## How can I get the guild from a message? @@ -86,9 +86,9 @@ implement [IEmote] and are valid options. [!code-csharp[Emoji](samples/emoji-self.cs)] -*** +--- -[AddReactionAsync]: xref:Discord.IMessage.AddReactionAsync* +[addreactionasync]: xref:Discord.IMessage.AddReactionAsync* ## What is a "preemptive rate limit?" @@ -107,7 +107,7 @@ reactions. ## Can I opt-out of preemptive rate limits? -Unfortunately, not at the moment. See [#401](https://github.com/RogueException/Discord.Net/issues/401). +Unfortunately, not at the moment. See [#401](https://github.com/discord-net/Discord.Net/issues/401). [IChannel]: xref:Discord.IChannel [ICategoryChannel]: xref:Discord.ICategoryChannel @@ -120,4 +120,4 @@ Unfortunately, not at the moment. See [#401](https://github.com/RogueException/D [IUserMessage]: xref:Discord.IUserMessage [IEmote]: xref:Discord.IEmote [Emote]: xref:Discord.Emote -[Emoji]: xref:Discord.Emoji \ No newline at end of file +[Emoji]: xref:Discord.Emoji diff --git a/docs/faq/basics/client-basics.md b/docs/faq/basics/client-basics.md index 9377ac2e9..ade33c35d 100644 --- a/docs/faq/basics/client-basics.md +++ b/docs/faq/basics/client-basics.md @@ -9,6 +9,58 @@ In the following section, you will find commonly asked questions and answers about common issues that you may face when utilizing the various clients offered by the library. +## I keep having trouble with intents! + +As Discord.NET has upgraded from Discord API v6 to API v9, +`GatewayIntents` must now be specified in the socket config, as well as on the [developer portal]. + +```cs + +// Where ever you declared your websocket client. +DiscordSocketClient _client; + +... + +var config = new DiscordSocketConfig() +{ + .. // Other config options can be presented here. + GatewayIntents = GatewayIntents.All +} + +_client = new DiscordSocketClient(config); + +``` +### Common intents: + +- AllUnprivileged: This is a group of most common intents, that do NOT require any [developer portal] intents to be enabled. +This includes intents that receive messages such as: `GatewayIntents.GuildMessages, GatewayIntents.DirectMessages` +- GuildMembers: An intent disabled by default, as you need to enable it in the [developer portal]. +- GuildPresences: Also disabled by default, this intent together with `GuildMembers` are the only intents not included in `AllUnprivileged`. +- All: All intents, it is ill adviced to use this without care, as it *can* cause a memory leak from presence. +The library will give responsive warnings if you specify unnecessary intents. + + +> [!NOTE] +> All gateway intents, their Discord API counterpart and their enum value are listed +> [HERE](xref:Discord.GatewayIntents) + +### Stacking intents: + +It is common that you require several intents together. +The example below shows how this can be done. + +```cs + +GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.GuildMembers | .. + +``` + +> [!NOTE] +> Further documentation on the ` | ` operator can be found +> [HERE](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/bitwise-and-shift-operators) + +[developer portal]: https://discord.com/developers/ + ## My client keeps returning 401 upon logging in! > [!WARNING] @@ -28,9 +80,9 @@ There are few possible reasons why this may occur. mind that a token is **different** from a *client secret*. [TokenType]: xref:Discord.TokenType -[827]: https://github.com/RogueException/Discord.Net/issues/827 -[958]: https://github.com/RogueException/Discord.Net/issues/958 -[Discord API Terms of Service]: https://discordapp.com/developers/docs/legal +[827]: https://github.com/discord-net/Discord.Net/issues/827 +[958]: https://github.com/discord-net/Discord.Net/issues/958 +[Discord API Terms of Service]: https://discord.com/developers/docs/legal ## How do I do X, Y, Z when my bot connects/logs on? Why do I get a `NullReferenceException` upon calling any client methods after connect? @@ -73,7 +125,9 @@ instances, with each one serving a different amount of guilds. There are very few differences from the [DiscordSocketClient] class, and it is very straightforward to modify your existing code to use a [DiscordShardedClient] when necessary. -1. You need to specify the total amount of shards, or shard ids, via [DiscordShardedClient]'s constructors. +1. You can specify the total amount of shards, or shard ids, via [DiscordShardedClient]'s constructors. +If the total shards are not specified then the library will get the recommended shard count via the +[Get Gateway Bot](https://discord.com/developers/docs/topics/gateway#get-gateway-bot) route. 2. The [Connected], [Disconnected], [Ready], and [LatencyUpdated] events are replaced with [ShardConnected], [ShardDisconnected], [ShardReady], and [ShardLatencyUpdated]. 3. Every event handler you apply/remove to the [DiscordShardedClient] is applied/removed to each shard. diff --git a/docs/faq/basics/getting-started.md b/docs/faq/basics/getting-started.md index f38d2cea7..dc4b11548 100644 --- a/docs/faq/basics/getting-started.md +++ b/docs/faq/basics/getting-started.md @@ -74,6 +74,9 @@ it will return the user ID of the aforementioned user. Several common ways to do this: -1. Make the role mentionable and mention the role, and escape it +1. (Easiest) Right click on the role either in the Server Settings + or in the user's role list. + ![Roles](images/role-copy.png) +2. Make the role mentionable and mention the role, and escape it using the `\` character in front. -2. Inspect the roles collection within the guild via your debugger. \ No newline at end of file +3. Inspect the roles collection within the guild via your debugger. diff --git a/docs/faq/basics/images/role-copy.png b/docs/faq/basics/images/role-copy.png new file mode 100644 index 000000000..1dbc2982f Binary files /dev/null and b/docs/faq/basics/images/role-copy.png differ diff --git a/docs/faq/basics/images/scope.png b/docs/faq/basics/images/scope.png new file mode 100644 index 000000000..04d60bce2 Binary files /dev/null and b/docs/faq/basics/images/scope.png differ diff --git a/docs/faq/basics/interactions.md b/docs/faq/basics/interactions.md new file mode 100644 index 000000000..33b89ac2d --- /dev/null +++ b/docs/faq/basics/interactions.md @@ -0,0 +1,88 @@ +--- +uid: FAQ.Basics.InteractionBasics +title: Basics of interactions, common practice +--- + +# Interactions basics, where to get started + +This section answers basic questions and common mistakes in handling application commands, and responding to them. + +## What's the difference between RespondAsync, DeferAsync and FollowupAsync? + +The difference between these 3 functions is in how you handle the command response. +[RespondAsync] and +[DeferAsync] let the API know you have succesfully received the command. This is also called 'acknowledging' a command. +DeferAsync will not send out a response, RespondAsync will. +[FollowupAsync] follows up on succesful acknowledgement. + +> [!WARNING] +> If you have not acknowledged the command FollowupAsync will not work! the interaction has not been resonded to, so you cannot follow it up! + +[RespondAsync]: xref:Discord.IDiscordInteraction +[DeferAsync]: xref:Discord.IDiscordInteraction +[FollowUpAsync]: xref:Discord.IDiscordInteraction + +## Im getting System.TimeoutException: 'Cannot respond to an interaction after 3 seconds!' + +This happens because your computers clock is out of sync or your trying to respond after 3 seconds. If your clock is out of sync and you cant fix it, you can set the `UseInteractionSnowflakeDate` to false in the config. + +## Bad form Exception when I try to create my commands, why do I get this? + +Bad form exceptions are thrown if the slash, user or message command builder has invalid values. +The following options could resolve your error. + +#### Is your command name lowercase? + +If your command name is not lowercase, it is not seen as a valid command entry. +`Avatar` is invalid; `avatar` is valid. + +#### Are your values below or above the required amount? (This also applies to message components) + +Discord expects all values to be below maximum allowed. +Going over this maximum amount of characters causes an exception. + +> [!NOTE] +> All maximum and minimum value requirements can be found in the [Discord Developer Docs]. +> For components, structure documentation is found [here]. + +[Discord Developer Docs]: https://discord.com/developers/docs/interactions/application-commands#application-commands +[here]: https://discord.com/developers/docs/interactions/message-components#message-components + +#### Is your subcommand branching correct? + +Branching structure is covered properly here: xref:Guides.SlashCommands.SubCommand + +## My interaction commands are not showing up? + +If you registered your commands globally, it can take up to 1 hour for them to register. +Did you register a guild command (should be instant), or waited more than an hour and still don't have them show up? + +- Try to check for any errors in the console, there is a good chance something might have been thrown. + +- Register your commands after the Ready event in the client. The client is not configured to register commands before this moment. + +- Check if no bad form exception is thrown; If so, refer to the above question. + +- Do you have the application commands scope checked when adding your bot to guilds? + +![Scope check](images/scope.png) + +## There are many options for creating commands, which do I use? + +[!code-csharp[Register examples](samples/registerint.cs)] + +> [!NOTE] +> You can use bulkoverwrite even if there are no commands in guild, nor globally. +> The bulkoverwrite method disposes the old set of commands and replaces it with the new. + +## Do I need to create commands on startup? + +If you are registering your commands for the first time, it is required to create them once. +After this, commands will exist indefinitely until you overwrite them. +Overwriting is only required if you make changes to existing commands, or add new ones. + +## I can't see all of my user/message commands, why? + +Message and user commands have a limit of 5 per guild, and another 5 globally. +If you have more than 5 guild-only message commands being registered, no more than 5 will actually show up. +You can get up to 10 entries to show if you register 5 per guild, and another 5 globally. diff --git a/docs/faq/basics/samples/registerint.cs b/docs/faq/basics/samples/registerint.cs new file mode 100644 index 000000000..68fd2e608 --- /dev/null +++ b/docs/faq/basics/samples/registerint.cs @@ -0,0 +1,21 @@ +private async Task ReadyAsync() +{ + // pull your commands from some array, everyone has a different approach for this. + var commands = _builders.ToArray(); + + // write your list of commands globally in one go. + await _client.Rest.BulkOverwriteGlobalCommands(commands); + + // write your array of commands to one guild in one go. + // You can do a foreach (... in _client.Guilds) approach to write to all guilds. + await _client.Rest.BulkOverwriteGuildCommands(commands, /* some guild ID */); + + foreach (var c in commands) + { + // Create a global command, repeating usage for multiple commands. + await _client.Rest.CreateGlobalCommand(c); + + // Create a guild command, repeating usage for multiple commands. + await _client.Rest.CreateGuildCommand(c, guildId); + } +} diff --git a/docs/faq/commands/dependency-injection.md b/docs/faq/commands/dependency-injection.md index 0a5de3e32..d6b7f8b58 100644 --- a/docs/faq/commands/dependency-injection.md +++ b/docs/faq/commands/dependency-injection.md @@ -23,7 +23,7 @@ throughout execution. Think of it like a chest that holds whatever you throw at it that won't be affected by anything unless you want it to. Note that you should also learn Microsoft's implementation of [Dependency Injection] \([video]) before proceeding, -as well as how it works in [Discord.Net](xref:Guides.Commands.DI#usage-in-modules). +as well as how it works in [Discord.Net](xref:Guides.TextCommands.DI#usage-in-modules). A brief example of service and dependency injection can be seen below. diff --git a/docs/faq/commands/general.md b/docs/faq/commands/general.md index de6d48dc1..cff078746 100644 --- a/docs/faq/commands/general.md +++ b/docs/faq/commands/general.md @@ -1,9 +1,9 @@ --- uid: FAQ.Commands.General -title: General Questions about Commands +title: General Questions about chat Commands --- -# Command-related Questions +# Chat Command-related Questions In the following section, you will find commonly asked questions and answered regarding general command usage when using @Discord.Commands. @@ -144,4 +144,4 @@ For #4, exceptions are caught in [CommandService.Log] event under [LogMessage.Exception]: xref:Discord.LogMessage.Exception* [ExecuteResult.Exception]: xref:Discord.Commands.ExecuteResult.Exception* [CommandException]: xref:Discord.Commands.CommandException -[IResult]: xref:Discord.Commands.IResult \ No newline at end of file +[IResult]: xref:Discord.Commands.IResult diff --git a/docs/faq/commands/interaction.md b/docs/faq/commands/interaction.md new file mode 100644 index 000000000..db61bc3f5 --- /dev/null +++ b/docs/faq/commands/interaction.md @@ -0,0 +1,52 @@ +--- +uid: FAQ.Commands.Interactions +title: Interaction service +--- + +# Interaction commands in services + +A chapter talking about the interaction service framework. +For questions about interactions in general, refer to the [Interactions FAQ] + +## Module dependencies aren't getting populated by Property Injection? + +Make sure the properties are publicly accessible and publicly settable. + +## How do I use this * interaction specific method/property? + +If your interaction context holds a down-casted version of the interaction object, you need to up-cast it. +Ideally, use pattern matching to make sure its the type of interaction you are expecting it to be. + +## `InteractionService.ExecuteAsync()` always returns a successful result, how do i access the failed command execution results? + +If you are using `RunMode.Async` you need to setup your post-execution pipeline around `CommandExecuted` events. + +## How do I check if the executing user has * permission? + +Refer to the [documentation about preconditions] + +## How do I send the HTTP Response from inside the command modules. + +Set the `RestResponseCallback` property of [InteractionServiceConfig] with a delegate for handling HTTP Responses and use +`RestInteractionModuleBase` to create your command modules. `RespondAsync()` and `DeferAsync()` methods of this module base will use the +`RestResponseCallback` to create interaction responses. + +## Is there a cleaner way of creating parameter choices other than using `[Choice]`? + +The default `enum` [TypeConverter] of the Interaction Service will +automatically register `enum`s as multiple choice options. + +## How do I add an optional `enum` parameter but make the default value not visible to the user? + +The default `enum` [TypeConverter] of the Interaction Service comes with `[Hide]` attribute that +can be used to prevent certain enum values from getting registered. + +## How does the InteractionService determine the generic TypeConverter to use for a parameter type? + +It compares the _target base type_ key of the +[TypeConverter] and chooses the one that sits highest on the inheritance hierarchy. + +[TypeConverter]: xref:Discord.Interactions.TypeConverter +[Interactions FAQ]: xref: FAQ.Basics.Interactions +[InteractionServiceConfig]: xref:Discord.Interactions.InteractionServiceConfig +[documentation about preconditions]: xref: Guides.ChatCommands.Preconditions diff --git a/docs/faq/misc/glossary.md b/docs/faq/misc/glossary.md index 95bdbaa03..232690917 100644 --- a/docs/faq/misc/glossary.md +++ b/docs/faq/misc/glossary.md @@ -19,18 +19,18 @@ channels, and are often referred to as "servers". * A **Channel** ([IChannel]) represents a generic channel. - Example: #dotnet_discord-net - See [Channel Types](#channel-types) - + [IGuild]: xref:Discord.IGuild [IChannel]: xref:Discord.IChannel ## Channel Types ### Message Channels -* A **Text Channel** ([ITextChannel]) is a message channel from a -Guild. +* A **Text Channel** ([ITextChannel]) is a message channel from a Guild. +* A **Thread Channel** ([IThreadChannel]) is a thread channel from a Guild. +* A **News Channel** ([INewsChannel]) (also goes as announcement channel) is a news channel from a Guild. * A **DM Channel** ([IDMChannel]) is a message channel from a DM. -* A **Group Channel** ([IGroupChannel]) is a message channel from a -Group. +* A **Group Channel** ([IGroupChannel]) is a message channel from a Group. - This is rarely used due to the bot's inability to join groups. * A **Private Channel** ([IPrivateChannel]) is a DM or a Group. * A **Message Channel** ([IMessageChannel]) can be any of the above. @@ -39,11 +39,15 @@ Group. * A **Guild Channel** ([IGuildChannel]) is a guild channel in a guild. - This can be any channels that may exist in a guild. * A **Voice Channel** ([IVoiceChannel]) is a voice channel in a guild. +* A **Stage Channel** ([IStageChannel]) is a stage channel in a guild. * A **Category Channel** ([ICategoryChannel]) (2.0+) is a category that holds one or more sub-channels. * A **Nested Channel** ([INestedChannel]) (2.0+) is a channel that can exist under a category. +> [!NOTE] +> A Channel ([IChannel]) can be all types of channels. + [INestedChannel]: xref:Discord.INestedChannel [IGuildChannel]: xref:Discord.IGuildChannel [IMessageChannel]: xref:Discord.IMessageChannel @@ -53,6 +57,33 @@ exist under a category. [IPrivateChannel]: xref:Discord.IPrivateChannel [IVoiceChannel]: xref:Discord.IVoiceChannel [ICategoryChannel]: xref:Discord.ICategoryChannel +[IChannel]: xref:Discord.IChannel +[IThreadChannel]: xref:Discord.IThreadChannel +[IStageChannel]: xref:Discord.IStageChannel +[INewsChannel]: xref:Discord.INewsChannel + +## Message Types + +* An **User Message** ([IUserMessage]) is a message sent by a user. +* A **System Message** ([ISystemMessage]) is a message sent by Discord itself. +* A **Message** ([IMessage]) can be any of the above. + +[IUserMessage]: xref:Discord.IUserMessage +[ISystemMessage]: xref:Discord.ISystemMessage +[IMessage]: xref:Discord.IMessage + +## User Types + +* A **Guild User** ([IGuildUser]) is a user available inside a guild. +* A **Group User** ([IGroupUser]) is a user available inside a group. + - This is rarely used due to the bot's inability to join groups. +* A **Self User** ([ISelfUser]) is the bot user the client is currently logged in as. +* An **User** ([IUser]) can be any of the above. + +[IGuildUser]: xref:Discord.IGuildUser +[IGroupUser]: xref:Discord.IGroupUser +[ISelfUser]: xref:Discord.ISelfUser +[IUser]: xref:Discord.IUser ## Emoji Types @@ -64,6 +95,15 @@ exist under a category. [Emote]: xref:Discord.Emote [Emoji]: xref:Discord.Emoji + +## Sticker Types + +* A **Sticker** ([ISticker]) is a standard Discord sticker. +* A **Custom Sticker ([ICustomSticker]) is a Guild-unique sticker. + +[ISticker]: xref:Discord.ISticker +[ICustomSticker]: xref:Discord.ICustomSticker + ## Activity Types * A **Game** ([Game]) refers to a user's game activity. @@ -79,4 +119,4 @@ activity for listening to a song on Spotify. [RichGame]: xref:Discord.RichGame [StreamingGame]: xref:Discord.StreamingGame [SpotifyGame]: xref:Discord.SpotifyGame -[Rich Presence Intro]: https://discordapp.com/developers/docs/rich-presence/best-practices \ No newline at end of file +[Rich Presence Intro]: https://discord.com/developers/docs/rich-presence/best-practices diff --git a/docs/faq/misc/legacy.md b/docs/faq/misc/legacy.md index 5931579d3..ddb2d03c6 100644 --- a/docs/faq/misc/legacy.md +++ b/docs/faq/misc/legacy.md @@ -18,7 +18,7 @@ their breaking nature. Visit the repo's [release tag] to see the latest public pre-release. -[release tag]: https://github.com/RogueException/Discord.Net/releases +[release tag]: https://github.com/discord-net/Discord.Net/releases ## I came from an earlier version of Discord.Net 1.0, and DependencyMap doesn't seem to exist anymore in the later revision? What happened to it? @@ -26,4 +26,4 @@ The `DependencyMap` has been replaced with Microsoft's [DependencyInjection] Abstractions. An example usage can be seen [here](https://github.com/foxbot/DiscordBotBase/blob/csharp/src/DiscordBot/Program.cs#L36). -[DependencyInjection]: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection \ No newline at end of file +[DependencyInjection]: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection diff --git a/docs/faq/toc.yml b/docs/faq/toc.yml index 393e948f6..5a7e7e7f2 100644 --- a/docs/faq/toc.yml +++ b/docs/faq/toc.yml @@ -6,10 +6,14 @@ topicUid: FAQ.Basics.BasicOp - name: Client Basics topicUid: FAQ.Basics.ClientBasics + - name: Interactions + topicUid: FAQ.Basics.InteractionBasics - name: Commands items: - - name: General + - name: String commands topicUid: FAQ.Commands.General + - name: Interaction commands + topicUid: FAQ.Commands.Interactions - name: Dependency Injection topicUid: FAQ.Commands.DI - name: Glossary diff --git a/docs/guides/concepts/entities.md b/docs/guides/concepts/entities.md index 5ad5b01f2..e3ca7db32 100644 --- a/docs/guides/concepts/entities.md +++ b/docs/guides/concepts/entities.md @@ -31,8 +31,7 @@ But that doesn't mean a message _can't_ come from a retrieve information about a guild from a message entity, you will need to cast its channel object to a `SocketTextChannel`. -You can find out various types of entities in the @FAQ.Misc.Glossary -page. +You can find out various types of entities in the [Glossary page.](xref:FAQ.Glossary) ## Navigation @@ -63,4 +62,4 @@ a variant of the type that you need. ## Sample -[!code-csharp[Entity Sample](samples/entities.cs)] \ No newline at end of file +[!code-csharp[Entity Sample](samples/entities.cs)] diff --git a/docs/guides/concepts/ratelimits.md b/docs/guides/concepts/ratelimits.md new file mode 100644 index 000000000..afeb5f795 --- /dev/null +++ b/docs/guides/concepts/ratelimits.md @@ -0,0 +1,49 @@ +# Ratelimits + +Ratelimits are a core concept of any API - Discords API is no exception. each verified library must follow the ratelimit guidelines. + +### Using the ratelimit callback + +There is a new property within `RequestOptions` called RatelimitCallback. This callback is called when a request is made via the rest api. The callback is called with a `IRateLimitInfo` parameter: + +| Name | Type | Description | +| ---------- | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | +| IsGlobal | bool | Whether or not this ratelimit info is global. | +| Limit | int? | The number of requests that can be made. | +| Remaining | int? | The number of remaining requests that can be made. | +| RetryAfter | int? | The total time (in seconds) of when the current rate limit bucket will reset. Can have decimals to match previous millisecond ratelimit precision. | +| Reset | DateTimeOffset? | The time at which the rate limit resets. | +| ResetAfter | TimeSpan? | The absolute time when this ratelimit resets. | +| Bucket | string | A unique string denoting the rate limit being encountered (non-inclusive of major parameters in the route path). | +| Lag | TimeSpan? | The amount of lag for the request. This is used to denote the precise time of when the ratelimit expires. | +| Endpoint | string | The endpoint that this ratelimit info came from. | + +Let's set up a ratelimit callback that will print out the ratelimit info to the console. + +```cs +public async Task MyRatelimitCallback(IRateLimitInfo info) +{ + Console.WriteLine($"{info.IsGlobal} {info.Limit} {info.Remaining} {info.RetryAfter} {info.Reset} {info.ResetAfter} {info.Bucket} {info.Lag} {info.Endpoint}"); +} +``` + +Let's use this callback in a send message function + +```cs +[Command("ping")] +public async Task ping() +{ + var options = new RequestOptions() + { + RatelimitCallback = MyRatelimitCallback + }; + + await Context.Channel.SendMessageAsync("Pong!", options: options); +} +``` + +Running this produces the following output: + +``` +False 5 4 2021-09-09 3:48:14 AM +00:00 00:00:05 a06de0de4a08126315431cc0c55ee3dc 00:00:00.9891364 channels/848511736872828929/messages +``` diff --git a/docs/guides/emoji/emoji.md b/docs/guides/emoji/emoji.md index 60a84409c..dbf654bbf 100644 --- a/docs/guides/emoji/emoji.md +++ b/docs/guides/emoji/emoji.md @@ -46,14 +46,16 @@ form; this can be obtained in several different ways. ### Emoji Declaration After obtaining the Unicode representation of the emoji, you may -create the @Discord.Emoji object by passing the string into its +create the @Discord.Emoji object by passing the string with unicode into its constructor (e.g. `new Emoji("👌");` or `new Emoji("\uD83D\uDC4C");`). Your method of declaring an @Discord.Emoji should look similar to this: - [!code-csharp[Emoji Sample](samples/emoji-sample.cs)] +Also you can use `Emoji.Parse()` or `Emoji.TryParse()` methods +for parsing emojis from strings like `:heart:`, `<3` or `❤`. + [FileFormat.Info]: https://www.fileformat.info/info/emoji/list.htm ## Emote @@ -97,4 +99,4 @@ this: ## Additional Information To learn more about emote and emojis and how they could be used, -see the documentation of @Discord.IEmote. \ No newline at end of file +see the documentation of @Discord.IEmote. diff --git a/docs/guides/getting_started/first-bot.md b/docs/guides/getting_started/first-bot.md index bdae80c7f..e1af20d30 100644 --- a/docs/guides/getting_started/first-bot.md +++ b/docs/guides/getting_started/first-bot.md @@ -31,7 +31,7 @@ the Discord Applications Portal first. ![Step 7](images/intro-public-bot.png) -[Discord Applications Portal]: https://discordapp.com/developers/applications/ +[Discord Applications Portal]: https://discord.com/developers/applications/ ## Adding your bot to a server @@ -80,15 +80,11 @@ recommended for these operations to be awaited in a properly established async context whenever possible. To establish an async context, we will be creating an async main method -in your console application, and rewriting the static main method to -invoke the new async main. +in your console application. [!code-csharp[Async Context](samples/first-bot/async-context.cs)] -As a result of this, your program will now start and immediately -jump into an async context. This allows us to create a connection -to Discord later on without having to worry about setting up the -correct async implementation. +As a result of this, your program will now start into an async context. > [!WARNING] > If your application throws any exceptions within an async context, @@ -165,11 +161,11 @@ or any other blocking method, such as reading from the console. > the source code for your bot. > > In the following example, we retrieve the token from a pre-defined -> variable, which is **NOT** secure, especially if you plan on +> variable, which is **NOT** secure, especially if you plan on > distributing the application in any shape or form. > -> We recommend alternative storage such as -> [Environment Variables], an external configuration file, or a +> We recommend alternative storage such as +> [Environment Variables], an external configuration file, or a > secrets manager for safe-handling of secrets. > > [Environment Variables]: https://en.wikipedia.org/wiki/Environment_variable @@ -221,4 +217,4 @@ should be to separate... 2. the modules (handle commands) 3. the services (persistent storage, pure functions, data manipulation) -[CommandService]: xref:Discord.Commands.CommandService \ No newline at end of file +[CommandService]: xref:Discord.Commands.CommandService diff --git a/docs/guides/getting_started/images/nightlies-vs-note.png b/docs/guides/getting_started/images/nightlies-vs-note.png deleted file mode 100644 index 0dcf2dea3..000000000 Binary files a/docs/guides/getting_started/images/nightlies-vs-note.png and /dev/null differ diff --git a/docs/guides/getting_started/images/nightlies-vs-step1.png b/docs/guides/getting_started/images/nightlies-vs-step1.png deleted file mode 100644 index a399ca66c..000000000 Binary files a/docs/guides/getting_started/images/nightlies-vs-step1.png and /dev/null differ diff --git a/docs/guides/getting_started/images/nightlies-vs-step2.png b/docs/guides/getting_started/images/nightlies-vs-step2.png deleted file mode 100644 index 75cecbb8d..000000000 Binary files a/docs/guides/getting_started/images/nightlies-vs-step2.png and /dev/null differ diff --git a/docs/guides/getting_started/images/nightlies-vs-step4.png b/docs/guides/getting_started/images/nightlies-vs-step4.png deleted file mode 100644 index 6462ab994..000000000 Binary files a/docs/guides/getting_started/images/nightlies-vs-step4.png and /dev/null differ diff --git a/docs/guides/getting_started/installing.md b/docs/guides/getting_started/installing.md index 61e3bb6ec..0dde72380 100644 --- a/docs/guides/getting_started/installing.md +++ b/docs/guides/getting_started/installing.md @@ -11,9 +11,9 @@ may also compile this library yourself should you so desire. ## Supported Platforms -Discord.Net targets [.NET Standard] both 1.3 and 2.0; this also means -that creating applications using the latest version of [.NET Core] is -the most recommended. If you are bound by Windows-specific APIs or +Discord.Net targets [.NET 6.0] and [.NET 5.0], but is also available on older versions, like [.NET Standard] and [.NET Core]; this still means +that creating applications using the latest version of .NET (6.0) +is most recommended. If you are bound by Windows-specific APIs or other limitations, you may also consider targeting [.NET Framework] 4.6.1 or higher. @@ -22,10 +22,12 @@ other limitations, you may also consider targeting [.NET Framework] > notice. It is known to have issues with the library's WebSockets > implementation and may crash the application upon startup. -[Mono]: https://www.mono-project.com/ -[.NET Standard]: https://docs.microsoft.com/en-us/dotnet/articles/standard/library -[.NET Core]: https://docs.microsoft.com/en-us/dotnet/articles/core/ -[.NET Framework]: https://docs.microsoft.com/en-us/dotnet/framework/get-started/ +[mono]: https://www.mono-project.com/ +[.net 6.0]: https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-6 +[.net 5.0]: https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-5 +[.net standard]: https://docs.microsoft.com/en-us/dotnet/articles/standard/library +[.net core]: https://docs.microsoft.com/en-us/dotnet/articles/core/ +[.net framework]: https://docs.microsoft.com/en-us/dotnet/framework/get-started/ [additional steps]: #installing-on-net-standard-11 ## Installing with NuGet @@ -37,37 +39,37 @@ Development builds of Discord.Net, as well as add-ons, will be published to our [MyGet feed]. See @Guides.GettingStarted.Installation.Nightlies to learn more. -[official NuGet feed]: https://nuget.org -[MyGet feed]: https://www.myget.org/feed/Packages/discord-net +[official nuget feed]: https://nuget.org +[myget feed]: https://www.myget.org/feed/Packages/discord-net ### [Using Visual Studio](#tab/vs-install) 1. Create a new solution for your bot 2. In the Solution Explorer, find the "Dependencies" element under your - bot's project + bot's project 3. Right click on "Dependencies", and select "Manage NuGet packages" - ![Step 3](images/install-vs-deps.png) + ![Step 3](images/install-vs-deps.png) 4. In the "Browse" tab, search for `Discord.Net` 5. Install the `Discord.Net` package - ![Step 5](images/install-vs-nuget.png) + ![Step 5](images/install-vs-nuget.png) ### [Using JetBrains Rider](#tab/rider-install) 1. Create a new solution for your bot 2. Open the NuGet window (Tools > NuGet > Manage NuGet packages for Solution) - ![Step 2](images/install-rider-nuget-manager.png) + ![Step 2](images/install-rider-nuget-manager.png) 3. In the "Packages" tab, search for `Discord.Net` - ![Step 3](images/install-rider-search.png) + ![Step 3](images/install-rider-search.png) 4. Install by adding the package to your project - ![Step 4](images/install-rider-add.png) + ![Step 4](images/install-rider-add.png) ### [Using Visual Studio Code](#tab/vs-code) @@ -82,7 +84,7 @@ published to our [MyGet feed]. See 2. Navigate to where your `*.csproj` is located 3. Enter `dotnet add package Discord.Net` -*** +--- ## Compiling from Source @@ -90,15 +92,15 @@ In order to compile Discord.Net, you will need the following: ### Using Visual Studio -* [Visual Studio 2019](https://visualstudio.microsoft.com/) -* [.NET Core SDK] +- [Visual Studio 2019](https://visualstudio.microsoft.com/) or later. +- [.NET 5 SDK] -The .NET Core and Docker workload is required during Visual Studio +The .NET 5 workload is required during Visual Studio installation. ### Using Command Line -* [.NET Core SDK] +* [.NET 5 SDK] ## Additional Information @@ -117,28 +119,28 @@ by installing one or more custom packages as listed below. 1. Download the latest [.NET Core SDK]. 2. Create or move your existing project to use .NET Core. 3. Modify your `` tag to at least `netcoreapp2.1`, or - by adding the `--framework netcoreapp2.1` switch when building. + by adding the `--framework netcoreapp2.1` switch when building. #### [Custom Packages](#tab/custom-pkg) -1. Install or compile the following packages: +1. Install or compile the following packages: - * `Discord.Net.Providers.WS4Net` - * `Discord.Net.Providers.UDPClient` (Optional) - * This is _only_ required if your bot will be utilizing voice chat. + - `Discord.Net.Providers.WS4Net` + - `Discord.Net.Providers.UDPClient` (Optional) + - This is _only_ required if your bot will be utilizing voice chat. -2. Configure your [DiscordSocketClient] to use these custom providers -over the default ones. +2. Configure your [DiscordSocketClient] to use these custom providers + over the default ones. - * To do this, set the `WebSocketProvider` and the optional - `UdpSocketProvider` properties on the [DiscordSocketConfig] that you - are passing into your client. + * To do this, set the `WebSocketProvider` and the optional + `UdpSocketProvider` properties on the [DiscordSocketConfig] that you + are passing into your client. [!code-csharp[Example](samples/netstd11.cs)] -[DiscordSocketClient]: xref:Discord.WebSocket.DiscordSocketClient -[DiscordSocketConfig]: xref:Discord.WebSocket.DiscordSocketConfig +[discordsocketclient]: xref:Discord.WebSocket.DiscordSocketClient +[discordsocketconfig]: xref:Discord.WebSocket.DiscordSocketConfig -*** +--- -[.NET Core SDK]: https://dotnet.microsoft.com/download \ No newline at end of file +[.NET 5 SDK]: https://dotnet.microsoft.com/download diff --git a/docs/guides/getting_started/labs.md b/docs/guides/getting_started/labs.md new file mode 100644 index 000000000..e52014312 --- /dev/null +++ b/docs/guides/getting_started/labs.md @@ -0,0 +1,30 @@ +--- +uid: Guides.GettingStarted.Installation.Labs +title: Installing Labs builds +--- + +# Installing Discord.NET Labs + +Discord.NET Labs is the experimental repository that introduces new features & chips away at all bugs until ready for merging into Discord.NET. +Are you looking to test or play with new features? + +> [!IMPORTANT] +> It is very ill advised to use Discord.NET Labs in a production environment normally, +> considering it can include bugs that have not been discovered yet, as features are freshly added. +> However if approached correctly, will work as a pre-release to Discord.NET. +> Make sure to report any bugs at the Labs [repository] or on [Discord] + +[Discord]: https://discord.gg/dnet +[repository]: https://github.com/Discord-Net-Labs/Discord.Net-Labs + +## Installation: + +[NuGet] - This only includes releases, on which features are ready to test. + +> [!NOTE] +> Installing NuGet packages is covered fully at [Installing Discord NET](xref:Guides.GettingStarted.Installation) + +[MyGet] - Available for current builds and unreleased features. + +[NuGet]: https://www.nuget.org/packages/Discord.Net.Labs/ +[MyGet]: https://www.myget.org/feed/Packages/discord-net-labs diff --git a/docs/guides/getting_started/nightlies.md b/docs/guides/getting_started/nightlies.md deleted file mode 100644 index 2b9fde87b..000000000 --- a/docs/guides/getting_started/nightlies.md +++ /dev/null @@ -1,97 +0,0 @@ ---- -uid: Guides.GettingStarted.Installation.Nightlies -title: Installing Nightly Build ---- - -# Installing Discord.Net Nightly Build - -Before Discord.Net pushes a new set of features into the stable -version, we use nightly builds to test the features with the -community for an extensive period of time. Each nightly build is -compiled by AppVeyor whenever a new commit is made and will be pushed -to our MyGet feed. - -> [!IMPORTANT] -> Although nightlies are generally stable and have more features -> and bug fixes than the current stable build on NuGet, there -> will be breaking changes during the development or -> breaking bugs; these bugs are usually fixed as soon as they -> are discovered, but you should still be aware of that. - -## Installing with MyGet (Recommended) - -MyGet is typically used by many development teams to publish their -latest pre-release packages before the features are finalized and -pushed to NuGet. - -The following is the feed link of Discord.Net, - -* `https://www.myget.org/F/discord-net/api/v3/index.json` - -Depending on which IDE you use, there are many different ways of -adding the feed to your package source. - -### [Using Visual Studio](#tab/vs) - -1. Go to `Tools` > `NuGet Package Manager` > `Package Manager Settings` - - ![VS](images/nightlies-vs-step1.png) - -2. Go to `Package Sources` - - ![Package Sources](images/nightlies-vs-step2.png) - -3. Click on the add icon -4. Fill in the desired name and source as shown below and hit `Update` - - ![Add Source](images/nightlies-vs-step4.png) - -> [!NOTE] -> Remember to tick the `Include pre-release` checkbox to see the -> nightly builds! -> ![Checkbox](images/nightlies-vs-note.png) - -### [Using dotnet CLI](#tab/cli) - -1. Launch a terminal of your choice -2. Navigate to where your `*.csproj` is located -3. Type `dotnet add package Discord.Net --source https://www.myget.org/F/discord-net/api/v3/index.json` - -### [Using Local NuGet.Config](#tab/local-nuget-config) - -If you plan on deploying your bot or developing outside of Visual -Studio, you will need to create a local NuGet configuration file for -your project. - -To do this, create a file named `NuGet.Config` alongside the root of -your application, where the project is located. - -Paste the following snippets into this configuration file, adding any -additional feeds if necessary. - -[!code[NuGet Configuration](samples/nuget.config)] - -After which, you may install the packages by directly modifying the -project file and specifying a version, or by using -the [Package Manager Console](https://docs.microsoft.com/en-us/nuget/tools/powershell-reference) -(`Install-Package Discord.Net -IncludePrerelease`). - -*** - -## Installing from AppVeyor Artifacts - -As mentioned in the first paragraph, we utilize AppVeyor to perform -automated tests and publish the new build. During the publishing -process, we also upload the NuGet packages onto -AppVeyor's Artifact collection. - -The latest build status can be found within our [AppVeyor project]. - -[AppVeyor project]: https://ci.appveyor.com/project/rogueexception/discord-net - -1. In the project, you may find our latest build including the - aforementioned artifacts. - ![Artifacts](images/appveyor-artifacts.png) -2. In the artifacts collection, you should see the latest packages - packed in `*.nupkg` form which you could download from and use. - ![NuPkgs](images/appveyor-nupkg.png) diff --git a/docs/guides/getting_started/samples/first-bot/async-context.cs b/docs/guides/getting_started/samples/first-bot/async-context.cs index 3c98c9e46..98a3cea15 100644 --- a/docs/guides/getting_started/samples/first-bot/async-context.cs +++ b/docs/guides/getting_started/samples/first-bot/async-context.cs @@ -1,7 +1,6 @@ public class Program { - public static void Main(string[] args) - => new Program().MainAsync().GetAwaiter().GetResult(); + public static Task Main(string[] args) => new Program().MainAsync(); public async Task MainAsync() { diff --git a/docs/guides/getting_started/samples/first-bot/complete.cs b/docs/guides/getting_started/samples/first-bot/complete.cs index 871641e23..542056435 100644 --- a/docs/guides/getting_started/samples/first-bot/complete.cs +++ b/docs/guides/getting_started/samples/first-bot/complete.cs @@ -2,8 +2,7 @@ public class Program { private DiscordSocketClient _client; - public static void Main(string[] args) - => new Program().MainAsync().GetAwaiter().GetResult(); + public static Task Main(string[] args) => new Program().MainAsync(); public async Task MainAsync() { diff --git a/docs/guides/getting_started/samples/first-bot/structure.cs b/docs/guides/getting_started/samples/first-bot/structure.cs index 5165e2fdb..4e64b1732 100644 --- a/docs/guides/getting_started/samples/first-bot/structure.cs +++ b/docs/guides/getting_started/samples/first-bot/structure.cs @@ -10,11 +10,11 @@ using Discord.WebSocket; class Program { // Program entry point - static void Main(string[] args) + static Task Main(string[] args) { // Call the Program constructor, followed by the // MainAsync method and wait until it finishes (which should be never). - new Program().MainAsync().GetAwaiter().GetResult(); + return new Program().MainAsync(); } private readonly DiscordSocketClient _client; diff --git a/docs/guides/guild_events/creating-guild-events.md b/docs/guides/guild_events/creating-guild-events.md new file mode 100644 index 000000000..64ac0de9b --- /dev/null +++ b/docs/guides/guild_events/creating-guild-events.md @@ -0,0 +1,31 @@ +--- +uid: Guides.GuildEvents.Creating +title: Creating Guild Events +--- + +# Creating guild events + +You can create new guild events by using the `CreateEventAsync` function on a guild. + +### Parameters + +| Name | Type | Summary | +| ------------- | --------------------------------- | ---------------------------------------------------------------------------- | +| name | `string` | Sets the name of the event. | +| startTime | `DateTimeOffset` | Sets the start time of the event. | +| type | `GuildScheduledEventType` | Sets the type of the event. | +| privacyLevel? | `GuildScheduledEventPrivacyLevel` | Sets the privacy level of the event | +| description? | `string` | Sets the description of the event. | +| endTime? | `DateTimeOffset?` | Sets the end time of the event. | +| channelId? | `ulong?` | Sets the channel id of the event, only valid on stage or voice channel types | +| location? | `string` | Sets the location of the event, only valid on external types | + +Lets create a basic test event. + +```cs +var guild = client.GetGuild(guildId); + +var guildEvent = await guild.CreateEventAsync("test event", DateTimeOffset.UtcNow.AddDays(1), GuildScheduledEventType.External, endTime: DateTimeOffset.UtcNow.AddDays(2), location: "Space"); +``` + +This code will create an event that lasts a day and starts tomorrow. It will be an external event thats in space. diff --git a/docs/guides/guild_events/getting-event-users.md b/docs/guides/guild_events/getting-event-users.md new file mode 100644 index 000000000..f4b5388a0 --- /dev/null +++ b/docs/guides/guild_events/getting-event-users.md @@ -0,0 +1,16 @@ +--- +uid: Guides.GuildEvents.GettingUsers +title: Getting Guild Event Users +--- + +# Getting Event Users + +You can get a collection of users who are currently interested in the event by calling `GetUsersAsync`. This method works like any other get users method as in it returns an async enumerable. This method also supports pagination by user id. + +```cs +// get all users and flatten the result into one collection. +var users = await event.GetUsersAsync().FlattenAsync(); + +// get users around the 613425648685547541 id. +var aroundUsers = await event.GetUsersAsync(613425648685547541, Direction.Around).FlattenAsync(); +``` diff --git a/docs/guides/guild_events/intro.md b/docs/guides/guild_events/intro.md new file mode 100644 index 000000000..b60a8c70d --- /dev/null +++ b/docs/guides/guild_events/intro.md @@ -0,0 +1,41 @@ +--- +uid: Guides.GuildEvents.Intro +title: Introduction to Guild Events +--- + +# Guild Events + +Guild events are a way to host events within a guild. They offer alot of features and flexibility. + +## Getting started with guild events + +You can access any events within a guild by calling `GetEventsAsync` on a guild. + +```cs +var guildEvents = await guild.GetEventsAsync(); +``` + +If your working with socket guilds you can just use the `Events` property: + +```cs +var guildEvents = guild.Events; +``` + +There are also new gateway events that you can hook to receive guild scheduled events on. + +```cs +// Fired when a guild event is cancelled. +client.GuildScheduledEventCancelled += ... + +// Fired when a guild event is completed. +client.GuildScheduledEventCompleted += ... + +// Fired when a guild event is started. +client.GuildScheduledEventStarted += ... + +// Fired when a guild event is created. +client.GuildScheduledEventCreated += ... + +// Fired when a guild event is updated. +client.GuildScheduledEventUpdated += ... +``` diff --git a/docs/guides/guild_events/modifying-events.md b/docs/guides/guild_events/modifying-events.md new file mode 100644 index 000000000..05e14ec98 --- /dev/null +++ b/docs/guides/guild_events/modifying-events.md @@ -0,0 +1,23 @@ +--- +uid: Guides.GuildEvents.Modifying +title: Modifying Guild Events +--- + +# Modifying Events + +You can modify events using the `ModifyAsync` method to modify the event, heres the properties you can modify: + +| Name | Type | Description | +| ------------ | --------------------------------- | -------------------------------------------- | +| ChannelId | `ulong?` | Gets or sets the channel id of the event. | +| string | `string` | Gets or sets the location of this event. | +| Name | `string` | Gets or sets the name of the event. | +| PrivacyLevel | `GuildScheduledEventPrivacyLevel` | Gets or sets the privacy level of the event. | +| StartTime | `DateTimeOffset` | Gets or sets the start time of the event. | +| EndTime | `DateTimeOffset` | Gets or sets the end time of the event. | +| Description | `string` | Gets or sets the description of the event. | +| Type | `GuildScheduledEventType` | Gets or sets the type of the event. | +| Status | `GuildScheduledEventStatus` | Gets or sets the status of the event. | + +> [!NOTE] +> All of these properties are optional. diff --git a/docs/guides/int_basics/application-commands/context-menu-commands/creating-context-menu-commands.md b/docs/guides/int_basics/application-commands/context-menu-commands/creating-context-menu-commands.md new file mode 100644 index 000000000..4e6210ba8 --- /dev/null +++ b/docs/guides/int_basics/application-commands/context-menu-commands/creating-context-menu-commands.md @@ -0,0 +1,110 @@ +--- +uid: Guides.ContextCommands.Creating +title: Creating Context Commands +--- + +# Creating context menu commands. + +There are two kinds of Context Menu Commands: User Commands and Message Commands. +Each of these have a Global and Guild variant. +Global menu commands are available for every guild that adds your app. An individual app's global commands are also available in DMs if that app has a bot that shares a mutual guild with the user. + +Guild commands are specific to the guild you specify when making them. Guild commands are not available in DMs. Command names are unique per application within each scope (global and guild). That means: + +- Your app cannot have two global commands with the same name +- Your app cannot have two guild commands within the same name on the same guild +- Your app can have a global and guild command with the same name +- Multiple apps can have commands with the same names + +[!IMPORTANT] +> Apps can have a maximum of 5 global context menu commands, +> and an additional 5 guild-specific context menu commands per guild. + +## UserCommandBuilder + +The context menu user command builder will help you create user commands. The builder has these available fields and methods: + +| Name | Type | Description | +| -------- | -------- | ------------------------------------------------------------------------------------------------ | +| Name | string | The name of this context menu command. | +| WithName | Function | Sets the field name. | +| Build | Function | Builds the builder into the appropriate `UserCommandProperties` class used to make Menu commands | + +## MessageCommandBuilder + +The context menu message command builder will help you create message commands. The builder has these available fields and methods: + +| Name | Type | Description | +| -------- | -------- | --------------------------------------------------------------------------------------------------- | +| Name | string | The name of this context menu command. | +| WithName | Function | Sets the field name. | +| Build | Function | Builds the builder into the appropriate `MessageCommandProperties` class used to make Menu commands | + +> [!NOTE] +> Context Menu command names can be upper and lowercase, and use spaces. +> They cannot be registered pre-ready. + +Let's use the user command builder to make a global and guild command. + +```cs +// Let's hook the ready event for creating our commands in. +client.Ready += Client_Ready; + +... + +public async Task Client_Ready() +{ + // Let's build a guild command! We're going to need a guild so lets just put that in a variable. + var guild = client.GetGuild(guildId); + + // Next, lets create our user and message command builder. This is like the embed builder but for context menu commands. + var guildUserCommand = new UserCommandBuilder(); + var guildMessageCommand = new MessageCommandBuilder(); + + // Note: Names have to be all lowercase and match the regular expression ^[\w -]{3,32}$ + guildUserCommand.WithName("Guild User Command"); + guildMessageCommand.WithName("Guild Message Command"); + + // Descriptions are not used with User and Message commands + //guildCommand.WithDescription(""); + + // Let's do our global commands + var globalUserCommand = new UserCommandBuilder(); + globalCommand.WithName("Global User Command"); + var globalMessageCommand = new MessageCommandBuilder(); + globalMessageCommand.WithName("Global Message Command"); + + + try + { + // Now that we have our builder, we can call the BulkOverwriteApplicationCommandAsync to make our context commands. Note: this will overwrite all your previous commands with this array. + await guild.BulkOverwriteApplicationCommandAsync(new ApplicationCommandProperties[] + { + guildUserCommand.Build(), + guildMessageCommand.Build() + }); + + // With global commands we dont need the guild. + await client.BulkOverwriteGlobalApplicationCommandsAsync(new ApplicationCommandProperties[] + { + globalUserCommand.Build(), + globalMessageCommand.Build() + }) + } + catch(ApplicationCommandException exception) + { + // If our command was invalid, we should catch an ApplicationCommandException. This exception contains the path of the error as well as the error message. You can serialize the Error field in the exception to get a visual of where your error is. + var json = JsonConvert.SerializeObject(exception.Error, Formatting.Indented); + + // You can send this error somewhere or just print it to the console, for this example we're just going to print it. + Console.WriteLine(json); + } +} + +``` + +> [!NOTE] +> Application commands only need to be created once. They do _not_ have to be +> 'created' on every startup or connection. +> The example simple shows creating them in the ready event +> as it's simpler than creating normal bot commands to register application commands. diff --git a/docs/guides/int_basics/application-commands/context-menu-commands/receiving-context-menu-command-events.md b/docs/guides/int_basics/application-commands/context-menu-commands/receiving-context-menu-command-events.md new file mode 100644 index 000000000..d4e973d04 --- /dev/null +++ b/docs/guides/int_basics/application-commands/context-menu-commands/receiving-context-menu-command-events.md @@ -0,0 +1,33 @@ +--- +uid: Guides.ContextCommands.Reveiving +title: Receiving Context Commands +--- + +# Receiving Context Menu events + +User commands and Message commands have their own unique event just like the other interaction types. For user commands the event is `UserCommandExecuted` and for message commands the event is `MessageCommandExecuted`. + +```cs +// For message commands +client.MessageCommandExecuted += MessageCommandHandler; + +// For user commands +client.UserCommandExecuted += UserCommandHandler; + +... + +public async Task MessageCommandHandler(SocketMessageCommand arg) +{ + Console.Writeline("Message command received!"); +} + +public async Task UserCommandHandler(SocketUserCommand arg) +{ + Console.Writeline("User command received!"); +} +``` + +User commands contain a SocketUser object called `Member` in their data class, showing the user that was clicked to run the command. +Message commands contain a SocketMessage object called `Message` in their data class, showing the message that was clicked to run the command. + +Both return the user who ran the command, the guild (if any), channel, etc. \ No newline at end of file diff --git a/docs/guides/int_basics/application-commands/intro.md b/docs/guides/int_basics/application-commands/intro.md new file mode 100644 index 000000000..f55d0a2fc --- /dev/null +++ b/docs/guides/int_basics/application-commands/intro.md @@ -0,0 +1,51 @@ +--- +uid: Guides.SlashCommands.Intro +title: Introduction to slash commands +--- + + +# Getting started with application commands. + +This guide will show you how to use application commands. +If you have extra questions that aren't covered here you can come to our +[Discord](https://discord.com/invite/dvSfUTet3K) server and ask around there. + +## What is an application command? + +Application commands consist of three different types. Slash commands, context menu User commands and context menu Message commands. +Slash commands are made up of a name, description, and a block of options, which you can think of like arguments to a function. +The name and description help users find your command among many others, and the options validate user input as they fill out your command. +Message and User commands are only a name, to the user. So try to make the name descriptive. +They're accessed by right clicking (or long press, on mobile) a user or a message, respectively. + +> [!IMPORTANT] +> Context menu commands are currently not supported on mobile. + +All three varieties of application commands have both Global and Guild variants. +Your global commands are available in every guild that adds your application. +You can also make commands for a specific guild; they're only available in that guild. +The User and Message commands are more limited in quantity than the slash commands. +For specifics, check out their respective guide pages. + +An Interaction is the message that your application receives when a user uses a command. +It includes the values that the user submitted, as well as some metadata about this particular instance of the command being used: +the guild_id, +channel_id, +member and other fields. +You can find all the values in our data models. + +## Authorizing your bot for application commands + +There is a new special OAuth2 scope for applications called `applications.commands`. +In order to make Application Commands work within a guild, the guild must authorize your application +with the `applications.commands` scope. The bot scope is not enough. + +Head over to your discord applications OAuth2 screen and make sure to select the `application.commands` scope. + +![OAuth2 scoping](slash-commands/images/oauth.png) + +From there you can then use the link to add your bot to a server. + +> [!NOTE] +> In order for users in your guild to use your slash commands, they need to have +> the "Use Application Commands" permission on the guild. diff --git a/docs/guides/int_basics/application-commands/slash-commands/bulk-overwrite-of-global-slash-commands.md b/docs/guides/int_basics/application-commands/slash-commands/bulk-overwrite-of-global-slash-commands.md new file mode 100644 index 000000000..6a64b9c68 --- /dev/null +++ b/docs/guides/int_basics/application-commands/slash-commands/bulk-overwrite-of-global-slash-commands.md @@ -0,0 +1,41 @@ +--- +uid: Guides.SlashCommands.BulkOverwrite +title: Slash Command Bulk Overwrites +--- + +If you have too many global commands then you might want to consider using the bulk overwrite function. + +```cs +public async Task Client_Ready() +{ + List applicationCommandProperties = new(); + try + { + // Simple help slash command. + SlashCommandBuilder globalCommandHelp = new SlashCommandBuilder(); + globalCommandHelp.WithName("help"); + globalCommandHelp.WithDescription("Shows information about the bot."); + applicationCommandProperties.Add(globalCommandHelp.Build()); + + // Slash command with name as its parameter. + SlashCommandOptionBuilder slashCommandOptionBuilder = new(); + slashCommandOptionBuilder.WithName("name"); + slashCommandOptionBuilder.WithType(ApplicationCommandOptionType.String); + slashCommandOptionBuilder.WithDescription("Add a family"); + slashCommandOptionBuilder.WithRequired(true); // Only add this if you want it to be required + + SlashCommandBuilder globalCommandAddFamily = new SlashCommandBuilder(); + globalCommandAddFamily.WithName("add-family"); + globalCommandAddFamily.WithDescription("Add a family"); + globalCommandAddFamily.AddOptions(slashCommandOptionBuilder); + applicationCommandProperties.Add(globalCommandAddFamily.Build()); + + await _client.BulkOverwriteGlobalApplicationCommandsAsync(applicationCommandProperties.ToArray()); + } + catch (ApplicationCommandException exception) + { + var json = JsonConvert.SerializeObject(exception.Error, Formatting.Indented); + Console.WriteLine(json); + } +} +``` diff --git a/docs/guides/int_basics/application-commands/slash-commands/choice-slash-command.md b/docs/guides/int_basics/application-commands/slash-commands/choice-slash-command.md new file mode 100644 index 000000000..3951e1141 --- /dev/null +++ b/docs/guides/int_basics/application-commands/slash-commands/choice-slash-command.md @@ -0,0 +1,85 @@ +--- +uid: Guides.SlashCommands.Choices +title: Slash Command Choices +--- + +# Slash Command Choices. + +With slash command options you can add choices, making the user select between some set values. Lets create a command that asks how much they like our bot! + +Let's set up our slash command: + +```cs +private async Task Client_Ready() +{ + ulong guildId = 848176216011046962; + + var guildCommand = new SlashCommandBuilder() + .WithName("feedback") + .WithDescription("Tell us how much you are enjoying this bot!") + .AddOption(new SlashCommandOptionBuilder() + .WithName("rating") + .WithDescription("The rating your willing to give our bot") + .WithRequired(true) + .AddChoice("Terrible", 1) + .AddChoice("Meh", 2) + .AddChoice("Good", 3) + .AddChoice("Lovely", 4) + .AddChoice("Excellent!", 5) + .WithType(ApplicationCommandOptionType.Integer) + ).Build(); + + try + { + await client.Rest.CreateGuildCommand(guildCommand.Build(), guildId); + } + catch(ApplicationCommandException exception) + { + var json = JsonConvert.SerializeObject(exception.Error, Formatting.Indented); + Console.WriteLine(json); + } +} +``` +> [!NOTE] +> Your `ApplicationCommandOptionType` specifies which type your choices are, you need to use `ApplicationCommandOptionType.Integer` for choices whos values are whole numbers, `ApplicationCommandOptionType.Number` for choices whos values are doubles, and `ApplicationCommandOptionType.String` for string values. + +We have defined 5 choices for the user to pick from, each choice has a value assigned to it. The value can either be a string or an int. In our case we're going to use an int. This is what the command looks like: + +![feedback style](images/feedback1.png) + +Lets add our code for handling the interaction. + +```cs +private async Task SlashCommandHandler(SocketSlashCommand command) +{ + // Let's add a switch statement for the command name so we can handle multiple commands in one event. + switch(command.Data.Name) + { + case "list-roles": + await HandleListRoleCommand(command); + break; + case "settings": + await HandleSettingsCommand(command); + break; + case "feedback": + await HandleFeedbackCommand(command); + break; + } +} + +private async Task HandleFeedbackCommand(SocketSlashCommand command) +{ + var embedBuilder = new EmbedBuilder() + .WithAuthor(command.User) + .WithTitle("Feedback") + .WithDescription($"Thanks for your feedback! You rated us {command.Data.Options.First().Value}/5") + .WithColor(Color.Green) + .WithCurrentTimestamp(); + + await command.RespondAsync(embed: embedBuilder.Build()); +} +``` + +And this is the result: + +![feedback working](images/feedback2.png) diff --git a/docs/guides/int_basics/application-commands/slash-commands/creating-slash-commands.md b/docs/guides/int_basics/application-commands/slash-commands/creating-slash-commands.md new file mode 100644 index 000000000..9e35de285 --- /dev/null +++ b/docs/guides/int_basics/application-commands/slash-commands/creating-slash-commands.md @@ -0,0 +1,98 @@ +--- +uid: Guides.SlashCommands.Creating +title: Creating Slash Commands +--- + +# Creating your first slash commands. + +There are two kinds of Slash Commands: global commands and guild commands. +Global commands are available for every guild that adds your app. An individual app's global commands are also available in DMs if that app has a bot that shares a mutual guild with the user. + +Guild commands are specific to the guild you specify when making them. Guild commands are not available in DMs. Command names are unique per application within each scope (global and guild). That means: + +- Your app cannot have two global commands with the same name +- Your app cannot have two guild commands within the same name on the same guild +- Your app can have a global and guild command with the same name +- Multiple apps can have commands with the same names + +**Note**: Apps can have a maximum of 100 global commands, and an additional 100 guild-specific commands per guild. + +**Note**: Global commands will take up to 1 hour to create, delete or modify on guilds. If you need to update a command quickly for testing you can create it as a guild command. + +If you don't have the code for a bot ready yet please follow [this guide](https://docs.stillu.cc/guides/getting_started/first-bot.html). + +## SlashCommandBuilder + +The slash command builder will help you create slash commands. The builder has these available fields and methods: + +| Name | Type | Description | +| --------------------- | -------------------------------- | -------------------------------------------------------------------------------------------- | +| MaxNameLength | const int | The maximum length of a name for a slash command allowed by Discord. | +| MaxDescriptionLength | const int | The maximum length of a commands description allowed by Discord. | +| MaxOptionsCount | const int | The maximum count of command options allowed by Discord | +| Name | string | The name of this slash command. | +| Description | string | A 1-100 length description of this slash command | +| Options | List\ | The options for this command. | +| DefaultPermission | bool | Whether the command is enabled by default when the app is added to a guild. | +| WithName | Function | Sets the field name. | +| WithDescription | Function | Sets the description of the current command. | +| WithDefaultPermission | Function | Sets the default permission of the current command. | +| AddOption | Function | Adds an option to the current slash command. | +| Build | Function | Builds the builder into a `SlashCommandCreationProperties` class used to make slash commands | + +> [!NOTE] +> Slash command names must be all lowercase! + +## Creating a Slash Command + +Let's use the slash command builder to make a global and guild command. + +```cs +// Let's hook the ready event for creating our commands in. +client.Ready += Client_Ready; + +... + +public async Task Client_Ready() +{ + // Let's build a guild command! We're going to need a guild so lets just put that in a variable. + var guild = client.GetGuild(guildId); + + // Next, lets create our slash command builder. This is like the embed builder but for slash commands. + var guildCommand = new SlashCommandBuilder(); + + // Note: Names have to be all lowercase and match the regular expression ^[\w-]{3,32}$ + guildCommand.WithName("first-command"); + + // Descriptions can have a max length of 100. + guildCommand.WithDescription("This is my first guild slash command!"); + + // Let's do our global command + var globalCommand = new SlashCommandBuilder(); + globalCommand.WithName("first-global-command"); + globalCommand.WithDescription("This is my frist global slash command"); + + try + { + // Now that we have our builder, we can call the CreateApplicationCommandAsync method to make our slash command. + await guild.CreateApplicationCommandAsync(guildCommand.Build()); + + // With global commands we dont need the guild. + await client.CreateGlobalApplicationCommandAsync(globalCommand.Build()); + // Using the ready event is a simple implementation for the sake of the example. Suitable for testing and development. + // For a production bot, it is recommended to only run the CreateGlobalApplicationCommandAsync() once for each command. + } + catch(ApplicationCommandException exception) + { + // If our command was invalid, we should catch an ApplicationCommandException. This exception contains the path of the error as well as the error message. You can serialize the Error field in the exception to get a visual of where your error is. + var json = JsonConvert.SerializeObject(exception.Error, Formatting.Indented); + + // You can send this error somewhere or just print it to the console, for this example we're just going to print it. + Console.WriteLine(json); + } +} + +``` + +> [!NOTE] +> Slash commands only need to be created once. They do _not_ have to be 'created' on every startup or connection. The example simple shows creating them in the ready event as it's simpler than creating normal bot commands to register slash commands. The global commands take up to an hour to register every time the CreateGlobalApplicationCommandAsync() is called for a given command. diff --git a/docs/guides/int_basics/application-commands/slash-commands/images/ephemeral1.png b/docs/guides/int_basics/application-commands/slash-commands/images/ephemeral1.png new file mode 100644 index 000000000..61eab94b6 Binary files /dev/null and b/docs/guides/int_basics/application-commands/slash-commands/images/ephemeral1.png differ diff --git a/docs/guides/int_basics/application-commands/slash-commands/images/feedback1.png b/docs/guides/int_basics/application-commands/slash-commands/images/feedback1.png new file mode 100644 index 000000000..08e5b8c21 Binary files /dev/null and b/docs/guides/int_basics/application-commands/slash-commands/images/feedback1.png differ diff --git a/docs/guides/int_basics/application-commands/slash-commands/images/feedback2.png b/docs/guides/int_basics/application-commands/slash-commands/images/feedback2.png new file mode 100644 index 000000000..3e75c87db Binary files /dev/null and b/docs/guides/int_basics/application-commands/slash-commands/images/feedback2.png differ diff --git a/docs/guides/int_basics/application-commands/slash-commands/images/listroles1.png b/docs/guides/int_basics/application-commands/slash-commands/images/listroles1.png new file mode 100644 index 000000000..43015e203 Binary files /dev/null and b/docs/guides/int_basics/application-commands/slash-commands/images/listroles1.png differ diff --git a/docs/guides/int_basics/application-commands/slash-commands/images/listroles2.png b/docs/guides/int_basics/application-commands/slash-commands/images/listroles2.png new file mode 100644 index 000000000..d0b954380 Binary files /dev/null and b/docs/guides/int_basics/application-commands/slash-commands/images/listroles2.png differ diff --git a/docs/guides/int_basics/application-commands/slash-commands/images/oauth.png b/docs/guides/int_basics/application-commands/slash-commands/images/oauth.png new file mode 100644 index 000000000..e0f8224a8 Binary files /dev/null and b/docs/guides/int_basics/application-commands/slash-commands/images/oauth.png differ diff --git a/docs/guides/int_basics/application-commands/slash-commands/images/settings1.png b/docs/guides/int_basics/application-commands/slash-commands/images/settings1.png new file mode 100644 index 000000000..0eb4d711a Binary files /dev/null and b/docs/guides/int_basics/application-commands/slash-commands/images/settings1.png differ diff --git a/docs/guides/int_basics/application-commands/slash-commands/images/settings2.png b/docs/guides/int_basics/application-commands/slash-commands/images/settings2.png new file mode 100644 index 000000000..5ced63134 Binary files /dev/null and b/docs/guides/int_basics/application-commands/slash-commands/images/settings2.png differ diff --git a/docs/guides/int_basics/application-commands/slash-commands/images/settings3.png b/docs/guides/int_basics/application-commands/slash-commands/images/settings3.png new file mode 100644 index 000000000..485110814 Binary files /dev/null and b/docs/guides/int_basics/application-commands/slash-commands/images/settings3.png differ diff --git a/docs/guides/int_basics/application-commands/slash-commands/images/slashcommand1.png b/docs/guides/int_basics/application-commands/slash-commands/images/slashcommand1.png new file mode 100644 index 000000000..0c4e0aec7 Binary files /dev/null and b/docs/guides/int_basics/application-commands/slash-commands/images/slashcommand1.png differ diff --git a/docs/guides/int_basics/application-commands/slash-commands/images/slashcommand2.png b/docs/guides/int_basics/application-commands/slash-commands/images/slashcommand2.png new file mode 100644 index 000000000..828d8a2ce Binary files /dev/null and b/docs/guides/int_basics/application-commands/slash-commands/images/slashcommand2.png differ diff --git a/docs/guides/int_basics/application-commands/slash-commands/parameters.md b/docs/guides/int_basics/application-commands/slash-commands/parameters.md new file mode 100644 index 000000000..6afd83729 --- /dev/null +++ b/docs/guides/int_basics/application-commands/slash-commands/parameters.md @@ -0,0 +1,102 @@ +--- +uid: Guides.SlashCommands.Parameters +title: Slash Command Parameters +--- + +# Slash command parameters + +Slash commands can have a bunch of parameters, each their own type. Let's first go over the types of parameters we can have. + +| Name | Description | +| --------------- | -------------------------------------------------- | +| SubCommand | A subcommand inside of a subcommand group. | +| SubCommandGroup | The parent command group of subcommands. | +| String | A string of text. | +| Integer | A number. | +| Boolean | True or False. | +| User | A user | +| Channel | A channel, this includes voice text and categories | +| Role | A role. | +| Mentionable | A role or a user. | + +Each one of the parameter types has its own DNET type in the `SocketSlashCommandDataOption`'s Value field: +| Name | C# Type | +| --------------- | ------------------------------------------------ | +| SubCommand | NA | +| SubCommandGroup | NA | +| String | `string` | +| Integer | `int` | +| Boolean | `bool` | +| User | `SocketGuildUser` or `SocketUser` | +| Role | `SocketRole` | +| Channel | `SocketChannel` | +| Mentionable | `SocketUser`, `SocketGuildUser`, or `SocketRole` | + +Let's start by making a command that takes in a user and lists their roles. + +```cs +client.Ready += Client_Ready; + +... + +public async Task Client_Ready() +{ + ulong guildId = 848176216011046962; + + var guildCommand = new SlashCommandBuilder() + .WithName("list-roles") + .WithDescription("Lists all roles of a user.") + .AddOption("user", ApplicationCommandOptionType.User, "The users whos roles you want to be listed", isRequired: true); + + try + { + await client.Rest.CreateGuildCommand(guildCommand.Build(), guildId); + } + catch(ApplicationCommandException exception) + { + var json = JsonConvert.SerializeObject(exception.Error, Formatting.Indented); + Console.WriteLine(json); + } +} + +``` + +![list roles command](images/listroles1.png) + +That seems to be working, now Let's handle the interaction. + +```cs +private async Task SlashCommandHandler(SocketSlashCommand command) +{ + // Let's add a switch statement for the command name so we can handle multiple commands in one event. + switch(command.Data.Name) + { + case "list-roles": + await HandleListRoleCommand(command); + break; + } +} + +private async Task HandleListRoleCommand(SocketSlashCommand command) +{ + // We need to extract the user parameter from the command. since we only have one option and it's required, we can just use the first option. + var guildUser = (SocketGuildUser)command.Data.Options.First().Value; + + // We remove the everyone role and select the mention of each role. + var roleList = string.Join(",\n", guildUser.Roles.Where(x => !x.IsEveryone).Select(x => x.Mention)); + + var embedBuiler = new EmbedBuilder() + .WithAuthor(guildUser.ToString(), guildUser.GetAvatarUrl() ?? guildUser.GetDefaultAvatarUrl()) + .WithTitle("Roles") + .WithDescription(roleList) + .WithColor(Color.Green) + .WithCurrentTimestamp(); + + // Now, Let's respond with the embed. + await command.RespondAsync(embed: embedBuiler.Build()); +} +``` + +![working list roles](images/listroles2.png) + +That has worked! Next, we will go over responding ephemerally. diff --git a/docs/guides/int_basics/application-commands/slash-commands/responding-ephemerally.md b/docs/guides/int_basics/application-commands/slash-commands/responding-ephemerally.md new file mode 100644 index 000000000..10b04a8d2 --- /dev/null +++ b/docs/guides/int_basics/application-commands/slash-commands/responding-ephemerally.md @@ -0,0 +1,23 @@ +--- +uid: Guides.SlashCommands.Ephemeral +title: Ephemeral Responses +--- + +# Responding ephemerally + +What is an ephemeral response? Basically, only the user who executed the command can see the result of it, this is pretty simple to implement. + +> [!NOTE] +> You don't have to run arg.DeferAsync() to capture the interaction, you can use arg.RespondAsync() with a message to capture it, this also follows the ephemeral rule. + +When responding with either `FollowupAsync` or `RespondAsync` you can pass in an `ephemeral` property. When setting it to true it will respond ephemerally, false and it will respond non-ephemerally. + +Let's use this in our list role command. + +```cs +await command.RespondAsync(embed: embedBuiler.Build(), ephemeral: true); +``` + +Running the command now only shows the message to us! + +![ephemeral command](images/ephemeral1.png) \ No newline at end of file diff --git a/docs/guides/int_basics/application-commands/slash-commands/responding-to-slash-commands.md b/docs/guides/int_basics/application-commands/slash-commands/responding-to-slash-commands.md new file mode 100644 index 000000000..3dbc579fe --- /dev/null +++ b/docs/guides/int_basics/application-commands/slash-commands/responding-to-slash-commands.md @@ -0,0 +1,40 @@ +--- +uid: Guides.SlashCommands.Receiving +title: Receiving and Responding to Slash Commands +--- + +# Responding to interactions. + +Interactions are the base thing sent over by Discord. Slash commands are one of the interaction types. We can listen to the `SlashCommandExecuted` event to respond to them. Lets add this to our code: + +```cs +client.SlashCommandExecuted += SlashCommandHandler; + +... + +private async Task SlashCommandHandler(SocketSlashCommand command) +{ + +} +``` + +With every type of interaction there is a `Data` field. This is where the relevant information lives about our command that was executed. In our case, `Data` is a `SocketSlashCommandData` instance. In the data class, we can access the name of the command triggered as well as the options if there were any. For this example, we're just going to respond with the name of the command executed. + +```cs +private async Task SlashCommandHandler(SocketSlashCommand command) +{ + await command.RespondAsync($"You executed {command.Data.Name}"); +} +``` + +Let's try this out! + +![slash command picker](images/slashcommand1.png) + +![slash command result](images/slashcommand2.png) + +> [!NOTE] +> After receiving an interaction, you must respond to acknowledge it. You can choose to respond with a message immediately using `RespondAsync()` or you can choose to send a deferred response with `DeferAsync()`. +> If choosing a deferred response, the user will see a loading state for the interaction, and you'll have up to 15 minutes to edit the original deferred response using `ModifyOriginalResponseAsync()`. You can read more about response types [here](https://discord.com/developers/docs/interactions/slash-commands#interaction-response) + +This seems to be working! Next, we will look at parameters for slash commands. diff --git a/docs/guides/int_basics/application-commands/slash-commands/subcommands.md b/docs/guides/int_basics/application-commands/slash-commands/subcommands.md new file mode 100644 index 000000000..83d7b283c --- /dev/null +++ b/docs/guides/int_basics/application-commands/slash-commands/subcommands.md @@ -0,0 +1,219 @@ +--- +uid: Guides.SlashCommands.SubCommand +title: Sub Commands +--- + +# Subcommands + +Subcommands allow you to have multiple commands available in a single command. They can be useful for representing sub options for a command. For example: A settings command. Let's first look at some limitations with subcommands set by discord. + +- An app can have up to 25 subcommand groups on a top-level command +- An app can have up to 25 subcommands within a subcommand group +- commands can have up to 25 `options` +- options can have up to 25 `choices` + +``` +VALID + +command +| +|__ subcommand +| +|__ subcommand + +---- + +command +| +|__ subcommand-group + | + |__ subcommand +| +|__ subcommand-group + | + |__ subcommand + + +------- + +INVALID + + +command +| +|__ subcommand-group + | + |__ subcommand-group +| +|__ subcommand-group + | + |__ subcommand-group + +---- + +INVALID + +command +| +|__ subcommand + | + |__ subcommand-group +| +|__ subcommand + | + |__ subcommand-group +``` + +Let's write a settings command that can change 3 fields in our bot. + +```cs +public string FieldA { get; set; } = "test"; +public int FieldB { get; set; } = 10; +public bool FieldC { get; set; } = true; + +public async Task Client_Ready() +{ + ulong guildId = 848176216011046962; + + var guildCommand = new SlashCommandBuilder() + .WithName("settings") + .WithDescription("Changes some settings within the bot.") + .AddOption(new SlashCommandOptionBuilder() + .WithName("field-a") + .WithDescription("Gets or sets the field A") + .WithType(ApplicationCommandOptionType.SubCommandGroup) + .AddOption(new SlashCommandOptionBuilder() + .WithName("set") + .WithDescription("Sets the field A") + .WithType(ApplicationCommandOptionType.SubCommand) + .AddOption("value", ApplicationCommandOptionType.String, "the value to set the field", isRequired: true) + ).AddOption(new SlashCommandOptionBuilder() + .WithName("get") + .WithDescription("Gets the value of field A.") + .WithType(ApplicationCommandOptionType.SubCommand) + ) + ).AddOption(new SlashCommandOptionBuilder() + .WithName("field-b") + .WithDescription("Gets or sets the field B") + .WithType(ApplicationCommandOptionType.SubCommandGroup) + .AddOption(new SlashCommandOptionBuilder() + .WithName("set") + .WithDescription("Sets the field B") + .WithType(ApplicationCommandOptionType.SubCommand) + .AddOption("value", ApplicationCommandOptionType.Integer, "the value to set the fie to.", isRequired: true) + ).AddOption(new SlashCommandOptionBuilder() + .WithName("get") + .WithDescription("Gets the value of field B.") + .WithType(ApplicationCommandOptionType.SubCommand) + ) + ).AddOption(new SlashCommandOptionBuilder() + .WithName("field-c") + .WithDescription("Gets or sets the field C") + .WithType(ApplicationCommandOptionType.SubCommandGroup) + .AddOption(new SlashCommandOptionBuilder() + .WithName("set") + .WithDescription("Sets the field C") + .WithType(ApplicationCommandOptionType.SubCommand) + .AddOption("value", ApplicationCommandOptionType.Boolean, "the value to set the fie to.", isRequired: true) + ).AddOption(new SlashCommandOptionBuilder() + .WithName("get") + .WithDescription("Gets the value of field C.") + .WithType(ApplicationCommandOptionType.SubCommand) + ) + ); + + try + { + await client.Rest.CreateGuildCommand(guildCommand.Build(), guildId); + } + catch(ApplicationCommandException exception) + { + var json = JsonConvert.SerializeObject(exception.Error, Formatting.Indented); + Console.WriteLine(json); + } +} +``` + +All that code generates a command that looks like this: +![settings](images/settings1.png) + +Now that we have our command made, we need to handle the multiple options with this command. So lets add this into our handler: + +```cs +private async Task SlashCommandHandler(SocketSlashCommand command) +{ + // Let's add a switch statement for the command name so we can handle multiple commands in one event. + switch(command.Data.Name) + { + case "list-roles": + await HandleListRoleCommand(command); + break; + case "settings": + await HandleSettingsCommand(command); + break; + } +} + +private async Task HandleSettingsCommand(SocketSlashCommand command) +{ + // First lets extract our variables + var fieldName = command.Data.Options.First().Name; + var getOrSet = command.Data.Options.First().Options.First().Name; + // Since there is no value on a get command, we use the ? operator because "Options" can be null. + var value = command.Data.Options.First().Options.First().Options?.FirstOrDefault().Value; + + switch (fieldName) + { + case "field-a": + { + if(getOrSet == "get") + { + await command.RespondAsync($"The value of `field-a` is `{FieldA}`"); + } + else if (getOrSet == "set") + { + this.FieldA = (string)value; + await command.RespondAsync($"`field-a` has been set to `{FieldA}`"); + } + } + break; + case "field-b": + { + if (getOrSet == "get") + { + await command.RespondAsync($"The value of `field-b` is `{FieldB}`"); + } + else if (getOrSet == "set") + { + this.FieldB = (int)value; + await command.RespondAsync($"`field-b` has been set to `{FieldB}`"); + } + } + break; + case "field-c": + { + if (getOrSet == "get") + { + await command.RespondAsync($"The value of `field-c` is `{FieldC}`"); + } + else if (getOrSet == "set") + { + this.FieldC = (bool)value; + await command.RespondAsync($"`field-c` has been set to `{FieldC}`"); + } + } + break; + } +} + +``` + +Now, let's try this out! Running the 3 get commands seems to get the default values we set. + +![settings get](images/settings2.png) + +Now let's try changing each to a different value. + +![settings set](images/settings3.png) + +That has worked! Next, let't look at choices in commands. diff --git a/docs/guides/int_basics/intro.md b/docs/guides/int_basics/intro.md new file mode 100644 index 000000000..62b2dfdb5 --- /dev/null +++ b/docs/guides/int_basics/intro.md @@ -0,0 +1,10 @@ +--- +uid: Guides.Interactions.Intro +title: Introduction to Interactions +--- + +# Interactions + +Placeholder text does the brrr. + +Links to different sections of guides: msg comp / slash commands. diff --git a/docs/guides/int_basics/message-components/advanced.md b/docs/guides/int_basics/message-components/advanced.md new file mode 100644 index 000000000..49b3f31a6 --- /dev/null +++ b/docs/guides/int_basics/message-components/advanced.md @@ -0,0 +1,87 @@ +--- +uid: Guides.MessageComponents.Advanced +title: Advanced Concepts +--- + +# Advanced + +Lets say you have some components on an ephemeral slash command, and you want to modify the message that the button is on. The issue with this is that ephemeral messages are not stored and can not be get via rest or other means. + +Luckily, Discord thought of this and introduced a way to modify them with interactions. + +### Using the UpdateAsync method + +Components come with an `UpdateAsync` method that can update the message that the component was on. You can use it like a `ModifyAsync` method. + +Lets use it with a command, we first create our command, in this example im just going to use a message command: + +```cs +var command = new MessageCommandBuilder() + .WithName("testing").Build(); + +await client.GetGuild(guildId).BulkOverwriteApplicationCommandAsync(new [] { command, buttonCommand }); +``` + +Next, we listen for this command, and respond with some components when its used: + +```cs +var menu = new SelectMenuBuilder() +{ + CustomId = "select-1", + Placeholder = "Select Somthing!", + MaxValues = 1, + MinValues = 1, +}; + +menu.AddOption("Meh", "1", "Its not gaming.") + .AddOption("Ish", "2", "Some would say that this is gaming.") + .AddOption("Moderate", "3", "It could pass as gaming") + .AddOption("Confirmed", "4", "We are gaming") + .AddOption("Excellent", "5", "It is renowned as gaming nation wide", new Emoji("🔥")); + +var components = new ComponentBuilder() + .WithSelectMenu(menu); + + +await arg.RespondAsync("On a scale of one to five, how gaming is this?", component: componBuild(), ephemeral: true); +break; +``` + +Now, let's listen to the select menu executed event and add a case for `select-1` + +```cs +client.SelectMenuExecuted += SelectMenuHandler; + +... + +public async Task SelectMenuHandler(SocketMessageComponent arg) +{ + switch (arg.Data.CustomId) + { + case "select-1": + var value = arg.Data.Values.First(); + var menu = new SelectMenuBuilder() + { + CustomId = "select-1", + Placeholder = $"{(arg.Message.Components.First().Components.First() as SelectMenu).Options.FirstOrDefault(x => x.Value == value).Label}", + MaxValues = 1, + MinValues = 1, + Disabled = true + }; + + menu.AddOption("Meh", "1", "Its not gaming.") + .AddOption("Ish", "2", "Some would say that this is gaming.") + .AddOption("Moderate", "3", "It could pass as gaming") + .AddOption("Confirmed", "4", "We are gaming") + .AddOption("Excellent", "5", "It is renowned as gaming nation wide", new Emoji("🔥")); + + // We use UpdateAsync to update the message and its original content and components. + await arg.UpdateAsync(x => + { + x.Content = $"Thank you {arg.User.Mention} for rating us {value}/5 on the gaming scale"; + x.Components = new ComponentBuilder().WithSelectMenu(menu).Build(); + }); + break; + } +} +``` diff --git a/docs/guides/int_basics/message-components/buttons-in-depth.md b/docs/guides/int_basics/message-components/buttons-in-depth.md new file mode 100644 index 000000000..5da48c69b --- /dev/null +++ b/docs/guides/int_basics/message-components/buttons-in-depth.md @@ -0,0 +1,45 @@ +--- +uid: Guides.MessageComponents.Buttons +title: Buttons in Depth +--- + +# Buttons in depth + +There are many changes you can make to buttons, lets take a look at the parameters in the `WithButton` function" +| Name | Type | Description | +|----------|---------------|----------------------------------------------------------------| +| label | `string` | The label text for the button. | +| customId | `string` | The custom id of the button. | +| style | `ButtonStyle` | The style of the button. | +| emote | `IEmote` | A IEmote to be used with this button. | +| url | `string` | A URL to be used only if the `ButtonStyle` is a Link. | +| disabled | `bool` | Whether or not the button is disabled. | +| row | `int` | The row to place the button if it has enough room, otherwise 0 | + +### Label + +This is the front facing text that the user sees. The maximum length is 80 characters. + +### CustomId + +This is the property sent to you by discord when a button is clicked. It is not required for link buttons as they do not emit an event. The maximum length is 100 characters. + +### Style + +Styling your buttons are important for indicating different actions: + +![](images/image3.png) + +You can do this by using the `ButtonStyle` which has all the styles defined. + +### Emote + +You can specify an `IEmote` when creating buttons to add them to your button. They have the same restrictions as putting guild based emotes in messages. + +### Url + +If you use the link style with your button you can specify a url. When this button is clicked the user is taken to that url. + +### Disabled + +You can specify if your button is disabled, meaning users won't be able to click on it. diff --git a/docs/guides/int_basics/message-components/images/image1.png b/docs/guides/int_basics/message-components/images/image1.png new file mode 100644 index 000000000..a161d8a61 Binary files /dev/null and b/docs/guides/int_basics/message-components/images/image1.png differ diff --git a/docs/guides/int_basics/message-components/images/image2.png b/docs/guides/int_basics/message-components/images/image2.png new file mode 100644 index 000000000..9303de91b Binary files /dev/null and b/docs/guides/int_basics/message-components/images/image2.png differ diff --git a/docs/guides/int_basics/message-components/images/image3.png b/docs/guides/int_basics/message-components/images/image3.png new file mode 100644 index 000000000..7480e1da9 Binary files /dev/null and b/docs/guides/int_basics/message-components/images/image3.png differ diff --git a/docs/guides/int_basics/message-components/images/image4.png b/docs/guides/int_basics/message-components/images/image4.png new file mode 100644 index 000000000..c54ab791f Binary files /dev/null and b/docs/guides/int_basics/message-components/images/image4.png differ diff --git a/docs/guides/int_basics/message-components/images/image5.png b/docs/guides/int_basics/message-components/images/image5.png new file mode 100644 index 000000000..096b7587f Binary files /dev/null and b/docs/guides/int_basics/message-components/images/image5.png differ diff --git a/docs/guides/int_basics/message-components/images/image6.png b/docs/guides/int_basics/message-components/images/image6.png new file mode 100644 index 000000000..1536096d0 Binary files /dev/null and b/docs/guides/int_basics/message-components/images/image6.png differ diff --git a/docs/guides/int_basics/message-components/intro.md b/docs/guides/int_basics/message-components/intro.md new file mode 100644 index 000000000..cc22d54c5 --- /dev/null +++ b/docs/guides/int_basics/message-components/intro.md @@ -0,0 +1,66 @@ +--- +uid: Guides.MessageComponents.Intro +title: Getting Started with Components +--- + +# Message Components + +Message components are a framework for adding interactive elements to a message your app or bot sends. They're accessible, customizable, and easy to use. + +## What is a Component + +Components are a new parameter you can use when sending messages with your bot. There are currently 2 different types of components you can use: Buttons and Select Menus. + +## Creating components + +Lets create a simple component that has a button. First thing we need is a way to trigger the message, this can be done via commands or simply a ready event. Lets make a command that triggers our button message. + +```cs +[Command("spawner")] +public async Task Spawn() +{ + // Reply with some components +} +``` + +We now have our command, but we need to actually send the buttons with the command. To do that, lets look at the `ComponentBuilder` class: + +| Name | Description | +| ---------------- | --------------------------------------------------------------------------- | +| `FromMessage` | Creates a new builder from a message. | +| `FromComponents` | Creates a new builder from the provided list of components. | +| `WithSelectMenu` | Adds a `SelectMenuBuilder` to the `ComponentBuilder` at the specific row. | +| `WithButton` | Adds a `ButtonBuilder` to the `ComponentBuilder` at the specific row. | +| `Build` | Builds this builder into a `MessageComponent` used to send your components. | + +We see that we can use the `WithButton` function so lets do that. looking at its parameters it takes: + +- `label` - The display text of the button. +- `customId` - The custom id of the button, this is whats sent by discord when your button is clicked. +- `style` - The discord defined style of the button. +- `emote` - An emote to be displayed with the button. +- `url` - The url of the button if its a link button. +- `disabled` - Whether or not the button is disabled. +- `row` - The row the button will occupy. + +Since were just making a busic button, we dont have to specify anything else besides the label and custom id. + +```cs +var builder = new ComponentBuilder() + .WithButton("label", "custom-id"); +``` + +Lets add this to our command: + +```cs +[Command("spawner")] +public async Task Spawn() +{ + var builder = new ComponentBuilder() + .WithButton("label", "custom-id"); + + await ReplyAsync("Here is a button!", components: builder.Build()); +} +``` + +![](images\image1.png) diff --git a/docs/guides/int_basics/message-components/responding-to-buttons.md b/docs/guides/int_basics/message-components/responding-to-buttons.md new file mode 100644 index 000000000..7546c6fe2 --- /dev/null +++ b/docs/guides/int_basics/message-components/responding-to-buttons.md @@ -0,0 +1,37 @@ +--- +uid: Guides.MessageComponents.Responding +title: Responding to Components +--- + +# Responding to button clicks + +Responding to buttons is pretty simple, there are a couple ways of doing it and we can cover both. + +### Method 1: Hooking the InteractionCreated Event + +We can hook the `ButtonExecuted` event for button type interactions: + +```cs +client.ButtonExecuted += MyButtonHandler; +``` + +Now, lets write our handler. + +```cs +public async Task MyButtonHandler(SocketMessageComponent component) +{ + // We can now check for our custom id + switch(component.Data.CustomId) + { + // Since we set our buttons custom id as 'custom-id', we can check for it like this: + case "custom-id": + // Lets respond by sending a message saying they clicked the button + await component.RespondAsync($"{component.User.Mention} has clicked the button!"); + break; + } +} +``` + +Running it and clicking the button: + +![](images/image2.png) \ No newline at end of file diff --git a/docs/guides/int_basics/message-components/select-menus.md b/docs/guides/int_basics/message-components/select-menus.md new file mode 100644 index 000000000..6dfe151b1 --- /dev/null +++ b/docs/guides/int_basics/message-components/select-menus.md @@ -0,0 +1,76 @@ +--- +uid: Guides.MessageComponents.SelectMenus +title: Select Menus +--- + +# Select menus + +Select menus allow users to select from a range of options, this can be quite useful with configuration commands etc. + +## Creating a select menu + +We can use a `SelectMenuBuilder` to create our menu. + +```cs +var menuBuilder = new SelectMenuBuilder() + .WithPlaceholder("Select an option") + .WithCustomId("menu-1") + .WithMinValues(1) + .WithMaxValues(1) + .AddOption("Option A", "opt-a", "Option B is lying!") + .AddOption("Option B", "opt-b", "Option A is telling the truth!"); + +var builder = new ComponentBuilder() + .WithSelectMenu(menuBuilder); +``` + +Lets add this to a command: + +```cs +[Command("spawner")] +public async Task Spawn() +{ + var menuBuilder = new SelectMenuBuilder() + .WithPlaceholder("Select an option") + .WithCustomId("menu-1") + .WithMinValues(1) + .WithMaxValues(1) + .AddOption("Option A", "opt-a", "Option B is lying!") + .AddOption("Option B", "opt-b", "Option A is telling the truth!"); + + var builder = new ComponentBuilder() + .WithSelectMenu(menuBuilder); + + await ReplyAsync("Whos really lying?", components: builder.Build()); +} +``` + +Running this produces this result: + +![](images/image4.png) + +And opening the menu we see: + +![](images/image5.png) + +Lets handle the selection of an option, We can hook the `SelectMenuExecuted` event to handle our select menu: + +```cs +client.SelectMenuExecuted += MyMenuHandler; +``` + +The `SelectMenuExecuted` also supplies a `SocketMessageComponent` argument, we can confirm that its a select menu by checking the `ComponentType` inside of the data field if we need, but the library will do that for us and only execute our handler if its a select menu. + +The values that the user has selected will be inside of the `Values` collection in the Data field. we can list all of them back to the user for this example. + +```cs +public async Task MyMenuHandler(SocketMessageComponent arg) +{ + var text = string.Join(", ", arg.Data.Values); + await arg.RespondAsync($"You have selected {text}"); +} +``` + +Running this produces this result: + +![](images/image6.png) diff --git a/docs/guides/int_framework/autocompletion.md b/docs/guides/int_framework/autocompletion.md new file mode 100644 index 000000000..834db2b4f --- /dev/null +++ b/docs/guides/int_framework/autocompletion.md @@ -0,0 +1,47 @@ +--- +uid: Guides.IntFw.AutoCompletion +title: Command Autocompletion +--- + +# AutocompleteHandlers + +[Autocompleters] provide a similar pattern to TypeConverters. +[Autocompleters] are cached, singleton services and they are used by the +Interaction Service to handle Autocomplete Interations targeted to a specific Slash Command parameter. + +To start using AutocompleteHandlers, use the `[AutocompleteAttribute(Type type)]` overload of the [AutocompleteAttribute]. +This will dynamically link the parameter to the [AutocompleteHandler] type. + +AutocompleteHandlers raise the `AutocompleteHandlerExecuted` event on execution. This event can be also used to create a post-execution logic, just like the `*CommandExecuted` events. + +## Creating AutocompleteHandlers + +A valid AutocompleteHandlers must inherit [AutocompleteHandler] base type and implement all of its abstract methods. + +### GenerateSuggestionsAsync() + +The Interactions Service uses this method to generate a response of an Autocomplete Interaction. +This method should return `AutocompletionResult.FromSuccess(IEnumerable)` to +display parameter suggestions to the user. If there are no suggestions to be presented to the user, you have two results: + +1. Returning the parameterless `AutocompletionResult.FromSuccess()` will display a "No options match your search." message to the user. +2. Returning `AutocompleteResult.FromError()` will make the Interaction Service **not** respond to the interaction, +consequently displaying the user a "Loading options failed." message. `AutocompletionResult.FromError()` is solely used for error handling purposes. Discord currently doesn't allow +you to display custom error messages. This result type will be directly returned to the `AutocompleteHandlerExecuted` method. + +## Resolving AutocompleteHandler Dependencies + +AutocompleteHandler dependencies are resolved using the same dependency injection +pattern as the Interaction Modules. +Property injection and constructor injection are both valid ways to get service dependencies. + +Because [AutocompleterHandlers] are constructed at service startup, +class dependencies are resolved only once. + +> [!NOTE] +> If you need to access per-request dependencies you can use the +> IServiceProvider parameter of the `GenerateSuggestionsAsync()` method. + +[AutoCompleteHandlers]: xref:Discord.Interactions.AutocompleteHandler +[AutoCompleteHandler]: xref:Discord.Interactions.AutocompleteHandler +[AutoCompleteAttribute]: diff --git a/docs/guides/int_framework/dependency-injection.md b/docs/guides/int_framework/dependency-injection.md new file mode 100644 index 000000000..31d001f4b --- /dev/null +++ b/docs/guides/int_framework/dependency-injection.md @@ -0,0 +1,13 @@ +--- +uid: Guides.IntFw.DI +title: Dependency Injection +--- + +# Dependency Injection + +Dependency injection in the Interaction Service is mostly based on that of the Text-based command service, +for which further information is found [here](xref:Guides.TextCommands.DI). + +> [!NOTE] +> The 2 are nearly identical, except for one detail: +> [Resolving Module Dependencies](xref:Guides.IntFw.Intro#resolving-module-dependencies) diff --git a/docs/guides/int_framework/intro.md b/docs/guides/int_framework/intro.md new file mode 100644 index 000000000..7dfd7ac6e --- /dev/null +++ b/docs/guides/int_framework/intro.md @@ -0,0 +1,353 @@ +--- +uid: Guides.IntFw.Intro +title: Introduction to the Interaction Service +--- + +# Getting Started + +The Interaction Service provides an attribute based framework for creating Discord Interaction handlers. + +To start using the Interaction Service, you need to create a service instance. +Optionally you can provide the [InteractionService] constructor with a +[InteractionServiceConfig] to change the services behaviour to suit your needs. + +```csharp +... +// _client here is DiscordSocketClient. +// A different approach to passing in a restclient is also possible. +var _interactionService = new InteractionService(_client.Rest); + +... +``` + +## Modules + +Attribute based Interaction handlers must be defined within a command module class. +Command modules are responsible for executing the Interaction handlers and providing them with the necessary execution info and helper functions. + +Command modules are transient objects. +A new module instance is created before a command execution starts then it will be disposed right after the method returns. + +Every module class must: + +- be public +- inherit [InteractionModuleBase] + +Optionally you can override the included : + +- OnModuleBuilding (executed after the module is built) +- BeforeExecute (executed before a command execution starts) +- AfterExecute (executed after a command execution concludes) + +methods to configure the modules behaviour. + +Every command module exposes a set of helper methods, namely: + +- `RespondAsync()` => Respond to the interaction +- `FollowupAsync()` => Create a followup message for an interaction +- `ReplyAsync()` => Send a message to the origin channel of the interaction +- `DeleteOriginalResponseAsync()` => Delete the original interaction response + +## Commands + +Valid **Interaction Commands** must comply with the following requirements: + +| | return type | max parameter count | allowed parameter types | attribute | +|-------------------------------|------------------------------|---------------------|-------------------------------|--------------------------| +|[Slash Command](#slash-commands)| `Task`/`Task` | 25 | any* | `[SlashCommand]` | +|[User Command](#user-commands) | `Task`/`Task` | 1 | Implementations of `IUser` | `[UserCommand]` | +|[Message Command](#message-commands)| `Task`/`Task` | 1 | Implementations of `IMessage` | `[MessageCommand]` | +|[Component Interaction Command](#component-interaction-commands)| `Task`/`Task` | inf | `string` or `string[]` | `[ComponentInteraction]` | +|[Autocomplete Command](#autocomplete-commands)| `Task`/`Task` | - | - | `[AutocompleteCommand]`| + +> [!NOTE] +> a `TypeConverter` that is capable of parsing type in question must be registered to the [InteractionService] instance. +> You should avoid using long running code in your command module. +> Depending on your setup, long running code may block the Gateway thread of your bot, interrupting its connection to Discord. + +## Slash Commands + +Slash Commands are created using the [SlashCommandAttribute]. +Every Slash Command must declare a name and a description. +You can check Discords **Application Command Naming Guidelines** +[here](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-naming). + +[!code-csharp[Slash Command](samples/intro/slashcommand.cs)] + +### Parameters + +Slash Commands can have up to 25 method parameters. You must name your parameters in accordance with +[Discords Naming Guidelines](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-naming). +[InteractionService] also features a pascal casing seperator for formatting parameter names with +pascal casing into Discord compliant parameter names('parameterName' => 'parameter-name'). +By default, your methods can feature the following parameter types: + +- Implementations of [IUser] +- Implementations of [IChannel] +- Implementations of [IRole] +- Implementations of [IMentionable] +- `string` +- `float`, `double`, `decimal` +- `bool` +- `char` +- `sbyte`, `byte` +- `int16`, `int32`, `int64` +- `uint16`, `uint32`, `uint64` +- `enum` (Values are registered as multiple choice options and are enforced by Discord. Use `[HideAttribute]` on enum values to prevent them from getting registered.) +- `DateTime` +- `TimeSpan` + +--- + +**You can use more specialized implementations of [IChannel] to restrict the allowed channel types for a channel type option.* +| interface | Channel Type | +|---------------------|-------------------------------| +| `IStageChannel` | Stage Channels | +| `IVoiceChannel` | Voice Channels | +| `IDMChannel` | DM Channels | +| `IGroupChannel` | Group Channels | +| `ICategory Channel` | Category Channels | +| `INewsChannel` | News Channels | +| `IThreadChannel` | Public, Private, News Threads | +| `ITextChannel` | Text Channels | + +--- + +#### Optional Parameters + +Parameters with default values (ie. `int count = 0`) will be displayed as optional parameters on Discord Client. + +#### Parameter Summary + +By using the [SummaryAttribute] you can customize the displayed name and description of a parameter + +[!code-csharp[Summary Attribute](samples/intro/summaryattribute.cs)] + +#### Parameter Choices + +[ChoiceAttribute] can be used to add choices to a parameter. + +[!code-csharp[Choice Attribute](samples/intro/groupattribute.cs)] + +This Slash Command will be displayed exactly the same as the previous example. + +#### Channel Types + +Channel types for an [IChannel] parameter can also be restricted using the [ChannelTypesAttribute]. + +[!code-csharp[Channel Attribute](samples/intro/channelattribute.cs)] + +In this case, user can only input Stage Channels and Text Channels to this parameter. + +#### Min/Max Value + +You can specify the permitted max/min value for a number type parameter using the [MaxValueAttribute] and [MinValueAttribute]. + +## User Commands + +A valid User Command must have the following structure: + +[!code-csharp[User Command](samples/intro/usercommand.cs)] + +> [!WARNING] +> User commands can only have one parameter and its type must be an implementation of [IUser]. + +## Message Commands + +A valid Message Command must have the following structure: + +[!code-csharp[Message Command](samples/intro/messagecommand.cs)] + +> [!WARNING] +> Message commands can only have one parameter and its type must be an implementation of [IMessage]. + +## Component Interaction Commands + +Component Interaction Commands are used to handle interactions that originate from **Discord Message Component**s. +This pattern is particularly useful if you will be reusing a set a **Custom ID**s. + +Component Interaction Commands support wild card matching, +by default `*` character can be used to create a wild card pattern. +Interaction Service will use lazy matching to capture the words corresponding to the wild card character. +And the captured words will be passed on to the command method in the same order they were captured. + +[!code-csharp[Button](samples/intro/button.cs)] + +You may use as many wild card characters as you want. + +> [!NOTE] +> If Interaction Service recieves a component interaction with **player:play,rickroll** custom id, +> `op` will be *play* and `name` will be *rickroll* + +## Select Menus + +Unlike button interactions, select menu interactions also contain the values of the selected menu items. +In this case, you should structure your method to accept a string array. + +[!code-csharp[Dropdown](samples/intro/dropdown.cs)] + +> [!NOTE] +> Wildcards may also be used to match a select menu ID, +> though keep in mind that the array containing the select menu values should be the last parameter. + +## Autocomplete Commands + +Autocomplete commands must be parameterless methods. A valid Autocomplete command must have the following structure: + +[!code-csharp[Autocomplete Command](samples/intro/autocomplete.cs)] + +Alternatively, you can use the [AutocompleteHandlers] to simplify this workflow. + +## Interaction Context + +Every command module provides its commands with an execution context. +This context property includes general information about the underlying interaction that triggered the command execution. +The base command context. + +You can design your modules to work with different implementation types of [IInteractionContext]. +To achieve this, make sure your module classes inherit from the generic variant of the [InteractionModuleBase]. + +> [!NOTE] +> Context type must be consistent throughout the project, or you will run into issues during runtime. + +The [InteractionService] ships with 4 different kinds of [InteractionContext]: + +1. [InteractionContext]]: A bare-bones execution context consisting of only implementation neutral interfaces +2. [SocketInteractionContext]: An execution context for use with [DiscordSocketClient]. Socket entities are exposed in this context without the need of casting them. +3. [ShardedInteractionContext]: [DiscordShardedClient] variant of the [SocketInteractionContext] +4. [RestInteractionContext]: An execution context designed to be used with a [DiscordRestClient] and webhook based interactions pattern + +You can create custom Interaction Contexts by implementing the [IInteractionContext] interface. + +One problem with using the concrete type InteractionContexts is that you cannot access the information that is specific to different interaction types without casting. Concrete type interaction contexts are great for creating shared interaction modules but you can also use the generic variants of the built-in interaction contexts to create interaction specific interaction modules. + +> [!INFO] +> Message component interactions have access to a special method called `UpdateAsync()` to update the body of the method the interaction originated from. +> Normally this wouldn't be accessable without casting the `Context.Interaction`. + +[!code-csharp[Context Example](samples/intro/context.cs)] + +## Loading Modules + +[InteractionService] can automatically discover and load modules that inherit [InteractionModuleBase] from an `Assembly`. +Call `InteractionService.AddModulesAsync()` to use this functionality. + +> [!NOTE] +> You can also manually add Interaction modules using the `InteractionService.AddModuleAsync()` +> method by providing the module type you want to load. + +## Resolving Module Dependencies + +Module dependencies are resolved using the Constructor Injection and Property Injection patterns. +Meaning, the constructor parameters and public settable properties of a module will be assigned using the `IServiceProvider`. +For more information on dependency injection, read the [DependencyInjection] guides. + +> [!NOTE] +> On every command execution, module dependencies are resolved using a new service scope which allows you to utilize scoped service instances, just like in Asp.Net. +> Including the precondition checks, every module method is executed using the same service scope and service scopes are disposed right after the `AfterExecute` method returns. + +## Module Groups + +Module groups allow you to create sub-commands and sub-commands groups. +By nesting commands inside a module that is tagged with [GroupAttribute] you can create prefixed commands. + +> [!WARNING] +> Although creating nested module stuctures are allowed, +> you are not permitted to use more than 2 [GroupAttribute]'s in module hierarchy. + +## Executing Commands + +Any of the following socket events can be used to execute commands: + +- [InteractionCreated] +- [ButtonExecuted] +- [SelectMenuExecuted] +- [AutocompleteExecuted] +- [UserCommandExecuted] +- [MessageCommandExecuted] + +Commands can be either executed on the gateway thread or on a seperate thread from the thread pool. This behaviour can be configured by changing the *RunMode* property of `InteractionServiceConfig` or by setting the *runMode* parameter of a command attribute. + +You can also configure the way [InteractionService] executes the commands. +By default, commands are executed using `ConstructorInfo.Invoke()` to create module instances and +`MethodInfo.Invoke()` method for executing the method bodies. +By setting, `InteractionServiceConfig.UseCompiledLambda` to `true`, you can make [InteractionService] create module instances and execute commands using +*Compiled Lambda* expressions. This cuts down on command execution time but it might add some memory overhead. + +Time it takes to create a module instance and execute a `Task.Delay(0)` method using the Reflection methods compared to Compiled Lambda expressions: + +| Method | Mean | Error | StdDev | +|----------------- |----------:|---------:|---------:| +| ReflectionInvoke | 225.93 ns | 4.522 ns | 7.040 ns | +| CompiledLambda | 48.79 ns | 0.981 ns | 1.276 ns | + +## Registering Commands to Discord + +Application commands loaded to the Interaction Service can be registered to Discord using a number of different methods. +In most cases `RegisterCommandsGloballyAsync()` and `RegisterCommandsToGuildAsync()` are the methods to use. +Command registration methods can only be used after the gateway client is ready or the rest client is logged in. + +[!code-csharp[Registering Commands Example](samples/intro/registering.cs)] + +Methods like `AddModulesToGuildAsync()`, `AddCommandsToGuildAsync()`, `AddModulesGloballyAsync()` and `AddCommandsGloballyAsync()` +can be used to register cherry picked modules or commands to global/guild scopes. + +> [!NOTE] +> In debug environment, since Global commands can take up to 1 hour to register/update, +> it is adviced to register your commands to a test guild for your changes to take effect immediately. +> You can use preprocessor directives to create a simple logic for registering commands as seen above + +## Interaction Utility + +Interaction Service ships with a static `InteractionUtiliy` +class which contains some helper methods to asynchronously waiting for Discord Interactions. +For instance, `WaitForInteractionAsync()` method allows you to wait for an Interaction for a given amount of time. +This method returns the first encountered Interaction that satisfies the provided predicate. + +> [!WARNING] +> If you are running the Interaction Service on `RunMode.Sync` you should avoid using this method in your commands, +> as it will block the gateway thread and interrupt your bots connection. + +## Webhook Based Interactions + +Instead of using the gateway to recieve Discord Interactions, Discord allows you to recieve Interaction events over Webhooks. +Interaction Service also supports this Interaction type but to be able to +respond to the Interactions within your command modules you need to perform the following: + +- Make your modules inherit `RestInteractionModuleBase` +- Set the `ResponseCallback` property of `InteractionServiceConfig` so that the `ResponseCallback` +delegate can be used to create HTTP responses from a deserialized json object string. +- Use the interaction endpoints of the module base instead of the interaction object (ie. `RespondAsync()`, `FollowupAsync()`...). + +[AutocompleteHandlers]: xref:Guides.IntFw.AutoCompletion +[DependencyInjection]: xref:Guides.TextCommands.DI + +[GroupAttribute]: xref:Discord.Interactions.GroupAttribute +[InteractionService]: xref:Discord.Interactions.InteractionService +[InteractionServiceConfig]: xref:Discord.Interactions.InteractionServiceConfig +[InteractionModuleBase]: xref:Discord.Interactions.InteractionModuleBase +[SlashCommandAttribute]: xref:Discord.Interactions.SlashCommandAttribute +[InteractionCreated]: xref:Discord.WebSocket.BaseSocketClient +[ButtonExecuted]: xref:Discord.WebSocket.BaseSocketClient +[SelectMenuExecuted]: xref:Discord.WebSocket.BaseSocketClient +[AutocompleteExecuted]: xref:Discord.WebSocket.BaseSocketClient +[UserCommandExecuted]: xref:Discord.WebSocket.BaseSocketClient +[MessageCommandExecuted]: xref:Discord.WebSocket.BaseSocketClient +[DiscordSocketClient]: xref:Discord.WebSocket.DiscordSocketClient +[DiscordRestClient]: xref:Discord.Rest.DiscordRestClient +[SocketInteractionContext]: xref:Discord.Interactions.SocketInteractionContext +[ShardedInteractionContext]: xref:Discord.Interactions.ShardedInteractionContext +[InteractionContext]: xref:Discord.Interactions.InteractionContext +[IInteractionContect]: xref:Discord.Interactions.IInteractionContext +[RestInteractionContext]: xref:Discord.Rest.RestInteractionContext +[SummaryAttribute]: xref:Discord.Interactions.SummaryAttribute +[ChoiceAttribute]: xref:Discord.Interactions.ChoiceAttribute +[ChannelTypesAttribute]: xref:Discord.Interactions.ChannelTypesAttribute +[MaxValueAttribute]: xref:Discord.Interactions.MaxValueAttribute +[MinValueAttribute]: xref:Discord.Interactions.MinValueAttribute + +[IChannel]: xref:Discord.IChannel +[IRole]: xref:Discord.IRole +[IUser]: xref:Discord.IUser +[IMessage]: xref:Discord.IMessage +[IMentionable]: xref:Discord.IMentionable diff --git a/docs/guides/int_framework/post-execution.md b/docs/guides/int_framework/post-execution.md new file mode 100644 index 000000000..70da8ad1e --- /dev/null +++ b/docs/guides/int_framework/post-execution.md @@ -0,0 +1,69 @@ +--- +uid: Guides.IntFw.PostExecution +title: Post-Command execution +--- + +# Post-Execution Logic + +Interaction Service uses [IResult] to provide information about the state of command execution. +These can be used to log internal exceptions or provide some insight to the command user. + +If you are running your commands using `RunMode.Sync` these command results can be retrieved from +the return value of [InteractionService.ExecuteCommandAsync] method or by +registering delegates to Interaction Service events. + +If you are using the `RunMode.Async` to run your commands, +you must use the Interaction Service events to get the execution results. When using `RunMode.Async`, +[InteractionService.ExecuteCommandAsync] will always return a successful result. + +[InteractionService.ExecuteCommandAsync]: xref:Discord.Interactions.InteractionService.ExecuteCommandAsync* + +## Results + +Interaction Result come in a handful of different flavours: + +1. [AutocompletionResult]: returned by Autocompleters +2. [ExecuteResult]: contains the result of method body execution process +3. [PreconditionGroupResult]: returned by Precondition groups +4. [PreconditionResult]: returned by preconditions +5. [RuntimeResult]: a user implementable result for returning user defined results +6. [SearchResult]: returned by command lookup map +7. [TypeConverterResult]: returned by TypeConverters + +> [!NOTE] +> You can either use the [IResult.Error] property of an Interaction result or create type check for the +> afformentioned result types to branch out your post-execution logic to handle different situations. + + +[AutocompletionResult]: xref:Discord.AutocompleteResult +[ExecuteResult]: xref:Discord.Interactions.ExecuteResult +[PreconditionGroupResult]: xref:Discord.Interactions.PreconditionGroupResult +[PreconditionResult]: xref:Discord.Interactions.PreconditionResult +[SearchResult]: xref:Discord.Interactions.SearchResult`1 +[TypeConverterResult]: xref:Discord.Interactions.TypeConverterResult +[IResult.Error]: xref:Discord.Interactions.IResult.Error* + +## CommandExecuted Events + +Every time a command gets executed, Interaction Service raises a `CommandExecuted` event. +These events can be used to create a post-execution pipeline. + +[!code-csharp[Error Review](samples/postexecution/error_review.cs)] + +## Log Event + +InteractionService regularly outputs information about the occuring events to keep the developer informed. + +## Runtime Result + +Interaction commands allow you to return `Task` to pass on additional information about the command execution +process back to your post-execution logic. + +Custom [RuntimeResult] classes can be created by inheriting the base [RuntimeResult] class. + +If command execution process reaches the method body of the command and no exceptions are thrown during +the execution of the method body, [RuntimeResult] returned by your command will be accessible by casting/type-checking the +[IResult] parameter of the `CommandExecuted` event delegate. + +[RuntimeResult]: xref:Discord.Interactions.RuntimeResult +[IResult]: xref:Discord.Interactions.IResult diff --git a/docs/guides/int_framework/preconditions.md b/docs/guides/int_framework/preconditions.md new file mode 100644 index 000000000..75e572798 --- /dev/null +++ b/docs/guides/int_framework/preconditions.md @@ -0,0 +1,77 @@ +--- +uid: Guides.IntFw.Preconditions +title: Preconditions +--- + +# Preconditions + +Precondition logic is the same as it is for Text-based commands. +A list of attributes and usage is still given for people who are new to both. + +There are two types of Preconditions you can use: + +* [PreconditionAttribute] can be applied to Modules, Groups, or Commands. +* [ParameterPreconditionAttribute] can be applied to Parameters. + +You may visit their respective API documentation to find out more. + +[PreconditionAttribute]: xref:Discord.Interactions.PreconditionAttribute +[ParameterPreconditionAttribute]: xref:Discord.Interactions.ParameterPreconditionAttribute + +## Bundled Preconditions + +@Discord.Interactions ships with several bundled Preconditions for you +to use. + +* @Discord.Interactions.RequireContextAttribute +* @Discord.Interactions.RequireOwnerAttribute +* @Discord.Interactions.RequireBotPermissionAttribute +* @Discord.Interactions.RequireUserPermissionAttribute +* @Discord.Interactions.RequireNsfwAttribute +* @Discord.Interactions.RequireRoleAttribute + +## Using Preconditions + +To use a precondition, simply apply any valid precondition candidate to +a command method signature as an attribute. + +[!code-csharp[Precondition usage](samples/preconditions/precondition_usage.cs)] + +## ORing Preconditions + +When writing commands, you may want to allow some of them to be +executed when only some of the precondition checks are passed. + +This is where the [Group] property of a precondition attribute comes in +handy. By assigning two or more preconditions to a group, the command +system will allow the command to be executed when one of the +precondition passes. + +### Example - ORing Preconditions + +[!code-csharp[OR Precondition](samples/preconditions/group_precondition.cs)] + +[Group]: xref:Discord.Commands.PreconditionAttribute.Group + +## Custom Preconditions + +To write your own Precondition, create a new class that inherits from +either [PreconditionAttribute] or [ParameterPreconditionAttribute] +depending on your use. + +In order for your Precondition to function, you will need to override +the [CheckPermissionsAsync] method. + +If the context meets the required parameters, return +[PreconditionResult.FromSuccess], otherwise return +[PreconditionResult.FromError] and include an error message if +necessary. + +> [!NOTE] +> Visual Studio can help you implement missing members +> from the abstract class by using the "Implement Abstract Class" +> IntelliSense hint. + +[CheckPermissionsAsync]: xref:Discord.Commands.PreconditionAttribute.CheckPermissionsAsync* +[PreconditionResult.FromSuccess]: xref:Discord.Commands.PreconditionResult.FromSuccess* +[PreconditionResult.FromError]: xref:Discord.Commands.PreconditionResult.FromError* diff --git a/docs/guides/int_framework/samples/intro/autocomplete.cs b/docs/guides/int_framework/samples/intro/autocomplete.cs new file mode 100644 index 000000000..f93c56eaa --- /dev/null +++ b/docs/guides/int_framework/samples/intro/autocomplete.cs @@ -0,0 +1,9 @@ +[AutocompleteCommand("parameter_name", "command_name")] +public async Task Autocomplete() +{ + IEnumerable results; + + ... + + await (Context.Interaction as SocketAutocompleteInteraction).RespondAsync(results); +} diff --git a/docs/guides/int_framework/samples/intro/button.cs b/docs/guides/int_framework/samples/intro/button.cs new file mode 100644 index 000000000..2b04d081b --- /dev/null +++ b/docs/guides/int_framework/samples/intro/button.cs @@ -0,0 +1,5 @@ +[ComponentInteraction("player:*,*")] +public async Task Play(string op, string name) +{ + ... +} diff --git a/docs/guides/int_framework/samples/intro/channelattribute.cs b/docs/guides/int_framework/samples/intro/channelattribute.cs new file mode 100644 index 000000000..09eb0275f --- /dev/null +++ b/docs/guides/int_framework/samples/intro/channelattribute.cs @@ -0,0 +1,5 @@ +[SlashCommand("name", "Description")] +public async Task Command([ChannelTypes(ChannelType.Stage, ChannelType.Text)] IChannel channel) +{ + ... +} diff --git a/docs/guides/int_framework/samples/intro/context.cs b/docs/guides/int_framework/samples/intro/context.cs new file mode 100644 index 000000000..5976ffc5c --- /dev/null +++ b/docs/guides/int_framework/samples/intro/context.cs @@ -0,0 +1,14 @@ +discordClient.ButtonExecuted += async (interaction) => +{ + var ctx = new SocketInteractionContext(discordClient, interaction); + await _interactionService.ExecuteAsync(ctx, serviceProvider); +}; + +public class MessageComponentModule : InteractionModuleBase> +{ + [ComponentInteraction("custom_id")] + public async Command() + { + Context.Interaction.UpdateAsync(...); + } +} diff --git a/docs/guides/int_framework/samples/intro/dropdown.cs b/docs/guides/int_framework/samples/intro/dropdown.cs new file mode 100644 index 000000000..2b0af477f --- /dev/null +++ b/docs/guides/int_framework/samples/intro/dropdown.cs @@ -0,0 +1,11 @@ +[ComponentInteraction("role_selection")] +public async Task RoleSelection(string[] selectedRoles) +{ + ... +} + +[ComponentInteraction("role_selection_*")] +public async Task RoleSelection(string id, string[] selectedRoles) +{ + ... +} diff --git a/docs/guides/int_framework/samples/intro/groupattribute.cs b/docs/guides/int_framework/samples/intro/groupattribute.cs new file mode 100644 index 000000000..86a492c31 --- /dev/null +++ b/docs/guides/int_framework/samples/intro/groupattribute.cs @@ -0,0 +1,21 @@ +[SlashCommand("blep", "Send a random adorable animal photo")] +public async Task Blep([Choice("Dog", "dog"), Choice("Cat", "cat"), Choice("Penguin", "penguin")] string animal) +{ + ... +} + +// In most cases, you can use an enum to replace the seperate choice attributes in a command. + +public enum Animal +{ + Cat, + Dog, + Penguin +} + +[SlashCommand("blep", "Send a random adorable animal photo")] +public async Task Blep(Animal animal) +{ + ... +} +``` diff --git a/docs/guides/int_framework/samples/intro/messagecommand.cs b/docs/guides/int_framework/samples/intro/messagecommand.cs new file mode 100644 index 000000000..5cb0c4b60 --- /dev/null +++ b/docs/guides/int_framework/samples/intro/messagecommand.cs @@ -0,0 +1,5 @@ +[MessageCommand("Bookmark")] +public async Task Bookmark(IMessage msg) +{ + ... +} diff --git a/docs/guides/int_framework/samples/intro/registering.cs b/docs/guides/int_framework/samples/intro/registering.cs new file mode 100644 index 000000000..f603df7bf --- /dev/null +++ b/docs/guides/int_framework/samples/intro/registering.cs @@ -0,0 +1,5 @@ +#if DEBUG + await interactionService.RegisterCommandsToGuildAsync(); +#else + await interactionService.RegisterCommandsGloballyAsync(); +#endif diff --git a/docs/guides/int_framework/samples/intro/slashcommand.cs b/docs/guides/int_framework/samples/intro/slashcommand.cs new file mode 100644 index 000000000..5f4f7fb0f --- /dev/null +++ b/docs/guides/int_framework/samples/intro/slashcommand.cs @@ -0,0 +1,5 @@ +[SlashCommand("echo", "Echo an input")] +public async Task Echo(string input) +{ + await RespondAsync(input); +} diff --git a/docs/guides/int_framework/samples/intro/summaryattribute.cs b/docs/guides/int_framework/samples/intro/summaryattribute.cs new file mode 100644 index 000000000..8a9b7d3e1 --- /dev/null +++ b/docs/guides/int_framework/samples/intro/summaryattribute.cs @@ -0,0 +1 @@ +[Summary(description: "this is a parameter description")] string input diff --git a/docs/guides/int_framework/samples/intro/usercommand.cs b/docs/guides/int_framework/samples/intro/usercommand.cs new file mode 100644 index 000000000..02c4a1e63 --- /dev/null +++ b/docs/guides/int_framework/samples/intro/usercommand.cs @@ -0,0 +1,5 @@ +[UserCommand("Say Hello")] +public async Task SayHello(IUser user) +{ + ... +} diff --git a/docs/guides/int_framework/samples/postexecution/error_review.cs b/docs/guides/int_framework/samples/postexecution/error_review.cs new file mode 100644 index 000000000..dd397b2c9 --- /dev/null +++ b/docs/guides/int_framework/samples/postexecution/error_review.cs @@ -0,0 +1,28 @@ +interactionService.SlashCommandExecuted += SlashCommandExecuted; + +async Task SlashCommandExecuted(SlashCommandInfo arg1, Discord.IInteractionContext arg2, IResult arg3) +{ + if (!arg3.IsSuccess) + { + switch (arg3.Error) + { + case InteractionCommandError.UnmetPrecondition: + await arg2.Interaction.RespondAsync($"Unmet Precondition: {arg3.ErrorReason}"); + break; + case InteractionCommandError.UnknownCommand: + await arg2.Interaction.RespondAsync("Unknown command"); + break; + case InteractionCommandError.BadArgs: + await arg2.Interaction.RespondAsync("Invalid number or arguments"); + break; + case InteractionCommandError.Exception: + await arg2.Interaction.RespondAsync("Command exception:{arg3.ErrorReason}"); + break; + case InteractionCommandError.Unsuccessful: + await arg2.Interaction.RespondAsync("Command could not be executed"); + break; + default: + break; + } + } +} diff --git a/docs/guides/commands/samples/preconditions/group_precondition.cs b/docs/guides/int_framework/samples/preconditions/group_precondition.cs similarity index 100% rename from docs/guides/commands/samples/preconditions/group_precondition.cs rename to docs/guides/int_framework/samples/preconditions/group_precondition.cs diff --git a/docs/guides/int_framework/samples/preconditions/precondition_usage.cs b/docs/guides/int_framework/samples/preconditions/precondition_usage.cs new file mode 100644 index 000000000..bea2918dc --- /dev/null +++ b/docs/guides/int_framework/samples/preconditions/precondition_usage.cs @@ -0,0 +1,3 @@ +[RequireOwner] +[SlashCommand("hi")] +public Task SayHiAsync() => RespondAsync("hello owner!"); diff --git a/docs/guides/int_framework/samples/typeconverters/enum_converter.cs b/docs/guides/int_framework/samples/typeconverters/enum_converter.cs new file mode 100644 index 000000000..6e1b9ded6 --- /dev/null +++ b/docs/guides/int_framework/samples/typeconverters/enum_converter.cs @@ -0,0 +1,30 @@ +internal sealed class EnumConverter : TypeConverter where T : struct, Enum +{ + public override ApplicationCommandOptionType GetDiscordType() => ApplicationCommandOptionType.String; + + public override Task ReadAsync(IInteractionCommandContext context, SocketSlashCommandDataOption option, IServiceProvider services) + { + if (Enum.TryParse((string)option.Value, out var result)) + return Task.FromResult(TypeConverterResult.FromSuccess(result)); + else + return Task.FromResult(TypeConverterResult.FromError(InteractionCommandError.ConvertFailed, $"Value {option.Value} cannot be converted to {nameof(T)}")); + } + + public override void Write(ApplicationCommandOptionProperties properties, IParameterInfo parameterInfo) + { + var names = Enum.GetNames(typeof(T)); + if (names.Length <= 25) + { + var choices = new List(); + + foreach (var name in names) + choices.Add(new ApplicationCommandOptionChoiceProperties + { + Name = name, + Value = name + }); + + properties.Choices = choices; + } + } +} diff --git a/docs/guides/int_framework/typeconverters.md b/docs/guides/int_framework/typeconverters.md new file mode 100644 index 000000000..96bdcb906 --- /dev/null +++ b/docs/guides/int_framework/typeconverters.md @@ -0,0 +1,118 @@ +--- +uid: Guides.IntFw.TypeConverters +title: Parameter Type Converters +--- + +# TypeConverters + +[TypeConverters] are responsible for registering command parameters to Discord and parsing the user inputs into method parameters. + +By default, TypeConverters for the following types are provided with @Discord.Interactions library. + +- Implementations of [IUser] +- Implementations of [IChannel] +- Implementations of [IRole] +- Implementations of [IMentionable] +- `string` +- `float`, `double`, `decimal` +- `bool` +- `char` +- `sbyte`, `byte` +- `int16`, `int32`, `int64` +- `uint16`, `uint32`, `uint64` +- `enum` +- `DateTime` +- `TimeSpan` + +## Creating TypeConverters + +Depending on your needs, there are two types of TypeConverters you can create: + +- Concrete type +- Generic type + +A valid converter must inherit [TypeConverter] base type. And override the abstract base methods. + +### CanConvertTo() Method + +This method is used by Interaction Service to search for alternative Type Converters. + +Interaction Services determines the most suitable [TypeConverter] for a parameter type in the following order: + +1. It searches for a [TypeConverter] that is registered to specifically target that parameter type +2. It searches for a [TypeConverter] that returns `true` when its `CanConvertTo()` method is invoked for thaty parameter type. +3. It searches for a generic `TypeConverter` with a matching type constraint. If there are more multiple matches, +the one whose type constraint is the most specialized will be chosen. + +> [!NOTE} +> Alternatively, you can use the generic variant (`TypeConverter`) of the +> [TypeConverter] base class which implements the following method body for `CanConvertTo()` method + +```csharp +public sealed override bool CanConvertTo (Type type) => + typeof(T).IsAssignableFrom(type); +``` + +### GetDiscordType() Method + +This method is used by [InteractionService] to determine the +[Discord Application Command Option type](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-type) +of a parameter type. + +### ReadAsync() Method + +This method is used by [InteractionService] to parse the user input. +This method should return @Discord.Interactions.TypeConverterResult.FromSuccess* if the parsing operation is successful, +otherwise it should return @Discord.Interactions.TypeConverterResult.FromError* . +The inner logic of this method is totally up to you, +however you should avoid using long running code. + +### Write() Method + +This method is used to configure the **Discord Application Command Option** before it gets registered to Discord. +Command Option is configured by modifying the `ApplicationCommandOptionProperties` instance. + +> [!WARNING] +> The default parameter building pipeline is isolated and will not be disturbed by the [TypeConverter] workflow. +> But changes made in this method will override the values generated by the +> [InteractionService] for a **Discord Application Command Option**. + +## Example Enum TypeConverter + +[!code-csharp[Enum Converter](samples/typeconverters/enum_converter.cs)] + +> [!IMPORTANT] +> TypeConverters must be registered prior to module discovery. +> If Interaction Service encounters a parameter type that doesn't belong to any of the +> registered [TypeConverters] during this phase, it will throw an exception. + +## Concrete TypeConverters + +Registering Concrete TypeConverters are as simple as creating an instance of your custom converter and invoking `AddTypeConverter()` method. + +```csharp +interactionService.AddTypeConverter(new StringArrayConverter()); +``` + +## Generic TypeConverters + +To register a generic `TypeConverter`, you need to invoke the `AddGenericTypeConverter()` method of the Interaction Service class. +You need to pass the type of your `TypeConverter` and a target base type to this method. + +For instance, to register the previously mentioned enum converter the following can be used: + +```csharp +interactionService.AddGenericTypeConverter(typeof(EnumConverter<>)); +``` + +Interaction service checks if the target base type satisfies the type constraints of the Generic `TypeConverter` class. + +> [!NOTE] +> Dependencies of Generic TypeConverters are also resolved using the Dependency Injection pattern. + +[TypeConverter]: xref:Discord.Interactions.TypeConverter +[InteractionService]: xref:Discord.Interactions.InteractionService +[IChannel]: xref:Discord.IChannel +[IRole]: xref:Discord.IRole +[IUser]: xref:Discord.IUser +[IMentionable]: xref:Discord.IMentionable diff --git a/docs/guides/introduction/intro.md b/docs/guides/introduction/intro.md index 0a4ca26e9..0bc1b90f6 100644 --- a/docs/guides/introduction/intro.md +++ b/docs/guides/introduction/intro.md @@ -23,7 +23,7 @@ in [our GitHub repository]. > Please note that you should *not* try to blindly copy paste > the code. The examples are meant to be a template or a guide. -[our GitHub repository]: https://github.com/RogueException/Discord.Net/tree/dev/samples +[our GitHub repository]: https://github.com/discord-net/Discord.Net/ [Task-based Asynchronous Pattern]: https://docs.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/task-based-asynchronous-pattern-tap [polymorphism]: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/polymorphism [interface]: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/interfaces/ @@ -44,8 +44,5 @@ resources to get you started. ## Still have questions? -Please visit us at `#dotnet_discord-net` on the [Discord API] server. -Describe the problem in details to us, what you've done, and, -if any, the problematic code uploaded onto [Hastebin](https://hastebin.com). - -[Discord API]: https://discord.gg/jkrBmQR \ No newline at end of file +Please visit us at our [Discord](https://discord.gg/dnet) server. +Describe the problem in details to us, what you've tried and what you need help with. diff --git a/docs/guides/commands/dependency-injection.md b/docs/guides/text_commands/dependency-injection.md similarity index 85% rename from docs/guides/commands/dependency-injection.md rename to docs/guides/text_commands/dependency-injection.md index 5dc5b02d2..3253643ef 100644 --- a/docs/guides/commands/dependency-injection.md +++ b/docs/guides/text_commands/dependency-injection.md @@ -1,14 +1,18 @@ --- -uid: Guides.Commands.DI +uid: Guides.TextCommands.DI title: Dependency Injection --- # Dependency Injection -The Command Service is bundled with a very barebone Dependency +The Text Command Service is bundled with a very barebone Dependency Injection service for your convenience. It is recommended that you use DI when writing your modules. +> [!WARNING] +> If you were brought here from the Interaction Service guides, +> make sure to replace all namespaces that imply `Discord.Commands` with `Discord.Interactions` + ## Setup 1. Create a @Microsoft.Extensions.DependencyInjection.ServiceCollection. @@ -44,4 +48,4 @@ manner. [!code-csharp[Injection Modules](samples/dependency-injection/dependency_module.cs)] [!code-csharp[Disallow Dependency Injection](samples/dependency-injection/dependency_module_noinject.cs)] -[DontInjectAttribute]: xref:Discord.Commands.DontInjectAttribute \ No newline at end of file +[DontInjectAttribute]: xref:Discord.Commands.DontInjectAttribute diff --git a/docs/guides/commands/intro.md b/docs/guides/text_commands/intro.md similarity index 96% rename from docs/guides/commands/intro.md rename to docs/guides/text_commands/intro.md index abe7065c1..6632c127a 100644 --- a/docs/guides/commands/intro.md +++ b/docs/guides/text_commands/intro.md @@ -1,9 +1,9 @@ --- -uid: Guides.Commands.Intro -title: Introduction to Command Service +uid: Guides.TextCommands.Intro +title: Introduction to the Chat Command Service --- -# The Command Service +# The Text Command Service [Discord.Commands](xref:Discord.Commands) provides an attribute-based command parser. @@ -134,7 +134,7 @@ If, for whatever reason, you have two commands which are ambiguous to each other, you may use the @Discord.Commands.PriorityAttribute to specify which should be tested before the other. -The `Priority` attributes are sorted in ascending order; the higher +The `Priority` attributes are sorted in descending order; the higher priority will be called first. ### Command Context @@ -187,7 +187,7 @@ service provider. ### Module Constructors -Modules are constructed using @Guides.Commands.DI. Any parameters +Modules are constructed using [Dependency Injection](xref:Guides.TextCommands.DI). Any parameters that are placed in the Module's constructor must be injected into an @System.IServiceProvider first. diff --git a/docs/guides/commands/namedarguments.md b/docs/guides/text_commands/namedarguments.md similarity index 98% rename from docs/guides/commands/namedarguments.md rename to docs/guides/text_commands/namedarguments.md index 890a8463f..18281d664 100644 --- a/docs/guides/commands/namedarguments.md +++ b/docs/guides/text_commands/namedarguments.md @@ -1,5 +1,5 @@ --- -uid: Guides.Commands.NamedArguments +uid: Guides.TextCommands.NamedArguments title: Named Arguments --- diff --git a/docs/guides/commands/post-execution.md b/docs/guides/text_commands/post-execution.md similarity index 97% rename from docs/guides/commands/post-execution.md rename to docs/guides/text_commands/post-execution.md index 782d256b2..49fe2f5f9 100644 --- a/docs/guides/commands/post-execution.md +++ b/docs/guides/text_commands/post-execution.md @@ -1,9 +1,9 @@ --- -uid: Guides.Commands.PostExecution +uid: Guides.TextCommands.PostExecution title: Post-command Execution Handling --- -# Post-execution Handling for Commands +# Post-execution Handling for Text Commands When developing commands, you may want to consider building a post-execution handling system so you can have finer control @@ -117,4 +117,4 @@ of the command. [CommandExecuted]: xref:Discord.Commands.CommandService.CommandExecuted [ExecuteAsync]: xref:Discord.Commands.CommandService.ExecuteAsync* [ExecuteResult]: xref:Discord.Commands.ExecuteResult -[Command Guide]: xref:Guides.Commands.Intro \ No newline at end of file +[Command Guide]: xref:Guides.TextCommands.Intro diff --git a/docs/guides/commands/preconditions.md b/docs/guides/text_commands/preconditions.md similarity index 98% rename from docs/guides/commands/preconditions.md rename to docs/guides/text_commands/preconditions.md index 8e8298b86..4be7ca2bb 100644 --- a/docs/guides/commands/preconditions.md +++ b/docs/guides/text_commands/preconditions.md @@ -1,5 +1,5 @@ --- -uid: Guides.Commands.Preconditions +uid: Guides.TextCommands.Preconditions title: Preconditions --- diff --git a/docs/guides/commands/samples/dependency-injection/dependency_map_setup.cs b/docs/guides/text_commands/samples/dependency-injection/dependency_map_setup.cs similarity index 100% rename from docs/guides/commands/samples/dependency-injection/dependency_map_setup.cs rename to docs/guides/text_commands/samples/dependency-injection/dependency_map_setup.cs diff --git a/docs/guides/commands/samples/dependency-injection/dependency_module.cs b/docs/guides/text_commands/samples/dependency-injection/dependency_module.cs similarity index 100% rename from docs/guides/commands/samples/dependency-injection/dependency_module.cs rename to docs/guides/text_commands/samples/dependency-injection/dependency_module.cs diff --git a/docs/guides/commands/samples/dependency-injection/dependency_module_noinject.cs b/docs/guides/text_commands/samples/dependency-injection/dependency_module_noinject.cs similarity index 100% rename from docs/guides/commands/samples/dependency-injection/dependency_module_noinject.cs rename to docs/guides/text_commands/samples/dependency-injection/dependency_module_noinject.cs diff --git a/docs/guides/commands/samples/intro/command_handler.cs b/docs/guides/text_commands/samples/intro/command_handler.cs similarity index 100% rename from docs/guides/commands/samples/intro/command_handler.cs rename to docs/guides/text_commands/samples/intro/command_handler.cs diff --git a/docs/guides/commands/samples/intro/empty-module.cs b/docs/guides/text_commands/samples/intro/empty-module.cs similarity index 100% rename from docs/guides/commands/samples/intro/empty-module.cs rename to docs/guides/text_commands/samples/intro/empty-module.cs diff --git a/docs/guides/commands/samples/intro/groups.cs b/docs/guides/text_commands/samples/intro/groups.cs similarity index 100% rename from docs/guides/commands/samples/intro/groups.cs rename to docs/guides/text_commands/samples/intro/groups.cs diff --git a/docs/guides/commands/samples/intro/module.cs b/docs/guides/text_commands/samples/intro/module.cs similarity index 100% rename from docs/guides/commands/samples/intro/module.cs rename to docs/guides/text_commands/samples/intro/module.cs diff --git a/docs/guides/commands/samples/post-execution/command_exception_log.cs b/docs/guides/text_commands/samples/post-execution/command_exception_log.cs similarity index 100% rename from docs/guides/commands/samples/post-execution/command_exception_log.cs rename to docs/guides/text_commands/samples/post-execution/command_exception_log.cs diff --git a/docs/guides/commands/samples/post-execution/command_executed_adv_demo.cs b/docs/guides/text_commands/samples/post-execution/command_executed_adv_demo.cs similarity index 100% rename from docs/guides/commands/samples/post-execution/command_executed_adv_demo.cs rename to docs/guides/text_commands/samples/post-execution/command_executed_adv_demo.cs diff --git a/docs/guides/commands/samples/post-execution/command_executed_demo.cs b/docs/guides/text_commands/samples/post-execution/command_executed_demo.cs similarity index 100% rename from docs/guides/commands/samples/post-execution/command_executed_demo.cs rename to docs/guides/text_commands/samples/post-execution/command_executed_demo.cs diff --git a/docs/guides/commands/samples/post-execution/customresult_base.cs b/docs/guides/text_commands/samples/post-execution/customresult_base.cs similarity index 100% rename from docs/guides/commands/samples/post-execution/customresult_base.cs rename to docs/guides/text_commands/samples/post-execution/customresult_base.cs diff --git a/docs/guides/commands/samples/post-execution/customresult_extended.cs b/docs/guides/text_commands/samples/post-execution/customresult_extended.cs similarity index 100% rename from docs/guides/commands/samples/post-execution/customresult_extended.cs rename to docs/guides/text_commands/samples/post-execution/customresult_extended.cs diff --git a/docs/guides/commands/samples/post-execution/customresult_usage.cs b/docs/guides/text_commands/samples/post-execution/customresult_usage.cs similarity index 100% rename from docs/guides/commands/samples/post-execution/customresult_usage.cs rename to docs/guides/text_commands/samples/post-execution/customresult_usage.cs diff --git a/docs/guides/commands/samples/post-execution/post-execution_basic.cs b/docs/guides/text_commands/samples/post-execution/post-execution_basic.cs similarity index 100% rename from docs/guides/commands/samples/post-execution/post-execution_basic.cs rename to docs/guides/text_commands/samples/post-execution/post-execution_basic.cs diff --git a/docs/guides/text_commands/samples/preconditions/group_precondition.cs b/docs/guides/text_commands/samples/preconditions/group_precondition.cs new file mode 100644 index 000000000..bae102b9a --- /dev/null +++ b/docs/guides/text_commands/samples/preconditions/group_precondition.cs @@ -0,0 +1,9 @@ +// The following example only requires the user to either have the +// Administrator permission in this guild or own the bot application. +[RequireUserPermission(GuildPermission.Administrator, Group = "Permission")] +[RequireOwner(Group = "Permission")] +public class AdminModule : ModuleBase +{ + [Command("ban")] + public Task BanAsync(IUser user) => Context.Guild.AddBanAsync(user); +} \ No newline at end of file diff --git a/docs/guides/commands/samples/preconditions/precondition_usage.cs b/docs/guides/text_commands/samples/preconditions/precondition_usage.cs similarity index 100% rename from docs/guides/commands/samples/preconditions/precondition_usage.cs rename to docs/guides/text_commands/samples/preconditions/precondition_usage.cs diff --git a/docs/guides/commands/samples/preconditions/require_role.cs b/docs/guides/text_commands/samples/preconditions/require_role.cs similarity index 100% rename from docs/guides/commands/samples/preconditions/require_role.cs rename to docs/guides/text_commands/samples/preconditions/require_role.cs diff --git a/docs/guides/commands/samples/typereaders/typereader-register.cs b/docs/guides/text_commands/samples/typereaders/typereader-register.cs similarity index 100% rename from docs/guides/commands/samples/typereaders/typereader-register.cs rename to docs/guides/text_commands/samples/typereaders/typereader-register.cs diff --git a/docs/guides/commands/samples/typereaders/typereader.cs b/docs/guides/text_commands/samples/typereaders/typereader.cs similarity index 100% rename from docs/guides/commands/samples/typereaders/typereader.cs rename to docs/guides/text_commands/samples/typereaders/typereader.cs diff --git a/docs/guides/commands/typereaders.md b/docs/guides/text_commands/typereaders.md similarity index 97% rename from docs/guides/commands/typereaders.md rename to docs/guides/text_commands/typereaders.md index f942c9341..bf911dac7 100644 --- a/docs/guides/commands/typereaders.md +++ b/docs/guides/text_commands/typereaders.md @@ -1,5 +1,5 @@ --- -uid: Guides.Commands.TypeReaders +uid: Guides.TextCommands.TypeReaders title: Type Readers --- @@ -67,4 +67,4 @@ To register a TypeReader, invoke [CommandService.AddTypeReader]. ### Example - Adding a Type Reader -[!code-csharp[Adding TypeReaders](samples/typereaders/typereader-register.cs)] \ No newline at end of file +[!code-csharp[Adding TypeReaders](samples/typereaders/typereader-register.cs)] diff --git a/docs/guides/toc.yml b/docs/guides/toc.yml index a6c38768f..cf4ea5516 100644 --- a/docs/guides/toc.yml +++ b/docs/guides/toc.yml @@ -1,12 +1,14 @@ - name: Introduction topicUid: Guides.Introduction +- name: V2 to V3 Guide + topicUid: Guides.V2V3Guide - name: Getting Started items: - name: Installation topicUid: Guides.GettingStarted.Installation items: - - name: Nightly Builds - topicUid: Guides.GettingStarted.Installation.Nightlies + - name: Nightly builds + topicUid: Guides.GettingStarted.Installation.Labs - name: Your First Bot topicUid: Guides.GettingStarted.FirstBot - name: Terminology @@ -21,23 +23,83 @@ topicUid: Guides.Concepts.ManageConnections - name: Entities topicUid: Guides.Concepts.Entities -- name: Working with Commands +- name: Working with Text-based Commands items: - name: Introduction - topicUid: Guides.Commands.Intro + topicUid: Guides.TextCommands.Intro - name: TypeReaders - topicUid: Guides.Commands.TypeReaders + topicUid: Guides.TextCommands.TypeReaders - name: Named Arguments - topicUid: Guides.Commands.NamedArguments + topicUid: Guides.TextCommands.NamedArguments - name: Preconditions - topicUid: Guides.Commands.Preconditions + topicUid: Guides.TextCommands.Preconditions - name: Dependency Injection - topicUid: Guides.Commands.DI + topicUid: Guides.TextCommands.DI - name: Post-execution Handling - topicUid: Guides.Commands.PostExecution + topicUid: Guides.TextCommands.PostExecution +- name: Working with the Interaction Framework + items: + - name: Introduction + topicUid: Guides.IntFw.Intro + - name: Auto-Completion + topicUid: Guides.IntFw.AutoCompletion + - name: TypeConverters + topicUid: Guides.IntFw.TypeConverters + - name: Preconditions + topicUid: Guides.IntFw.Preconditions + - name: Dependency Injection + topicUid: Guides.IntFw.DI + - name: Post-execution Handling + topicUid: Guides.IntFw.PostExecution +- name: Slash Command Basics + items: + - name: Introduction + topicUid: Guides.SlashCommands.Intro + - name: Creating slash commands + topicUid: Guides.SlashCommands.Creating + - name: Receiving and responding to slash commands + topicUid: Guides.SlashCommands.Receiving + - name: Slash command parameters + topicUid: Guides.SlashCommands.Parameters + - name: Ephemeral responses + topicUid: Guides.SlashCommands.Ephemeral + - name: Sub commands + topicUid: Guides.SlashCommands.SubCommand + - name: Slash command choices + topicUid: Guides.SlashCommands.Choices + - name: Slash commands Bulk Overwrites + topicUid: Guides.SlashCommands.BulkOverwrite +- name: Context Command Basics + items: + - name: Creating Context Commands + topicUid: Guides.ContextCommands.Creating + - name: Receiving Context Commands + topicUid: Guides.ContextCommands.Reveiving +- name: Message Component Basics + items: + - name: Introduction + topicUid: Guides.MessageComponents.Intro + - name: Responding to Components + topicUid: Guides.MessageComponents.Responding + - name: Buttons in depth + topicUid: Guides.MessageComponents.Buttons + - name: Select menus + topicUid: Guides.MessageComponents.SelectMenus + - name: Advanced Concepts + topicUid: Guides.MessageComponents.Advanced +- name: Guild Events + items: + - name: Introduction + topicUid: Guides.GuildEvents.Intro + - name: Creating Events + topicUid: Guides.GuildEvents.Creating + - name: Getting Event Users + topicUid: Guides.GuildEvents.GettingUsers + - name: Modifying Events + topicUid: Guides.GuildEvents.Modifying - name: Emoji topicUid: Guides.Emoji - name: Voice topicUid: Guides.Voice.SendingVoice - name: Deployment - topicUid: Guides.Deployment \ No newline at end of file + topicUid: Guides.Deployment diff --git a/docs/guides/v2_v3_guide/v2_to_v3_guide.md b/docs/guides/v2_v3_guide/v2_to_v3_guide.md new file mode 100644 index 000000000..915c4a57f --- /dev/null +++ b/docs/guides/v2_v3_guide/v2_to_v3_guide.md @@ -0,0 +1,85 @@ +--- +uid: Guides.V2V3Guide +title: V2 -> V3 Guide +--- + +# V2 to V3 Guide + +V3 is designed to be a more feature complete, more reliable, +and more flexible library than any previous version. + +Below are the most notable breaking changes that you would need to update your code to work with V3. + +### GatewayIntents + +As Discord.NET has upgraded from Discord API v6 to API v9, +`GatewayIntents` must now be specified in the socket config, as well as on the [developer portal]. + +```cs + +// Where ever you declared your websocket client. +DiscordSocketClient _client; + +... + +var config = new DiscordSocketConfig() +{ + .. // Other config options can be presented here. + GatewayIntents = GatewayIntents.All +} + +_client = new DiscordSocketClient(config); + +``` +#### Common intents: + +- AllUnprivileged: This is a group of most common intents, that do NOT require any [developer portal] intents to be enabled. +This includes intents that receive messages such as: `GatewayIntents.GuildMessages, GatewayIntents.DirectMessages` +- GuildMembers: An intent disabled by default, as you need to enable it in the [developer portal]. +- GuildPresences: Also disabled by default, this intent together with `GuildMembers` are the only intents not included in `AllUnprivileged`. +- All: All intents, it is ill adviced to use this without care, as it *can* cause a memory leak from presence. +The library will give responsive warnings if you specify unnecessary intents. + + +> [!NOTE] +> All gateway intents, their Discord API counterpart and their enum value are listed +> [HERE](xref:Discord.GatewayIntents) + +#### Stacking intents: + +It is common that you require several intents together. +The example below shows how this can be done. + +```cs + +GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.GuildMembers | .. + +``` + +> [!NOTE] +> Further documentation on the ` | ` operator can be found +> [HERE](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/bitwise-and-shift-operators) + +[developer portal]: https://discord.com/developers/ + +### ReactionAdded Event + +The reaction added event has been changed to have both parameters cacheable. +This allows you to download the channel and message if they aren't cached instead of them being null. + +### UserIsTyping Event + +The user is typing event has been changed to have both parameters cacheable. +This allows you to download the user and channel if they aren't cached instead of them being null. + +### Presence + +There is a new event called `PresenceUpdated` that is called when a user's presence changes, +instead of `GuildMemberUpdated` or `UserUpdated`. +If your code relied on these events to get presence data then you need to update it to work with the new event. + +## Migrating your commands to slash command + +The new InteractionService was designed to act like the previous service for text-based commands. +Your pre-existing code will continue to work, but you will need to migrate your modules and response functions to use the new +InteractionService methods. Docs on this can be found in the Guides section. diff --git a/docs/guides/voice/sending-voice.md b/docs/guides/voice/sending-voice.md index 476f2f42e..555adbca2 100644 --- a/docs/guides/voice/sending-voice.md +++ b/docs/guides/voice/sending-voice.md @@ -18,7 +18,7 @@ when developing on .NET Core, this is where you execute `dotnet run` from; typically the same directory as your csproj). For Windows Users, precompiled binaries are available for your -convienence [here](https://discord.foxbot.me/binaries/). +convienence [here](https://github.com/discord-net/Discord.Net/tree/dev/voice-natives). For Linux Users, you will need to compile [Sodium] and [Opus] from source, or install them from your package manager. diff --git a/docs/index.md b/docs/index.md index 34350df70..32b0498ea 100644 --- a/docs/index.md +++ b/docs/index.md @@ -3,20 +3,20 @@ uid: Root.Landing title: Home --- -# Discord.Net Documentation +# Discord.NET Documentation -[![GitHub](https://img.shields.io/github/last-commit/discord-net/discord.net?style=plastic)](https://github.com/discord-net/Discord.Net) +[![GitHub](https://img.shields.io/github/last-commit/discord-net/Discord.Net?style=plastic)](https://github.com/discord-net/Discord.Net) [![NuGet](https://img.shields.io/nuget/vpre/Discord.Net.svg?maxAge=2592000?style=plastic)](https://www.nuget.org/packages/Discord.Net) [![MyGet](https://img.shields.io/myget/discord-net/vpre/Discord.Net.svg)](https://www.myget.org/feed/Packages/discord-net) [![Build Status](https://dev.azure.com/discord-net/Discord.Net/_apis/build/status/discord-net.Discord.Net?branchName=dev)](https://dev.azure.com/discord-net/Discord.Net/_build/latest?definitionId=1&branchName=dev) -[![Discord](https://discordapp.com/api/guilds/81384788765712384/widget.png)](https://discord.gg/jkrBmQR) +[![Discord](https://discord.com/api/guilds/81384788765712384/widget.png)](https://discord.gg/dnet) -## What is Discord.Net? +## What is Discord.NET? Discord.Net is an asynchronous, multi-platform .NET Library used to -interface with the [Discord API](https://discordapp.com/). +interface with the [Discord API](https://discord.com/). ## Where to begin? @@ -26,3 +26,57 @@ If this is your first time using Discord.Net, you should refer to the More experienced users might want to refer to the [API Documentation](xref:API.Docs) for a breakdown of the individual objects in the library. + +## Nightlies + +Nightlies are builds of Discord.NET that are still in an experimental phase, and have not been released. +These are not included in the main repository, and are instead taken over by [Discord.NET Labs]. + +Discord.NET Labs is an experimental fork of Discord.NET that implements the newest discord features +for testing and development to eventually get merged into Discord.NET. + +[Installing Discord.NET Labs](xref:Guides.GettingStarted.Installation.Labs) + +[Discord.NET Labs]: https://github.com/Discord-Net-Labs/Discord.Net-Labs + +## Questions? + +Frequently asked questions are covered in the +FAQ. Read it thoroughly because most common questions are already answered there. + +If you still have unanswered questions after reading the [FAQ](xref:FAQ.Basics.GetStarted), further support is available on +[Discord](https://discord.gg/dnet). + +## Commonly used features + +#### Interaction Framework + +A counterpart to staple command service of Discord.NET, the Interaction Framework implements the same +feature-rich structure to register & handle interactions like Slash commands & buttons. + +- Read about the Interaction Framework + [here](xref:Guides.IntFw.Intro) + +#### Slash Commands + +Slash commands are purposed to take over the normal prefixed commands in Discord and comes with good functionality to serve as a replacement. +Being interactions, they are handled as SocketInteractions. Creating and receiving slashcommands is covered below. + +- Find out more about slash commands in the + [Slash Command Guides](xref:Guides.SlashCommands.Intro) + +#### Context Message & User Ccommands + +These commands can be pointed at messages and users, in custom application tabs. +Being interactions as well, they are able to be handled just like slash commands. They do not have options however. + +- Learn how to create and handle these commands in the + [Context Command Guides](xref:Guides.ContextCommands.Creating) + +#### Message Components + +Components of a message such as buttons and dropdowns, which can be interacted with and responded to. +Message components can be set in rows and multiple can exist on a single message! + +- Explanation on how to add & respond to message components can be found in the + [Message Component Guides](xref:Guides.MessageComponents.Intro) diff --git a/docs/marketing/logo/SVG/Combinationmark White Border.svg b/docs/marketing/logo/SVG/Combinationmark White Border.svg new file mode 100644 index 000000000..787803d4b --- /dev/null +++ b/docs/marketing/logo/SVG/Combinationmark White Border.svg @@ -0,0 +1,21 @@ + + + + + + Combinationmark White + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/toc.yml b/docs/toc.yml index bea010c5a..810995383 100644 --- a/docs/toc.yml +++ b/docs/toc.yml @@ -8,4 +8,4 @@ href: api/ topicUid: API.Docs - name: Changelog - topicHref: ../CHANGELOG.md \ No newline at end of file + topicHref: ../CHANGELOG.md diff --git a/samples/01_basic_ping_bot/01_basic_ping_bot.csproj b/samples/01_basic_ping_bot/01_basic_ping_bot.csproj index 4b4e35e3f..6e1a6365f 100644 --- a/samples/01_basic_ping_bot/01_basic_ping_bot.csproj +++ b/samples/01_basic_ping_bot/01_basic_ping_bot.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.0 + net5.0 diff --git a/samples/02_commands_framework/02_commands_framework.csproj b/samples/02_commands_framework/02_commands_framework.csproj index 84b30aa99..30c25e846 100644 --- a/samples/02_commands_framework/02_commands_framework.csproj +++ b/samples/02_commands_framework/02_commands_framework.csproj @@ -2,11 +2,11 @@ Exe - netcoreapp3.0 + net5.0 - + diff --git a/samples/02_commands_framework/Modules/PublicModule.cs b/samples/02_commands_framework/Modules/PublicModule.cs index b9263649f..18423f609 100644 --- a/samples/02_commands_framework/Modules/PublicModule.cs +++ b/samples/02_commands_framework/Modules/PublicModule.cs @@ -31,7 +31,7 @@ namespace _02_commands_framework.Modules [Command("userinfo")] public async Task UserInfoAsync(IUser user = null) { - user = user ?? Context.User; + user ??= Context.User; await ReplyAsync(user.ToString()); } diff --git a/samples/02_commands_framework/Program.cs b/samples/02_commands_framework/Program.cs index 67cb87764..8a2f37dce 100644 --- a/samples/02_commands_framework/Program.cs +++ b/samples/02_commands_framework/Program.cs @@ -39,7 +39,7 @@ namespace _02_commands_framework services.GetRequiredService().Log += LogAsync; // Tokens should be considered secret data and never hard-coded. - // We can read from the environment variable to avoid hardcoding. + // We can read from the environment variable to avoid hard coding. await client.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("token")); await client.StartAsync(); diff --git a/samples/03_sharded_client/03_sharded_client.csproj b/samples/03_sharded_client/03_sharded_client.csproj index a6599c117..c4c42516e 100644 --- a/samples/03_sharded_client/03_sharded_client.csproj +++ b/samples/03_sharded_client/03_sharded_client.csproj @@ -2,12 +2,12 @@ Exe - netcoreapp3.0 + net5.0 _03_sharded_client - + diff --git a/samples/03_sharded_client/Modules/PublicModule.cs b/samples/03_sharded_client/Modules/PublicModule.cs index 60e57563a..fad2ba98c 100644 --- a/samples/03_sharded_client/Modules/PublicModule.cs +++ b/samples/03_sharded_client/Modules/PublicModule.cs @@ -9,7 +9,7 @@ namespace _03_sharded_client.Modules [Command("info")] public async Task InfoAsync() { - var msg = $@"Hi {Context.User}! There are currently {Context.Client.Shards} shards! + var msg = $@"Hi {Context.User}! There are currently {Context.Client.Shards.Count} shards! This guild is being served by shard number {Context.Client.GetShardFor(Context.Guild).ShardId}"; await ReplyAsync(msg); } diff --git a/samples/03_sharded_client/Services/CommandHandlingService.cs b/samples/03_sharded_client/Services/CommandHandlingService.cs index 1230cbcff..adc91b12c 100644 --- a/samples/03_sharded_client/Services/CommandHandlingService.cs +++ b/samples/03_sharded_client/Services/CommandHandlingService.cs @@ -54,7 +54,7 @@ namespace _03_sharded_client.Services if (!command.IsSpecified) return; - // the command was succesful, we don't care about this result, unless we want to log that a command succeeded. + // the command was successful, we don't care about this result, unless we want to log that a command succeeded. if (result.IsSuccess) return; diff --git a/samples/04_interactions_framework/04_interactions_framework.csproj b/samples/04_interactions_framework/04_interactions_framework.csproj new file mode 100644 index 000000000..780ab69bd --- /dev/null +++ b/samples/04_interactions_framework/04_interactions_framework.csproj @@ -0,0 +1,25 @@ + + + + Exe + net5.0 + _04_interactions_framework + + + + + + + + + + + + + + + + + + + diff --git a/samples/04_interactions_framework/CommandHandler.cs b/samples/04_interactions_framework/CommandHandler.cs new file mode 100644 index 000000000..735557da5 --- /dev/null +++ b/samples/04_interactions_framework/CommandHandler.cs @@ -0,0 +1,146 @@ +using Discord; +using Discord.Interactions; +using Discord.WebSocket; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace _04_interactions_framework +{ + public class CommandHandler + { + private readonly DiscordSocketClient _client; + private readonly InteractionService _commands; + private readonly IServiceProvider _services; + + public CommandHandler(DiscordSocketClient client, InteractionService commands, IServiceProvider services) + { + _client = client; + _commands = commands; + _services = services; + } + + public async Task InitializeAsync ( ) + { + // Add the public modules that inherit InteractionModuleBase to the InteractionService + await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _services); + + // Process the InteractionCreated payloads to execute Interactions commands + _client.InteractionCreated += HandleInteraction; + + // Process the command execution results + _commands.SlashCommandExecuted += SlashCommandExecuted; + _commands.ContextCommandExecuted += ContextCommandExecuted; + _commands.ComponentCommandExecuted += ComponentCommandExecuted; + } + + private Task ComponentCommandExecuted (ComponentCommandInfo arg1, Discord.IInteractionContext arg2, IResult arg3) + { + if (!arg3.IsSuccess) + { + switch (arg3.Error) + { + case InteractionCommandError.UnmetPrecondition: + // implement + break; + case InteractionCommandError.UnknownCommand: + // implement + break; + case InteractionCommandError.BadArgs: + // implement + break; + case InteractionCommandError.Exception: + // implement + break; + case InteractionCommandError.Unsuccessful: + // implement + break; + default: + break; + } + } + + return Task.CompletedTask; + } + + private Task ContextCommandExecuted (ContextCommandInfo arg1, Discord.IInteractionContext arg2, IResult arg3) + { + if (!arg3.IsSuccess) + { + switch (arg3.Error) + { + case InteractionCommandError.UnmetPrecondition: + // implement + break; + case InteractionCommandError.UnknownCommand: + // implement + break; + case InteractionCommandError.BadArgs: + // implement + break; + case InteractionCommandError.Exception: + // implement + break; + case InteractionCommandError.Unsuccessful: + // implement + break; + default: + break; + } + } + + return Task.CompletedTask; + } + + private Task SlashCommandExecuted (SlashCommandInfo arg1, Discord.IInteractionContext arg2, IResult arg3) + { + if (!arg3.IsSuccess) + { + switch (arg3.Error) + { + case InteractionCommandError.UnmetPrecondition: + // implement + break; + case InteractionCommandError.UnknownCommand: + // implement + break; + case InteractionCommandError.BadArgs: + // implement + break; + case InteractionCommandError.Exception: + // implement + break; + case InteractionCommandError.Unsuccessful: + // implement + break; + default: + break; + } + } + + return Task.CompletedTask; + } + + private async Task HandleInteraction (SocketInteraction arg) + { + try + { + // Create an execution context that matches the generic type parameter of your InteractionModuleBase modules + var ctx = new SocketInteractionContext(_client, arg); + await _commands.ExecuteCommandAsync(ctx, _services); + } + catch (Exception ex) + { + Console.WriteLine(ex); + + // If a Slash Command execution fails it is most likely that the original interaction acknowledgement will persist. It is a good idea to delete the original + // response, or at least let the user know that something went wrong during the command execution. + if(arg.Type == InteractionType.ApplicationCommand) + await arg.GetOriginalResponseAsync().ContinueWith(async (msg) => await msg.Result.DeleteAsync()); + } + } + } +} diff --git a/samples/04_interactions_framework/ExampleEnum.cs b/samples/04_interactions_framework/ExampleEnum.cs new file mode 100644 index 000000000..2ea5733c0 --- /dev/null +++ b/samples/04_interactions_framework/ExampleEnum.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _04_interactions_framework +{ + public enum ExampleEnum + { + First, + Second, + Third, + Fourth + } +} diff --git a/samples/04_interactions_framework/Modules/UtilityModule.cs b/samples/04_interactions_framework/Modules/UtilityModule.cs new file mode 100644 index 000000000..d6cbb1a9f --- /dev/null +++ b/samples/04_interactions_framework/Modules/UtilityModule.cs @@ -0,0 +1,93 @@ +using Discord; +using Discord.Interactions; +using Discord.WebSocket; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _04_interactions_framework.Modules +{ + // Interation modules must be public and inherit from an IInterationModuleBase + public class UtilityModule : InteractionModuleBase + { + // Dependencies can be accessed through Property injection, public properties with public setters will be set by the service provider + public InteractionService Commands { get; set; } + + private CommandHandler _handler; + + // Constructor injection is also a valid way to access the dependecies + public UtilityModule ( CommandHandler handler ) + { + _handler = handler; + } + + // Slash Commands are declared using the [SlashCommand], you need to provide a name and a description, both following the Discord guidelines + [SlashCommand("ping", "Recieve a pong")] + // By setting the DefaultPermission to false, you can disable the command by default. No one can use the command until you give them permission + [DefaultPermission(false)] + public async Task Ping ( ) + { + await RespondAsync("pong"); + } + + // You can use a number of parameter types in you Slash Command handlers (string, int, double, bool, IUser, IChannel, IMentionable, IRole, Enums) by default. Optionally, + // you can implement your own TypeConverters to support a wider range of parameter types. For more information, refer to the library documentation. + // Optional method parameters(parameters with a default value) also will be displayed as optional on Discord. + + // [Summary] lets you customize the name and the description of a parameter + [SlashCommand("echo", "Repeat the input")] + public async Task Echo(string echo, [Summary(description: "mention the user")]bool mention = false) + { + await RespondAsync(echo + (mention ? Context.User.Mention : string.Empty)); + } + + // [Group] will create a command group. [SlashCommand]s and [ComponentInteraction]s will be registered with the group prefix + [Group("test_group", "This is a command group")] + public class GroupExample : InteractionModuleBase + { + // You can create command choices either by using the [Choice] attribute or by creating an enum. Every enum with 25 or less values will be registered as a multiple + // choice option + [SlashCommand("choice_example", "Enums create choices")] + public async Task ChoiceExample(ExampleEnum input) + { + await RespondAsync(input.ToString()); + } + } + + // User Commands can only have one parameter, which must be a type of SocketUser + [UserCommand("SayHello")] + public async Task SayHello(IUser user) + { + await RespondAsync($"Hello, {user.Mention}"); + } + + // Message Commands can only have one parameter, which must be a type of SocketMessage + [MessageCommand("Delete")] + [RequireOwner] + public async Task DeleteMesage(IMessage message) + { + await message.DeleteAsync(); + await RespondAsync("Deleted message."); + } + + // Use [ComponentInteraction] to handle message component interactions. Message component interaction with the matching customId will be executed. + // Alternatively, you can create a wild card pattern using the '*' character. Interaction Service will perform a lazy regex search and capture the matching strings. + // You can then access these capture groups from the method parameters, in the order they were captured. Using the wild card pattern, you can cherry pick component interactions. + [ComponentInteraction("musicSelect:*,*")] + public async Task ButtonPress(string id, string name) + { + // ... + await RespondAsync($"Playing song: {name}/{id}"); + } + + // Select Menu interactions, contain ids of the menu options that were selected by the user. You can access the option ids from the method parameters. + // You can also use the wild card pattern with Select Menus, in that case, the wild card captures will be passed on to the method first, followed by the option ids. + [ComponentInteraction("roleSelect")] + public async Task RoleSelect(params string[] selections) + { + // implement + } + } +} diff --git a/samples/04_interactions_framework/Program.cs b/samples/04_interactions_framework/Program.cs new file mode 100644 index 000000000..5dedbfae9 --- /dev/null +++ b/samples/04_interactions_framework/Program.cs @@ -0,0 +1,85 @@ +using Discord; +using Discord.Interactions; +using Discord.WebSocket; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; + +namespace _04_interactions_framework +{ + class Program + { + static void Main ( string[] args ) + { + // One of the more flexable ways to access the configuration data is to use the Microsoft's Configuration model, + // this way we can avoid hard coding the environment secrets. I opted to use the Json and environment variable providers here. + IConfiguration config = new ConfigurationBuilder() + .AddEnvironmentVariables(prefix: "DC_") + .AddJsonFile("appsettings.json", optional: true) + .Build(); + + RunAsync(config).GetAwaiter().GetResult(); + } + + static async Task RunAsync (IConfiguration configuration ) + { + // Dependency injection is a key part of the Interactions framework but it needs to be disposed at the end of the app's lifetime. + using var services = ConfigureServices(configuration); + + var client = services.GetRequiredService(); + var commands = services.GetRequiredService(); + + client.Log += LogAsync; + commands.Log += LogAsync; + + // Slash Commands and Context Commands are can be automatically registered, but this process needs to happen after the client enters the READY state. + // Since Global Commands take around 1 hour to register, we should use a test guild to instantly update and test our commands. To determine the method we should + // register the commands with, we can check whether we are in a DEBUG environment and if we are, we can register the commands to a predetermined test guild. + client.Ready += async ( ) => + { + if (IsDebug()) + // Id of the test guild can be provided from the Configuration object + await commands.RegisterCommandsToGuildAsync(configuration.GetValue("testGuild"), true); + else + await commands.RegisterCommandsGloballyAsync(true); + }; + + // Here we can initialize the service that will register and execute our commands + await services.GetRequiredService().InitializeAsync(); + + // Bot token can be provided from the Configuration object we set up earlier + await client.LoginAsync(TokenType.Bot, configuration["token"]); + await client.StartAsync(); + + await Task.Delay(Timeout.Infinite); + } + + static Task LogAsync(LogMessage message) + { + Console.WriteLine(message.ToString()); + return Task.CompletedTask; + } + + static ServiceProvider ConfigureServices ( IConfiguration configuration ) + { + return new ServiceCollection() + .AddSingleton(configuration) + .AddSingleton() + .AddSingleton(x => new InteractionService(x.GetRequiredService())) + .AddSingleton() + .BuildServiceProvider(); + } + + static bool IsDebug ( ) + { + #if DEBUG + return true; + #else + return false; + #endif + } + } +} diff --git a/samples/04_interactions_framework/RequireOwnerAttribute.cs b/samples/04_interactions_framework/RequireOwnerAttribute.cs new file mode 100644 index 000000000..2f2493838 --- /dev/null +++ b/samples/04_interactions_framework/RequireOwnerAttribute.cs @@ -0,0 +1,27 @@ +using Discord; +using Discord.Interactions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _04_interactions_framework +{ + public class RequireOwnerAttribute : PreconditionAttribute + { + public override async Task CheckRequirementsAsync (IInteractionContext context, ICommandInfo commandInfo, IServiceProvider services) + { + switch (context.Client.TokenType) + { + case TokenType.Bot: + var application = await context.Client.GetApplicationInfoAsync().ConfigureAwait(false); + if (context.User.Id != application.Owner.Id) + return PreconditionResult.FromError(ErrorMessage ?? "Command can only be run by the owner of the bot."); + return PreconditionResult.FromSuccess(); + default: + return PreconditionResult.FromError($"{nameof(RequireOwnerAttribute)} is not supported by this {nameof(TokenType)}."); + } + } + } +} diff --git a/samples/04_webhook_client/Program.cs b/samples/04_webhook_client/Program.cs index c2e5faa03..f3a50036c 100644 --- a/samples/04_webhook_client/Program.cs +++ b/samples/04_webhook_client/Program.cs @@ -14,10 +14,10 @@ namespace _04_webhook_client public async Task MainAsync() { - // The webhook url follows the format https://discordapp.com/api/webhooks/{id}/{token} + // The webhook url follows the format https://discord.com/api/webhooks/{id}/{token} // Because anyone with the webhook URL can use your webhook - // you should NOT hard code the URL or ID + token into your application. - using (var client = new DiscordWebhookClient("https://discordapp.com/api/webhooks/123/abc123")) + // you should NOT hard code the URL or ID + token into your application. + using (var client = new DiscordWebhookClient("https://discord.com/api/webhooks/123/abc123")) { var embed = new EmbedBuilder { @@ -26,7 +26,7 @@ namespace _04_webhook_client }; // Webhooks are able to send multiple embeds per message - // As such, your embeds must be passed as a collection. + // As such, your embeds must be passed as a collection. await client.SendMessageAsync(text: "Send a message to this webhook!", embeds: new[] { embed.Build() }); } } diff --git a/samples/idn/Inspector.cs b/samples/idn/Inspector.cs index 3806e0e79..1544c8d07 100644 --- a/samples/idn/Inspector.cs +++ b/samples/idn/Inspector.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Reflection; using System.Text; -namespace idn +namespace Idn { public static class Inspector { diff --git a/samples/idn/Program.cs b/samples/idn/Program.cs index ffd8fd1af..abc315a2d 100644 --- a/samples/idn/Program.cs +++ b/samples/idn/Program.cs @@ -13,7 +13,7 @@ using System.Threading; using System.Text; using System.Diagnostics; -namespace idn +namespace Idn { public class Program { diff --git a/samples/idn/idn.csproj b/samples/idn/idn.csproj index 984c86383..fafb3df3f 100644 --- a/samples/idn/idn.csproj +++ b/samples/idn/idn.csproj @@ -2,11 +2,11 @@ Exe - netcoreapp3.1 + net5.0 - + diff --git a/src/Discord.Net.Analyzers/Discord.Net.Analyzers.csproj b/src/Discord.Net.Analyzers/Discord.Net.Analyzers.csproj index 1b2ee45bf..5fe98fc86 100644 --- a/src/Discord.Net.Analyzers/Discord.Net.Analyzers.csproj +++ b/src/Discord.Net.Analyzers/Discord.Net.Analyzers.csproj @@ -1,4 +1,4 @@ - + Discord.Net.Analyzers @@ -7,7 +7,7 @@ netstandard2.0;netstandard2.1 - + diff --git a/src/Discord.Net.Commands/Attributes/AliasAttribute.cs b/src/Discord.Net.Commands/Attributes/AliasAttribute.cs index 16eb3ba73..c4b78f534 100644 --- a/src/Discord.Net.Commands/Attributes/AliasAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/AliasAttribute.cs @@ -16,7 +16,7 @@ namespace Discord.Commands /// /// [Command("stats")] /// [Alias("stat", "info")] - /// public async Task GetStatsAsync(IUser user) + /// public Task GetStatsAsync(IUser user) /// { /// // ...pull stats /// } diff --git a/src/Discord.Net.Commands/Builders/CommandBuilder.cs b/src/Discord.Net.Commands/Builders/CommandBuilder.cs index 3f1ca883a..1d946a33d 100644 --- a/src/Discord.Net.Commands/Builders/CommandBuilder.cs +++ b/src/Discord.Net.Commands/Builders/CommandBuilder.cs @@ -7,6 +7,7 @@ namespace Discord.Commands.Builders { public class CommandBuilder { + #region CommandBuilder private readonly List _preconditions; private readonly List _parameters; private readonly List _attributes; @@ -27,8 +28,9 @@ namespace Discord.Commands.Builders public IReadOnlyList Parameters => _parameters; public IReadOnlyList Attributes => _attributes; public IReadOnlyList Aliases => _aliases; + #endregion - //Automatic + #region Automatic internal CommandBuilder(ModuleBuilder module) { Module = module; @@ -38,7 +40,9 @@ namespace Discord.Commands.Builders _attributes = new List(); _aliases = new List(); } - //User-defined + #endregion + + #region User-defined internal CommandBuilder(ModuleBuilder module, string primaryAlias, Func callback) : this(module) { @@ -132,7 +136,7 @@ namespace Discord.Commands.Builders var firstMultipleParam = _parameters.FirstOrDefault(x => x.IsMultiple); if ((firstMultipleParam != null) && (firstMultipleParam != lastParam)) throw new InvalidOperationException($"Only the last parameter in a command may have the Multiple flag. Parameter: {firstMultipleParam.Name} in {PrimaryAlias}"); - + var firstRemainderParam = _parameters.FirstOrDefault(x => x.IsRemainder); if ((firstRemainderParam != null) && (firstRemainderParam != lastParam)) throw new InvalidOperationException($"Only the last parameter in a command may have the Remainder flag. Parameter: {firstRemainderParam.Name} in {PrimaryAlias}"); @@ -140,5 +144,6 @@ namespace Discord.Commands.Builders return new CommandInfo(this, info, service); } + #endregion } } diff --git a/src/Discord.Net.Commands/Builders/ModuleBuilder.cs b/src/Discord.Net.Commands/Builders/ModuleBuilder.cs index 6dc50db31..f2a7eeb1f 100644 --- a/src/Discord.Net.Commands/Builders/ModuleBuilder.cs +++ b/src/Discord.Net.Commands/Builders/ModuleBuilder.cs @@ -7,6 +7,8 @@ namespace Discord.Commands.Builders { public class ModuleBuilder { + #region ModuleBuilder + private string _group; private readonly List _commands; private readonly List _submodules; private readonly List _preconditions; @@ -18,7 +20,14 @@ namespace Discord.Commands.Builders public string Name { get; set; } public string Summary { get; set; } public string Remarks { get; set; } - public string Group { get; set; } + public string Group { get => _group; + set + { + _aliases.Remove(_group); + _group = value; + AddAliases(value); + } + } public IReadOnlyList Commands => _commands; public IReadOnlyList Modules => _submodules; @@ -27,8 +36,9 @@ namespace Discord.Commands.Builders public IReadOnlyList Aliases => _aliases; internal TypeInfo TypeInfo { get; set; } + #endregion - //Automatic + #region Automatic internal ModuleBuilder(CommandService service, ModuleBuilder parent) { Service = service; @@ -40,7 +50,9 @@ namespace Discord.Commands.Builders _attributes = new List(); _aliases = new List(); } - //User-defined + #endregion + + #region User-defined internal ModuleBuilder(CommandService service, ModuleBuilder parent, string primaryAlias) : this(service, parent) { @@ -132,5 +144,6 @@ namespace Discord.Commands.Builders public ModuleInfo Build(CommandService service, IServiceProvider services) => BuildImpl(service, services); internal ModuleInfo Build(CommandService service, IServiceProvider services, ModuleInfo parent) => BuildImpl(service, services, parent); + #endregion } } diff --git a/src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs b/src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs index aec8dcbe3..22c58f5c7 100644 --- a/src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs +++ b/src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs @@ -116,9 +116,8 @@ namespace Discord.Commands builder.AddAliases(alias.Aliases); break; case GroupAttribute group: - builder.Name = builder.Name ?? group.Prefix; + builder.Name ??= group.Prefix; builder.Group = group.Prefix; - builder.AddAliases(group.Prefix); break; case PreconditionAttribute precondition: builder.AddPrecondition(precondition); @@ -135,7 +134,8 @@ namespace Discord.Commands if (builder.Name == null) builder.Name = typeInfo.Name; - var validCommands = typeInfo.DeclaredMethods.Where(IsValidCommandDefinition); + // Get all methods (including from inherited members), that are valid commands + var validCommands = typeInfo.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(IsValidCommandDefinition); foreach (var method in validCommands) { @@ -157,7 +157,7 @@ namespace Discord.Commands case CommandAttribute command: builder.AddAliases(command.Text); builder.RunMode = command.RunMode; - builder.Name = builder.Name ?? command.Text; + builder.Name ??= command.Text; builder.IgnoreExtraArgs = command.IgnoreExtraArgs ?? service._ignoreExtraArgs; break; case NameAttribute name: @@ -290,7 +290,7 @@ namespace Discord.Commands return reader; } - //We dont have a cached type reader, create one + //We don't have a cached type reader, create one reader = ReflectionUtils.CreateObject(typeReaderType.GetTypeInfo(), service, services); service.AddTypeReader(paramType, reader, false); diff --git a/src/Discord.Net.Commands/Builders/ParameterBuilder.cs b/src/Discord.Net.Commands/Builders/ParameterBuilder.cs index 4ad5bfac0..afe3a5af6 100644 --- a/src/Discord.Net.Commands/Builders/ParameterBuilder.cs +++ b/src/Discord.Net.Commands/Builders/ParameterBuilder.cs @@ -8,6 +8,7 @@ namespace Discord.Commands.Builders { public class ParameterBuilder { + #region ParameterBuilder private readonly List _preconditions; private readonly List _attributes; @@ -24,8 +25,9 @@ namespace Discord.Commands.Builders public IReadOnlyList Preconditions => _preconditions; public IReadOnlyList Attributes => _attributes; +#endregion - //Automatic + #region Automatic internal ParameterBuilder(CommandBuilder command) { _preconditions = new List(); @@ -33,7 +35,9 @@ namespace Discord.Commands.Builders Command = command; } - //User-defined + #endregion + + #region User-defined internal ParameterBuilder(CommandBuilder command, string name, Type type) : this(command) { @@ -50,7 +54,7 @@ namespace Discord.Commands.Builders if (type.GetTypeInfo().IsValueType) DefaultValue = Activator.CreateInstance(type); else if (type.IsArray) - type = ParameterType.GetElementType(); + DefaultValue = Array.CreateInstance(type.GetElementType(), 0); ParameterType = type; } @@ -127,10 +131,11 @@ namespace Discord.Commands.Builders internal ParameterInfo Build(CommandInfo info) { - if ((TypeReader ?? (TypeReader = GetReader(ParameterType))) == null) + if ((TypeReader ??= GetReader(ParameterType)) == null) throw new InvalidOperationException($"No type reader found for type {ParameterType.Name}, one must be specified"); return new ParameterInfo(this, info, Command.Module.Service); } + #endregion } } diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index 1d4b0e15a..fce67b9b2 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -29,6 +29,7 @@ namespace Discord.Commands ///
public class CommandService : IDisposable { + #region CommandService /// /// Occurs when a command-related information is received. /// @@ -131,8 +132,9 @@ namespace Discord.Commands entityTypeReaders.Add((typeof(IUser), typeof(UserTypeReader<>))); _entityTypeReaders = entityTypeReaders.ToImmutable(); } + #endregion - //Modules + #region Modules public async Task CreateModuleAsync(string primaryAlias, Action buildFunc) { await _moduleLock.WaitAsync().ConfigureAwait(false); @@ -187,7 +189,7 @@ namespace Discord.Commands /// public async Task AddModuleAsync(Type type, IServiceProvider services) { - services = services ?? EmptyServiceProvider.Instance; + services ??= EmptyServiceProvider.Instance; await _moduleLock.WaitAsync().ConfigureAwait(false); try @@ -222,7 +224,7 @@ namespace Discord.Commands /// public async Task> AddModulesAsync(Assembly assembly, IServiceProvider services) { - services = services ?? EmptyServiceProvider.Instance; + services ??= EmptyServiceProvider.Instance; await _moduleLock.WaitAsync().ConfigureAwait(false); try @@ -322,8 +324,9 @@ namespace Discord.Commands return true; } + #endregion - //Type Readers + #region Type Readers /// /// Adds a custom to this for the supplied object /// type. @@ -408,7 +411,7 @@ namespace Discord.Commands var typeInfo = type.GetTypeInfo(); if (typeInfo.IsEnum) return true; - return _entityTypeReaders.Any(x => type == x.EntityType || typeInfo.ImplementedInterfaces.Contains(x.TypeReaderType)); + return _entityTypeReaders.Any(x => type == x.EntityType || typeInfo.ImplementedInterfaces.Contains(x.EntityType)); } internal void AddNullableTypeReader(Type valueType, TypeReader valueTypeReader) { @@ -435,6 +438,13 @@ namespace Discord.Commands _defaultTypeReaders[type] = reader; return reader; } + var underlyingType = Nullable.GetUnderlyingType(type); + if (underlyingType != null && underlyingType.IsEnum) + { + reader = NullableTypeReader.Create(underlyingType, EnumTypeReader.GetReader(underlyingType)); + _defaultTypeReaders[type] = reader; + return reader; + } //Is this an entity? for (int i = 0; i < _entityTypeReaders.Count; i++) @@ -448,8 +458,9 @@ namespace Discord.Commands } return null; } + #endregion - //Execution + #region Execution /// /// Searches for the command. /// @@ -503,22 +514,92 @@ namespace Discord.Commands /// public async Task ExecuteAsync(ICommandContext context, string input, IServiceProvider services, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) { - services = services ?? EmptyServiceProvider.Instance; + services ??= EmptyServiceProvider.Instance; var searchResult = Search(input); - if (!searchResult.IsSuccess) + + var validationResult = await ValidateAndGetBestMatch(searchResult, context, services, multiMatchHandling); + + if (validationResult is SearchResult result) + { + await _commandExecutedEvent.InvokeAsync(Optional.Create(), context, result).ConfigureAwait(false); + return result; + } + + if (validationResult is MatchResult matchResult) + { + return await HandleCommandPipeline(matchResult, context, services); + } + + return validationResult; + } + + private async Task HandleCommandPipeline(MatchResult matchResult, ICommandContext context, IServiceProvider services) + { + if (!matchResult.IsSuccess) + return matchResult; + + if (matchResult.Pipeline is ParseResult parseResult) + { + if (!parseResult.IsSuccess) + { + await _commandExecutedEvent.InvokeAsync(matchResult.Match.Value.Command, context, parseResult); + return parseResult; + } + + var executeResult = await matchResult.Match.Value.ExecuteAsync(context, parseResult, services); + + if (!executeResult.IsSuccess && !(executeResult is RuntimeResult || executeResult is ExecuteResult)) // succesful results raise the event in CommandInfo#ExecuteInternalAsync (have to raise it there b/c deffered execution) + await _commandExecutedEvent.InvokeAsync(matchResult.Match.Value.Command, context, executeResult); + return executeResult; + } + + if (matchResult.Pipeline is PreconditionResult preconditionResult) + { + await _commandExecutedEvent.InvokeAsync(matchResult.Match.Value.Command, context, preconditionResult).ConfigureAwait(false); + } + + return matchResult; + } + + // Calculates the 'score' of a command given a parse result + float CalculateScore(CommandMatch match, ParseResult parseResult) + { + float argValuesScore = 0, paramValuesScore = 0; + + if (match.Command.Parameters.Count > 0) { - await _commandExecutedEvent.InvokeAsync(Optional.Create(), context, searchResult).ConfigureAwait(false); - return searchResult; + var argValuesSum = parseResult.ArgValues?.Sum(x => x.Values.OrderByDescending(y => y.Score).FirstOrDefault().Score) ?? 0; + var paramValuesSum = parseResult.ParamValues?.Sum(x => x.Values.OrderByDescending(y => y.Score).FirstOrDefault().Score) ?? 0; + + argValuesScore = argValuesSum / match.Command.Parameters.Count; + paramValuesScore = paramValuesSum / match.Command.Parameters.Count; } - - var commands = searchResult.Commands; + var totalArgsScore = (argValuesScore + paramValuesScore) / 2; + return match.Command.Priority + totalArgsScore * 0.99f; + } + + /// + /// Validates and gets the best from a specified + /// + /// The SearchResult. + /// The context of the command. + /// The service provider to be used on the command's dependency injection. + /// The handling mode when multiple command matches are found. + /// A task that represents the asynchronous validation operation. The task result contains the result of the + /// command validation as a or a if no matches were found. + public async Task ValidateAndGetBestMatch(SearchResult matches, ICommandContext context, IServiceProvider provider, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) + { + if (!matches.IsSuccess) + return matches; + + var commands = matches.Commands; var preconditionResults = new Dictionary(); - foreach (var match in commands) + foreach (var command in commands) { - preconditionResults[match] = await match.Command.CheckPreconditionsAsync(context, services).ConfigureAwait(false); + preconditionResults[command] = await command.CheckPreconditionsAsync(context, provider); } var successfulPreconditions = preconditionResults @@ -529,19 +610,16 @@ namespace Discord.Commands { //All preconditions failed, return the one from the highest priority command var bestCandidate = preconditionResults - .OrderByDescending(x => x.Key.Command.Priority) - .FirstOrDefault(x => !x.Value.IsSuccess); - - await _commandExecutedEvent.InvokeAsync(bestCandidate.Key.Command, context, bestCandidate.Value).ConfigureAwait(false); - return bestCandidate.Value; + .OrderByDescending(x => x.Key.Command.Priority) + .FirstOrDefault(x => !x.Value.IsSuccess); + return MatchResult.FromSuccess(bestCandidate.Key,bestCandidate.Value); } - //If we get this far, at least one precondition was successful. + var parseResults = new Dictionary(); - var parseResultsDict = new Dictionary(); foreach (var pair in successfulPreconditions) { - var parseResult = await pair.Key.ParseAsync(context, searchResult, pair.Value, services).ConfigureAwait(false); + var parseResult = await pair.Key.ParseAsync(context, matches, pair.Value, provider).ConfigureAwait(false); if (parseResult.Error == CommandError.MultipleMatches) { @@ -556,53 +634,31 @@ namespace Discord.Commands } } - parseResultsDict[pair.Key] = parseResult; - } - - // Calculates the 'score' of a command given a parse result - float CalculateScore(CommandMatch match, ParseResult parseResult) - { - float argValuesScore = 0, paramValuesScore = 0; - - if (match.Command.Parameters.Count > 0) - { - var argValuesSum = parseResult.ArgValues?.Sum(x => x.Values.OrderByDescending(y => y.Score).FirstOrDefault().Score) ?? 0; - var paramValuesSum = parseResult.ParamValues?.Sum(x => x.Values.OrderByDescending(y => y.Score).FirstOrDefault().Score) ?? 0; - - argValuesScore = argValuesSum / match.Command.Parameters.Count; - paramValuesScore = paramValuesSum / match.Command.Parameters.Count; - } - - var totalArgsScore = (argValuesScore + paramValuesScore) / 2; - return match.Command.Priority + totalArgsScore * 0.99f; + parseResults[pair.Key] = parseResult; } - //Order the parse results by their score so that we choose the most likely result to execute - var parseResults = parseResultsDict - .OrderByDescending(x => CalculateScore(x.Key, x.Value)); + var weightedParseResults = parseResults + .OrderByDescending(x => CalculateScore(x.Key, x.Value)); - var successfulParses = parseResults + var successfulParses = weightedParseResults .Where(x => x.Value.IsSuccess) .ToArray(); - if (successfulParses.Length == 0) + if(successfulParses.Length == 0) { - //All parses failed, return the one from the highest priority command, using score as a tie breaker var bestMatch = parseResults .FirstOrDefault(x => !x.Value.IsSuccess); - await _commandExecutedEvent.InvokeAsync(bestMatch.Key.Command, context, bestMatch.Value).ConfigureAwait(false); - return bestMatch.Value; + return MatchResult.FromSuccess(bestMatch.Key, bestMatch.Value); } - //If we get this far, at least one parse was successful. Execute the most likely overload. var chosenOverload = successfulParses[0]; - var result = await chosenOverload.Key.ExecuteAsync(context, chosenOverload.Value, services).ConfigureAwait(false); - if (!result.IsSuccess && !(result is RuntimeResult || result is ExecuteResult)) // succesful results raise the event in CommandInfo#ExecuteInternalAsync (have to raise it there b/c deffered execution) - await _commandExecutedEvent.InvokeAsync(chosenOverload.Key.Command, context, result); - return result; + + return MatchResult.FromSuccess(chosenOverload.Key, chosenOverload.Value); } + #endregion + #region Dispose protected virtual void Dispose(bool disposing) { if (!_isDisposed) @@ -620,5 +676,6 @@ namespace Discord.Commands { Dispose(true); } + #endregion } } diff --git a/src/Discord.Net.Commands/Discord.Net.Commands.csproj b/src/Discord.Net.Commands/Discord.Net.Commands.csproj index 95e7db491..fea719016 100644 --- a/src/Discord.Net.Commands/Discord.Net.Commands.csproj +++ b/src/Discord.Net.Commands/Discord.Net.Commands.csproj @@ -1,14 +1,14 @@ + Discord.Net.Commands Discord.Commands A Discord.Net extension adding support for bot commands. - net461;netstandard2.0;netstandard2.1 - netstandard2.0;netstandard2.1 + net6.0;net5.0;net461;netstandard2.0;netstandard2.1 + net6.0;net5.0;netstandard2.0;netstandard2.1 - diff --git a/src/Discord.Net.Commands/Extensions/MessageExtensions.cs b/src/Discord.Net.Commands/Extensions/MessageExtensions.cs index f880e1d98..9aa83d418 100644 --- a/src/Discord.Net.Commands/Extensions/MessageExtensions.cs +++ b/src/Discord.Net.Commands/Extensions/MessageExtensions.cs @@ -51,8 +51,7 @@ namespace Discord.Commands if (endPos == -1) return false; if (text.Length < endPos + 2 || text[endPos + 1] != ' ') return false; //Must end in "> " - ulong userId; - if (!MentionUtils.TryParseUser(text.Substring(0, endPos + 1), out userId)) return false; + if (!MentionUtils.TryParseUser(text.Substring(0, endPos + 1), out ulong userId)) return false; if (userId == user.Id) { argPos = endPos + 2; diff --git a/src/Discord.Net.Commands/IModuleBase.cs b/src/Discord.Net.Commands/IModuleBase.cs index 3b641ec5f..8b021f4de 100644 --- a/src/Discord.Net.Commands/IModuleBase.cs +++ b/src/Discord.Net.Commands/IModuleBase.cs @@ -2,14 +2,34 @@ using Discord.Commands.Builders; namespace Discord.Commands { - internal interface IModuleBase + /// + /// Represents a generic module base. + /// + public interface IModuleBase { + /// + /// Sets the context of this module base. + /// + /// The context to set. void SetContext(ICommandContext context); + /// + /// Executed before a command is run in this module base. + /// + /// The command thats about to run. void BeforeExecute(CommandInfo command); - + + /// + /// Executed after a command is ran in this module base. + /// + /// The command that ran. void AfterExecute(CommandInfo command); + /// + /// Executed when this module is building. + /// + /// The command service that is building this module. + /// The builder constructing this module. void OnModuleBuilding(CommandService commandService, ModuleBuilder builder); } } diff --git a/src/Discord.Net.Commands/Info/CommandInfo.cs b/src/Discord.Net.Commands/Info/CommandInfo.cs index 3bcef9831..773c7c773 100644 --- a/src/Discord.Net.Commands/Info/CommandInfo.cs +++ b/src/Discord.Net.Commands/Info/CommandInfo.cs @@ -123,7 +123,7 @@ namespace Discord.Commands public async Task CheckPreconditionsAsync(ICommandContext context, IServiceProvider services = null) { - services = services ?? EmptyServiceProvider.Instance; + services ??= EmptyServiceProvider.Instance; async Task CheckGroups(IEnumerable preconditions, string type) { @@ -164,7 +164,7 @@ namespace Discord.Commands public async Task ParseAsync(ICommandContext context, int startIndex, SearchResult searchResult, PreconditionResult preconditionResult = null, IServiceProvider services = null) { - services = services ?? EmptyServiceProvider.Instance; + services ??= EmptyServiceProvider.Instance; if (!searchResult.IsSuccess) return ParseResult.FromError(searchResult); @@ -201,7 +201,7 @@ namespace Discord.Commands } public async Task ExecuteAsync(ICommandContext context, IEnumerable argList, IEnumerable paramList, IServiceProvider services) { - services = services ?? EmptyServiceProvider.Instance; + services ??= EmptyServiceProvider.Instance; try { diff --git a/src/Discord.Net.Commands/Info/ParameterInfo.cs b/src/Discord.Net.Commands/Info/ParameterInfo.cs index b435b301a..a6ba9dfde 100644 --- a/src/Discord.Net.Commands/Info/ParameterInfo.cs +++ b/src/Discord.Net.Commands/Info/ParameterInfo.cs @@ -75,7 +75,7 @@ namespace Discord.Commands public async Task CheckPreconditionsAsync(ICommandContext context, object arg, IServiceProvider services = null) { - services = services ?? EmptyServiceProvider.Instance; + services ??= EmptyServiceProvider.Instance; foreach (var precondition in Preconditions) { @@ -89,7 +89,7 @@ namespace Discord.Commands public async Task ParseAsync(ICommandContext context, string input, IServiceProvider services = null) { - services = services ?? EmptyServiceProvider.Instance; + services ??= EmptyServiceProvider.Instance; return await _reader.ReadAsync(context, input, services).ConfigureAwait(false); } diff --git a/src/Discord.Net.Commands/ModuleBase.cs b/src/Discord.Net.Commands/ModuleBase.cs index ec1722c70..5008cca35 100644 --- a/src/Discord.Net.Commands/ModuleBase.cs +++ b/src/Discord.Net.Commands/ModuleBase.cs @@ -16,6 +16,7 @@ namespace Discord.Commands public abstract class ModuleBase : IModuleBase where T : class, ICommandContext { + #region ModuleBase /// /// The underlying context of the command. /// @@ -35,9 +36,14 @@ namespace Discord.Commands /// Specifies if notifications are sent for mentioned users and roles in the . /// If null, all mentioned roles and users will be notified. /// - protected virtual async Task ReplyAsync(string message = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null) + /// The request options for this request. + /// The message references to be included. Used to reply to specific messages. + /// The message components to be included with this message. Used for interactions. + /// A collection of stickers to send with the file. + /// A array of s to send with this response. Max 10. + protected virtual async Task ReplyAsync(string message = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) { - return await Context.Channel.SendMessageAsync(message, isTTS, embed, options, allowedMentions).ConfigureAwait(false); + return await Context.Channel.SendMessageAsync(message, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); } /// /// The method to execute before executing the command. @@ -62,8 +68,9 @@ namespace Discord.Commands protected virtual void OnModuleBuilding(CommandService commandService, ModuleBuilder builder) { } + #endregion - //IModuleBase + #region IModuleBase void IModuleBase.SetContext(ICommandContext context) { var newValue = context as T; @@ -72,5 +79,6 @@ namespace Discord.Commands void IModuleBase.BeforeExecute(CommandInfo command) => BeforeExecute(command); void IModuleBase.AfterExecute(CommandInfo command) => AfterExecute(command); void IModuleBase.OnModuleBuilding(CommandService commandService, ModuleBuilder builder) => OnModuleBuilding(commandService, builder); + #endregion } } diff --git a/src/Discord.Net.Commands/Readers/TimeSpanTypeReader.cs b/src/Discord.Net.Commands/Readers/TimeSpanTypeReader.cs index b4a27cb5b..5448553b3 100644 --- a/src/Discord.Net.Commands/Readers/TimeSpanTypeReader.cs +++ b/src/Discord.Net.Commands/Readers/TimeSpanTypeReader.cs @@ -6,30 +6,50 @@ namespace Discord.Commands { internal class TimeSpanTypeReader : TypeReader { - private static readonly string[] Formats = { - "%d'd'%h'h'%m'm'%s's'", //4d3h2m1s - "%d'd'%h'h'%m'm'", //4d3h2m - "%d'd'%h'h'%s's'", //4d3h 1s - "%d'd'%h'h'", //4d3h - "%d'd'%m'm'%s's'", //4d 2m1s - "%d'd'%m'm'", //4d 2m - "%d'd'%s's'", //4d 1s - "%d'd'", //4d - "%h'h'%m'm'%s's'", // 3h2m1s - "%h'h'%m'm'", // 3h2m - "%h'h'%s's'", // 3h 1s - "%h'h'", // 3h - "%m'm'%s's'", // 2m1s - "%m'm'", // 2m - "%s's'", // 1s + /// + /// TimeSpan try parse formats. + /// + private static readonly string[] Formats = + { + "%d'd'%h'h'%m'm'%s's'", // 4d3h2m1s + "%d'd'%h'h'%m'm'", // 4d3h2m + "%d'd'%h'h'%s's'", // 4d3h 1s + "%d'd'%h'h'", // 4d3h + "%d'd'%m'm'%s's'", // 4d 2m1s + "%d'd'%m'm'", // 4d 2m + "%d'd'%s's'", // 4d 1s + "%d'd'", // 4d + "%h'h'%m'm'%s's'", // 3h2m1s + "%h'h'%m'm'", // 3h2m + "%h'h'%s's'", // 3h 1s + "%h'h'", // 3h + "%m'm'%s's'", // 2m1s + "%m'm'", // 2m + "%s's'", // 1s }; /// public override Task ReadAsync(ICommandContext context, string input, IServiceProvider services) { - return (TimeSpan.TryParseExact(input.ToLowerInvariant(), Formats, CultureInfo.InvariantCulture, out var timeSpan)) - ? Task.FromResult(TypeReaderResult.FromSuccess(timeSpan)) - : Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Failed to parse TimeSpan")); + if (string.IsNullOrEmpty(input)) + throw new ArgumentException(message: $"{nameof(input)} must not be null or empty.", paramName: nameof(input)); + + var isNegative = input[0] == '-'; // Char for CultureInfo.InvariantCulture.NumberFormat.NegativeSign + if (isNegative) + { + input = input.Substring(1); + } + + if (TimeSpan.TryParseExact(input.ToLowerInvariant(), Formats, CultureInfo.InvariantCulture, out var timeSpan)) + { + return isNegative + ? Task.FromResult(TypeReaderResult.FromSuccess(-timeSpan)) + : Task.FromResult(TypeReaderResult.FromSuccess(timeSpan)); + } + else + { + return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Failed to parse TimeSpan")); + } } } } diff --git a/src/Discord.Net.Commands/Results/MatchResult.cs b/src/Discord.Net.Commands/Results/MatchResult.cs new file mode 100644 index 000000000..fb266efa6 --- /dev/null +++ b/src/Discord.Net.Commands/Results/MatchResult.cs @@ -0,0 +1,47 @@ +using System; + +namespace Discord.Commands +{ + public class MatchResult : IResult + { + /// + /// Gets the command that may have matched during the command execution. + /// + public CommandMatch? Match { get; } + + /// + /// Gets on which pipeline stage the command may have matched or failed. + /// + public IResult? Pipeline { get; } + + /// + public CommandError? Error { get; } + /// + public string ErrorReason { get; } + /// + public bool IsSuccess => !Error.HasValue; + + private MatchResult(CommandMatch? match, IResult? pipeline, CommandError? error, string errorReason) + { + Match = match; + Error = error; + Pipeline = pipeline; + ErrorReason = errorReason; + } + + public static MatchResult FromSuccess(CommandMatch match, IResult pipeline) + => new MatchResult(match,pipeline,null, null); + public static MatchResult FromError(CommandError error, string reason) + => new MatchResult(null,null,error, reason); + public static MatchResult FromError(Exception ex) + => FromError(CommandError.Exception, ex.Message); + public static MatchResult FromError(IResult result) + => new MatchResult(null, null,result.Error, result.ErrorReason); + public static MatchResult FromError(IResult pipeline, CommandError error, string reason) + => new MatchResult(null, pipeline, error, reason); + + public override string ToString() => IsSuccess ? "Success" : $"{Error}: {ErrorReason}"; + private string DebuggerDisplay => IsSuccess ? "Success" : $"{Error}: {ErrorReason}"; + + } +} diff --git a/src/Discord.Net.Commands/RunMode.cs b/src/Discord.Net.Commands/RunMode.cs index 8e230b500..d6b49065b 100644 --- a/src/Discord.Net.Commands/RunMode.cs +++ b/src/Discord.Net.Commands/RunMode.cs @@ -8,7 +8,7 @@ namespace Discord.Commands public enum RunMode { /// - /// The default behaviour set in . + /// The default behavior set in . /// Default, /// diff --git a/src/Discord.Net.Core/AssemblyInfo.cs b/src/Discord.Net.Core/AssemblyInfo.cs index b7c60f3d3..0031c2dbf 100644 --- a/src/Discord.Net.Core/AssemblyInfo.cs +++ b/src/Discord.Net.Core/AssemblyInfo.cs @@ -8,3 +8,4 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Discord.Net.Commands")] [assembly: InternalsVisibleTo("Discord.Net.Tests")] [assembly: InternalsVisibleTo("Discord.Net.Tests.Unit")] +[assembly: InternalsVisibleTo("Discord.Net.Interactions")] diff --git a/src/Discord.Net.Core/Audio/IAudioClient.cs b/src/Discord.Net.Core/Audio/IAudioClient.cs index 018c8bc05..2fc52a529 100644 --- a/src/Discord.Net.Core/Audio/IAudioClient.cs +++ b/src/Discord.Net.Core/Audio/IAudioClient.cs @@ -1,4 +1,5 @@ -using System; +using System; +using System.Collections.Generic; using System.Threading.Tasks; namespace Discord.Audio @@ -20,6 +21,9 @@ namespace Discord.Audio /// Gets the estimated round-trip latency, in milliseconds, to the voice UDP server. int UdpLatency { get; } + /// Gets the current audio streams. + IReadOnlyDictionary GetStreams(); + Task StopAsync(); Task SetSpeakingAsync(bool value); diff --git a/src/Discord.Net.Core/CDN.cs b/src/Discord.Net.Core/CDN.cs index 32ffbba90..d6535a4f1 100644 --- a/src/Discord.Net.Core/CDN.cs +++ b/src/Discord.Net.Core/CDN.cs @@ -7,6 +7,17 @@ namespace Discord /// public static class CDN { + /// + /// Returns a team icon URL. + /// + /// The team identifier. + /// The icon identifier. + /// + /// A URL pointing to the team's icon. + /// + public static string GetTeamIconUrl(ulong teamId, string iconId) + => iconId != null ? $"{DiscordConfig.CDNUrl}team-icons/{teamId}/{iconId}.jpg" : null; + /// /// Returns an application icon URL. /// @@ -35,6 +46,32 @@ namespace Discord string extension = FormatToExtension(format, avatarId); return $"{DiscordConfig.CDNUrl}avatars/{userId}/{avatarId}.{extension}?size={size}"; } + + public static string GetGuildUserAvatarUrl(ulong userId, ulong guildId, string avatarId, ushort size, ImageFormat format) + { + if (avatarId == null) + return null; + string extension = FormatToExtension(format, avatarId); + return $"{DiscordConfig.CDNUrl}guilds/{guildId}/users/{userId}/avatars/{avatarId}.{extension}?size={size}"; + } + + /// + /// Returns a user banner URL. + /// + /// The user snowflake identifier. + /// The banner identifier. + /// The size of the image to return in horizontal pixels. This can be any power of two between 16 and 2048. + /// The format to return. + /// + /// A URL pointing to the user's banner in the specified size. + /// + public static string GetUserBannerUrl(ulong userId, string bannerId, ushort size, ImageFormat format) + { + if (bannerId == null) + return null; + string extension = FormatToExtension(format, bannerId); + return $"{DiscordConfig.CDNUrl}banners/{userId}/{bannerId}.{extension}?size={size}"; + } /// /// Returns the default user avatar URL. /// @@ -57,16 +94,36 @@ namespace Discord public static string GetGuildIconUrl(ulong guildId, string iconId) => iconId != null ? $"{DiscordConfig.CDNUrl}icons/{guildId}/{iconId}.jpg" : null; /// + /// Returns a guild role's icon URL. + /// + /// The role identifier. + /// The icon hash. + /// + /// A URL pointing to the guild role's icon. + /// + public static string GetGuildRoleIconUrl(ulong roleId, string roleHash) + => roleHash != null ? $"{DiscordConfig.CDNUrl}role-icons/{roleId}/{roleHash}.png" : null; + /// /// Returns a guild splash URL. /// /// The guild snowflake identifier. /// The splash icon identifier. /// - /// A URL pointing to the guild's icon. + /// A URL pointing to the guild's splash. /// public static string GetGuildSplashUrl(ulong guildId, string splashId) => splashId != null ? $"{DiscordConfig.CDNUrl}splashes/{guildId}/{splashId}.jpg" : null; /// + /// Returns a guild discovery splash URL. + /// + /// The guild snowflake identifier. + /// The discovery splash icon identifier. + /// + /// A URL pointing to the guild's discovery splash. + /// + public static string GetGuildDiscoverySplashUrl(ulong guildId, string discoverySplashId) + => discoverySplashId != null ? $"{DiscordConfig.CDNUrl}discovery-splashes/{guildId}/{discoverySplashId}.jpg" : null; + /// /// Returns a channel icon URL. /// /// The channel snowflake identifier. @@ -82,15 +139,17 @@ namespace Discord /// /// The guild snowflake identifier. /// The banner image identifier. + /// The format to return. /// The size of the image to return in horizontal pixels. This can be any power of two between 16 and 2048 inclusive. /// /// A URL pointing to the guild's banner image. /// - public static string GetGuildBannerUrl(ulong guildId, string bannerId, ushort? size = null) + public static string GetGuildBannerUrl(ulong guildId, string bannerId, ImageFormat format, ushort? size = null) { - if (!string.IsNullOrEmpty(bannerId)) - return $"{DiscordConfig.CDNUrl}banners/{guildId}/{bannerId}.jpg" + (size.HasValue ? $"?size={size}" : string.Empty); - return null; + if (string.IsNullOrEmpty(bannerId)) + return null; + string extension = FormatToExtension(format, bannerId); + return $"{DiscordConfig.CDNUrl}banners/{guildId}/{bannerId}.{extension}" + (size.HasValue ? $"?size={size}" : string.Empty); } /// /// Returns an emoji URL. @@ -138,23 +197,39 @@ namespace Discord public static string GetSpotifyDirectUrl(string trackId) => $"https://open.spotify.com/track/{trackId}"; + /// + /// Gets a stickers url based off the id and format. + /// + /// The id of the sticker. + /// The format of the sticker. + /// + /// A URL to the sticker. + /// + public static string GetStickerUrl(ulong stickerId, StickerFormatType format = StickerFormatType.Png) + => $"{DiscordConfig.CDNUrl}stickers/{stickerId}.{FormatToExtension(format)}"; + + private static string FormatToExtension(StickerFormatType format) + { + return format switch + { + StickerFormatType.None or StickerFormatType.Png or StickerFormatType.Apng => "png", // In the case of the Sticker endpoint, the sticker will be available as PNG if its format_type is PNG or APNG, and as Lottie if its format_type is LOTTIE. + StickerFormatType.Lottie => "lottie", + _ => throw new ArgumentException(nameof(format)), + }; + } + private static string FormatToExtension(ImageFormat format, string imageId) { if (format == ImageFormat.Auto) format = imageId.StartsWith("a_") ? ImageFormat.Gif : ImageFormat.Png; - switch (format) + return format switch { - case ImageFormat.Gif: - return "gif"; - case ImageFormat.Jpeg: - return "jpeg"; - case ImageFormat.Png: - return "png"; - case ImageFormat.WebP: - return "webp"; - default: - throw new ArgumentException(nameof(format)); - } + ImageFormat.Gif => "gif", + ImageFormat.Jpeg => "jpeg", + ImageFormat.Png => "png", + ImageFormat.WebP => "webp", + _ => throw new ArgumentException(nameof(format)), + }; } } } diff --git a/src/Discord.Net.Core/Discord.Net.Core.csproj b/src/Discord.Net.Core/Discord.Net.Core.csproj index dd2f2afe3..783565e04 100644 --- a/src/Discord.Net.Core/Discord.Net.Core.csproj +++ b/src/Discord.Net.Core/Discord.Net.Core.csproj @@ -1,18 +1,28 @@ + Discord.Net.Core Discord The core components for the Discord.Net library. - net461;netstandard2.0;netstandard2.1 - netstandard2.0;netstandard2.1 + net6.0;net5.0;net461;netstandard2.0;netstandard2.1 + net6.0;net5.0;netstandard2.0;netstandard2.1 - - - - + + + all + + + + + + + + + + - + \ No newline at end of file diff --git a/src/Discord.Net.Core/DiscordConfig.cs b/src/Discord.Net.Core/DiscordConfig.cs index 51970a781..d5951bd07 100644 --- a/src/Discord.Net.Core/DiscordConfig.cs +++ b/src/Discord.Net.Core/DiscordConfig.cs @@ -13,10 +13,10 @@ namespace Discord /// /// An representing the API version that Discord.Net uses to communicate with Discord. /// A list of available API version can be seen on the official - /// Discord API documentation + /// Discord API documentation /// . /// - public const int APIVersion = 6; + public const int APIVersion = 9; /// /// Returns the Voice API version Discord.Net uses. /// @@ -43,14 +43,14 @@ namespace Discord /// /// The user agent used in each Discord.Net request. /// - public static string UserAgent { get; } = $"DiscordBot (https://github.com/RogueException/Discord.Net, v{Version})"; + public static string UserAgent { get; } = $"DiscordBot (https://github.com/discord-net/Discord.Net, v{Version})"; /// /// Returns the base Discord API URL. /// /// /// The Discord API URL using . /// - public static readonly string APIUrl = $"https://discordapp.com/api/v{APIVersion}/"; + public static readonly string APIUrl = $"https://discord.com/api/v{APIVersion}/"; /// /// Returns the base Discord CDN URL. /// @@ -94,6 +94,13 @@ namespace Discord /// The maximum number of users that can be gotten per-batch. /// public const int MaxUsersPerBatch = 1000; + /// + /// Returns the max users allowed to be in a request for guild event users. + /// + /// + /// The maximum number of users that can be gotten per-batch. + /// + public const int MaxGuildEventUsersPerBatch = 100; /// /// Returns the max guilds allowed to be in a request. /// @@ -141,18 +148,6 @@ namespace Discord /// internal bool DisplayInitialLog { get; set; } = true; - /// - /// Gets or sets the level of precision of the rate limit reset response. - /// - /// - /// If set to , this value will be rounded up to the - /// nearest second. - /// - /// - /// The currently set . - /// - public RateLimitPrecision RateLimitPrecision { get; set; } = RateLimitPrecision.Millisecond; - /// /// Gets or sets whether or not rate-limits should use the system clock. /// @@ -170,5 +165,17 @@ namespace Discord /// clock. Your system will still need a stable clock. /// public bool UseSystemClock { get; set; } = true; + + /// + /// Gets or sets whether or not the internal experation check uses the system date + /// + snowflake date to check if an interaction can be responded to. + /// + /// + /// If set to then the CreatedAt property in an interaction + /// will be set to when it was received instead of the snowflakes date. + ///
+ /// This will still require a stable clock on your system. + ///
+ public bool UseInteractionSnowflakeDate { get; set; } = true; } } diff --git a/src/Discord.Net.Core/DiscordErrorCode.cs b/src/Discord.Net.Core/DiscordErrorCode.cs new file mode 100644 index 000000000..03f8b19e9 --- /dev/null +++ b/src/Discord.Net.Core/DiscordErrorCode.cs @@ -0,0 +1,199 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents a set of json error codes received by discord. + /// + public enum DiscordErrorCode + { + GeneralError = 0, + + #region UnknownXYZ (10XXX) + UnknownAccount = 10001, + UnknownApplication = 10002, + UnknownChannel = 10003, + UnknownGuild = 10004, + UnknownIntegration = 10005, + UnknownInvite = 10006, + UnknownMember = 10007, + UnknownMessage = 10008, + UnknownPermissionOverwrite = 10009, + UnknownProvider = 10010, + UnknownRole = 10011, + UnknownToken = 10012, + UnknownUser = 10013, + UnknownEmoji = 10014, + UnknownWebhook = 10015, + UnknownWebhookService = 10016, + UnknownSession = 10020, + UnknownBan = 10026, + UnknownSKU = 10027, + UnknownStoreListing = 10028, + UnknownEntitlement = 10029, + UnknownBuild = 10030, + UnknownLobby = 10031, + UnknownBranch = 10032, + UnknownStoreDirectoryLayout = 10033, + UnknownRedistributable = 10036, + UnknownGiftCode = 10038, + UnknownStream = 10049, + UnknownPremiumServerSubscribeCooldown = 10050, + UnknownGuildTemplate = 10057, + UnknownDiscoverableServerCategory = 10059, + UnknownSticker = 10060, + UnknownInteraction = 10062, + UnknownApplicationCommand = 10063, + UnknownApplicationCommandPermissions = 10066, + UnknownStageInstance = 10067, + UnknownGuildMemberVerificationForm = 10068, + UnknownGuildWelcomeScreen = 10069, + UnknownGuildScheduledEvent = 10070, + UnknownGuildScheduledEventUser = 10071, + #endregion + + #region General Actions (20XXX) + BotsCannotUse = 20001, + OnlyBotsCanUse = 20002, + CannotSendExplicitContent = 20009, + ApplicationActionUnauthorized = 20012, + ActionSlowmode = 20016, + OnlyOwnerAction = 20018, + AnnouncementEditRatelimit = 20022, + ChannelWriteRatelimit = 20028, + WriteRatelimitReached = 20029, + WordsNotAllowed = 20031, + GuildPremiumTooLow = 20035, + #endregion + + #region Numeric Limits Reached (30XXX) + MaximumGuildsReached = 30001, + MaximumFriendsReached = 30002, + MaximumPinsReached = 30003, + MaximumRecipientsReached = 30004, + MaximumGuildRolesReached = 30005, + MaximumWebhooksReached = 30007, + MaximumEmojisReached = 30008, + MaximumReactionsReached = 30010, + MaximumGuildChannelsReached = 30013, + MaximumAttachmentsReached = 30015, + MaximumInvitesReached = 30016, + MaximumAnimatedEmojisReached = 30018, + MaximumServerMembersReached = 30019, + MaximumServerCategoriesReached = 30030, + GuildTemplateAlreadyExists = 30031, + MaximumThreadMembersReached = 30033, + MaximumBansForNonGuildMembersReached = 30035, + MaximumBanFetchesReached = 30037, + MaximumUncompleteGuildScheduledEvents = 30038, + MaximumStickersReached = 30039, + MaximumPruneRequestReached = 30040, + MaximumGuildWigitsReached = 30042, + #endregion + + #region General Request Errors (40XXX) + TokenUnauthorized = 40001, + InvalidVerification = 40002, + OpeningDMTooFast = 40003, + RequestEntityTooLarge = 40005, + FeatureDisabled = 40006, + UserBanned = 40007, + TargetUserNotInVoice = 40032, + MessageAlreadyCrossposted = 40033, + ApplicationNameAlreadyExists = 40041, + #endregion + + #region Action Preconditions/Checks (50XXX) + MissingPermissions = 50001, + InvalidAccountType = 50002, + CannotExecuteForDM = 50003, + GuildWigitDisabled = 50004, + CannotEditOtherUsersMessage = 50005, + CannotSendEmptyMessage = 50006, + CannotSendMessageToUser = 50007, + CannotSendMessageToVoiceChannel = 50008, + ChannelVerificationTooHight = 50009, + OAuth2ApplicationDoesntHaveBot = 50010, + OAuth2ApplicationLimitReached = 50011, + InvalidOAuth2State = 50012, + InsufficientPermissions = 50013, + InvalidAuthenticationToken = 50014, + NoteTooLong = 50015, + ProvidedMessageDeleteCountOutOfBounds = 50016, + InvalidPinChannel = 50019, + InvalidInvite = 50020, + CannotExecuteOnSystemMessage = 50021, + CannotExecuteOnChannelType = 50024, + InvalidOAuth2Token = 50025, + MissingOAuth2Scope = 50026, + InvalidWebhookToken = 50027, + InvalidRole = 50028, + InvalidRecipients = 50033, + BulkDeleteMessageTooOld = 50034, + InvalidFormBody = 50035, + InviteAcceptedForGuildThatBotIsntIn = 50036, + InvalidAPIVersion = 50041, + FileUploadTooBig = 50045, + InvalidFileUpload = 50046, + CannotSelfRedeemGift = 50054, + InvalidGuild = 50055, + PaymentSourceRequiredForGift = 50070, + CannotDeleteRequiredCommunityChannel = 50074, + InvalidSticker = 50081, + CannotExecuteOnArchivedThread = 50083, + InvalidThreadNotificationSettings = 50084, + BeforeValueEarlierThanThreadCreation = 50085, + ServerLocaleUnavailable = 50095, + ServerRequiresMonetization = 50097, + ServerRequiresBoosts = 50101, + RequestBodyContainsInvalidJSON = 50109, + #endregion + + #region 2FA (60XXX) + Requires2FA = 60003, + #endregion + + #region User Searches (80XXX) + NoUsersWithTag = 80004, + #endregion + + #region Reactions (90XXX) + ReactionBlocked = 90001, + #endregion + + #region API Status (130XXX) + APIOverloaded = 130000, + #endregion + + #region Stage Errors (150XXX) + StageAlreadyOpened = 150006, + #endregion + + #region Reply and Thread Errors (160XXX) + CannotReplyWithoutReadMessageHistory = 160002, + MessageAlreadyContainsThread = 160004, + ThreadIsLocked = 160005, + MaximumActiveThreadsReached = 160006, + MaximumAnnouncementThreadsReached = 160007, + #endregion + + #region Sticker Uploads (170XXX) + InvalidJSONLottie = 170001, + LottieCantContainRasters = 170002, + StickerMaximumFramerateExceeded = 170003, + StickerMaximumFrameCountExceeded = 170004, + LottieMaximumDimentionsExceeded = 170005, + StickerFramerateBoundsExceeed = 170006, + StickerAnimationDurationTooLong = 170007, + #endregion + + #region Guild Scheduled Events + CannotUpdateFinishedEvent = 180000, + FailedStageCreation = 180002, + #endregion + } +} diff --git a/src/Discord.Net.Core/DiscordJsonError.cs b/src/Discord.Net.Core/DiscordJsonError.cs new file mode 100644 index 000000000..fdf82ea0c --- /dev/null +++ b/src/Discord.Net.Core/DiscordJsonError.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents a generic parsed json error received from discord after performing a rest request. + /// + public struct DiscordJsonError + { + /// + /// Gets the json path of the error. + /// + public string Path { get; } + + /// + /// Gets a collection of errors associated with the specific property at the path. + /// + public IReadOnlyCollection Errors { get; } + + internal DiscordJsonError(string path, DiscordError[] errors) + { + Path = path; + Errors = errors.ToImmutableArray(); + } + } + + /// + /// Represents an error with a property. + /// + public struct DiscordError + { + /// + /// Gets the code of the error. + /// + public string Code { get; } + + /// + /// Gets the message describing what went wrong. + /// + public string Message { get; } + + internal DiscordError(string code, string message) + { + Code = code; + Message = message; + } + } +} diff --git a/src/Discord.Net.Core/Entities/Activities/ActivityProperties.cs b/src/Discord.Net.Core/Entities/Activities/ActivityProperties.cs index a7d13235f..15a79dff6 100644 --- a/src/Discord.Net.Core/Entities/Activities/ActivityProperties.cs +++ b/src/Discord.Net.Core/Entities/Activities/ActivityProperties.cs @@ -33,6 +33,18 @@ namespace Discord /// /// Indicates that a user can play this song. /// - Play = 0b100000 + Play = 0b100000, + /// + /// Indicates that a user is playing an activity in a voice channel with friends. + /// + PartyPrivacyFriends = 0b1000000, + /// + /// Indicates that a user is playing an activity in a voice channel. + /// + PartyPrivacyVoiceChannel = 0b10000000, + /// + /// Indicates that a user is playing an activity in a voice channel. + /// + Embedded = 0b10000000 } } diff --git a/src/Discord.Net.Core/Entities/Activities/ActivityType.cs b/src/Discord.Net.Core/Entities/Activities/ActivityType.cs index 8c44f49e3..1f67886eb 100644 --- a/src/Discord.Net.Core/Entities/Activities/ActivityType.cs +++ b/src/Discord.Net.Core/Entities/Activities/ActivityType.cs @@ -25,5 +25,9 @@ namespace Discord /// The user has set a custom status. ///
CustomStatus = 4, + /// + /// The user is competing in a game. + /// + Competing = 5, } } diff --git a/src/Discord.Net.Core/Entities/Activities/DefaultApplications.cs b/src/Discord.Net.Core/Entities/Activities/DefaultApplications.cs new file mode 100644 index 000000000..80f128fa8 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Activities/DefaultApplications.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + public enum DefaultApplications : ulong + { + /// + /// Watch youtube together. + /// + Youtube = 880218394199220334, + + /// + /// Youtube development application. + /// + YoutubeDev = 880218832743055411, + + /// + /// Poker! + /// + Poker = 755827207812677713, + + /// + /// Betrayal: A Party Adventure. Betrayal is a social deduction game inspired by Werewolf, Town of Salem, and Among Us. + /// + Betrayal = 773336526917861400, + + /// + /// Sit back, relax, and do some fishing! + /// + Fishing = 814288819477020702, + + /// + /// The queens gambit. + /// + Chess = 832012774040141894, + + /// + /// Development version of chess. + /// + ChessDev = 832012586023256104, + + /// + /// LetterTile is a version of scrabble. + /// + LetterTile = 879863686565621790, + + /// + /// Find words in a jumble of letters in coffee. + /// + WordSnack = 879863976006127627, + + /// + /// It's like skribbl.io. + /// + DoodleCrew = 878067389634314250, + + /// + /// It's like cards against humanity. + /// + Awkword = 879863881349087252, + + /// + /// A word-search like game where you unscramble words and score points in a scrabble fashion. + /// + SpellCast = 852509694341283871, + + /// + /// Classic checkers + /// + Checkers = 832013003968348200, + + /// + /// The development version of poker. + /// + PokerDev = 763133495793942528, + + /// + /// SketchyArtist. + /// + SketchyArtist = 879864070101172255 + } +} diff --git a/src/Discord.Net.Core/Entities/ApplicationFlags.cs b/src/Discord.Net.Core/Entities/ApplicationFlags.cs new file mode 100644 index 000000000..1ede4257d --- /dev/null +++ b/src/Discord.Net.Core/Entities/ApplicationFlags.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents public flags for an application. + /// + public enum ApplicationFlags + { + GatewayPresence = 1 << 12, + GatewayPresenceLimited = 1 << 13, + GatewayGuildMembers = 1 << 14, + GatewayGuildMembersLimited = 1 << 15, + VerificationPendingGuildLimit = 1 << 16, + Embedded = 1 << 17, + GatewayMessageContent = 1 << 18, + GatewayMessageContentLimited = 1 << 19 + } +} diff --git a/src/Discord.Net.Core/Entities/ApplicationInstallParams.cs b/src/Discord.Net.Core/Entities/ApplicationInstallParams.cs new file mode 100644 index 000000000..180592f1e --- /dev/null +++ b/src/Discord.Net.Core/Entities/ApplicationInstallParams.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents install parameters for an application. + /// + public class ApplicationInstallParams + { + /// + /// Gets the scopes to install this application. + /// + public IReadOnlyCollection Scopes { get; } + + /// + /// Gets the default permissions to install this application + /// + public GuildPermission? Permission { get; } + + internal ApplicationInstallParams(string[] scopes, GuildPermission? permission) + { + Scopes = scopes.ToImmutableArray(); + Permission = permission; + } + } +} diff --git a/src/Discord.Net.Core/Entities/AuditLogs/ActionType.cs b/src/Discord.Net.Core/Entities/AuditLogs/ActionType.cs index 1728b2021..5092b4e7f 100644 --- a/src/Discord.Net.Core/Entities/AuditLogs/ActionType.cs +++ b/src/Discord.Net.Core/Entities/AuditLogs/ActionType.cs @@ -142,5 +142,55 @@ namespace Discord /// A message was unpinned from this guild. /// MessageUnpinned = 75, + + /// + /// A integration was created + /// + IntegrationCreated = 80, + /// + /// A integration was updated + /// + IntegrationUpdated = 81, + /// + /// An integration was deleted + /// + IntegrationDeleted = 82, + /// + /// A stage instance was created. + /// + StageInstanceCreated = 83, + /// + /// A stage instance was updated. + /// + StageInstanceUpdated = 84, + /// + /// A stage instance was deleted. + /// + StageInstanceDeleted = 85, + + /// + /// A sticker was created. + /// + StickerCreated = 90, + /// + /// A sticker was updated. + /// + StickerUpdated = 91, + /// + /// A sticker was deleted. + /// + StickerDeleted = 92, + /// + /// A thread was created. + /// + ThreadCreate = 110, + /// + /// A thread was updated. + /// + ThreadUpdate = 111, + /// + /// A thread was deleted. + /// + ThreadDelete = 112 } } diff --git a/src/Discord.Net.Core/Entities/Channels/AudioChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/AudioChannelProperties.cs new file mode 100644 index 000000000..01d436f2a --- /dev/null +++ b/src/Discord.Net.Core/Entities/Channels/AudioChannelProperties.cs @@ -0,0 +1,18 @@ +namespace Discord +{ + /// + /// Provides properties that are used to modify an with the specified changes. + /// + public class AudioChannelProperties + { + /// + /// Sets whether the user should be muted. + /// + public Optional SelfMute { get; set; } + + /// + /// Sets whether the user should be deafened. + /// + public Optional SelfDeaf { get; set; } + } +} diff --git a/src/Discord.Net.Core/Entities/Channels/ChannelType.cs b/src/Discord.Net.Core/Entities/Channels/ChannelType.cs index 6dd910ba6..e60bd5031 100644 --- a/src/Discord.Net.Core/Entities/Channels/ChannelType.cs +++ b/src/Discord.Net.Core/Entities/Channels/ChannelType.cs @@ -14,6 +14,18 @@ namespace Discord /// The channel is a category channel. Category = 4, /// The channel is a news channel. - News = 5 + News = 5, + /// The channel is a store channel. + Store = 6, + /// The channel is a temporary thread channel under a news channel. + NewsThread = 10, + /// The channel is a temporary thread channel under a text channel. + PublicThread = 11, + /// The channel is a private temporary thread channel under a text channel. + PrivateThread = 12, + /// The channel is a stage voice channel. + Stage = 13, + /// The channel is a guild directory used in hub servers. (Unreleased) + GuildDirectory = 14 } } diff --git a/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs index 9552b0a60..339d6fffd 100644 --- a/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs +++ b/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; + namespace Discord { /// @@ -26,9 +28,13 @@ namespace Discord /// /// /// Setting this value to a category's snowflake identifier will change or set this channel's parent to the - /// specified channel; setting this value to 0 will detach this channel from its parent if one + /// specified channel; setting this value to will detach this channel from its parent if one /// is set. /// public Optional CategoryId { get; set; } + /// + /// Gets or sets the permission overwrites for this channel. + /// + public Optional> PermissionOverwrites { get; set; } } } diff --git a/src/Discord.Net.Core/Entities/Channels/IAudioChannel.cs b/src/Discord.Net.Core/Entities/Channels/IAudioChannel.cs index 179f4b03e..a52d41b3f 100644 --- a/src/Discord.Net.Core/Entities/Channels/IAudioChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IAudioChannel.cs @@ -1,4 +1,5 @@ using Discord.Audio; +using System; using System.Threading.Tasks; namespace Discord @@ -8,6 +9,14 @@ namespace Discord /// public interface IAudioChannel : IChannel { + /// + /// Gets the RTC region for this audio channel. + /// + /// + /// This property can be . + /// + string RTCRegion { get; } + /// /// Connects to this audio channel. /// @@ -27,5 +36,16 @@ namespace Discord /// A task representing the asynchronous operation for disconnecting from the audio channel. /// Task DisconnectAsync(); + + /// + /// Modifies this audio channel. + /// + /// The properties to modify the channel with. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + /// + Task ModifyAsync(Action func, RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs b/src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs index f5b986295..00ec38746 100644 --- a/src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs @@ -27,11 +27,15 @@ namespace Discord /// Specifies if notifications are sent for mentioned users and roles in the message . /// If null, all mentioned roles and users will be notified. /// + /// The message references to be included. Used to reply to specific messages. + /// The message components to be included with this message. Used for interactions. + /// A collection of stickers to send with the message. + /// A array of s to send with this response. Max 10. /// /// A task that represents an asynchronous send operation for delivering the message. The task result /// contains the sent message. /// - Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null); + Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null); /// /// Sends a file to this message channel with an optional caption. /// @@ -59,11 +63,19 @@ namespace Discord /// The to be sent. /// The options to be used when sending the request. /// Whether the message attachment should be hidden as a spoiler. + /// + /// Specifies if notifications are sent for mentioned users and roles in the message . + /// If null, all mentioned roles and users will be notified. + /// + /// The message references to be included. Used to reply to specific messages. + /// The message components to be included with this message. Used for interactions. + /// A collection of stickers to send with the file. + /// A array of s to send with this response. Max 10. /// /// A task that represents an asynchronous send operation for delivering the message. The task result /// contains the sent message. /// - Task SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false); + Task SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null); /// /// Sends a file to this message channel with an optional caption. /// @@ -88,11 +100,77 @@ namespace Discord /// The to be sent. /// The options to be used when sending the request. /// Whether the message attachment should be hidden as a spoiler. + /// + /// Specifies if notifications are sent for mentioned users and roles in the message . + /// If null, all mentioned roles and users will be notified. + /// + /// The message references to be included. Used to reply to specific messages. + /// The message components to be included with this message. Used for interactions. + /// A collection of stickers to send with the file. + /// A array of s to send with this response. Max 10. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null); + /// + /// Sends a file to this message channel with an optional caption. + /// + /// + /// This method sends a file as if you are uploading an attachment directly from your Discord client. + /// + /// If you wish to upload an image and have it embedded in a embed, + /// you may upload the file and refer to the file with "attachment://filename.ext" in the + /// . See the example section for its usage. + /// + /// + /// The attachment containing the file and description. + /// The message to be sent. + /// Whether the message should be read aloud by Discord or not. + /// The to be sent. + /// The options to be used when sending the request. + /// + /// Specifies if notifications are sent for mentioned users and roles in the message . + /// If null, all mentioned roles and users will be notified. + /// + /// The message references to be included. Used to reply to specific messages. + /// The message components to be included with this message. Used for interactions. + /// A collection of stickers to send with the file. + /// A array of s to send with this response. Max 10. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + Task SendFileAsync(FileAttachment attachment, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null); + /// + /// Sends a collection of files to this message channel. + /// + /// + /// This method sends files as if you are uploading attachments directly from your Discord client. + /// + /// If you wish to upload an image and have it embedded in a embed, + /// you may upload the file and refer to the file with "attachment://filename.ext" in the + /// . See the example section for its usage. + /// + /// + /// A collection of attachments to upload. + /// The message to be sent. + /// Whether the message should be read aloud by Discord or not. + /// The to be sent. + /// The options to be used when sending the request. + /// + /// Specifies if notifications are sent for mentioned users and roles in the message . + /// If null, all mentioned roles and users will be notified. + /// + /// The message references to be included. Used to reply to specific messages. + /// The message components to be included with this message. Used for interactions. + /// A collection of stickers to send with the file. + /// A array of s to send with this response. Max 10. /// /// A task that represents an asynchronous send operation for delivering the message. The task result /// contains the sent message. /// - Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false); + Task SendFilesAsync(IEnumerable attachments, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null); /// /// Gets a message from this message channel. @@ -246,6 +324,21 @@ namespace Discord /// Task DeleteMessageAsync(IMessage message, RequestOptions options = null); + /// + /// Modifies a message. + /// + /// + /// This method modifies this message with the specified properties. To see an example of this + /// method and what properties are available, please refer to . + /// + /// The snowflake identifier of the message that would be changed. + /// A delegate containing the properties to modify the message with. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + Task ModifyMessageAsync(ulong messageId, Action func, RequestOptions options = null); + /// /// Broadcasts the "user is typing" message to all users in this channel, lasting 10 seconds. /// diff --git a/src/Discord.Net.Core/Entities/Channels/INestedChannel.cs b/src/Discord.Net.Core/Entities/Channels/INestedChannel.cs index 2c9503db1..511d2bf51 100644 --- a/src/Discord.Net.Core/Entities/Channels/INestedChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/INestedChannel.cs @@ -12,7 +12,7 @@ namespace Discord /// Gets the parent (category) ID of this channel in the guild's channel list. /// /// - /// A representing the snowflake identifier of the parent of this channel; + /// A representing the snowflake identifier of the parent of this channel; /// null if none is set. /// ulong? CategoryId { get; } @@ -56,6 +56,58 @@ namespace Discord /// metadata object containing information for the created invite. /// Task CreateInviteAsync(int? maxAge = 86400, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null); + + /// + /// Creates a new invite to this channel. + /// + /// The id of the embedded application to open for this invite. + /// The time (in seconds) until the invite expires. Set to null to never expire. + /// The max amount of times this invite may be used. Set to null to have unlimited uses. + /// If true, the user accepting this invite will be kicked from the guild after closing their client. + /// If true, don't try to reuse a similar invite (useful for creating many unique one time use invites). + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous invite creation operation. The task result contains an invite + /// metadata object containing information for the created invite. + /// + Task CreateInviteToApplicationAsync(ulong applicationId, int? maxAge = 86400, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null); + + /// + /// Creates a new invite to this channel. + /// + /// The application to open for this invite. + /// The time (in seconds) until the invite expires. Set to null to never expire. + /// The max amount of times this invite may be used. Set to null to have unlimited uses. + /// If true, the user accepting this invite will be kicked from the guild after closing their client. + /// If true, don't try to reuse a similar invite (useful for creating many unique one time use invites). + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous invite creation operation. The task result contains an invite + /// metadata object containing information for the created invite. + /// + Task CreateInviteToApplicationAsync(DefaultApplications application, int? maxAge = 86400, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null); + + /// + /// Creates a new invite to this channel. + /// + /// + /// The following example creates a new invite to this channel; the invite lasts for 12 hours and can only + /// be used 3 times throughout its lifespan. + /// + /// await guildChannel.CreateInviteAsync(maxAge: 43200, maxUses: 3); + /// + /// + /// The id of the user whose stream to display for this invite. + /// The time (in seconds) until the invite expires. Set to null to never expire. + /// The max amount of times this invite may be used. Set to null to have unlimited uses. + /// If true, the user accepting this invite will be kicked from the guild after closing their client. + /// If true, don't try to reuse a similar invite (useful for creating many unique one time use invites). + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous invite creation operation. The task result contains an invite + /// metadata object containing information for the created invite. + /// + Task CreateInviteToStreamAsync(IUser user, int? maxAge = 86400, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null); /// /// Gets a collection of all invites to this channel. /// B diff --git a/src/Discord.Net.Core/Entities/Channels/INewsChannel.cs b/src/Discord.Net.Core/Entities/Channels/INewsChannel.cs new file mode 100644 index 000000000..a1223b48b --- /dev/null +++ b/src/Discord.Net.Core/Entities/Channels/INewsChannel.cs @@ -0,0 +1,9 @@ +namespace Discord +{ + /// + /// Represents a generic news channel in a guild that can send and receive messages. + /// + public interface INewsChannel : ITextChannel + { + } +} diff --git a/src/Discord.Net.Core/Entities/Channels/IStageChannel.cs b/src/Discord.Net.Core/Entities/Channels/IStageChannel.cs new file mode 100644 index 000000000..5e0be5b7e --- /dev/null +++ b/src/Discord.Net.Core/Entities/Channels/IStageChannel.cs @@ -0,0 +1,114 @@ +using System; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents a generic Stage Channel. + /// + public interface IStageChannel : IVoiceChannel + { + /// + /// Gets the topic of the Stage instance. + /// + /// + /// If the stage isn't live then this property will be set to . + /// + string Topic { get; } + + /// + /// Gets the of the current stage. + /// + /// + /// If the stage isn't live then this property will be set to . + /// + StagePrivacyLevel? PrivacyLevel { get; } + + /// + /// Gets whether or not stage discovery is disabled. + /// + bool? IsDiscoverableDisabled { get; } + + /// + /// Gets whether or not the stage is live. + /// + bool IsLive { get; } + + /// + /// Starts the stage, creating a stage instance. + /// + /// The topic for the stage/ + /// The privacy level of the stage. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous start operation. + /// + Task StartStageAsync(string topic, StagePrivacyLevel privacyLevel = StagePrivacyLevel.GuildOnly, RequestOptions options = null); + + /// + /// Modifies the current stage instance. + /// + /// The properties to modify the stage instance with. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modify operation. + /// + Task ModifyInstanceAsync(Action func, RequestOptions options = null); + + /// + /// Stops the stage, deleting the stage instance. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous stop operation. + /// + Task StopStageAsync(RequestOptions options = null); + + /// + /// Indicates that the bot would like to speak within a stage channel. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous request to speak operation. + /// + Task RequestToSpeakAsync(RequestOptions options = null); + + /// + /// Makes the current user become a speaker within a stage. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous speaker modify operation. + /// + Task BecomeSpeakerAsync(RequestOptions options = null); + + /// + /// Makes the current user a listener. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous stop operation. + /// + Task StopSpeakingAsync(RequestOptions options = null); + + /// + /// Makes a user a speaker within a stage. + /// + /// The user to make the speaker. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous move operation. + /// + Task MoveToSpeakerAsync(IGuildUser user, RequestOptions options = null); + + /// + /// Removes a user from speaking. + /// + /// The user to remove from speaking. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous remove operation. + /// + Task RemoveFromSpeakerAsync(IGuildUser user, RequestOptions options = null); + } +} diff --git a/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs b/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs index a2baf6990..ae0fe674b 100644 --- a/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs @@ -114,5 +114,40 @@ namespace Discord /// of webhooks that is available in this channel. /// Task> GetWebhooksAsync(RequestOptions options = null); + + /// + /// Creates a thread within this . + /// + /// + /// When is the thread type will be based off of the + /// channel its created in. When called on a , it creates a . + /// When called on a , it creates a . The id of the created + /// thread will be the same as the id of the message, and as such a message can only have a + /// single thread created from it. + /// + /// The name of the thread. + /// + /// The type of the thread. + /// + /// Note: This parameter is not used if the parameter is not specified. + /// + /// + /// + /// The duration on which this thread archives after. + /// + /// Note: Options and + /// are only available for guilds that are boosted. You can check in the to see if the + /// guild has the THREE_DAY_THREAD_ARCHIVE and SEVEN_DAY_THREAD_ARCHIVE. + /// + /// + /// The message which to start the thread from. + /// Whether non-moderators can add other non-moderators to a thread; only available when creating a private thread + /// The amount of seconds a user has to wait before sending another message (0-21600) + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous create operation. The task result contains a + /// + Task CreateThreadAsync(string name, ThreadType type = ThreadType.PublicThread, ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, + IMessage message = null, bool? invitable = null, int? slowmode = null, RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Entities/Channels/IThreadChannel.cs b/src/Discord.Net.Core/Entities/Channels/IThreadChannel.cs new file mode 100644 index 000000000..50e46efa6 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Channels/IThreadChannel.cs @@ -0,0 +1,89 @@ +using System; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents a thread channel inside of a guild. + /// + public interface IThreadChannel : ITextChannel + { + /// + /// Gets the type of the current thread channel. + /// + ThreadType Type { get; } + + /// + /// Gets whether or not the current user has joined this thread. + /// + bool HasJoined { get; } + + /// + /// Gets whether or not the current thread is archived. + /// + bool IsArchived { get; } + + /// + /// Gets the duration of time before the thread is automatically archived after no activity. + /// + ThreadArchiveDuration AutoArchiveDuration { get; } + + /// + /// Gets the timestamp when the thread's archive status was last changed, used for calculating recent activity. + /// + DateTimeOffset ArchiveTimestamp { get; } + + /// + /// Gets whether or not the current thread is locked. + /// + bool IsLocked { get; } + + /// + /// Gets an approximate count of users in a thread, stops counting after 50. + /// + int MemberCount { get; } + + /// + /// Gets an approximate count of messages in a thread, stops counting after 50. + /// + int MessageCount { get; } + + /// + /// Joins the current thread. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous join operation. + /// + Task JoinAsync(RequestOptions options = null); + + /// + /// Leaves the current thread. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous leave operation. + /// + Task LeaveAsync(RequestOptions options = null); + + /// + /// Adds a user to this thread. + /// + /// The to add. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous operation of adding a member to a thread. + /// + Task AddUserAsync(IGuildUser user, RequestOptions options = null); + + /// + /// Removes a user from this thread. + /// + /// The to remove from this thread. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous operation of removing a user from this thread. + /// + Task RemoveUserAsync(IGuildUser user, RequestOptions options = null); + } +} diff --git a/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs b/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs index 9c2d008ee..1d36a41b9 100644 --- a/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs @@ -6,7 +6,7 @@ namespace Discord /// /// Represents a generic voice channel in a guild. /// - public interface IVoiceChannel : INestedChannel, IAudioChannel + public interface IVoiceChannel : INestedChannel, IAudioChannel, IMentionable { /// /// Gets the bit-rate that the clients in this voice channel are requested to use. diff --git a/src/Discord.Net.Core/Entities/Channels/StageInstanceProperties.cs b/src/Discord.Net.Core/Entities/Channels/StageInstanceProperties.cs new file mode 100644 index 000000000..35201fe0f --- /dev/null +++ b/src/Discord.Net.Core/Entities/Channels/StageInstanceProperties.cs @@ -0,0 +1,18 @@ +namespace Discord +{ + /// + /// Represents properties to use when modifying a stage instance. + /// + public class StageInstanceProperties + { + /// + /// Gets or sets the topic of the stage. + /// + public Optional Topic { get; set; } + + /// + /// Gets or sets the privacy level of the stage. + /// + public Optional PrivacyLevel { get; set; } + } +} diff --git a/src/Discord.Net.Core/Entities/Channels/StagePrivacyLevel.cs b/src/Discord.Net.Core/Entities/Channels/StagePrivacyLevel.cs new file mode 100644 index 000000000..0582a3e52 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Channels/StagePrivacyLevel.cs @@ -0,0 +1,17 @@ +namespace Discord +{ + /// + /// Represents the privacy level of a stage. + /// + public enum StagePrivacyLevel + { + /// + /// The Stage instance is visible publicly, such as on Stage Discovery. + /// + Public = 1, + /// + /// The Stage instance is visible to only guild members. + /// + GuildOnly = 2 + } +} diff --git a/src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs index 821f358f5..2dceb025c 100644 --- a/src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs +++ b/src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs @@ -38,5 +38,21 @@ namespace Discord /// /// Thrown if the value does not fall within [0, 21600]. public Optional SlowModeInterval { get; set; } + + /// + /// Gets or sets whether or not the thread is archived. + /// + public Optional Archived { get; set; } + + /// + /// Gets or sets whether or not the thread is locked. + /// + public Optional Locked { get; set; } + + /// + /// Gets or sets the auto archive duration. + /// + public Optional AutoArchiveDuration { get; set; } + } } diff --git a/src/Discord.Net.Core/Entities/Channels/ThreadArchiveDuration.cs b/src/Discord.Net.Core/Entities/Channels/ThreadArchiveDuration.cs new file mode 100644 index 000000000..2c8a0652c --- /dev/null +++ b/src/Discord.Net.Core/Entities/Channels/ThreadArchiveDuration.cs @@ -0,0 +1,34 @@ +namespace Discord +{ + /// + /// Represents the thread auto archive duration. + /// + public enum ThreadArchiveDuration + { + /// + /// One hour (60 minutes). + /// + OneHour = 60, + + /// + /// One day (1440 minutes). + /// + OneDay = 1440, + + /// + /// Three days (4320 minutes). + /// + /// This option is explicitly available to nitro users. + /// + /// + ThreeDays = 4320, + + /// + /// One week (10080 minutes). + /// + /// This option is explicitly available to nitro users. + /// + /// + OneWeek = 10080 + } +} diff --git a/src/Discord.Net.Core/Entities/Channels/ThreadType.cs b/src/Discord.Net.Core/Entities/Channels/ThreadType.cs new file mode 100644 index 000000000..379128d21 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Channels/ThreadType.cs @@ -0,0 +1,23 @@ +namespace Discord +{ + /// + /// Represents types of threads. + /// + public enum ThreadType + { + /// + /// Represents a temporary sub-channel within a GUILD_NEWS channel. + /// + NewsThread = 10, + + /// + /// Represents a temporary sub-channel within a GUILD_TEXT channel. + /// + PublicThread = 11, + + /// + /// Represents a temporary sub-channel within a GUILD_TEXT channel that is only viewable by those invited and those with the MANAGE_THREADS permission + /// + PrivateThread = 12 + } +} diff --git a/src/Discord.Net.Core/Entities/Channels/VoiceChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/VoiceChannelProperties.cs index fb4d47800..251a45c3d 100644 --- a/src/Discord.Net.Core/Entities/Channels/VoiceChannelProperties.cs +++ b/src/Discord.Net.Core/Entities/Channels/VoiceChannelProperties.cs @@ -13,5 +13,9 @@ namespace Discord /// Gets or sets the maximum number of users that can be present in a channel, or null if none. /// public Optional UserLimit { get; set; } + /// + /// Gets or sets the channel voice region id, automatic when set to . + /// + public Optional RTCRegion { get; set; } } } diff --git a/src/Discord.Net.Core/Entities/Emotes/Emoji.cs b/src/Discord.Net.Core/Entities/Emotes/Emoji.cs index d5e795094..2bf17d645 100644 --- a/src/Discord.Net.Core/Entities/Emotes/Emoji.cs +++ b/src/Discord.Net.Core/Entities/Emotes/Emoji.cs @@ -1,3 +1,9 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Collections.ObjectModel; +using System.Linq; + namespace Discord { /// @@ -5,12 +11,11 @@ namespace Discord /// public class Emoji : IEmote { - // TODO: need to constrain this to Unicode-only emojis somehow - /// public string Name { get; } + /// - /// Gets the Unicode representation of this emote. + /// Gets the Unicode representation of this emoji. /// /// /// A string that resolves to . @@ -32,16 +37,5941 @@ namespace Discord /// The object to compare with the current object. public override bool Equals(object other) { - if (other == null) return false; - if (other == this) return true; + if (other == null) + return false; + + if (other == this) + return true; + + return other is Emoji otherEmoji && string.Equals(Name, otherEmoji.Name); + } + + /// Tries to parse an from its raw format. + /// The raw encoding of an emoji. For example: :heart: or ❤ + /// An emoji. + public static bool TryParse(string text, out Emoji result) + { + result = null; + if (string.IsNullOrWhiteSpace(text)) + return false; + + if (NamesAndUnicodes.ContainsKey(text)) + result = new Emoji(NamesAndUnicodes[text]); + + if (Unicodes.Contains(text)) + result = new Emoji(text); + + return result != null; + } - var otherEmoji = other as Emoji; - if (otherEmoji == null) return false; + /// Parse an from its raw format. + /// The raw encoding of an emoji. For example: :heart: or ❤ + /// String is not emoji or unicode! + public static Emoji Parse(string emojiStr) + { + if (!TryParse(emojiStr, out var emoji)) + throw new FormatException("String is not emoji name or unicode!"); - return string.Equals(Name, otherEmoji.Name); + return emoji; } /// public override int GetHashCode() => Name.GetHashCode(); + + private static IReadOnlyDictionary NamesAndUnicodes { get; } = new Dictionary + { + [",:("] = "\uD83D\uDE13", + [",:)"] = "\uD83D\uDE05", + [",:-("] = "\uD83D\uDE13", + [",:-)"] = "\uD83D\uDE05", + [",=("] = "\uD83D\uDE13", + [",=)"] = "\uD83D\uDE05", + [",=-("] = "\uD83D\uDE13", + [",=-)"] = "\uD83D\uDE05", + ["0:)"] = "\uD83D\uDE07", + ["0:-)"] = "\uD83D\uDE07", + ["0=)"] = "\uD83D\uDE07", + ["0=-)"] = "\uD83D\uDE07", + ["8-)"] = "\uD83D\uDE0E", + [":$"] = "\uD83D\uDE12", + [":'("] = "\uD83D\uDE22", + [":')"] = "\uD83D\uDE02", + [":'-("] = "\uD83D\uDE22", + [":'-)"] = "\uD83D\uDE02", + [":'-D"] = "\uD83D\uDE02", + [":'D"] = "\uD83D\uDE02", + [":("] = "\uD83D\uDE26", + [":)"] = "\uD83D\uDE42", + [":*"] = "\uD83D\uDE17", + [":+1:"] = "\uD83D\uDC4D", + [":+1::skin-tone-1:"] = "\uD83D\uDC4D\uD83C\uDFFB", + [":+1::skin-tone-2:"] = "\uD83D\uDC4D\uD83C\uDFFC", + [":+1::skin-tone-3:"] = "\uD83D\uDC4D\uD83C\uDFFD", + [":+1::skin-tone-4:"] = "\uD83D\uDC4D\uD83C\uDFFE", + [":+1::skin-tone-5:"] = "\uD83D\uDC4D\uD83C\uDFFF", + [":+1_tone1:"] = "\uD83D\uDC4D\uD83C\uDFFB", + [":+1_tone2:"] = "\uD83D\uDC4D\uD83C\uDFFC", + [":+1_tone3:"] = "\uD83D\uDC4D\uD83C\uDFFD", + [":+1_tone4:"] = "\uD83D\uDC4D\uD83C\uDFFE", + [":+1_tone5:"] = "\uD83D\uDC4D\uD83C\uDFFF", + [":,'("] = "\uD83D\uDE2D", + [":,'-("] = "\uD83D\uDE2D", + [":,("] = "\uD83D\uDE22", + [":,)"] = "\uD83D\uDE02", + [":,-("] = "\uD83D\uDE22", + [":,-)"] = "\uD83D\uDE02", + [":,-D"] = "\uD83D\uDE02", + [":,D"] = "\uD83D\uDE02", + [":-$"] = "\uD83D\uDE12", + [":-("] = "\uD83D\uDE26", + [":-)"] = "\uD83D\uDE42", + [":-*"] = "\uD83D\uDE17", + [":-/"] = "\uD83D\uDE15", + [":-1:"] = "\uD83D\uDC4E", + [":-1::skin-tone-1:"] = "\uD83D\uDC4E\uD83C\uDFFB", + [":-1::skin-tone-2:"] = "\uD83D\uDC4E\uD83C\uDFFC", + [":-1::skin-tone-3:"] = "\uD83D\uDC4E\uD83C\uDFFD", + [":-1::skin-tone-4:"] = "\uD83D\uDC4E\uD83C\uDFFE", + [":-1::skin-tone-5:"] = "\uD83D\uDC4E\uD83C\uDFFF", + [":-@"] = "\uD83D\uDE21", + [":-D"] = "\uD83D\uDE04", + [":-O"] = "\uD83D\uDE2E", + [":-P"] = "\uD83D\uDE1B", + [":-S"] = "\uD83D\uDE12", + [":-Z"] = "\uD83D\uDE12", + [":-\")"] = "\uD83D\uDE0A", + [":-\\"] = "\uD83D\uDE15", + [":-o"] = "\uD83D\uDE2E", + [":-|"] = "\uD83D\uDE10", + [":100:"] = "\uD83D\uDCAF", + [":1234:"] = "\uD83D\uDD22", + [":8ball:"] = "\uD83C\uDFB1", + [":@"] = "\uD83D\uDE21", + [":D"] = "\uD83D\uDE04", + [":O"] = "\uD83D\uDE2E", + [":P"] = "\uD83D\uDE1B", + [":\")"] = "\uD83D\uDE0A", + [":_1_tone1:"] = "\uD83D\uDC4E\uD83C\uDFFB", + [":_1_tone2:"] = "\uD83D\uDC4E\uD83C\uDFFC", + [":_1_tone3:"] = "\uD83D\uDC4E\uD83C\uDFFD", + [":_1_tone4:"] = "\uD83D\uDC4E\uD83C\uDFFE", + [":_1_tone5:"] = "\uD83D\uDC4E\uD83C\uDFFF", + [":a:"] = "\uD83C\uDD70️", + [":ab:"] = "\uD83C\uDD8E", + [":abacus:"] = "\uD83E\uDDEE", + [":abc:"] = "\uD83D\uDD24", + [":abcd:"] = "\uD83D\uDD21", + [":accept:"] = "\uD83C\uDE51", + [":adhesive_bandage:"] = "\uD83E\uDE79", + [":admission_tickets:"] = "\uD83C\uDF9F️", + [":adult:"] = "\uD83E\uDDD1", + [":adult::skin-tone-1:"] = "\uD83E\uDDD1\uD83C\uDFFB", + [":adult::skin-tone-2:"] = "\uD83E\uDDD1\uD83C\uDFFC", + [":adult::skin-tone-3:"] = "\uD83E\uDDD1\uD83C\uDFFD", + [":adult::skin-tone-4:"] = "\uD83E\uDDD1\uD83C\uDFFE", + [":adult::skin-tone-5:"] = "\uD83E\uDDD1\uD83C\uDFFF", + [":adult_dark_skin_tone:"] = "\uD83E\uDDD1\uD83C\uDFFF", + [":adult_light_skin_tone:"] = "\uD83E\uDDD1\uD83C\uDFFB", + [":adult_medium_dark_skin_tone:"] = "\uD83E\uDDD1\uD83C\uDFFE", + [":adult_medium_light_skin_tone:"] = "\uD83E\uDDD1\uD83C\uDFFC", + [":adult_medium_skin_tone:"] = "\uD83E\uDDD1\uD83C\uDFFD", + [":adult_tone1:"] = "\uD83E\uDDD1\uD83C\uDFFB", + [":adult_tone2:"] = "\uD83E\uDDD1\uD83C\uDFFC", + [":adult_tone3:"] = "\uD83E\uDDD1\uD83C\uDFFD", + [":adult_tone4:"] = "\uD83E\uDDD1\uD83C\uDFFE", + [":adult_tone5:"] = "\uD83E\uDDD1\uD83C\uDFFF", + [":aerial_tramway:"] = "\uD83D\uDEA1", + [":airplane:"] = "✈️", + [":airplane_arriving:"] = "\uD83D\uDEEC", + [":airplane_departure:"] = "\uD83D\uDEEB", + [":airplane_small:"] = "\uD83D\uDEE9️", + [":alarm_clock:"] = "⏰", + [":alembic:"] = "⚗️", + [":alien:"] = "\uD83D\uDC7D", + [":ambulance:"] = "\uD83D\uDE91", + [":amphora:"] = "\uD83C\uDFFA", + [":anchor:"] = "⚓", + [":angel:"] = "\uD83D\uDC7C", + [":angel::skin-tone-1:"] = "\uD83D\uDC7C\uD83C\uDFFB", + [":angel::skin-tone-2:"] = "\uD83D\uDC7C\uD83C\uDFFC", + [":angel::skin-tone-3:"] = "\uD83D\uDC7C\uD83C\uDFFD", + [":angel::skin-tone-4:"] = "\uD83D\uDC7C\uD83C\uDFFE", + [":angel::skin-tone-5:"] = "\uD83D\uDC7C\uD83C\uDFFF", + [":angel_tone1:"] = "\uD83D\uDC7C\uD83C\uDFFB", + [":angel_tone2:"] = "\uD83D\uDC7C\uD83C\uDFFC", + [":angel_tone3:"] = "\uD83D\uDC7C\uD83C\uDFFD", + [":angel_tone4:"] = "\uD83D\uDC7C\uD83C\uDFFE", + [":angel_tone5:"] = "\uD83D\uDC7C\uD83C\uDFFF", + [":anger:"] = "\uD83D\uDCA2", + [":anger_right:"] = "\uD83D\uDDEF️", + [":angry:"] = "\uD83D\uDE20", + [":anguished:"] = "\uD83D\uDE27", + [":ant:"] = "\uD83D\uDC1C", + [":apple:"] = "\uD83C\uDF4E", + [":aquarius:"] = "♒", + [":archery:"] = "\uD83C\uDFF9", + [":aries:"] = "♈", + [":arrow_backward:"] = "◀️", + [":arrow_double_down:"] = "⏬", + [":arrow_double_up:"] = "⏫", + [":arrow_down:"] = "⬇️", + [":arrow_down_small:"] = "\uD83D\uDD3D", + [":arrow_forward:"] = "▶️", + [":arrow_heading_down:"] = "⤵️", + [":arrow_heading_up:"] = "⤴️", + [":arrow_left:"] = "⬅️", + [":arrow_lower_left:"] = "↙️", + [":arrow_lower_right:"] = "↘️", + [":arrow_right:"] = "➡️", + [":arrow_right_hook:"] = "↪️", + [":arrow_up:"] = "⬆️", + [":arrow_up_down:"] = "↕️", + [":arrow_up_small:"] = "\uD83D\uDD3C", + [":arrow_upper_left:"] = "↖️", + [":arrow_upper_right:"] = "↗️", + [":arrows_clockwise:"] = "\uD83D\uDD03", + [":arrows_counterclockwise:"] = "\uD83D\uDD04", + [":art:"] = "\uD83C\uDFA8", + [":articulated_lorry:"] = "\uD83D\uDE9B", + [":asterisk:"] = "*️⃣", + [":astonished:"] = "\uD83D\uDE32", + [":athletic_shoe:"] = "\uD83D\uDC5F", + [":atm:"] = "\uD83C\uDFE7", + [":atom:"] = "⚛️", + [":atom_symbol:"] = "⚛️", + [":auto_rickshaw:"] = "\uD83D\uDEFA", + [":avocado:"] = "\uD83E\uDD51", + [":axe:"] = "\uD83E\uDE93", + [":b:"] = "\uD83C\uDD71️", + [":baby:"] = "\uD83D\uDC76", + [":baby::skin-tone-1:"] = "\uD83D\uDC76\uD83C\uDFFB", + [":baby::skin-tone-2:"] = "\uD83D\uDC76\uD83C\uDFFC", + [":baby::skin-tone-3:"] = "\uD83D\uDC76\uD83C\uDFFD", + [":baby::skin-tone-4:"] = "\uD83D\uDC76\uD83C\uDFFE", + [":baby::skin-tone-5:"] = "\uD83D\uDC76\uD83C\uDFFF", + [":baby_bottle:"] = "\uD83C\uDF7C", + [":baby_chick:"] = "\uD83D\uDC24", + [":baby_symbol:"] = "\uD83D\uDEBC", + [":baby_tone1:"] = "\uD83D\uDC76\uD83C\uDFFB", + [":baby_tone2:"] = "\uD83D\uDC76\uD83C\uDFFC", + [":baby_tone3:"] = "\uD83D\uDC76\uD83C\uDFFD", + [":baby_tone4:"] = "\uD83D\uDC76\uD83C\uDFFE", + [":baby_tone5:"] = "\uD83D\uDC76\uD83C\uDFFF", + [":back:"] = "\uD83D\uDD19", + [":back_of_hand:"] = "\uD83E\uDD1A", + [":back_of_hand::skin-tone-1:"] = "\uD83E\uDD1A\uD83C\uDFFB", + [":back_of_hand::skin-tone-2:"] = "\uD83E\uDD1A\uD83C\uDFFC", + [":back_of_hand::skin-tone-3:"] = "\uD83E\uDD1A\uD83C\uDFFD", + [":back_of_hand::skin-tone-4:"] = "\uD83E\uDD1A\uD83C\uDFFE", + [":back_of_hand::skin-tone-5:"] = "\uD83E\uDD1A\uD83C\uDFFF", + [":back_of_hand_tone1:"] = "\uD83E\uDD1A\uD83C\uDFFB", + [":back_of_hand_tone2:"] = "\uD83E\uDD1A\uD83C\uDFFC", + [":back_of_hand_tone3:"] = "\uD83E\uDD1A\uD83C\uDFFD", + [":back_of_hand_tone4:"] = "\uD83E\uDD1A\uD83C\uDFFE", + [":back_of_hand_tone5:"] = "\uD83E\uDD1A\uD83C\uDFFF", + [":bacon:"] = "\uD83E\uDD53", + [":badger:"] = "\uD83E\uDDA1", + [":badminton:"] = "\uD83C\uDFF8", + [":bagel:"] = "\uD83E\uDD6F", + [":baggage_claim:"] = "\uD83D\uDEC4", + [":baguette_bread:"] = "\uD83E\uDD56", + [":ballet_shoes:"] = "\uD83E\uDE70", + [":balloon:"] = "\uD83C\uDF88", + [":ballot_box:"] = "\uD83D\uDDF3️", + [":ballot_box_with_ballot:"] = "\uD83D\uDDF3️", + [":ballot_box_with_check:"] = "☑️", + [":bamboo:"] = "\uD83C\uDF8D", + [":banana:"] = "\uD83C\uDF4C", + [":bangbang:"] = "‼️", + [":banjo:"] = "\uD83E\uDE95", + [":bank:"] = "\uD83C\uDFE6", + [":bar_chart:"] = "\uD83D\uDCCA", + [":barber:"] = "\uD83D\uDC88", + [":baseball:"] = "⚾", + [":basket:"] = "\uD83E\uDDFA", + [":basketball:"] = "\uD83C\uDFC0", + [":basketball_player:"] = "⛹️", + [":basketball_player::skin-tone-1:"] = "⛹\uD83C\uDFFB", + [":basketball_player::skin-tone-2:"] = "⛹\uD83C\uDFFC", + [":basketball_player::skin-tone-3:"] = "⛹\uD83C\uDFFD", + [":basketball_player::skin-tone-4:"] = "⛹\uD83C\uDFFE", + [":basketball_player::skin-tone-5:"] = "⛹\uD83C\uDFFF", + [":basketball_player_tone1:"] = "⛹\uD83C\uDFFB", + [":basketball_player_tone2:"] = "⛹\uD83C\uDFFC", + [":basketball_player_tone3:"] = "⛹\uD83C\uDFFD", + [":basketball_player_tone4:"] = "⛹\uD83C\uDFFE", + [":basketball_player_tone5:"] = "⛹\uD83C\uDFFF", + [":bat:"] = "\uD83E\uDD87", + [":bath:"] = "\uD83D\uDEC0", + [":bath::skin-tone-1:"] = "\uD83D\uDEC0\uD83C\uDFFB", + [":bath::skin-tone-2:"] = "\uD83D\uDEC0\uD83C\uDFFC", + [":bath::skin-tone-3:"] = "\uD83D\uDEC0\uD83C\uDFFD", + [":bath::skin-tone-4:"] = "\uD83D\uDEC0\uD83C\uDFFE", + [":bath::skin-tone-5:"] = "\uD83D\uDEC0\uD83C\uDFFF", + [":bath_tone1:"] = "\uD83D\uDEC0\uD83C\uDFFB", + [":bath_tone2:"] = "\uD83D\uDEC0\uD83C\uDFFC", + [":bath_tone3:"] = "\uD83D\uDEC0\uD83C\uDFFD", + [":bath_tone4:"] = "\uD83D\uDEC0\uD83C\uDFFE", + [":bath_tone5:"] = "\uD83D\uDEC0\uD83C\uDFFF", + [":bathtub:"] = "\uD83D\uDEC1", + [":battery:"] = "\uD83D\uDD0B", + [":beach:"] = "\uD83C\uDFD6️", + [":beach_umbrella:"] = "⛱️", + [":beach_with_umbrella:"] = "\uD83C\uDFD6️", + [":bear:"] = "\uD83D\uDC3B", + [":bearded_person:"] = "\uD83E\uDDD4", + [":bearded_person::skin-tone-1:"] = "\uD83E\uDDD4\uD83C\uDFFB", + [":bearded_person::skin-tone-2:"] = "\uD83E\uDDD4\uD83C\uDFFC", + [":bearded_person::skin-tone-3:"] = "\uD83E\uDDD4\uD83C\uDFFD", + [":bearded_person::skin-tone-4:"] = "\uD83E\uDDD4\uD83C\uDFFE", + [":bearded_person::skin-tone-5:"] = "\uD83E\uDDD4\uD83C\uDFFF", + [":bearded_person_dark_skin_tone:"] = "\uD83E\uDDD4\uD83C\uDFFF", + [":bearded_person_light_skin_tone:"] = "\uD83E\uDDD4\uD83C\uDFFB", + [":bearded_person_medium_dark_skin_tone:"] = "\uD83E\uDDD4\uD83C\uDFFE", + [":bearded_person_medium_light_skin_tone:"] = "\uD83E\uDDD4\uD83C\uDFFC", + [":bearded_person_medium_skin_tone:"] = "\uD83E\uDDD4\uD83C\uDFFD", + [":bearded_person_tone1:"] = "\uD83E\uDDD4\uD83C\uDFFB", + [":bearded_person_tone2:"] = "\uD83E\uDDD4\uD83C\uDFFC", + [":bearded_person_tone3:"] = "\uD83E\uDDD4\uD83C\uDFFD", + [":bearded_person_tone4:"] = "\uD83E\uDDD4\uD83C\uDFFE", + [":bearded_person_tone5:"] = "\uD83E\uDDD4\uD83C\uDFFF", + [":bed:"] = "\uD83D\uDECF️", + [":bee:"] = "\uD83D\uDC1D", + [":beer:"] = "\uD83C\uDF7A", + [":beers:"] = "\uD83C\uDF7B", + [":beetle:"] = "\uD83D\uDC1E", + [":beginner:"] = "\uD83D\uDD30", + [":bell:"] = "\uD83D\uDD14", + [":bellhop:"] = "\uD83D\uDECE️", + [":bellhop_bell:"] = "\uD83D\uDECE️", + [":bento:"] = "\uD83C\uDF71", + [":beverage_box:"] = "\uD83E\uDDC3", + [":bicyclist:"] = "\uD83D\uDEB4", + [":bicyclist::skin-tone-1:"] = "\uD83D\uDEB4\uD83C\uDFFB", + [":bicyclist::skin-tone-2:"] = "\uD83D\uDEB4\uD83C\uDFFC", + [":bicyclist::skin-tone-3:"] = "\uD83D\uDEB4\uD83C\uDFFD", + [":bicyclist::skin-tone-4:"] = "\uD83D\uDEB4\uD83C\uDFFE", + [":bicyclist::skin-tone-5:"] = "\uD83D\uDEB4\uD83C\uDFFF", + [":bicyclist_tone1:"] = "\uD83D\uDEB4\uD83C\uDFFB", + [":bicyclist_tone2:"] = "\uD83D\uDEB4\uD83C\uDFFC", + [":bicyclist_tone3:"] = "\uD83D\uDEB4\uD83C\uDFFD", + [":bicyclist_tone4:"] = "\uD83D\uDEB4\uD83C\uDFFE", + [":bicyclist_tone5:"] = "\uD83D\uDEB4\uD83C\uDFFF", + [":bike:"] = "\uD83D\uDEB2", + [":bikini:"] = "\uD83D\uDC59", + [":billed_cap:"] = "\uD83E\uDDE2", + [":biohazard:"] = "☣️", + [":biohazard_sign:"] = "☣️", + [":bird:"] = "\uD83D\uDC26", + [":birthday:"] = "\uD83C\uDF82", + [":black_circle:"] = "⚫", + [":black_heart:"] = "\uD83D\uDDA4", + [":black_joker:"] = "\uD83C\uDCCF", + [":black_large_square:"] = "⬛", + [":black_medium_small_square:"] = "◾", + [":black_medium_square:"] = "◼️", + [":black_nib:"] = "✒️", + [":black_small_square:"] = "▪️", + [":black_square_button:"] = "\uD83D\uDD32", + [":blond_haired_man:"] = "\uD83D\uDC71\u200D♂️", + [":blond_haired_man::skin-tone-1:"] = "\uD83D\uDC71\uD83C\uDFFB\u200D♂️", + [":blond_haired_man::skin-tone-2:"] = "\uD83D\uDC71\uD83C\uDFFC\u200D♂️", + [":blond_haired_man::skin-tone-3:"] = "\uD83D\uDC71\uD83C\uDFFD\u200D♂️", + [":blond_haired_man::skin-tone-4:"] = "\uD83D\uDC71\uD83C\uDFFE\u200D♂️", + [":blond_haired_man::skin-tone-5:"] = "\uD83D\uDC71\uD83C\uDFFF\u200D♂️", + [":blond_haired_man_dark_skin_tone:"] = "\uD83D\uDC71\uD83C\uDFFF\u200D♂️", + [":blond_haired_man_light_skin_tone:"] = "\uD83D\uDC71\uD83C\uDFFB\u200D♂️", + [":blond_haired_man_medium_dark_skin_tone:"] = "\uD83D\uDC71\uD83C\uDFFE\u200D♂️", + [":blond_haired_man_medium_light_skin_tone:"] = "\uD83D\uDC71\uD83C\uDFFC\u200D♂️", + [":blond_haired_man_medium_skin_tone:"] = "\uD83D\uDC71\uD83C\uDFFD\u200D♂️", + [":blond_haired_man_tone1:"] = "\uD83D\uDC71\uD83C\uDFFB\u200D♂️", + [":blond_haired_man_tone2:"] = "\uD83D\uDC71\uD83C\uDFFC\u200D♂️", + [":blond_haired_man_tone3:"] = "\uD83D\uDC71\uD83C\uDFFD\u200D♂️", + [":blond_haired_man_tone4:"] = "\uD83D\uDC71\uD83C\uDFFE\u200D♂️", + [":blond_haired_man_tone5:"] = "\uD83D\uDC71\uD83C\uDFFF\u200D♂️", + [":blond_haired_person:"] = "\uD83D\uDC71", + [":blond_haired_person::skin-tone-1:"] = "\uD83D\uDC71\uD83C\uDFFB", + [":blond_haired_person::skin-tone-2:"] = "\uD83D\uDC71\uD83C\uDFFC", + [":blond_haired_person::skin-tone-3:"] = "\uD83D\uDC71\uD83C\uDFFD", + [":blond_haired_person::skin-tone-4:"] = "\uD83D\uDC71\uD83C\uDFFE", + [":blond_haired_person::skin-tone-5:"] = "\uD83D\uDC71\uD83C\uDFFF", + [":blond_haired_person_tone1:"] = "\uD83D\uDC71\uD83C\uDFFB", + [":blond_haired_person_tone2:"] = "\uD83D\uDC71\uD83C\uDFFC", + [":blond_haired_person_tone3:"] = "\uD83D\uDC71\uD83C\uDFFD", + [":blond_haired_person_tone4:"] = "\uD83D\uDC71\uD83C\uDFFE", + [":blond_haired_person_tone5:"] = "\uD83D\uDC71\uD83C\uDFFF", + [":blond_haired_woman:"] = "\uD83D\uDC71\u200D♀️", + [":blond_haired_woman::skin-tone-1:"] = "\uD83D\uDC71\uD83C\uDFFB\u200D♀️", + [":blond_haired_woman::skin-tone-2:"] = "\uD83D\uDC71\uD83C\uDFFC\u200D♀️", + [":blond_haired_woman::skin-tone-3:"] = "\uD83D\uDC71\uD83C\uDFFD\u200D♀️", + [":blond_haired_woman::skin-tone-4:"] = "\uD83D\uDC71\uD83C\uDFFE\u200D♀️", + [":blond_haired_woman::skin-tone-5:"] = "\uD83D\uDC71\uD83C\uDFFF\u200D♀️", + [":blond_haired_woman_dark_skin_tone:"] = "\uD83D\uDC71\uD83C\uDFFF\u200D♀️", + [":blond_haired_woman_light_skin_tone:"] = "\uD83D\uDC71\uD83C\uDFFB\u200D♀️", + [":blond_haired_woman_medium_dark_skin_tone:"] = "\uD83D\uDC71\uD83C\uDFFE\u200D♀️", + [":blond_haired_woman_medium_light_skin_tone:"] = "\uD83D\uDC71\uD83C\uDFFC\u200D♀️", + [":blond_haired_woman_medium_skin_tone:"] = "\uD83D\uDC71\uD83C\uDFFD\u200D♀️", + [":blond_haired_woman_tone1:"] = "\uD83D\uDC71\uD83C\uDFFB\u200D♀️", + [":blond_haired_woman_tone2:"] = "\uD83D\uDC71\uD83C\uDFFC\u200D♀️", + [":blond_haired_woman_tone3:"] = "\uD83D\uDC71\uD83C\uDFFD\u200D♀️", + [":blond_haired_woman_tone4:"] = "\uD83D\uDC71\uD83C\uDFFE\u200D♀️", + [":blond_haired_woman_tone5:"] = "\uD83D\uDC71\uD83C\uDFFF\u200D♀️", + [":blossom:"] = "\uD83C\uDF3C", + [":blowfish:"] = "\uD83D\uDC21", + [":blue_book:"] = "\uD83D\uDCD8", + [":blue_car:"] = "\uD83D\uDE99", + [":blue_circle:"] = "\uD83D\uDD35", + [":blue_heart:"] = "\uD83D\uDC99", + [":blue_square:"] = "\uD83D\uDFE6", + [":blush:"] = "\uD83D\uDE0A", + [":boar:"] = "\uD83D\uDC17", + [":bomb:"] = "\uD83D\uDCA3", + [":bone:"] = "\uD83E\uDDB4", + [":book:"] = "\uD83D\uDCD6", + [":bookmark:"] = "\uD83D\uDD16", + [":bookmark_tabs:"] = "\uD83D\uDCD1", + [":books:"] = "\uD83D\uDCDA", + [":boom:"] = "\uD83D\uDCA5", + [":boot:"] = "\uD83D\uDC62", + [":bottle_with_popping_cork:"] = "\uD83C\uDF7E", + [":bouquet:"] = "\uD83D\uDC90", + [":bow:"] = "\uD83D\uDE47", + [":bow::skin-tone-1:"] = "\uD83D\uDE47\uD83C\uDFFB", + [":bow::skin-tone-2:"] = "\uD83D\uDE47\uD83C\uDFFC", + [":bow::skin-tone-3:"] = "\uD83D\uDE47\uD83C\uDFFD", + [":bow::skin-tone-4:"] = "\uD83D\uDE47\uD83C\uDFFE", + [":bow::skin-tone-5:"] = "\uD83D\uDE47\uD83C\uDFFF", + [":bow_and_arrow:"] = "\uD83C\uDFF9", + [":bow_tone1:"] = "\uD83D\uDE47\uD83C\uDFFB", + [":bow_tone2:"] = "\uD83D\uDE47\uD83C\uDFFC", + [":bow_tone3:"] = "\uD83D\uDE47\uD83C\uDFFD", + [":bow_tone4:"] = "\uD83D\uDE47\uD83C\uDFFE", + [":bow_tone5:"] = "\uD83D\uDE47\uD83C\uDFFF", + [":bowl_with_spoon:"] = "\uD83E\uDD63", + [":bowling:"] = "\uD83C\uDFB3", + [":boxing_glove:"] = "\uD83E\uDD4A", + [":boxing_gloves:"] = "\uD83E\uDD4A", + [":boy:"] = "\uD83D\uDC66", + [":boy::skin-tone-1:"] = "\uD83D\uDC66\uD83C\uDFFB", + [":boy::skin-tone-2:"] = "\uD83D\uDC66\uD83C\uDFFC", + [":boy::skin-tone-3:"] = "\uD83D\uDC66\uD83C\uDFFD", + [":boy::skin-tone-4:"] = "\uD83D\uDC66\uD83C\uDFFE", + [":boy::skin-tone-5:"] = "\uD83D\uDC66\uD83C\uDFFF", + [":boy_tone1:"] = "\uD83D\uDC66\uD83C\uDFFB", + [":boy_tone2:"] = "\uD83D\uDC66\uD83C\uDFFC", + [":boy_tone3:"] = "\uD83D\uDC66\uD83C\uDFFD", + [":boy_tone4:"] = "\uD83D\uDC66\uD83C\uDFFE", + [":boy_tone5:"] = "\uD83D\uDC66\uD83C\uDFFF", + [":brain:"] = "\uD83E\uDDE0", + [":bread:"] = "\uD83C\uDF5E", + [":breast_feeding:"] = "\uD83E\uDD31", + [":breast_feeding::skin-tone-1:"] = "\uD83E\uDD31\uD83C\uDFFB", + [":breast_feeding::skin-tone-2:"] = "\uD83E\uDD31\uD83C\uDFFC", + [":breast_feeding::skin-tone-3:"] = "\uD83E\uDD31\uD83C\uDFFD", + [":breast_feeding::skin-tone-4:"] = "\uD83E\uDD31\uD83C\uDFFE", + [":breast_feeding::skin-tone-5:"] = "\uD83E\uDD31\uD83C\uDFFF", + [":breast_feeding_dark_skin_tone:"] = "\uD83E\uDD31\uD83C\uDFFF", + [":breast_feeding_light_skin_tone:"] = "\uD83E\uDD31\uD83C\uDFFB", + [":breast_feeding_medium_dark_skin_tone:"] = "\uD83E\uDD31\uD83C\uDFFE", + [":breast_feeding_medium_light_skin_tone:"] = "\uD83E\uDD31\uD83C\uDFFC", + [":breast_feeding_medium_skin_tone:"] = "\uD83E\uDD31\uD83C\uDFFD", + [":breast_feeding_tone1:"] = "\uD83E\uDD31\uD83C\uDFFB", + [":breast_feeding_tone2:"] = "\uD83E\uDD31\uD83C\uDFFC", + [":breast_feeding_tone3:"] = "\uD83E\uDD31\uD83C\uDFFD", + [":breast_feeding_tone4:"] = "\uD83E\uDD31\uD83C\uDFFE", + [":breast_feeding_tone5:"] = "\uD83E\uDD31\uD83C\uDFFF", + [":bricks:"] = "\uD83E\uDDF1", + [":bride_with_veil:"] = "\uD83D\uDC70", + [":bride_with_veil::skin-tone-1:"] = "\uD83D\uDC70\uD83C\uDFFB", + [":bride_with_veil::skin-tone-2:"] = "\uD83D\uDC70\uD83C\uDFFC", + [":bride_with_veil::skin-tone-3:"] = "\uD83D\uDC70\uD83C\uDFFD", + [":bride_with_veil::skin-tone-4:"] = "\uD83D\uDC70\uD83C\uDFFE", + [":bride_with_veil::skin-tone-5:"] = "\uD83D\uDC70\uD83C\uDFFF", + [":bride_with_veil_tone1:"] = "\uD83D\uDC70\uD83C\uDFFB", + [":bride_with_veil_tone2:"] = "\uD83D\uDC70\uD83C\uDFFC", + [":bride_with_veil_tone3:"] = "\uD83D\uDC70\uD83C\uDFFD", + [":bride_with_veil_tone4:"] = "\uD83D\uDC70\uD83C\uDFFE", + [":bride_with_veil_tone5:"] = "\uD83D\uDC70\uD83C\uDFFF", + [":bridge_at_night:"] = "\uD83C\uDF09", + [":briefcase:"] = "\uD83D\uDCBC", + [":briefs:"] = "\uD83E\uDE72", + [":broccoli:"] = "\uD83E\uDD66", + [":broken_heart:"] = "\uD83D\uDC94", + [":broom:"] = "\uD83E\uDDF9", + [":brown_circle:"] = "\uD83D\uDFE4", + [":brown_heart:"] = "\uD83E\uDD0E", + [":brown_square:"] = "\uD83D\uDFEB", + [":bug:"] = "\uD83D\uDC1B", + [":building_construction:"] = "\uD83C\uDFD7️", + [":bulb:"] = "\uD83D\uDCA1", + [":bullettrain_front:"] = "\uD83D\uDE85", + [":bullettrain_side:"] = "\uD83D\uDE84", + [":burrito:"] = "\uD83C\uDF2F", + [":bus:"] = "\uD83D\uDE8C", + [":busstop:"] = "\uD83D\uDE8F", + [":bust_in_silhouette:"] = "\uD83D\uDC64", + [":busts_in_silhouette:"] = "\uD83D\uDC65", + [":butter:"] = "\uD83E\uDDC8", + [":butterfly:"] = "\uD83E\uDD8B", + [":cactus:"] = "\uD83C\uDF35", + [":cake:"] = "\uD83C\uDF70", + [":calendar:"] = "\uD83D\uDCC6", + [":calendar_spiral:"] = "\uD83D\uDDD3️", + [":call_me:"] = "\uD83E\uDD19", + [":call_me::skin-tone-1:"] = "\uD83E\uDD19\uD83C\uDFFB", + [":call_me::skin-tone-2:"] = "\uD83E\uDD19\uD83C\uDFFC", + [":call_me::skin-tone-3:"] = "\uD83E\uDD19\uD83C\uDFFD", + [":call_me::skin-tone-4:"] = "\uD83E\uDD19\uD83C\uDFFE", + [":call_me::skin-tone-5:"] = "\uD83E\uDD19\uD83C\uDFFF", + [":call_me_hand:"] = "\uD83E\uDD19", + [":call_me_hand::skin-tone-1:"] = "\uD83E\uDD19\uD83C\uDFFB", + [":call_me_hand::skin-tone-2:"] = "\uD83E\uDD19\uD83C\uDFFC", + [":call_me_hand::skin-tone-3:"] = "\uD83E\uDD19\uD83C\uDFFD", + [":call_me_hand::skin-tone-4:"] = "\uD83E\uDD19\uD83C\uDFFE", + [":call_me_hand::skin-tone-5:"] = "\uD83E\uDD19\uD83C\uDFFF", + [":call_me_hand_tone1:"] = "\uD83E\uDD19\uD83C\uDFFB", + [":call_me_hand_tone2:"] = "\uD83E\uDD19\uD83C\uDFFC", + [":call_me_hand_tone3:"] = "\uD83E\uDD19\uD83C\uDFFD", + [":call_me_hand_tone4:"] = "\uD83E\uDD19\uD83C\uDFFE", + [":call_me_hand_tone5:"] = "\uD83E\uDD19\uD83C\uDFFF", + [":call_me_tone1:"] = "\uD83E\uDD19\uD83C\uDFFB", + [":call_me_tone2:"] = "\uD83E\uDD19\uD83C\uDFFC", + [":call_me_tone3:"] = "\uD83E\uDD19\uD83C\uDFFD", + [":call_me_tone4:"] = "\uD83E\uDD19\uD83C\uDFFE", + [":call_me_tone5:"] = "\uD83E\uDD19\uD83C\uDFFF", + [":calling:"] = "\uD83D\uDCF2", + [":camel:"] = "\uD83D\uDC2B", + [":camera:"] = "\uD83D\uDCF7", + [":camera_with_flash:"] = "\uD83D\uDCF8", + [":camping:"] = "\uD83C\uDFD5️", + [":cancer:"] = "♋", + [":candle:"] = "\uD83D\uDD6F️", + [":candy:"] = "\uD83C\uDF6C", + [":canned_food:"] = "\uD83E\uDD6B", + [":canoe:"] = "\uD83D\uDEF6", + [":capital_abcd:"] = "\uD83D\uDD20", + [":capricorn:"] = "♑", + [":card_box:"] = "\uD83D\uDDC3️", + [":card_file_box:"] = "\uD83D\uDDC3️", + [":card_index:"] = "\uD83D\uDCC7", + [":card_index_dividers:"] = "\uD83D\uDDC2️", + [":carousel_horse:"] = "\uD83C\uDFA0", + [":carrot:"] = "\uD83E\uDD55", + [":cartwheel:"] = "\uD83E\uDD38", + [":cartwheel::skin-tone-1:"] = "\uD83E\uDD38\uD83C\uDFFB", + [":cartwheel::skin-tone-2:"] = "\uD83E\uDD38\uD83C\uDFFC", + [":cartwheel::skin-tone-3:"] = "\uD83E\uDD38\uD83C\uDFFD", + [":cartwheel::skin-tone-4:"] = "\uD83E\uDD38\uD83C\uDFFE", + [":cartwheel::skin-tone-5:"] = "\uD83E\uDD38\uD83C\uDFFF", + [":cartwheel_tone1:"] = "\uD83E\uDD38\uD83C\uDFFB", + [":cartwheel_tone2:"] = "\uD83E\uDD38\uD83C\uDFFC", + [":cartwheel_tone3:"] = "\uD83E\uDD38\uD83C\uDFFD", + [":cartwheel_tone4:"] = "\uD83E\uDD38\uD83C\uDFFE", + [":cartwheel_tone5:"] = "\uD83E\uDD38\uD83C\uDFFF", + [":cat2:"] = "\uD83D\uDC08", + [":cat:"] = "\uD83D\uDC31", + [":cd:"] = "\uD83D\uDCBF", + [":chains:"] = "⛓️", + [":chair:"] = "\uD83E\uDE91", + [":champagne:"] = "\uD83C\uDF7E", + [":champagne_glass:"] = "\uD83E\uDD42", + [":chart:"] = "\uD83D\uDCB9", + [":chart_with_downwards_trend:"] = "\uD83D\uDCC9", + [":chart_with_upwards_trend:"] = "\uD83D\uDCC8", + [":checkered_flag:"] = "\uD83C\uDFC1", + [":cheese:"] = "\uD83E\uDDC0", + [":cheese_wedge:"] = "\uD83E\uDDC0", + [":cherries:"] = "\uD83C\uDF52", + [":cherry_blossom:"] = "\uD83C\uDF38", + [":chess_pawn:"] = "♟️", + [":chestnut:"] = "\uD83C\uDF30", + [":chicken:"] = "\uD83D\uDC14", + [":child:"] = "\uD83E\uDDD2", + [":child::skin-tone-1:"] = "\uD83E\uDDD2\uD83C\uDFFB", + [":child::skin-tone-2:"] = "\uD83E\uDDD2\uD83C\uDFFC", + [":child::skin-tone-3:"] = "\uD83E\uDDD2\uD83C\uDFFD", + [":child::skin-tone-4:"] = "\uD83E\uDDD2\uD83C\uDFFE", + [":child::skin-tone-5:"] = "\uD83E\uDDD2\uD83C\uDFFF", + [":child_dark_skin_tone:"] = "\uD83E\uDDD2\uD83C\uDFFF", + [":child_light_skin_tone:"] = "\uD83E\uDDD2\uD83C\uDFFB", + [":child_medium_dark_skin_tone:"] = "\uD83E\uDDD2\uD83C\uDFFE", + [":child_medium_light_skin_tone:"] = "\uD83E\uDDD2\uD83C\uDFFC", + [":child_medium_skin_tone:"] = "\uD83E\uDDD2\uD83C\uDFFD", + [":child_tone1:"] = "\uD83E\uDDD2\uD83C\uDFFB", + [":child_tone2:"] = "\uD83E\uDDD2\uD83C\uDFFC", + [":child_tone3:"] = "\uD83E\uDDD2\uD83C\uDFFD", + [":child_tone4:"] = "\uD83E\uDDD2\uD83C\uDFFE", + [":child_tone5:"] = "\uD83E\uDDD2\uD83C\uDFFF", + [":children_crossing:"] = "\uD83D\uDEB8", + [":chipmunk:"] = "\uD83D\uDC3F️", + [":chocolate_bar:"] = "\uD83C\uDF6B", + [":chopsticks:"] = "\uD83E\uDD62", + [":christmas_tree:"] = "\uD83C\uDF84", + [":church:"] = "⛪", + [":cinema:"] = "\uD83C\uDFA6", + [":circus_tent:"] = "\uD83C\uDFAA", + [":city_dusk:"] = "\uD83C\uDF06", + [":city_sunrise:"] = "\uD83C\uDF07", + [":city_sunset:"] = "\uD83C\uDF07", + [":cityscape:"] = "\uD83C\uDFD9️", + [":cl:"] = "\uD83C\uDD91", + [":clap:"] = "\uD83D\uDC4F", + [":clap::skin-tone-1:"] = "\uD83D\uDC4F\uD83C\uDFFB", + [":clap::skin-tone-2:"] = "\uD83D\uDC4F\uD83C\uDFFC", + [":clap::skin-tone-3:"] = "\uD83D\uDC4F\uD83C\uDFFD", + [":clap::skin-tone-4:"] = "\uD83D\uDC4F\uD83C\uDFFE", + [":clap::skin-tone-5:"] = "\uD83D\uDC4F\uD83C\uDFFF", + [":clap_tone1:"] = "\uD83D\uDC4F\uD83C\uDFFB", + [":clap_tone2:"] = "\uD83D\uDC4F\uD83C\uDFFC", + [":clap_tone3:"] = "\uD83D\uDC4F\uD83C\uDFFD", + [":clap_tone4:"] = "\uD83D\uDC4F\uD83C\uDFFE", + [":clap_tone5:"] = "\uD83D\uDC4F\uD83C\uDFFF", + [":clapper:"] = "\uD83C\uDFAC", + [":classical_building:"] = "\uD83C\uDFDB️", + [":clinking_glass:"] = "\uD83E\uDD42", + [":clipboard:"] = "\uD83D\uDCCB", + [":clock1030:"] = "\uD83D\uDD65", + [":clock10:"] = "\uD83D\uDD59", + [":clock1130:"] = "\uD83D\uDD66", + [":clock11:"] = "\uD83D\uDD5A", + [":clock1230:"] = "\uD83D\uDD67", + [":clock12:"] = "\uD83D\uDD5B", + [":clock130:"] = "\uD83D\uDD5C", + [":clock1:"] = "\uD83D\uDD50", + [":clock230:"] = "\uD83D\uDD5D", + [":clock2:"] = "\uD83D\uDD51", + [":clock330:"] = "\uD83D\uDD5E", + [":clock3:"] = "\uD83D\uDD52", + [":clock430:"] = "\uD83D\uDD5F", + [":clock4:"] = "\uD83D\uDD53", + [":clock530:"] = "\uD83D\uDD60", + [":clock5:"] = "\uD83D\uDD54", + [":clock630:"] = "\uD83D\uDD61", + [":clock6:"] = "\uD83D\uDD55", + [":clock730:"] = "\uD83D\uDD62", + [":clock7:"] = "\uD83D\uDD56", + [":clock830:"] = "\uD83D\uDD63", + [":clock8:"] = "\uD83D\uDD57", + [":clock930:"] = "\uD83D\uDD64", + [":clock9:"] = "\uD83D\uDD58", + [":clock:"] = "\uD83D\uDD70️", + [":closed_book:"] = "\uD83D\uDCD5", + [":closed_lock_with_key:"] = "\uD83D\uDD10", + [":closed_umbrella:"] = "\uD83C\uDF02", + [":cloud:"] = "☁️", + [":cloud_lightning:"] = "\uD83C\uDF29️", + [":cloud_rain:"] = "\uD83C\uDF27️", + [":cloud_snow:"] = "\uD83C\uDF28️", + [":cloud_tornado:"] = "\uD83C\uDF2A️", + [":cloud_with_lightning:"] = "\uD83C\uDF29️", + [":cloud_with_rain:"] = "\uD83C\uDF27️", + [":cloud_with_snow:"] = "\uD83C\uDF28️", + [":cloud_with_tornado:"] = "\uD83C\uDF2A️", + [":clown:"] = "\uD83E\uDD21", + [":clown_face:"] = "\uD83E\uDD21", + [":clubs:"] = "♣️", + [":coat:"] = "\uD83E\uDDE5", + [":cocktail:"] = "\uD83C\uDF78", + [":coconut:"] = "\uD83E\uDD65", + [":coffee:"] = "☕", + [":coffin:"] = "⚰️", + [":coin:"] = "\uD83E\uDE99", + [":cold_face:"] = "\uD83E\uDD76", + [":cold_sweat:"] = "\uD83D\uDE30", + [":comet:"] = "☄️", + [":compass:"] = "\uD83E\uDDED", + [":compression:"] = "\uD83D\uDDDC️", + [":computer:"] = "\uD83D\uDCBB", + [":confetti_ball:"] = "\uD83C\uDF8A", + [":confounded:"] = "\uD83D\uDE16", + [":confused:"] = "\uD83D\uDE15", + [":congratulations:"] = "㊗️", + [":construction:"] = "\uD83D\uDEA7", + [":construction_site:"] = "\uD83C\uDFD7️", + [":construction_worker:"] = "\uD83D\uDC77", + [":construction_worker::skin-tone-1:"] = "\uD83D\uDC77\uD83C\uDFFB", + [":construction_worker::skin-tone-2:"] = "\uD83D\uDC77\uD83C\uDFFC", + [":construction_worker::skin-tone-3:"] = "\uD83D\uDC77\uD83C\uDFFD", + [":construction_worker::skin-tone-4:"] = "\uD83D\uDC77\uD83C\uDFFE", + [":construction_worker::skin-tone-5:"] = "\uD83D\uDC77\uD83C\uDFFF", + [":construction_worker_tone1:"] = "\uD83D\uDC77\uD83C\uDFFB", + [":construction_worker_tone2:"] = "\uD83D\uDC77\uD83C\uDFFC", + [":construction_worker_tone3:"] = "\uD83D\uDC77\uD83C\uDFFD", + [":construction_worker_tone4:"] = "\uD83D\uDC77\uD83C\uDFFE", + [":construction_worker_tone5:"] = "\uD83D\uDC77\uD83C\uDFFF", + [":control_knobs:"] = "\uD83C\uDF9B️", + [":convenience_store:"] = "\uD83C\uDFEA", + [":cookie:"] = "\uD83C\uDF6A", + [":cooking:"] = "\uD83C\uDF73", + [":cool:"] = "\uD83C\uDD92", + [":cop:"] = "\uD83D\uDC6E", + [":cop::skin-tone-1:"] = "\uD83D\uDC6E\uD83C\uDFFB", + [":cop::skin-tone-2:"] = "\uD83D\uDC6E\uD83C\uDFFC", + [":cop::skin-tone-3:"] = "\uD83D\uDC6E\uD83C\uDFFD", + [":cop::skin-tone-4:"] = "\uD83D\uDC6E\uD83C\uDFFE", + [":cop::skin-tone-5:"] = "\uD83D\uDC6E\uD83C\uDFFF", + [":cop_tone1:"] = "\uD83D\uDC6E\uD83C\uDFFB", + [":cop_tone2:"] = "\uD83D\uDC6E\uD83C\uDFFC", + [":cop_tone3:"] = "\uD83D\uDC6E\uD83C\uDFFD", + [":cop_tone4:"] = "\uD83D\uDC6E\uD83C\uDFFE", + [":cop_tone5:"] = "\uD83D\uDC6E\uD83C\uDFFF", + [":copyright:"] = "©️", + [":corn:"] = "\uD83C\uDF3D", + [":couch:"] = "\uD83D\uDECB️", + [":couch_and_lamp:"] = "\uD83D\uDECB️", + [":couple:"] = "\uD83D\uDC6B", + [":couple_mm:"] = "\uD83D\uDC68\u200D❤️\u200D\uD83D\uDC68", + [":couple_with_heart:"] = "\uD83D\uDC91", + [":couple_with_heart_mm:"] = "\uD83D\uDC68\u200D❤️\u200D\uD83D\uDC68", + [":couple_with_heart_woman_man:"] = "\uD83D\uDC69\u200D❤️\u200D\uD83D\uDC68", + [":couple_with_heart_ww:"] = "\uD83D\uDC69\u200D❤️\u200D\uD83D\uDC69", + [":couple_ww:"] = "\uD83D\uDC69\u200D❤️\u200D\uD83D\uDC69", + [":couplekiss:"] = "\uD83D\uDC8F", + [":couplekiss_mm:"] = "\uD83D\uDC68\u200D❤️\u200D\uD83D\uDC8B\u200D\uD83D\uDC68", + [":couplekiss_ww:"] = "\uD83D\uDC69\u200D❤️\u200D\uD83D\uDC8B\u200D\uD83D\uDC69", + [":cow2:"] = "\uD83D\uDC04", + [":cow:"] = "\uD83D\uDC2E", + [":cowboy:"] = "\uD83E\uDD20", + [":crab:"] = "\uD83E\uDD80", + [":crayon:"] = "\uD83D\uDD8D️", + [":credit_card:"] = "\uD83D\uDCB3", + [":crescent_moon:"] = "\uD83C\uDF19", + [":cricket:"] = "\uD83E\uDD97", + [":cricket_bat_ball:"] = "\uD83C\uDFCF", + [":cricket_game:"] = "\uD83C\uDFCF", + [":crocodile:"] = "\uD83D\uDC0A", + [":croissant:"] = "\uD83E\uDD50", + [":cross:"] = "✝️", + [":crossed_flags:"] = "\uD83C\uDF8C", + [":crossed_swords:"] = "⚔️", + [":crown:"] = "\uD83D\uDC51", + [":cruise_ship:"] = "\uD83D\uDEF3️", + [":cry:"] = "\uD83D\uDE22", + [":crying_cat_face:"] = "\uD83D\uDE3F", + [":crystal_ball:"] = "\uD83D\uDD2E", + [":cucumber:"] = "\uD83E\uDD52", + [":cup_with_straw:"] = "\uD83E\uDD64", + [":cupcake:"] = "\uD83E\uDDC1", + [":cupid:"] = "\uD83D\uDC98", + [":curling_stone:"] = "\uD83E\uDD4C", + [":curly_loop:"] = "➰", + [":currency_exchange:"] = "\uD83D\uDCB1", + [":curry:"] = "\uD83C\uDF5B", + [":custard:"] = "\uD83C\uDF6E", + [":customs:"] = "\uD83D\uDEC3", + [":cut_of_meat:"] = "\uD83E\uDD69", + [":cyclone:"] = "\uD83C\uDF00", + [":dagger:"] = "\uD83D\uDDE1️", + [":dagger_knife:"] = "\uD83D\uDDE1️", + [":dancer:"] = "\uD83D\uDC83", + [":dancer::skin-tone-1:"] = "\uD83D\uDC83\uD83C\uDFFB", + [":dancer::skin-tone-2:"] = "\uD83D\uDC83\uD83C\uDFFC", + [":dancer::skin-tone-3:"] = "\uD83D\uDC83\uD83C\uDFFD", + [":dancer::skin-tone-4:"] = "\uD83D\uDC83\uD83C\uDFFE", + [":dancer::skin-tone-5:"] = "\uD83D\uDC83\uD83C\uDFFF", + [":dancer_tone1:"] = "\uD83D\uDC83\uD83C\uDFFB", + [":dancer_tone2:"] = "\uD83D\uDC83\uD83C\uDFFC", + [":dancer_tone3:"] = "\uD83D\uDC83\uD83C\uDFFD", + [":dancer_tone4:"] = "\uD83D\uDC83\uD83C\uDFFE", + [":dancer_tone5:"] = "\uD83D\uDC83\uD83C\uDFFF", + [":dancers:"] = "\uD83D\uDC6F", + [":dango:"] = "\uD83C\uDF61", + [":dark_sunglasses:"] = "\uD83D\uDD76️", + [":dart:"] = "\uD83C\uDFAF", + [":dash:"] = "\uD83D\uDCA8", + [":date:"] = "\uD83D\uDCC5", + [":deaf_man:"] = "\uD83E\uDDCF\u200D♂️", + [":deaf_man::skin-tone-1:"] = "\uD83E\uDDCF\uD83C\uDFFB\u200D♂️", + [":deaf_man::skin-tone-2:"] = "\uD83E\uDDCF\uD83C\uDFFC\u200D♂️", + [":deaf_man::skin-tone-3:"] = "\uD83E\uDDCF\uD83C\uDFFD\u200D♂️", + [":deaf_man::skin-tone-4:"] = "\uD83E\uDDCF\uD83C\uDFFE\u200D♂️", + [":deaf_man::skin-tone-5:"] = "\uD83E\uDDCF\uD83C\uDFFF\u200D♂️", + [":deaf_man_dark_skin_tone:"] = "\uD83E\uDDCF\uD83C\uDFFF\u200D♂️", + [":deaf_man_light_skin_tone:"] = "\uD83E\uDDCF\uD83C\uDFFB\u200D♂️", + [":deaf_man_medium_dark_skin_tone:"] = "\uD83E\uDDCF\uD83C\uDFFE\u200D♂️", + [":deaf_man_medium_light_skin_tone:"] = "\uD83E\uDDCF\uD83C\uDFFC\u200D♂️", + [":deaf_man_medium_skin_tone:"] = "\uD83E\uDDCF\uD83C\uDFFD\u200D♂️", + [":deaf_man_tone1:"] = "\uD83E\uDDCF\uD83C\uDFFB\u200D♂️", + [":deaf_man_tone2:"] = "\uD83E\uDDCF\uD83C\uDFFC\u200D♂️", + [":deaf_man_tone3:"] = "\uD83E\uDDCF\uD83C\uDFFD\u200D♂️", + [":deaf_man_tone4:"] = "\uD83E\uDDCF\uD83C\uDFFE\u200D♂️", + [":deaf_man_tone5:"] = "\uD83E\uDDCF\uD83C\uDFFF\u200D♂️", + [":deaf_person:"] = "\uD83E\uDDCF", + [":deaf_person::skin-tone-1:"] = "\uD83E\uDDCF\uD83C\uDFFB", + [":deaf_person::skin-tone-2:"] = "\uD83E\uDDCF\uD83C\uDFFC", + [":deaf_person::skin-tone-3:"] = "\uD83E\uDDCF\uD83C\uDFFD", + [":deaf_person::skin-tone-4:"] = "\uD83E\uDDCF\uD83C\uDFFE", + [":deaf_person::skin-tone-5:"] = "\uD83E\uDDCF\uD83C\uDFFF", + [":deaf_person_dark_skin_tone:"] = "\uD83E\uDDCF\uD83C\uDFFF", + [":deaf_person_light_skin_tone:"] = "\uD83E\uDDCF\uD83C\uDFFB", + [":deaf_person_medium_dark_skin_tone:"] = "\uD83E\uDDCF\uD83C\uDFFE", + [":deaf_person_medium_light_skin_tone:"] = "\uD83E\uDDCF\uD83C\uDFFC", + [":deaf_person_medium_skin_tone:"] = "\uD83E\uDDCF\uD83C\uDFFD", + [":deaf_person_tone1:"] = "\uD83E\uDDCF\uD83C\uDFFB", + [":deaf_person_tone2:"] = "\uD83E\uDDCF\uD83C\uDFFC", + [":deaf_person_tone3:"] = "\uD83E\uDDCF\uD83C\uDFFD", + [":deaf_person_tone4:"] = "\uD83E\uDDCF\uD83C\uDFFE", + [":deaf_person_tone5:"] = "\uD83E\uDDCF\uD83C\uDFFF", + [":deaf_woman:"] = "\uD83E\uDDCF\u200D♀️", + [":deaf_woman::skin-tone-1:"] = "\uD83E\uDDCF\uD83C\uDFFB\u200D♀️", + [":deaf_woman::skin-tone-2:"] = "\uD83E\uDDCF\uD83C\uDFFC\u200D♀️", + [":deaf_woman::skin-tone-3:"] = "\uD83E\uDDCF\uD83C\uDFFD\u200D♀️", + [":deaf_woman::skin-tone-4:"] = "\uD83E\uDDCF\uD83C\uDFFE\u200D♀️", + [":deaf_woman::skin-tone-5:"] = "\uD83E\uDDCF\uD83C\uDFFF\u200D♀️", + [":deaf_woman_dark_skin_tone:"] = "\uD83E\uDDCF\uD83C\uDFFF\u200D♀️", + [":deaf_woman_light_skin_tone:"] = "\uD83E\uDDCF\uD83C\uDFFB\u200D♀️", + [":deaf_woman_medium_dark_skin_tone:"] = "\uD83E\uDDCF\uD83C\uDFFE\u200D♀️", + [":deaf_woman_medium_light_skin_tone:"] = "\uD83E\uDDCF\uD83C\uDFFC\u200D♀️", + [":deaf_woman_medium_skin_tone:"] = "\uD83E\uDDCF\uD83C\uDFFD\u200D♀️", + [":deaf_woman_tone1:"] = "\uD83E\uDDCF\uD83C\uDFFB\u200D♀️", + [":deaf_woman_tone2:"] = "\uD83E\uDDCF\uD83C\uDFFC\u200D♀️", + [":deaf_woman_tone3:"] = "\uD83E\uDDCF\uD83C\uDFFD\u200D♀️", + [":deaf_woman_tone4:"] = "\uD83E\uDDCF\uD83C\uDFFE\u200D♀️", + [":deaf_woman_tone5:"] = "\uD83E\uDDCF\uD83C\uDFFF\u200D♀️", + [":deciduous_tree:"] = "\uD83C\uDF33", + [":deer:"] = "\uD83E\uDD8C", + [":department_store:"] = "\uD83C\uDFEC", + [":derelict_house_building:"] = "\uD83C\uDFDA️", + [":desert:"] = "\uD83C\uDFDC️", + [":desert_island:"] = "\uD83C\uDFDD️", + [":desktop:"] = "\uD83D\uDDA5️", + [":desktop_computer:"] = "\uD83D\uDDA5️", + [":detective:"] = "\uD83D\uDD75️", + [":detective::skin-tone-1:"] = "\uD83D\uDD75\uD83C\uDFFB", + [":detective::skin-tone-2:"] = "\uD83D\uDD75\uD83C\uDFFC", + [":detective::skin-tone-3:"] = "\uD83D\uDD75\uD83C\uDFFD", + [":detective::skin-tone-4:"] = "\uD83D\uDD75\uD83C\uDFFE", + [":detective::skin-tone-5:"] = "\uD83D\uDD75\uD83C\uDFFF", + [":detective_tone1:"] = "\uD83D\uDD75\uD83C\uDFFB", + [":detective_tone2:"] = "\uD83D\uDD75\uD83C\uDFFC", + [":detective_tone3:"] = "\uD83D\uDD75\uD83C\uDFFD", + [":detective_tone4:"] = "\uD83D\uDD75\uD83C\uDFFE", + [":detective_tone5:"] = "\uD83D\uDD75\uD83C\uDFFF", + [":diamond_shape_with_a_dot_inside:"] = "\uD83D\uDCA0", + [":diamonds:"] = "♦️", + [":disappointed:"] = "\uD83D\uDE1E", + [":disappointed_relieved:"] = "\uD83D\uDE25", + [":dividers:"] = "\uD83D\uDDC2️", + [":diving_mask:"] = "\uD83E\uDD3F", + [":diya_lamp:"] = "\uD83E\uDE94", + [":dizzy:"] = "\uD83D\uDCAB", + [":dizzy_face:"] = "\uD83D\uDE35", + [":dna:"] = "\uD83E\uDDEC", + [":do_not_litter:"] = "\uD83D\uDEAF", + [":dog2:"] = "\uD83D\uDC15", + [":dog:"] = "\uD83D\uDC36", + [":dollar:"] = "\uD83D\uDCB5", + [":dolls:"] = "\uD83C\uDF8E", + [":dolphin:"] = "\uD83D\uDC2C", + [":door:"] = "\uD83D\uDEAA", + [":double_vertical_bar:"] = "⏸️", + [":doughnut:"] = "\uD83C\uDF69", + [":dove:"] = "\uD83D\uDD4A️", + [":dove_of_peace:"] = "\uD83D\uDD4A️", + [":dragon:"] = "\uD83D\uDC09", + [":dragon_face:"] = "\uD83D\uDC32", + [":dress:"] = "\uD83D\uDC57", + [":dromedary_camel:"] = "\uD83D\uDC2A", + [":drool:"] = "\uD83E\uDD24", + [":drooling_face:"] = "\uD83E\uDD24", + [":drop_of_blood:"] = "\uD83E\uDE78", + [":droplet:"] = "\uD83D\uDCA7", + [":drum:"] = "\uD83E\uDD41", + [":drum_with_drumsticks:"] = "\uD83E\uDD41", + [":duck:"] = "\uD83E\uDD86", + [":dumpling:"] = "\uD83E\uDD5F", + [":dvd:"] = "\uD83D\uDCC0", + [":e_mail:"] = "\uD83D\uDCE7", + [":eagle:"] = "\uD83E\uDD85", + [":ear:"] = "\uD83D\uDC42", + [":ear::skin-tone-1:"] = "\uD83D\uDC42\uD83C\uDFFB", + [":ear::skin-tone-2:"] = "\uD83D\uDC42\uD83C\uDFFC", + [":ear::skin-tone-3:"] = "\uD83D\uDC42\uD83C\uDFFD", + [":ear::skin-tone-4:"] = "\uD83D\uDC42\uD83C\uDFFE", + [":ear::skin-tone-5:"] = "\uD83D\uDC42\uD83C\uDFFF", + [":ear_of_rice:"] = "\uD83C\uDF3E", + [":ear_tone1:"] = "\uD83D\uDC42\uD83C\uDFFB", + [":ear_tone2:"] = "\uD83D\uDC42\uD83C\uDFFC", + [":ear_tone3:"] = "\uD83D\uDC42\uD83C\uDFFD", + [":ear_tone4:"] = "\uD83D\uDC42\uD83C\uDFFE", + [":ear_tone5:"] = "\uD83D\uDC42\uD83C\uDFFF", + [":ear_with_hearing_aid:"] = "\uD83E\uDDBB", + [":ear_with_hearing_aid::skin-tone-1:"] = "\uD83E\uDDBB\uD83C\uDFFB", + [":ear_with_hearing_aid::skin-tone-2:"] = "\uD83E\uDDBB\uD83C\uDFFC", + [":ear_with_hearing_aid::skin-tone-3:"] = "\uD83E\uDDBB\uD83C\uDFFD", + [":ear_with_hearing_aid::skin-tone-4:"] = "\uD83E\uDDBB\uD83C\uDFFE", + [":ear_with_hearing_aid::skin-tone-5:"] = "\uD83E\uDDBB\uD83C\uDFFF", + [":ear_with_hearing_aid_dark_skin_tone:"] = "\uD83E\uDDBB\uD83C\uDFFF", + [":ear_with_hearing_aid_light_skin_tone:"] = "\uD83E\uDDBB\uD83C\uDFFB", + [":ear_with_hearing_aid_medium_dark_skin_tone:"] = "\uD83E\uDDBB\uD83C\uDFFE", + [":ear_with_hearing_aid_medium_light_skin_tone:"] = "\uD83E\uDDBB\uD83C\uDFFC", + [":ear_with_hearing_aid_medium_skin_tone:"] = "\uD83E\uDDBB\uD83C\uDFFD", + [":ear_with_hearing_aid_tone1:"] = "\uD83E\uDDBB\uD83C\uDFFB", + [":ear_with_hearing_aid_tone2:"] = "\uD83E\uDDBB\uD83C\uDFFC", + [":ear_with_hearing_aid_tone3:"] = "\uD83E\uDDBB\uD83C\uDFFD", + [":ear_with_hearing_aid_tone4:"] = "\uD83E\uDDBB\uD83C\uDFFE", + [":ear_with_hearing_aid_tone5:"] = "\uD83E\uDDBB\uD83C\uDFFF", + [":earth_africa:"] = "\uD83C\uDF0D", + [":earth_americas:"] = "\uD83C\uDF0E", + [":earth_asia:"] = "\uD83C\uDF0F", + [":egg:"] = "\uD83E\uDD5A", + [":eggplant:"] = "\uD83C\uDF46", + [":eight:"] = "8️⃣", + [":eight_pointed_black_star:"] = "✴️", + [":eight_spoked_asterisk:"] = "✳️", + [":eject:"] = "⏏️", + [":eject_symbol:"] = "⏏️", + [":electric_plug:"] = "\uD83D\uDD0C", + [":elephant:"] = "\uD83D\uDC18", + [":elf:"] = "\uD83E\uDDDD", + [":elf::skin-tone-1:"] = "\uD83E\uDDDD\uD83C\uDFFB", + [":elf::skin-tone-2:"] = "\uD83E\uDDDD\uD83C\uDFFC", + [":elf::skin-tone-3:"] = "\uD83E\uDDDD\uD83C\uDFFD", + [":elf::skin-tone-4:"] = "\uD83E\uDDDD\uD83C\uDFFE", + [":elf::skin-tone-5:"] = "\uD83E\uDDDD\uD83C\uDFFF", + [":elf_dark_skin_tone:"] = "\uD83E\uDDDD\uD83C\uDFFF", + [":elf_light_skin_tone:"] = "\uD83E\uDDDD\uD83C\uDFFB", + [":elf_medium_dark_skin_tone:"] = "\uD83E\uDDDD\uD83C\uDFFE", + [":elf_medium_light_skin_tone:"] = "\uD83E\uDDDD\uD83C\uDFFC", + [":elf_medium_skin_tone:"] = "\uD83E\uDDDD\uD83C\uDFFD", + [":elf_tone1:"] = "\uD83E\uDDDD\uD83C\uDFFB", + [":elf_tone2:"] = "\uD83E\uDDDD\uD83C\uDFFC", + [":elf_tone3:"] = "\uD83E\uDDDD\uD83C\uDFFD", + [":elf_tone4:"] = "\uD83E\uDDDD\uD83C\uDFFE", + [":elf_tone5:"] = "\uD83E\uDDDD\uD83C\uDFFF", + [":email:"] = "\uD83D\uDCE7", + [":end:"] = "\uD83D\uDD1A", + [":england:"] = "\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67\uDB40\uDC7F", + [":envelope:"] = "✉️", + [":envelope_with_arrow:"] = "\uD83D\uDCE9", + [":euro:"] = "\uD83D\uDCB6", + [":european_castle:"] = "\uD83C\uDFF0", + [":european_post_office:"] = "\uD83C\uDFE4", + [":evergreen_tree:"] = "\uD83C\uDF32", + [":exclamation:"] = "❗", + [":expecting_woman:"] = "\uD83E\uDD30", + [":expecting_woman::skin-tone-1:"] = "\uD83E\uDD30\uD83C\uDFFB", + [":expecting_woman::skin-tone-2:"] = "\uD83E\uDD30\uD83C\uDFFC", + [":expecting_woman::skin-tone-3:"] = "\uD83E\uDD30\uD83C\uDFFD", + [":expecting_woman::skin-tone-4:"] = "\uD83E\uDD30\uD83C\uDFFE", + [":expecting_woman::skin-tone-5:"] = "\uD83E\uDD30\uD83C\uDFFF", + [":expecting_woman_tone1:"] = "\uD83E\uDD30\uD83C\uDFFB", + [":expecting_woman_tone2:"] = "\uD83E\uDD30\uD83C\uDFFC", + [":expecting_woman_tone3:"] = "\uD83E\uDD30\uD83C\uDFFD", + [":expecting_woman_tone4:"] = "\uD83E\uDD30\uD83C\uDFFE", + [":expecting_woman_tone5:"] = "\uD83E\uDD30\uD83C\uDFFF", + [":exploding_head:"] = "\uD83E\uDD2F", + [":expressionless:"] = "\uD83D\uDE11", + [":eye:"] = "\uD83D\uDC41️", + [":eye_in_speech_bubble:"] = "\uD83D\uDC41\u200D\uD83D\uDDE8", + [":eyeglasses:"] = "\uD83D\uDC53", + [":eyes:"] = "\uD83D\uDC40", + [":face_palm:"] = "\uD83E\uDD26", + [":face_palm::skin-tone-1:"] = "\uD83E\uDD26\uD83C\uDFFB", + [":face_palm::skin-tone-2:"] = "\uD83E\uDD26\uD83C\uDFFC", + [":face_palm::skin-tone-3:"] = "\uD83E\uDD26\uD83C\uDFFD", + [":face_palm::skin-tone-4:"] = "\uD83E\uDD26\uD83C\uDFFE", + [":face_palm::skin-tone-5:"] = "\uD83E\uDD26\uD83C\uDFFF", + [":face_palm_tone1:"] = "\uD83E\uDD26\uD83C\uDFFB", + [":face_palm_tone2:"] = "\uD83E\uDD26\uD83C\uDFFC", + [":face_palm_tone3:"] = "\uD83E\uDD26\uD83C\uDFFD", + [":face_palm_tone4:"] = "\uD83E\uDD26\uD83C\uDFFE", + [":face_palm_tone5:"] = "\uD83E\uDD26\uD83C\uDFFF", + [":face_vomiting:"] = "\uD83E\uDD2E", + [":face_with_cowboy_hat:"] = "\uD83E\uDD20", + [":face_with_hand_over_mouth:"] = "\uD83E\uDD2D", + [":face_with_head_bandage:"] = "\uD83E\uDD15", + [":face_with_monocle:"] = "\uD83E\uDDD0", + [":face_with_raised_eyebrow:"] = "\uD83E\uDD28", + [":face_with_rolling_eyes:"] = "\uD83D\uDE44", + [":face_with_symbols_over_mouth:"] = "\uD83E\uDD2C", + [":face_with_thermometer:"] = "\uD83E\uDD12", + [":facepalm:"] = "\uD83E\uDD26", + [":facepalm::skin-tone-1:"] = "\uD83E\uDD26\uD83C\uDFFB", + [":facepalm::skin-tone-2:"] = "\uD83E\uDD26\uD83C\uDFFC", + [":facepalm::skin-tone-3:"] = "\uD83E\uDD26\uD83C\uDFFD", + [":facepalm::skin-tone-4:"] = "\uD83E\uDD26\uD83C\uDFFE", + [":facepalm::skin-tone-5:"] = "\uD83E\uDD26\uD83C\uDFFF", + [":facepalm_tone1:"] = "\uD83E\uDD26\uD83C\uDFFB", + [":facepalm_tone2:"] = "\uD83E\uDD26\uD83C\uDFFC", + [":facepalm_tone3:"] = "\uD83E\uDD26\uD83C\uDFFD", + [":facepalm_tone4:"] = "\uD83E\uDD26\uD83C\uDFFE", + [":facepalm_tone5:"] = "\uD83E\uDD26\uD83C\uDFFF", + [":factory:"] = "\uD83C\uDFED", + [":fairy:"] = "\uD83E\uDDDA", + [":fairy::skin-tone-1:"] = "\uD83E\uDDDA\uD83C\uDFFB", + [":fairy::skin-tone-2:"] = "\uD83E\uDDDA\uD83C\uDFFC", + [":fairy::skin-tone-3:"] = "\uD83E\uDDDA\uD83C\uDFFD", + [":fairy::skin-tone-4:"] = "\uD83E\uDDDA\uD83C\uDFFE", + [":fairy::skin-tone-5:"] = "\uD83E\uDDDA\uD83C\uDFFF", + [":fairy_dark_skin_tone:"] = "\uD83E\uDDDA\uD83C\uDFFF", + [":fairy_light_skin_tone:"] = "\uD83E\uDDDA\uD83C\uDFFB", + [":fairy_medium_dark_skin_tone:"] = "\uD83E\uDDDA\uD83C\uDFFE", + [":fairy_medium_light_skin_tone:"] = "\uD83E\uDDDA\uD83C\uDFFC", + [":fairy_medium_skin_tone:"] = "\uD83E\uDDDA\uD83C\uDFFD", + [":fairy_tone1:"] = "\uD83E\uDDDA\uD83C\uDFFB", + [":fairy_tone2:"] = "\uD83E\uDDDA\uD83C\uDFFC", + [":fairy_tone3:"] = "\uD83E\uDDDA\uD83C\uDFFD", + [":fairy_tone4:"] = "\uD83E\uDDDA\uD83C\uDFFE", + [":fairy_tone5:"] = "\uD83E\uDDDA\uD83C\uDFFF", + [":falafel:"] = "\uD83E\uDDC6", + [":fallen_leaf:"] = "\uD83C\uDF42", + [":family:"] = "\uD83D\uDC6A", + [":family_man_boy:"] = "\uD83D\uDC68\u200D\uD83D\uDC66", + [":family_man_boy_boy:"] = "\uD83D\uDC68\u200D\uD83D\uDC66\u200D\uD83D\uDC66", + [":family_man_girl:"] = "\uD83D\uDC68\u200D\uD83D\uDC67", + [":family_man_girl_boy:"] = "\uD83D\uDC68\u200D\uD83D\uDC67\u200D\uD83D\uDC66", + [":family_man_girl_girl:"] = "\uD83D\uDC68\u200D\uD83D\uDC67\u200D\uD83D\uDC67", + [":family_man_woman_boy:"] = "\uD83D\uDC68\u200D\uD83D\uDC69\u200D\uD83D\uDC66", + [":family_mmb:"] = "\uD83D\uDC68\u200D\uD83D\uDC68\u200D\uD83D\uDC66", + [":family_mmbb:"] = "\uD83D\uDC68\u200D\uD83D\uDC68\u200D\uD83D\uDC66\u200D\uD83D\uDC66", + [":family_mmg:"] = "\uD83D\uDC68\u200D\uD83D\uDC68\u200D\uD83D\uDC67", + [":family_mmgb:"] = "\uD83D\uDC68\u200D\uD83D\uDC68\u200D\uD83D\uDC67\u200D\uD83D\uDC66", + [":family_mmgg:"] = "\uD83D\uDC68\u200D\uD83D\uDC68\u200D\uD83D\uDC67\u200D\uD83D\uDC67", + [":family_mwbb:"] = "\uD83D\uDC68\u200D\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66", + [":family_mwg:"] = "\uD83D\uDC68\u200D\uD83D\uDC69\u200D\uD83D\uDC67", + [":family_mwgb:"] = "\uD83D\uDC68\u200D\uD83D\uDC69\u200D\uD83D\uDC67\u200D\uD83D\uDC66", + [":family_mwgg:"] = "\uD83D\uDC68\u200D\uD83D\uDC69\u200D\uD83D\uDC67\u200D\uD83D\uDC67", + [":family_woman_boy:"] = "\uD83D\uDC69\u200D\uD83D\uDC66", + [":family_woman_boy_boy:"] = "\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66", + [":family_woman_girl:"] = "\uD83D\uDC69\u200D\uD83D\uDC67", + [":family_woman_girl_boy:"] = "\uD83D\uDC69\u200D\uD83D\uDC67\u200D\uD83D\uDC66", + [":family_woman_girl_girl:"] = "\uD83D\uDC69\u200D\uD83D\uDC67\u200D\uD83D\uDC67", + [":family_wwb:"] = "\uD83D\uDC69\u200D\uD83D\uDC69\u200D\uD83D\uDC66", + [":family_wwbb:"] = "\uD83D\uDC69\u200D\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66", + [":family_wwg:"] = "\uD83D\uDC69\u200D\uD83D\uDC69\u200D\uD83D\uDC67", + [":family_wwgb:"] = "\uD83D\uDC69\u200D\uD83D\uDC69\u200D\uD83D\uDC67\u200D\uD83D\uDC66", + [":family_wwgg:"] = "\uD83D\uDC69\u200D\uD83D\uDC69\u200D\uD83D\uDC67\u200D\uD83D\uDC67", + [":fast_forward:"] = "⏩", + [":fax:"] = "\uD83D\uDCE0", + [":fearful:"] = "\uD83D\uDE28", + [":feet:"] = "\uD83D\uDC3E", + [":female_sign:"] = "♀️", + [":fencer:"] = "\uD83E\uDD3A", + [":fencing:"] = "\uD83E\uDD3A", + [":ferris_wheel:"] = "\uD83C\uDFA1", + [":ferry:"] = "⛴️", + [":field_hockey:"] = "\uD83C\uDFD1", + [":file_cabinet:"] = "\uD83D\uDDC4️", + [":file_folder:"] = "\uD83D\uDCC1", + [":film_frames:"] = "\uD83C\uDF9E️", + [":film_projector:"] = "\uD83D\uDCFD️", + [":fingers_crossed:"] = "\uD83E\uDD1E", + [":fingers_crossed::skin-tone-1:"] = "\uD83E\uDD1E\uD83C\uDFFB", + [":fingers_crossed::skin-tone-2:"] = "\uD83E\uDD1E\uD83C\uDFFC", + [":fingers_crossed::skin-tone-3:"] = "\uD83E\uDD1E\uD83C\uDFFD", + [":fingers_crossed::skin-tone-4:"] = "\uD83E\uDD1E\uD83C\uDFFE", + [":fingers_crossed::skin-tone-5:"] = "\uD83E\uDD1E\uD83C\uDFFF", + [":fingers_crossed_tone1:"] = "\uD83E\uDD1E\uD83C\uDFFB", + [":fingers_crossed_tone2:"] = "\uD83E\uDD1E\uD83C\uDFFC", + [":fingers_crossed_tone3:"] = "\uD83E\uDD1E\uD83C\uDFFD", + [":fingers_crossed_tone4:"] = "\uD83E\uDD1E\uD83C\uDFFE", + [":fingers_crossed_tone5:"] = "\uD83E\uDD1E\uD83C\uDFFF", + [":fire:"] = "\uD83D\uDD25", + [":fire_engine:"] = "\uD83D\uDE92", + [":fire_extinguisher:"] = "\uD83E\uDDEF", + [":firecracker:"] = "\uD83E\uDDE8", + [":fireworks:"] = "\uD83C\uDF86", + [":first_place:"] = "\uD83E\uDD47", + [":first_place_medal:"] = "\uD83E\uDD47", + [":first_quarter_moon:"] = "\uD83C\uDF13", + [":first_quarter_moon_with_face:"] = "\uD83C\uDF1B", + [":fish:"] = "\uD83D\uDC1F", + [":fish_cake:"] = "\uD83C\uDF65", + [":fishing_pole_and_fish:"] = "\uD83C\uDFA3", + [":fist:"] = "✊", + [":fist::skin-tone-1:"] = "✊\uD83C\uDFFB", + [":fist::skin-tone-2:"] = "✊\uD83C\uDFFC", + [":fist::skin-tone-3:"] = "✊\uD83C\uDFFD", + [":fist::skin-tone-4:"] = "✊\uD83C\uDFFE", + [":fist::skin-tone-5:"] = "✊\uD83C\uDFFF", + [":fist_tone1:"] = "✊\uD83C\uDFFB", + [":fist_tone2:"] = "✊\uD83C\uDFFC", + [":fist_tone3:"] = "✊\uD83C\uDFFD", + [":fist_tone4:"] = "✊\uD83C\uDFFE", + [":fist_tone5:"] = "✊\uD83C\uDFFF", + [":five:"] = "5️⃣", + [":flag_ac:"] = "\uD83C\uDDE6\uD83C\uDDE8", + [":flag_ad:"] = "\uD83C\uDDE6\uD83C\uDDE9", + [":flag_ae:"] = "\uD83C\uDDE6\uD83C\uDDEA", + [":flag_af:"] = "\uD83C\uDDE6\uD83C\uDDEB", + [":flag_ag:"] = "\uD83C\uDDE6\uD83C\uDDEC", + [":flag_ai:"] = "\uD83C\uDDE6\uD83C\uDDEE", + [":flag_al:"] = "\uD83C\uDDE6\uD83C\uDDF1", + [":flag_am:"] = "\uD83C\uDDE6\uD83C\uDDF2", + [":flag_ao:"] = "\uD83C\uDDE6\uD83C\uDDF4", + [":flag_aq:"] = "\uD83C\uDDE6\uD83C\uDDF6", + [":flag_ar:"] = "\uD83C\uDDE6\uD83C\uDDF7", + [":flag_as:"] = "\uD83C\uDDE6\uD83C\uDDF8", + [":flag_at:"] = "\uD83C\uDDE6\uD83C\uDDF9", + [":flag_au:"] = "\uD83C\uDDE6\uD83C\uDDFA", + [":flag_aw:"] = "\uD83C\uDDE6\uD83C\uDDFC", + [":flag_ax:"] = "\uD83C\uDDE6\uD83C\uDDFD", + [":flag_az:"] = "\uD83C\uDDE6\uD83C\uDDFF", + [":flag_ba:"] = "\uD83C\uDDE7\uD83C\uDDE6", + [":flag_bb:"] = "\uD83C\uDDE7\uD83C\uDDE7", + [":flag_bd:"] = "\uD83C\uDDE7\uD83C\uDDE9", + [":flag_be:"] = "\uD83C\uDDE7\uD83C\uDDEA", + [":flag_bf:"] = "\uD83C\uDDE7\uD83C\uDDEB", + [":flag_bg:"] = "\uD83C\uDDE7\uD83C\uDDEC", + [":flag_bh:"] = "\uD83C\uDDE7\uD83C\uDDED", + [":flag_bi:"] = "\uD83C\uDDE7\uD83C\uDDEE", + [":flag_bj:"] = "\uD83C\uDDE7\uD83C\uDDEF", + [":flag_bl:"] = "\uD83C\uDDE7\uD83C\uDDF1", + [":flag_black:"] = "\uD83C\uDFF4", + [":flag_bm:"] = "\uD83C\uDDE7\uD83C\uDDF2", + [":flag_bn:"] = "\uD83C\uDDE7\uD83C\uDDF3", + [":flag_bo:"] = "\uD83C\uDDE7\uD83C\uDDF4", + [":flag_bq:"] = "\uD83C\uDDE7\uD83C\uDDF6", + [":flag_br:"] = "\uD83C\uDDE7\uD83C\uDDF7", + [":flag_bs:"] = "\uD83C\uDDE7\uD83C\uDDF8", + [":flag_bt:"] = "\uD83C\uDDE7\uD83C\uDDF9", + [":flag_bv:"] = "\uD83C\uDDE7\uD83C\uDDFB", + [":flag_bw:"] = "\uD83C\uDDE7\uD83C\uDDFC", + [":flag_by:"] = "\uD83C\uDDE7\uD83C\uDDFE", + [":flag_bz:"] = "\uD83C\uDDE7\uD83C\uDDFF", + [":flag_ca:"] = "\uD83C\uDDE8\uD83C\uDDE6", + [":flag_cc:"] = "\uD83C\uDDE8\uD83C\uDDE8", + [":flag_cd:"] = "\uD83C\uDDE8\uD83C\uDDE9", + [":flag_cf:"] = "\uD83C\uDDE8\uD83C\uDDEB", + [":flag_cg:"] = "\uD83C\uDDE8\uD83C\uDDEC", + [":flag_ch:"] = "\uD83C\uDDE8\uD83C\uDDED", + [":flag_ci:"] = "\uD83C\uDDE8\uD83C\uDDEE", + [":flag_ck:"] = "\uD83C\uDDE8\uD83C\uDDF0", + [":flag_cl:"] = "\uD83C\uDDE8\uD83C\uDDF1", + [":flag_cm:"] = "\uD83C\uDDE8\uD83C\uDDF2", + [":flag_cn:"] = "\uD83C\uDDE8\uD83C\uDDF3", + [":flag_co:"] = "\uD83C\uDDE8\uD83C\uDDF4", + [":flag_cp:"] = "\uD83C\uDDE8\uD83C\uDDF5", + [":flag_cr:"] = "\uD83C\uDDE8\uD83C\uDDF7", + [":flag_cu:"] = "\uD83C\uDDE8\uD83C\uDDFA", + [":flag_cv:"] = "\uD83C\uDDE8\uD83C\uDDFB", + [":flag_cw:"] = "\uD83C\uDDE8\uD83C\uDDFC", + [":flag_cx:"] = "\uD83C\uDDE8\uD83C\uDDFD", + [":flag_cy:"] = "\uD83C\uDDE8\uD83C\uDDFE", + [":flag_cz:"] = "\uD83C\uDDE8\uD83C\uDDFF", + [":flag_de:"] = "\uD83C\uDDE9\uD83C\uDDEA", + [":flag_dg:"] = "\uD83C\uDDE9\uD83C\uDDEC", + [":flag_dj:"] = "\uD83C\uDDE9\uD83C\uDDEF", + [":flag_dk:"] = "\uD83C\uDDE9\uD83C\uDDF0", + [":flag_dm:"] = "\uD83C\uDDE9\uD83C\uDDF2", + [":flag_do:"] = "\uD83C\uDDE9\uD83C\uDDF4", + [":flag_dz:"] = "\uD83C\uDDE9\uD83C\uDDFF", + [":flag_ea:"] = "\uD83C\uDDEA\uD83C\uDDE6", + [":flag_ec:"] = "\uD83C\uDDEA\uD83C\uDDE8", + [":flag_ee:"] = "\uD83C\uDDEA\uD83C\uDDEA", + [":flag_eg:"] = "\uD83C\uDDEA\uD83C\uDDEC", + [":flag_eh:"] = "\uD83C\uDDEA\uD83C\uDDED", + [":flag_er:"] = "\uD83C\uDDEA\uD83C\uDDF7", + [":flag_es:"] = "\uD83C\uDDEA\uD83C\uDDF8", + [":flag_et:"] = "\uD83C\uDDEA\uD83C\uDDF9", + [":flag_eu:"] = "\uD83C\uDDEA\uD83C\uDDFA", + [":flag_fi:"] = "\uD83C\uDDEB\uD83C\uDDEE", + [":flag_fj:"] = "\uD83C\uDDEB\uD83C\uDDEF", + [":flag_fk:"] = "\uD83C\uDDEB\uD83C\uDDF0", + [":flag_fm:"] = "\uD83C\uDDEB\uD83C\uDDF2", + [":flag_fo:"] = "\uD83C\uDDEB\uD83C\uDDF4", + [":flag_fr:"] = "\uD83C\uDDEB\uD83C\uDDF7", + [":flag_ga:"] = "\uD83C\uDDEC\uD83C\uDDE6", + [":flag_gb:"] = "\uD83C\uDDEC\uD83C\uDDE7", + [":flag_gd:"] = "\uD83C\uDDEC\uD83C\uDDE9", + [":flag_ge:"] = "\uD83C\uDDEC\uD83C\uDDEA", + [":flag_gf:"] = "\uD83C\uDDEC\uD83C\uDDEB", + [":flag_gg:"] = "\uD83C\uDDEC\uD83C\uDDEC", + [":flag_gh:"] = "\uD83C\uDDEC\uD83C\uDDED", + [":flag_gi:"] = "\uD83C\uDDEC\uD83C\uDDEE", + [":flag_gl:"] = "\uD83C\uDDEC\uD83C\uDDF1", + [":flag_gm:"] = "\uD83C\uDDEC\uD83C\uDDF2", + [":flag_gn:"] = "\uD83C\uDDEC\uD83C\uDDF3", + [":flag_gp:"] = "\uD83C\uDDEC\uD83C\uDDF5", + [":flag_gq:"] = "\uD83C\uDDEC\uD83C\uDDF6", + [":flag_gr:"] = "\uD83C\uDDEC\uD83C\uDDF7", + [":flag_gs:"] = "\uD83C\uDDEC\uD83C\uDDF8", + [":flag_gt:"] = "\uD83C\uDDEC\uD83C\uDDF9", + [":flag_gu:"] = "\uD83C\uDDEC\uD83C\uDDFA", + [":flag_gw:"] = "\uD83C\uDDEC\uD83C\uDDFC", + [":flag_gy:"] = "\uD83C\uDDEC\uD83C\uDDFE", + [":flag_hk:"] = "\uD83C\uDDED\uD83C\uDDF0", + [":flag_hm:"] = "\uD83C\uDDED\uD83C\uDDF2", + [":flag_hn:"] = "\uD83C\uDDED\uD83C\uDDF3", + [":flag_hr:"] = "\uD83C\uDDED\uD83C\uDDF7", + [":flag_ht:"] = "\uD83C\uDDED\uD83C\uDDF9", + [":flag_hu:"] = "\uD83C\uDDED\uD83C\uDDFA", + [":flag_ic:"] = "\uD83C\uDDEE\uD83C\uDDE8", + [":flag_id:"] = "\uD83C\uDDEE\uD83C\uDDE9", + [":flag_ie:"] = "\uD83C\uDDEE\uD83C\uDDEA", + [":flag_il:"] = "\uD83C\uDDEE\uD83C\uDDF1", + [":flag_im:"] = "\uD83C\uDDEE\uD83C\uDDF2", + [":flag_in:"] = "\uD83C\uDDEE\uD83C\uDDF3", + [":flag_io:"] = "\uD83C\uDDEE\uD83C\uDDF4", + [":flag_iq:"] = "\uD83C\uDDEE\uD83C\uDDF6", + [":flag_ir:"] = "\uD83C\uDDEE\uD83C\uDDF7", + [":flag_is:"] = "\uD83C\uDDEE\uD83C\uDDF8", + [":flag_it:"] = "\uD83C\uDDEE\uD83C\uDDF9", + [":flag_je:"] = "\uD83C\uDDEF\uD83C\uDDEA", + [":flag_jm:"] = "\uD83C\uDDEF\uD83C\uDDF2", + [":flag_jo:"] = "\uD83C\uDDEF\uD83C\uDDF4", + [":flag_jp:"] = "\uD83C\uDDEF\uD83C\uDDF5", + [":flag_ke:"] = "\uD83C\uDDF0\uD83C\uDDEA", + [":flag_kg:"] = "\uD83C\uDDF0\uD83C\uDDEC", + [":flag_kh:"] = "\uD83C\uDDF0\uD83C\uDDED", + [":flag_ki:"] = "\uD83C\uDDF0\uD83C\uDDEE", + [":flag_km:"] = "\uD83C\uDDF0\uD83C\uDDF2", + [":flag_kn:"] = "\uD83C\uDDF0\uD83C\uDDF3", + [":flag_kp:"] = "\uD83C\uDDF0\uD83C\uDDF5", + [":flag_kr:"] = "\uD83C\uDDF0\uD83C\uDDF7", + [":flag_kw:"] = "\uD83C\uDDF0\uD83C\uDDFC", + [":flag_ky:"] = "\uD83C\uDDF0\uD83C\uDDFE", + [":flag_kz:"] = "\uD83C\uDDF0\uD83C\uDDFF", + [":flag_la:"] = "\uD83C\uDDF1\uD83C\uDDE6", + [":flag_lb:"] = "\uD83C\uDDF1\uD83C\uDDE7", + [":flag_lc:"] = "\uD83C\uDDF1\uD83C\uDDE8", + [":flag_li:"] = "\uD83C\uDDF1\uD83C\uDDEE", + [":flag_lk:"] = "\uD83C\uDDF1\uD83C\uDDF0", + [":flag_lr:"] = "\uD83C\uDDF1\uD83C\uDDF7", + [":flag_ls:"] = "\uD83C\uDDF1\uD83C\uDDF8", + [":flag_lt:"] = "\uD83C\uDDF1\uD83C\uDDF9", + [":flag_lu:"] = "\uD83C\uDDF1\uD83C\uDDFA", + [":flag_lv:"] = "\uD83C\uDDF1\uD83C\uDDFB", + [":flag_ly:"] = "\uD83C\uDDF1\uD83C\uDDFE", + [":flag_ma:"] = "\uD83C\uDDF2\uD83C\uDDE6", + [":flag_mc:"] = "\uD83C\uDDF2\uD83C\uDDE8", + [":flag_md:"] = "\uD83C\uDDF2\uD83C\uDDE9", + [":flag_me:"] = "\uD83C\uDDF2\uD83C\uDDEA", + [":flag_mf:"] = "\uD83C\uDDF2\uD83C\uDDEB", + [":flag_mg:"] = "\uD83C\uDDF2\uD83C\uDDEC", + [":flag_mh:"] = "\uD83C\uDDF2\uD83C\uDDED", + [":flag_mk:"] = "\uD83C\uDDF2\uD83C\uDDF0", + [":flag_ml:"] = "\uD83C\uDDF2\uD83C\uDDF1", + [":flag_mm:"] = "\uD83C\uDDF2\uD83C\uDDF2", + [":flag_mn:"] = "\uD83C\uDDF2\uD83C\uDDF3", + [":flag_mo:"] = "\uD83C\uDDF2\uD83C\uDDF4", + [":flag_mp:"] = "\uD83C\uDDF2\uD83C\uDDF5", + [":flag_mq:"] = "\uD83C\uDDF2\uD83C\uDDF6", + [":flag_mr:"] = "\uD83C\uDDF2\uD83C\uDDF7", + [":flag_ms:"] = "\uD83C\uDDF2\uD83C\uDDF8", + [":flag_mt:"] = "\uD83C\uDDF2\uD83C\uDDF9", + [":flag_mu:"] = "\uD83C\uDDF2\uD83C\uDDFA", + [":flag_mv:"] = "\uD83C\uDDF2\uD83C\uDDFB", + [":flag_mw:"] = "\uD83C\uDDF2\uD83C\uDDFC", + [":flag_mx:"] = "\uD83C\uDDF2\uD83C\uDDFD", + [":flag_my:"] = "\uD83C\uDDF2\uD83C\uDDFE", + [":flag_mz:"] = "\uD83C\uDDF2\uD83C\uDDFF", + [":flag_na:"] = "\uD83C\uDDF3\uD83C\uDDE6", + [":flag_nc:"] = "\uD83C\uDDF3\uD83C\uDDE8", + [":flag_ne:"] = "\uD83C\uDDF3\uD83C\uDDEA", + [":flag_nf:"] = "\uD83C\uDDF3\uD83C\uDDEB", + [":flag_ng:"] = "\uD83C\uDDF3\uD83C\uDDEC", + [":flag_ni:"] = "\uD83C\uDDF3\uD83C\uDDEE", + [":flag_nl:"] = "\uD83C\uDDF3\uD83C\uDDF1", + [":flag_no:"] = "\uD83C\uDDF3\uD83C\uDDF4", + [":flag_np:"] = "\uD83C\uDDF3\uD83C\uDDF5", + [":flag_nr:"] = "\uD83C\uDDF3\uD83C\uDDF7", + [":flag_nu:"] = "\uD83C\uDDF3\uD83C\uDDFA", + [":flag_nz:"] = "\uD83C\uDDF3\uD83C\uDDFF", + [":flag_om:"] = "\uD83C\uDDF4\uD83C\uDDF2", + [":flag_pa:"] = "\uD83C\uDDF5\uD83C\uDDE6", + [":flag_pe:"] = "\uD83C\uDDF5\uD83C\uDDEA", + [":flag_pf:"] = "\uD83C\uDDF5\uD83C\uDDEB", + [":flag_pg:"] = "\uD83C\uDDF5\uD83C\uDDEC", + [":flag_ph:"] = "\uD83C\uDDF5\uD83C\uDDED", + [":flag_pk:"] = "\uD83C\uDDF5\uD83C\uDDF0", + [":flag_pl:"] = "\uD83C\uDDF5\uD83C\uDDF1", + [":flag_pm:"] = "\uD83C\uDDF5\uD83C\uDDF2", + [":flag_pn:"] = "\uD83C\uDDF5\uD83C\uDDF3", + [":flag_pr:"] = "\uD83C\uDDF5\uD83C\uDDF7", + [":flag_ps:"] = "\uD83C\uDDF5\uD83C\uDDF8", + [":flag_pt:"] = "\uD83C\uDDF5\uD83C\uDDF9", + [":flag_pw:"] = "\uD83C\uDDF5\uD83C\uDDFC", + [":flag_py:"] = "\uD83C\uDDF5\uD83C\uDDFE", + [":flag_qa:"] = "\uD83C\uDDF6\uD83C\uDDE6", + [":flag_re:"] = "\uD83C\uDDF7\uD83C\uDDEA", + [":flag_ro:"] = "\uD83C\uDDF7\uD83C\uDDF4", + [":flag_rs:"] = "\uD83C\uDDF7\uD83C\uDDF8", + [":flag_ru:"] = "\uD83C\uDDF7\uD83C\uDDFA", + [":flag_rw:"] = "\uD83C\uDDF7\uD83C\uDDFC", + [":flag_sa:"] = "\uD83C\uDDF8\uD83C\uDDE6", + [":flag_sb:"] = "\uD83C\uDDF8\uD83C\uDDE7", + [":flag_sc:"] = "\uD83C\uDDF8\uD83C\uDDE8", + [":flag_sd:"] = "\uD83C\uDDF8\uD83C\uDDE9", + [":flag_se:"] = "\uD83C\uDDF8\uD83C\uDDEA", + [":flag_sg:"] = "\uD83C\uDDF8\uD83C\uDDEC", + [":flag_sh:"] = "\uD83C\uDDF8\uD83C\uDDED", + [":flag_si:"] = "\uD83C\uDDF8\uD83C\uDDEE", + [":flag_sj:"] = "\uD83C\uDDF8\uD83C\uDDEF", + [":flag_sk:"] = "\uD83C\uDDF8\uD83C\uDDF0", + [":flag_sl:"] = "\uD83C\uDDF8\uD83C\uDDF1", + [":flag_sm:"] = "\uD83C\uDDF8\uD83C\uDDF2", + [":flag_sn:"] = "\uD83C\uDDF8\uD83C\uDDF3", + [":flag_so:"] = "\uD83C\uDDF8\uD83C\uDDF4", + [":flag_sr:"] = "\uD83C\uDDF8\uD83C\uDDF7", + [":flag_ss:"] = "\uD83C\uDDF8\uD83C\uDDF8", + [":flag_st:"] = "\uD83C\uDDF8\uD83C\uDDF9", + [":flag_sv:"] = "\uD83C\uDDF8\uD83C\uDDFB", + [":flag_sx:"] = "\uD83C\uDDF8\uD83C\uDDFD", + [":flag_sy:"] = "\uD83C\uDDF8\uD83C\uDDFE", + [":flag_sz:"] = "\uD83C\uDDF8\uD83C\uDDFF", + [":flag_ta:"] = "\uD83C\uDDF9\uD83C\uDDE6", + [":flag_tc:"] = "\uD83C\uDDF9\uD83C\uDDE8", + [":flag_td:"] = "\uD83C\uDDF9\uD83C\uDDE9", + [":flag_tf:"] = "\uD83C\uDDF9\uD83C\uDDEB", + [":flag_tg:"] = "\uD83C\uDDF9\uD83C\uDDEC", + [":flag_th:"] = "\uD83C\uDDF9\uD83C\uDDED", + [":flag_tj:"] = "\uD83C\uDDF9\uD83C\uDDEF", + [":flag_tk:"] = "\uD83C\uDDF9\uD83C\uDDF0", + [":flag_tl:"] = "\uD83C\uDDF9\uD83C\uDDF1", + [":flag_tm:"] = "\uD83C\uDDF9\uD83C\uDDF2", + [":flag_tn:"] = "\uD83C\uDDF9\uD83C\uDDF3", + [":flag_to:"] = "\uD83C\uDDF9\uD83C\uDDF4", + [":flag_tr:"] = "\uD83C\uDDF9\uD83C\uDDF7", + [":flag_tt:"] = "\uD83C\uDDF9\uD83C\uDDF9", + [":flag_tv:"] = "\uD83C\uDDF9\uD83C\uDDFB", + [":flag_tw:"] = "\uD83C\uDDF9\uD83C\uDDFC", + [":flag_tz:"] = "\uD83C\uDDF9\uD83C\uDDFF", + [":flag_ua:"] = "\uD83C\uDDFA\uD83C\uDDE6", + [":flag_ug:"] = "\uD83C\uDDFA\uD83C\uDDEC", + [":flag_um:"] = "\uD83C\uDDFA\uD83C\uDDF2", + [":flag_us:"] = "\uD83C\uDDFA\uD83C\uDDF8", + [":flag_uy:"] = "\uD83C\uDDFA\uD83C\uDDFE", + [":flag_uz:"] = "\uD83C\uDDFA\uD83C\uDDFF", + [":flag_va:"] = "\uD83C\uDDFB\uD83C\uDDE6", + [":flag_vc:"] = "\uD83C\uDDFB\uD83C\uDDE8", + [":flag_ve:"] = "\uD83C\uDDFB\uD83C\uDDEA", + [":flag_vg:"] = "\uD83C\uDDFB\uD83C\uDDEC", + [":flag_vi:"] = "\uD83C\uDDFB\uD83C\uDDEE", + [":flag_vn:"] = "\uD83C\uDDFB\uD83C\uDDF3", + [":flag_vu:"] = "\uD83C\uDDFB\uD83C\uDDFA", + [":flag_wf:"] = "\uD83C\uDDFC\uD83C\uDDEB", + [":flag_white:"] = "\uD83C\uDFF3️", + [":flag_ws:"] = "\uD83C\uDDFC\uD83C\uDDF8", + [":flag_xk:"] = "\uD83C\uDDFD\uD83C\uDDF0", + [":flag_ye:"] = "\uD83C\uDDFE\uD83C\uDDEA", + [":flag_yt:"] = "\uD83C\uDDFE\uD83C\uDDF9", + [":flag_za:"] = "\uD83C\uDDFF\uD83C\uDDE6", + [":flag_zm:"] = "\uD83C\uDDFF\uD83C\uDDF2", + [":flag_zw:"] = "\uD83C\uDDFF\uD83C\uDDFC", + [":flags:"] = "\uD83C\uDF8F", + [":flame:"] = "\uD83D\uDD25", + [":flamingo:"] = "\uD83E\uDDA9", + [":flan:"] = "\uD83C\uDF6E", + [":flashlight:"] = "\uD83D\uDD26", + [":fleur_de_lis:"] = "⚜️", + [":floppy_disk:"] = "\uD83D\uDCBE", + [":flower_playing_cards:"] = "\uD83C\uDFB4", + [":flushed:"] = "\uD83D\uDE33", + [":flying_disc:"] = "\uD83E\uDD4F", + [":flying_saucer:"] = "\uD83D\uDEF8", + [":fog:"] = "\uD83C\uDF2B️", + [":foggy:"] = "\uD83C\uDF01", + [":foot:"] = "\uD83E\uDDB6", + [":foot::skin-tone-1:"] = "\uD83E\uDDB6\uD83C\uDFFB", + [":foot::skin-tone-2:"] = "\uD83E\uDDB6\uD83C\uDFFC", + [":foot::skin-tone-3:"] = "\uD83E\uDDB6\uD83C\uDFFD", + [":foot::skin-tone-4:"] = "\uD83E\uDDB6\uD83C\uDFFE", + [":foot::skin-tone-5:"] = "\uD83E\uDDB6\uD83C\uDFFF", + [":foot_dark_skin_tone:"] = "\uD83E\uDDB6\uD83C\uDFFF", + [":foot_light_skin_tone:"] = "\uD83E\uDDB6\uD83C\uDFFB", + [":foot_medium_dark_skin_tone:"] = "\uD83E\uDDB6\uD83C\uDFFE", + [":foot_medium_light_skin_tone:"] = "\uD83E\uDDB6\uD83C\uDFFC", + [":foot_medium_skin_tone:"] = "\uD83E\uDDB6\uD83C\uDFFD", + [":foot_tone1:"] = "\uD83E\uDDB6\uD83C\uDFFB", + [":foot_tone2:"] = "\uD83E\uDDB6\uD83C\uDFFC", + [":foot_tone3:"] = "\uD83E\uDDB6\uD83C\uDFFD", + [":foot_tone4:"] = "\uD83E\uDDB6\uD83C\uDFFE", + [":foot_tone5:"] = "\uD83E\uDDB6\uD83C\uDFFF", + [":football:"] = "\uD83C\uDFC8", + [":footprints:"] = "\uD83D\uDC63", + [":fork_and_knife:"] = "\uD83C\uDF74", + [":fork_and_knife_with_plate:"] = "\uD83C\uDF7D️", + [":fork_knife_plate:"] = "\uD83C\uDF7D️", + [":fortune_cookie:"] = "\uD83E\uDD60", + [":fountain:"] = "⛲", + [":four:"] = "4️⃣", + [":four_leaf_clover:"] = "\uD83C\uDF40", + [":fox:"] = "\uD83E\uDD8A", + [":fox_face:"] = "\uD83E\uDD8A", + [":frame_photo:"] = "\uD83D\uDDBC️", + [":frame_with_picture:"] = "\uD83D\uDDBC️", + [":free:"] = "\uD83C\uDD93", + [":french_bread:"] = "\uD83E\uDD56", + [":fried_shrimp:"] = "\uD83C\uDF64", + [":fries:"] = "\uD83C\uDF5F", + [":frog:"] = "\uD83D\uDC38", + [":frowning2:"] = "☹️", + [":frowning:"] = "\uD83D\uDE26", + [":fuelpump:"] = "⛽", + [":full_moon:"] = "\uD83C\uDF15", + [":full_moon_with_face:"] = "\uD83C\uDF1D", + [":funeral_urn:"] = "⚱️", + [":game_die:"] = "\uD83C\uDFB2", + [":garlic:"] = "\uD83E\uDDC4", + [":gay_pride_flag:"] = "\uD83C\uDFF3️\u200D\uD83C\uDF08", + [":gear:"] = "⚙️", + [":gem:"] = "\uD83D\uDC8E", + [":gemini:"] = "♊", + [":genie:"] = "\uD83E\uDDDE", + [":ghost:"] = "\uD83D\uDC7B", + [":gift:"] = "\uD83C\uDF81", + [":gift_heart:"] = "\uD83D\uDC9D", + [":giraffe:"] = "\uD83E\uDD92", + [":girl:"] = "\uD83D\uDC67", + [":girl::skin-tone-1:"] = "\uD83D\uDC67\uD83C\uDFFB", + [":girl::skin-tone-2:"] = "\uD83D\uDC67\uD83C\uDFFC", + [":girl::skin-tone-3:"] = "\uD83D\uDC67\uD83C\uDFFD", + [":girl::skin-tone-4:"] = "\uD83D\uDC67\uD83C\uDFFE", + [":girl::skin-tone-5:"] = "\uD83D\uDC67\uD83C\uDFFF", + [":girl_tone1:"] = "\uD83D\uDC67\uD83C\uDFFB", + [":girl_tone2:"] = "\uD83D\uDC67\uD83C\uDFFC", + [":girl_tone3:"] = "\uD83D\uDC67\uD83C\uDFFD", + [":girl_tone4:"] = "\uD83D\uDC67\uD83C\uDFFE", + [":girl_tone5:"] = "\uD83D\uDC67\uD83C\uDFFF", + [":glass_of_milk:"] = "\uD83E\uDD5B", + [":globe_with_meridians:"] = "\uD83C\uDF10", + [":gloves:"] = "\uD83E\uDDE4", + [":goal:"] = "\uD83E\uDD45", + [":goal_net:"] = "\uD83E\uDD45", + [":goat:"] = "\uD83D\uDC10", + [":goggles:"] = "\uD83E\uDD7D", + [":golf:"] = "⛳", + [":golfer:"] = "\uD83C\uDFCC️", + [":golfer::skin-tone-1:"] = "\uD83C\uDFCC\uD83C\uDFFB", + [":golfer::skin-tone-2:"] = "\uD83C\uDFCC\uD83C\uDFFC", + [":golfer::skin-tone-3:"] = "\uD83C\uDFCC\uD83C\uDFFD", + [":golfer::skin-tone-4:"] = "\uD83C\uDFCC\uD83C\uDFFE", + [":golfer::skin-tone-5:"] = "\uD83C\uDFCC\uD83C\uDFFF", + [":gorilla:"] = "\uD83E\uDD8D", + [":grandma:"] = "\uD83D\uDC75", + [":grandma::skin-tone-1:"] = "\uD83D\uDC75\uD83C\uDFFB", + [":grandma::skin-tone-2:"] = "\uD83D\uDC75\uD83C\uDFFC", + [":grandma::skin-tone-3:"] = "\uD83D\uDC75\uD83C\uDFFD", + [":grandma::skin-tone-4:"] = "\uD83D\uDC75\uD83C\uDFFE", + [":grandma::skin-tone-5:"] = "\uD83D\uDC75\uD83C\uDFFF", + [":grandma_tone1:"] = "\uD83D\uDC75\uD83C\uDFFB", + [":grandma_tone2:"] = "\uD83D\uDC75\uD83C\uDFFC", + [":grandma_tone3:"] = "\uD83D\uDC75\uD83C\uDFFD", + [":grandma_tone4:"] = "\uD83D\uDC75\uD83C\uDFFE", + [":grandma_tone5:"] = "\uD83D\uDC75\uD83C\uDFFF", + [":grapes:"] = "\uD83C\uDF47", + [":green_apple:"] = "\uD83C\uDF4F", + [":green_book:"] = "\uD83D\uDCD7", + [":green_circle:"] = "\uD83D\uDFE2", + [":green_heart:"] = "\uD83D\uDC9A", + [":green_salad:"] = "\uD83E\uDD57", + [":green_square:"] = "\uD83D\uDFE9", + [":grey_exclamation:"] = "❕", + [":grey_question:"] = "❔", + [":grimacing:"] = "\uD83D\uDE2C", + [":grin:"] = "\uD83D\uDE01", + [":grinning:"] = "\uD83D\uDE00", + [":guard:"] = "\uD83D\uDC82", + [":guard::skin-tone-1:"] = "\uD83D\uDC82\uD83C\uDFFB", + [":guard::skin-tone-2:"] = "\uD83D\uDC82\uD83C\uDFFC", + [":guard::skin-tone-3:"] = "\uD83D\uDC82\uD83C\uDFFD", + [":guard::skin-tone-4:"] = "\uD83D\uDC82\uD83C\uDFFE", + [":guard::skin-tone-5:"] = "\uD83D\uDC82\uD83C\uDFFF", + [":guard_tone1:"] = "\uD83D\uDC82\uD83C\uDFFB", + [":guard_tone2:"] = "\uD83D\uDC82\uD83C\uDFFC", + [":guard_tone3:"] = "\uD83D\uDC82\uD83C\uDFFD", + [":guard_tone4:"] = "\uD83D\uDC82\uD83C\uDFFE", + [":guard_tone5:"] = "\uD83D\uDC82\uD83C\uDFFF", + [":guardsman:"] = "\uD83D\uDC82", + [":guardsman::skin-tone-1:"] = "\uD83D\uDC82\uD83C\uDFFB", + [":guardsman::skin-tone-2:"] = "\uD83D\uDC82\uD83C\uDFFC", + [":guardsman::skin-tone-3:"] = "\uD83D\uDC82\uD83C\uDFFD", + [":guardsman::skin-tone-4:"] = "\uD83D\uDC82\uD83C\uDFFE", + [":guardsman::skin-tone-5:"] = "\uD83D\uDC82\uD83C\uDFFF", + [":guardsman_tone1:"] = "\uD83D\uDC82\uD83C\uDFFB", + [":guardsman_tone2:"] = "\uD83D\uDC82\uD83C\uDFFC", + [":guardsman_tone3:"] = "\uD83D\uDC82\uD83C\uDFFD", + [":guardsman_tone4:"] = "\uD83D\uDC82\uD83C\uDFFE", + [":guardsman_tone5:"] = "\uD83D\uDC82\uD83C\uDFFF", + [":guide_dog:"] = "\uD83E\uDDAE", + [":guitar:"] = "\uD83C\uDFB8", + [":gun:"] = "\uD83D\uDD2B", + [":haircut:"] = "\uD83D\uDC87", + [":haircut::skin-tone-1:"] = "\uD83D\uDC87\uD83C\uDFFB", + [":haircut::skin-tone-2:"] = "\uD83D\uDC87\uD83C\uDFFC", + [":haircut::skin-tone-3:"] = "\uD83D\uDC87\uD83C\uDFFD", + [":haircut::skin-tone-4:"] = "\uD83D\uDC87\uD83C\uDFFE", + [":haircut::skin-tone-5:"] = "\uD83D\uDC87\uD83C\uDFFF", + [":haircut_tone1:"] = "\uD83D\uDC87\uD83C\uDFFB", + [":haircut_tone2:"] = "\uD83D\uDC87\uD83C\uDFFC", + [":haircut_tone3:"] = "\uD83D\uDC87\uD83C\uDFFD", + [":haircut_tone4:"] = "\uD83D\uDC87\uD83C\uDFFE", + [":haircut_tone5:"] = "\uD83D\uDC87\uD83C\uDFFF", + [":hamburger:"] = "\uD83C\uDF54", + [":hammer:"] = "\uD83D\uDD28", + [":hammer_and_pick:"] = "⚒️", + [":hammer_and_wrench:"] = "\uD83D\uDEE0️", + [":hammer_pick:"] = "⚒️", + [":hamster:"] = "\uD83D\uDC39", + [":hand_splayed:"] = "\uD83D\uDD90️", + [":hand_splayed::skin-tone-1:"] = "\uD83D\uDD90\uD83C\uDFFB", + [":hand_splayed::skin-tone-2:"] = "\uD83D\uDD90\uD83C\uDFFC", + [":hand_splayed::skin-tone-3:"] = "\uD83D\uDD90\uD83C\uDFFD", + [":hand_splayed::skin-tone-4:"] = "\uD83D\uDD90\uD83C\uDFFE", + [":hand_splayed::skin-tone-5:"] = "\uD83D\uDD90\uD83C\uDFFF", + [":hand_splayed_tone1:"] = "\uD83D\uDD90\uD83C\uDFFB", + [":hand_splayed_tone2:"] = "\uD83D\uDD90\uD83C\uDFFC", + [":hand_splayed_tone3:"] = "\uD83D\uDD90\uD83C\uDFFD", + [":hand_splayed_tone4:"] = "\uD83D\uDD90\uD83C\uDFFE", + [":hand_splayed_tone5:"] = "\uD83D\uDD90\uD83C\uDFFF", + [":hand_with_index_and_middle_finger_crossed:"] = "\uD83E\uDD1E", + [":hand_with_index_and_middle_finger_crossed::skin-tone-1:"] = "\uD83E\uDD1E\uD83C\uDFFB", + [":hand_with_index_and_middle_finger_crossed::skin-tone-2:"] = "\uD83E\uDD1E\uD83C\uDFFC", + [":hand_with_index_and_middle_finger_crossed::skin-tone-3:"] = "\uD83E\uDD1E\uD83C\uDFFD", + [":hand_with_index_and_middle_finger_crossed::skin-tone-4:"] = "\uD83E\uDD1E\uD83C\uDFFE", + [":hand_with_index_and_middle_finger_crossed::skin-tone-5:"] = "\uD83E\uDD1E\uD83C\uDFFF", + [":hand_with_index_and_middle_fingers_crossed_tone1:"] = "\uD83E\uDD1E\uD83C\uDFFB", + [":hand_with_index_and_middle_fingers_crossed_tone2:"] = "\uD83E\uDD1E\uD83C\uDFFC", + [":hand_with_index_and_middle_fingers_crossed_tone3:"] = "\uD83E\uDD1E\uD83C\uDFFD", + [":hand_with_index_and_middle_fingers_crossed_tone4:"] = "\uD83E\uDD1E\uD83C\uDFFE", + [":hand_with_index_and_middle_fingers_crossed_tone5:"] = "\uD83E\uDD1E\uD83C\uDFFF", + [":handbag:"] = "\uD83D\uDC5C", + [":handball:"] = "\uD83E\uDD3E", + [":handball::skin-tone-1:"] = "\uD83E\uDD3E\uD83C\uDFFB", + [":handball::skin-tone-2:"] = "\uD83E\uDD3E\uD83C\uDFFC", + [":handball::skin-tone-3:"] = "\uD83E\uDD3E\uD83C\uDFFD", + [":handball::skin-tone-4:"] = "\uD83E\uDD3E\uD83C\uDFFE", + [":handball::skin-tone-5:"] = "\uD83E\uDD3E\uD83C\uDFFF", + [":handball_tone1:"] = "\uD83E\uDD3E\uD83C\uDFFB", + [":handball_tone2:"] = "\uD83E\uDD3E\uD83C\uDFFC", + [":handball_tone3:"] = "\uD83E\uDD3E\uD83C\uDFFD", + [":handball_tone4:"] = "\uD83E\uDD3E\uD83C\uDFFE", + [":handball_tone5:"] = "\uD83E\uDD3E\uD83C\uDFFF", + [":handshake:"] = "\uD83E\uDD1D", + [":hankey:"] = "\uD83D\uDCA9", + [":hash:"] = "#️⃣", + [":hatched_chick:"] = "\uD83D\uDC25", + [":hatching_chick:"] = "\uD83D\uDC23", + [":head_bandage:"] = "\uD83E\uDD15", + [":headphones:"] = "\uD83C\uDFA7", + [":hear_no_evil:"] = "\uD83D\uDE49", + [":heart:"] = "❤️", + [":heart_decoration:"] = "\uD83D\uDC9F", + [":heart_exclamation:"] = "❣️", + [":heart_eyes:"] = "\uD83D\uDE0D", + [":heart_eyes_cat:"] = "\uD83D\uDE3B", + [":heartbeat:"] = "\uD83D\uDC93", + [":heartpulse:"] = "\uD83D\uDC97", + [":hearts:"] = "♥️", + [":heavy_check_mark:"] = "✔️", + [":heavy_division_sign:"] = "➗", + [":heavy_dollar_sign:"] = "\uD83D\uDCB2", + [":heavy_heart_exclamation_mark_ornament:"] = "❣️", + [":heavy_minus_sign:"] = "➖", + [":heavy_multiplication_x:"] = "✖️", + [":heavy_plus_sign:"] = "➕", + [":hedgehog:"] = "\uD83E\uDD94", + [":helicopter:"] = "\uD83D\uDE81", + [":helmet_with_cross:"] = "⛑️", + [":helmet_with_white_cross:"] = "⛑️", + [":herb:"] = "\uD83C\uDF3F", + [":hibiscus:"] = "\uD83C\uDF3A", + [":high_brightness:"] = "\uD83D\uDD06", + [":high_heel:"] = "\uD83D\uDC60", + [":hiking_boot:"] = "\uD83E\uDD7E", + [":hindu_temple:"] = "\uD83D\uDED5", + [":hippopotamus:"] = "\uD83E\uDD9B", + [":hockey:"] = "\uD83C\uDFD2", + [":hole:"] = "\uD83D\uDD73️", + [":homes:"] = "\uD83C\uDFD8️", + [":honey_pot:"] = "\uD83C\uDF6F", + [":horse:"] = "\uD83D\uDC34", + [":horse_racing:"] = "\uD83C\uDFC7", + [":horse_racing::skin-tone-1:"] = "\uD83C\uDFC7\uD83C\uDFFB", + [":horse_racing::skin-tone-2:"] = "\uD83C\uDFC7\uD83C\uDFFC", + [":horse_racing::skin-tone-3:"] = "\uD83C\uDFC7\uD83C\uDFFD", + [":horse_racing::skin-tone-4:"] = "\uD83C\uDFC7\uD83C\uDFFE", + [":horse_racing::skin-tone-5:"] = "\uD83C\uDFC7\uD83C\uDFFF", + [":horse_racing_tone1:"] = "\uD83C\uDFC7\uD83C\uDFFB", + [":horse_racing_tone2:"] = "\uD83C\uDFC7\uD83C\uDFFC", + [":horse_racing_tone3:"] = "\uD83C\uDFC7\uD83C\uDFFD", + [":horse_racing_tone4:"] = "\uD83C\uDFC7\uD83C\uDFFE", + [":horse_racing_tone5:"] = "\uD83C\uDFC7\uD83C\uDFFF", + [":hospital:"] = "\uD83C\uDFE5", + [":hot_dog:"] = "\uD83C\uDF2D", + [":hot_face:"] = "\uD83E\uDD75", + [":hot_pepper:"] = "\uD83C\uDF36️", + [":hotdog:"] = "\uD83C\uDF2D", + [":hotel:"] = "\uD83C\uDFE8", + [":hotsprings:"] = "♨️", + [":hourglass:"] = "⌛", + [":hourglass_flowing_sand:"] = "⏳", + [":house:"] = "\uD83C\uDFE0", + [":house_abandoned:"] = "\uD83C\uDFDA️", + [":house_buildings:"] = "\uD83C\uDFD8️", + [":house_with_garden:"] = "\uD83C\uDFE1", + [":hugging:"] = "\uD83E\uDD17", + [":hugging_face:"] = "\uD83E\uDD17", + [":hushed:"] = "\uD83D\uDE2F", + [":ice_cream:"] = "\uD83C\uDF68", + [":ice_cube:"] = "\uD83E\uDDCA", + [":ice_skate:"] = "⛸️", + [":icecream:"] = "\uD83C\uDF66", + [":id:"] = "\uD83C\uDD94", + [":ideograph_advantage:"] = "\uD83C\uDE50", + [":imp:"] = "\uD83D\uDC7F", + [":inbox_tray:"] = "\uD83D\uDCE5", + [":incoming_envelope:"] = "\uD83D\uDCE8", + [":infinity:"] = "♾️", + [":information_desk_person:"] = "\uD83D\uDC81", + [":information_desk_person::skin-tone-1:"] = "\uD83D\uDC81\uD83C\uDFFB", + [":information_desk_person::skin-tone-2:"] = "\uD83D\uDC81\uD83C\uDFFC", + [":information_desk_person::skin-tone-3:"] = "\uD83D\uDC81\uD83C\uDFFD", + [":information_desk_person::skin-tone-4:"] = "\uD83D\uDC81\uD83C\uDFFE", + [":information_desk_person::skin-tone-5:"] = "\uD83D\uDC81\uD83C\uDFFF", + [":information_desk_person_tone1:"] = "\uD83D\uDC81\uD83C\uDFFB", + [":information_desk_person_tone2:"] = "\uD83D\uDC81\uD83C\uDFFC", + [":information_desk_person_tone3:"] = "\uD83D\uDC81\uD83C\uDFFD", + [":information_desk_person_tone4:"] = "\uD83D\uDC81\uD83C\uDFFE", + [":information_desk_person_tone5:"] = "\uD83D\uDC81\uD83C\uDFFF", + [":information_source:"] = "ℹ️", + [":innocent:"] = "\uD83D\uDE07", + [":interrobang:"] = "⁉️", + [":iphone:"] = "\uD83D\uDCF1", + [":island:"] = "\uD83C\uDFDD️", + [":izakaya_lantern:"] = "\uD83C\uDFEE", + [":jack_o_lantern:"] = "\uD83C\uDF83", + [":japan:"] = "\uD83D\uDDFE", + [":japanese_castle:"] = "\uD83C\uDFEF", + [":japanese_goblin:"] = "\uD83D\uDC7A", + [":japanese_ogre:"] = "\uD83D\uDC79", + [":jeans:"] = "\uD83D\uDC56", + [":jigsaw:"] = "\uD83E\uDDE9", + [":joy:"] = "\uD83D\uDE02", + [":joy_cat:"] = "\uD83D\uDE39", + [":joystick:"] = "\uD83D\uDD79️", + [":juggler:"] = "\uD83E\uDD39", + [":juggler::skin-tone-1:"] = "\uD83E\uDD39\uD83C\uDFFB", + [":juggler::skin-tone-2:"] = "\uD83E\uDD39\uD83C\uDFFC", + [":juggler::skin-tone-3:"] = "\uD83E\uDD39\uD83C\uDFFD", + [":juggler::skin-tone-4:"] = "\uD83E\uDD39\uD83C\uDFFE", + [":juggler::skin-tone-5:"] = "\uD83E\uDD39\uD83C\uDFFF", + [":juggler_tone1:"] = "\uD83E\uDD39\uD83C\uDFFB", + [":juggler_tone2:"] = "\uD83E\uDD39\uD83C\uDFFC", + [":juggler_tone3:"] = "\uD83E\uDD39\uD83C\uDFFD", + [":juggler_tone4:"] = "\uD83E\uDD39\uD83C\uDFFE", + [":juggler_tone5:"] = "\uD83E\uDD39\uD83C\uDFFF", + [":juggling:"] = "\uD83E\uDD39", + [":juggling::skin-tone-1:"] = "\uD83E\uDD39\uD83C\uDFFB", + [":juggling::skin-tone-2:"] = "\uD83E\uDD39\uD83C\uDFFC", + [":juggling::skin-tone-3:"] = "\uD83E\uDD39\uD83C\uDFFD", + [":juggling::skin-tone-4:"] = "\uD83E\uDD39\uD83C\uDFFE", + [":juggling::skin-tone-5:"] = "\uD83E\uDD39\uD83C\uDFFF", + [":juggling_tone1:"] = "\uD83E\uDD39\uD83C\uDFFB", + [":juggling_tone2:"] = "\uD83E\uDD39\uD83C\uDFFC", + [":juggling_tone3:"] = "\uD83E\uDD39\uD83C\uDFFD", + [":juggling_tone4:"] = "\uD83E\uDD39\uD83C\uDFFE", + [":juggling_tone5:"] = "\uD83E\uDD39\uD83C\uDFFF", + [":kaaba:"] = "\uD83D\uDD4B", + [":kangaroo:"] = "\uD83E\uDD98", + [":karate_uniform:"] = "\uD83E\uDD4B", + [":kayak:"] = "\uD83D\uDEF6", + [":key2:"] = "\uD83D\uDDDD️", + [":key:"] = "\uD83D\uDD11", + [":keyboard:"] = "⌨️", + [":keycap_asterisk:"] = "*️⃣", + [":keycap_ten:"] = "\uD83D\uDD1F", + [":kimono:"] = "\uD83D\uDC58", + [":kiss:"] = "\uD83D\uDC8B", + [":kiss_mm:"] = "\uD83D\uDC68\u200D❤️\u200D\uD83D\uDC8B\u200D\uD83D\uDC68", + [":kiss_woman_man:"] = "\uD83D\uDC69\u200D❤️\u200D\uD83D\uDC8B\u200D\uD83D\uDC68", + [":kiss_ww:"] = "\uD83D\uDC69\u200D❤️\u200D\uD83D\uDC8B\u200D\uD83D\uDC69", + [":kissing:"] = "\uD83D\uDE17", + [":kissing_cat:"] = "\uD83D\uDE3D", + [":kissing_closed_eyes:"] = "\uD83D\uDE1A", + [":kissing_heart:"] = "\uD83D\uDE18", + [":kissing_smiling_eyes:"] = "\uD83D\uDE19", + [":kite:"] = "\uD83E\uDE81", + [":kiwi:"] = "\uD83E\uDD5D", + [":kiwifruit:"] = "\uD83E\uDD5D", + [":knife:"] = "\uD83D\uDD2A", + [":koala:"] = "\uD83D\uDC28", + [":koko:"] = "\uD83C\uDE01", + [":knot:"] = "\uD83E\uDEA2", + [":lab_coat:"] = "\uD83E\uDD7C", + [":label:"] = "\uD83C\uDFF7️", + [":lacrosse:"] = "\uD83E\uDD4D", + [":large_blue_diamond:"] = "\uD83D\uDD37", + [":large_orange_diamond:"] = "\uD83D\uDD36", + [":last_quarter_moon:"] = "\uD83C\uDF17", + [":last_quarter_moon_with_face:"] = "\uD83C\uDF1C", + [":latin_cross:"] = "✝️", + [":laughing:"] = "\uD83D\uDE06", + [":leafy_green:"] = "\uD83E\uDD6C", + [":leaves:"] = "\uD83C\uDF43", + [":ledger:"] = "\uD83D\uDCD2", + [":left_facing_fist:"] = "\uD83E\uDD1B", + [":left_facing_fist::skin-tone-1:"] = "\uD83E\uDD1B\uD83C\uDFFB", + [":left_facing_fist::skin-tone-2:"] = "\uD83E\uDD1B\uD83C\uDFFC", + [":left_facing_fist::skin-tone-3:"] = "\uD83E\uDD1B\uD83C\uDFFD", + [":left_facing_fist::skin-tone-4:"] = "\uD83E\uDD1B\uD83C\uDFFE", + [":left_facing_fist::skin-tone-5:"] = "\uD83E\uDD1B\uD83C\uDFFF", + [":left_facing_fist_tone1:"] = "\uD83E\uDD1B\uD83C\uDFFB", + [":left_facing_fist_tone2:"] = "\uD83E\uDD1B\uD83C\uDFFC", + [":left_facing_fist_tone3:"] = "\uD83E\uDD1B\uD83C\uDFFD", + [":left_facing_fist_tone4:"] = "\uD83E\uDD1B\uD83C\uDFFE", + [":left_facing_fist_tone5:"] = "\uD83E\uDD1B\uD83C\uDFFF", + [":left_fist:"] = "\uD83E\uDD1B", + [":left_fist::skin-tone-1:"] = "\uD83E\uDD1B\uD83C\uDFFB", + [":left_fist::skin-tone-2:"] = "\uD83E\uDD1B\uD83C\uDFFC", + [":left_fist::skin-tone-3:"] = "\uD83E\uDD1B\uD83C\uDFFD", + [":left_fist::skin-tone-4:"] = "\uD83E\uDD1B\uD83C\uDFFE", + [":left_fist::skin-tone-5:"] = "\uD83E\uDD1B\uD83C\uDFFF", + [":left_fist_tone1:"] = "\uD83E\uDD1B\uD83C\uDFFB", + [":left_fist_tone2:"] = "\uD83E\uDD1B\uD83C\uDFFC", + [":left_fist_tone3:"] = "\uD83E\uDD1B\uD83C\uDFFD", + [":left_fist_tone4:"] = "\uD83E\uDD1B\uD83C\uDFFE", + [":left_fist_tone5:"] = "\uD83E\uDD1B\uD83C\uDFFF", + [":left_luggage:"] = "\uD83D\uDEC5", + [":left_right_arrow:"] = "↔️", + [":left_speech_bubble:"] = "\uD83D\uDDE8️", + [":leftwards_arrow_with_hook:"] = "↩️", + [":leg:"] = "\uD83E\uDDB5", + [":leg::skin-tone-1:"] = "\uD83E\uDDB5\uD83C\uDFFB", + [":leg::skin-tone-2:"] = "\uD83E\uDDB5\uD83C\uDFFC", + [":leg::skin-tone-3:"] = "\uD83E\uDDB5\uD83C\uDFFD", + [":leg::skin-tone-4:"] = "\uD83E\uDDB5\uD83C\uDFFE", + [":leg::skin-tone-5:"] = "\uD83E\uDDB5\uD83C\uDFFF", + [":leg_dark_skin_tone:"] = "\uD83E\uDDB5\uD83C\uDFFF", + [":leg_light_skin_tone:"] = "\uD83E\uDDB5\uD83C\uDFFB", + [":leg_medium_dark_skin_tone:"] = "\uD83E\uDDB5\uD83C\uDFFE", + [":leg_medium_light_skin_tone:"] = "\uD83E\uDDB5\uD83C\uDFFC", + [":leg_medium_skin_tone:"] = "\uD83E\uDDB5\uD83C\uDFFD", + [":leg_tone1:"] = "\uD83E\uDDB5\uD83C\uDFFB", + [":leg_tone2:"] = "\uD83E\uDDB5\uD83C\uDFFC", + [":leg_tone3:"] = "\uD83E\uDDB5\uD83C\uDFFD", + [":leg_tone4:"] = "\uD83E\uDDB5\uD83C\uDFFE", + [":leg_tone5:"] = "\uD83E\uDDB5\uD83C\uDFFF", + [":lemon:"] = "\uD83C\uDF4B", + [":leo:"] = "♌", + [":leopard:"] = "\uD83D\uDC06", + [":level_slider:"] = "\uD83C\uDF9A️", + [":levitate:"] = "\uD83D\uDD74️", + [":levitate::skin-tone-1:"] = "\uD83D\uDD74\uD83C\uDFFB", + [":levitate::skin-tone-2:"] = "\uD83D\uDD74\uD83C\uDFFC", + [":levitate::skin-tone-3:"] = "\uD83D\uDD74\uD83C\uDFFD", + [":levitate::skin-tone-4:"] = "\uD83D\uDD74\uD83C\uDFFE", + [":levitate::skin-tone-5:"] = "\uD83D\uDD74\uD83C\uDFFF", + [":levitate_tone1:"] = "\uD83D\uDD74\uD83C\uDFFB", + [":levitate_tone2:"] = "\uD83D\uDD74\uD83C\uDFFC", + [":levitate_tone3:"] = "\uD83D\uDD74\uD83C\uDFFD", + [":levitate_tone4:"] = "\uD83D\uDD74\uD83C\uDFFE", + [":levitate_tone5:"] = "\uD83D\uDD74\uD83C\uDFFF", + [":liar:"] = "\uD83E\uDD25", + [":libra:"] = "♎", + [":lifter:"] = "\uD83C\uDFCB️", + [":lifter::skin-tone-1:"] = "\uD83C\uDFCB\uD83C\uDFFB", + [":lifter::skin-tone-2:"] = "\uD83C\uDFCB\uD83C\uDFFC", + [":lifter::skin-tone-3:"] = "\uD83C\uDFCB\uD83C\uDFFD", + [":lifter::skin-tone-4:"] = "\uD83C\uDFCB\uD83C\uDFFE", + [":lifter::skin-tone-5:"] = "\uD83C\uDFCB\uD83C\uDFFF", + [":lifter_tone1:"] = "\uD83C\uDFCB\uD83C\uDFFB", + [":lifter_tone2:"] = "\uD83C\uDFCB\uD83C\uDFFC", + [":lifter_tone3:"] = "\uD83C\uDFCB\uD83C\uDFFD", + [":lifter_tone4:"] = "\uD83C\uDFCB\uD83C\uDFFE", + [":lifter_tone5:"] = "\uD83C\uDFCB\uD83C\uDFFF", + [":light_rail:"] = "\uD83D\uDE88", + [":link:"] = "\uD83D\uDD17", + [":linked_paperclips:"] = "\uD83D\uDD87️", + [":lion:"] = "\uD83E\uDD81", + [":lion_face:"] = "\uD83E\uDD81", + [":lips:"] = "\uD83D\uDC44", + [":lipstick:"] = "\uD83D\uDC84", + [":lizard:"] = "\uD83E\uDD8E", + [":llama:"] = "\uD83E\uDD99", + [":lobster:"] = "\uD83E\uDD9E", + [":lock:"] = "\uD83D\uDD12", + [":lock_with_ink_pen:"] = "\uD83D\uDD0F", + [":lollipop:"] = "\uD83C\uDF6D", + [":loop:"] = "➿", + [":loud_sound:"] = "\uD83D\uDD0A", + [":loudspeaker:"] = "\uD83D\uDCE2", + [":love_hotel:"] = "\uD83C\uDFE9", + [":love_letter:"] = "\uD83D\uDC8C", + [":love_you_gesture:"] = "\uD83E\uDD1F", + [":love_you_gesture::skin-tone-1:"] = "\uD83E\uDD1F\uD83C\uDFFB", + [":love_you_gesture::skin-tone-2:"] = "\uD83E\uDD1F\uD83C\uDFFC", + [":love_you_gesture::skin-tone-3:"] = "\uD83E\uDD1F\uD83C\uDFFD", + [":love_you_gesture::skin-tone-4:"] = "\uD83E\uDD1F\uD83C\uDFFE", + [":love_you_gesture::skin-tone-5:"] = "\uD83E\uDD1F\uD83C\uDFFF", + [":love_you_gesture_dark_skin_tone:"] = "\uD83E\uDD1F\uD83C\uDFFF", + [":love_you_gesture_light_skin_tone:"] = "\uD83E\uDD1F\uD83C\uDFFB", + [":love_you_gesture_medium_dark_skin_tone:"] = "\uD83E\uDD1F\uD83C\uDFFE", + [":love_you_gesture_medium_light_skin_tone:"] = "\uD83E\uDD1F\uD83C\uDFFC", + [":love_you_gesture_medium_skin_tone:"] = "\uD83E\uDD1F\uD83C\uDFFD", + [":love_you_gesture_tone1:"] = "\uD83E\uDD1F\uD83C\uDFFB", + [":love_you_gesture_tone2:"] = "\uD83E\uDD1F\uD83C\uDFFC", + [":love_you_gesture_tone3:"] = "\uD83E\uDD1F\uD83C\uDFFD", + [":love_you_gesture_tone4:"] = "\uD83E\uDD1F\uD83C\uDFFE", + [":love_you_gesture_tone5:"] = "\uD83E\uDD1F\uD83C\uDFFF", + [":low_brightness:"] = "\uD83D\uDD05", + [":lower_left_ballpoint_pen:"] = "\uD83D\uDD8A️", + [":lower_left_crayon:"] = "\uD83D\uDD8D️", + [":lower_left_fountain_pen:"] = "\uD83D\uDD8B️", + [":lower_left_paintbrush:"] = "\uD83D\uDD8C️", + [":luggage:"] = "\uD83E\uDDF3", + [":lying_face:"] = "\uD83E\uDD25", + [":m:"] = "Ⓜ️", + [":mag:"] = "\uD83D\uDD0D", + [":mag_right:"] = "\uD83D\uDD0E", + [":mage:"] = "\uD83E\uDDD9", + [":mage::skin-tone-1:"] = "\uD83E\uDDD9\uD83C\uDFFB", + [":mage::skin-tone-2:"] = "\uD83E\uDDD9\uD83C\uDFFC", + [":mage::skin-tone-3:"] = "\uD83E\uDDD9\uD83C\uDFFD", + [":mage::skin-tone-4:"] = "\uD83E\uDDD9\uD83C\uDFFE", + [":mage::skin-tone-5:"] = "\uD83E\uDDD9\uD83C\uDFFF", + [":mage_dark_skin_tone:"] = "\uD83E\uDDD9\uD83C\uDFFF", + [":mage_light_skin_tone:"] = "\uD83E\uDDD9\uD83C\uDFFB", + [":mage_medium_dark_skin_tone:"] = "\uD83E\uDDD9\uD83C\uDFFE", + [":mage_medium_light_skin_tone:"] = "\uD83E\uDDD9\uD83C\uDFFC", + [":mage_medium_skin_tone:"] = "\uD83E\uDDD9\uD83C\uDFFD", + [":mage_tone1:"] = "\uD83E\uDDD9\uD83C\uDFFB", + [":mage_tone2:"] = "\uD83E\uDDD9\uD83C\uDFFC", + [":mage_tone3:"] = "\uD83E\uDDD9\uD83C\uDFFD", + [":mage_tone4:"] = "\uD83E\uDDD9\uD83C\uDFFE", + [":mage_tone5:"] = "\uD83E\uDDD9\uD83C\uDFFF", + [":magnet:"] = "\uD83E\uDDF2", + [":mahjong:"] = "\uD83C\uDC04", + [":mailbox:"] = "\uD83D\uDCEB", + [":mailbox_closed:"] = "\uD83D\uDCEA", + [":mailbox_with_mail:"] = "\uD83D\uDCEC", + [":mailbox_with_no_mail:"] = "\uD83D\uDCED", + [":male_dancer:"] = "\uD83D\uDD7A", + [":male_dancer::skin-tone-1:"] = "\uD83D\uDD7A\uD83C\uDFFB", + [":male_dancer::skin-tone-2:"] = "\uD83D\uDD7A\uD83C\uDFFC", + [":male_dancer::skin-tone-3:"] = "\uD83D\uDD7A\uD83C\uDFFD", + [":male_dancer::skin-tone-4:"] = "\uD83D\uDD7A\uD83C\uDFFE", + [":male_dancer::skin-tone-5:"] = "\uD83D\uDD7A\uD83C\uDFFF", + [":male_dancer_tone1:"] = "\uD83D\uDD7A\uD83C\uDFFB", + [":male_dancer_tone2:"] = "\uD83D\uDD7A\uD83C\uDFFC", + [":male_dancer_tone3:"] = "\uD83D\uDD7A\uD83C\uDFFD", + [":male_dancer_tone4:"] = "\uD83D\uDD7A\uD83C\uDFFE", + [":male_dancer_tone5:"] = "\uD83D\uDD7A\uD83C\uDFFF", + [":male_sign:"] = "♂️", + [":man:"] = "\uD83D\uDC68", + [":man::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB", + [":man::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC", + [":man::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD", + [":man::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE", + [":man::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF", + [":man_artist:"] = "\uD83D\uDC68\u200D\uD83C\uDFA8", + [":man_artist::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDFA8", + [":man_artist::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDFA8", + [":man_artist::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDFA8", + [":man_artist::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDFA8", + [":man_artist::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDFA8", + [":man_artist_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDFA8", + [":man_artist_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDFA8", + [":man_artist_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDFA8", + [":man_artist_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDFA8", + [":man_artist_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDFA8", + [":man_artist_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDFA8", + [":man_artist_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDFA8", + [":man_artist_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDFA8", + [":man_artist_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDFA8", + [":man_artist_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDFA8", + [":man_astronaut:"] = "\uD83D\uDC68\u200D\uD83D\uDE80", + [":man_astronaut::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDE80", + [":man_astronaut::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDE80", + [":man_astronaut::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDE80", + [":man_astronaut::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDE80", + [":man_astronaut::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDE80", + [":man_astronaut_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDE80", + [":man_astronaut_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDE80", + [":man_astronaut_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDE80", + [":man_astronaut_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDE80", + [":man_astronaut_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDE80", + [":man_astronaut_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDE80", + [":man_astronaut_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDE80", + [":man_astronaut_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDE80", + [":man_astronaut_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDE80", + [":man_astronaut_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDE80", + [":man_bald:"] = "\uD83D\uDC68\u200D\uD83E\uDDB2", + [":man_bald::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDB2", + [":man_bald::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDB2", + [":man_bald::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDB2", + [":man_bald::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDB2", + [":man_bald::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDB2", + [":man_bald_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDB2", + [":man_bald_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDB2", + [":man_bald_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDB2", + [":man_bald_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDB2", + [":man_bald_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDB2", + [":man_bald_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDB2", + [":man_bald_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDB2", + [":man_bald_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDB2", + [":man_bald_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDB2", + [":man_bald_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDB2", + [":man_biking:"] = "\uD83D\uDEB4\u200D♂️", + [":man_biking::skin-tone-1:"] = "\uD83D\uDEB4\uD83C\uDFFB\u200D♂️", + [":man_biking::skin-tone-2:"] = "\uD83D\uDEB4\uD83C\uDFFC\u200D♂️", + [":man_biking::skin-tone-3:"] = "\uD83D\uDEB4\uD83C\uDFFD\u200D♂️", + [":man_biking::skin-tone-4:"] = "\uD83D\uDEB4\uD83C\uDFFE\u200D♂️", + [":man_biking::skin-tone-5:"] = "\uD83D\uDEB4\uD83C\uDFFF\u200D♂️", + [":man_biking_dark_skin_tone:"] = "\uD83D\uDEB4\uD83C\uDFFF\u200D♂️", + [":man_biking_light_skin_tone:"] = "\uD83D\uDEB4\uD83C\uDFFB\u200D♂️", + [":man_biking_medium_dark_skin_tone:"] = "\uD83D\uDEB4\uD83C\uDFFE\u200D♂️", + [":man_biking_medium_light_skin_tone:"] = "\uD83D\uDEB4\uD83C\uDFFC\u200D♂️", + [":man_biking_medium_skin_tone:"] = "\uD83D\uDEB4\uD83C\uDFFD\u200D♂️", + [":man_biking_tone1:"] = "\uD83D\uDEB4\uD83C\uDFFB\u200D♂️", + [":man_biking_tone2:"] = "\uD83D\uDEB4\uD83C\uDFFC\u200D♂️", + [":man_biking_tone3:"] = "\uD83D\uDEB4\uD83C\uDFFD\u200D♂️", + [":man_biking_tone4:"] = "\uD83D\uDEB4\uD83C\uDFFE\u200D♂️", + [":man_biking_tone5:"] = "\uD83D\uDEB4\uD83C\uDFFF\u200D♂️", + [":man_bouncing_ball:"] = "⛹️\u200D♂️", + [":man_bouncing_ball::skin-tone-1:"] = "⛹\uD83C\uDFFB\u200D♂️", + [":man_bouncing_ball::skin-tone-2:"] = "⛹\uD83C\uDFFC\u200D♂️", + [":man_bouncing_ball::skin-tone-3:"] = "⛹\uD83C\uDFFD\u200D♂️", + [":man_bouncing_ball::skin-tone-4:"] = "⛹\uD83C\uDFFE\u200D♂️", + [":man_bouncing_ball::skin-tone-5:"] = "⛹\uD83C\uDFFF\u200D♂️", + [":man_bouncing_ball_dark_skin_tone:"] = "⛹\uD83C\uDFFF\u200D♂️", + [":man_bouncing_ball_light_skin_tone:"] = "⛹\uD83C\uDFFB\u200D♂️", + [":man_bouncing_ball_medium_dark_skin_tone:"] = "⛹\uD83C\uDFFE\u200D♂️", + [":man_bouncing_ball_medium_light_skin_tone:"] = "⛹\uD83C\uDFFC\u200D♂️", + [":man_bouncing_ball_medium_skin_tone:"] = "⛹\uD83C\uDFFD\u200D♂️", + [":man_bouncing_ball_tone1:"] = "⛹\uD83C\uDFFB\u200D♂️", + [":man_bouncing_ball_tone2:"] = "⛹\uD83C\uDFFC\u200D♂️", + [":man_bouncing_ball_tone3:"] = "⛹\uD83C\uDFFD\u200D♂️", + [":man_bouncing_ball_tone4:"] = "⛹\uD83C\uDFFE\u200D♂️", + [":man_bouncing_ball_tone5:"] = "⛹\uD83C\uDFFF\u200D♂️", + [":man_bowing:"] = "\uD83D\uDE47\u200D♂️", + [":man_bowing::skin-tone-1:"] = "\uD83D\uDE47\uD83C\uDFFB\u200D♂️", + [":man_bowing::skin-tone-2:"] = "\uD83D\uDE47\uD83C\uDFFC\u200D♂️", + [":man_bowing::skin-tone-3:"] = "\uD83D\uDE47\uD83C\uDFFD\u200D♂️", + [":man_bowing::skin-tone-4:"] = "\uD83D\uDE47\uD83C\uDFFE\u200D♂️", + [":man_bowing::skin-tone-5:"] = "\uD83D\uDE47\uD83C\uDFFF\u200D♂️", + [":man_bowing_dark_skin_tone:"] = "\uD83D\uDE47\uD83C\uDFFF\u200D♂️", + [":man_bowing_light_skin_tone:"] = "\uD83D\uDE47\uD83C\uDFFB\u200D♂️", + [":man_bowing_medium_dark_skin_tone:"] = "\uD83D\uDE47\uD83C\uDFFE\u200D♂️", + [":man_bowing_medium_light_skin_tone:"] = "\uD83D\uDE47\uD83C\uDFFC\u200D♂️", + [":man_bowing_medium_skin_tone:"] = "\uD83D\uDE47\uD83C\uDFFD\u200D♂️", + [":man_bowing_tone1:"] = "\uD83D\uDE47\uD83C\uDFFB\u200D♂️", + [":man_bowing_tone2:"] = "\uD83D\uDE47\uD83C\uDFFC\u200D♂️", + [":man_bowing_tone3:"] = "\uD83D\uDE47\uD83C\uDFFD\u200D♂️", + [":man_bowing_tone4:"] = "\uD83D\uDE47\uD83C\uDFFE\u200D♂️", + [":man_bowing_tone5:"] = "\uD83D\uDE47\uD83C\uDFFF\u200D♂️", + [":man_cartwheeling:"] = "\uD83E\uDD38\u200D♂️", + [":man_cartwheeling::skin-tone-1:"] = "\uD83E\uDD38\uD83C\uDFFB\u200D♂️", + [":man_cartwheeling::skin-tone-2:"] = "\uD83E\uDD38\uD83C\uDFFC\u200D♂️", + [":man_cartwheeling::skin-tone-3:"] = "\uD83E\uDD38\uD83C\uDFFD\u200D♂️", + [":man_cartwheeling::skin-tone-4:"] = "\uD83E\uDD38\uD83C\uDFFE\u200D♂️", + [":man_cartwheeling::skin-tone-5:"] = "\uD83E\uDD38\uD83C\uDFFF\u200D♂️", + [":man_cartwheeling_dark_skin_tone:"] = "\uD83E\uDD38\uD83C\uDFFF\u200D♂️", + [":man_cartwheeling_light_skin_tone:"] = "\uD83E\uDD38\uD83C\uDFFB\u200D♂️", + [":man_cartwheeling_medium_dark_skin_tone:"] = "\uD83E\uDD38\uD83C\uDFFE\u200D♂️", + [":man_cartwheeling_medium_light_skin_tone:"] = "\uD83E\uDD38\uD83C\uDFFC\u200D♂️", + [":man_cartwheeling_medium_skin_tone:"] = "\uD83E\uDD38\uD83C\uDFFD\u200D♂️", + [":man_cartwheeling_tone1:"] = "\uD83E\uDD38\uD83C\uDFFB\u200D♂️", + [":man_cartwheeling_tone2:"] = "\uD83E\uDD38\uD83C\uDFFC\u200D♂️", + [":man_cartwheeling_tone3:"] = "\uD83E\uDD38\uD83C\uDFFD\u200D♂️", + [":man_cartwheeling_tone4:"] = "\uD83E\uDD38\uD83C\uDFFE\u200D♂️", + [":man_cartwheeling_tone5:"] = "\uD83E\uDD38\uD83C\uDFFF\u200D♂️", + [":man_climbing:"] = "\uD83E\uDDD7\u200D♂️", + [":man_climbing::skin-tone-1:"] = "\uD83E\uDDD7\uD83C\uDFFB\u200D♂️", + [":man_climbing::skin-tone-2:"] = "\uD83E\uDDD7\uD83C\uDFFC\u200D♂️", + [":man_climbing::skin-tone-3:"] = "\uD83E\uDDD7\uD83C\uDFFD\u200D♂️", + [":man_climbing::skin-tone-4:"] = "\uD83E\uDDD7\uD83C\uDFFE\u200D♂️", + [":man_climbing::skin-tone-5:"] = "\uD83E\uDDD7\uD83C\uDFFF\u200D♂️", + [":man_climbing_dark_skin_tone:"] = "\uD83E\uDDD7\uD83C\uDFFF\u200D♂️", + [":man_climbing_light_skin_tone:"] = "\uD83E\uDDD7\uD83C\uDFFB\u200D♂️", + [":man_climbing_medium_dark_skin_tone:"] = "\uD83E\uDDD7\uD83C\uDFFE\u200D♂️", + [":man_climbing_medium_light_skin_tone:"] = "\uD83E\uDDD7\uD83C\uDFFC\u200D♂️", + [":man_climbing_medium_skin_tone:"] = "\uD83E\uDDD7\uD83C\uDFFD\u200D♂️", + [":man_climbing_tone1:"] = "\uD83E\uDDD7\uD83C\uDFFB\u200D♂️", + [":man_climbing_tone2:"] = "\uD83E\uDDD7\uD83C\uDFFC\u200D♂️", + [":man_climbing_tone3:"] = "\uD83E\uDDD7\uD83C\uDFFD\u200D♂️", + [":man_climbing_tone4:"] = "\uD83E\uDDD7\uD83C\uDFFE\u200D♂️", + [":man_climbing_tone5:"] = "\uD83E\uDDD7\uD83C\uDFFF\u200D♂️", + [":man_construction_worker:"] = "\uD83D\uDC77\u200D♂️", + [":man_construction_worker::skin-tone-1:"] = "\uD83D\uDC77\uD83C\uDFFB\u200D♂️", + [":man_construction_worker::skin-tone-2:"] = "\uD83D\uDC77\uD83C\uDFFC\u200D♂️", + [":man_construction_worker::skin-tone-3:"] = "\uD83D\uDC77\uD83C\uDFFD\u200D♂️", + [":man_construction_worker::skin-tone-4:"] = "\uD83D\uDC77\uD83C\uDFFE\u200D♂️", + [":man_construction_worker::skin-tone-5:"] = "\uD83D\uDC77\uD83C\uDFFF\u200D♂️", + [":man_construction_worker_dark_skin_tone:"] = "\uD83D\uDC77\uD83C\uDFFF\u200D♂️", + [":man_construction_worker_light_skin_tone:"] = "\uD83D\uDC77\uD83C\uDFFB\u200D♂️", + [":man_construction_worker_medium_dark_skin_tone:"] = "\uD83D\uDC77\uD83C\uDFFE\u200D♂️", + [":man_construction_worker_medium_light_skin_tone:"] = "\uD83D\uDC77\uD83C\uDFFC\u200D♂️", + [":man_construction_worker_medium_skin_tone:"] = "\uD83D\uDC77\uD83C\uDFFD\u200D♂️", + [":man_construction_worker_tone1:"] = "\uD83D\uDC77\uD83C\uDFFB\u200D♂️", + [":man_construction_worker_tone2:"] = "\uD83D\uDC77\uD83C\uDFFC\u200D♂️", + [":man_construction_worker_tone3:"] = "\uD83D\uDC77\uD83C\uDFFD\u200D♂️", + [":man_construction_worker_tone4:"] = "\uD83D\uDC77\uD83C\uDFFE\u200D♂️", + [":man_construction_worker_tone5:"] = "\uD83D\uDC77\uD83C\uDFFF\u200D♂️", + [":man_cook:"] = "\uD83D\uDC68\u200D\uD83C\uDF73", + [":man_cook::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDF73", + [":man_cook::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDF73", + [":man_cook::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDF73", + [":man_cook::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDF73", + [":man_cook::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDF73", + [":man_cook_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDF73", + [":man_cook_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDF73", + [":man_cook_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDF73", + [":man_cook_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDF73", + [":man_cook_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDF73", + [":man_cook_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDF73", + [":man_cook_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDF73", + [":man_cook_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDF73", + [":man_cook_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDF73", + [":man_cook_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDF73", + [":man_curly_haired:"] = "\uD83D\uDC68\u200D\uD83E\uDDB1", + [":man_curly_haired::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDB1", + [":man_curly_haired::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDB1", + [":man_curly_haired::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDB1", + [":man_curly_haired::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDB1", + [":man_curly_haired::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDB1", + [":man_curly_haired_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDB1", + [":man_curly_haired_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDB1", + [":man_curly_haired_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDB1", + [":man_curly_haired_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDB1", + [":man_curly_haired_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDB1", + [":man_curly_haired_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDB1", + [":man_curly_haired_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDB1", + [":man_curly_haired_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDB1", + [":man_curly_haired_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDB1", + [":man_curly_haired_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDB1", + [":man_dancing:"] = "\uD83D\uDD7A", + [":man_dancing::skin-tone-1:"] = "\uD83D\uDD7A\uD83C\uDFFB", + [":man_dancing::skin-tone-2:"] = "\uD83D\uDD7A\uD83C\uDFFC", + [":man_dancing::skin-tone-3:"] = "\uD83D\uDD7A\uD83C\uDFFD", + [":man_dancing::skin-tone-4:"] = "\uD83D\uDD7A\uD83C\uDFFE", + [":man_dancing::skin-tone-5:"] = "\uD83D\uDD7A\uD83C\uDFFF", + [":man_dancing_tone1:"] = "\uD83D\uDD7A\uD83C\uDFFB", + [":man_dancing_tone2:"] = "\uD83D\uDD7A\uD83C\uDFFC", + [":man_dancing_tone3:"] = "\uD83D\uDD7A\uD83C\uDFFD", + [":man_dancing_tone4:"] = "\uD83D\uDD7A\uD83C\uDFFE", + [":man_dancing_tone5:"] = "\uD83D\uDD7A\uD83C\uDFFF", + [":man_detective:"] = "\uD83D\uDD75️\u200D♂️", + [":man_detective::skin-tone-1:"] = "\uD83D\uDD75\uD83C\uDFFB\u200D♂️", + [":man_detective::skin-tone-2:"] = "\uD83D\uDD75\uD83C\uDFFC\u200D♂️", + [":man_detective::skin-tone-3:"] = "\uD83D\uDD75\uD83C\uDFFD\u200D♂️", + [":man_detective::skin-tone-4:"] = "\uD83D\uDD75\uD83C\uDFFE\u200D♂️", + [":man_detective::skin-tone-5:"] = "\uD83D\uDD75\uD83C\uDFFF\u200D♂️", + [":man_detective_dark_skin_tone:"] = "\uD83D\uDD75\uD83C\uDFFF\u200D♂️", + [":man_detective_light_skin_tone:"] = "\uD83D\uDD75\uD83C\uDFFB\u200D♂️", + [":man_detective_medium_dark_skin_tone:"] = "\uD83D\uDD75\uD83C\uDFFE\u200D♂️", + [":man_detective_medium_light_skin_tone:"] = "\uD83D\uDD75\uD83C\uDFFC\u200D♂️", + [":man_detective_medium_skin_tone:"] = "\uD83D\uDD75\uD83C\uDFFD\u200D♂️", + [":man_detective_tone1:"] = "\uD83D\uDD75\uD83C\uDFFB\u200D♂️", + [":man_detective_tone2:"] = "\uD83D\uDD75\uD83C\uDFFC\u200D♂️", + [":man_detective_tone3:"] = "\uD83D\uDD75\uD83C\uDFFD\u200D♂️", + [":man_detective_tone4:"] = "\uD83D\uDD75\uD83C\uDFFE\u200D♂️", + [":man_detective_tone5:"] = "\uD83D\uDD75\uD83C\uDFFF\u200D♂️", + [":man_elf:"] = "\uD83E\uDDDD\u200D♂️", + [":man_elf::skin-tone-1:"] = "\uD83E\uDDDD\uD83C\uDFFB\u200D♂️", + [":man_elf::skin-tone-2:"] = "\uD83E\uDDDD\uD83C\uDFFC\u200D♂️", + [":man_elf::skin-tone-3:"] = "\uD83E\uDDDD\uD83C\uDFFD\u200D♂️", + [":man_elf::skin-tone-4:"] = "\uD83E\uDDDD\uD83C\uDFFE\u200D♂️", + [":man_elf::skin-tone-5:"] = "\uD83E\uDDDD\uD83C\uDFFF\u200D♂️", + [":man_elf_dark_skin_tone:"] = "\uD83E\uDDDD\uD83C\uDFFF\u200D♂️", + [":man_elf_light_skin_tone:"] = "\uD83E\uDDDD\uD83C\uDFFB\u200D♂️", + [":man_elf_medium_dark_skin_tone:"] = "\uD83E\uDDDD\uD83C\uDFFE\u200D♂️", + [":man_elf_medium_light_skin_tone:"] = "\uD83E\uDDDD\uD83C\uDFFC\u200D♂️", + [":man_elf_medium_skin_tone:"] = "\uD83E\uDDDD\uD83C\uDFFD\u200D♂️", + [":man_elf_tone1:"] = "\uD83E\uDDDD\uD83C\uDFFB\u200D♂️", + [":man_elf_tone2:"] = "\uD83E\uDDDD\uD83C\uDFFC\u200D♂️", + [":man_elf_tone3:"] = "\uD83E\uDDDD\uD83C\uDFFD\u200D♂️", + [":man_elf_tone4:"] = "\uD83E\uDDDD\uD83C\uDFFE\u200D♂️", + [":man_elf_tone5:"] = "\uD83E\uDDDD\uD83C\uDFFF\u200D♂️", + [":man_facepalming:"] = "\uD83E\uDD26\u200D♂️", + [":man_facepalming::skin-tone-1:"] = "\uD83E\uDD26\uD83C\uDFFB\u200D♂️", + [":man_facepalming::skin-tone-2:"] = "\uD83E\uDD26\uD83C\uDFFC\u200D♂️", + [":man_facepalming::skin-tone-3:"] = "\uD83E\uDD26\uD83C\uDFFD\u200D♂️", + [":man_facepalming::skin-tone-4:"] = "\uD83E\uDD26\uD83C\uDFFE\u200D♂️", + [":man_facepalming::skin-tone-5:"] = "\uD83E\uDD26\uD83C\uDFFF\u200D♂️", + [":man_facepalming_dark_skin_tone:"] = "\uD83E\uDD26\uD83C\uDFFF\u200D♂️", + [":man_facepalming_light_skin_tone:"] = "\uD83E\uDD26\uD83C\uDFFB\u200D♂️", + [":man_facepalming_medium_dark_skin_tone:"] = "\uD83E\uDD26\uD83C\uDFFE\u200D♂️", + [":man_facepalming_medium_light_skin_tone:"] = "\uD83E\uDD26\uD83C\uDFFC\u200D♂️", + [":man_facepalming_medium_skin_tone:"] = "\uD83E\uDD26\uD83C\uDFFD\u200D♂️", + [":man_facepalming_tone1:"] = "\uD83E\uDD26\uD83C\uDFFB\u200D♂️", + [":man_facepalming_tone2:"] = "\uD83E\uDD26\uD83C\uDFFC\u200D♂️", + [":man_facepalming_tone3:"] = "\uD83E\uDD26\uD83C\uDFFD\u200D♂️", + [":man_facepalming_tone4:"] = "\uD83E\uDD26\uD83C\uDFFE\u200D♂️", + [":man_facepalming_tone5:"] = "\uD83E\uDD26\uD83C\uDFFF\u200D♂️", + [":man_factory_worker:"] = "\uD83D\uDC68\u200D\uD83C\uDFED", + [":man_factory_worker::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDFED", + [":man_factory_worker::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDFED", + [":man_factory_worker::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDFED", + [":man_factory_worker::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDFED", + [":man_factory_worker::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDFED", + [":man_factory_worker_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDFED", + [":man_factory_worker_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDFED", + [":man_factory_worker_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDFED", + [":man_factory_worker_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDFED", + [":man_factory_worker_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDFED", + [":man_factory_worker_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDFED", + [":man_factory_worker_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDFED", + [":man_factory_worker_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDFED", + [":man_factory_worker_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDFED", + [":man_factory_worker_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDFED", + [":man_fairy:"] = "\uD83E\uDDDA\u200D♂️", + [":man_fairy::skin-tone-1:"] = "\uD83E\uDDDA\uD83C\uDFFB\u200D♂️", + [":man_fairy::skin-tone-2:"] = "\uD83E\uDDDA\uD83C\uDFFC\u200D♂️", + [":man_fairy::skin-tone-3:"] = "\uD83E\uDDDA\uD83C\uDFFD\u200D♂️", + [":man_fairy::skin-tone-4:"] = "\uD83E\uDDDA\uD83C\uDFFE\u200D♂️", + [":man_fairy::skin-tone-5:"] = "\uD83E\uDDDA\uD83C\uDFFF\u200D♂️", + [":man_fairy_dark_skin_tone:"] = "\uD83E\uDDDA\uD83C\uDFFF\u200D♂️", + [":man_fairy_light_skin_tone:"] = "\uD83E\uDDDA\uD83C\uDFFB\u200D♂️", + [":man_fairy_medium_dark_skin_tone:"] = "\uD83E\uDDDA\uD83C\uDFFE\u200D♂️", + [":man_fairy_medium_light_skin_tone:"] = "\uD83E\uDDDA\uD83C\uDFFC\u200D♂️", + [":man_fairy_medium_skin_tone:"] = "\uD83E\uDDDA\uD83C\uDFFD\u200D♂️", + [":man_fairy_tone1:"] = "\uD83E\uDDDA\uD83C\uDFFB\u200D♂️", + [":man_fairy_tone2:"] = "\uD83E\uDDDA\uD83C\uDFFC\u200D♂️", + [":man_fairy_tone3:"] = "\uD83E\uDDDA\uD83C\uDFFD\u200D♂️", + [":man_fairy_tone4:"] = "\uD83E\uDDDA\uD83C\uDFFE\u200D♂️", + [":man_fairy_tone5:"] = "\uD83E\uDDDA\uD83C\uDFFF\u200D♂️", + [":man_farmer:"] = "\uD83D\uDC68\u200D\uD83C\uDF3E", + [":man_farmer::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDF3E", + [":man_farmer::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDF3E", + [":man_farmer::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDF3E", + [":man_farmer::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDF3E", + [":man_farmer::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDF3E", + [":man_farmer_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDF3E", + [":man_farmer_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDF3E", + [":man_farmer_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDF3E", + [":man_farmer_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDF3E", + [":man_farmer_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDF3E", + [":man_farmer_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDF3E", + [":man_farmer_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDF3E", + [":man_farmer_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDF3E", + [":man_farmer_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDF3E", + [":man_farmer_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDF3E", + [":man_firefighter:"] = "\uD83D\uDC68\u200D\uD83D\uDE92", + [":man_firefighter::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDE92", + [":man_firefighter::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDE92", + [":man_firefighter::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDE92", + [":man_firefighter::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDE92", + [":man_firefighter::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDE92", + [":man_firefighter_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDE92", + [":man_firefighter_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDE92", + [":man_firefighter_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDE92", + [":man_firefighter_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDE92", + [":man_firefighter_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDE92", + [":man_firefighter_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDE92", + [":man_firefighter_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDE92", + [":man_firefighter_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDE92", + [":man_firefighter_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDE92", + [":man_firefighter_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDE92", + [":man_frowning:"] = "\uD83D\uDE4D\u200D♂️", + [":man_frowning::skin-tone-1:"] = "\uD83D\uDE4D\uD83C\uDFFB\u200D♂️", + [":man_frowning::skin-tone-2:"] = "\uD83D\uDE4D\uD83C\uDFFC\u200D♂️", + [":man_frowning::skin-tone-3:"] = "\uD83D\uDE4D\uD83C\uDFFD\u200D♂️", + [":man_frowning::skin-tone-4:"] = "\uD83D\uDE4D\uD83C\uDFFE\u200D♂️", + [":man_frowning::skin-tone-5:"] = "\uD83D\uDE4D\uD83C\uDFFF\u200D♂️", + [":man_frowning_dark_skin_tone:"] = "\uD83D\uDE4D\uD83C\uDFFF\u200D♂️", + [":man_frowning_light_skin_tone:"] = "\uD83D\uDE4D\uD83C\uDFFB\u200D♂️", + [":man_frowning_medium_dark_skin_tone:"] = "\uD83D\uDE4D\uD83C\uDFFE\u200D♂️", + [":man_frowning_medium_light_skin_tone:"] = "\uD83D\uDE4D\uD83C\uDFFC\u200D♂️", + [":man_frowning_medium_skin_tone:"] = "\uD83D\uDE4D\uD83C\uDFFD\u200D♂️", + [":man_frowning_tone1:"] = "\uD83D\uDE4D\uD83C\uDFFB\u200D♂️", + [":man_frowning_tone2:"] = "\uD83D\uDE4D\uD83C\uDFFC\u200D♂️", + [":man_frowning_tone3:"] = "\uD83D\uDE4D\uD83C\uDFFD\u200D♂️", + [":man_frowning_tone4:"] = "\uD83D\uDE4D\uD83C\uDFFE\u200D♂️", + [":man_frowning_tone5:"] = "\uD83D\uDE4D\uD83C\uDFFF\u200D♂️", + [":man_genie:"] = "\uD83E\uDDDE\u200D♂️", + [":man_gesturing_no:"] = "\uD83D\uDE45\u200D♂️", + [":man_gesturing_no::skin-tone-1:"] = "\uD83D\uDE45\uD83C\uDFFB\u200D♂️", + [":man_gesturing_no::skin-tone-2:"] = "\uD83D\uDE45\uD83C\uDFFC\u200D♂️", + [":man_gesturing_no::skin-tone-3:"] = "\uD83D\uDE45\uD83C\uDFFD\u200D♂️", + [":man_gesturing_no::skin-tone-4:"] = "\uD83D\uDE45\uD83C\uDFFE\u200D♂️", + [":man_gesturing_no::skin-tone-5:"] = "\uD83D\uDE45\uD83C\uDFFF\u200D♂️", + [":man_gesturing_no_dark_skin_tone:"] = "\uD83D\uDE45\uD83C\uDFFF\u200D♂️", + [":man_gesturing_no_light_skin_tone:"] = "\uD83D\uDE45\uD83C\uDFFB\u200D♂️", + [":man_gesturing_no_medium_dark_skin_tone:"] = "\uD83D\uDE45\uD83C\uDFFE\u200D♂️", + [":man_gesturing_no_medium_light_skin_tone:"] = "\uD83D\uDE45\uD83C\uDFFC\u200D♂️", + [":man_gesturing_no_medium_skin_tone:"] = "\uD83D\uDE45\uD83C\uDFFD\u200D♂️", + [":man_gesturing_no_tone1:"] = "\uD83D\uDE45\uD83C\uDFFB\u200D♂️", + [":man_gesturing_no_tone2:"] = "\uD83D\uDE45\uD83C\uDFFC\u200D♂️", + [":man_gesturing_no_tone3:"] = "\uD83D\uDE45\uD83C\uDFFD\u200D♂️", + [":man_gesturing_no_tone4:"] = "\uD83D\uDE45\uD83C\uDFFE\u200D♂️", + [":man_gesturing_no_tone5:"] = "\uD83D\uDE45\uD83C\uDFFF\u200D♂️", + [":man_gesturing_ok:"] = "\uD83D\uDE46\u200D♂️", + [":man_gesturing_ok::skin-tone-1:"] = "\uD83D\uDE46\uD83C\uDFFB\u200D♂️", + [":man_gesturing_ok::skin-tone-2:"] = "\uD83D\uDE46\uD83C\uDFFC\u200D♂️", + [":man_gesturing_ok::skin-tone-3:"] = "\uD83D\uDE46\uD83C\uDFFD\u200D♂️", + [":man_gesturing_ok::skin-tone-4:"] = "\uD83D\uDE46\uD83C\uDFFE\u200D♂️", + [":man_gesturing_ok::skin-tone-5:"] = "\uD83D\uDE46\uD83C\uDFFF\u200D♂️", + [":man_gesturing_ok_dark_skin_tone:"] = "\uD83D\uDE46\uD83C\uDFFF\u200D♂️", + [":man_gesturing_ok_light_skin_tone:"] = "\uD83D\uDE46\uD83C\uDFFB\u200D♂️", + [":man_gesturing_ok_medium_dark_skin_tone:"] = "\uD83D\uDE46\uD83C\uDFFE\u200D♂️", + [":man_gesturing_ok_medium_light_skin_tone:"] = "\uD83D\uDE46\uD83C\uDFFC\u200D♂️", + [":man_gesturing_ok_medium_skin_tone:"] = "\uD83D\uDE46\uD83C\uDFFD\u200D♂️", + [":man_gesturing_ok_tone1:"] = "\uD83D\uDE46\uD83C\uDFFB\u200D♂️", + [":man_gesturing_ok_tone2:"] = "\uD83D\uDE46\uD83C\uDFFC\u200D♂️", + [":man_gesturing_ok_tone3:"] = "\uD83D\uDE46\uD83C\uDFFD\u200D♂️", + [":man_gesturing_ok_tone4:"] = "\uD83D\uDE46\uD83C\uDFFE\u200D♂️", + [":man_gesturing_ok_tone5:"] = "\uD83D\uDE46\uD83C\uDFFF\u200D♂️", + [":man_getting_face_massage:"] = "\uD83D\uDC86\u200D♂️", + [":man_getting_face_massage::skin-tone-1:"] = "\uD83D\uDC86\uD83C\uDFFB\u200D♂️", + [":man_getting_face_massage::skin-tone-2:"] = "\uD83D\uDC86\uD83C\uDFFC\u200D♂️", + [":man_getting_face_massage::skin-tone-3:"] = "\uD83D\uDC86\uD83C\uDFFD\u200D♂️", + [":man_getting_face_massage::skin-tone-4:"] = "\uD83D\uDC86\uD83C\uDFFE\u200D♂️", + [":man_getting_face_massage::skin-tone-5:"] = "\uD83D\uDC86\uD83C\uDFFF\u200D♂️", + [":man_getting_face_massage_dark_skin_tone:"] = "\uD83D\uDC86\uD83C\uDFFF\u200D♂️", + [":man_getting_face_massage_light_skin_tone:"] = "\uD83D\uDC86\uD83C\uDFFB\u200D♂️", + [":man_getting_face_massage_medium_dark_skin_tone:"] = "\uD83D\uDC86\uD83C\uDFFE\u200D♂️", + [":man_getting_face_massage_medium_light_skin_tone:"] = "\uD83D\uDC86\uD83C\uDFFC\u200D♂️", + [":man_getting_face_massage_medium_skin_tone:"] = "\uD83D\uDC86\uD83C\uDFFD\u200D♂️", + [":man_getting_face_massage_tone1:"] = "\uD83D\uDC86\uD83C\uDFFB\u200D♂️", + [":man_getting_face_massage_tone2:"] = "\uD83D\uDC86\uD83C\uDFFC\u200D♂️", + [":man_getting_face_massage_tone3:"] = "\uD83D\uDC86\uD83C\uDFFD\u200D♂️", + [":man_getting_face_massage_tone4:"] = "\uD83D\uDC86\uD83C\uDFFE\u200D♂️", + [":man_getting_face_massage_tone5:"] = "\uD83D\uDC86\uD83C\uDFFF\u200D♂️", + [":man_getting_haircut:"] = "\uD83D\uDC87\u200D♂️", + [":man_getting_haircut::skin-tone-1:"] = "\uD83D\uDC87\uD83C\uDFFB\u200D♂️", + [":man_getting_haircut::skin-tone-2:"] = "\uD83D\uDC87\uD83C\uDFFC\u200D♂️", + [":man_getting_haircut::skin-tone-3:"] = "\uD83D\uDC87\uD83C\uDFFD\u200D♂️", + [":man_getting_haircut::skin-tone-4:"] = "\uD83D\uDC87\uD83C\uDFFE\u200D♂️", + [":man_getting_haircut::skin-tone-5:"] = "\uD83D\uDC87\uD83C\uDFFF\u200D♂️", + [":man_getting_haircut_dark_skin_tone:"] = "\uD83D\uDC87\uD83C\uDFFF\u200D♂️", + [":man_getting_haircut_light_skin_tone:"] = "\uD83D\uDC87\uD83C\uDFFB\u200D♂️", + [":man_getting_haircut_medium_dark_skin_tone:"] = "\uD83D\uDC87\uD83C\uDFFE\u200D♂️", + [":man_getting_haircut_medium_light_skin_tone:"] = "\uD83D\uDC87\uD83C\uDFFC\u200D♂️", + [":man_getting_haircut_medium_skin_tone:"] = "\uD83D\uDC87\uD83C\uDFFD\u200D♂️", + [":man_getting_haircut_tone1:"] = "\uD83D\uDC87\uD83C\uDFFB\u200D♂️", + [":man_getting_haircut_tone2:"] = "\uD83D\uDC87\uD83C\uDFFC\u200D♂️", + [":man_getting_haircut_tone3:"] = "\uD83D\uDC87\uD83C\uDFFD\u200D♂️", + [":man_getting_haircut_tone4:"] = "\uD83D\uDC87\uD83C\uDFFE\u200D♂️", + [":man_getting_haircut_tone5:"] = "\uD83D\uDC87\uD83C\uDFFF\u200D♂️", + [":man_golfing:"] = "\uD83C\uDFCC️\u200D♂️", + [":man_golfing::skin-tone-1:"] = "\uD83C\uDFCC\uD83C\uDFFB\u200D♂️", + [":man_golfing::skin-tone-2:"] = "\uD83C\uDFCC\uD83C\uDFFC\u200D♂️", + [":man_golfing::skin-tone-3:"] = "\uD83C\uDFCC\uD83C\uDFFD\u200D♂️", + [":man_golfing::skin-tone-4:"] = "\uD83C\uDFCC\uD83C\uDFFE\u200D♂️", + [":man_golfing::skin-tone-5:"] = "\uD83C\uDFCC\uD83C\uDFFF\u200D♂️", + [":man_golfing_dark_skin_tone:"] = "\uD83C\uDFCC\uD83C\uDFFF\u200D♂️", + [":man_golfing_light_skin_tone:"] = "\uD83C\uDFCC\uD83C\uDFFB\u200D♂️", + [":man_golfing_medium_dark_skin_tone:"] = "\uD83C\uDFCC\uD83C\uDFFE\u200D♂️", + [":man_golfing_medium_light_skin_tone:"] = "\uD83C\uDFCC\uD83C\uDFFC\u200D♂️", + [":man_golfing_medium_skin_tone:"] = "\uD83C\uDFCC\uD83C\uDFFD\u200D♂️", + [":man_golfing_tone1:"] = "\uD83C\uDFCC\uD83C\uDFFB\u200D♂️", + [":man_golfing_tone2:"] = "\uD83C\uDFCC\uD83C\uDFFC\u200D♂️", + [":man_golfing_tone3:"] = "\uD83C\uDFCC\uD83C\uDFFD\u200D♂️", + [":man_golfing_tone4:"] = "\uD83C\uDFCC\uD83C\uDFFE\u200D♂️", + [":man_golfing_tone5:"] = "\uD83C\uDFCC\uD83C\uDFFF\u200D♂️", + [":man_guard:"] = "\uD83D\uDC82\u200D♂️", + [":man_guard::skin-tone-1:"] = "\uD83D\uDC82\uD83C\uDFFB\u200D♂️", + [":man_guard::skin-tone-2:"] = "\uD83D\uDC82\uD83C\uDFFC\u200D♂️", + [":man_guard::skin-tone-3:"] = "\uD83D\uDC82\uD83C\uDFFD\u200D♂️", + [":man_guard::skin-tone-4:"] = "\uD83D\uDC82\uD83C\uDFFE\u200D♂️", + [":man_guard::skin-tone-5:"] = "\uD83D\uDC82\uD83C\uDFFF\u200D♂️", + [":man_guard_dark_skin_tone:"] = "\uD83D\uDC82\uD83C\uDFFF\u200D♂️", + [":man_guard_light_skin_tone:"] = "\uD83D\uDC82\uD83C\uDFFB\u200D♂️", + [":man_guard_medium_dark_skin_tone:"] = "\uD83D\uDC82\uD83C\uDFFE\u200D♂️", + [":man_guard_medium_light_skin_tone:"] = "\uD83D\uDC82\uD83C\uDFFC\u200D♂️", + [":man_guard_medium_skin_tone:"] = "\uD83D\uDC82\uD83C\uDFFD\u200D♂️", + [":man_guard_tone1:"] = "\uD83D\uDC82\uD83C\uDFFB\u200D♂️", + [":man_guard_tone2:"] = "\uD83D\uDC82\uD83C\uDFFC\u200D♂️", + [":man_guard_tone3:"] = "\uD83D\uDC82\uD83C\uDFFD\u200D♂️", + [":man_guard_tone4:"] = "\uD83D\uDC82\uD83C\uDFFE\u200D♂️", + [":man_guard_tone5:"] = "\uD83D\uDC82\uD83C\uDFFF\u200D♂️", + [":man_health_worker:"] = "\uD83D\uDC68\u200D⚕️", + [":man_health_worker::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D⚕️", + [":man_health_worker::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D⚕️", + [":man_health_worker::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D⚕️", + [":man_health_worker::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D⚕️", + [":man_health_worker::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D⚕️", + [":man_health_worker_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D⚕️", + [":man_health_worker_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D⚕️", + [":man_health_worker_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D⚕️", + [":man_health_worker_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D⚕️", + [":man_health_worker_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D⚕️", + [":man_health_worker_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D⚕️", + [":man_health_worker_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D⚕️", + [":man_health_worker_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D⚕️", + [":man_health_worker_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D⚕️", + [":man_health_worker_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D⚕️", + [":man_in_business_suit_levitating:"] = "\uD83D\uDD74️", + [":man_in_business_suit_levitating::skin-tone-1:"] = "\uD83D\uDD74\uD83C\uDFFB", + [":man_in_business_suit_levitating::skin-tone-2:"] = "\uD83D\uDD74\uD83C\uDFFC", + [":man_in_business_suit_levitating::skin-tone-3:"] = "\uD83D\uDD74\uD83C\uDFFD", + [":man_in_business_suit_levitating::skin-tone-4:"] = "\uD83D\uDD74\uD83C\uDFFE", + [":man_in_business_suit_levitating::skin-tone-5:"] = "\uD83D\uDD74\uD83C\uDFFF", + [":man_in_business_suit_levitating_dark_skin_tone:"] = "\uD83D\uDD74\uD83C\uDFFF", + [":man_in_business_suit_levitating_light_skin_tone:"] = "\uD83D\uDD74\uD83C\uDFFB", + [":man_in_business_suit_levitating_medium_dark_skin_tone:"] = "\uD83D\uDD74\uD83C\uDFFE", + [":man_in_business_suit_levitating_medium_light_skin_tone:"] = "\uD83D\uDD74\uD83C\uDFFC", + [":man_in_business_suit_levitating_medium_skin_tone:"] = "\uD83D\uDD74\uD83C\uDFFD", + [":man_in_business_suit_levitating_tone1:"] = "\uD83D\uDD74\uD83C\uDFFB", + [":man_in_business_suit_levitating_tone2:"] = "\uD83D\uDD74\uD83C\uDFFC", + [":man_in_business_suit_levitating_tone3:"] = "\uD83D\uDD74\uD83C\uDFFD", + [":man_in_business_suit_levitating_tone4:"] = "\uD83D\uDD74\uD83C\uDFFE", + [":man_in_business_suit_levitating_tone5:"] = "\uD83D\uDD74\uD83C\uDFFF", + [":man_in_lotus_position:"] = "\uD83E\uDDD8\u200D♂️", + [":man_in_lotus_position::skin-tone-1:"] = "\uD83E\uDDD8\uD83C\uDFFB\u200D♂️", + [":man_in_lotus_position::skin-tone-2:"] = "\uD83E\uDDD8\uD83C\uDFFC\u200D♂️", + [":man_in_lotus_position::skin-tone-3:"] = "\uD83E\uDDD8\uD83C\uDFFD\u200D♂️", + [":man_in_lotus_position::skin-tone-4:"] = "\uD83E\uDDD8\uD83C\uDFFE\u200D♂️", + [":man_in_lotus_position::skin-tone-5:"] = "\uD83E\uDDD8\uD83C\uDFFF\u200D♂️", + [":man_in_lotus_position_dark_skin_tone:"] = "\uD83E\uDDD8\uD83C\uDFFF\u200D♂️", + [":man_in_lotus_position_light_skin_tone:"] = "\uD83E\uDDD8\uD83C\uDFFB\u200D♂️", + [":man_in_lotus_position_medium_dark_skin_tone:"] = "\uD83E\uDDD8\uD83C\uDFFE\u200D♂️", + [":man_in_lotus_position_medium_light_skin_tone:"] = "\uD83E\uDDD8\uD83C\uDFFC\u200D♂️", + [":man_in_lotus_position_medium_skin_tone:"] = "\uD83E\uDDD8\uD83C\uDFFD\u200D♂️", + [":man_in_lotus_position_tone1:"] = "\uD83E\uDDD8\uD83C\uDFFB\u200D♂️", + [":man_in_lotus_position_tone2:"] = "\uD83E\uDDD8\uD83C\uDFFC\u200D♂️", + [":man_in_lotus_position_tone3:"] = "\uD83E\uDDD8\uD83C\uDFFD\u200D♂️", + [":man_in_lotus_position_tone4:"] = "\uD83E\uDDD8\uD83C\uDFFE\u200D♂️", + [":man_in_lotus_position_tone5:"] = "\uD83E\uDDD8\uD83C\uDFFF\u200D♂️", + [":man_in_manual_wheelchair:"] = "\uD83D\uDC68\u200D\uD83E\uDDBD", + [":man_in_manual_wheelchair::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDBD", + [":man_in_manual_wheelchair::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDBD", + [":man_in_manual_wheelchair::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDBD", + [":man_in_manual_wheelchair::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDBD", + [":man_in_manual_wheelchair::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDBD", + [":man_in_manual_wheelchair_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDBD", + [":man_in_manual_wheelchair_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDBD", + [":man_in_manual_wheelchair_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDBD", + [":man_in_manual_wheelchair_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDBD", + [":man_in_manual_wheelchair_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDBD", + [":man_in_manual_wheelchair_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDBD", + [":man_in_manual_wheelchair_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDBD", + [":man_in_manual_wheelchair_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDBD", + [":man_in_manual_wheelchair_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDBD", + [":man_in_manual_wheelchair_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDBD", + [":man_in_motorized_wheelchair:"] = "\uD83D\uDC68\u200D\uD83E\uDDBC", + [":man_in_motorized_wheelchair::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDBC", + [":man_in_motorized_wheelchair::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDBC", + [":man_in_motorized_wheelchair::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDBC", + [":man_in_motorized_wheelchair::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDBC", + [":man_in_motorized_wheelchair::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDBC", + [":man_in_motorized_wheelchair_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDBC", + [":man_in_motorized_wheelchair_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDBC", + [":man_in_motorized_wheelchair_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDBC", + [":man_in_motorized_wheelchair_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDBC", + [":man_in_motorized_wheelchair_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDBC", + [":man_in_motorized_wheelchair_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDBC", + [":man_in_motorized_wheelchair_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDBC", + [":man_in_motorized_wheelchair_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDBC", + [":man_in_motorized_wheelchair_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDBC", + [":man_in_motorized_wheelchair_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDBC", + [":man_in_steamy_room:"] = "\uD83E\uDDD6\u200D♂️", + [":man_in_steamy_room::skin-tone-1:"] = "\uD83E\uDDD6\uD83C\uDFFB\u200D♂️", + [":man_in_steamy_room::skin-tone-2:"] = "\uD83E\uDDD6\uD83C\uDFFC\u200D♂️", + [":man_in_steamy_room::skin-tone-3:"] = "\uD83E\uDDD6\uD83C\uDFFD\u200D♂️", + [":man_in_steamy_room::skin-tone-4:"] = "\uD83E\uDDD6\uD83C\uDFFE\u200D♂️", + [":man_in_steamy_room::skin-tone-5:"] = "\uD83E\uDDD6\uD83C\uDFFF\u200D♂️", + [":man_in_steamy_room_dark_skin_tone:"] = "\uD83E\uDDD6\uD83C\uDFFF\u200D♂️", + [":man_in_steamy_room_light_skin_tone:"] = "\uD83E\uDDD6\uD83C\uDFFB\u200D♂️", + [":man_in_steamy_room_medium_dark_skin_tone:"] = "\uD83E\uDDD6\uD83C\uDFFE\u200D♂️", + [":man_in_steamy_room_medium_light_skin_tone:"] = "\uD83E\uDDD6\uD83C\uDFFC\u200D♂️", + [":man_in_steamy_room_medium_skin_tone:"] = "\uD83E\uDDD6\uD83C\uDFFD\u200D♂️", + [":man_in_steamy_room_tone1:"] = "\uD83E\uDDD6\uD83C\uDFFB\u200D♂️", + [":man_in_steamy_room_tone2:"] = "\uD83E\uDDD6\uD83C\uDFFC\u200D♂️", + [":man_in_steamy_room_tone3:"] = "\uD83E\uDDD6\uD83C\uDFFD\u200D♂️", + [":man_in_steamy_room_tone4:"] = "\uD83E\uDDD6\uD83C\uDFFE\u200D♂️", + [":man_in_steamy_room_tone5:"] = "\uD83E\uDDD6\uD83C\uDFFF\u200D♂️", + [":man_in_tuxedo:"] = "\uD83E\uDD35", + [":man_in_tuxedo::skin-tone-1:"] = "\uD83E\uDD35\uD83C\uDFFB", + [":man_in_tuxedo::skin-tone-2:"] = "\uD83E\uDD35\uD83C\uDFFC", + [":man_in_tuxedo::skin-tone-3:"] = "\uD83E\uDD35\uD83C\uDFFD", + [":man_in_tuxedo::skin-tone-4:"] = "\uD83E\uDD35\uD83C\uDFFE", + [":man_in_tuxedo::skin-tone-5:"] = "\uD83E\uDD35\uD83C\uDFFF", + [":man_in_tuxedo_tone1:"] = "\uD83E\uDD35\uD83C\uDFFB", + [":man_in_tuxedo_tone2:"] = "\uD83E\uDD35\uD83C\uDFFC", + [":man_in_tuxedo_tone3:"] = "\uD83E\uDD35\uD83C\uDFFD", + [":man_in_tuxedo_tone4:"] = "\uD83E\uDD35\uD83C\uDFFE", + [":man_in_tuxedo_tone5:"] = "\uD83E\uDD35\uD83C\uDFFF", + [":man_judge:"] = "\uD83D\uDC68\u200D⚖️", + [":man_judge::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D⚖️", + [":man_judge::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D⚖️", + [":man_judge::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D⚖️", + [":man_judge::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D⚖️", + [":man_judge::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D⚖️", + [":man_judge_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D⚖️", + [":man_judge_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D⚖️", + [":man_judge_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D⚖️", + [":man_judge_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D⚖️", + [":man_judge_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D⚖️", + [":man_judge_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D⚖️", + [":man_judge_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D⚖️", + [":man_judge_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D⚖️", + [":man_judge_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D⚖️", + [":man_judge_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D⚖️", + [":man_juggling:"] = "\uD83E\uDD39\u200D♂️", + [":man_juggling::skin-tone-1:"] = "\uD83E\uDD39\uD83C\uDFFB\u200D♂️", + [":man_juggling::skin-tone-2:"] = "\uD83E\uDD39\uD83C\uDFFC\u200D♂️", + [":man_juggling::skin-tone-3:"] = "\uD83E\uDD39\uD83C\uDFFD\u200D♂️", + [":man_juggling::skin-tone-4:"] = "\uD83E\uDD39\uD83C\uDFFE\u200D♂️", + [":man_juggling::skin-tone-5:"] = "\uD83E\uDD39\uD83C\uDFFF\u200D♂️", + [":man_juggling_dark_skin_tone:"] = "\uD83E\uDD39\uD83C\uDFFF\u200D♂️", + [":man_juggling_light_skin_tone:"] = "\uD83E\uDD39\uD83C\uDFFB\u200D♂️", + [":man_juggling_medium_dark_skin_tone:"] = "\uD83E\uDD39\uD83C\uDFFE\u200D♂️", + [":man_juggling_medium_light_skin_tone:"] = "\uD83E\uDD39\uD83C\uDFFC\u200D♂️", + [":man_juggling_medium_skin_tone:"] = "\uD83E\uDD39\uD83C\uDFFD\u200D♂️", + [":man_juggling_tone1:"] = "\uD83E\uDD39\uD83C\uDFFB\u200D♂️", + [":man_juggling_tone2:"] = "\uD83E\uDD39\uD83C\uDFFC\u200D♂️", + [":man_juggling_tone3:"] = "\uD83E\uDD39\uD83C\uDFFD\u200D♂️", + [":man_juggling_tone4:"] = "\uD83E\uDD39\uD83C\uDFFE\u200D♂️", + [":man_juggling_tone5:"] = "\uD83E\uDD39\uD83C\uDFFF\u200D♂️", + [":man_kneeling:"] = "\uD83E\uDDCE\u200D♂️", + [":man_kneeling::skin-tone-1:"] = "\uD83E\uDDCE\uD83C\uDFFB\u200D♂️", + [":man_kneeling::skin-tone-2:"] = "\uD83E\uDDCE\uD83C\uDFFC\u200D♂️", + [":man_kneeling::skin-tone-3:"] = "\uD83E\uDDCE\uD83C\uDFFD\u200D♂️", + [":man_kneeling::skin-tone-4:"] = "\uD83E\uDDCE\uD83C\uDFFE\u200D♂️", + [":man_kneeling::skin-tone-5:"] = "\uD83E\uDDCE\uD83C\uDFFF\u200D♂️", + [":man_kneeling_dark_skin_tone:"] = "\uD83E\uDDCE\uD83C\uDFFF\u200D♂️", + [":man_kneeling_light_skin_tone:"] = "\uD83E\uDDCE\uD83C\uDFFB\u200D♂️", + [":man_kneeling_medium_dark_skin_tone:"] = "\uD83E\uDDCE\uD83C\uDFFE\u200D♂️", + [":man_kneeling_medium_light_skin_tone:"] = "\uD83E\uDDCE\uD83C\uDFFC\u200D♂️", + [":man_kneeling_medium_skin_tone:"] = "\uD83E\uDDCE\uD83C\uDFFD\u200D♂️", + [":man_kneeling_tone1:"] = "\uD83E\uDDCE\uD83C\uDFFB\u200D♂️", + [":man_kneeling_tone2:"] = "\uD83E\uDDCE\uD83C\uDFFC\u200D♂️", + [":man_kneeling_tone3:"] = "\uD83E\uDDCE\uD83C\uDFFD\u200D♂️", + [":man_kneeling_tone4:"] = "\uD83E\uDDCE\uD83C\uDFFE\u200D♂️", + [":man_kneeling_tone5:"] = "\uD83E\uDDCE\uD83C\uDFFF\u200D♂️", + [":man_lifting_weights:"] = "\uD83C\uDFCB️\u200D♂️", + [":man_lifting_weights::skin-tone-1:"] = "\uD83C\uDFCB\uD83C\uDFFB\u200D♂️", + [":man_lifting_weights::skin-tone-2:"] = "\uD83C\uDFCB\uD83C\uDFFC\u200D♂️", + [":man_lifting_weights::skin-tone-3:"] = "\uD83C\uDFCB\uD83C\uDFFD\u200D♂️", + [":man_lifting_weights::skin-tone-4:"] = "\uD83C\uDFCB\uD83C\uDFFE\u200D♂️", + [":man_lifting_weights::skin-tone-5:"] = "\uD83C\uDFCB\uD83C\uDFFF\u200D♂️", + [":man_lifting_weights_dark_skin_tone:"] = "\uD83C\uDFCB\uD83C\uDFFF\u200D♂️", + [":man_lifting_weights_light_skin_tone:"] = "\uD83C\uDFCB\uD83C\uDFFB\u200D♂️", + [":man_lifting_weights_medium_dark_skin_tone:"] = "\uD83C\uDFCB\uD83C\uDFFE\u200D♂️", + [":man_lifting_weights_medium_light_skin_tone:"] = "\uD83C\uDFCB\uD83C\uDFFC\u200D♂️", + [":man_lifting_weights_medium_skin_tone:"] = "\uD83C\uDFCB\uD83C\uDFFD\u200D♂️", + [":man_lifting_weights_tone1:"] = "\uD83C\uDFCB\uD83C\uDFFB\u200D♂️", + [":man_lifting_weights_tone2:"] = "\uD83C\uDFCB\uD83C\uDFFC\u200D♂️", + [":man_lifting_weights_tone3:"] = "\uD83C\uDFCB\uD83C\uDFFD\u200D♂️", + [":man_lifting_weights_tone4:"] = "\uD83C\uDFCB\uD83C\uDFFE\u200D♂️", + [":man_lifting_weights_tone5:"] = "\uD83C\uDFCB\uD83C\uDFFF\u200D♂️", + [":man_mage:"] = "\uD83E\uDDD9\u200D♂️", + [":man_mage::skin-tone-1:"] = "\uD83E\uDDD9\uD83C\uDFFB\u200D♂️", + [":man_mage::skin-tone-2:"] = "\uD83E\uDDD9\uD83C\uDFFC\u200D♂️", + [":man_mage::skin-tone-3:"] = "\uD83E\uDDD9\uD83C\uDFFD\u200D♂️", + [":man_mage::skin-tone-4:"] = "\uD83E\uDDD9\uD83C\uDFFE\u200D♂️", + [":man_mage::skin-tone-5:"] = "\uD83E\uDDD9\uD83C\uDFFF\u200D♂️", + [":man_mage_dark_skin_tone:"] = "\uD83E\uDDD9\uD83C\uDFFF\u200D♂️", + [":man_mage_light_skin_tone:"] = "\uD83E\uDDD9\uD83C\uDFFB\u200D♂️", + [":man_mage_medium_dark_skin_tone:"] = "\uD83E\uDDD9\uD83C\uDFFE\u200D♂️", + [":man_mage_medium_light_skin_tone:"] = "\uD83E\uDDD9\uD83C\uDFFC\u200D♂️", + [":man_mage_medium_skin_tone:"] = "\uD83E\uDDD9\uD83C\uDFFD\u200D♂️", + [":man_mage_tone1:"] = "\uD83E\uDDD9\uD83C\uDFFB\u200D♂️", + [":man_mage_tone2:"] = "\uD83E\uDDD9\uD83C\uDFFC\u200D♂️", + [":man_mage_tone3:"] = "\uD83E\uDDD9\uD83C\uDFFD\u200D♂️", + [":man_mage_tone4:"] = "\uD83E\uDDD9\uD83C\uDFFE\u200D♂️", + [":man_mage_tone5:"] = "\uD83E\uDDD9\uD83C\uDFFF\u200D♂️", + [":man_mechanic:"] = "\uD83D\uDC68\u200D\uD83D\uDD27", + [":man_mechanic::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDD27", + [":man_mechanic::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDD27", + [":man_mechanic::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDD27", + [":man_mechanic::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDD27", + [":man_mechanic::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDD27", + [":man_mechanic_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDD27", + [":man_mechanic_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDD27", + [":man_mechanic_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDD27", + [":man_mechanic_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDD27", + [":man_mechanic_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDD27", + [":man_mechanic_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDD27", + [":man_mechanic_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDD27", + [":man_mechanic_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDD27", + [":man_mechanic_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDD27", + [":man_mechanic_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDD27", + [":man_mountain_biking:"] = "\uD83D\uDEB5\u200D♂️", + [":man_mountain_biking::skin-tone-1:"] = "\uD83D\uDEB5\uD83C\uDFFB\u200D♂️", + [":man_mountain_biking::skin-tone-2:"] = "\uD83D\uDEB5\uD83C\uDFFC\u200D♂️", + [":man_mountain_biking::skin-tone-3:"] = "\uD83D\uDEB5\uD83C\uDFFD\u200D♂️", + [":man_mountain_biking::skin-tone-4:"] = "\uD83D\uDEB5\uD83C\uDFFE\u200D♂️", + [":man_mountain_biking::skin-tone-5:"] = "\uD83D\uDEB5\uD83C\uDFFF\u200D♂️", + [":man_mountain_biking_dark_skin_tone:"] = "\uD83D\uDEB5\uD83C\uDFFF\u200D♂️", + [":man_mountain_biking_light_skin_tone:"] = "\uD83D\uDEB5\uD83C\uDFFB\u200D♂️", + [":man_mountain_biking_medium_dark_skin_tone:"] = "\uD83D\uDEB5\uD83C\uDFFE\u200D♂️", + [":man_mountain_biking_medium_light_skin_tone:"] = "\uD83D\uDEB5\uD83C\uDFFC\u200D♂️", + [":man_mountain_biking_medium_skin_tone:"] = "\uD83D\uDEB5\uD83C\uDFFD\u200D♂️", + [":man_mountain_biking_tone1:"] = "\uD83D\uDEB5\uD83C\uDFFB\u200D♂️", + [":man_mountain_biking_tone2:"] = "\uD83D\uDEB5\uD83C\uDFFC\u200D♂️", + [":man_mountain_biking_tone3:"] = "\uD83D\uDEB5\uD83C\uDFFD\u200D♂️", + [":man_mountain_biking_tone4:"] = "\uD83D\uDEB5\uD83C\uDFFE\u200D♂️", + [":man_mountain_biking_tone5:"] = "\uD83D\uDEB5\uD83C\uDFFF\u200D♂️", + [":man_office_worker:"] = "\uD83D\uDC68\u200D\uD83D\uDCBC", + [":man_office_worker::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDCBC", + [":man_office_worker::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDCBC", + [":man_office_worker::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDCBC", + [":man_office_worker::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDCBC", + [":man_office_worker::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDCBC", + [":man_office_worker_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDCBC", + [":man_office_worker_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDCBC", + [":man_office_worker_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDCBC", + [":man_office_worker_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDCBC", + [":man_office_worker_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDCBC", + [":man_office_worker_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDCBC", + [":man_office_worker_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDCBC", + [":man_office_worker_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDCBC", + [":man_office_worker_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDCBC", + [":man_office_worker_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDCBC", + [":man_pilot:"] = "\uD83D\uDC68\u200D✈️", + [":man_pilot::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D✈️", + [":man_pilot::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D✈️", + [":man_pilot::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D✈️", + [":man_pilot::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D✈️", + [":man_pilot::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D✈️", + [":man_pilot_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D✈️", + [":man_pilot_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D✈️", + [":man_pilot_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D✈️", + [":man_pilot_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D✈️", + [":man_pilot_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D✈️", + [":man_pilot_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D✈️", + [":man_pilot_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D✈️", + [":man_pilot_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D✈️", + [":man_pilot_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D✈️", + [":man_pilot_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D✈️", + [":man_playing_handball:"] = "\uD83E\uDD3E\u200D♂️", + [":man_playing_handball::skin-tone-1:"] = "\uD83E\uDD3E\uD83C\uDFFB\u200D♂️", + [":man_playing_handball::skin-tone-2:"] = "\uD83E\uDD3E\uD83C\uDFFC\u200D♂️", + [":man_playing_handball::skin-tone-3:"] = "\uD83E\uDD3E\uD83C\uDFFD\u200D♂️", + [":man_playing_handball::skin-tone-4:"] = "\uD83E\uDD3E\uD83C\uDFFE\u200D♂️", + [":man_playing_handball::skin-tone-5:"] = "\uD83E\uDD3E\uD83C\uDFFF\u200D♂️", + [":man_playing_handball_dark_skin_tone:"] = "\uD83E\uDD3E\uD83C\uDFFF\u200D♂️", + [":man_playing_handball_light_skin_tone:"] = "\uD83E\uDD3E\uD83C\uDFFB\u200D♂️", + [":man_playing_handball_medium_dark_skin_tone:"] = "\uD83E\uDD3E\uD83C\uDFFE\u200D♂️", + [":man_playing_handball_medium_light_skin_tone:"] = "\uD83E\uDD3E\uD83C\uDFFC\u200D♂️", + [":man_playing_handball_medium_skin_tone:"] = "\uD83E\uDD3E\uD83C\uDFFD\u200D♂️", + [":man_playing_handball_tone1:"] = "\uD83E\uDD3E\uD83C\uDFFB\u200D♂️", + [":man_playing_handball_tone2:"] = "\uD83E\uDD3E\uD83C\uDFFC\u200D♂️", + [":man_playing_handball_tone3:"] = "\uD83E\uDD3E\uD83C\uDFFD\u200D♂️", + [":man_playing_handball_tone4:"] = "\uD83E\uDD3E\uD83C\uDFFE\u200D♂️", + [":man_playing_handball_tone5:"] = "\uD83E\uDD3E\uD83C\uDFFF\u200D♂️", + [":man_playing_water_polo:"] = "\uD83E\uDD3D\u200D♂️", + [":man_playing_water_polo::skin-tone-1:"] = "\uD83E\uDD3D\uD83C\uDFFB\u200D♂️", + [":man_playing_water_polo::skin-tone-2:"] = "\uD83E\uDD3D\uD83C\uDFFC\u200D♂️", + [":man_playing_water_polo::skin-tone-3:"] = "\uD83E\uDD3D\uD83C\uDFFD\u200D♂️", + [":man_playing_water_polo::skin-tone-4:"] = "\uD83E\uDD3D\uD83C\uDFFE\u200D♂️", + [":man_playing_water_polo::skin-tone-5:"] = "\uD83E\uDD3D\uD83C\uDFFF\u200D♂️", + [":man_playing_water_polo_dark_skin_tone:"] = "\uD83E\uDD3D\uD83C\uDFFF\u200D♂️", + [":man_playing_water_polo_light_skin_tone:"] = "\uD83E\uDD3D\uD83C\uDFFB\u200D♂️", + [":man_playing_water_polo_medium_dark_skin_tone:"] = "\uD83E\uDD3D\uD83C\uDFFE\u200D♂️", + [":man_playing_water_polo_medium_light_skin_tone:"] = "\uD83E\uDD3D\uD83C\uDFFC\u200D♂️", + [":man_playing_water_polo_medium_skin_tone:"] = "\uD83E\uDD3D\uD83C\uDFFD\u200D♂️", + [":man_playing_water_polo_tone1:"] = "\uD83E\uDD3D\uD83C\uDFFB\u200D♂️", + [":man_playing_water_polo_tone2:"] = "\uD83E\uDD3D\uD83C\uDFFC\u200D♂️", + [":man_playing_water_polo_tone3:"] = "\uD83E\uDD3D\uD83C\uDFFD\u200D♂️", + [":man_playing_water_polo_tone4:"] = "\uD83E\uDD3D\uD83C\uDFFE\u200D♂️", + [":man_playing_water_polo_tone5:"] = "\uD83E\uDD3D\uD83C\uDFFF\u200D♂️", + [":man_police_officer:"] = "\uD83D\uDC6E\u200D♂️", + [":man_police_officer::skin-tone-1:"] = "\uD83D\uDC6E\uD83C\uDFFB\u200D♂️", + [":man_police_officer::skin-tone-2:"] = "\uD83D\uDC6E\uD83C\uDFFC\u200D♂️", + [":man_police_officer::skin-tone-3:"] = "\uD83D\uDC6E\uD83C\uDFFD\u200D♂️", + [":man_police_officer::skin-tone-4:"] = "\uD83D\uDC6E\uD83C\uDFFE\u200D♂️", + [":man_police_officer::skin-tone-5:"] = "\uD83D\uDC6E\uD83C\uDFFF\u200D♂️", + [":man_police_officer_dark_skin_tone:"] = "\uD83D\uDC6E\uD83C\uDFFF\u200D♂️", + [":man_police_officer_light_skin_tone:"] = "\uD83D\uDC6E\uD83C\uDFFB\u200D♂️", + [":man_police_officer_medium_dark_skin_tone:"] = "\uD83D\uDC6E\uD83C\uDFFE\u200D♂️", + [":man_police_officer_medium_light_skin_tone:"] = "\uD83D\uDC6E\uD83C\uDFFC\u200D♂️", + [":man_police_officer_medium_skin_tone:"] = "\uD83D\uDC6E\uD83C\uDFFD\u200D♂️", + [":man_police_officer_tone1:"] = "\uD83D\uDC6E\uD83C\uDFFB\u200D♂️", + [":man_police_officer_tone2:"] = "\uD83D\uDC6E\uD83C\uDFFC\u200D♂️", + [":man_police_officer_tone3:"] = "\uD83D\uDC6E\uD83C\uDFFD\u200D♂️", + [":man_police_officer_tone4:"] = "\uD83D\uDC6E\uD83C\uDFFE\u200D♂️", + [":man_police_officer_tone5:"] = "\uD83D\uDC6E\uD83C\uDFFF\u200D♂️", + [":man_pouting:"] = "\uD83D\uDE4E\u200D♂️", + [":man_pouting::skin-tone-1:"] = "\uD83D\uDE4E\uD83C\uDFFB\u200D♂️", + [":man_pouting::skin-tone-2:"] = "\uD83D\uDE4E\uD83C\uDFFC\u200D♂️", + [":man_pouting::skin-tone-3:"] = "\uD83D\uDE4E\uD83C\uDFFD\u200D♂️", + [":man_pouting::skin-tone-4:"] = "\uD83D\uDE4E\uD83C\uDFFE\u200D♂️", + [":man_pouting::skin-tone-5:"] = "\uD83D\uDE4E\uD83C\uDFFF\u200D♂️", + [":man_pouting_dark_skin_tone:"] = "\uD83D\uDE4E\uD83C\uDFFF\u200D♂️", + [":man_pouting_light_skin_tone:"] = "\uD83D\uDE4E\uD83C\uDFFB\u200D♂️", + [":man_pouting_medium_dark_skin_tone:"] = "\uD83D\uDE4E\uD83C\uDFFE\u200D♂️", + [":man_pouting_medium_light_skin_tone:"] = "\uD83D\uDE4E\uD83C\uDFFC\u200D♂️", + [":man_pouting_medium_skin_tone:"] = "\uD83D\uDE4E\uD83C\uDFFD\u200D♂️", + [":man_pouting_tone1:"] = "\uD83D\uDE4E\uD83C\uDFFB\u200D♂️", + [":man_pouting_tone2:"] = "\uD83D\uDE4E\uD83C\uDFFC\u200D♂️", + [":man_pouting_tone3:"] = "\uD83D\uDE4E\uD83C\uDFFD\u200D♂️", + [":man_pouting_tone4:"] = "\uD83D\uDE4E\uD83C\uDFFE\u200D♂️", + [":man_pouting_tone5:"] = "\uD83D\uDE4E\uD83C\uDFFF\u200D♂️", + [":man_raising_hand:"] = "\uD83D\uDE4B\u200D♂️", + [":man_raising_hand::skin-tone-1:"] = "\uD83D\uDE4B\uD83C\uDFFB\u200D♂️", + [":man_raising_hand::skin-tone-2:"] = "\uD83D\uDE4B\uD83C\uDFFC\u200D♂️", + [":man_raising_hand::skin-tone-3:"] = "\uD83D\uDE4B\uD83C\uDFFD\u200D♂️", + [":man_raising_hand::skin-tone-4:"] = "\uD83D\uDE4B\uD83C\uDFFE\u200D♂️", + [":man_raising_hand::skin-tone-5:"] = "\uD83D\uDE4B\uD83C\uDFFF\u200D♂️", + [":man_raising_hand_dark_skin_tone:"] = "\uD83D\uDE4B\uD83C\uDFFF\u200D♂️", + [":man_raising_hand_light_skin_tone:"] = "\uD83D\uDE4B\uD83C\uDFFB\u200D♂️", + [":man_raising_hand_medium_dark_skin_tone:"] = "\uD83D\uDE4B\uD83C\uDFFE\u200D♂️", + [":man_raising_hand_medium_light_skin_tone:"] = "\uD83D\uDE4B\uD83C\uDFFC\u200D♂️", + [":man_raising_hand_medium_skin_tone:"] = "\uD83D\uDE4B\uD83C\uDFFD\u200D♂️", + [":man_raising_hand_tone1:"] = "\uD83D\uDE4B\uD83C\uDFFB\u200D♂️", + [":man_raising_hand_tone2:"] = "\uD83D\uDE4B\uD83C\uDFFC\u200D♂️", + [":man_raising_hand_tone3:"] = "\uD83D\uDE4B\uD83C\uDFFD\u200D♂️", + [":man_raising_hand_tone4:"] = "\uD83D\uDE4B\uD83C\uDFFE\u200D♂️", + [":man_raising_hand_tone5:"] = "\uD83D\uDE4B\uD83C\uDFFF\u200D♂️", + [":man_red_haired:"] = "\uD83D\uDC68\u200D\uD83E\uDDB0", + [":man_red_haired::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDB0", + [":man_red_haired::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDB0", + [":man_red_haired::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDB0", + [":man_red_haired::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDB0", + [":man_red_haired::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDB0", + [":man_red_haired_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDB0", + [":man_red_haired_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDB0", + [":man_red_haired_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDB0", + [":man_red_haired_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDB0", + [":man_red_haired_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDB0", + [":man_red_haired_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDB0", + [":man_red_haired_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDB0", + [":man_red_haired_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDB0", + [":man_red_haired_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDB0", + [":man_red_haired_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDB0", + [":man_rowing_boat:"] = "\uD83D\uDEA3\u200D♂️", + [":man_rowing_boat::skin-tone-1:"] = "\uD83D\uDEA3\uD83C\uDFFB\u200D♂️", + [":man_rowing_boat::skin-tone-2:"] = "\uD83D\uDEA3\uD83C\uDFFC\u200D♂️", + [":man_rowing_boat::skin-tone-3:"] = "\uD83D\uDEA3\uD83C\uDFFD\u200D♂️", + [":man_rowing_boat::skin-tone-4:"] = "\uD83D\uDEA3\uD83C\uDFFE\u200D♂️", + [":man_rowing_boat::skin-tone-5:"] = "\uD83D\uDEA3\uD83C\uDFFF\u200D♂️", + [":man_rowing_boat_dark_skin_tone:"] = "\uD83D\uDEA3\uD83C\uDFFF\u200D♂️", + [":man_rowing_boat_light_skin_tone:"] = "\uD83D\uDEA3\uD83C\uDFFB\u200D♂️", + [":man_rowing_boat_medium_dark_skin_tone:"] = "\uD83D\uDEA3\uD83C\uDFFE\u200D♂️", + [":man_rowing_boat_medium_light_skin_tone:"] = "\uD83D\uDEA3\uD83C\uDFFC\u200D♂️", + [":man_rowing_boat_medium_skin_tone:"] = "\uD83D\uDEA3\uD83C\uDFFD\u200D♂️", + [":man_rowing_boat_tone1:"] = "\uD83D\uDEA3\uD83C\uDFFB\u200D♂️", + [":man_rowing_boat_tone2:"] = "\uD83D\uDEA3\uD83C\uDFFC\u200D♂️", + [":man_rowing_boat_tone3:"] = "\uD83D\uDEA3\uD83C\uDFFD\u200D♂️", + [":man_rowing_boat_tone4:"] = "\uD83D\uDEA3\uD83C\uDFFE\u200D♂️", + [":man_rowing_boat_tone5:"] = "\uD83D\uDEA3\uD83C\uDFFF\u200D♂️", + [":man_running:"] = "\uD83C\uDFC3\u200D♂️", + [":man_running::skin-tone-1:"] = "\uD83C\uDFC3\uD83C\uDFFB\u200D♂️", + [":man_running::skin-tone-2:"] = "\uD83C\uDFC3\uD83C\uDFFC\u200D♂️", + [":man_running::skin-tone-3:"] = "\uD83C\uDFC3\uD83C\uDFFD\u200D♂️", + [":man_running::skin-tone-4:"] = "\uD83C\uDFC3\uD83C\uDFFE\u200D♂️", + [":man_running::skin-tone-5:"] = "\uD83C\uDFC3\uD83C\uDFFF\u200D♂️", + [":man_running_dark_skin_tone:"] = "\uD83C\uDFC3\uD83C\uDFFF\u200D♂️", + [":man_running_light_skin_tone:"] = "\uD83C\uDFC3\uD83C\uDFFB\u200D♂️", + [":man_running_medium_dark_skin_tone:"] = "\uD83C\uDFC3\uD83C\uDFFE\u200D♂️", + [":man_running_medium_light_skin_tone:"] = "\uD83C\uDFC3\uD83C\uDFFC\u200D♂️", + [":man_running_medium_skin_tone:"] = "\uD83C\uDFC3\uD83C\uDFFD\u200D♂️", + [":man_running_tone1:"] = "\uD83C\uDFC3\uD83C\uDFFB\u200D♂️", + [":man_running_tone2:"] = "\uD83C\uDFC3\uD83C\uDFFC\u200D♂️", + [":man_running_tone3:"] = "\uD83C\uDFC3\uD83C\uDFFD\u200D♂️", + [":man_running_tone4:"] = "\uD83C\uDFC3\uD83C\uDFFE\u200D♂️", + [":man_running_tone5:"] = "\uD83C\uDFC3\uD83C\uDFFF\u200D♂️", + [":man_scientist:"] = "\uD83D\uDC68\u200D\uD83D\uDD2C", + [":man_scientist::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDD2C", + [":man_scientist::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDD2C", + [":man_scientist::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDD2C", + [":man_scientist::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDD2C", + [":man_scientist::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDD2C", + [":man_scientist_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDD2C", + [":man_scientist_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDD2C", + [":man_scientist_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDD2C", + [":man_scientist_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDD2C", + [":man_scientist_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDD2C", + [":man_scientist_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDD2C", + [":man_scientist_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDD2C", + [":man_scientist_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDD2C", + [":man_scientist_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDD2C", + [":man_scientist_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDD2C", + [":man_shrugging:"] = "\uD83E\uDD37\u200D♂️", + [":man_shrugging::skin-tone-1:"] = "\uD83E\uDD37\uD83C\uDFFB\u200D♂️", + [":man_shrugging::skin-tone-2:"] = "\uD83E\uDD37\uD83C\uDFFC\u200D♂️", + [":man_shrugging::skin-tone-3:"] = "\uD83E\uDD37\uD83C\uDFFD\u200D♂️", + [":man_shrugging::skin-tone-4:"] = "\uD83E\uDD37\uD83C\uDFFE\u200D♂️", + [":man_shrugging::skin-tone-5:"] = "\uD83E\uDD37\uD83C\uDFFF\u200D♂️", + [":man_shrugging_dark_skin_tone:"] = "\uD83E\uDD37\uD83C\uDFFF\u200D♂️", + [":man_shrugging_light_skin_tone:"] = "\uD83E\uDD37\uD83C\uDFFB\u200D♂️", + [":man_shrugging_medium_dark_skin_tone:"] = "\uD83E\uDD37\uD83C\uDFFE\u200D♂️", + [":man_shrugging_medium_light_skin_tone:"] = "\uD83E\uDD37\uD83C\uDFFC\u200D♂️", + [":man_shrugging_medium_skin_tone:"] = "\uD83E\uDD37\uD83C\uDFFD\u200D♂️", + [":man_shrugging_tone1:"] = "\uD83E\uDD37\uD83C\uDFFB\u200D♂️", + [":man_shrugging_tone2:"] = "\uD83E\uDD37\uD83C\uDFFC\u200D♂️", + [":man_shrugging_tone3:"] = "\uD83E\uDD37\uD83C\uDFFD\u200D♂️", + [":man_shrugging_tone4:"] = "\uD83E\uDD37\uD83C\uDFFE\u200D♂️", + [":man_shrugging_tone5:"] = "\uD83E\uDD37\uD83C\uDFFF\u200D♂️", + [":man_singer:"] = "\uD83D\uDC68\u200D\uD83C\uDFA4", + [":man_singer::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDFA4", + [":man_singer::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDFA4", + [":man_singer::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDFA4", + [":man_singer::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDFA4", + [":man_singer::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDFA4", + [":man_singer_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDFA4", + [":man_singer_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDFA4", + [":man_singer_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDFA4", + [":man_singer_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDFA4", + [":man_singer_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDFA4", + [":man_singer_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDFA4", + [":man_singer_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDFA4", + [":man_singer_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDFA4", + [":man_singer_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDFA4", + [":man_singer_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDFA4", + [":man_standing:"] = "\uD83E\uDDCD\u200D♂️", + [":man_standing::skin-tone-1:"] = "\uD83E\uDDCD\uD83C\uDFFB\u200D♂️", + [":man_standing::skin-tone-2:"] = "\uD83E\uDDCD\uD83C\uDFFC\u200D♂️", + [":man_standing::skin-tone-3:"] = "\uD83E\uDDCD\uD83C\uDFFD\u200D♂️", + [":man_standing::skin-tone-4:"] = "\uD83E\uDDCD\uD83C\uDFFE\u200D♂️", + [":man_standing::skin-tone-5:"] = "\uD83E\uDDCD\uD83C\uDFFF\u200D♂️", + [":man_standing_dark_skin_tone:"] = "\uD83E\uDDCD\uD83C\uDFFF\u200D♂️", + [":man_standing_light_skin_tone:"] = "\uD83E\uDDCD\uD83C\uDFFB\u200D♂️", + [":man_standing_medium_dark_skin_tone:"] = "\uD83E\uDDCD\uD83C\uDFFE\u200D♂️", + [":man_standing_medium_light_skin_tone:"] = "\uD83E\uDDCD\uD83C\uDFFC\u200D♂️", + [":man_standing_medium_skin_tone:"] = "\uD83E\uDDCD\uD83C\uDFFD\u200D♂️", + [":man_standing_tone1:"] = "\uD83E\uDDCD\uD83C\uDFFB\u200D♂️", + [":man_standing_tone2:"] = "\uD83E\uDDCD\uD83C\uDFFC\u200D♂️", + [":man_standing_tone3:"] = "\uD83E\uDDCD\uD83C\uDFFD\u200D♂️", + [":man_standing_tone4:"] = "\uD83E\uDDCD\uD83C\uDFFE\u200D♂️", + [":man_standing_tone5:"] = "\uD83E\uDDCD\uD83C\uDFFF\u200D♂️", + [":man_student:"] = "\uD83D\uDC68\u200D\uD83C\uDF93", + [":man_student::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDF93", + [":man_student::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDF93", + [":man_student::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDF93", + [":man_student::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDF93", + [":man_student::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDF93", + [":man_student_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDF93", + [":man_student_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDF93", + [":man_student_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDF93", + [":man_student_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDF93", + [":man_student_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDF93", + [":man_student_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDF93", + [":man_student_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDF93", + [":man_student_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDF93", + [":man_student_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDF93", + [":man_student_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDF93", + [":man_superhero:"] = "\uD83E\uDDB8\u200D♂️", + [":man_superhero::skin-tone-1:"] = "\uD83E\uDDB8\uD83C\uDFFB\u200D♂️", + [":man_superhero::skin-tone-2:"] = "\uD83E\uDDB8\uD83C\uDFFC\u200D♂️", + [":man_superhero::skin-tone-3:"] = "\uD83E\uDDB8\uD83C\uDFFD\u200D♂️", + [":man_superhero::skin-tone-4:"] = "\uD83E\uDDB8\uD83C\uDFFE\u200D♂️", + [":man_superhero::skin-tone-5:"] = "\uD83E\uDDB8\uD83C\uDFFF\u200D♂️", + [":man_superhero_dark_skin_tone:"] = "\uD83E\uDDB8\uD83C\uDFFF\u200D♂️", + [":man_superhero_light_skin_tone:"] = "\uD83E\uDDB8\uD83C\uDFFB\u200D♂️", + [":man_superhero_medium_dark_skin_tone:"] = "\uD83E\uDDB8\uD83C\uDFFE\u200D♂️", + [":man_superhero_medium_light_skin_tone:"] = "\uD83E\uDDB8\uD83C\uDFFC\u200D♂️", + [":man_superhero_medium_skin_tone:"] = "\uD83E\uDDB8\uD83C\uDFFD\u200D♂️", + [":man_superhero_tone1:"] = "\uD83E\uDDB8\uD83C\uDFFB\u200D♂️", + [":man_superhero_tone2:"] = "\uD83E\uDDB8\uD83C\uDFFC\u200D♂️", + [":man_superhero_tone3:"] = "\uD83E\uDDB8\uD83C\uDFFD\u200D♂️", + [":man_superhero_tone4:"] = "\uD83E\uDDB8\uD83C\uDFFE\u200D♂️", + [":man_superhero_tone5:"] = "\uD83E\uDDB8\uD83C\uDFFF\u200D♂️", + [":man_supervillain:"] = "\uD83E\uDDB9\u200D♂️", + [":man_supervillain::skin-tone-1:"] = "\uD83E\uDDB9\uD83C\uDFFB\u200D♂️", + [":man_supervillain::skin-tone-2:"] = "\uD83E\uDDB9\uD83C\uDFFC\u200D♂️", + [":man_supervillain::skin-tone-3:"] = "\uD83E\uDDB9\uD83C\uDFFD\u200D♂️", + [":man_supervillain::skin-tone-4:"] = "\uD83E\uDDB9\uD83C\uDFFE\u200D♂️", + [":man_supervillain::skin-tone-5:"] = "\uD83E\uDDB9\uD83C\uDFFF\u200D♂️", + [":man_supervillain_dark_skin_tone:"] = "\uD83E\uDDB9\uD83C\uDFFF\u200D♂️", + [":man_supervillain_light_skin_tone:"] = "\uD83E\uDDB9\uD83C\uDFFB\u200D♂️", + [":man_supervillain_medium_dark_skin_tone:"] = "\uD83E\uDDB9\uD83C\uDFFE\u200D♂️", + [":man_supervillain_medium_light_skin_tone:"] = "\uD83E\uDDB9\uD83C\uDFFC\u200D♂️", + [":man_supervillain_medium_skin_tone:"] = "\uD83E\uDDB9\uD83C\uDFFD\u200D♂️", + [":man_supervillain_tone1:"] = "\uD83E\uDDB9\uD83C\uDFFB\u200D♂️", + [":man_supervillain_tone2:"] = "\uD83E\uDDB9\uD83C\uDFFC\u200D♂️", + [":man_supervillain_tone3:"] = "\uD83E\uDDB9\uD83C\uDFFD\u200D♂️", + [":man_supervillain_tone4:"] = "\uD83E\uDDB9\uD83C\uDFFE\u200D♂️", + [":man_supervillain_tone5:"] = "\uD83E\uDDB9\uD83C\uDFFF\u200D♂️", + [":man_surfing:"] = "\uD83C\uDFC4\u200D♂️", + [":man_surfing::skin-tone-1:"] = "\uD83C\uDFC4\uD83C\uDFFB\u200D♂️", + [":man_surfing::skin-tone-2:"] = "\uD83C\uDFC4\uD83C\uDFFC\u200D♂️", + [":man_surfing::skin-tone-3:"] = "\uD83C\uDFC4\uD83C\uDFFD\u200D♂️", + [":man_surfing::skin-tone-4:"] = "\uD83C\uDFC4\uD83C\uDFFE\u200D♂️", + [":man_surfing::skin-tone-5:"] = "\uD83C\uDFC4\uD83C\uDFFF\u200D♂️", + [":man_surfing_dark_skin_tone:"] = "\uD83C\uDFC4\uD83C\uDFFF\u200D♂️", + [":man_surfing_light_skin_tone:"] = "\uD83C\uDFC4\uD83C\uDFFB\u200D♂️", + [":man_surfing_medium_dark_skin_tone:"] = "\uD83C\uDFC4\uD83C\uDFFE\u200D♂️", + [":man_surfing_medium_light_skin_tone:"] = "\uD83C\uDFC4\uD83C\uDFFC\u200D♂️", + [":man_surfing_medium_skin_tone:"] = "\uD83C\uDFC4\uD83C\uDFFD\u200D♂️", + [":man_surfing_tone1:"] = "\uD83C\uDFC4\uD83C\uDFFB\u200D♂️", + [":man_surfing_tone2:"] = "\uD83C\uDFC4\uD83C\uDFFC\u200D♂️", + [":man_surfing_tone3:"] = "\uD83C\uDFC4\uD83C\uDFFD\u200D♂️", + [":man_surfing_tone4:"] = "\uD83C\uDFC4\uD83C\uDFFE\u200D♂️", + [":man_surfing_tone5:"] = "\uD83C\uDFC4\uD83C\uDFFF\u200D♂️", + [":man_swimming:"] = "\uD83C\uDFCA\u200D♂️", + [":man_swimming::skin-tone-1:"] = "\uD83C\uDFCA\uD83C\uDFFB\u200D♂️", + [":man_swimming::skin-tone-2:"] = "\uD83C\uDFCA\uD83C\uDFFC\u200D♂️", + [":man_swimming::skin-tone-3:"] = "\uD83C\uDFCA\uD83C\uDFFD\u200D♂️", + [":man_swimming::skin-tone-4:"] = "\uD83C\uDFCA\uD83C\uDFFE\u200D♂️", + [":man_swimming::skin-tone-5:"] = "\uD83C\uDFCA\uD83C\uDFFF\u200D♂️", + [":man_swimming_dark_skin_tone:"] = "\uD83C\uDFCA\uD83C\uDFFF\u200D♂️", + [":man_swimming_light_skin_tone:"] = "\uD83C\uDFCA\uD83C\uDFFB\u200D♂️", + [":man_swimming_medium_dark_skin_tone:"] = "\uD83C\uDFCA\uD83C\uDFFE\u200D♂️", + [":man_swimming_medium_light_skin_tone:"] = "\uD83C\uDFCA\uD83C\uDFFC\u200D♂️", + [":man_swimming_medium_skin_tone:"] = "\uD83C\uDFCA\uD83C\uDFFD\u200D♂️", + [":man_swimming_tone1:"] = "\uD83C\uDFCA\uD83C\uDFFB\u200D♂️", + [":man_swimming_tone2:"] = "\uD83C\uDFCA\uD83C\uDFFC\u200D♂️", + [":man_swimming_tone3:"] = "\uD83C\uDFCA\uD83C\uDFFD\u200D♂️", + [":man_swimming_tone4:"] = "\uD83C\uDFCA\uD83C\uDFFE\u200D♂️", + [":man_swimming_tone5:"] = "\uD83C\uDFCA\uD83C\uDFFF\u200D♂️", + [":man_teacher:"] = "\uD83D\uDC68\u200D\uD83C\uDFEB", + [":man_teacher::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDFEB", + [":man_teacher::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDFEB", + [":man_teacher::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDFEB", + [":man_teacher::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDFEB", + [":man_teacher::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDFEB", + [":man_teacher_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDFEB", + [":man_teacher_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDFEB", + [":man_teacher_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDFEB", + [":man_teacher_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDFEB", + [":man_teacher_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDFEB", + [":man_teacher_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83C\uDFEB", + [":man_teacher_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83C\uDFEB", + [":man_teacher_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83C\uDFEB", + [":man_teacher_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83C\uDFEB", + [":man_teacher_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83C\uDFEB", + [":man_technologist:"] = "\uD83D\uDC68\u200D\uD83D\uDCBB", + [":man_technologist::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDCBB", + [":man_technologist::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDCBB", + [":man_technologist::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDCBB", + [":man_technologist::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDCBB", + [":man_technologist::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDCBB", + [":man_technologist_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDCBB", + [":man_technologist_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDCBB", + [":man_technologist_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDCBB", + [":man_technologist_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDCBB", + [":man_technologist_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDCBB", + [":man_technologist_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83D\uDCBB", + [":man_technologist_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83D\uDCBB", + [":man_technologist_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83D\uDCBB", + [":man_technologist_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83D\uDCBB", + [":man_technologist_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83D\uDCBB", + [":man_tipping_hand:"] = "\uD83D\uDC81\u200D♂️", + [":man_tipping_hand::skin-tone-1:"] = "\uD83D\uDC81\uD83C\uDFFB\u200D♂️", + [":man_tipping_hand::skin-tone-2:"] = "\uD83D\uDC81\uD83C\uDFFC\u200D♂️", + [":man_tipping_hand::skin-tone-3:"] = "\uD83D\uDC81\uD83C\uDFFD\u200D♂️", + [":man_tipping_hand::skin-tone-4:"] = "\uD83D\uDC81\uD83C\uDFFE\u200D♂️", + [":man_tipping_hand::skin-tone-5:"] = "\uD83D\uDC81\uD83C\uDFFF\u200D♂️", + [":man_tipping_hand_dark_skin_tone:"] = "\uD83D\uDC81\uD83C\uDFFF\u200D♂️", + [":man_tipping_hand_light_skin_tone:"] = "\uD83D\uDC81\uD83C\uDFFB\u200D♂️", + [":man_tipping_hand_medium_dark_skin_tone:"] = "\uD83D\uDC81\uD83C\uDFFE\u200D♂️", + [":man_tipping_hand_medium_light_skin_tone:"] = "\uD83D\uDC81\uD83C\uDFFC\u200D♂️", + [":man_tipping_hand_medium_skin_tone:"] = "\uD83D\uDC81\uD83C\uDFFD\u200D♂️", + [":man_tipping_hand_tone1:"] = "\uD83D\uDC81\uD83C\uDFFB\u200D♂️", + [":man_tipping_hand_tone2:"] = "\uD83D\uDC81\uD83C\uDFFC\u200D♂️", + [":man_tipping_hand_tone3:"] = "\uD83D\uDC81\uD83C\uDFFD\u200D♂️", + [":man_tipping_hand_tone4:"] = "\uD83D\uDC81\uD83C\uDFFE\u200D♂️", + [":man_tipping_hand_tone5:"] = "\uD83D\uDC81\uD83C\uDFFF\u200D♂️", + [":man_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB", + [":man_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC", + [":man_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD", + [":man_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE", + [":man_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF", + [":man_vampire:"] = "\uD83E\uDDDB\u200D♂️", + [":man_vampire::skin-tone-1:"] = "\uD83E\uDDDB\uD83C\uDFFB\u200D♂️", + [":man_vampire::skin-tone-2:"] = "\uD83E\uDDDB\uD83C\uDFFC\u200D♂️", + [":man_vampire::skin-tone-3:"] = "\uD83E\uDDDB\uD83C\uDFFD\u200D♂️", + [":man_vampire::skin-tone-4:"] = "\uD83E\uDDDB\uD83C\uDFFE\u200D♂️", + [":man_vampire::skin-tone-5:"] = "\uD83E\uDDDB\uD83C\uDFFF\u200D♂️", + [":man_vampire_dark_skin_tone:"] = "\uD83E\uDDDB\uD83C\uDFFF\u200D♂️", + [":man_vampire_light_skin_tone:"] = "\uD83E\uDDDB\uD83C\uDFFB\u200D♂️", + [":man_vampire_medium_dark_skin_tone:"] = "\uD83E\uDDDB\uD83C\uDFFE\u200D♂️", + [":man_vampire_medium_light_skin_tone:"] = "\uD83E\uDDDB\uD83C\uDFFC\u200D♂️", + [":man_vampire_medium_skin_tone:"] = "\uD83E\uDDDB\uD83C\uDFFD\u200D♂️", + [":man_vampire_tone1:"] = "\uD83E\uDDDB\uD83C\uDFFB\u200D♂️", + [":man_vampire_tone2:"] = "\uD83E\uDDDB\uD83C\uDFFC\u200D♂️", + [":man_vampire_tone3:"] = "\uD83E\uDDDB\uD83C\uDFFD\u200D♂️", + [":man_vampire_tone4:"] = "\uD83E\uDDDB\uD83C\uDFFE\u200D♂️", + [":man_vampire_tone5:"] = "\uD83E\uDDDB\uD83C\uDFFF\u200D♂️", + [":man_walking:"] = "\uD83D\uDEB6\u200D♂️", + [":man_walking::skin-tone-1:"] = "\uD83D\uDEB6\uD83C\uDFFB\u200D♂️", + [":man_walking::skin-tone-2:"] = "\uD83D\uDEB6\uD83C\uDFFC\u200D♂️", + [":man_walking::skin-tone-3:"] = "\uD83D\uDEB6\uD83C\uDFFD\u200D♂️", + [":man_walking::skin-tone-4:"] = "\uD83D\uDEB6\uD83C\uDFFE\u200D♂️", + [":man_walking::skin-tone-5:"] = "\uD83D\uDEB6\uD83C\uDFFF\u200D♂️", + [":man_walking_dark_skin_tone:"] = "\uD83D\uDEB6\uD83C\uDFFF\u200D♂️", + [":man_walking_light_skin_tone:"] = "\uD83D\uDEB6\uD83C\uDFFB\u200D♂️", + [":man_walking_medium_dark_skin_tone:"] = "\uD83D\uDEB6\uD83C\uDFFE\u200D♂️", + [":man_walking_medium_light_skin_tone:"] = "\uD83D\uDEB6\uD83C\uDFFC\u200D♂️", + [":man_walking_medium_skin_tone:"] = "\uD83D\uDEB6\uD83C\uDFFD\u200D♂️", + [":man_walking_tone1:"] = "\uD83D\uDEB6\uD83C\uDFFB\u200D♂️", + [":man_walking_tone2:"] = "\uD83D\uDEB6\uD83C\uDFFC\u200D♂️", + [":man_walking_tone3:"] = "\uD83D\uDEB6\uD83C\uDFFD\u200D♂️", + [":man_walking_tone4:"] = "\uD83D\uDEB6\uD83C\uDFFE\u200D♂️", + [":man_walking_tone5:"] = "\uD83D\uDEB6\uD83C\uDFFF\u200D♂️", + [":man_wearing_turban:"] = "\uD83D\uDC73\u200D♂️", + [":man_wearing_turban::skin-tone-1:"] = "\uD83D\uDC73\uD83C\uDFFB\u200D♂️", + [":man_wearing_turban::skin-tone-2:"] = "\uD83D\uDC73\uD83C\uDFFC\u200D♂️", + [":man_wearing_turban::skin-tone-3:"] = "\uD83D\uDC73\uD83C\uDFFD\u200D♂️", + [":man_wearing_turban::skin-tone-4:"] = "\uD83D\uDC73\uD83C\uDFFE\u200D♂️", + [":man_wearing_turban::skin-tone-5:"] = "\uD83D\uDC73\uD83C\uDFFF\u200D♂️", + [":man_wearing_turban_dark_skin_tone:"] = "\uD83D\uDC73\uD83C\uDFFF\u200D♂️", + [":man_wearing_turban_light_skin_tone:"] = "\uD83D\uDC73\uD83C\uDFFB\u200D♂️", + [":man_wearing_turban_medium_dark_skin_tone:"] = "\uD83D\uDC73\uD83C\uDFFE\u200D♂️", + [":man_wearing_turban_medium_light_skin_tone:"] = "\uD83D\uDC73\uD83C\uDFFC\u200D♂️", + [":man_wearing_turban_medium_skin_tone:"] = "\uD83D\uDC73\uD83C\uDFFD\u200D♂️", + [":man_wearing_turban_tone1:"] = "\uD83D\uDC73\uD83C\uDFFB\u200D♂️", + [":man_wearing_turban_tone2:"] = "\uD83D\uDC73\uD83C\uDFFC\u200D♂️", + [":man_wearing_turban_tone3:"] = "\uD83D\uDC73\uD83C\uDFFD\u200D♂️", + [":man_wearing_turban_tone4:"] = "\uD83D\uDC73\uD83C\uDFFE\u200D♂️", + [":man_wearing_turban_tone5:"] = "\uD83D\uDC73\uD83C\uDFFF\u200D♂️", + [":man_white_haired:"] = "\uD83D\uDC68\u200D\uD83E\uDDB3", + [":man_white_haired::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDB3", + [":man_white_haired::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDB3", + [":man_white_haired::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDB3", + [":man_white_haired::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDB3", + [":man_white_haired::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDB3", + [":man_white_haired_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDB3", + [":man_white_haired_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDB3", + [":man_white_haired_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDB3", + [":man_white_haired_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDB3", + [":man_white_haired_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDB3", + [":man_white_haired_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDB3", + [":man_white_haired_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDB3", + [":man_white_haired_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDB3", + [":man_white_haired_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDB3", + [":man_white_haired_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDB3", + [":man_with_chinese_cap:"] = "\uD83D\uDC72", + [":man_with_chinese_cap::skin-tone-1:"] = "\uD83D\uDC72\uD83C\uDFFB", + [":man_with_chinese_cap::skin-tone-2:"] = "\uD83D\uDC72\uD83C\uDFFC", + [":man_with_chinese_cap::skin-tone-3:"] = "\uD83D\uDC72\uD83C\uDFFD", + [":man_with_chinese_cap::skin-tone-4:"] = "\uD83D\uDC72\uD83C\uDFFE", + [":man_with_chinese_cap::skin-tone-5:"] = "\uD83D\uDC72\uD83C\uDFFF", + [":man_with_chinese_cap_tone1:"] = "\uD83D\uDC72\uD83C\uDFFB", + [":man_with_chinese_cap_tone2:"] = "\uD83D\uDC72\uD83C\uDFFC", + [":man_with_chinese_cap_tone3:"] = "\uD83D\uDC72\uD83C\uDFFD", + [":man_with_chinese_cap_tone4:"] = "\uD83D\uDC72\uD83C\uDFFE", + [":man_with_chinese_cap_tone5:"] = "\uD83D\uDC72\uD83C\uDFFF", + [":man_with_gua_pi_mao:"] = "\uD83D\uDC72", + [":man_with_gua_pi_mao::skin-tone-1:"] = "\uD83D\uDC72\uD83C\uDFFB", + [":man_with_gua_pi_mao::skin-tone-2:"] = "\uD83D\uDC72\uD83C\uDFFC", + [":man_with_gua_pi_mao::skin-tone-3:"] = "\uD83D\uDC72\uD83C\uDFFD", + [":man_with_gua_pi_mao::skin-tone-4:"] = "\uD83D\uDC72\uD83C\uDFFE", + [":man_with_gua_pi_mao::skin-tone-5:"] = "\uD83D\uDC72\uD83C\uDFFF", + [":man_with_gua_pi_mao_tone1:"] = "\uD83D\uDC72\uD83C\uDFFB", + [":man_with_gua_pi_mao_tone2:"] = "\uD83D\uDC72\uD83C\uDFFC", + [":man_with_gua_pi_mao_tone3:"] = "\uD83D\uDC72\uD83C\uDFFD", + [":man_with_gua_pi_mao_tone4:"] = "\uD83D\uDC72\uD83C\uDFFE", + [":man_with_gua_pi_mao_tone5:"] = "\uD83D\uDC72\uD83C\uDFFF", + [":man_with_probing_cane:"] = "\uD83D\uDC68\u200D\uD83E\uDDAF", + [":man_with_probing_cane::skin-tone-1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDAF", + [":man_with_probing_cane::skin-tone-2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDAF", + [":man_with_probing_cane::skin-tone-3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDAF", + [":man_with_probing_cane::skin-tone-4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDAF", + [":man_with_probing_cane::skin-tone-5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDAF", + [":man_with_probing_cane_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDAF", + [":man_with_probing_cane_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDAF", + [":man_with_probing_cane_medium_dark_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDAF", + [":man_with_probing_cane_medium_light_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDAF", + [":man_with_probing_cane_medium_skin_tone:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDAF", + [":man_with_probing_cane_tone1:"] = "\uD83D\uDC68\uD83C\uDFFB\u200D\uD83E\uDDAF", + [":man_with_probing_cane_tone2:"] = "\uD83D\uDC68\uD83C\uDFFC\u200D\uD83E\uDDAF", + [":man_with_probing_cane_tone3:"] = "\uD83D\uDC68\uD83C\uDFFD\u200D\uD83E\uDDAF", + [":man_with_probing_cane_tone4:"] = "\uD83D\uDC68\uD83C\uDFFE\u200D\uD83E\uDDAF", + [":man_with_probing_cane_tone5:"] = "\uD83D\uDC68\uD83C\uDFFF\u200D\uD83E\uDDAF", + [":man_with_turban:"] = "\uD83D\uDC73", + [":man_with_turban::skin-tone-1:"] = "\uD83D\uDC73\uD83C\uDFFB", + [":man_with_turban::skin-tone-2:"] = "\uD83D\uDC73\uD83C\uDFFC", + [":man_with_turban::skin-tone-3:"] = "\uD83D\uDC73\uD83C\uDFFD", + [":man_with_turban::skin-tone-4:"] = "\uD83D\uDC73\uD83C\uDFFE", + [":man_with_turban::skin-tone-5:"] = "\uD83D\uDC73\uD83C\uDFFF", + [":man_with_turban_tone1:"] = "\uD83D\uDC73\uD83C\uDFFB", + [":man_with_turban_tone2:"] = "\uD83D\uDC73\uD83C\uDFFC", + [":man_with_turban_tone3:"] = "\uD83D\uDC73\uD83C\uDFFD", + [":man_with_turban_tone4:"] = "\uD83D\uDC73\uD83C\uDFFE", + [":man_with_turban_tone5:"] = "\uD83D\uDC73\uD83C\uDFFF", + [":man_zombie:"] = "\uD83E\uDDDF\u200D♂️", + [":mango:"] = "\uD83E\uDD6D", + [":mans_shoe:"] = "\uD83D\uDC5E", + [":mantlepiece_clock:"] = "\uD83D\uDD70️", + [":manual_wheelchair:"] = "\uD83E\uDDBD", + [":map:"] = "\uD83D\uDDFA️", + [":maple_leaf:"] = "\uD83C\uDF41", + [":martial_arts_uniform:"] = "\uD83E\uDD4B", + [":mask:"] = "\uD83D\uDE37", + [":massage:"] = "\uD83D\uDC86", + [":massage::skin-tone-1:"] = "\uD83D\uDC86\uD83C\uDFFB", + [":massage::skin-tone-2:"] = "\uD83D\uDC86\uD83C\uDFFC", + [":massage::skin-tone-3:"] = "\uD83D\uDC86\uD83C\uDFFD", + [":massage::skin-tone-4:"] = "\uD83D\uDC86\uD83C\uDFFE", + [":massage::skin-tone-5:"] = "\uD83D\uDC86\uD83C\uDFFF", + [":massage_tone1:"] = "\uD83D\uDC86\uD83C\uDFFB", + [":massage_tone2:"] = "\uD83D\uDC86\uD83C\uDFFC", + [":massage_tone3:"] = "\uD83D\uDC86\uD83C\uDFFD", + [":massage_tone4:"] = "\uD83D\uDC86\uD83C\uDFFE", + [":massage_tone5:"] = "\uD83D\uDC86\uD83C\uDFFF", + [":mate:"] = "\uD83E\uDDC9", + [":meat_on_bone:"] = "\uD83C\uDF56", + [":mechanical_arm:"] = "\uD83E\uDDBE", + [":mechanical_leg:"] = "\uD83E\uDDBF", + [":medal:"] = "\uD83C\uDFC5", + [":medical_symbol:"] = "⚕️", + [":mega:"] = "\uD83D\uDCE3", + [":melon:"] = "\uD83C\uDF48", + [":memo:"] = "\uD83D\uDCDD", + [":men_with_bunny_ears_partying:"] = "\uD83D\uDC6F\u200D♂️", + [":men_wrestling:"] = "\uD83E\uDD3C\u200D♂️", + [":menorah:"] = "\uD83D\uDD4E", + [":mens:"] = "\uD83D\uDEB9", + [":mermaid:"] = "\uD83E\uDDDC\u200D♀️", + [":mermaid::skin-tone-1:"] = "\uD83E\uDDDC\uD83C\uDFFB\u200D♀️", + [":mermaid::skin-tone-2:"] = "\uD83E\uDDDC\uD83C\uDFFC\u200D♀️", + [":mermaid::skin-tone-3:"] = "\uD83E\uDDDC\uD83C\uDFFD\u200D♀️", + [":mermaid::skin-tone-4:"] = "\uD83E\uDDDC\uD83C\uDFFE\u200D♀️", + [":mermaid::skin-tone-5:"] = "\uD83E\uDDDC\uD83C\uDFFF\u200D♀️", + [":mermaid_dark_skin_tone:"] = "\uD83E\uDDDC\uD83C\uDFFF\u200D♀️", + [":mermaid_light_skin_tone:"] = "\uD83E\uDDDC\uD83C\uDFFB\u200D♀️", + [":mermaid_medium_dark_skin_tone:"] = "\uD83E\uDDDC\uD83C\uDFFE\u200D♀️", + [":mermaid_medium_light_skin_tone:"] = "\uD83E\uDDDC\uD83C\uDFFC\u200D♀️", + [":mermaid_medium_skin_tone:"] = "\uD83E\uDDDC\uD83C\uDFFD\u200D♀️", + [":mermaid_tone1:"] = "\uD83E\uDDDC\uD83C\uDFFB\u200D♀️", + [":mermaid_tone2:"] = "\uD83E\uDDDC\uD83C\uDFFC\u200D♀️", + [":mermaid_tone3:"] = "\uD83E\uDDDC\uD83C\uDFFD\u200D♀️", + [":mermaid_tone4:"] = "\uD83E\uDDDC\uD83C\uDFFE\u200D♀️", + [":mermaid_tone5:"] = "\uD83E\uDDDC\uD83C\uDFFF\u200D♀️", + [":merman:"] = "\uD83E\uDDDC\u200D♂️", + [":merman::skin-tone-1:"] = "\uD83E\uDDDC\uD83C\uDFFB\u200D♂️", + [":merman::skin-tone-2:"] = "\uD83E\uDDDC\uD83C\uDFFC\u200D♂️", + [":merman::skin-tone-3:"] = "\uD83E\uDDDC\uD83C\uDFFD\u200D♂️", + [":merman::skin-tone-4:"] = "\uD83E\uDDDC\uD83C\uDFFE\u200D♂️", + [":merman::skin-tone-5:"] = "\uD83E\uDDDC\uD83C\uDFFF\u200D♂️", + [":merman_dark_skin_tone:"] = "\uD83E\uDDDC\uD83C\uDFFF\u200D♂️", + [":merman_light_skin_tone:"] = "\uD83E\uDDDC\uD83C\uDFFB\u200D♂️", + [":merman_medium_dark_skin_tone:"] = "\uD83E\uDDDC\uD83C\uDFFE\u200D♂️", + [":merman_medium_light_skin_tone:"] = "\uD83E\uDDDC\uD83C\uDFFC\u200D♂️", + [":merman_medium_skin_tone:"] = "\uD83E\uDDDC\uD83C\uDFFD\u200D♂️", + [":merman_tone1:"] = "\uD83E\uDDDC\uD83C\uDFFB\u200D♂️", + [":merman_tone2:"] = "\uD83E\uDDDC\uD83C\uDFFC\u200D♂️", + [":merman_tone3:"] = "\uD83E\uDDDC\uD83C\uDFFD\u200D♂️", + [":merman_tone4:"] = "\uD83E\uDDDC\uD83C\uDFFE\u200D♂️", + [":merman_tone5:"] = "\uD83E\uDDDC\uD83C\uDFFF\u200D♂️", + [":merperson:"] = "\uD83E\uDDDC", + [":merperson::skin-tone-1:"] = "\uD83E\uDDDC\uD83C\uDFFB", + [":merperson::skin-tone-2:"] = "\uD83E\uDDDC\uD83C\uDFFC", + [":merperson::skin-tone-3:"] = "\uD83E\uDDDC\uD83C\uDFFD", + [":merperson::skin-tone-4:"] = "\uD83E\uDDDC\uD83C\uDFFE", + [":merperson::skin-tone-5:"] = "\uD83E\uDDDC\uD83C\uDFFF", + [":merperson_dark_skin_tone:"] = "\uD83E\uDDDC\uD83C\uDFFF", + [":merperson_light_skin_tone:"] = "\uD83E\uDDDC\uD83C\uDFFB", + [":merperson_medium_dark_skin_tone:"] = "\uD83E\uDDDC\uD83C\uDFFE", + [":merperson_medium_light_skin_tone:"] = "\uD83E\uDDDC\uD83C\uDFFC", + [":merperson_medium_skin_tone:"] = "\uD83E\uDDDC\uD83C\uDFFD", + [":merperson_tone1:"] = "\uD83E\uDDDC\uD83C\uDFFB", + [":merperson_tone2:"] = "\uD83E\uDDDC\uD83C\uDFFC", + [":merperson_tone3:"] = "\uD83E\uDDDC\uD83C\uDFFD", + [":merperson_tone4:"] = "\uD83E\uDDDC\uD83C\uDFFE", + [":merperson_tone5:"] = "\uD83E\uDDDC\uD83C\uDFFF", + [":metal:"] = "\uD83E\uDD18", + [":metal::skin-tone-1:"] = "\uD83E\uDD18\uD83C\uDFFB", + [":metal::skin-tone-2:"] = "\uD83E\uDD18\uD83C\uDFFC", + [":metal::skin-tone-3:"] = "\uD83E\uDD18\uD83C\uDFFD", + [":metal::skin-tone-4:"] = "\uD83E\uDD18\uD83C\uDFFE", + [":metal::skin-tone-5:"] = "\uD83E\uDD18\uD83C\uDFFF", + [":metal_tone1:"] = "\uD83E\uDD18\uD83C\uDFFB", + [":metal_tone2:"] = "\uD83E\uDD18\uD83C\uDFFC", + [":metal_tone3:"] = "\uD83E\uDD18\uD83C\uDFFD", + [":metal_tone4:"] = "\uD83E\uDD18\uD83C\uDFFE", + [":metal_tone5:"] = "\uD83E\uDD18\uD83C\uDFFF", + [":metro:"] = "\uD83D\uDE87", + [":microbe:"] = "\uD83E\uDDA0", + [":microphone2:"] = "\uD83C\uDF99️", + [":microphone:"] = "\uD83C\uDFA4", + [":microscope:"] = "\uD83D\uDD2C", + [":middle_finger:"] = "\uD83D\uDD95", + [":middle_finger::skin-tone-1:"] = "\uD83D\uDD95\uD83C\uDFFB", + [":middle_finger::skin-tone-2:"] = "\uD83D\uDD95\uD83C\uDFFC", + [":middle_finger::skin-tone-3:"] = "\uD83D\uDD95\uD83C\uDFFD", + [":middle_finger::skin-tone-4:"] = "\uD83D\uDD95\uD83C\uDFFE", + [":middle_finger::skin-tone-5:"] = "\uD83D\uDD95\uD83C\uDFFF", + [":middle_finger_tone1:"] = "\uD83D\uDD95\uD83C\uDFFB", + [":middle_finger_tone2:"] = "\uD83D\uDD95\uD83C\uDFFC", + [":middle_finger_tone3:"] = "\uD83D\uDD95\uD83C\uDFFD", + [":middle_finger_tone4:"] = "\uD83D\uDD95\uD83C\uDFFE", + [":middle_finger_tone5:"] = "\uD83D\uDD95\uD83C\uDFFF", + [":military_medal:"] = "\uD83C\uDF96️", + [":milk:"] = "\uD83E\uDD5B", + [":milky_way:"] = "\uD83C\uDF0C", + [":minibus:"] = "\uD83D\uDE90", + [":minidisc:"] = "\uD83D\uDCBD", + [":mobile_phone_off:"] = "\uD83D\uDCF4", + [":money_mouth:"] = "\uD83E\uDD11", + [":money_mouth_face:"] = "\uD83E\uDD11", + [":money_with_wings:"] = "\uD83D\uDCB8", + [":moneybag:"] = "\uD83D\uDCB0", + [":monkey:"] = "\uD83D\uDC12", + [":monkey_face:"] = "\uD83D\uDC35", + [":monorail:"] = "\uD83D\uDE9D", + [":moon_cake:"] = "\uD83E\uDD6E", + [":mortar_board:"] = "\uD83C\uDF93", + [":mosque:"] = "\uD83D\uDD4C", + [":mosquito:"] = "\uD83E\uDD9F", + [":mother_christmas:"] = "\uD83E\uDD36", + [":mother_christmas::skin-tone-1:"] = "\uD83E\uDD36\uD83C\uDFFB", + [":mother_christmas::skin-tone-2:"] = "\uD83E\uDD36\uD83C\uDFFC", + [":mother_christmas::skin-tone-3:"] = "\uD83E\uDD36\uD83C\uDFFD", + [":mother_christmas::skin-tone-4:"] = "\uD83E\uDD36\uD83C\uDFFE", + [":mother_christmas::skin-tone-5:"] = "\uD83E\uDD36\uD83C\uDFFF", + [":mother_christmas_tone1:"] = "\uD83E\uDD36\uD83C\uDFFB", + [":mother_christmas_tone2:"] = "\uD83E\uDD36\uD83C\uDFFC", + [":mother_christmas_tone3:"] = "\uD83E\uDD36\uD83C\uDFFD", + [":mother_christmas_tone4:"] = "\uD83E\uDD36\uD83C\uDFFE", + [":mother_christmas_tone5:"] = "\uD83E\uDD36\uD83C\uDFFF", + [":motor_scooter:"] = "\uD83D\uDEF5", + [":motorbike:"] = "\uD83D\uDEF5", + [":motorboat:"] = "\uD83D\uDEE5️", + [":motorcycle:"] = "\uD83C\uDFCD️", + [":motorized_wheelchair:"] = "\uD83E\uDDBC", + [":motorway:"] = "\uD83D\uDEE3️", + [":mount_fuji:"] = "\uD83D\uDDFB", + [":mountain:"] = "⛰️", + [":mountain_bicyclist:"] = "\uD83D\uDEB5", + [":mountain_bicyclist::skin-tone-1:"] = "\uD83D\uDEB5\uD83C\uDFFB", + [":mountain_bicyclist::skin-tone-2:"] = "\uD83D\uDEB5\uD83C\uDFFC", + [":mountain_bicyclist::skin-tone-3:"] = "\uD83D\uDEB5\uD83C\uDFFD", + [":mountain_bicyclist::skin-tone-4:"] = "\uD83D\uDEB5\uD83C\uDFFE", + [":mountain_bicyclist::skin-tone-5:"] = "\uD83D\uDEB5\uD83C\uDFFF", + [":mountain_bicyclist_tone1:"] = "\uD83D\uDEB5\uD83C\uDFFB", + [":mountain_bicyclist_tone2:"] = "\uD83D\uDEB5\uD83C\uDFFC", + [":mountain_bicyclist_tone3:"] = "\uD83D\uDEB5\uD83C\uDFFD", + [":mountain_bicyclist_tone4:"] = "\uD83D\uDEB5\uD83C\uDFFE", + [":mountain_bicyclist_tone5:"] = "\uD83D\uDEB5\uD83C\uDFFF", + [":mountain_cableway:"] = "\uD83D\uDEA0", + [":mountain_railway:"] = "\uD83D\uDE9E", + [":mountain_snow:"] = "\uD83C\uDFD4️", + [":mouse2:"] = "\uD83D\uDC01", + [":mouse:"] = "\uD83D\uDC2D", + [":mouse_three_button:"] = "\uD83D\uDDB1️", + [":movie_camera:"] = "\uD83C\uDFA5", + [":moyai:"] = "\uD83D\uDDFF", + [":mrs_claus:"] = "\uD83E\uDD36", + [":mrs_claus::skin-tone-1:"] = "\uD83E\uDD36\uD83C\uDFFB", + [":mrs_claus::skin-tone-2:"] = "\uD83E\uDD36\uD83C\uDFFC", + [":mrs_claus::skin-tone-3:"] = "\uD83E\uDD36\uD83C\uDFFD", + [":mrs_claus::skin-tone-4:"] = "\uD83E\uDD36\uD83C\uDFFE", + [":mrs_claus::skin-tone-5:"] = "\uD83E\uDD36\uD83C\uDFFF", + [":mrs_claus_tone1:"] = "\uD83E\uDD36\uD83C\uDFFB", + [":mrs_claus_tone2:"] = "\uD83E\uDD36\uD83C\uDFFC", + [":mrs_claus_tone3:"] = "\uD83E\uDD36\uD83C\uDFFD", + [":mrs_claus_tone4:"] = "\uD83E\uDD36\uD83C\uDFFE", + [":mrs_claus_tone5:"] = "\uD83E\uDD36\uD83C\uDFFF", + [":muscle:"] = "\uD83D\uDCAA", + [":muscle::skin-tone-1:"] = "\uD83D\uDCAA\uD83C\uDFFB", + [":muscle::skin-tone-2:"] = "\uD83D\uDCAA\uD83C\uDFFC", + [":muscle::skin-tone-3:"] = "\uD83D\uDCAA\uD83C\uDFFD", + [":muscle::skin-tone-4:"] = "\uD83D\uDCAA\uD83C\uDFFE", + [":muscle::skin-tone-5:"] = "\uD83D\uDCAA\uD83C\uDFFF", + [":muscle_tone1:"] = "\uD83D\uDCAA\uD83C\uDFFB", + [":muscle_tone2:"] = "\uD83D\uDCAA\uD83C\uDFFC", + [":muscle_tone3:"] = "\uD83D\uDCAA\uD83C\uDFFD", + [":muscle_tone4:"] = "\uD83D\uDCAA\uD83C\uDFFE", + [":muscle_tone5:"] = "\uD83D\uDCAA\uD83C\uDFFF", + [":mushroom:"] = "\uD83C\uDF44", + [":musical_keyboard:"] = "\uD83C\uDFB9", + [":musical_note:"] = "\uD83C\uDFB5", + [":musical_score:"] = "\uD83C\uDFBC", + [":mute:"] = "\uD83D\uDD07", + [":nail_care:"] = "\uD83D\uDC85", + [":nail_care::skin-tone-1:"] = "\uD83D\uDC85\uD83C\uDFFB", + [":nail_care::skin-tone-2:"] = "\uD83D\uDC85\uD83C\uDFFC", + [":nail_care::skin-tone-3:"] = "\uD83D\uDC85\uD83C\uDFFD", + [":nail_care::skin-tone-4:"] = "\uD83D\uDC85\uD83C\uDFFE", + [":nail_care::skin-tone-5:"] = "\uD83D\uDC85\uD83C\uDFFF", + [":nail_care_tone1:"] = "\uD83D\uDC85\uD83C\uDFFB", + [":nail_care_tone2:"] = "\uD83D\uDC85\uD83C\uDFFC", + [":nail_care_tone3:"] = "\uD83D\uDC85\uD83C\uDFFD", + [":nail_care_tone4:"] = "\uD83D\uDC85\uD83C\uDFFE", + [":nail_care_tone5:"] = "\uD83D\uDC85\uD83C\uDFFF", + [":name_badge:"] = "\uD83D\uDCDB", + [":national_park:"] = "\uD83C\uDFDE️", + [":nauseated_face:"] = "\uD83E\uDD22", + [":nazar_amulet:"] = "\uD83E\uDDFF", + [":necktie:"] = "\uD83D\uDC54", + [":negative_squared_cross_mark:"] = "❎", + [":nerd:"] = "\uD83E\uDD13", + [":nerd_face:"] = "\uD83E\uDD13", + [":neutral_face:"] = "\uD83D\uDE10", + [":new:"] = "\uD83C\uDD95", + [":new_moon:"] = "\uD83C\uDF11", + [":new_moon_with_face:"] = "\uD83C\uDF1A", + [":newspaper2:"] = "\uD83D\uDDDE️", + [":newspaper:"] = "\uD83D\uDCF0", + [":next_track:"] = "⏭️", + [":ng:"] = "\uD83C\uDD96", + [":night_with_stars:"] = "\uD83C\uDF03", + [":nine:"] = "9️⃣", + [":no_bell:"] = "\uD83D\uDD15", + [":no_bicycles:"] = "\uD83D\uDEB3", + [":no_entry:"] = "⛔", + [":no_entry_sign:"] = "\uD83D\uDEAB", + [":no_good:"] = "\uD83D\uDE45", + [":no_good::skin-tone-1:"] = "\uD83D\uDE45\uD83C\uDFFB", + [":no_good::skin-tone-2:"] = "\uD83D\uDE45\uD83C\uDFFC", + [":no_good::skin-tone-3:"] = "\uD83D\uDE45\uD83C\uDFFD", + [":no_good::skin-tone-4:"] = "\uD83D\uDE45\uD83C\uDFFE", + [":no_good::skin-tone-5:"] = "\uD83D\uDE45\uD83C\uDFFF", + [":no_good_tone1:"] = "\uD83D\uDE45\uD83C\uDFFB", + [":no_good_tone2:"] = "\uD83D\uDE45\uD83C\uDFFC", + [":no_good_tone3:"] = "\uD83D\uDE45\uD83C\uDFFD", + [":no_good_tone4:"] = "\uD83D\uDE45\uD83C\uDFFE", + [":no_good_tone5:"] = "\uD83D\uDE45\uD83C\uDFFF", + [":no_mobile_phones:"] = "\uD83D\uDCF5", + [":no_mouth:"] = "\uD83D\uDE36", + [":no_pedestrians:"] = "\uD83D\uDEB7", + [":no_smoking:"] = "\uD83D\uDEAD", + [":non_potable_water:"] = "\uD83D\uDEB1", + [":nose:"] = "\uD83D\uDC43", + [":nose::skin-tone-1:"] = "\uD83D\uDC43\uD83C\uDFFB", + [":nose::skin-tone-2:"] = "\uD83D\uDC43\uD83C\uDFFC", + [":nose::skin-tone-3:"] = "\uD83D\uDC43\uD83C\uDFFD", + [":nose::skin-tone-4:"] = "\uD83D\uDC43\uD83C\uDFFE", + [":nose::skin-tone-5:"] = "\uD83D\uDC43\uD83C\uDFFF", + [":nose_tone1:"] = "\uD83D\uDC43\uD83C\uDFFB", + [":nose_tone2:"] = "\uD83D\uDC43\uD83C\uDFFC", + [":nose_tone3:"] = "\uD83D\uDC43\uD83C\uDFFD", + [":nose_tone4:"] = "\uD83D\uDC43\uD83C\uDFFE", + [":nose_tone5:"] = "\uD83D\uDC43\uD83C\uDFFF", + [":notebook:"] = "\uD83D\uDCD3", + [":notebook_with_decorative_cover:"] = "\uD83D\uDCD4", + [":notepad_spiral:"] = "\uD83D\uDDD2️", + [":notes:"] = "\uD83C\uDFB6", + [":nut_and_bolt:"] = "\uD83D\uDD29", + [":o"] = "\uD83D\uDE2E", + [":o2:"] = "\uD83C\uDD7E️", + [":o:"] = "⭕", + [":ocean:"] = "\uD83C\uDF0A", + [":octagonal_sign:"] = "\uD83D\uDED1", + [":octopus:"] = "\uD83D\uDC19", + [":oden:"] = "\uD83C\uDF62", + [":office:"] = "\uD83C\uDFE2", + [":oil:"] = "\uD83D\uDEE2️", + [":oil_drum:"] = "\uD83D\uDEE2️", + [":ok:"] = "\uD83C\uDD97", + [":ok_hand:"] = "\uD83D\uDC4C", + [":ok_hand::skin-tone-1:"] = "\uD83D\uDC4C\uD83C\uDFFB", + [":ok_hand::skin-tone-2:"] = "\uD83D\uDC4C\uD83C\uDFFC", + [":ok_hand::skin-tone-3:"] = "\uD83D\uDC4C\uD83C\uDFFD", + [":ok_hand::skin-tone-4:"] = "\uD83D\uDC4C\uD83C\uDFFE", + [":ok_hand::skin-tone-5:"] = "\uD83D\uDC4C\uD83C\uDFFF", + [":ok_hand_tone1:"] = "\uD83D\uDC4C\uD83C\uDFFB", + [":ok_hand_tone2:"] = "\uD83D\uDC4C\uD83C\uDFFC", + [":ok_hand_tone3:"] = "\uD83D\uDC4C\uD83C\uDFFD", + [":ok_hand_tone4:"] = "\uD83D\uDC4C\uD83C\uDFFE", + [":ok_hand_tone5:"] = "\uD83D\uDC4C\uD83C\uDFFF", + [":ok_woman:"] = "\uD83D\uDE46", + [":ok_woman::skin-tone-1:"] = "\uD83D\uDE46\uD83C\uDFFB", + [":ok_woman::skin-tone-2:"] = "\uD83D\uDE46\uD83C\uDFFC", + [":ok_woman::skin-tone-3:"] = "\uD83D\uDE46\uD83C\uDFFD", + [":ok_woman::skin-tone-4:"] = "\uD83D\uDE46\uD83C\uDFFE", + [":ok_woman::skin-tone-5:"] = "\uD83D\uDE46\uD83C\uDFFF", + [":ok_woman_tone1:"] = "\uD83D\uDE46\uD83C\uDFFB", + [":ok_woman_tone2:"] = "\uD83D\uDE46\uD83C\uDFFC", + [":ok_woman_tone3:"] = "\uD83D\uDE46\uD83C\uDFFD", + [":ok_woman_tone4:"] = "\uD83D\uDE46\uD83C\uDFFE", + [":ok_woman_tone5:"] = "\uD83D\uDE46\uD83C\uDFFF", + [":old_key:"] = "\uD83D\uDDDD️", + [":older_adult:"] = "\uD83E\uDDD3", + [":older_adult::skin-tone-1:"] = "\uD83E\uDDD3\uD83C\uDFFB", + [":older_adult::skin-tone-2:"] = "\uD83E\uDDD3\uD83C\uDFFC", + [":older_adult::skin-tone-3:"] = "\uD83E\uDDD3\uD83C\uDFFD", + [":older_adult::skin-tone-4:"] = "\uD83E\uDDD3\uD83C\uDFFE", + [":older_adult::skin-tone-5:"] = "\uD83E\uDDD3\uD83C\uDFFF", + [":older_adult_dark_skin_tone:"] = "\uD83E\uDDD3\uD83C\uDFFF", + [":older_adult_light_skin_tone:"] = "\uD83E\uDDD3\uD83C\uDFFB", + [":older_adult_medium_dark_skin_tone:"] = "\uD83E\uDDD3\uD83C\uDFFE", + [":older_adult_medium_light_skin_tone:"] = "\uD83E\uDDD3\uD83C\uDFFC", + [":older_adult_medium_skin_tone:"] = "\uD83E\uDDD3\uD83C\uDFFD", + [":older_adult_tone1:"] = "\uD83E\uDDD3\uD83C\uDFFB", + [":older_adult_tone2:"] = "\uD83E\uDDD3\uD83C\uDFFC", + [":older_adult_tone3:"] = "\uD83E\uDDD3\uD83C\uDFFD", + [":older_adult_tone4:"] = "\uD83E\uDDD3\uD83C\uDFFE", + [":older_adult_tone5:"] = "\uD83E\uDDD3\uD83C\uDFFF", + [":older_man:"] = "\uD83D\uDC74", + [":older_man::skin-tone-1:"] = "\uD83D\uDC74\uD83C\uDFFB", + [":older_man::skin-tone-2:"] = "\uD83D\uDC74\uD83C\uDFFC", + [":older_man::skin-tone-3:"] = "\uD83D\uDC74\uD83C\uDFFD", + [":older_man::skin-tone-4:"] = "\uD83D\uDC74\uD83C\uDFFE", + [":older_man::skin-tone-5:"] = "\uD83D\uDC74\uD83C\uDFFF", + [":older_man_tone1:"] = "\uD83D\uDC74\uD83C\uDFFB", + [":older_man_tone2:"] = "\uD83D\uDC74\uD83C\uDFFC", + [":older_man_tone3:"] = "\uD83D\uDC74\uD83C\uDFFD", + [":older_man_tone4:"] = "\uD83D\uDC74\uD83C\uDFFE", + [":older_man_tone5:"] = "\uD83D\uDC74\uD83C\uDFFF", + [":older_woman:"] = "\uD83D\uDC75", + [":older_woman::skin-tone-1:"] = "\uD83D\uDC75\uD83C\uDFFB", + [":older_woman::skin-tone-2:"] = "\uD83D\uDC75\uD83C\uDFFC", + [":older_woman::skin-tone-3:"] = "\uD83D\uDC75\uD83C\uDFFD", + [":older_woman::skin-tone-4:"] = "\uD83D\uDC75\uD83C\uDFFE", + [":older_woman::skin-tone-5:"] = "\uD83D\uDC75\uD83C\uDFFF", + [":older_woman_tone1:"] = "\uD83D\uDC75\uD83C\uDFFB", + [":older_woman_tone2:"] = "\uD83D\uDC75\uD83C\uDFFC", + [":older_woman_tone3:"] = "\uD83D\uDC75\uD83C\uDFFD", + [":older_woman_tone4:"] = "\uD83D\uDC75\uD83C\uDFFE", + [":older_woman_tone5:"] = "\uD83D\uDC75\uD83C\uDFFF", + [":om_symbol:"] = "\uD83D\uDD49️", + [":on:"] = "\uD83D\uDD1B", + [":oncoming_automobile:"] = "\uD83D\uDE98", + [":oncoming_bus:"] = "\uD83D\uDE8D", + [":oncoming_police_car:"] = "\uD83D\uDE94", + [":oncoming_taxi:"] = "\uD83D\uDE96", + [":one:"] = "1️⃣", + [":one_piece_swimsuit:"] = "\uD83E\uDE71", + [":onion:"] = "\uD83E\uDDC5", + [":open_file_folder:"] = "\uD83D\uDCC2", + [":open_hands:"] = "\uD83D\uDC50", + [":open_hands::skin-tone-1:"] = "\uD83D\uDC50\uD83C\uDFFB", + [":open_hands::skin-tone-2:"] = "\uD83D\uDC50\uD83C\uDFFC", + [":open_hands::skin-tone-3:"] = "\uD83D\uDC50\uD83C\uDFFD", + [":open_hands::skin-tone-4:"] = "\uD83D\uDC50\uD83C\uDFFE", + [":open_hands::skin-tone-5:"] = "\uD83D\uDC50\uD83C\uDFFF", + [":open_hands_tone1:"] = "\uD83D\uDC50\uD83C\uDFFB", + [":open_hands_tone2:"] = "\uD83D\uDC50\uD83C\uDFFC", + [":open_hands_tone3:"] = "\uD83D\uDC50\uD83C\uDFFD", + [":open_hands_tone4:"] = "\uD83D\uDC50\uD83C\uDFFE", + [":open_hands_tone5:"] = "\uD83D\uDC50\uD83C\uDFFF", + [":open_mouth:"] = "\uD83D\uDE2E", + [":ophiuchus:"] = "⛎", + [":orange_book:"] = "\uD83D\uDCD9", + [":orange_circle:"] = "\uD83D\uDFE0", + [":orange_heart:"] = "\uD83E\uDDE1", + [":orange_square:"] = "\uD83D\uDFE7", + [":orangutan:"] = "\uD83E\uDDA7", + [":orthodox_cross:"] = "☦️", + [":otter:"] = "\uD83E\uDDA6", + [":outbox_tray:"] = "\uD83D\uDCE4", + [":owl:"] = "\uD83E\uDD89", + [":ox:"] = "\uD83D\uDC02", + [":oyster:"] = "\uD83E\uDDAA", + [":package:"] = "\uD83D\uDCE6", + [":paella:"] = "\uD83E\uDD58", + [":page_facing_up:"] = "\uD83D\uDCC4", + [":page_with_curl:"] = "\uD83D\uDCC3", + [":pager:"] = "\uD83D\uDCDF", + [":paintbrush:"] = "\uD83D\uDD8C️", + [":palm_tree:"] = "\uD83C\uDF34", + [":palms_up_together:"] = "\uD83E\uDD32", + [":palms_up_together::skin-tone-1:"] = "\uD83E\uDD32\uD83C\uDFFB", + [":palms_up_together::skin-tone-2:"] = "\uD83E\uDD32\uD83C\uDFFC", + [":palms_up_together::skin-tone-3:"] = "\uD83E\uDD32\uD83C\uDFFD", + [":palms_up_together::skin-tone-4:"] = "\uD83E\uDD32\uD83C\uDFFE", + [":palms_up_together::skin-tone-5:"] = "\uD83E\uDD32\uD83C\uDFFF", + [":palms_up_together_dark_skin_tone:"] = "\uD83E\uDD32\uD83C\uDFFF", + [":palms_up_together_light_skin_tone:"] = "\uD83E\uDD32\uD83C\uDFFB", + [":palms_up_together_medium_dark_skin_tone:"] = "\uD83E\uDD32\uD83C\uDFFE", + [":palms_up_together_medium_light_skin_tone:"] = "\uD83E\uDD32\uD83C\uDFFC", + [":palms_up_together_medium_skin_tone:"] = "\uD83E\uDD32\uD83C\uDFFD", + [":palms_up_together_tone1:"] = "\uD83E\uDD32\uD83C\uDFFB", + [":palms_up_together_tone2:"] = "\uD83E\uDD32\uD83C\uDFFC", + [":palms_up_together_tone3:"] = "\uD83E\uDD32\uD83C\uDFFD", + [":palms_up_together_tone4:"] = "\uD83E\uDD32\uD83C\uDFFE", + [":palms_up_together_tone5:"] = "\uD83E\uDD32\uD83C\uDFFF", + [":pancakes:"] = "\uD83E\uDD5E", + [":panda_face:"] = "\uD83D\uDC3C", + [":paperclip:"] = "\uD83D\uDCCE", + [":paperclips:"] = "\uD83D\uDD87️", + [":parachute:"] = "\uD83E\uDE82", + [":park:"] = "\uD83C\uDFDE️", + [":parking:"] = "\uD83C\uDD7F️", + [":parrot:"] = "\uD83E\uDD9C", + [":part_alternation_mark:"] = "〽️", + [":partly_sunny:"] = "⛅", + [":partying_face:"] = "\uD83E\uDD73", + [":passenger_ship:"] = "\uD83D\uDEF3️", + [":passport_control:"] = "\uD83D\uDEC2", + [":pause_button:"] = "⏸️", + [":paw_prints:"] = "\uD83D\uDC3E", + [":peace:"] = "☮️", + [":peace_symbol:"] = "☮️", + [":peach:"] = "\uD83C\uDF51", + [":peacock:"] = "\uD83E\uDD9A", + [":peanuts:"] = "\uD83E\uDD5C", + [":pear:"] = "\uD83C\uDF50", + [":pen_ballpoint:"] = "\uD83D\uDD8A️", + [":pen_fountain:"] = "\uD83D\uDD8B️", + [":pencil2:"] = "✏️", + [":pencil:"] = "\uD83D\uDCDD", + [":penguin:"] = "\uD83D\uDC27", + [":pensive:"] = "\uD83D\uDE14", + [":people_holding_hands:"] = "\uD83E\uDDD1\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1", + [":people_with_bunny_ears_partying:"] = "\uD83D\uDC6F", + [":people_wrestling:"] = "\uD83E\uDD3C", + [":performing_arts:"] = "\uD83C\uDFAD", + [":persevere:"] = "\uD83D\uDE23", + [":person_biking:"] = "\uD83D\uDEB4", + [":person_biking::skin-tone-1:"] = "\uD83D\uDEB4\uD83C\uDFFB", + [":person_biking::skin-tone-2:"] = "\uD83D\uDEB4\uD83C\uDFFC", + [":person_biking::skin-tone-3:"] = "\uD83D\uDEB4\uD83C\uDFFD", + [":person_biking::skin-tone-4:"] = "\uD83D\uDEB4\uD83C\uDFFE", + [":person_biking::skin-tone-5:"] = "\uD83D\uDEB4\uD83C\uDFFF", + [":person_biking_tone1:"] = "\uD83D\uDEB4\uD83C\uDFFB", + [":person_biking_tone2:"] = "\uD83D\uDEB4\uD83C\uDFFC", + [":person_biking_tone3:"] = "\uD83D\uDEB4\uD83C\uDFFD", + [":person_biking_tone4:"] = "\uD83D\uDEB4\uD83C\uDFFE", + [":person_biking_tone5:"] = "\uD83D\uDEB4\uD83C\uDFFF", + [":person_bouncing_ball:"] = "⛹️", + [":person_bouncing_ball::skin-tone-1:"] = "⛹\uD83C\uDFFB", + [":person_bouncing_ball::skin-tone-2:"] = "⛹\uD83C\uDFFC", + [":person_bouncing_ball::skin-tone-3:"] = "⛹\uD83C\uDFFD", + [":person_bouncing_ball::skin-tone-4:"] = "⛹\uD83C\uDFFE", + [":person_bouncing_ball::skin-tone-5:"] = "⛹\uD83C\uDFFF", + [":person_bouncing_ball_tone1:"] = "⛹\uD83C\uDFFB", + [":person_bouncing_ball_tone2:"] = "⛹\uD83C\uDFFC", + [":person_bouncing_ball_tone3:"] = "⛹\uD83C\uDFFD", + [":person_bouncing_ball_tone4:"] = "⛹\uD83C\uDFFE", + [":person_bouncing_ball_tone5:"] = "⛹\uD83C\uDFFF", + [":person_bowing:"] = "\uD83D\uDE47", + [":person_bowing::skin-tone-1:"] = "\uD83D\uDE47\uD83C\uDFFB", + [":person_bowing::skin-tone-2:"] = "\uD83D\uDE47\uD83C\uDFFC", + [":person_bowing::skin-tone-3:"] = "\uD83D\uDE47\uD83C\uDFFD", + [":person_bowing::skin-tone-4:"] = "\uD83D\uDE47\uD83C\uDFFE", + [":person_bowing::skin-tone-5:"] = "\uD83D\uDE47\uD83C\uDFFF", + [":person_bowing_tone1:"] = "\uD83D\uDE47\uD83C\uDFFB", + [":person_bowing_tone2:"] = "\uD83D\uDE47\uD83C\uDFFC", + [":person_bowing_tone3:"] = "\uD83D\uDE47\uD83C\uDFFD", + [":person_bowing_tone4:"] = "\uD83D\uDE47\uD83C\uDFFE", + [":person_bowing_tone5:"] = "\uD83D\uDE47\uD83C\uDFFF", + [":person_climbing:"] = "\uD83E\uDDD7", + [":person_climbing::skin-tone-1:"] = "\uD83E\uDDD7\uD83C\uDFFB", + [":person_climbing::skin-tone-2:"] = "\uD83E\uDDD7\uD83C\uDFFC", + [":person_climbing::skin-tone-3:"] = "\uD83E\uDDD7\uD83C\uDFFD", + [":person_climbing::skin-tone-4:"] = "\uD83E\uDDD7\uD83C\uDFFE", + [":person_climbing::skin-tone-5:"] = "\uD83E\uDDD7\uD83C\uDFFF", + [":person_climbing_dark_skin_tone:"] = "\uD83E\uDDD7\uD83C\uDFFF", + [":person_climbing_light_skin_tone:"] = "\uD83E\uDDD7\uD83C\uDFFB", + [":person_climbing_medium_dark_skin_tone:"] = "\uD83E\uDDD7\uD83C\uDFFE", + [":person_climbing_medium_light_skin_tone:"] = "\uD83E\uDDD7\uD83C\uDFFC", + [":person_climbing_medium_skin_tone:"] = "\uD83E\uDDD7\uD83C\uDFFD", + [":person_climbing_tone1:"] = "\uD83E\uDDD7\uD83C\uDFFB", + [":person_climbing_tone2:"] = "\uD83E\uDDD7\uD83C\uDFFC", + [":person_climbing_tone3:"] = "\uD83E\uDDD7\uD83C\uDFFD", + [":person_climbing_tone4:"] = "\uD83E\uDDD7\uD83C\uDFFE", + [":person_climbing_tone5:"] = "\uD83E\uDDD7\uD83C\uDFFF", + [":person_doing_cartwheel:"] = "\uD83E\uDD38", + [":person_doing_cartwheel::skin-tone-1:"] = "\uD83E\uDD38\uD83C\uDFFB", + [":person_doing_cartwheel::skin-tone-2:"] = "\uD83E\uDD38\uD83C\uDFFC", + [":person_doing_cartwheel::skin-tone-3:"] = "\uD83E\uDD38\uD83C\uDFFD", + [":person_doing_cartwheel::skin-tone-4:"] = "\uD83E\uDD38\uD83C\uDFFE", + [":person_doing_cartwheel::skin-tone-5:"] = "\uD83E\uDD38\uD83C\uDFFF", + [":person_doing_cartwheel_tone1:"] = "\uD83E\uDD38\uD83C\uDFFB", + [":person_doing_cartwheel_tone2:"] = "\uD83E\uDD38\uD83C\uDFFC", + [":person_doing_cartwheel_tone3:"] = "\uD83E\uDD38\uD83C\uDFFD", + [":person_doing_cartwheel_tone4:"] = "\uD83E\uDD38\uD83C\uDFFE", + [":person_doing_cartwheel_tone5:"] = "\uD83E\uDD38\uD83C\uDFFF", + [":person_facepalming:"] = "\uD83E\uDD26", + [":person_facepalming::skin-tone-1:"] = "\uD83E\uDD26\uD83C\uDFFB", + [":person_facepalming::skin-tone-2:"] = "\uD83E\uDD26\uD83C\uDFFC", + [":person_facepalming::skin-tone-3:"] = "\uD83E\uDD26\uD83C\uDFFD", + [":person_facepalming::skin-tone-4:"] = "\uD83E\uDD26\uD83C\uDFFE", + [":person_facepalming::skin-tone-5:"] = "\uD83E\uDD26\uD83C\uDFFF", + [":person_facepalming_tone1:"] = "\uD83E\uDD26\uD83C\uDFFB", + [":person_facepalming_tone2:"] = "\uD83E\uDD26\uD83C\uDFFC", + [":person_facepalming_tone3:"] = "\uD83E\uDD26\uD83C\uDFFD", + [":person_facepalming_tone4:"] = "\uD83E\uDD26\uD83C\uDFFE", + [":person_facepalming_tone5:"] = "\uD83E\uDD26\uD83C\uDFFF", + [":person_fencing:"] = "\uD83E\uDD3A", + [":person_frowning:"] = "\uD83D\uDE4D", + [":person_frowning::skin-tone-1:"] = "\uD83D\uDE4D\uD83C\uDFFB", + [":person_frowning::skin-tone-2:"] = "\uD83D\uDE4D\uD83C\uDFFC", + [":person_frowning::skin-tone-3:"] = "\uD83D\uDE4D\uD83C\uDFFD", + [":person_frowning::skin-tone-4:"] = "\uD83D\uDE4D\uD83C\uDFFE", + [":person_frowning::skin-tone-5:"] = "\uD83D\uDE4D\uD83C\uDFFF", + [":person_frowning_tone1:"] = "\uD83D\uDE4D\uD83C\uDFFB", + [":person_frowning_tone2:"] = "\uD83D\uDE4D\uD83C\uDFFC", + [":person_frowning_tone3:"] = "\uD83D\uDE4D\uD83C\uDFFD", + [":person_frowning_tone4:"] = "\uD83D\uDE4D\uD83C\uDFFE", + [":person_frowning_tone5:"] = "\uD83D\uDE4D\uD83C\uDFFF", + [":person_gesturing_no:"] = "\uD83D\uDE45", + [":person_gesturing_no::skin-tone-1:"] = "\uD83D\uDE45\uD83C\uDFFB", + [":person_gesturing_no::skin-tone-2:"] = "\uD83D\uDE45\uD83C\uDFFC", + [":person_gesturing_no::skin-tone-3:"] = "\uD83D\uDE45\uD83C\uDFFD", + [":person_gesturing_no::skin-tone-4:"] = "\uD83D\uDE45\uD83C\uDFFE", + [":person_gesturing_no::skin-tone-5:"] = "\uD83D\uDE45\uD83C\uDFFF", + [":person_gesturing_no_tone1:"] = "\uD83D\uDE45\uD83C\uDFFB", + [":person_gesturing_no_tone2:"] = "\uD83D\uDE45\uD83C\uDFFC", + [":person_gesturing_no_tone3:"] = "\uD83D\uDE45\uD83C\uDFFD", + [":person_gesturing_no_tone4:"] = "\uD83D\uDE45\uD83C\uDFFE", + [":person_gesturing_no_tone5:"] = "\uD83D\uDE45\uD83C\uDFFF", + [":person_gesturing_ok:"] = "\uD83D\uDE46", + [":person_gesturing_ok::skin-tone-1:"] = "\uD83D\uDE46\uD83C\uDFFB", + [":person_gesturing_ok::skin-tone-2:"] = "\uD83D\uDE46\uD83C\uDFFC", + [":person_gesturing_ok::skin-tone-3:"] = "\uD83D\uDE46\uD83C\uDFFD", + [":person_gesturing_ok::skin-tone-4:"] = "\uD83D\uDE46\uD83C\uDFFE", + [":person_gesturing_ok::skin-tone-5:"] = "\uD83D\uDE46\uD83C\uDFFF", + [":person_gesturing_ok_tone1:"] = "\uD83D\uDE46\uD83C\uDFFB", + [":person_gesturing_ok_tone2:"] = "\uD83D\uDE46\uD83C\uDFFC", + [":person_gesturing_ok_tone3:"] = "\uD83D\uDE46\uD83C\uDFFD", + [":person_gesturing_ok_tone4:"] = "\uD83D\uDE46\uD83C\uDFFE", + [":person_gesturing_ok_tone5:"] = "\uD83D\uDE46\uD83C\uDFFF", + [":person_getting_haircut:"] = "\uD83D\uDC87", + [":person_getting_haircut::skin-tone-1:"] = "\uD83D\uDC87\uD83C\uDFFB", + [":person_getting_haircut::skin-tone-2:"] = "\uD83D\uDC87\uD83C\uDFFC", + [":person_getting_haircut::skin-tone-3:"] = "\uD83D\uDC87\uD83C\uDFFD", + [":person_getting_haircut::skin-tone-4:"] = "\uD83D\uDC87\uD83C\uDFFE", + [":person_getting_haircut::skin-tone-5:"] = "\uD83D\uDC87\uD83C\uDFFF", + [":person_getting_haircut_tone1:"] = "\uD83D\uDC87\uD83C\uDFFB", + [":person_getting_haircut_tone2:"] = "\uD83D\uDC87\uD83C\uDFFC", + [":person_getting_haircut_tone3:"] = "\uD83D\uDC87\uD83C\uDFFD", + [":person_getting_haircut_tone4:"] = "\uD83D\uDC87\uD83C\uDFFE", + [":person_getting_haircut_tone5:"] = "\uD83D\uDC87\uD83C\uDFFF", + [":person_getting_massage:"] = "\uD83D\uDC86", + [":person_getting_massage::skin-tone-1:"] = "\uD83D\uDC86\uD83C\uDFFB", + [":person_getting_massage::skin-tone-2:"] = "\uD83D\uDC86\uD83C\uDFFC", + [":person_getting_massage::skin-tone-3:"] = "\uD83D\uDC86\uD83C\uDFFD", + [":person_getting_massage::skin-tone-4:"] = "\uD83D\uDC86\uD83C\uDFFE", + [":person_getting_massage::skin-tone-5:"] = "\uD83D\uDC86\uD83C\uDFFF", + [":person_getting_massage_tone1:"] = "\uD83D\uDC86\uD83C\uDFFB", + [":person_getting_massage_tone2:"] = "\uD83D\uDC86\uD83C\uDFFC", + [":person_getting_massage_tone3:"] = "\uD83D\uDC86\uD83C\uDFFD", + [":person_getting_massage_tone4:"] = "\uD83D\uDC86\uD83C\uDFFE", + [":person_getting_massage_tone5:"] = "\uD83D\uDC86\uD83C\uDFFF", + [":person_golfing:"] = "\uD83C\uDFCC️", + [":person_golfing::skin-tone-1:"] = "\uD83C\uDFCC\uD83C\uDFFB", + [":person_golfing::skin-tone-2:"] = "\uD83C\uDFCC\uD83C\uDFFC", + [":person_golfing::skin-tone-3:"] = "\uD83C\uDFCC\uD83C\uDFFD", + [":person_golfing::skin-tone-4:"] = "\uD83C\uDFCC\uD83C\uDFFE", + [":person_golfing::skin-tone-5:"] = "\uD83C\uDFCC\uD83C\uDFFF", + [":person_golfing_dark_skin_tone:"] = "\uD83C\uDFCC\uD83C\uDFFF", + [":person_golfing_light_skin_tone:"] = "\uD83C\uDFCC\uD83C\uDFFB", + [":person_golfing_medium_dark_skin_tone:"] = "\uD83C\uDFCC\uD83C\uDFFE", + [":person_golfing_medium_light_skin_tone:"] = "\uD83C\uDFCC\uD83C\uDFFC", + [":person_golfing_medium_skin_tone:"] = "\uD83C\uDFCC\uD83C\uDFFD", + [":person_golfing_tone1:"] = "\uD83C\uDFCC\uD83C\uDFFB", + [":person_golfing_tone2:"] = "\uD83C\uDFCC\uD83C\uDFFC", + [":person_golfing_tone3:"] = "\uD83C\uDFCC\uD83C\uDFFD", + [":person_golfing_tone4:"] = "\uD83C\uDFCC\uD83C\uDFFE", + [":person_golfing_tone5:"] = "\uD83C\uDFCC\uD83C\uDFFF", + [":person_in_bed_dark_skin_tone:"] = "\uD83D\uDECC\uD83C\uDFFF", + [":person_in_bed_light_skin_tone:"] = "\uD83D\uDECC\uD83C\uDFFB", + [":person_in_bed_medium_dark_skin_tone:"] = "\uD83D\uDECC\uD83C\uDFFE", + [":person_in_bed_medium_light_skin_tone:"] = "\uD83D\uDECC\uD83C\uDFFC", + [":person_in_bed_medium_skin_tone:"] = "\uD83D\uDECC\uD83C\uDFFD", + [":person_in_bed_tone1:"] = "\uD83D\uDECC\uD83C\uDFFB", + [":person_in_bed_tone2:"] = "\uD83D\uDECC\uD83C\uDFFC", + [":person_in_bed_tone3:"] = "\uD83D\uDECC\uD83C\uDFFD", + [":person_in_bed_tone4:"] = "\uD83D\uDECC\uD83C\uDFFE", + [":person_in_bed_tone5:"] = "\uD83D\uDECC\uD83C\uDFFF", + [":person_in_lotus_position:"] = "\uD83E\uDDD8", + [":person_in_lotus_position::skin-tone-1:"] = "\uD83E\uDDD8\uD83C\uDFFB", + [":person_in_lotus_position::skin-tone-2:"] = "\uD83E\uDDD8\uD83C\uDFFC", + [":person_in_lotus_position::skin-tone-3:"] = "\uD83E\uDDD8\uD83C\uDFFD", + [":person_in_lotus_position::skin-tone-4:"] = "\uD83E\uDDD8\uD83C\uDFFE", + [":person_in_lotus_position::skin-tone-5:"] = "\uD83E\uDDD8\uD83C\uDFFF", + [":person_in_lotus_position_dark_skin_tone:"] = "\uD83E\uDDD8\uD83C\uDFFF", + [":person_in_lotus_position_light_skin_tone:"] = "\uD83E\uDDD8\uD83C\uDFFB", + [":person_in_lotus_position_medium_dark_skin_tone:"] = "\uD83E\uDDD8\uD83C\uDFFE", + [":person_in_lotus_position_medium_light_skin_tone:"] = "\uD83E\uDDD8\uD83C\uDFFC", + [":person_in_lotus_position_medium_skin_tone:"] = "\uD83E\uDDD8\uD83C\uDFFD", + [":person_in_lotus_position_tone1:"] = "\uD83E\uDDD8\uD83C\uDFFB", + [":person_in_lotus_position_tone2:"] = "\uD83E\uDDD8\uD83C\uDFFC", + [":person_in_lotus_position_tone3:"] = "\uD83E\uDDD8\uD83C\uDFFD", + [":person_in_lotus_position_tone4:"] = "\uD83E\uDDD8\uD83C\uDFFE", + [":person_in_lotus_position_tone5:"] = "\uD83E\uDDD8\uD83C\uDFFF", + [":person_in_steamy_room:"] = "\uD83E\uDDD6", + [":person_in_steamy_room::skin-tone-1:"] = "\uD83E\uDDD6\uD83C\uDFFB", + [":person_in_steamy_room::skin-tone-2:"] = "\uD83E\uDDD6\uD83C\uDFFC", + [":person_in_steamy_room::skin-tone-3:"] = "\uD83E\uDDD6\uD83C\uDFFD", + [":person_in_steamy_room::skin-tone-4:"] = "\uD83E\uDDD6\uD83C\uDFFE", + [":person_in_steamy_room::skin-tone-5:"] = "\uD83E\uDDD6\uD83C\uDFFF", + [":person_in_steamy_room_dark_skin_tone:"] = "\uD83E\uDDD6\uD83C\uDFFF", + [":person_in_steamy_room_light_skin_tone:"] = "\uD83E\uDDD6\uD83C\uDFFB", + [":person_in_steamy_room_medium_dark_skin_tone:"] = "\uD83E\uDDD6\uD83C\uDFFE", + [":person_in_steamy_room_medium_light_skin_tone:"] = "\uD83E\uDDD6\uD83C\uDFFC", + [":person_in_steamy_room_medium_skin_tone:"] = "\uD83E\uDDD6\uD83C\uDFFD", + [":person_in_steamy_room_tone1:"] = "\uD83E\uDDD6\uD83C\uDFFB", + [":person_in_steamy_room_tone2:"] = "\uD83E\uDDD6\uD83C\uDFFC", + [":person_in_steamy_room_tone3:"] = "\uD83E\uDDD6\uD83C\uDFFD", + [":person_in_steamy_room_tone4:"] = "\uD83E\uDDD6\uD83C\uDFFE", + [":person_in_steamy_room_tone5:"] = "\uD83E\uDDD6\uD83C\uDFFF", + [":person_juggling:"] = "\uD83E\uDD39", + [":person_juggling::skin-tone-1:"] = "\uD83E\uDD39\uD83C\uDFFB", + [":person_juggling::skin-tone-2:"] = "\uD83E\uDD39\uD83C\uDFFC", + [":person_juggling::skin-tone-3:"] = "\uD83E\uDD39\uD83C\uDFFD", + [":person_juggling::skin-tone-4:"] = "\uD83E\uDD39\uD83C\uDFFE", + [":person_juggling::skin-tone-5:"] = "\uD83E\uDD39\uD83C\uDFFF", + [":person_juggling_tone1:"] = "\uD83E\uDD39\uD83C\uDFFB", + [":person_juggling_tone2:"] = "\uD83E\uDD39\uD83C\uDFFC", + [":person_juggling_tone3:"] = "\uD83E\uDD39\uD83C\uDFFD", + [":person_juggling_tone4:"] = "\uD83E\uDD39\uD83C\uDFFE", + [":person_juggling_tone5:"] = "\uD83E\uDD39\uD83C\uDFFF", + [":person_kneeling:"] = "\uD83E\uDDCE", + [":person_kneeling::skin-tone-1:"] = "\uD83E\uDDCE\uD83C\uDFFB", + [":person_kneeling::skin-tone-2:"] = "\uD83E\uDDCE\uD83C\uDFFC", + [":person_kneeling::skin-tone-3:"] = "\uD83E\uDDCE\uD83C\uDFFD", + [":person_kneeling::skin-tone-4:"] = "\uD83E\uDDCE\uD83C\uDFFE", + [":person_kneeling::skin-tone-5:"] = "\uD83E\uDDCE\uD83C\uDFFF", + [":person_kneeling_dark_skin_tone:"] = "\uD83E\uDDCE\uD83C\uDFFF", + [":person_kneeling_light_skin_tone:"] = "\uD83E\uDDCE\uD83C\uDFFB", + [":person_kneeling_medium_dark_skin_tone:"] = "\uD83E\uDDCE\uD83C\uDFFE", + [":person_kneeling_medium_light_skin_tone:"] = "\uD83E\uDDCE\uD83C\uDFFC", + [":person_kneeling_medium_skin_tone:"] = "\uD83E\uDDCE\uD83C\uDFFD", + [":person_kneeling_tone1:"] = "\uD83E\uDDCE\uD83C\uDFFB", + [":person_kneeling_tone2:"] = "\uD83E\uDDCE\uD83C\uDFFC", + [":person_kneeling_tone3:"] = "\uD83E\uDDCE\uD83C\uDFFD", + [":person_kneeling_tone4:"] = "\uD83E\uDDCE\uD83C\uDFFE", + [":person_kneeling_tone5:"] = "\uD83E\uDDCE\uD83C\uDFFF", + [":person_lifting_weights:"] = "\uD83C\uDFCB️", + [":person_lifting_weights::skin-tone-1:"] = "\uD83C\uDFCB\uD83C\uDFFB", + [":person_lifting_weights::skin-tone-2:"] = "\uD83C\uDFCB\uD83C\uDFFC", + [":person_lifting_weights::skin-tone-3:"] = "\uD83C\uDFCB\uD83C\uDFFD", + [":person_lifting_weights::skin-tone-4:"] = "\uD83C\uDFCB\uD83C\uDFFE", + [":person_lifting_weights::skin-tone-5:"] = "\uD83C\uDFCB\uD83C\uDFFF", + [":person_lifting_weights_tone1:"] = "\uD83C\uDFCB\uD83C\uDFFB", + [":person_lifting_weights_tone2:"] = "\uD83C\uDFCB\uD83C\uDFFC", + [":person_lifting_weights_tone3:"] = "\uD83C\uDFCB\uD83C\uDFFD", + [":person_lifting_weights_tone4:"] = "\uD83C\uDFCB\uD83C\uDFFE", + [":person_lifting_weights_tone5:"] = "\uD83C\uDFCB\uD83C\uDFFF", + [":person_mountain_biking:"] = "\uD83D\uDEB5", + [":person_mountain_biking::skin-tone-1:"] = "\uD83D\uDEB5\uD83C\uDFFB", + [":person_mountain_biking::skin-tone-2:"] = "\uD83D\uDEB5\uD83C\uDFFC", + [":person_mountain_biking::skin-tone-3:"] = "\uD83D\uDEB5\uD83C\uDFFD", + [":person_mountain_biking::skin-tone-4:"] = "\uD83D\uDEB5\uD83C\uDFFE", + [":person_mountain_biking::skin-tone-5:"] = "\uD83D\uDEB5\uD83C\uDFFF", + [":person_mountain_biking_tone1:"] = "\uD83D\uDEB5\uD83C\uDFFB", + [":person_mountain_biking_tone2:"] = "\uD83D\uDEB5\uD83C\uDFFC", + [":person_mountain_biking_tone3:"] = "\uD83D\uDEB5\uD83C\uDFFD", + [":person_mountain_biking_tone4:"] = "\uD83D\uDEB5\uD83C\uDFFE", + [":person_mountain_biking_tone5:"] = "\uD83D\uDEB5\uD83C\uDFFF", + [":person_playing_handball:"] = "\uD83E\uDD3E", + [":person_playing_handball::skin-tone-1:"] = "\uD83E\uDD3E\uD83C\uDFFB", + [":person_playing_handball::skin-tone-2:"] = "\uD83E\uDD3E\uD83C\uDFFC", + [":person_playing_handball::skin-tone-3:"] = "\uD83E\uDD3E\uD83C\uDFFD", + [":person_playing_handball::skin-tone-4:"] = "\uD83E\uDD3E\uD83C\uDFFE", + [":person_playing_handball::skin-tone-5:"] = "\uD83E\uDD3E\uD83C\uDFFF", + [":person_playing_handball_tone1:"] = "\uD83E\uDD3E\uD83C\uDFFB", + [":person_playing_handball_tone2:"] = "\uD83E\uDD3E\uD83C\uDFFC", + [":person_playing_handball_tone3:"] = "\uD83E\uDD3E\uD83C\uDFFD", + [":person_playing_handball_tone4:"] = "\uD83E\uDD3E\uD83C\uDFFE", + [":person_playing_handball_tone5:"] = "\uD83E\uDD3E\uD83C\uDFFF", + [":person_playing_water_polo:"] = "\uD83E\uDD3D", + [":person_playing_water_polo::skin-tone-1:"] = "\uD83E\uDD3D\uD83C\uDFFB", + [":person_playing_water_polo::skin-tone-2:"] = "\uD83E\uDD3D\uD83C\uDFFC", + [":person_playing_water_polo::skin-tone-3:"] = "\uD83E\uDD3D\uD83C\uDFFD", + [":person_playing_water_polo::skin-tone-4:"] = "\uD83E\uDD3D\uD83C\uDFFE", + [":person_playing_water_polo::skin-tone-5:"] = "\uD83E\uDD3D\uD83C\uDFFF", + [":person_playing_water_polo_tone1:"] = "\uD83E\uDD3D\uD83C\uDFFB", + [":person_playing_water_polo_tone2:"] = "\uD83E\uDD3D\uD83C\uDFFC", + [":person_playing_water_polo_tone3:"] = "\uD83E\uDD3D\uD83C\uDFFD", + [":person_playing_water_polo_tone4:"] = "\uD83E\uDD3D\uD83C\uDFFE", + [":person_playing_water_polo_tone5:"] = "\uD83E\uDD3D\uD83C\uDFFF", + [":person_pouting:"] = "\uD83D\uDE4E", + [":person_pouting::skin-tone-1:"] = "\uD83D\uDE4E\uD83C\uDFFB", + [":person_pouting::skin-tone-2:"] = "\uD83D\uDE4E\uD83C\uDFFC", + [":person_pouting::skin-tone-3:"] = "\uD83D\uDE4E\uD83C\uDFFD", + [":person_pouting::skin-tone-4:"] = "\uD83D\uDE4E\uD83C\uDFFE", + [":person_pouting::skin-tone-5:"] = "\uD83D\uDE4E\uD83C\uDFFF", + [":person_pouting_tone1:"] = "\uD83D\uDE4E\uD83C\uDFFB", + [":person_pouting_tone2:"] = "\uD83D\uDE4E\uD83C\uDFFC", + [":person_pouting_tone3:"] = "\uD83D\uDE4E\uD83C\uDFFD", + [":person_pouting_tone4:"] = "\uD83D\uDE4E\uD83C\uDFFE", + [":person_pouting_tone5:"] = "\uD83D\uDE4E\uD83C\uDFFF", + [":person_raising_hand:"] = "\uD83D\uDE4B", + [":person_raising_hand::skin-tone-1:"] = "\uD83D\uDE4B\uD83C\uDFFB", + [":person_raising_hand::skin-tone-2:"] = "\uD83D\uDE4B\uD83C\uDFFC", + [":person_raising_hand::skin-tone-3:"] = "\uD83D\uDE4B\uD83C\uDFFD", + [":person_raising_hand::skin-tone-4:"] = "\uD83D\uDE4B\uD83C\uDFFE", + [":person_raising_hand::skin-tone-5:"] = "\uD83D\uDE4B\uD83C\uDFFF", + [":person_raising_hand_tone1:"] = "\uD83D\uDE4B\uD83C\uDFFB", + [":person_raising_hand_tone2:"] = "\uD83D\uDE4B\uD83C\uDFFC", + [":person_raising_hand_tone3:"] = "\uD83D\uDE4B\uD83C\uDFFD", + [":person_raising_hand_tone4:"] = "\uD83D\uDE4B\uD83C\uDFFE", + [":person_raising_hand_tone5:"] = "\uD83D\uDE4B\uD83C\uDFFF", + [":person_rowing_boat:"] = "\uD83D\uDEA3", + [":person_rowing_boat::skin-tone-1:"] = "\uD83D\uDEA3\uD83C\uDFFB", + [":person_rowing_boat::skin-tone-2:"] = "\uD83D\uDEA3\uD83C\uDFFC", + [":person_rowing_boat::skin-tone-3:"] = "\uD83D\uDEA3\uD83C\uDFFD", + [":person_rowing_boat::skin-tone-4:"] = "\uD83D\uDEA3\uD83C\uDFFE", + [":person_rowing_boat::skin-tone-5:"] = "\uD83D\uDEA3\uD83C\uDFFF", + [":person_rowing_boat_tone1:"] = "\uD83D\uDEA3\uD83C\uDFFB", + [":person_rowing_boat_tone2:"] = "\uD83D\uDEA3\uD83C\uDFFC", + [":person_rowing_boat_tone3:"] = "\uD83D\uDEA3\uD83C\uDFFD", + [":person_rowing_boat_tone4:"] = "\uD83D\uDEA3\uD83C\uDFFE", + [":person_rowing_boat_tone5:"] = "\uD83D\uDEA3\uD83C\uDFFF", + [":person_running:"] = "\uD83C\uDFC3", + [":person_running::skin-tone-1:"] = "\uD83C\uDFC3\uD83C\uDFFB", + [":person_running::skin-tone-2:"] = "\uD83C\uDFC3\uD83C\uDFFC", + [":person_running::skin-tone-3:"] = "\uD83C\uDFC3\uD83C\uDFFD", + [":person_running::skin-tone-4:"] = "\uD83C\uDFC3\uD83C\uDFFE", + [":person_running::skin-tone-5:"] = "\uD83C\uDFC3\uD83C\uDFFF", + [":person_running_tone1:"] = "\uD83C\uDFC3\uD83C\uDFFB", + [":person_running_tone2:"] = "\uD83C\uDFC3\uD83C\uDFFC", + [":person_running_tone3:"] = "\uD83C\uDFC3\uD83C\uDFFD", + [":person_running_tone4:"] = "\uD83C\uDFC3\uD83C\uDFFE", + [":person_running_tone5:"] = "\uD83C\uDFC3\uD83C\uDFFF", + [":person_shrugging:"] = "\uD83E\uDD37", + [":person_shrugging::skin-tone-1:"] = "\uD83E\uDD37\uD83C\uDFFB", + [":person_shrugging::skin-tone-2:"] = "\uD83E\uDD37\uD83C\uDFFC", + [":person_shrugging::skin-tone-3:"] = "\uD83E\uDD37\uD83C\uDFFD", + [":person_shrugging::skin-tone-4:"] = "\uD83E\uDD37\uD83C\uDFFE", + [":person_shrugging::skin-tone-5:"] = "\uD83E\uDD37\uD83C\uDFFF", + [":person_shrugging_tone1:"] = "\uD83E\uDD37\uD83C\uDFFB", + [":person_shrugging_tone2:"] = "\uD83E\uDD37\uD83C\uDFFC", + [":person_shrugging_tone3:"] = "\uD83E\uDD37\uD83C\uDFFD", + [":person_shrugging_tone4:"] = "\uD83E\uDD37\uD83C\uDFFE", + [":person_shrugging_tone5:"] = "\uD83E\uDD37\uD83C\uDFFF", + [":person_standing:"] = "\uD83E\uDDCD", + [":person_standing::skin-tone-1:"] = "\uD83E\uDDCD\uD83C\uDFFB", + [":person_standing::skin-tone-2:"] = "\uD83E\uDDCD\uD83C\uDFFC", + [":person_standing::skin-tone-3:"] = "\uD83E\uDDCD\uD83C\uDFFD", + [":person_standing::skin-tone-4:"] = "\uD83E\uDDCD\uD83C\uDFFE", + [":person_standing::skin-tone-5:"] = "\uD83E\uDDCD\uD83C\uDFFF", + [":person_standing_dark_skin_tone:"] = "\uD83E\uDDCD\uD83C\uDFFF", + [":person_standing_light_skin_tone:"] = "\uD83E\uDDCD\uD83C\uDFFB", + [":person_standing_medium_dark_skin_tone:"] = "\uD83E\uDDCD\uD83C\uDFFE", + [":person_standing_medium_light_skin_tone:"] = "\uD83E\uDDCD\uD83C\uDFFC", + [":person_standing_medium_skin_tone:"] = "\uD83E\uDDCD\uD83C\uDFFD", + [":person_standing_tone1:"] = "\uD83E\uDDCD\uD83C\uDFFB", + [":person_standing_tone2:"] = "\uD83E\uDDCD\uD83C\uDFFC", + [":person_standing_tone3:"] = "\uD83E\uDDCD\uD83C\uDFFD", + [":person_standing_tone4:"] = "\uD83E\uDDCD\uD83C\uDFFE", + [":person_standing_tone5:"] = "\uD83E\uDDCD\uD83C\uDFFF", + [":person_surfing:"] = "\uD83C\uDFC4", + [":person_surfing::skin-tone-1:"] = "\uD83C\uDFC4\uD83C\uDFFB", + [":person_surfing::skin-tone-2:"] = "\uD83C\uDFC4\uD83C\uDFFC", + [":person_surfing::skin-tone-3:"] = "\uD83C\uDFC4\uD83C\uDFFD", + [":person_surfing::skin-tone-4:"] = "\uD83C\uDFC4\uD83C\uDFFE", + [":person_surfing::skin-tone-5:"] = "\uD83C\uDFC4\uD83C\uDFFF", + [":person_surfing_tone1:"] = "\uD83C\uDFC4\uD83C\uDFFB", + [":person_surfing_tone2:"] = "\uD83C\uDFC4\uD83C\uDFFC", + [":person_surfing_tone3:"] = "\uD83C\uDFC4\uD83C\uDFFD", + [":person_surfing_tone4:"] = "\uD83C\uDFC4\uD83C\uDFFE", + [":person_surfing_tone5:"] = "\uD83C\uDFC4\uD83C\uDFFF", + [":person_swimming:"] = "\uD83C\uDFCA", + [":person_swimming::skin-tone-1:"] = "\uD83C\uDFCA\uD83C\uDFFB", + [":person_swimming::skin-tone-2:"] = "\uD83C\uDFCA\uD83C\uDFFC", + [":person_swimming::skin-tone-3:"] = "\uD83C\uDFCA\uD83C\uDFFD", + [":person_swimming::skin-tone-4:"] = "\uD83C\uDFCA\uD83C\uDFFE", + [":person_swimming::skin-tone-5:"] = "\uD83C\uDFCA\uD83C\uDFFF", + [":person_swimming_tone1:"] = "\uD83C\uDFCA\uD83C\uDFFB", + [":person_swimming_tone2:"] = "\uD83C\uDFCA\uD83C\uDFFC", + [":person_swimming_tone3:"] = "\uD83C\uDFCA\uD83C\uDFFD", + [":person_swimming_tone4:"] = "\uD83C\uDFCA\uD83C\uDFFE", + [":person_swimming_tone5:"] = "\uD83C\uDFCA\uD83C\uDFFF", + [":person_tipping_hand:"] = "\uD83D\uDC81", + [":person_tipping_hand::skin-tone-1:"] = "\uD83D\uDC81\uD83C\uDFFB", + [":person_tipping_hand::skin-tone-2:"] = "\uD83D\uDC81\uD83C\uDFFC", + [":person_tipping_hand::skin-tone-3:"] = "\uD83D\uDC81\uD83C\uDFFD", + [":person_tipping_hand::skin-tone-4:"] = "\uD83D\uDC81\uD83C\uDFFE", + [":person_tipping_hand::skin-tone-5:"] = "\uD83D\uDC81\uD83C\uDFFF", + [":person_tipping_hand_tone1:"] = "\uD83D\uDC81\uD83C\uDFFB", + [":person_tipping_hand_tone2:"] = "\uD83D\uDC81\uD83C\uDFFC", + [":person_tipping_hand_tone3:"] = "\uD83D\uDC81\uD83C\uDFFD", + [":person_tipping_hand_tone4:"] = "\uD83D\uDC81\uD83C\uDFFE", + [":person_tipping_hand_tone5:"] = "\uD83D\uDC81\uD83C\uDFFF", + [":person_walking:"] = "\uD83D\uDEB6", + [":person_walking::skin-tone-1:"] = "\uD83D\uDEB6\uD83C\uDFFB", + [":person_walking::skin-tone-2:"] = "\uD83D\uDEB6\uD83C\uDFFC", + [":person_walking::skin-tone-3:"] = "\uD83D\uDEB6\uD83C\uDFFD", + [":person_walking::skin-tone-4:"] = "\uD83D\uDEB6\uD83C\uDFFE", + [":person_walking::skin-tone-5:"] = "\uD83D\uDEB6\uD83C\uDFFF", + [":person_walking_tone1:"] = "\uD83D\uDEB6\uD83C\uDFFB", + [":person_walking_tone2:"] = "\uD83D\uDEB6\uD83C\uDFFC", + [":person_walking_tone3:"] = "\uD83D\uDEB6\uD83C\uDFFD", + [":person_walking_tone4:"] = "\uD83D\uDEB6\uD83C\uDFFE", + [":person_walking_tone5:"] = "\uD83D\uDEB6\uD83C\uDFFF", + [":person_wearing_turban:"] = "\uD83D\uDC73", + [":person_wearing_turban::skin-tone-1:"] = "\uD83D\uDC73\uD83C\uDFFB", + [":person_wearing_turban::skin-tone-2:"] = "\uD83D\uDC73\uD83C\uDFFC", + [":person_wearing_turban::skin-tone-3:"] = "\uD83D\uDC73\uD83C\uDFFD", + [":person_wearing_turban::skin-tone-4:"] = "\uD83D\uDC73\uD83C\uDFFE", + [":person_wearing_turban::skin-tone-5:"] = "\uD83D\uDC73\uD83C\uDFFF", + [":person_wearing_turban_tone1:"] = "\uD83D\uDC73\uD83C\uDFFB", + [":person_wearing_turban_tone2:"] = "\uD83D\uDC73\uD83C\uDFFC", + [":person_wearing_turban_tone3:"] = "\uD83D\uDC73\uD83C\uDFFD", + [":person_wearing_turban_tone4:"] = "\uD83D\uDC73\uD83C\uDFFE", + [":person_wearing_turban_tone5:"] = "\uD83D\uDC73\uD83C\uDFFF", + [":person_with_ball:"] = "⛹️", + [":person_with_ball::skin-tone-1:"] = "⛹\uD83C\uDFFB", + [":person_with_ball::skin-tone-2:"] = "⛹\uD83C\uDFFC", + [":person_with_ball::skin-tone-3:"] = "⛹\uD83C\uDFFD", + [":person_with_ball::skin-tone-4:"] = "⛹\uD83C\uDFFE", + [":person_with_ball::skin-tone-5:"] = "⛹\uD83C\uDFFF", + [":person_with_ball_tone1:"] = "⛹\uD83C\uDFFB", + [":person_with_ball_tone2:"] = "⛹\uD83C\uDFFC", + [":person_with_ball_tone3:"] = "⛹\uD83C\uDFFD", + [":person_with_ball_tone4:"] = "⛹\uD83C\uDFFE", + [":person_with_ball_tone5:"] = "⛹\uD83C\uDFFF", + [":person_with_blond_hair:"] = "\uD83D\uDC71", + [":person_with_blond_hair::skin-tone-1:"] = "\uD83D\uDC71\uD83C\uDFFB", + [":person_with_blond_hair::skin-tone-2:"] = "\uD83D\uDC71\uD83C\uDFFC", + [":person_with_blond_hair::skin-tone-3:"] = "\uD83D\uDC71\uD83C\uDFFD", + [":person_with_blond_hair::skin-tone-4:"] = "\uD83D\uDC71\uD83C\uDFFE", + [":person_with_blond_hair::skin-tone-5:"] = "\uD83D\uDC71\uD83C\uDFFF", + [":person_with_blond_hair_tone1:"] = "\uD83D\uDC71\uD83C\uDFFB", + [":person_with_blond_hair_tone2:"] = "\uD83D\uDC71\uD83C\uDFFC", + [":person_with_blond_hair_tone3:"] = "\uD83D\uDC71\uD83C\uDFFD", + [":person_with_blond_hair_tone4:"] = "\uD83D\uDC71\uD83C\uDFFE", + [":person_with_blond_hair_tone5:"] = "\uD83D\uDC71\uD83C\uDFFF", + [":person_with_pouting_face:"] = "\uD83D\uDE4E", + [":person_with_pouting_face::skin-tone-1:"] = "\uD83D\uDE4E\uD83C\uDFFB", + [":person_with_pouting_face::skin-tone-2:"] = "\uD83D\uDE4E\uD83C\uDFFC", + [":person_with_pouting_face::skin-tone-3:"] = "\uD83D\uDE4E\uD83C\uDFFD", + [":person_with_pouting_face::skin-tone-4:"] = "\uD83D\uDE4E\uD83C\uDFFE", + [":person_with_pouting_face::skin-tone-5:"] = "\uD83D\uDE4E\uD83C\uDFFF", + [":person_with_pouting_face_tone1:"] = "\uD83D\uDE4E\uD83C\uDFFB", + [":person_with_pouting_face_tone2:"] = "\uD83D\uDE4E\uD83C\uDFFC", + [":person_with_pouting_face_tone3:"] = "\uD83D\uDE4E\uD83C\uDFFD", + [":person_with_pouting_face_tone4:"] = "\uD83D\uDE4E\uD83C\uDFFE", + [":person_with_pouting_face_tone5:"] = "\uD83D\uDE4E\uD83C\uDFFF", + [":petri_dish:"] = "\uD83E\uDDEB", + [":pick:"] = "⛏️", + [":pie:"] = "\uD83E\uDD67", + [":pig2:"] = "\uD83D\uDC16", + [":pig:"] = "\uD83D\uDC37", + [":pig_nose:"] = "\uD83D\uDC3D", + [":pill:"] = "\uD83D\uDC8A", + [":pinching_hand:"] = "\uD83E\uDD0F", + [":pinching_hand::skin-tone-1:"] = "\uD83E\uDD0F\uD83C\uDFFB", + [":pinching_hand::skin-tone-2:"] = "\uD83E\uDD0F\uD83C\uDFFC", + [":pinching_hand::skin-tone-3:"] = "\uD83E\uDD0F\uD83C\uDFFD", + [":pinching_hand::skin-tone-4:"] = "\uD83E\uDD0F\uD83C\uDFFE", + [":pinching_hand::skin-tone-5:"] = "\uD83E\uDD0F\uD83C\uDFFF", + [":pinching_hand_dark_skin_tone:"] = "\uD83E\uDD0F\uD83C\uDFFF", + [":pinching_hand_light_skin_tone:"] = "\uD83E\uDD0F\uD83C\uDFFB", + [":pinching_hand_medium_dark_skin_tone:"] = "\uD83E\uDD0F\uD83C\uDFFE", + [":pinching_hand_medium_light_skin_tone:"] = "\uD83E\uDD0F\uD83C\uDFFC", + [":pinching_hand_medium_skin_tone:"] = "\uD83E\uDD0F\uD83C\uDFFD", + [":pinching_hand_tone1:"] = "\uD83E\uDD0F\uD83C\uDFFB", + [":pinching_hand_tone2:"] = "\uD83E\uDD0F\uD83C\uDFFC", + [":pinching_hand_tone3:"] = "\uD83E\uDD0F\uD83C\uDFFD", + [":pinching_hand_tone4:"] = "\uD83E\uDD0F\uD83C\uDFFE", + [":pinching_hand_tone5:"] = "\uD83E\uDD0F\uD83C\uDFFF", + [":pineapple:"] = "\uD83C\uDF4D", + [":ping_pong:"] = "\uD83C\uDFD3", + [":pirate_flag:"] = "\uD83C\uDFF4\u200D☠️", + [":pisces:"] = "♓", + [":pizza:"] = "\uD83C\uDF55", + [":place_of_worship:"] = "\uD83D\uDED0", + [":play_pause:"] = "⏯️", + [":pleading_face:"] = "\uD83E\uDD7A", + [":point_down:"] = "\uD83D\uDC47", + [":point_down::skin-tone-1:"] = "\uD83D\uDC47\uD83C\uDFFB", + [":point_down::skin-tone-2:"] = "\uD83D\uDC47\uD83C\uDFFC", + [":point_down::skin-tone-3:"] = "\uD83D\uDC47\uD83C\uDFFD", + [":point_down::skin-tone-4:"] = "\uD83D\uDC47\uD83C\uDFFE", + [":point_down::skin-tone-5:"] = "\uD83D\uDC47\uD83C\uDFFF", + [":point_down_tone1:"] = "\uD83D\uDC47\uD83C\uDFFB", + [":point_down_tone2:"] = "\uD83D\uDC47\uD83C\uDFFC", + [":point_down_tone3:"] = "\uD83D\uDC47\uD83C\uDFFD", + [":point_down_tone4:"] = "\uD83D\uDC47\uD83C\uDFFE", + [":point_down_tone5:"] = "\uD83D\uDC47\uD83C\uDFFF", + [":point_left:"] = "\uD83D\uDC48", + [":point_left::skin-tone-1:"] = "\uD83D\uDC48\uD83C\uDFFB", + [":point_left::skin-tone-2:"] = "\uD83D\uDC48\uD83C\uDFFC", + [":point_left::skin-tone-3:"] = "\uD83D\uDC48\uD83C\uDFFD", + [":point_left::skin-tone-4:"] = "\uD83D\uDC48\uD83C\uDFFE", + [":point_left::skin-tone-5:"] = "\uD83D\uDC48\uD83C\uDFFF", + [":point_left_tone1:"] = "\uD83D\uDC48\uD83C\uDFFB", + [":point_left_tone2:"] = "\uD83D\uDC48\uD83C\uDFFC", + [":point_left_tone3:"] = "\uD83D\uDC48\uD83C\uDFFD", + [":point_left_tone4:"] = "\uD83D\uDC48\uD83C\uDFFE", + [":point_left_tone5:"] = "\uD83D\uDC48\uD83C\uDFFF", + [":point_right:"] = "\uD83D\uDC49", + [":point_right::skin-tone-1:"] = "\uD83D\uDC49\uD83C\uDFFB", + [":point_right::skin-tone-2:"] = "\uD83D\uDC49\uD83C\uDFFC", + [":point_right::skin-tone-3:"] = "\uD83D\uDC49\uD83C\uDFFD", + [":point_right::skin-tone-4:"] = "\uD83D\uDC49\uD83C\uDFFE", + [":point_right::skin-tone-5:"] = "\uD83D\uDC49\uD83C\uDFFF", + [":point_right_tone1:"] = "\uD83D\uDC49\uD83C\uDFFB", + [":point_right_tone2:"] = "\uD83D\uDC49\uD83C\uDFFC", + [":point_right_tone3:"] = "\uD83D\uDC49\uD83C\uDFFD", + [":point_right_tone4:"] = "\uD83D\uDC49\uD83C\uDFFE", + [":point_right_tone5:"] = "\uD83D\uDC49\uD83C\uDFFF", + [":point_up:"] = "☝️", + [":point_up::skin-tone-1:"] = "☝\uD83C\uDFFB", + [":point_up::skin-tone-2:"] = "☝\uD83C\uDFFC", + [":point_up::skin-tone-3:"] = "☝\uD83C\uDFFD", + [":point_up::skin-tone-4:"] = "☝\uD83C\uDFFE", + [":point_up::skin-tone-5:"] = "☝\uD83C\uDFFF", + [":point_up_2:"] = "\uD83D\uDC46", + [":point_up_2::skin-tone-1:"] = "\uD83D\uDC46\uD83C\uDFFB", + [":point_up_2::skin-tone-2:"] = "\uD83D\uDC46\uD83C\uDFFC", + [":point_up_2::skin-tone-3:"] = "\uD83D\uDC46\uD83C\uDFFD", + [":point_up_2::skin-tone-4:"] = "\uD83D\uDC46\uD83C\uDFFE", + [":point_up_2::skin-tone-5:"] = "\uD83D\uDC46\uD83C\uDFFF", + [":point_up_2_tone1:"] = "\uD83D\uDC46\uD83C\uDFFB", + [":point_up_2_tone2:"] = "\uD83D\uDC46\uD83C\uDFFC", + [":point_up_2_tone3:"] = "\uD83D\uDC46\uD83C\uDFFD", + [":point_up_2_tone4:"] = "\uD83D\uDC46\uD83C\uDFFE", + [":point_up_2_tone5:"] = "\uD83D\uDC46\uD83C\uDFFF", + [":point_up_tone1:"] = "☝\uD83C\uDFFB", + [":point_up_tone2:"] = "☝\uD83C\uDFFC", + [":point_up_tone3:"] = "☝\uD83C\uDFFD", + [":point_up_tone4:"] = "☝\uD83C\uDFFE", + [":point_up_tone5:"] = "☝\uD83C\uDFFF", + [":police_car:"] = "\uD83D\uDE93", + [":police_officer:"] = "\uD83D\uDC6E", + [":police_officer::skin-tone-1:"] = "\uD83D\uDC6E\uD83C\uDFFB", + [":police_officer::skin-tone-2:"] = "\uD83D\uDC6E\uD83C\uDFFC", + [":police_officer::skin-tone-3:"] = "\uD83D\uDC6E\uD83C\uDFFD", + [":police_officer::skin-tone-4:"] = "\uD83D\uDC6E\uD83C\uDFFE", + [":police_officer::skin-tone-5:"] = "\uD83D\uDC6E\uD83C\uDFFF", + [":police_officer_tone1:"] = "\uD83D\uDC6E\uD83C\uDFFB", + [":police_officer_tone2:"] = "\uD83D\uDC6E\uD83C\uDFFC", + [":police_officer_tone3:"] = "\uD83D\uDC6E\uD83C\uDFFD", + [":police_officer_tone4:"] = "\uD83D\uDC6E\uD83C\uDFFE", + [":police_officer_tone5:"] = "\uD83D\uDC6E\uD83C\uDFFF", + [":poo:"] = "\uD83D\uDCA9", + [":poodle:"] = "\uD83D\uDC29", + [":poop:"] = "\uD83D\uDCA9", + [":popcorn:"] = "\uD83C\uDF7F", + [":post_office:"] = "\uD83C\uDFE3", + [":postal_horn:"] = "\uD83D\uDCEF", + [":postbox:"] = "\uD83D\uDCEE", + [":potable_water:"] = "\uD83D\uDEB0", + [":potato:"] = "\uD83E\uDD54", + [":pouch:"] = "\uD83D\uDC5D", + [":poultry_leg:"] = "\uD83C\uDF57", + [":pound:"] = "\uD83D\uDCB7", + [":pouting_cat:"] = "\uD83D\uDE3E", + [":pray:"] = "\uD83D\uDE4F", + [":pray::skin-tone-1:"] = "\uD83D\uDE4F\uD83C\uDFFB", + [":pray::skin-tone-2:"] = "\uD83D\uDE4F\uD83C\uDFFC", + [":pray::skin-tone-3:"] = "\uD83D\uDE4F\uD83C\uDFFD", + [":pray::skin-tone-4:"] = "\uD83D\uDE4F\uD83C\uDFFE", + [":pray::skin-tone-5:"] = "\uD83D\uDE4F\uD83C\uDFFF", + [":pray_tone1:"] = "\uD83D\uDE4F\uD83C\uDFFB", + [":pray_tone2:"] = "\uD83D\uDE4F\uD83C\uDFFC", + [":pray_tone3:"] = "\uD83D\uDE4F\uD83C\uDFFD", + [":pray_tone4:"] = "\uD83D\uDE4F\uD83C\uDFFE", + [":pray_tone5:"] = "\uD83D\uDE4F\uD83C\uDFFF", + [":prayer_beads:"] = "\uD83D\uDCFF", + [":pregnant_woman:"] = "\uD83E\uDD30", + [":pregnant_woman::skin-tone-1:"] = "\uD83E\uDD30\uD83C\uDFFB", + [":pregnant_woman::skin-tone-2:"] = "\uD83E\uDD30\uD83C\uDFFC", + [":pregnant_woman::skin-tone-3:"] = "\uD83E\uDD30\uD83C\uDFFD", + [":pregnant_woman::skin-tone-4:"] = "\uD83E\uDD30\uD83C\uDFFE", + [":pregnant_woman::skin-tone-5:"] = "\uD83E\uDD30\uD83C\uDFFF", + [":pregnant_woman_tone1:"] = "\uD83E\uDD30\uD83C\uDFFB", + [":pregnant_woman_tone2:"] = "\uD83E\uDD30\uD83C\uDFFC", + [":pregnant_woman_tone3:"] = "\uD83E\uDD30\uD83C\uDFFD", + [":pregnant_woman_tone4:"] = "\uD83E\uDD30\uD83C\uDFFE", + [":pregnant_woman_tone5:"] = "\uD83E\uDD30\uD83C\uDFFF", + [":pretzel:"] = "\uD83E\uDD68", + [":previous_track:"] = "⏮️", + [":prince:"] = "\uD83E\uDD34", + [":prince::skin-tone-1:"] = "\uD83E\uDD34\uD83C\uDFFB", + [":prince::skin-tone-2:"] = "\uD83E\uDD34\uD83C\uDFFC", + [":prince::skin-tone-3:"] = "\uD83E\uDD34\uD83C\uDFFD", + [":prince::skin-tone-4:"] = "\uD83E\uDD34\uD83C\uDFFE", + [":prince::skin-tone-5:"] = "\uD83E\uDD34\uD83C\uDFFF", + [":prince_tone1:"] = "\uD83E\uDD34\uD83C\uDFFB", + [":prince_tone2:"] = "\uD83E\uDD34\uD83C\uDFFC", + [":prince_tone3:"] = "\uD83E\uDD34\uD83C\uDFFD", + [":prince_tone4:"] = "\uD83E\uDD34\uD83C\uDFFE", + [":prince_tone5:"] = "\uD83E\uDD34\uD83C\uDFFF", + [":princess:"] = "\uD83D\uDC78", + [":princess::skin-tone-1:"] = "\uD83D\uDC78\uD83C\uDFFB", + [":princess::skin-tone-2:"] = "\uD83D\uDC78\uD83C\uDFFC", + [":princess::skin-tone-3:"] = "\uD83D\uDC78\uD83C\uDFFD", + [":princess::skin-tone-4:"] = "\uD83D\uDC78\uD83C\uDFFE", + [":princess::skin-tone-5:"] = "\uD83D\uDC78\uD83C\uDFFF", + [":princess_tone1:"] = "\uD83D\uDC78\uD83C\uDFFB", + [":princess_tone2:"] = "\uD83D\uDC78\uD83C\uDFFC", + [":princess_tone3:"] = "\uD83D\uDC78\uD83C\uDFFD", + [":princess_tone4:"] = "\uD83D\uDC78\uD83C\uDFFE", + [":princess_tone5:"] = "\uD83D\uDC78\uD83C\uDFFF", + [":printer:"] = "\uD83D\uDDA8️", + [":probing_cane:"] = "\uD83E\uDDAF", + [":projector:"] = "\uD83D\uDCFD️", + [":pudding:"] = "\uD83C\uDF6E", + [":punch:"] = "\uD83D\uDC4A", + [":punch::skin-tone-1:"] = "\uD83D\uDC4A\uD83C\uDFFB", + [":punch::skin-tone-2:"] = "\uD83D\uDC4A\uD83C\uDFFC", + [":punch::skin-tone-3:"] = "\uD83D\uDC4A\uD83C\uDFFD", + [":punch::skin-tone-4:"] = "\uD83D\uDC4A\uD83C\uDFFE", + [":punch::skin-tone-5:"] = "\uD83D\uDC4A\uD83C\uDFFF", + [":punch_tone1:"] = "\uD83D\uDC4A\uD83C\uDFFB", + [":punch_tone2:"] = "\uD83D\uDC4A\uD83C\uDFFC", + [":punch_tone3:"] = "\uD83D\uDC4A\uD83C\uDFFD", + [":punch_tone4:"] = "\uD83D\uDC4A\uD83C\uDFFE", + [":punch_tone5:"] = "\uD83D\uDC4A\uD83C\uDFFF", + [":purple_circle:"] = "\uD83D\uDFE3", + [":purple_heart:"] = "\uD83D\uDC9C", + [":purple_square:"] = "\uD83D\uDFEA", + [":purse:"] = "\uD83D\uDC5B", + [":pushpin:"] = "\uD83D\uDCCC", + [":put_litter_in_its_place:"] = "\uD83D\uDEAE", + [":question:"] = "❓", + [":rabbit2:"] = "\uD83D\uDC07", + [":rabbit:"] = "\uD83D\uDC30", + [":raccoon:"] = "\uD83E\uDD9D", + [":race_car:"] = "\uD83C\uDFCE️", + [":racehorse:"] = "\uD83D\uDC0E", + [":racing_car:"] = "\uD83C\uDFCE️", + [":racing_motorcycle:"] = "\uD83C\uDFCD️", + [":radio:"] = "\uD83D\uDCFB", + [":radio_button:"] = "\uD83D\uDD18", + [":radioactive:"] = "☢️", + [":radioactive_sign:"] = "☢️", + [":rage:"] = "\uD83D\uDE21", + [":railroad_track:"] = "\uD83D\uDEE4️", + [":railway_car:"] = "\uD83D\uDE83", + [":railway_track:"] = "\uD83D\uDEE4️", + [":rainbow:"] = "\uD83C\uDF08", + [":rainbow_flag:"] = "\uD83C\uDFF3️\u200D\uD83C\uDF08", + [":raised_back_of_hand:"] = "\uD83E\uDD1A", + [":raised_back_of_hand::skin-tone-1:"] = "\uD83E\uDD1A\uD83C\uDFFB", + [":raised_back_of_hand::skin-tone-2:"] = "\uD83E\uDD1A\uD83C\uDFFC", + [":raised_back_of_hand::skin-tone-3:"] = "\uD83E\uDD1A\uD83C\uDFFD", + [":raised_back_of_hand::skin-tone-4:"] = "\uD83E\uDD1A\uD83C\uDFFE", + [":raised_back_of_hand::skin-tone-5:"] = "\uD83E\uDD1A\uD83C\uDFFF", + [":raised_back_of_hand_tone1:"] = "\uD83E\uDD1A\uD83C\uDFFB", + [":raised_back_of_hand_tone2:"] = "\uD83E\uDD1A\uD83C\uDFFC", + [":raised_back_of_hand_tone3:"] = "\uD83E\uDD1A\uD83C\uDFFD", + [":raised_back_of_hand_tone4:"] = "\uD83E\uDD1A\uD83C\uDFFE", + [":raised_back_of_hand_tone5:"] = "\uD83E\uDD1A\uD83C\uDFFF", + [":raised_hand:"] = "✋", + [":raised_hand::skin-tone-1:"] = "✋\uD83C\uDFFB", + [":raised_hand::skin-tone-2:"] = "✋\uD83C\uDFFC", + [":raised_hand::skin-tone-3:"] = "✋\uD83C\uDFFD", + [":raised_hand::skin-tone-4:"] = "✋\uD83C\uDFFE", + [":raised_hand::skin-tone-5:"] = "✋\uD83C\uDFFF", + [":raised_hand_tone1:"] = "✋\uD83C\uDFFB", + [":raised_hand_tone2:"] = "✋\uD83C\uDFFC", + [":raised_hand_tone3:"] = "✋\uD83C\uDFFD", + [":raised_hand_tone4:"] = "✋\uD83C\uDFFE", + [":raised_hand_tone5:"] = "✋\uD83C\uDFFF", + [":raised_hand_with_fingers_splayed:"] = "\uD83D\uDD90️", + [":raised_hand_with_fingers_splayed::skin-tone-1:"] = "\uD83D\uDD90\uD83C\uDFFB", + [":raised_hand_with_fingers_splayed::skin-tone-2:"] = "\uD83D\uDD90\uD83C\uDFFC", + [":raised_hand_with_fingers_splayed::skin-tone-3:"] = "\uD83D\uDD90\uD83C\uDFFD", + [":raised_hand_with_fingers_splayed::skin-tone-4:"] = "\uD83D\uDD90\uD83C\uDFFE", + [":raised_hand_with_fingers_splayed::skin-tone-5:"] = "\uD83D\uDD90\uD83C\uDFFF", + [":raised_hand_with_fingers_splayed_tone1:"] = "\uD83D\uDD90\uD83C\uDFFB", + [":raised_hand_with_fingers_splayed_tone2:"] = "\uD83D\uDD90\uD83C\uDFFC", + [":raised_hand_with_fingers_splayed_tone3:"] = "\uD83D\uDD90\uD83C\uDFFD", + [":raised_hand_with_fingers_splayed_tone4:"] = "\uD83D\uDD90\uD83C\uDFFE", + [":raised_hand_with_fingers_splayed_tone5:"] = "\uD83D\uDD90\uD83C\uDFFF", + [":raised_hand_with_part_between_middle_and_ring_fingers:"] = "\uD83D\uDD96", + [":raised_hand_with_part_between_middle_and_ring_fingers::skin-tone-1:"] = "\uD83D\uDD96\uD83C\uDFFB", + [":raised_hand_with_part_between_middle_and_ring_fingers::skin-tone-2:"] = "\uD83D\uDD96\uD83C\uDFFC", + [":raised_hand_with_part_between_middle_and_ring_fingers::skin-tone-3:"] = "\uD83D\uDD96\uD83C\uDFFD", + [":raised_hand_with_part_between_middle_and_ring_fingers::skin-tone-4:"] = "\uD83D\uDD96\uD83C\uDFFE", + [":raised_hand_with_part_between_middle_and_ring_fingers::skin-tone-5:"] = "\uD83D\uDD96\uD83C\uDFFF", + [":raised_hand_with_part_between_middle_and_ring_fingers_tone1:"] = "\uD83D\uDD96\uD83C\uDFFB", + [":raised_hand_with_part_between_middle_and_ring_fingers_tone2:"] = "\uD83D\uDD96\uD83C\uDFFC", + [":raised_hand_with_part_between_middle_and_ring_fingers_tone3:"] = "\uD83D\uDD96\uD83C\uDFFD", + [":raised_hand_with_part_between_middle_and_ring_fingers_tone4:"] = "\uD83D\uDD96\uD83C\uDFFE", + [":raised_hand_with_part_between_middle_and_ring_fingers_tone5:"] = "\uD83D\uDD96\uD83C\uDFFF", + [":raised_hands:"] = "\uD83D\uDE4C", + [":raised_hands::skin-tone-1:"] = "\uD83D\uDE4C\uD83C\uDFFB", + [":raised_hands::skin-tone-2:"] = "\uD83D\uDE4C\uD83C\uDFFC", + [":raised_hands::skin-tone-3:"] = "\uD83D\uDE4C\uD83C\uDFFD", + [":raised_hands::skin-tone-4:"] = "\uD83D\uDE4C\uD83C\uDFFE", + [":raised_hands::skin-tone-5:"] = "\uD83D\uDE4C\uD83C\uDFFF", + [":raised_hands_tone1:"] = "\uD83D\uDE4C\uD83C\uDFFB", + [":raised_hands_tone2:"] = "\uD83D\uDE4C\uD83C\uDFFC", + [":raised_hands_tone3:"] = "\uD83D\uDE4C\uD83C\uDFFD", + [":raised_hands_tone4:"] = "\uD83D\uDE4C\uD83C\uDFFE", + [":raised_hands_tone5:"] = "\uD83D\uDE4C\uD83C\uDFFF", + [":raising_hand:"] = "\uD83D\uDE4B", + [":raising_hand::skin-tone-1:"] = "\uD83D\uDE4B\uD83C\uDFFB", + [":raising_hand::skin-tone-2:"] = "\uD83D\uDE4B\uD83C\uDFFC", + [":raising_hand::skin-tone-3:"] = "\uD83D\uDE4B\uD83C\uDFFD", + [":raising_hand::skin-tone-4:"] = "\uD83D\uDE4B\uD83C\uDFFE", + [":raising_hand::skin-tone-5:"] = "\uD83D\uDE4B\uD83C\uDFFF", + [":raising_hand_tone1:"] = "\uD83D\uDE4B\uD83C\uDFFB", + [":raising_hand_tone2:"] = "\uD83D\uDE4B\uD83C\uDFFC", + [":raising_hand_tone3:"] = "\uD83D\uDE4B\uD83C\uDFFD", + [":raising_hand_tone4:"] = "\uD83D\uDE4B\uD83C\uDFFE", + [":raising_hand_tone5:"] = "\uD83D\uDE4B\uD83C\uDFFF", + [":ram:"] = "\uD83D\uDC0F", + [":ramen:"] = "\uD83C\uDF5C", + [":rat:"] = "\uD83D\uDC00", + [":razor:"] = "\uD83E\uDE92", + [":receipt:"] = "\uD83E\uDDFE", + [":record_button:"] = "⏺️", + [":recycle:"] = "♻️", + [":red_car:"] = "\uD83D\uDE97", + [":red_circle:"] = "\uD83D\uDD34", + [":red_envelope:"] = "\uD83E\uDDE7", + [":red_square:"] = "\uD83D\uDFE5", + [":regional_indicator_a:"] = "\uD83C\uDDE6", + [":regional_indicator_b:"] = "\uD83C\uDDE7", + [":regional_indicator_c:"] = "\uD83C\uDDE8", + [":regional_indicator_d:"] = "\uD83C\uDDE9", + [":regional_indicator_e:"] = "\uD83C\uDDEA", + [":regional_indicator_f:"] = "\uD83C\uDDEB", + [":regional_indicator_g:"] = "\uD83C\uDDEC", + [":regional_indicator_h:"] = "\uD83C\uDDED", + [":regional_indicator_i:"] = "\uD83C\uDDEE", + [":regional_indicator_j:"] = "\uD83C\uDDEF", + [":regional_indicator_k:"] = "\uD83C\uDDF0", + [":regional_indicator_l:"] = "\uD83C\uDDF1", + [":regional_indicator_m:"] = "\uD83C\uDDF2", + [":regional_indicator_n:"] = "\uD83C\uDDF3", + [":regional_indicator_o:"] = "\uD83C\uDDF4", + [":regional_indicator_p:"] = "\uD83C\uDDF5", + [":regional_indicator_q:"] = "\uD83C\uDDF6", + [":regional_indicator_r:"] = "\uD83C\uDDF7", + [":regional_indicator_s:"] = "\uD83C\uDDF8", + [":regional_indicator_t:"] = "\uD83C\uDDF9", + [":regional_indicator_u:"] = "\uD83C\uDDFA", + [":regional_indicator_v:"] = "\uD83C\uDDFB", + [":regional_indicator_w:"] = "\uD83C\uDDFC", + [":regional_indicator_x:"] = "\uD83C\uDDFD", + [":regional_indicator_y:"] = "\uD83C\uDDFE", + [":regional_indicator_z:"] = "\uD83C\uDDFF", + [":registered:"] = "®️", + [":relaxed:"] = "☺️", + [":relieved:"] = "\uD83D\uDE0C", + [":reminder_ribbon:"] = "\uD83C\uDF97️", + [":repeat:"] = "\uD83D\uDD01", + [":repeat_one:"] = "\uD83D\uDD02", + [":restroom:"] = "\uD83D\uDEBB", + [":reversed_hand_with_middle_finger_extended:"] = "\uD83D\uDD95", + [":reversed_hand_with_middle_finger_extended::skin-tone-1:"] = "\uD83D\uDD95\uD83C\uDFFB", + [":reversed_hand_with_middle_finger_extended::skin-tone-2:"] = "\uD83D\uDD95\uD83C\uDFFC", + [":reversed_hand_with_middle_finger_extended::skin-tone-3:"] = "\uD83D\uDD95\uD83C\uDFFD", + [":reversed_hand_with_middle_finger_extended::skin-tone-4:"] = "\uD83D\uDD95\uD83C\uDFFE", + [":reversed_hand_with_middle_finger_extended::skin-tone-5:"] = "\uD83D\uDD95\uD83C\uDFFF", + [":reversed_hand_with_middle_finger_extended_tone1:"] = "\uD83D\uDD95\uD83C\uDFFB", + [":reversed_hand_with_middle_finger_extended_tone2:"] = "\uD83D\uDD95\uD83C\uDFFC", + [":reversed_hand_with_middle_finger_extended_tone3:"] = "\uD83D\uDD95\uD83C\uDFFD", + [":reversed_hand_with_middle_finger_extended_tone4:"] = "\uD83D\uDD95\uD83C\uDFFE", + [":reversed_hand_with_middle_finger_extended_tone5:"] = "\uD83D\uDD95\uD83C\uDFFF", + [":revolving_hearts:"] = "\uD83D\uDC9E", + [":rewind:"] = "⏪", + [":rhino:"] = "\uD83E\uDD8F", + [":rhinoceros:"] = "\uD83E\uDD8F", + [":ribbon:"] = "\uD83C\uDF80", + [":rice:"] = "\uD83C\uDF5A", + [":rice_ball:"] = "\uD83C\uDF59", + [":rice_cracker:"] = "\uD83C\uDF58", + [":rice_scene:"] = "\uD83C\uDF91", + [":right_anger_bubble:"] = "\uD83D\uDDEF️", + [":right_facing_fist:"] = "\uD83E\uDD1C", + [":right_facing_fist::skin-tone-1:"] = "\uD83E\uDD1C\uD83C\uDFFB", + [":right_facing_fist::skin-tone-2:"] = "\uD83E\uDD1C\uD83C\uDFFC", + [":right_facing_fist::skin-tone-3:"] = "\uD83E\uDD1C\uD83C\uDFFD", + [":right_facing_fist::skin-tone-4:"] = "\uD83E\uDD1C\uD83C\uDFFE", + [":right_facing_fist::skin-tone-5:"] = "\uD83E\uDD1C\uD83C\uDFFF", + [":right_facing_fist_tone1:"] = "\uD83E\uDD1C\uD83C\uDFFB", + [":right_facing_fist_tone2:"] = "\uD83E\uDD1C\uD83C\uDFFC", + [":right_facing_fist_tone3:"] = "\uD83E\uDD1C\uD83C\uDFFD", + [":right_facing_fist_tone4:"] = "\uD83E\uDD1C\uD83C\uDFFE", + [":right_facing_fist_tone5:"] = "\uD83E\uDD1C\uD83C\uDFFF", + [":right_fist:"] = "\uD83E\uDD1C", + [":right_fist::skin-tone-1:"] = "\uD83E\uDD1C\uD83C\uDFFB", + [":right_fist::skin-tone-2:"] = "\uD83E\uDD1C\uD83C\uDFFC", + [":right_fist::skin-tone-3:"] = "\uD83E\uDD1C\uD83C\uDFFD", + [":right_fist::skin-tone-4:"] = "\uD83E\uDD1C\uD83C\uDFFE", + [":right_fist::skin-tone-5:"] = "\uD83E\uDD1C\uD83C\uDFFF", + [":right_fist_tone1:"] = "\uD83E\uDD1C\uD83C\uDFFB", + [":right_fist_tone2:"] = "\uD83E\uDD1C\uD83C\uDFFC", + [":right_fist_tone3:"] = "\uD83E\uDD1C\uD83C\uDFFD", + [":right_fist_tone4:"] = "\uD83E\uDD1C\uD83C\uDFFE", + [":right_fist_tone5:"] = "\uD83E\uDD1C\uD83C\uDFFF", + [":ring:"] = "\uD83D\uDC8D", + [":ringed_planet:"] = "\uD83E\uDE90", + [":robot:"] = "\uD83E\uDD16", + [":robot_face:"] = "\uD83E\uDD16", + [":rocket:"] = "\uD83D\uDE80", + [":rofl:"] = "\uD83E\uDD23", + [":roll_of_paper:"] = "\uD83E\uDDFB", + [":rolled_up_newspaper:"] = "\uD83D\uDDDE️", + [":roller_coaster:"] = "\uD83C\uDFA2", + [":rolling_eyes:"] = "\uD83D\uDE44", + [":rolling_on_the_floor_laughing:"] = "\uD83E\uDD23", + [":rooster:"] = "\uD83D\uDC13", + [":rose:"] = "\uD83C\uDF39", + [":rosette:"] = "\uD83C\uDFF5️", + [":rotating_light:"] = "\uD83D\uDEA8", + [":round_pushpin:"] = "\uD83D\uDCCD", + [":rowboat:"] = "\uD83D\uDEA3", + [":rowboat::skin-tone-1:"] = "\uD83D\uDEA3\uD83C\uDFFB", + [":rowboat::skin-tone-2:"] = "\uD83D\uDEA3\uD83C\uDFFC", + [":rowboat::skin-tone-3:"] = "\uD83D\uDEA3\uD83C\uDFFD", + [":rowboat::skin-tone-4:"] = "\uD83D\uDEA3\uD83C\uDFFE", + [":rowboat::skin-tone-5:"] = "\uD83D\uDEA3\uD83C\uDFFF", + [":rowboat_tone1:"] = "\uD83D\uDEA3\uD83C\uDFFB", + [":rowboat_tone2:"] = "\uD83D\uDEA3\uD83C\uDFFC", + [":rowboat_tone3:"] = "\uD83D\uDEA3\uD83C\uDFFD", + [":rowboat_tone4:"] = "\uD83D\uDEA3\uD83C\uDFFE", + [":rowboat_tone5:"] = "\uD83D\uDEA3\uD83C\uDFFF", + [":rugby_football:"] = "\uD83C\uDFC9", + [":runner:"] = "\uD83C\uDFC3", + [":runner::skin-tone-1:"] = "\uD83C\uDFC3\uD83C\uDFFB", + [":runner::skin-tone-2:"] = "\uD83C\uDFC3\uD83C\uDFFC", + [":runner::skin-tone-3:"] = "\uD83C\uDFC3\uD83C\uDFFD", + [":runner::skin-tone-4:"] = "\uD83C\uDFC3\uD83C\uDFFE", + [":runner::skin-tone-5:"] = "\uD83C\uDFC3\uD83C\uDFFF", + [":runner_tone1:"] = "\uD83C\uDFC3\uD83C\uDFFB", + [":runner_tone2:"] = "\uD83C\uDFC3\uD83C\uDFFC", + [":runner_tone3:"] = "\uD83C\uDFC3\uD83C\uDFFD", + [":runner_tone4:"] = "\uD83C\uDFC3\uD83C\uDFFE", + [":runner_tone5:"] = "\uD83C\uDFC3\uD83C\uDFFF", + [":running_shirt_with_sash:"] = "\uD83C\uDFBD", + [":s"] = "\uD83D\uDE12", + [":sa:"] = "\uD83C\uDE02️", + [":safety_pin:"] = "\uD83E\uDDF7", + [":safety_vest:"] = "\uD83E\uDDBA", + [":sagittarius:"] = "♐", + [":sailboat:"] = "⛵", + [":sake:"] = "\uD83C\uDF76", + [":salad:"] = "\uD83E\uDD57", + [":salt:"] = "\uD83E\uDDC2", + [":sandal:"] = "\uD83D\uDC61", + [":sandwich:"] = "\uD83E\uDD6A", + [":santa:"] = "\uD83C\uDF85", + [":santa::skin-tone-1:"] = "\uD83C\uDF85\uD83C\uDFFB", + [":santa::skin-tone-2:"] = "\uD83C\uDF85\uD83C\uDFFC", + [":santa::skin-tone-3:"] = "\uD83C\uDF85\uD83C\uDFFD", + [":santa::skin-tone-4:"] = "\uD83C\uDF85\uD83C\uDFFE", + [":santa::skin-tone-5:"] = "\uD83C\uDF85\uD83C\uDFFF", + [":santa_tone1:"] = "\uD83C\uDF85\uD83C\uDFFB", + [":santa_tone2:"] = "\uD83C\uDF85\uD83C\uDFFC", + [":santa_tone3:"] = "\uD83C\uDF85\uD83C\uDFFD", + [":santa_tone4:"] = "\uD83C\uDF85\uD83C\uDFFE", + [":santa_tone5:"] = "\uD83C\uDF85\uD83C\uDFFF", + [":sari:"] = "\uD83E\uDD7B", + [":satellite:"] = "\uD83D\uDCE1", + [":satellite_orbital:"] = "\uD83D\uDEF0️", + [":satisfied:"] = "\uD83D\uDE06", + [":sauropod:"] = "\uD83E\uDD95", + [":saxophone:"] = "\uD83C\uDFB7", + [":scales:"] = "⚖️", + [":scarf:"] = "\uD83E\uDDE3", + [":school:"] = "\uD83C\uDFEB", + [":school_satchel:"] = "\uD83C\uDF92", + [":scissors:"] = "✂️", + [":scooter:"] = "\uD83D\uDEF4", + [":scorpion:"] = "\uD83E\uDD82", + [":scorpius:"] = "♏", + [":scotland:"] = "\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74\uDB40\uDC7F", + [":scream:"] = "\uD83D\uDE31", + [":scream_cat:"] = "\uD83D\uDE40", + [":scroll:"] = "\uD83D\uDCDC", + [":seat:"] = "\uD83D\uDCBA", + [":second_place:"] = "\uD83E\uDD48", + [":second_place_medal:"] = "\uD83E\uDD48", + [":secret:"] = "㊙️", + [":see_no_evil:"] = "\uD83D\uDE48", + [":seedling:"] = "\uD83C\uDF31", + [":selfie:"] = "\uD83E\uDD33", + [":selfie::skin-tone-1:"] = "\uD83E\uDD33\uD83C\uDFFB", + [":selfie::skin-tone-2:"] = "\uD83E\uDD33\uD83C\uDFFC", + [":selfie::skin-tone-3:"] = "\uD83E\uDD33\uD83C\uDFFD", + [":selfie::skin-tone-4:"] = "\uD83E\uDD33\uD83C\uDFFE", + [":selfie::skin-tone-5:"] = "\uD83E\uDD33\uD83C\uDFFF", + [":selfie_tone1:"] = "\uD83E\uDD33\uD83C\uDFFB", + [":selfie_tone2:"] = "\uD83E\uDD33\uD83C\uDFFC", + [":selfie_tone3:"] = "\uD83E\uDD33\uD83C\uDFFD", + [":selfie_tone4:"] = "\uD83E\uDD33\uD83C\uDFFE", + [":selfie_tone5:"] = "\uD83E\uDD33\uD83C\uDFFF", + [":service_dog:"] = "\uD83D\uDC15\u200D\uD83E\uDDBA", + [":seven:"] = "7️⃣", + [":shaking_hands:"] = "\uD83E\uDD1D", + [":shallow_pan_of_food:"] = "\uD83E\uDD58", + [":shamrock:"] = "☘️", + [":shark:"] = "\uD83E\uDD88", + [":shaved_ice:"] = "\uD83C\uDF67", + [":sheep:"] = "\uD83D\uDC11", + [":shell:"] = "\uD83D\uDC1A", + [":shelled_peanut:"] = "\uD83E\uDD5C", + [":shield:"] = "\uD83D\uDEE1️", + [":shinto_shrine:"] = "⛩️", + [":ship:"] = "\uD83D\uDEA2", + [":shirt:"] = "\uD83D\uDC55", + [":shit:"] = "\uD83D\uDCA9", + [":shopping_bags:"] = "\uD83D\uDECD️", + [":shopping_cart:"] = "\uD83D\uDED2", + [":shopping_trolley:"] = "\uD83D\uDED2", + [":shorts:"] = "\uD83E\uDE73", + [":shower:"] = "\uD83D\uDEBF", + [":shrimp:"] = "\uD83E\uDD90", + [":shrug:"] = "\uD83E\uDD37", + [":shrug::skin-tone-1:"] = "\uD83E\uDD37\uD83C\uDFFB", + [":shrug::skin-tone-2:"] = "\uD83E\uDD37\uD83C\uDFFC", + [":shrug::skin-tone-3:"] = "\uD83E\uDD37\uD83C\uDFFD", + [":shrug::skin-tone-4:"] = "\uD83E\uDD37\uD83C\uDFFE", + [":shrug::skin-tone-5:"] = "\uD83E\uDD37\uD83C\uDFFF", + [":shrug_tone1:"] = "\uD83E\uDD37\uD83C\uDFFB", + [":shrug_tone2:"] = "\uD83E\uDD37\uD83C\uDFFC", + [":shrug_tone3:"] = "\uD83E\uDD37\uD83C\uDFFD", + [":shrug_tone4:"] = "\uD83E\uDD37\uD83C\uDFFE", + [":shrug_tone5:"] = "\uD83E\uDD37\uD83C\uDFFF", + [":shushing_face:"] = "\uD83E\uDD2B", + [":sick:"] = "\uD83E\uDD22", + [":sign_of_the_horns:"] = "\uD83E\uDD18", + [":sign_of_the_horns::skin-tone-1:"] = "\uD83E\uDD18\uD83C\uDFFB", + [":sign_of_the_horns::skin-tone-2:"] = "\uD83E\uDD18\uD83C\uDFFC", + [":sign_of_the_horns::skin-tone-3:"] = "\uD83E\uDD18\uD83C\uDFFD", + [":sign_of_the_horns::skin-tone-4:"] = "\uD83E\uDD18\uD83C\uDFFE", + [":sign_of_the_horns::skin-tone-5:"] = "\uD83E\uDD18\uD83C\uDFFF", + [":sign_of_the_horns_tone1:"] = "\uD83E\uDD18\uD83C\uDFFB", + [":sign_of_the_horns_tone2:"] = "\uD83E\uDD18\uD83C\uDFFC", + [":sign_of_the_horns_tone3:"] = "\uD83E\uDD18\uD83C\uDFFD", + [":sign_of_the_horns_tone4:"] = "\uD83E\uDD18\uD83C\uDFFE", + [":sign_of_the_horns_tone5:"] = "\uD83E\uDD18\uD83C\uDFFF", + [":signal_strength:"] = "\uD83D\uDCF6", + [":six:"] = "6️⃣", + [":six_pointed_star:"] = "\uD83D\uDD2F", + [":skateboard:"] = "\uD83D\uDEF9", + [":skeleton:"] = "\uD83D\uDC80", + [":ski:"] = "\uD83C\uDFBF", + [":skier:"] = "⛷️", + [":skull:"] = "\uD83D\uDC80", + [":skull_and_crossbones:"] = "☠️", + [":skull_crossbones:"] = "☠️", + [":skunk:"] = "\uD83E\uDDA8", + [":sled:"] = "\uD83D\uDEF7", + [":sleeping:"] = "\uD83D\uDE34", + [":sleeping_accommodation:"] = "\uD83D\uDECC", + [":sleeping_accommodation::skin-tone-1:"] = "\uD83D\uDECC\uD83C\uDFFB", + [":sleeping_accommodation::skin-tone-2:"] = "\uD83D\uDECC\uD83C\uDFFC", + [":sleeping_accommodation::skin-tone-3:"] = "\uD83D\uDECC\uD83C\uDFFD", + [":sleeping_accommodation::skin-tone-4:"] = "\uD83D\uDECC\uD83C\uDFFE", + [":sleeping_accommodation::skin-tone-5:"] = "\uD83D\uDECC\uD83C\uDFFF", + [":sleepy:"] = "\uD83D\uDE2A", + [":sleuth_or_spy:"] = "\uD83D\uDD75️", + [":sleuth_or_spy::skin-tone-1:"] = "\uD83D\uDD75\uD83C\uDFFB", + [":sleuth_or_spy::skin-tone-2:"] = "\uD83D\uDD75\uD83C\uDFFC", + [":sleuth_or_spy::skin-tone-3:"] = "\uD83D\uDD75\uD83C\uDFFD", + [":sleuth_or_spy::skin-tone-4:"] = "\uD83D\uDD75\uD83C\uDFFE", + [":sleuth_or_spy::skin-tone-5:"] = "\uD83D\uDD75\uD83C\uDFFF", + [":sleuth_or_spy_tone1:"] = "\uD83D\uDD75\uD83C\uDFFB", + [":sleuth_or_spy_tone2:"] = "\uD83D\uDD75\uD83C\uDFFC", + [":sleuth_or_spy_tone3:"] = "\uD83D\uDD75\uD83C\uDFFD", + [":sleuth_or_spy_tone4:"] = "\uD83D\uDD75\uD83C\uDFFE", + [":sleuth_or_spy_tone5:"] = "\uD83D\uDD75\uD83C\uDFFF", + [":slight_frown:"] = "\uD83D\uDE41", + [":slight_smile:"] = "\uD83D\uDE42", + [":slightly_frowning_face:"] = "\uD83D\uDE41", + [":slightly_smiling_face:"] = "\uD83D\uDE42", + [":slot_machine:"] = "\uD83C\uDFB0", + [":sloth:"] = "\uD83E\uDDA5", + [":small_airplane:"] = "\uD83D\uDEE9️", + [":small_blue_diamond:"] = "\uD83D\uDD39", + [":small_orange_diamond:"] = "\uD83D\uDD38", + [":small_red_triangle:"] = "\uD83D\uDD3A", + [":small_red_triangle_down:"] = "\uD83D\uDD3B", + [":smile:"] = "\uD83D\uDE04", + [":smile_cat:"] = "\uD83D\uDE38", + [":smiley:"] = "\uD83D\uDE03", + [":smiley_cat:"] = "\uD83D\uDE3A", + [":smiling_face_with_3_hearts:"] = "\uD83E\uDD70", + [":smiling_imp:"] = "\uD83D\uDE08", + [":smirk:"] = "\uD83D\uDE0F", + [":smirk_cat:"] = "\uD83D\uDE3C", + [":smoking:"] = "\uD83D\uDEAC", + [":snail:"] = "\uD83D\uDC0C", + [":snake:"] = "\uD83D\uDC0D", + [":sneeze:"] = "\uD83E\uDD27", + [":sneezing_face:"] = "\uD83E\uDD27", + [":snow_capped_mountain:"] = "\uD83C\uDFD4️", + [":snowboarder:"] = "\uD83C\uDFC2", + [":snowboarder::skin-tone-1:"] = "\uD83C\uDFC2\uD83C\uDFFB", + [":snowboarder::skin-tone-2:"] = "\uD83C\uDFC2\uD83C\uDFFC", + [":snowboarder::skin-tone-3:"] = "\uD83C\uDFC2\uD83C\uDFFD", + [":snowboarder::skin-tone-4:"] = "\uD83C\uDFC2\uD83C\uDFFE", + [":snowboarder::skin-tone-5:"] = "\uD83C\uDFC2\uD83C\uDFFF", + [":snowboarder_dark_skin_tone:"] = "\uD83C\uDFC2\uD83C\uDFFF", + [":snowboarder_light_skin_tone:"] = "\uD83C\uDFC2\uD83C\uDFFB", + [":snowboarder_medium_dark_skin_tone:"] = "\uD83C\uDFC2\uD83C\uDFFE", + [":snowboarder_medium_light_skin_tone:"] = "\uD83C\uDFC2\uD83C\uDFFC", + [":snowboarder_medium_skin_tone:"] = "\uD83C\uDFC2\uD83C\uDFFD", + [":snowboarder_tone1:"] = "\uD83C\uDFC2\uD83C\uDFFB", + [":snowboarder_tone2:"] = "\uD83C\uDFC2\uD83C\uDFFC", + [":snowboarder_tone3:"] = "\uD83C\uDFC2\uD83C\uDFFD", + [":snowboarder_tone4:"] = "\uD83C\uDFC2\uD83C\uDFFE", + [":snowboarder_tone5:"] = "\uD83C\uDFC2\uD83C\uDFFF", + [":snowflake:"] = "❄️", + [":snowman2:"] = "☃️", + [":snowman:"] = "⛄", + [":soap:"] = "\uD83E\uDDFC", + [":sob:"] = "\uD83D\uDE2D", + [":soccer:"] = "⚽", + [":socks:"] = "\uD83E\uDDE6", + [":softball:"] = "\uD83E\uDD4E", + [":soon:"] = "\uD83D\uDD1C", + [":sos:"] = "\uD83C\uDD98", + [":sound:"] = "\uD83D\uDD09", + [":space_invader:"] = "\uD83D\uDC7E", + [":spades:"] = "♠️", + [":spaghetti:"] = "\uD83C\uDF5D", + [":sparkle:"] = "❇️", + [":sparkler:"] = "\uD83C\uDF87", + [":sparkles:"] = "✨", + [":sparkling_heart:"] = "\uD83D\uDC96", + [":speak_no_evil:"] = "\uD83D\uDE4A", + [":speaker:"] = "\uD83D\uDD08", + [":speaking_head:"] = "\uD83D\uDDE3️", + [":speaking_head_in_silhouette:"] = "\uD83D\uDDE3️", + [":speech_balloon:"] = "\uD83D\uDCAC", + [":speech_left:"] = "\uD83D\uDDE8️", + [":speedboat:"] = "\uD83D\uDEA4", + [":spider:"] = "\uD83D\uDD77️", + [":spider_web:"] = "\uD83D\uDD78️", + [":spiral_calendar_pad:"] = "\uD83D\uDDD3️", + [":spiral_note_pad:"] = "\uD83D\uDDD2️", + [":sponge:"] = "\uD83E\uDDFD", + [":spoon:"] = "\uD83E\uDD44", + [":sports_medal:"] = "\uD83C\uDFC5", + [":spy:"] = "\uD83D\uDD75️", + [":spy::skin-tone-1:"] = "\uD83D\uDD75\uD83C\uDFFB", + [":spy::skin-tone-2:"] = "\uD83D\uDD75\uD83C\uDFFC", + [":spy::skin-tone-3:"] = "\uD83D\uDD75\uD83C\uDFFD", + [":spy::skin-tone-4:"] = "\uD83D\uDD75\uD83C\uDFFE", + [":spy::skin-tone-5:"] = "\uD83D\uDD75\uD83C\uDFFF", + [":spy_tone1:"] = "\uD83D\uDD75\uD83C\uDFFB", + [":spy_tone2:"] = "\uD83D\uDD75\uD83C\uDFFC", + [":spy_tone3:"] = "\uD83D\uDD75\uD83C\uDFFD", + [":spy_tone4:"] = "\uD83D\uDD75\uD83C\uDFFE", + [":spy_tone5:"] = "\uD83D\uDD75\uD83C\uDFFF", + [":squeeze_bottle:"] = "\uD83E\uDDF4", + [":squid:"] = "\uD83E\uDD91", + [":stadium:"] = "\uD83C\uDFDF️", + [":star2:"] = "\uD83C\uDF1F", + [":star:"] = "⭐", + [":star_and_crescent:"] = "☪️", + [":star_of_david:"] = "✡️", + [":star_struck:"] = "\uD83E\uDD29", + [":stars:"] = "\uD83C\uDF20", + [":station:"] = "\uD83D\uDE89", + [":statue_of_liberty:"] = "\uD83D\uDDFD", + [":steam_locomotive:"] = "\uD83D\uDE82", + [":stethoscope:"] = "\uD83E\uDE7A", + [":stew:"] = "\uD83C\uDF72", + [":stop_button:"] = "⏹️", + [":stop_sign:"] = "\uD83D\uDED1", + [":stopwatch:"] = "⏱️", + [":straight_ruler:"] = "\uD83D\uDCCF", + [":strawberry:"] = "\uD83C\uDF53", + [":stuck_out_tongue:"] = "\uD83D\uDE1B", + [":stuck_out_tongue_closed_eyes:"] = "\uD83D\uDE1D", + [":stuck_out_tongue_winking_eye:"] = "\uD83D\uDE1C", + [":studio_microphone:"] = "\uD83C\uDF99️", + [":stuffed_flatbread:"] = "\uD83E\uDD59", + [":stuffed_pita:"] = "\uD83E\uDD59", + [":sun_with_face:"] = "\uD83C\uDF1E", + [":sunflower:"] = "\uD83C\uDF3B", + [":sunglasses:"] = "\uD83D\uDE0E", + [":sunny:"] = "☀️", + [":sunrise:"] = "\uD83C\uDF05", + [":sunrise_over_mountains:"] = "\uD83C\uDF04", + [":superhero:"] = "\uD83E\uDDB8", + [":superhero::skin-tone-1:"] = "\uD83E\uDDB8\uD83C\uDFFB", + [":superhero::skin-tone-2:"] = "\uD83E\uDDB8\uD83C\uDFFC", + [":superhero::skin-tone-3:"] = "\uD83E\uDDB8\uD83C\uDFFD", + [":superhero::skin-tone-4:"] = "\uD83E\uDDB8\uD83C\uDFFE", + [":superhero::skin-tone-5:"] = "\uD83E\uDDB8\uD83C\uDFFF", + [":superhero_dark_skin_tone:"] = "\uD83E\uDDB8\uD83C\uDFFF", + [":superhero_light_skin_tone:"] = "\uD83E\uDDB8\uD83C\uDFFB", + [":superhero_medium_dark_skin_tone:"] = "\uD83E\uDDB8\uD83C\uDFFE", + [":superhero_medium_light_skin_tone:"] = "\uD83E\uDDB8\uD83C\uDFFC", + [":superhero_medium_skin_tone:"] = "\uD83E\uDDB8\uD83C\uDFFD", + [":superhero_tone1:"] = "\uD83E\uDDB8\uD83C\uDFFB", + [":superhero_tone2:"] = "\uD83E\uDDB8\uD83C\uDFFC", + [":superhero_tone3:"] = "\uD83E\uDDB8\uD83C\uDFFD", + [":superhero_tone4:"] = "\uD83E\uDDB8\uD83C\uDFFE", + [":superhero_tone5:"] = "\uD83E\uDDB8\uD83C\uDFFF", + [":supervillain:"] = "\uD83E\uDDB9", + [":supervillain::skin-tone-1:"] = "\uD83E\uDDB9\uD83C\uDFFB", + [":supervillain::skin-tone-2:"] = "\uD83E\uDDB9\uD83C\uDFFC", + [":supervillain::skin-tone-3:"] = "\uD83E\uDDB9\uD83C\uDFFD", + [":supervillain::skin-tone-4:"] = "\uD83E\uDDB9\uD83C\uDFFE", + [":supervillain::skin-tone-5:"] = "\uD83E\uDDB9\uD83C\uDFFF", + [":supervillain_dark_skin_tone:"] = "\uD83E\uDDB9\uD83C\uDFFF", + [":supervillain_light_skin_tone:"] = "\uD83E\uDDB9\uD83C\uDFFB", + [":supervillain_medium_dark_skin_tone:"] = "\uD83E\uDDB9\uD83C\uDFFE", + [":supervillain_medium_light_skin_tone:"] = "\uD83E\uDDB9\uD83C\uDFFC", + [":supervillain_medium_skin_tone:"] = "\uD83E\uDDB9\uD83C\uDFFD", + [":supervillain_tone1:"] = "\uD83E\uDDB9\uD83C\uDFFB", + [":supervillain_tone2:"] = "\uD83E\uDDB9\uD83C\uDFFC", + [":supervillain_tone3:"] = "\uD83E\uDDB9\uD83C\uDFFD", + [":supervillain_tone4:"] = "\uD83E\uDDB9\uD83C\uDFFE", + [":supervillain_tone5:"] = "\uD83E\uDDB9\uD83C\uDFFF", + [":surfer:"] = "\uD83C\uDFC4", + [":surfer::skin-tone-1:"] = "\uD83C\uDFC4\uD83C\uDFFB", + [":surfer::skin-tone-2:"] = "\uD83C\uDFC4\uD83C\uDFFC", + [":surfer::skin-tone-3:"] = "\uD83C\uDFC4\uD83C\uDFFD", + [":surfer::skin-tone-4:"] = "\uD83C\uDFC4\uD83C\uDFFE", + [":surfer::skin-tone-5:"] = "\uD83C\uDFC4\uD83C\uDFFF", + [":surfer_tone1:"] = "\uD83C\uDFC4\uD83C\uDFFB", + [":surfer_tone2:"] = "\uD83C\uDFC4\uD83C\uDFFC", + [":surfer_tone3:"] = "\uD83C\uDFC4\uD83C\uDFFD", + [":surfer_tone4:"] = "\uD83C\uDFC4\uD83C\uDFFE", + [":surfer_tone5:"] = "\uD83C\uDFC4\uD83C\uDFFF", + [":sushi:"] = "\uD83C\uDF63", + [":suspension_railway:"] = "\uD83D\uDE9F", + [":swan:"] = "\uD83E\uDDA2", + [":sweat:"] = "\uD83D\uDE13", + [":sweat_drops:"] = "\uD83D\uDCA6", + [":sweat_smile:"] = "\uD83D\uDE05", + [":sweet_potato:"] = "\uD83C\uDF60", + [":swimmer:"] = "\uD83C\uDFCA", + [":swimmer::skin-tone-1:"] = "\uD83C\uDFCA\uD83C\uDFFB", + [":swimmer::skin-tone-2:"] = "\uD83C\uDFCA\uD83C\uDFFC", + [":swimmer::skin-tone-3:"] = "\uD83C\uDFCA\uD83C\uDFFD", + [":swimmer::skin-tone-4:"] = "\uD83C\uDFCA\uD83C\uDFFE", + [":swimmer::skin-tone-5:"] = "\uD83C\uDFCA\uD83C\uDFFF", + [":swimmer_tone1:"] = "\uD83C\uDFCA\uD83C\uDFFB", + [":swimmer_tone2:"] = "\uD83C\uDFCA\uD83C\uDFFC", + [":swimmer_tone3:"] = "\uD83C\uDFCA\uD83C\uDFFD", + [":swimmer_tone4:"] = "\uD83C\uDFCA\uD83C\uDFFE", + [":swimmer_tone5:"] = "\uD83C\uDFCA\uD83C\uDFFF", + [":symbols:"] = "\uD83D\uDD23", + [":synagogue:"] = "\uD83D\uDD4D", + [":syringe:"] = "\uD83D\uDC89", + [":t_rex:"] = "\uD83E\uDD96", + [":table_tennis:"] = "\uD83C\uDFD3", + [":taco:"] = "\uD83C\uDF2E", + [":tada:"] = "\uD83C\uDF89", + [":takeout_box:"] = "\uD83E\uDD61", + [":tanabata_tree:"] = "\uD83C\uDF8B", + [":tangerine:"] = "\uD83C\uDF4A", + [":taurus:"] = "♉", + [":taxi:"] = "\uD83D\uDE95", + [":tea:"] = "\uD83C\uDF75", + [":teddy_bear:"] = "\uD83E\uDDF8", + [":telephone:"] = "☎️", + [":telephone_receiver:"] = "\uD83D\uDCDE", + [":telescope:"] = "\uD83D\uDD2D", + [":tennis:"] = "\uD83C\uDFBE", + [":tent:"] = "⛺", + [":test_tube:"] = "\uD83E\uDDEA", + [":thermometer:"] = "\uD83C\uDF21️", + [":thermometer_face:"] = "\uD83E\uDD12", + [":thinking:"] = "\uD83E\uDD14", + [":thinking_face:"] = "\uD83E\uDD14", + [":third_place:"] = "\uD83E\uDD49", + [":third_place_medal:"] = "\uD83E\uDD49", + [":thought_balloon:"] = "\uD83D\uDCAD", + [":thread:"] = "\uD83E\uDDF5", + [":three:"] = "3️⃣", + [":three_button_mouse:"] = "\uD83D\uDDB1️", + [":thumbdown:"] = "\uD83D\uDC4E", + [":thumbdown::skin-tone-1:"] = "\uD83D\uDC4E\uD83C\uDFFB", + [":thumbdown::skin-tone-2:"] = "\uD83D\uDC4E\uD83C\uDFFC", + [":thumbdown::skin-tone-3:"] = "\uD83D\uDC4E\uD83C\uDFFD", + [":thumbdown::skin-tone-4:"] = "\uD83D\uDC4E\uD83C\uDFFE", + [":thumbdown::skin-tone-5:"] = "\uD83D\uDC4E\uD83C\uDFFF", + [":thumbdown_tone1:"] = "\uD83D\uDC4E\uD83C\uDFFB", + [":thumbdown_tone2:"] = "\uD83D\uDC4E\uD83C\uDFFC", + [":thumbdown_tone3:"] = "\uD83D\uDC4E\uD83C\uDFFD", + [":thumbdown_tone4:"] = "\uD83D\uDC4E\uD83C\uDFFE", + [":thumbdown_tone5:"] = "\uD83D\uDC4E\uD83C\uDFFF", + [":thumbsdown:"] = "\uD83D\uDC4E", + [":thumbsdown::skin-tone-1:"] = "\uD83D\uDC4E\uD83C\uDFFB", + [":thumbsdown::skin-tone-2:"] = "\uD83D\uDC4E\uD83C\uDFFC", + [":thumbsdown::skin-tone-3:"] = "\uD83D\uDC4E\uD83C\uDFFD", + [":thumbsdown::skin-tone-4:"] = "\uD83D\uDC4E\uD83C\uDFFE", + [":thumbsdown::skin-tone-5:"] = "\uD83D\uDC4E\uD83C\uDFFF", + [":thumbsdown_tone1:"] = "\uD83D\uDC4E\uD83C\uDFFB", + [":thumbsdown_tone2:"] = "\uD83D\uDC4E\uD83C\uDFFC", + [":thumbsdown_tone3:"] = "\uD83D\uDC4E\uD83C\uDFFD", + [":thumbsdown_tone4:"] = "\uD83D\uDC4E\uD83C\uDFFE", + [":thumbsdown_tone5:"] = "\uD83D\uDC4E\uD83C\uDFFF", + [":thumbsup:"] = "\uD83D\uDC4D", + [":thumbsup::skin-tone-1:"] = "\uD83D\uDC4D\uD83C\uDFFB", + [":thumbsup::skin-tone-2:"] = "\uD83D\uDC4D\uD83C\uDFFC", + [":thumbsup::skin-tone-3:"] = "\uD83D\uDC4D\uD83C\uDFFD", + [":thumbsup::skin-tone-4:"] = "\uD83D\uDC4D\uD83C\uDFFE", + [":thumbsup::skin-tone-5:"] = "\uD83D\uDC4D\uD83C\uDFFF", + [":thumbsup_tone1:"] = "\uD83D\uDC4D\uD83C\uDFFB", + [":thumbsup_tone2:"] = "\uD83D\uDC4D\uD83C\uDFFC", + [":thumbsup_tone3:"] = "\uD83D\uDC4D\uD83C\uDFFD", + [":thumbsup_tone4:"] = "\uD83D\uDC4D\uD83C\uDFFE", + [":thumbsup_tone5:"] = "\uD83D\uDC4D\uD83C\uDFFF", + [":thumbup:"] = "\uD83D\uDC4D", + [":thumbup::skin-tone-1:"] = "\uD83D\uDC4D\uD83C\uDFFB", + [":thumbup::skin-tone-2:"] = "\uD83D\uDC4D\uD83C\uDFFC", + [":thumbup::skin-tone-3:"] = "\uD83D\uDC4D\uD83C\uDFFD", + [":thumbup::skin-tone-4:"] = "\uD83D\uDC4D\uD83C\uDFFE", + [":thumbup::skin-tone-5:"] = "\uD83D\uDC4D\uD83C\uDFFF", + [":thumbup_tone1:"] = "\uD83D\uDC4D\uD83C\uDFFB", + [":thumbup_tone2:"] = "\uD83D\uDC4D\uD83C\uDFFC", + [":thumbup_tone3:"] = "\uD83D\uDC4D\uD83C\uDFFD", + [":thumbup_tone4:"] = "\uD83D\uDC4D\uD83C\uDFFE", + [":thumbup_tone5:"] = "\uD83D\uDC4D\uD83C\uDFFF", + [":thunder_cloud_and_rain:"] = "⛈️", + [":thunder_cloud_rain:"] = "⛈️", + [":ticket:"] = "\uD83C\uDFAB", + [":tickets:"] = "\uD83C\uDF9F️", + [":tiger2:"] = "\uD83D\uDC05", + [":tiger:"] = "\uD83D\uDC2F", + [":timer:"] = "⏲️", + [":timer_clock:"] = "⏲️", + [":tired_face:"] = "\uD83D\uDE2B", + [":tm:"] = "™️", + [":toilet:"] = "\uD83D\uDEBD", + [":tokyo_tower:"] = "\uD83D\uDDFC", + [":tomato:"] = "\uD83C\uDF45", + [":tongue:"] = "\uD83D\uDC45", + [":toolbox:"] = "\uD83E\uDDF0", + [":tools:"] = "\uD83D\uDEE0️", + [":tooth:"] = "\uD83E\uDDB7", + [":top:"] = "\uD83D\uDD1D", + [":tophat:"] = "\uD83C\uDFA9", + [":track_next:"] = "⏭️", + [":track_previous:"] = "⏮️", + [":trackball:"] = "\uD83D\uDDB2️", + [":tractor:"] = "\uD83D\uDE9C", + [":traffic_light:"] = "\uD83D\uDEA5", + [":train2:"] = "\uD83D\uDE86", + [":train:"] = "\uD83D\uDE8B", + [":tram:"] = "\uD83D\uDE8A", + [":triangular_flag_on_post:"] = "\uD83D\uDEA9", + [":triangular_ruler:"] = "\uD83D\uDCD0", + [":trident:"] = "\uD83D\uDD31", + [":triumph:"] = "\uD83D\uDE24", + [":trolleybus:"] = "\uD83D\uDE8E", + [":trophy:"] = "\uD83C\uDFC6", + [":tropical_drink:"] = "\uD83C\uDF79", + [":tropical_fish:"] = "\uD83D\uDC20", + [":truck:"] = "\uD83D\uDE9A", + [":trumpet:"] = "\uD83C\uDFBA", + [":tulip:"] = "\uD83C\uDF37", + [":tumbler_glass:"] = "\uD83E\uDD43", + [":turkey:"] = "\uD83E\uDD83", + [":turtle:"] = "\uD83D\uDC22", + [":tuxedo_tone1:"] = "\uD83E\uDD35\uD83C\uDFFB", + [":tuxedo_tone2:"] = "\uD83E\uDD35\uD83C\uDFFC", + [":tuxedo_tone3:"] = "\uD83E\uDD35\uD83C\uDFFD", + [":tuxedo_tone4:"] = "\uD83E\uDD35\uD83C\uDFFE", + [":tuxedo_tone5:"] = "\uD83E\uDD35\uD83C\uDFFF", + [":tv:"] = "\uD83D\uDCFA", + [":twisted_rightwards_arrows:"] = "\uD83D\uDD00", + [":two:"] = "2️⃣", + [":two_hearts:"] = "\uD83D\uDC95", + [":two_men_holding_hands:"] = "\uD83D\uDC6C", + [":two_women_holding_hands:"] = "\uD83D\uDC6D", + [":u5272:"] = "\uD83C\uDE39", + [":u5408:"] = "\uD83C\uDE34", + [":u55b6:"] = "\uD83C\uDE3A", + [":u6307:"] = "\uD83C\uDE2F", + [":u6708:"] = "\uD83C\uDE37️", + [":u6709:"] = "\uD83C\uDE36", + [":u6e80:"] = "\uD83C\uDE35", + [":u7121:"] = "\uD83C\uDE1A", + [":u7533:"] = "\uD83C\uDE38", + [":u7981:"] = "\uD83C\uDE32", + [":u7a7a:"] = "\uD83C\uDE33", + [":umbrella2:"] = "☂️", + [":umbrella:"] = "☔", + [":umbrella_on_ground:"] = "⛱️", + [":unamused:"] = "\uD83D\uDE12", + [":underage:"] = "\uD83D\uDD1E", + [":unicorn:"] = "\uD83E\uDD84", + [":unicorn_face:"] = "\uD83E\uDD84", + [":united_nations:"] = "\uD83C\uDDFA\uD83C\uDDF3", + [":unlock:"] = "\uD83D\uDD13", + [":up:"] = "\uD83C\uDD99", + [":upside_down:"] = "\uD83D\uDE43", + [":upside_down_face:"] = "\uD83D\uDE43", + [":urn:"] = "⚱️", + [":v:"] = "✌️", + [":v::skin-tone-1:"] = "✌\uD83C\uDFFB", + [":v::skin-tone-2:"] = "✌\uD83C\uDFFC", + [":v::skin-tone-3:"] = "✌\uD83C\uDFFD", + [":v::skin-tone-4:"] = "✌\uD83C\uDFFE", + [":v::skin-tone-5:"] = "✌\uD83C\uDFFF", + [":v_tone1:"] = "✌\uD83C\uDFFB", + [":v_tone2:"] = "✌\uD83C\uDFFC", + [":v_tone3:"] = "✌\uD83C\uDFFD", + [":v_tone4:"] = "✌\uD83C\uDFFE", + [":v_tone5:"] = "✌\uD83C\uDFFF", + [":vampire:"] = "\uD83E\uDDDB", + [":vampire::skin-tone-1:"] = "\uD83E\uDDDB\uD83C\uDFFB", + [":vampire::skin-tone-2:"] = "\uD83E\uDDDB\uD83C\uDFFC", + [":vampire::skin-tone-3:"] = "\uD83E\uDDDB\uD83C\uDFFD", + [":vampire::skin-tone-4:"] = "\uD83E\uDDDB\uD83C\uDFFE", + [":vampire::skin-tone-5:"] = "\uD83E\uDDDB\uD83C\uDFFF", + [":vampire_dark_skin_tone:"] = "\uD83E\uDDDB\uD83C\uDFFF", + [":vampire_light_skin_tone:"] = "\uD83E\uDDDB\uD83C\uDFFB", + [":vampire_medium_dark_skin_tone:"] = "\uD83E\uDDDB\uD83C\uDFFE", + [":vampire_medium_light_skin_tone:"] = "\uD83E\uDDDB\uD83C\uDFFC", + [":vampire_medium_skin_tone:"] = "\uD83E\uDDDB\uD83C\uDFFD", + [":vampire_tone1:"] = "\uD83E\uDDDB\uD83C\uDFFB", + [":vampire_tone2:"] = "\uD83E\uDDDB\uD83C\uDFFC", + [":vampire_tone3:"] = "\uD83E\uDDDB\uD83C\uDFFD", + [":vampire_tone4:"] = "\uD83E\uDDDB\uD83C\uDFFE", + [":vampire_tone5:"] = "\uD83E\uDDDB\uD83C\uDFFF", + [":vertical_traffic_light:"] = "\uD83D\uDEA6", + [":vhs:"] = "\uD83D\uDCFC", + [":vibration_mode:"] = "\uD83D\uDCF3", + [":video_camera:"] = "\uD83D\uDCF9", + [":video_game:"] = "\uD83C\uDFAE", + [":violin:"] = "\uD83C\uDFBB", + [":virgo:"] = "♍", + [":volcano:"] = "\uD83C\uDF0B", + [":volleyball:"] = "\uD83C\uDFD0", + [":vs:"] = "\uD83C\uDD9A", + [":vulcan:"] = "\uD83D\uDD96", + [":vulcan::skin-tone-1:"] = "\uD83D\uDD96\uD83C\uDFFB", + [":vulcan::skin-tone-2:"] = "\uD83D\uDD96\uD83C\uDFFC", + [":vulcan::skin-tone-3:"] = "\uD83D\uDD96\uD83C\uDFFD", + [":vulcan::skin-tone-4:"] = "\uD83D\uDD96\uD83C\uDFFE", + [":vulcan::skin-tone-5:"] = "\uD83D\uDD96\uD83C\uDFFF", + [":vulcan_tone1:"] = "\uD83D\uDD96\uD83C\uDFFB", + [":vulcan_tone2:"] = "\uD83D\uDD96\uD83C\uDFFC", + [":vulcan_tone3:"] = "\uD83D\uDD96\uD83C\uDFFD", + [":vulcan_tone4:"] = "\uD83D\uDD96\uD83C\uDFFE", + [":vulcan_tone5:"] = "\uD83D\uDD96\uD83C\uDFFF", + [":waffle:"] = "\uD83E\uDDC7", + [":wales:"] = "\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73\uDB40\uDC7F", + [":walking:"] = "\uD83D\uDEB6", + [":walking::skin-tone-1:"] = "\uD83D\uDEB6\uD83C\uDFFB", + [":walking::skin-tone-2:"] = "\uD83D\uDEB6\uD83C\uDFFC", + [":walking::skin-tone-3:"] = "\uD83D\uDEB6\uD83C\uDFFD", + [":walking::skin-tone-4:"] = "\uD83D\uDEB6\uD83C\uDFFE", + [":walking::skin-tone-5:"] = "\uD83D\uDEB6\uD83C\uDFFF", + [":walking_tone1:"] = "\uD83D\uDEB6\uD83C\uDFFB", + [":walking_tone2:"] = "\uD83D\uDEB6\uD83C\uDFFC", + [":walking_tone3:"] = "\uD83D\uDEB6\uD83C\uDFFD", + [":walking_tone4:"] = "\uD83D\uDEB6\uD83C\uDFFE", + [":walking_tone5:"] = "\uD83D\uDEB6\uD83C\uDFFF", + [":waning_crescent_moon:"] = "\uD83C\uDF18", + [":waning_gibbous_moon:"] = "\uD83C\uDF16", + [":warning:"] = "⚠️", + [":wastebasket:"] = "\uD83D\uDDD1️", + [":watch:"] = "⌚", + [":water_buffalo:"] = "\uD83D\uDC03", + [":water_polo:"] = "\uD83E\uDD3D", + [":water_polo::skin-tone-1:"] = "\uD83E\uDD3D\uD83C\uDFFB", + [":water_polo::skin-tone-2:"] = "\uD83E\uDD3D\uD83C\uDFFC", + [":water_polo::skin-tone-3:"] = "\uD83E\uDD3D\uD83C\uDFFD", + [":water_polo::skin-tone-4:"] = "\uD83E\uDD3D\uD83C\uDFFE", + [":water_polo::skin-tone-5:"] = "\uD83E\uDD3D\uD83C\uDFFF", + [":water_polo_tone1:"] = "\uD83E\uDD3D\uD83C\uDFFB", + [":water_polo_tone2:"] = "\uD83E\uDD3D\uD83C\uDFFC", + [":water_polo_tone3:"] = "\uD83E\uDD3D\uD83C\uDFFD", + [":water_polo_tone4:"] = "\uD83E\uDD3D\uD83C\uDFFE", + [":water_polo_tone5:"] = "\uD83E\uDD3D\uD83C\uDFFF", + [":watermelon:"] = "\uD83C\uDF49", + [":wave:"] = "\uD83D\uDC4B", + [":wave::skin-tone-1:"] = "\uD83D\uDC4B\uD83C\uDFFB", + [":wave::skin-tone-2:"] = "\uD83D\uDC4B\uD83C\uDFFC", + [":wave::skin-tone-3:"] = "\uD83D\uDC4B\uD83C\uDFFD", + [":wave::skin-tone-4:"] = "\uD83D\uDC4B\uD83C\uDFFE", + [":wave::skin-tone-5:"] = "\uD83D\uDC4B\uD83C\uDFFF", + [":wave_tone1:"] = "\uD83D\uDC4B\uD83C\uDFFB", + [":wave_tone2:"] = "\uD83D\uDC4B\uD83C\uDFFC", + [":wave_tone3:"] = "\uD83D\uDC4B\uD83C\uDFFD", + [":wave_tone4:"] = "\uD83D\uDC4B\uD83C\uDFFE", + [":wave_tone5:"] = "\uD83D\uDC4B\uD83C\uDFFF", + [":wavy_dash:"] = "〰️", + [":waxing_crescent_moon:"] = "\uD83C\uDF12", + [":waxing_gibbous_moon:"] = "\uD83C\uDF14", + [":wc:"] = "\uD83D\uDEBE", + [":weary:"] = "\uD83D\uDE29", + [":wedding:"] = "\uD83D\uDC92", + [":weight_lifter:"] = "\uD83C\uDFCB️", + [":weight_lifter::skin-tone-1:"] = "\uD83C\uDFCB\uD83C\uDFFB", + [":weight_lifter::skin-tone-2:"] = "\uD83C\uDFCB\uD83C\uDFFC", + [":weight_lifter::skin-tone-3:"] = "\uD83C\uDFCB\uD83C\uDFFD", + [":weight_lifter::skin-tone-4:"] = "\uD83C\uDFCB\uD83C\uDFFE", + [":weight_lifter::skin-tone-5:"] = "\uD83C\uDFCB\uD83C\uDFFF", + [":weight_lifter_tone1:"] = "\uD83C\uDFCB\uD83C\uDFFB", + [":weight_lifter_tone2:"] = "\uD83C\uDFCB\uD83C\uDFFC", + [":weight_lifter_tone3:"] = "\uD83C\uDFCB\uD83C\uDFFD", + [":weight_lifter_tone4:"] = "\uD83C\uDFCB\uD83C\uDFFE", + [":weight_lifter_tone5:"] = "\uD83C\uDFCB\uD83C\uDFFF", + [":whale2:"] = "\uD83D\uDC0B", + [":whale:"] = "\uD83D\uDC33", + [":wheel_of_dharma:"] = "☸️", + [":wheelchair:"] = "♿", + [":whisky:"] = "\uD83E\uDD43", + [":white_check_mark:"] = "✅", + [":white_circle:"] = "⚪", + [":white_flower:"] = "\uD83D\uDCAE", + [":white_frowning_face:"] = "☹️", + [":white_heart:"] = "\uD83E\uDD0D", + [":white_large_square:"] = "⬜", + [":white_medium_small_square:"] = "◽", + [":white_medium_square:"] = "◻️", + [":white_small_square:"] = "▫️", + [":white_square_button:"] = "\uD83D\uDD33", + [":white_sun_behind_cloud:"] = "\uD83C\uDF25️", + [":white_sun_behind_cloud_with_rain:"] = "\uD83C\uDF26️", + [":white_sun_cloud:"] = "\uD83C\uDF25️", + [":white_sun_rain_cloud:"] = "\uD83C\uDF26️", + [":white_sun_small_cloud:"] = "\uD83C\uDF24️", + [":white_sun_with_small_cloud:"] = "\uD83C\uDF24️", + [":wilted_flower:"] = "\uD83E\uDD40", + [":wilted_rose:"] = "\uD83E\uDD40", + [":wind_blowing_face:"] = "\uD83C\uDF2C️", + [":wind_chime:"] = "\uD83C\uDF90", + [":wine_glass:"] = "\uD83C\uDF77", + [":wink:"] = "\uD83D\uDE09", + [":wolf:"] = "\uD83D\uDC3A", + [":woman:"] = "\uD83D\uDC69", + [":woman::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB", + [":woman::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC", + [":woman::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD", + [":woman::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE", + [":woman::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF", + [":woman_artist:"] = "\uD83D\uDC69\u200D\uD83C\uDFA8", + [":woman_artist::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDFA8", + [":woman_artist::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDFA8", + [":woman_artist::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDFA8", + [":woman_artist::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDFA8", + [":woman_artist::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDFA8", + [":woman_artist_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDFA8", + [":woman_artist_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDFA8", + [":woman_artist_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDFA8", + [":woman_artist_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDFA8", + [":woman_artist_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDFA8", + [":woman_artist_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDFA8", + [":woman_artist_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDFA8", + [":woman_artist_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDFA8", + [":woman_artist_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDFA8", + [":woman_artist_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDFA8", + [":woman_astronaut:"] = "\uD83D\uDC69\u200D\uD83D\uDE80", + [":woman_astronaut::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDE80", + [":woman_astronaut::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDE80", + [":woman_astronaut::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDE80", + [":woman_astronaut::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDE80", + [":woman_astronaut::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDE80", + [":woman_astronaut_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDE80", + [":woman_astronaut_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDE80", + [":woman_astronaut_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDE80", + [":woman_astronaut_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDE80", + [":woman_astronaut_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDE80", + [":woman_astronaut_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDE80", + [":woman_astronaut_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDE80", + [":woman_astronaut_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDE80", + [":woman_astronaut_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDE80", + [":woman_astronaut_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDE80", + [":woman_bald:"] = "\uD83D\uDC69\u200D\uD83E\uDDB2", + [":woman_bald::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDB2", + [":woman_bald::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDB2", + [":woman_bald::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDB2", + [":woman_bald::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDB2", + [":woman_bald::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDB2", + [":woman_bald_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDB2", + [":woman_bald_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDB2", + [":woman_bald_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDB2", + [":woman_bald_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDB2", + [":woman_bald_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDB2", + [":woman_bald_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDB2", + [":woman_bald_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDB2", + [":woman_bald_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDB2", + [":woman_bald_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDB2", + [":woman_bald_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDB2", + [":woman_biking:"] = "\uD83D\uDEB4\u200D♀️", + [":woman_biking::skin-tone-1:"] = "\uD83D\uDEB4\uD83C\uDFFB\u200D♀️", + [":woman_biking::skin-tone-2:"] = "\uD83D\uDEB4\uD83C\uDFFC\u200D♀️", + [":woman_biking::skin-tone-3:"] = "\uD83D\uDEB4\uD83C\uDFFD\u200D♀️", + [":woman_biking::skin-tone-4:"] = "\uD83D\uDEB4\uD83C\uDFFE\u200D♀️", + [":woman_biking::skin-tone-5:"] = "\uD83D\uDEB4\uD83C\uDFFF\u200D♀️", + [":woman_biking_dark_skin_tone:"] = "\uD83D\uDEB4\uD83C\uDFFF\u200D♀️", + [":woman_biking_light_skin_tone:"] = "\uD83D\uDEB4\uD83C\uDFFB\u200D♀️", + [":woman_biking_medium_dark_skin_tone:"] = "\uD83D\uDEB4\uD83C\uDFFE\u200D♀️", + [":woman_biking_medium_light_skin_tone:"] = "\uD83D\uDEB4\uD83C\uDFFC\u200D♀️", + [":woman_biking_medium_skin_tone:"] = "\uD83D\uDEB4\uD83C\uDFFD\u200D♀️", + [":woman_biking_tone1:"] = "\uD83D\uDEB4\uD83C\uDFFB\u200D♀️", + [":woman_biking_tone2:"] = "\uD83D\uDEB4\uD83C\uDFFC\u200D♀️", + [":woman_biking_tone3:"] = "\uD83D\uDEB4\uD83C\uDFFD\u200D♀️", + [":woman_biking_tone4:"] = "\uD83D\uDEB4\uD83C\uDFFE\u200D♀️", + [":woman_biking_tone5:"] = "\uD83D\uDEB4\uD83C\uDFFF\u200D♀️", + [":woman_bouncing_ball:"] = "⛹️\u200D♀️", + [":woman_bouncing_ball::skin-tone-1:"] = "⛹\uD83C\uDFFB\u200D♀️", + [":woman_bouncing_ball::skin-tone-2:"] = "⛹\uD83C\uDFFC\u200D♀️", + [":woman_bouncing_ball::skin-tone-3:"] = "⛹\uD83C\uDFFD\u200D♀️", + [":woman_bouncing_ball::skin-tone-4:"] = "⛹\uD83C\uDFFE\u200D♀️", + [":woman_bouncing_ball::skin-tone-5:"] = "⛹\uD83C\uDFFF\u200D♀️", + [":woman_bouncing_ball_dark_skin_tone:"] = "⛹\uD83C\uDFFF\u200D♀️", + [":woman_bouncing_ball_light_skin_tone:"] = "⛹\uD83C\uDFFB\u200D♀️", + [":woman_bouncing_ball_medium_dark_skin_tone:"] = "⛹\uD83C\uDFFE\u200D♀️", + [":woman_bouncing_ball_medium_light_skin_tone:"] = "⛹\uD83C\uDFFC\u200D♀️", + [":woman_bouncing_ball_medium_skin_tone:"] = "⛹\uD83C\uDFFD\u200D♀️", + [":woman_bouncing_ball_tone1:"] = "⛹\uD83C\uDFFB\u200D♀️", + [":woman_bouncing_ball_tone2:"] = "⛹\uD83C\uDFFC\u200D♀️", + [":woman_bouncing_ball_tone3:"] = "⛹\uD83C\uDFFD\u200D♀️", + [":woman_bouncing_ball_tone4:"] = "⛹\uD83C\uDFFE\u200D♀️", + [":woman_bouncing_ball_tone5:"] = "⛹\uD83C\uDFFF\u200D♀️", + [":woman_bowing:"] = "\uD83D\uDE47\u200D♀️", + [":woman_bowing::skin-tone-1:"] = "\uD83D\uDE47\uD83C\uDFFB\u200D♀️", + [":woman_bowing::skin-tone-2:"] = "\uD83D\uDE47\uD83C\uDFFC\u200D♀️", + [":woman_bowing::skin-tone-3:"] = "\uD83D\uDE47\uD83C\uDFFD\u200D♀️", + [":woman_bowing::skin-tone-4:"] = "\uD83D\uDE47\uD83C\uDFFE\u200D♀️", + [":woman_bowing::skin-tone-5:"] = "\uD83D\uDE47\uD83C\uDFFF\u200D♀️", + [":woman_bowing_dark_skin_tone:"] = "\uD83D\uDE47\uD83C\uDFFF\u200D♀️", + [":woman_bowing_light_skin_tone:"] = "\uD83D\uDE47\uD83C\uDFFB\u200D♀️", + [":woman_bowing_medium_dark_skin_tone:"] = "\uD83D\uDE47\uD83C\uDFFE\u200D♀️", + [":woman_bowing_medium_light_skin_tone:"] = "\uD83D\uDE47\uD83C\uDFFC\u200D♀️", + [":woman_bowing_medium_skin_tone:"] = "\uD83D\uDE47\uD83C\uDFFD\u200D♀️", + [":woman_bowing_tone1:"] = "\uD83D\uDE47\uD83C\uDFFB\u200D♀️", + [":woman_bowing_tone2:"] = "\uD83D\uDE47\uD83C\uDFFC\u200D♀️", + [":woman_bowing_tone3:"] = "\uD83D\uDE47\uD83C\uDFFD\u200D♀️", + [":woman_bowing_tone4:"] = "\uD83D\uDE47\uD83C\uDFFE\u200D♀️", + [":woman_bowing_tone5:"] = "\uD83D\uDE47\uD83C\uDFFF\u200D♀️", + [":woman_cartwheeling:"] = "\uD83E\uDD38\u200D♀️", + [":woman_cartwheeling::skin-tone-1:"] = "\uD83E\uDD38\uD83C\uDFFB\u200D♀️", + [":woman_cartwheeling::skin-tone-2:"] = "\uD83E\uDD38\uD83C\uDFFC\u200D♀️", + [":woman_cartwheeling::skin-tone-3:"] = "\uD83E\uDD38\uD83C\uDFFD\u200D♀️", + [":woman_cartwheeling::skin-tone-4:"] = "\uD83E\uDD38\uD83C\uDFFE\u200D♀️", + [":woman_cartwheeling::skin-tone-5:"] = "\uD83E\uDD38\uD83C\uDFFF\u200D♀️", + [":woman_cartwheeling_dark_skin_tone:"] = "\uD83E\uDD38\uD83C\uDFFF\u200D♀️", + [":woman_cartwheeling_light_skin_tone:"] = "\uD83E\uDD38\uD83C\uDFFB\u200D♀️", + [":woman_cartwheeling_medium_dark_skin_tone:"] = "\uD83E\uDD38\uD83C\uDFFE\u200D♀️", + [":woman_cartwheeling_medium_light_skin_tone:"] = "\uD83E\uDD38\uD83C\uDFFC\u200D♀️", + [":woman_cartwheeling_medium_skin_tone:"] = "\uD83E\uDD38\uD83C\uDFFD\u200D♀️", + [":woman_cartwheeling_tone1:"] = "\uD83E\uDD38\uD83C\uDFFB\u200D♀️", + [":woman_cartwheeling_tone2:"] = "\uD83E\uDD38\uD83C\uDFFC\u200D♀️", + [":woman_cartwheeling_tone3:"] = "\uD83E\uDD38\uD83C\uDFFD\u200D♀️", + [":woman_cartwheeling_tone4:"] = "\uD83E\uDD38\uD83C\uDFFE\u200D♀️", + [":woman_cartwheeling_tone5:"] = "\uD83E\uDD38\uD83C\uDFFF\u200D♀️", + [":woman_climbing:"] = "\uD83E\uDDD7\u200D♀️", + [":woman_climbing::skin-tone-1:"] = "\uD83E\uDDD7\uD83C\uDFFB\u200D♀️", + [":woman_climbing::skin-tone-2:"] = "\uD83E\uDDD7\uD83C\uDFFC\u200D♀️", + [":woman_climbing::skin-tone-3:"] = "\uD83E\uDDD7\uD83C\uDFFD\u200D♀️", + [":woman_climbing::skin-tone-4:"] = "\uD83E\uDDD7\uD83C\uDFFE\u200D♀️", + [":woman_climbing::skin-tone-5:"] = "\uD83E\uDDD7\uD83C\uDFFF\u200D♀️", + [":woman_climbing_dark_skin_tone:"] = "\uD83E\uDDD7\uD83C\uDFFF\u200D♀️", + [":woman_climbing_light_skin_tone:"] = "\uD83E\uDDD7\uD83C\uDFFB\u200D♀️", + [":woman_climbing_medium_dark_skin_tone:"] = "\uD83E\uDDD7\uD83C\uDFFE\u200D♀️", + [":woman_climbing_medium_light_skin_tone:"] = "\uD83E\uDDD7\uD83C\uDFFC\u200D♀️", + [":woman_climbing_medium_skin_tone:"] = "\uD83E\uDDD7\uD83C\uDFFD\u200D♀️", + [":woman_climbing_tone1:"] = "\uD83E\uDDD7\uD83C\uDFFB\u200D♀️", + [":woman_climbing_tone2:"] = "\uD83E\uDDD7\uD83C\uDFFC\u200D♀️", + [":woman_climbing_tone3:"] = "\uD83E\uDDD7\uD83C\uDFFD\u200D♀️", + [":woman_climbing_tone4:"] = "\uD83E\uDDD7\uD83C\uDFFE\u200D♀️", + [":woman_climbing_tone5:"] = "\uD83E\uDDD7\uD83C\uDFFF\u200D♀️", + [":woman_construction_worker:"] = "\uD83D\uDC77\u200D♀️", + [":woman_construction_worker::skin-tone-1:"] = "\uD83D\uDC77\uD83C\uDFFB\u200D♀️", + [":woman_construction_worker::skin-tone-2:"] = "\uD83D\uDC77\uD83C\uDFFC\u200D♀️", + [":woman_construction_worker::skin-tone-3:"] = "\uD83D\uDC77\uD83C\uDFFD\u200D♀️", + [":woman_construction_worker::skin-tone-4:"] = "\uD83D\uDC77\uD83C\uDFFE\u200D♀️", + [":woman_construction_worker::skin-tone-5:"] = "\uD83D\uDC77\uD83C\uDFFF\u200D♀️", + [":woman_construction_worker_dark_skin_tone:"] = "\uD83D\uDC77\uD83C\uDFFF\u200D♀️", + [":woman_construction_worker_light_skin_tone:"] = "\uD83D\uDC77\uD83C\uDFFB\u200D♀️", + [":woman_construction_worker_medium_dark_skin_tone:"] = "\uD83D\uDC77\uD83C\uDFFE\u200D♀️", + [":woman_construction_worker_medium_light_skin_tone:"] = "\uD83D\uDC77\uD83C\uDFFC\u200D♀️", + [":woman_construction_worker_medium_skin_tone:"] = "\uD83D\uDC77\uD83C\uDFFD\u200D♀️", + [":woman_construction_worker_tone1:"] = "\uD83D\uDC77\uD83C\uDFFB\u200D♀️", + [":woman_construction_worker_tone2:"] = "\uD83D\uDC77\uD83C\uDFFC\u200D♀️", + [":woman_construction_worker_tone3:"] = "\uD83D\uDC77\uD83C\uDFFD\u200D♀️", + [":woman_construction_worker_tone4:"] = "\uD83D\uDC77\uD83C\uDFFE\u200D♀️", + [":woman_construction_worker_tone5:"] = "\uD83D\uDC77\uD83C\uDFFF\u200D♀️", + [":woman_cook:"] = "\uD83D\uDC69\u200D\uD83C\uDF73", + [":woman_cook::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDF73", + [":woman_cook::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDF73", + [":woman_cook::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDF73", + [":woman_cook::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDF73", + [":woman_cook::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDF73", + [":woman_cook_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDF73", + [":woman_cook_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDF73", + [":woman_cook_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDF73", + [":woman_cook_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDF73", + [":woman_cook_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDF73", + [":woman_cook_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDF73", + [":woman_cook_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDF73", + [":woman_cook_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDF73", + [":woman_cook_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDF73", + [":woman_cook_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDF73", + [":woman_curly_haired:"] = "\uD83D\uDC69\u200D\uD83E\uDDB1", + [":woman_curly_haired::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDB1", + [":woman_curly_haired::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDB1", + [":woman_curly_haired::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDB1", + [":woman_curly_haired::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDB1", + [":woman_curly_haired::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDB1", + [":woman_curly_haired_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDB1", + [":woman_curly_haired_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDB1", + [":woman_curly_haired_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDB1", + [":woman_curly_haired_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDB1", + [":woman_curly_haired_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDB1", + [":woman_curly_haired_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDB1", + [":woman_curly_haired_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDB1", + [":woman_curly_haired_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDB1", + [":woman_curly_haired_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDB1", + [":woman_curly_haired_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDB1", + [":woman_detective:"] = "\uD83D\uDD75️\u200D♀️", + [":woman_detective::skin-tone-1:"] = "\uD83D\uDD75\uD83C\uDFFB\u200D♀️", + [":woman_detective::skin-tone-2:"] = "\uD83D\uDD75\uD83C\uDFFC\u200D♀️", + [":woman_detective::skin-tone-3:"] = "\uD83D\uDD75\uD83C\uDFFD\u200D♀️", + [":woman_detective::skin-tone-4:"] = "\uD83D\uDD75\uD83C\uDFFE\u200D♀️", + [":woman_detective::skin-tone-5:"] = "\uD83D\uDD75\uD83C\uDFFF\u200D♀️", + [":woman_detective_dark_skin_tone:"] = "\uD83D\uDD75\uD83C\uDFFF\u200D♀️", + [":woman_detective_light_skin_tone:"] = "\uD83D\uDD75\uD83C\uDFFB\u200D♀️", + [":woman_detective_medium_dark_skin_tone:"] = "\uD83D\uDD75\uD83C\uDFFE\u200D♀️", + [":woman_detective_medium_light_skin_tone:"] = "\uD83D\uDD75\uD83C\uDFFC\u200D♀️", + [":woman_detective_medium_skin_tone:"] = "\uD83D\uDD75\uD83C\uDFFD\u200D♀️", + [":woman_detective_tone1:"] = "\uD83D\uDD75\uD83C\uDFFB\u200D♀️", + [":woman_detective_tone2:"] = "\uD83D\uDD75\uD83C\uDFFC\u200D♀️", + [":woman_detective_tone3:"] = "\uD83D\uDD75\uD83C\uDFFD\u200D♀️", + [":woman_detective_tone4:"] = "\uD83D\uDD75\uD83C\uDFFE\u200D♀️", + [":woman_detective_tone5:"] = "\uD83D\uDD75\uD83C\uDFFF\u200D♀️", + [":woman_elf:"] = "\uD83E\uDDDD\u200D♀️", + [":woman_elf::skin-tone-1:"] = "\uD83E\uDDDD\uD83C\uDFFB\u200D♀️", + [":woman_elf::skin-tone-2:"] = "\uD83E\uDDDD\uD83C\uDFFC\u200D♀️", + [":woman_elf::skin-tone-3:"] = "\uD83E\uDDDD\uD83C\uDFFD\u200D♀️", + [":woman_elf::skin-tone-4:"] = "\uD83E\uDDDD\uD83C\uDFFE\u200D♀️", + [":woman_elf::skin-tone-5:"] = "\uD83E\uDDDD\uD83C\uDFFF\u200D♀️", + [":woman_elf_dark_skin_tone:"] = "\uD83E\uDDDD\uD83C\uDFFF\u200D♀️", + [":woman_elf_light_skin_tone:"] = "\uD83E\uDDDD\uD83C\uDFFB\u200D♀️", + [":woman_elf_medium_dark_skin_tone:"] = "\uD83E\uDDDD\uD83C\uDFFE\u200D♀️", + [":woman_elf_medium_light_skin_tone:"] = "\uD83E\uDDDD\uD83C\uDFFC\u200D♀️", + [":woman_elf_medium_skin_tone:"] = "\uD83E\uDDDD\uD83C\uDFFD\u200D♀️", + [":woman_elf_tone1:"] = "\uD83E\uDDDD\uD83C\uDFFB\u200D♀️", + [":woman_elf_tone2:"] = "\uD83E\uDDDD\uD83C\uDFFC\u200D♀️", + [":woman_elf_tone3:"] = "\uD83E\uDDDD\uD83C\uDFFD\u200D♀️", + [":woman_elf_tone4:"] = "\uD83E\uDDDD\uD83C\uDFFE\u200D♀️", + [":woman_elf_tone5:"] = "\uD83E\uDDDD\uD83C\uDFFF\u200D♀️", + [":woman_facepalming:"] = "\uD83E\uDD26\u200D♀️", + [":woman_facepalming::skin-tone-1:"] = "\uD83E\uDD26\uD83C\uDFFB\u200D♀️", + [":woman_facepalming::skin-tone-2:"] = "\uD83E\uDD26\uD83C\uDFFC\u200D♀️", + [":woman_facepalming::skin-tone-3:"] = "\uD83E\uDD26\uD83C\uDFFD\u200D♀️", + [":woman_facepalming::skin-tone-4:"] = "\uD83E\uDD26\uD83C\uDFFE\u200D♀️", + [":woman_facepalming::skin-tone-5:"] = "\uD83E\uDD26\uD83C\uDFFF\u200D♀️", + [":woman_facepalming_dark_skin_tone:"] = "\uD83E\uDD26\uD83C\uDFFF\u200D♀️", + [":woman_facepalming_light_skin_tone:"] = "\uD83E\uDD26\uD83C\uDFFB\u200D♀️", + [":woman_facepalming_medium_dark_skin_tone:"] = "\uD83E\uDD26\uD83C\uDFFE\u200D♀️", + [":woman_facepalming_medium_light_skin_tone:"] = "\uD83E\uDD26\uD83C\uDFFC\u200D♀️", + [":woman_facepalming_medium_skin_tone:"] = "\uD83E\uDD26\uD83C\uDFFD\u200D♀️", + [":woman_facepalming_tone1:"] = "\uD83E\uDD26\uD83C\uDFFB\u200D♀️", + [":woman_facepalming_tone2:"] = "\uD83E\uDD26\uD83C\uDFFC\u200D♀️", + [":woman_facepalming_tone3:"] = "\uD83E\uDD26\uD83C\uDFFD\u200D♀️", + [":woman_facepalming_tone4:"] = "\uD83E\uDD26\uD83C\uDFFE\u200D♀️", + [":woman_facepalming_tone5:"] = "\uD83E\uDD26\uD83C\uDFFF\u200D♀️", + [":woman_factory_worker:"] = "\uD83D\uDC69\u200D\uD83C\uDFED", + [":woman_factory_worker::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDFED", + [":woman_factory_worker::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDFED", + [":woman_factory_worker::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDFED", + [":woman_factory_worker::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDFED", + [":woman_factory_worker::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDFED", + [":woman_factory_worker_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDFED", + [":woman_factory_worker_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDFED", + [":woman_factory_worker_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDFED", + [":woman_factory_worker_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDFED", + [":woman_factory_worker_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDFED", + [":woman_factory_worker_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDFED", + [":woman_factory_worker_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDFED", + [":woman_factory_worker_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDFED", + [":woman_factory_worker_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDFED", + [":woman_factory_worker_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDFED", + [":woman_fairy:"] = "\uD83E\uDDDA\u200D♀️", + [":woman_fairy::skin-tone-1:"] = "\uD83E\uDDDA\uD83C\uDFFB\u200D♀️", + [":woman_fairy::skin-tone-2:"] = "\uD83E\uDDDA\uD83C\uDFFC\u200D♀️", + [":woman_fairy::skin-tone-3:"] = "\uD83E\uDDDA\uD83C\uDFFD\u200D♀️", + [":woman_fairy::skin-tone-4:"] = "\uD83E\uDDDA\uD83C\uDFFE\u200D♀️", + [":woman_fairy::skin-tone-5:"] = "\uD83E\uDDDA\uD83C\uDFFF\u200D♀️", + [":woman_fairy_dark_skin_tone:"] = "\uD83E\uDDDA\uD83C\uDFFF\u200D♀️", + [":woman_fairy_light_skin_tone:"] = "\uD83E\uDDDA\uD83C\uDFFB\u200D♀️", + [":woman_fairy_medium_dark_skin_tone:"] = "\uD83E\uDDDA\uD83C\uDFFE\u200D♀️", + [":woman_fairy_medium_light_skin_tone:"] = "\uD83E\uDDDA\uD83C\uDFFC\u200D♀️", + [":woman_fairy_medium_skin_tone:"] = "\uD83E\uDDDA\uD83C\uDFFD\u200D♀️", + [":woman_fairy_tone1:"] = "\uD83E\uDDDA\uD83C\uDFFB\u200D♀️", + [":woman_fairy_tone2:"] = "\uD83E\uDDDA\uD83C\uDFFC\u200D♀️", + [":woman_fairy_tone3:"] = "\uD83E\uDDDA\uD83C\uDFFD\u200D♀️", + [":woman_fairy_tone4:"] = "\uD83E\uDDDA\uD83C\uDFFE\u200D♀️", + [":woman_fairy_tone5:"] = "\uD83E\uDDDA\uD83C\uDFFF\u200D♀️", + [":woman_farmer:"] = "\uD83D\uDC69\u200D\uD83C\uDF3E", + [":woman_farmer::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDF3E", + [":woman_farmer::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDF3E", + [":woman_farmer::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDF3E", + [":woman_farmer::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDF3E", + [":woman_farmer::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDF3E", + [":woman_farmer_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDF3E", + [":woman_farmer_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDF3E", + [":woman_farmer_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDF3E", + [":woman_farmer_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDF3E", + [":woman_farmer_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDF3E", + [":woman_farmer_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDF3E", + [":woman_farmer_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDF3E", + [":woman_farmer_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDF3E", + [":woman_farmer_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDF3E", + [":woman_farmer_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDF3E", + [":woman_firefighter:"] = "\uD83D\uDC69\u200D\uD83D\uDE92", + [":woman_firefighter::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDE92", + [":woman_firefighter::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDE92", + [":woman_firefighter::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDE92", + [":woman_firefighter::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDE92", + [":woman_firefighter::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDE92", + [":woman_firefighter_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDE92", + [":woman_firefighter_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDE92", + [":woman_firefighter_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDE92", + [":woman_firefighter_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDE92", + [":woman_firefighter_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDE92", + [":woman_firefighter_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDE92", + [":woman_firefighter_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDE92", + [":woman_firefighter_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDE92", + [":woman_firefighter_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDE92", + [":woman_firefighter_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDE92", + [":woman_frowning:"] = "\uD83D\uDE4D\u200D♀️", + [":woman_frowning::skin-tone-1:"] = "\uD83D\uDE4D\uD83C\uDFFB\u200D♀️", + [":woman_frowning::skin-tone-2:"] = "\uD83D\uDE4D\uD83C\uDFFC\u200D♀️", + [":woman_frowning::skin-tone-3:"] = "\uD83D\uDE4D\uD83C\uDFFD\u200D♀️", + [":woman_frowning::skin-tone-4:"] = "\uD83D\uDE4D\uD83C\uDFFE\u200D♀️", + [":woman_frowning::skin-tone-5:"] = "\uD83D\uDE4D\uD83C\uDFFF\u200D♀️", + [":woman_frowning_dark_skin_tone:"] = "\uD83D\uDE4D\uD83C\uDFFF\u200D♀️", + [":woman_frowning_light_skin_tone:"] = "\uD83D\uDE4D\uD83C\uDFFB\u200D♀️", + [":woman_frowning_medium_dark_skin_tone:"] = "\uD83D\uDE4D\uD83C\uDFFE\u200D♀️", + [":woman_frowning_medium_light_skin_tone:"] = "\uD83D\uDE4D\uD83C\uDFFC\u200D♀️", + [":woman_frowning_medium_skin_tone:"] = "\uD83D\uDE4D\uD83C\uDFFD\u200D♀️", + [":woman_frowning_tone1:"] = "\uD83D\uDE4D\uD83C\uDFFB\u200D♀️", + [":woman_frowning_tone2:"] = "\uD83D\uDE4D\uD83C\uDFFC\u200D♀️", + [":woman_frowning_tone3:"] = "\uD83D\uDE4D\uD83C\uDFFD\u200D♀️", + [":woman_frowning_tone4:"] = "\uD83D\uDE4D\uD83C\uDFFE\u200D♀️", + [":woman_frowning_tone5:"] = "\uD83D\uDE4D\uD83C\uDFFF\u200D♀️", + [":woman_genie:"] = "\uD83E\uDDDE\u200D♀️", + [":woman_gesturing_no:"] = "\uD83D\uDE45\u200D♀️", + [":woman_gesturing_no::skin-tone-1:"] = "\uD83D\uDE45\uD83C\uDFFB\u200D♀️", + [":woman_gesturing_no::skin-tone-2:"] = "\uD83D\uDE45\uD83C\uDFFC\u200D♀️", + [":woman_gesturing_no::skin-tone-3:"] = "\uD83D\uDE45\uD83C\uDFFD\u200D♀️", + [":woman_gesturing_no::skin-tone-4:"] = "\uD83D\uDE45\uD83C\uDFFE\u200D♀️", + [":woman_gesturing_no::skin-tone-5:"] = "\uD83D\uDE45\uD83C\uDFFF\u200D♀️", + [":woman_gesturing_no_dark_skin_tone:"] = "\uD83D\uDE45\uD83C\uDFFF\u200D♀️", + [":woman_gesturing_no_light_skin_tone:"] = "\uD83D\uDE45\uD83C\uDFFB\u200D♀️", + [":woman_gesturing_no_medium_dark_skin_tone:"] = "\uD83D\uDE45\uD83C\uDFFE\u200D♀️", + [":woman_gesturing_no_medium_light_skin_tone:"] = "\uD83D\uDE45\uD83C\uDFFC\u200D♀️", + [":woman_gesturing_no_medium_skin_tone:"] = "\uD83D\uDE45\uD83C\uDFFD\u200D♀️", + [":woman_gesturing_no_tone1:"] = "\uD83D\uDE45\uD83C\uDFFB\u200D♀️", + [":woman_gesturing_no_tone2:"] = "\uD83D\uDE45\uD83C\uDFFC\u200D♀️", + [":woman_gesturing_no_tone3:"] = "\uD83D\uDE45\uD83C\uDFFD\u200D♀️", + [":woman_gesturing_no_tone4:"] = "\uD83D\uDE45\uD83C\uDFFE\u200D♀️", + [":woman_gesturing_no_tone5:"] = "\uD83D\uDE45\uD83C\uDFFF\u200D♀️", + [":woman_gesturing_ok:"] = "\uD83D\uDE46\u200D♀️", + [":woman_gesturing_ok::skin-tone-1:"] = "\uD83D\uDE46\uD83C\uDFFB\u200D♀️", + [":woman_gesturing_ok::skin-tone-2:"] = "\uD83D\uDE46\uD83C\uDFFC\u200D♀️", + [":woman_gesturing_ok::skin-tone-3:"] = "\uD83D\uDE46\uD83C\uDFFD\u200D♀️", + [":woman_gesturing_ok::skin-tone-4:"] = "\uD83D\uDE46\uD83C\uDFFE\u200D♀️", + [":woman_gesturing_ok::skin-tone-5:"] = "\uD83D\uDE46\uD83C\uDFFF\u200D♀️", + [":woman_gesturing_ok_dark_skin_tone:"] = "\uD83D\uDE46\uD83C\uDFFF\u200D♀️", + [":woman_gesturing_ok_light_skin_tone:"] = "\uD83D\uDE46\uD83C\uDFFB\u200D♀️", + [":woman_gesturing_ok_medium_dark_skin_tone:"] = "\uD83D\uDE46\uD83C\uDFFE\u200D♀️", + [":woman_gesturing_ok_medium_light_skin_tone:"] = "\uD83D\uDE46\uD83C\uDFFC\u200D♀️", + [":woman_gesturing_ok_medium_skin_tone:"] = "\uD83D\uDE46\uD83C\uDFFD\u200D♀️", + [":woman_gesturing_ok_tone1:"] = "\uD83D\uDE46\uD83C\uDFFB\u200D♀️", + [":woman_gesturing_ok_tone2:"] = "\uD83D\uDE46\uD83C\uDFFC\u200D♀️", + [":woman_gesturing_ok_tone3:"] = "\uD83D\uDE46\uD83C\uDFFD\u200D♀️", + [":woman_gesturing_ok_tone4:"] = "\uD83D\uDE46\uD83C\uDFFE\u200D♀️", + [":woman_gesturing_ok_tone5:"] = "\uD83D\uDE46\uD83C\uDFFF\u200D♀️", + [":woman_getting_face_massage:"] = "\uD83D\uDC86\u200D♀️", + [":woman_getting_face_massage::skin-tone-1:"] = "\uD83D\uDC86\uD83C\uDFFB\u200D♀️", + [":woman_getting_face_massage::skin-tone-2:"] = "\uD83D\uDC86\uD83C\uDFFC\u200D♀️", + [":woman_getting_face_massage::skin-tone-3:"] = "\uD83D\uDC86\uD83C\uDFFD\u200D♀️", + [":woman_getting_face_massage::skin-tone-4:"] = "\uD83D\uDC86\uD83C\uDFFE\u200D♀️", + [":woman_getting_face_massage::skin-tone-5:"] = "\uD83D\uDC86\uD83C\uDFFF\u200D♀️", + [":woman_getting_face_massage_dark_skin_tone:"] = "\uD83D\uDC86\uD83C\uDFFF\u200D♀️", + [":woman_getting_face_massage_light_skin_tone:"] = "\uD83D\uDC86\uD83C\uDFFB\u200D♀️", + [":woman_getting_face_massage_medium_dark_skin_tone:"] = "\uD83D\uDC86\uD83C\uDFFE\u200D♀️", + [":woman_getting_face_massage_medium_light_skin_tone:"] = "\uD83D\uDC86\uD83C\uDFFC\u200D♀️", + [":woman_getting_face_massage_medium_skin_tone:"] = "\uD83D\uDC86\uD83C\uDFFD\u200D♀️", + [":woman_getting_face_massage_tone1:"] = "\uD83D\uDC86\uD83C\uDFFB\u200D♀️", + [":woman_getting_face_massage_tone2:"] = "\uD83D\uDC86\uD83C\uDFFC\u200D♀️", + [":woman_getting_face_massage_tone3:"] = "\uD83D\uDC86\uD83C\uDFFD\u200D♀️", + [":woman_getting_face_massage_tone4:"] = "\uD83D\uDC86\uD83C\uDFFE\u200D♀️", + [":woman_getting_face_massage_tone5:"] = "\uD83D\uDC86\uD83C\uDFFF\u200D♀️", + [":woman_getting_haircut:"] = "\uD83D\uDC87\u200D♀️", + [":woman_getting_haircut::skin-tone-1:"] = "\uD83D\uDC87\uD83C\uDFFB\u200D♀️", + [":woman_getting_haircut::skin-tone-2:"] = "\uD83D\uDC87\uD83C\uDFFC\u200D♀️", + [":woman_getting_haircut::skin-tone-3:"] = "\uD83D\uDC87\uD83C\uDFFD\u200D♀️", + [":woman_getting_haircut::skin-tone-4:"] = "\uD83D\uDC87\uD83C\uDFFE\u200D♀️", + [":woman_getting_haircut::skin-tone-5:"] = "\uD83D\uDC87\uD83C\uDFFF\u200D♀️", + [":woman_getting_haircut_dark_skin_tone:"] = "\uD83D\uDC87\uD83C\uDFFF\u200D♀️", + [":woman_getting_haircut_light_skin_tone:"] = "\uD83D\uDC87\uD83C\uDFFB\u200D♀️", + [":woman_getting_haircut_medium_dark_skin_tone:"] = "\uD83D\uDC87\uD83C\uDFFE\u200D♀️", + [":woman_getting_haircut_medium_light_skin_tone:"] = "\uD83D\uDC87\uD83C\uDFFC\u200D♀️", + [":woman_getting_haircut_medium_skin_tone:"] = "\uD83D\uDC87\uD83C\uDFFD\u200D♀️", + [":woman_getting_haircut_tone1:"] = "\uD83D\uDC87\uD83C\uDFFB\u200D♀️", + [":woman_getting_haircut_tone2:"] = "\uD83D\uDC87\uD83C\uDFFC\u200D♀️", + [":woman_getting_haircut_tone3:"] = "\uD83D\uDC87\uD83C\uDFFD\u200D♀️", + [":woman_getting_haircut_tone4:"] = "\uD83D\uDC87\uD83C\uDFFE\u200D♀️", + [":woman_getting_haircut_tone5:"] = "\uD83D\uDC87\uD83C\uDFFF\u200D♀️", + [":woman_golfing:"] = "\uD83C\uDFCC️\u200D♀️", + [":woman_golfing::skin-tone-1:"] = "\uD83C\uDFCC\uD83C\uDFFB\u200D♀️", + [":woman_golfing::skin-tone-2:"] = "\uD83C\uDFCC\uD83C\uDFFC\u200D♀️", + [":woman_golfing::skin-tone-3:"] = "\uD83C\uDFCC\uD83C\uDFFD\u200D♀️", + [":woman_golfing::skin-tone-4:"] = "\uD83C\uDFCC\uD83C\uDFFE\u200D♀️", + [":woman_golfing::skin-tone-5:"] = "\uD83C\uDFCC\uD83C\uDFFF\u200D♀️", + [":woman_golfing_dark_skin_tone:"] = "\uD83C\uDFCC\uD83C\uDFFF\u200D♀️", + [":woman_golfing_light_skin_tone:"] = "\uD83C\uDFCC\uD83C\uDFFB\u200D♀️", + [":woman_golfing_medium_dark_skin_tone:"] = "\uD83C\uDFCC\uD83C\uDFFE\u200D♀️", + [":woman_golfing_medium_light_skin_tone:"] = "\uD83C\uDFCC\uD83C\uDFFC\u200D♀️", + [":woman_golfing_medium_skin_tone:"] = "\uD83C\uDFCC\uD83C\uDFFD\u200D♀️", + [":woman_golfing_tone1:"] = "\uD83C\uDFCC\uD83C\uDFFB\u200D♀️", + [":woman_golfing_tone2:"] = "\uD83C\uDFCC\uD83C\uDFFC\u200D♀️", + [":woman_golfing_tone3:"] = "\uD83C\uDFCC\uD83C\uDFFD\u200D♀️", + [":woman_golfing_tone4:"] = "\uD83C\uDFCC\uD83C\uDFFE\u200D♀️", + [":woman_golfing_tone5:"] = "\uD83C\uDFCC\uD83C\uDFFF\u200D♀️", + [":woman_guard:"] = "\uD83D\uDC82\u200D♀️", + [":woman_guard::skin-tone-1:"] = "\uD83D\uDC82\uD83C\uDFFB\u200D♀️", + [":woman_guard::skin-tone-2:"] = "\uD83D\uDC82\uD83C\uDFFC\u200D♀️", + [":woman_guard::skin-tone-3:"] = "\uD83D\uDC82\uD83C\uDFFD\u200D♀️", + [":woman_guard::skin-tone-4:"] = "\uD83D\uDC82\uD83C\uDFFE\u200D♀️", + [":woman_guard::skin-tone-5:"] = "\uD83D\uDC82\uD83C\uDFFF\u200D♀️", + [":woman_guard_dark_skin_tone:"] = "\uD83D\uDC82\uD83C\uDFFF\u200D♀️", + [":woman_guard_light_skin_tone:"] = "\uD83D\uDC82\uD83C\uDFFB\u200D♀️", + [":woman_guard_medium_dark_skin_tone:"] = "\uD83D\uDC82\uD83C\uDFFE\u200D♀️", + [":woman_guard_medium_light_skin_tone:"] = "\uD83D\uDC82\uD83C\uDFFC\u200D♀️", + [":woman_guard_medium_skin_tone:"] = "\uD83D\uDC82\uD83C\uDFFD\u200D♀️", + [":woman_guard_tone1:"] = "\uD83D\uDC82\uD83C\uDFFB\u200D♀️", + [":woman_guard_tone2:"] = "\uD83D\uDC82\uD83C\uDFFC\u200D♀️", + [":woman_guard_tone3:"] = "\uD83D\uDC82\uD83C\uDFFD\u200D♀️", + [":woman_guard_tone4:"] = "\uD83D\uDC82\uD83C\uDFFE\u200D♀️", + [":woman_guard_tone5:"] = "\uD83D\uDC82\uD83C\uDFFF\u200D♀️", + [":woman_health_worker:"] = "\uD83D\uDC69\u200D⚕️", + [":woman_health_worker::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D⚕️", + [":woman_health_worker::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D⚕️", + [":woman_health_worker::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D⚕️", + [":woman_health_worker::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D⚕️", + [":woman_health_worker::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D⚕️", + [":woman_health_worker_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D⚕️", + [":woman_health_worker_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D⚕️", + [":woman_health_worker_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D⚕️", + [":woman_health_worker_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D⚕️", + [":woman_health_worker_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D⚕️", + [":woman_health_worker_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D⚕️", + [":woman_health_worker_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D⚕️", + [":woman_health_worker_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D⚕️", + [":woman_health_worker_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D⚕️", + [":woman_health_worker_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D⚕️", + [":woman_in_lotus_position:"] = "\uD83E\uDDD8\u200D♀️", + [":woman_in_lotus_position::skin-tone-1:"] = "\uD83E\uDDD8\uD83C\uDFFB\u200D♀️", + [":woman_in_lotus_position::skin-tone-2:"] = "\uD83E\uDDD8\uD83C\uDFFC\u200D♀️", + [":woman_in_lotus_position::skin-tone-3:"] = "\uD83E\uDDD8\uD83C\uDFFD\u200D♀️", + [":woman_in_lotus_position::skin-tone-4:"] = "\uD83E\uDDD8\uD83C\uDFFE\u200D♀️", + [":woman_in_lotus_position::skin-tone-5:"] = "\uD83E\uDDD8\uD83C\uDFFF\u200D♀️", + [":woman_in_lotus_position_dark_skin_tone:"] = "\uD83E\uDDD8\uD83C\uDFFF\u200D♀️", + [":woman_in_lotus_position_light_skin_tone:"] = "\uD83E\uDDD8\uD83C\uDFFB\u200D♀️", + [":woman_in_lotus_position_medium_dark_skin_tone:"] = "\uD83E\uDDD8\uD83C\uDFFE\u200D♀️", + [":woman_in_lotus_position_medium_light_skin_tone:"] = "\uD83E\uDDD8\uD83C\uDFFC\u200D♀️", + [":woman_in_lotus_position_medium_skin_tone:"] = "\uD83E\uDDD8\uD83C\uDFFD\u200D♀️", + [":woman_in_lotus_position_tone1:"] = "\uD83E\uDDD8\uD83C\uDFFB\u200D♀️", + [":woman_in_lotus_position_tone2:"] = "\uD83E\uDDD8\uD83C\uDFFC\u200D♀️", + [":woman_in_lotus_position_tone3:"] = "\uD83E\uDDD8\uD83C\uDFFD\u200D♀️", + [":woman_in_lotus_position_tone4:"] = "\uD83E\uDDD8\uD83C\uDFFE\u200D♀️", + [":woman_in_lotus_position_tone5:"] = "\uD83E\uDDD8\uD83C\uDFFF\u200D♀️", + [":woman_in_manual_wheelchair:"] = "\uD83D\uDC69\u200D\uD83E\uDDBD", + [":woman_in_manual_wheelchair::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDBD", + [":woman_in_manual_wheelchair::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDBD", + [":woman_in_manual_wheelchair::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDBD", + [":woman_in_manual_wheelchair::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDBD", + [":woman_in_manual_wheelchair::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDBD", + [":woman_in_manual_wheelchair_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDBD", + [":woman_in_manual_wheelchair_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDBD", + [":woman_in_manual_wheelchair_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDBD", + [":woman_in_manual_wheelchair_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDBD", + [":woman_in_manual_wheelchair_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDBD", + [":woman_in_manual_wheelchair_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDBD", + [":woman_in_manual_wheelchair_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDBD", + [":woman_in_manual_wheelchair_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDBD", + [":woman_in_manual_wheelchair_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDBD", + [":woman_in_manual_wheelchair_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDBD", + [":woman_in_motorized_wheelchair:"] = "\uD83D\uDC69\u200D\uD83E\uDDBC", + [":woman_in_motorized_wheelchair::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDBC", + [":woman_in_motorized_wheelchair::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDBC", + [":woman_in_motorized_wheelchair::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDBC", + [":woman_in_motorized_wheelchair::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDBC", + [":woman_in_motorized_wheelchair::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDBC", + [":woman_in_motorized_wheelchair_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDBC", + [":woman_in_motorized_wheelchair_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDBC", + [":woman_in_motorized_wheelchair_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDBC", + [":woman_in_motorized_wheelchair_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDBC", + [":woman_in_motorized_wheelchair_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDBC", + [":woman_in_motorized_wheelchair_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDBC", + [":woman_in_motorized_wheelchair_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDBC", + [":woman_in_motorized_wheelchair_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDBC", + [":woman_in_motorized_wheelchair_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDBC", + [":woman_in_motorized_wheelchair_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDBC", + [":woman_in_steamy_room:"] = "\uD83E\uDDD6\u200D♀️", + [":woman_in_steamy_room::skin-tone-1:"] = "\uD83E\uDDD6\uD83C\uDFFB\u200D♀️", + [":woman_in_steamy_room::skin-tone-2:"] = "\uD83E\uDDD6\uD83C\uDFFC\u200D♀️", + [":woman_in_steamy_room::skin-tone-3:"] = "\uD83E\uDDD6\uD83C\uDFFD\u200D♀️", + [":woman_in_steamy_room::skin-tone-4:"] = "\uD83E\uDDD6\uD83C\uDFFE\u200D♀️", + [":woman_in_steamy_room::skin-tone-5:"] = "\uD83E\uDDD6\uD83C\uDFFF\u200D♀️", + [":woman_in_steamy_room_dark_skin_tone:"] = "\uD83E\uDDD6\uD83C\uDFFF\u200D♀️", + [":woman_in_steamy_room_light_skin_tone:"] = "\uD83E\uDDD6\uD83C\uDFFB\u200D♀️", + [":woman_in_steamy_room_medium_dark_skin_tone:"] = "\uD83E\uDDD6\uD83C\uDFFE\u200D♀️", + [":woman_in_steamy_room_medium_light_skin_tone:"] = "\uD83E\uDDD6\uD83C\uDFFC\u200D♀️", + [":woman_in_steamy_room_medium_skin_tone:"] = "\uD83E\uDDD6\uD83C\uDFFD\u200D♀️", + [":woman_in_steamy_room_tone1:"] = "\uD83E\uDDD6\uD83C\uDFFB\u200D♀️", + [":woman_in_steamy_room_tone2:"] = "\uD83E\uDDD6\uD83C\uDFFC\u200D♀️", + [":woman_in_steamy_room_tone3:"] = "\uD83E\uDDD6\uD83C\uDFFD\u200D♀️", + [":woman_in_steamy_room_tone4:"] = "\uD83E\uDDD6\uD83C\uDFFE\u200D♀️", + [":woman_in_steamy_room_tone5:"] = "\uD83E\uDDD6\uD83C\uDFFF\u200D♀️", + [":woman_judge:"] = "\uD83D\uDC69\u200D⚖️", + [":woman_judge::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D⚖️", + [":woman_judge::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D⚖️", + [":woman_judge::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D⚖️", + [":woman_judge::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D⚖️", + [":woman_judge::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D⚖️", + [":woman_judge_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D⚖️", + [":woman_judge_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D⚖️", + [":woman_judge_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D⚖️", + [":woman_judge_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D⚖️", + [":woman_judge_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D⚖️", + [":woman_judge_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D⚖️", + [":woman_judge_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D⚖️", + [":woman_judge_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D⚖️", + [":woman_judge_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D⚖️", + [":woman_judge_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D⚖️", + [":woman_juggling:"] = "\uD83E\uDD39\u200D♀️", + [":woman_juggling::skin-tone-1:"] = "\uD83E\uDD39\uD83C\uDFFB\u200D♀️", + [":woman_juggling::skin-tone-2:"] = "\uD83E\uDD39\uD83C\uDFFC\u200D♀️", + [":woman_juggling::skin-tone-3:"] = "\uD83E\uDD39\uD83C\uDFFD\u200D♀️", + [":woman_juggling::skin-tone-4:"] = "\uD83E\uDD39\uD83C\uDFFE\u200D♀️", + [":woman_juggling::skin-tone-5:"] = "\uD83E\uDD39\uD83C\uDFFF\u200D♀️", + [":woman_juggling_dark_skin_tone:"] = "\uD83E\uDD39\uD83C\uDFFF\u200D♀️", + [":woman_juggling_light_skin_tone:"] = "\uD83E\uDD39\uD83C\uDFFB\u200D♀️", + [":woman_juggling_medium_dark_skin_tone:"] = "\uD83E\uDD39\uD83C\uDFFE\u200D♀️", + [":woman_juggling_medium_light_skin_tone:"] = "\uD83E\uDD39\uD83C\uDFFC\u200D♀️", + [":woman_juggling_medium_skin_tone:"] = "\uD83E\uDD39\uD83C\uDFFD\u200D♀️", + [":woman_juggling_tone1:"] = "\uD83E\uDD39\uD83C\uDFFB\u200D♀️", + [":woman_juggling_tone2:"] = "\uD83E\uDD39\uD83C\uDFFC\u200D♀️", + [":woman_juggling_tone3:"] = "\uD83E\uDD39\uD83C\uDFFD\u200D♀️", + [":woman_juggling_tone4:"] = "\uD83E\uDD39\uD83C\uDFFE\u200D♀️", + [":woman_juggling_tone5:"] = "\uD83E\uDD39\uD83C\uDFFF\u200D♀️", + [":woman_kneeling:"] = "\uD83E\uDDCE\u200D♀️", + [":woman_kneeling::skin-tone-1:"] = "\uD83E\uDDCE\uD83C\uDFFB\u200D♀️", + [":woman_kneeling::skin-tone-2:"] = "\uD83E\uDDCE\uD83C\uDFFC\u200D♀️", + [":woman_kneeling::skin-tone-3:"] = "\uD83E\uDDCE\uD83C\uDFFD\u200D♀️", + [":woman_kneeling::skin-tone-4:"] = "\uD83E\uDDCE\uD83C\uDFFE\u200D♀️", + [":woman_kneeling::skin-tone-5:"] = "\uD83E\uDDCE\uD83C\uDFFF\u200D♀️", + [":woman_kneeling_dark_skin_tone:"] = "\uD83E\uDDCE\uD83C\uDFFF\u200D♀️", + [":woman_kneeling_light_skin_tone:"] = "\uD83E\uDDCE\uD83C\uDFFB\u200D♀️", + [":woman_kneeling_medium_dark_skin_tone:"] = "\uD83E\uDDCE\uD83C\uDFFE\u200D♀️", + [":woman_kneeling_medium_light_skin_tone:"] = "\uD83E\uDDCE\uD83C\uDFFC\u200D♀️", + [":woman_kneeling_medium_skin_tone:"] = "\uD83E\uDDCE\uD83C\uDFFD\u200D♀️", + [":woman_kneeling_tone1:"] = "\uD83E\uDDCE\uD83C\uDFFB\u200D♀️", + [":woman_kneeling_tone2:"] = "\uD83E\uDDCE\uD83C\uDFFC\u200D♀️", + [":woman_kneeling_tone3:"] = "\uD83E\uDDCE\uD83C\uDFFD\u200D♀️", + [":woman_kneeling_tone4:"] = "\uD83E\uDDCE\uD83C\uDFFE\u200D♀️", + [":woman_kneeling_tone5:"] = "\uD83E\uDDCE\uD83C\uDFFF\u200D♀️", + [":woman_lifting_weights:"] = "\uD83C\uDFCB️\u200D♀️", + [":woman_lifting_weights::skin-tone-1:"] = "\uD83C\uDFCB\uD83C\uDFFB\u200D♀️", + [":woman_lifting_weights::skin-tone-2:"] = "\uD83C\uDFCB\uD83C\uDFFC\u200D♀️", + [":woman_lifting_weights::skin-tone-3:"] = "\uD83C\uDFCB\uD83C\uDFFD\u200D♀️", + [":woman_lifting_weights::skin-tone-4:"] = "\uD83C\uDFCB\uD83C\uDFFE\u200D♀️", + [":woman_lifting_weights::skin-tone-5:"] = "\uD83C\uDFCB\uD83C\uDFFF\u200D♀️", + [":woman_lifting_weights_dark_skin_tone:"] = "\uD83C\uDFCB\uD83C\uDFFF\u200D♀️", + [":woman_lifting_weights_light_skin_tone:"] = "\uD83C\uDFCB\uD83C\uDFFB\u200D♀️", + [":woman_lifting_weights_medium_dark_skin_tone:"] = "\uD83C\uDFCB\uD83C\uDFFE\u200D♀️", + [":woman_lifting_weights_medium_light_skin_tone:"] = "\uD83C\uDFCB\uD83C\uDFFC\u200D♀️", + [":woman_lifting_weights_medium_skin_tone:"] = "\uD83C\uDFCB\uD83C\uDFFD\u200D♀️", + [":woman_lifting_weights_tone1:"] = "\uD83C\uDFCB\uD83C\uDFFB\u200D♀️", + [":woman_lifting_weights_tone2:"] = "\uD83C\uDFCB\uD83C\uDFFC\u200D♀️", + [":woman_lifting_weights_tone3:"] = "\uD83C\uDFCB\uD83C\uDFFD\u200D♀️", + [":woman_lifting_weights_tone4:"] = "\uD83C\uDFCB\uD83C\uDFFE\u200D♀️", + [":woman_lifting_weights_tone5:"] = "\uD83C\uDFCB\uD83C\uDFFF\u200D♀️", + [":woman_mage:"] = "\uD83E\uDDD9\u200D♀️", + [":woman_mage::skin-tone-1:"] = "\uD83E\uDDD9\uD83C\uDFFB\u200D♀️", + [":woman_mage::skin-tone-2:"] = "\uD83E\uDDD9\uD83C\uDFFC\u200D♀️", + [":woman_mage::skin-tone-3:"] = "\uD83E\uDDD9\uD83C\uDFFD\u200D♀️", + [":woman_mage::skin-tone-4:"] = "\uD83E\uDDD9\uD83C\uDFFE\u200D♀️", + [":woman_mage::skin-tone-5:"] = "\uD83E\uDDD9\uD83C\uDFFF\u200D♀️", + [":woman_mage_dark_skin_tone:"] = "\uD83E\uDDD9\uD83C\uDFFF\u200D♀️", + [":woman_mage_light_skin_tone:"] = "\uD83E\uDDD9\uD83C\uDFFB\u200D♀️", + [":woman_mage_medium_dark_skin_tone:"] = "\uD83E\uDDD9\uD83C\uDFFE\u200D♀️", + [":woman_mage_medium_light_skin_tone:"] = "\uD83E\uDDD9\uD83C\uDFFC\u200D♀️", + [":woman_mage_medium_skin_tone:"] = "\uD83E\uDDD9\uD83C\uDFFD\u200D♀️", + [":woman_mage_tone1:"] = "\uD83E\uDDD9\uD83C\uDFFB\u200D♀️", + [":woman_mage_tone2:"] = "\uD83E\uDDD9\uD83C\uDFFC\u200D♀️", + [":woman_mage_tone3:"] = "\uD83E\uDDD9\uD83C\uDFFD\u200D♀️", + [":woman_mage_tone4:"] = "\uD83E\uDDD9\uD83C\uDFFE\u200D♀️", + [":woman_mage_tone5:"] = "\uD83E\uDDD9\uD83C\uDFFF\u200D♀️", + [":woman_mechanic:"] = "\uD83D\uDC69\u200D\uD83D\uDD27", + [":woman_mechanic::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDD27", + [":woman_mechanic::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDD27", + [":woman_mechanic::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDD27", + [":woman_mechanic::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDD27", + [":woman_mechanic::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDD27", + [":woman_mechanic_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDD27", + [":woman_mechanic_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDD27", + [":woman_mechanic_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDD27", + [":woman_mechanic_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDD27", + [":woman_mechanic_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDD27", + [":woman_mechanic_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDD27", + [":woman_mechanic_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDD27", + [":woman_mechanic_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDD27", + [":woman_mechanic_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDD27", + [":woman_mechanic_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDD27", + [":woman_mountain_biking:"] = "\uD83D\uDEB5\u200D♀️", + [":woman_mountain_biking::skin-tone-1:"] = "\uD83D\uDEB5\uD83C\uDFFB\u200D♀️", + [":woman_mountain_biking::skin-tone-2:"] = "\uD83D\uDEB5\uD83C\uDFFC\u200D♀️", + [":woman_mountain_biking::skin-tone-3:"] = "\uD83D\uDEB5\uD83C\uDFFD\u200D♀️", + [":woman_mountain_biking::skin-tone-4:"] = "\uD83D\uDEB5\uD83C\uDFFE\u200D♀️", + [":woman_mountain_biking::skin-tone-5:"] = "\uD83D\uDEB5\uD83C\uDFFF\u200D♀️", + [":woman_mountain_biking_dark_skin_tone:"] = "\uD83D\uDEB5\uD83C\uDFFF\u200D♀️", + [":woman_mountain_biking_light_skin_tone:"] = "\uD83D\uDEB5\uD83C\uDFFB\u200D♀️", + [":woman_mountain_biking_medium_dark_skin_tone:"] = "\uD83D\uDEB5\uD83C\uDFFE\u200D♀️", + [":woman_mountain_biking_medium_light_skin_tone:"] = "\uD83D\uDEB5\uD83C\uDFFC\u200D♀️", + [":woman_mountain_biking_medium_skin_tone:"] = "\uD83D\uDEB5\uD83C\uDFFD\u200D♀️", + [":woman_mountain_biking_tone1:"] = "\uD83D\uDEB5\uD83C\uDFFB\u200D♀️", + [":woman_mountain_biking_tone2:"] = "\uD83D\uDEB5\uD83C\uDFFC\u200D♀️", + [":woman_mountain_biking_tone3:"] = "\uD83D\uDEB5\uD83C\uDFFD\u200D♀️", + [":woman_mountain_biking_tone4:"] = "\uD83D\uDEB5\uD83C\uDFFE\u200D♀️", + [":woman_mountain_biking_tone5:"] = "\uD83D\uDEB5\uD83C\uDFFF\u200D♀️", + [":woman_office_worker:"] = "\uD83D\uDC69\u200D\uD83D\uDCBC", + [":woman_office_worker::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDCBC", + [":woman_office_worker::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDCBC", + [":woman_office_worker::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDCBC", + [":woman_office_worker::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDCBC", + [":woman_office_worker::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDCBC", + [":woman_office_worker_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDCBC", + [":woman_office_worker_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDCBC", + [":woman_office_worker_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDCBC", + [":woman_office_worker_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDCBC", + [":woman_office_worker_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDCBC", + [":woman_office_worker_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDCBC", + [":woman_office_worker_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDCBC", + [":woman_office_worker_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDCBC", + [":woman_office_worker_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDCBC", + [":woman_office_worker_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDCBC", + [":woman_pilot:"] = "\uD83D\uDC69\u200D✈️", + [":woman_pilot::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D✈️", + [":woman_pilot::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D✈️", + [":woman_pilot::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D✈️", + [":woman_pilot::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D✈️", + [":woman_pilot::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D✈️", + [":woman_pilot_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D✈️", + [":woman_pilot_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D✈️", + [":woman_pilot_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D✈️", + [":woman_pilot_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D✈️", + [":woman_pilot_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D✈️", + [":woman_pilot_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D✈️", + [":woman_pilot_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D✈️", + [":woman_pilot_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D✈️", + [":woman_pilot_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D✈️", + [":woman_pilot_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D✈️", + [":woman_playing_handball:"] = "\uD83E\uDD3E\u200D♀️", + [":woman_playing_handball::skin-tone-1:"] = "\uD83E\uDD3E\uD83C\uDFFB\u200D♀️", + [":woman_playing_handball::skin-tone-2:"] = "\uD83E\uDD3E\uD83C\uDFFC\u200D♀️", + [":woman_playing_handball::skin-tone-3:"] = "\uD83E\uDD3E\uD83C\uDFFD\u200D♀️", + [":woman_playing_handball::skin-tone-4:"] = "\uD83E\uDD3E\uD83C\uDFFE\u200D♀️", + [":woman_playing_handball::skin-tone-5:"] = "\uD83E\uDD3E\uD83C\uDFFF\u200D♀️", + [":woman_playing_handball_dark_skin_tone:"] = "\uD83E\uDD3E\uD83C\uDFFF\u200D♀️", + [":woman_playing_handball_light_skin_tone:"] = "\uD83E\uDD3E\uD83C\uDFFB\u200D♀️", + [":woman_playing_handball_medium_dark_skin_tone:"] = "\uD83E\uDD3E\uD83C\uDFFE\u200D♀️", + [":woman_playing_handball_medium_light_skin_tone:"] = "\uD83E\uDD3E\uD83C\uDFFC\u200D♀️", + [":woman_playing_handball_medium_skin_tone:"] = "\uD83E\uDD3E\uD83C\uDFFD\u200D♀️", + [":woman_playing_handball_tone1:"] = "\uD83E\uDD3E\uD83C\uDFFB\u200D♀️", + [":woman_playing_handball_tone2:"] = "\uD83E\uDD3E\uD83C\uDFFC\u200D♀️", + [":woman_playing_handball_tone3:"] = "\uD83E\uDD3E\uD83C\uDFFD\u200D♀️", + [":woman_playing_handball_tone4:"] = "\uD83E\uDD3E\uD83C\uDFFE\u200D♀️", + [":woman_playing_handball_tone5:"] = "\uD83E\uDD3E\uD83C\uDFFF\u200D♀️", + [":woman_playing_water_polo:"] = "\uD83E\uDD3D\u200D♀️", + [":woman_playing_water_polo::skin-tone-1:"] = "\uD83E\uDD3D\uD83C\uDFFB\u200D♀️", + [":woman_playing_water_polo::skin-tone-2:"] = "\uD83E\uDD3D\uD83C\uDFFC\u200D♀️", + [":woman_playing_water_polo::skin-tone-3:"] = "\uD83E\uDD3D\uD83C\uDFFD\u200D♀️", + [":woman_playing_water_polo::skin-tone-4:"] = "\uD83E\uDD3D\uD83C\uDFFE\u200D♀️", + [":woman_playing_water_polo::skin-tone-5:"] = "\uD83E\uDD3D\uD83C\uDFFF\u200D♀️", + [":woman_playing_water_polo_dark_skin_tone:"] = "\uD83E\uDD3D\uD83C\uDFFF\u200D♀️", + [":woman_playing_water_polo_light_skin_tone:"] = "\uD83E\uDD3D\uD83C\uDFFB\u200D♀️", + [":woman_playing_water_polo_medium_dark_skin_tone:"] = "\uD83E\uDD3D\uD83C\uDFFE\u200D♀️", + [":woman_playing_water_polo_medium_light_skin_tone:"] = "\uD83E\uDD3D\uD83C\uDFFC\u200D♀️", + [":woman_playing_water_polo_medium_skin_tone:"] = "\uD83E\uDD3D\uD83C\uDFFD\u200D♀️", + [":woman_playing_water_polo_tone1:"] = "\uD83E\uDD3D\uD83C\uDFFB\u200D♀️", + [":woman_playing_water_polo_tone2:"] = "\uD83E\uDD3D\uD83C\uDFFC\u200D♀️", + [":woman_playing_water_polo_tone3:"] = "\uD83E\uDD3D\uD83C\uDFFD\u200D♀️", + [":woman_playing_water_polo_tone4:"] = "\uD83E\uDD3D\uD83C\uDFFE\u200D♀️", + [":woman_playing_water_polo_tone5:"] = "\uD83E\uDD3D\uD83C\uDFFF\u200D♀️", + [":woman_police_officer:"] = "\uD83D\uDC6E\u200D♀️", + [":woman_police_officer::skin-tone-1:"] = "\uD83D\uDC6E\uD83C\uDFFB\u200D♀️", + [":woman_police_officer::skin-tone-2:"] = "\uD83D\uDC6E\uD83C\uDFFC\u200D♀️", + [":woman_police_officer::skin-tone-3:"] = "\uD83D\uDC6E\uD83C\uDFFD\u200D♀️", + [":woman_police_officer::skin-tone-4:"] = "\uD83D\uDC6E\uD83C\uDFFE\u200D♀️", + [":woman_police_officer::skin-tone-5:"] = "\uD83D\uDC6E\uD83C\uDFFF\u200D♀️", + [":woman_police_officer_dark_skin_tone:"] = "\uD83D\uDC6E\uD83C\uDFFF\u200D♀️", + [":woman_police_officer_light_skin_tone:"] = "\uD83D\uDC6E\uD83C\uDFFB\u200D♀️", + [":woman_police_officer_medium_dark_skin_tone:"] = "\uD83D\uDC6E\uD83C\uDFFE\u200D♀️", + [":woman_police_officer_medium_light_skin_tone:"] = "\uD83D\uDC6E\uD83C\uDFFC\u200D♀️", + [":woman_police_officer_medium_skin_tone:"] = "\uD83D\uDC6E\uD83C\uDFFD\u200D♀️", + [":woman_police_officer_tone1:"] = "\uD83D\uDC6E\uD83C\uDFFB\u200D♀️", + [":woman_police_officer_tone2:"] = "\uD83D\uDC6E\uD83C\uDFFC\u200D♀️", + [":woman_police_officer_tone3:"] = "\uD83D\uDC6E\uD83C\uDFFD\u200D♀️", + [":woman_police_officer_tone4:"] = "\uD83D\uDC6E\uD83C\uDFFE\u200D♀️", + [":woman_police_officer_tone5:"] = "\uD83D\uDC6E\uD83C\uDFFF\u200D♀️", + [":woman_pouting:"] = "\uD83D\uDE4E\u200D♀️", + [":woman_pouting::skin-tone-1:"] = "\uD83D\uDE4E\uD83C\uDFFB\u200D♀️", + [":woman_pouting::skin-tone-2:"] = "\uD83D\uDE4E\uD83C\uDFFC\u200D♀️", + [":woman_pouting::skin-tone-3:"] = "\uD83D\uDE4E\uD83C\uDFFD\u200D♀️", + [":woman_pouting::skin-tone-4:"] = "\uD83D\uDE4E\uD83C\uDFFE\u200D♀️", + [":woman_pouting::skin-tone-5:"] = "\uD83D\uDE4E\uD83C\uDFFF\u200D♀️", + [":woman_pouting_dark_skin_tone:"] = "\uD83D\uDE4E\uD83C\uDFFF\u200D♀️", + [":woman_pouting_light_skin_tone:"] = "\uD83D\uDE4E\uD83C\uDFFB\u200D♀️", + [":woman_pouting_medium_dark_skin_tone:"] = "\uD83D\uDE4E\uD83C\uDFFE\u200D♀️", + [":woman_pouting_medium_light_skin_tone:"] = "\uD83D\uDE4E\uD83C\uDFFC\u200D♀️", + [":woman_pouting_medium_skin_tone:"] = "\uD83D\uDE4E\uD83C\uDFFD\u200D♀️", + [":woman_pouting_tone1:"] = "\uD83D\uDE4E\uD83C\uDFFB\u200D♀️", + [":woman_pouting_tone2:"] = "\uD83D\uDE4E\uD83C\uDFFC\u200D♀️", + [":woman_pouting_tone3:"] = "\uD83D\uDE4E\uD83C\uDFFD\u200D♀️", + [":woman_pouting_tone4:"] = "\uD83D\uDE4E\uD83C\uDFFE\u200D♀️", + [":woman_pouting_tone5:"] = "\uD83D\uDE4E\uD83C\uDFFF\u200D♀️", + [":woman_raising_hand:"] = "\uD83D\uDE4B\u200D♀️", + [":woman_raising_hand::skin-tone-1:"] = "\uD83D\uDE4B\uD83C\uDFFB\u200D♀️", + [":woman_raising_hand::skin-tone-2:"] = "\uD83D\uDE4B\uD83C\uDFFC\u200D♀️", + [":woman_raising_hand::skin-tone-3:"] = "\uD83D\uDE4B\uD83C\uDFFD\u200D♀️", + [":woman_raising_hand::skin-tone-4:"] = "\uD83D\uDE4B\uD83C\uDFFE\u200D♀️", + [":woman_raising_hand::skin-tone-5:"] = "\uD83D\uDE4B\uD83C\uDFFF\u200D♀️", + [":woman_raising_hand_dark_skin_tone:"] = "\uD83D\uDE4B\uD83C\uDFFF\u200D♀️", + [":woman_raising_hand_light_skin_tone:"] = "\uD83D\uDE4B\uD83C\uDFFB\u200D♀️", + [":woman_raising_hand_medium_dark_skin_tone:"] = "\uD83D\uDE4B\uD83C\uDFFE\u200D♀️", + [":woman_raising_hand_medium_light_skin_tone:"] = "\uD83D\uDE4B\uD83C\uDFFC\u200D♀️", + [":woman_raising_hand_medium_skin_tone:"] = "\uD83D\uDE4B\uD83C\uDFFD\u200D♀️", + [":woman_raising_hand_tone1:"] = "\uD83D\uDE4B\uD83C\uDFFB\u200D♀️", + [":woman_raising_hand_tone2:"] = "\uD83D\uDE4B\uD83C\uDFFC\u200D♀️", + [":woman_raising_hand_tone3:"] = "\uD83D\uDE4B\uD83C\uDFFD\u200D♀️", + [":woman_raising_hand_tone4:"] = "\uD83D\uDE4B\uD83C\uDFFE\u200D♀️", + [":woman_raising_hand_tone5:"] = "\uD83D\uDE4B\uD83C\uDFFF\u200D♀️", + [":woman_red_haired:"] = "\uD83D\uDC69\u200D\uD83E\uDDB0", + [":woman_red_haired::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDB0", + [":woman_red_haired::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDB0", + [":woman_red_haired::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDB0", + [":woman_red_haired::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDB0", + [":woman_red_haired::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDB0", + [":woman_red_haired_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDB0", + [":woman_red_haired_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDB0", + [":woman_red_haired_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDB0", + [":woman_red_haired_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDB0", + [":woman_red_haired_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDB0", + [":woman_red_haired_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDB0", + [":woman_red_haired_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDB0", + [":woman_red_haired_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDB0", + [":woman_red_haired_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDB0", + [":woman_red_haired_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDB0", + [":woman_rowing_boat:"] = "\uD83D\uDEA3\u200D♀️", + [":woman_rowing_boat::skin-tone-1:"] = "\uD83D\uDEA3\uD83C\uDFFB\u200D♀️", + [":woman_rowing_boat::skin-tone-2:"] = "\uD83D\uDEA3\uD83C\uDFFC\u200D♀️", + [":woman_rowing_boat::skin-tone-3:"] = "\uD83D\uDEA3\uD83C\uDFFD\u200D♀️", + [":woman_rowing_boat::skin-tone-4:"] = "\uD83D\uDEA3\uD83C\uDFFE\u200D♀️", + [":woman_rowing_boat::skin-tone-5:"] = "\uD83D\uDEA3\uD83C\uDFFF\u200D♀️", + [":woman_rowing_boat_dark_skin_tone:"] = "\uD83D\uDEA3\uD83C\uDFFF\u200D♀️", + [":woman_rowing_boat_light_skin_tone:"] = "\uD83D\uDEA3\uD83C\uDFFB\u200D♀️", + [":woman_rowing_boat_medium_dark_skin_tone:"] = "\uD83D\uDEA3\uD83C\uDFFE\u200D♀️", + [":woman_rowing_boat_medium_light_skin_tone:"] = "\uD83D\uDEA3\uD83C\uDFFC\u200D♀️", + [":woman_rowing_boat_medium_skin_tone:"] = "\uD83D\uDEA3\uD83C\uDFFD\u200D♀️", + [":woman_rowing_boat_tone1:"] = "\uD83D\uDEA3\uD83C\uDFFB\u200D♀️", + [":woman_rowing_boat_tone2:"] = "\uD83D\uDEA3\uD83C\uDFFC\u200D♀️", + [":woman_rowing_boat_tone3:"] = "\uD83D\uDEA3\uD83C\uDFFD\u200D♀️", + [":woman_rowing_boat_tone4:"] = "\uD83D\uDEA3\uD83C\uDFFE\u200D♀️", + [":woman_rowing_boat_tone5:"] = "\uD83D\uDEA3\uD83C\uDFFF\u200D♀️", + [":woman_running:"] = "\uD83C\uDFC3\u200D♀️", + [":woman_running::skin-tone-1:"] = "\uD83C\uDFC3\uD83C\uDFFB\u200D♀️", + [":woman_running::skin-tone-2:"] = "\uD83C\uDFC3\uD83C\uDFFC\u200D♀️", + [":woman_running::skin-tone-3:"] = "\uD83C\uDFC3\uD83C\uDFFD\u200D♀️", + [":woman_running::skin-tone-4:"] = "\uD83C\uDFC3\uD83C\uDFFE\u200D♀️", + [":woman_running::skin-tone-5:"] = "\uD83C\uDFC3\uD83C\uDFFF\u200D♀️", + [":woman_running_dark_skin_tone:"] = "\uD83C\uDFC3\uD83C\uDFFF\u200D♀️", + [":woman_running_light_skin_tone:"] = "\uD83C\uDFC3\uD83C\uDFFB\u200D♀️", + [":woman_running_medium_dark_skin_tone:"] = "\uD83C\uDFC3\uD83C\uDFFE\u200D♀️", + [":woman_running_medium_light_skin_tone:"] = "\uD83C\uDFC3\uD83C\uDFFC\u200D♀️", + [":woman_running_medium_skin_tone:"] = "\uD83C\uDFC3\uD83C\uDFFD\u200D♀️", + [":woman_running_tone1:"] = "\uD83C\uDFC3\uD83C\uDFFB\u200D♀️", + [":woman_running_tone2:"] = "\uD83C\uDFC3\uD83C\uDFFC\u200D♀️", + [":woman_running_tone3:"] = "\uD83C\uDFC3\uD83C\uDFFD\u200D♀️", + [":woman_running_tone4:"] = "\uD83C\uDFC3\uD83C\uDFFE\u200D♀️", + [":woman_running_tone5:"] = "\uD83C\uDFC3\uD83C\uDFFF\u200D♀️", + [":woman_scientist:"] = "\uD83D\uDC69\u200D\uD83D\uDD2C", + [":woman_scientist::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDD2C", + [":woman_scientist::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDD2C", + [":woman_scientist::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDD2C", + [":woman_scientist::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDD2C", + [":woman_scientist::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDD2C", + [":woman_scientist_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDD2C", + [":woman_scientist_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDD2C", + [":woman_scientist_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDD2C", + [":woman_scientist_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDD2C", + [":woman_scientist_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDD2C", + [":woman_scientist_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDD2C", + [":woman_scientist_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDD2C", + [":woman_scientist_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDD2C", + [":woman_scientist_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDD2C", + [":woman_scientist_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDD2C", + [":woman_shrugging:"] = "\uD83E\uDD37\u200D♀️", + [":woman_shrugging::skin-tone-1:"] = "\uD83E\uDD37\uD83C\uDFFB\u200D♀️", + [":woman_shrugging::skin-tone-2:"] = "\uD83E\uDD37\uD83C\uDFFC\u200D♀️", + [":woman_shrugging::skin-tone-3:"] = "\uD83E\uDD37\uD83C\uDFFD\u200D♀️", + [":woman_shrugging::skin-tone-4:"] = "\uD83E\uDD37\uD83C\uDFFE\u200D♀️", + [":woman_shrugging::skin-tone-5:"] = "\uD83E\uDD37\uD83C\uDFFF\u200D♀️", + [":woman_shrugging_dark_skin_tone:"] = "\uD83E\uDD37\uD83C\uDFFF\u200D♀️", + [":woman_shrugging_light_skin_tone:"] = "\uD83E\uDD37\uD83C\uDFFB\u200D♀️", + [":woman_shrugging_medium_dark_skin_tone:"] = "\uD83E\uDD37\uD83C\uDFFE\u200D♀️", + [":woman_shrugging_medium_light_skin_tone:"] = "\uD83E\uDD37\uD83C\uDFFC\u200D♀️", + [":woman_shrugging_medium_skin_tone:"] = "\uD83E\uDD37\uD83C\uDFFD\u200D♀️", + [":woman_shrugging_tone1:"] = "\uD83E\uDD37\uD83C\uDFFB\u200D♀️", + [":woman_shrugging_tone2:"] = "\uD83E\uDD37\uD83C\uDFFC\u200D♀️", + [":woman_shrugging_tone3:"] = "\uD83E\uDD37\uD83C\uDFFD\u200D♀️", + [":woman_shrugging_tone4:"] = "\uD83E\uDD37\uD83C\uDFFE\u200D♀️", + [":woman_shrugging_tone5:"] = "\uD83E\uDD37\uD83C\uDFFF\u200D♀️", + [":woman_singer:"] = "\uD83D\uDC69\u200D\uD83C\uDFA4", + [":woman_singer::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDFA4", + [":woman_singer::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDFA4", + [":woman_singer::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDFA4", + [":woman_singer::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDFA4", + [":woman_singer::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDFA4", + [":woman_singer_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDFA4", + [":woman_singer_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDFA4", + [":woman_singer_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDFA4", + [":woman_singer_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDFA4", + [":woman_singer_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDFA4", + [":woman_singer_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDFA4", + [":woman_singer_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDFA4", + [":woman_singer_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDFA4", + [":woman_singer_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDFA4", + [":woman_singer_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDFA4", + [":woman_standing:"] = "\uD83E\uDDCD\u200D♀️", + [":woman_standing::skin-tone-1:"] = "\uD83E\uDDCD\uD83C\uDFFB\u200D♀️", + [":woman_standing::skin-tone-2:"] = "\uD83E\uDDCD\uD83C\uDFFC\u200D♀️", + [":woman_standing::skin-tone-3:"] = "\uD83E\uDDCD\uD83C\uDFFD\u200D♀️", + [":woman_standing::skin-tone-4:"] = "\uD83E\uDDCD\uD83C\uDFFE\u200D♀️", + [":woman_standing::skin-tone-5:"] = "\uD83E\uDDCD\uD83C\uDFFF\u200D♀️", + [":woman_standing_dark_skin_tone:"] = "\uD83E\uDDCD\uD83C\uDFFF\u200D♀️", + [":woman_standing_light_skin_tone:"] = "\uD83E\uDDCD\uD83C\uDFFB\u200D♀️", + [":woman_standing_medium_dark_skin_tone:"] = "\uD83E\uDDCD\uD83C\uDFFE\u200D♀️", + [":woman_standing_medium_light_skin_tone:"] = "\uD83E\uDDCD\uD83C\uDFFC\u200D♀️", + [":woman_standing_medium_skin_tone:"] = "\uD83E\uDDCD\uD83C\uDFFD\u200D♀️", + [":woman_standing_tone1:"] = "\uD83E\uDDCD\uD83C\uDFFB\u200D♀️", + [":woman_standing_tone2:"] = "\uD83E\uDDCD\uD83C\uDFFC\u200D♀️", + [":woman_standing_tone3:"] = "\uD83E\uDDCD\uD83C\uDFFD\u200D♀️", + [":woman_standing_tone4:"] = "\uD83E\uDDCD\uD83C\uDFFE\u200D♀️", + [":woman_standing_tone5:"] = "\uD83E\uDDCD\uD83C\uDFFF\u200D♀️", + [":woman_student:"] = "\uD83D\uDC69\u200D\uD83C\uDF93", + [":woman_student::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDF93", + [":woman_student::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDF93", + [":woman_student::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDF93", + [":woman_student::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDF93", + [":woman_student::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDF93", + [":woman_student_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDF93", + [":woman_student_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDF93", + [":woman_student_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDF93", + [":woman_student_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDF93", + [":woman_student_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDF93", + [":woman_student_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDF93", + [":woman_student_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDF93", + [":woman_student_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDF93", + [":woman_student_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDF93", + [":woman_student_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDF93", + [":woman_superhero:"] = "\uD83E\uDDB8\u200D♀️", + [":woman_superhero::skin-tone-1:"] = "\uD83E\uDDB8\uD83C\uDFFB\u200D♀️", + [":woman_superhero::skin-tone-2:"] = "\uD83E\uDDB8\uD83C\uDFFC\u200D♀️", + [":woman_superhero::skin-tone-3:"] = "\uD83E\uDDB8\uD83C\uDFFD\u200D♀️", + [":woman_superhero::skin-tone-4:"] = "\uD83E\uDDB8\uD83C\uDFFE\u200D♀️", + [":woman_superhero::skin-tone-5:"] = "\uD83E\uDDB8\uD83C\uDFFF\u200D♀️", + [":woman_superhero_dark_skin_tone:"] = "\uD83E\uDDB8\uD83C\uDFFF\u200D♀️", + [":woman_superhero_light_skin_tone:"] = "\uD83E\uDDB8\uD83C\uDFFB\u200D♀️", + [":woman_superhero_medium_dark_skin_tone:"] = "\uD83E\uDDB8\uD83C\uDFFE\u200D♀️", + [":woman_superhero_medium_light_skin_tone:"] = "\uD83E\uDDB8\uD83C\uDFFC\u200D♀️", + [":woman_superhero_medium_skin_tone:"] = "\uD83E\uDDB8\uD83C\uDFFD\u200D♀️", + [":woman_superhero_tone1:"] = "\uD83E\uDDB8\uD83C\uDFFB\u200D♀️", + [":woman_superhero_tone2:"] = "\uD83E\uDDB8\uD83C\uDFFC\u200D♀️", + [":woman_superhero_tone3:"] = "\uD83E\uDDB8\uD83C\uDFFD\u200D♀️", + [":woman_superhero_tone4:"] = "\uD83E\uDDB8\uD83C\uDFFE\u200D♀️", + [":woman_superhero_tone5:"] = "\uD83E\uDDB8\uD83C\uDFFF\u200D♀️", + [":woman_supervillain:"] = "\uD83E\uDDB9\u200D♀️", + [":woman_supervillain::skin-tone-1:"] = "\uD83E\uDDB9\uD83C\uDFFB\u200D♀️", + [":woman_supervillain::skin-tone-2:"] = "\uD83E\uDDB9\uD83C\uDFFC\u200D♀️", + [":woman_supervillain::skin-tone-3:"] = "\uD83E\uDDB9\uD83C\uDFFD\u200D♀️", + [":woman_supervillain::skin-tone-4:"] = "\uD83E\uDDB9\uD83C\uDFFE\u200D♀️", + [":woman_supervillain::skin-tone-5:"] = "\uD83E\uDDB9\uD83C\uDFFF\u200D♀️", + [":woman_supervillain_dark_skin_tone:"] = "\uD83E\uDDB9\uD83C\uDFFF\u200D♀️", + [":woman_supervillain_light_skin_tone:"] = "\uD83E\uDDB9\uD83C\uDFFB\u200D♀️", + [":woman_supervillain_medium_dark_skin_tone:"] = "\uD83E\uDDB9\uD83C\uDFFE\u200D♀️", + [":woman_supervillain_medium_light_skin_tone:"] = "\uD83E\uDDB9\uD83C\uDFFC\u200D♀️", + [":woman_supervillain_medium_skin_tone:"] = "\uD83E\uDDB9\uD83C\uDFFD\u200D♀️", + [":woman_supervillain_tone1:"] = "\uD83E\uDDB9\uD83C\uDFFB\u200D♀️", + [":woman_supervillain_tone2:"] = "\uD83E\uDDB9\uD83C\uDFFC\u200D♀️", + [":woman_supervillain_tone3:"] = "\uD83E\uDDB9\uD83C\uDFFD\u200D♀️", + [":woman_supervillain_tone4:"] = "\uD83E\uDDB9\uD83C\uDFFE\u200D♀️", + [":woman_supervillain_tone5:"] = "\uD83E\uDDB9\uD83C\uDFFF\u200D♀️", + [":woman_surfing:"] = "\uD83C\uDFC4\u200D♀️", + [":woman_surfing::skin-tone-1:"] = "\uD83C\uDFC4\uD83C\uDFFB\u200D♀️", + [":woman_surfing::skin-tone-2:"] = "\uD83C\uDFC4\uD83C\uDFFC\u200D♀️", + [":woman_surfing::skin-tone-3:"] = "\uD83C\uDFC4\uD83C\uDFFD\u200D♀️", + [":woman_surfing::skin-tone-4:"] = "\uD83C\uDFC4\uD83C\uDFFE\u200D♀️", + [":woman_surfing::skin-tone-5:"] = "\uD83C\uDFC4\uD83C\uDFFF\u200D♀️", + [":woman_surfing_dark_skin_tone:"] = "\uD83C\uDFC4\uD83C\uDFFF\u200D♀️", + [":woman_surfing_light_skin_tone:"] = "\uD83C\uDFC4\uD83C\uDFFB\u200D♀️", + [":woman_surfing_medium_dark_skin_tone:"] = "\uD83C\uDFC4\uD83C\uDFFE\u200D♀️", + [":woman_surfing_medium_light_skin_tone:"] = "\uD83C\uDFC4\uD83C\uDFFC\u200D♀️", + [":woman_surfing_medium_skin_tone:"] = "\uD83C\uDFC4\uD83C\uDFFD\u200D♀️", + [":woman_surfing_tone1:"] = "\uD83C\uDFC4\uD83C\uDFFB\u200D♀️", + [":woman_surfing_tone2:"] = "\uD83C\uDFC4\uD83C\uDFFC\u200D♀️", + [":woman_surfing_tone3:"] = "\uD83C\uDFC4\uD83C\uDFFD\u200D♀️", + [":woman_surfing_tone4:"] = "\uD83C\uDFC4\uD83C\uDFFE\u200D♀️", + [":woman_surfing_tone5:"] = "\uD83C\uDFC4\uD83C\uDFFF\u200D♀️", + [":woman_swimming:"] = "\uD83C\uDFCA\u200D♀️", + [":woman_swimming::skin-tone-1:"] = "\uD83C\uDFCA\uD83C\uDFFB\u200D♀️", + [":woman_swimming::skin-tone-2:"] = "\uD83C\uDFCA\uD83C\uDFFC\u200D♀️", + [":woman_swimming::skin-tone-3:"] = "\uD83C\uDFCA\uD83C\uDFFD\u200D♀️", + [":woman_swimming::skin-tone-4:"] = "\uD83C\uDFCA\uD83C\uDFFE\u200D♀️", + [":woman_swimming::skin-tone-5:"] = "\uD83C\uDFCA\uD83C\uDFFF\u200D♀️", + [":woman_swimming_dark_skin_tone:"] = "\uD83C\uDFCA\uD83C\uDFFF\u200D♀️", + [":woman_swimming_light_skin_tone:"] = "\uD83C\uDFCA\uD83C\uDFFB\u200D♀️", + [":woman_swimming_medium_dark_skin_tone:"] = "\uD83C\uDFCA\uD83C\uDFFE\u200D♀️", + [":woman_swimming_medium_light_skin_tone:"] = "\uD83C\uDFCA\uD83C\uDFFC\u200D♀️", + [":woman_swimming_medium_skin_tone:"] = "\uD83C\uDFCA\uD83C\uDFFD\u200D♀️", + [":woman_swimming_tone1:"] = "\uD83C\uDFCA\uD83C\uDFFB\u200D♀️", + [":woman_swimming_tone2:"] = "\uD83C\uDFCA\uD83C\uDFFC\u200D♀️", + [":woman_swimming_tone3:"] = "\uD83C\uDFCA\uD83C\uDFFD\u200D♀️", + [":woman_swimming_tone4:"] = "\uD83C\uDFCA\uD83C\uDFFE\u200D♀️", + [":woman_swimming_tone5:"] = "\uD83C\uDFCA\uD83C\uDFFF\u200D♀️", + [":woman_teacher:"] = "\uD83D\uDC69\u200D\uD83C\uDFEB", + [":woman_teacher::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDFEB", + [":woman_teacher::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDFEB", + [":woman_teacher::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDFEB", + [":woman_teacher::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDFEB", + [":woman_teacher::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDFEB", + [":woman_teacher_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDFEB", + [":woman_teacher_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDFEB", + [":woman_teacher_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDFEB", + [":woman_teacher_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDFEB", + [":woman_teacher_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDFEB", + [":woman_teacher_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83C\uDFEB", + [":woman_teacher_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83C\uDFEB", + [":woman_teacher_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDFEB", + [":woman_teacher_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83C\uDFEB", + [":woman_teacher_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83C\uDFEB", + [":woman_technologist:"] = "\uD83D\uDC69\u200D\uD83D\uDCBB", + [":woman_technologist::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDCBB", + [":woman_technologist::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDCBB", + [":woman_technologist::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDCBB", + [":woman_technologist::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDCBB", + [":woman_technologist::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDCBB", + [":woman_technologist_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDCBB", + [":woman_technologist_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDCBB", + [":woman_technologist_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDCBB", + [":woman_technologist_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDCBB", + [":woman_technologist_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDCBB", + [":woman_technologist_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDCBB", + [":woman_technologist_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83D\uDCBB", + [":woman_technologist_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83D\uDCBB", + [":woman_technologist_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83D\uDCBB", + [":woman_technologist_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83D\uDCBB", + [":woman_tipping_hand:"] = "\uD83D\uDC81\u200D♀️", + [":woman_tipping_hand::skin-tone-1:"] = "\uD83D\uDC81\uD83C\uDFFB\u200D♀️", + [":woman_tipping_hand::skin-tone-2:"] = "\uD83D\uDC81\uD83C\uDFFC\u200D♀️", + [":woman_tipping_hand::skin-tone-3:"] = "\uD83D\uDC81\uD83C\uDFFD\u200D♀️", + [":woman_tipping_hand::skin-tone-4:"] = "\uD83D\uDC81\uD83C\uDFFE\u200D♀️", + [":woman_tipping_hand::skin-tone-5:"] = "\uD83D\uDC81\uD83C\uDFFF\u200D♀️", + [":woman_tipping_hand_dark_skin_tone:"] = "\uD83D\uDC81\uD83C\uDFFF\u200D♀️", + [":woman_tipping_hand_light_skin_tone:"] = "\uD83D\uDC81\uD83C\uDFFB\u200D♀️", + [":woman_tipping_hand_medium_dark_skin_tone:"] = "\uD83D\uDC81\uD83C\uDFFE\u200D♀️", + [":woman_tipping_hand_medium_light_skin_tone:"] = "\uD83D\uDC81\uD83C\uDFFC\u200D♀️", + [":woman_tipping_hand_medium_skin_tone:"] = "\uD83D\uDC81\uD83C\uDFFD\u200D♀️", + [":woman_tipping_hand_tone1:"] = "\uD83D\uDC81\uD83C\uDFFB\u200D♀️", + [":woman_tipping_hand_tone2:"] = "\uD83D\uDC81\uD83C\uDFFC\u200D♀️", + [":woman_tipping_hand_tone3:"] = "\uD83D\uDC81\uD83C\uDFFD\u200D♀️", + [":woman_tipping_hand_tone4:"] = "\uD83D\uDC81\uD83C\uDFFE\u200D♀️", + [":woman_tipping_hand_tone5:"] = "\uD83D\uDC81\uD83C\uDFFF\u200D♀️", + [":woman_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB", + [":woman_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC", + [":woman_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD", + [":woman_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE", + [":woman_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF", + [":woman_vampire:"] = "\uD83E\uDDDB\u200D♀️", + [":woman_vampire::skin-tone-1:"] = "\uD83E\uDDDB\uD83C\uDFFB\u200D♀️", + [":woman_vampire::skin-tone-2:"] = "\uD83E\uDDDB\uD83C\uDFFC\u200D♀️", + [":woman_vampire::skin-tone-3:"] = "\uD83E\uDDDB\uD83C\uDFFD\u200D♀️", + [":woman_vampire::skin-tone-4:"] = "\uD83E\uDDDB\uD83C\uDFFE\u200D♀️", + [":woman_vampire::skin-tone-5:"] = "\uD83E\uDDDB\uD83C\uDFFF\u200D♀️", + [":woman_vampire_dark_skin_tone:"] = "\uD83E\uDDDB\uD83C\uDFFF\u200D♀️", + [":woman_vampire_light_skin_tone:"] = "\uD83E\uDDDB\uD83C\uDFFB\u200D♀️", + [":woman_vampire_medium_dark_skin_tone:"] = "\uD83E\uDDDB\uD83C\uDFFE\u200D♀️", + [":woman_vampire_medium_light_skin_tone:"] = "\uD83E\uDDDB\uD83C\uDFFC\u200D♀️", + [":woman_vampire_medium_skin_tone:"] = "\uD83E\uDDDB\uD83C\uDFFD\u200D♀️", + [":woman_vampire_tone1:"] = "\uD83E\uDDDB\uD83C\uDFFB\u200D♀️", + [":woman_vampire_tone2:"] = "\uD83E\uDDDB\uD83C\uDFFC\u200D♀️", + [":woman_vampire_tone3:"] = "\uD83E\uDDDB\uD83C\uDFFD\u200D♀️", + [":woman_vampire_tone4:"] = "\uD83E\uDDDB\uD83C\uDFFE\u200D♀️", + [":woman_vampire_tone5:"] = "\uD83E\uDDDB\uD83C\uDFFF\u200D♀️", + [":woman_walking:"] = "\uD83D\uDEB6\u200D♀️", + [":woman_walking::skin-tone-1:"] = "\uD83D\uDEB6\uD83C\uDFFB\u200D♀️", + [":woman_walking::skin-tone-2:"] = "\uD83D\uDEB6\uD83C\uDFFC\u200D♀️", + [":woman_walking::skin-tone-3:"] = "\uD83D\uDEB6\uD83C\uDFFD\u200D♀️", + [":woman_walking::skin-tone-4:"] = "\uD83D\uDEB6\uD83C\uDFFE\u200D♀️", + [":woman_walking::skin-tone-5:"] = "\uD83D\uDEB6\uD83C\uDFFF\u200D♀️", + [":woman_walking_dark_skin_tone:"] = "\uD83D\uDEB6\uD83C\uDFFF\u200D♀️", + [":woman_walking_light_skin_tone:"] = "\uD83D\uDEB6\uD83C\uDFFB\u200D♀️", + [":woman_walking_medium_dark_skin_tone:"] = "\uD83D\uDEB6\uD83C\uDFFE\u200D♀️", + [":woman_walking_medium_light_skin_tone:"] = "\uD83D\uDEB6\uD83C\uDFFC\u200D♀️", + [":woman_walking_medium_skin_tone:"] = "\uD83D\uDEB6\uD83C\uDFFD\u200D♀️", + [":woman_walking_tone1:"] = "\uD83D\uDEB6\uD83C\uDFFB\u200D♀️", + [":woman_walking_tone2:"] = "\uD83D\uDEB6\uD83C\uDFFC\u200D♀️", + [":woman_walking_tone3:"] = "\uD83D\uDEB6\uD83C\uDFFD\u200D♀️", + [":woman_walking_tone4:"] = "\uD83D\uDEB6\uD83C\uDFFE\u200D♀️", + [":woman_walking_tone5:"] = "\uD83D\uDEB6\uD83C\uDFFF\u200D♀️", + [":woman_wearing_turban:"] = "\uD83D\uDC73\u200D♀️", + [":woman_wearing_turban::skin-tone-1:"] = "\uD83D\uDC73\uD83C\uDFFB\u200D♀️", + [":woman_wearing_turban::skin-tone-2:"] = "\uD83D\uDC73\uD83C\uDFFC\u200D♀️", + [":woman_wearing_turban::skin-tone-3:"] = "\uD83D\uDC73\uD83C\uDFFD\u200D♀️", + [":woman_wearing_turban::skin-tone-4:"] = "\uD83D\uDC73\uD83C\uDFFE\u200D♀️", + [":woman_wearing_turban::skin-tone-5:"] = "\uD83D\uDC73\uD83C\uDFFF\u200D♀️", + [":woman_wearing_turban_dark_skin_tone:"] = "\uD83D\uDC73\uD83C\uDFFF\u200D♀️", + [":woman_wearing_turban_light_skin_tone:"] = "\uD83D\uDC73\uD83C\uDFFB\u200D♀️", + [":woman_wearing_turban_medium_dark_skin_tone:"] = "\uD83D\uDC73\uD83C\uDFFE\u200D♀️", + [":woman_wearing_turban_medium_light_skin_tone:"] = "\uD83D\uDC73\uD83C\uDFFC\u200D♀️", + [":woman_wearing_turban_medium_skin_tone:"] = "\uD83D\uDC73\uD83C\uDFFD\u200D♀️", + [":woman_wearing_turban_tone1:"] = "\uD83D\uDC73\uD83C\uDFFB\u200D♀️", + [":woman_wearing_turban_tone2:"] = "\uD83D\uDC73\uD83C\uDFFC\u200D♀️", + [":woman_wearing_turban_tone3:"] = "\uD83D\uDC73\uD83C\uDFFD\u200D♀️", + [":woman_wearing_turban_tone4:"] = "\uD83D\uDC73\uD83C\uDFFE\u200D♀️", + [":woman_wearing_turban_tone5:"] = "\uD83D\uDC73\uD83C\uDFFF\u200D♀️", + [":woman_white_haired:"] = "\uD83D\uDC69\u200D\uD83E\uDDB3", + [":woman_white_haired::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDB3", + [":woman_white_haired::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDB3", + [":woman_white_haired::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDB3", + [":woman_white_haired::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDB3", + [":woman_white_haired::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDB3", + [":woman_white_haired_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDB3", + [":woman_white_haired_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDB3", + [":woman_white_haired_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDB3", + [":woman_white_haired_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDB3", + [":woman_white_haired_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDB3", + [":woman_white_haired_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDB3", + [":woman_white_haired_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDB3", + [":woman_white_haired_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDB3", + [":woman_white_haired_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDB3", + [":woman_white_haired_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDB3", + [":woman_with_headscarf:"] = "\uD83E\uDDD5", + [":woman_with_headscarf::skin-tone-1:"] = "\uD83E\uDDD5\uD83C\uDFFB", + [":woman_with_headscarf::skin-tone-2:"] = "\uD83E\uDDD5\uD83C\uDFFC", + [":woman_with_headscarf::skin-tone-3:"] = "\uD83E\uDDD5\uD83C\uDFFD", + [":woman_with_headscarf::skin-tone-4:"] = "\uD83E\uDDD5\uD83C\uDFFE", + [":woman_with_headscarf::skin-tone-5:"] = "\uD83E\uDDD5\uD83C\uDFFF", + [":woman_with_headscarf_dark_skin_tone:"] = "\uD83E\uDDD5\uD83C\uDFFF", + [":woman_with_headscarf_light_skin_tone:"] = "\uD83E\uDDD5\uD83C\uDFFB", + [":woman_with_headscarf_medium_dark_skin_tone:"] = "\uD83E\uDDD5\uD83C\uDFFE", + [":woman_with_headscarf_medium_light_skin_tone:"] = "\uD83E\uDDD5\uD83C\uDFFC", + [":woman_with_headscarf_medium_skin_tone:"] = "\uD83E\uDDD5\uD83C\uDFFD", + [":woman_with_headscarf_tone1:"] = "\uD83E\uDDD5\uD83C\uDFFB", + [":woman_with_headscarf_tone2:"] = "\uD83E\uDDD5\uD83C\uDFFC", + [":woman_with_headscarf_tone3:"] = "\uD83E\uDDD5\uD83C\uDFFD", + [":woman_with_headscarf_tone4:"] = "\uD83E\uDDD5\uD83C\uDFFE", + [":woman_with_headscarf_tone5:"] = "\uD83E\uDDD5\uD83C\uDFFF", + [":woman_with_probing_cane:"] = "\uD83D\uDC69\u200D\uD83E\uDDAF", + [":woman_with_probing_cane::skin-tone-1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDAF", + [":woman_with_probing_cane::skin-tone-2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDAF", + [":woman_with_probing_cane::skin-tone-3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDAF", + [":woman_with_probing_cane::skin-tone-4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDAF", + [":woman_with_probing_cane::skin-tone-5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDAF", + [":woman_with_probing_cane_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDAF", + [":woman_with_probing_cane_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDAF", + [":woman_with_probing_cane_medium_dark_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDAF", + [":woman_with_probing_cane_medium_light_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDAF", + [":woman_with_probing_cane_medium_skin_tone:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDAF", + [":woman_with_probing_cane_tone1:"] = "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDDAF", + [":woman_with_probing_cane_tone2:"] = "\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDDAF", + [":woman_with_probing_cane_tone3:"] = "\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDDAF", + [":woman_with_probing_cane_tone4:"] = "\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDDAF", + [":woman_with_probing_cane_tone5:"] = "\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDDAF", + [":woman_zombie:"] = "\uD83E\uDDDF\u200D♀️", + [":womans_clothes:"] = "\uD83D\uDC5A", + [":womans_flat_shoe:"] = "\uD83E\uDD7F", + [":womans_hat:"] = "\uD83D\uDC52", + [":women_with_bunny_ears_partying:"] = "\uD83D\uDC6F\u200D♀️", + [":women_wrestling:"] = "\uD83E\uDD3C\u200D♀️", + [":womens:"] = "\uD83D\uDEBA", + [":woozy_face:"] = "\uD83E\uDD74", + [":world_map:"] = "\uD83D\uDDFA️", + [":worried:"] = "\uD83D\uDE1F", + [":worship_symbol:"] = "\uD83D\uDED0", + [":wrench:"] = "\uD83D\uDD27", + [":wrestlers:"] = "\uD83E\uDD3C", + [":wrestling:"] = "\uD83E\uDD3C", + [":writing_hand:"] = "✍️", + [":writing_hand::skin-tone-1:"] = "✍\uD83C\uDFFB", + [":writing_hand::skin-tone-2:"] = "✍\uD83C\uDFFC", + [":writing_hand::skin-tone-3:"] = "✍\uD83C\uDFFD", + [":writing_hand::skin-tone-4:"] = "✍\uD83C\uDFFE", + [":writing_hand::skin-tone-5:"] = "✍\uD83C\uDFFF", + [":writing_hand_tone1:"] = "✍\uD83C\uDFFB", + [":writing_hand_tone2:"] = "✍\uD83C\uDFFC", + [":writing_hand_tone3:"] = "✍\uD83C\uDFFD", + [":writing_hand_tone4:"] = "✍\uD83C\uDFFE", + [":writing_hand_tone5:"] = "✍\uD83C\uDFFF", + [":x:"] = "❌", + [":yarn:"] = "\uD83E\uDDF6", + [":yawning_face:"] = "\uD83E\uDD71", + [":yellow_circle:"] = "\uD83D\uDFE1", + [":yellow_heart:"] = "\uD83D\uDC9B", + [":yellow_square:"] = "\uD83D\uDFE8", + [":yen:"] = "\uD83D\uDCB4", + [":yin_yang:"] = "☯️", + [":yo_yo:"] = "\uD83E\uDE80", + [":yum:"] = "\uD83D\uDE0B", + [":z"] = "\uD83D\uDE12", + [":zany_face:"] = "\uD83E\uDD2A", + [":zap:"] = "⚡", + [":zebra:"] = "\uD83E\uDD93", + [":zero:"] = "0️⃣", + [":zipper_mouth:"] = "\uD83E\uDD10", + [":zipper_mouth_face:"] = "\uD83E\uDD10", + [":zombie:"] = "\uD83E\uDDDF", + [":zzz:"] = "\uD83D\uDCA4", + [":|"] = "\uD83D\uDE10", + [";("] = "\uD83D\uDE2D", + [";)"] = "\uD83D\uDE09", + [";-("] = "\uD83D\uDE2D", + [";-)"] = "\uD83D\uDE09", + [":("] = "\uD83D\uDE20", + [">:-("] = "\uD83D\uDE20", + [">=("] = "\uD83D\uDE20", + [">=-("] = "\uD83D\uDE20", + ["B-)"] = "\uD83D\uDE0E", + ["O:)"] = "\uD83D\uDE07", + ["O:-)"] = "\uD83D\uDE07", + ["O=)"] = "\uD83D\uDE07", + ["O=-)"] = "\uD83D\uDE07", + ["X-)"] = "\uD83D\uDE06", + ["]:("] = "\uD83D\uDC7F", + ["]:)"] = "\uD83D\uDE08", + ["]:-("] = "\uD83D\uDC7F", + ["]:-)"] = "\uD83D\uDE08", + ["]=("] = "\uD83D\uDC7F", + ["]=)"] = "\uD83D\uDE08", + ["]=-("] = "\uD83D\uDC7F", + ["]=-)"] = "\uD83D\uDE08", + ["o:)"] = "\uD83D\uDE07", + ["o:-)"] = "\uD83D\uDE07", + ["o=)"] = "\uD83D\uDE07", + ["o=-)"] = "\uD83D\uDE07", + ["x-)"] = "\uD83D\uDE06", + ["♡"] = "❤️" + }; + + private static IReadOnlyCollection _unicodes; + private static IReadOnlyCollection Unicodes + { + get + { + _unicodes ??= NamesAndUnicodes.Select(kvp => kvp.Value).ToImmutableHashSet(); + return _unicodes; + } + } + + private static IReadOnlyDictionary> _unicodesAndNames; + private static IReadOnlyDictionary> UnicodesAndNames + { + get + { + _unicodesAndNames ??= + NamesAndUnicodes + .GroupBy(kvp => kvp.Value) + .ToImmutableDictionary( + grouping => grouping.Key, + grouping => grouping.Select(kvp => kvp.Key) + .ToList() + .AsReadOnly() + ); + return _unicodesAndNames; + } + } + + public static implicit operator Emoji(string s) => Parse(s); } } diff --git a/src/Discord.Net.Core/Entities/Emotes/Emote.cs b/src/Discord.Net.Core/Entities/Emotes/Emote.cs index 6054b3f74..3a8cd7457 100644 --- a/src/Discord.Net.Core/Entities/Emotes/Emote.cs +++ b/src/Discord.Net.Core/Entities/Emotes/Emote.cs @@ -74,6 +74,10 @@ namespace Discord public static bool TryParse(string text, out Emote result) { result = null; + + if (text == null) + return false; + if (text.Length >= 4 && text[0] == '<' && (text[1] == ':' || (text[1] == 'a' && text[2] == ':')) && text[text.Length - 1] == '>') { bool animated = text[1] == 'a'; @@ -102,5 +106,7 @@ namespace Discord /// A string representing the raw presentation of the emote (e.g. <:thonkang:282745590985523200>). /// public override string ToString() => $"<{(Animated ? "a" : "")}:{Name}:{Id}>"; + + public static implicit operator Emote(string s) => Parse(s); } } diff --git a/src/Discord.Net.Core/Entities/Gateway/BotGateway.cs b/src/Discord.Net.Core/Entities/Gateway/BotGateway.cs new file mode 100644 index 000000000..c9be0ac1f --- /dev/null +++ b/src/Discord.Net.Core/Entities/Gateway/BotGateway.cs @@ -0,0 +1,22 @@ +namespace Discord +{ + /// + /// Stores the gateway information related to the current bot. + /// + public class BotGateway + { + /// + /// Gets the WSS URL that can be used for connecting to the gateway. + /// + public string Url { get; internal set; } + /// + /// Gets the recommended number of shards to use when connecting. + /// + public int Shards { get; internal set; } + /// + /// Gets the that contains the information + /// about the current session start limit. + /// + public SessionStartLimit SessionStartLimit { get; internal set; } + } +} diff --git a/src/Discord.Net.Core/Entities/Gateway/SessionStartLimit.cs b/src/Discord.Net.Core/Entities/Gateway/SessionStartLimit.cs new file mode 100644 index 000000000..74ae96af1 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Gateway/SessionStartLimit.cs @@ -0,0 +1,38 @@ +namespace Discord +{ + /// + /// Stores the information related to the gateway identify request. + /// + public class SessionStartLimit + { + /// + /// Gets the total number of session starts the current user is allowed. + /// + /// + /// The maximum amount of session starts the current user is allowed. + /// + public int Total { get; internal set; } + /// + /// Gets the remaining number of session starts the current user is allowed. + /// + /// + /// The remaining amount of session starts the current user is allowed. + /// + public int Remaining { get; internal set; } + /// + /// Gets the number of milliseconds after which the limit resets. + /// + /// + /// The milliseconds until the limit resets back to the . + /// + public int ResetAfter { get; internal set; } + /// + /// Gets the maximum concurrent identify requests in a time window. + /// + /// + /// The maximum concurrent identify requests in a time window, + /// limited to the same rate limit key. + /// + public int MaxConcurrency { get; internal set; } + } +} diff --git a/src/Discord.Net.Core/Entities/Guilds/GuildFeature.cs b/src/Discord.Net.Core/Entities/Guilds/GuildFeature.cs new file mode 100644 index 000000000..e3c325227 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Guilds/GuildFeature.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + [Flags] + public enum GuildFeature + { + /// + /// The guild has no features. + /// + None = 0, + /// + /// The guild has access to set an animated guild icon. + /// + AnimatedIcon = 1 << 0, + /// + /// The guild has access to set a guild banner image. + /// + Banner = 1 << 1, + /// + /// The guild has access to use commerce features (i.e. create store channels). + /// + Commerce = 1 << 2, + /// + /// The guild can enable welcome screen, Membership Screening, stage channels and discovery, and receives community updates. + /// + Community = 1 << 3, + /// + /// The guild is able to be discovered in the directory. + /// + Discoverable = 1 << 4, + /// + /// The guild is able to be featured in the directory. + /// + Featureable = 1 << 5, + /// + /// The guild has access to set an invite splash background. + /// + InviteSplash = 1 << 6, + /// + /// The guild has enabled Membership Screening. + /// + MemberVerificationGateEnabled = 1 << 7, + /// + /// The guild has enabled monetization. + /// + MonetizationEnabled = 1 << 8, + /// + /// The guild has increased custom sticker slots. + /// + MoreStickers = 1 << 9, + /// + /// The guild has access to create news channels. + /// + News = 1 << 10, + /// + /// The guild is partnered. + /// + Partnered = 1 << 11, + /// + /// The guild can be previewed before joining via Membership Screening or the directory. + /// + PreviewEnabled = 1 << 12, + /// + /// The guild has access to create private threads. + /// + PrivateThreads = 1 << 13, + /// + /// The guild is able to set role icons. + /// + RoleIcons = 1 << 14, + /// + /// The guild has access to the seven day archive time for threads. + /// + SevenDayThreadArchive = 1 << 15, + /// + /// The guild has access to the three day archive time for threads. + /// + ThreeDayThreadArchive = 1 << 16, + /// + /// The guild has enabled ticketed events. + /// + TicketedEventsEnabled = 1 << 17, + /// + /// The guild has access to set a vanity URL. + /// + VanityUrl = 1 << 18, + /// + /// The guild is verified. + /// + Verified = 1 << 19, + /// + /// The guild has access to set 384kbps bitrate in voice (previously VIP voice servers). + /// + VIPRegions = 1 << 20, + /// + /// The guild has enabled the welcome screen. + /// + WelcomeScreenEnabled = 1 << 21, + } +} diff --git a/src/Discord.Net.Core/Entities/Guilds/GuildFeatures.cs b/src/Discord.Net.Core/Entities/Guilds/GuildFeatures.cs new file mode 100644 index 000000000..699e47cf3 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Guilds/GuildFeatures.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + public class GuildFeatures + { + /// + /// Gets the flags of recognized features for this guild. + /// + public GuildFeature Value { get; } + + /// + /// Gets a collection of experimental features for this guild. + /// + public IReadOnlyCollection Experimental { get; } + + + internal GuildFeatures(GuildFeature value, string[] experimental) + { + Value = value; + Experimental = experimental.ToImmutableArray(); + } + + public bool HasFeature(GuildFeature feature) + => Value.HasFlag(feature); + public bool HasFeature(string feature) + => Experimental.Contains(feature); + + internal void EnsureFeature(GuildFeature feature) + { + if (!HasFeature(feature)) + { + var vals = Enum.GetValues(typeof(GuildFeature)).Cast(); + + var missingValues = vals.Where(x => feature.HasFlag(x) && !Value.HasFlag(x)); + + throw new InvalidOperationException($"Missing required guild feature{(missingValues.Count() > 1 ? "s" : "")} {string.Join(", ", missingValues.Select(x => x.ToString()))} in order to execute this operation."); + } + } + } +} diff --git a/src/Discord.Net.Core/Entities/Guilds/GuildProperties.cs b/src/Discord.Net.Core/Entities/Guilds/GuildProperties.cs index 981e1198c..d50b2ac38 100644 --- a/src/Discord.Net.Core/Entities/Guilds/GuildProperties.cs +++ b/src/Discord.Net.Core/Entities/Guilds/GuildProperties.cs @@ -85,8 +85,9 @@ namespace Discord /// given that the has also been set. /// A value of will deny guild boost messages from being sent, and allow all /// other types of messages. - /// Refer to the extension methods and - /// to check if these system channel message types + /// Refer to the extension methods , + /// , , + /// and to check if these system channel message types /// are enabled, without the need to manipulate the logic of the flag. /// public Optional SystemChannelFlags { get; set; } @@ -108,5 +109,9 @@ namespace Discord /// the value of will be unused. /// public Optional PreferredCulture { get; set; } + /// + /// Gets or sets if the boost progress bar is enabled. + /// + public Optional IsBoostProgressBarEnabled { get; set; } } } diff --git a/src/Discord.Net.Core/Entities/Guilds/GuildScheduledEventPrivacyLevel.cs b/src/Discord.Net.Core/Entities/Guilds/GuildScheduledEventPrivacyLevel.cs new file mode 100644 index 000000000..87881104c --- /dev/null +++ b/src/Discord.Net.Core/Entities/Guilds/GuildScheduledEventPrivacyLevel.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents the privacy level of a guild scheduled event. + /// + public enum GuildScheduledEventPrivacyLevel + { + /// + /// The scheduled event is public and available in discovery. + /// + [Obsolete("This event type isn't supported yet! check back later.", true)] + Public = 1, + + /// + /// The scheduled event is only accessible to guild members. + /// + Private = 2, + } +} diff --git a/src/Discord.Net.Core/Entities/Guilds/GuildScheduledEventStatus.cs b/src/Discord.Net.Core/Entities/Guilds/GuildScheduledEventStatus.cs new file mode 100644 index 000000000..6e3aa1ab3 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Guilds/GuildScheduledEventStatus.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents the status of a guild event. + /// + public enum GuildScheduledEventStatus + { + /// + /// The event is scheduled for a set time. + /// + Scheduled = 1, + + /// + /// The event has started. + /// + Active = 2, + + /// + /// The event was completed. + /// + Completed = 3, + + /// + /// The event was canceled. + /// + Cancelled = 4, + } +} diff --git a/src/Discord.Net.Core/Entities/Guilds/GuildScheduledEventType.cs b/src/Discord.Net.Core/Entities/Guilds/GuildScheduledEventType.cs new file mode 100644 index 000000000..ad741eee1 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Guilds/GuildScheduledEventType.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents the type of a guild scheduled event. + /// + public enum GuildScheduledEventType + { + /// + /// The event doesn't have a set type. + /// + None = 0, + + /// + /// The event is set in a stage channel. + /// + Stage = 1, + + /// + /// The event is set in a voice channel. + /// + Voice = 2, + + /// + /// The event is set for somewhere externally from discord. + /// + External = 3, + } +} diff --git a/src/Discord.Net.Core/Entities/Guilds/GuildScheduledEventsProperties.cs b/src/Discord.Net.Core/Entities/Guilds/GuildScheduledEventsProperties.cs new file mode 100644 index 000000000..a3fd729e5 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Guilds/GuildScheduledEventsProperties.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Provides properties that are used to modify an with the specified changes. + /// + public class GuildScheduledEventsProperties + { + /// + /// Gets or sets the channel id of the event. + /// + public Optional ChannelId { get; set; } + + /// + /// Gets or sets the location of this event. + /// + public Optional Location { get; set; } + + /// + /// Gets or sets the name of the event. + /// + public Optional Name { get; set; } + + /// + /// Gets or sets the privacy level of the event. + /// + public Optional PrivacyLevel { get; set; } + + /// + /// Gets or sets the start time of the event. + /// + public Optional StartTime { get; set; } + /// + /// Gets or sets the end time of the event. + /// + public Optional EndTime { get; set; } + + /// + /// Gets or sets the description of the event. + /// + public Optional Description { get; set; } + + /// + /// Gets or sets the type of the event. + /// + public Optional Type { get; set; } + + /// + /// Gets or sets the status of the event. + /// + public Optional Status { get; set; } + } +} diff --git a/src/Discord.Net.Core/Entities/Guilds/GuildEmbedProperties.cs b/src/Discord.Net.Core/Entities/Guilds/GuildWidgetProperties.cs similarity index 76% rename from src/Discord.Net.Core/Entities/Guilds/GuildEmbedProperties.cs rename to src/Discord.Net.Core/Entities/Guilds/GuildWidgetProperties.cs index 34473e93c..842bb7f3e 100644 --- a/src/Discord.Net.Core/Entities/Guilds/GuildEmbedProperties.cs +++ b/src/Discord.Net.Core/Entities/Guilds/GuildWidgetProperties.cs @@ -3,18 +3,18 @@ namespace Discord /// /// Provides properties that are used to modify the widget of an with the specified changes. /// - public class GuildEmbedProperties + public class GuildWidgetProperties { /// /// Sets whether the widget should be enabled. /// public Optional Enabled { get; set; } /// - /// Sets the channel that the invite should place its users in, if not null. + /// Sets the channel that the invite should place its users in, if not . /// public Optional Channel { get; set; } /// - /// Sets the channel the invite should place its users in, if not null. + /// Sets the channel that the invite should place its users in, if not . /// public Optional ChannelId { get; set; } } diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs index cdf0118c4..ae1b2d67d 100644 --- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs @@ -2,6 +2,7 @@ using Discord.Audio; using System; using System.Collections.Generic; using System.Globalization; +using System.IO; using System.Threading.Tasks; namespace Discord @@ -23,17 +24,17 @@ namespace Discord /// automatically moved to the AFK voice channel. /// /// - /// An representing the amount of time in seconds for a user to be marked as inactive + /// An representing the amount of time in seconds for a user to be marked as inactive /// and moved into the AFK voice channel. /// int AFKTimeout { get; } /// - /// Gets a value that indicates whether this guild is embeddable (i.e. can use widget). + /// Gets a value that indicates whether this guild has the widget enabled. /// /// - /// true if this guild can be embedded via widgets; otherwise false. + /// if this guild has a widget enabled; otherwise . /// - bool IsEmbeddable { get; } + bool IsWidgetEnabled { get; } /// /// Gets the default message notifications for users who haven't explicitly set their notification settings. /// @@ -64,31 +65,45 @@ namespace Discord /// Gets the ID of this guild's icon. /// /// - /// An identifier for the splash image; null if none is set. + /// An identifier for the splash image; if none is set. /// string IconId { get; } /// /// Gets the URL of this guild's icon. /// /// - /// A URL pointing to the guild's icon; null if none is set. + /// A URL pointing to the guild's icon; if none is set. /// string IconUrl { get; } /// /// Gets the ID of this guild's splash image. /// /// - /// An identifier for the splash image; null if none is set. + /// An identifier for the splash image; if none is set. /// string SplashId { get; } /// /// Gets the URL of this guild's splash image. /// /// - /// A URL pointing to the guild's splash image; null if none is set. + /// A URL pointing to the guild's splash image; if none is set. /// string SplashUrl { get; } /// + /// Gets the ID of this guild's discovery splash image. + /// + /// + /// An identifier for the discovery splash image; if none is set. + /// + string DiscoverySplashId { get; } + /// + /// Gets the URL of this guild's discovery splash image. + /// + /// + /// A URL pointing to the guild's discovery splash image; if none is set. + /// + string DiscoverySplashUrl { get; } + /// /// Determines if this guild is currently connected and ready to be used. /// /// @@ -98,7 +113,7 @@ namespace Discord /// This boolean is used to determine if the guild is currently connected to the WebSocket and is ready to be used/accessed. /// /// - /// true if this guild is currently connected and ready to be used; otherwise false. + /// true if this guild is currently connected and ready to be used; otherwise . /// bool Available { get; } @@ -106,53 +121,54 @@ namespace Discord /// Gets the ID of the AFK voice channel for this guild. /// /// - /// A representing the snowflake identifier of the AFK voice channel; null if + /// A representing the snowflake identifier of the AFK voice channel; if /// none is set. /// ulong? AFKChannelId { get; } /// - /// Gets the ID of the default channel for this guild. + /// Gets the ID of the channel assigned to the widget of this guild. /// - /// - /// This property retrieves the snowflake identifier of the first viewable text channel for this guild. - /// - /// This channel does not guarantee the user can send message to it, as it only looks for the first viewable - /// text channel. - /// - /// /// - /// A representing the snowflake identifier of the default text channel; 0 if - /// none can be found. + /// A representing the snowflake identifier of the channel assigned to the widget found + /// within the widget settings of this guild; if none is set. /// - ulong DefaultChannelId { get; } + ulong? WidgetChannelId { get; } /// - /// Gets the ID of the widget embed channel of this guild. + /// Gets the ID of the channel where randomized welcome messages are sent. /// /// - /// A representing the snowflake identifier of the embedded channel found within the - /// widget settings of this guild; null if none is set. + /// A representing the snowflake identifier of the system channel where randomized + /// welcome messages are sent; if none is set. /// - ulong? EmbedChannelId { get; } + ulong? SystemChannelId { get; } /// - /// Gets the ID of the channel where randomized welcome messages are sent. + /// Gets the ID of the channel with the rules. /// /// - /// A representing the snowflake identifier of the system channel where randomized - /// welcome messages are sent; null if none is set. + /// A representing the snowflake identifier of the channel that contains the rules; + /// if none is set. /// - ulong? SystemChannelId { get; } + ulong? RulesChannelId { get; } + /// + /// Gets the ID of the channel where admins and moderators of Community guilds receive notices from Discord. + /// + /// + /// A representing the snowflake identifier of the channel where admins and moderators + /// of Community guilds receive notices from Discord; if none is set. + /// + ulong? PublicUpdatesChannelId { get; } /// /// Gets the ID of the user that owns this guild. /// /// - /// A representing the snowflake identifier of the user that owns this guild. + /// A representing the snowflake identifier of the user that owns this guild. /// ulong OwnerId { get; } /// /// Gets the application ID of the guild creator if it is bot-created. /// /// - /// A representing the snowflake identifier of the application ID that created this guild, or null if it was not bot-created. + /// A representing the snowflake identifier of the application ID that created this guild, or if it was not bot-created. /// ulong? ApplicationId { get; } /// @@ -184,12 +200,19 @@ namespace Discord /// IReadOnlyCollection Emotes { get; } /// - /// Gets a collection of all extra features added to this guild. + /// Gets a collection of all custom stickers for this guild. /// /// - /// A read-only collection of enabled features in this guild. + /// A read-only collection of all custom stickers for this guild. /// - IReadOnlyCollection Features { get; } + IReadOnlyCollection Stickers { get; } + /// + /// Gets the features for this guild. + /// + /// + /// A flags enum containing all the features for the guild. + /// + GuildFeatures Features { get; } /// /// Gets a collection of all roles in this guild. /// @@ -208,21 +231,21 @@ namespace Discord /// Gets the identifier for this guilds banner image. /// /// - /// An identifier for the banner image; null if none is set. + /// An identifier for the banner image; if none is set. /// string BannerId { get; } /// /// Gets the URL of this guild's banner image. /// /// - /// A URL pointing to the guild's banner image; null if none is set. + /// A URL pointing to the guild's banner image; if none is set. /// string BannerUrl { get; } /// /// Gets the code for this guild's vanity invite URL. /// /// - /// A string containing the vanity invite code for this guild; null if none is set. + /// A string containing the vanity invite code for this guild; if none is set. /// string VanityURLCode { get; } /// @@ -236,7 +259,7 @@ namespace Discord /// Gets the description for the guild. /// /// - /// The description for the guild; null if none is set. + /// The description for the guild; if none is set. /// string Description { get; } /// @@ -246,9 +269,57 @@ namespace Discord /// This is the number of users who have boosted this guild. /// /// - /// The number of premium subscribers of this guild. + /// The number of premium subscribers of this guild; if not available. /// int PremiumSubscriptionCount { get; } + /// + /// Gets the maximum number of presences for the guild. + /// + /// + /// The maximum number of presences for the guild. + /// + int? MaxPresences { get; } + /// + /// Gets the maximum number of members for the guild. + /// + /// + /// The maximum number of members for the guild. + /// + int? MaxMembers { get; } + /// + /// Gets the maximum amount of users in a video channel. + /// + /// + /// The maximum amount of users in a video channel. + /// + int? MaxVideoChannelUsers { get; } + /// + /// Gets the approximate number of members in this guild. + /// + /// + /// Only available when getting a guild via REST when `with_counts` is true. + /// + /// + /// The approximate number of members in this guild. + /// + int? ApproximateMemberCount { get; } + /// + /// Gets the approximate number of non-offline members in this guild. + /// + /// + /// Only available when getting a guild via REST when `with_counts` is true. + /// + /// + /// The approximate number of non-offline members in this guild. + /// + int? ApproximatePresenceCount { get; } + /// + /// Gets the max bitrate for voice channels in this guild. + /// + /// + /// A representing the maximum bitrate value allowed by Discord in this guild. + /// + int MaxBitrate { get; } /// /// Gets the preferred locale of this guild in IETF BCP 47 @@ -260,6 +331,14 @@ namespace Discord /// string PreferredLocale { get; } + /// + /// Gets the NSFW level of this guild. + /// + /// + /// The NSFW level of this guild. + /// + NsfwLevel NsfwLevel { get; } + /// /// Gets the preferred culture of this guild. /// @@ -267,6 +346,18 @@ namespace Discord /// The preferred culture information of this guild. /// CultureInfo PreferredCulture { get; } + /// + /// Gets whether the guild has the boost progress bar enabled. + /// + /// + /// if the boost progress bar is enabled; otherwise . + /// + bool IsBoostProgressBarEnabled { get; } + + /// + /// Gets the upload limit in bytes for this guild. This number is dependent on the guild's boost status. + /// + ulong MaxUploadLimit { get; } /// /// Modifies this guild. @@ -278,14 +369,14 @@ namespace Discord /// Task ModifyAsync(Action func, RequestOptions options = null); /// - /// Modifies this guild's embed channel. + /// Modifies this guild's widget. /// /// The delegate containing the properties to modify the guild widget with. /// The options to be used when sending the request. /// /// A task that represents the asynchronous modification operation. /// - Task ModifyEmbedAsync(Action func, RequestOptions options = null); + Task ModifyWidgetAsync(Action func, RequestOptions options = null); /// /// Bulk-modifies the order of channels in this guild. /// @@ -336,7 +427,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains a ban object, which - /// contains the user information and the reason for the ban; null if the ban entry cannot be found. + /// contains the user information and the reason for the ban; if the ban entry cannot be found. /// Task GetBanAsync(IUser user, RequestOptions options = null); /// @@ -346,7 +437,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains a ban object, which - /// contains the user information and the reason for the ban; null if the ban entry cannot be found. + /// contains the user information and the reason for the ban; if the ban entry cannot be found. /// Task GetBanAsync(ulong userId, RequestOptions options = null); /// @@ -410,7 +501,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the generic channel - /// associated with the specified ; null if none is found. + /// associated with the specified ; if none is found. /// Task GetChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// @@ -431,7 +522,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the text channel - /// associated with the specified ; null if none is found. + /// associated with the specified ; if none is found. /// Task GetTextChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// @@ -462,17 +553,38 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the voice channel associated - /// with the specified ; null if none is found. + /// with the specified ; if none is found. /// Task GetVoiceChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// + /// Gets a stage channel in this guild. + /// + /// The snowflake identifier for the stage channel. + /// The that determines whether the object should be fetched from cache. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the stage channel associated + /// with the specified ; if none is found. + /// + Task GetStageChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + /// + /// Gets a collection of all stage channels in this guild. + /// + /// The that determines whether the object should be fetched from cache. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a read-only collection of + /// stage channels found within this guild. + /// + Task> GetStageChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + /// /// Gets the AFK voice channel in this guild. /// /// The that determines whether the object should be fetched from cache. /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the voice channel that the - /// AFK users will be moved to after they have idled for too long; null if none is set. + /// AFK users will be moved to after they have idled for too long; if none is set. /// Task GetAFKChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// @@ -482,7 +594,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the text channel where - /// randomized welcome messages will be sent to; null if none is set. + /// randomized welcome messages will be sent to; if none is set. /// Task GetSystemChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// @@ -492,19 +604,59 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the first viewable text - /// channel in this guild; null if none is found. + /// channel in this guild; if none is found. /// Task GetDefaultChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// - /// Gets the embed channel (i.e. the channel set in the guild's widget settings) in this guild. + /// Gets the widget channel (i.e. the channel set in the guild's widget settings) in this guild. /// /// The that determines whether the object should be fetched from cache. /// The options to be used when sending the request. /// - /// A task that represents the asynchronous get operation. The task result contains the embed channel set - /// within the server's widget settings; null if none is set. + /// A task that represents the asynchronous get operation. The task result contains the widget channel set + /// within the server's widget settings; if none is set. /// - Task GetEmbedChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + Task GetWidgetChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + /// + /// Gets the text channel where Community guilds can display rules and/or guidelines. + /// + /// The that determines whether the object should be fetched from cache. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the text channel + /// where Community guilds can display rules and/or guidelines; if none is set. + /// + Task GetRulesChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + /// + /// Gets the text channel where admins and moderators of Community guilds receive notices from Discord. + /// + /// The that determines whether the object should be fetched from cache. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the text channel where + /// admins and moderators of Community guilds receive notices from Discord; if none is set. + /// + Task GetPublicUpdatesChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + /// + /// Gets a thread channel within this guild. + /// + /// The id of the thread channel. + /// The that determines whether the object should be fetched from cache. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the thread channel. + /// + Task GetThreadChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + /// + /// Gets a collection of all thread channels in this guild. + /// + /// The that determines whether the object should be fetched from cache. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a read-only collection of + /// thread channels found within this guild. + /// + Task> GetThreadChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// /// Creates a new text channel in this guild. @@ -534,6 +686,17 @@ namespace Discord /// Task CreateVoiceChannelAsync(string name, Action func = null, RequestOptions options = null); /// + /// Creates a new stage channel in this guild. + /// + /// The new name for the stage channel. + /// The delegate containing the properties to be applied to the channel upon its creation. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the newly created + /// stage channel. + /// + Task CreateStageChannelAsync(string name, Action func = null, RequestOptions options = null); + /// /// Creates a new channel category in this guild. /// /// The new name for the category. @@ -573,7 +736,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the partial metadata of - /// the vanity invite found within this guild; null if none is found. + /// the vanity invite found within this guild; if none is found. /// Task GetVanityInviteAsync(RequestOptions options = null); @@ -582,7 +745,7 @@ namespace Discord /// /// The snowflake identifier for the role. /// - /// A role that is associated with the specified ; null if none is found. + /// A role that is associated with the specified ; if none is found. /// IRole GetRole(ulong id); /// @@ -624,9 +787,15 @@ namespace Discord /// The OAuth2 access token for the user, requested with the guilds.join scope. /// The delegate containing the properties to be applied to the user upon being added to the guild. /// The options to be used when sending the request. - /// A guild user associated with the specified ; null if the user is already in the guild. + /// A guild user associated with the specified ; if the user is already in the guild. Task AddGuildUserAsync(ulong userId, string accessToken, Action func = null, RequestOptions options = null); /// + /// Disconnects the user from its current voice channel. + /// + /// The user to disconnect. + /// A task that represents the asynchronous operation for disconnecting a user. + Task DisconnectAsync(IGuildUser user); + /// /// Gets a collection of all users in this guild. /// /// @@ -649,7 +818,7 @@ namespace Discord /// /// This method retrieves a user found within this guild. /// - /// This may return null in the WebSocket implementation due to incomplete user collection in + /// This may return in the WebSocket implementation due to incomplete user collection in /// large guilds. /// /// @@ -658,7 +827,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the guild user - /// associated with the specified ; null if none is found. + /// associated with the specified ; if none is found. /// Task GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// @@ -684,7 +853,7 @@ namespace Discord /// Downloads all users for this guild if the current list is incomplete. /// /// - /// This method downloads all users found within this guild throught the Gateway and caches them. + /// This method downloads all users found within this guild through the Gateway and caches them. /// /// /// A task that represents the asynchronous download operation. @@ -705,11 +874,28 @@ namespace Discord /// The number of days required for the users to be kicked. /// Whether this prune action is a simulation. /// The options to be used when sending the request. + /// An array of role IDs to be included in the prune of users who do not have any additional roles. /// /// A task that represents the asynchronous prune operation. The task result contains the number of users to /// be or has been removed from this guild. /// - Task PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null); + Task PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null, IEnumerable includeRoleIds = null); + /// + /// Gets a collection of users in this guild that the name or nickname starts with the + /// provided at . + /// + /// + /// The can not be higher than . + /// + /// The partial name or nickname to search. + /// The maximum number of users to be gotten. + /// The that determines whether the object should be fetched from cache. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a collection of guild + /// users that the name or nickname starts with the provided at . + /// + Task> SearchUsersAsync(string query, int limit = DiscordConfig.MaxUsersPerBatch, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// /// Gets the specified number of audit log entries for this guild. @@ -735,7 +921,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the webhook with the - /// specified ; null if none is found. + /// specified ; if none is found. /// Task GetWebhookAsync(ulong id, RequestOptions options = null); /// @@ -748,6 +934,15 @@ namespace Discord /// Task> GetWebhooksAsync(RequestOptions options = null); + /// + /// Gets a collection of emotes from this guild. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a read-only collection + /// of emotes found within the guild. + /// + Task> GetEmotesAsync(RequestOptions options = null); /// /// Gets a specific emote from this guild. /// @@ -755,7 +950,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the emote found with the - /// specified ; null if none is found. + /// specified ; if none is found. /// Task GetEmoteAsync(ulong id, RequestOptions options = null); /// @@ -781,6 +976,15 @@ namespace Discord /// emote. /// Task ModifyEmoteAsync(GuildEmote emote, Action func, RequestOptions options = null); + + /// + /// Moves the user to the voice channel. + /// + /// The user to move. + /// the channel where the user gets moved to. + /// A task that represents the asynchronous operation for moving a user. + Task MoveAsync(IGuildUser user, IVoiceChannel targetChannel); + /// /// Deletes an existing from this guild. /// @@ -790,5 +994,174 @@ namespace Discord /// A task that represents the asynchronous removal operation. /// Task DeleteEmoteAsync(GuildEmote emote, RequestOptions options = null); + + /// + /// Creates a new sticker in this guild. + /// + /// The name of the sticker. + /// The description of the sticker. + /// The tags of the sticker. + /// The image of the new emote. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the created sticker. + /// + Task CreateStickerAsync(string name, string description, IEnumerable tags, Image image, RequestOptions options = null); + + /// + /// Creates a new sticker in this guild. + /// + /// The name of the sticker. + /// The description of the sticker. + /// The tags of the sticker. + /// The path of the file to upload. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the created sticker. + /// + Task CreateStickerAsync(string name, string description, IEnumerable tags, string path, RequestOptions options = null); + + /// + /// Creates a new sticker in this guild. + /// + /// The name of the sticker. + /// The description of the sticker. + /// The tags of the sticker. + /// The stream containing the file data. + /// The name of the file with the extension, ex: image.png. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the created sticker. + /// + Task CreateStickerAsync(string name, string description, IEnumerable tags, Stream stream, string filename, RequestOptions options = null); + + /// + /// Gets a specific sticker within this guild. + /// + /// The id of the sticker to get. + /// The that determines whether the object should be fetched from cache. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the sticker found with the + /// specified ; if none is found. + /// + Task GetStickerAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + + /// + /// Gets a collection of all stickers within this guild. + /// + /// The that determines whether the object should be fetched from cache. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a read-only collection + /// of stickers found within the guild. + /// + Task> GetStickersAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + + /// + /// Deletes a sticker within this guild. + /// + /// The sticker to delete. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous removal operation. + /// + Task DeleteStickerAsync(ICustomSticker sticker, RequestOptions options = null); + + /// + /// Gets a event within this guild. + /// + /// The id of the event. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. + /// + Task GetEventAsync(ulong id, RequestOptions options = null); + + /// + /// Gets a collection of events within this guild. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. + /// + Task> GetEventsAsync(RequestOptions options = null); + + /// + /// Creates an event within this guild. + /// + /// The name of the event. + /// The privacy level of the event. + /// The start time of the event. + /// The type of the event. + /// The description of the event. + /// The end time of the event. + /// + /// The channel id of the event. + /// + /// The event must have a type of or + /// in order to use this property. + /// + /// + /// A collection of speakers for the event. + /// The location of the event; links are supported + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous create operation. + /// + Task CreateEventAsync( + string name, + DateTimeOffset startTime, + GuildScheduledEventType type, + GuildScheduledEventPrivacyLevel privacyLevel = GuildScheduledEventPrivacyLevel.Private, + string description = null, + DateTimeOffset? endTime = null, + ulong? channelId = null, + string location = null, + RequestOptions options = null); + + /// + /// Gets this guilds application commands. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a read-only collection + /// of application commands found within the guild. + /// + Task> GetApplicationCommandsAsync(RequestOptions options = null); + + /// + /// Gets an application command within this guild with the specified id. + /// + /// The id of the application command to get. + /// The that determines whether the object should be fetched from cache. + /// The options to be used when sending the request. + /// + /// A ValueTask that represents the asynchronous get operation. The task result contains a + /// if found, otherwise . + /// + Task GetApplicationCommandAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, + RequestOptions options = null); + + /// + /// Creates an application command within this guild. + /// + /// The properties to use when creating the command. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the command that was created. + /// + Task CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null); + + /// + /// Overwrites the application commands within this guild. + /// + /// A collection of properties to use when creating the commands. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains a collection of commands that was created. + /// + Task> BulkOverwriteApplicationCommandsAsync(ApplicationCommandProperties[] properties, + RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuildScheduledEvent.cs b/src/Discord.Net.Core/Entities/Guilds/IGuildScheduledEvent.cs new file mode 100644 index 000000000..e50f4cc2b --- /dev/null +++ b/src/Discord.Net.Core/Entities/Guilds/IGuildScheduledEvent.cs @@ -0,0 +1,170 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents a generic guild scheduled event. + /// + public interface IGuildScheduledEvent : IEntity + { + /// + /// Gets the guild this event is scheduled in. + /// + IGuild Guild { get; } + + /// + /// Gets the optional channel id where this event will be hosted. + /// + ulong? ChannelId { get; } + + /// + /// Gets the user who created the event. + /// + IUser Creator { get; } + + /// + /// Gets the name of the event. + /// + string Name { get; } + + /// + /// Gets the description of the event. + /// + /// + /// This field is when the event doesn't have a discription. + /// + string Description { get; } + + /// + /// Gets the start time of the event. + /// + DateTimeOffset StartTime { get; } + + /// + /// Gets the optional end time of the event. + /// + DateTimeOffset? EndTime { get; } + + /// + /// Gets the privacy level of the event. + /// + GuildScheduledEventPrivacyLevel PrivacyLevel { get; } + + /// + /// Gets the status of the event. + /// + GuildScheduledEventStatus Status { get; } + + /// + /// Gets the type of the event. + /// + GuildScheduledEventType Type { get; } + + /// + /// Gets the optional entity id of the event. The "entity" of the event + /// can be a stage instance event as is seperate from . + /// + ulong? EntityId { get; } + + /// + /// Gets the location of the event if the is external. + /// + string Location { get; } + + /// + /// Gets the user count of the event. + /// + int? UserCount { get; } + + /// + /// Starts the event. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous start operation. + /// + Task StartAsync(RequestOptions options = null); + /// + /// Ends or canceles the event. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous end operation. + /// + Task EndAsync(RequestOptions options = null); + + /// + /// Modifies the guild event. + /// + /// The delegate containing the properties to modify the event with. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + Task ModifyAsync(Action func, RequestOptions options = null); + + /// + /// Deletes the current event. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous delete operation. + /// + Task DeleteAsync(RequestOptions options = null); + + /// + /// Gets a collection of N users interested in the event. + /// + /// + /// + /// The returned collection is an asynchronous enumerable object; one must call + /// to access the individual messages as a + /// collection. + /// + /// This method will attempt to fetch all users that are interested in the event. + /// The library will attempt to split up the requests according to and . + /// In other words, if there are 300 users, and the constant + /// is 100, the request will be split into 3 individual requests; thus returning 3 individual asynchronous + /// responses, hence the need of flattening. + /// + /// The options to be used when sending the request. + /// + /// Paged collection of users. + /// + IAsyncEnumerable> GetUsersAsync(RequestOptions options = null); + + /// + /// Gets a collection of N users interested in the event. + /// + /// + /// + /// The returned collection is an asynchronous enumerable object; one must call + /// to access the individual users as a + /// collection. + /// + /// + /// Do not fetch too many users at once! This may cause unwanted preemptive rate limit or even actual + /// rate limit, causing your bot to freeze! + /// + /// This method will attempt to fetch the number of users specified under around + /// the user depending on the . The library will + /// attempt to split up the requests according to your and + /// . In other words, should the user request 500 users, + /// and the constant is 100, the request will + /// be split into 5 individual requests; thus returning 5 individual asynchronous responses, hence the need + /// of flattening. + /// + /// The ID of the starting user to get the users from. + /// The direction of the users to be gotten from. + /// The numbers of users to be gotten from. + /// The options to be used when sending the request. + /// + /// Paged collection of users. + /// + IAsyncEnumerable> GetUsersAsync(ulong fromUserId, Direction dir, int limit = DiscordConfig.MaxGuildEventUsersPerBatch, RequestOptions options = null); + } +} diff --git a/src/Discord.Net.Core/Entities/Guilds/NsfwLevel.cs b/src/Discord.Net.Core/Entities/Guilds/NsfwLevel.cs new file mode 100644 index 000000000..e3ac345d9 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Guilds/NsfwLevel.cs @@ -0,0 +1,22 @@ +namespace Discord +{ + public enum NsfwLevel + { + /// + /// Default or unset. + /// + Default = 0, + /// + /// Guild has extremely suggestive or mature content that would only be suitable for users 18 or over. + /// + Explicit = 1, + /// + /// Guild has no content that could be deemed NSFW; in other words, SFW. + /// + Safe = 2, + /// + /// Guild has mildly NSFW content that may not be suitable for users under 18. + /// + AgeRestricted = 3 + } +} \ No newline at end of file diff --git a/src/Discord.Net.Core/Entities/Guilds/PermissionTarget.cs b/src/Discord.Net.Core/Entities/Guilds/PermissionTarget.cs index 3da2fb147..fb759e4c5 100644 --- a/src/Discord.Net.Core/Entities/Guilds/PermissionTarget.cs +++ b/src/Discord.Net.Core/Entities/Guilds/PermissionTarget.cs @@ -8,10 +8,10 @@ namespace Discord /// /// The target of the permission is a role. /// - Role, + Role = 0, /// /// The target of the permission is a user. /// - User + User = 1, } } diff --git a/src/Discord.Net.Core/Entities/Guilds/SystemChannelMessageDeny.cs b/src/Discord.Net.Core/Entities/Guilds/SystemChannelMessageDeny.cs index 3f69693d0..06de7b812 100644 --- a/src/Discord.Net.Core/Entities/Guilds/SystemChannelMessageDeny.cs +++ b/src/Discord.Net.Core/Entities/Guilds/SystemChannelMessageDeny.cs @@ -17,6 +17,14 @@ namespace Discord /// /// Deny the messages that are sent when a user boosts the guild. /// - GuildBoost = 0b10 + GuildBoost = 0b10, + /// + /// Deny the messages that are related to guild setup. + /// + GuildSetupTip = 0b100, + /// + /// Deny the reply with sticker button on welcome messages. + /// + WelcomeMessageReply = 0b1000 } } diff --git a/src/Discord.Net.Core/Entities/IApplication.cs b/src/Discord.Net.Core/Entities/IApplication.cs index 78a87dc19..d25e82c4b 100644 --- a/src/Discord.Net.Core/Entities/IApplication.cs +++ b/src/Discord.Net.Core/Entities/IApplication.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; + namespace Discord { /// @@ -16,16 +18,47 @@ namespace Discord /// /// Gets the RPC origins of the application. /// - string[] RPCOrigins { get; } - ulong Flags { get; } + IReadOnlyCollection RPCOrigins { get; } + /// + /// Gets the application's public flags. + /// + ApplicationFlags Flags { get; } + /// + /// Gets a collection of install parameters for this application. + /// + ApplicationInstallParams InstallParams { get; } + /// + /// Gets a collection of tags related to the application. + /// + IReadOnlyCollection Tags { get; } /// /// Gets the icon URL of the application. /// string IconUrl { get; } - + /// + /// Gets if the bot is public. + /// + bool IsBotPublic { get; } + /// + /// Gets if the bot requires code grant. + /// + bool BotRequiresCodeGrant { get; } + /// + /// Gets the team associated with this application if there is one. + /// + ITeam Team { get; } /// /// Gets the partial user object containing info on the owner of the application. /// IUser Owner { get; } + /// + /// Gets the url of the app's terms of service. + /// + public string TermsOfService { get; } + /// + /// Gets the the url of the app's privacy policy. + /// + public string PrivacyPolicy { get; } + } } diff --git a/src/Discord.Net.Core/Entities/IUpdateable.cs b/src/Discord.Net.Core/Entities/IUpdateable.cs index 3ae4613f5..d561e57a6 100644 --- a/src/Discord.Net.Core/Entities/IUpdateable.cs +++ b/src/Discord.Net.Core/Entities/IUpdateable.cs @@ -10,6 +10,7 @@ namespace Discord /// /// Updates this object's properties with its current state. /// + /// The options to be used when sending the request. Task UpdateAsync(RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOption.cs b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOption.cs new file mode 100644 index 000000000..5857bac81 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOption.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; + +namespace Discord +{ + /// + /// Represents a for making slash commands. + /// + public class ApplicationCommandOptionProperties + { + private string _name; + private string _description; + + /// + /// Gets or sets the name of this option. + /// + public string Name + { + get => _name; + set + { + if (value == null) + throw new ArgumentNullException(nameof(value), $"{nameof(Name)} cannot be null."); + + if (value.Length > 32) + throw new ArgumentOutOfRangeException(nameof(value), "Name length must be less than or equal to 32."); + + if (!Regex.IsMatch(value, @"^[\w-]{1,32}$")) + throw new FormatException($"{nameof(value)} must match the regex ^[\\w-]{{1,32}}$"); + + if (value.Any(x => char.IsUpper(x))) + throw new FormatException("Name cannot contain any uppercase characters."); + + _name = value; + } + } + + /// + /// Gets or sets the description of this option. + /// + public string Description + { + get => _description; + set => _description = value?.Length switch + { + > 100 => throw new ArgumentOutOfRangeException(nameof(value), "Description length must be less than or equal to 100."), + 0 => throw new ArgumentOutOfRangeException(nameof(value), "Description length must be at least 1."), + _ => value + }; + } + + /// + /// Gets or sets the type of this option. + /// + public ApplicationCommandOptionType Type { get; set; } + + /// + /// Gets or sets whether or not this options is the first required option for the user to complete. only one option can be default. + /// + public bool? IsDefault { get; set; } + + /// + /// Gets or sets if the option is required. + /// + public bool? IsRequired { get; set; } + + /// + /// Gets or sets whether or not this option supports autocomplete. + /// + public bool IsAutocomplete { get; set; } + + /// + /// Gets or sets the smallest number value the user can input. + /// + public double? MinValue { get; set; } + + /// + /// Gets or sets the largest number value the user can input. + /// + public double? MaxValue { get; set; } + + /// + /// Gets or sets the choices for string and int types for the user to pick from. + /// + public List Choices { get; set; } + + /// + /// Gets or sets if this option is a subcommand or subcommand group type, these nested options will be the parameters. + /// + public List Options { get; set; } + + /// + /// Gets or sets the allowed channel types for this option. + /// + public List ChannelTypes { get; set; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionChoice.cs b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionChoice.cs new file mode 100644 index 000000000..6a908b075 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionChoice.cs @@ -0,0 +1,44 @@ +using System; + +namespace Discord +{ + /// + /// Represents a choice for a . This class is used when making new commands. + /// + public class ApplicationCommandOptionChoiceProperties + { + private string _name; + private object _value; + + /// + /// Gets or sets the name of this choice. + /// + public string Name + { + get => _name; + set => _name = value?.Length switch + { + > 100 => throw new ArgumentOutOfRangeException(nameof(value), "Name length must be less than or equal to 100."), + 0 => throw new ArgumentOutOfRangeException(nameof(value), "Name length must at least 1."), + _ => value + }; + } + + /// + /// Gets the value of this choice. + /// + /// Discord only accepts int, double/floats, and string as the input. + /// + /// + public object Value + { + get => _value; + set + { + if (value != null && value is not string && !value.IsNumericType()) + throw new ArgumentException("The value of a choice must be a string or a numeric type!"); + _value = value; + } + } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionType.cs b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionType.cs new file mode 100644 index 000000000..0f919f1f6 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionType.cs @@ -0,0 +1,58 @@ +namespace Discord +{ + /// + /// The option type of the Slash command parameter, See the discord docs. + /// + public enum ApplicationCommandOptionType : byte + { + /// + /// A sub command. + /// + SubCommand = 1, + + /// + /// A group of sub commands. + /// + SubCommandGroup = 2, + + /// + /// A of text. + /// + String = 3, + + /// + /// An . + /// + Integer = 4, + + /// + /// A . + /// + Boolean = 5, + + /// + /// A . + /// + User = 6, + + /// + /// A . + /// + Channel = 7, + + /// + /// A . + /// + Role = 8, + + /// + /// A or . + /// + Mentionable = 9, + + /// + /// A . + /// + Number = 10 + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs new file mode 100644 index 000000000..501a0e905 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs @@ -0,0 +1,22 @@ +namespace Discord +{ + /// + /// Represents the base class to create/modify application commands. + /// + public abstract class ApplicationCommandProperties + { + internal abstract ApplicationCommandType Type { get; } + + /// + /// Gets or sets the name of this command. + /// + public Optional Name { get; set; } + + /// + /// Gets or sets whether the command is enabled by default when the app is added to a guild. Default is + /// + public Optional IsDefaultPermission { get; set; } + + internal ApplicationCommandProperties() { } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandTypes.cs b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandTypes.cs new file mode 100644 index 000000000..8cd31a420 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandTypes.cs @@ -0,0 +1,23 @@ +namespace Discord +{ + /// + /// Represents the types of application commands. + /// + public enum ApplicationCommandType : byte + { + /// + /// A Slash command type + /// + Slash = 1, + + /// + /// A Context Menu User command type + /// + User = 2, + + /// + /// A Context Menu Message command type + /// + Message = 3 + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/AutocompleteOption.cs b/src/Discord.Net.Core/Entities/Interactions/AutocompleteOption.cs new file mode 100644 index 000000000..eb22a9d27 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/AutocompleteOption.cs @@ -0,0 +1,36 @@ +namespace Discord +{ + /// + /// Represents an autocomplete option. + /// + public class AutocompleteOption + { + /// + /// Gets the type of this option. + /// + public ApplicationCommandOptionType Type { get; } + + /// + /// Gets the name of the option. + /// + public string Name { get; } + + /// + /// Gets the value of the option. + /// + public object Value { get; } + + /// + /// Gets whether or not this option is focused by the executing user. + /// + public bool Focused { get; } + + internal AutocompleteOption(ApplicationCommandOptionType type, string name, object value, bool focused) + { + Type = type; + Name = name; + Value = value; + Focused = focused; + } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/AutocompleteResult.cs b/src/Discord.Net.Core/Entities/Interactions/AutocompleteResult.cs new file mode 100644 index 000000000..0603a5a50 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/AutocompleteResult.cs @@ -0,0 +1,73 @@ +using System; + +namespace Discord +{ + /// + /// Represents a result to an autocomplete interaction. + /// + public class AutocompleteResult + { + private object _value; + private string _name; + + /// + /// Gets or sets the name of the result. + /// + /// + /// Name cannot be null and has to be between 1-100 characters in length. + /// + /// + /// + public string Name + { + get => _name; + set + { + if (value == null) + throw new ArgumentNullException(nameof(value), $"{nameof(Name)} cannot be null."); + _name = value.Length switch + { + > 100 => throw new ArgumentOutOfRangeException(nameof(value), "Name length must be less than or equal to 100."), + 0 => throw new ArgumentOutOfRangeException(nameof(value), "Name length must be at least 1."), + _ => value + }; + } + } + + /// + /// Gets or sets the value of the result. + /// + /// + /// Only , , and are allowed for a value. + /// + /// + /// + public object Value + { + get => _value; + set + { + if (value is not string && !value.IsNumericType()) + throw new ArgumentException($"{nameof(value)} must be a numeric type or a string!"); + + _value = value; + } + } + + /// + /// Creates a new . + /// + public AutocompleteResult() { } + + /// + /// Creates a new with the passed in and . + /// + /// + /// + public AutocompleteResult(string name, object value) + { + Name = name; + Value = value; + } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteraction.cs new file mode 100644 index 000000000..07d66bfcb --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteraction.cs @@ -0,0 +1,13 @@ +namespace Discord +{ + /// + /// Represents a Message Command interaction. + /// + public interface IMessageCommandInteraction : IApplicationCommandInteraction + { + /// + /// Gets the data associated with this interaction. + /// + new IMessageCommandInteractionData Data { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteractionData.cs b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteractionData.cs new file mode 100644 index 000000000..311eef2d6 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IMessageCommandInteractionData.cs @@ -0,0 +1,13 @@ +namespace Discord +{ + /// + /// Represents the data tied with the interaction. + /// + public interface IMessageCommandInteractionData : IApplicationCommandInteractionData + { + /// + /// Gets the message associated with this message command. + /// + IMessage Message { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteraction.cs new file mode 100644 index 000000000..2ffdfd9f6 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteraction.cs @@ -0,0 +1,13 @@ +namespace Discord +{ + /// + /// Represents a User Command interaction. + /// + public interface IUserCommandInteraction : IApplicationCommandInteraction + { + /// + /// Gets the data associated with this interaction. + /// + new IUserCommandInteractionData Data { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteractionData.cs b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteractionData.cs new file mode 100644 index 000000000..36e482ec9 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/IUserCommandInteractionData.cs @@ -0,0 +1,13 @@ +namespace Discord +{ + /// + /// Represents the data tied with the interaction. + /// + public interface IUserCommandInteractionData : IApplicationCommandInteractionData + { + /// + /// Gets the user who this command targets. + /// + IUser User { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/MessageCommandBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/MessageCommandBuilder.cs new file mode 100644 index 000000000..c7a7cf741 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/MessageCommandBuilder.cs @@ -0,0 +1,77 @@ +namespace Discord +{ + /// + /// A class used to build Message commands. + /// + public class MessageCommandBuilder + { + /// + /// Returns the maximum length a commands name allowed by Discord + /// + public const int MaxNameLength = 32; + + /// + /// Gets or sets the name of this Message command. + /// + public string Name + { + get => _name; + set + { + Preconditions.NotNullOrEmpty(value, nameof(Name)); + Preconditions.AtLeast(value.Length, 1, nameof(Name)); + Preconditions.AtMost(value.Length, MaxNameLength, nameof(Name)); + + _name = value; + } + } + + /// + /// Gets or sets whether the command is enabled by default when the app is added to a guild + /// + public bool IsDefaultPermission { get; set; } = true; + + private string _name; + + /// + /// Build the current builder into a class. + /// + /// + /// A that can be used to create message commands. + /// + public MessageCommandProperties Build() + { + var props = new MessageCommandProperties + { + Name = Name, + IsDefaultPermission = IsDefaultPermission + }; + + return props; + } + + /// + /// Sets the field name. + /// + /// The value to set the field name to. + /// + /// The current builder. + /// + public MessageCommandBuilder WithName(string name) + { + Name = name; + return this; + } + + /// + /// Sets the default permission of the current command. + /// + /// The default permission value to set. + /// The current builder. + public MessageCommandBuilder WithDefaultPermission(bool isDefaultPermission) + { + IsDefaultPermission = isDefaultPermission; + return this; + } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/MessageCommandProperties.cs b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/MessageCommandProperties.cs new file mode 100644 index 000000000..356ed23d6 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/MessageCommandProperties.cs @@ -0,0 +1,10 @@ +namespace Discord +{ + /// + /// A class used to create message commands. + /// + public class MessageCommandProperties : ApplicationCommandProperties + { + internal override ApplicationCommandType Type => ApplicationCommandType.Message; + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/UserCommandBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/UserCommandBuilder.cs new file mode 100644 index 000000000..bd1078be3 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/UserCommandBuilder.cs @@ -0,0 +1,75 @@ +namespace Discord +{ + /// + /// A class used to build user commands. + /// + public class UserCommandBuilder + { + /// + /// Returns the maximum length a commands name allowed by Discord. + /// + public const int MaxNameLength = 32; + + /// + /// Gets or sets the name of this User command. + /// + public string Name + { + get => _name; + set + { + Preconditions.NotNullOrEmpty(value, nameof(Name)); + Preconditions.AtLeast(value.Length, 1, nameof(Name)); + Preconditions.AtMost(value.Length, MaxNameLength, nameof(Name)); + + _name = value; + } + } + + /// + /// Gets or sets whether the command is enabled by default when the app is added to a guild. + /// + public bool IsDefaultPermission { get; set; } = true; + + private string _name; + + /// + /// Build the current builder into a class. + /// + /// A that can be used to create user commands. + public UserCommandProperties Build() + { + var props = new UserCommandProperties + { + Name = Name, + IsDefaultPermission = IsDefaultPermission + }; + + return props; + } + + /// + /// Sets the field name. + /// + /// The value to set the field name to. + /// + /// The current builder. + /// + public UserCommandBuilder WithName(string name) + { + Name = name; + return this; + } + + /// + /// Sets the default permission of the current command. + /// + /// The default permission value to set. + /// The current builder. + public UserCommandBuilder WithDefaultPermission(bool isDefaultPermission) + { + IsDefaultPermission = isDefaultPermission; + return this; + } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/UserCommandProperties.cs b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/UserCommandProperties.cs new file mode 100644 index 000000000..c42e916d9 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/UserCommandProperties.cs @@ -0,0 +1,10 @@ +namespace Discord +{ + /// + /// A class used to create User commands. + /// + public class UserCommandProperties : ApplicationCommandProperties + { + internal override ApplicationCommandType Type => ApplicationCommandType.User; + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommand.cs b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommand.cs new file mode 100644 index 000000000..72045a52a --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommand.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// The base command model that belongs to an application. + /// + public interface IApplicationCommand : ISnowflakeEntity, IDeletable + { + /// + /// Gets the unique id of the parent application. + /// + ulong ApplicationId { get; } + + /// + /// Gets the type of the command. + /// + ApplicationCommandType Type { get; } + + /// + /// Gets the name of the command. + /// + string Name { get; } + + /// + /// Gets the description of the command. + /// + string Description { get; } + + /// + /// Gets whether the command is enabled by default when the app is added to a guild. + /// + bool IsDefaultPermission { get; } + + /// + /// Gets a collection of options for this application command. + /// + IReadOnlyCollection Options { get; } + + /// + /// Modifies the current application command. + /// + /// The new properties to use when modifying the command. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + Task ModifyAsync(Action func, RequestOptions options = null); + + /// + /// Modifies the current application command. + /// + /// The new properties to use when modifying the command. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + /// Thrown when you pass in an invalid type. + Task ModifyAsync(Action func, RequestOptions options = null) + where TArg : ApplicationCommandProperties; + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteraction.cs new file mode 100644 index 000000000..b079a47be --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteraction.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents an application command interaction. + /// + public interface IApplicationCommandInteraction : IDiscordInteraction + { + /// + /// Gets the data of the application command interaction + /// + new IApplicationCommandInteractionData Data { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionData.cs b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionData.cs new file mode 100644 index 000000000..428f20fb6 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionData.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; + +namespace Discord +{ + /// + /// Represents data of an Interaction Command, see . + /// + public interface IApplicationCommandInteractionData : IDiscordInteractionData + { + /// + /// Gets the snowflake id of this command. + /// + ulong Id { get; } + + /// + /// Gets the name of this command. + /// + string Name { get; } + + /// + /// Gets the options that the user has provided. + /// + IReadOnlyCollection Options { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionDataOption.cs b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionDataOption.cs new file mode 100644 index 000000000..072d2b32b --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionDataOption.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; + +namespace Discord +{ + /// + /// Represents a option group for a command. + /// + public interface IApplicationCommandInteractionDataOption + { + /// + /// Gets the name of the parameter. + /// + string Name { get; } + + /// + /// Gets the value of the pair. + /// + /// This objects type can be any one of the option types in . + /// + /// + object Value { get; } + + /// + /// Gets the type of this data's option. + /// + ApplicationCommandOptionType Type { get; } + + /// + /// Gets the nested options of this option. + /// + IReadOnlyCollection Options { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOption.cs b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOption.cs new file mode 100644 index 000000000..72554fc98 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOption.cs @@ -0,0 +1,65 @@ +using System.Collections.Generic; + +namespace Discord +{ + /// + /// Options for the . + /// + public interface IApplicationCommandOption + { + /// + /// Gets the type of this . + /// + ApplicationCommandOptionType Type { get; } + + /// + /// Gets the name of this command option. + /// + string Name { get; } + + /// + /// Gets the description of this command option. + /// + string Description { get; } + + /// + /// Gets whether or not this is the first required option for the user to complete. + /// + bool? IsDefault { get; } + + /// + /// Gets whether or not the parameter is required or optional. + /// + bool? IsRequired { get; } + + /// + /// Gets whether or not the option has autocomplete enabled. + /// + bool? IsAutocomplete { get; } + + /// + /// Gets the smallest number value the user can input. + /// + double? MinValue { get; } + + /// + /// Gets the largest number value the user can input. + /// + double? MaxValue { get; } + + /// + /// Gets the choices for string and int types for the user to pick from. + /// + IReadOnlyCollection Choices { get; } + + /// + /// Gets the sub-options for this command option. + /// + IReadOnlyCollection Options { get; } + + /// + /// Gets the allowed channel types for this option. + /// + IReadOnlyCollection ChannelTypes { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOptionChoice.cs b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOptionChoice.cs new file mode 100644 index 000000000..631706c6f --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOptionChoice.cs @@ -0,0 +1,18 @@ +namespace Discord +{ + /// + /// Specifies choices for command group. + /// + public interface IApplicationCommandOptionChoice + { + /// + /// Gets the choice name. + /// + string Name { get; } + + /// + /// Gets the value of the choice. + /// + object Value { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/IDiscordInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/IDiscordInteraction.cs new file mode 100644 index 000000000..064d3c4da --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/IDiscordInteraction.cs @@ -0,0 +1,323 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents a discord interaction. + /// + public interface IDiscordInteraction : ISnowflakeEntity + { + /// + /// Gets the id of the interaction. + /// + new ulong Id { get; } + + /// + /// Gets the type of this . + /// + InteractionType Type { get; } + + /// + /// Gets the data sent within this interaction. + /// + IDiscordInteractionData Data { get; } + + /// + /// Gets the continuation token for responding to the interaction. + /// + string Token { get; } + + /// + /// Gets the version of the interaction, always 1. + /// + int Version { get; } + + /// + /// Gets whether or not this interaction has been responded to. + /// + /// + /// This property is locally set -- if you're running multiple bots + /// off the same token then this property won't be in sync with them. + /// + bool HasResponded { get; } + + /// + /// Gets the user who invoked the interaction. + /// + IUser User { get; } + + /// + /// Responds to an Interaction with type . + /// + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// The request options for this response. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, + bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); + + /// + /// Responds to this interaction with a file attachment. + /// + /// The file to upload. + /// The file name of the attachment. + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// The request options for this response. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// +#if NETCOREAPP3_0_OR_GREATER + async Task RespondWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + { + using(var file = new FileAttachment(fileStream, fileName)) + { + await RespondWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + } + } +#else + Task RespondWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); +#endif + /// + /// Responds to this interaction with a file attachment. + /// + /// The file to upload. + /// The file name of the attachment. + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// The request options for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// +#if NETCOREAPP3_0_OR_GREATER + async Task RespondWithFileAsync(string filePath, string fileName = null, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + { + using (var file = new FileAttachment(filePath, fileName)) + { + await RespondWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + } + } +#else + Task RespondWithFileAsync(string filePath, string fileName = null, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); +#endif + /// + /// Responds to this interaction with a file attachment. + /// + /// The attachment containing the file and description. + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// The request options for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// +#if NETCOREAPP3_0_OR_GREATER + Task RespondWithFileAsync(FileAttachment attachment, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + => RespondWithFilesAsync(new FileAttachment[] { attachment }, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options); +#else + Task RespondWithFileAsync(FileAttachment attachment, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); +#endif + /// + /// Responds to this interaction with a collection of file attachments. + /// + /// A collection of attachments to upload. + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// The request options for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + Task RespondWithFilesAsync(IEnumerable attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); + /// + /// Sends a followup message for this interaction. + /// + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// The request options for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + Task FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); + /// + /// Sends a followup message for this interaction. + /// + /// The file to upload. + /// The file name of the attachment. + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// The request options for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// +#if NETCOREAPP3_0_OR_GREATER + async Task FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + { + using(var file = new FileAttachment(fileStream, fileName)) + { + return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + } + } +#else + Task FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); +#endif + /// + /// Sends a followup message for this interaction. + /// + /// The file to upload. + /// The file name of the attachment. + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// The request options for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// +#if NETCOREAPP3_0_OR_GREATER + async Task FollowupWithFileAsync(string filePath, string fileName = null, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + { + using (var file = new FileAttachment(filePath, fileName)) + { + return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + } + } +#else + Task FollowupWithFileAsync(string filePath, string fileName = null, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); +#endif + /// + /// Sends a followup message for this interaction. + /// + /// The attachment containing the file and description. + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// The request options for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// +#if NETCOREAPP3_0_OR_GREATER + Task FollowupWithFileAsync(FileAttachment attachment, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + => FollowupWithFilesAsync(new FileAttachment[] { attachment }, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options); +#else + Task FollowupWithFileAsync(FileAttachment attachment, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); +#endif + /// + /// Sends a followup message for this interaction. + /// + /// A collection of attachments to upload. + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// The request options for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + Task FollowupWithFilesAsync(IEnumerable attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); + /// + /// Gets the original response for this interaction. + /// + /// The request options for this request. + /// A that represents the initial response. + Task GetOriginalResponseAsync(RequestOptions options = null); + /// + /// Edits original response for this interaction. + /// + /// A delegate containing the properties to modify the message with. + /// The request options for this request. + /// + /// A task that represents an asynchronous modification operation. The task result + /// contains the updated message. + /// + Task ModifyOriginalResponseAsync(Action func, RequestOptions options = null); + /// + /// Deletes the original response to this interaction. + /// + /// The request options for this request. + /// + /// A task that represents an asynchronous deletion operation. + /// + Task DeleteOriginalResponseAsync(RequestOptions options = null); + /// + /// Acknowledges this interaction. + /// + /// + /// A task that represents the asynchronous operation of deferring the interaction. + /// + Task DeferAsync(bool ephemeral = false, RequestOptions options = null); + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/IDiscordInteractionData.cs b/src/Discord.Net.Core/Entities/Interactions/IDiscordInteractionData.cs new file mode 100644 index 000000000..42b95738e --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/IDiscordInteractionData.cs @@ -0,0 +1,7 @@ +namespace Discord +{ + /// + /// Represents an interface used to specify classes that they are a valid data type of a class. + /// + public interface IDiscordInteractionData { } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/InteractionResponseType.cs b/src/Discord.Net.Core/Entities/Interactions/InteractionResponseType.cs new file mode 100644 index 000000000..ebdf29781 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/InteractionResponseType.cs @@ -0,0 +1,46 @@ +using System; + +namespace Discord +{ + /// + /// The response type for an . + /// + /// + /// After receiving an interaction, you must respond to acknowledge it. You can choose to respond with a message immediately using + /// or you can choose to send a deferred response with . If choosing a deferred response, the user will see a loading state for the interaction, + /// and you'll have up to 15 minutes to edit the original deferred response using Edit Original Interaction Response. + /// You can read more about Response types Here. + /// + public enum InteractionResponseType : byte + { + /// + /// ACK a Ping. + /// + Pong = 1, + + /// + /// Respond to an interaction with a message. + /// + ChannelMessageWithSource = 4, + + /// + /// ACK an interaction and edit a response later, the user sees a loading state. + /// + DeferredChannelMessageWithSource = 5, + + /// + /// For components: ACK an interaction and edit the original message later; the user does not see a loading state. + /// + DeferredUpdateMessage = 6, + + /// + /// For components: edit the message the component was attached to. + /// + UpdateMessage = 7, + + /// + /// Respond with a set of choices to a autocomplete interaction. + /// + ApplicationCommandAutocompleteResult = 8 + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/InteractionType.cs b/src/Discord.Net.Core/Entities/Interactions/InteractionType.cs new file mode 100644 index 000000000..e09c906b5 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/InteractionType.cs @@ -0,0 +1,28 @@ +namespace Discord +{ + /// + /// Represents a type of Interaction from discord. + /// + public enum InteractionType : byte + { + /// + /// A ping from discord. + /// + Ping = 1, + + /// + /// A sent from discord. + /// + ApplicationCommand = 2, + + /// + /// A sent from discord. + /// + MessageComponent = 3, + + /// + /// An autocomplete request sent from discord. + /// + ApplicationCommandAutocomplete = 4 + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ActionRowComponent.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ActionRowComponent.cs new file mode 100644 index 000000000..202a5687f --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ActionRowComponent.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; + +namespace Discord +{ + /// + /// Represents a Row for child components to live in. + /// + public class ActionRowComponent : IMessageComponent + { + /// + public ComponentType Type => ComponentType.ActionRow; + + /// + /// Gets the child components in this row. + /// + public IReadOnlyCollection Components { get; internal set; } + + internal ActionRowComponent() { } + + internal ActionRowComponent(List components) + { + Components = components; + } + + string IMessageComponent.CustomId => null; + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ButtonComponent.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ButtonComponent.cs new file mode 100644 index 000000000..4b9fa2753 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ButtonComponent.cs @@ -0,0 +1,61 @@ +namespace Discord +{ + /// + /// Represents a Button. + /// + public class ButtonComponent : IMessageComponent + { + /// + public ComponentType Type => ComponentType.Button; + + /// + /// Gets the of this button, example buttons with each style can be found Here. + /// + public ButtonStyle Style { get; } + + /// + /// Gets the label of the button, this is the text that is shown. + /// + public string Label { get; } + + /// + /// Gets the displayed with this button. + /// + public IEmote Emote { get; } + + /// + public string CustomId { get; } + + /// + /// Gets the URL for a button. + /// + /// + /// You cannot have a button with a URL and a CustomId. + /// + public string Url { get; } + + /// + /// Gets whether this button is disabled or not. + /// + public bool IsDisabled { get; } + + /// + /// Turns this button into a button builder. + /// + /// + /// A newly created button builder with the same properties as this button. + /// + public ButtonBuilder ToBuilder() + => new ButtonBuilder(Label, CustomId, Style, Url, Emote, IsDisabled); + + internal ButtonComponent(ButtonStyle style, string label, IEmote emote, string customId, string url, bool isDisabled) + { + Style = style; + Label = label; + Emote = emote; + CustomId = customId; + Url = url; + IsDisabled = isDisabled; + } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ButtonStyle.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ButtonStyle.cs new file mode 100644 index 000000000..92d48ab4f --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ButtonStyle.cs @@ -0,0 +1,33 @@ +namespace Discord +{ + /// + /// Represents different styles to use with buttons. You can see an example of the different styles at + /// + public enum ButtonStyle + { + /// + /// A Blurple button + /// + Primary = 1, + + /// + /// A Grey (or gray) button + /// + Secondary = 2, + + /// + /// A Green button + /// + Success = 3, + + /// + /// A Red button + /// + Danger = 4, + + /// + /// A button with a little popup box indicating that this button is a link. + /// + Link = 5 + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs new file mode 100644 index 000000000..4461a4205 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs @@ -0,0 +1,1064 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Discord.Utils; + +namespace Discord +{ + /// + /// Represents a builder for creating a . + /// + public class ComponentBuilder + { + /// + /// The max length of a . + /// + public const int MaxCustomIdLength = 100; + + /// + /// The max amount of rows a message can have. + /// + public const int MaxActionRowCount = 5; + + /// + /// Gets or sets the Action Rows for this Component Builder. + /// + /// cannot be null. + /// count exceeds . + public List ActionRows + { + get => _actionRows; + set + { + if (value == null) + throw new ArgumentNullException(nameof(value), $"{nameof(ActionRows)} cannot be null."); + if (value.Count > MaxActionRowCount) + throw new ArgumentOutOfRangeException(nameof(value), $"Action row count must be less than or equal to {MaxActionRowCount}."); + _actionRows = value; + } + } + + private List _actionRows; + + /// + /// Creates a new builder from a message. + /// + /// The message to create the builder from. + /// The newly created builder. + public static ComponentBuilder FromMessage(IMessage message) + => FromComponents(message.Components); + + /// + /// Creates a new builder from the provided list of components. + /// + /// The components to create the builder from. + /// The newly created builder. + public static ComponentBuilder FromComponents(IReadOnlyCollection components) + { + var builder = new ComponentBuilder(); + for (int i = 0; i != components.Count; i++) + { + var component = components.ElementAt(i); + builder.AddComponent(component, i); + } + return builder; + } + + internal void AddComponent(IMessageComponent component, int row) + { + switch (component) + { + case ButtonComponent button: + WithButton(button.Label, button.CustomId, button.Style, button.Emote, button.Url, button.IsDisabled, row); + break; + case ActionRowComponent actionRow: + foreach (var cmp in actionRow.Components) + AddComponent(cmp, row); + break; + case SelectMenuComponent menu: + WithSelectMenu(menu.CustomId, menu.Options.Select(x => new SelectMenuOptionBuilder(x.Label, x.Value, x.Description, x.Emote, x.IsDefault)).ToList(), menu.Placeholder, menu.MinValues, menu.MaxValues, menu.IsDisabled, row); + break; + } + } + + /// + /// Adds a to the at the specific row. + /// If the row cannot accept the component then it will add it to a row that can. + /// + /// The custom id of the menu. + /// The options of the menu. + /// The placeholder of the menu. + /// The min values of the placeholder. + /// The max values of the placeholder. + /// Whether or not the menu is disabled. + /// The row to add the menu to. + /// + public ComponentBuilder WithSelectMenu(string customId, List options, + string placeholder = null, int minValues = 1, int maxValues = 1, bool disabled = false, int row = 0) + { + return WithSelectMenu(new SelectMenuBuilder() + .WithCustomId(customId) + .WithOptions(options) + .WithPlaceholder(placeholder) + .WithMaxValues(maxValues) + .WithMinValues(minValues) + .WithDisabled(disabled), + row); + } + + /// + /// Adds a to the at the specific row. + /// If the row cannot accept the component then it will add it to a row that can. + /// + /// The menu to add. + /// The row to attempt to add this component on. + /// There is no more row to add a menu. + /// must be less than . + /// The current builder. + public ComponentBuilder WithSelectMenu(SelectMenuBuilder menu, int row = 0) + { + Preconditions.LessThan(row, MaxActionRowCount, nameof(row)); + if (menu.Options.Distinct().Count() != menu.Options.Count) + throw new InvalidOperationException("Please make sure that there is no duplicates values."); + + var builtMenu = menu.Build(); + + if (_actionRows == null) + { + _actionRows = new List + { + new ActionRowBuilder().AddComponent(builtMenu) + }; + } + else + { + if (_actionRows.Count == row) + _actionRows.Add(new ActionRowBuilder().AddComponent(builtMenu)); + else + { + ActionRowBuilder actionRow; + if (_actionRows.Count > row) + actionRow = _actionRows.ElementAt(row); + else + { + actionRow = new ActionRowBuilder(); + _actionRows.Add(actionRow); + } + + if (actionRow.CanTakeComponent(builtMenu)) + actionRow.AddComponent(builtMenu); + else if (row < MaxActionRowCount) + WithSelectMenu(menu, row + 1); + else + throw new InvalidOperationException($"There is no more row to add a {nameof(builtMenu)}"); + } + } + + return this; + } + + /// + /// Adds a with specified parameters to the at the specific row. + /// If the row cannot accept the component then it will add it to a row that can. + /// + /// The label text for the newly added button. + /// The style of this newly added button. + /// A to be used with this button. + /// The custom id of the newly added button. + /// A URL to be used only if the is a Link. + /// Whether or not the newly created button is disabled. + /// The row the button should be placed on. + /// The current builder. + public ComponentBuilder WithButton( + string label = null, + string customId = null, + ButtonStyle style = ButtonStyle.Primary, + IEmote emote = null, + string url = null, + bool disabled = false, + int row = 0) + { + var button = new ButtonBuilder() + .WithLabel(label) + .WithStyle(style) + .WithEmote(emote) + .WithCustomId(customId) + .WithUrl(url) + .WithDisabled(disabled); + + return WithButton(button, row); + } + + /// + /// Adds a to the at the specific row. + /// If the row cannot accept the component then it will add it to a row that can. + /// + /// The button to add. + /// The row to add the button. + /// There is no more row to add a menu. + /// must be less than . + /// The current builder. + public ComponentBuilder WithButton(ButtonBuilder button, int row = 0) + { + Preconditions.LessThan(row, MaxActionRowCount, nameof(row)); + + var builtButton = button.Build(); + + if (_actionRows == null) + { + _actionRows = new List + { + new ActionRowBuilder().AddComponent(builtButton) + }; + } + else + { + if (_actionRows.Count == row) + _actionRows.Add(new ActionRowBuilder().AddComponent(builtButton)); + else + { + ActionRowBuilder actionRow; + if (_actionRows.Count > row) + actionRow = _actionRows.ElementAt(row); + else + { + actionRow = new ActionRowBuilder(); + _actionRows.Add(actionRow); + } + + if (actionRow.CanTakeComponent(builtButton)) + actionRow.AddComponent(builtButton); + else if (row < MaxActionRowCount) + WithButton(button, row + 1); + else + throw new InvalidOperationException($"There is no more row to add a {nameof(button)}"); + } + } + + return this; + } + + /// + /// Builds this builder into a used to send your components. + /// + /// A that can be sent with . + public MessageComponent Build() + { + return _actionRows != null + ? new MessageComponent(_actionRows.Select(x => x.Build()).ToList()) + : MessageComponent.Empty; + } + } + + /// + /// Represents a class used to build Action rows. + /// + public class ActionRowBuilder + { + /// + /// The max amount of child components this row can hold. + /// + public const int MaxChildCount = 5; + + /// + /// Gets or sets the components inside this row. + /// + /// cannot be null. + /// count exceeds . + public List Components + { + get => _components; + set + { + if (value == null) + throw new ArgumentNullException(nameof(value), $"{nameof(Components)} cannot be null."); + + _components = value.Count switch + { + 0 => throw new ArgumentOutOfRangeException(nameof(value), "There must be at least 1 component in a row."), + > MaxChildCount => throw new ArgumentOutOfRangeException(nameof(value), $"Action row can only contain {MaxChildCount} child components!"), + _ => value + }; + } + } + + private List _components = new List(); + + /// + /// Adds a list of components to the current row. + /// + /// The list of components to add. + /// + /// The current builder. + public ActionRowBuilder WithComponents(List components) + { + Components = components; + return this; + } + + /// + /// Adds a component at the end of the current row. + /// + /// The component to add. + /// Components count reached + /// The current builder. + public ActionRowBuilder AddComponent(IMessageComponent component) + { + if (Components.Count >= MaxChildCount) + throw new InvalidOperationException($"Components count reached {MaxChildCount}"); + + Components.Add(component); + return this; + } + + /// + /// Builds the current builder to a that can be used within a + /// + /// A that can be used within a + public ActionRowComponent Build() + { + return new ActionRowComponent(_components); + } + + internal bool CanTakeComponent(IMessageComponent component) + { + switch (component.Type) + { + case ComponentType.ActionRow: + return false; + case ComponentType.Button: + if (Components.Any(x => x.Type == ComponentType.SelectMenu)) + return false; + else + return Components.Count < 5; + case ComponentType.SelectMenu: + return Components.Count == 0; + default: + return false; + } + } + } + + /// + /// Represents a class used to build 's. + /// + public class ButtonBuilder + { + /// + /// The max length of a . + /// + public const int MaxButtonLabelLength = 80; + + /// + /// Gets or sets the label of the current button. + /// + /// length exceeds . + /// length exceeds . + public string Label + { + get => _label; + set => _label = value?.Length switch + { + > MaxButtonLabelLength => throw new ArgumentOutOfRangeException(nameof(value), $"Label length must be less or equal to {MaxButtonLabelLength}."), + 0 => throw new ArgumentOutOfRangeException(nameof(value), "Label length must be at least 1."), + _ => value + }; + } + + /// + /// Gets or sets the custom id of the current button. + /// + /// length exceeds + /// length subceeds 1. + public string CustomId + { + get => _customId; + set => _customId = value?.Length switch + { + > ComponentBuilder.MaxCustomIdLength => throw new ArgumentOutOfRangeException(nameof(value), $"Custom Id length must be less or equal to {ComponentBuilder.MaxCustomIdLength}."), + 0 => throw new ArgumentOutOfRangeException(nameof(value), "Custom Id length must be at least 1."), + _ => value + }; + } + + /// + /// Gets or sets the of the current button. + /// + public ButtonStyle Style { get; set; } + + /// + /// Gets or sets the of the current button. + /// + public IEmote Emote { get; set; } + + /// + /// Gets or sets the url of the current button. + /// + public string Url { get; set; } + + /// + /// Gets or sets whether the current button is disabled. + /// + public bool IsDisabled { get; set; } + + private string _label; + private string _customId; + + /// + /// Creates a new instance of a . + /// + public ButtonBuilder() { } + + /// + /// Creates a new instance of a . + /// + /// The label to use on the newly created link button. + /// The url of this button. + /// The custom ID of this button. + /// The custom ID of this button. + /// The emote of this button. + /// Disabled this button or not. + public ButtonBuilder(string label = null, string customId = null, ButtonStyle style = ButtonStyle.Primary, string url = null, IEmote emote = null, bool isDisabled = false) + { + CustomId = customId; + Style = style; + Url = url; + Label = label; + IsDisabled = isDisabled; + Emote = emote; + } + + /// + /// Creates a new instance of a from instance of a . + /// + public ButtonBuilder(ButtonComponent button) + { + CustomId = button.CustomId; + Style = button.Style; + Url = button.Url; + Label = button.Label; + IsDisabled = button.IsDisabled; + Emote = button.Emote; + } + + /// + /// Creates a button with the style. + /// + /// The label for this link button. + /// The url for this link button to go to. + /// The emote for this link button. + /// A builder with the newly created button. + public static ButtonBuilder CreateLinkButton(string label, string url, IEmote emote = null) + => new ButtonBuilder(label, null, ButtonStyle.Link, url, emote: emote); + + /// + /// Creates a button with the style. + /// + /// The label for this danger button. + /// The custom id for this danger button. + /// The emote for this danger button. + /// A builder with the newly created button. + public static ButtonBuilder CreateDangerButton(string label, string customId, IEmote emote = null) + => new ButtonBuilder(label, customId, ButtonStyle.Danger, emote: emote); + + /// + /// Creates a button with the style. + /// + /// The label for this primary button. + /// The custom id for this primary button. + /// The emote for this primary button. + /// A builder with the newly created button. + public static ButtonBuilder CreatePrimaryButton(string label, string customId, IEmote emote = null) + => new ButtonBuilder(label, customId, emote: emote); + + /// + /// Creates a button with the style. + /// + /// The label for this secondary button. + /// The custom id for this secondary button. + /// The emote for this secondary button. + /// A builder with the newly created button. + public static ButtonBuilder CreateSecondaryButton(string label, string customId, IEmote emote = null) + => new ButtonBuilder(label, customId, ButtonStyle.Secondary, emote: emote); + + /// + /// Creates a button with the style. + /// + /// The label for this success button. + /// The custom id for this success button. + /// The emote for this success button. + /// A builder with the newly created button. + public static ButtonBuilder CreateSuccessButton(string label, string customId, IEmote emote = null) + => new ButtonBuilder(label, customId, ButtonStyle.Success, emote: emote); + + /// + /// Sets the current buttons label to the specified text. + /// + /// The text for the label. + /// + /// The current builder. + public ButtonBuilder WithLabel(string label) + { + Label = label; + return this; + } + + /// + /// Sets the current buttons style. + /// + /// The style for this builders button. + /// The current builder. + public ButtonBuilder WithStyle(ButtonStyle style) + { + Style = style; + return this; + } + + /// + /// Sets the current buttons emote. + /// + /// The emote to use for the current button. + /// The current builder. + public ButtonBuilder WithEmote(IEmote emote) + { + Emote = emote; + return this; + } + + /// + /// Sets the current buttons url. + /// + /// The url to use for the current button. + /// The current builder. + public ButtonBuilder WithUrl(string url) + { + Url = url; + return this; + } + + /// + /// Sets the custom id of the current button. + /// + /// The id to use for the current button. + /// + /// The current builder. + public ButtonBuilder WithCustomId(string id) + { + CustomId = id; + return this; + } + + /// + /// Sets whether the current button is disabled. + /// + /// Whether the current button is disabled or not. + /// The current builder. + public ButtonBuilder WithDisabled(bool isDisabled) + { + IsDisabled = isDisabled; + return this; + } + + /// + /// Builds this builder into a to be used in a . + /// + /// A to be used in a . + /// A button must contain either a or a , but not both. + /// A button must have an or a . + /// A link button must contain a URL. + /// A URL must include a protocol (http or https). + /// A non-link button must contain a custom id + public ButtonComponent Build() + { + if (string.IsNullOrEmpty(Label) && Emote == null) + throw new InvalidOperationException("A button must have an Emote or a label!"); + + if (!(string.IsNullOrEmpty(Url) ^ string.IsNullOrEmpty(CustomId))) + throw new InvalidOperationException("A button must contain either a URL or a CustomId, but not both!"); + + if (Style == ButtonStyle.Link) + { + if (string.IsNullOrEmpty(Url)) + throw new InvalidOperationException("Link buttons must have a link associated with them"); + UrlValidation.ValidateButton(Url); + } + else if (string.IsNullOrEmpty(CustomId)) + throw new InvalidOperationException("Non-link buttons must have a custom id associated with them"); + + return new ButtonComponent(Style, Label, Emote, CustomId, Url, IsDisabled); + } + } + + /// + /// Represents a class used to build 's. + /// + public class SelectMenuBuilder + { + /// + /// The max length of a . + /// + public const int MaxPlaceholderLength = 100; + + /// + /// The maximum number of values for the and properties. + /// + public const int MaxValuesCount = 25; + + /// + /// The maximum number of options a can have. + /// + public const int MaxOptionCount = 25; + + /// + /// Gets or sets the custom id of the current select menu. + /// + /// length exceeds + /// length subceeds 1. + public string CustomId + { + get => _customId; + set => _customId = value?.Length switch + { + > ComponentBuilder.MaxCustomIdLength => throw new ArgumentOutOfRangeException(nameof(value), $"Custom Id length must be less or equal to {ComponentBuilder.MaxCustomIdLength}."), + 0 => throw new ArgumentOutOfRangeException(nameof(value), "Custom Id length must be at least 1."), + _ => value + }; + } + + /// + /// Gets or sets the placeholder text of the current select menu. + /// + /// length exceeds . + /// length subceeds 1. + public string Placeholder + { + get => _placeholder; + set => _placeholder = value?.Length switch + { + > MaxPlaceholderLength => throw new ArgumentOutOfRangeException(nameof(value), $"Placeholder length must be less or equal to {MaxPlaceholderLength}."), + 0 => throw new ArgumentOutOfRangeException(nameof(value), "Placeholder length must be at least 1."), + _ => value + }; + } + + /// + /// Gets or sets the minimum values of the current select menu. + /// + /// exceeds . + public int MinValues + { + get => _minValues; + set + { + Preconditions.AtMost(value, MaxValuesCount, nameof(MinValues)); + _minValues = value; + } + } + + /// + /// Gets or sets the maximum values of the current select menu. + /// + /// exceeds . + public int MaxValues + { + get => _maxValues; + set + { + Preconditions.AtMost(value, MaxValuesCount, nameof(MaxValues)); + _maxValues = value; + } + } + + /// + /// Gets or sets a collection of for this current select menu. + /// + /// count exceeds . + /// is null. + public List Options + { + get => _options; + set + { + if (value != null) + Preconditions.AtMost(value.Count, MaxOptionCount, nameof(Options)); + else + throw new ArgumentNullException(nameof(value), $"{nameof(Options)} cannot be null."); + + _options = value; + } + } + + /// + /// Gets or sets whether the current menu is disabled. + /// + public bool IsDisabled { get; set; } + + private List _options = new List(); + private int _minValues = 1; + private int _maxValues = 1; + private string _placeholder; + private string _customId; + + /// + /// Creates a new instance of a . + /// + public SelectMenuBuilder() { } + + /// + /// Creates a new instance of a from instance of . + /// + public SelectMenuBuilder(SelectMenuComponent selectMenu) + { + Placeholder = selectMenu.Placeholder; + CustomId = selectMenu.Placeholder; + MaxValues = selectMenu.MaxValues; + MinValues = selectMenu.MinValues; + IsDisabled = selectMenu.IsDisabled; + Options = selectMenu.Options? + .Select(x => new SelectMenuOptionBuilder(x.Label, x.Value, x.Description, x.Emote, x.IsDefault)) + .ToList(); + } + + /// + /// Creates a new instance of a . + /// + /// The custom id of this select menu. + /// The options for this select menu. + /// The placeholder of this select menu. + /// The max values of this select menu. + /// The min values of this select menu. + /// Disabled this select menu or not. + public SelectMenuBuilder(string customId, List options, string placeholder = null, int maxValues = 1, int minValues = 1, bool isDisabled = false) + { + CustomId = customId; + Options = options; + Placeholder = placeholder; + IsDisabled = isDisabled; + MaxValues = maxValues; + MinValues = minValues; + } + + /// + /// Sets the field CustomId. + /// + /// The value to set the field CustomId to. + /// + /// + /// The current builder. + /// + public SelectMenuBuilder WithCustomId(string customId) + { + CustomId = customId; + return this; + } + + /// + /// Sets the field placeholder. + /// + /// The value to set the field placeholder to. + /// + /// + /// The current builder. + /// + public SelectMenuBuilder WithPlaceholder(string placeholder) + { + Placeholder = placeholder; + return this; + } + + /// + /// Sets the field minValues. + /// + /// The value to set the field minValues to. + /// + /// + /// The current builder. + /// + public SelectMenuBuilder WithMinValues(int minValues) + { + MinValues = minValues; + return this; + } + + /// + /// Sets the field maxValues. + /// + /// The value to set the field maxValues to. + /// + /// + /// The current builder. + /// + public SelectMenuBuilder WithMaxValues(int maxValues) + { + MaxValues = maxValues; + return this; + } + + /// + /// Sets the field options. + /// + /// The value to set the field options to. + /// + /// + /// The current builder. + /// + public SelectMenuBuilder WithOptions(List options) + { + Options = options; + return this; + } + + /// + /// Add one option to menu options. + /// + /// The option builder class containing the option properties. + /// Options count reached . + /// + /// The current builder. + /// + public SelectMenuBuilder AddOption(SelectMenuOptionBuilder option) + { + if (Options.Count >= MaxOptionCount) + throw new InvalidOperationException($"Options count reached {MaxOptionCount}."); + + Options.Add(option); + return this; + } + + /// + /// Add one option to menu options. + /// + /// The label for this option. + /// The value of this option. + /// The description of this option. + /// The emote of this option. + /// Render this option as selected by default or not. + /// Options count reached . + /// + /// The current builder. + /// + public SelectMenuBuilder AddOption(string label, string value, string description = null, IEmote emote = null, bool? isDefault = null) + { + AddOption(new SelectMenuOptionBuilder(label, value, description, emote, isDefault)); + return this; + } + + /// + /// Sets whether the current menu is disabled. + /// + /// Whether the current menu is disabled or not. + /// + /// The current builder. + /// + public SelectMenuBuilder WithDisabled(bool isDisabled) + { + IsDisabled = isDisabled; + return this; + } + + /// + /// Builds a + /// + /// The newly built + public SelectMenuComponent Build() + { + var options = Options?.Select(x => x.Build()).ToList(); + + return new SelectMenuComponent(CustomId, options, Placeholder, MinValues, MaxValues, IsDisabled); + } + } + + /// + /// Represents a class used to build 's. + /// + public class SelectMenuOptionBuilder + { + /// + /// The maximum length of a . + /// + public const int MaxSelectLabelLength = 100; + + /// + /// The maximum length of a . + /// + public const int MaxDescriptionLength = 100; + + /// + /// The maximum length of a . + /// + public const int MaxSelectValueLength = 100; + + /// + /// Gets or sets the label of the current select menu. + /// + /// length exceeds + /// length subceeds 1. + public string Label + { + get => _label; + set => _label = value?.Length switch + { + > MaxSelectLabelLength => throw new ArgumentOutOfRangeException(nameof(value), $"Label length must be less or equal to {MaxSelectLabelLength}."), + 0 => throw new ArgumentOutOfRangeException(nameof(value), "Label length must be at least 1."), + _ => value + }; + } + + /// + /// Gets or sets the value of the current select menu. + /// + /// length exceeds . + /// length subceeds 1. + public string Value + { + get => _value; + set => _value = value?.Length switch + { + > MaxSelectValueLength => throw new ArgumentOutOfRangeException(nameof(value), $"Value length must be less or equal to {MaxSelectValueLength}."), + 0 => throw new ArgumentOutOfRangeException(nameof(value), "Value length must be at least 1."), + _ => value + }; + } + + /// + /// Gets or sets this menu options description. + /// + /// length exceeds . + /// length subceeds 1. + public string Description + { + get => _description; + set => _description = value?.Length switch + { + > MaxDescriptionLength => throw new ArgumentOutOfRangeException(nameof(value), $"Description length must be less or equal to {MaxDescriptionLength}."), + 0 => throw new ArgumentOutOfRangeException(nameof(value), "Description length must be at least 1."), + _ => value + }; + } + + /// + /// Gets or sets the emote of this option. + /// + public IEmote Emote { get; set; } + + /// + /// Gets or sets the whether or not this option will render selected by default. + /// + public bool? IsDefault { get; set; } + + private string _label; + private string _value; + private string _description; + + /// + /// Creates a new instance of a . + /// + public SelectMenuOptionBuilder() { } + + /// + /// Creates a new instance of a . + /// + /// The label for this option. + /// The value of this option. + /// The description of this option. + /// The emote of this option. + /// Render this option as selected by default or not. + public SelectMenuOptionBuilder(string label, string value, string description = null, IEmote emote = null, bool? isDefault = null) + { + Label = label; + Value = value; + Description = description; + Emote = emote; + IsDefault = isDefault; + } + + /// + /// Creates a new instance of a from instance of a . + /// + public SelectMenuOptionBuilder(SelectMenuOption option) + { + Label = option.Label; + Value = option.Value; + Description = option.Description; + Emote = option.Emote; + IsDefault = option.IsDefault; + } + + /// + /// Sets the field label. + /// + /// The value to set the field label to. + /// + /// + /// The current builder. + /// + public SelectMenuOptionBuilder WithLabel(string label) + { + Label = label; + return this; + } + + /// + /// Sets the field value. + /// + /// The value to set the field value to. + /// + /// + /// The current builder. + /// + public SelectMenuOptionBuilder WithValue(string value) + { + Value = value; + return this; + } + + /// + /// Sets the field description. + /// + /// The value to set the field description to. + /// + /// + /// The current builder. + /// + public SelectMenuOptionBuilder WithDescription(string description) + { + Description = description; + return this; + } + + /// + /// Sets the field emote. + /// + /// The value to set the field emote to. + /// + /// The current builder. + /// + public SelectMenuOptionBuilder WithEmote(IEmote emote) + { + Emote = emote; + return this; + } + + /// + /// Sets the field default. + /// + /// The value to set the field default to. + /// + /// The current builder. + /// + public SelectMenuOptionBuilder WithDefault(bool isDefault) + { + IsDefault = isDefault; + return this; + } + + /// + /// Builds a . + /// + /// The newly built . + public SelectMenuOption Build() + { + return new SelectMenuOption(Label, Value, Description, Emote, IsDefault); + } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentType.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentType.cs new file mode 100644 index 000000000..70bc1f301 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentType.cs @@ -0,0 +1,23 @@ +namespace Discord +{ + /// + /// Represents a type of a component. + /// + public enum ComponentType + { + /// + /// A container for other components. + /// + ActionRow = 1, + + /// + /// A clickable button. + /// + Button = 2, + + /// + /// A select menu for picking from choices. + /// + SelectMenu = 3 + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/IComponentInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/IComponentInteraction.cs new file mode 100644 index 000000000..2a46e8f18 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/IComponentInteraction.cs @@ -0,0 +1,18 @@ +namespace Discord +{ + /// + /// Represents an interaction type for Message Components. + /// + public interface IComponentInteraction : IDiscordInteraction + { + /// + /// Gets the data received with this interaction, contains the button that was clicked. + /// + new IComponentInteractionData Data { get; } + + /// + /// Gets the message that contained the trigger for this interaction. + /// + IUserMessage Message { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/IComponentInteractionData.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/IComponentInteractionData.cs new file mode 100644 index 000000000..99b9b6f6c --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/IComponentInteractionData.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; + +namespace Discord +{ + /// + /// Represents the data sent with the . + /// + public interface IComponentInteractionData : IDiscordInteractionData + { + /// + /// Gets the components Custom Id that was clicked. + /// + string CustomId { get; } + + /// + /// Gets the type of the component clicked. + /// + ComponentType Type { get; } + + /// + /// Gets the value(s) of a interaction response. + /// + IReadOnlyCollection Values { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/IMessageComponent.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/IMessageComponent.cs new file mode 100644 index 000000000..9366a44d6 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/IMessageComponent.cs @@ -0,0 +1,18 @@ +namespace Discord +{ + /// + /// Represents a message component on a message. + /// + public interface IMessageComponent + { + /// + /// Gets the of this Message Component. + /// + ComponentType Type { get; } + + /// + /// Gets the custom id of the component if possible; otherwise . + /// + string CustomId { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/MessageComponent.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/MessageComponent.cs new file mode 100644 index 000000000..720588681 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/MessageComponent.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; + +namespace Discord +{ + /// + /// Represents a component object used to send components with messages. + /// + public class MessageComponent + { + /// + /// Gets the components to be used in a message. + /// + public IReadOnlyCollection Components { get; } + + internal MessageComponent(List components) + { + Components = components; + } + + /// + /// Returns a empty . + /// + internal static MessageComponent Empty + => new MessageComponent(new List()); + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/SelectMenuComponent.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/SelectMenuComponent.cs new file mode 100644 index 000000000..229c1e148 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/SelectMenuComponent.cs @@ -0,0 +1,67 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Discord +{ + /// + /// Represents a select menu component defined at + /// + public class SelectMenuComponent : IMessageComponent + { + /// + public ComponentType Type => ComponentType.SelectMenu; + + /// + public string CustomId { get; } + + /// + /// Gets the menus options to select from. + /// + public IReadOnlyCollection Options { get; } + + /// + /// Gets the custom placeholder text if nothing is selected. + /// + public string Placeholder { get; } + + /// + /// Gets the minimum number of items that must be chosen. + /// + public int MinValues { get; } + + /// + /// Gets the maximum number of items that can be chosen. + /// + public int MaxValues { get; } + + /// + /// Gets whether this menu is disabled or not. + /// + public bool IsDisabled { get; } + + /// + /// Turns this select menu into a builder. + /// + /// + /// A newly create builder with the same properties as this select menu. + /// + public SelectMenuBuilder ToBuilder() + => new SelectMenuBuilder( + CustomId, + Options.Select(x => new SelectMenuOptionBuilder(x.Label, x.Value, x.Description, x.Emote, x.IsDefault)).ToList(), + Placeholder, + MaxValues, + MinValues, + IsDisabled); + + internal SelectMenuComponent(string customId, List options, string placeholder, int minValues, int maxValues, bool disabled) + { + CustomId = customId; + Options = options; + Placeholder = placeholder; + MinValues = minValues; + MaxValues = maxValues; + IsDisabled = disabled; + } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/SelectMenuOption.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/SelectMenuOption.cs new file mode 100644 index 000000000..6856e1ee3 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/SelectMenuOption.cs @@ -0,0 +1,42 @@ +namespace Discord +{ + /// + /// Represents a choice for a . + /// + public class SelectMenuOption + { + /// + /// Gets the user-facing name of the option. + /// + public string Label { get; } + + /// + /// Gets the dev-define value of the option. + /// + public string Value { get; } + + /// + /// Gets a description of the option. + /// + public string Description { get; } + + /// + /// Gets the displayed with this menu option. + /// + public IEmote Emote { get; } + + /// + /// Gets whether or not this option will render as selected by default. + /// + public bool? IsDefault { get; } + + internal SelectMenuOption(string label, string value, string description, IEmote emote, bool? defaultValue) + { + Label = label; + Value = value; + Description = description; + Emote = emote; + IsDefault = defaultValue; + } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs new file mode 100644 index 000000000..bb5343d84 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteraction.cs @@ -0,0 +1,13 @@ +namespace Discord +{ + /// + /// Represents a . + /// + public interface IAutocompleteInteraction : IDiscordInteraction + { + /// + /// Gets the autocomplete data of this interaction. + /// + new IAutocompleteInteractionData Data { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteractionData.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteractionData.cs new file mode 100644 index 000000000..e6d1e9fae --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/IAutocompleteInteractionData.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; + +namespace Discord +{ + /// + /// Represents data for a slash commands autocomplete interaction. + /// + public interface IAutocompleteInteractionData : IDiscordInteractionData + { + /// + /// Gets the name of the invoked command. + /// + string CommandName { get; } + + /// + /// Gets the id of the invoked command. + /// + ulong CommandId { get; } + + /// + /// Gets the type of the invoked command. + /// + ApplicationCommandType Type { get; } + + /// + /// Gets the version of the invoked command. + /// + ulong Version { get; } + + /// + /// Gets the current autocomplete option that is actively being filled out. + /// + AutocompleteOption Current { get; } + + /// + /// Gets a collection of all the other options the executing users has filled out. + /// + IReadOnlyCollection Options { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/ISlashCommandInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/ISlashCommandInteraction.cs new file mode 100644 index 000000000..f28c35e40 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/ISlashCommandInteraction.cs @@ -0,0 +1,13 @@ +namespace Discord +{ + /// + /// Represents a slash command interaction. + /// + public interface ISlashCommandInteraction : IApplicationCommandInteraction + { + /// + /// Gets the data associated with this interaction. + /// + new IApplicationCommandInteractionData Data { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandBuilder.cs new file mode 100644 index 000000000..ccfb2da0a --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandBuilder.cs @@ -0,0 +1,643 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; + +namespace Discord +{ + /// + /// Represents a class used to build slash commands. + /// + public class SlashCommandBuilder + { + /// + /// Returns the maximum length a commands name allowed by Discord + /// + public const int MaxNameLength = 32; + /// + /// Returns the maximum length of a commands description allowed by Discord. + /// + public const int MaxDescriptionLength = 100; + /// + /// Returns the maximum count of command options allowed by Discord + /// + public const int MaxOptionsCount = 25; + + /// + /// Gets or sets the name of this slash command. + /// + public string Name + { + get => _name; + set + { + Preconditions.NotNullOrEmpty(value, nameof(value)); + Preconditions.AtLeast(value.Length, 1, nameof(value)); + Preconditions.AtMost(value.Length, MaxNameLength, nameof(value)); + + // Discord updated the docs, this regex prevents special characters like @!$%(... etc, + // https://discord.com/developers/docs/interactions/slash-commands#applicationcommand + if (!Regex.IsMatch(value, @"^[\w-]{1,32}$")) + throw new ArgumentException("Command name cannot contain any special characters or whitespaces!", nameof(value)); + + if (value.Any(x => char.IsUpper(x))) + throw new FormatException("Name cannot contain any uppercase characters."); + + _name = value; + } + } + + /// + /// Gets or sets a 1-100 length description of this slash command + /// + public string Description + { + get => _description; + set + { + Preconditions.NotNullOrEmpty(value, nameof(Description)); + Preconditions.AtLeast(value.Length, 1, nameof(Description)); + Preconditions.AtMost(value.Length, MaxDescriptionLength, nameof(Description)); + + _description = value; + } + } + + /// + /// Gets or sets the options for this command. + /// + public List Options + { + get => _options; + set + { + Preconditions.AtMost(value?.Count ?? 0, MaxOptionsCount, nameof(value)); + _options = value; + } + } + + /// + /// Gets or sets whether the command is enabled by default when the app is added to a guild + /// + public bool IsDefaultPermission { get; set; } = true; + + private string _name; + private string _description; + private List _options; + + /// + /// Build the current builder into a class. + /// + /// A that can be used to create slash commands. + public SlashCommandProperties Build() + { + var props = new SlashCommandProperties + { + Name = Name, + Description = Description, + IsDefaultPermission = IsDefaultPermission, + }; + + if (Options != null && Options.Any()) + { + var options = new List(); + + Options.OrderByDescending(x => x.IsRequired ?? false).ToList().ForEach(x => options.Add(x.Build())); + + props.Options = options; + } + + return props; + } + + /// + /// Sets the field name. + /// + /// The value to set the field name to. + /// + /// The current builder. + /// + public SlashCommandBuilder WithName(string name) + { + Name = name; + return this; + } + + /// + /// Sets the description of the current command. + /// + /// The description of this command. + /// The current builder. + public SlashCommandBuilder WithDescription(string description) + { + Description = description; + return this; + } + + /// + /// Sets the default permission of the current command. + /// + /// The default permission value to set. + /// The current builder. + public SlashCommandBuilder WithDefaultPermission(bool value) + { + IsDefaultPermission = value; + return this; + } + + /// + /// Adds an option to the current slash command. + /// + /// The name of the option to add. + /// The type of this option. + /// The description of this option. + /// If this option is required for this command. + /// If this option is the default option. + /// If this option is set to autocomplete. + /// The options of the option to add. + /// The allowed channel types for this option. + /// The choices of this option. + /// The smallest number value the user can input. + /// The largest number value the user can input. + /// The current builder. + public SlashCommandBuilder AddOption(string name, ApplicationCommandOptionType type, + string description, bool? isRequired = null, bool? isDefault = null, bool isAutocomplete = false, double? minValue = null, double? maxValue = null, + List options = null, List channelTypes = null, params ApplicationCommandOptionChoiceProperties[] choices) + { + // Make sure the name matches the requirements from discord + Preconditions.NotNullOrEmpty(name, nameof(name)); + Preconditions.AtLeast(name.Length, 1, nameof(name)); + Preconditions.AtMost(name.Length, MaxNameLength, nameof(name)); + + // Discord updated the docs, this regex prevents special characters like @!$%( and s p a c e s.. etc, + // https://discord.com/developers/docs/interactions/slash-commands#applicationcommand + if (!Regex.IsMatch(name, @"^[\w-]{1,32}$")) + throw new ArgumentException("Command name cannot contain any special characters or whitespaces!", nameof(name)); + + // same with description + Preconditions.NotNullOrEmpty(description, nameof(description)); + Preconditions.AtLeast(description.Length, 1, nameof(description)); + Preconditions.AtMost(description.Length, MaxDescriptionLength, nameof(description)); + + // make sure theres only one option with default set to true + if (isDefault == true && Options?.Any(x => x.IsDefault == true) == true) + throw new ArgumentException("There can only be one command option with default set to true!", nameof(isDefault)); + + var option = new SlashCommandOptionBuilder + { + Name = name, + Description = description, + IsRequired = isRequired, + IsDefault = isDefault, + Options = options, + Type = type, + IsAutocomplete = isAutocomplete, + Choices = (choices ?? Array.Empty()).ToList(), + ChannelTypes = channelTypes, + MinValue = minValue, + MaxValue = maxValue, + }; + + return AddOption(option); + } + + /// + /// Adds an option to this slash command. + /// + /// The option to add. + /// The current builder. + public SlashCommandBuilder AddOption(SlashCommandOptionBuilder option) + { + Options ??= new List(); + + if (Options.Count >= MaxOptionsCount) + throw new InvalidOperationException($"Cannot have more than {MaxOptionsCount} options!"); + + Preconditions.NotNull(option, nameof(option)); + + Options.Add(option); + return this; + } + /// + /// Adds a collection of options to the current slash command. + /// + /// The collection of options to add. + /// The current builder. + public SlashCommandBuilder AddOptions(params SlashCommandOptionBuilder[] options) + { + if (options == null) + throw new ArgumentNullException(nameof(options), "Options cannot be null!"); + + if (options.Length == 0) + throw new ArgumentException("Options cannot be empty!", nameof(options)); + + Options ??= new List(); + + if (Options.Count + options.Length > MaxOptionsCount) + throw new ArgumentOutOfRangeException(nameof(options), $"Cannot have more than {MaxOptionsCount} options!"); + + Options.AddRange(options); + return this; + } + } + + /// + /// Represents a class used to build options for the . + /// + public class SlashCommandOptionBuilder + { + /// + /// The max length of a choice's name allowed by Discord. + /// + public const int ChoiceNameMaxLength = 100; + + /// + /// The maximum number of choices allowed by Discord. + /// + public const int MaxChoiceCount = 25; + + private string _name; + private string _description; + + /// + /// Gets or sets the name of this option. + /// + public string Name + { + get => _name; + set + { + if (value != null) + { + Preconditions.AtLeast(value.Length, 1, nameof(value)); + Preconditions.AtMost(value.Length, SlashCommandBuilder.MaxNameLength, nameof(value)); + if (!Regex.IsMatch(value, @"^[\w-]{1,32}$")) + throw new ArgumentException("Option name cannot contain any special characters or whitespaces!", nameof(value)); + } + + _name = value; + } + } + + /// + /// Gets or sets the description of this option. + /// + public string Description + { + get => _description; + set + { + if (value != null) + { + Preconditions.AtLeast(value.Length, 1, nameof(value)); + Preconditions.AtMost(value.Length, SlashCommandBuilder.MaxDescriptionLength, nameof(value)); + } + + _description = value; + } + } + + /// + /// Gets or sets the type of this option. + /// + public ApplicationCommandOptionType Type { get; set; } + + /// + /// Gets or sets whether or not this options is the first required option for the user to complete. only one option can be default. + /// + public bool? IsDefault { get; set; } + + /// + /// Gets or sets if the option is required. + /// + public bool? IsRequired { get; set; } = null; + + /// + /// Gets or sets whether or not this option supports autocomplete. + /// + public bool IsAutocomplete { get; set; } + + /// + /// Gets or sets the smallest number value the user can input. + /// + public double? MinValue { get; set; } + + /// + /// Gets or sets the largest number value the user can input. + /// + public double? MaxValue { get; set; } + + /// + /// Gets or sets the choices for string and int types for the user to pick from. + /// + public List Choices { get; set; } + + /// + /// Gets or sets if this option is a subcommand or subcommand group type, these nested options will be the parameters. + /// + public List Options { get; set; } + + /// + /// Gets or sets the allowed channel types for this option. + /// + public List ChannelTypes { get; set; } + + /// + /// Builds the current option. + /// + /// The built version of this option. + public ApplicationCommandOptionProperties Build() + { + bool isSubType = Type == ApplicationCommandOptionType.SubCommandGroup; + bool isIntType = Type == ApplicationCommandOptionType.Integer; + + if (isSubType && (Options == null || !Options.Any())) + throw new InvalidOperationException("SubCommands/SubCommandGroups must have at least one option"); + + if (!isSubType && Options != null && Options.Any() && Type != ApplicationCommandOptionType.SubCommand) + throw new InvalidOperationException($"Cannot have options on {Type} type"); + + if (isIntType && MinValue != null && MinValue % 1 != 0) + throw new InvalidOperationException("MinValue cannot have decimals on Integer command options."); + + if (isIntType && MaxValue != null && MaxValue % 1 != 0) + throw new InvalidOperationException("MaxValue cannot have decimals on Integer command options."); + + return new ApplicationCommandOptionProperties + { + Name = Name, + Description = Description, + IsDefault = IsDefault, + IsRequired = IsRequired, + Type = Type, + Options = Options?.Count > 0 + ? Options.OrderByDescending(x => x.IsRequired ?? false).Select(x => x.Build()).ToList() + : new List(), + Choices = Choices, + IsAutocomplete = IsAutocomplete, + ChannelTypes = ChannelTypes, + MinValue = MinValue, + MaxValue = MaxValue + }; + } + + /// + /// Adds an option to the current slash command. + /// + /// The name of the option to add. + /// The type of this option. + /// The description of this option. + /// If this option is required for this command. + /// If this option is the default option. + /// If this option supports autocomplete. + /// The options of the option to add. + /// The allowed channel types for this option. + /// The choices of this option. + /// The smallest number value the user can input. + /// The largest number value the user can input. + /// The current builder. + public SlashCommandOptionBuilder AddOption(string name, ApplicationCommandOptionType type, + string description, bool? isRequired = null, bool isDefault = false, bool isAutocomplete = false, double? minValue = null, double? maxValue = null, + List options = null, List channelTypes = null, params ApplicationCommandOptionChoiceProperties[] choices) + { + // Make sure the name matches the requirements from discord + Preconditions.NotNullOrEmpty(name, nameof(name)); + Preconditions.AtLeast(name.Length, 1, nameof(name)); + Preconditions.AtMost(name.Length, SlashCommandBuilder.MaxNameLength, nameof(name)); + + // Discord updated the docs, this regex prevents special characters like @!$%( and s p a c e s.. etc, + // https://discord.com/developers/docs/interactions/slash-commands#applicationcommand + if (!Regex.IsMatch(name, @"^[\w-]{1,32}$")) + throw new ArgumentException("Command name cannot contain any special characters or whitespaces!", nameof(name)); + + // same with description + Preconditions.NotNullOrEmpty(description, nameof(description)); + Preconditions.AtLeast(description.Length, 1, nameof(description)); + Preconditions.AtMost(description.Length, SlashCommandBuilder.MaxDescriptionLength, nameof(description)); + + // make sure theres only one option with default set to true + if (isDefault && Options?.Any(x => x.IsDefault == true) == true) + throw new ArgumentException("There can only be one command option with default set to true!", nameof(isDefault)); + + var option = new SlashCommandOptionBuilder + { + Name = name, + Description = description, + IsRequired = isRequired, + IsDefault = isDefault, + IsAutocomplete = isAutocomplete, + MinValue = minValue, + MaxValue = maxValue, + Options = options, + Type = type, + Choices = (choices ?? Array.Empty()).ToList(), + ChannelTypes = channelTypes + }; + + return AddOption(option); + } + /// + /// Adds a sub option to the current option. + /// + /// The sub option to add. + /// The current builder. + public SlashCommandOptionBuilder AddOption(SlashCommandOptionBuilder option) + { + Options ??= new List(); + + if (Options.Count >= SlashCommandBuilder.MaxOptionsCount) + throw new InvalidOperationException($"There can only be {SlashCommandBuilder.MaxOptionsCount} options per sub command group!"); + + Preconditions.NotNull(option, nameof(option)); + + Options.Add(option); + return this; + } + + /// + /// Adds a choice to the current option. + /// + /// The name of the choice. + /// The value of the choice. + /// The current builder. + public SlashCommandOptionBuilder AddChoice(string name, int value) + { + return AddChoiceInternal(name, value); + } + + /// + /// Adds a choice to the current option. + /// + /// The name of the choice. + /// The value of the choice. + /// The current builder. + public SlashCommandOptionBuilder AddChoice(string name, string value) + { + return AddChoiceInternal(name, value); + } + + /// + /// Adds a choice to the current option. + /// + /// The name of the choice. + /// The value of the choice. + /// The current builder. + public SlashCommandOptionBuilder AddChoice(string name, double value) + { + return AddChoiceInternal(name, value); + } + + /// + /// Adds a choice to the current option. + /// + /// The name of the choice. + /// The value of the choice. + /// The current builder. + public SlashCommandOptionBuilder AddChoice(string name, float value) + { + return AddChoiceInternal(name, value); + } + + /// + /// Adds a choice to the current option. + /// + /// The name of the choice. + /// The value of the choice. + /// The current builder. + public SlashCommandOptionBuilder AddChoice(string name, long value) + { + return AddChoiceInternal(name, value); + } + + private SlashCommandOptionBuilder AddChoiceInternal(string name, object value) + { + Choices ??= new List(); + + if (Choices.Count >= MaxChoiceCount) + throw new InvalidOperationException($"Cannot add more than {MaxChoiceCount} choices!"); + + Preconditions.NotNull(name, nameof(name)); + Preconditions.NotNull(value, nameof(value)); + + Preconditions.AtLeast(name.Length, 1, nameof(name)); + Preconditions.AtMost(name.Length, 100, nameof(name)); + + if(value is string str) + { + Preconditions.AtLeast(str.Length, 1, nameof(value)); + Preconditions.AtMost(str.Length, 100, nameof(value)); + } + + Choices.Add(new ApplicationCommandOptionChoiceProperties + { + Name = name, + Value = value + }); + + return this; + } + + /// + /// Adds a channel type to the current option. + /// + /// The to add. + /// The current builder. + public SlashCommandOptionBuilder AddChannelType(ChannelType channelType) + { + ChannelTypes ??= new List(); + + ChannelTypes.Add(channelType); + + return this; + } + + /// + /// Sets the current builders name. + /// + /// The name to set the current option builder. + /// The current builder. + public SlashCommandOptionBuilder WithName(string name) + { + Name = name; + + return this; + } + + /// + /// Sets the current builders description. + /// + /// The description to set. + /// The current builder. + public SlashCommandOptionBuilder WithDescription(string description) + { + Description = description; + return this; + } + + /// + /// Sets the current builders required field. + /// + /// The value to set. + /// The current builder. + public SlashCommandOptionBuilder WithRequired(bool value) + { + IsRequired = value; + return this; + } + + /// + /// Sets the current builders default field. + /// + /// The value to set. + /// The current builder. + public SlashCommandOptionBuilder WithDefault(bool value) + { + IsDefault = value; + return this; + } + + /// + /// Sets the current builders autocomplete field. + /// + /// The value to set. + /// The current builder. + public SlashCommandOptionBuilder WithAutocomplete(bool value) + { + IsAutocomplete = value; + return this; + } + + /// + /// Sets the current builders min value field. + /// + /// The value to set. + /// The current builder. + public SlashCommandOptionBuilder WithMinValue(double value) + { + MinValue = value; + return this; + } + + /// + /// Sets the current builders max value field. + /// + /// The value to set. + /// The current builder. + public SlashCommandOptionBuilder WithMaxValue(double value) + { + MaxValue = value; + return this; + } + + /// + /// Sets the current type of this builder. + /// + /// The type to set. + /// The current builder. + public SlashCommandOptionBuilder WithType(ApplicationCommandOptionType type) + { + Type = type; + return this; + } + } +} diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandProperties.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandProperties.cs new file mode 100644 index 000000000..20ba2868f --- /dev/null +++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandProperties.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; + +namespace Discord +{ + /// + /// Represents a class used to create slash commands. + /// + public class SlashCommandProperties : ApplicationCommandProperties + { + internal override ApplicationCommandType Type => ApplicationCommandType.Slash; + + /// + /// Gets or sets the discription of this command. + /// + public Optional Description { get; set; } + + /// + /// Gets or sets the options for this command. + /// + public Optional> Options { get; set; } + + internal SlashCommandProperties() { } + } +} diff --git a/src/Discord.Net.Core/Entities/Invites/IInvite.cs b/src/Discord.Net.Core/Entities/Invites/IInvite.cs index 993f1f047..47ffffacb 100644 --- a/src/Discord.Net.Core/Entities/Invites/IInvite.cs +++ b/src/Discord.Net.Core/Entities/Invites/IInvite.cs @@ -20,6 +20,13 @@ namespace Discord /// string Url { get; } + /// + /// Gets the user that created this invite. + /// + /// + /// A user that created this invite. + /// + IUser Inviter { get; } /// /// Gets the channel this invite is linked to. /// @@ -83,5 +90,19 @@ namespace Discord /// invite points to; null if one cannot be obtained. /// int? MemberCount { get; } + /// + /// Gets the user this invite is linked to via . + /// + /// + /// A user that is linked to this invite. + /// + IUser TargetUser { get; } + /// + /// Gets the type of the linked for this invite. + /// + /// + /// The type of the linked user that is linked to this invite. + /// + TargetUserType TargetUserType { get; } } } diff --git a/src/Discord.Net.Core/Entities/Invites/IInviteMetadata.cs b/src/Discord.Net.Core/Entities/Invites/IInviteMetadata.cs index 471dc377f..c2580c853 100644 --- a/src/Discord.Net.Core/Entities/Invites/IInviteMetadata.cs +++ b/src/Discord.Net.Core/Entities/Invites/IInviteMetadata.cs @@ -7,20 +7,6 @@ namespace Discord /// public interface IInviteMetadata : IInvite { - /// - /// Gets the user that created this invite. - /// - /// - /// A user that created this invite. - /// - IUser Inviter { get; } - /// - /// Gets a value that indicates whether the invite has been revoked. - /// - /// - /// true if this invite was revoked; otherwise false. - /// - bool IsRevoked { get; } /// /// Gets a value that indicates whether the invite is a temporary one. /// diff --git a/src/Discord.Net.Core/Entities/Invites/TargetUserType.cs b/src/Discord.Net.Core/Entities/Invites/TargetUserType.cs new file mode 100644 index 000000000..e1818d7a9 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Invites/TargetUserType.cs @@ -0,0 +1,18 @@ +namespace Discord +{ + public enum TargetUserType + { + /// + /// The invite whose target user type is not defined. + /// + Undefined = 0, + /// + /// The invite is for a Go Live stream. + /// + Stream = 1, + /// + /// The invite is for embedded application. + /// + EmbeddedApplication = 2 + } +} diff --git a/src/Discord.Net.Core/Entities/Messages/AllowedMentionTypes.cs b/src/Discord.Net.Core/Entities/Messages/AllowedMentionTypes.cs index 3ce6531b7..ecd872d83 100644 --- a/src/Discord.Net.Core/Entities/Messages/AllowedMentionTypes.cs +++ b/src/Discord.Net.Core/Entities/Messages/AllowedMentionTypes.cs @@ -8,17 +8,27 @@ namespace Discord [Flags] public enum AllowedMentionTypes { + /// + /// No flag is set. + /// + /// + /// This flag is not used to control mentions. + /// + /// It will always be present and does not mean mentions will not be allowed. + /// + /// + None = 0, /// /// Controls role mentions. /// - Roles, + Roles = 1, /// /// Controls user mentions. /// - Users, + Users = 2, /// /// Controls @everyone and @here mentions. /// - Everyone, + Everyone = 4, } } diff --git a/src/Discord.Net.Core/Entities/Messages/AllowedMentions.cs b/src/Discord.Net.Core/Entities/Messages/AllowedMentions.cs index 9b168bbd0..0206ad7b1 100644 --- a/src/Discord.Net.Core/Entities/Messages/AllowedMentions.cs +++ b/src/Discord.Net.Core/Entities/Messages/AllowedMentions.cs @@ -39,7 +39,7 @@ namespace Discord /// flag of the property. If the flag is set, the value of this property /// must be null or empty. /// - public List RoleIds { get; set; } + public List RoleIds { get; set; } = new List(); /// /// Gets or sets the list of all user ids that will be mentioned. @@ -47,7 +47,15 @@ namespace Discord /// flag of the property. If the flag is set, the value of this property /// must be null or empty. /// - public List UserIds { get; set; } + public List UserIds { get; set; } = new List(); + + /// + /// Gets or sets whether to mention the author of the message you are replying to or not. + /// + /// + /// Specifically for inline replies. + /// + public bool? MentionRepliedUser { get; set; } = null; /// /// Initializes a new instance of the class. diff --git a/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs b/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs index 555fd95df..0304120f5 100644 --- a/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs +++ b/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; +using Discord.Utils; namespace Discord { @@ -12,25 +13,24 @@ namespace Discord { private string _title; private string _description; - private string _url; private EmbedImage? _image; private EmbedThumbnail? _thumbnail; private List _fields; - /// - /// Returns the maximum number of fields allowed by Discord. + /// + /// Returns the maximum number of fields allowed by Discord. /// public const int MaxFieldCount = 25; - /// - /// Returns the maximum length of title allowed by Discord. + /// + /// Returns the maximum length of title allowed by Discord. /// public const int MaxTitleLength = 256; - /// - /// Returns the maximum length of description allowed by Discord. + /// + /// Returns the maximum length of description allowed by Discord. /// - public const int MaxDescriptionLength = 2048; - /// - /// Returns the maximum length of total characters allowed by Discord. + public const int MaxDescriptionLength = 4096; + /// + /// Returns the maximum length of total characters allowed by Discord. /// public const int MaxEmbedLength = 6000; @@ -70,26 +70,14 @@ namespace Discord /// Gets or sets the URL of an . /// Url is not a well-formed . /// The URL of the embed. - public string Url - { - get => _url; - set - { - if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI.", paramName: nameof(Url)); - _url = value; - } - } + public string Url { get; set; } /// Gets or sets the thumbnail URL of an . /// Url is not a well-formed . /// The thumbnail URL of the embed. public string ThumbnailUrl { get => _thumbnail?.Url; - set - { - if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI.", paramName: nameof(ThumbnailUrl)); - _thumbnail = new EmbedThumbnail(value, null, null, null); - } + set => _thumbnail = new EmbedThumbnail(value, null, null, null); } /// Gets or sets the image URL of an . /// Url is not a well-formed . @@ -97,17 +85,13 @@ namespace Discord public string ImageUrl { get => _image?.Url; - set - { - if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI.", paramName: nameof(ImageUrl)); - _image = new EmbedImage(value, null, null, null); - } + set => _image = new EmbedImage(value, null, null, null); } /// Gets or sets the list of of an . - /// An embed builder's fields collection is set to + /// An embed builder's fields collection is set to /// null. - /// Description length exceeds . + /// Fields count exceeds . /// /// The list of existing . public List Fields @@ -154,7 +138,7 @@ namespace Discord /// Gets the total length of all embed properties. /// /// - /// The combined length of , , , + /// The combined length of , , , /// , , and . /// public int Length @@ -183,7 +167,7 @@ namespace Discord Title = title; return this; } - /// + /// /// Sets the description of an . /// /// The description to be set. @@ -195,7 +179,7 @@ namespace Discord Description = description; return this; } - /// + /// /// Sets the URL of an . /// /// The URL to be set. @@ -207,7 +191,7 @@ namespace Discord Url = url; return this; } - /// + /// /// Sets the thumbnail URL of an . /// /// The thumbnail URL to be set. @@ -418,11 +402,29 @@ namespace Discord /// The built embed object. /// /// Total embed length exceeds . + /// Any Url must include its protocols (i.e http:// or https://). public Embed Build() { if (Length > MaxEmbedLength) throw new InvalidOperationException($"Total embed length must be less than or equal to {MaxEmbedLength}."); - + if (!string.IsNullOrEmpty(Url)) + UrlValidation.Validate(Url, true); + if (!string.IsNullOrEmpty(ThumbnailUrl)) + UrlValidation.Validate(ThumbnailUrl, true); + if (!string.IsNullOrEmpty(ImageUrl)) + UrlValidation.Validate(ImageUrl, true); + if (Author != null) + { + if (!string.IsNullOrEmpty(Author.Url)) + UrlValidation.Validate(Author.Url, true); + if (!string.IsNullOrEmpty(Author.IconUrl)) + UrlValidation.Validate(Author.IconUrl, true); + } + if(Footer != null) + { + if (!string.IsNullOrEmpty(Footer.IconUrl)) + UrlValidation.Validate(Footer.IconUrl, true); + } var fields = ImmutableArray.CreateBuilder(Fields.Count); for (int i = 0; i < Fields.Count; i++) fields.Add(Fields[i].Build()); @@ -553,8 +555,6 @@ namespace Discord public class EmbedAuthorBuilder { private string _name; - private string _url; - private string _iconUrl; /// /// Gets the maximum author name length allowed by Discord. /// @@ -585,15 +585,7 @@ namespace Discord /// /// The URL of the author field. /// - public string Url - { - get => _url; - set - { - if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI.", paramName: nameof(Url)); - _url = value; - } - } + public string Url { get; set; } /// /// Gets or sets the icon URL of the author field. /// @@ -601,15 +593,7 @@ namespace Discord /// /// The icon URL of the author field. /// - public string IconUrl - { - get => _iconUrl; - set - { - if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI.", paramName: nameof(IconUrl)); - _iconUrl = value; - } - } + public string IconUrl { get; set; } /// /// Sets the name of the author field. @@ -671,7 +655,6 @@ namespace Discord public class EmbedFooterBuilder { private string _text; - private string _iconUrl; /// /// Gets the maximum footer length allowed by Discord. @@ -703,15 +686,7 @@ namespace Discord /// /// The icon URL of the footer field. /// - public string IconUrl - { - get => _iconUrl; - set - { - if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI.", paramName: nameof(IconUrl)); - _iconUrl = value; - } - } + public string IconUrl { get; set; } /// /// Sets the name of the footer field. diff --git a/src/Discord.Net.Core/Entities/Messages/FileAttachment.cs b/src/Discord.Net.Core/Entities/Messages/FileAttachment.cs new file mode 100644 index 000000000..582f5c2e7 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Messages/FileAttachment.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + public struct FileAttachment : IDisposable + { + public string FileName { get; set; } + public string Description { get; set; } + public bool IsSpoiler { get; set; } + +#pragma warning disable IDISP008 + public Stream Stream { get; } +#pragma warning restore IDISP008 + + private bool _isDisposed; + + /// + /// Creates a file attachment from a stream. + /// + /// The stream to create the attachment from. + /// The name of the attachment. + /// The description of the attachment. + /// Whether or not the attachment is a spoiler. + public FileAttachment(Stream stream, string fileName, string description = null, bool isSpoiler = false) + { + _isDisposed = false; + FileName = fileName; + Description = description; + Stream = stream; + IsSpoiler = isSpoiler; + } + + /// + /// Create the file attachment from a file path. + /// + /// + /// This file path is NOT validated and is passed directly into a + /// . + /// + /// The path to the file. + /// The name of the attachment. + /// The description of the attachment. + /// Whether or not the attachment is a spoiler. + /// + /// is a zero-length string, contains only white space, or contains one or more invalid + /// characters as defined by . + /// + /// is null. + /// + /// The specified path, file name, or both exceed the system-defined maximum length. For example, on + /// Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 + /// characters. + /// + /// is in an invalid format. + /// + /// The specified is invalid, (for example, it is on an unmapped drive). + /// + /// + /// specified a directory.-or- The caller does not have the required permission. + /// + /// The file specified in was not found. + /// + /// An I/O error occurred while opening the file. + public FileAttachment(string path, string fileName = null, string description = null, bool isSpoiler = false) + { + _isDisposed = false; + Stream = File.OpenRead(path); + FileName = fileName ?? Path.GetFileName(path); + Description = description; + IsSpoiler = isSpoiler; + } + + public void Dispose() + { + if (!_isDisposed) + { + Stream?.Dispose(); + _isDisposed = true; + } + } + } +} diff --git a/src/Discord.Net.Core/Entities/Messages/IAttachment.cs b/src/Discord.Net.Core/Entities/Messages/IAttachment.cs index 655777998..e94e9f97c 100644 --- a/src/Discord.Net.Core/Entities/Messages/IAttachment.cs +++ b/src/Discord.Net.Core/Entities/Messages/IAttachment.cs @@ -55,5 +55,12 @@ namespace Discord /// The width of this attachment if it is a picture; otherwise null. /// int? Width { get; } + /// + /// Gets whether or not this attachment is ephemeral. + /// + /// + /// if the attachment is ephemeral; otherwise . + /// + bool Ephemeral { get; } } } diff --git a/src/Discord.Net.Core/Entities/Messages/IMessage.cs b/src/Discord.Net.Core/Entities/Messages/IMessage.cs index aac526831..f5f2ca007 100644 --- a/src/Discord.Net.Core/Entities/Messages/IMessage.cs +++ b/src/Discord.Net.Core/Entities/Messages/IMessage.cs @@ -10,7 +10,7 @@ namespace Discord public interface IMessage : ISnowflakeEntity, IDeletable { /// - /// Gets the type of this system message. + /// Gets the type of this message. /// MessageType Type { get; } /// @@ -39,6 +39,13 @@ namespace Discord /// bool IsSuppressed { get; } /// + /// Gets the value that indicates whether this message mentioned everyone. + /// + /// + /// true if this message mentioned everyone; otherwise false. + /// + bool MentionedEveryone { get; } + /// /// Gets the content for this message. /// /// @@ -46,6 +53,13 @@ namespace Discord /// string Content { get; } /// + /// Gets the clean content for this message. + /// + /// + /// A string that contains the body of the message stripped of mentions, markdown, emojis and pings; note that this field may be empty if there is an embed. + /// + string CleanContent { get; } + /// /// Gets the time this message was sent. /// /// @@ -85,10 +99,10 @@ namespace Discord /// Gets all embeds included in this message. /// /// - /// /// This property gets a read-only collection of embeds associated with this message. Depending on the /// message, a sent message may contain one or more embeds. This is usually true when multiple link previews /// are generated; however, only one can be featured. + /// /// /// A read-only collection of embed objects. /// @@ -141,11 +155,11 @@ namespace Discord MessageApplication Application { get; } /// - /// Gets the reference to the original message if it was crossposted. + /// Gets the reference to the original message if it is a crosspost, channel follow add, pin, or reply message. /// /// - /// Sent with Cross-posted messages, meaning they were published from news channels - /// and received by subscriber channels. + /// Sent with cross-posted messages, meaning they were published from news channels + /// and received by subscriber channels, channel follow adds, pins, and message replies. /// /// /// A message's reference, if any is associated. @@ -157,6 +171,38 @@ namespace Discord /// IReadOnlyDictionary Reactions { get; } + /// + /// The 's attached to this message + /// + IReadOnlyCollection Components { get; } + + /// + /// Gets all stickers items included in this message. + /// + /// + /// A read-only collection of sticker item objects. + /// + IReadOnlyCollection Stickers { get; } + + /// + /// Gets the flags related to this message. + /// + /// + /// This value is determined by bitwise OR-ing values together. + /// + /// + /// A message's flags, if any is associated. + /// + MessageFlags? Flags { get; } + + /// + /// Gets the interaction this message is a response to. + /// + /// + /// A if the message is a response to an interaction; otherwise . + /// + IMessageInteraction Interaction { get; } + /// /// Adds a reaction to this message. /// @@ -215,6 +261,15 @@ namespace Discord /// A task that represents the asynchronous removal operation. /// Task RemoveAllReactionsAsync(RequestOptions options = null); + /// + /// Removes all reactions with a specific emoji from this message. + /// + /// The emoji used to react to this message. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous removal operation. + /// + Task RemoveAllReactionsForEmoteAsync(IEmote emote, RequestOptions options = null); /// /// Gets all users that reacted to a message with a given emote. diff --git a/src/Discord.Net.Core/Entities/Messages/IMessageInteraction.cs b/src/Discord.Net.Core/Entities/Messages/IMessageInteraction.cs new file mode 100644 index 000000000..ebd03b627 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Messages/IMessageInteraction.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents a partial within a message. + /// + public interface IMessageInteraction + { + /// + /// Gets the snowflake id of the interaction. + /// + ulong Id { get; } + + /// + /// Gets the type of the interaction. + /// + InteractionType Type { get; } + + /// + /// Gets the name of the application command used. + /// + string Name { get; } + + /// + /// Gets the who invoked the interaction. + /// + IUser User { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Messages/IUserMessage.cs b/src/Discord.Net.Core/Entities/Messages/IUserMessage.cs index e2fb25aae..c2d0e13bc 100644 --- a/src/Discord.Net.Core/Entities/Messages/IUserMessage.cs +++ b/src/Discord.Net.Core/Entities/Messages/IUserMessage.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Threading.Tasks; namespace Discord @@ -9,6 +8,14 @@ namespace Discord /// public interface IUserMessage : IMessage { + /// + /// Gets the referenced message if it is a crosspost, channel follow add, pin, or reply message. + /// + /// + /// The referenced message, if any is associated and still exists. + /// + IUserMessage ReferencedMessage { get; } + /// /// Modifies this message. /// @@ -29,18 +36,6 @@ namespace Discord /// Task ModifyAsync(Action func, RequestOptions options = null); /// - /// Modifies the suppression of this message. - /// - /// - /// This method modifies whether or not embeds in this message are suppressed (hidden). - /// - /// Whether or not embeds in this message should be suppressed. - /// The options to be used when sending the request. - /// - /// A task that represents the asynchronous modification operation. - /// - Task ModifySuppressionAsync(bool suppressEmbeds, RequestOptions options = null); - /// /// Adds this message to its channel's pinned messages. /// /// The options to be used when sending the request. diff --git a/src/Discord.Net.Core/Entities/Messages/MessageFlags.cs b/src/Discord.Net.Core/Entities/Messages/MessageFlags.cs new file mode 100644 index 000000000..6f9450372 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Messages/MessageFlags.cs @@ -0,0 +1,48 @@ +using System; + +namespace Discord +{ + [Flags] + public enum MessageFlags + { + /// + /// Default value for flags, when none are given to a message. + /// + None = 0, + /// + /// Flag given to messages that have been published to subscribed + /// channels (via Channel Following). + /// + Crossposted = 1 << 0, + /// + /// Flag given to messages that originated from a message in another + /// channel (via Channel Following). + /// + IsCrosspost = 1 << 1, + /// + /// Flag given to messages that do not display any embeds. + /// + SuppressEmbeds = 1 << 2, + /// + /// Flag given to messages that the source message for this crosspost + /// has been deleted (via Channel Following). + /// + SourceMessageDeleted = 1 << 3, + /// + /// Flag given to messages that came from the urgent message system. + /// + Urgent = 1 << 4, + /// + /// Flag given to messages has an associated thread, with the same id as the message + /// + HasThread = 1 << 5, + /// + /// Flag given to messages that is only visible to the user who invoked the Interaction. + /// + Ephemeral = 1 << 6, + /// + /// Flag given to messages that is an Interaction Response and the bot is "thinking" + /// + Loading = 1 << 7 + } +} diff --git a/src/Discord.Net.Core/Entities/Messages/MessageInteraction.cs b/src/Discord.Net.Core/Entities/Messages/MessageInteraction.cs new file mode 100644 index 000000000..cbbebd932 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Messages/MessageInteraction.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents a partial within a message. + /// + /// The type of the user. + public class MessageInteraction : IMessageInteraction where TUser : IUser + { + /// + /// Gets the snowflake id of the interaction. + /// + public ulong Id { get; } + + /// + /// Gets the type of the interaction. + /// + public InteractionType Type { get; } + + /// + /// Gets the name of the application command used. + /// + public string Name { get; } + + /// + /// Gets the who invoked the interaction. + /// + public TUser User { get; } + + internal MessageInteraction(ulong id, InteractionType type, string name, TUser user) + { + Id = id; + Type = type; + Name = name; + User = user; + } + + IUser IMessageInteraction.User => User; + } +} diff --git a/src/Discord.Net.Core/Entities/Messages/MessageProperties.cs b/src/Discord.Net.Core/Entities/Messages/MessageProperties.cs index b632d6a18..1a4eaff2d 100644 --- a/src/Discord.Net.Core/Entities/Messages/MessageProperties.cs +++ b/src/Discord.Net.Core/Entities/Messages/MessageProperties.cs @@ -1,10 +1,12 @@ +using System.Collections.Generic; + namespace Discord { /// /// Properties that are used to modify an with the specified changes. /// /// - /// The content of a message can be cleared with if and only if an + /// The content of a message can be cleared with if and only if an /// is present. /// /// @@ -17,9 +19,41 @@ namespace Discord /// This must be less than the constant defined by . /// public Optional Content { get; set; } + /// - /// Gets or sets the embed the message should display. + /// Gets or sets a single embed for this message. /// + /// + /// This property will be added to the array, in the future please use the array rather than this property. + /// public Optional Embed { get; set; } + + /// + /// Gets or sets the embeds of the message. + /// + public Optional Embeds { get; set; } + + /// + /// Gets or sets the components for this message. + /// + public Optional Components { get; set; } + + /// + /// Gets or sets the flags of the message. + /// + /// + /// Only can be set/unset and you need to be + /// the author of the message. + /// + public Optional Flags { get; set; } + /// + /// Gets or sets the allowed mentions of the message. + /// + public Optional AllowedMentions { get; set; } + + /// + /// Gets or sets the attachments for the message. + /// + public Optional> Attachments { get; set; } } } diff --git a/src/Discord.Net.Core/Entities/Messages/MessageReference.cs b/src/Discord.Net.Core/Entities/Messages/MessageReference.cs index 57a508a7c..029910e56 100644 --- a/src/Discord.Net.Core/Entities/Messages/MessageReference.cs +++ b/src/Discord.Net.Core/Entities/Messages/MessageReference.cs @@ -3,7 +3,7 @@ using System.Diagnostics; namespace Discord { /// - /// Contains the IDs sent from a crossposted message. + /// Contains the IDs sent from a crossposted message or inline reply. /// [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class MessageReference @@ -16,13 +16,36 @@ namespace Discord /// /// Gets the Channel ID of the original message. /// - public ulong ChannelId { get; internal set; } + /// + /// It only will be the default value (zero) if it was instantiated with a in the constructor. + /// + public ulong ChannelId { get => InternalChannelId.GetValueOrDefault(); } + internal Optional InternalChannelId; /// /// Gets the Guild ID of the original message. /// public Optional GuildId { get; internal set; } + /// + /// Initializes a new instance of the class. + /// + /// + /// The ID of the message that will be referenced. Used to reply to specific messages and the only parameter required for it. + /// + /// + /// The ID of the channel that will be referenced. It will be validated if sent. + /// + /// + /// The ID of the guild that will be referenced. It will be validated if sent. + /// + public MessageReference(ulong? messageId = null, ulong? channelId = null, ulong? guildId = null) + { + MessageId = messageId ?? Optional.Create(); + InternalChannelId = channelId ?? Optional.Create(); + GuildId = guildId ?? Optional.Create(); + } + private string DebuggerDisplay => $"Channel ID: ({ChannelId}){(GuildId.IsSpecified ? $", Guild ID: ({GuildId.Value})" : "")}" + $"{(MessageId.IsSpecified ? $", Message ID: ({MessageId.Value})" : "")}"; diff --git a/src/Discord.Net.Core/Entities/Messages/MessageType.cs b/src/Discord.Net.Core/Entities/Messages/MessageType.cs index ee5f4fb4d..b83f88434 100644 --- a/src/Discord.Net.Core/Entities/Messages/MessageType.cs +++ b/src/Discord.Net.Core/Entities/Messages/MessageType.cs @@ -57,5 +57,54 @@ namespace Discord /// The message for when a news channel subscription is added to a text channel. /// ChannelFollowAdd = 12, + /// + /// The message for when a guild is disqualified from discovery. + /// + GuildDiscoveryDisqualified = 14, + /// + /// The message for when a guild is requalified for discovery. + /// + GuildDiscoveryRequalified = 15, + /// + /// The message for when the initial warning is sent for the initial grace period discovery. + /// + GuildDiscoveryGracePeriodInitialWarning = 16, + /// + /// The message for when the final warning is sent for the initial grace period discovery. + /// + GuildDiscoveryGracePeriodFinalWarning = 17, + /// + /// The message for when a thread is created. + /// + ThreadCreated = 18, + /// + /// The message is an inline reply. + /// + /// + /// Only available in API v8. + /// + Reply = 19, + /// + /// The message is an Application Command. + /// + /// + /// Only available in API v8. + /// + ApplicationCommand = 20, + /// + /// The message that starts a thread. + /// + /// + /// Only available in API v9. + /// + ThreadStarterMessage = 21, + /// + /// The message for a invite reminder. + /// + GuildInviteReminder = 22, + /// + /// The message for a context menu command. + /// + ContextMenuCommand = 23, } } diff --git a/src/Discord.Net.Core/Entities/Messages/StickerFormatType.cs b/src/Discord.Net.Core/Entities/Messages/StickerFormatType.cs new file mode 100644 index 000000000..82e6b15a4 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Messages/StickerFormatType.cs @@ -0,0 +1,25 @@ +namespace Discord +{ + /// + /// Defines the types of formats for stickers. + /// + public enum StickerFormatType + { + /// + /// Default value for a sticker format type. + /// + None = 0, + /// + /// The sticker format type is png. + /// + Png = 1, + /// + /// The sticker format type is apng. + /// + Apng = 2, + /// + /// The sticker format type is lottie. + /// + Lottie = 3 + } +} diff --git a/src/Discord.Net.Core/Entities/Messages/TimestampTag.cs b/src/Discord.Net.Core/Entities/Messages/TimestampTag.cs new file mode 100644 index 000000000..347b0daaa --- /dev/null +++ b/src/Discord.Net.Core/Entities/Messages/TimestampTag.cs @@ -0,0 +1,47 @@ +using System; + +namespace Discord +{ + /// + /// Represents a class used to make timestamps in messages. see . + /// + public class TimestampTag + { + /// + /// Gets or sets the style of the timestamp tag. + /// + public TimestampTagStyles Style { get; set; } = TimestampTagStyles.ShortDateTime; + + /// + /// Gets or sets the time for this timestamp tag. + /// + public DateTime Time { get; set; } + + /// + /// Converts the current timestamp tag to the string representation supported by discord. + /// + /// If the is null then the default 0 will be used. + /// + /// + /// A string that is compatible in a discord message, ex: <t:1625944201:f> + public override string ToString() + { + return $""; + } + + /// + /// Creates a new timestamp tag with the specified datetime object. + /// + /// The time of this timestamp tag. + /// The style for this timestamp tag. + /// The newly create timestamp tag. + public static TimestampTag FromDateTime(DateTime time, TimestampTagStyles style = TimestampTagStyles.ShortDateTime) + { + return new TimestampTag + { + Style = style, + Time = time + }; + } + } +} diff --git a/src/Discord.Net.Core/Entities/Messages/TimestampTagStyle.cs b/src/Discord.Net.Core/Entities/Messages/TimestampTagStyle.cs new file mode 100644 index 000000000..89f3c79b5 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Messages/TimestampTagStyle.cs @@ -0,0 +1,43 @@ +namespace Discord +{ + /// + /// Represents a set of styles to use with a + /// + public enum TimestampTagStyles + { + /// + /// A short time string: 16:20 + /// + ShortTime = 116, + + /// + /// A long time string: 16:20:30 + /// + LongTime = 84, + + /// + /// A short date string: 20/04/2021 + /// + ShortDate = 100, + + /// + /// A long date string: 20 April 2021 + /// + LongDate = 68, + + /// + /// A short datetime string: 20 April 2021 16:20 + /// + ShortDateTime = 102, + + /// + /// A long datetime string: Tuesday, 20 April 2021 16:20 + /// + LongDateTime = 70, + + /// + /// The relative time to the user: 2 months ago + /// + Relative = 82 + } +} diff --git a/src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissionTarget.cs b/src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissionTarget.cs new file mode 100644 index 000000000..9a99b34f1 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissionTarget.cs @@ -0,0 +1,17 @@ +namespace Discord +{ + /// + /// Specifies the target of the permission. + /// + public enum ApplicationCommandPermissionTarget + { + /// + /// The target of the permission is a role. + /// + Role = 1, + /// + /// The target of the permission is a user. + /// + User = 2 + } +} diff --git a/src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissions.cs b/src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissions.cs new file mode 100644 index 000000000..28a6455e2 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissions.cs @@ -0,0 +1,62 @@ +namespace Discord +{ + /// + /// Application command permissions allow you to enable or disable commands for specific users or roles within a guild. + /// + public class ApplicationCommandPermission + { + /// + /// The id of the role or user. + /// + public ulong TargetId { get; } + + /// + /// The target of this permission. + /// + public ApplicationCommandPermissionTarget TargetType { get; } + + /// + /// to allow, otherwise . + /// + public bool Permission { get; } + + internal ApplicationCommandPermission() { } + + /// + /// Creates a new . + /// + /// The id you want to target this permission value for. + /// The type of the targetId parameter. + /// The value of this permission. + public ApplicationCommandPermission(ulong targetId, ApplicationCommandPermissionTarget targetType, bool allow) + { + TargetId = targetId; + TargetType = targetType; + Permission = allow; + } + + /// + /// Creates a new targeting . + /// + /// The user you want to target this permission value for. + /// The value of this permission. + public ApplicationCommandPermission(IUser target, bool allow) + { + TargetId = target.Id; + Permission = allow; + TargetType = ApplicationCommandPermissionTarget.User; + } + + /// + /// Creates a new targeting . + /// + /// The role you want to target this permission value for. + /// The value of this permission. + public ApplicationCommandPermission(IRole target, bool allow) + { + TargetId = target.Id; + Permission = allow; + TargetType = ApplicationCommandPermissionTarget.Role; + } + } +} diff --git a/src/Discord.Net.Core/Entities/Permissions/ChannelPermission.cs b/src/Discord.Net.Core/Entities/Permissions/ChannelPermission.cs index e1f78373e..45e24b7fa 100644 --- a/src/Discord.Net.Core/Entities/Permissions/ChannelPermission.cs +++ b/src/Discord.Net.Core/Entities/Permissions/ChannelPermission.cs @@ -10,99 +10,141 @@ namespace Discord /// /// Allows creation of instant invites. /// - CreateInstantInvite = 0x00_00_00_01, + CreateInstantInvite = 0x00_00_00_00_01, /// /// Allows management and editing of channels. /// - ManageChannels = 0x00_00_00_10, + ManageChannels = 0x00_00_00_00_10, // Text /// /// Allows for the addition of reactions to messages. /// - AddReactions = 0x00_00_00_40, - /// - /// Allows for reading of messages. This flag is obsolete, use instead. - /// - [Obsolete("Use ViewChannel instead.")] - ReadMessages = ViewChannel, + AddReactions = 0x00_00_00_00_40, /// /// Allows guild members to view a channel, which includes reading messages in text channels. /// - ViewChannel = 0x00_00_04_00, + ViewChannel = 0x00_00_00_04_00, /// /// Allows for sending messages in a channel. /// - SendMessages = 0x00_00_08_00, + SendMessages = 0x00_00_00_08_00, /// /// Allows for sending of text-to-speech messages. /// - SendTTSMessages = 0x00_00_10_00, + SendTTSMessages = 0x00_00_00_10_00, /// /// Allows for deletion of other users messages. /// - ManageMessages = 0x00_00_20_00, + ManageMessages = 0x00_00_00_20_00, /// /// Allows links sent by users with this permission will be auto-embedded. /// - EmbedLinks = 0x00_00_40_00, + EmbedLinks = 0x00_00_00_40_00, /// /// Allows for uploading images and files. /// - AttachFiles = 0x00_00_80_00, + AttachFiles = 0x00_00_00_80_00, /// /// Allows for reading of message history. /// - ReadMessageHistory = 0x00_01_00_00, + ReadMessageHistory = 0x00_00_01_00_00, /// /// Allows for using the @everyone tag to notify all users in a channel, and the @here tag to notify all /// online users in a channel. /// - MentionEveryone = 0x00_02_00_00, + MentionEveryone = 0x00_00_02_00_00, /// /// Allows the usage of custom emojis from other servers. /// - UseExternalEmojis = 0x00_04_00_00, + UseExternalEmojis = 0x00_00_04_00_00, // Voice /// /// Allows for joining of a voice channel. /// - Connect = 0x00_10_00_00, + Connect = 0x00_00_10_00_00, /// /// Allows for speaking in a voice channel. /// - Speak = 0x00_20_00_00, + Speak = 0x00_00_20_00_00, /// /// Allows for muting members in a voice channel. /// - MuteMembers = 0x00_40_00_00, + MuteMembers = 0x00_00_40_00_00, /// /// Allows for deafening of members in a voice channel. /// - DeafenMembers = 0x00_80_00_00, + DeafenMembers = 0x00_00_80_00_00, /// /// Allows for moving of members between voice channels. /// - MoveMembers = 0x01_00_00_00, + MoveMembers = 0x00_01_00_00_00, /// /// Allows for using voice-activity-detection in a voice channel. /// - UseVAD = 0x02_00_00_00, - PrioritySpeaker = 0x00_00_01_00, + UseVAD = 0x00_02_00_00_00, + + /// + /// Allows for using priority speaker in a voice channel. + /// + PrioritySpeaker = 0x00_00_00_01_00, + /// /// Allows video streaming in a voice channel. /// - Stream = 0x00_00_02_00, + Stream = 0x00_00_00_02_00, // More General /// /// Allows management and editing of roles. /// - ManageRoles = 0x10_00_00_00, + ManageRoles = 0x00_10_00_00_00, /// /// Allows management and editing of webhooks. /// - ManageWebhooks = 0x20_00_00_00, + ManageWebhooks = 0x00_20_00_00_00, + + /// + /// Allows management and editing of emojis. + /// + ManageEmojis = 0x00_40_00_00_00, + + /// + /// Allows members to use slash commands in text channels. + /// + UseApplicationCommands = 0x00_80_00_00_00, + + /// + /// Allows for requesting to speak in stage channels. (This permission is under active development and may be changed or removed.) + /// + RequestToSpeak = 0x01_00_00_00_00, + + /// + /// Allows for deleting and archiving threads, and viewing all private threads + /// + ManageThreads = 0x04_00_00_00_00, + + /// + /// Allows for creating public threads. + /// + CreatePublicThreads = 0x08_00_00_00_00, + /// + /// Allows for creating private threads. + /// + CreatePrivateThreads = 0x10_00_00_00_00, + /// + /// Allows the usage of custom stickers from other servers. + /// + UseExternalStickers = 0x20_00_00_00_00, + /// + /// Allows for sending messages in threads. + /// + SendMessagesInThreads = 0x40_00_00_00_00, + /// + /// Allows for launching activities (applications with the EMBEDDED flag) in a voice channel. + /// + StartEmbeddedActivities = 0x80_00_00_00_00 + } } diff --git a/src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs b/src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs index 99885b070..ee5c9984a 100644 --- a/src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs +++ b/src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs @@ -7,90 +7,106 @@ namespace Discord [DebuggerDisplay("{DebuggerDisplay,nq}")] public struct ChannelPermissions { - /// Gets a blank that grants no permissions. - /// A structure that does not contain any set permissions. + /// Gets a blank that grants no permissions. + /// A structure that does not contain any set permissions. public static readonly ChannelPermissions None = new ChannelPermissions(); - /// Gets a that grants all permissions for text channels. - public static readonly ChannelPermissions Text = new ChannelPermissions(0b01100_0000000_1111111110001_010001); - /// Gets a that grants all permissions for voice channels. - public static readonly ChannelPermissions Voice = new ChannelPermissions(0b00100_1111110_0000000011100_010001); - /// Gets a that grants all permissions for category channels. + /// Gets a that grants all permissions for text channels. + public static readonly ChannelPermissions Text = new ChannelPermissions(0b0_11111_0101100_0000000_1111111110001_010001); + /// Gets a that grants all permissions for voice channels. + public static readonly ChannelPermissions Voice = new ChannelPermissions(0b1_00000_0000100_1111110_0000000011100_010001); + /// Gets a that grants all permissions for stage channels. + public static readonly ChannelPermissions Stage = new ChannelPermissions(0b0_00000_1000100_0111010_0000000010000_010001); + /// Gets a that grants all permissions for category channels. public static readonly ChannelPermissions Category = new ChannelPermissions(0b01100_1111110_1111111110001_010001); - /// Gets a that grants all permissions for direct message channels. - public static readonly ChannelPermissions DM = new ChannelPermissions(0b00000_1000110_1011100110000_000000); - /// Gets a that grants all permissions for group channels. + /// Gets a that grants all permissions for direct message channels. + public static readonly ChannelPermissions DM = new ChannelPermissions(0b00000_1000110_1011100110001_000000); + /// Gets a that grants all permissions for group channels. public static readonly ChannelPermissions Group = new ChannelPermissions(0b00000_1000110_0001101100000_000000); - /// Gets a that grants all permissions for a given channel type. + /// Gets a that grants all permissions for a given channel type. /// Unknown channel type. public static ChannelPermissions All(IChannel channel) { - switch (channel) + return channel switch { - case ITextChannel _: return Text; - case IVoiceChannel _: return Voice; - case ICategoryChannel _: return Category; - case IDMChannel _: return DM; - case IGroupChannel _: return Group; - default: throw new ArgumentException(message: "Unknown channel type.", paramName: nameof(channel)); - } + ITextChannel _ => Text, + IStageChannel _ => Stage, + IVoiceChannel _ => Voice, + ICategoryChannel _ => Category, + IDMChannel _ => DM, + IGroupChannel _ => Group, + _ => throw new ArgumentException(message: "Unknown channel type.", paramName: nameof(channel)), + }; } - /// Gets a packed value representing all the permissions in this . + /// Gets a packed value representing all the permissions in this . public ulong RawValue { get; } - /// If true, a user may create invites. + /// If true, a user may create invites. public bool CreateInstantInvite => Permissions.GetValue(RawValue, ChannelPermission.CreateInstantInvite); - /// If true, a user may create, delete and modify this channel. + /// If true, a user may create, delete and modify this channel. public bool ManageChannel => Permissions.GetValue(RawValue, ChannelPermission.ManageChannels); - /// If true, a user may add reactions. + /// If true, a user may add reactions. public bool AddReactions => Permissions.GetValue(RawValue, ChannelPermission.AddReactions); - /// If true, a user may join channels. - [Obsolete("Use ViewChannel instead.")] - public bool ReadMessages => ViewChannel; - /// If true, a user may view channels. + /// If true, a user may view channels. public bool ViewChannel => Permissions.GetValue(RawValue, ChannelPermission.ViewChannel); - /// If true, a user may send messages. + /// If true, a user may send messages. public bool SendMessages => Permissions.GetValue(RawValue, ChannelPermission.SendMessages); - /// If true, a user may send text-to-speech messages. + /// If true, a user may send text-to-speech messages. public bool SendTTSMessages => Permissions.GetValue(RawValue, ChannelPermission.SendTTSMessages); - /// If true, a user may delete messages. + /// If true, a user may delete messages. public bool ManageMessages => Permissions.GetValue(RawValue, ChannelPermission.ManageMessages); - /// If true, Discord will auto-embed links sent by this user. + /// If true, Discord will auto-embed links sent by this user. public bool EmbedLinks => Permissions.GetValue(RawValue, ChannelPermission.EmbedLinks); - /// If true, a user may send files. + /// If true, a user may send files. public bool AttachFiles => Permissions.GetValue(RawValue, ChannelPermission.AttachFiles); - /// If true, a user may read previous messages. + /// If true, a user may read previous messages. public bool ReadMessageHistory => Permissions.GetValue(RawValue, ChannelPermission.ReadMessageHistory); - /// If true, a user may mention @everyone. + /// If true, a user may mention @everyone. public bool MentionEveryone => Permissions.GetValue(RawValue, ChannelPermission.MentionEveryone); - /// If true, a user may use custom emoji from other guilds. + /// If true, a user may use custom emoji from other guilds. public bool UseExternalEmojis => Permissions.GetValue(RawValue, ChannelPermission.UseExternalEmojis); - /// If true, a user may connect to a voice channel. + /// If true, a user may connect to a voice channel. public bool Connect => Permissions.GetValue(RawValue, ChannelPermission.Connect); - /// If true, a user may speak in a voice channel. + /// If true, a user may speak in a voice channel. public bool Speak => Permissions.GetValue(RawValue, ChannelPermission.Speak); - /// If true, a user may mute users. + /// If true, a user may mute users. public bool MuteMembers => Permissions.GetValue(RawValue, ChannelPermission.MuteMembers); - /// If true, a user may deafen users. + /// If true, a user may deafen users. public bool DeafenMembers => Permissions.GetValue(RawValue, ChannelPermission.DeafenMembers); - /// If true, a user may move other users between voice channels. + /// If true, a user may move other users between voice channels. public bool MoveMembers => Permissions.GetValue(RawValue, ChannelPermission.MoveMembers); - /// If true, a user may use voice-activity-detection rather than push-to-talk. + /// If true, a user may use voice-activity-detection rather than push-to-talk. public bool UseVAD => Permissions.GetValue(RawValue, ChannelPermission.UseVAD); - /// If true, a user may use priority speaker in a voice channel. + /// If true, a user may use priority speaker in a voice channel. public bool PrioritySpeaker => Permissions.GetValue(RawValue, ChannelPermission.PrioritySpeaker); - /// If true, a user may stream video in a voice channel. + /// If true, a user may stream video in a voice channel. public bool Stream => Permissions.GetValue(RawValue, ChannelPermission.Stream); - /// If true, a user may adjust role permissions. This also implictly grants all other permissions. + /// If true, a user may adjust role permissions. This also implicitly grants all other permissions. public bool ManageRoles => Permissions.GetValue(RawValue, ChannelPermission.ManageRoles); - /// If true, a user may edit the webhooks for this channel. + /// If true, a user may edit the webhooks for this channel. public bool ManageWebhooks => Permissions.GetValue(RawValue, ChannelPermission.ManageWebhooks); + /// If true, a user may use application commands in this guild. + public bool UseApplicationCommands => Permissions.GetValue(RawValue, ChannelPermission.UseApplicationCommands); + /// If true, a user may request to speak in stage channels. + public bool RequestToSpeak => Permissions.GetValue(RawValue, ChannelPermission.RequestToSpeak); + /// If true, a user may manage threads in this guild. + public bool ManageThreads => Permissions.GetValue(RawValue, ChannelPermission.ManageThreads); + /// If true, a user may create public threads in this guild. + public bool CreatePublicThreads => Permissions.GetValue(RawValue, ChannelPermission.CreatePublicThreads); + /// If true, a user may create private threads in this guild. + public bool CreatePrivateThreads => Permissions.GetValue(RawValue, ChannelPermission.CreatePrivateThreads); + /// If true, a user may use external stickers in this guild. + public bool UseExternalStickers => Permissions.GetValue(RawValue, ChannelPermission.UseExternalStickers); + /// If true, a user may send messages in threads in this guild. + public bool SendMessagesInThreads => Permissions.GetValue(RawValue, ChannelPermission.SendMessagesInThreads); + /// If true, a user launch application activities in voice channels in this guild. + public bool StartEmbeddedActivities => Permissions.GetValue(RawValue, ChannelPermission.StartEmbeddedActivities); - /// Creates a new with the provided packed value. + /// Creates a new with the provided packed value. public ChannelPermissions(ulong rawValue) { RawValue = rawValue; } private ChannelPermissions(ulong initialValue, @@ -115,7 +131,15 @@ namespace Discord bool? prioritySpeaker = null, bool? stream = null, bool? manageRoles = null, - bool? manageWebhooks = null) + bool? manageWebhooks = null, + bool? useApplicationCommands = null, + bool? requestToSpeak = null, + bool? manageThreads = null, + bool? createPublicThreads = null, + bool? createPrivateThreads = null, + bool? useExternalStickers = null, + bool? sendMessagesInThreads = null, + bool? startEmbeddedActivities = null) { ulong value = initialValue; @@ -141,11 +165,19 @@ namespace Discord Permissions.SetValue(ref value, stream, ChannelPermission.Stream); Permissions.SetValue(ref value, manageRoles, ChannelPermission.ManageRoles); Permissions.SetValue(ref value, manageWebhooks, ChannelPermission.ManageWebhooks); + Permissions.SetValue(ref value, useApplicationCommands, ChannelPermission.UseApplicationCommands); + Permissions.SetValue(ref value, requestToSpeak, ChannelPermission.RequestToSpeak); + Permissions.SetValue(ref value, manageThreads, ChannelPermission.ManageThreads); + Permissions.SetValue(ref value, createPublicThreads, ChannelPermission.CreatePublicThreads); + Permissions.SetValue(ref value, createPrivateThreads, ChannelPermission.CreatePrivateThreads); + Permissions.SetValue(ref value, useExternalStickers, ChannelPermission.UseExternalStickers); + Permissions.SetValue(ref value, sendMessagesInThreads, ChannelPermission.SendMessagesInThreads); + Permissions.SetValue(ref value, startEmbeddedActivities, ChannelPermission.StartEmbeddedActivities); RawValue = value; } - /// Creates a new with the provided permissions. + /// Creates a new with the provided permissions. public ChannelPermissions( bool createInstantInvite = false, bool manageChannel = false, @@ -168,13 +200,23 @@ namespace Discord bool prioritySpeaker = false, bool stream = false, bool manageRoles = false, - bool manageWebhooks = false) + bool manageWebhooks = false, + bool useApplicationCommands = false, + bool requestToSpeak = false, + bool manageThreads = false, + bool createPublicThreads = false, + bool createPrivateThreads = false, + bool useExternalStickers = false, + bool sendMessagesInThreads = false, + bool startEmbeddedActivities = false) : this(0, createInstantInvite, manageChannel, addReactions, viewChannel, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, - speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, prioritySpeaker, stream, manageRoles, manageWebhooks) + speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, prioritySpeaker, stream, manageRoles, manageWebhooks, + useApplicationCommands, requestToSpeak, manageThreads, createPublicThreads, createPrivateThreads, useExternalStickers, sendMessagesInThreads, + startEmbeddedActivities) { } - /// Creates a new from this one, changing the provided non-null permissions. + /// Creates a new from this one, changing the provided non-null permissions. public ChannelPermissions Modify( bool? createInstantInvite = null, bool? manageChannel = null, @@ -197,7 +239,15 @@ namespace Discord bool? prioritySpeaker = null, bool? stream = null, bool? manageRoles = null, - bool? manageWebhooks = null) + bool? manageWebhooks = null, + bool? useApplicationCommands = null, + bool? requestToSpeak = null, + bool? manageThreads = null, + bool? createPublicThreads = null, + bool? createPrivateThreads = null, + bool? useExternalStickers = null, + bool? sendMessagesInThreads = null, + bool? startEmbeddedActivities = null) => new ChannelPermissions(RawValue, createInstantInvite, manageChannel, @@ -220,7 +270,15 @@ namespace Discord prioritySpeaker, stream, manageRoles, - manageWebhooks); + manageWebhooks, + useApplicationCommands, + requestToSpeak, + manageThreads, + createPublicThreads, + createPrivateThreads, + useExternalStickers, + sendMessagesInThreads, + startEmbeddedActivities); public bool Has(ChannelPermission permission) => Permissions.GetValue(RawValue, permission); diff --git a/src/Discord.Net.Core/Entities/Permissions/GuildApplicationCommandPermissions.cs b/src/Discord.Net.Core/Entities/Permissions/GuildApplicationCommandPermissions.cs new file mode 100644 index 000000000..e738fec4c --- /dev/null +++ b/src/Discord.Net.Core/Entities/Permissions/GuildApplicationCommandPermissions.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; + +namespace Discord +{ + /// + /// Returned when fetching the permissions for a command in a guild. + /// + public class GuildApplicationCommandPermission + + { + /// + /// The id of the command. + /// + public ulong CommandId { get; } + + /// + /// The id of the application the command belongs to. + /// + public ulong ApplicationId { get; } + + /// + /// The id of the guild. + /// + public ulong GuildId { get; } + + /// + /// The permissions for the command in the guild. + /// + public IReadOnlyCollection Permissions { get; } + + internal GuildApplicationCommandPermission(ulong commandId, ulong appId, ulong guildId, ApplicationCommandPermission[] permissions) + { + CommandId = commandId; + ApplicationId = appId; + GuildId = guildId; + Permissions = permissions; + } + } +} diff --git a/src/Discord.Net.Core/Entities/Permissions/GuildPermission.cs b/src/Discord.Net.Core/Entities/Permissions/GuildPermission.cs index 3c8a5e810..299ff3bd8 100644 --- a/src/Discord.Net.Core/Entities/Permissions/GuildPermission.cs +++ b/src/Discord.Net.Core/Entities/Permissions/GuildPermission.cs @@ -10,7 +10,7 @@ namespace Discord /// /// Allows creation of instant invites. /// - CreateInstantInvite = 0x00_00_00_01, + CreateInstantInvite = 0x00_00_00_01, /// /// Allows kicking members. /// @@ -18,7 +18,7 @@ namespace Discord /// This permission requires the owner account to use two-factor /// authentication when used on a guild that has server-wide 2FA enabled. /// - KickMembers = 0x00_00_00_02, + KickMembers = 0x00_00_00_02, /// /// Allows banning members. /// @@ -26,7 +26,7 @@ namespace Discord /// This permission requires the owner account to use two-factor /// authentication when used on a guild that has server-wide 2FA enabled. /// - BanMembers = 0x00_00_00_04, + BanMembers = 0x00_00_00_04, /// /// Allows all permissions and bypasses channel permission overwrites. /// @@ -34,7 +34,7 @@ namespace Discord /// This permission requires the owner account to use two-factor /// authentication when used on a guild that has server-wide 2FA enabled. /// - Administrator = 0x00_00_00_08, + Administrator = 0x00_00_00_08, /// /// Allows management and editing of channels. /// @@ -42,7 +42,7 @@ namespace Discord /// This permission requires the owner account to use two-factor /// authentication when used on a guild that has server-wide 2FA enabled. /// - ManageChannels = 0x00_00_00_10, + ManageChannels = 0x00_00_00_10, /// /// Allows management and editing of the guild. /// @@ -50,25 +50,33 @@ namespace Discord /// This permission requires the owner account to use two-factor /// authentication when used on a guild that has server-wide 2FA enabled. /// - ManageGuild = 0x00_00_00_20, + ManageGuild = 0x00_00_00_20, + /// + /// Allows for viewing of guild insights + /// + ViewGuildInsights = 0x00_08_00_00, // Text /// /// Allows for the addition of reactions to messages. /// - AddReactions = 0x00_00_00_40, + AddReactions = 0x00_00_00_40, /// /// Allows for viewing of audit logs. /// - ViewAuditLog = 0x00_00_00_80, - [Obsolete("Use ViewChannel instead.")] - ReadMessages = ViewChannel, - ViewChannel = 0x00_00_04_00, - SendMessages = 0x00_00_08_00, + ViewAuditLog = 0x00_00_00_80, + /// + /// Allows guild members to view a channel, which includes reading messages in text channels. + /// + ViewChannel = 0x00_00_04_00, + /// + /// Allows for sending messages in a channel + /// + SendMessages = 0x00_00_08_00, /// /// Allows for sending of text-to-speech messages. /// - SendTTSMessages = 0x00_00_10_00, + SendTTSMessages = 0x00_00_10_00, /// /// Allows for deletion of other users messages. /// @@ -76,70 +84,73 @@ namespace Discord /// This permission requires the owner account to use two-factor /// authentication when used on a guild that has server-wide 2FA enabled. /// - ManageMessages = 0x00_00_20_00, + ManageMessages = 0x00_00_20_00, /// /// Allows links sent by users with this permission will be auto-embedded. /// - EmbedLinks = 0x00_00_40_00, + EmbedLinks = 0x00_00_40_00, /// /// Allows for uploading images and files. /// - AttachFiles = 0x00_00_80_00, + AttachFiles = 0x00_00_80_00, /// /// Allows for reading of message history. /// - ReadMessageHistory = 0x00_01_00_00, + ReadMessageHistory = 0x00_01_00_00, /// /// Allows for using the @everyone tag to notify all users in a channel, and the @here tag to notify all /// online users in a channel. /// - MentionEveryone = 0x00_02_00_00, + MentionEveryone = 0x00_02_00_00, /// /// Allows the usage of custom emojis from other servers. /// - UseExternalEmojis = 0x00_04_00_00, + UseExternalEmojis = 0x00_04_00_00, // Voice /// /// Allows for joining of a voice channel. /// - Connect = 0x00_10_00_00, + Connect = 0x00_10_00_00, /// /// Allows for speaking in a voice channel. /// - Speak = 0x00_20_00_00, + Speak = 0x00_20_00_00, /// /// Allows for muting members in a voice channel. /// - MuteMembers = 0x00_40_00_00, + MuteMembers = 0x00_40_00_00, /// /// Allows for deafening of members in a voice channel. /// - DeafenMembers = 0x00_80_00_00, + DeafenMembers = 0x00_80_00_00, /// /// Allows for moving of members between voice channels. /// - MoveMembers = 0x01_00_00_00, + MoveMembers = 0x01_00_00_00, /// /// Allows for using voice-activity-detection in a voice channel. /// - UseVAD = 0x02_00_00_00, - PrioritySpeaker = 0x00_00_01_00, + UseVAD = 0x02_00_00_00, + /// + /// Allows for using priority speaker in a voice channel. + /// + PrioritySpeaker = 0x00_00_01_00, /// /// Allows video streaming in a voice channel. /// - Stream = 0x00_00_02_00, + Stream = 0x00_00_02_00, // General 2 /// /// Allows for modification of own nickname. /// - ChangeNickname = 0x04_00_00_00, + ChangeNickname = 0x04_00_00_00, /// /// Allows for modification of other users nicknames. /// - ManageNicknames = 0x08_00_00_00, + ManageNicknames = 0x08_00_00_00, /// /// Allows management and editing of roles. /// @@ -147,7 +158,7 @@ namespace Discord /// This permission requires the owner account to use two-factor /// authentication when used on a guild that has server-wide 2FA enabled. /// - ManageRoles = 0x10_00_00_00, + ManageRoles = 0x10_00_00_00, /// /// Allows management and editing of webhooks. /// @@ -155,14 +166,58 @@ namespace Discord /// This permission requires the owner account to use two-factor /// authentication when used on a guild that has server-wide 2FA enabled. /// - ManageWebhooks = 0x20_00_00_00, + ManageWebhooks = 0x20_00_00_00, + /// + /// Allows management and editing of emojis and stickers. + /// + /// + /// This permission requires the owner account to use two-factor + /// authentication when used on a guild that has server-wide 2FA enabled. + /// + ManageEmojisAndStickers = 0x40_00_00_00, + /// + /// Allows members to use application commands like slash commands and context menus in text channels. + /// + UseApplicationCommands = 0x80_00_00_00, /// - /// Allows management and editing of emojis. + /// Allows for requesting to speak in stage channels. + /// + RequestToSpeak = 0x01_00_00_00_00, + /// + /// Allows for creating, editing, and deleting guild scheduled events. + /// + ManageEvents = 0x02_00_00_00_00, + /// + /// Allows for deleting and archiving threads, and viewing all private threads. /// /// /// This permission requires the owner account to use two-factor /// authentication when used on a guild that has server-wide 2FA enabled. /// - ManageEmojis = 0x40_00_00_00 + ManageThreads = 0x04_00_00_00_00, + /// + /// Allows for creating public threads. + /// + CreatePublicThreads = 0x08_00_00_00_00, + /// + /// Allows for creating private threads. + /// + CreatePrivateThreads = 0x10_00_00_00_00, + /// + /// Allows the usage of custom stickers from other servers. + /// + UseExternalStickers = 0x20_00_00_00_00, + /// + /// Allows for sending messages in threads. + /// + SendMessagesInThreads = 0x40_00_00_00_00, + /// + /// Allows for launching activities (applications with the EMBEDDED flag) in a voice channel. + /// + StartEmbeddedActivities = 0x80_00_00_00_00, + /// + /// Allows for timing out users. + /// + ModerateMembers = 0x01_00_00_00_00_00 } } diff --git a/src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs b/src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs index a5adad47c..649944ede 100644 --- a/src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs +++ b/src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Linq; namespace Discord { @@ -10,9 +11,9 @@ namespace Discord /// Gets a blank that grants no permissions. public static readonly GuildPermissions None = new GuildPermissions(); /// Gets a that grants all guild permissions for webhook users. - public static readonly GuildPermissions Webhook = new GuildPermissions(0b00000_0000000_0001101100000_000000); + public static readonly GuildPermissions Webhook = new GuildPermissions(0b0_00000_0000000_0000000_0001101100000_000000); /// Gets a that grants all guild permissions. - public static readonly GuildPermissions All = new GuildPermissions(0b11111_1111110_1111111111111_111111); + public static readonly GuildPermissions All = new GuildPermissions(0b1_11111_1111111_1111111_1111111111111_111111); /// Gets a packed value representing all the permissions in this . public ulong RawValue { get; } @@ -34,10 +35,9 @@ namespace Discord public bool AddReactions => Permissions.GetValue(RawValue, GuildPermission.AddReactions); /// If true, a user may view the audit log. public bool ViewAuditLog => Permissions.GetValue(RawValue, GuildPermission.ViewAuditLog); + /// If true, a user may view the guild insights. + public bool ViewGuildInsights => Permissions.GetValue(RawValue, GuildPermission.ViewGuildInsights); - /// If True, a user may join channels. - [Obsolete("Use ViewChannel instead.")] - public bool ReadMessages => ViewChannel; /// If True, a user may view channels. public bool ViewChannel => Permissions.GetValue(RawValue, GuildPermission.ViewChannel); /// If True, a user may send messages. @@ -82,12 +82,34 @@ namespace Discord public bool ManageRoles => Permissions.GetValue(RawValue, GuildPermission.ManageRoles); /// If true, a user may edit the webhooks for this guild. public bool ManageWebhooks => Permissions.GetValue(RawValue, GuildPermission.ManageWebhooks); - /// If true, a user may edit the emojis for this guild. - public bool ManageEmojis => Permissions.GetValue(RawValue, GuildPermission.ManageEmojis); - + /// If true, a user may edit the emojis and stickers for this guild. + public bool ManageEmojisAndStickers => Permissions.GetValue(RawValue, GuildPermission.ManageEmojisAndStickers); + /// If true, a user may use slash commands in this guild. + public bool UseApplicationCommands => Permissions.GetValue(RawValue, GuildPermission.UseApplicationCommands); + /// If true, a user may request to speak in stage channels. + public bool RequestToSpeak => Permissions.GetValue(RawValue, GuildPermission.RequestToSpeak); + /// If true, a user may create, edit, and delete events. + public bool ManageEvents => Permissions.GetValue(RawValue, GuildPermission.ManageEvents); + /// If true, a user may manage threads in this guild. + public bool ManageThreads => Permissions.GetValue(RawValue, GuildPermission.ManageThreads); + /// If true, a user may create public threads in this guild. + public bool CreatePublicThreads => Permissions.GetValue(RawValue, GuildPermission.CreatePublicThreads); + /// If true, a user may create private threads in this guild. + public bool CreatePrivateThreads => Permissions.GetValue(RawValue, GuildPermission.CreatePrivateThreads); + /// If true, a user may use external stickers in this guild. + public bool UseExternalStickers => Permissions.GetValue(RawValue, GuildPermission.UseExternalStickers); + /// If true, a user may send messages in threads in this guild. + public bool SendMessagesInThreads => Permissions.GetValue(RawValue, GuildPermission.SendMessagesInThreads); + /// If true, a user launch application activities in voice channels in this guild. + public bool StartEmbeddedActivities => Permissions.GetValue(RawValue, GuildPermission.StartEmbeddedActivities); + /// If true, a user can timeout other users in this guild. + public bool ModerateMembers => Permissions.GetValue(RawValue, GuildPermission.ModerateMembers); /// Creates a new with the provided packed value. public GuildPermissions(ulong rawValue) { RawValue = rawValue; } + /// Creates a new with the provided packed value after converting to ulong. + public GuildPermissions(string rawValue) { RawValue = ulong.Parse(rawValue); } + private GuildPermissions(ulong initialValue, bool? createInstantInvite = null, bool? kickMembers = null, @@ -97,6 +119,7 @@ namespace Discord bool? manageGuild = null, bool? addReactions = null, bool? viewAuditLog = null, + bool? viewGuildInsights = null, bool? viewChannel = null, bool? sendMessages = null, bool? sendTTSMessages = null, @@ -118,7 +141,17 @@ namespace Discord bool? manageNicknames = null, bool? manageRoles = null, bool? manageWebhooks = null, - bool? manageEmojis = null) + bool? manageEmojisAndStickers = null, + bool? useApplicationCommands = null, + bool? requestToSpeak = null, + bool? manageEvents = null, + bool? manageThreads = null, + bool? createPublicThreads = null, + bool? createPrivateThreads = null, + bool? useExternalStickers = null, + bool? sendMessagesInThreads = null, + bool? startEmbeddedActivities = null, + bool? moderateMembers = null) { ulong value = initialValue; @@ -130,6 +163,7 @@ namespace Discord Permissions.SetValue(ref value, manageGuild, GuildPermission.ManageGuild); Permissions.SetValue(ref value, addReactions, GuildPermission.AddReactions); Permissions.SetValue(ref value, viewAuditLog, GuildPermission.ViewAuditLog); + Permissions.SetValue(ref value, viewGuildInsights, GuildPermission.ViewGuildInsights); Permissions.SetValue(ref value, viewChannel, GuildPermission.ViewChannel); Permissions.SetValue(ref value, sendMessages, GuildPermission.SendMessages); Permissions.SetValue(ref value, sendTTSMessages, GuildPermission.SendTTSMessages); @@ -151,7 +185,17 @@ namespace Discord Permissions.SetValue(ref value, manageNicknames, GuildPermission.ManageNicknames); Permissions.SetValue(ref value, manageRoles, GuildPermission.ManageRoles); Permissions.SetValue(ref value, manageWebhooks, GuildPermission.ManageWebhooks); - Permissions.SetValue(ref value, manageEmojis, GuildPermission.ManageEmojis); + Permissions.SetValue(ref value, manageEmojisAndStickers, GuildPermission.ManageEmojisAndStickers); + Permissions.SetValue(ref value, useApplicationCommands, GuildPermission.UseApplicationCommands); + Permissions.SetValue(ref value, requestToSpeak, GuildPermission.RequestToSpeak); + Permissions.SetValue(ref value, manageEvents, GuildPermission.ManageEvents); + Permissions.SetValue(ref value, manageThreads, GuildPermission.ManageThreads); + Permissions.SetValue(ref value, createPublicThreads, GuildPermission.CreatePublicThreads); + Permissions.SetValue(ref value, createPrivateThreads, GuildPermission.CreatePrivateThreads); + Permissions.SetValue(ref value, useExternalStickers, GuildPermission.UseExternalStickers); + Permissions.SetValue(ref value, sendMessagesInThreads, GuildPermission.SendMessagesInThreads); + Permissions.SetValue(ref value, startEmbeddedActivities, GuildPermission.StartEmbeddedActivities); + Permissions.SetValue(ref value, moderateMembers, GuildPermission.ModerateMembers); RawValue = value; } @@ -166,6 +210,7 @@ namespace Discord bool manageGuild = false, bool addReactions = false, bool viewAuditLog = false, + bool viewGuildInsights = false, bool viewChannel = false, bool sendMessages = false, bool sendTTSMessages = false, @@ -187,7 +232,17 @@ namespace Discord bool manageNicknames = false, bool manageRoles = false, bool manageWebhooks = false, - bool manageEmojis = false) + bool manageEmojisAndStickers = false, + bool useApplicationCommands = false, + bool requestToSpeak = false, + bool manageEvents = false, + bool manageThreads = false, + bool createPublicThreads = false, + bool createPrivateThreads = false, + bool useExternalStickers = false, + bool sendMessagesInThreads = false, + bool startEmbeddedActivities = false, + bool moderateMembers = false) : this(0, createInstantInvite: createInstantInvite, manageRoles: manageRoles, @@ -198,6 +253,7 @@ namespace Discord manageGuild: manageGuild, addReactions: addReactions, viewAuditLog: viewAuditLog, + viewGuildInsights: viewGuildInsights, viewChannel: viewChannel, sendMessages: sendMessages, sendTTSMessages: sendTTSMessages, @@ -218,7 +274,17 @@ namespace Discord changeNickname: changeNickname, manageNicknames: manageNicknames, manageWebhooks: manageWebhooks, - manageEmojis: manageEmojis) + manageEmojisAndStickers: manageEmojisAndStickers, + useApplicationCommands: useApplicationCommands, + requestToSpeak: requestToSpeak, + manageEvents: manageEvents, + manageThreads: manageThreads, + createPublicThreads: createPublicThreads, + createPrivateThreads: createPrivateThreads, + useExternalStickers: useExternalStickers, + sendMessagesInThreads: sendMessagesInThreads, + startEmbeddedActivities: startEmbeddedActivities, + moderateMembers: moderateMembers) { } /// Creates a new from this one, changing the provided non-null permissions. @@ -231,6 +297,7 @@ namespace Discord bool? manageGuild = null, bool? addReactions = null, bool? viewAuditLog = null, + bool? viewGuildInsights = null, bool? viewChannel = null, bool? sendMessages = null, bool? sendTTSMessages = null, @@ -252,11 +319,23 @@ namespace Discord bool? manageNicknames = null, bool? manageRoles = null, bool? manageWebhooks = null, - bool? manageEmojis = null) + bool? manageEmojisAndStickers = null, + bool? useApplicationCommands = null, + bool? requestToSpeak = null, + bool? manageEvents = null, + bool? manageThreads = null, + bool? createPublicThreads = null, + bool? createPrivateThreads = null, + bool? useExternalStickers = null, + bool? sendMessagesInThreads = null, + bool? startEmbeddedActivities = null, + bool? moderateMembers = null) => new GuildPermissions(RawValue, createInstantInvite, kickMembers, banMembers, administrator, manageChannels, manageGuild, addReactions, - viewAuditLog, viewChannel, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles, + viewAuditLog, viewGuildInsights, viewChannel, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers, moveMembers, - useVoiceActivation, prioritySpeaker, stream, changeNickname, manageNicknames, manageRoles, manageWebhooks, manageEmojis); + useVoiceActivation, prioritySpeaker, stream, changeNickname, manageNicknames, manageRoles, manageWebhooks, manageEmojisAndStickers, + useApplicationCommands, requestToSpeak, manageEvents, manageThreads, createPublicThreads, createPrivateThreads, useExternalStickers, sendMessagesInThreads, + startEmbeddedActivities, moderateMembers); /// /// Returns a value that indicates if a specific is enabled @@ -286,6 +365,18 @@ namespace Discord return perms; } + internal void Ensure(GuildPermission permissions) + { + if (!Has(permissions)) + { + var vals = Enum.GetValues(typeof(GuildPermission)).Cast(); + var currentValues = RawValue; + var missingValues = vals.Where(x => permissions.HasFlag(x) && !Permissions.GetValue(currentValues, x)); + + throw new InvalidOperationException($"Missing required guild permission{(missingValues.Count() > 1 ? "s" : "")} {string.Join(", ", missingValues.Select(x => x.ToString()))} in order to execute this operation."); + } + } + public override string ToString() => RawValue.ToString(); private string DebuggerDisplay => $"{string.Join(", ", ToList())}"; } diff --git a/src/Discord.Net.Core/Entities/Permissions/OverwritePermissions.cs b/src/Discord.Net.Core/Entities/Permissions/OverwritePermissions.cs index 04bb2f668..0e634ad1a 100644 --- a/src/Discord.Net.Core/Entities/Permissions/OverwritePermissions.cs +++ b/src/Discord.Net.Core/Entities/Permissions/OverwritePermissions.cs @@ -1,3 +1,4 @@ +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Diagnostics; @@ -43,9 +44,6 @@ namespace Discord /// If Allowed, a user may add reactions. public PermValue AddReactions => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.AddReactions); /// If Allowed, a user may join channels. - [Obsolete("Use ViewChannel instead.")] - public PermValue ReadMessages => ViewChannel; - /// If Allowed, a user may join channels. public PermValue ViewChannel => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ViewChannel); /// If Allowed, a user may send messages. public PermValue SendMessages => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.SendMessages); @@ -76,11 +74,31 @@ namespace Discord public PermValue MoveMembers => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.MoveMembers); /// If Allowed, a user may use voice-activity-detection rather than push-to-talk. public PermValue UseVAD => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.UseVAD); + /// If Allowed, a user may use priority speaker in a voice channel. + public PermValue PrioritySpeaker => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.PrioritySpeaker); + /// If Allowed, a user may go live in a voice channel. + public PermValue Stream => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.Stream); /// If Allowed, a user may adjust role permissions. This also implicitly grants all other permissions. public PermValue ManageRoles => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ManageRoles); /// If True, a user may edit the webhooks for this channel. public PermValue ManageWebhooks => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ManageWebhooks); + /// If true, a user may use slash commands in this guild. + public PermValue UseApplicationCommands => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.UseApplicationCommands); + /// If true, a user may request to speak in stage channels. + public PermValue RequestToSpeak => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.RequestToSpeak); + /// If true, a user may manage threads in this guild. + public PermValue ManageThreads => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.ManageThreads); + /// If true, a user may create public threads in this guild. + public PermValue CreatePublicThreads => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.CreatePublicThreads); + /// If true, a user may create private threads in this guild. + public PermValue CreatePrivateThreads => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.CreatePrivateThreads); + /// If true, a user may use external stickers in this guild. + public PermValue UseExternalStickers => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.UseExternalStickers); + /// If true, a user may send messages in threads in this guild. + public PermValue SendMessagesInThreads => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.SendMessagesInThreads); + /// If true, a user launch application activities in voice channels in this guild. + public PermValue StartEmbeddedActivities => Permissions.GetValue(AllowValue, DenyValue, ChannelPermission.StartEmbeddedActivities); /// Creates a new OverwritePermissions with the provided allow and deny packed values. public OverwritePermissions(ulong allowValue, ulong denyValue) @@ -89,6 +107,13 @@ namespace Discord DenyValue = denyValue; } + /// Creates a new OverwritePermissions with the provided allow and deny packed values after converting to ulong. + public OverwritePermissions(string allowValue, string denyValue) + { + AllowValue = ulong.Parse(allowValue); + DenyValue = ulong.Parse(denyValue); + } + private OverwritePermissions(ulong allowValue, ulong denyValue, PermValue? createInstantInvite = null, PermValue? manageChannel = null, @@ -109,7 +134,20 @@ namespace Discord PermValue? moveMembers = null, PermValue? useVoiceActivation = null, PermValue? manageRoles = null, - PermValue? manageWebhooks = null) + PermValue? manageWebhooks = null, + PermValue? prioritySpeaker = null, + PermValue? stream = null, + PermValue? useSlashCommands = null, + PermValue? useApplicationCommands = null, + PermValue? requestToSpeak = null, + PermValue? manageThreads = null, + PermValue? createPublicThreads = null, + PermValue? createPrivateThreads = null, + PermValue? usePublicThreads = null, + PermValue? usePrivateThreads = null, + PermValue? useExternalStickers = null, + PermValue? sendMessagesInThreads = null, + PermValue? startEmbeddedActivities = null) { Permissions.SetValue(ref allowValue, ref denyValue, createInstantInvite, ChannelPermission.CreateInstantInvite); Permissions.SetValue(ref allowValue, ref denyValue, manageChannel, ChannelPermission.ManageChannels); @@ -129,8 +167,18 @@ namespace Discord Permissions.SetValue(ref allowValue, ref denyValue, deafenMembers, ChannelPermission.DeafenMembers); Permissions.SetValue(ref allowValue, ref denyValue, moveMembers, ChannelPermission.MoveMembers); Permissions.SetValue(ref allowValue, ref denyValue, useVoiceActivation, ChannelPermission.UseVAD); + Permissions.SetValue(ref allowValue, ref denyValue, prioritySpeaker, ChannelPermission.PrioritySpeaker); + Permissions.SetValue(ref allowValue, ref denyValue, stream, ChannelPermission.Stream); Permissions.SetValue(ref allowValue, ref denyValue, manageRoles, ChannelPermission.ManageRoles); Permissions.SetValue(ref allowValue, ref denyValue, manageWebhooks, ChannelPermission.ManageWebhooks); + Permissions.SetValue(ref allowValue, ref denyValue, useApplicationCommands, ChannelPermission.UseApplicationCommands); + Permissions.SetValue(ref allowValue, ref denyValue, requestToSpeak, ChannelPermission.RequestToSpeak); + Permissions.SetValue(ref allowValue, ref denyValue, manageThreads, ChannelPermission.ManageThreads); + Permissions.SetValue(ref allowValue, ref denyValue, createPublicThreads, ChannelPermission.CreatePublicThreads); + Permissions.SetValue(ref allowValue, ref denyValue, createPrivateThreads, ChannelPermission.CreatePrivateThreads); + Permissions.SetValue(ref allowValue, ref denyValue, useExternalStickers, ChannelPermission.UseExternalStickers); + Permissions.SetValue(ref allowValue, ref denyValue, sendMessagesInThreads, ChannelPermission.SendMessagesInThreads); + Permissions.SetValue(ref allowValue, ref denyValue, startEmbeddedActivities, ChannelPermission.StartEmbeddedActivities); AllowValue = allowValue; DenyValue = denyValue; @@ -159,10 +207,25 @@ namespace Discord PermValue moveMembers = PermValue.Inherit, PermValue useVoiceActivation = PermValue.Inherit, PermValue manageRoles = PermValue.Inherit, - PermValue manageWebhooks = PermValue.Inherit) + PermValue manageWebhooks = PermValue.Inherit, + PermValue prioritySpeaker = PermValue.Inherit, + PermValue stream = PermValue.Inherit, + PermValue useSlashCommands = PermValue.Inherit, + PermValue useApplicationCommands = PermValue.Inherit, + PermValue requestToSpeak = PermValue.Inherit, + PermValue manageThreads = PermValue.Inherit, + PermValue createPublicThreads = PermValue.Inherit, + PermValue createPrivateThreads = PermValue.Inherit, + PermValue usePublicThreads = PermValue.Inherit, + PermValue usePrivateThreads = PermValue.Inherit, + PermValue useExternalStickers = PermValue.Inherit, + PermValue sendMessagesInThreads = PermValue.Inherit, + PermValue startEmbeddedActivities = PermValue.Inherit) : this(0, 0, createInstantInvite, manageChannel, addReactions, viewChannel, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers, - moveMembers, useVoiceActivation, manageRoles, manageWebhooks) { } + moveMembers, useVoiceActivation, manageRoles, manageWebhooks, prioritySpeaker, stream, useSlashCommands, useApplicationCommands, + requestToSpeak, manageThreads, createPublicThreads, createPrivateThreads, usePublicThreads, usePrivateThreads, useExternalStickers, + sendMessagesInThreads, startEmbeddedActivities) { } /// /// Initializes a new from the current one, changing the provided @@ -188,10 +251,25 @@ namespace Discord PermValue? moveMembers = null, PermValue? useVoiceActivation = null, PermValue? manageRoles = null, - PermValue? manageWebhooks = null) + PermValue? manageWebhooks = null, + PermValue? prioritySpeaker = null, + PermValue? stream = null, + PermValue? useSlashCommands = null, + PermValue? useApplicationCommands = null, + PermValue? requestToSpeak = null, + PermValue? manageThreads = null, + PermValue? createPublicThreads = null, + PermValue? createPrivateThreads = null, + PermValue? usePublicThreads = null, + PermValue? usePrivateThreads = null, + PermValue? useExternalStickers = null, + PermValue? sendMessagesInThreads = null, + PermValue? startEmbeddedActivities = null) => new OverwritePermissions(AllowValue, DenyValue, createInstantInvite, manageChannel, addReactions, viewChannel, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers, - moveMembers, useVoiceActivation, manageRoles, manageWebhooks); + moveMembers, useVoiceActivation, manageRoles, manageWebhooks, prioritySpeaker, stream, useSlashCommands, useApplicationCommands, + requestToSpeak, manageThreads, createPublicThreads, createPrivateThreads, usePublicThreads, usePrivateThreads, useExternalStickers, + sendMessagesInThreads, startEmbeddedActivities); /// /// Creates a of all the values that are allowed. diff --git a/src/Discord.Net.Core/Entities/Roles/Color.cs b/src/Discord.Net.Core/Entities/Roles/Color.cs index 7c2d152a4..ee50710e8 100644 --- a/src/Discord.Net.Core/Entities/Roles/Color.cs +++ b/src/Discord.Net.Core/Entities/Roles/Color.cs @@ -10,68 +10,70 @@ namespace Discord [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public struct Color { + /// Gets the max decimal value of color. + public const uint MaxDecimalValue = 0xFFFFFF; /// Gets the default user color value. - public static readonly Color Default = new Color(0); + public static readonly Color Default = new(0); /// Gets the teal color value. /// A color struct with the hex value of 1ABC9C. - public static readonly Color Teal = new Color(0x1ABC9C); + public static readonly Color Teal = new(0x1ABC9C); /// Gets the dark teal color value. /// A color struct with the hex value of 11806A. - public static readonly Color DarkTeal = new Color(0x11806A); + public static readonly Color DarkTeal = new(0x11806A); /// Gets the green color value. /// A color struct with the hex value of 2ECC71. - public static readonly Color Green = new Color(0x2ECC71); + public static readonly Color Green = new(0x2ECC71); /// Gets the dark green color value. /// A color struct with the hex value of 1F8B4C. - public static readonly Color DarkGreen = new Color(0x1F8B4C); + public static readonly Color DarkGreen = new(0x1F8B4C); /// Gets the blue color value. /// A color struct with the hex value of 3498DB. - public static readonly Color Blue = new Color(0x3498DB); + public static readonly Color Blue = new(0x3498DB); /// Gets the dark blue color value. /// A color struct with the hex value of 206694. - public static readonly Color DarkBlue = new Color(0x206694); + public static readonly Color DarkBlue = new(0x206694); /// Gets the purple color value. /// A color struct with the hex value of 9B59B6. - public static readonly Color Purple = new Color(0x9B59B6); + public static readonly Color Purple = new(0x9B59B6); /// Gets the dark purple color value. /// A color struct with the hex value of 71368A. - public static readonly Color DarkPurple = new Color(0x71368A); + public static readonly Color DarkPurple = new(0x71368A); /// Gets the magenta color value. /// A color struct with the hex value of E91E63. - public static readonly Color Magenta = new Color(0xE91E63); + public static readonly Color Magenta = new(0xE91E63); /// Gets the dark magenta color value. /// A color struct with the hex value of AD1457. - public static readonly Color DarkMagenta = new Color(0xAD1457); + public static readonly Color DarkMagenta = new(0xAD1457); /// Gets the gold color value. /// A color struct with the hex value of F1C40F. - public static readonly Color Gold = new Color(0xF1C40F); + public static readonly Color Gold = new(0xF1C40F); /// Gets the light orange color value. /// A color struct with the hex value of C27C0E. - public static readonly Color LightOrange = new Color(0xC27C0E); + public static readonly Color LightOrange = new(0xC27C0E); /// Gets the orange color value. /// A color struct with the hex value of E67E22. - public static readonly Color Orange = new Color(0xE67E22); + public static readonly Color Orange = new(0xE67E22); /// Gets the dark orange color value. /// A color struct with the hex value of A84300. - public static readonly Color DarkOrange = new Color(0xA84300); + public static readonly Color DarkOrange = new(0xA84300); /// Gets the red color value. /// A color struct with the hex value of E74C3C. - public static readonly Color Red = new Color(0xE74C3C); + public static readonly Color Red = new(0xE74C3C); /// Gets the dark red color value. /// A color struct with the hex value of 992D22. - public static readonly Color DarkRed = new Color(0x992D22); + public static readonly Color DarkRed = new(0x992D22); /// Gets the light grey color value. /// A color struct with the hex value of 979C9F. - public static readonly Color LightGrey = new Color(0x979C9F); + public static readonly Color LightGrey = new(0x979C9F); /// Gets the lighter grey color value. /// A color struct with the hex value of 95A5A6. - public static readonly Color LighterGrey = new Color(0x95A5A6); + public static readonly Color LighterGrey = new(0x95A5A6); /// Gets the dark grey color value. /// A color struct with the hex value of 607D8B. - public static readonly Color DarkGrey = new Color(0x607D8B); + public static readonly Color DarkGrey = new(0x607D8B); /// Gets the darker grey color value. /// A color struct with the hex value of 546E7A. - public static readonly Color DarkerGrey = new Color(0x546E7A); + public static readonly Color DarkerGrey = new(0x546E7A); /// Gets the encoded value for this color. /// @@ -91,22 +93,27 @@ namespace Discord /// Initializes a struct with the given raw value. /// /// - /// The following will create a color that has a hex value of + /// The following will create a color that has a hex value of /// #607D8B. /// /// Color darkGrey = new Color(0x607D8B); /// /// /// The raw value of the color (e.g. 0x607D8B). + /// Value exceeds . public Color(uint rawValue) { + if (rawValue > MaxDecimalValue) + throw new ArgumentException($"{nameof(RawValue)} of color cannot be greater than {MaxDecimalValue}!", nameof(rawValue)); + RawValue = rawValue; } + /// /// Initializes a struct with the given RGB bytes. /// /// - /// The following will create a color that has a value of + /// The following will create a color that has a value of /// #607D8B. /// /// Color darkGrey = new Color((byte)0b_01100000, (byte)0b_01111101, (byte)0b_10001011); @@ -115,19 +122,24 @@ namespace Discord /// The byte that represents the red color. /// The byte that represents the green color. /// The byte that represents the blue color. + /// Value exceeds . public Color(byte r, byte g, byte b) { - RawValue = - ((uint)r << 16) | - ((uint)g << 8) | - (uint)b; + uint value = ((uint)r << 16) + | ((uint)g << 8) + | (uint)b; + + if (value > MaxDecimalValue) + throw new ArgumentException($"{nameof(RawValue)} of color cannot be greater than {MaxDecimalValue}!"); + + RawValue = value; } /// /// Initializes a struct with the given RGB value. /// /// - /// The following will create a color that has a value of + /// The following will create a color that has a value of /// #607D8B. /// /// Color darkGrey = new Color(96, 125, 139); @@ -145,16 +157,15 @@ namespace Discord throw new ArgumentOutOfRangeException(nameof(g), "Value must be within [0,255]."); if (b < 0 || b > 255) throw new ArgumentOutOfRangeException(nameof(b), "Value must be within [0,255]."); - RawValue = - ((uint)r << 16) | - ((uint)g << 8) | - (uint)b; + RawValue = ((uint)r << 16) + | ((uint)g << 8) + | (uint)b; } /// /// Initializes a struct with the given RGB float value. /// /// - /// The following will create a color that has a value of + /// The following will create a color that has a value of /// #607c8c. /// /// Color darkGrey = new Color(0.38f, 0.49f, 0.55f); @@ -172,10 +183,9 @@ namespace Discord throw new ArgumentOutOfRangeException(nameof(g), "Value must be within [0,1]."); if (b < 0.0f || b > 1.0f) throw new ArgumentOutOfRangeException(nameof(b), "Value must be within [0,1]."); - RawValue = - ((uint)(r * 255.0f) << 16) | - ((uint)(g * 255.0f) << 8) | - (uint)(b * 255.0f); + RawValue = ((uint)(r * 255.0f) << 16) + | ((uint)(g * 255.0f) << 8) + | (uint)(b * 255.0f); } public static bool operator ==(Color lhs, Color rhs) @@ -184,15 +194,22 @@ namespace Discord public static bool operator !=(Color lhs, Color rhs) => lhs.RawValue != rhs.RawValue; + public static implicit operator Color(uint rawValue) + => new(rawValue); + + public static implicit operator uint(Color color) + => color.RawValue; + public override bool Equals(object obj) - => (obj is Color c && RawValue == c.RawValue); + => obj is Color c && RawValue == c.RawValue; public override int GetHashCode() => RawValue.GetHashCode(); - public static implicit operator StandardColor(Color color) => - StandardColor.FromArgb((int)color.RawValue); - public static explicit operator Color(StandardColor color) => - new Color((uint)color.ToArgb() << 8 >> 8); + public static implicit operator StandardColor(Color color) + => StandardColor.FromArgb((int)color.RawValue); + + public static explicit operator Color(StandardColor color) + => new((uint)color.ToArgb() << 8 >> 8); /// /// Gets the hexadecimal representation of the color (e.g. #000ccc). diff --git a/src/Discord.Net.Core/Entities/Roles/IRole.cs b/src/Discord.Net.Core/Entities/Roles/IRole.cs index 66556fc2c..59ca41e31 100644 --- a/src/Discord.Net.Core/Entities/Roles/IRole.cs +++ b/src/Discord.Net.Core/Entities/Roles/IRole.cs @@ -52,6 +52,20 @@ namespace Discord /// string Name { get; } /// + /// Gets the icon of this role. + /// + /// + /// A string containing the hash of this role's icon. + /// + string Icon { get; } + /// + /// Gets the unicode emoji of this role. + /// + /// + /// This field is mutually exclusive with , either icon is set or emoji is set. + /// + Emoji Emoji { get; } + /// /// Gets the permissions granted to members of this role. /// /// @@ -65,6 +79,13 @@ namespace Discord /// An representing the position of the role in the role list of the guild. /// int Position { get; } + /// + /// Gets the tags related to this role. + /// + /// + /// A object containing all tags related to this role. + /// + RoleTags Tags { get; } /// /// Modifies this role. @@ -79,5 +100,13 @@ namespace Discord /// A task that represents the asynchronous modification operation. /// Task ModifyAsync(Action func, RequestOptions options = null); + + /// + /// Gets the image url of the icon role. + /// + /// + /// An image url of the icon role. + /// + string GetIconUrl(); } } diff --git a/src/Discord.Net.Core/Entities/Roles/RoleProperties.cs b/src/Discord.Net.Core/Entities/Roles/RoleProperties.cs index a58112b28..b6399c054 100644 --- a/src/Discord.Net.Core/Entities/Roles/RoleProperties.cs +++ b/src/Discord.Net.Core/Entities/Roles/RoleProperties.cs @@ -1,3 +1,5 @@ +using System; + namespace Discord { /// @@ -51,6 +53,24 @@ namespace Discord /// public Optional Hoist { get; set; } /// + /// Gets or sets the icon of the role. + /// + /// + /// This value cannot be set at the same time as Emoji, as they are both exclusive. + /// + /// Setting an Icon will override a currently existing Emoji if present. + /// + public Optional Icon { get; set; } + /// + /// Gets or sets the unicode emoji of the role. + /// + /// + /// This value cannot be set at the same time as Icon, as they are both exclusive. + /// + /// Setting an Emoji will override a currently existing Icon if present. + /// + public Optional Emoji { get; set; } + /// /// Gets or sets whether or not this role can be mentioned. /// /// diff --git a/src/Discord.Net.Core/Entities/Roles/RoleTags.cs b/src/Discord.Net.Core/Entities/Roles/RoleTags.cs new file mode 100644 index 000000000..d0cbd3580 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Roles/RoleTags.cs @@ -0,0 +1,40 @@ +namespace Discord +{ + /// + /// Provides tags related to a discord role. + /// + public class RoleTags + { + /// + /// Gets the identifier of the bot that this role belongs to, if it does. + /// + /// + /// A if this role belongs to a bot; otherwise + /// . + /// + public ulong? BotId { get; } + /// + /// Gets the identifier of the integration that this role belongs to, if it does. + /// + /// + /// A if this role belongs to an integration; otherwise + /// . + /// + public ulong? IntegrationId { get; } + /// + /// Gets if this role is the guild's premium subscriber (booster) role. + /// + /// + /// if this role is the guild's premium subscriber role; + /// otherwise . + /// + public bool IsPremiumSubscriberRole { get; } + + internal RoleTags(ulong? botId, ulong? integrationId, bool isPremiumSubscriber) + { + BotId = botId; + IntegrationId = integrationId; + IsPremiumSubscriberRole = isPremiumSubscriber; + } + } +} diff --git a/src/Discord.Net.Core/Entities/Stickers/ICustomSticker.cs b/src/Discord.Net.Core/Entities/Stickers/ICustomSticker.cs new file mode 100644 index 000000000..9cba38c80 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Stickers/ICustomSticker.cs @@ -0,0 +1,59 @@ +using System; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents a custom sticker within a guild. + /// + public interface ICustomSticker : ISticker + { + /// + /// Gets the users id who uploaded the sticker. + /// + /// + /// In order to get the author id, the bot needs the MANAGE_EMOJIS_AND_STICKERS permission. + /// + ulong? AuthorId { get; } + + /// + /// Gets the guild that this custom sticker is in. + /// + IGuild Guild { get; } + + /// + /// Modifies this sticker. + /// + /// + /// This method modifies this sticker with the specified properties. To see an example of this + /// method and what properties are available, please refer to . + ///
+ ///
+ /// The bot needs the MANAGE_EMOJIS_AND_STICKERS permission within the guild in order to modify stickers. + ///
+ /// + /// The following example replaces the name of the sticker with kekw. + /// + /// await sticker.ModifyAsync(x => x.Name = "kekw"); + /// + /// + /// A delegate containing the properties to modify the sticker with. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + Task ModifyAsync(Action func, RequestOptions options = null); + + /// + /// Deletes the current sticker. + /// + /// + /// The bot needs the MANAGE_EMOJIS_AND_STICKERS permission inside the guild in order to delete stickers. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous deletion operation. + /// + Task DeleteAsync(RequestOptions options = null); + } +} diff --git a/src/Discord.Net.Core/Entities/Stickers/ISticker.cs b/src/Discord.Net.Core/Entities/Stickers/ISticker.cs new file mode 100644 index 000000000..9deea753f --- /dev/null +++ b/src/Discord.Net.Core/Entities/Stickers/ISticker.cs @@ -0,0 +1,71 @@ +using System.Collections.Generic; + +namespace Discord +{ + /// + /// Represents a discord sticker. + /// + public interface ISticker : IStickerItem + { + /// + /// Gets the ID of this sticker. + /// + /// + /// A snowflake ID associated with this sticker. + /// + new ulong Id { get; } + /// + /// Gets the ID of the pack of this sticker. + /// + /// + /// A snowflake ID associated with the pack of this sticker. + /// + ulong PackId { get; } + /// + /// Gets the name of this sticker. + /// + /// + /// A with the name of this sticker. + /// + new string Name { get; } + /// + /// Gets the description of this sticker. + /// + /// + /// A with the description of this sticker. + /// + string Description { get; } + /// + /// Gets the list of tags of this sticker. + /// + /// + /// A read-only list with the tags of this sticker. + /// + IReadOnlyCollection Tags { get; } + /// + /// Gets the type of this sticker. + /// + StickerType Type { get; } + /// + /// Gets the format type of this sticker. + /// + /// + /// A with the format type of this sticker. + /// + new StickerFormatType Format { get; } + + /// + /// Gets whether this guild sticker can be used, may be false due to loss of Server Boosts. + /// + bool? IsAvailable { get; } + + /// + /// Gets the standard sticker's sort order within its pack. + /// + int? SortOrder { get; } + /// + /// Gets the image url for this sticker. + /// + string GetStickerUrl(); + } +} diff --git a/src/Discord.Net.Core/Entities/Stickers/IStickerItem.cs b/src/Discord.Net.Core/Entities/Stickers/IStickerItem.cs new file mode 100644 index 000000000..07ea63db9 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Stickers/IStickerItem.cs @@ -0,0 +1,23 @@ +namespace Discord +{ + /// + /// Represents a partial sticker item received with a message. + /// + public interface IStickerItem + { + /// + /// The id of the sticker. + /// + ulong Id { get; } + + /// + /// The name of the sticker. + /// + string Name { get; } + + /// + /// The format of the sticker. + /// + StickerFormatType Format { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Stickers/StickerPack.cs b/src/Discord.Net.Core/Entities/Stickers/StickerPack.cs new file mode 100644 index 000000000..c0c90aa69 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Stickers/StickerPack.cs @@ -0,0 +1,59 @@ +using System.Collections.Generic; +using System.Collections.Immutable; + +namespace Discord +{ + /// + /// Represents a discord sticker pack. + /// + /// The type of the stickers within the collection. + public class StickerPack where TSticker : ISticker + { + /// + /// Gets the id of the sticker pack. + /// + public ulong Id { get; } + + /// + /// Gets a collection of the stickers in the pack. + /// + public IReadOnlyCollection Stickers { get; } + + /// + /// Gets the name of the sticker pack. + /// + public string Name { get; } + + /// + /// Gets the id of the pack's SKU. + /// + public ulong SkuId { get; } + + /// + /// Gets the id of a sticker in the pack which is shown as the pack's icon. + /// + public ulong? CoverStickerId { get; } + + /// + /// Gets the description of the sticker pack. + /// + public string Description { get; } + + /// + /// Gets the id of the sticker pack's banner image + /// + public ulong BannerAssetId { get; } + + internal StickerPack(string name, ulong id, ulong skuid, ulong? coverStickerId, string description, ulong bannerAssetId, IEnumerable stickers) + { + Name = name; + Id = id; + SkuId = skuid; + CoverStickerId = coverStickerId; + Description = description; + BannerAssetId = bannerAssetId; + + Stickers = stickers.ToImmutableArray(); + } + } +} diff --git a/src/Discord.Net.Core/Entities/Stickers/StickerProperties.cs b/src/Discord.Net.Core/Entities/Stickers/StickerProperties.cs new file mode 100644 index 000000000..5f51e5f3d --- /dev/null +++ b/src/Discord.Net.Core/Entities/Stickers/StickerProperties.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; + +namespace Discord +{ + /// + /// Represents a class used to modify stickers. + /// + public class StickerProperties + { + /// + /// Gets or sets the name of the sticker. + /// + public Optional Name { get; set; } + + /// + /// Gets or sets the description of the sticker. + /// + public Optional Description { get; set; } + + /// + /// Gets or sets the tags of the sticker. + /// + public Optional> Tags { get; set; } + } +} diff --git a/src/Discord.Net.Core/Entities/Stickers/StickerType.cs b/src/Discord.Net.Core/Entities/Stickers/StickerType.cs new file mode 100644 index 000000000..0db550772 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Stickers/StickerType.cs @@ -0,0 +1,18 @@ +namespace Discord +{ + /// + /// Represents a type of sticker.. + /// + public enum StickerType + { + /// + /// Represents a discord standard sticker, this type of sticker cannot be modified by an application. + /// + Standard = 1, + + /// + /// Represents a sticker that was created within a guild. + /// + Guild = 2 + } +} diff --git a/src/Discord.Net.Core/Entities/Teams/ITeam.cs b/src/Discord.Net.Core/Entities/Teams/ITeam.cs new file mode 100644 index 000000000..b6e3d987b --- /dev/null +++ b/src/Discord.Net.Core/Entities/Teams/ITeam.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; + +namespace Discord +{ + /// + /// Represents a Discord Team. + /// + public interface ITeam + { + /// + /// Gets the team icon url. + /// + string IconUrl { get; } + /// + /// Gets the team unique identifier. + /// + ulong Id { get; } + /// + /// Gets the members of this team. + /// + IReadOnlyList TeamMembers { get; } + /// + /// Gets the name of this team. + /// + string Name { get; } + /// + /// Gets the user identifier that owns this team. + /// + ulong OwnerUserId { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Teams/ITeamMember.cs b/src/Discord.Net.Core/Entities/Teams/ITeamMember.cs new file mode 100644 index 000000000..fe0e499e5 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Teams/ITeamMember.cs @@ -0,0 +1,25 @@ +namespace Discord +{ + /// + /// Represents a Discord Team member. + /// + public interface ITeamMember + { + /// + /// Gets the membership state of this team member. + /// + MembershipState MembershipState { get; } + /// + /// Gets the permissions of this team member. + /// + string[] Permissions { get; } + /// + /// Gets the team unique identifier for this team member. + /// + ulong TeamId { get; } + /// + /// Gets the Discord user of this team member. + /// + IUser User { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Teams/MembershipState.cs b/src/Discord.Net.Core/Entities/Teams/MembershipState.cs new file mode 100644 index 000000000..45b1693b0 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Teams/MembershipState.cs @@ -0,0 +1,11 @@ +namespace Discord +{ + /// + /// Represents the membership state of a team member. + /// + public enum MembershipState + { + Invited, + Accepted, + } +} diff --git a/src/Discord.Net.Core/Entities/Users/GuildUserProperties.cs b/src/Discord.Net.Core/Entities/Users/GuildUserProperties.cs index 8f2d2111e..935b956c3 100644 --- a/src/Discord.Net.Core/Entities/Users/GuildUserProperties.cs +++ b/src/Discord.Net.Core/Entities/Users/GuildUserProperties.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; namespace Discord @@ -72,6 +73,14 @@ namespace Discord /// /// This user MUST already be in a for this to work. /// - public Optional ChannelId { get; set; } // TODO: v3 breaking change, change ChannelId to ulong? to allow for kicking users from voice + public Optional ChannelId { get; set; } + + /// + /// Sets a timestamp how long a user should be timed out for. + /// + /// + /// or a time in the past to clear a currently existing timeout. + /// + public Optional TimedOutUntil { get; set; } } } diff --git a/src/Discord.Net.Core/Entities/Users/IGuildUser.cs b/src/Discord.Net.Core/Entities/Users/IGuildUser.cs index 60fa06cbd..95896eef0 100644 --- a/src/Discord.Net.Core/Entities/Users/IGuildUser.cs +++ b/src/Discord.Net.Core/Entities/Users/IGuildUser.cs @@ -25,6 +25,13 @@ namespace Discord /// string Nickname { get; } /// + /// Gets the guild specific avatar for this users. + /// + /// + /// The users guild avatar hash if they have one; otherwise . + /// + string GuildAvatarId { get; } + /// /// Gets the guild-level permissions for this user. /// /// @@ -68,13 +75,34 @@ namespace Discord /// IReadOnlyCollection RoleIds { get; } + /// + /// Whether the user has passed the guild's Membership Screening requirements. + /// + bool? IsPending { get; } + + /// + /// Gets the users position within the role hierarchy. + /// + int Hierarchy { get; } + + /// + /// Gets the date and time that indicates if and for how long a user has been timed out. + /// + /// + /// or a timestamp in the past if the user is not timed out. + /// + /// + /// A indicating how long the user will be timed out for. + /// + DateTimeOffset? TimedOutUntil { get; } + /// /// Gets the level permissions granted to this user to a given channel. /// /// /// The following example checks if the current user has the ability to send a message with attachment in - /// this channel; if so, uploads a file via . - /// + /// this channel; if so, uploads a file via . + /// /// if (currentUser?.GetPermissions(targetChannel)?.AttachFiles) /// await targetChannel.SendFileAsync("fortnite.png"); /// @@ -86,6 +114,20 @@ namespace Discord /// ChannelPermissions GetPermissions(IGuildChannel channel); + /// + /// Gets the guild avatar URL for this user. + /// + /// + /// This property retrieves a URL for this guild user's guild specific avatar. In event that the user does not have a valid guild avatar + /// (i.e. their avatar identifier is not set), this method will return null. + /// + /// The format to return. + /// The size of the image to return in. This can be any power of two between 16 and 2048. + /// + /// + /// A string representing the user's avatar URL; null if the user does not have an avatar in place. + /// + string GetGuildAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128); /// /// Kicks this user from this guild. /// @@ -108,7 +150,15 @@ namespace Discord /// A task that represents the asynchronous modification operation. /// Task ModifyAsync(Action func, RequestOptions options = null); - + /// + /// Adds the specified role to this user in the guild. + /// + /// The role to be added to the user. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous role addition operation. + /// + Task AddRoleAsync(ulong roleId, RequestOptions options = null); /// /// Adds the specified role to this user in the guild. /// @@ -119,6 +169,15 @@ namespace Discord /// Task AddRoleAsync(IRole role, RequestOptions options = null); /// + /// Adds the specified to this user in the guild. + /// + /// The roles to be added to the user. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous role addition operation. + /// + Task AddRolesAsync(IEnumerable roleIds, RequestOptions options = null); + /// /// Adds the specified to this user in the guild. /// /// The roles to be added to the user. @@ -128,6 +187,15 @@ namespace Discord /// Task AddRolesAsync(IEnumerable roles, RequestOptions options = null); /// + /// Removes the specified from this user in the guild. + /// + /// The role to be removed from the user. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous role removal operation. + /// + Task RemoveRoleAsync(ulong roleId, RequestOptions options = null); + /// /// Removes the specified from this user in the guild. /// /// The role to be removed from the user. @@ -137,6 +205,15 @@ namespace Discord /// Task RemoveRoleAsync(IRole role, RequestOptions options = null); /// + /// Removes the specified from this user in the guild. + /// + /// The roles to be removed from the user. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous role removal operation. + /// + Task RemoveRolesAsync(IEnumerable roleIds, RequestOptions options = null); + /// /// Removes the specified from this user in the guild. /// /// The roles to be removed from the user. @@ -145,5 +222,22 @@ namespace Discord /// A task that represents the asynchronous role removal operation. /// Task RemoveRolesAsync(IEnumerable roles, RequestOptions options = null); + /// + /// Sets a timeout based on provided to this user in the guild. + /// + /// The indicating how long a user should be timed out for. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous timeout creation operation. + /// + Task SetTimeOutAsync(TimeSpan span, RequestOptions options = null); + /// + /// Removes the current timeout from the user in this guild if one exists. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous timeout removal operation. + /// + Task RemoveTimeOutAsync(RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Entities/Users/IPresence.cs b/src/Discord.Net.Core/Entities/Users/IPresence.cs index 620eb907c..45babf481 100644 --- a/src/Discord.Net.Core/Entities/Users/IPresence.cs +++ b/src/Discord.Net.Core/Entities/Users/IPresence.cs @@ -1,4 +1,4 @@ -using System.Collections.Immutable; +using System.Collections.Generic; namespace Discord { @@ -7,10 +7,6 @@ namespace Discord ///
public interface IPresence { - /// - /// Gets the activity this user is currently doing. - /// - IActivity Activity { get; } /// /// Gets the current status of this user. /// @@ -18,6 +14,10 @@ namespace Discord /// /// Gets the set of clients where this user is currently active. /// - IImmutableSet ActiveClients { get; } + IReadOnlyCollection ActiveClients { get; } + /// + /// Gets the list of activities that this user currently has available. + /// + IReadOnlyCollection Activities { get; } } } diff --git a/src/Discord.Net.Core/Entities/Users/IUser.cs b/src/Discord.Net.Core/Entities/Users/IUser.cs index c36fb2326..2f79450f3 100644 --- a/src/Discord.Net.Core/Entities/Users/IUser.cs +++ b/src/Discord.Net.Core/Entities/Users/IUser.cs @@ -10,19 +10,20 @@ namespace Discord /// /// Gets the identifier of this user's avatar. /// - string AvatarId { get; } + string AvatarId { get; } /// /// Gets the avatar URL for this user. /// /// /// This property retrieves a URL for this user's avatar. In event that the user does not have a valid avatar - /// (i.e. their avatar identifier is not set), this property will return null. If you wish to + /// (i.e. their avatar identifier is not set), this method will return null. If you wish to /// retrieve the default avatar for this user, consider using (see /// example). /// /// - /// The following example attempts to retrieve the user's current avatar and send it to a channel; if one is - /// not set, a default avatar for this user will be returned instead. + /// The following example attempts to retrieve the user's current avatar and send it to a channel; if one is + /// not set, a default avatar for this user will be returned instead. /// /// @@ -75,16 +76,26 @@ namespace Discord /// Gets the username for this user. ///
string Username { get; } + /// + /// Gets the public flags that are applied to this user's account. + /// + /// + /// This value is determined by bitwise OR-ing values together. + /// + /// + /// The value of public flags for this user. + /// + UserProperties? PublicFlags { get; } /// - /// Gets the direct message channel of this user, or create one if it does not already exist. + /// Creates the direct message channel of this user. /// /// /// This method is used to obtain or create a channel used to send a direct message. /// /// In event that the current user cannot send a message to the target user, a channel can and will - /// still be created by Discord. However, attempting to send a message will yield a - /// with a 403 as its + /// still be created by Discord. However, attempting to send a message will yield a + /// with a 403 as its /// . There are currently no official workarounds by /// Discord. /// @@ -92,7 +103,7 @@ namespace Discord /// /// The following example attempts to send a direct message to the target user and logs the incident should /// it fail. - /// /// /// The options to be used when sending the request. @@ -100,6 +111,6 @@ namespace Discord /// A task that represents the asynchronous operation for getting or creating a DM channel. The task result /// contains the DM channel associated with this user. /// - Task GetOrCreateDMChannelAsync(RequestOptions options = null); + Task CreateDMChannelAsync(RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Entities/Users/IVoiceState.cs b/src/Discord.Net.Core/Entities/Users/IVoiceState.cs index a9b347003..c9a22761f 100644 --- a/src/Discord.Net.Core/Entities/Users/IVoiceState.cs +++ b/src/Discord.Net.Core/Entities/Users/IVoiceState.cs @@ -1,3 +1,5 @@ +using System; + namespace Discord { /// @@ -62,5 +64,9 @@ namespace Discord /// true if the user is streaming; otherwise false. /// bool IsStreaming { get; } + /// + /// Gets the time on which the user requested to speak. + /// + DateTimeOffset? RequestToSpeakTimestamp { get; } } } diff --git a/src/Discord.Net.Core/Entities/Users/UserProperties.cs b/src/Discord.Net.Core/Entities/Users/UserProperties.cs index 4f7272daa..4cf4162a9 100644 --- a/src/Discord.Net.Core/Entities/Users/UserProperties.cs +++ b/src/Discord.Net.Core/Entities/Users/UserProperties.cs @@ -10,32 +10,64 @@ namespace Discord /// None = 0, /// - /// Flag given to Discord staff. + /// Flag given to users who are a Discord employee. /// - Staff = 0b1, + Staff = 1 << 0, /// - /// Flag given to Discord partners. + /// Flag given to users who are owners of a partnered Discord server. /// - Partner = 0b10, + Partner = 1 << 1, /// - /// Flag given to users who have participated in the bug report program. + /// Flag given to users in HypeSquad events. /// - BugHunter = 0b1000, + HypeSquadEvents = 1 << 2, + /// + /// Flag given to users who have participated in the bug report program and are level 1. + /// + BugHunterLevel1 = 1 << 3, /// /// Flag given to users who are in the HypeSquad House of Bravery. /// - HypeSquadBravery = 0b100_0000, + HypeSquadBravery = 1 << 6, /// /// Flag given to users who are in the HypeSquad House of Brilliance. /// - HypeSquadBrilliance = 0b1000_0000, + HypeSquadBrilliance = 1 << 7, /// /// Flag given to users who are in the HypeSquad House of Balance. /// - HypeSquadBalance = 0b1_0000_0000, + HypeSquadBalance = 1 << 8, /// /// Flag given to users who subscribed to Nitro before games were added. /// - EarlySupporter = 0b10_0000_0000, + EarlySupporter = 1 << 9, + /// + /// Flag given to users who are part of a team. + /// + TeamUser = 1 << 10, + /// + /// Flag given to users who represent Discord (System). + /// + System = 1 << 12, + /// + /// Flag given to users who have participated in the bug report program and are level 2. + /// + BugHunterLevel2 = 1 << 14, + /// + /// Flag given to users who are verified bots. + /// + VerifiedBot = 1 << 16, + /// + /// Flag given to users that developed bots and early verified their accounts. + /// + EarlyVerifiedBotDeveloper = 1 << 17, + /// + /// Flag given to users that are discord certified moderators who has give discord's exam. + /// + DiscordCertifiedModerator = 1 << 18, + /// + /// Flag given to bots that use only outgoing webhooks, exclusively. + /// + BotHTTPInteractions = 1 << 19, } } diff --git a/src/Discord.Net.Core/Entities/Webhooks/IWebhook.cs b/src/Discord.Net.Core/Entities/Webhooks/IWebhook.cs index b2d017316..d5bc70d71 100644 --- a/src/Discord.Net.Core/Entities/Webhooks/IWebhook.cs +++ b/src/Discord.Net.Core/Entities/Webhooks/IWebhook.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; namespace Discord @@ -49,6 +49,11 @@ namespace Discord ///
IUser Creator { get; } + /// + /// Gets the ID of the application owning this webhook. + /// + ulong? ApplicationId { get; } + /// /// Modifies this webhook. /// diff --git a/src/Discord.Net.Core/Extensions/EmbedBuilderExtensions.cs b/src/Discord.Net.Core/Extensions/EmbedBuilderExtensions.cs index a3b8ddd5b..c05df7cb7 100644 --- a/src/Discord.Net.Core/Extensions/EmbedBuilderExtensions.cs +++ b/src/Discord.Net.Core/Extensions/EmbedBuilderExtensions.cs @@ -27,7 +27,7 @@ namespace Discord /// Fills the embed author field with the provided user's full username and avatar URL. public static EmbedBuilder WithAuthor(this EmbedBuilder builder, IUser user) => - builder.WithAuthor($"{user.Username}#{user.Discriminator}", user.GetAvatarUrl()); + builder.WithAuthor($"{user.Username}#{user.Discriminator}", user.GetAvatarUrl() ?? user.GetDefaultAvatarUrl()); /// Converts a object to a . /// The embed type is not . diff --git a/src/Discord.Net.Core/Extensions/GuildExtensions.cs b/src/Discord.Net.Core/Extensions/GuildExtensions.cs index 58b749cc4..9dd8de82e 100644 --- a/src/Discord.Net.Core/Extensions/GuildExtensions.cs +++ b/src/Discord.Net.Core/Extensions/GuildExtensions.cs @@ -20,5 +20,21 @@ namespace Discord /// A bool indicating if the guild boost messages are enabled in the system channel. public static bool GetGuildBoostMessagesEnabled(this IGuild guild) => !guild.SystemChannelFlags.HasFlag(SystemChannelMessageDeny.GuildBoost); + + /// + /// Gets if guild setup system messages are enabled. + /// + /// The guild to check. + /// A bool indicating if the guild setup messages are enabled in the system channel. + public static bool GetGuildSetupTipMessagesEnabled(this IGuild guild) + => !guild.SystemChannelFlags.HasFlag(SystemChannelMessageDeny.GuildSetupTip); + + /// + /// Gets if guild welcome messages have a reply with sticker button. + /// + /// The guild to check. + /// A bool indicating if the guild welcome messages have a reply with sticker button. + public static bool GetGuildWelcomeMessageReplyEnabled(this IGuild guild) + => !guild.SystemChannelFlags.HasFlag(SystemChannelMessageDeny.WelcomeMessageReply); } } diff --git a/src/Discord.Net.Core/Extensions/MessageExtensions.cs b/src/Discord.Net.Core/Extensions/MessageExtensions.cs index 64a1d89ab..c187ecd5b 100644 --- a/src/Discord.Net.Core/Extensions/MessageExtensions.cs +++ b/src/Discord.Net.Core/Extensions/MessageExtensions.cs @@ -17,14 +17,14 @@ namespace Discord public static string GetJumpUrl(this IMessage msg) { var channel = msg.Channel; - return $"https://discordapp.com/channels/{(channel is IDMChannel ? "@me" : $"{(channel as ITextChannel).GuildId}")}/{channel.Id}/{msg.Id}"; + return $"https://discord.com/channels/{(channel is IDMChannel ? "@me" : $"{(channel as ITextChannel).GuildId}")}/{channel.Id}/{msg.Id}"; } /// /// Add multiple reactions to a message. /// /// - /// This method does not bulk add reactions! It will send a request for each reaction inculded. + /// This method does not bulk add reactions! It will send a request for each reaction included. /// /// /// @@ -34,7 +34,7 @@ namespace Discord /// /// /// The message to add reactions to. - /// An array of reactions to add to the message + /// An array of reactions to add to the message. /// The options to be used when sending the request. /// /// A task that represents the asynchronous operation for adding a reaction to this message. @@ -59,7 +59,8 @@ namespace Discord /// ///
/// The message to remove reactions from. - /// An array of reactions to remove from the message + /// The user who removed the reaction. + /// An array of reactions to remove from the message. /// The options to be used when sending the request. /// /// A task that represents the asynchronous operation for removing a reaction to this message. @@ -71,5 +72,29 @@ namespace Discord foreach (var rxn in reactions) await msg.RemoveReactionAsync(rxn, user, options).ConfigureAwait(false); } + + /// + /// Sends an inline reply that references a message. + /// + /// The message that is being replied on. + /// The message to be sent. + /// Determines whether the message should be read aloud by Discord or not. + /// The to be sent. + /// A array of s to send with this response. Max 10. + /// + /// Specifies if notifications are sent for mentioned users and roles in the message . + /// If null, all mentioned roles and users will be notified. + /// + /// The options to be used when sending the request. + /// The message components to be included with this message. Used for interactions. + /// A collection of stickers to send with the message. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + public static async Task ReplyAsync(this IUserMessage msg, string text = null, bool isTTS = false, Embed embed = null, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + { + return await msg.Channel.SendMessageAsync(text, isTTS, embed, options, allowedMentions, new MessageReference(messageId: msg.Id), components, stickers, embeds).ConfigureAwait(false); + } } } diff --git a/src/Discord.Net.Core/Extensions/ObjectExtensions.cs b/src/Discord.Net.Core/Extensions/ObjectExtensions.cs new file mode 100644 index 000000000..240fb47aa --- /dev/null +++ b/src/Discord.Net.Core/Extensions/ObjectExtensions.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + internal static class ObjectExtensions + { + public static bool IsNumericType(this object o) + { + switch (Type.GetTypeCode(o.GetType())) + { + case TypeCode.Byte: + case TypeCode.SByte: + case TypeCode.UInt16: + case TypeCode.UInt32: + case TypeCode.UInt64: + case TypeCode.Int16: + case TypeCode.Int32: + case TypeCode.Int64: + case TypeCode.Decimal: + case TypeCode.Double: + case TypeCode.Single: + return true; + default: + return false; + } + } + } +} diff --git a/src/Discord.Net.Core/Extensions/StringExtensions.cs b/src/Discord.Net.Core/Extensions/StringExtensions.cs deleted file mode 100644 index c0ebb2626..000000000 --- a/src/Discord.Net.Core/Extensions/StringExtensions.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace Discord -{ - internal static class StringExtensions - { - public static bool IsNullOrUri(this string url) => - string.IsNullOrEmpty(url) || Uri.IsWellFormedUriString(url, UriKind.Absolute); - } -} diff --git a/src/Discord.Net.Core/Extensions/UserExtensions.cs b/src/Discord.Net.Core/Extensions/UserExtensions.cs index 90f26828a..ce914170d 100644 --- a/src/Discord.Net.Core/Extensions/UserExtensions.cs +++ b/src/Discord.Net.Core/Extensions/UserExtensions.cs @@ -32,6 +32,8 @@ namespace Discord /// Specifies if notifications are sent for mentioned users and roles in the message . /// If null, all mentioned roles and users will be notified. /// + /// The message components to be included with this message. Used for interactions. + /// A array of s to send with this response. Max 10. /// /// A task that represents the asynchronous send operation. The task result contains the sent message. /// @@ -40,9 +42,11 @@ namespace Discord bool isTTS = false, Embed embed = null, RequestOptions options = null, - AllowedMentions allowedMentions = null) + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed[] embeds = null) { - return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendMessageAsync(text, isTTS, embed, options, allowedMentions).ConfigureAwait(false); + return await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendMessageAsync(text, isTTS, embed, options, allowedMentions, components: components, embeds: embeds).ConfigureAwait(false); } /// @@ -81,6 +85,8 @@ namespace Discord /// Whether the message should be read aloud by Discord or not. /// The to be sent. /// The options to be used when sending the request. + /// The message component to be included with this message. Used for interactions. + /// A array of s to send with this response. Max 10. /// /// A task that represents an asynchronous send operation for delivering the message. The task result /// contains the sent message. @@ -91,10 +97,11 @@ namespace Discord string text = null, bool isTTS = false, Embed embed = null, - RequestOptions options = null - ) + RequestOptions options = null, + MessageComponent components = null, + Embed[] embeds = null) { - return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(stream, filename, text, isTTS, embed, options).ConfigureAwait(false); + return await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(stream, filename, text, isTTS, embed, options, components: components, embeds: embeds).ConfigureAwait(false); } /// @@ -138,6 +145,8 @@ namespace Discord /// Whether the message should be read aloud by Discord or not. /// The to be sent. /// The options to be used when sending the request. + /// The message component to be included with this message. Used for interactions. + /// A array of s to send with this response. Max 10. /// /// A task that represents an asynchronous send operation for delivering the message. The task result /// contains the sent message. @@ -147,9 +156,11 @@ namespace Discord string text = null, bool isTTS = false, Embed embed = null, - RequestOptions options = null) + RequestOptions options = null, + MessageComponent components = null, + Embed[] embeds = null) { - return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false); + return await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(filePath, text, isTTS, embed, options, components: components, embeds: embeds).ConfigureAwait(false); } /// diff --git a/src/Discord.Net.Core/Format.cs b/src/Discord.Net.Core/Format.cs index 0ab70f89c..a5951aa73 100644 --- a/src/Discord.Net.Core/Format.cs +++ b/src/Discord.Net.Core/Format.cs @@ -1,4 +1,5 @@ using System.Text; +using System.Text.RegularExpressions; namespace Discord { @@ -6,7 +7,8 @@ namespace Discord public static class Format { // Characters which need escaping - private static readonly string[] SensitiveCharacters = { "\\", "*", "_", "~", "`", "|", ">" }; + private static readonly string[] SensitiveCharacters = { + "\\", "*", "_", "~", "`", ".", ":", "/", ">", "|" }; /// Returns a markdown-formatted string with bold formatting. public static string Bold(string text) => $"**{text}**"; @@ -14,7 +16,7 @@ namespace Discord public static string Italics(string text) => $"*{text}*"; /// Returns a markdown-formatted string with underline formatting. public static string Underline(string text) => $"__{text}__"; - /// Returns a markdown-formatted string with strikethrough formatting. + /// Returns a markdown-formatted string with strike-through formatting. public static string Strikethrough(string text) => $"~~{text}~~"; /// Returns a string with spoiler formatting. public static string Spoiler(string text) => $"||{text}||"; @@ -91,5 +93,27 @@ namespace Discord return $">>> {text}"; } + + /// + /// Remove discord supported markdown from text. + /// + /// The to remove markdown from. + /// Gets the unformatted text. + public static string StripMarkDown(string text) + { + //Remove discord supported markdown + var newText = Regex.Replace(text, @"(\*|_|`|~|>|\\)", ""); + return newText; + } + + /// + /// Formats a user's username + discriminator while maintaining bidirectional unicode + /// + /// The user whos username and discriminator to format + /// The username + discriminator + public static string UsernameAndDiscriminator(IUser user) + { + return $"\u2066{user.Username}\u2069#{user.Discriminator}"; + } } } diff --git a/src/Discord.Net.Core/GatewayIntents.cs b/src/Discord.Net.Core/GatewayIntents.cs new file mode 100644 index 000000000..f2a99e44c --- /dev/null +++ b/src/Discord.Net.Core/GatewayIntents.cs @@ -0,0 +1,56 @@ +using System; + +namespace Discord +{ + [Flags] + public enum GatewayIntents + { + /// This intent includes no events + None = 0, + /// This intent includes GUILD_CREATE, GUILD_UPDATE, GUILD_DELETE, GUILD_ROLE_CREATE, GUILD_ROLE_UPDATE, GUILD_ROLE_DELETE, CHANNEL_CREATE, CHANNEL_UPDATE, CHANNEL_DELETE, CHANNEL_PINS_UPDATE + Guilds = 1 << 0, + /// This intent includes GUILD_MEMBER_ADD, GUILD_MEMBER_UPDATE, GUILD_MEMBER_REMOVE + /// This is a privileged intent and must be enabled in the Developer Portal. + GuildMembers = 1 << 1, + /// This intent includes GUILD_BAN_ADD, GUILD_BAN_REMOVE + GuildBans = 1 << 2, + /// This intent includes GUILD_EMOJIS_UPDATE + GuildEmojis = 1 << 3, + /// This intent includes GUILD_INTEGRATIONS_UPDATE + GuildIntegrations = 1 << 4, + /// This intent includes WEBHOOKS_UPDATE + GuildWebhooks = 1 << 5, + /// This intent includes INVITE_CREATE, INVITE_DELETE + GuildInvites = 1 << 6, + /// This intent includes VOICE_STATE_UPDATE + GuildVoiceStates = 1 << 7, + /// This intent includes PRESENCE_UPDATE + /// This is a privileged intent and must be enabled in the Developer Portal. + GuildPresences = 1 << 8, + /// This intent includes MESSAGE_CREATE, MESSAGE_UPDATE, MESSAGE_DELETE, MESSAGE_DELETE_BULK + GuildMessages = 1 << 9, + /// This intent includes MESSAGE_REACTION_ADD, MESSAGE_REACTION_REMOVE, MESSAGE_REACTION_REMOVE_ALL, MESSAGE_REACTION_REMOVE_EMOJI + GuildMessageReactions = 1 << 10, + /// This intent includes TYPING_START + GuildMessageTyping = 1 << 11, + /// This intent includes CHANNEL_CREATE, MESSAGE_CREATE, MESSAGE_UPDATE, MESSAGE_DELETE, CHANNEL_PINS_UPDATE + DirectMessages = 1 << 12, + /// This intent includes MESSAGE_REACTION_ADD, MESSAGE_REACTION_REMOVE, MESSAGE_REACTION_REMOVE_ALL, MESSAGE_REACTION_REMOVE_EMOJI + DirectMessageReactions = 1 << 13, + /// This intent includes TYPING_START + DirectMessageTyping = 1 << 14, + /// This intent includes GUILD_SCHEDULED_EVENT_CREATE, GUILD_SCHEDULED_EVENT_UPDATE, GUILD_SCHEDULED_EVENT_DELETE, GUILD_SCHEDULED_EVENT_USER_ADD, GUILD_SCHEDULED_EVENT_USER_REMOVE + GuildScheduledEvents = 1 << 16, + /// + /// This intent includes all but and + /// which are privileged and must be enabled in the Developer Portal. + /// + AllUnprivileged = Guilds | GuildBans | GuildEmojis | GuildIntegrations | GuildWebhooks | GuildInvites | + GuildVoiceStates | GuildMessages | GuildMessageReactions | GuildMessageTyping | DirectMessages | + DirectMessageReactions | DirectMessageTyping | GuildScheduledEvents, + /// + /// This intent includes all of them, including privileged ones. + /// + All = AllUnprivileged | GuildMembers | GuildPresences + } +} diff --git a/src/Discord.Net.Core/IDiscordClient.cs b/src/Discord.Net.Core/IDiscordClient.cs index 848a97405..14e156769 100644 --- a/src/Discord.Net.Core/IDiscordClient.cs +++ b/src/Discord.Net.Core/IDiscordClient.cs @@ -141,6 +141,47 @@ namespace Discord /// Task> GetConnectionsAsync(RequestOptions options = null); + /// + /// Gets a global application command. + /// + /// The id of the command. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the application command if found, otherwise + /// . + /// + Task GetGlobalApplicationCommandAsync(ulong id, RequestOptions options = null); + + /// + /// Gets a collection of all global commands. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a read-only collection of global + /// application commands. + /// + Task> GetGlobalApplicationCommandsAsync(RequestOptions options = null); + + /// + /// Creates a global application command. + /// + /// The properties to use when creating the command. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the created application command. + /// + Task CreateGlobalApplicationCommand(ApplicationCommandProperties properties, RequestOptions options = null); + + /// + /// Bulk overwrites all global application commands. + /// + /// A collection of properties to use when creating the commands. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains a collection of application commands that were created. + /// + Task> BulkOverwriteGlobalApplicationCommand(ApplicationCommandProperties[] properties, RequestOptions options = null); + /// /// Gets a guild. /// @@ -274,5 +315,15 @@ namespace Discord /// that represents the number of shards that should be used with this account. /// Task GetRecommendedShardCountAsync(RequestOptions options = null); + + /// + /// Gets the gateway information related to the bot. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a + /// that represents the gateway information related to the bot. + /// + Task GetBotGatewayAsync(RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Interactions/IInteractionContext.cs b/src/Discord.Net.Core/Interactions/IInteractionContext.cs new file mode 100644 index 000000000..3b5ba521d --- /dev/null +++ b/src/Discord.Net.Core/Interactions/IInteractionContext.cs @@ -0,0 +1,36 @@ +namespace Discord +{ + /// + /// Represents the context of an Interaction. + /// + public interface IInteractionContext + { + /// + /// Gets the client that will be used to handle this interaction. + /// + IDiscordClient Client { get; } + + /// + /// Gets the guild the interaction originated from. + /// + /// + /// Will be if the interaction originated from a DM channel or the interaction was a Context Command interaction. + /// + IGuild Guild { get; } + + /// + /// Gets the channel the interaction originated from. + /// + IMessageChannel Channel { get; } + + /// + /// Gets the user who invoked the interaction event. + /// + IUser User { get; } + + /// + /// Gets the underlying interaction. + /// + IDiscordInteraction Interaction { get; } + } +} diff --git a/src/Discord.Net.Core/Interactions/IRestInteractionContext.cs b/src/Discord.Net.Core/Interactions/IRestInteractionContext.cs new file mode 100644 index 000000000..2aa5156b4 --- /dev/null +++ b/src/Discord.Net.Core/Interactions/IRestInteractionContext.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + public interface IRestInteractionContext : IInteractionContext + { + /// + /// Gets or sets the callback to use when the service has outgoing json for the rest webhook. + /// + /// + /// If this property is the default callback will be used. + /// + Func InteractionResponseCallback { get; } + } +} diff --git a/src/Discord.Net.Core/Net/ApplicationCommandException.cs b/src/Discord.Net.Core/Net/ApplicationCommandException.cs new file mode 100644 index 000000000..4b4890d12 --- /dev/null +++ b/src/Discord.Net.Core/Net/ApplicationCommandException.cs @@ -0,0 +1,15 @@ +using System; +using System.Linq; + +namespace Discord.Net +{ + [Obsolete("Please use HttpException instead of this. Will be removed in next major version.", false)] + public class ApplicationCommandException : HttpException + { + public ApplicationCommandException(HttpException httpError) + : base(httpError.HttpCode, httpError.Request, httpError.DiscordCode, httpError.Reason, httpError.Errors.ToArray()) + { + + } + } +} diff --git a/src/Discord.Net.Core/Net/BucketId.cs b/src/Discord.Net.Core/Net/BucketId.cs new file mode 100644 index 000000000..96281a0ed --- /dev/null +++ b/src/Discord.Net.Core/Net/BucketId.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; + +namespace Discord.Net +{ + /// + /// Represents a ratelimit bucket. + /// + public class BucketId : IEquatable + { + /// + /// Gets the http method used to make the request if available. + /// + public string HttpMethod { get; } + /// + /// Gets the endpoint that is going to be requested if available. + /// + public string Endpoint { get; } + /// + /// Gets the major parameters of the route. + /// + public IOrderedEnumerable> MajorParameters { get; } + /// + /// Gets the hash of this bucket. + /// + /// + /// The hash is provided by Discord to group ratelimits. + /// + public string BucketHash { get; } + /// + /// Gets if this bucket is a hash type. + /// + public bool IsHashBucket { get => BucketHash != null; } + + private BucketId(string httpMethod, string endpoint, IEnumerable> majorParameters, string bucketHash) + { + HttpMethod = httpMethod; + Endpoint = endpoint; + MajorParameters = majorParameters.OrderBy(x => x.Key); + BucketHash = bucketHash; + } + + /// + /// Creates a new based on the + /// and . + /// + /// Http method used to make the request. + /// Endpoint that is going to receive requests. + /// Major parameters of the route of this endpoint. + /// + /// A based on the + /// and the with the provided data. + /// + public static BucketId Create(string httpMethod, string endpoint, Dictionary majorParams) + { + Preconditions.NotNullOrWhitespace(endpoint, nameof(endpoint)); + majorParams ??= new Dictionary(); + return new BucketId(httpMethod, endpoint, majorParams, null); + } + + /// + /// Creates a new based on a + /// and a previous . + /// + /// Bucket hash provided by Discord. + /// that is going to be upgraded to a hash type. + /// + /// A based on the + /// and . + /// + public static BucketId Create(string hash, BucketId oldBucket) + { + Preconditions.NotNullOrWhitespace(hash, nameof(hash)); + Preconditions.NotNull(oldBucket, nameof(oldBucket)); + return new BucketId(null, null, oldBucket.MajorParameters, hash); + } + + /// + /// Gets the string that will define this bucket as a hash based one. + /// + /// + /// A that defines this bucket as a hash based one. + /// + public string GetBucketHash() + => IsHashBucket ? $"{BucketHash}:{string.Join("/", MajorParameters.Select(x => x.Value))}" : null; + + /// + /// Gets the string that will define this bucket as an endpoint based one. + /// + /// + /// A that defines this bucket as an endpoint based one. + /// + public string GetUniqueEndpoint() + => HttpMethod != null ? $"{HttpMethod} {Endpoint}" : Endpoint; + + public override bool Equals(object obj) + => Equals(obj as BucketId); + + public override int GetHashCode() + => IsHashBucket ? (BucketHash, string.Join("/", MajorParameters.Select(x => x.Value))).GetHashCode() : (HttpMethod, Endpoint).GetHashCode(); + + public override string ToString() + => GetBucketHash() ?? GetUniqueEndpoint(); + + public bool Equals(BucketId other) + { + if (other is null) + return false; + if (ReferenceEquals(this, other)) + return true; + if (GetType() != other.GetType()) + return false; + return ToString() == other.ToString(); + } + } +} diff --git a/src/Discord.Net.Core/Net/HttpException.cs b/src/Discord.Net.Core/Net/HttpException.cs index d36bd66f9..07551f0e7 100644 --- a/src/Discord.Net.Core/Net/HttpException.cs +++ b/src/Discord.Net.Core/Net/HttpException.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Collections.Immutable; using System.Net; namespace Discord.Net @@ -13,7 +15,7 @@ namespace Discord.Net /// /// /// An - /// HTTP status code + /// HTTP status code /// from Discord. /// public HttpStatusCode HttpCode { get; } @@ -22,10 +24,10 @@ namespace Discord.Net /// /// /// A - /// JSON error code + /// JSON error code /// from Discord, or null if none. /// - public int? DiscordCode { get; } + public DiscordErrorCode? DiscordCode { get; } /// /// Gets the reason of the exception. /// @@ -34,6 +36,10 @@ namespace Discord.Net /// Gets the request object used to send the request. /// public IRequest Request { get; } + /// + /// Gets a collection of json errors describing what went wrong with the request. + /// + public IReadOnlyCollection Errors { get; } /// /// Initializes a new instance of the class. @@ -42,13 +48,14 @@ namespace Discord.Net /// The request that was sent prior to the exception. /// The Discord status code returned. /// The reason behind the exception. - public HttpException(HttpStatusCode httpCode, IRequest request, int? discordCode = null, string reason = null) - : base(CreateMessage(httpCode, discordCode, reason)) + public HttpException(HttpStatusCode httpCode, IRequest request, DiscordErrorCode? discordCode = null, string reason = null, DiscordJsonError[] errors = null) + : base(CreateMessage(httpCode, (int?)discordCode, reason)) { HttpCode = httpCode; Request = request; DiscordCode = discordCode; Reason = reason; + Errors = errors?.ToImmutableArray() ?? ImmutableArray.Empty; } private static string CreateMessage(HttpStatusCode httpCode, int? discordCode = null, string reason = null) diff --git a/src/Discord.Net.Core/Net/Rest/IRateLimitInfo.cs b/src/Discord.Net.Core/Net/Rest/IRateLimitInfo.cs new file mode 100644 index 000000000..816f25af4 --- /dev/null +++ b/src/Discord.Net.Core/Net/Rest/IRateLimitInfo.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + /// + /// Represents a generic ratelimit info. + /// + public interface IRateLimitInfo + { + /// + /// Gets whether or not this ratelimit info is global. + /// + bool IsGlobal { get; } + + /// + /// Gets the number of requests that can be made. + /// + int? Limit { get; } + + /// + /// Gets the number of remaining requests that can be made. + /// + int? Remaining { get; } + + /// + /// Gets the total time (in seconds) of when the current rate limit bucket will reset. Can have decimals to match previous millisecond ratelimit precision. + /// + int? RetryAfter { get; } + + /// + /// Gets the at which the rate limit resets. + /// + DateTimeOffset? Reset { get; } + + /// + /// Gets the absolute time when this ratelimit resets. + /// + TimeSpan? ResetAfter { get; } + + /// + /// Gets a unique string denoting the rate limit being encountered (non-inclusive of major parameters in the route path). + /// + string Bucket { get; } + + /// + /// Gets the amount of lag for the request. This is used to denote the precise time of when the ratelimit expires. + /// + TimeSpan? Lag { get; } + + /// + /// Gets the endpoint that this ratelimit info came from. + /// + string Endpoint { get; } + } +} diff --git a/src/Discord.Net.Core/Net/WebSocketClosedException.cs b/src/Discord.Net.Core/Net/WebSocketClosedException.cs index 6e2564f6e..c743cd696 100644 --- a/src/Discord.Net.Core/Net/WebSocketClosedException.cs +++ b/src/Discord.Net.Core/Net/WebSocketClosedException.cs @@ -11,7 +11,7 @@ namespace Discord.Net /// /// /// A - /// close code + /// close code /// from Discord. /// public int CloseCode { get; } diff --git a/src/Discord.Net.Core/RateLimitPrecision.cs b/src/Discord.Net.Core/RateLimitPrecision.cs deleted file mode 100644 index fe3c1b90e..000000000 --- a/src/Discord.Net.Core/RateLimitPrecision.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Discord -{ - /// - /// Specifies the level of precision to request in the rate limit - /// response header. - /// - public enum RateLimitPrecision - { - /// - /// Specifies precision rounded up to the nearest whole second - /// - Second, - /// - /// Specifies precision rounded to the nearest millisecond. - /// - Millisecond - } -} diff --git a/src/Discord.Net.Core/RequestOptions.cs b/src/Discord.Net.Core/RequestOptions.cs index 1b05df2a3..46aa2681f 100644 --- a/src/Discord.Net.Core/RequestOptions.cs +++ b/src/Discord.Net.Core/RequestOptions.cs @@ -1,4 +1,7 @@ +using Discord.Net; +using System; using System.Threading; +using System.Threading.Tasks; namespace Discord { @@ -13,10 +16,10 @@ namespace Discord public static RequestOptions Default => new RequestOptions(); /// - /// Gets or sets the maximum time to wait for for this request to complete. + /// Gets or sets the maximum time to wait for this request to complete. /// /// - /// Gets or set the max time, in milliseconds, to wait for for this request to complete. If + /// Gets or set the max time, in milliseconds, to wait for this request to complete. If /// null, a request will not time out. If a rate limit has been triggered for this request's bucket /// and will not be unpaused in time, this request will fail immediately. /// @@ -56,10 +59,16 @@ namespace Discord /// public bool? UseSystemClock { get; set; } + /// + /// Gets or sets the callback to execute regarding ratelimits for this request. + /// + public Func RatelimitCallback { get; set; } + internal bool IgnoreState { get; set; } - internal string BucketId { get; set; } + internal BucketId BucketId { get; set; } internal bool IsClientBucket { get; set; } internal bool IsReactionBucket { get; set; } + internal bool IsGatewayBucket { get; set; } internal static RequestOptions CreateOrClone(RequestOptions options) { @@ -69,6 +78,17 @@ namespace Discord return options.Clone(); } + internal void ExecuteRatelimitCallback(IRateLimitInfo info) + { + if (RatelimitCallback != null) + { + _ = Task.Run(async () => + { + await RatelimitCallback(info); + }); + } + } + /// /// Initializes a new class with the default request timeout set in /// . diff --git a/src/Discord.Net.Core/TokenType.cs b/src/Discord.Net.Core/TokenType.cs index 8ca3f031c..03b840830 100644 --- a/src/Discord.Net.Core/TokenType.cs +++ b/src/Discord.Net.Core/TokenType.cs @@ -5,8 +5,6 @@ namespace Discord /// Specifies the type of token to use with the client. public enum TokenType { - [Obsolete("User logins are deprecated and may result in a ToS strike against your account - please see https://github.com/RogueException/Discord.Net/issues/827", error: true)] - User, /// /// An OAuth2 token type. /// diff --git a/src/Discord.Net.Core/Utils/Cacheable.cs b/src/Discord.Net.Core/Utils/Cacheable.cs index 1857ae7a0..4aa768292 100644 --- a/src/Discord.Net.Core/Utils/Cacheable.cs +++ b/src/Discord.Net.Core/Utils/Cacheable.cs @@ -63,4 +63,60 @@ namespace Discord /// public async Task GetOrDownloadAsync() => HasValue ? Value : await DownloadAsync().ConfigureAwait(false); } + public struct Cacheable + where TCachedEntity : IEntity, TRelationship + where TDownloadableEntity : IEntity, TRelationship + where TId : IEquatable + { + /// + /// Gets whether this entity is cached. + /// + public bool HasValue { get; } + /// + /// Gets the ID of this entity. + /// + public TId Id { get; } + /// + /// Gets the entity if it could be pulled from cache. + /// + /// + /// This value is not guaranteed to be set; in cases where the entity cannot be pulled from cache, it is + /// null. + /// + public TCachedEntity Value { get; } + private Func> DownloadFunc { get; } + + internal Cacheable(TCachedEntity value, TId id, bool hasValue, Func> downloadFunc) + { + Value = value; + Id = id; + HasValue = hasValue; + DownloadFunc = downloadFunc; + } + + /// + /// Downloads this entity. + /// + /// Thrown when used from a user account. + /// Thrown when the message is deleted. + /// + /// A task that represents the asynchronous download operation. The task result contains the downloaded + /// entity. + /// + public async Task DownloadAsync() + { + return await DownloadFunc().ConfigureAwait(false); + } + + /// + /// Returns the cached entity if it exists; otherwise downloads it. + /// + /// Thrown when used from a user account. + /// Thrown when the message is deleted and is not in cache. + /// + /// A task that represents the asynchronous operation that attempts to get the message via cache or to + /// download the message. The task result contains the downloaded entity. + /// + public async Task GetOrDownloadAsync() => HasValue ? Value : await DownloadAsync().ConfigureAwait(false); + } } diff --git a/src/Discord.Net.Core/Utils/Comparers.cs b/src/Discord.Net.Core/Utils/Comparers.cs index 7ec9f5c74..3c7b8aa3c 100644 --- a/src/Discord.Net.Core/Utils/Comparers.cs +++ b/src/Discord.Net.Core/Utils/Comparers.cs @@ -41,16 +41,13 @@ namespace Discord { public override bool Equals(TEntity x, TEntity y) { - bool xNull = x == null; - bool yNull = y == null; - - if (xNull && yNull) - return true; - - if (xNull ^ yNull) - return false; - - return x.Id.Equals(y.Id); + return (x, y) switch + { + (null, null) => true, + (null, _) => false, + (_, null) => false, + var (l, r) => l.Id.Equals(r.Id) + }; } public override int GetHashCode(TEntity obj) diff --git a/src/Discord.Net.Core/Utils/MentionUtils.cs b/src/Discord.Net.Core/Utils/MentionUtils.cs index 6ffb7eee6..059df6b5a 100644 --- a/src/Discord.Net.Core/Utils/MentionUtils.cs +++ b/src/Discord.Net.Core/Utils/MentionUtils.cs @@ -40,6 +40,7 @@ namespace Discord /// /// Parses a provided user mention string. /// + /// The user mention. /// Invalid mention format. public static ulong ParseUser(string text) { @@ -50,6 +51,8 @@ namespace Discord /// /// Tries to parse a provided user mention string. /// + /// The user mention. + /// The UserId of the user. public static bool TryParseUser(string text, out ulong userId) { if (text.Length >= 3 && text[0] == '<' && text[1] == '@' && text[text.Length - 1] == '>') diff --git a/src/Discord.Net.Core/Utils/Optional.cs b/src/Discord.Net.Core/Utils/Optional.cs index 348179699..985be9240 100644 --- a/src/Discord.Net.Core/Utils/Optional.cs +++ b/src/Discord.Net.Core/Utils/Optional.cs @@ -7,7 +7,7 @@ namespace Discord [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public struct Optional { - public static Optional Unspecified => default(Optional); + public static Optional Unspecified => default; private readonly T _value; /// Gets the value for this parameter. @@ -43,18 +43,18 @@ namespace Discord public override int GetHashCode() => IsSpecified ? _value.GetHashCode() : 0; public override string ToString() => IsSpecified ? _value?.ToString() : null; - private string DebuggerDisplay => IsSpecified ? (_value?.ToString() ?? "") : ""; + private string DebuggerDisplay => IsSpecified ? _value?.ToString() ?? "" : ""; - public static implicit operator Optional(T value) => new Optional(value); + public static implicit operator Optional(T value) => new(value); public static explicit operator T(Optional value) => value.Value; } public static class Optional { public static Optional Create() => Optional.Unspecified; - public static Optional Create(T value) => new Optional(value); + public static Optional Create(T value) => new(value); public static T? ToNullable(this Optional val) where T : struct - => val.IsSpecified ? val.Value : (T?)null; + => val.IsSpecified ? val.Value : null; } } diff --git a/src/Discord.Net.Core/Utils/Preconditions.cs b/src/Discord.Net.Core/Utils/Preconditions.cs index 60415852c..ff8eb7c0d 100644 --- a/src/Discord.Net.Core/Utils/Preconditions.cs +++ b/src/Discord.Net.Core/Utils/Preconditions.cs @@ -4,7 +4,7 @@ namespace Discord { internal static class Preconditions { - //Objects + #region Objects /// must not be . public static void NotNull(T obj, string name, string msg = null) where T : class { if (obj == null) throw CreateNotNullException(name, msg); } /// must not be . @@ -15,8 +15,9 @@ namespace Discord if (msg == null) return new ArgumentNullException(paramName: name); else return new ArgumentNullException(paramName: name, message: msg); } + #endregion - //Strings + #region Strings /// cannot be blank. public static void NotEmpty(string obj, string name, string msg = null) { if (obj.Length == 0) throw CreateNotEmptyException(name, msg); } /// cannot be blank. @@ -58,8 +59,9 @@ namespace Discord private static ArgumentException CreateNotEmptyException(string name, string msg) => new ArgumentException(message: msg ?? "Argument cannot be blank.", paramName: name); + #endregion - //Numerics + #region Numerics /// Value may not be equal to . public static void NotEqual(sbyte obj, sbyte value, string name, string msg = null) { if (obj == value) throw CreateNotEqualException(name, msg, value); } /// Value may not be equal to . @@ -271,8 +273,9 @@ namespace Discord private static ArgumentException CreateLessThanException(string name, string msg, T value) => new ArgumentException(message: msg ?? $"Value must be less than {value}.", paramName: name); + #endregion - // Bulk Delete + #region Bulk Delete /// Messages are younger than 2 weeks. public static void YoungerThanTwoWeeks(ulong[] collection, string name) { @@ -293,5 +296,6 @@ namespace Discord throw new ArgumentException(message: "The everyone role cannot be assigned to a user.", paramName: name); } } + #endregion } } diff --git a/src/Discord.Net.Core/Utils/SnowflakeUtils.cs b/src/Discord.Net.Core/Utils/SnowflakeUtils.cs index dd8f8ca66..e52c99376 100644 --- a/src/Discord.Net.Core/Utils/SnowflakeUtils.cs +++ b/src/Discord.Net.Core/Utils/SnowflakeUtils.cs @@ -12,7 +12,7 @@ namespace Discord /// /// The snowflake identifier to resolve. /// - /// A representing the time for when the object is geenrated. + /// A representing the time for when the object is generated. /// public static DateTimeOffset FromSnowflake(ulong value) => DateTimeOffset.FromUnixTimeMilliseconds((long)((value >> 22) + 1420070400000UL)); diff --git a/src/Discord.Net.Core/Utils/UrlValidation.cs b/src/Discord.Net.Core/Utils/UrlValidation.cs new file mode 100644 index 000000000..8e877bd4e --- /dev/null +++ b/src/Discord.Net.Core/Utils/UrlValidation.cs @@ -0,0 +1,42 @@ +using System; + +namespace Discord.Utils +{ + internal static class UrlValidation + { + /// + /// Not full URL validation right now. Just ensures protocol is present and that it's either http or https + /// should be used for url buttons. + /// + /// The URL to validate before sending to Discord. + /// to allow the attachment:// protocol; otherwise . + /// A URL must include a protocol (http or https). + /// true if URL is valid by our standard, false if null, throws an error upon invalid. + public static bool Validate(string url, bool allowAttachments = false) + { + if (string.IsNullOrEmpty(url)) + return false; + if (!(url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || url.StartsWith("https://", StringComparison.OrdinalIgnoreCase) || (allowAttachments ? url.StartsWith("attachment://", StringComparison.Ordinal) : false))) + throw new InvalidOperationException($"The url {url} must include a protocol (either {(allowAttachments ? "HTTP, HTTPS, or ATTACHMENT" : "HTTP or HTTPS")})"); + return true; + } + + /// + /// Not full URL validation right now. Just Ensures the protocol is either http, https, or discord + /// should be used everything other than url buttons. + /// + /// The URL to validate before sending to discord. + /// A URL must include a protocol (either http, https, or discord). + /// true if the URL is valid by our standard, false if null, throws an error upon invalid. + public static bool ValidateButton(string url) + { + if (string.IsNullOrEmpty(url)) + return false; + if (!(url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || + url.StartsWith("https://", StringComparison.OrdinalIgnoreCase) || + url.StartsWith("discord://", StringComparison.OrdinalIgnoreCase))) + throw new InvalidOperationException($"The url {url} must include a protocol (either HTTP, HTTPS, or DISCORD)"); + return true; + } + } +} diff --git a/src/Discord.Net.Examples/Core/Entities/Channels/IMessageChannel.Examples.cs b/src/Discord.Net.Examples/Core/Entities/Channels/IMessageChannel.Examples.cs index 5f9d4b5d6..d920e9710 100644 --- a/src/Discord.Net.Examples/Core/Entities/Channels/IMessageChannel.Examples.cs +++ b/src/Discord.Net.Examples/Core/Entities/Channels/IMessageChannel.Examples.cs @@ -108,7 +108,6 @@ namespace Discord.Net.Examples.Core.Entities.Channels using (channel.EnterTypingState()) await LongRunningAsync(); #endregion - } } } diff --git a/src/Discord.Net.Examples/Core/Entities/Users/IUser.Examples.cs b/src/Discord.Net.Examples/Core/Entities/Users/IUser.Examples.cs index 79a90b46d..83daedaa0 100644 --- a/src/Discord.Net.Examples/Core/Entities/Users/IUser.Examples.cs +++ b/src/Discord.Net.Examples/Core/Entities/Users/IUser.Examples.cs @@ -18,11 +18,11 @@ namespace Discord.Net.Examples.Core.Entities.Users #endregion - #region GetOrCreateDMChannelAsync + #region CreateDMChannelAsync public async Task MessageUserAsync(IUser user) { - var channel = await user.GetOrCreateDMChannelAsync(); + var channel = await user.CreateDMChannelAsync(); try { await channel.SendMessageAsync("Awesome stuff!"); diff --git a/src/Discord.Net.Examples/Discord.Net.Examples.csproj b/src/Discord.Net.Examples/Discord.Net.Examples.csproj index ec0253428..b4a336f9f 100644 --- a/src/Discord.Net.Examples/Discord.Net.Examples.csproj +++ b/src/Discord.Net.Examples/Discord.Net.Examples.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net5.0 @@ -15,7 +15,7 @@ - + diff --git a/src/Discord.Net.Examples/WebSocket/BaseSocketClient.Events.Examples.cs b/src/Discord.Net.Examples/WebSocket/BaseSocketClient.Events.Examples.cs index 387584877..27d393c07 100644 --- a/src/Discord.Net.Examples/WebSocket/BaseSocketClient.Events.Examples.cs +++ b/src/Discord.Net.Examples/WebSocket/BaseSocketClient.Events.Examples.cs @@ -15,7 +15,7 @@ namespace Discord.Net.Examples.WebSocket => client.ReactionAdded += HandleReactionAddedAsync; public async Task HandleReactionAddedAsync(Cacheable cachedMessage, - ISocketMessageChannel originChannel, SocketReaction reaction) + Cacheable originChannel, SocketReaction reaction) { var message = await cachedMessage.GetOrDownloadAsync(); if (message != null && reaction.User.IsSpecified) @@ -100,16 +100,17 @@ namespace Discord.Net.Examples.WebSocket public void HookMessageDeleted(BaseSocketClient client) => client.MessageDeleted += HandleMessageDelete; - public Task HandleMessageDelete(Cacheable cachedMessage, ISocketMessageChannel channel) + public async Task HandleMessageDelete(Cacheable cachedMessage, Cacheable cachedChannel) { // check if the message exists in cache; if not, we cannot report what was removed - if (!cachedMessage.HasValue) return Task.CompletedTask; + if (!cachedMessage.HasValue) return; + // gets or downloads the channel if it's not in the cache + IMessageChannel channel = await cachedChannel.GetOrDownloadAsync(); var message = cachedMessage.Value; Console.WriteLine( $"A message ({message.Id}) from {message.Author} was removed from the channel {channel.Name} ({channel.Id}):" + Environment.NewLine + message.Content); - return Task.CompletedTask; } #endregion diff --git a/src/Discord.Net.Interactions/Attributes/AutocompleteAttribute.cs b/src/Discord.Net.Interactions/Attributes/AutocompleteAttribute.cs new file mode 100644 index 000000000..e17c9ff14 --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/AutocompleteAttribute.cs @@ -0,0 +1,36 @@ +using System; + +namespace Discord.Interactions +{ + /// + /// Set the to . + /// + [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class AutocompleteAttribute : Attribute + { + /// + /// Type of the . + /// + public Type AutocompleteHandlerType { get; } + + /// + /// Set the to and define a to handle + /// Autocomplete interactions targeting the parameter this is applied to. + /// + /// + /// must be set to to use this constructor. + /// + public AutocompleteAttribute(Type autocompleteHandlerType) + { + if (!typeof(IAutocompleteHandler).IsAssignableFrom(autocompleteHandlerType)) + throw new InvalidOperationException($"{autocompleteHandlerType.FullName} isn't a valid {nameof(IAutocompleteHandler)} type"); + + AutocompleteHandlerType = autocompleteHandlerType; + } + + /// + /// Set the to without specifying a . + /// + public AutocompleteAttribute() { } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/ChannelTypesAttribute.cs b/src/Discord.Net.Interactions/Attributes/ChannelTypesAttribute.cs new file mode 100644 index 000000000..013641377 --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/ChannelTypesAttribute.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; + +namespace Discord.Interactions +{ + /// + /// Specify the target channel types for a option. + /// + [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public sealed class ChannelTypesAttribute : Attribute + { + /// + /// Gets the allowed channel types for this option. + /// + public IReadOnlyCollection ChannelTypes { get; } + + /// + /// Specify the target channel types for a option. + /// + /// The allowed channel types for this option. + public ChannelTypesAttribute (params ChannelType[] channelTypes) + { + if (channelTypes is null) + throw new ArgumentNullException(nameof(channelTypes)); + + ChannelTypes = channelTypes.ToImmutableArray(); + } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/ChoiceAttribute.cs b/src/Discord.Net.Interactions/Attributes/ChoiceAttribute.cs new file mode 100644 index 000000000..200c75f9e --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/ChoiceAttribute.cs @@ -0,0 +1,64 @@ +using System; + +namespace Discord.Interactions +{ + /// + /// Add a pre-determined argument value to a command parameter. + /// + [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true, Inherited = true)] + public class ChoiceAttribute : Attribute + { + /// + /// Gets the name of the choice. + /// + public string Name { get; } + + /// + /// Gets the type of this choice. + /// + public SlashCommandChoiceType Type { get; } + + /// + /// Gets the value that will be used whenever this choice is selected. + /// + public object Value { get; } + + private ChoiceAttribute (string name) + { + Name = name; + } + + /// + /// Create a parameter choice with type . + /// + /// Name of the choice. + /// Predefined value of the choice. + public ChoiceAttribute (string name, string value) : this(name) + { + Type = SlashCommandChoiceType.String; + Value = value; + } + + /// + /// Create a parameter choice with type . + /// + /// Name of the choice. + /// Predefined value of the choice. + public ChoiceAttribute (string name, int value) : this(name) + { + Type = SlashCommandChoiceType.Integer; + Value = value; + } + + /// + /// Create a parameter choice with type . + /// + /// Name of the choice. + /// Predefined value of the choice. + public ChoiceAttribute (string name, double value) : this(name) + { + Type = SlashCommandChoiceType.Number; + Value = value; + } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/Commands/AutocompleteCommandAttribute.cs b/src/Discord.Net.Interactions/Attributes/Commands/AutocompleteCommandAttribute.cs new file mode 100644 index 000000000..df46dcfa4 --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/Commands/AutocompleteCommandAttribute.cs @@ -0,0 +1,39 @@ +using System; + +namespace Discord.Interactions +{ + /// + /// Create an Autocomplete Command. + /// + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public class AutocompleteCommandAttribute : Attribute + { + /// + /// Gets the name of the target parameter. + /// + public string ParameterName { get; } + + /// + /// Gets the name of the target command. + /// + public string CommandName { get; } + + /// + /// Get the run mode this command gets executed with. + /// + public RunMode RunMode { get; } + + /// + /// Create a command for Autocomplete interaction handling. + /// + /// Name of the target parameter. + /// Name of the target command. + /// Set the run mode of the command. + public AutocompleteCommandAttribute(string parameterName, string commandName, RunMode runMode = RunMode.Default) + { + ParameterName = parameterName; + CommandName = commandName; + RunMode = runMode; + } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/Commands/ComponentInteractionAttribute.cs b/src/Discord.Net.Interactions/Attributes/Commands/ComponentInteractionAttribute.cs new file mode 100644 index 000000000..70bc285fc --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/Commands/ComponentInteractionAttribute.cs @@ -0,0 +1,44 @@ +using System; + +namespace Discord.Interactions +{ + /// + /// Create a Message Component interaction handler, CustomId represents + /// the CustomId of the Message Component that will be handled. + /// + /// + /// s will add prefixes to this command if is set to + /// CustomID supports a Wild Card pattern where you can use the to match a set of CustomIDs. + /// + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public class ComponentInteractionAttribute : Attribute + { + /// + /// Gets the string to compare the Message Component CustomIDs with. + /// + public string CustomId { get; } + + /// + /// Gets if s will be ignored while creating this command and this method will be treated as a top level command. + /// + public bool IgnoreGroupNames { get; } + + /// + /// Gets the run mode this command gets executed with. + /// + public RunMode RunMode { get; } + + /// + /// Create a command for component interaction handling. + /// + /// String to compare the Message Component CustomIDs with. + /// If s will be ignored while creating this command and this method will be treated as a top level command. + /// Set the run mode of the command. + public ComponentInteractionAttribute (string customId, bool ignoreGroupNames = false, RunMode runMode = RunMode.Default) + { + CustomId = customId; + IgnoreGroupNames = ignoreGroupNames; + RunMode = runMode; + } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/Commands/ContextCommandAttribute.cs b/src/Discord.Net.Interactions/Attributes/Commands/ContextCommandAttribute.cs new file mode 100644 index 000000000..fd303a45c --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/Commands/ContextCommandAttribute.cs @@ -0,0 +1,36 @@ +using System; +using System.Reflection; + +namespace Discord.Interactions +{ + /// + /// Base attribute for creating a Context Commands. + /// + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public abstract class ContextCommandAttribute : Attribute + { + /// + /// Gets the name of this Context Command. + /// + public string Name { get; } + + /// + /// Gets the type of this Context Command. + /// + public ApplicationCommandType CommandType { get; } + + /// + /// Gets the run mode this command gets executed with. + /// + public RunMode RunMode { get; } + + internal ContextCommandAttribute (string name, ApplicationCommandType commandType, RunMode runMode = RunMode.Default) + { + Name = name; + CommandType = commandType; + RunMode = runMode; + } + + internal virtual void CheckMethodDefinition (MethodInfo methodInfo) { } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/Commands/MessageCommandAttribute.cs b/src/Discord.Net.Interactions/Attributes/Commands/MessageCommandAttribute.cs new file mode 100644 index 000000000..93d010c81 --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/Commands/MessageCommandAttribute.cs @@ -0,0 +1,29 @@ +using System; +using System.Reflection; + +namespace Discord.Interactions +{ + /// + /// Create a Message Context Command. + /// + /// + /// s won't add prefixes to this command. + /// + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public class MessageCommandAttribute : ContextCommandAttribute + { + /// + /// Register a method as a Message Context Command. + /// + /// Name of the context command. + public MessageCommandAttribute (string name) : base(name, ApplicationCommandType.Message) { } + + internal override void CheckMethodDefinition (MethodInfo methodInfo) + { + var parameters = methodInfo.GetParameters(); + + if (parameters.Length != 1 || !typeof(IMessage).IsAssignableFrom(parameters[0].ParameterType)) + throw new InvalidOperationException($"Message Commands must have only one parameter that is a type of {nameof(IMessage)}"); + } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/Commands/SlashCommandAttribute.cs b/src/Discord.Net.Interactions/Attributes/Commands/SlashCommandAttribute.cs new file mode 100644 index 000000000..aebc366a0 --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/Commands/SlashCommandAttribute.cs @@ -0,0 +1,49 @@ +using System; + +namespace Discord.Interactions +{ + /// + /// Create an Slash Application Command. + /// + /// + /// prefix will be used to created nested Slash Application Commands. + /// + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + public class SlashCommandAttribute : Attribute + { + /// + /// Gets the name of the Slash Command. + /// + public string Name { get; } + + /// + /// Gets the description of the Slash Command. + /// + public string Description { get; } + + /// + /// Gets if s will be ignored while creating this command and this method will be treated as a top level command. + /// + public bool IgnoreGroupNames { get; } + + /// + /// Gets the run mode this command gets executed with. + /// + public RunMode RunMode { get; } + + /// + /// Register a method as a Slash Command. + /// + /// Name of the command. + /// Description of the command. + /// If , s will be ignored while creating this command and this method will be treated as a top level command. + /// Set the run mode of the command. + public SlashCommandAttribute (string name, string description, bool ignoreGroupNames = false, RunMode runMode = RunMode.Default) + { + Name = name; + Description = description; + IgnoreGroupNames = ignoreGroupNames; + RunMode = runMode; + } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/Commands/UserCommandAttribute.cs b/src/Discord.Net.Interactions/Attributes/Commands/UserCommandAttribute.cs new file mode 100644 index 000000000..592dcf5c3 --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/Commands/UserCommandAttribute.cs @@ -0,0 +1,29 @@ +using System; +using System.Reflection; + +namespace Discord.Interactions +{ + /// + /// Create an User Context Command. + /// + /// + /// s won't add prefixes to this command. + /// + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public class UserCommandAttribute : ContextCommandAttribute + { + /// + /// Register a command as a User Context Command. + /// + /// Name of this User Context Command. + public UserCommandAttribute (string name) : base(name, ApplicationCommandType.User) { } + + internal override void CheckMethodDefinition (MethodInfo methodInfo) + { + var parameters = methodInfo.GetParameters(); + + if (parameters.Length != 1 || !typeof(IUser).IsAssignableFrom(parameters[0].ParameterType)) + throw new InvalidOperationException($"User Commands must have only one parameter that is a type of {nameof(IUser)}"); + } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/DefaultPermissionAttribute.cs b/src/Discord.Net.Interactions/Attributes/DefaultPermissionAttribute.cs new file mode 100644 index 000000000..ed0a532be --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/DefaultPermissionAttribute.cs @@ -0,0 +1,25 @@ +using System; + +namespace Discord.Interactions +{ + /// + /// Set the "Default Permission" property of an Application Command. + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public class DefaultPermissionAttribute : Attribute + { + /// + /// Gets whether the users are allowed to use a Slash Command by default or not. + /// + public bool IsDefaultPermission { get; } + + /// + /// Set the default permission of a Slash Command. + /// + /// if the users are allowed to use this command. + public DefaultPermissionAttribute (bool isDefaultPermission) + { + IsDefaultPermission = isDefaultPermission; + } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/DontAutoRegisterAttribute.cs b/src/Discord.Net.Interactions/Attributes/DontAutoRegisterAttribute.cs new file mode 100644 index 000000000..18deb785e --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/DontAutoRegisterAttribute.cs @@ -0,0 +1,13 @@ +using System; + +namespace Discord.Interactions +{ + /// + /// s with this attribute will not be registered by the or + /// methods. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class DontAutoRegisterAttribute : Attribute + { + } +} diff --git a/src/Discord.Net.Interactions/Attributes/GroupAttribute.cs b/src/Discord.Net.Interactions/Attributes/GroupAttribute.cs new file mode 100644 index 000000000..7014c35a5 --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/GroupAttribute.cs @@ -0,0 +1,35 @@ +using System; + +namespace Discord.Interactions +{ + /// + /// Create nested Slash Commands by marking a module as a command group. + /// + /// + /// commands wil not be affected by this. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class GroupAttribute : Attribute + { + /// + /// Gets the name of the group. + /// + public string Name { get; } + + /// + /// Gets the description of the group. + /// + public string Description { get; } + + /// + /// Create a command group. + /// + /// Name of the group. + /// Description of the group. + public GroupAttribute (string name, string description) + { + Name = name; + Description = description; + } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/MaxValueAttribute.cs b/src/Discord.Net.Interactions/Attributes/MaxValueAttribute.cs new file mode 100644 index 000000000..1b46a4ecd --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/MaxValueAttribute.cs @@ -0,0 +1,25 @@ +using System; + +namespace Discord.Interactions +{ + /// + /// Set the maximum value permitted for a number type parameter. + /// + [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public sealed class MaxValueAttribute : Attribute + { + /// + /// Gets the maximum value permitted. + /// + public double Value { get; } + + /// + /// Set the maximum value permitted for a number type parameter. + /// + /// The maximum value permitted. + public MaxValueAttribute(double value) + { + Value = value; + } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/MinValueAttribute.cs b/src/Discord.Net.Interactions/Attributes/MinValueAttribute.cs new file mode 100644 index 000000000..cce7a3b2c --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/MinValueAttribute.cs @@ -0,0 +1,25 @@ +using System; + +namespace Discord.Interactions +{ + /// + /// Set the minimum value permitted for a number type parameter. + /// + [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public sealed class MinValueAttribute : Attribute + { + /// + /// Gets the minimum value permitted. + /// + public double Value { get; } + + /// + /// Set the minimum value permitted for a number type parameter. + /// + /// The minimum value permitted. + public MinValueAttribute(double value) + { + Value = value; + } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/ParameterPreconditionAttribute.cs b/src/Discord.Net.Interactions/Attributes/ParameterPreconditionAttribute.cs new file mode 100644 index 000000000..22b9dc42b --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/ParameterPreconditionAttribute.cs @@ -0,0 +1,34 @@ +using System; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Requires the parameter to pass the specified precondition before execution can begin. + /// + /// + [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true, Inherited = true)] + public abstract class ParameterPreconditionAttribute : Attribute + { + /// + /// Gets the error message to be returned if execution context doesn't pass the precondition check. + /// + /// + /// When overridden in a derived class, uses the supplied string + /// as the error message if the precondition doesn't pass. + /// Setting this for a class that doesn't override + /// this property is a no-op. + /// + public virtual string ErrorMessage { get; } + + /// + /// Checks whether the condition is met before execution of the command. + /// + /// The context of the command. + /// The parameter of the command being checked against. + /// The raw value of the parameter. + /// The service collection used for dependency injection. + public abstract Task CheckRequirementsAsync (IInteractionContext context, IParameterInfo parameterInfo, object value, + IServiceProvider services); + } +} diff --git a/src/Discord.Net.Interactions/Attributes/PreconditionAttribute.cs b/src/Discord.Net.Interactions/Attributes/PreconditionAttribute.cs new file mode 100644 index 000000000..37c9de2cf --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/PreconditionAttribute.cs @@ -0,0 +1,42 @@ +using System; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Requires the module or class to pass the specified precondition before execution can begin. + /// + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] + public abstract class PreconditionAttribute : Attribute + { + /// + /// Gets the group that this precondition belongs to. + /// + /// + /// of the same group require only one of the preconditions to pass in order to + /// be successful (A || B). Specifying = null or not at all will + /// require *all* preconditions to pass, just like normal (A && B). + /// + public string Group { get; set; } = null; + + /// + /// Gets the error message to be returned if execution context doesn't pass the precondition check. + /// + /// + /// When overridden in a derived class, uses the supplied string + /// as the error message if the precondition doesn't pass. + /// Setting this for a class that doesn't override + /// this property is a no-op. + /// + public virtual string ErrorMessage { get; } + + /// + /// Checks if the command to be executed meets the precondition requirements. + /// + /// The context of the command. + /// The command being executed. + /// The service collection used for dependency injection. + public abstract Task CheckRequirementsAsync (IInteractionContext context, ICommandInfo commandInfo, IServiceProvider services); + } +} diff --git a/src/Discord.Net.Interactions/Attributes/Preconditions/RequireBotPermissionAttribute.cs b/src/Discord.Net.Interactions/Attributes/Preconditions/RequireBotPermissionAttribute.cs new file mode 100644 index 000000000..1dd3092ff --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/Preconditions/RequireBotPermissionAttribute.cs @@ -0,0 +1,84 @@ +using System; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Requires the bot to have a specific permission in the channel a command is invoked in. + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] + public class RequireBotPermissionAttribute : PreconditionAttribute + { + /// + /// Gets the specified of the precondition. + /// + public GuildPermission? GuildPermission { get; } + /// + /// Gets the specified of the precondition. + /// + public ChannelPermission? ChannelPermission { get; } + /// + /// Gets or sets the error message if the precondition + /// fails due to being run outside of a Guild channel. + /// + public string NotAGuildErrorMessage { get; set; } + + /// + /// Requires the bot account to have a specific . + /// + /// + /// This precondition will always fail if the command is being invoked in a . + /// + /// + /// The that the bot must have. Multiple permissions can be specified + /// by ORing the permissions together. + /// + public RequireBotPermissionAttribute(GuildPermission permission) + { + GuildPermission = permission; + ChannelPermission = null; + } + /// + /// Requires that the bot account to have a specific . + /// + /// + /// The that the bot must have. Multiple permissions can be + /// specified by ORing the permissions together. + /// + public RequireBotPermissionAttribute(ChannelPermission permission) + { + ChannelPermission = permission; + GuildPermission = null; + } + + /// + public override async Task CheckRequirementsAsync(IInteractionContext context, ICommandInfo command, IServiceProvider services) + { + IGuildUser guildUser = null; + if (context.Guild != null) + guildUser = await context.Guild.GetCurrentUserAsync().ConfigureAwait(false); + + if (GuildPermission.HasValue) + { + if (guildUser == null) + return PreconditionResult.FromError(NotAGuildErrorMessage ?? "Command must be used in a guild channel."); + if (!guildUser.GuildPermissions.Has(GuildPermission.Value)) + return PreconditionResult.FromError(ErrorMessage ?? $"Bot requires guild permission {GuildPermission.Value}."); + } + + if (ChannelPermission.HasValue) + { + ChannelPermissions perms; + if (context.Channel is IGuildChannel guildChannel) + perms = guildUser.GetPermissions(guildChannel); + else + perms = ChannelPermissions.All(context.Channel); + + if (!perms.Has(ChannelPermission.Value)) + return PreconditionResult.FromError(ErrorMessage ?? $"Bot requires channel permission {ChannelPermission.Value}."); + } + + return PreconditionResult.FromSuccess(); + } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/Preconditions/RequireContextAttribute.cs b/src/Discord.Net.Interactions/Attributes/Preconditions/RequireContextAttribute.cs new file mode 100644 index 000000000..2f1b1df0d --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/Preconditions/RequireContextAttribute.cs @@ -0,0 +1,72 @@ +using System; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Defines the type of command context (i.e. where the command is being executed). + /// + [Flags] + public enum ContextType + { + /// + /// Specifies the command to be executed within a guild. + /// + Guild = 0x01, + /// + /// Specifies the command to be executed within a DM. + /// + DM = 0x02, + /// + /// Specifies the command to be executed within a group. + /// + Group = 0x04 + } + + /// + /// Requires the command to be invoked in a specified context (e.g. in guild, DM). + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] + public class RequireContextAttribute : PreconditionAttribute + { + /// + /// Gets the context required to execute the command. + /// + public ContextType Contexts { get; } + + /// Requires the command to be invoked in the specified context. + /// The type of context the command can be invoked in. Multiple contexts can be specified by ORing the contexts together. + /// + /// + /// [Command("secret")] + /// [RequireContext(ContextType.DM | ContextType.Group)] + /// public Task PrivateOnlyAsync() + /// { + /// return ReplyAsync("shh, this command is a secret"); + /// } + /// + /// + public RequireContextAttribute(ContextType contexts) + { + Contexts = contexts; + } + + /// + public override Task CheckRequirementsAsync(IInteractionContext context, ICommandInfo command, IServiceProvider services) + { + bool isValid = false; + + if ((Contexts & ContextType.Guild) != 0) + isValid = context.Channel is IGuildChannel; + if ((Contexts & ContextType.DM) != 0) + isValid = isValid || context.Channel is IDMChannel; + if ((Contexts & ContextType.Group) != 0) + isValid = isValid || context.Channel is IGroupChannel; + + if (isValid) + return Task.FromResult(PreconditionResult.FromSuccess()); + else + return Task.FromResult(PreconditionResult.FromError(ErrorMessage ?? $"Invalid context for command; accepted contexts: {Contexts}.")); + } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/Preconditions/RequireNsfwAttribute.cs b/src/Discord.Net.Interactions/Attributes/Preconditions/RequireNsfwAttribute.cs new file mode 100644 index 000000000..f943ae080 --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/Preconditions/RequireNsfwAttribute.cs @@ -0,0 +1,42 @@ +using System; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Requires the command to be invoked in a channel marked NSFW. + /// + /// + /// The precondition will restrict the access of the command or module to be accessed within a guild channel + /// that has been marked as mature or NSFW. If the channel is not of type or the + /// channel is not marked as NSFW, the precondition will fail with an erroneous . + /// + /// + /// The following example restricts the command too-cool to an NSFW-enabled channel only. + /// + /// public class DankModule : ModuleBase + /// { + /// [Command("cool")] + /// public Task CoolAsync() + /// => ReplyAsync("I'm cool for everyone."); + /// + /// [RequireNsfw] + /// [Command("too-cool")] + /// public Task TooCoolAsync() + /// => ReplyAsync("You can only see this if you're cool enough."); + /// } + /// + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] + public class RequireNsfwAttribute : PreconditionAttribute + { + /// + public override Task CheckRequirementsAsync(IInteractionContext context, ICommandInfo command, IServiceProvider services) + { + if (context.Channel is ITextChannel text && text.IsNsfw) + return Task.FromResult(PreconditionResult.FromSuccess()); + else + return Task.FromResult(PreconditionResult.FromError(ErrorMessage ?? "This command may only be invoked in an NSFW channel.")); + } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/Preconditions/RequireOwnerAttribute.cs b/src/Discord.Net.Interactions/Attributes/Preconditions/RequireOwnerAttribute.cs new file mode 100644 index 000000000..827ede239 --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/Preconditions/RequireOwnerAttribute.cs @@ -0,0 +1,36 @@ +using System; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Requires the command to be invoked by the owner of the bot. + /// + /// + /// This precondition will restrict the access of the command or module to the owner of the Discord application. + /// If the precondition fails to be met, an erroneous will be returned with the + /// message "Command can only be run by the owner of the bot." + /// + /// This precondition will only work if the account has a of + /// ;otherwise, this precondition will always fail. + /// + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] + public class RequireOwnerAttribute : PreconditionAttribute + { + /// + public override async Task CheckRequirementsAsync(IInteractionContext context, ICommandInfo command, IServiceProvider services) + { + switch (context.Client.TokenType) + { + case TokenType.Bot: + var application = await context.Client.GetApplicationInfoAsync().ConfigureAwait(false); + if (context.User.Id != application.Owner.Id) + return PreconditionResult.FromError(ErrorMessage ?? "Command can only be run by the owner of the bot."); + return PreconditionResult.FromSuccess(); + default: + return PreconditionResult.FromError($"{nameof(RequireOwnerAttribute)} is not supported by this {nameof(TokenType)}."); + } + } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/Preconditions/RequireRoleAttribute.cs b/src/Discord.Net.Interactions/Attributes/Preconditions/RequireRoleAttribute.cs new file mode 100644 index 000000000..7126d55b6 --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/Preconditions/RequireRoleAttribute.cs @@ -0,0 +1,73 @@ +using System; +using System.Linq; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Requires the user invoking the command to have a specified role. + /// + public class RequireRoleAttribute : PreconditionAttribute + { + /// + /// Gets the specified Role name of the precondition. + /// + public string RoleName { get; } + + /// + /// Gets the specified Role ID of the precondition. + /// + public ulong? RoleId { get; } + + /// + /// Gets or sets the error message if the precondition + /// fails due to being run outside of a Guild channel. + /// + public string NotAGuildErrorMessage { get; set; } + + /// + /// Requires that the user invoking the command to have a specific Role. + /// + /// Id of the role that the user must have. + public RequireRoleAttribute(ulong roleId) + { + RoleId = roleId; + } + + /// + /// Requires that the user invoking the command to have a specific Role. + /// + /// Name of the role that the user must have. + public RequireRoleAttribute(string roleName) + { + RoleName = roleName; + } + + /// + public override Task CheckRequirementsAsync(IInteractionContext context, ICommandInfo commandInfo, IServiceProvider services) + { + if (context.User is not IGuildUser guildUser) + return Task.FromResult(PreconditionResult.FromError(NotAGuildErrorMessage ?? "Command must be used in a guild channel.")); + + if (RoleId.HasValue) + { + if (guildUser.RoleIds.Contains(RoleId.Value)) + return Task.FromResult(PreconditionResult.FromSuccess()); + else + return Task.FromResult(PreconditionResult.FromError(ErrorMessage ?? $"User requires guild role {context.Guild.GetRole(RoleId.Value).Name}.")); + } + + if (!string.IsNullOrEmpty(RoleName)) + { + var roleNames = guildUser.RoleIds.Select(x => guildUser.Guild.GetRole(x).Name); + + if (roleNames.Contains(RoleName)) + return Task.FromResult(PreconditionResult.FromSuccess()); + else + return Task.FromResult(PreconditionResult.FromError(ErrorMessage ?? $"User requires guild role {RoleName}.")); + } + + return Task.FromResult(PreconditionResult.FromSuccess()); + } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/Preconditions/RequireUserPermissionAttribute.cs b/src/Discord.Net.Interactions/Attributes/Preconditions/RequireUserPermissionAttribute.cs new file mode 100644 index 000000000..77d6e8f25 --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/Preconditions/RequireUserPermissionAttribute.cs @@ -0,0 +1,81 @@ +using System; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Requires the user invoking the command to have a specified permission. + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] + public class RequireUserPermissionAttribute : PreconditionAttribute + { + /// + /// Gets the specified of the precondition. + /// + public GuildPermission? GuildPermission { get; } + /// + /// Gets the specified of the precondition. + /// + public ChannelPermission? ChannelPermission { get; } + /// + /// Gets or sets the error message if the precondition + /// fails due to being run outside of a Guild channel. + /// + public string NotAGuildErrorMessage { get; set; } + + /// + /// Requires that the user invoking the command to have a specific . + /// + /// + /// This precondition will always fail if the command is being invoked in a . + /// + /// + /// The that the user must have. Multiple permissions can be + /// specified by ORing the permissions together. + /// + public RequireUserPermissionAttribute(GuildPermission guildPermission) + { + GuildPermission = guildPermission; + } + + /// + /// Requires that the user invoking the command to have a specific . + /// + /// + /// The that the user must have. Multiple permissions can be + /// specified by ORing the permissions together. + /// + public RequireUserPermissionAttribute(ChannelPermission channelPermission) + { + ChannelPermission = channelPermission; + } + + /// + public override Task CheckRequirementsAsync(IInteractionContext context, ICommandInfo commandInfo, IServiceProvider services) + { + var guildUser = context.User as IGuildUser; + + if (GuildPermission.HasValue) + { + if (guildUser == null) + return Task.FromResult(PreconditionResult.FromError(NotAGuildErrorMessage ?? "Command must be used in a guild channel.")); + if (!guildUser.GuildPermissions.Has(GuildPermission.Value)) + return Task.FromResult(PreconditionResult.FromError(ErrorMessage ?? $"User requires guild permission {GuildPermission.Value}.")); + } + + if (ChannelPermission.HasValue) + { + ChannelPermissions perms; + if (context.Channel is IGuildChannel guildChannel) + perms = guildUser.GetPermissions(guildChannel); + else + perms = ChannelPermissions.All(context.Channel); + + if (!perms.Has(ChannelPermission.Value)) + return Task.FromResult(PreconditionResult.FromError(ErrorMessage ?? $"User requires channel permission {ChannelPermission.Value}.")); + } + + return Task.FromResult(PreconditionResult.FromSuccess()); + } + } +} diff --git a/src/Discord.Net.Interactions/Attributes/SummaryAttribute.cs b/src/Discord.Net.Interactions/Attributes/SummaryAttribute.cs new file mode 100644 index 000000000..694569257 --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/SummaryAttribute.cs @@ -0,0 +1,32 @@ +using System; + +namespace Discord.Interactions +{ + /// + /// Customize the name and description of an Slash Application Command parameter. + /// + [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class SummaryAttribute : Attribute + { + /// + /// Gets the name of the parameter. + /// + public string Name { get; } = null; + + /// + /// Gets the description of the parameter. + /// + public string Description { get; } = null; + + /// + /// Modify the default name and description values of a Slash Command parameter. + /// + /// Name of the parameter. + /// Description of the parameter. + public SummaryAttribute (string name = null, string description = null) + { + Name = name; + Description = description; + } + } +} diff --git a/src/Discord.Net.Interactions/AutocompleteHandlers/AutocompleteHandler.cs b/src/Discord.Net.Interactions/AutocompleteHandlers/AutocompleteHandler.cs new file mode 100644 index 000000000..1dd3cf2bf --- /dev/null +++ b/src/Discord.Net.Interactions/AutocompleteHandlers/AutocompleteHandler.cs @@ -0,0 +1,106 @@ +using Discord.Rest; +using Discord.WebSocket; +using System; +using System.Reflection; +using System.Runtime.ExceptionServices; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Base class for creating Autocompleters. uses Autocompleters to generate parameter suggestions. + /// + public abstract class AutocompleteHandler : IAutocompleteHandler + { + /// + public InteractionService InteractionService { get; set; } + + /// + public abstract Task GenerateSuggestionsAsync(IInteractionContext context, IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter, + IServiceProvider services); + + protected virtual string GetLogString(IInteractionContext context) + { + var interaction = (context.Interaction as IAutocompleteInteraction); + return $"{interaction.Data.CommandName}: {interaction.Data.Current.Name} Autocomplete"; + } + + /// + public async Task ExecuteAsync(IInteractionContext context, IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter, + IServiceProvider services) + { + switch (InteractionService._runMode) + { + case RunMode.Sync: + { + return await ExecuteInternalAsync(context, autocompleteInteraction, parameter, services).ConfigureAwait(false); + } + case RunMode.Async: + _ = Task.Run(async () => + { + await ExecuteInternalAsync(context, autocompleteInteraction, parameter, services).ConfigureAwait(false); + }); + break; + default: + throw new InvalidOperationException($"RunMode {InteractionService._runMode} is not supported."); + } + + return ExecuteResult.FromSuccess(); + } + + private async Task ExecuteInternalAsync(IInteractionContext context, IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter, + IServiceProvider services) + { + try + { + var result = await GenerateSuggestionsAsync(context, autocompleteInteraction, parameter, services).ConfigureAwait(false); + + if (result.IsSuccess) + switch (autocompleteInteraction) + { + case RestAutocompleteInteraction restAutocomplete: + var payload = restAutocomplete.Respond(result.Suggestions); + + if (context is IRestInteractionContext restContext && restContext.InteractionResponseCallback != null) + await restContext.InteractionResponseCallback.Invoke(payload).ConfigureAwait(false); + else + await InteractionService._restResponseCallback(context, payload).ConfigureAwait(false); + break; + case SocketAutocompleteInteraction socketAutocomplete: + await socketAutocomplete.RespondAsync(result.Suggestions).ConfigureAwait(false); + break; + } + + await InteractionService._autocompleteHandlerExecutedEvent.InvokeAsync(this, context, result).ConfigureAwait(false); + return result; + } + catch (Exception ex) + { + var originalEx = ex; + while (ex is TargetInvocationException) + ex = ex.InnerException; + + await InteractionService._cmdLogger.ErrorAsync(ex).ConfigureAwait(false); + + var result = ExecuteResult.FromError(ex); + await InteractionService._autocompleteHandlerExecutedEvent.InvokeAsync(this, context, result).ConfigureAwait(false); + + if (InteractionService._throwOnError) + { + if (ex == originalEx) + throw; + else + ExceptionDispatchInfo.Capture(ex).Throw(); + } + + return result; + } + finally + { + await InteractionService._cmdLogger.VerboseAsync($"Executed {GetLogString(context)}").ConfigureAwait(false); + } + } + } +} + + diff --git a/src/Discord.Net.Interactions/AutocompleteHandlers/IAutocompleteHandler.cs b/src/Discord.Net.Interactions/AutocompleteHandlers/IAutocompleteHandler.cs new file mode 100644 index 000000000..8072b30ed --- /dev/null +++ b/src/Discord.Net.Interactions/AutocompleteHandlers/IAutocompleteHandler.cs @@ -0,0 +1,43 @@ +using Discord.WebSocket; +using System; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Represent a Autocomplete handler object that can be executed to generate parameter suggestions. + /// + public interface IAutocompleteHandler + { + /// + /// Gets the the underlying command service. + /// + InteractionService InteractionService { get; } + + /// + /// Will be used to generate parameter suggestions. + /// + /// Command execution context. + /// Autocomplete Interaction payload. + /// Parameter information of the target parameter. + /// Dependencies that will be used to create the module instance. + /// + /// A task representing the execution process. The task result contains the Autocompletion result. + /// + Task GenerateSuggestionsAsync(IInteractionContext context, IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter, + IServiceProvider services); + + /// + /// Executes the with the provided context. + /// + /// The execution context. + /// AutocompleteInteraction payload. + /// Parameter information of the target parameter. + /// Dependencies that will be used to create the module instance. + /// + /// A task representing the execution process. The task result contains the execution result. + /// + Task ExecuteAsync(IInteractionContext context, IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter, + IServiceProvider services); + } +} diff --git a/src/Discord.Net.Interactions/Builders/Commands/AutocompleteCommandBuilder.cs b/src/Discord.Net.Interactions/Builders/Commands/AutocompleteCommandBuilder.cs new file mode 100644 index 000000000..c383f1be1 --- /dev/null +++ b/src/Discord.Net.Interactions/Builders/Commands/AutocompleteCommandBuilder.cs @@ -0,0 +1,76 @@ +using System; + +namespace Discord.Interactions.Builders +{ + /// + /// Represents a builder for creating . + /// + public sealed class AutocompleteCommandBuilder : CommandBuilder + { + /// + /// Gets the name of the target parameter. + /// + public string ParameterName { get; set; } + + /// + /// Gets the name of the target command. + /// + public string CommandName { get; set; } + + protected override AutocompleteCommandBuilder Instance => this; + + internal AutocompleteCommandBuilder(ModuleBuilder module) : base(module) { } + + /// + /// Initializes a new . + /// + /// Parent module of this command. + /// Name of this command. + /// Execution callback of this command. + public AutocompleteCommandBuilder(ModuleBuilder module, string name, ExecuteCallback callback) : base(module, name, callback) { } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public AutocompleteCommandBuilder WithParameterName(string name) + { + ParameterName = name; + return this; + } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public AutocompleteCommandBuilder WithCommandName(string name) + { + CommandName = name; + return this; + } + + /// + /// Adds a command parameter to the parameters collection. + /// + /// factory. + /// + /// The builder instance. + /// + public override AutocompleteCommandBuilder AddParameter(Action configure) + { + var parameter = new CommandParameterBuilder(this); + configure(parameter); + AddParameters(parameter); + return this; + } + + internal override AutocompleteCommandInfo Build(ModuleInfo module, InteractionService commandService) => + new AutocompleteCommandInfo(this, module, commandService); + } +} diff --git a/src/Discord.Net.Interactions/Builders/Commands/CommandBuilder.cs b/src/Discord.Net.Interactions/Builders/Commands/CommandBuilder.cs new file mode 100644 index 000000000..5c35e8871 --- /dev/null +++ b/src/Discord.Net.Interactions/Builders/Commands/CommandBuilder.cs @@ -0,0 +1,174 @@ +using System; +using System.Collections.Generic; + +namespace Discord.Interactions.Builders +{ + /// + /// Represents the base builder class for creating . + /// + /// The this builder yields when built. + /// Inherited type. + /// Builder type for this commands parameters. + public abstract class CommandBuilder : ICommandBuilder + where TInfo : class, ICommandInfo + where TBuilder : CommandBuilder + where TParamBuilder : class, IParameterBuilder + { + private readonly List _attributes; + private readonly List _preconditions; + private readonly List _parameters; + + protected abstract TBuilder Instance { get; } + + /// + public ModuleBuilder Module { get; } + + //// + public ExecuteCallback Callback { get; internal set; } + + /// + public string Name { get; internal set; } + + /// + public string MethodName { get; set; } + + /// + public bool IgnoreGroupNames { get; set; } + + /// + public RunMode RunMode { get; set; } + + /// + public IReadOnlyList Attributes => _attributes; + + /// + public IReadOnlyList Parameters => _parameters; + + /// + public IReadOnlyList Preconditions => _preconditions; + + /// + IReadOnlyList ICommandBuilder.Parameters => Parameters; + + internal CommandBuilder (ModuleBuilder module) + { + _attributes = new List(); + _preconditions = new List(); + _parameters = new List(); + + Module = module; + } + + protected CommandBuilder (ModuleBuilder module, string name, ExecuteCallback callback) : this(module) + { + Name = name; + Callback = callback; + } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public TBuilder WithName (string name) + { + Name = name; + return Instance; + } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public TBuilder WithMethodName (string name) + { + MethodName = name; + return Instance; + } + + /// + /// Adds attributes to . + /// + /// New attributes to be added to . + /// + /// The builder instance. + /// + public TBuilder WithAttributes (params Attribute[] attributes) + { + _attributes.AddRange(attributes); + return Instance; + } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public TBuilder SetRunMode (RunMode runMode) + { + RunMode = runMode; + return Instance; + } + + /// + /// Adds parameter builders to . + /// + /// New parameter builders to be added to . + /// + /// The builder instance. + /// + public TBuilder AddParameters (params TParamBuilder[] parameters) + { + _parameters.AddRange(parameters); + return Instance; + } + + /// + /// Adds preconditions to . + /// + /// New preconditions to be added to . + /// + /// The builder instance. + /// + public TBuilder WithPreconditions (params PreconditionAttribute[] preconditions) + { + _preconditions.AddRange(preconditions); + return Instance; + } + + /// + public abstract TBuilder AddParameter (Action configure); + + internal abstract TInfo Build (ModuleInfo module, InteractionService commandService); + + //ICommandBuilder + /// + ICommandBuilder ICommandBuilder.WithName (string name) => + WithName(name); + + /// + ICommandBuilder ICommandBuilder.WithMethodName (string name) => + WithMethodName(name); + ICommandBuilder ICommandBuilder.WithAttributes (params Attribute[] attributes) => + WithAttributes(attributes); + + /// + ICommandBuilder ICommandBuilder.SetRunMode (RunMode runMode) => + SetRunMode(runMode); + + /// + ICommandBuilder ICommandBuilder.AddParameters (params IParameterBuilder[] parameters) => + AddParameters(parameters as TParamBuilder); + + /// + ICommandBuilder ICommandBuilder.WithPreconditions (params PreconditionAttribute[] preconditions) => + WithPreconditions(preconditions); + } +} diff --git a/src/Discord.Net.Interactions/Builders/Commands/ComponentCommandBuilder.cs b/src/Discord.Net.Interactions/Builders/Commands/ComponentCommandBuilder.cs new file mode 100644 index 000000000..e42dfabce --- /dev/null +++ b/src/Discord.Net.Interactions/Builders/Commands/ComponentCommandBuilder.cs @@ -0,0 +1,40 @@ +using System; + +namespace Discord.Interactions.Builders +{ + /// + /// Represents a builder for creating . + /// + public sealed class ComponentCommandBuilder : CommandBuilder + { + protected override ComponentCommandBuilder Instance => this; + + internal ComponentCommandBuilder (ModuleBuilder module) : base(module) { } + + /// + /// Initializes a new . + /// + /// Parent module of this command. + /// Name of this command. + /// Execution callback of this command. + public ComponentCommandBuilder (ModuleBuilder module, string name, ExecuteCallback callback) : base(module, name, callback) { } + + /// + /// Adds a command parameter to the parameters collection. + /// + /// factory. + /// + /// The builder instance. + /// + public override ComponentCommandBuilder AddParameter (Action configure) + { + var parameter = new CommandParameterBuilder(this); + configure(parameter); + AddParameters(parameter); + return this; + } + + internal override ComponentCommandInfo Build (ModuleInfo module, InteractionService commandService) => + new ComponentCommandInfo(this, module, commandService); + } +} diff --git a/src/Discord.Net.Interactions/Builders/Commands/ContextCommandBuilder.cs b/src/Discord.Net.Interactions/Builders/Commands/ContextCommandBuilder.cs new file mode 100644 index 000000000..d40547b3c --- /dev/null +++ b/src/Discord.Net.Interactions/Builders/Commands/ContextCommandBuilder.cs @@ -0,0 +1,76 @@ +using System; + +namespace Discord.Interactions.Builders +{ + /// + /// Represents a builder for creating . + /// + public sealed class ContextCommandBuilder : CommandBuilder + { + protected override ContextCommandBuilder Instance => this; + + /// + /// Gets the type of this command. + /// + public ApplicationCommandType CommandType { get; set; } + + /// + /// Gets the default permission of this command. + /// + public bool DefaultPermission { get; set; } = true; + + internal ContextCommandBuilder (ModuleBuilder module) : base(module) { } + + /// + /// Initializes a new . + /// + /// Parent module of this command. + /// Name of this command. + /// Execution callback of this command. + public ContextCommandBuilder (ModuleBuilder module, string name, ExecuteCallback callback) : base(module, name, callback) { } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public ContextCommandBuilder SetType (ApplicationCommandType commandType) + { + CommandType = commandType; + return this; + } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public ContextCommandBuilder SetDefaultPermission (bool defaultPermision) + { + DefaultPermission = defaultPermision; + return this; + } + + /// + /// Adds a command parameter to the parameters collection. + /// + /// factory. + /// + /// The builder instance. + /// + public override ContextCommandBuilder AddParameter (Action configure) + { + var parameter = new CommandParameterBuilder(this); + configure(parameter); + AddParameters(parameter); + return this; + } + + internal override ContextCommandInfo Build (ModuleInfo module, InteractionService commandService) => + ContextCommandInfo.Create(this, module, commandService); + } +} diff --git a/src/Discord.Net.Interactions/Builders/Commands/ICommandBuilder.cs b/src/Discord.Net.Interactions/Builders/Commands/ICommandBuilder.cs new file mode 100644 index 000000000..95007296c --- /dev/null +++ b/src/Discord.Net.Interactions/Builders/Commands/ICommandBuilder.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; + +namespace Discord.Interactions.Builders +{ + /// + /// Represent a command builder for creating . + /// + public interface ICommandBuilder + { + /// + /// Gets the execution delegate of this command. + /// + ExecuteCallback Callback { get; } + + /// + /// Gets the parent module of this command. + /// + ModuleBuilder Module { get; } + + /// + /// Gets the name of this command. + /// + string Name { get; } + + /// + /// Gets or sets the method name of this command. + /// + string MethodName { get; set; } + + /// + /// Gets or sets if this command will be registered and executed as a standalone command, unaffected by the s of + /// of the commands parents. + /// + bool IgnoreGroupNames { get; set; } + + /// + /// Gets or sets the run mode this command gets executed with. + /// + RunMode RunMode { get; set; } + + /// + /// Gets a collection of the attributes of this command. + /// + IReadOnlyList Attributes { get; } + + /// + /// Gets a collection of the parameters of this command. + /// + IReadOnlyList Parameters { get; } + + /// + /// Gets a collection of the preconditions of this command. + /// + IReadOnlyList Preconditions { get; } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + ICommandBuilder WithName (string name); + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + ICommandBuilder WithMethodName (string name); + + /// + /// Adds attributes to . + /// + /// New attributes to be added to . + /// + /// The builder instance. + /// + ICommandBuilder WithAttributes (params Attribute[] attributes); + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + ICommandBuilder SetRunMode (RunMode runMode); + + /// + /// Adds parameter builders to . + /// + /// New parameter builders to be added to . + /// + /// The builder instance. + /// + ICommandBuilder AddParameters (params IParameterBuilder[] parameters); + + /// + /// Adds preconditions to . + /// + /// New preconditions to be added to . + /// + /// The builder instance. + /// + ICommandBuilder WithPreconditions (params PreconditionAttribute[] preconditions); + } +} diff --git a/src/Discord.Net.Interactions/Builders/Commands/SlashCommandBuilder.cs b/src/Discord.Net.Interactions/Builders/Commands/SlashCommandBuilder.cs new file mode 100644 index 000000000..d8e9b0658 --- /dev/null +++ b/src/Discord.Net.Interactions/Builders/Commands/SlashCommandBuilder.cs @@ -0,0 +1,76 @@ +using System; + +namespace Discord.Interactions.Builders +{ + /// + /// Represents a builder for creating . + /// + public sealed class SlashCommandBuilder : CommandBuilder + { + protected override SlashCommandBuilder Instance => this; + + /// + /// Gets and sets the description of this command. + /// + public string Description { get; set; } + + /// + /// Gets and sets the default permission of this command. + /// + public bool DefaultPermission { get; set; } = true; + + internal SlashCommandBuilder (ModuleBuilder module) : base(module) { } + + /// + /// Initializes a new . + /// + /// Parent module of this command. + /// Name of this command. + /// Execution callback of this command. + public SlashCommandBuilder (ModuleBuilder module, string name, ExecuteCallback callback) : base(module, name, callback) { } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public SlashCommandBuilder WithDescription (string description) + { + Description = description; + return this; + } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public SlashCommandBuilder WithDefaultPermission (bool permission) + { + DefaultPermission = permission; + return Instance; + } + + /// + /// Adds a command parameter to the parameters collection. + /// + /// factory. + /// + /// The builder instance. + /// + public override SlashCommandBuilder AddParameter (Action configure) + { + var parameter = new SlashCommandParameterBuilder(this); + configure(parameter); + AddParameters(parameter); + return this; + } + + internal override SlashCommandInfo Build (ModuleInfo module, InteractionService commandService) => + new SlashCommandInfo(this, module, commandService); + } +} diff --git a/src/Discord.Net.Interactions/Builders/ModuleBuilder.cs b/src/Discord.Net.Interactions/Builders/ModuleBuilder.cs new file mode 100644 index 000000000..036964778 --- /dev/null +++ b/src/Discord.Net.Interactions/Builders/ModuleBuilder.cs @@ -0,0 +1,352 @@ +using System; +using System.Collections.Generic; +using System.Reflection; + +namespace Discord.Interactions.Builders +{ + /// + /// Represents a builder for creating . + /// + public class ModuleBuilder + { + private readonly List _attributes; + private readonly List _preconditions; + private readonly List _subModules; + private readonly List _slashCommands; + private readonly List _contextCommands; + private readonly List _componentCommands; + private readonly List _autocompleteCommands; + + /// + /// Gets the underlying Interaction Service. + /// + public InteractionService InteractionService { get; } + + /// + /// Gets the parent module if this module is a sub-module. + /// + public ModuleBuilder Parent { get; } + + /// + /// Gets the name of this module. + /// + public string Name { get; internal set; } + + /// + /// Gets and sets the group name of this module. + /// + public string SlashGroupName { get; set; } + + /// + /// Gets whether this has a . + /// + public bool IsSlashGroup => !string.IsNullOrEmpty(SlashGroupName); + + /// + /// Gets and sets the description of this module. + /// + public string Description { get; set; } + + /// + /// Gets and sets the default permission of this module. + /// + public bool DefaultPermission { get; set; } = true; + + /// + /// Gets and sets whether this has a . + /// + public bool DontAutoRegister { get; set; } = false; + + /// + /// Gets a collection of the attributes of this module. + /// + public IReadOnlyList Attributes => _attributes; + + /// + /// Gets a collection of the preconditions of this module. + /// + public IReadOnlyCollection Preconditions => _preconditions; + + /// + /// Gets a collection of the sub-modules of this module. + /// + public IReadOnlyList SubModules => _subModules; + + /// + /// Gets a collection of the Slash Commands of this module. + /// + public IReadOnlyList SlashCommands => _slashCommands; + + /// + /// Gets a collection of the Context Commands of this module. + /// + public IReadOnlyList ContextCommands => _contextCommands; + + /// + /// Gets a collection of the Component Commands of this module. + /// + public IReadOnlyList ComponentCommands => _componentCommands; + + /// + /// Gets a collection of the Autocomplete Commands of this module. + /// + public IReadOnlyList AutocompleteCommands => _autocompleteCommands; + + internal TypeInfo TypeInfo { get; set; } + + internal ModuleBuilder (InteractionService interactionService, ModuleBuilder parent = null) + { + InteractionService = interactionService; + Parent = parent; + + _attributes = new List(); + _subModules = new List(); + _slashCommands = new List(); + _contextCommands = new List(); + _componentCommands = new List(); + _autocompleteCommands = new List(); + _preconditions = new List(); + } + + /// + /// Initializes a new . + /// + /// The underlying Interaction Service. + /// Name of this module. + /// Parent module of this sub-module. + public ModuleBuilder (InteractionService interactionService, string name, ModuleBuilder parent = null) : this(interactionService, parent) + { + Name = name; + } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public ModuleBuilder WithGroupName (string name) + { + SlashGroupName = name; + return this; + } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public ModuleBuilder WithDescription (string description) + { + Description = description; + return this; + } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public ModuleBuilder WithDefaultPermision (bool permission) + { + DefaultPermission = permission; + return this; + } + + /// + /// Adds attributes to . + /// + /// New attributes to be added to . + /// + /// The builder instance. + /// + public ModuleBuilder AddAttributes (params Attribute[] attributes) + { + _attributes.AddRange(attributes); + return this; + } + + /// + /// Adds preconditions to . + /// + /// New preconditions to be added to . + /// + /// The builder instance. + /// + public ModuleBuilder AddPreconditions (params PreconditionAttribute[] preconditions) + { + _preconditions.AddRange(preconditions); + return this; + } + + /// + /// Adds slash command builder to . + /// + /// factory. + /// + /// The builder instance. + /// + public ModuleBuilder AddSlashCommand (Action configure) + { + var command = new SlashCommandBuilder(this); + configure(command); + _slashCommands.Add(command); + return this; + } + + /// + /// Adds slash command builder to . + /// + /// Name of the command. + /// Command callback to be executed. + /// factory. + /// + /// The builder instance. + /// + public ModuleBuilder AddSlashCommand(string name, ExecuteCallback callback, Action configure) + { + var command = new SlashCommandBuilder(this, name, callback); + configure(command); + _slashCommands.Add(command); + return this; + } + + /// + /// Adds context command builder to . + /// + /// factory. + /// + /// The builder instance. + /// + public ModuleBuilder AddContextCommand (Action configure) + { + var command = new ContextCommandBuilder(this); + configure(command); + _contextCommands.Add(command); + return this; + } + + /// + /// Adds context command builder to . + /// + /// Name of the command. + /// Command callback to be executed. + /// factory. + /// + /// The builder instance. + /// + public ModuleBuilder AddContextCommand(string name, ExecuteCallback callback, Action configure) + { + var command = new ContextCommandBuilder(this, name, callback); + configure(command); + _contextCommands.Add(command); + return this; + } + + /// + /// Adds component command builder to . + /// + /// factory. + /// + /// The builder instance. + /// + public ModuleBuilder AddComponentCommand (Action configure) + { + var command = new ComponentCommandBuilder(this); + configure(command); + _componentCommands.Add(command); + return this; + } + + /// + /// Adds component command builder to . + /// + /// Name of the command. + /// Command callback to be executed. + /// factory. + /// + /// The builder instance. + /// + public ModuleBuilder AddComponentCommand(string name, ExecuteCallback callback, Action configure) + { + var command = new ComponentCommandBuilder(this, name, callback); + configure(command); + _componentCommands.Add(command); + return this; + } + + /// + /// Adds autocomplete command builder to . + /// + /// factory. + /// + /// The builder instance. + /// + public ModuleBuilder AddAutocompleteCommand(Action configure) + { + var command = new AutocompleteCommandBuilder(this); + configure(command); + _autocompleteCommands.Add(command); + return this; + } + + /// + /// Adds autocomplete command builder to . + /// + /// Name of the command. + /// Command callback to be executed. + /// factory. + /// + /// The builder instance. + /// + public ModuleBuilder AddSlashCommand(string name, ExecuteCallback callback, Action configure) + { + var command = new AutocompleteCommandBuilder(this, name, callback); + configure(command); + _autocompleteCommands.Add(command); + return this; + } + + /// + /// Adds sub-module builder to . + /// + /// factory. + /// + /// The builder instance. + /// + public ModuleBuilder AddModule (Action configure) + { + var subModule = new ModuleBuilder(InteractionService, this); + configure(subModule); + _subModules.Add(subModule); + return this; + } + + internal ModuleInfo Build (InteractionService interactionService, IServiceProvider services, ModuleInfo parent = null) + { + if (TypeInfo is not null && ModuleClassBuilder.IsValidModuleDefinition(TypeInfo)) + { + var instance = ReflectionUtils.CreateObject(TypeInfo, interactionService, services); + + try + { + instance.Construct(this, interactionService); + var moduleInfo = new ModuleInfo(this, interactionService, services, parent); + instance.OnModuleBuilding(interactionService, moduleInfo); + return moduleInfo; + } + finally + { + (instance as IDisposable)?.Dispose(); + } + } + else + return new(this, interactionService, services, parent); + } + } +} diff --git a/src/Discord.Net.Interactions/Builders/ModuleClassBuilder.cs b/src/Discord.Net.Interactions/Builders/ModuleClassBuilder.cs new file mode 100644 index 000000000..071c68349 --- /dev/null +++ b/src/Discord.Net.Interactions/Builders/ModuleClassBuilder.cs @@ -0,0 +1,471 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace Discord.Interactions.Builders +{ + internal static class ModuleClassBuilder + { + private static readonly TypeInfo ModuleTypeInfo = typeof(IInteractionModuleBase).GetTypeInfo(); + + public const int MaxCommandDepth = 3; + + public static async Task> SearchAsync (Assembly assembly, InteractionService commandService) + { + static bool IsLoadableModule (TypeInfo info) + { + return info.DeclaredMethods.Any(x => x.GetCustomAttribute() != null); + } + + var result = new List(); + + foreach (var type in assembly.DefinedTypes) + { + if (( type.IsPublic || type.IsNestedPublic ) && IsValidModuleDefinition(type)) + { + result.Add(type); + } + else if (IsLoadableModule(type)) + { + await commandService._cmdLogger.WarningAsync($"Class {type.FullName} is not public and cannot be loaded.").ConfigureAwait(false); + } + } + return result; + } + + public static async Task> BuildAsync (IEnumerable validTypes, InteractionService commandService, + IServiceProvider services) + { + var topLevelGroups = validTypes.Where(x => x.DeclaringType == null || !IsValidModuleDefinition(x.DeclaringType.GetTypeInfo())); + var built = new List(); + + var result = new Dictionary(); + + foreach (var type in topLevelGroups) + { + var builder = new ModuleBuilder(commandService); + + BuildModule(builder, type, commandService, services); + BuildSubModules(builder, type.DeclaredNestedTypes, built, commandService, services); + built.Add(type); + + var moduleInfo = builder.Build(commandService, services); + + result.Add(type.AsType(), moduleInfo); + } + + await commandService._cmdLogger.DebugAsync($"Successfully built {built.Count} Slash Command modules.").ConfigureAwait(false); + + return result; + } + + private static void BuildModule (ModuleBuilder builder, TypeInfo typeInfo, InteractionService commandService, + IServiceProvider services) + { + var attributes = typeInfo.GetCustomAttributes(); + + builder.Name = typeInfo.Name; + builder.TypeInfo = typeInfo; + + foreach (var attribute in attributes) + { + switch (attribute) + { + case GroupAttribute group: + { + builder.SlashGroupName = group.Name; + builder.Description = group.Description; + } + break; + case DefaultPermissionAttribute defPermission: + { + builder.DefaultPermission = defPermission.IsDefaultPermission; + } + break; + case PreconditionAttribute precondition: + builder.AddPreconditions(precondition); + break; + case DontAutoRegisterAttribute dontAutoRegister: + builder.DontAutoRegister = true; + break; + default: + builder.AddAttributes(attribute); + break; + } + } + + var methods = typeInfo.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); + + var validSlashCommands = methods.Where(IsValidSlashCommandDefinition); + var validContextCommands = methods.Where(IsValidContextCommandDefinition); + var validInteractions = methods.Where(IsValidComponentCommandDefinition); + var validAutocompleteCommands = methods.Where(IsValidAutocompleteCommandDefinition); + + Func createInstance = commandService._useCompiledLambda ? + ReflectionUtils.CreateLambdaBuilder(typeInfo, commandService) : ReflectionUtils.CreateBuilder(typeInfo, commandService); + + foreach (var method in validSlashCommands) + builder.AddSlashCommand(x => BuildSlashCommand(x, createInstance, method, commandService, services)); + + foreach (var method in validContextCommands) + builder.AddContextCommand(x => BuildContextCommand(x, createInstance, method, commandService, services)); + + foreach (var method in validInteractions) + builder.AddComponentCommand(x => BuildComponentCommand(x, createInstance, method, commandService, services)); + + foreach(var method in validAutocompleteCommands) + builder.AddAutocompleteCommand(x => BuildAutocompleteCommand(x, createInstance, method, commandService, services)); + } + + private static void BuildSubModules (ModuleBuilder parent, IEnumerable subModules, IList builtTypes, InteractionService commandService, + IServiceProvider services, int slashGroupDepth = 0) + { + foreach (var submodule in subModules.Where(IsValidModuleDefinition)) + { + if (builtTypes.Contains(submodule)) + continue; + + parent.AddModule((builder) => + { + BuildModule(builder, submodule, commandService, services); + + if (slashGroupDepth >= MaxCommandDepth - 1) + throw new InvalidOperationException($"Slash Commands only support {MaxCommandDepth - 1} command prefixes for sub-commands"); + + BuildSubModules(builder, submodule.DeclaredNestedTypes, builtTypes, commandService, services, builder.IsSlashGroup ? slashGroupDepth + 1 : slashGroupDepth); + }); + builtTypes.Add(submodule); + } + } + + private static void BuildSlashCommand (SlashCommandBuilder builder, Func createInstance, MethodInfo methodInfo, + InteractionService commandService, IServiceProvider services) + { + var attributes = methodInfo.GetCustomAttributes(); + + builder.MethodName = methodInfo.Name; + + foreach (var attribute in attributes) + { + switch (attribute) + { + case SlashCommandAttribute command: + { + builder.Name = command.Name; + builder.Description = command.Description; + builder.IgnoreGroupNames = command.IgnoreGroupNames; + builder.RunMode = command.RunMode; + } + break; + case DefaultPermissionAttribute defaultPermission: + { + builder.DefaultPermission = defaultPermission.IsDefaultPermission; + } + break; + case PreconditionAttribute precondition: + builder.WithPreconditions(precondition); + break; + default: + builder.WithAttributes(attribute); + break; + } + } + + var parameters = methodInfo.GetParameters(); + + foreach (var parameter in parameters) + builder.AddParameter(x => BuildSlashParameter(x, parameter, services)); + + builder.Callback = CreateCallback(createInstance, methodInfo, commandService); + } + + private static void BuildContextCommand (ContextCommandBuilder builder, Func createInstance, MethodInfo methodInfo, + InteractionService commandService, IServiceProvider services) + { + var attributes = methodInfo.GetCustomAttributes(); + + builder.MethodName = methodInfo.Name; + + foreach (var attribute in attributes) + { + switch (attribute) + { + case ContextCommandAttribute command: + { + builder.Name = command.Name; + builder.CommandType = command.CommandType; + builder.RunMode = command.RunMode; + + command.CheckMethodDefinition(methodInfo); + } + break; + case DefaultPermissionAttribute defaultPermission: + { + builder.DefaultPermission = defaultPermission.IsDefaultPermission; + } + break; + case PreconditionAttribute precondition: + builder.WithPreconditions(precondition); + break; + default: + builder.WithAttributes(attribute); + break; + } + } + + var parameters = methodInfo.GetParameters(); + + foreach (var parameter in parameters) + builder.AddParameter(x => BuildParameter(x, parameter)); + + builder.Callback = CreateCallback(createInstance, methodInfo, commandService); + } + + private static void BuildComponentCommand (ComponentCommandBuilder builder, Func createInstance, MethodInfo methodInfo, + InteractionService commandService, IServiceProvider services) + { + if (!methodInfo.GetParameters().All(x => x.ParameterType == typeof(string) || x.ParameterType == typeof(string[]))) + throw new InvalidOperationException($"Interaction method parameters all must be types of {typeof(string).Name} or {typeof(string[]).Name}"); + + var attributes = methodInfo.GetCustomAttributes(); + + builder.MethodName = methodInfo.Name; + + foreach (var attribute in attributes) + { + switch (attribute) + { + case ComponentInteractionAttribute interaction: + { + builder.Name = interaction.CustomId; + builder.RunMode = interaction.RunMode; + builder.IgnoreGroupNames = interaction.IgnoreGroupNames; + } + break; + case PreconditionAttribute precondition: + builder.WithPreconditions(precondition); + break; + default: + builder.WithAttributes(attribute); + break; + } + } + + var parameters = methodInfo.GetParameters(); + + foreach (var parameter in parameters) + builder.AddParameter(x => BuildParameter(x, parameter)); + + builder.Callback = CreateCallback(createInstance, methodInfo, commandService); + } + + private static void BuildAutocompleteCommand(AutocompleteCommandBuilder builder, Func createInstance, MethodInfo methodInfo, + InteractionService commandService, IServiceProvider services) + { + var attributes = methodInfo.GetCustomAttributes(); + + builder.MethodName = methodInfo.Name; + + foreach(var attribute in attributes) + { + switch (attribute) + { + case AutocompleteCommandAttribute autocomplete: + { + builder.ParameterName = autocomplete.ParameterName; + builder.CommandName = autocomplete.CommandName; + builder.Name = autocomplete.CommandName + " " + autocomplete.ParameterName; + builder.RunMode = autocomplete.RunMode; + } + break; + case PreconditionAttribute precondition: + builder.WithPreconditions(precondition); + break; + default: + builder.WithAttributes(attribute); + break; + } + } + + var parameters = methodInfo.GetParameters(); + + foreach (var parameter in parameters) + builder.AddParameter(x => BuildParameter(x, parameter)); + + builder.Callback = CreateCallback(createInstance, methodInfo, commandService); + } + + private static ExecuteCallback CreateCallback (Func createInstance, + MethodInfo methodInfo, InteractionService commandService) + { + Func commandInvoker = commandService._useCompiledLambda ? + ReflectionUtils.CreateMethodInvoker(methodInfo) : (module, args) => methodInfo.Invoke(module, args) as Task; + + async Task ExecuteCallback (IInteractionContext context, object[] args, IServiceProvider serviceProvider, ICommandInfo commandInfo) + { + var instance = createInstance(serviceProvider); + instance.SetContext(context); + + try + { + await instance.BeforeExecuteAsync(commandInfo).ConfigureAwait(false); + instance.BeforeExecute(commandInfo); + var task = commandInvoker(instance, args) ?? Task.Delay(0); + + if (task is Task runtimeTask) + { + return await runtimeTask.ConfigureAwait(false); + } + else + { + await task.ConfigureAwait(false); + return ExecuteResult.FromSuccess(); + + } + } + catch (Exception ex) + { + await commandService._cmdLogger.ErrorAsync(ex).ConfigureAwait(false); + return ExecuteResult.FromError(ex); + } + finally + { + await instance.AfterExecuteAsync(commandInfo).ConfigureAwait(false); + instance.AfterExecute(commandInfo); + ( instance as IDisposable )?.Dispose(); + } + } + + return ExecuteCallback; + } + + #region Parameters + private static void BuildSlashParameter (SlashCommandParameterBuilder builder, ParameterInfo paramInfo, IServiceProvider services) + { + var attributes = paramInfo.GetCustomAttributes(); + var paramType = paramInfo.ParameterType; + + builder.Name = paramInfo.Name; + builder.Description = paramInfo.Name; + builder.IsRequired = !paramInfo.IsOptional; + builder.DefaultValue = paramInfo.DefaultValue; + builder.SetParameterType(paramType, services); + + foreach (var attribute in attributes) + { + switch (attribute) + { + case SummaryAttribute description: + { + if (!string.IsNullOrEmpty(description.Name)) + builder.Name = description.Name; + + if (!string.IsNullOrEmpty(description.Description)) + builder.Description = description.Description; + } + break; + case ChoiceAttribute choice: + builder.WithChoices(new ParameterChoice(choice.Name, choice.Value)); + break; + case ParamArrayAttribute _: + builder.IsParameterArray = true; + break; + case ParameterPreconditionAttribute precondition: + builder.AddPreconditions(precondition); + break; + case ChannelTypesAttribute channelTypes: + builder.WithChannelTypes(channelTypes.ChannelTypes); + break; + case AutocompleteAttribute autocomplete: + builder.Autocomplete = true; + if(autocomplete.AutocompleteHandlerType is not null) + builder.WithAutocompleteHandler(autocomplete.AutocompleteHandlerType, services); + break; + case MaxValueAttribute maxValue: + builder.MaxValue = maxValue.Value; + break; + case MinValueAttribute minValue: + builder.MinValue = minValue.Value; + break; + default: + builder.AddAttributes(attribute); + break; + } + } + + // Replace pascal casings with '-' + builder.Name = Regex.Replace(builder.Name, "(?<=[a-z])(?=[A-Z])", "-").ToLower(); + } + + private static void BuildParameter (CommandParameterBuilder builder, ParameterInfo paramInfo) + { + var attributes = paramInfo.GetCustomAttributes(); + var paramType = paramInfo.ParameterType; + + builder.Name = paramInfo.Name; + builder.IsRequired = !paramInfo.IsOptional; + builder.DefaultValue = paramInfo.DefaultValue; + builder.SetParameterType(paramType); + + foreach (var attribute in attributes) + { + switch (attribute) + { + case ParameterPreconditionAttribute precondition: + builder.AddPreconditions(precondition); + break; + case ParamArrayAttribute _: + builder.IsParameterArray = true; + break; + default: + builder.AddAttributes(attribute); + break; + } + } + } + #endregion + + internal static bool IsValidModuleDefinition (TypeInfo typeInfo) + { + return ModuleTypeInfo.IsAssignableFrom(typeInfo) && + !typeInfo.IsAbstract && + !typeInfo.ContainsGenericParameters; + } + + private static bool IsValidSlashCommandDefinition (MethodInfo methodInfo) + { + return methodInfo.IsDefined(typeof(SlashCommandAttribute)) && + ( methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task) ) && + !methodInfo.IsStatic && + !methodInfo.IsGenericMethod; + } + + private static bool IsValidContextCommandDefinition (MethodInfo methodInfo) + { + return methodInfo.IsDefined(typeof(ContextCommandAttribute)) && + ( methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task) ) && + !methodInfo.IsStatic && + !methodInfo.IsGenericMethod; + } + + private static bool IsValidComponentCommandDefinition (MethodInfo methodInfo) + { + return methodInfo.IsDefined(typeof(ComponentInteractionAttribute)) && + (methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task)) && + !methodInfo.IsStatic && + !methodInfo.IsGenericMethod; + } + + private static bool IsValidAutocompleteCommandDefinition (MethodInfo methodInfo) + { + return methodInfo.IsDefined(typeof(AutocompleteCommandAttribute)) && + (methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(Task)) && + !methodInfo.IsStatic && + !methodInfo.IsGenericMethod && + methodInfo.GetParameters().Length == 0; + } + } +} diff --git a/src/Discord.Net.Interactions/Builders/Parameters/CommandParameterBuilder.cs b/src/Discord.Net.Interactions/Builders/Parameters/CommandParameterBuilder.cs new file mode 100644 index 000000000..0aada9833 --- /dev/null +++ b/src/Discord.Net.Interactions/Builders/Parameters/CommandParameterBuilder.cs @@ -0,0 +1,25 @@ +using System; + +namespace Discord.Interactions.Builders +{ + /// + /// Represents a builder for creating . + /// + public sealed class CommandParameterBuilder : ParameterBuilder + { + protected override CommandParameterBuilder Instance => this; + + internal CommandParameterBuilder (ICommandBuilder command) : base(command) { } + + /// + /// Initializes a new . + /// + /// Parent command of this parameter. + /// Name of this command. + /// Type of this parameter. + public CommandParameterBuilder (ICommandBuilder command, string name, Type type) : base(command, name, type) { } + + internal override CommandParameterInfo Build (ICommandInfo command) => + new CommandParameterInfo(this, command); + } +} diff --git a/src/Discord.Net.Interactions/Builders/Parameters/IParameterBuilder.cs b/src/Discord.Net.Interactions/Builders/Parameters/IParameterBuilder.cs new file mode 100644 index 000000000..6dd5ad3a0 --- /dev/null +++ b/src/Discord.Net.Interactions/Builders/Parameters/IParameterBuilder.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; + +namespace Discord.Interactions.Builders +{ + /// + /// Represent a command builder for creating . + /// + public interface IParameterBuilder + { + /// + /// Gets the parent command of this parameter. + /// + ICommandBuilder Command { get; } + + /// + /// Gets the name of this parameter. + /// + string Name { get; } + + /// + /// Gets the type of this parameter. + /// + Type ParameterType { get; } + + /// + /// Gets whether this parameter is required. + /// + bool IsRequired { get; } + + /// + /// Gets whether this parameter is . + /// + bool IsParameterArray { get; } + + /// + /// Gets the deafult value of this parameter. + /// + object DefaultValue { get; } + + /// + /// Gets a collection of the attributes of this command. + /// + IReadOnlyCollection Attributes { get; } + + /// + /// Gets a collection of the preconditions of this command. + /// + IReadOnlyCollection Preconditions { get; } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + IParameterBuilder WithName (string name); + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + IParameterBuilder SetParameterType (Type type); + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + IParameterBuilder SetRequired (bool isRequired); + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + IParameterBuilder SetDefaultValue (object defaultValue); + + /// + /// Adds attributes to . + /// + /// New attributes to be added to . + /// + /// The builder instance. + /// + IParameterBuilder AddAttributes (params Attribute[] attributes); + + /// + /// Adds preconditions to . + /// + /// New attributes to be added to . + /// + /// The builder instance. + /// + IParameterBuilder AddPreconditions (params ParameterPreconditionAttribute[] preconditions); + } +} diff --git a/src/Discord.Net.Interactions/Builders/Parameters/ParameterBuilder.cs b/src/Discord.Net.Interactions/Builders/Parameters/ParameterBuilder.cs new file mode 100644 index 000000000..78d007d44 --- /dev/null +++ b/src/Discord.Net.Interactions/Builders/Parameters/ParameterBuilder.cs @@ -0,0 +1,162 @@ +using System; +using System.Collections.Generic; + +namespace Discord.Interactions.Builders +{ + /// + /// Represents the base builder class for creating . + /// + /// The this builder yields when built. + /// Inherited type. + public abstract class ParameterBuilder : IParameterBuilder + where TInfo : class, IParameterInfo + where TBuilder : ParameterBuilder + { + private readonly List _preconditions; + private readonly List _attributes; + + /// + public ICommandBuilder Command { get; } + + /// + public string Name { get; internal set; } + + /// + public Type ParameterType { get; private set; } + + /// + public bool IsRequired { get; set; } = true; + + /// + public bool IsParameterArray { get; set; } = false; + + /// + public object DefaultValue { get; set; } + + /// + public IReadOnlyCollection Attributes => _attributes; + + /// + public IReadOnlyCollection Preconditions => _preconditions; + protected abstract TBuilder Instance { get; } + + internal ParameterBuilder (ICommandBuilder command) + { + _attributes = new List(); + _preconditions = new List(); + + Command = command; + } + + protected ParameterBuilder (ICommandBuilder command, string name, Type type) : this(command) + { + Name = name; + SetParameterType(type); + } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public virtual TBuilder WithName (string name) + { + Name = name; + return Instance; + } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public virtual TBuilder SetParameterType (Type type) + { + ParameterType = type; + return Instance; + } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public virtual TBuilder SetRequired (bool isRequired) + { + IsRequired = isRequired; + return Instance; + } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public virtual TBuilder SetDefaultValue (object defaultValue) + { + DefaultValue = defaultValue; + return Instance; + } + + /// + /// Adds attributes to + /// + /// New attributes to be added to . + /// + /// The builder instance. + /// + public virtual TBuilder AddAttributes (params Attribute[] attributes) + { + _attributes.AddRange(attributes); + return Instance; + } + + /// + /// Adds preconditions to + /// + /// New attributes to be added to . + /// + /// The builder instance. + /// + public virtual TBuilder AddPreconditions (params ParameterPreconditionAttribute[] attributes) + { + _preconditions.AddRange(attributes); + return Instance; + } + + internal abstract TInfo Build (ICommandInfo command); + + //IParameterBuilder + /// + IParameterBuilder IParameterBuilder.WithName (string name) => + WithName(name); + + /// + IParameterBuilder IParameterBuilder.SetParameterType (Type type) => + SetParameterType(type); + + /// + IParameterBuilder IParameterBuilder.SetRequired (bool isRequired) => + SetRequired(isRequired); + + /// + IParameterBuilder IParameterBuilder.SetDefaultValue (object defaultValue) => + SetDefaultValue(defaultValue); + + /// + IParameterBuilder IParameterBuilder.AddAttributes (params Attribute[] attributes) => + AddAttributes(attributes); + + /// + IParameterBuilder IParameterBuilder.AddPreconditions (params ParameterPreconditionAttribute[] preconditions) => + AddPreconditions(preconditions); + } +} diff --git a/src/Discord.Net.Interactions/Builders/Parameters/SlashCommandParameterBuilder.cs b/src/Discord.Net.Interactions/Builders/Parameters/SlashCommandParameterBuilder.cs new file mode 100644 index 000000000..c208a4b0e --- /dev/null +++ b/src/Discord.Net.Interactions/Builders/Parameters/SlashCommandParameterBuilder.cs @@ -0,0 +1,178 @@ +using System; +using System.Collections.Generic; + +namespace Discord.Interactions.Builders +{ + /// + /// Represents a builder for creating . + /// + public sealed class SlashCommandParameterBuilder : ParameterBuilder + { + private readonly List _choices = new(); + private readonly List _channelTypes = new(); + + /// + /// Gets or sets the description of this parameter. + /// + public string Description { get; set; } + + /// + /// Gets or sets the max value of this parameter. + /// + public double? MaxValue { get; set; } + + /// + /// Gets or sets the min value of this parameter. + /// + public double? MinValue { get; set; } + + /// + /// Gets a collection of the choices of this command. + /// + public IReadOnlyCollection Choices => _choices; + + /// + /// Gets a collection of the channel types of this command. + /// + public IReadOnlyCollection ChannelTypes => _channelTypes; + + /// + /// Gets or sets whether this parameter should be configured for Autocomplete Interactions. + /// + public bool Autocomplete { get; set; } + + /// + /// Gets or sets the of this parameter. + /// + public TypeConverter TypeConverter { get; private set; } + + /// + /// Gets or sets the of this parameter. + /// + public IAutocompleteHandler AutocompleteHandler { get; set; } + protected override SlashCommandParameterBuilder Instance => this; + + internal SlashCommandParameterBuilder(ICommandBuilder command) : base(command) { } + + /// + /// Initializes a new . + /// + /// Parent command of this parameter. + /// Name of this command. + /// Type of this parameter. + public SlashCommandParameterBuilder(ICommandBuilder command, string name, Type type) : base(command, name, type) { } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public SlashCommandParameterBuilder WithDescription(string description) + { + Description = description; + return this; + } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public SlashCommandParameterBuilder WithMinValue(double value) + { + MinValue = value; + return this; + } + + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public SlashCommandParameterBuilder WithMaxValue(double value) + { + MaxValue = value; + return this; + } + + /// + /// Adds parameter choices to . + /// + /// New choices to be added to . + /// + /// The builder instance. + /// + public SlashCommandParameterBuilder WithChoices(params ParameterChoice[] options) + { + _choices.AddRange(options); + return this; + } + + /// + /// Adds channel types to . + /// + /// New channel types to be added to . + /// + /// The builder instance. + /// + public SlashCommandParameterBuilder WithChannelTypes(params ChannelType[] channelTypes) + { + _channelTypes.AddRange(channelTypes); + return this; + } + + /// + /// Adds channel types to . + /// + /// New channel types to be added to . + /// + /// The builder instance. + /// + public SlashCommandParameterBuilder WithChannelTypes(IEnumerable channelTypes) + { + _channelTypes.AddRange(channelTypes); + return this; + } + + /// + /// Sets . + /// + /// Type of the . + /// Service container to be used to resolve the dependencies of this parameters . + /// + /// The builder instance. + /// + public SlashCommandParameterBuilder WithAutocompleteHandler(Type autocompleteHandlerType, IServiceProvider services = null) + { + AutocompleteHandler = Command.Module.InteractionService.GetAutocompleteHandler(autocompleteHandlerType, services); + return this; + } + + /// + public override SlashCommandParameterBuilder SetParameterType(Type type) => SetParameterType(type, null); + + /// + /// Sets . + /// + /// New value of the . + /// Service container to be used to resolve the dependencies of this parameters . + /// + /// The builder instance. + /// + public SlashCommandParameterBuilder SetParameterType(Type type, IServiceProvider services = null) + { + base.SetParameterType(type); + TypeConverter = Command.Module.InteractionService.GetTypeConverter(ParameterType, services); + return this; + } + + internal override SlashCommandParameterInfo Build(ICommandInfo command) => + new SlashCommandParameterInfo(this, command as SlashCommandInfo); + } +} diff --git a/src/Discord.Net.Interactions/Discord.Net.Interactions.csproj b/src/Discord.Net.Interactions/Discord.Net.Interactions.csproj new file mode 100644 index 000000000..c617eff61 --- /dev/null +++ b/src/Discord.Net.Interactions/Discord.Net.Interactions.csproj @@ -0,0 +1,24 @@ + + + + + net6.0;net5.0;net461;netstandard2.0;netstandard2.1 + net6.0;net5.0;netstandard2.0;netstandard2.1 + Discord.Interactions + Discord.Net.Interactions + A Discord.Net extension adding support for Application Commands. + + + + + + + + + + + + + + + diff --git a/src/Discord.Net.Interactions/Entities/ParameterChoice.cs b/src/Discord.Net.Interactions/Entities/ParameterChoice.cs new file mode 100644 index 000000000..30f107858 --- /dev/null +++ b/src/Discord.Net.Interactions/Entities/ParameterChoice.cs @@ -0,0 +1,24 @@ +namespace Discord.Interactions +{ + /// + /// Represents a Slash Command parameter choice. + /// + public class ParameterChoice + { + /// + /// Gets the name of the choice. + /// + public string Name { get; } + + /// + /// Gets the value of the choice. + /// + public object Value { get; } + + internal ParameterChoice (string name, object value) + { + Name = name; + Value = value; + } + } +} diff --git a/src/Discord.Net.Interactions/Entities/SlashCommandChoiceType.cs b/src/Discord.Net.Interactions/Entities/SlashCommandChoiceType.cs new file mode 100644 index 000000000..c3497d5c9 --- /dev/null +++ b/src/Discord.Net.Interactions/Entities/SlashCommandChoiceType.cs @@ -0,0 +1,21 @@ +namespace Discord.Interactions +{ + /// + /// Supported types of pre-defined parameter choices. + /// + public enum SlashCommandChoiceType + { + /// + /// Discord type for . + /// + String, + /// + /// Discord type for . + /// + Integer, + /// + /// Discord type for . + /// + Number + } +} diff --git a/src/Discord.Net.Interactions/Extensions/AutocompleteOptionComparer.cs b/src/Discord.Net.Interactions/Extensions/AutocompleteOptionComparer.cs new file mode 100644 index 000000000..9f16afa31 --- /dev/null +++ b/src/Discord.Net.Interactions/Extensions/AutocompleteOptionComparer.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; + +namespace Discord.Interactions +{ + internal class AutocompleteOptionComparer : IComparer + { + public int Compare(ApplicationCommandOptionType x, ApplicationCommandOptionType y) + { + if (x == ApplicationCommandOptionType.SubCommandGroup) + { + if (y == ApplicationCommandOptionType.SubCommandGroup) + return 0; + else + return 1; + } + else if (x == ApplicationCommandOptionType.SubCommand) + { + if (y == ApplicationCommandOptionType.SubCommandGroup) + return -1; + else if (y == ApplicationCommandOptionType.SubCommand) + return 0; + else + return 1; + } + else + { + if (y == ApplicationCommandOptionType.SubCommand || y == ApplicationCommandOptionType.SubCommandGroup) + return -1; + else + return 0; + } + } + } +} diff --git a/src/Discord.Net.Interactions/Extensions/WebSocketExtensions.cs b/src/Discord.Net.Interactions/Extensions/WebSocketExtensions.cs new file mode 100644 index 000000000..388efcbf9 --- /dev/null +++ b/src/Discord.Net.Interactions/Extensions/WebSocketExtensions.cs @@ -0,0 +1,53 @@ +using Discord.Rest; +using System.Collections.Generic; +using System.Linq; + +namespace Discord.WebSocket +{ + internal static class WebSocketExtensions + { + /// + /// Get the name of the executed command and its parents in hierarchical order. + /// + /// + /// + /// The name of the executed command and its parents in hierarchical order. + /// + public static IList GetCommandKeywords(this IApplicationCommandInteractionData data) + { + var keywords = new List { data.Name }; + + var child = data.Options?.ElementAtOrDefault(0); + + while (child?.Type == ApplicationCommandOptionType.SubCommandGroup || child?.Type == ApplicationCommandOptionType.SubCommand) + { + keywords.Add(child.Name); + child = child.Options?.ElementAtOrDefault(0); + } + + return keywords; + } + + /// + /// Get the name of the executed command and its parents in hierarchical order. + /// + /// + /// + /// The name of the executed command and its parents in hierarchical order. + /// + public static IList GetCommandKeywords(this IAutocompleteInteractionData data) + { + var keywords = new List { data.CommandName }; + + var group = data.Options?.FirstOrDefault(x => x.Type == ApplicationCommandOptionType.SubCommandGroup); + if (group is not null) + keywords.Add(group.Name); + + var subcommand = data.Options?.FirstOrDefault(x => x.Type == ApplicationCommandOptionType.SubCommand); + if (subcommand is not null) + keywords.Add(subcommand.Name); + + return keywords; + } + } +} diff --git a/src/Discord.Net.Interactions/IInteractionModuleBase.cs b/src/Discord.Net.Interactions/IInteractionModuleBase.cs new file mode 100644 index 000000000..cc944a558 --- /dev/null +++ b/src/Discord.Net.Interactions/IInteractionModuleBase.cs @@ -0,0 +1,54 @@ +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Represents a generic interaction module base. + /// + public interface IInteractionModuleBase + { + /// + /// Sets the context of this module. + /// + /// + void SetContext (IInteractionContext context); + + /// + /// Method body to be executed asynchronously before executing an application command. + /// + /// Command information related to the Discord Application Command. + Task BeforeExecuteAsync(ICommandInfo command); + + /// + /// Method body to be executed before executing an application command. + /// + /// Command information related to the Discord Application Command. + void BeforeExecute(ICommandInfo command); + + /// + /// Method body to be executed asynchronously after an application command execution. + /// + /// Command information related to the Discord Application Command. + Task AfterExecuteAsync(ICommandInfo command); + + /// + /// Method body to be executed after an application command execution. + /// + /// Command information related to the Discord Application Command. + void AfterExecute (ICommandInfo command); + + /// + /// Method body to be executed when is called. + /// + /// Command Service instance that built this module. + /// Info class of this module. + void OnModuleBuilding (InteractionService commandService, ModuleInfo module); + + /// + /// Method body to be executed after the automated module creation is completed and before is called. + /// + /// Builder class of this module. + /// Command Service instance that is building this method. + void Construct(Builders.ModuleBuilder builder, InteractionService commandService); + } +} diff --git a/src/Discord.Net.Interactions/Info/Commands/AutocompleteCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/AutocompleteCommandInfo.cs new file mode 100644 index 000000000..712b058a3 --- /dev/null +++ b/src/Discord.Net.Interactions/Info/Commands/AutocompleteCommandInfo.cs @@ -0,0 +1,89 @@ +using Discord.Interactions.Builders; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Represents the info class of an attribute based method for handling Autocomplete Interaction events. + /// + public sealed class AutocompleteCommandInfo : CommandInfo + { + /// + /// Gets the name of the target parameter. + /// + public string ParameterName { get; } + + /// + /// Gets the name of the target command. + /// + public string CommandName { get; } + + /// + public override IReadOnlyCollection Parameters { get; } + + /// + public override bool SupportsWildCards => false; + + internal AutocompleteCommandInfo(AutocompleteCommandBuilder builder, ModuleInfo module, InteractionService commandService) : base(builder, module, commandService) + { + Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray(); + ParameterName = builder.ParameterName; + CommandName = builder.CommandName; + } + + /// + public override async Task ExecuteAsync(IInteractionContext context, IServiceProvider services) + { + if (context.Interaction is not IAutocompleteInteraction) + return ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Autocomplete Interaction"); + + try + { + return await RunAsync(context, Array.Empty(), services).ConfigureAwait(false); + } + catch (Exception ex) + { + return ExecuteResult.FromError(ex); + } + } + + /// + protected override Task InvokeModuleEvent(IInteractionContext context, IResult result) => + CommandService._autocompleteCommandExecutedEvent.InvokeAsync(this, context, result); + + /// + protected override string GetLogString(IInteractionContext context) + { + if (context.Guild != null) + return $"Autocomplete Command: \"{base.ToString()}\" for {context.User} in {context.Guild}/{context.Channel}"; + else + return $"Autocomplete Command: \"{base.ToString()}\" for {context.User} in {context.Channel}"; + } + + internal IList GetCommandKeywords() + { + var keywords = new List() { ParameterName, CommandName }; + + if(!IgnoreGroupNames) + { + var currentParent = Module; + + while (currentParent != null) + { + if (!string.IsNullOrEmpty(currentParent.SlashGroupName)) + keywords.Add(currentParent.SlashGroupName); + + currentParent = currentParent.Parent; + } + } + + keywords.Reverse(); + + return keywords; + } + } +} diff --git a/src/Discord.Net.Interactions/Info/Commands/CommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/CommandInfo.cs new file mode 100644 index 000000000..cfbcbacf2 --- /dev/null +++ b/src/Discord.Net.Interactions/Info/Commands/CommandInfo.cs @@ -0,0 +1,272 @@ +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Reflection; +using System.Runtime.ExceptionServices; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Represents a cached method execution delegate. + /// + /// Execution context that will be injected into the module class. + /// Method arguments array. + /// Service collection for initializing the module. + /// Command info class of the executed method. + /// + /// A task representing the execution operation. + /// + public delegate Task ExecuteCallback (IInteractionContext context, object[] args, IServiceProvider serviceProvider, ICommandInfo commandInfo); + + /// + /// The base information class for commands. + /// + /// The type of that is used by this command type. + public abstract class CommandInfo : ICommandInfo where TParameter : class, IParameterInfo + { + private readonly ExecuteCallback _action; + private readonly ILookup _groupedPreconditions; + + /// + public ModuleInfo Module { get; } + + /// + public InteractionService CommandService { get; } + + /// + public string Name { get; } + + /// + public string MethodName { get; } + + /// + public virtual bool IgnoreGroupNames { get; } + + /// + public abstract bool SupportsWildCards { get; } + + /// + public bool IsTopLevelCommand { get; } + + /// + public RunMode RunMode { get; } + + /// + public IReadOnlyCollection Attributes { get; } + + /// + public IReadOnlyCollection Preconditions { get; } + + /// + public abstract IReadOnlyCollection Parameters { get; } + + internal CommandInfo(Builders.ICommandBuilder builder, ModuleInfo module, InteractionService commandService) + { + CommandService = commandService; + Module = module; + + Name = builder.Name; + MethodName = builder.MethodName; + IgnoreGroupNames = builder.IgnoreGroupNames; + IsTopLevelCommand = IgnoreGroupNames || CheckTopLevel(Module); + RunMode = builder.RunMode != RunMode.Default ? builder.RunMode : commandService._runMode; + Attributes = builder.Attributes.ToImmutableArray(); + Preconditions = builder.Preconditions.ToImmutableArray(); + + _action = builder.Callback; + _groupedPreconditions = builder.Preconditions.ToLookup(x => x.Group, x => x, StringComparer.Ordinal); + } + + /// + public abstract Task ExecuteAsync(IInteractionContext context, IServiceProvider services); + protected abstract Task InvokeModuleEvent(IInteractionContext context, IResult result); + protected abstract string GetLogString(IInteractionContext context); + + /// + public async Task CheckPreconditionsAsync(IInteractionContext context, IServiceProvider services) + { + async Task CheckGroups(ILookup preconditions, string type) + { + foreach (IGrouping preconditionGroup in preconditions) + { + if (preconditionGroup.Key == null) + { + foreach (PreconditionAttribute precondition in preconditionGroup) + { + var result = await precondition.CheckRequirementsAsync(context, this, services).ConfigureAwait(false); + if (!result.IsSuccess) + return result; + } + } + else + { + var results = new List(); + foreach (PreconditionAttribute precondition in preconditionGroup) + results.Add(await precondition.CheckRequirementsAsync(context, this, services).ConfigureAwait(false)); + + if (!results.Any(p => p.IsSuccess)) + return PreconditionGroupResult.FromError($"{type} precondition group {preconditionGroup.Key} failed.", results); + } + } + return PreconditionGroupResult.FromSuccess(); + } + + var moduleResult = await CheckGroups(Module.GroupedPreconditions, "Module").ConfigureAwait(false); + if (!moduleResult.IsSuccess) + return moduleResult; + + var commandResult = await CheckGroups(_groupedPreconditions, "Command").ConfigureAwait(false); + if (!commandResult.IsSuccess) + return commandResult; + + return PreconditionResult.FromSuccess(); + } + + protected async Task RunAsync(IInteractionContext context, object[] args, IServiceProvider services) + { + switch (RunMode) + { + case RunMode.Sync: + { + if (CommandService._autoServiceScopes) + { + using var scope = services?.CreateScope(); + return await ExecuteInternalAsync(context, args, scope?.ServiceProvider ?? EmptyServiceProvider.Instance).ConfigureAwait(false); + } + else + return await ExecuteInternalAsync(context, args, services).ConfigureAwait(false); + } + case RunMode.Async: + _ = Task.Run(async () => + { + if (CommandService._autoServiceScopes) + { + using var scope = services?.CreateScope(); + await ExecuteInternalAsync(context, args, scope?.ServiceProvider ?? EmptyServiceProvider.Instance).ConfigureAwait(false); + } + else + await ExecuteInternalAsync(context, args, services).ConfigureAwait(false); + }); + break; + default: + throw new InvalidOperationException($"RunMode {RunMode} is not supported."); + } + + return ExecuteResult.FromSuccess(); + } + + private async Task ExecuteInternalAsync(IInteractionContext context, object[] args, IServiceProvider services) + { + await CommandService._cmdLogger.DebugAsync($"Executing {GetLogString(context)}").ConfigureAwait(false); + + try + { + var preconditionResult = await CheckPreconditionsAsync(context, services).ConfigureAwait(false); + if (!preconditionResult.IsSuccess) + { + await InvokeModuleEvent(context, preconditionResult).ConfigureAwait(false); + return preconditionResult; + } + + var index = 0; + foreach (var parameter in Parameters) + { + var result = await parameter.CheckPreconditionsAsync(context, args[index++], services).ConfigureAwait(false); + if (!result.IsSuccess) + { + await InvokeModuleEvent(context, result).ConfigureAwait(false); + return result; + } + } + + var task = _action(context, args, services, this); + + if (task is Task resultTask) + { + var result = await resultTask.ConfigureAwait(false); + await InvokeModuleEvent(context, result).ConfigureAwait(false); + if (result is RuntimeResult || result is ExecuteResult) + return result; + } + else + { + await task.ConfigureAwait(false); + var result = ExecuteResult.FromSuccess(); + await InvokeModuleEvent(context, result).ConfigureAwait(false); + return result; + } + + var failResult = ExecuteResult.FromError(InteractionCommandError.Unsuccessful, "Command execution failed for an unknown reason"); + await InvokeModuleEvent(context, failResult).ConfigureAwait(false); + return failResult; + } + catch (Exception ex) + { + var originalEx = ex; + while (ex is TargetInvocationException) + ex = ex.InnerException; + + await Module.CommandService._cmdLogger.ErrorAsync(ex).ConfigureAwait(false); + + var result = ExecuteResult.FromError(ex); + await InvokeModuleEvent(context, result).ConfigureAwait(false); + + if (Module.CommandService._throwOnError) + { + if (ex == originalEx) + throw; + else + ExceptionDispatchInfo.Capture(ex).Throw(); + } + + return result; + } + finally + { + await CommandService._cmdLogger.VerboseAsync($"Executed {GetLogString(context)}").ConfigureAwait(false); + } + } + + private static bool CheckTopLevel(ModuleInfo parent) + { + var currentParent = parent; + + while (currentParent != null) + { + if (currentParent.IsSlashGroup) + return false; + + currentParent = currentParent.Parent; + } + return true; + } + + // ICommandInfo + + /// + IReadOnlyCollection ICommandInfo.Parameters => Parameters; + + /// + public override string ToString() + { + StringBuilder builder = new(); + + var currentParent = Module; + + while (currentParent != null) + { + if (currentParent.IsSlashGroup) + builder.AppendFormat(" {0}", currentParent.SlashGroupName); + + currentParent = currentParent.Parent; + } + builder.AppendFormat(" {0}", Name); + + return builder.ToString().Trim(); + } + } +} diff --git a/src/Discord.Net.Interactions/Info/Commands/ComponentCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/ComponentCommandInfo.cs new file mode 100644 index 000000000..62195bf0c --- /dev/null +++ b/src/Discord.Net.Interactions/Info/Commands/ComponentCommandInfo.cs @@ -0,0 +1,132 @@ +using Discord.Interactions.Builders; +using Discord.WebSocket; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Represents the info class of an attribute based method for handling Component Interaction events. + /// + public class ComponentCommandInfo : CommandInfo + { + /// + public override IReadOnlyCollection Parameters { get; } + + /// + public override bool SupportsWildCards => true; + + internal ComponentCommandInfo(ComponentCommandBuilder builder, ModuleInfo module, InteractionService commandService) : base(builder, module, commandService) + { + Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray(); + } + + /// + public override async Task ExecuteAsync(IInteractionContext context, IServiceProvider services) + => await ExecuteAsync(context, services, null).ConfigureAwait(false); + + /// + /// Execute this command using dependency injection. + /// + /// Context that will be injected to the . + /// Services that will be used while initializing the . + /// Provide additional string parameters to the method along with the auto generated parameters. + /// + /// A task representing the asyncronous command execution process. + /// + public async Task ExecuteAsync(IInteractionContext context, IServiceProvider services, params string[] additionalArgs) + { + if (context.Interaction is not IComponentInteraction componentInteraction) + return ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Message Component Interaction"); + + var args = new List(); + + if (additionalArgs is not null) + args.AddRange(additionalArgs); + + if (componentInteraction.Data?.Values is not null) + args.AddRange(componentInteraction.Data.Values); + + return await ExecuteAsync(context, Parameters, args, services); + } + + /// + public async Task ExecuteAsync(IInteractionContext context, IEnumerable paramList, IEnumerable values, + IServiceProvider services) + { + if (context.Interaction is not SocketMessageComponent messageComponent) + return ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Component Command Interaction"); + + try + { + var strCount = Parameters.Count(x => x.ParameterType == typeof(string)); + + if (strCount > values?.Count()) + return ExecuteResult.FromError(InteractionCommandError.BadArgs, "Command was invoked with too few parameters"); + + var componentValues = messageComponent.Data?.Values; + + var args = new object[Parameters.Count]; + + if (componentValues is not null) + { + if (Parameters.Last().ParameterType == typeof(string[])) + args[args.Length - 1] = componentValues.ToArray(); + else + return ExecuteResult.FromError(InteractionCommandError.BadArgs, $"Select Menu Interaction handlers must accept a {typeof(string[]).FullName} as its last parameter"); + } + + for (var i = 0; i < strCount; i++) + args[i] = values.ElementAt(i); + + return await RunAsync(context, args, services).ConfigureAwait(false); + } + catch (Exception ex) + { + return ExecuteResult.FromError(ex); + } + } + + private static object[] GenerateArgs(IEnumerable paramList, IEnumerable argList) + { + var result = new object[paramList.Count()]; + + for (var i = 0; i < paramList.Count(); i++) + { + var parameter = paramList.ElementAt(i); + + if (argList?.ElementAt(i) == null) + { + if (!parameter.IsRequired) + result[i] = parameter.DefaultValue; + else + throw new InvalidOperationException($"Component Interaction handler is executed with too few args."); + } + else if (parameter.IsParameterArray) + { + string[] paramArray = new string[argList.Count() - i]; + argList.ToArray().CopyTo(paramArray, i); + result[i] = paramArray; + } + else + result[i] = argList?.ElementAt(i); + } + + return result; + } + + protected override Task InvokeModuleEvent(IInteractionContext context, IResult result) + => CommandService._componentCommandExecutedEvent.InvokeAsync(this, context, result); + + protected override string GetLogString(IInteractionContext context) + { + if (context.Guild != null) + return $"Component Interaction: \"{base.ToString()}\" for {context.User} in {context.Guild}/{context.Channel}"; + else + return $"Component Interaction: \"{base.ToString()}\" for {context.User} in {context.Channel}"; + } + } +} diff --git a/src/Discord.Net.Interactions/Info/Commands/ContextCommands/ContextCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/ContextCommands/ContextCommandInfo.cs new file mode 100644 index 000000000..4c2e7af7d --- /dev/null +++ b/src/Discord.Net.Interactions/Info/Commands/ContextCommands/ContextCommandInfo.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Base information class for attribute based context command handlers. + /// + public abstract class ContextCommandInfo : CommandInfo, IApplicationCommandInfo + { + /// + public ApplicationCommandType CommandType { get; } + + /// + public bool DefaultPermission { get; } + + /// + public override IReadOnlyCollection Parameters { get; } + + /// + public override bool SupportsWildCards => false; + + /// + public override bool IgnoreGroupNames => true; + + internal ContextCommandInfo (Builders.ContextCommandBuilder builder, ModuleInfo module, InteractionService commandService) + : base(builder, module, commandService) + { + CommandType = builder.CommandType; + DefaultPermission = builder.DefaultPermission; + Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray(); + } + + internal static ContextCommandInfo Create (Builders.ContextCommandBuilder builder, ModuleInfo module, InteractionService commandService) + { + return builder.CommandType switch + { + ApplicationCommandType.User => new UserCommandInfo(builder, module, commandService), + ApplicationCommandType.Message => new MessageCommandInfo(builder, module, commandService), + _ => throw new InvalidOperationException("This command type is not a supported Context Command"), + }; + } + + /// + protected override Task InvokeModuleEvent (IInteractionContext context, IResult result) + => CommandService._contextCommandExecutedEvent.InvokeAsync(this, context, result); + } +} diff --git a/src/Discord.Net.Interactions/Info/Commands/ContextCommands/MessageCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/ContextCommands/MessageCommandInfo.cs new file mode 100644 index 000000000..e05955df8 --- /dev/null +++ b/src/Discord.Net.Interactions/Info/Commands/ContextCommands/MessageCommandInfo.cs @@ -0,0 +1,41 @@ +using System; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Represents the info class of an attribute based method for command type . + /// + public class MessageCommandInfo : ContextCommandInfo + { + internal MessageCommandInfo(Builders.ContextCommandBuilder builder, ModuleInfo module, InteractionService commandService) + : base(builder, module, commandService) { } + + /// + public override async Task ExecuteAsync(IInteractionContext context, IServiceProvider services) + { + if (context.Interaction is not IMessageCommandInteraction messageCommand) + return ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Message Command Interation"); + + try + { + object[] args = new object[1] { messageCommand.Data.Message }; + + return await RunAsync(context, args, services).ConfigureAwait(false); + } + catch (Exception ex) + { + return ExecuteResult.FromError(ex); + } + } + + /// + protected override string GetLogString(IInteractionContext context) + { + if (context.Guild != null) + return $"Message Command: \"{base.ToString()}\" for {context.User} in {context.Guild}/{context.Channel}"; + else + return $"Message Command: \"{base.ToString()}\" for {context.User} in {context.Channel}"; + } + } +} diff --git a/src/Discord.Net.Interactions/Info/Commands/ContextCommands/UserCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/ContextCommands/UserCommandInfo.cs new file mode 100644 index 000000000..8862e1798 --- /dev/null +++ b/src/Discord.Net.Interactions/Info/Commands/ContextCommands/UserCommandInfo.cs @@ -0,0 +1,41 @@ +using System; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Represents the info class of an attribute based method for command type . + /// + public class UserCommandInfo : ContextCommandInfo + { + internal UserCommandInfo(Builders.ContextCommandBuilder builder, ModuleInfo module, InteractionService commandService) + : base(builder, module, commandService) { } + + /// + public override async Task ExecuteAsync(IInteractionContext context, IServiceProvider services) + { + if (context.Interaction is not IUserCommandInteraction userCommand) + return ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Message Command Interation"); + + try + { + object[] args = new object[1] { userCommand.Data.User }; + + return await RunAsync(context, args, services).ConfigureAwait(false); + } + catch (Exception ex) + { + return ExecuteResult.FromError(ex); + } + } + + /// + protected override string GetLogString(IInteractionContext context) + { + if (context.Guild != null) + return $"User Command: \"{base.ToString()}\" for {context.User} in {context.Guild}/{context.Channel}"; + else + return $"User Command: \"{base.ToString()}\" for {context.User} in {context.Channel}"; + } + } +} diff --git a/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs new file mode 100644 index 000000000..116a07ab4 --- /dev/null +++ b/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs @@ -0,0 +1,112 @@ +using Discord.Rest; +using Discord.WebSocket; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Represents the info class of an attribute based method for command type . + /// + public class SlashCommandInfo : CommandInfo, IApplicationCommandInfo + { + /// + /// Gets the command description that will be displayed on Discord. + /// + public string Description { get; } + + /// + public ApplicationCommandType CommandType { get; } = ApplicationCommandType.Slash; + + /// + public bool DefaultPermission { get; } + + /// + public override IReadOnlyCollection Parameters { get; } + + /// + public override bool SupportsWildCards => false; + + internal SlashCommandInfo (Builders.SlashCommandBuilder builder, ModuleInfo module, InteractionService commandService) : base(builder, module, commandService) + { + Description = builder.Description; + DefaultPermission = builder.DefaultPermission; + Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray(); + } + + /// + public override async Task ExecuteAsync (IInteractionContext context, IServiceProvider services) + { + if(context.Interaction is not ISlashCommandInteraction slashCommand) + return ExecuteResult.FromError(InteractionCommandError.ParseFailed, $"Provided {nameof(IInteractionContext)} doesn't belong to a Slash Command Interaction"); + + var options = slashCommand.Data.Options; + + while (options != null && options.Any(x => x.Type == ApplicationCommandOptionType.SubCommand || x.Type == ApplicationCommandOptionType.SubCommandGroup)) + options = options.ElementAt(0)?.Options; + + return await ExecuteAsync(context, Parameters, options?.ToList(), services); + } + + private async Task ExecuteAsync (IInteractionContext context, IEnumerable paramList, + List argList, IServiceProvider services) + { + try + { + if (paramList?.Count() < argList?.Count()) + return ExecuteResult.FromError(InteractionCommandError.BadArgs ,"Command was invoked with too many parameters"); + + var args = new object[paramList.Count()]; + + for (var i = 0; i < paramList.Count(); i++) + { + var parameter = paramList.ElementAt(i); + + var arg = argList?.Find(x => string.Equals(x.Name, parameter.Name, StringComparison.OrdinalIgnoreCase)); + + if (arg == default) + { + if (parameter.IsRequired) + return ExecuteResult.FromError(InteractionCommandError.BadArgs, "Command was invoked with too few parameters"); + else + args[i] = parameter.DefaultValue; + } + else + { + var typeConverter = parameter.TypeConverter; + + var readResult = await typeConverter.ReadAsync(context, arg, services).ConfigureAwait(false); + + if (!readResult.IsSuccess) + { + await InvokeModuleEvent(context, readResult).ConfigureAwait(false); + return readResult; + } + + args[i] = readResult.Value; + } + } + + return await RunAsync(context, args, services).ConfigureAwait(false); + } + catch (Exception ex) + { + return ExecuteResult.FromError(ex); + } + } + + protected override Task InvokeModuleEvent (IInteractionContext context, IResult result) + => CommandService._slashCommandExecutedEvent.InvokeAsync(this, context, result); + + protected override string GetLogString (IInteractionContext context) + { + if (context.Guild != null) + return $"Slash Command: \"{base.ToString()}\" for {context.User} in {context.Guild}/{context.Channel}"; + else + return $"Slash Command: \"{base.ToString()}\" for {context.User} in {context.Channel}"; + } + } +} diff --git a/src/Discord.Net.Interactions/Info/IApplicationCommandInfo.cs b/src/Discord.Net.Interactions/Info/IApplicationCommandInfo.cs new file mode 100644 index 000000000..1e0d532b0 --- /dev/null +++ b/src/Discord.Net.Interactions/Info/IApplicationCommandInfo.cs @@ -0,0 +1,23 @@ +namespace Discord.Interactions +{ + /// + /// Represents a command that can be registered to Discord. + /// + public interface IApplicationCommandInfo + { + /// + /// Gets the name of this command. + /// + string Name { get; } + + /// + /// Gets the type of this command. + /// + ApplicationCommandType CommandType { get; } + + /// + /// Gets the DefaultPermission of this command. + /// + bool DefaultPermission { get; } + } +} diff --git a/src/Discord.Net.Interactions/Info/ICommandInfo.cs b/src/Discord.Net.Interactions/Info/ICommandInfo.cs new file mode 100644 index 000000000..843d5198b --- /dev/null +++ b/src/Discord.Net.Interactions/Info/ICommandInfo.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Represent a command information object that can be executed. + /// + public interface ICommandInfo + { + /// + /// Gets the name of the command. + /// + string Name { get; } + + /// + /// Gets the name of the command handler method. + /// + string MethodName { get; } + + /// + /// Gets if this command will be registered and executed as a standalone command, unaffected by the s of + /// of the commands parents. + /// + bool IgnoreGroupNames { get; } + + /// + /// Gets wheter this command supports wild card patterns. + /// + bool SupportsWildCards { get; } + + /// + /// Gets if this command is a top level command and none of its parents have a . + /// + bool IsTopLevelCommand { get; } + + /// + /// Gets the module that the method belongs to. + /// + ModuleInfo Module { get; } + + /// + /// Gets the the underlying command service. + /// + InteractionService CommandService { get; } + + /// + /// Get the run mode this command gets executed with. + /// + RunMode RunMode { get; } + + /// + /// Gets a collection of the attributes of this command. + /// + IReadOnlyCollection Attributes { get; } + + /// + /// Gets a collection of the preconditions of this command. + /// + IReadOnlyCollection Preconditions { get; } + + /// + /// Gets a collection of the parameters of this command. + /// + IReadOnlyCollection Parameters { get; } + + /// + /// Executes the command with the provided context. + /// + /// The execution context. + /// Dependencies that will be used to create the module instance. + /// + /// A task representing the execution process. The task result contains the execution result. + /// + Task ExecuteAsync (IInteractionContext context, IServiceProvider services); + + /// + /// Check if an execution context meets the command precondition requirements. + /// + Task CheckPreconditionsAsync (IInteractionContext context, IServiceProvider services); + } +} diff --git a/src/Discord.Net.Interactions/Info/IParameterInfo.cs b/src/Discord.Net.Interactions/Info/IParameterInfo.cs new file mode 100644 index 000000000..8244476e1 --- /dev/null +++ b/src/Discord.Net.Interactions/Info/IParameterInfo.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Represents a parameter. + /// + public interface IParameterInfo + { + /// + /// Gets the command that this parameter belongs to. + /// + ICommandInfo Command { get; } + + /// + /// Gets the name of this parameter. + /// + string Name { get; } + + /// + /// Gets the type of this parameter. + /// + Type ParameterType { get; } + + /// + /// Gets whether this parameter is required. + /// + bool IsRequired { get; } + + /// + /// Gets whether this parameter is marked with a keyword. + /// + bool IsParameterArray { get; } + + /// + /// Gets the default value of this parameter if the parameter is optional. + /// + object DefaultValue { get; } + + /// + /// Gets a list of the attributes this parameter has. + /// + IReadOnlyCollection Attributes { get; } + + /// + /// Gets a list of the preconditions this parameter has. + /// + IReadOnlyCollection Preconditions { get; } + + /// + /// Check if an execution context meets the parameter precondition requirements. + /// + Task CheckPreconditionsAsync (IInteractionContext context, object value, IServiceProvider services); + } +} diff --git a/src/Discord.Net.Interactions/Info/ModuleInfo.cs b/src/Discord.Net.Interactions/Info/ModuleInfo.cs new file mode 100644 index 000000000..4388ea722 --- /dev/null +++ b/src/Discord.Net.Interactions/Info/ModuleInfo.cs @@ -0,0 +1,217 @@ +using Discord.Interactions.Builders; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; + +namespace Discord.Interactions +{ + /// + /// Contains the information of a Interactions Module. + /// + public class ModuleInfo + { + internal ILookup GroupedPreconditions { get; } + + /// + /// Gets the underlying command service. + /// + public InteractionService CommandService { get; } + + /// + /// Gets the name of this module class. + /// + public string Name { get; } + + /// + /// Gets the group name of this module, if the module is marked with a . + /// + public string SlashGroupName { get; } + + /// + /// Gets if this module is marked with a . + /// + public bool IsSlashGroup => !string.IsNullOrEmpty(SlashGroupName); + + /// + /// Gets the description of this module if is . + /// + public string Description { get; } + + /// + /// Gets the default Permission of this module. + /// + public bool DefaultPermission { get; } + + /// + /// Gets the collection of Sub Modules of this module. + /// + public IReadOnlyList SubModules { get; } + + /// + /// Gets the Slash Commands that are declared in this module. + /// + public IReadOnlyList SlashCommands { get; } + + /// + /// Gets the Context Commands that are declared in this module. + /// + public IReadOnlyList ContextCommands { get; } + + /// + /// Gets the Component Commands that are declared in this module. + /// + public IReadOnlyCollection ComponentCommands { get; } + + /// + /// Gets the Autocomplete Commands that are declared in this module. + /// + public IReadOnlyCollection AutocompleteCommands { get; } + + /// + /// Gets the declaring type of this module, if is . + /// + public ModuleInfo Parent { get; } + + /// + /// Gets if this module is declared by another . + /// + public bool IsSubModule => Parent != null; + + /// + /// Gets a collection of the attributes of this module. + /// + public IReadOnlyCollection Attributes { get; } + + /// + /// Gets a collection of the preconditions of this module. + /// + public IReadOnlyCollection Preconditions { get; } + + /// + /// Gets if this module has a valid and has no parent with a . + /// + public bool IsTopLevelGroup { get; } + + /// + /// Gets if this module will not be registered by + /// or methods. + /// + public bool DontAutoRegister { get; } + + internal ModuleInfo (ModuleBuilder builder, InteractionService commandService, IServiceProvider services, ModuleInfo parent = null) + { + CommandService = commandService; + + Name = builder.Name; + SlashGroupName = builder.SlashGroupName; + Description = builder.Description; + Parent = parent; + DefaultPermission = builder.DefaultPermission; + SlashCommands = BuildSlashCommands(builder).ToImmutableArray(); + ContextCommands = BuildContextCommands(builder).ToImmutableArray(); + ComponentCommands = BuildComponentCommands(builder).ToImmutableArray(); + AutocompleteCommands = BuildAutocompleteCommands(builder).ToImmutableArray(); + SubModules = BuildSubModules(builder, commandService, services).ToImmutableArray(); + Attributes = BuildAttributes(builder).ToImmutableArray(); + Preconditions = BuildPreconditions(builder).ToImmutableArray(); + IsTopLevelGroup = IsSlashGroup && CheckTopLevel(parent); + DontAutoRegister = builder.DontAutoRegister; + + GroupedPreconditions = Preconditions.ToLookup(x => x.Group, x => x, StringComparer.Ordinal); + } + + private IEnumerable BuildSubModules (ModuleBuilder builder, InteractionService commandService, IServiceProvider services) + { + var result = new List(); + + foreach (Builders.ModuleBuilder moduleBuilder in builder.SubModules) + result.Add(moduleBuilder.Build(commandService, services, this)); + + return result; + } + + private IEnumerable BuildSlashCommands (ModuleBuilder builder) + { + var result = new List(); + + foreach (Builders.SlashCommandBuilder commandBuilder in builder.SlashCommands) + result.Add(commandBuilder.Build(this, CommandService)); + + return result; + } + + private IEnumerable BuildContextCommands (ModuleBuilder builder) + { + var result = new List(); + + foreach (Builders.ContextCommandBuilder commandBuilder in builder.ContextCommands) + result.Add(commandBuilder.Build(this, CommandService)); + + return result; + } + + private IEnumerable BuildComponentCommands (ModuleBuilder builder) + { + var result = new List(); + + foreach (var interactionBuilder in builder.ComponentCommands) + result.Add(interactionBuilder.Build(this, CommandService)); + + return result; + } + + private IEnumerable BuildAutocompleteCommands( ModuleBuilder builder) + { + var result = new List(); + + foreach (var commandBuilder in builder.AutocompleteCommands) + result.Add(commandBuilder.Build(this, CommandService)); + + return result; + } + + private IEnumerable BuildAttributes (ModuleBuilder builder) + { + var result = new List(); + var currentParent = builder; + + while (currentParent != null) + { + result.AddRange(currentParent.Attributes); + currentParent = currentParent.Parent; + } + + return result; + } + + private static IEnumerable BuildPreconditions (ModuleBuilder builder) + { + var preconditions = new List(); + + var parent = builder; + + while (parent != null) + { + preconditions.AddRange(parent.Preconditions); + parent = parent.Parent; + } + + return preconditions; + } + + private static bool CheckTopLevel (ModuleInfo parent) + { + var currentParent = parent; + + while (currentParent != null) + { + if (currentParent.IsSlashGroup) + return false; + + currentParent = currentParent.Parent; + } + return true; + } + } +} diff --git a/src/Discord.Net.Interactions/Info/Parameters/CommandParameterInfo.cs b/src/Discord.Net.Interactions/Info/Parameters/CommandParameterInfo.cs new file mode 100644 index 000000000..050cf4230 --- /dev/null +++ b/src/Discord.Net.Interactions/Info/Parameters/CommandParameterInfo.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Represents the base parameter info class for commands. + /// + public class CommandParameterInfo : IParameterInfo + { + /// + public ICommandInfo Command { get; } + + /// + public string Name { get; } + + /// + public Type ParameterType { get; } + + /// + public bool IsRequired { get; } + + /// + public bool IsParameterArray { get; } + + /// + public object DefaultValue { get; } + + /// + public IReadOnlyCollection Attributes { get; } + + /// + public IReadOnlyCollection Preconditions { get; } + + internal CommandParameterInfo (Builders.IParameterBuilder builder, ICommandInfo command) + { + Command = command; + Name = builder.Name; + ParameterType = builder.ParameterType; + IsRequired = builder.IsRequired; + IsParameterArray = builder.IsParameterArray; + DefaultValue = builder.DefaultValue; + Attributes = builder.Attributes.ToImmutableArray(); + Preconditions = builder.Preconditions.ToImmutableArray(); + } + + /// + public async Task CheckPreconditionsAsync (IInteractionContext context, object value, IServiceProvider services) + { + foreach (var precondition in Preconditions) + { + var result = await precondition.CheckRequirementsAsync(context, this, value, services).ConfigureAwait(false); + if (!result.IsSuccess) + return result; + } + + return PreconditionResult.FromSuccess(); + } + } +} diff --git a/src/Discord.Net.Interactions/Info/Parameters/SlashCommandParameterInfo.cs b/src/Discord.Net.Interactions/Info/Parameters/SlashCommandParameterInfo.cs new file mode 100644 index 000000000..68b63c806 --- /dev/null +++ b/src/Discord.Net.Interactions/Info/Parameters/SlashCommandParameterInfo.cs @@ -0,0 +1,72 @@ +using System.Collections.Generic; +using System.Collections.Immutable; + +namespace Discord.Interactions +{ + /// + /// Represents the parameter info class for commands. + /// + public class SlashCommandParameterInfo : CommandParameterInfo + { + /// + public new SlashCommandInfo Command => base.Command as SlashCommandInfo; + + /// + /// Gets the description of the Slash Command Parameter. + /// + public string Description { get; } + + /// + /// Gets the minimum value permitted for a number type parameter. + /// + public double? MinValue { get; } + + /// + /// Gets the maxmimum value permitted for a number type parameter. + /// + public double? MaxValue { get; } + + /// + /// Gets the that will be used to convert the incoming into + /// . + /// + public TypeConverter TypeConverter { get; } + + /// + /// Gets the thats linked to this parameter. + /// + public IAutocompleteHandler AutocompleteHandler { get; } + + /// + /// Gets whether this parameter is configured for Autocomplete Interactions. + /// + public bool IsAutocomplete { get; } + + /// + /// Gets the Discord option type this parameter represents. + /// + public ApplicationCommandOptionType DiscordOptionType => TypeConverter.GetDiscordType(); + + /// + /// Gets the parameter choices of this Slash Application Command parameter. + /// + public IReadOnlyCollection Choices { get; } + + /// + /// Gets the allowed channel types for this option. + /// + public IReadOnlyCollection ChannelTypes { get; } + + internal SlashCommandParameterInfo(Builders.SlashCommandParameterBuilder builder, SlashCommandInfo command) : base(builder, command) + { + TypeConverter = builder.TypeConverter; + AutocompleteHandler = builder.AutocompleteHandler; + Description = builder.Description; + MaxValue = builder.MaxValue; + MinValue = builder.MinValue; + IsAutocomplete = builder.Autocomplete; + Choices = builder.Choices.ToImmutableArray(); + ChannelTypes = builder.ChannelTypes.ToImmutableArray(); + } + } +} diff --git a/src/Discord.Net.Interactions/InteractionCommandError.cs b/src/Discord.Net.Interactions/InteractionCommandError.cs new file mode 100644 index 000000000..7000e9ab3 --- /dev/null +++ b/src/Discord.Net.Interactions/InteractionCommandError.cs @@ -0,0 +1,43 @@ +namespace Discord.Interactions +{ + /// + /// Defines the type of error a command can throw. + /// + public enum InteractionCommandError + { + /// + /// Thrown when the command is unknown. + /// + UnknownCommand, + + /// + /// Thrown when the Slash Command parameter fails to be converted by a TypeReader. + /// + ConvertFailed, + + /// + /// Thrown when the input text has too few or too many arguments. + /// + BadArgs, + + /// + /// Thrown when an exception occurs mid-command execution. + /// + Exception, + + /// + /// Thrown when the command is not successfully executed on runtime. + /// + Unsuccessful, + + /// + /// Thrown when the command fails to meet a 's conditions. + /// + UnmetPrecondition, + + /// + /// Thrown when the command context cannot be parsed by the . + /// + ParseFailed + } +} diff --git a/src/Discord.Net.Interactions/InteractionContext.cs b/src/Discord.Net.Interactions/InteractionContext.cs new file mode 100644 index 000000000..99a8d8736 --- /dev/null +++ b/src/Discord.Net.Interactions/InteractionContext.cs @@ -0,0 +1,34 @@ +namespace Discord.Interactions +{ + /// + public class InteractionContext : IInteractionContext + { + /// + public IDiscordClient Client { get; } + /// + public IGuild Guild { get; } + /// + public IMessageChannel Channel { get; } + /// + public IUser User { get; } + /// + public IDiscordInteraction Interaction { get; } + + /// + /// Initializes a new . + /// + /// The underlying client. + /// The underlying interaction. + /// who executed the command. + /// the command originated from. + public InteractionContext(IDiscordClient client, IDiscordInteraction interaction, IMessageChannel channel = null) + { + Client = client; + Interaction = interaction; + Channel = channel; + Guild = (interaction.User as IGuildUser)?.Guild; + User = interaction.User; + Interaction = interaction; + } + } +} diff --git a/src/Discord.Net.Interactions/InteractionModuleBase.cs b/src/Discord.Net.Interactions/InteractionModuleBase.cs new file mode 100644 index 000000000..95e64916f --- /dev/null +++ b/src/Discord.Net.Interactions/InteractionModuleBase.cs @@ -0,0 +1,77 @@ +using System; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Provides a base class for a command module to inherit from. + /// + /// Type of interaction context to be injected into the module. + public abstract class InteractionModuleBase : IInteractionModuleBase where T : class, IInteractionContext + { + /// + /// Gets the underlying context of the command. + /// + public T Context { get; private set; } + + /// + public virtual void AfterExecute (ICommandInfo command) { } + + /// + public virtual void BeforeExecute (ICommandInfo command) { } + + /// + public virtual Task BeforeExecuteAsync(ICommandInfo command) => Task.CompletedTask; + + /// + public virtual Task AfterExecuteAsync(ICommandInfo command) => Task.CompletedTask; + + /// + public virtual void OnModuleBuilding (InteractionService commandService, ModuleInfo module) { } + + /// + public virtual void Construct (Builders.ModuleBuilder builder, InteractionService commandService) { } + + internal void SetContext (IInteractionContext context) + { + var newValue = context as T; + Context = newValue ?? throw new InvalidOperationException($"Invalid context type. Expected {typeof(T).Name}, got {context.GetType().Name}."); + } + + /// + protected virtual async Task DeferAsync(bool ephemeral = false, RequestOptions options = null) => + await Context.Interaction.DeferAsync(ephemeral, options).ConfigureAwait(false); + + /// + protected virtual async Task RespondAsync (string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, Embed embed = null) => + await Context.Interaction.RespondAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + + /// + protected virtual async Task FollowupAsync (string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, Embed embed = null) => + await Context.Interaction.FollowupAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + + /// + protected virtual async Task ReplyAsync (string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, + AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null) => + await Context.Channel.SendMessageAsync(text, false, embed, options, allowedMentions, messageReference, components).ConfigureAwait(false); + + /// + protected virtual async Task DeleteOriginalResponseAsync ( ) + { + var response = await Context.Interaction.GetOriginalResponseAsync().ConfigureAwait(false); + await response.DeleteAsync().ConfigureAwait(false); + } + + //IInteractionModuleBase + + /// + void IInteractionModuleBase.SetContext (IInteractionContext context) => SetContext(context); + } + + /// + /// Provides a base class for a command module to inherit from. + /// + public abstract class InteractionModuleBase : InteractionModuleBase { } +} diff --git a/src/Discord.Net.Interactions/InteractionService.cs b/src/Discord.Net.Interactions/InteractionService.cs new file mode 100644 index 000000000..ac96f08ec --- /dev/null +++ b/src/Discord.Net.Interactions/InteractionService.cs @@ -0,0 +1,947 @@ +using Discord.Interactions.Builders; +using Discord.Logging; +using Discord.Rest; +using Discord.WebSocket; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Provides the framework for building and registering Discord Application Commands. + /// + public class InteractionService : IDisposable + { + /// + /// Occurs when a Slash Command related information is recieved. + /// + public event Func Log { add { _logEvent.Add(value); } remove { _logEvent.Remove(value); } } + internal readonly AsyncEvent> _logEvent = new (); + + /// + /// Occurs when a Slash Command is executed. + /// + public event Func SlashCommandExecuted { add { _slashCommandExecutedEvent.Add(value); } remove { _slashCommandExecutedEvent.Remove(value); } } + internal readonly AsyncEvent> _slashCommandExecutedEvent = new (); + + /// + /// Occurs when a Context Command is executed. + /// + public event Func ContextCommandExecuted { add { _contextCommandExecutedEvent.Add(value); } remove { _contextCommandExecutedEvent.Remove(value); } } + internal readonly AsyncEvent> _contextCommandExecutedEvent = new (); + + /// + /// Occurs when a Message Component command is executed. + /// + public event Func ComponentCommandExecuted { add { _componentCommandExecutedEvent.Add(value); } remove { _componentCommandExecutedEvent.Remove(value); } } + internal readonly AsyncEvent> _componentCommandExecutedEvent = new (); + + /// + /// Occurs when a Autocomplete command is executed. + /// + public event Func AutocompleteCommandExecuted { add { _autocompleteCommandExecutedEvent.Add(value); } remove { _autocompleteCommandExecutedEvent.Remove(value); } } + internal readonly AsyncEvent> _autocompleteCommandExecutedEvent = new(); + + /// + /// Occurs when a AutocompleteHandler is executed. + /// + public event Func AutocompleteHandlerExecuted { add { _autocompleteHandlerExecutedEvent.Add(value); } remove { _autocompleteHandlerExecutedEvent.Remove(value); } } + internal readonly AsyncEvent> _autocompleteHandlerExecutedEvent = new(); + + private readonly ConcurrentDictionary _typedModuleDefs; + private readonly CommandMap _slashCommandMap; + private readonly ConcurrentDictionary> _contextCommandMaps; + private readonly CommandMap _componentCommandMap; + private readonly CommandMap _autocompleteCommandMap; + private readonly HashSet _moduleDefs; + private readonly ConcurrentDictionary _typeConverters; + private readonly ConcurrentDictionary _genericTypeConverters; + private readonly ConcurrentDictionary _autocompleteHandlers = new(); + private readonly SemaphoreSlim _lock; + internal readonly Logger _cmdLogger; + internal readonly LogManager _logManager; + internal readonly Func _getRestClient; + + internal readonly bool _throwOnError, _useCompiledLambda, _enableAutocompleteHandlers, _autoServiceScopes; + internal readonly string _wildCardExp; + internal readonly RunMode _runMode; + internal readonly RestResponseCallback _restResponseCallback; + + /// + /// Rest client to be used to register application commands. + /// + public DiscordRestClient RestClient { get => _getRestClient(); } + + /// + /// Represents all modules loaded within . + /// + public IReadOnlyList Modules => _moduleDefs.ToList(); + + /// + /// Represents all Slash Commands loaded within . + /// + public IReadOnlyList SlashCommands => _moduleDefs.SelectMany(x => x.SlashCommands).ToList(); + + /// + /// Represents all Context Commands loaded within . + /// + public IReadOnlyList ContextCommands => _moduleDefs.SelectMany(x => x.ContextCommands).ToList(); + + /// + /// Represents all Component Commands loaded within . + /// + public IReadOnlyCollection ComponentCommands => _moduleDefs.SelectMany(x => x.ComponentCommands).ToList(); + + /// + /// Initialize a with provided configurations. + /// + /// The discord client. + /// The configuration class. + public InteractionService (DiscordSocketClient discord, InteractionServiceConfig config = null) + : this(() => discord.Rest, config ?? new InteractionServiceConfig()) { } + + /// + /// Initialize a with provided configurations. + /// + /// The discord client. + /// The configuration class. + public InteractionService (DiscordShardedClient discord, InteractionServiceConfig config = null) + : this(() => discord.Rest, config ?? new InteractionServiceConfig()) { } + + /// + /// Initialize a with provided configurations. + /// + /// The discord client. + /// The configuration class. + public InteractionService (BaseSocketClient discord, InteractionServiceConfig config = null) + :this(() => discord.Rest, config ?? new InteractionServiceConfig()) { } + + /// + /// Initialize a with provided configurations. + /// + /// The discord client. + /// The configuration class. + public InteractionService (DiscordRestClient discord, InteractionServiceConfig config = null) + :this(() => discord, config ?? new InteractionServiceConfig()) { } + + private InteractionService (Func getRestClient, InteractionServiceConfig config = null) + { + config ??= new InteractionServiceConfig(); + + _lock = new SemaphoreSlim(1, 1); + _typedModuleDefs = new ConcurrentDictionary(); + _moduleDefs = new HashSet(); + + _logManager = new LogManager(config.LogLevel); + _logManager.Message += async msg => await _logEvent.InvokeAsync(msg).ConfigureAwait(false); + _cmdLogger = _logManager.CreateLogger("App Commands"); + + _slashCommandMap = new CommandMap(this); + _contextCommandMaps = new ConcurrentDictionary>(); + _componentCommandMap = new CommandMap(this, config.InteractionCustomIdDelimiters); + _autocompleteCommandMap = new CommandMap(this); + + _getRestClient = getRestClient; + + _runMode = config.DefaultRunMode; + if (_runMode == RunMode.Default) + throw new InvalidOperationException($"RunMode cannot be set to {RunMode.Default}"); + + _throwOnError = config.ThrowOnError; + _wildCardExp = config.WildCardExpression; + _useCompiledLambda = config.UseCompiledLambda; + _enableAutocompleteHandlers = config.EnableAutocompleteHandlers; + _autoServiceScopes = config.AutoServiceScopes; + _restResponseCallback = config.RestResponseCallback; + + _genericTypeConverters = new ConcurrentDictionary + { + [typeof(IChannel)] = typeof(DefaultChannelConverter<>), + [typeof(IRole)] = typeof(DefaultRoleConverter<>), + [typeof(IUser)] = typeof(DefaultUserConverter<>), + [typeof(IMentionable)] = typeof(DefaultMentionableConverter<>), + [typeof(IConvertible)] = typeof(DefaultValueConverter<>), + [typeof(Enum)] = typeof(EnumConverter<>), + [typeof(Nullable<>)] = typeof(NullableConverter<>), + }; + + _typeConverters = new ConcurrentDictionary + { + [typeof(TimeSpan)] = new TimeSpanConverter() + }; + } + + /// + /// Create and loads a using a builder factory. + /// + /// Name of the module. + /// The for your dependency injection solution if using one; otherwise, pass null. + /// Module builder factory. + /// + /// A task representing the operation for adding modules. The task result contains the built module instance. + /// + public async Task CreateModuleAsync(string name, IServiceProvider services, Action buildFunc) + { + services ??= EmptyServiceProvider.Instance; + + await _lock.WaitAsync().ConfigureAwait(false); + try + { + var builder = new ModuleBuilder(this, name); + buildFunc(builder); + + var moduleInfo = builder.Build(this, services); + LoadModuleInternal(moduleInfo); + + return moduleInfo; + } + finally + { + _lock.Release(); + } + } + + /// + /// Discover and load command modules from an . + /// + /// the command modules are defined in. + /// The for your dependency injection solution if using one; otherwise, pass null. + /// + /// A task representing the operation for adding modules. The task result contains a collection of the modules added. + /// + public async Task> AddModulesAsync (Assembly assembly, IServiceProvider services) + { + services ??= EmptyServiceProvider.Instance; + + await _lock.WaitAsync().ConfigureAwait(false); + + try + { + var types = await ModuleClassBuilder.SearchAsync(assembly, this); + var moduleDefs = await ModuleClassBuilder.BuildAsync(types, this, services); + + foreach (var info in moduleDefs) + { + _typedModuleDefs[info.Key] = info.Value; + LoadModuleInternal(info.Value); + } + return moduleDefs.Values; + } + finally + { + _lock.Release(); + } + } + + /// + /// Add a command module from a . + /// + /// Type of the module. + /// The for your dependency injection solution if using one; otherwise, pass null . + /// + /// A task representing the operation for adding the module. The task result contains the built module. + /// + /// + /// Thrown if this module has already been added. + /// + /// + /// Thrown when the is not a valid module definition. + /// + public Task AddModuleAsync (IServiceProvider services) where T : class => + AddModuleAsync(typeof(T), services); + + /// + /// Add a command module from a . + /// + /// Type of the module. + /// The for your dependency injection solution if using one; otherwise, pass null . + /// + /// A task representing the operation for adding the module. The task result contains the built module. + /// + /// + /// Thrown if this module has already been added. + /// + /// + /// Thrown when the is not a valid module definition. + /// + public async Task AddModuleAsync (Type type, IServiceProvider services) + { + if (!typeof(IInteractionModuleBase).IsAssignableFrom(type)) + throw new ArgumentException("Type parameter must be a type of Slash Module", "T"); + + services ??= EmptyServiceProvider.Instance; + + await _lock.WaitAsync().ConfigureAwait(false); + + try + { + var typeInfo = type.GetTypeInfo(); + + if (_typedModuleDefs.ContainsKey(typeInfo)) + throw new ArgumentException("Module definition for this type already exists."); + + var moduleDef = ( await ModuleClassBuilder.BuildAsync(new List { typeInfo }, this, services).ConfigureAwait(false) ).FirstOrDefault(); + + if (moduleDef.Value == default) + throw new InvalidOperationException($"Could not build the module {typeInfo.FullName}, did you pass an invalid type?"); + + if (!_typedModuleDefs.TryAdd(type, moduleDef.Value)) + throw new ArgumentException("Module definition for this type already exists."); + + _typedModuleDefs[moduleDef.Key] = moduleDef.Value; + LoadModuleInternal(moduleDef.Value); + + return moduleDef.Value; + } + finally + { + _lock.Release(); + } + } + + /// + /// Register Application Commands from and to a guild. + /// + /// Id of the target guild. + /// If , this operation will not delete the commands that are missing from . + /// + /// A task representing the command registration process. The task result contains the active application commands of the target guild. + /// + public async Task> RegisterCommandsToGuildAsync (ulong guildId, bool deleteMissing = true) + { + EnsureClientReady(); + + var topLevelModules = _moduleDefs.Where(x => !x.IsSubModule); + var props = topLevelModules.SelectMany(x => x.ToApplicationCommandProps()).ToList(); + + if (!deleteMissing) + { + + var existing = await RestClient.GetGuildApplicationCommands(guildId).ConfigureAwait(false); + var missing = existing.Where(x => !props.Any(y => y.Name.IsSpecified && y.Name.Value == x.Name)); + props.AddRange(missing.Select(x => x.ToApplicationCommandProps())); + } + + return await RestClient.BulkOverwriteGuildCommands(props.ToArray(), guildId).ConfigureAwait(false); + } + + /// + /// Register Application Commands from and to Discord on in global scope. + /// + /// If , this operation will not delete the commands that are missing from . + /// + /// A task representing the command registration process. The task result contains the active global application commands of bot. + /// + public async Task> RegisterCommandsGloballyAsync (bool deleteMissing = true) + { + EnsureClientReady(); + + var topLevelModules = _moduleDefs.Where(x => !x.IsSubModule); + var props = topLevelModules.SelectMany(x => x.ToApplicationCommandProps()).ToList(); + + if (!deleteMissing) + { + var existing = await RestClient.GetGlobalApplicationCommands().ConfigureAwait(false); + var missing = existing.Where(x => !props.Any(y => y.Name.IsSpecified && y.Name.Value == x.Name)); + props.AddRange(missing.Select(x => x.ToApplicationCommandProps())); + } + + return await RestClient.BulkOverwriteGlobalCommands(props.ToArray()).ConfigureAwait(false); + } + + /// + /// Register Application Commands from to a guild. + /// + /// + /// Commands will be registered as standalone commands, if you want the to take effect, + /// use . Registering a commands without group names might cause the command traversal to fail. + /// + /// The target guild. + /// Commands to be registered to Discord. + /// + /// A task representing the command registration process. The task result contains the active application commands of the target guild. + /// + public async Task> AddCommandsToGuildAsync(IGuild guild, bool deleteMissing = false, params ICommandInfo[] commands) + { + EnsureClientReady(); + + if (guild is null) + throw new ArgumentNullException(nameof(guild)); + + var props = new List(); + + foreach (var command in commands) + { + switch (command) + { + case SlashCommandInfo slashCommand: + props.Add(slashCommand.ToApplicationCommandProps()); + break; + case ContextCommandInfo contextCommand: + props.Add(contextCommand.ToApplicationCommandProps()); + break; + default: + throw new InvalidOperationException($"Command type {command.GetType().FullName} isn't supported yet"); + } + } + + if (!deleteMissing) + { + var existing = await RestClient.GetGuildApplicationCommands(guild.Id).ConfigureAwait(false); + var missing = existing.Where(x => !props.Any(y => y.Name.IsSpecified && y.Name.Value == x.Name)); + props.AddRange(missing.Select(x => x.ToApplicationCommandProps())); + } + + return await RestClient.BulkOverwriteGuildCommands(props.ToArray(), guild.Id).ConfigureAwait(false); + } + + /// + /// Register Application Commands from modules provided in to a guild. + /// + /// The target guild. + /// Modules to be registered to Discord. + /// + /// A task representing the command registration process. The task result contains the active application commands of the target guild. + /// + public async Task> AddModulesToGuildAsync(IGuild guild, bool deleteMissing = false, params ModuleInfo[] modules) + { + EnsureClientReady(); + + if (guild is null) + throw new ArgumentNullException(nameof(guild)); + + var props = modules.SelectMany(x => x.ToApplicationCommandProps(true)).ToList(); + + if (!deleteMissing) + { + var existing = await RestClient.GetGuildApplicationCommands(guild.Id).ConfigureAwait(false); + var missing = existing.Where(x => !props.Any(y => y.Name.IsSpecified && y.Name.Value == x.Name)); + props.AddRange(missing.Select(x => x.ToApplicationCommandProps())); + } + + return await RestClient.BulkOverwriteGuildCommands(props.ToArray(), guild.Id).ConfigureAwait(false); + } + + /// + /// Register Application Commands from modules provided in as global commands. + /// + /// Modules to be registered to Discord. + /// + /// A task representing the command registration process. The task result contains the active application commands of the target guild. + /// + public async Task> AddModulesGloballyAsync(bool deleteMissing = false, params ModuleInfo[] modules) + { + EnsureClientReady(); + + var props = modules.SelectMany(x => x.ToApplicationCommandProps(true)).ToList(); + + if (!deleteMissing) + { + var existing = await RestClient.GetGlobalApplicationCommands().ConfigureAwait(false); + var missing = existing.Where(x => !props.Any(y => y.Name.IsSpecified && y.Name.Value == x.Name)); + props.AddRange(missing.Select(x => x.ToApplicationCommandProps())); + } + + return await RestClient.BulkOverwriteGlobalCommands(props.ToArray()).ConfigureAwait(false); + } + + /// + /// Register Application Commands from as global commands. + /// + /// + /// Commands will be registered as standalone commands, if you want the to take effect, + /// use . Registering a commands without group names might cause the command traversal to fail. + /// + /// Commands to be registered to Discord. + /// + /// A task representing the command registration process. The task result contains the active application commands of the target guild. + /// + public async Task> AddCommandsGloballyAsync(bool deleteMissing = false, params IApplicationCommandInfo[] commands) + { + EnsureClientReady(); + + var props = new List(); + + foreach (var command in commands) + { + switch (command) + { + case SlashCommandInfo slashCommand: + props.Add(slashCommand.ToApplicationCommandProps()); + break; + case ContextCommandInfo contextCommand: + props.Add(contextCommand.ToApplicationCommandProps()); + break; + default: + throw new InvalidOperationException($"Command type {command.GetType().FullName} isn't supported yet"); + } + } + + if (!deleteMissing) + { + var existing = await RestClient.GetGlobalApplicationCommands().ConfigureAwait(false); + var missing = existing.Where(x => !props.Any(y => y.Name.IsSpecified && y.Name.Value == x.Name)); + props.AddRange(missing.Select(x => x.ToApplicationCommandProps())); + } + + return await RestClient.BulkOverwriteGlobalCommands(props.ToArray()).ConfigureAwait(false); + } + + private void LoadModuleInternal (ModuleInfo module) + { + _moduleDefs.Add(module); + + foreach (var command in module.SlashCommands) + _slashCommandMap.AddCommand(command, command.IgnoreGroupNames); + + foreach (var command in module.ContextCommands) + _contextCommandMaps.GetOrAdd(command.CommandType, new CommandMap(this)).AddCommand(command, command.IgnoreGroupNames); + + foreach (var interaction in module.ComponentCommands) + _componentCommandMap.AddCommand(interaction, interaction.IgnoreGroupNames); + + foreach (var command in module.AutocompleteCommands) + _autocompleteCommandMap.AddCommand(command.GetCommandKeywords(), command); + + foreach (var subModule in module.SubModules) + LoadModuleInternal(subModule); + } + + /// + /// Remove a command module. + /// + /// The of the module. + /// + /// A task that represents the asynchronous removal operation. The task result contains a value that + /// indicates whether the module is successfully removed. + /// + public Task RemoveModuleAsync ( ) => + RemoveModuleAsync(typeof(T)); + + /// + /// Remove a command module. + /// + /// The of the module. + /// + /// A task that represents the asynchronous removal operation. The task result contains a value that + /// indicates whether the module is successfully removed. + /// + public async Task RemoveModuleAsync (Type type) + { + await _lock.WaitAsync().ConfigureAwait(false); + + try + { + if (!_typedModuleDefs.TryRemove(type, out var module)) + return false; + + return RemoveModuleInternal(module); + } + finally + { + _lock.Release(); + } + } + + /// + /// Remove a command module. + /// + /// The to be removed from the service. + /// + /// A task that represents the asynchronous removal operation. The task result contains a value that + /// indicates whether the is successfully removed. + /// + public async Task RemoveModuleAsync(ModuleInfo module) + { + await _lock.WaitAsync().ConfigureAwait(false); + + try + { + var typeModulePair = _typedModuleDefs.FirstOrDefault(x => x.Value.Equals(module)); + + if (!typeModulePair.Equals(default(KeyValuePair))) + _typedModuleDefs.TryRemove(typeModulePair.Key, out var _); + + return RemoveModuleInternal(module); + } + finally + { + _lock.Release(); + } + } + + private bool RemoveModuleInternal (ModuleInfo moduleInfo) + { + if (!_moduleDefs.Remove(moduleInfo)) + return false; + + foreach (var command in moduleInfo.SlashCommands) + { + _slashCommandMap.RemoveCommand(command); + } + + return true; + } + + /// + /// Execute a Command from a given . + /// + /// Name context of the command. + /// The service to be used in the command's dependency injection. + /// + /// A task representing the command execution process. The task result contains the result of the execution. + /// + public async Task ExecuteCommandAsync (IInteractionContext context, IServiceProvider services) + { + var interaction = context.Interaction; + + return interaction switch + { + ISlashCommandInteraction slashCommand => await ExecuteSlashCommandAsync(context, slashCommand, services).ConfigureAwait(false), + IComponentInteraction messageComponent => await ExecuteComponentCommandAsync(context, messageComponent.Data.CustomId, services).ConfigureAwait(false), + IUserCommandInteraction userCommand => await ExecuteContextCommandAsync(context, userCommand.Data.Name, ApplicationCommandType.User, services).ConfigureAwait(false), + IMessageCommandInteraction messageCommand => await ExecuteContextCommandAsync(context, messageCommand.Data.Name, ApplicationCommandType.Message, services).ConfigureAwait(false), + IAutocompleteInteraction autocomplete => await ExecuteAutocompleteAsync(context, autocomplete, services).ConfigureAwait(false), + _ => throw new InvalidOperationException($"{interaction.Type} interaction type cannot be executed by the Interaction service"), + }; + } + + private async Task ExecuteSlashCommandAsync (IInteractionContext context, ISlashCommandInteraction interaction, IServiceProvider services) + { + var keywords = interaction.Data.GetCommandKeywords(); + + var result = _slashCommandMap.GetCommand(keywords); + + if (!result.IsSuccess) + { + await _cmdLogger.DebugAsync($"Unknown slash command, skipping execution ({string.Join(" ", keywords).ToUpper()})"); + + await _slashCommandExecutedEvent.InvokeAsync(null, context, result).ConfigureAwait(false); + return result; + } + return await result.Command.ExecuteAsync(context, services).ConfigureAwait(false); + } + + private async Task ExecuteContextCommandAsync (IInteractionContext context, string input, ApplicationCommandType commandType, IServiceProvider services) + { + if (!_contextCommandMaps.TryGetValue(commandType, out var map)) + return SearchResult.FromError(input, InteractionCommandError.UnknownCommand, $"No {commandType} command found."); + + var result = map.GetCommand(input); + + if (!result.IsSuccess) + { + await _cmdLogger.DebugAsync($"Unknown context command, skipping execution ({result.Text.ToUpper()})"); + + await _contextCommandExecutedEvent.InvokeAsync(null, context, result).ConfigureAwait(false); + return result; + } + return await result.Command.ExecuteAsync(context, services).ConfigureAwait(false); + } + + private async Task ExecuteComponentCommandAsync (IInteractionContext context, string input, IServiceProvider services) + { + var result = _componentCommandMap.GetCommand(input); + + if (!result.IsSuccess) + { + await _cmdLogger.DebugAsync($"Unknown custom interaction id, skipping execution ({input.ToUpper()})"); + + await _componentCommandExecutedEvent.InvokeAsync(null, context, result).ConfigureAwait(false); + return result; + } + return await result.Command.ExecuteAsync(context, services, result.RegexCaptureGroups).ConfigureAwait(false); + } + + private async Task ExecuteAutocompleteAsync (IInteractionContext context, IAutocompleteInteraction interaction, IServiceProvider services ) + { + var keywords = interaction.Data.GetCommandKeywords(); + + if(_enableAutocompleteHandlers) + { + var autocompleteHandlerResult = _slashCommandMap.GetCommand(keywords); + + if(autocompleteHandlerResult.IsSuccess) + { + var parameter = autocompleteHandlerResult.Command.Parameters.FirstOrDefault(x => string.Equals(x.Name, interaction.Data.Current.Name, StringComparison.Ordinal)); + + if(parameter?.AutocompleteHandler is not null) + return await parameter.AutocompleteHandler.ExecuteAsync(context, interaction, parameter, services).ConfigureAwait(false); + } + } + + keywords.Add(interaction.Data.Current.Name); + + var commandResult = _autocompleteCommandMap.GetCommand(keywords); + + if(!commandResult.IsSuccess) + { + await _cmdLogger.DebugAsync($"Unknown command name, skipping autocomplete process ({interaction.Data.CommandName.ToUpper()})"); + + await _autocompleteCommandExecutedEvent.InvokeAsync(null, context, commandResult).ConfigureAwait(false); + return commandResult; + } + + return await commandResult.Command.ExecuteAsync(context, services).ConfigureAwait(false); + } + + internal TypeConverter GetTypeConverter (Type type, IServiceProvider services = null) + { + if (_typeConverters.TryGetValue(type, out var specific)) + return specific; + else if (_genericTypeConverters.Any(x => x.Key.IsAssignableFrom(type) + || (x.Key.IsGenericTypeDefinition && type.IsGenericType && x.Key.GetGenericTypeDefinition() == type.GetGenericTypeDefinition()))) + { + services ??= EmptyServiceProvider.Instance; + + var converterType = GetMostSpecificTypeConverter(type); + var converter = ReflectionUtils.CreateObject(converterType.MakeGenericType(type).GetTypeInfo(), this, services); + _typeConverters[type] = converter; + return converter; + } + + else if (_typeConverters.Any(x => x.Value.CanConvertTo(type))) + return _typeConverters.First(x => x.Value.CanConvertTo(type)).Value; + + throw new ArgumentException($"No type {nameof(TypeConverter)} is defined for this {type.FullName}", "type"); + } + + /// + /// Add a concrete type . + /// + /// Primary target of the . + /// The instance. + public void AddTypeConverter (TypeConverter converter) => + AddTypeConverter(typeof(T), converter); + + /// + /// Add a concrete type . + /// + /// Primary target of the . + /// The instance. + public void AddTypeConverter (Type type, TypeConverter converter) + { + if (!converter.CanConvertTo(type)) + throw new ArgumentException($"This {converter.GetType().FullName} cannot read {type.FullName} and cannot be registered as its {nameof(TypeConverter)}"); + + _typeConverters[type] = converter; + } + + /// + /// Add a generic type . + /// + /// Generic Type constraint of the of the . + /// Type of the . + + public void AddGenericTypeConverter (Type converterType) => + AddGenericTypeConverter(typeof(T), converterType); + + /// + /// Add a generic type . + /// + /// Generic Type constraint of the of the . + /// Type of the . + public void AddGenericTypeConverter (Type targetType, Type converterType) + { + if (!converterType.IsGenericTypeDefinition) + throw new ArgumentException($"{converterType.FullName} is not generic."); + + var genericArguments = converterType.GetGenericArguments(); + + if (genericArguments.Count() > 1) + throw new InvalidOperationException($"Valid generic {converterType.FullName}s cannot have more than 1 generic type parameter"); + + var constraints = genericArguments.SelectMany(x => x.GetGenericParameterConstraints()); + + if (!constraints.Any(x => x.IsAssignableFrom(targetType))) + throw new InvalidOperationException($"This generic class does not support type {targetType.FullName}"); + + _genericTypeConverters[targetType] = converterType; + } + + internal IAutocompleteHandler GetAutocompleteHandler(Type autocompleteHandlerType, IServiceProvider services = null) + { + services ??= EmptyServiceProvider.Instance; + + if (!_enableAutocompleteHandlers) + throw new InvalidOperationException($"{nameof(IAutocompleteHandler)}s are not enabled. To use this feature set {nameof(InteractionServiceConfig.EnableAutocompleteHandlers)} to TRUE"); + + if (_autocompleteHandlers.TryGetValue(autocompleteHandlerType, out var autocompleteHandler)) + return autocompleteHandler; + else + { + autocompleteHandler = ReflectionUtils.CreateObject(autocompleteHandlerType.GetTypeInfo(), this, services); + _autocompleteHandlers[autocompleteHandlerType] = autocompleteHandler; + return autocompleteHandler; + } + } + + /// + /// Modify the command permissions of the matching Discord Slash Command. + /// + /// Module representing the top level Slash Command. + /// Target guild. + /// New permission values. + /// + /// The active command permissions after the modification. + /// + public async Task ModifySlashCommandPermissionsAsync (ModuleInfo module, IGuild guild, + params ApplicationCommandPermission[] permissions) + { + if (!module.IsSlashGroup) + throw new InvalidOperationException($"This module does not have a {nameof(GroupAttribute)} and does not represent an Application Command"); + + if (!module.IsTopLevelGroup) + throw new InvalidOperationException("This module is not a top level application command. You cannot change its permissions"); + + if (guild is null) + throw new ArgumentNullException("guild"); + + var commands = await RestClient.GetGuildApplicationCommands(guild.Id).ConfigureAwait(false); + var appCommand = commands.First(x => x.Name == module.SlashGroupName); + + return await appCommand.ModifyCommandPermissions(permissions).ConfigureAwait(false); + } + + /// + /// Modify the command permissions of the matching Discord Slash Command. + /// + /// The Slash Command. + /// Target guild. + /// New permission values. + /// + /// The active command permissions after the modification. + /// + public async Task ModifySlashCommandPermissionsAsync (SlashCommandInfo command, IGuild guild, + params ApplicationCommandPermission[] permissions) => + await ModifyApplicationCommandPermissionsAsync(command, guild, permissions).ConfigureAwait(false); + + /// + /// Modify the command permissions of the matching Discord Slash Command. + /// + /// The Context Command. + /// Target guild. + /// New permission values. + /// + /// The active command permissions after the modification. + /// + public async Task ModifyContextCommandPermissionsAsync (ContextCommandInfo command, IGuild guild, + params ApplicationCommandPermission[] permissions) => + await ModifyApplicationCommandPermissionsAsync(command, guild, permissions).ConfigureAwait(false); + + private async Task ModifyApplicationCommandPermissionsAsync (T command, IGuild guild, + params ApplicationCommandPermission[] permissions) where T : class, IApplicationCommandInfo, ICommandInfo + { + if (!command.IsTopLevelCommand) + throw new InvalidOperationException("This command is not a top level application command. You cannot change its permissions"); + + if (guild is null) + throw new ArgumentNullException("guild"); + + var commands = await RestClient.GetGuildApplicationCommands(guild.Id).ConfigureAwait(false); + var appCommand = commands.First(x => x.Name == ( command as IApplicationCommandInfo ).Name); + + return await appCommand.ModifyCommandPermissions(permissions).ConfigureAwait(false); + } + + /// + /// Gets a . + /// + /// Declaring module type of this command, must be a type of . + /// Method name of the handler, use of is recommended. + /// + /// instance for this command. + /// + /// Module or Slash Command couldn't be found. + public SlashCommandInfo GetSlashCommandInfo (string methodName) where TModule : class + { + var module = GetModuleInfo(); + + return module.SlashCommands.First(x => x.MethodName == methodName); + } + + /// + /// Gets a . + /// + /// Declaring module type of this command, must be a type of . + /// Method name of the handler, use of is recommended. + /// + /// instance for this command. + /// + /// Module or Context Command couldn't be found. + public ContextCommandInfo GetContextCommandInfo (string methodName) where TModule : class + { + var module = GetModuleInfo(); + + return module.ContextCommands.First(x => x.MethodName == methodName); + } + + /// + /// Gets a . + /// + /// Declaring module type of this command, must be a type of . + /// Method name of the handler, use of is recommended. + /// + /// instance for this command. + /// + /// Module or Component Command couldn't be found. + public ComponentCommandInfo GetComponentCommandInfo (string methodName) where TModule : class + { + var module = GetModuleInfo(); + + return module.ComponentCommands.First(x => x.MethodName == methodName); + } + + /// + /// Gets a built . + /// + /// Type of the module, must be a type of . + /// + /// instance for this module. + /// + public ModuleInfo GetModuleInfo ( ) where TModule : class + { + if (!typeof(IInteractionModuleBase).IsAssignableFrom(typeof(TModule))) + throw new ArgumentException("Type parameter must be a type of Slash Module", "TModule"); + + var module = _typedModuleDefs[typeof(TModule)]; + + if (module is null) + throw new InvalidOperationException($"{typeof(TModule).FullName} is not loaded to the Slash Command Service"); + + return module; + } + + /// + public void Dispose ( ) + { + _lock.Dispose(); + } + + private Type GetMostSpecificTypeConverter (Type type) + { + if (_genericTypeConverters.TryGetValue(type, out var matching)) + return matching; + + if (type.IsGenericType && _genericTypeConverters.TryGetValue(type.GetGenericTypeDefinition(), out var genericDefinition)) + return genericDefinition; + + var typeInterfaces = type.GetInterfaces(); + var candidates = _genericTypeConverters.Where(x => x.Key.IsAssignableFrom(type)) + .OrderByDescending(x => typeInterfaces.Count(y => y.IsAssignableFrom(x.Key))); + + return candidates.First().Value; + } + + private void EnsureClientReady() + { + if (RestClient?.CurrentUser is null || RestClient?.CurrentUser?.Id == 0) + throw new InvalidOperationException($"Provided client is not ready to execute this operation, invoke this operation after a `Client Ready` event"); + } + } +} diff --git a/src/Discord.Net.Interactions/InteractionServiceConfig.cs b/src/Discord.Net.Interactions/InteractionServiceConfig.cs new file mode 100644 index 000000000..a1583a124 --- /dev/null +++ b/src/Discord.Net.Interactions/InteractionServiceConfig.cs @@ -0,0 +1,70 @@ +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Represents a configuration class for . + /// + public class InteractionServiceConfig + { + /// + /// Gets or sets the minimum log level severity that will be sent to the event. + /// + public LogSeverity LogLevel { get; set; } = LogSeverity.Info; + + /// + /// Gets or sets the default commands should have, if one is not specified on the + /// Command attribute or builder. + /// + public RunMode DefaultRunMode { get; set; } = RunMode.Async; + + /// + /// Gets or sets whether commands should push exceptions up to the caller. + /// + public bool ThrowOnError { get; set; } = true; + + /// + /// Gets or sets the delimiters that will be used to seperate group names and the method name when a Message Component Interaction is recieved. + /// + public char[] InteractionCustomIdDelimiters { get; set; } + + /// + /// Gets or sets the string expression that will be treated as a wild card. + /// + public string WildCardExpression { get; set; } + + /// + /// Gets or sets the option to use compiled lambda expressions to create module instances and execute commands. This method improves performance at the cost of memory. + /// + public bool UseCompiledLambda { get; set; } = false; + + /// + /// Gets or sets the option allowing you to use s. + /// + /// + /// Since s are prioritized over s, if s are not used, this should be + /// disabled to decrease the lookup time. + /// + public bool EnableAutocompleteHandlers { get; set; } = true; + + /// + /// Gets or sets whether new service scopes should be automatically created when resolving module depedencies on every command execution. + /// + public bool AutoServiceScopes { get; set; } = true; + + /// + /// Gets or sets delegate to be used by the when responding to a Rest based interaction. + /// + public RestResponseCallback RestResponseCallback { get; set; } = (ctx, str) => Task.CompletedTask; + } + + /// + /// Represents a cached delegate for creating interaction responses to webhook based Discord Interactions. + /// + /// Execution context that will be injected into the module class. + /// Body of the interaction response. + /// + /// A task representing the response operation. + /// + public delegate Task RestResponseCallback(IInteractionContext context, string responseBody); +} diff --git a/src/Discord.Net.Interactions/Map/CommandMap.cs b/src/Discord.Net.Interactions/Map/CommandMap.cs new file mode 100644 index 000000000..2e7bf5368 --- /dev/null +++ b/src/Discord.Net.Interactions/Map/CommandMap.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Discord.Interactions +{ + internal class CommandMap where T : class, ICommandInfo + { + private readonly char[] _seperators; + + private readonly CommandMapNode _root; + private readonly InteractionService _commandService; + + public IReadOnlyCollection Seperators => _seperators; + + public CommandMap(InteractionService commandService, char[] seperators = null) + { + _seperators = seperators ?? Array.Empty(); + + _commandService = commandService; + _root = new CommandMapNode(null, _commandService._wildCardExp); + } + + public void AddCommand(T command, bool ignoreGroupNames = false) + { + if (ignoreGroupNames) + AddCommandToRoot(command); + else + AddCommand(command); + } + + public void AddCommandToRoot(T command) + { + string[] key = new string[] { command.Name }; + _root.AddCommand(key, 0, command); + } + + public void AddCommand(IList input, T command) + { + _root.AddCommand(input, 0, command); + } + + public void RemoveCommand(T command) + { + var key = ParseCommandName(command); + + _root.RemoveCommand(key, 0); + } + + public SearchResult GetCommand(string input) + { + if(_seperators.Any()) + return GetCommand(input.Split(_seperators)); + else + return GetCommand(new string[] { input }); + } + + public SearchResult GetCommand(IList input) => + _root.GetCommand(input, 0); + + private void AddCommand(T command) + { + var key = ParseCommandName(command); + + _root.AddCommand(key, 0, command); + } + + private IList ParseCommandName(T command) + { + var keywords = new List() { command.Name }; + + var currentParent = command.Module; + + while (currentParent != null) + { + if (!string.IsNullOrEmpty(currentParent.SlashGroupName)) + keywords.Add(currentParent.SlashGroupName); + + currentParent = currentParent.Parent; + } + + keywords.Reverse(); + + return keywords; + } + } +} diff --git a/src/Discord.Net.Interactions/Map/CommandMapNode.cs b/src/Discord.Net.Interactions/Map/CommandMapNode.cs new file mode 100644 index 000000000..c866fe00e --- /dev/null +++ b/src/Discord.Net.Interactions/Map/CommandMapNode.cs @@ -0,0 +1,113 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; + +namespace Discord.Interactions +{ + internal class CommandMapNode where T : class, ICommandInfo + { + private const string RegexWildCardExp = "(\\S+)?"; + + private readonly string _wildCardStr = "*"; + private readonly ConcurrentDictionary> _nodes; + private readonly ConcurrentDictionary _commands; + private readonly ConcurrentDictionary _wildCardCommands; + + public IReadOnlyDictionary> Nodes => _nodes; + public IReadOnlyDictionary Commands => _commands; + public IReadOnlyDictionary WildCardCommands => _wildCardCommands; + public string Name { get; } + + public CommandMapNode (string name, string wildCardExp = null) + { + Name = name; + _nodes = new ConcurrentDictionary>(); + _commands = new ConcurrentDictionary(); + _wildCardCommands = new ConcurrentDictionary(); + + if (!string.IsNullOrEmpty(wildCardExp)) + _wildCardStr = wildCardExp; + } + + public void AddCommand (IList keywords, int index, T commandInfo) + { + if (keywords.Count == index + 1) + { + if (commandInfo.SupportsWildCards && commandInfo.Name.Contains(_wildCardStr)) + { + var escapedStr = RegexUtils.EscapeExcluding(commandInfo.Name, _wildCardStr.ToArray()); + var patternStr = "\\A" + escapedStr.Replace(_wildCardStr, RegexWildCardExp) + "\\Z"; + var regex = new Regex(patternStr, RegexOptions.Singleline | RegexOptions.Compiled); + + if (!_wildCardCommands.TryAdd(regex, commandInfo)) + throw new InvalidOperationException($"A {typeof(T).FullName} already exists with the same name: {string.Join(" ", keywords)}"); + } + else + { + if (!_commands.TryAdd(keywords[index], commandInfo)) + throw new InvalidOperationException($"A {typeof(T).FullName} already exists with the same name: {string.Join(" ", keywords)}"); + } + } + else + { + var node = _nodes.GetOrAdd(keywords[index], (key) => new CommandMapNode(key, _wildCardStr)); + node.AddCommand(keywords, ++index, commandInfo); + } + } + + public bool RemoveCommand (IList keywords, int index) + { + if (keywords.Count == index + 1) + return _commands.TryRemove(keywords[index], out var _); + else + { + if (!_nodes.TryGetValue(keywords[index], out var node)) + throw new InvalidOperationException($"No descendant node was found with the name {keywords[index]}"); + + return node.RemoveCommand(keywords, ++index); + } + } + + public SearchResult GetCommand (IList keywords, int index) + { + string name = string.Join(" ", keywords); + + if (keywords.Count == index + 1) + { + if (_commands.TryGetValue(keywords[index], out var cmd)) + return SearchResult.FromSuccess(name, cmd); + else + { + foreach (var cmdPair in _wildCardCommands) + { + var match = cmdPair.Key.Match(keywords[index]); + if (match.Success) + { + var args = new string[match.Groups.Count - 1]; + + for (var i = 1; i < match.Groups.Count; i++) + args[i - 1] = match.Groups[i].Value; + + return SearchResult.FromSuccess(name, cmdPair.Value, args.ToArray()); + } + } + } + } + else + { + if (_nodes.TryGetValue(keywords[index], out var node)) + return node.GetCommand(keywords, ++index); + } + + return SearchResult.FromError(name, InteractionCommandError.UnknownCommand, $"No {typeof(T).FullName} found for {name}"); + } + + public SearchResult GetCommand (string text, int index, char[] seperators) + { + var keywords = text.Split(seperators); + return GetCommand(keywords, index); + } + } +} diff --git a/src/Discord.Net.Interactions/RestInteractionModuleBase.cs b/src/Discord.Net.Interactions/RestInteractionModuleBase.cs new file mode 100644 index 000000000..a07614f7f --- /dev/null +++ b/src/Discord.Net.Interactions/RestInteractionModuleBase.cs @@ -0,0 +1,69 @@ +using Discord.Rest; +using System; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Provides a base class for a Rest based command module to inherit from. + /// + /// Type of interaction context to be injected into the module. + public abstract class RestInteractionModuleBase : InteractionModuleBase + where T : class, IInteractionContext + { + /// + /// Gets or sets the underlying Interaction Service. + /// + public InteractionService InteractionService { get; set; } + + /// + /// Defer a Rest based Discord Interaction using the delegate. + /// + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The request options for this response. + /// + /// A Task representing the operation of creating the interaction response. + /// + /// Thrown if the interaction isn't a type of . + protected override async Task DeferAsync(bool ephemeral = false, RequestOptions options = null) + { + if (Context.Interaction is not RestInteraction restInteraction) + throw new InvalidOperationException($"Invalid interaction type. Interaction must be a type of {nameof(RestInteraction)} in order to execute this method"); + + var payload = restInteraction.Defer(ephemeral, options); + + if (Context is IRestInteractionContext restContext && restContext.InteractionResponseCallback != null) + await restContext.InteractionResponseCallback.Invoke(payload).ConfigureAwait(false); + else + await InteractionService._restResponseCallback(Context, payload).ConfigureAwait(false); + } + + /// + /// Respond to a Rest based Discord Interaction using the delegate. + /// + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// The request options for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// + /// A Task representing the operation of creating the interaction response. + /// + /// Thrown if the interaction isn't a type of . + protected override async Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, Embed embed = null) + { + if (Context.Interaction is not RestInteraction restInteraction) + throw new InvalidOperationException($"Invalid interaction type. Interaction must be a type of {nameof(RestInteraction)} in order to execute this method"); + + var payload = restInteraction.Respond(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options); + + if (Context is IRestInteractionContext restContext && restContext.InteractionResponseCallback != null) + await restContext.InteractionResponseCallback.Invoke(payload).ConfigureAwait(false); + else + await InteractionService._restResponseCallback(Context, payload).ConfigureAwait(false); + } + } +} diff --git a/src/Discord.Net.Interactions/Results/AutocompletionResult.cs b/src/Discord.Net.Interactions/Results/AutocompletionResult.cs new file mode 100644 index 000000000..2dc9f93be --- /dev/null +++ b/src/Discord.Net.Interactions/Results/AutocompletionResult.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; + +namespace Discord.Interactions +{ + /// + /// Contains the information of a Autocomplete Interaction result. + /// + public struct AutocompletionResult : IResult + { + /// + public InteractionCommandError? Error { get; } + + /// + public string ErrorReason { get; } + + /// + public bool IsSuccess => Error is null; + + /// + /// Get the collection of Autocomplete suggestions to be displayed to the user. + /// + public IReadOnlyCollection Suggestions { get; } + + private AutocompletionResult(IEnumerable suggestions, InteractionCommandError? error, string reason) + { + Suggestions = suggestions?.ToImmutableArray(); + Error = error; + ErrorReason = reason; + } + + /// + /// Initializes a new with no error and without any indicating the command service shouldn't + /// return any suggestions. + /// + /// + /// A that does not contain any errors. + /// + public static AutocompletionResult FromSuccess() => + new AutocompletionResult(null, null, null); + + /// + /// Initializes a new with no error. + /// + /// Autocomplete suggestions to be displayed to the user + /// + /// A that does not contain any errors. + /// + public static AutocompletionResult FromSuccess(IEnumerable suggestions) => + new AutocompletionResult(suggestions, null, null); + + /// + /// Initializes a new with a specified result; this may or may not be an + /// successful execution depending on the and + /// specified. + /// + /// The result to inherit from. + /// + /// A that inherits the error type and reason. + /// + public static AutocompletionResult FromError(IResult result) => + new AutocompletionResult(null, result.Error, result.ErrorReason); + + /// + /// Initializes a new with a specified exception, indicating an unsuccessful + /// execution. + /// + /// The exception that caused the autocomplete process to fail. + /// + /// A that contains the exception that caused the unsuccessful execution, along + /// with a of type as well as the exception message as the + /// reason. + /// + public static AutocompletionResult FromError(Exception exception) => + new AutocompletionResult(null, InteractionCommandError.Exception, exception.Message); + + /// + /// Initializes a new with a specified and its + /// reason, indicating an unsuccessful execution. + /// + /// The type of error. + /// The reason behind the error. + /// + /// A that contains a and reason. + /// + public static AutocompletionResult FromError(InteractionCommandError error, string reason) => + new AutocompletionResult(null, error, reason); + + /// + /// Gets a string that indicates the autocompletion result. + /// + /// + /// Success if is true; otherwise ": + /// ". + /// + public override string ToString() => IsSuccess ? "Success" : $"{Error}: {ErrorReason}"; + } +} diff --git a/src/Discord.Net.Interactions/Results/ExecuteResult.cs b/src/Discord.Net.Interactions/Results/ExecuteResult.cs new file mode 100644 index 000000000..ad2ccd1d3 --- /dev/null +++ b/src/Discord.Net.Interactions/Results/ExecuteResult.cs @@ -0,0 +1,86 @@ +using System; + +namespace Discord.Interactions +{ + /// + /// Contains information of the command's overall execution result. + /// + public struct ExecuteResult : IResult + { + /// + /// Gets the exception that may have occurred during the command execution. + /// + public Exception Exception { get; } + + /// + public InteractionCommandError? Error { get; } + + /// + public string ErrorReason { get; } + + /// + public bool IsSuccess => !Error.HasValue; + + private ExecuteResult (Exception exception, InteractionCommandError? commandError, string errorReason) + { + Exception = exception; + Error = commandError; + ErrorReason = errorReason; + } + + /// + /// Initializes a new with no error, indicating a successful execution. + /// + /// + /// A that does not contain any errors. + /// + public static ExecuteResult FromSuccess ( ) => + new ExecuteResult(null, null, null); + + /// + /// Initializes a new with a specified and its + /// reason, indicating an unsuccessful execution. + /// + /// The type of error. + /// The reason behind the error. + /// + /// A that contains a and reason. + /// + public static ExecuteResult FromError (InteractionCommandError commandError, string reason) => + new ExecuteResult(null, commandError, reason); + + /// + /// Initializes a new with a specified exception, indicating an unsuccessful + /// execution. + /// + /// The exception that caused the command execution to fail. + /// + /// A that contains the exception that caused the unsuccessful execution, along + /// with a of type Exception as well as the exception message as the + /// reason. + /// + public static ExecuteResult FromError (Exception exception) => + new ExecuteResult(exception, InteractionCommandError.Exception, exception.Message); + + /// + /// Initializes a new with a specified result; this may or may not be an + /// successful execution depending on the and + /// specified. + /// + /// The result to inherit from. + /// + /// A that inherits the error type and reason. + /// + public static ExecuteResult FromError (IResult result) => + new ExecuteResult(null, result.Error, result.ErrorReason); + + /// + /// Gets a string that indicates the execution result. + /// + /// + /// Success if is ; otherwise ": + /// ". + /// + public override string ToString ( ) => IsSuccess ? "Success" : $"{Error}: {ErrorReason}"; + } +} diff --git a/src/Discord.Net.Interactions/Results/IResult.cs b/src/Discord.Net.Interactions/Results/IResult.cs new file mode 100644 index 000000000..1b6089c3a --- /dev/null +++ b/src/Discord.Net.Interactions/Results/IResult.cs @@ -0,0 +1,33 @@ +namespace Discord.Interactions +{ + /// + /// Contains information of the result related to a command. + /// + public interface IResult + { + /// + /// Gets the error type that may have occurred during the operation. + /// + /// + /// A indicating the type of error that may have occurred during the operation; + /// if the operation was successful. + /// + InteractionCommandError? Error { get; } + + /// + /// Gets the reason for the error. + /// + /// + /// A string containing the error reason. + /// + string ErrorReason { get; } + + /// + /// Indicates whether the operation was successful or not. + /// + /// + /// if the result is positive; otherwise . + /// + bool IsSuccess { get; } + } +} diff --git a/src/Discord.Net.Interactions/Results/PreconditionGroupResult.cs b/src/Discord.Net.Interactions/Results/PreconditionGroupResult.cs new file mode 100644 index 000000000..40acb6099 --- /dev/null +++ b/src/Discord.Net.Interactions/Results/PreconditionGroupResult.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; + +namespace Discord.Interactions +{ + /// + /// Represents a result type for grouped command preconditions. + /// + public class PreconditionGroupResult : PreconditionResult + { + /// + /// Gets the results of the preconditions of this group. + /// + public IReadOnlyCollection Results { get; } + + private PreconditionGroupResult (InteractionCommandError? error, string reason, IEnumerable results) : base(error, reason) + { + Results = results?.ToImmutableArray(); + } + + /// + /// Returns a with no errors. + /// + public static new PreconditionGroupResult FromSuccess ( ) => + new PreconditionGroupResult(null, null, null); + + /// + /// Returns a with and the . + /// + /// The exception that caused the precondition check to fail. + public static new PreconditionGroupResult FromError (Exception exception) => + new PreconditionGroupResult(InteractionCommandError.Exception, exception.Message, null); + + /// + /// Returns a with the specified type. + /// + /// The result of failure. + public static new PreconditionGroupResult FromError (IResult result) => + new PreconditionGroupResult(result.Error, result.ErrorReason, null); + + /// + /// Returns a with and the + /// specified reason. + /// + /// The reason of failure. + /// Precondition results of this group + public static PreconditionGroupResult FromError (string reason, IEnumerable results) => + new PreconditionGroupResult(InteractionCommandError.UnmetPrecondition, reason, results); + } +} diff --git a/src/Discord.Net.Interactions/Results/PreconditionResult.cs b/src/Discord.Net.Interactions/Results/PreconditionResult.cs new file mode 100644 index 000000000..3d80f976c --- /dev/null +++ b/src/Discord.Net.Interactions/Results/PreconditionResult.cs @@ -0,0 +1,59 @@ +using System; + +namespace Discord.Interactions +{ + /// + /// Represents a result type for command preconditions. + /// + public class PreconditionResult : IResult + { + /// + public InteractionCommandError? Error { get; } + + /// + public string ErrorReason { get; } + + /// + public bool IsSuccess => Error == null; + + /// + /// Initializes a new class with the command type + /// and reason. + /// + /// The type of failure. + /// The reason of failure. + protected PreconditionResult (InteractionCommandError? error, string reason) + { + Error = error; + ErrorReason = reason; + } + + /// + /// Returns a with no errors. + /// + public static PreconditionResult FromSuccess ( ) => + new PreconditionResult(null, null); + + /// + /// Returns a with and the . + /// + /// The exception that caused the precondition check to fail. + public static PreconditionResult FromError (Exception exception) => + new PreconditionResult(InteractionCommandError.Exception, exception.Message); + + /// + /// Returns a with the specified type. + /// + /// The result of failure. + public static PreconditionResult FromError (IResult result) => + new PreconditionResult(result.Error, result.ErrorReason); + + /// + /// Returns a with and the + /// specified reason. + /// + /// The reason of failure. + public static PreconditionResult FromError (string reason) => + new PreconditionResult(InteractionCommandError.UnmetPrecondition, reason); + } +} diff --git a/src/Discord.Net.Interactions/Results/RuntimeResult.cs b/src/Discord.Net.Interactions/Results/RuntimeResult.cs new file mode 100644 index 000000000..a29b29252 --- /dev/null +++ b/src/Discord.Net.Interactions/Results/RuntimeResult.cs @@ -0,0 +1,37 @@ +namespace Discord.Interactions +{ + /// + /// Represents the base class for creating command result containers. + /// + public abstract class RuntimeResult : IResult + { + /// + public InteractionCommandError? Error { get; } + + /// + public string ErrorReason { get; } + + /// + public bool IsSuccess => !Error.HasValue; + + /// + /// Initializes a new class with the type of error and reason. + /// + /// The type of failure, or null if none. + /// The reason of failure. + protected RuntimeResult (InteractionCommandError? error, string reason) + { + Error = error; + ErrorReason = reason; + } + + /// + /// Gets a string that indicates the runtime result. + /// + /// + /// Success if is true; otherwise ": + /// ". + /// + public override string ToString ( ) => ErrorReason ?? ( IsSuccess ? "Successful" : "Unsuccessful" ); + } +} diff --git a/src/Discord.Net.Interactions/Results/SearchResult.cs b/src/Discord.Net.Interactions/Results/SearchResult.cs new file mode 100644 index 000000000..8555e9e5d --- /dev/null +++ b/src/Discord.Net.Interactions/Results/SearchResult.cs @@ -0,0 +1,93 @@ +using System; + +namespace Discord.Interactions +{ + /// + /// Contains information of a command search. + /// + /// Type of the target command type. + public struct SearchResult : IResult where T : class, ICommandInfo + { + /// + /// Gets the input text of the command search. + /// + public string Text { get; } + + /// + /// Gets the found command, if the search was successful. + /// + public T Command { get; } + + /// + /// Gets the Regex groups captured by the wild card pattern. + /// + public string[] RegexCaptureGroups { get; } + + /// + public InteractionCommandError? Error { get; } + + /// + public string ErrorReason { get; } + + /// + public bool IsSuccess => !Error.HasValue; + + private SearchResult (string text, T commandInfo, string[] captureGroups, InteractionCommandError? error, string reason) + { + Text = text; + Error = error; + RegexCaptureGroups = captureGroups; + Command = commandInfo; + ErrorReason = reason; + } + + /// + /// Initializes a new with no error, indicating a successful execution. + /// + /// + /// A that does not contain any errors. + /// + public static SearchResult FromSuccess (string text, T commandInfo, string[] wildCardMatch = null) => + new SearchResult(text, commandInfo, wildCardMatch, null, null); + + /// + /// Initializes a new with a specified and its + /// reason, indicating an unsuccessful execution. + /// + /// The type of error. + /// The reason behind the error. + /// + /// A that contains a and reason. + /// + public static SearchResult FromError (string text, InteractionCommandError error, string reason) => + new SearchResult(text, null, null, error, reason); + + /// + /// Initializes a new with a specified exception, indicating an unsuccessful + /// execution. + /// + /// The exception that caused the command execution to fail. + /// + /// A that contains the exception that caused the unsuccessful execution, along + /// with a of type Exception as well as the exception message as the + /// reason. + /// + public static SearchResult FromError (Exception ex) => + new SearchResult(null, null, null, InteractionCommandError.Exception, ex.Message); + + /// + /// Initializes a new with a specified result; this may or may not be an + /// successful depending on the and + /// specified. + /// + /// The result to inherit from. + /// + /// A that inherits the error type and reason. + /// + public static SearchResult FromError (IResult result) => + new SearchResult(null, null, null, result.Error, result.ErrorReason); + + /// + public override string ToString ( ) => IsSuccess ? "Success" : $"{Error}: {ErrorReason}"; + } +} diff --git a/src/Discord.Net.Interactions/Results/TypeConverterResult.cs b/src/Discord.Net.Interactions/Results/TypeConverterResult.cs new file mode 100644 index 000000000..bd89bf6b7 --- /dev/null +++ b/src/Discord.Net.Interactions/Results/TypeConverterResult.cs @@ -0,0 +1,61 @@ +using System; + +namespace Discord.Interactions +{ + /// + /// Represents a result type for . + /// + public struct TypeConverterResult : IResult + { + /// + /// Gets the result of the convertion if the operation was successful. + /// + public object Value { get; } + + /// + public InteractionCommandError? Error { get; } + + /// + public string ErrorReason { get; } + + /// + public bool IsSuccess => !Error.HasValue; + + private TypeConverterResult (object value, InteractionCommandError? error, string reason) + { + Value = value; + Error = error; + ErrorReason = reason; + } + + /// + /// Returns a with no errors. + /// + public static TypeConverterResult FromSuccess (object value) => + new TypeConverterResult(value, null, null); + + /// + /// Returns a with and the . + /// + /// The exception that caused the type convertion to fail. + public static TypeConverterResult FromError (Exception exception) => + new TypeConverterResult(null, InteractionCommandError.Exception, exception.Message); + + /// + /// Returns a with the specified error and the reason. + /// + /// The type of error. + /// The reason of failure. + public static TypeConverterResult FromError (InteractionCommandError error, string reason) => + new TypeConverterResult(null, error, reason); + + /// + /// Returns a with the specified type. + /// + /// The result of failure. + public static TypeConverterResult FromError (IResult result) => + new TypeConverterResult(null, result.Error, result.ErrorReason); + + public override string ToString ( ) => IsSuccess ? "Success" : $"{Error}: {ErrorReason}"; + } +} diff --git a/src/Discord.Net.Interactions/RunMode.cs b/src/Discord.Net.Interactions/RunMode.cs new file mode 100644 index 000000000..1577da8ad --- /dev/null +++ b/src/Discord.Net.Interactions/RunMode.cs @@ -0,0 +1,22 @@ +namespace Discord.Interactions +{ + /// + /// Specifies the behavior of the command execution workflow. + /// + /// + public enum RunMode + { + /// + /// Executes the command on the same thread as gateway one. + /// + Sync, + /// + /// Executes the command on a different thread from the gateway one. + /// + Async, + /// + /// The default behaviour set in . + /// + Default + } +} diff --git a/src/Discord.Net.Interactions/TypeConverters/DefaultEntityTypeConverter.cs b/src/Discord.Net.Interactions/TypeConverters/DefaultEntityTypeConverter.cs new file mode 100644 index 000000000..943ad39b7 --- /dev/null +++ b/src/Discord.Net.Interactions/TypeConverters/DefaultEntityTypeConverter.cs @@ -0,0 +1,83 @@ +using Discord.WebSocket; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + internal abstract class DefaultEntityTypeConverter : TypeConverter where T : class + { + public override Task ReadAsync (IInteractionContext context, IApplicationCommandInteractionDataOption option, IServiceProvider services) + { + var value = option.Value as T; + + if (value is not null) + return Task.FromResult(TypeConverterResult.FromSuccess(option.Value as T)); + else + return Task.FromResult(TypeConverterResult.FromError(InteractionCommandError.ConvertFailed, $"Provided input cannot be read as {nameof(IChannel)}")); + } + } + + internal class DefaultRoleConverter : DefaultEntityTypeConverter where T : class, IRole + { + public override ApplicationCommandOptionType GetDiscordType ( ) => ApplicationCommandOptionType.Role; + } + + internal class DefaultUserConverter : DefaultEntityTypeConverter where T : class, IUser + { + public override ApplicationCommandOptionType GetDiscordType ( ) => ApplicationCommandOptionType.User; + } + + internal class DefaultChannelConverter : DefaultEntityTypeConverter where T : class, IChannel + { + private readonly List _channelTypes; + + public DefaultChannelConverter ( ) + { + var type = typeof(T); + + _channelTypes = true switch + { + _ when typeof(IStageChannel).IsAssignableFrom(type) + => new List { ChannelType.Stage }, + + _ when typeof(IVoiceChannel).IsAssignableFrom(type) + => new List { ChannelType.Voice }, + + _ when typeof(IDMChannel).IsAssignableFrom(type) + => new List { ChannelType.DM }, + + _ when typeof(IGroupChannel).IsAssignableFrom(type) + => new List { ChannelType.Group }, + + _ when typeof(ICategoryChannel).IsAssignableFrom(type) + => new List { ChannelType.Category }, + + _ when typeof(INewsChannel).IsAssignableFrom(type) + => new List { ChannelType.News }, + + _ when typeof(IThreadChannel).IsAssignableFrom(type) + => new List { ChannelType.PublicThread, ChannelType.PrivateThread, ChannelType.NewsThread }, + + _ when typeof(ITextChannel).IsAssignableFrom(type) + => new List { ChannelType.Text }, + + _ => null + }; + } + + public override ApplicationCommandOptionType GetDiscordType ( ) => ApplicationCommandOptionType.Channel; + + public override void Write (ApplicationCommandOptionProperties properties, IParameterInfo parameter) + { + properties.ChannelTypes = _channelTypes; + } + } + + internal class DefaultMentionableConverter : DefaultEntityTypeConverter where T : class, IMentionable + { + public override ApplicationCommandOptionType GetDiscordType ( ) => ApplicationCommandOptionType.Mentionable; + } +} diff --git a/src/Discord.Net.Interactions/TypeConverters/DefaultValueConverter.cs b/src/Discord.Net.Interactions/TypeConverters/DefaultValueConverter.cs new file mode 100644 index 000000000..8e049ea7a --- /dev/null +++ b/src/Discord.Net.Interactions/TypeConverters/DefaultValueConverter.cs @@ -0,0 +1,61 @@ +using Discord.WebSocket; +using System; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + internal class DefaultValueConverter : TypeConverter where T : IConvertible + { + public override ApplicationCommandOptionType GetDiscordType ( ) + { + switch (Type.GetTypeCode(typeof(T))) + { + case TypeCode.Boolean: + return ApplicationCommandOptionType.Boolean; + + case TypeCode.DateTime: + case TypeCode.SByte: + case TypeCode.Byte: + case TypeCode.Char: + case TypeCode.String: + case TypeCode.Single: + return ApplicationCommandOptionType.String; + + case TypeCode.Int16: + case TypeCode.Int32: + case TypeCode.Int64: + case TypeCode.UInt16: + case TypeCode.UInt32: + case TypeCode.UInt64: + return ApplicationCommandOptionType.Integer; + + case TypeCode.Decimal: + case TypeCode.Double: + return ApplicationCommandOptionType.Number; + + case TypeCode.DBNull: + default: + throw new InvalidOperationException($"Parameter Type {typeof(T).FullName} is not supported by Discord."); + } + } + public override Task ReadAsync (IInteractionContext context, IApplicationCommandInteractionDataOption option, IServiceProvider services) + { + object value; + + if (option.Value is Optional optional) + value = optional.IsSpecified ? optional.Value : default(T); + else + value = option.Value; + + try + { + var converted = Convert.ChangeType(value, typeof(T)); + return Task.FromResult(TypeConverterResult.FromSuccess(converted)); + } + catch (InvalidCastException castEx) + { + return Task.FromResult(TypeConverterResult.FromError(castEx)); + } + } + } +} diff --git a/src/Discord.Net.Interactions/TypeConverters/EnumConverter.cs b/src/Discord.Net.Interactions/TypeConverters/EnumConverter.cs new file mode 100644 index 000000000..a06c70ec4 --- /dev/null +++ b/src/Discord.Net.Interactions/TypeConverters/EnumConverter.cs @@ -0,0 +1,49 @@ +using Discord.WebSocket; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + internal sealed class EnumConverter : TypeConverter where T : struct, Enum + { + public override ApplicationCommandOptionType GetDiscordType ( ) => ApplicationCommandOptionType.String; + public override Task ReadAsync (IInteractionContext context, IApplicationCommandInteractionDataOption option, IServiceProvider services) + { + if (Enum.TryParse((string)option.Value, out var result)) + return Task.FromResult(TypeConverterResult.FromSuccess(result)); + else + return Task.FromResult(TypeConverterResult.FromError(InteractionCommandError.ConvertFailed, $"Value {option.Value} cannot be converted to {nameof(T)}")); + } + + public override void Write (ApplicationCommandOptionProperties properties, IParameterInfo parameterInfo) + { + var names = Enum.GetNames(typeof(T)); + var members = names.SelectMany(x => typeof(T).GetMember(x)).Where(x => !x.IsDefined(typeof(HideAttribute), true)); + + if (members.Count() <= 25) + { + var choices = new List(); + + foreach (var member in members) + choices.Add(new ApplicationCommandOptionChoiceProperties + { + Name = member.Name, + Value = member.Name + }); + + properties.Choices = choices; + } + } + } + + /// + /// Enum values tagged with this attribute will not be displayed as a parameter choice + /// + /// + /// This attributer must be used along with the default + /// + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class HideAttribute : Attribute { } +} diff --git a/src/Discord.Net.Interactions/TypeConverters/NullableConverter.cs b/src/Discord.Net.Interactions/TypeConverters/NullableConverter.cs new file mode 100644 index 000000000..874171175 --- /dev/null +++ b/src/Discord.Net.Interactions/TypeConverters/NullableConverter.cs @@ -0,0 +1,29 @@ +using System; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + internal class NullableConverter : TypeConverter + { + private readonly TypeConverter _typeConverter; + + public NullableConverter(InteractionService interactionService, IServiceProvider services) + { + var type = Nullable.GetUnderlyingType(typeof(T)); + + if (type is null) + throw new ArgumentException($"No type {nameof(TypeConverter)} is defined for this {type.FullName}", "type"); + + _typeConverter = interactionService.GetTypeConverter(type, services); + } + + public override ApplicationCommandOptionType GetDiscordType() + => _typeConverter.GetDiscordType(); + + public override Task ReadAsync(IInteractionContext context, IApplicationCommandInteractionDataOption option, IServiceProvider services) + => _typeConverter.ReadAsync(context, option, services); + + public override void Write(ApplicationCommandOptionProperties properties, IParameterInfo parameter) + => _typeConverter.Write(properties, parameter); + } +} diff --git a/src/Discord.Net.Interactions/TypeConverters/TimeSpanConverter.cs b/src/Discord.Net.Interactions/TypeConverters/TimeSpanConverter.cs new file mode 100644 index 000000000..9a5274ff9 --- /dev/null +++ b/src/Discord.Net.Interactions/TypeConverters/TimeSpanConverter.cs @@ -0,0 +1,36 @@ +using Discord.WebSocket; +using System; +using System.Globalization; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + internal sealed class TimeSpanConverter : TypeConverter + { + public override ApplicationCommandOptionType GetDiscordType ( ) => ApplicationCommandOptionType.String; + public override Task ReadAsync (IInteractionContext context, IApplicationCommandInteractionDataOption option, IServiceProvider services) + { + return ( TimeSpan.TryParseExact(( option.Value as string ).ToLowerInvariant(), Formats, CultureInfo.InvariantCulture, out var timeSpan) ) + ? Task.FromResult(TypeConverterResult.FromSuccess(timeSpan)) + : Task.FromResult(TypeConverterResult.FromError(InteractionCommandError.ConvertFailed, "Failed to parse TimeSpan")); + } + + private static readonly string[] Formats = { + "%d'd'%h'h'%m'm'%s's'", //4d3h2m1s + "%d'd'%h'h'%m'm'", //4d3h2m + "%d'd'%h'h'%s's'", //4d3h 1s + "%d'd'%h'h'", //4d3h + "%d'd'%m'm'%s's'", //4d 2m1s + "%d'd'%m'm'", //4d 2m + "%d'd'%s's'", //4d 1s + "%d'd'", //4d + "%h'h'%m'm'%s's'", // 3h2m1s + "%h'h'%m'm'", // 3h2m + "%h'h'%s's'", // 3h 1s + "%h'h'", // 3h + "%m'm'%s's'", // 2m1s + "%m'm'", // 2m + "%s's'", // 1s + }; + } +} diff --git a/src/Discord.Net.Interactions/TypeConverters/TypeConverter.cs b/src/Discord.Net.Interactions/TypeConverters/TypeConverter.cs new file mode 100644 index 000000000..360b6ce4a --- /dev/null +++ b/src/Discord.Net.Interactions/TypeConverters/TypeConverter.cs @@ -0,0 +1,46 @@ +using System; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Base class for creating TypeConverters. uses TypeConverters to interface with Slash Command parameters. + /// + public abstract class TypeConverter + { + /// + /// Will be used to search for alternative TypeConverters whenever the Command Service encounters an unknown parameter type. + /// + /// + /// + public abstract bool CanConvertTo(Type type); + + /// + /// Will be used to get the Application Command Option type. + /// + /// The option type. + public abstract ApplicationCommandOptionType GetDiscordType(); + + /// + /// Will be used to read the incoming payload before executing the method body. + /// + /// Command exexution context. + /// Recieved option payload. + /// Service provider that will be used to initialize the command module. + /// The result of the read process. + public abstract Task ReadAsync(IInteractionContext context, IApplicationCommandInteractionDataOption option, IServiceProvider services); + + /// + /// Will be used to manipulate the outgoing command option, before the command gets registered to Discord. + /// + public virtual void Write(ApplicationCommandOptionProperties properties, IParameterInfo parameter) { } + } + + /// + public abstract class TypeConverter : TypeConverter + { + /// + public sealed override bool CanConvertTo(Type type) => + typeof(T).IsAssignableFrom(type); + } +} diff --git a/src/Discord.Net.Interactions/Utilities/ApplicationCommandRestUtil.cs b/src/Discord.Net.Interactions/Utilities/ApplicationCommandRestUtil.cs new file mode 100644 index 000000000..48b6e44e7 --- /dev/null +++ b/src/Discord.Net.Interactions/Utilities/ApplicationCommandRestUtil.cs @@ -0,0 +1,200 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Discord.Interactions +{ + internal static class ApplicationCommandRestUtil + { + #region Parameters + public static ApplicationCommandOptionProperties ToApplicationCommandOptionProps(this SlashCommandParameterInfo parameterInfo) + { + var props = new ApplicationCommandOptionProperties + { + Name = parameterInfo.Name, + Description = parameterInfo.Description, + Type = parameterInfo.DiscordOptionType, + IsRequired = parameterInfo.IsRequired, + Choices = parameterInfo.Choices?.Select(x => new ApplicationCommandOptionChoiceProperties + { + Name = x.Name, + Value = x.Value + })?.ToList(), + ChannelTypes = parameterInfo.ChannelTypes?.ToList(), + IsAutocomplete = parameterInfo.IsAutocomplete, + MaxValue = parameterInfo.MaxValue, + MinValue = parameterInfo.MinValue + }; + + parameterInfo.TypeConverter.Write(props, parameterInfo); + + return props; + } + #endregion + + #region Commands + + public static SlashCommandProperties ToApplicationCommandProps(this SlashCommandInfo commandInfo) + { + var props = new SlashCommandBuilder() + { + Name = commandInfo.Name, + Description = commandInfo.Description, + IsDefaultPermission = commandInfo.DefaultPermission, + }.Build(); + + if (commandInfo.Parameters.Count > SlashCommandBuilder.MaxOptionsCount) + throw new InvalidOperationException($"Slash Commands cannot have more than {SlashCommandBuilder.MaxOptionsCount} command parameters"); + + props.Options = commandInfo.Parameters.Select(x => x.ToApplicationCommandOptionProps())?.ToList() ?? Optional>.Unspecified; + + return props; + } + + public static ApplicationCommandOptionProperties ToApplicationCommandOptionProps(this SlashCommandInfo commandInfo) => + new ApplicationCommandOptionProperties + { + Name = commandInfo.Name, + Description = commandInfo.Description, + Type = ApplicationCommandOptionType.SubCommand, + IsRequired = false, + Options = commandInfo.Parameters?.Select(x => x.ToApplicationCommandOptionProps())?.ToList() + }; + + public static ApplicationCommandProperties ToApplicationCommandProps(this ContextCommandInfo commandInfo) + => commandInfo.CommandType switch + { + ApplicationCommandType.Message => new MessageCommandBuilder { Name = commandInfo.Name, IsDefaultPermission = commandInfo.DefaultPermission}.Build(), + ApplicationCommandType.User => new UserCommandBuilder { Name = commandInfo.Name, IsDefaultPermission=commandInfo.DefaultPermission}.Build(), + _ => throw new InvalidOperationException($"{commandInfo.CommandType} isn't a supported command type.") + }; + #endregion + + #region Modules + + public static IReadOnlyCollection ToApplicationCommandProps(this ModuleInfo moduleInfo, bool ignoreDontRegister = false) + { + var args = new List(); + + moduleInfo.ParseModuleModel(args, ignoreDontRegister); + return args; + } + + private static void ParseModuleModel(this ModuleInfo moduleInfo, List args, bool ignoreDontRegister) + { + if (moduleInfo.DontAutoRegister && !ignoreDontRegister) + return; + + args.AddRange(moduleInfo.ContextCommands?.Select(x => x.ToApplicationCommandProps())); + + if (!moduleInfo.IsSlashGroup) + { + args.AddRange(moduleInfo.SlashCommands?.Select(x => x.ToApplicationCommandProps())); + + foreach (var submodule in moduleInfo.SubModules) + submodule.ParseModuleModel(args, ignoreDontRegister); + } + else + { + var options = new List(); + + foreach (var command in moduleInfo.SlashCommands) + { + if (command.IgnoreGroupNames) + args.Add(command.ToApplicationCommandProps()); + else + options.Add(command.ToApplicationCommandOptionProps()); + } + + options.AddRange(moduleInfo.SubModules?.SelectMany(x => x.ParseSubModule(args, ignoreDontRegister))); + + var props = new SlashCommandBuilder + { + Name = moduleInfo.SlashGroupName, + Description = moduleInfo.Description, + IsDefaultPermission = moduleInfo.DefaultPermission, + }.Build(); + + if (options.Count > SlashCommandBuilder.MaxOptionsCount) + throw new InvalidOperationException($"Slash Commands cannot have more than {SlashCommandBuilder.MaxOptionsCount} command parameters"); + + props.Options = options; + + args.Add(props); + } + } + + private static IReadOnlyCollection ParseSubModule(this ModuleInfo moduleInfo, List args, + bool ignoreDontRegister) + { + if (moduleInfo.DontAutoRegister && !ignoreDontRegister) + return Array.Empty(); + + args.AddRange(moduleInfo.ContextCommands?.Select(x => x.ToApplicationCommandProps())); + + var options = new List(); + options.AddRange(moduleInfo.SubModules?.SelectMany(x => x.ParseSubModule(args, ignoreDontRegister))); + + foreach (var command in moduleInfo.SlashCommands) + { + if (command.IgnoreGroupNames) + args.Add(command.ToApplicationCommandProps()); + else + options.Add(command.ToApplicationCommandOptionProps()); + } + + if (!moduleInfo.IsSlashGroup) + return options; + else + return new List() { new ApplicationCommandOptionProperties + { + Name = moduleInfo.SlashGroupName, + Description = moduleInfo.Description, + Type = ApplicationCommandOptionType.SubCommandGroup, + Options = options + } }; + } + + #endregion + + public static ApplicationCommandProperties ToApplicationCommandProps(this IApplicationCommand command) + { + return command.Type switch + { + ApplicationCommandType.Slash => new SlashCommandProperties + { + Name = command.Name, + Description = command.Description, + IsDefaultPermission = command.IsDefaultPermission, + Options = command.Options?.Select(x => x.ToApplicationCommandOptionProps())?.ToList() ?? Optional>.Unspecified + }, + ApplicationCommandType.User => new UserCommandProperties + { + Name = command.Name, + IsDefaultPermission = command.IsDefaultPermission + }, + ApplicationCommandType.Message => new MessageCommandProperties + { + Name = command.Name, + IsDefaultPermission = command.IsDefaultPermission + }, + _ => throw new InvalidOperationException($"Cannot create command properties for command type {command.Type}"), + }; + } + + public static ApplicationCommandOptionProperties ToApplicationCommandOptionProps(this IApplicationCommandOption commandOption) => + new ApplicationCommandOptionProperties + { + Name = commandOption.Name, + Description = commandOption.Description, + Type = commandOption.Type, + IsRequired = commandOption.IsRequired, + Choices = commandOption.Choices?.Select(x => new ApplicationCommandOptionChoiceProperties + { + Name = x.Name, + Value = x.Value + }).ToList(), + Options = commandOption.Options?.Select(x => x.ToApplicationCommandOptionProps()).ToList() + }; + } +} diff --git a/src/Discord.Net.Interactions/Utilities/EmptyServiceProvider.cs b/src/Discord.Net.Interactions/Utilities/EmptyServiceProvider.cs new file mode 100644 index 000000000..a53800946 --- /dev/null +++ b/src/Discord.Net.Interactions/Utilities/EmptyServiceProvider.cs @@ -0,0 +1,11 @@ +using System; + +namespace Discord.Interactions +{ + internal class EmptyServiceProvider : IServiceProvider + { + public static EmptyServiceProvider Instance => new EmptyServiceProvider(); + + public object GetService (Type serviceType) => null; + } +} diff --git a/src/Discord.Net.Interactions/Utilities/InteractionUtility.cs b/src/Discord.Net.Interactions/Utilities/InteractionUtility.cs new file mode 100644 index 000000000..9751b613d --- /dev/null +++ b/src/Discord.Net.Interactions/Utilities/InteractionUtility.cs @@ -0,0 +1,113 @@ +using Discord.WebSocket; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + /// + /// Utility class containing helper methods for interacting with Discord Interactions. + /// + public static class InteractionUtility + { + /// + /// Wait for an Interaction event for a given amount of time as an asynchronous opration. + /// + /// Client that should be listened to for the event. + /// Timeout duration for this operation. + /// Delegate for cheking whether an Interaction meets the requirements. + /// Token for canceling the wait operation. + /// + /// A Task representing the asyncronous waiting operation. If the user responded in the given amount of time, Task result contains the user response, + /// otherwise the Task result is . + /// + public static async Task WaitForInteractionAsync (BaseSocketClient client, TimeSpan timeout, + Predicate predicate, CancellationToken cancellationToken = default) + { + var tcs = new TaskCompletionSource(); + + var waitCancelSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); + Task wait = Task.Delay(timeout, waitCancelSource.Token) + .ContinueWith((t) => + { + if (!t.IsCanceled) + tcs.SetResult(null); + }); + + cancellationToken.Register(( ) => tcs.SetCanceled()); + + client.InteractionCreated += HandleInteraction; + var result = await tcs.Task.ConfigureAwait(false); + client.InteractionCreated -= HandleInteraction; + + return result; + + Task HandleInteraction (SocketInteraction interaction) + { + if (predicate(interaction)) + { + waitCancelSource.Cancel(); + tcs.SetResult(interaction); + } + + return Task.CompletedTask; + } + } + + /// + /// Wait for an Message Component Interaction event for a given amount of time as an asynchronous opration . + /// + /// Client that should be listened to for the event. + /// The message that or should originate from. + /// Timeout duration for this operation. + /// Token for canceling the wait operation. + /// + /// A Task representing the asyncronous waiting operation with a result, + /// the result is null if the process timed out before receiving a valid Interaction. + /// + public static Task WaitForMessageComponentAsync(BaseSocketClient client, IUserMessage fromMessage, TimeSpan timeout, + CancellationToken cancellationToken = default) + { + bool Predicate (SocketInteraction interaction) => interaction is SocketMessageComponent component && + component.Message.Id == fromMessage.Id; + + return WaitForInteractionAsync(client, timeout, Predicate, cancellationToken); + } + + /// + /// Create a confirmation dialog and wait for user input asynchronously. + /// + /// Client that should be listened to for the event. + /// Send the confirmation prompt to this channel. + /// Timeout duration of this operation. + /// Optional custom prompt message. + /// Token for canceling the wait operation. + /// + /// A Task representing the asyncronous waiting operation with a result, + /// the result is if the user declined the prompt or didnt answer in time, if the user confirmed the prompt. + /// + public static async Task ConfirmAsync (BaseSocketClient client, IMessageChannel channel, TimeSpan timeout, string message = null, + CancellationToken cancellationToken = default) + { + message ??= "Would you like to continue?"; + var confirmId = $"confirm"; + var declineId = $"decline"; + + var component = new ComponentBuilder() + .WithButton("Confirm", confirmId, ButtonStyle.Success) + .WithButton("Cancel", declineId, ButtonStyle.Danger) + .Build(); + + var prompt = await channel.SendMessageAsync(message, components: component).ConfigureAwait(false); + + var response = await WaitForMessageComponentAsync(client, prompt, timeout, cancellationToken).ConfigureAwait(false) as SocketMessageComponent; + + await prompt.DeleteAsync().ConfigureAwait(false); + + if (response != null && response.Data.CustomId == confirmId) + return true; + else + return false; + } + } +} diff --git a/src/Discord.Net.Interactions/Utilities/ReflectionUtils.cs b/src/Discord.Net.Interactions/Utilities/ReflectionUtils.cs new file mode 100644 index 000000000..b15662bfb --- /dev/null +++ b/src/Discord.Net.Interactions/Utilities/ReflectionUtils.cs @@ -0,0 +1,157 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using System.Threading.Tasks; + +namespace Discord.Interactions +{ + internal static class ReflectionUtils + { + private static readonly TypeInfo ObjectTypeInfo = typeof(object).GetTypeInfo(); + + internal static T CreateObject (TypeInfo typeInfo, InteractionService commandService, IServiceProvider services = null) => + CreateBuilder(typeInfo, commandService)(services); + + internal static Func CreateBuilder (TypeInfo typeInfo, InteractionService commandService) + { + var constructor = GetConstructor(typeInfo); + var parameters = constructor.GetParameters(); + var properties = GetProperties(typeInfo); + + return (services) => + { + var args = new object[parameters.Length]; + for (int i = 0; i < parameters.Length; i++) + args[i] = GetMember(commandService, services, parameters[i].ParameterType, typeInfo); + + var obj = InvokeConstructor(constructor, args, typeInfo); + foreach (var property in properties) + property.SetValue(obj, GetMember(commandService, services, property.PropertyType, typeInfo)); + return obj; + }; + } + + private static T InvokeConstructor (ConstructorInfo constructor, object[] args, TypeInfo ownerType) + { + try + { + return (T)constructor.Invoke(args); + } + catch (Exception ex) + { + throw new Exception($"Failed to create \"{ownerType.FullName}\".", ex); + } + } + private static ConstructorInfo GetConstructor (TypeInfo ownerType) + { + var constructors = ownerType.DeclaredConstructors.Where(x => !x.IsStatic).ToArray(); + if (constructors.Length == 0) + throw new InvalidOperationException($"No constructor found for \"{ownerType.FullName}\"."); + else if (constructors.Length > 1) + throw new InvalidOperationException($"Multiple constructors found for \"{ownerType.FullName}\"."); + return constructors[0]; + } + private static PropertyInfo[] GetProperties (TypeInfo ownerType) + { + var result = new List(); + while (ownerType != ObjectTypeInfo) + { + foreach (var prop in ownerType.DeclaredProperties) + { + if (prop.SetMethod?.IsStatic == false && prop.SetMethod?.IsPublic == true) + result.Add(prop); + } + ownerType = ownerType.BaseType.GetTypeInfo(); + } + return result.ToArray(); + } + private static object GetMember (InteractionService commandService, IServiceProvider services, Type memberType, TypeInfo ownerType) + { + if (memberType == typeof(InteractionService)) + return commandService; + if (memberType == typeof(IServiceProvider) || memberType == services.GetType()) + return services; + var service = services.GetService(memberType); + if (service != null) + return service; + throw new InvalidOperationException($"Failed to create \"{ownerType.FullName}\", dependency \"{memberType.Name}\" was not found."); + } + + internal static Func CreateMethodInvoker (MethodInfo methodInfo) + { + var parameters = methodInfo.GetParameters(); + var paramsExp = new Expression[parameters.Length]; + + var instanceExp = Expression.Parameter(typeof(T), "instance"); + var argsExp = Expression.Parameter(typeof(object[]), "args"); + + for (var i = 0; i < parameters.Length; i++) + { + var parameter = parameters[i]; + + var indexExp = Expression.Constant(i); + var accessExp = Expression.ArrayIndex(argsExp, indexExp); + paramsExp[i] = Expression.Convert(accessExp, parameter.ParameterType); + } + + var callExp = Expression.Call(Expression.Convert(instanceExp, methodInfo.ReflectedType), methodInfo, paramsExp); + var finalExp = Expression.Convert(callExp, typeof(Task)); + var lambda = Expression.Lambda>(finalExp, instanceExp, argsExp).Compile(); + + return lambda; + } + + /// + /// Create a type initializer using compiled lambda expressions + /// + internal static Func CreateLambdaBuilder (TypeInfo typeInfo, InteractionService commandService) + { + var constructor = GetConstructor(typeInfo); + var parameters = constructor.GetParameters(); + var properties = GetProperties(typeInfo); + + var argsExp = Expression.Parameter(typeof(object[]), "args"); + var propsExp = Expression.Parameter(typeof(object[]), "props"); + + var parameterExps = new Expression[parameters.Length]; + + for (var i = 0; i < parameters.Length; i++) + { + var indexExp = Expression.Constant(i); + var accessExp = Expression.ArrayIndex(argsExp, indexExp); + parameterExps[i] = Expression.Convert(accessExp, parameters[i].ParameterType); + } + + var newExp = Expression.New(constructor, parameterExps); + + var memberExps = new MemberAssignment[properties.Length]; + + for (var i = 0; i < properties.Length; i++) + { + var indexEx = Expression.Constant(i); + var accessExp = Expression.Convert(Expression.ArrayIndex(propsExp, indexEx), properties[i].PropertyType); + memberExps[i] = Expression.Bind(properties[i], accessExp); + } + var memberInit = Expression.MemberInit(newExp, memberExps); + var lambda = Expression.Lambda>(memberInit, argsExp, propsExp).Compile(); + + return (services) => + { + var args = new object[parameters.Length]; + var props = new object[properties.Length]; + + for (int i = 0; i < parameters.Length; i++) + args[i] = GetMember(commandService, services, parameters[i].ParameterType, typeInfo); + + for (int i = 0; i < properties.Length; i++) + props[i] = GetMember(commandService, services, properties[i].PropertyType, typeInfo); + + var instance = lambda(args, props); + + return instance; + }; + } + } +} diff --git a/src/Discord.Net.Interactions/Utilities/RegexUtils.cs b/src/Discord.Net.Interactions/Utilities/RegexUtils.cs new file mode 100644 index 000000000..82ba944f8 --- /dev/null +++ b/src/Discord.Net.Interactions/Utilities/RegexUtils.cs @@ -0,0 +1,85 @@ +using System; +using System.Linq; + +namespace System.Text.RegularExpressions +{ + internal static class RegexUtils + { + internal const byte Q = 5; // quantifier + internal const byte S = 4; // ordinary stoppper + internal const byte Z = 3; // ScanBlank stopper + internal const byte X = 2; // whitespace + internal const byte E = 1; // should be escaped + + internal static readonly byte[] _category = new byte[] { + // 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 1 2 3 4 5 6 7 8 9 A B C D E F + 0,0,0,0,0,0,0,0,0,X,X,0,X,X,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + // ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + X,0,0,Z,S,0,0,0,S,S,Q,Q,0,0,S,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,Q, + // @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,S,S,0,S,0, + // ' a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,Q,S,0,0,0}; + + internal static string EscapeExcluding(string input, params char[] exclude) + { + if (exclude is null) + throw new ArgumentNullException("exclude"); + + for (int i = 0; i < input.Length; i++) + { + if (IsMetachar(input[i]) && !exclude.Contains(input[i])) + { + StringBuilder sb = new StringBuilder(); + char ch = input[i]; + int lastpos; + + sb.Append(input, 0, i); + do + { + sb.Append('\\'); + switch (ch) + { + case '\n': + ch = 'n'; + break; + case '\r': + ch = 'r'; + break; + case '\t': + ch = 't'; + break; + case '\f': + ch = 'f'; + break; + } + sb.Append(ch); + i++; + lastpos = i; + + while (i < input.Length) + { + ch = input[i]; + if (IsMetachar(ch) && !exclude.Contains(input[i])) + break; + + i++; + } + + sb.Append(input, lastpos, i - lastpos); + + } while (i < input.Length); + + return sb.ToString(); + } + } + + return input; + } + + internal static bool IsMetachar(char ch) + { + return (ch <= '|' && _category[ch] >= E); + } + } +} diff --git a/src/Discord.Net.Rest/API/Common/ActionRowComponent.cs b/src/Discord.Net.Rest/API/Common/ActionRowComponent.cs new file mode 100644 index 000000000..9dede7e03 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/ActionRowComponent.cs @@ -0,0 +1,32 @@ +using Newtonsoft.Json; +using System.Linq; + +namespace Discord.API +{ + internal class ActionRowComponent : IMessageComponent + { + [JsonProperty("type")] + public ComponentType Type { get; set; } + + [JsonProperty("components")] + public IMessageComponent[] Components { get; set; } + + internal ActionRowComponent() { } + internal ActionRowComponent(Discord.ActionRowComponent c) + { + Type = c.Type; + Components = c.Components?.Select(x => + { + return x.Type switch + { + ComponentType.Button => new ButtonComponent(x as Discord.ButtonComponent), + ComponentType.SelectMenu => new SelectMenuComponent(x as Discord.SelectMenuComponent), + _ => null + }; + }).ToArray(); + } + + [JsonIgnore] + string IMessageComponent.CustomId => null; + } +} diff --git a/src/Discord.Net.Rest/Entities/Messages/AllowedMentions.cs b/src/Discord.Net.Rest/API/Common/AllowedMentions.cs similarity index 73% rename from src/Discord.Net.Rest/Entities/Messages/AllowedMentions.cs rename to src/Discord.Net.Rest/API/Common/AllowedMentions.cs index 5ab96032f..7737a464f 100644 --- a/src/Discord.Net.Rest/Entities/Messages/AllowedMentions.cs +++ b/src/Discord.Net.Rest/API/Common/AllowedMentions.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; namespace Discord.API { - public class AllowedMentions + internal class AllowedMentions { [JsonProperty("parse")] public Optional Parse { get; set; } @@ -11,5 +11,7 @@ namespace Discord.API public Optional Roles { get; set; } [JsonProperty("users")] public Optional Users { get; set; } + [JsonProperty("replied_user")] + public Optional RepliedUser { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/Application.cs b/src/Discord.Net.Rest/API/Common/Application.cs index ca4c443f1..62a1d9688 100644 --- a/src/Discord.Net.Rest/API/Common/Application.cs +++ b/src/Discord.Net.Rest/API/Common/Application.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API @@ -8,17 +7,30 @@ namespace Discord.API [JsonProperty("description")] public string Description { get; set; } [JsonProperty("rpc_origins")] - public string[] RPCOrigins { get; set; } + public Optional RPCOrigins { get; set; } [JsonProperty("name")] public string Name { get; set; } [JsonProperty("id")] public ulong Id { get; set; } [JsonProperty("icon")] public string Icon { get; set; } - + [JsonProperty("bot_public")] + public bool IsBotPublic { get; set; } + [JsonProperty("bot_require_code_grant")] + public bool BotRequiresCodeGrant { get; set; } + [JsonProperty("install_params")] + public Optional InstallParams { get; set; } + [JsonProperty("team")] + public Team Team { get; set; } [JsonProperty("flags"), Int53] - public Optional Flags { get; set; } + public Optional Flags { get; set; } [JsonProperty("owner")] public Optional Owner { get; set; } + [JsonProperty("tags")] + public Optional Tags { get; set; } + [JsonProperty("terms_of_service_url")] + public string TermsOfService { get; set; } + [JsonProperty("privacy_policy_url")] + public string PrivacyPolicy { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommand.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommand.cs new file mode 100644 index 000000000..81598b96e --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/ApplicationCommand.cs @@ -0,0 +1,28 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class ApplicationCommand + { + [JsonProperty("id")] + public ulong Id { get; set; } + + [JsonProperty("type")] + public ApplicationCommandType Type { get; set; } = ApplicationCommandType.Slash; // defaults to 1 which is slash. + + [JsonProperty("application_id")] + public ulong ApplicationId { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("options")] + public Optional Options { get; set; } + + [JsonProperty("default_permission")] + public Optional DefaultPermissions { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionData.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionData.cs new file mode 100644 index 000000000..a98ed77d6 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionData.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class ApplicationCommandInteractionData : IResolvable, IDiscordInteractionData + { + [JsonProperty("id")] + public ulong Id { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("options")] + public Optional Options { get; set; } + + [JsonProperty("resolved")] + public Optional Resolved { get; set; } + + [JsonProperty("type")] + public ApplicationCommandType Type { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataOption.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataOption.cs new file mode 100644 index 000000000..1e488c4e6 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataOption.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class ApplicationCommandInteractionDataOption + { + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("type")] + public ApplicationCommandOptionType Type { get; set; } + + [JsonProperty("value")] + public Optional Value { get; set; } + + [JsonProperty("options")] + public Optional Options { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataResolved.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataResolved.cs new file mode 100644 index 000000000..5b4b83e23 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataResolved.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace Discord.API +{ + internal class ApplicationCommandInteractionDataResolved + { + [JsonProperty("users")] + public Optional> Users { get; set; } + + [JsonProperty("members")] + public Optional> Members { get; set; } + + [JsonProperty("channels")] + public Optional> Channels { get; set; } + + [JsonProperty("roles")] + public Optional> Roles { get; set; } + [JsonProperty("messages")] + public Optional> Messages { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandOption.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandOption.cs new file mode 100644 index 000000000..d703bd46b --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandOption.cs @@ -0,0 +1,89 @@ +using Newtonsoft.Json; +using System.Linq; + +namespace Discord.API +{ + internal class ApplicationCommandOption + { + [JsonProperty("type")] + public ApplicationCommandOptionType Type { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("default")] + public Optional Default { get; set; } + + [JsonProperty("required")] + public Optional Required { get; set; } + + [JsonProperty("choices")] + public Optional Choices { get; set; } + + [JsonProperty("options")] + public Optional Options { get; set; } + + [JsonProperty("autocomplete")] + public Optional Autocomplete { get; set; } + + [JsonProperty("min_value")] + public Optional MinValue { get; set; } + + [JsonProperty("max_value")] + public Optional MaxValue { get; set; } + + [JsonProperty("channel_types")] + public Optional ChannelTypes { get; set; } + + public ApplicationCommandOption() { } + + public ApplicationCommandOption(IApplicationCommandOption cmd) + { + Choices = cmd.Choices.Select(x => new ApplicationCommandOptionChoice + { + Name = x.Name, + Value = x.Value + }).ToArray(); + + Options = cmd.Options.Select(x => new ApplicationCommandOption(x)).ToArray(); + + ChannelTypes = cmd.ChannelTypes.ToArray(); + + Required = cmd.IsRequired ?? Optional.Unspecified; + Default = cmd.IsDefault ?? Optional.Unspecified; + MinValue = cmd.MinValue ?? Optional.Unspecified; + MaxValue = cmd.MaxValue ?? Optional.Unspecified; + Autocomplete = cmd.IsAutocomplete ?? Optional.Unspecified; + + Name = cmd.Name; + Type = cmd.Type; + Description = cmd.Description; + } + public ApplicationCommandOption(ApplicationCommandOptionProperties option) + { + Choices = option.Choices?.Select(x => new ApplicationCommandOptionChoice + { + Name = x.Name, + Value = x.Value + }).ToArray() ?? Optional.Unspecified; + + Options = option.Options?.Select(x => new ApplicationCommandOption(x)).ToArray() ?? Optional.Unspecified; + + Required = option.IsRequired ?? Optional.Unspecified; + + Default = option.IsDefault ?? Optional.Unspecified; + MinValue = option.MinValue ?? Optional.Unspecified; + MaxValue = option.MaxValue ?? Optional.Unspecified; + + ChannelTypes = option.ChannelTypes?.ToArray() ?? Optional.Unspecified; + + Name = option.Name; + Type = option.Type; + Description = option.Description; + Autocomplete = option.IsAutocomplete; + } + } +} diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandOptionChoice.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandOptionChoice.cs new file mode 100644 index 000000000..6f84437f6 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandOptionChoice.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class ApplicationCommandOptionChoice + { + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("value")] + public object Value { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandPermissions.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandPermissions.cs new file mode 100644 index 000000000..8bde80f50 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandPermissions.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class ApplicationCommandPermissions + { + [JsonProperty("id")] + public ulong Id { get; set; } + + [JsonProperty("type")] + public ApplicationCommandPermissionTarget Type { get; set; } + + [JsonProperty("permission")] + public bool Permission { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/Attachment.cs b/src/Discord.Net.Rest/API/Common/Attachment.cs index 4a651d9fa..7970dc9a5 100644 --- a/src/Discord.Net.Rest/API/Common/Attachment.cs +++ b/src/Discord.Net.Rest/API/Common/Attachment.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API @@ -9,6 +8,10 @@ namespace Discord.API public ulong Id { get; set; } [JsonProperty("filename")] public string Filename { get; set; } + [JsonProperty("description")] + public Optional Description { get; set; } + [JsonProperty("content_type")] + public Optional ContentType { get; set; } [JsonProperty("size")] public int Size { get; set; } [JsonProperty("url")] @@ -19,5 +22,7 @@ namespace Discord.API public Optional Height { get; set; } [JsonProperty("width")] public Optional Width { get; set; } + [JsonProperty("ephemeral")] + public Optional Ephemeral { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/AuditLog.cs b/src/Discord.Net.Rest/API/Common/AuditLog.cs index cd8ad147d..c8bd6d3e2 100644 --- a/src/Discord.Net.Rest/API/Common/AuditLog.cs +++ b/src/Discord.Net.Rest/API/Common/AuditLog.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Discord.API { @@ -7,6 +7,12 @@ namespace Discord.API [JsonProperty("webhooks")] public Webhook[] Webhooks { get; set; } + [JsonProperty("threads")] + public Channel[] Threads { get; set; } + + [JsonProperty("integrations")] + public Integration[] Integrations { get; set; } + [JsonProperty("users")] public User[] Users { get; set; } diff --git a/src/Discord.Net.Rest/API/Common/AuditLogEntry.cs b/src/Discord.Net.Rest/API/Common/AuditLogEntry.cs index 80d9a9e97..9626ad67e 100644 --- a/src/Discord.Net.Rest/API/Common/AuditLogEntry.cs +++ b/src/Discord.Net.Rest/API/Common/AuditLogEntry.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Discord.API { @@ -7,7 +7,7 @@ namespace Discord.API [JsonProperty("target_id")] public ulong? TargetId { get; set; } [JsonProperty("user_id")] - public ulong UserId { get; set; } + public ulong? UserId { get; set; } [JsonProperty("changes")] public AuditLogChange[] Changes { get; set; } diff --git a/src/Discord.Net.Rest/API/Common/AutocompleteInteractionData.cs b/src/Discord.Net.Rest/API/Common/AutocompleteInteractionData.cs new file mode 100644 index 000000000..2184a0e98 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/AutocompleteInteractionData.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class AutocompleteInteractionData : IDiscordInteractionData + { + [JsonProperty("id")] + public ulong Id { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("type")] + public ApplicationCommandType Type { get; set; } + + [JsonProperty("version")] + public ulong Version { get; set; } + + [JsonProperty("options")] + public AutocompleteInteractionDataOption[] Options { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/AutocompleteInteractionDataOption.cs b/src/Discord.Net.Rest/API/Common/AutocompleteInteractionDataOption.cs new file mode 100644 index 000000000..1419f93b6 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/AutocompleteInteractionDataOption.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class AutocompleteInteractionDataOption + { + [JsonProperty("type")] + public ApplicationCommandOptionType Type { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("options")] + public Optional Options { get; set; } + + [JsonProperty("value")] + public Optional Value { get; set; } + + [JsonProperty("focused")] + public Optional Focused { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/Ban.cs b/src/Discord.Net.Rest/API/Common/Ban.cs index 202004f53..ff47c7904 100644 --- a/src/Discord.Net.Rest/API/Common/Ban.cs +++ b/src/Discord.Net.Rest/API/Common/Ban.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API diff --git a/src/Discord.Net.Rest/API/Common/ButtonComponent.cs b/src/Discord.Net.Rest/API/Common/ButtonComponent.cs new file mode 100644 index 000000000..7f737d7ad --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/ButtonComponent.cs @@ -0,0 +1,63 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class ButtonComponent : IMessageComponent + { + [JsonProperty("type")] + public ComponentType Type { get; set; } + + [JsonProperty("style")] + public ButtonStyle Style { get; set; } + + [JsonProperty("label")] + public Optional Label { get; set; } + + [JsonProperty("emoji")] + public Optional Emote { get; set; } + + [JsonProperty("custom_id")] + public Optional CustomId { get; set; } + + [JsonProperty("url")] + public Optional Url { get; set; } + + [JsonProperty("disabled")] + public Optional Disabled { get; set; } + + public ButtonComponent() { } + + public ButtonComponent(Discord.ButtonComponent c) + { + Type = c.Type; + Style = c.Style; + Label = c.Label; + CustomId = c.CustomId; + Url = c.Url; + Disabled = c.IsDisabled; + + if (c.Emote != null) + { + if (c.Emote is Emote e) + { + Emote = new Emoji + { + Name = e.Name, + Animated = e.Animated, + Id = e.Id + }; + } + else + { + Emote = new Emoji + { + Name = c.Emote.Name + }; + } + } + } + + [JsonIgnore] + string IMessageComponent.CustomId => CustomId.GetValueOrDefault(); + } +} diff --git a/src/Discord.Net.Rest/API/Common/Channel.cs b/src/Discord.Net.Rest/API/Common/Channel.cs index 57a5ce9ab..d565b269a 100644 --- a/src/Discord.Net.Rest/API/Common/Channel.cs +++ b/src/Discord.Net.Rest/API/Common/Channel.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; using System; @@ -41,6 +40,8 @@ namespace Discord.API public Optional Bitrate { get; set; } [JsonProperty("user_limit")] public Optional UserLimit { get; set; } + [JsonProperty("rtc_region")] + public Optional RTCRegion { get; set; } //PrivateChannel [JsonProperty("recipients")] @@ -49,5 +50,21 @@ namespace Discord.API //GroupChannel [JsonProperty("icon")] public Optional Icon { get; set; } + + //ThreadChannel + [JsonProperty("member")] + public Optional ThreadMember { get; set; } + + [JsonProperty("thread_metadata")] + public Optional ThreadMetadata { get; set; } + + [JsonProperty("owner_id")] + public Optional OwnerId { get; set; } + + [JsonProperty("message_count")] + public Optional MessageCount { get; set; } + + [JsonProperty("member_count")] + public Optional MemberCount { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/ChannelThreads.cs b/src/Discord.Net.Rest/API/Common/ChannelThreads.cs new file mode 100644 index 000000000..94b2396bf --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/ChannelThreads.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Discord.API.Rest +{ + internal class ChannelThreads + { + [JsonProperty("threads")] + public Channel[] Threads { get; set; } + + [JsonProperty("members")] + public ThreadMember[] Members { get; set; } + + [JsonProperty("has_more")] + public bool HasMore { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/Connection.cs b/src/Discord.Net.Rest/API/Common/Connection.cs index ad0a76ac1..bd8de3902 100644 --- a/src/Discord.Net.Rest/API/Common/Connection.cs +++ b/src/Discord.Net.Rest/API/Common/Connection.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; using System.Collections.Generic; diff --git a/src/Discord.Net.Rest/API/Common/DiscordError.cs b/src/Discord.Net.Rest/API/Common/DiscordError.cs new file mode 100644 index 000000000..ac1e5e13d --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/DiscordError.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.API +{ + [JsonConverter(typeof(Discord.Net.Converters.DiscordErrorConverter))] + internal class DiscordError + { + [JsonProperty("message")] + public string Message { get; set; } + [JsonProperty("code")] + public DiscordErrorCode Code { get; set; } + [JsonProperty("errors")] + public Optional Errors { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/Embed.cs b/src/Discord.Net.Rest/API/Common/Embed.cs index fbf20d987..77efa12aa 100644 --- a/src/Discord.Net.Rest/API/Common/Embed.cs +++ b/src/Discord.Net.Rest/API/Common/Embed.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using System; using Newtonsoft.Json; using Discord.Net.Converters; diff --git a/src/Discord.Net.Rest/API/Common/EmbedImage.cs b/src/Discord.Net.Rest/API/Common/EmbedImage.cs index e650d99f4..6b5db0681 100644 --- a/src/Discord.Net.Rest/API/Common/EmbedImage.cs +++ b/src/Discord.Net.Rest/API/Common/EmbedImage.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API diff --git a/src/Discord.Net.Rest/API/Common/EmbedProvider.cs b/src/Discord.Net.Rest/API/Common/EmbedProvider.cs index e01261483..ed0f7c3c8 100644 --- a/src/Discord.Net.Rest/API/Common/EmbedProvider.cs +++ b/src/Discord.Net.Rest/API/Common/EmbedProvider.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API diff --git a/src/Discord.Net.Rest/API/Common/EmbedThumbnail.cs b/src/Discord.Net.Rest/API/Common/EmbedThumbnail.cs index 9c87ca46b..dd25a1a26 100644 --- a/src/Discord.Net.Rest/API/Common/EmbedThumbnail.cs +++ b/src/Discord.Net.Rest/API/Common/EmbedThumbnail.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API diff --git a/src/Discord.Net.Rest/API/Common/EmbedVideo.cs b/src/Discord.Net.Rest/API/Common/EmbedVideo.cs index 3a034d244..f668217f0 100644 --- a/src/Discord.Net.Rest/API/Common/EmbedVideo.cs +++ b/src/Discord.Net.Rest/API/Common/EmbedVideo.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API diff --git a/src/Discord.Net.Rest/API/Common/Emoji.cs b/src/Discord.Net.Rest/API/Common/Emoji.cs index 945cc6d7e..ff0baa73e 100644 --- a/src/Discord.Net.Rest/API/Common/Emoji.cs +++ b/src/Discord.Net.Rest/API/Common/Emoji.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API diff --git a/src/Discord.Net.Rest/API/Common/Error.cs b/src/Discord.Net.Rest/API/Common/Error.cs new file mode 100644 index 000000000..a2b1777a3 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/Error.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class Error + { + [JsonProperty("code")] + public string Code { get; set; } + [JsonProperty("message")] + public string Message { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/Game.cs b/src/Discord.Net.Rest/API/Common/Game.cs index d3a618697..105ce0d73 100644 --- a/src/Discord.Net.Rest/API/Common/Game.cs +++ b/src/Discord.Net.Rest/API/Common/Game.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using System.Runtime.Serialization; @@ -41,6 +40,8 @@ namespace Discord.API public Optional Emoji { get; set; } [JsonProperty("created_at")] public Optional CreatedAt { get; set; } + //[JsonProperty("buttons")] + //public Optional Buttons { get; set; } [OnError] internal void OnError(StreamingContext context, ErrorContext errorContext) diff --git a/src/Discord.Net.Rest/API/Common/Guild.cs b/src/Discord.Net.Rest/API/Common/Guild.cs index 56bd841ea..d550c54a0 100644 --- a/src/Discord.Net.Rest/API/Common/Guild.cs +++ b/src/Discord.Net.Rest/API/Common/Guild.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API @@ -13,6 +12,8 @@ namespace Discord.API public string Icon { get; set; } [JsonProperty("splash")] public string Splash { get; set; } + [JsonProperty("discovery_splash")] + public string DiscoverySplash { get; set; } [JsonProperty("owner_id")] public ulong OwnerId { get; set; } [JsonProperty("region")] @@ -21,10 +22,6 @@ namespace Discord.API public ulong? AFKChannelId { get; set; } [JsonProperty("afk_timeout")] public int AFKTimeout { get; set; } - [JsonProperty("embed_enabled")] - public bool EmbedEnabled { get; set; } - [JsonProperty("embed_channel_id")] - public ulong? EmbedChannelId { get; set; } [JsonProperty("verification_level")] public VerificationLevel VerificationLevel { get; set; } [JsonProperty("default_message_notifications")] @@ -38,11 +35,15 @@ namespace Discord.API [JsonProperty("emojis")] public Emoji[] Emojis { get; set; } [JsonProperty("features")] - public string[] Features { get; set; } + public GuildFeatures Features { get; set; } [JsonProperty("mfa_level")] public MfaLevel MfaLevel { get; set; } [JsonProperty("application_id")] public ulong? ApplicationId { get; set; } + [JsonProperty("widget_enabled")] + public Optional WidgetEnabled { get; set; } + [JsonProperty("widget_channel_id")] + public Optional WidgetChannelId { get; set; } [JsonProperty("system_channel_id")] public ulong? SystemChannelId { get; set; } [JsonProperty("premium_tier")] @@ -56,9 +57,31 @@ namespace Discord.API // this value is inverted, flags set will turn OFF features [JsonProperty("system_channel_flags")] public SystemChannelMessageDeny SystemChannelFlags { get; set; } + [JsonProperty("rules_channel_id")] + public ulong? RulesChannelId { get; set; } + [JsonProperty("max_presences")] + public Optional MaxPresences { get; set; } + [JsonProperty("max_members")] + public Optional MaxMembers { get; set; } [JsonProperty("premium_subscription_count")] public int? PremiumSubscriptionCount { get; set; } [JsonProperty("preferred_locale")] public string PreferredLocale { get; set; } + [JsonProperty("public_updates_channel_id")] + public ulong? PublicUpdatesChannelId { get; set; } + [JsonProperty("max_video_channel_users")] + public Optional MaxVideoChannelUsers { get; set; } + [JsonProperty("approximate_member_count")] + public Optional ApproximateMemberCount { get; set; } + [JsonProperty("approximate_presence_count")] + public Optional ApproximatePresenceCount { get; set; } + [JsonProperty("threads")] + public Optional Threads { get; set; } + [JsonProperty("nsfw_level")] + public NsfwLevel NsfwLevel { get; set; } + [JsonProperty("stickers")] + public Sticker[] Stickers { get; set; } + [JsonProperty("premium_progress_bar_enabled")] + public Optional IsBoostProgressBarEnabled { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/GuildApplicationCommandPermissions.cs b/src/Discord.Net.Rest/API/Common/GuildApplicationCommandPermissions.cs new file mode 100644 index 000000000..cc74299f7 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/GuildApplicationCommandPermissions.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class GuildApplicationCommandPermission + { + [JsonProperty("id")] + public ulong Id { get; set; } + + [JsonProperty("application_id")] + public ulong ApplicationId { get; set; } + + [JsonProperty("guild_id")] + public ulong GuildId { get; set; } + + [JsonProperty("permissions")] + public ApplicationCommandPermissions[] Permissions { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/GuildMember.cs b/src/Discord.Net.Rest/API/Common/GuildMember.cs index 940eb925a..cd3101224 100644 --- a/src/Discord.Net.Rest/API/Common/GuildMember.cs +++ b/src/Discord.Net.Rest/API/Common/GuildMember.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; using System; @@ -10,6 +9,8 @@ namespace Discord.API public User User { get; set; } [JsonProperty("nick")] public Optional Nick { get; set; } + [JsonProperty("avatar")] + public Optional Avatar { get; set; } [JsonProperty("roles")] public Optional Roles { get; set; } [JsonProperty("joined_at")] @@ -18,7 +19,11 @@ namespace Discord.API public Optional Deaf { get; set; } [JsonProperty("mute")] public Optional Mute { get; set; } + [JsonProperty("pending")] + public Optional Pending { get; set; } [JsonProperty("premium_since")] public Optional PremiumSince { get; set; } + [JsonProperty("communication_disabled_until")] + public Optional TimedOutUntil { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/GuildScheduledEvent.cs b/src/Discord.Net.Rest/API/Common/GuildScheduledEvent.cs new file mode 100644 index 000000000..338c24dc9 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/GuildScheduledEvent.cs @@ -0,0 +1,43 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.API +{ + internal class GuildScheduledEvent + { + [JsonProperty("id")] + public ulong Id { get; set; } + [JsonProperty("guild_id")] + public ulong GuildId { get; set; } + [JsonProperty("channel_id")] + public Optional ChannelId { get; set; } + [JsonProperty("creator_id")] + public Optional CreatorId { get; set; } + [JsonProperty("name")] + public string Name { get; set; } + [JsonProperty("description")] + public Optional Description { get; set; } + [JsonProperty("scheduled_start_time")] + public DateTimeOffset ScheduledStartTime { get; set; } + [JsonProperty("scheduled_end_time")] + public DateTimeOffset? ScheduledEndTime { get; set; } + [JsonProperty("privacy_level")] + public GuildScheduledEventPrivacyLevel PrivacyLevel { get; set; } + [JsonProperty("status")] + public GuildScheduledEventStatus Status { get; set; } + [JsonProperty("entity_type")] + public GuildScheduledEventType EntityType { get; set; } + [JsonProperty("entity_id")] + public ulong? EntityId { get; set; } + [JsonProperty("entity_metadata")] + public GuildScheduledEventEntityMetadata EntityMetadata { get; set; } + [JsonProperty("creator")] + public Optional Creator { get; set; } + [JsonProperty("user_count")] + public Optional UserCount { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/GuildScheduledEventEntityMetadata.cs b/src/Discord.Net.Rest/API/Common/GuildScheduledEventEntityMetadata.cs new file mode 100644 index 000000000..1db38c0ae --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/GuildScheduledEventEntityMetadata.cs @@ -0,0 +1,15 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.API +{ + internal class GuildScheduledEventEntityMetadata + { + [JsonProperty("location")] + public Optional Location { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/GuildScheduledEventUser.cs b/src/Discord.Net.Rest/API/Common/GuildScheduledEventUser.cs new file mode 100644 index 000000000..1b0b93763 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/GuildScheduledEventUser.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.API +{ + internal class GuildScheduledEventUser + { + [JsonProperty("user")] + public User User { get; set; } + [JsonProperty("member")] + public Optional Member { get; set; } + [JsonProperty("guild_scheduled_event_id")] + public ulong GuildScheduledEventId { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/GuildEmbed.cs b/src/Discord.Net.Rest/API/Common/GuildWidget.cs similarity index 61% rename from src/Discord.Net.Rest/API/Common/GuildEmbed.cs rename to src/Discord.Net.Rest/API/Common/GuildWidget.cs index ff8b8e180..6b1d29cce 100644 --- a/src/Discord.Net.Rest/API/Common/GuildEmbed.cs +++ b/src/Discord.Net.Rest/API/Common/GuildWidget.cs @@ -1,13 +1,12 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API { - internal class GuildEmbed + internal class GuildWidget { [JsonProperty("enabled")] public bool Enabled { get; set; } [JsonProperty("channel_id")] - public ulong ChannelId { get; set; } + public ulong? ChannelId { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/InstallParams.cs b/src/Discord.Net.Rest/API/Common/InstallParams.cs new file mode 100644 index 000000000..1fb987f30 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/InstallParams.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.API +{ + internal class InstallParams + { + [JsonProperty("scopes")] + public string[] Scopes { get; set; } + [JsonProperty("permissions")] + public ulong Permission { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/Integration.cs b/src/Discord.Net.Rest/API/Common/Integration.cs index 821359975..47d67e149 100644 --- a/src/Discord.Net.Rest/API/Common/Integration.cs +++ b/src/Discord.Net.Rest/API/Common/Integration.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; using System; diff --git a/src/Discord.Net.Rest/API/Common/IntegrationAccount.cs b/src/Discord.Net.Rest/API/Common/IntegrationAccount.cs index 22831e795..a8d33931c 100644 --- a/src/Discord.Net.Rest/API/Common/IntegrationAccount.cs +++ b/src/Discord.Net.Rest/API/Common/IntegrationAccount.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API diff --git a/src/Discord.Net.Rest/API/Common/Interaction.cs b/src/Discord.Net.Rest/API/Common/Interaction.cs new file mode 100644 index 000000000..7f953384d --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/Interaction.cs @@ -0,0 +1,41 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + [JsonConverter(typeof(Net.Converters.InteractionConverter))] + internal class Interaction + { + [JsonProperty("id")] + public ulong Id { get; set; } + + [JsonProperty("application_id")] + public ulong ApplicationId { get; set; } + + [JsonProperty("type")] + public InteractionType Type { get; set; } + + [JsonProperty("data")] + public Optional Data { get; set; } + + [JsonProperty("guild_id")] + public Optional GuildId { get; set; } + + [JsonProperty("channel_id")] + public Optional ChannelId { get; set; } + + [JsonProperty("member")] + public Optional Member { get; set; } + + [JsonProperty("user")] + public Optional User { get; set; } + + [JsonProperty("token")] + public string Token { get; set; } + + [JsonProperty("version")] + public int Version { get; set; } + + [JsonProperty("message")] + public Optional Message { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/InteractionCallbackData.cs b/src/Discord.Net.Rest/API/Common/InteractionCallbackData.cs new file mode 100644 index 000000000..b07ebff49 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/InteractionCallbackData.cs @@ -0,0 +1,28 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class InteractionCallbackData + { + [JsonProperty("tts")] + public Optional TTS { get; set; } + + [JsonProperty("content")] + public Optional Content { get; set; } + + [JsonProperty("embeds")] + public Optional Embeds { get; set; } + + [JsonProperty("allowed_mentions")] + public Optional AllowedMentions { get; set; } + + [JsonProperty("flags")] + public Optional Flags { get; set; } + + [JsonProperty("components")] + public Optional Components { get; set; } + + [JsonProperty("choices")] + public Optional Choices { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/InteractionResponse.cs b/src/Discord.Net.Rest/API/Common/InteractionResponse.cs new file mode 100644 index 000000000..93d4cd307 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/InteractionResponse.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class InteractionResponse + { + [JsonProperty("type")] + public InteractionResponseType Type { get; set; } + + [JsonProperty("data")] + public Optional Data { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/Invite.cs b/src/Discord.Net.Rest/API/Common/Invite.cs index 649bc37ec..f9d53bad6 100644 --- a/src/Discord.Net.Rest/API/Common/Invite.cs +++ b/src/Discord.Net.Rest/API/Common/Invite.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API @@ -11,9 +10,15 @@ namespace Discord.API public Optional Guild { get; set; } [JsonProperty("channel")] public InviteChannel Channel { get; set; } + [JsonProperty("inviter")] + public Optional Inviter { get; set; } [JsonProperty("approximate_presence_count")] public Optional PresenceCount { get; set; } [JsonProperty("approximate_member_count")] public Optional MemberCount { get; set; } + [JsonProperty("target_user")] + public Optional TargetUser { get; set; } + [JsonProperty("target_user_type")] + public Optional TargetUserType { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/InviteChannel.cs b/src/Discord.Net.Rest/API/Common/InviteChannel.cs index f8f2a34f2..d601e65fe 100644 --- a/src/Discord.Net.Rest/API/Common/InviteChannel.cs +++ b/src/Discord.Net.Rest/API/Common/InviteChannel.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API diff --git a/src/Discord.Net.Rest/API/Common/InviteGuild.cs b/src/Discord.Net.Rest/API/Common/InviteGuild.cs index 3d6d7cd74..f5c634e4e 100644 --- a/src/Discord.Net.Rest/API/Common/InviteGuild.cs +++ b/src/Discord.Net.Rest/API/Common/InviteGuild.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API diff --git a/src/Discord.Net.Rest/API/Common/InviteMetadata.cs b/src/Discord.Net.Rest/API/Common/InviteMetadata.cs index ca019b79b..a06d06969 100644 --- a/src/Discord.Net.Rest/API/Common/InviteMetadata.cs +++ b/src/Discord.Net.Rest/API/Common/InviteMetadata.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; using System; @@ -6,19 +5,15 @@ namespace Discord.API { internal class InviteMetadata : Invite { - [JsonProperty("inviter")] - public User Inviter { get; set; } [JsonProperty("uses")] - public Optional Uses { get; set; } + public int Uses { get; set; } [JsonProperty("max_uses")] - public Optional MaxUses { get; set; } + public int MaxUses { get; set; } [JsonProperty("max_age")] - public Optional MaxAge { get; set; } + public int MaxAge { get; set; } [JsonProperty("temporary")] public bool Temporary { get; set; } [JsonProperty("created_at")] - public Optional CreatedAt { get; set; } - [JsonProperty("revoked")] - public bool Revoked { get; set; } + public DateTimeOffset CreatedAt { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/InviteVanity.cs b/src/Discord.Net.Rest/API/Common/InviteVanity.cs index d39792674..412795aa6 100644 --- a/src/Discord.Net.Rest/API/Common/InviteVanity.cs +++ b/src/Discord.Net.Rest/API/Common/InviteVanity.cs @@ -2,9 +2,21 @@ using Newtonsoft.Json; namespace Discord.API { + /// + /// Represents a vanity invite. + /// public class InviteVanity { + /// + /// The unique code for the invite link. + /// [JsonProperty("code")] public string Code { get; set; } + + /// + /// The total amount of vanity invite uses. + /// + [JsonProperty("uses")] + public int Uses { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/MembershipState.cs b/src/Discord.Net.Rest/API/Common/MembershipState.cs new file mode 100644 index 000000000..67fcc8908 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/MembershipState.cs @@ -0,0 +1,9 @@ +namespace Discord.API +{ + internal enum MembershipState + { + None = 0, + Invited = 1, + Accepted = 2, + } +} diff --git a/src/Discord.Net.Rest/API/Common/Message.cs b/src/Discord.Net.Rest/API/Common/Message.cs index b4529d457..d33a03fe5 100644 --- a/src/Discord.Net.Rest/API/Common/Message.cs +++ b/src/Discord.Net.Rest/API/Common/Message.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; using System; @@ -33,7 +32,7 @@ namespace Discord.API [JsonProperty("mention_everyone")] public Optional MentionEveryone { get; set; } [JsonProperty("mentions")] - public Optional[]> UserMentions { get; set; } + public Optional UserMentions { get; set; } [JsonProperty("mention_roles")] public Optional RoleMentions { get; set; } [JsonProperty("attachments")] @@ -56,5 +55,12 @@ namespace Discord.API public Optional Flags { get; set; } [JsonProperty("allowed_mentions")] public Optional AllowedMentions { get; set; } + [JsonProperty("referenced_message")] + public Optional ReferencedMessage { get; set; } + [JsonProperty("components")] + public Optional Components { get; set; } + public Optional Interaction { get; set; } + [JsonProperty("sticker_items")] + public Optional StickerItems { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/MessageComponentInteractionData.cs b/src/Discord.Net.Rest/API/Common/MessageComponentInteractionData.cs new file mode 100644 index 000000000..a7760911c --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/MessageComponentInteractionData.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class MessageComponentInteractionData : IDiscordInteractionData + { + [JsonProperty("custom_id")] + public string CustomId { get; set; } + + [JsonProperty("component_type")] + public ComponentType ComponentType { get; set; } + + [JsonProperty("values")] + public Optional Values { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/MessageFlags.cs b/src/Discord.Net.Rest/API/Common/MessageFlags.cs deleted file mode 100644 index ebe4e80ca..000000000 --- a/src/Discord.Net.Rest/API/Common/MessageFlags.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace Discord.API -{ - [Flags] - internal enum MessageFlags : byte // probably safe to constrain this to 8 values, if not, it's internal so who cares - { - Suppressed = 0x04, - } -} diff --git a/src/Discord.Net.Rest/API/Common/MessageInteraction.cs b/src/Discord.Net.Rest/API/Common/MessageInteraction.cs new file mode 100644 index 000000000..48f278396 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/MessageInteraction.cs @@ -0,0 +1,21 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.API +{ + internal class MessageInteraction + { + [JsonProperty("id")] + public ulong Id { get; set; } + [JsonProperty("type")] + public InteractionType Type { get; set; } + [JsonProperty("name")] + public string Name { get; set; } + [JsonProperty("user")] + public User User { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/MessageReference.cs b/src/Discord.Net.Rest/API/Common/MessageReference.cs index 8c0f8fe14..6cc7603e0 100644 --- a/src/Discord.Net.Rest/API/Common/MessageReference.cs +++ b/src/Discord.Net.Rest/API/Common/MessageReference.cs @@ -8,7 +8,7 @@ namespace Discord.API public Optional MessageId { get; set; } [JsonProperty("channel_id")] - public ulong ChannelId { get; set; } + public Optional ChannelId { get; set; } // Optional when sending, always present when receiving [JsonProperty("guild_id")] public Optional GuildId { get; set; } diff --git a/src/Discord.Net.Rest/API/Common/NitroStickerPacks.cs b/src/Discord.Net.Rest/API/Common/NitroStickerPacks.cs new file mode 100644 index 000000000..cc2f0d963 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/NitroStickerPacks.cs @@ -0,0 +1,11 @@ +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace Discord.API +{ + internal class NitroStickerPacks + { + [JsonProperty("sticker_packs")] + public List StickerPacks { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/Overwrite.cs b/src/Discord.Net.Rest/API/Common/Overwrite.cs index 1f3548a1c..a1fb534d8 100644 --- a/src/Discord.Net.Rest/API/Common/Overwrite.cs +++ b/src/Discord.Net.Rest/API/Common/Overwrite.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API @@ -10,8 +9,8 @@ namespace Discord.API [JsonProperty("type")] public PermissionTarget TargetType { get; set; } [JsonProperty("deny"), Int53] - public ulong Deny { get; set; } + public string Deny { get; set; } [JsonProperty("allow"), Int53] - public ulong Allow { get; set; } + public string Allow { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/Presence.cs b/src/Discord.Net.Rest/API/Common/Presence.cs index 22526e8ac..23f871ae6 100644 --- a/src/Discord.Net.Rest/API/Common/Presence.cs +++ b/src/Discord.Net.Rest/API/Common/Presence.cs @@ -1,5 +1,5 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; +using System; using System.Collections.Generic; namespace Discord.API @@ -12,8 +12,6 @@ namespace Discord.API public Optional GuildId { get; set; } [JsonProperty("status")] public UserStatus Status { get; set; } - [JsonProperty("game")] - public Game Game { get; set; } [JsonProperty("roles")] public Optional Roles { get; set; } @@ -26,5 +24,9 @@ namespace Discord.API // "client_status": { "desktop": "dnd", "mobile": "dnd" } [JsonProperty("client_status")] public Optional> ClientStatus { get; set; } + [JsonProperty("activities")] + public List Activities { get; set; } + [JsonProperty("premium_since")] + public Optional PremiumSince { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/PropertyErrorDescription.cs b/src/Discord.Net.Rest/API/Common/PropertyErrorDescription.cs new file mode 100644 index 000000000..145288e5d --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/PropertyErrorDescription.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.API +{ + internal class ErrorDetails + { + [JsonProperty("name")] + public Optional Name { get; set; } + [JsonProperty("errors")] + public Error[] Errors { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/ReadState.cs b/src/Discord.Net.Rest/API/Common/ReadState.cs index 6ea6e4bd0..9a66880c6 100644 --- a/src/Discord.Net.Rest/API/Common/ReadState.cs +++ b/src/Discord.Net.Rest/API/Common/ReadState.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API diff --git a/src/Discord.Net.Rest/API/Common/Relationship.cs b/src/Discord.Net.Rest/API/Common/Relationship.cs index ecbb96f80..d17f766af 100644 --- a/src/Discord.Net.Rest/API/Common/Relationship.cs +++ b/src/Discord.Net.Rest/API/Common/Relationship.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API diff --git a/src/Discord.Net.Rest/API/Common/RelationshipType.cs b/src/Discord.Net.Rest/API/Common/RelationshipType.cs index 0ed99f396..776ba156b 100644 --- a/src/Discord.Net.Rest/API/Common/RelationshipType.cs +++ b/src/Discord.Net.Rest/API/Common/RelationshipType.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 namespace Discord.API { internal enum RelationshipType diff --git a/src/Discord.Net.Rest/API/Common/Role.cs b/src/Discord.Net.Rest/API/Common/Role.cs index 856a8695f..81f54ccc0 100644 --- a/src/Discord.Net.Rest/API/Common/Role.cs +++ b/src/Discord.Net.Rest/API/Common/Role.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API @@ -9,6 +8,10 @@ namespace Discord.API public ulong Id { get; set; } [JsonProperty("name")] public string Name { get; set; } + [JsonProperty("icon")] + public Optional Icon { get; set; } + [JsonProperty("unicode_emoji")] + public Optional Emoji { get; set; } [JsonProperty("color")] public uint Color { get; set; } [JsonProperty("hoist")] @@ -18,8 +21,10 @@ namespace Discord.API [JsonProperty("position")] public int Position { get; set; } [JsonProperty("permissions"), Int53] - public ulong Permissions { get; set; } + public string Permissions { get; set; } [JsonProperty("managed")] public bool Managed { get; set; } + [JsonProperty("tags")] + public Optional Tags { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/RoleTags.cs b/src/Discord.Net.Rest/API/Common/RoleTags.cs new file mode 100644 index 000000000..9ddd39a64 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/RoleTags.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class RoleTags + { + [JsonProperty("bot_id")] + public Optional BotId { get; set; } + [JsonProperty("integration_id")] + public Optional IntegrationId { get; set; } + [JsonProperty("premium_subscriber")] + public Optional IsPremiumSubscriber { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/SelectMenuComponent.cs b/src/Discord.Net.Rest/API/Common/SelectMenuComponent.cs new file mode 100644 index 000000000..0886a8fe9 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/SelectMenuComponent.cs @@ -0,0 +1,42 @@ +using Newtonsoft.Json; +using System.Linq; + +namespace Discord.API +{ + internal class SelectMenuComponent : IMessageComponent + { + [JsonProperty("type")] + public ComponentType Type { get; set; } + + [JsonProperty("custom_id")] + public string CustomId { get; set; } + + [JsonProperty("options")] + public SelectMenuOption[] Options { get; set; } + + [JsonProperty("placeholder")] + public Optional Placeholder { get; set; } + + [JsonProperty("min_values")] + public int MinValues { get; set; } + + [JsonProperty("max_values")] + public int MaxValues { get; set; } + + [JsonProperty("disabled")] + public bool Disabled { get; set; } + + public SelectMenuComponent() { } + + public SelectMenuComponent(Discord.SelectMenuComponent component) + { + Type = component.Type; + CustomId = component.CustomId; + Options = component.Options.Select(x => new SelectMenuOption(x)).ToArray(); + Placeholder = component.Placeholder; + MinValues = component.MinValues; + MaxValues = component.MaxValues; + Disabled = component.IsDisabled; + } + } +} diff --git a/src/Discord.Net.Rest/API/Common/SelectMenuOption.cs b/src/Discord.Net.Rest/API/Common/SelectMenuOption.cs new file mode 100644 index 000000000..d0a25a829 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/SelectMenuOption.cs @@ -0,0 +1,53 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class SelectMenuOption + { + [JsonProperty("label")] + public string Label { get; set; } + + [JsonProperty("value")] + public string Value { get; set; } + + [JsonProperty("description")] + public Optional Description { get; set; } + + [JsonProperty("emoji")] + public Optional Emoji { get; set; } + + [JsonProperty("default")] + public Optional Default { get; set; } + + public SelectMenuOption() { } + + public SelectMenuOption(Discord.SelectMenuOption option) + { + Label = option.Label; + Value = option.Value; + Description = option.Description; + + if (option.Emote != null) + { + if (option.Emote is Emote e) + { + Emoji = new Emoji + { + Name = e.Name, + Animated = e.Animated, + Id = e.Id + }; + } + else + { + Emoji = new Emoji + { + Name = option.Emote.Name + }; + } + } + + Default = option.IsDefault ?? Optional.Unspecified; + } + } +} diff --git a/src/Discord.Net.Rest/API/Common/SessionStartLimit.cs b/src/Discord.Net.Rest/API/Common/SessionStartLimit.cs new file mode 100644 index 000000000..29d5ddf85 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/SessionStartLimit.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Discord.API.Rest +{ + internal class SessionStartLimit + { + [JsonProperty("total")] + public int Total { get; set; } + [JsonProperty("remaining")] + public int Remaining { get; set; } + [JsonProperty("reset_after")] + public int ResetAfter { get; set; } + [JsonProperty("max_concurrency")] + public int MaxConcurrency { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/StageInstance.cs b/src/Discord.Net.Rest/API/Common/StageInstance.cs new file mode 100644 index 000000000..3ec623949 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/StageInstance.cs @@ -0,0 +1,25 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class StageInstance + { + [JsonProperty("id")] + public ulong Id { get; set; } + + [JsonProperty("guild_id")] + public ulong GuildId { get; set; } + + [JsonProperty("channel_id")] + public ulong ChannelId { get; set; } + + [JsonProperty("topic")] + public string Topic { get; set; } + + [JsonProperty("privacy_level")] + public StagePrivacyLevel PrivacyLevel { get; set; } + + [JsonProperty("discoverable_disabled")] + public bool DiscoverableDisabled { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/Sticker.cs b/src/Discord.Net.Rest/API/Common/Sticker.cs new file mode 100644 index 000000000..b2c58d57c --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/Sticker.cs @@ -0,0 +1,30 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class Sticker + { + [JsonProperty("id")] + public ulong Id { get; set; } + [JsonProperty("pack_id")] + public ulong PackId { get; set; } + [JsonProperty("name")] + public string Name { get; set; } + [JsonProperty("description")] + public string Description { get; set; } + [JsonProperty("tags")] + public Optional Tags { get; set; } + [JsonProperty("type")] + public StickerType Type { get; set; } + [JsonProperty("format_type")] + public StickerFormatType FormatType { get; set; } + [JsonProperty("available")] + public bool? Available { get; set; } + [JsonProperty("guild_id")] + public Optional GuildId { get; set; } + [JsonProperty("user")] + public Optional User { get; set; } + [JsonProperty("sort_value")] + public int? SortValue { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/StickerItem.cs b/src/Discord.Net.Rest/API/Common/StickerItem.cs new file mode 100644 index 000000000..4b24f711b --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/StickerItem.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class StickerItem + { + [JsonProperty("id")] + public ulong Id { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("format_type")] + public StickerFormatType FormatType { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/StickerPack.cs b/src/Discord.Net.Rest/API/Common/StickerPack.cs new file mode 100644 index 000000000..3daaac5bf --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/StickerPack.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class StickerPack + { + [JsonProperty("id")] + public ulong Id { get; set; } + [JsonProperty("stickers")] + public Sticker[] Stickers { get; set; } + [JsonProperty("name")] + public string Name { get; set; } + [JsonProperty("sku_id")] + public ulong SkuId { get; set; } + [JsonProperty("cover_sticker_id")] + public Optional CoverStickerId { get; set; } + [JsonProperty("description")] + public string Description { get; set; } + [JsonProperty("banner_asset_id")] + public ulong BannerAssetId { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/Team.cs b/src/Discord.Net.Rest/API/Common/Team.cs new file mode 100644 index 000000000..b421dc18c --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/Team.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class Team + { + [JsonProperty("icon")] + public Optional Icon { get; set; } + [JsonProperty("id")] + public ulong Id { get; set; } + [JsonProperty("members")] + public TeamMember[] TeamMembers { get; set; } + [JsonProperty("name")] + public string Name { get; set; } + [JsonProperty("owner_user_id")] + public ulong OwnerUserId { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/TeamMember.cs b/src/Discord.Net.Rest/API/Common/TeamMember.cs new file mode 100644 index 000000000..f3cba608e --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/TeamMember.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class TeamMember + { + [JsonProperty("membership_state")] + public MembershipState MembershipState { get; set; } + [JsonProperty("permissions")] + public string[] Permissions { get; set; } + [JsonProperty("team_id")] + public ulong TeamId { get; set; } + [JsonProperty("user")] + public User User { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/ThreadMember.cs b/src/Discord.Net.Rest/API/Common/ThreadMember.cs new file mode 100644 index 000000000..30249ee44 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/ThreadMember.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; +using System; + +namespace Discord.API +{ + internal class ThreadMember + { + [JsonProperty("id")] + public Optional Id { get; set; } + + [JsonProperty("user_id")] + public Optional UserId { get; set; } + + [JsonProperty("join_timestamp")] + public DateTimeOffset JoinTimestamp { get; set; } + + [JsonProperty("flags")] + public int Flags { get; set; } // No enum type (yet?) + } +} diff --git a/src/Discord.Net.Rest/API/Common/ThreadMetadata.cs b/src/Discord.Net.Rest/API/Common/ThreadMetadata.cs new file mode 100644 index 000000000..39e9bd13e --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/ThreadMetadata.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; +using System; + +namespace Discord.API +{ + internal class ThreadMetadata + { + [JsonProperty("archived")] + public bool Archived { get; set; } + + [JsonProperty("auto_archive_duration")] + public ThreadArchiveDuration AutoArchiveDuration { get; set; } + + [JsonProperty("archive_timestamp")] + public DateTimeOffset ArchiveTimestamp { get; set; } + + [JsonProperty("locked")] + public Optional Locked { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Common/User.cs b/src/Discord.Net.Rest/API/Common/User.cs index 2eff3753d..08fe88cb0 100644 --- a/src/Discord.Net.Rest/API/Common/User.cs +++ b/src/Discord.Net.Rest/API/Common/User.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API @@ -15,6 +14,10 @@ namespace Discord.API public Optional Bot { get; set; } [JsonProperty("avatar")] public Optional Avatar { get; set; } + [JsonProperty("banner")] + public Optional Banner { get; set; } + [JsonProperty("accent_color")] + public Optional AccentColor { get; set; } //CurrentUser [JsonProperty("verified")] @@ -29,5 +32,7 @@ namespace Discord.API public Optional PremiumType { get; set; } [JsonProperty("locale")] public Optional Locale { get; set; } + [JsonProperty("public_flags")] + public Optional PublicFlags { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/UserGuild.cs b/src/Discord.Net.Rest/API/Common/UserGuild.cs index f4f763885..fc1fe833d 100644 --- a/src/Discord.Net.Rest/API/Common/UserGuild.cs +++ b/src/Discord.Net.Rest/API/Common/UserGuild.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API @@ -14,6 +13,6 @@ namespace Discord.API [JsonProperty("owner")] public bool Owner { get; set; } [JsonProperty("permissions"), Int53] - public ulong Permissions { get; set; } + public string Permissions { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/VoiceRegion.cs b/src/Discord.Net.Rest/API/Common/VoiceRegion.cs index 606af07bd..3cc66a0ef 100644 --- a/src/Discord.Net.Rest/API/Common/VoiceRegion.cs +++ b/src/Discord.Net.Rest/API/Common/VoiceRegion.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API diff --git a/src/Discord.Net.Rest/API/Common/VoiceState.cs b/src/Discord.Net.Rest/API/Common/VoiceState.cs index c7a571ed0..f7cd54a72 100644 --- a/src/Discord.Net.Rest/API/Common/VoiceState.cs +++ b/src/Discord.Net.Rest/API/Common/VoiceState.cs @@ -1,5 +1,5 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; +using System; namespace Discord.API { @@ -28,5 +28,7 @@ namespace Discord.API public bool Suppress { get; set; } [JsonProperty("self_stream")] public bool SelfStream { get; set; } + [JsonProperty("request_to_speak_timestamp")] + public Optional RequestToSpeakTimestamp { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/Webhook.cs b/src/Discord.Net.Rest/API/Common/Webhook.cs index cbd5fdad5..23b682bd3 100644 --- a/src/Discord.Net.Rest/API/Common/Webhook.cs +++ b/src/Discord.Net.Rest/API/Common/Webhook.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API @@ -21,5 +20,7 @@ namespace Discord.API [JsonProperty("user")] public Optional Creator { get; set; } + [JsonProperty("application_id")] + public ulong? ApplicationId { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Int53Attribute.cs b/src/Discord.Net.Rest/API/Int53Attribute.cs index 70ef2f185..3a21b583d 100644 --- a/src/Discord.Net.Rest/API/Int53Attribute.cs +++ b/src/Discord.Net.Rest/API/Int53Attribute.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using System; namespace Discord.API diff --git a/src/Discord.Net.Rest/API/Net/IResolvable.cs b/src/Discord.Net.Rest/API/Net/IResolvable.cs new file mode 100644 index 000000000..7485f5de8 --- /dev/null +++ b/src/Discord.Net.Rest/API/Net/IResolvable.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.API +{ + internal interface IResolvable + { + Optional Resolved { get; } + } +} diff --git a/src/Discord.Net.Rest/API/Net/MultipartFile.cs b/src/Discord.Net.Rest/API/Net/MultipartFile.cs index 604852e90..d6bc4c7ab 100644 --- a/src/Discord.Net.Rest/API/Net/MultipartFile.cs +++ b/src/Discord.Net.Rest/API/Net/MultipartFile.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; namespace Discord.Net.Rest { @@ -6,11 +6,13 @@ namespace Discord.Net.Rest { public Stream Stream { get; } public string Filename { get; } + public string ContentType { get; } - public MultipartFile(Stream stream, string filename) + public MultipartFile(Stream stream, string filename, string contentType = null) { Stream = stream; Filename = filename; + ContentType = contentType; } } } diff --git a/src/Discord.Net.Rest/API/Rest/CreateApplicationCommandParams.cs b/src/Discord.Net.Rest/API/Rest/CreateApplicationCommandParams.cs new file mode 100644 index 000000000..82f0befcd --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/CreateApplicationCommandParams.cs @@ -0,0 +1,31 @@ +using Newtonsoft.Json; + +namespace Discord.API.Rest +{ + internal class CreateApplicationCommandParams + { + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("type")] + public ApplicationCommandType Type { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("options")] + public Optional Options { get; set; } + + [JsonProperty("default_permission")] + public Optional DefaultPermission { get; set; } + + public CreateApplicationCommandParams() { } + public CreateApplicationCommandParams(string name, string description, ApplicationCommandType type, ApplicationCommandOption[] options = null) + { + Name = name; + Description = description; + Options = Optional.Create(options); + Type = type; + } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/CreateChannelInviteParams.cs b/src/Discord.Net.Rest/API/Rest/CreateChannelInviteParams.cs index db79bc314..852abe301 100644 --- a/src/Discord.Net.Rest/API/Rest/CreateChannelInviteParams.cs +++ b/src/Discord.Net.Rest/API/Rest/CreateChannelInviteParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest @@ -14,5 +13,11 @@ namespace Discord.API.Rest public Optional IsTemporary { get; set; } [JsonProperty("unique")] public Optional IsUnique { get; set; } + [JsonProperty("target_type")] + public Optional TargetType { get; set; } + [JsonProperty("target_user_id")] + public Optional TargetUserId { get; set; } + [JsonProperty("target_application_id")] + public Optional TargetApplicationId { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Rest/CreateDMChannelParams.cs b/src/Discord.Net.Rest/API/Rest/CreateDMChannelParams.cs index f32796e02..0a710dd1b 100644 --- a/src/Discord.Net.Rest/API/Rest/CreateDMChannelParams.cs +++ b/src/Discord.Net.Rest/API/Rest/CreateDMChannelParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/CreateGuildBanParams.cs b/src/Discord.Net.Rest/API/Rest/CreateGuildBanParams.cs index f0432e517..fce9df11f 100644 --- a/src/Discord.Net.Rest/API/Rest/CreateGuildBanParams.cs +++ b/src/Discord.Net.Rest/API/Rest/CreateGuildBanParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 namespace Discord.API.Rest { internal class CreateGuildBanParams diff --git a/src/Discord.Net.Rest/API/Rest/CreateGuildChannelParams.cs b/src/Discord.Net.Rest/API/Rest/CreateGuildChannelParams.cs index a102bd38d..57816e448 100644 --- a/src/Discord.Net.Rest/API/Rest/CreateGuildChannelParams.cs +++ b/src/Discord.Net.Rest/API/Rest/CreateGuildChannelParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest @@ -14,12 +13,16 @@ namespace Discord.API.Rest public Optional CategoryId { get; set; } [JsonProperty("position")] public Optional Position { get; set; } + [JsonProperty("permission_overwrites")] + public Optional Overwrites { get; set; } //Text channels [JsonProperty("topic")] public Optional Topic { get; set; } [JsonProperty("nsfw")] public Optional IsNsfw { get; set; } + [JsonProperty("rate_limit_per_user")] + public Optional SlowModeInterval { get; set; } //Voice channels [JsonProperty("bitrate")] diff --git a/src/Discord.Net.Rest/API/Rest/CreateGuildEmoteParams.cs b/src/Discord.Net.Rest/API/Rest/CreateGuildEmoteParams.cs index 308199820..c81f62f4c 100644 --- a/src/Discord.Net.Rest/API/Rest/CreateGuildEmoteParams.cs +++ b/src/Discord.Net.Rest/API/Rest/CreateGuildEmoteParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/CreateGuildIntegrationParams.cs b/src/Discord.Net.Rest/API/Rest/CreateGuildIntegrationParams.cs index 1053a0ed3..7358e5201 100644 --- a/src/Discord.Net.Rest/API/Rest/CreateGuildIntegrationParams.cs +++ b/src/Discord.Net.Rest/API/Rest/CreateGuildIntegrationParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/CreateGuildParams.cs b/src/Discord.Net.Rest/API/Rest/CreateGuildParams.cs index cda6caedf..e89c2b119 100644 --- a/src/Discord.Net.Rest/API/Rest/CreateGuildParams.cs +++ b/src/Discord.Net.Rest/API/Rest/CreateGuildParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/CreateGuildScheduledEventParams.cs b/src/Discord.Net.Rest/API/Rest/CreateGuildScheduledEventParams.cs new file mode 100644 index 000000000..a207d3374 --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/CreateGuildScheduledEventParams.cs @@ -0,0 +1,29 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.API.Rest +{ + internal class CreateGuildScheduledEventParams + { + [JsonProperty("channel_id")] + public Optional ChannelId { get; set; } + [JsonProperty("entity_metadata")] + public Optional EntityMetadata { get; set; } + [JsonProperty("name")] + public string Name { get; set; } + [JsonProperty("privacy_level")] + public GuildScheduledEventPrivacyLevel PrivacyLevel { get; set; } + [JsonProperty("scheduled_start_time")] + public DateTimeOffset StartTime { get; set; } + [JsonProperty("scheduled_end_time")] + public Optional EndTime { get; set; } + [JsonProperty("description")] + public Optional Description { get; set; } + [JsonProperty("entity_type")] + public GuildScheduledEventType Type { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/CreateMessageParams.cs b/src/Discord.Net.Rest/API/Rest/CreateMessageParams.cs index 4b56658d6..5996c7e83 100644 --- a/src/Discord.Net.Rest/API/Rest/CreateMessageParams.cs +++ b/src/Discord.Net.Rest/API/Rest/CreateMessageParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest @@ -11,13 +10,25 @@ namespace Discord.API.Rest [JsonProperty("nonce")] public Optional Nonce { get; set; } + [JsonProperty("tts")] public Optional IsTTS { get; set; } - [JsonProperty("embed")] - public Optional Embed { get; set; } + + [JsonProperty("embeds")] + public Optional Embeds { get; set; } + [JsonProperty("allowed_mentions")] public Optional AllowedMentions { get; set; } + [JsonProperty("message_reference")] + public Optional MessageReference { get; set; } + + [JsonProperty("components")] + public Optional Components { get; set; } + + [JsonProperty("sticker_ids")] + public Optional Stickers { get; set; } + public CreateMessageParams(string content) { Content = content; diff --git a/src/Discord.Net.Rest/API/Rest/CreateStageInstanceParams.cs b/src/Discord.Net.Rest/API/Rest/CreateStageInstanceParams.cs new file mode 100644 index 000000000..a1d59bb51 --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/CreateStageInstanceParams.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Discord.API.Rest +{ + internal class CreateStageInstanceParams + { + [JsonProperty("channel_id")] + public ulong ChannelId { get; set; } + + [JsonProperty("topic")] + public string Topic { get; set; } + + [JsonProperty("privacy_level")] + public Optional PrivacyLevel { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/CreateStickerParams.cs b/src/Discord.Net.Rest/API/Rest/CreateStickerParams.cs new file mode 100644 index 000000000..b330a0111 --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/CreateStickerParams.cs @@ -0,0 +1,35 @@ +using Discord.Net.Rest; +using System.Collections.Generic; +using System.IO; +namespace Discord.API.Rest +{ + internal class CreateStickerParams + { + public Stream File { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public string Tags { get; set; } + public string FileName { get; set; } + + public IReadOnlyDictionary ToDictionary() + { + var d = new Dictionary + { + ["name"] = $"{Name}", + ["description"] = Description, + ["tags"] = Tags + }; + + string contentType = "image/png"; + + if (File is FileStream fileStream) + contentType = $"image/{Path.GetExtension(fileStream.Name)}"; + else if (FileName != null) + contentType = $"image/{Path.GetExtension(FileName)}"; + + d["file"] = new MultipartFile(File, FileName ?? "image", contentType.Replace(".", "")); + + return d; + } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/CreateWebhookMessageParams.cs b/src/Discord.Net.Rest/API/Rest/CreateWebhookMessageParams.cs index 970a30201..ef0e0dd1d 100644 --- a/src/Discord.Net.Rest/API/Rest/CreateWebhookMessageParams.cs +++ b/src/Discord.Net.Rest/API/Rest/CreateWebhookMessageParams.cs @@ -1,28 +1,84 @@ -#pragma warning disable CS1591 +using Discord.Net.Converters; +using Discord.Net.Rest; using Newtonsoft.Json; +using System.Collections.Generic; +using System.IO; +using System.Text; namespace Discord.API.Rest { [JsonObject(MemberSerialization = MemberSerialization.OptIn)] internal class CreateWebhookMessageParams { + private static JsonSerializer _serializer = new JsonSerializer { ContractResolver = new DiscordContractResolver() }; + [JsonProperty("content")] - public string Content { get; } + public Optional Content { get; set; } [JsonProperty("nonce")] public Optional Nonce { get; set; } + [JsonProperty("tts")] public Optional IsTTS { get; set; } + [JsonProperty("embeds")] public Optional Embeds { get; set; } + [JsonProperty("username")] public Optional Username { get; set; } + [JsonProperty("avatar_url")] public Optional AvatarUrl { get; set; } - public CreateWebhookMessageParams(string content) + [JsonProperty("allowed_mentions")] + public Optional AllowedMentions { get; set; } + + [JsonProperty("flags")] + public Optional Flags { get; set; } + + [JsonProperty("components")] + public Optional Components { get; set; } + + [JsonProperty("file")] + public Optional File { get; set; } + + public IReadOnlyDictionary ToDictionary() { - Content = content; + var d = new Dictionary(); + + if (File.IsSpecified) + { + d["file"] = File.Value; + } + + var payload = new Dictionary + { + ["content"] = Content + }; + + if (IsTTS.IsSpecified) + payload["tts"] = IsTTS.Value.ToString(); + if (Nonce.IsSpecified) + payload["nonce"] = Nonce.Value; + if (Username.IsSpecified) + payload["username"] = Username.Value; + if (AvatarUrl.IsSpecified) + payload["avatar_url"] = AvatarUrl.Value; + if (Embeds.IsSpecified) + payload["embeds"] = Embeds.Value; + if (AllowedMentions.IsSpecified) + payload["allowed_mentions"] = AllowedMentions.Value; + if (Components.IsSpecified) + payload["components"] = Components.Value; + + var json = new StringBuilder(); + using (var text = new StringWriter(json)) + using (var writer = new JsonTextWriter(text)) + _serializer.Serialize(writer, payload); + + d["payload_json"] = json.ToString(); + + return d; } } } diff --git a/src/Discord.Net.Rest/API/Rest/CreateWebhookParams.cs b/src/Discord.Net.Rest/API/Rest/CreateWebhookParams.cs index 0d1059fab..242f451cb 100644 --- a/src/Discord.Net.Rest/API/Rest/CreateWebhookParams.cs +++ b/src/Discord.Net.Rest/API/Rest/CreateWebhookParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/DeleteMessagesParams.cs b/src/Discord.Net.Rest/API/Rest/DeleteMessagesParams.cs index ca9d8c26e..ca6b78406 100644 --- a/src/Discord.Net.Rest/API/Rest/DeleteMessagesParams.cs +++ b/src/Discord.Net.Rest/API/Rest/DeleteMessagesParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/GetBotGatewayResponse.cs b/src/Discord.Net.Rest/API/Rest/GetBotGatewayResponse.cs index 111fcf3db..3f8318cd1 100644 --- a/src/Discord.Net.Rest/API/Rest/GetBotGatewayResponse.cs +++ b/src/Discord.Net.Rest/API/Rest/GetBotGatewayResponse.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest @@ -9,5 +8,7 @@ namespace Discord.API.Rest public string Url { get; set; } [JsonProperty("shards")] public int Shards { get; set; } + [JsonProperty("session_start_limit")] + public SessionStartLimit SessionStartLimit { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Rest/GetChannelMessagesParams.cs b/src/Discord.Net.Rest/API/Rest/GetChannelMessagesParams.cs index ea5327667..52dd84836 100644 --- a/src/Discord.Net.Rest/API/Rest/GetChannelMessagesParams.cs +++ b/src/Discord.Net.Rest/API/Rest/GetChannelMessagesParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 namespace Discord.API.Rest { internal class GetChannelMessagesParams diff --git a/src/Discord.Net.Rest/API/Rest/GetEventUsersParams.cs b/src/Discord.Net.Rest/API/Rest/GetEventUsersParams.cs new file mode 100644 index 000000000..db3ac666e --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/GetEventUsersParams.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.API.Rest +{ + internal class GetEventUsersParams + { + public Optional Limit { get; set; } + public Optional RelativeDirection { get; set; } + public Optional RelativeUserId { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/GetGatewayResponse.cs b/src/Discord.Net.Rest/API/Rest/GetGatewayResponse.cs index ce3630170..11207633d 100644 --- a/src/Discord.Net.Rest/API/Rest/GetGatewayResponse.cs +++ b/src/Discord.Net.Rest/API/Rest/GetGatewayResponse.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/GetGuildMembersParams.cs b/src/Discord.Net.Rest/API/Rest/GetGuildMembersParams.cs index 66023cb43..67d380035 100644 --- a/src/Discord.Net.Rest/API/Rest/GetGuildMembersParams.cs +++ b/src/Discord.Net.Rest/API/Rest/GetGuildMembersParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 namespace Discord.API.Rest { internal class GetGuildMembersParams diff --git a/src/Discord.Net.Rest/API/Rest/GetGuildPruneCountResponse.cs b/src/Discord.Net.Rest/API/Rest/GetGuildPruneCountResponse.cs index 4af85acfa..1e7fc8c7b 100644 --- a/src/Discord.Net.Rest/API/Rest/GetGuildPruneCountResponse.cs +++ b/src/Discord.Net.Rest/API/Rest/GetGuildPruneCountResponse.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/GetGuildSummariesParams.cs b/src/Discord.Net.Rest/API/Rest/GetGuildSummariesParams.cs index f770ef398..1d3f70f07 100644 --- a/src/Discord.Net.Rest/API/Rest/GetGuildSummariesParams.cs +++ b/src/Discord.Net.Rest/API/Rest/GetGuildSummariesParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 namespace Discord.API.Rest { internal class GetGuildSummariesParams diff --git a/src/Discord.Net.Rest/API/Rest/GuildPruneParams.cs b/src/Discord.Net.Rest/API/Rest/GuildPruneParams.cs index 6a98d3758..c6caa1eb1 100644 --- a/src/Discord.Net.Rest/API/Rest/GuildPruneParams.cs +++ b/src/Discord.Net.Rest/API/Rest/GuildPruneParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest @@ -9,9 +8,13 @@ namespace Discord.API.Rest [JsonProperty("days")] public int Days { get; } - public GuildPruneParams(int days) + [JsonProperty("include_roles")] + public ulong[] IncludeRoleIds { get; } + + public GuildPruneParams(int days, ulong[] includeRoleIds) { Days = days; + IncludeRoleIds = includeRoleIds; } } } diff --git a/src/Discord.Net.Rest/API/Rest/ModifyApplicationCommandParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyApplicationCommandParams.cs new file mode 100644 index 000000000..5891c2c28 --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/ModifyApplicationCommandParams.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace Discord.API.Rest +{ + internal class ModifyApplicationCommandParams + { + [JsonProperty("name")] + public Optional Name { get; set; } + + [JsonProperty("description")] + public Optional Description { get; set; } + + [JsonProperty("options")] + public Optional Options { get; set; } + + [JsonProperty("default_permission")] + public Optional DefaultPermission { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/ModifyChannelPermissionsParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyChannelPermissionsParams.cs index 0fe5f7e5a..acb81034a 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyChannelPermissionsParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyChannelPermissionsParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest @@ -7,13 +6,13 @@ namespace Discord.API.Rest internal class ModifyChannelPermissionsParams { [JsonProperty("type")] - public string Type { get; } + public int Type { get; } [JsonProperty("allow")] - public ulong Allow { get; } + public string Allow { get; } [JsonProperty("deny")] - public ulong Deny { get; } + public string Deny { get; } - public ModifyChannelPermissionsParams(string type, ulong allow, ulong deny) + public ModifyChannelPermissionsParams(int type, string allow, string deny) { Type = type; Allow = allow; diff --git a/src/Discord.Net.Rest/API/Rest/ModifyCurrentUserNickParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyCurrentUserNickParams.cs index ba44e34cf..c10f2e4ec 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyCurrentUserNickParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyCurrentUserNickParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/ModifyCurrentUserParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyCurrentUserParams.cs index 7ba27c3a5..e28deb32b 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyCurrentUserParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyCurrentUserParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildApplicationCommandPermissions.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildApplicationCommandPermissions.cs new file mode 100644 index 000000000..a557061f3 --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildApplicationCommandPermissions.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace Discord.API.Rest +{ + internal class ModifyGuildApplicationCommandPermissions + { + [JsonProperty("id")] + public ulong Id { get; set; } + + [JsonProperty("permissions")] + public ApplicationCommandPermissions[] Permissions { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildApplicationCommandPermissionsParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildApplicationCommandPermissionsParams.cs new file mode 100644 index 000000000..322875b8e --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildApplicationCommandPermissionsParams.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace Discord.API.Rest +{ + internal class ModifyGuildApplicationCommandPermissionsParams + { + [JsonProperty("permissions")] + public ApplicationCommandPermissions[] Permissions { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs index e5e8a4632..dfe9cd980 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelsParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelsParams.cs index f97fbda0b..91567be3d 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelsParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelsParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildEmbedParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildEmbedParams.cs index 487744c65..420bdbeaf 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildEmbedParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildEmbedParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildEmoteParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildEmoteParams.cs index a2295dd5d..08b196daa 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildEmoteParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildEmoteParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildIntegrationParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildIntegrationParams.cs index 0a1b4f9fa..cf869c838 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildIntegrationParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildIntegrationParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildMemberParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildMemberParams.cs index a381d6f8f..eb7c944d1 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildMemberParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildMemberParams.cs @@ -1,5 +1,5 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; +using System; namespace Discord.API.Rest { @@ -16,5 +16,7 @@ namespace Discord.API.Rest public Optional RoleIds { get; set; } [JsonProperty("channel_id")] public Optional ChannelId { get; set; } + [JsonProperty("communication_disabled_until")] + public Optional TimedOutUntil { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildParams.cs index cfb107bcd..c1a20cb83 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest @@ -36,5 +35,7 @@ namespace Discord.API.Rest public Optional SystemChannelFlags { get; set; } [JsonProperty("preferred_locale")] public string PreferredLocale { get; set; } + [JsonProperty("premium_progress_bar_enabled")] + public Optional IsBoostProgressBarEnabled { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs index 287e1cafe..8aa92d40d 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest @@ -9,11 +8,15 @@ namespace Discord.API.Rest [JsonProperty("name")] public Optional Name { get; set; } [JsonProperty("permissions")] - public Optional Permissions { get; set; } + public Optional Permissions { get; set; } [JsonProperty("color")] public Optional Color { get; set; } [JsonProperty("hoist")] public Optional Hoist { get; set; } + [JsonProperty("icon")] + public Optional Icon { get; set; } + [JsonProperty("unicode_emoji")] + public Optional Emoji { get; set; } [JsonProperty("mentionable")] public Optional Mentionable { get; set; } } diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildRolesParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildRolesParams.cs index 0e816a260..eeb724523 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildRolesParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildRolesParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildScheduledEventParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildScheduledEventParams.cs new file mode 100644 index 000000000..3d191a0b3 --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildScheduledEventParams.cs @@ -0,0 +1,31 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.API.Rest +{ + internal class ModifyGuildScheduledEventParams + { + [JsonProperty("channel_id")] + public Optional ChannelId { get; set; } + [JsonProperty("entity_metadata")] + public Optional EntityMetadata { get; set; } + [JsonProperty("name")] + public Optional Name { get; set; } + [JsonProperty("privacy_level")] + public Optional PrivacyLevel { get; set; } + [JsonProperty("scheduled_start_time")] + public Optional StartTime { get; set; } + [JsonProperty("scheduled_end_time")] + public Optional EndTime { get; set; } + [JsonProperty("description")] + public Optional Description { get; set; } + [JsonProperty("entity_type")] + public Optional Type { get; set; } + [JsonProperty("status")] + public Optional Status { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildWidgetParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildWidgetParams.cs new file mode 100644 index 000000000..2e5658d51 --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildWidgetParams.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace Discord.API.Rest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + internal class ModifyGuildWidgetParams + { + [JsonProperty("enabled")] + public Optional Enabled { get; set; } + [JsonProperty("channel")] + public Optional ChannelId { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/ModifyInteractionResponseParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyInteractionResponseParams.cs new file mode 100644 index 000000000..a2c7cbee6 --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/ModifyInteractionResponseParams.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; + +namespace Discord.API.Rest +{ + internal class ModifyInteractionResponseParams + { + [JsonProperty("content")] + public Optional Content { get; set; } + + [JsonProperty("embeds")] + public Optional Embeds { get; set; } + + [JsonProperty("allowed_mentions")] + public Optional AllowedMentions { get; set; } + + [JsonProperty("components")] + public Optional Components { get; set; } + + [JsonProperty("flags")] + public Optional Flags { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/ModifyMessageParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyMessageParams.cs index fdff4de15..3dba45a5b 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyMessageParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyMessageParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest @@ -8,7 +7,13 @@ namespace Discord.API.Rest { [JsonProperty("content")] public Optional Content { get; set; } - [JsonProperty("embed")] - public Optional Embed { get; set; } + [JsonProperty("embeds")] + public Optional Embeds { get; set; } + [JsonProperty("components")] + public Optional Components { get; set; } + [JsonProperty("flags")] + public Optional Flags { get; set; } + [JsonProperty("allowed_mentions")] + public Optional AllowedMentions { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Rest/ModifyStageInstanceParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyStageInstanceParams.cs new file mode 100644 index 000000000..c09d8f216 --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/ModifyStageInstanceParams.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace Discord.API.Rest +{ + internal class ModifyStageInstanceParams + { + [JsonProperty("topic")] + public Optional Topic { get; set; } + + [JsonProperty("privacy_level")] + public Optional PrivacyLevel { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/ModifyStickerParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyStickerParams.cs new file mode 100644 index 000000000..bd538c72e --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/ModifyStickerParams.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; + +namespace Discord.API.Rest +{ + internal class ModifyStickerParams + { + [JsonProperty("name")] + public Optional Name { get; set; } + [JsonProperty("description")] + public Optional Description { get; set; } + [JsonProperty("tags")] + public Optional Tags { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs index 94f149fc1..409d90c3f 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/ModifyThreadParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyThreadParams.cs new file mode 100644 index 000000000..8c9216c3f --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/ModifyThreadParams.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; + +namespace Discord.API.Rest +{ + internal class ModifyThreadParams + { + [JsonProperty("name")] + public Optional Name { get; set; } + + [JsonProperty("archived")] + public Optional Archived { get; set; } + + [JsonProperty("auto_archive_duration")] + public Optional AutoArchiveDuration { get; set; } + + [JsonProperty("locked")] + public Optional Locked { get; set; } + + [JsonProperty("rate_limit_per_user")] + public Optional Slowmode { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/ModifyVoiceChannelParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyVoiceChannelParams.cs index ce36eb11f..2f8cacc69 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyVoiceChannelParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyVoiceChannelParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest @@ -10,5 +9,7 @@ namespace Discord.API.Rest public Optional Bitrate { get; set; } [JsonProperty("user_limit")] public Optional UserLimit { get; set; } + [JsonProperty("rtc_region")] + public Optional RTCRegion { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Rest/ModifyVoiceStateParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyVoiceStateParams.cs new file mode 100644 index 000000000..1ff0f3e08 --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/ModifyVoiceStateParams.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; +using System; + +namespace Discord.API.Rest +{ + internal class ModifyVoiceStateParams + { + [JsonProperty("channel_id")] + public ulong ChannelId { get; set; } + + [JsonProperty("suppress")] + public Optional Suppressed { get; set; } + + [JsonProperty("request_to_speak_timestamp")] + public Optional RequestToSpeakTimestamp { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/ModifyWebhookMessageParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyWebhookMessageParams.cs new file mode 100644 index 000000000..e73efaf36 --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/ModifyWebhookMessageParams.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; + +namespace Discord.API.Rest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + internal class ModifyWebhookMessageParams + { + [JsonProperty("content")] + public Optional Content { get; set; } + [JsonProperty("embeds")] + public Optional Embeds { get; set; } + [JsonProperty("allowed_mentions")] + public Optional AllowedMentions { get; set; } + [JsonProperty("components")] + public Optional Components { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/ModifyWebhookParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyWebhookParams.cs index 0f2d6e33b..2e4e6a4c4 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyWebhookParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyWebhookParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Rest diff --git a/src/Discord.Net.Rest/API/Rest/SearchGuildMembersParams.cs b/src/Discord.Net.Rest/API/Rest/SearchGuildMembersParams.cs new file mode 100644 index 000000000..56b3595fa --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/SearchGuildMembersParams.cs @@ -0,0 +1,8 @@ +namespace Discord.API.Rest +{ + internal class SearchGuildMembersParams + { + public string Query { get; set; } + public Optional Limit { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/StartThreadParams.cs b/src/Discord.Net.Rest/API/Rest/StartThreadParams.cs new file mode 100644 index 000000000..a13161cd4 --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/StartThreadParams.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; + +namespace Discord.API.Rest +{ + internal class StartThreadParams + { + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("auto_archive_duration")] + public ThreadArchiveDuration Duration { get; set; } + + [JsonProperty("type")] + public ThreadType Type { get; set; } + + [JsonProperty("invitable")] + public Optional Invitable { get; set; } + + [JsonProperty("rate_limit_per_user")] + public Optional Ratelimit { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/SuppressEmbedParams.cs b/src/Discord.Net.Rest/API/Rest/SuppressEmbedParams.cs deleted file mode 100644 index 9139627b8..000000000 --- a/src/Discord.Net.Rest/API/Rest/SuppressEmbedParams.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Newtonsoft.Json; - -namespace Discord.API.Rest -{ - [JsonObject(MemberSerialization = MemberSerialization.OptIn)] - internal class SuppressEmbedParams - { - [JsonProperty("suppress")] - public bool Suppressed { get; set; } - } -} diff --git a/src/Discord.Net.Rest/API/Rest/UploadFileParams.cs b/src/Discord.Net.Rest/API/Rest/UploadFileParams.cs index 7ba21d012..6340c3e38 100644 --- a/src/Discord.Net.Rest/API/Rest/UploadFileParams.cs +++ b/src/Discord.Net.Rest/API/Rest/UploadFileParams.cs @@ -1,9 +1,9 @@ -#pragma warning disable CS1591 using Discord.Net.Converters; using Discord.Net.Rest; using Newtonsoft.Json; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; namespace Discord.API.Rest @@ -12,28 +12,27 @@ namespace Discord.API.Rest { private static JsonSerializer _serializer = new JsonSerializer { ContractResolver = new DiscordContractResolver() }; - public Stream File { get; } + public FileAttachment[] Files { get; } - public Optional Filename { get; set; } public Optional Content { get; set; } public Optional Nonce { get; set; } public Optional IsTTS { get; set; } - public Optional Embed { get; set; } - public bool IsSpoiler { get; set; } = false; + public Optional Embeds { get; set; } + public Optional AllowedMentions { get; set; } + public Optional MessageReference { get; set; } + public Optional MessageComponent { get; set; } + public Optional Flags { get; set; } + public Optional Stickers { get; set; } - public UploadFileParams(Stream file) + public UploadFileParams(params Discord.FileAttachment[] attachments) { - File = file; + Files = attachments; } public IReadOnlyDictionary ToDictionary() { var d = new Dictionary(); - var filename = Filename.GetValueOrDefault("unknown.dat"); - if (IsSpoiler && !filename.StartsWith(AttachmentExtensions.SpoilerPrefix)) - filename = filename.Insert(0, AttachmentExtensions.SpoilerPrefix); - d["file"] = new MultipartFile(File, filename); - + var payload = new Dictionary(); if (Content.IsSpecified) payload["content"] = Content.Value; @@ -41,10 +40,39 @@ namespace Discord.API.Rest payload["tts"] = IsTTS.Value.ToString(); if (Nonce.IsSpecified) payload["nonce"] = Nonce.Value; - if (Embed.IsSpecified) - payload["embed"] = Embed.Value; - if (IsSpoiler) - payload["hasSpoiler"] = IsSpoiler.ToString(); + if (Embeds.IsSpecified) + payload["embeds"] = Embeds.Value; + if (AllowedMentions.IsSpecified) + payload["allowed_mentions"] = AllowedMentions.Value; + if (MessageComponent.IsSpecified) + payload["components"] = MessageComponent.Value; + if (MessageReference.IsSpecified) + payload["message_reference"] = MessageReference.Value; + if (Stickers.IsSpecified) + payload["sticker_ids"] = Stickers.Value; + if (Flags.IsSpecified) + payload["flags"] = Flags; + + List attachments = new(); + + for(int n = 0; n != Files.Length; n++) + { + var attachment = Files[n]; + + var filename = attachment.FileName ?? "unknown.dat"; + if (attachment.IsSpoiler && !filename.StartsWith(AttachmentExtensions.SpoilerPrefix)) + filename = filename.Insert(0, AttachmentExtensions.SpoilerPrefix); + d[$"files[{n}]"] = new MultipartFile(attachment.Stream, filename); + + attachments.Add(new + { + id = (ulong)n, + filename = filename, + description = attachment.Description ?? Optional.Unspecified + }); + } + + payload["attachments"] = attachments; var json = new StringBuilder(); using (var text = new StringWriter(json)) diff --git a/src/Discord.Net.Rest/API/Rest/UploadInteractionFileParams.cs b/src/Discord.Net.Rest/API/Rest/UploadInteractionFileParams.cs new file mode 100644 index 000000000..f004dec82 --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/UploadInteractionFileParams.cs @@ -0,0 +1,99 @@ +using Discord.Net.Converters; +using Discord.Net.Rest; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.API.Rest +{ + internal class UploadInteractionFileParams + { + private static JsonSerializer _serializer = new JsonSerializer { ContractResolver = new DiscordContractResolver() }; + + public FileAttachment[] Files { get; } + + public InteractionResponseType Type { get; set; } + public Optional Content { get; set; } + public Optional IsTTS { get; set; } + public Optional Embeds { get; set; } + public Optional AllowedMentions { get; set; } + public Optional MessageComponents { get; set; } + public Optional Flags { get; set; } + + public bool HasData + => Content.IsSpecified || + IsTTS.IsSpecified || + Embeds.IsSpecified || + AllowedMentions.IsSpecified || + MessageComponents.IsSpecified || + Flags.IsSpecified || + Files.Any(); + + public UploadInteractionFileParams(params FileAttachment[] files) + { + Files = files; + } + + public IReadOnlyDictionary ToDictionary() + { + var d = new Dictionary(); + + + var payload = new Dictionary(); + payload["type"] = Type; + + var data = new Dictionary(); + if (Content.IsSpecified) + data["content"] = Content.Value; + if (IsTTS.IsSpecified) + data["tts"] = IsTTS.Value.ToString(); + if (MessageComponents.IsSpecified) + data["components"] = MessageComponents.Value; + if (Embeds.IsSpecified) + data["embeds"] = Embeds.Value; + if (AllowedMentions.IsSpecified) + data["allowed_mentions"] = AllowedMentions.Value; + if (Flags.IsSpecified) + data["flags"] = Flags.Value; + + List attachments = new(); + + for (int n = 0; n != Files.Length; n++) + { + var attachment = Files[n]; + + var filename = attachment.FileName ?? "unknown.dat"; + if (attachment.IsSpoiler && !filename.StartsWith(AttachmentExtensions.SpoilerPrefix)) + filename = filename.Insert(0, AttachmentExtensions.SpoilerPrefix); + d[$"files[{n}]"] = new MultipartFile(attachment.Stream, filename); + + attachments.Add(new + { + id = (ulong)n, + filename = filename, + description = attachment.Description ?? Optional.Unspecified + }); + } + + data["attachments"] = attachments; + + payload["data"] = data; + + + if (data.Any()) + { + var json = new StringBuilder(); + using (var text = new StringWriter(json)) + using (var writer = new JsonTextWriter(text)) + _serializer.Serialize(writer, payload); + d["payload_json"] = json.ToString(); + } + + return d; + } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/UploadWebhookFileParams.cs b/src/Discord.Net.Rest/API/Rest/UploadWebhookFileParams.cs index 26153c21b..1a25e4782 100644 --- a/src/Discord.Net.Rest/API/Rest/UploadWebhookFileParams.cs +++ b/src/Discord.Net.Rest/API/Rest/UploadWebhookFileParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using System.Collections.Generic; using System.IO; using System.Text; @@ -12,31 +11,26 @@ namespace Discord.API.Rest { private static JsonSerializer _serializer = new JsonSerializer { ContractResolver = new DiscordContractResolver() }; - public Stream File { get; } + public FileAttachment[] Files { get; } - public Optional Filename { get; set; } public Optional Content { get; set; } public Optional Nonce { get; set; } public Optional IsTTS { get; set; } public Optional Username { get; set; } public Optional AvatarUrl { get; set; } public Optional Embeds { get; set; } + public Optional AllowedMentions { get; set; } + public Optional MessageComponents { get; set; } + public Optional Flags { get; set; } - public bool IsSpoiler { get; set; } = false; - - public UploadWebhookFileParams(Stream file) + public UploadWebhookFileParams(params FileAttachment[] files) { - File = file; + Files = files; } public IReadOnlyDictionary ToDictionary() { var d = new Dictionary(); - var filename = Filename.GetValueOrDefault("unknown.dat"); - if (IsSpoiler && !filename.StartsWith(AttachmentExtensions.SpoilerPrefix)) - filename = filename.Insert(0, AttachmentExtensions.SpoilerPrefix); - - d["file"] = new MultipartFile(File, filename); var payload = new Dictionary(); if (Content.IsSpecified) @@ -49,8 +43,35 @@ namespace Discord.API.Rest payload["username"] = Username.Value; if (AvatarUrl.IsSpecified) payload["avatar_url"] = AvatarUrl.Value; + if (MessageComponents.IsSpecified) + payload["components"] = MessageComponents.Value; if (Embeds.IsSpecified) payload["embeds"] = Embeds.Value; + if (AllowedMentions.IsSpecified) + payload["allowed_mentions"] = AllowedMentions.Value; + if (Flags.IsSpecified) + payload["flags"] = Flags.Value; + + List attachments = new(); + + for (int n = 0; n != Files.Length; n++) + { + var attachment = Files[n]; + + var filename = attachment.FileName ?? "unknown.dat"; + if (attachment.IsSpoiler && !filename.StartsWith(AttachmentExtensions.SpoilerPrefix)) + filename = filename.Insert(0, AttachmentExtensions.SpoilerPrefix); + d[$"files[{n}]"] = new MultipartFile(attachment.Stream, filename); + + attachments.Add(new + { + id = (ulong)n, + filename = filename, + description = attachment.Description ?? Optional.Unspecified + }); + } + + payload["attachments"] = attachments; var json = new StringBuilder(); using (var text = new StringWriter(json)) diff --git a/src/Discord.Net.Rest/AssemblyInfo.cs b/src/Discord.Net.Rest/AssemblyInfo.cs index 5c9351d64..837fd1d04 100644 --- a/src/Discord.Net.Rest/AssemblyInfo.cs +++ b/src/Discord.Net.Rest/AssemblyInfo.cs @@ -6,6 +6,7 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Discord.Net.Commands")] [assembly: InternalsVisibleTo("Discord.Net.Tests")] [assembly: InternalsVisibleTo("Discord.Net.Tests.Unit")] +[assembly: InternalsVisibleTo("Discord.Net.Interactions")] [assembly: TypeForwardedTo(typeof(Discord.Embed))] [assembly: TypeForwardedTo(typeof(Discord.EmbedBuilder))] diff --git a/src/Discord.Net.Rest/BaseDiscordClient.cs b/src/Discord.Net.Rest/BaseDiscordClient.cs index 500b55e28..2bf08e3c7 100644 --- a/src/Discord.Net.Rest/BaseDiscordClient.cs +++ b/src/Discord.Net.Rest/BaseDiscordClient.cs @@ -10,6 +10,7 @@ namespace Discord.Rest { public abstract class BaseDiscordClient : IDiscordClient { + #region BaseDiscordClient public event Func Log { add { _logEvent.Add(value); } remove { _logEvent.Remove(value); } } internal readonly AsyncEvent> _logEvent = new AsyncEvent>(); @@ -34,6 +35,7 @@ namespace Discord.Rest public ISelfUser CurrentUser { get; protected set; } /// public TokenType TokenType => ApiClient.AuthTokenType; + internal bool UseInteractionSnowflakeDate { get; private set; } /// Creates a new REST-only Discord client. internal BaseDiscordClient(DiscordRestConfig config, API.DiscordRestApiClient client) @@ -46,12 +48,14 @@ namespace Discord.Rest _restLogger = LogManager.CreateLogger("Rest"); _isFirstLogin = config.DisplayInitialLog; - ApiClient.RequestQueue.RateLimitTriggered += async (id, info) => + UseInteractionSnowflakeDate = config.UseInteractionSnowflakeDate; + + ApiClient.RequestQueue.RateLimitTriggered += async (id, info, endpoint) => { if (info == null) - await _restLogger.VerboseAsync($"Preemptive Rate limit triggered: {id ?? "null"}").ConfigureAwait(false); + await _restLogger.VerboseAsync($"Preemptive Rate limit triggered: {endpoint} {(id.IsHashBucket ? $"(Bucket: {id.BucketHash})" : "")}").ConfigureAwait(false); else - await _restLogger.WarningAsync($"Rate limit triggered: {id ?? "null"}").ConfigureAwait(false); + await _restLogger.WarningAsync($"Rate limit triggered: {endpoint} {(id.IsHashBucket ? $"(Bucket: {id.BucketHash})" : "")}").ConfigureAwait(false); }; ApiClient.SentRequest += async (method, endpoint, millis) => await _restLogger.VerboseAsync($"{method} {endpoint}: {millis} ms").ConfigureAwait(false); } @@ -167,7 +171,12 @@ namespace Discord.Rest public Task GetRecommendedShardCountAsync(RequestOptions options = null) => ClientHelper.GetRecommendShardCountAsync(this, options); - //IDiscordClient + /// + public Task GetBotGatewayAsync(RequestOptions options = null) + => ClientHelper.GetBotGatewayAsync(this, options); + #endregion + + #region IDiscordClient /// ConnectionState IDiscordClient.ConnectionState => ConnectionState.Disconnected; /// @@ -227,11 +236,25 @@ namespace Discord.Rest Task IDiscordClient.GetWebhookAsync(ulong id, RequestOptions options) => Task.FromResult(null); + /// + Task IDiscordClient.GetGlobalApplicationCommandAsync(ulong id, RequestOptions options) + => Task.FromResult(null); + + /// + Task> IDiscordClient.GetGlobalApplicationCommandsAsync(RequestOptions options) + => Task.FromResult>(ImmutableArray.Create()); + Task IDiscordClient.CreateGlobalApplicationCommand(ApplicationCommandProperties properties, RequestOptions options) + => Task.FromResult(null); + Task> IDiscordClient.BulkOverwriteGlobalApplicationCommand(ApplicationCommandProperties[] properties, + RequestOptions options) + => Task.FromResult>(ImmutableArray.Create()); + /// Task IDiscordClient.StartAsync() => Task.Delay(0); /// Task IDiscordClient.StopAsync() => Task.Delay(0); + #endregion } } diff --git a/src/Discord.Net.Rest/ClientHelper.cs b/src/Discord.Net.Rest/ClientHelper.cs index a8f6b58ef..5debea27e 100644 --- a/src/Discord.Net.Rest/ClientHelper.cs +++ b/src/Discord.Net.Rest/ClientHelper.cs @@ -10,14 +10,14 @@ namespace Discord.Rest { internal static class ClientHelper { - //Applications + #region Applications public static async Task GetApplicationInfoAsync(BaseDiscordClient client, RequestOptions options) { var model = await client.ApiClient.GetMyApplicationAsync(options).ConfigureAwait(false); return RestApplication.Create(client, model); } - public static async Task GetChannelAsync(BaseDiscordClient client, + public static async Task GetChannelAsync(BaseDiscordClient client, ulong id, RequestOptions options) { var model = await client.ApiClient.GetChannelAsync(id, options).ConfigureAwait(false); @@ -45,13 +45,13 @@ namespace Discord.Rest .Where(x => x.Type == ChannelType.Group) .Select(x => RestGroupChannel.Create(client, x)).ToImmutableArray(); } - + public static async Task> GetConnectionsAsync(BaseDiscordClient client, RequestOptions options) { var models = await client.ApiClient.GetMyConnectionsAsync(options).ConfigureAwait(false); return models.Select(RestConnection.Create).ToImmutableArray(); } - + public static async Task GetInviteAsync(BaseDiscordClient client, string inviteId, RequestOptions options) { @@ -60,24 +60,24 @@ namespace Discord.Rest return RestInviteMetadata.Create(client, null, null, model); return null; } - + public static async Task GetGuildAsync(BaseDiscordClient client, - ulong id, RequestOptions options) + ulong id, bool withCounts, RequestOptions options) { - var model = await client.ApiClient.GetGuildAsync(id, options).ConfigureAwait(false); + var model = await client.ApiClient.GetGuildAsync(id, withCounts, options).ConfigureAwait(false); if (model != null) return RestGuild.Create(client, model); return null; } - public static async Task GetGuildEmbedAsync(BaseDiscordClient client, + public static async Task GetGuildWidgetAsync(BaseDiscordClient client, ulong id, RequestOptions options) { - var model = await client.ApiClient.GetGuildEmbedAsync(id, options).ConfigureAwait(false); + var model = await client.ApiClient.GetGuildWidgetAsync(id, options).ConfigureAwait(false); if (model != null) - return RestGuildEmbed.Create(model); + return RestGuildWidget.Create(model); return null; } - public static IAsyncEnumerable> GetGuildSummariesAsync(BaseDiscordClient client, + public static IAsyncEnumerable> GetGuildSummariesAsync(BaseDiscordClient client, ulong? fromGuildId, int? limit, RequestOptions options) { return new PagedAsyncEnumerable( @@ -106,13 +106,13 @@ namespace Discord.Rest count: limit ); } - public static async Task> GetGuildsAsync(BaseDiscordClient client, RequestOptions options) + public static async Task> GetGuildsAsync(BaseDiscordClient client, bool withCounts, RequestOptions options) { var summaryModels = await GetGuildSummariesAsync(client, null, null, options).FlattenAsync().ConfigureAwait(false); var guilds = ImmutableArray.CreateBuilder(); foreach (var summaryModel in summaryModels) { - var guildModel = await client.ApiClient.GetGuildAsync(summaryModel.Id).ConfigureAwait(false); + var guildModel = await client.ApiClient.GetGuildAsync(summaryModel.Id, withCounts).ConfigureAwait(false); if (guildModel != null) guilds.Add(RestGuild.Create(client, guildModel)); } @@ -128,7 +128,7 @@ namespace Discord.Rest var model = await client.ApiClient.CreateGuildAsync(args, options).ConfigureAwait(false); return RestGuild.Create(client, model); } - + public static async Task GetUserAsync(BaseDiscordClient client, ulong id, RequestOptions options) { @@ -140,7 +140,7 @@ namespace Discord.Rest public static async Task GetGuildUserAsync(BaseDiscordClient client, ulong guildId, ulong id, RequestOptions options) { - var guild = await GetGuildAsync(client, guildId, options).ConfigureAwait(false); + var guild = await GetGuildAsync(client, guildId, false, options).ConfigureAwait(false); if (guild == null) return null; @@ -176,5 +176,93 @@ namespace Discord.Rest var response = await client.ApiClient.GetBotGatewayAsync(options).ConfigureAwait(false); return response.Shards; } + + public static async Task GetBotGatewayAsync(BaseDiscordClient client, RequestOptions options) + { + var response = await client.ApiClient.GetBotGatewayAsync(options).ConfigureAwait(false); + return new BotGateway + { + Url = response.Url, + Shards = response.Shards, + SessionStartLimit = new SessionStartLimit + { + Total = response.SessionStartLimit.Total, + Remaining = response.SessionStartLimit.Remaining, + ResetAfter = response.SessionStartLimit.ResetAfter, + MaxConcurrency = response.SessionStartLimit.MaxConcurrency + } + }; + } + + public static async Task> GetGlobalApplicationCommandsAsync(BaseDiscordClient client, + RequestOptions options = null) + { + var response = await client.ApiClient.GetGlobalApplicationCommandsAsync(options).ConfigureAwait(false); + + if (!response.Any()) + return Array.Empty(); + + return response.Select(x => RestGlobalCommand.Create(client, x)).ToArray(); + } + public static async Task GetGlobalApplicationCommandAsync(BaseDiscordClient client, ulong id, + RequestOptions options = null) + { + var model = await client.ApiClient.GetGlobalApplicationCommandAsync(id, options); + + return model != null ? RestGlobalCommand.Create(client, model) : null; + } + + public static async Task> GetGuildApplicationCommandsAsync(BaseDiscordClient client, ulong guildId, + RequestOptions options = null) + { + var response = await client.ApiClient.GetGuildApplicationCommandsAsync(guildId, options).ConfigureAwait(false); + + if (!response.Any()) + return ImmutableArray.Create(); + + return response.Select(x => RestGuildCommand.Create(client, x, guildId)).ToImmutableArray(); + } + public static async Task GetGuildApplicationCommandAsync(BaseDiscordClient client, ulong id, ulong guildId, + RequestOptions options = null) + { + var model = await client.ApiClient.GetGuildApplicationCommandAsync(guildId, id, options); + + return model != null ? RestGuildCommand.Create(client, model, guildId) : null; + } + public static async Task CreateGuildApplicationCommandAsync(BaseDiscordClient client, ulong guildId, ApplicationCommandProperties properties, + RequestOptions options = null) + { + var model = await InteractionHelper.CreateGuildCommandAsync(client, guildId, properties, options); + + return RestGuildCommand.Create(client, model, guildId); + } + public static async Task CreateGlobalApplicationCommandAsync(BaseDiscordClient client, ApplicationCommandProperties properties, + RequestOptions options = null) + { + var model = await InteractionHelper.CreateGlobalCommandAsync(client, properties, options); + + return RestGlobalCommand.Create(client, model); + } + public static async Task> BulkOverwriteGlobalApplicationCommandAsync(BaseDiscordClient client, ApplicationCommandProperties[] properties, + RequestOptions options = null) + { + var models = await InteractionHelper.BulkOverwriteGlobalCommandsAsync(client, properties, options); + + return models.Select(x => RestGlobalCommand.Create(client, x)).ToImmutableArray(); + } + public static async Task> BulkOverwriteGuildApplicationCommandAsync(BaseDiscordClient client, ulong guildId, + ApplicationCommandProperties[] properties, RequestOptions options = null) + { + var models = await InteractionHelper.BulkOverwriteGuildCommandsAsync(client, guildId, properties, options); + + return models.Select(x => RestGuildCommand.Create(client, x, guildId)).ToImmutableArray(); + } + + public static Task AddRoleAsync(BaseDiscordClient client, ulong guildId, ulong userId, ulong roleId, RequestOptions options = null) + => client.ApiClient.AddRoleAsync(guildId, userId, roleId, options); + + public static Task RemoveRoleAsync(BaseDiscordClient client, ulong guildId, ulong userId, ulong roleId, RequestOptions options = null) + => client.ApiClient.RemoveRoleAsync(guildId, userId, roleId, options); + #endregion } } diff --git a/src/Discord.Net.Rest/Discord.Net.Rest.csproj b/src/Discord.Net.Rest/Discord.Net.Rest.csproj index b9592f18d..98692998f 100644 --- a/src/Discord.Net.Rest/Discord.Net.Rest.csproj +++ b/src/Discord.Net.Rest/Discord.Net.Rest.csproj @@ -1,11 +1,12 @@ + Discord.Net.Rest Discord.Rest A core Discord.Net library containing the REST client and models. - net461;netstandard2.0;netstandard2.1 - netstandard2.0;netstandard2.1 + net6.0;net5.0;net461;netstandard2.0;netstandard2.1 + net6.0;net5.0;netstandard2.0;netstandard2.1 diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index 3a3d87f00..c9a4d6c30 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -1,5 +1,4 @@ -#pragma warning disable CS1591 using Discord.API.Rest; using Discord.Net; using Discord.Net.Converters; @@ -24,7 +23,8 @@ namespace Discord.API { internal class DiscordRestApiClient : IDisposable, IAsyncDisposable { - private static readonly ConcurrentDictionary> _bucketIdGenerators = new ConcurrentDictionary>(); + #region DiscordRestApiClient + private static readonly ConcurrentDictionary> _bucketIdGenerators = new ConcurrentDictionary>(); public event Func SentRequest { add { _sentRequestEvent.Add(value); } remove { _sentRequestEvent.Remove(value); } } private readonly AsyncEvent> _sentRequestEvent = new AsyncEvent>(); @@ -45,21 +45,18 @@ namespace Discord.API internal string AuthToken { get; private set; } internal IRestClient RestClient { get; private set; } internal ulong? CurrentUserId { get; set; } - public RateLimitPrecision RateLimitPrecision { get; private set; } - internal bool UseSystemClock { get; set; } - + internal bool UseSystemClock { get; set; } internal JsonSerializer Serializer => _serializer; /// Unknown OAuth token type. public DiscordRestApiClient(RestClientProvider restClientProvider, string userAgent, RetryMode defaultRetryMode = RetryMode.AlwaysRetry, - JsonSerializer serializer = null, RateLimitPrecision rateLimitPrecision = RateLimitPrecision.Second, bool useSystemClock = true) + JsonSerializer serializer = null, bool useSystemClock = true) { _restClientProvider = restClientProvider; UserAgent = userAgent; DefaultRetryMode = defaultRetryMode; _serializer = serializer ?? new JsonSerializer { ContractResolver = new DiscordContractResolver() }; - RateLimitPrecision = rateLimitPrecision; - UseSystemClock = useSystemClock; + UseSystemClock = useSystemClock; RequestQueue = new RequestQueue(); _stateLock = new SemaphoreSlim(1, 1); @@ -75,22 +72,16 @@ namespace Discord.API RestClient.SetHeader("accept", "*/*"); RestClient.SetHeader("user-agent", UserAgent); RestClient.SetHeader("authorization", GetPrefixedToken(AuthTokenType, AuthToken)); - RestClient.SetHeader("X-RateLimit-Precision", RateLimitPrecision.ToString().ToLower()); } /// Unknown OAuth token type. internal static string GetPrefixedToken(TokenType tokenType, string token) { - switch (tokenType) + return tokenType switch { - case default(TokenType): - return token; - case TokenType.Bot: - return $"Bot {token}"; - case TokenType.Bearer: - return $"Bearer {token}"; - default: - throw new ArgumentException(message: "Unknown OAuth token type.", paramName: nameof(tokenType)); - } + TokenType.Bot => $"Bot {token}", + TokenType.Bearer => $"Bearer {token}", + _ => throw new ArgumentException(message: "Unknown OAuth token type.", paramName: nameof(tokenType)), + }; } internal virtual void Dispose(bool disposing) { @@ -154,7 +145,7 @@ namespace Discord.API RestClient.SetCancelToken(_loginCancelToken.Token); AuthTokenType = tokenType; - AuthToken = token; + AuthToken = token?.TrimEnd(); if (tokenType != TokenType.Webhook) RestClient.SetHeader("authorization", GetPrefixedToken(AuthTokenType, AuthToken)); @@ -197,15 +188,16 @@ namespace Discord.API internal virtual Task ConnectInternalAsync() => Task.Delay(0); internal virtual Task DisconnectInternalAsync(Exception ex = null) => Task.Delay(0); + #endregion - //Core + #region Core internal Task SendAsync(string method, Expression> endpointExpr, BucketIds ids, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null) - => SendAsync(method, GetEndpoint(endpointExpr), GetBucketId(ids, endpointExpr, funcName), clientBucket, options); + => SendAsync(method, GetEndpoint(endpointExpr), GetBucketId(method, ids, endpointExpr, funcName), clientBucket, options); public async Task SendAsync(string method, string endpoint, - string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) + BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) { - options = options ?? new RequestOptions(); + options ??= new RequestOptions(); options.HeaderOnly = true; options.BucketId = bucketId; @@ -215,11 +207,11 @@ namespace Discord.API internal Task SendJsonAsync(string method, Expression> endpointExpr, object payload, BucketIds ids, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null) - => SendJsonAsync(method, GetEndpoint(endpointExpr), payload, GetBucketId(ids, endpointExpr, funcName), clientBucket, options); + => SendJsonAsync(method, GetEndpoint(endpointExpr), payload, GetBucketId(method, ids, endpointExpr, funcName), clientBucket, options); public async Task SendJsonAsync(string method, string endpoint, object payload, - string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) + BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) { - options = options ?? new RequestOptions(); + options ??= new RequestOptions(); options.HeaderOnly = true; options.BucketId = bucketId; @@ -230,11 +222,11 @@ namespace Discord.API internal Task SendMultipartAsync(string method, Expression> endpointExpr, IReadOnlyDictionary multipartArgs, BucketIds ids, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null) - => SendMultipartAsync(method, GetEndpoint(endpointExpr), multipartArgs, GetBucketId(ids, endpointExpr, funcName), clientBucket, options); + => SendMultipartAsync(method, GetEndpoint(endpointExpr), multipartArgs, GetBucketId(method, ids, endpointExpr, funcName), clientBucket, options); public async Task SendMultipartAsync(string method, string endpoint, IReadOnlyDictionary multipartArgs, - string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) + BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) { - options = options ?? new RequestOptions(); + options ??= new RequestOptions(); options.HeaderOnly = true; options.BucketId = bucketId; @@ -244,11 +236,11 @@ namespace Discord.API internal Task SendAsync(string method, Expression> endpointExpr, BucketIds ids, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null) where TResponse : class - => SendAsync(method, GetEndpoint(endpointExpr), GetBucketId(ids, endpointExpr, funcName), clientBucket, options); + => SendAsync(method, GetEndpoint(endpointExpr), GetBucketId(method, ids, endpointExpr, funcName), clientBucket, options); public async Task SendAsync(string method, string endpoint, - string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) where TResponse : class + BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) where TResponse : class { - options = options ?? new RequestOptions(); + options ??= new RequestOptions(); options.BucketId = bucketId; var request = new RestRequest(RestClient, method, endpoint, options); @@ -257,25 +249,26 @@ namespace Discord.API internal Task SendJsonAsync(string method, Expression> endpointExpr, object payload, BucketIds ids, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null) where TResponse : class - => SendJsonAsync(method, GetEndpoint(endpointExpr), payload, GetBucketId(ids, endpointExpr, funcName), clientBucket, options); + => SendJsonAsync(method, GetEndpoint(endpointExpr), payload, GetBucketId(method, ids, endpointExpr, funcName), clientBucket, options); public async Task SendJsonAsync(string method, string endpoint, object payload, - string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) where TResponse : class + BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) where TResponse : class { - options = options ?? new RequestOptions(); + options ??= new RequestOptions(); options.BucketId = bucketId; string json = payload != null ? SerializeJson(payload) : null; + var request = new JsonRestRequest(RestClient, method, endpoint, json, options); return DeserializeJson(await SendInternalAsync(method, endpoint, request).ConfigureAwait(false)); } internal Task SendMultipartAsync(string method, Expression> endpointExpr, IReadOnlyDictionary multipartArgs, BucketIds ids, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null) - => SendMultipartAsync(method, GetEndpoint(endpointExpr), multipartArgs, GetBucketId(ids, endpointExpr, funcName), clientBucket, options); + => SendMultipartAsync(method, GetEndpoint(endpointExpr), multipartArgs, GetBucketId(method, ids, endpointExpr, funcName), clientBucket, options); public async Task SendMultipartAsync(string method, string endpoint, IReadOnlyDictionary multipartArgs, - string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) + BucketId bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) { - options = options ?? new RequestOptions(); + options ??= new RequestOptions(); options.BucketId = bucketId; var request = new MultipartRestRequest(RestClient, method, endpoint, multipartArgs, options); @@ -288,8 +281,8 @@ namespace Discord.API CheckState(); if (request.Options.RetryMode == null) request.Options.RetryMode = DefaultRetryMode; - if (request.Options.UseSystemClock == null) - request.Options.UseSystemClock = UseSystemClock; + if (request.Options.UseSystemClock == null) + request.Options.UseSystemClock = UseSystemClock; var stopwatch = Stopwatch.StartNew(); var responseStream = await RequestQueue.SendAsync(request).ConfigureAwait(false); @@ -300,15 +293,17 @@ namespace Discord.API return responseStream; } + #endregion - //Auth + #region Auth public async Task ValidateTokenAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); await SendAsync("GET", () => "auth/login", new BucketIds(), options: options).ConfigureAwait(false); } + #endregion - //Gateway + #region Gateway public async Task GetGatewayAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); @@ -319,8 +314,9 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); return await SendAsync("GET", () => "gateway/bot", new BucketIds(), options: options).ConfigureAwait(false); } + #endregion - //Channels + #region Channels public async Task GetChannelAsync(ulong channelId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -345,6 +341,7 @@ namespace Discord.API var model = await SendAsync("GET", () => $"channels/{channelId}", ids, options: options).ConfigureAwait(false); if (!model.GuildId.IsSpecified || model.GuildId.Value != guildId) return null; + return model; } catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } @@ -363,11 +360,16 @@ namespace Discord.API Preconditions.NotNull(args, nameof(args)); Preconditions.GreaterThan(args.Bitrate, 0, nameof(args.Bitrate)); Preconditions.NotNullOrWhitespace(args.Name, nameof(args.Name)); + Preconditions.AtMost(args.Name.Length, 100, nameof(args.Name)); + if (args.Topic.IsSpecified) + Preconditions.AtMost(args.Topic.Value.Length, 1024, nameof(args.Name)); + options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); return await SendJsonAsync("POST", () => $"guilds/{guildId}/channels", args, ids, options: options).ConfigureAwait(false); } + public async Task DeleteChannelAsync(ulong channelId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -391,18 +393,29 @@ namespace Discord.API Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); Preconditions.AtLeast(args.Position, 0, nameof(args.Position)); - Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); + Preconditions.NotNullOrWhitespace(args.Name, nameof(args.Name)); + + if(args.Name.IsSpecified) + Preconditions.AtMost(args.Name.Value.Length, 100, nameof(args.Name)); + options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); return await SendJsonAsync("PATCH", () => $"channels/{channelId}", args, ids, options: options).ConfigureAwait(false); } + public async Task ModifyGuildChannelAsync(ulong channelId, Rest.ModifyTextChannelParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); Preconditions.AtLeast(args.Position, 0, nameof(args.Position)); - Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); + Preconditions.NotNullOrWhitespace(args.Name, nameof(args.Name)); + + if(args.Name.IsSpecified) + Preconditions.AtMost(args.Name.Value.Length, 100, nameof(args.Name)); + if(args.Topic.IsSpecified) + Preconditions.AtMost(args.Topic.Value.Length, 1024, nameof(args.Name)); + Preconditions.AtLeast(args.SlowModeInterval, 0, nameof(args.SlowModeInterval)); Preconditions.AtMost(args.SlowModeInterval, 21600, nameof(args.SlowModeInterval)); options = RequestOptions.CreateOrClone(options); @@ -410,6 +423,7 @@ namespace Discord.API var ids = new BucketIds(channelId: channelId); return await SendJsonAsync("PATCH", () => $"channels/{channelId}", args, ids, options: options).ConfigureAwait(false); } + public async Task ModifyGuildChannelAsync(ulong channelId, Rest.ModifyVoiceChannelParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -417,12 +431,13 @@ namespace Discord.API Preconditions.AtLeast(args.Bitrate, 8000, nameof(args.Bitrate)); Preconditions.AtLeast(args.UserLimit, 0, nameof(args.UserLimit)); Preconditions.AtLeast(args.Position, 0, nameof(args.Position)); - Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); + Preconditions.NotNullOrWhitespace(args.Name, nameof(args.Name)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); return await SendJsonAsync("PATCH", () => $"channels/{channelId}", args, ids, options: options).ConfigureAwait(false); } + public async Task ModifyGuildChannelsAsync(ulong guildId, IEnumerable args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -443,6 +458,266 @@ namespace Discord.API break; } } + #endregion + + #region Threads + public async Task ModifyThreadAsync(ulong channelId, ModifyThreadParams args, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + + var bucket = new BucketIds(channelId: channelId); + + return await SendJsonAsync("PATCH", () => $"channels/{channelId}", args, bucket, options: options); + } + + public async Task StartThreadAsync(ulong channelId, ulong messageId, StartThreadParams args, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(messageId, 0, nameof(messageId)); + + options = RequestOptions.CreateOrClone(options); + + var bucket = new BucketIds(0, channelId); + + return await SendJsonAsync("POST", () => $"channels/{channelId}/messages/{messageId}/threads", args, bucket, options: options).ConfigureAwait(false); + } + + public async Task StartThreadAsync(ulong channelId, StartThreadParams args, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + + options = RequestOptions.CreateOrClone(options); + + var bucket = new BucketIds(channelId: channelId); + + return await SendJsonAsync("POST", () => $"channels/{channelId}/threads", args, bucket, options: options).ConfigureAwait(false); + } + + public async Task JoinThreadAsync(ulong channelId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + + options = RequestOptions.CreateOrClone(options); + + var bucket = new BucketIds(channelId: channelId); + + await SendAsync("PUT", () => $"channels/{channelId}/thread-members/@me", bucket, options: options).ConfigureAwait(false); + } + + public async Task AddThreadMemberAsync(ulong channelId, ulong userId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(userId, 0, nameof(channelId)); + + options = RequestOptions.CreateOrClone(options); + + var bucket = new BucketIds(channelId: channelId); + + await SendAsync("PUT", () => $"channels/{channelId}/thread-members/{userId}", bucket, options: options).ConfigureAwait(false); + } + + public async Task LeaveThreadAsync(ulong channelId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + + options = RequestOptions.CreateOrClone(options); + + var bucket = new BucketIds(channelId: channelId); + + await SendAsync("DELETE", () => $"channels/{channelId}/thread-members/@me", bucket, options: options).ConfigureAwait(false); + } + + public async Task RemoveThreadMemberAsync(ulong channelId, ulong userId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(userId, 0, nameof(channelId)); + + options = RequestOptions.CreateOrClone(options); + var bucket = new BucketIds(channelId: channelId); + + await SendAsync("DELETE", () => $"channels/{channelId}/thread-members/{userId}", bucket, options: options).ConfigureAwait(false); + } + + public async Task ListThreadMembersAsync(ulong channelId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + + options = RequestOptions.CreateOrClone(options); + + var bucket = new BucketIds(channelId: channelId); + + return await SendAsync("GET", () => $"channels/{channelId}/thread-members", bucket, options: options).ConfigureAwait(false); + } + + public async Task GetThreadMemberAsync(ulong channelId, ulong userId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(userId, 0, nameof(userId)); + + options = RequestOptions.CreateOrClone(options); + + var bucket = new BucketIds(channelId: channelId); + + return await SendAsync("GET", () => $"channels/{channelId}/thread-members/{userId}", bucket, options: options).ConfigureAwait(false); + } + + public async Task GetActiveThreadsAsync(ulong channelId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + + options = RequestOptions.CreateOrClone(options); + + var bucket = new BucketIds(channelId: channelId); + + return await SendAsync("GET", () => $"channels/{channelId}/threads/active", bucket, options: options); + } + + public async Task GetPublicArchivedThreadsAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + + options = RequestOptions.CreateOrClone(options); + + var bucket = new BucketIds(channelId: channelId); + + string query = ""; + + if (limit.HasValue) + { + query = $"?before={before.GetValueOrDefault(DateTimeOffset.UtcNow).ToString("O")}&limit={limit.Value}"; + } + else if (before.HasValue) + { + query = $"?before={before.Value.ToString("O")}"; + } + + return await SendAsync("GET", () => $"channels/{channelId}/threads/archived/public{query}", bucket, options: options); + } + + public async Task GetPrivateArchivedThreadsAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, + RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + + options = RequestOptions.CreateOrClone(options); + + var bucket = new BucketIds(channelId: channelId); + + string query = ""; + + if (limit.HasValue) + { + query = $"?before={before.GetValueOrDefault(DateTimeOffset.UtcNow).ToString("O")}&limit={limit.Value}"; + } + else if (before.HasValue) + { + query = $"?before={before.Value.ToString("O")}"; + } + + return await SendAsync("GET", () => $"channels/{channelId}/threads/archived/private{query}", bucket, options: options); + } + + public async Task GetJoinedPrivateArchivedThreadsAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, + RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + + options = RequestOptions.CreateOrClone(options); + + var bucket = new BucketIds(channelId: channelId); + + string query = ""; + + if (limit.HasValue) + { + query = $"?before={SnowflakeUtils.ToSnowflake(before.GetValueOrDefault(DateTimeOffset.UtcNow))}&limit={limit.Value}"; + } + else if (before.HasValue) + { + query = $"?before={before.Value.ToString("O")}"; + } + + return await SendAsync("GET", () => $"channels/{channelId}/users/@me/threads/archived/private{query}", bucket, options: options); + } + #endregion + + #region Stage + public async Task CreateStageInstanceAsync(CreateStageInstanceParams args, RequestOptions options = null) + { + options = RequestOptions.CreateOrClone(options); + + var bucket = new BucketIds(); + + return await SendJsonAsync("POST", () => $"stage-instances", args, bucket, options: options).ConfigureAwait(false); + } + + public async Task ModifyStageInstanceAsync(ulong channelId, ModifyStageInstanceParams args, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + + options = RequestOptions.CreateOrClone(options); + + var bucket = new BucketIds(channelId: channelId); + + return await SendJsonAsync("PATCH", () => $"stage-instances/{channelId}", args, bucket, options: options).ConfigureAwait(false); + } + + public async Task DeleteStageInstanceAsync(ulong channelId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + + options = RequestOptions.CreateOrClone(options); + + try + { + await SendAsync("DELETE", $"stage-instances/{channelId}", options: options).ConfigureAwait(false); + } + catch (HttpException httpEx) when (httpEx.HttpCode == HttpStatusCode.NotFound) { } + } + + public async Task GetStageInstanceAsync(ulong channelId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + + options = RequestOptions.CreateOrClone(options); + + var bucket = new BucketIds(channelId: channelId); + + try + { + return await SendAsync("POST", () => $"stage-instances/{channelId}", bucket, options: options).ConfigureAwait(false); + } + catch (HttpException httpEx) when (httpEx.HttpCode == HttpStatusCode.NotFound) + { + return null; + } + } + + public async Task ModifyMyVoiceState(ulong guildId, ModifyVoiceStateParams args, RequestOptions options = null) + { + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + + options = RequestOptions.CreateOrClone(options); + + var bucket = new BucketIds(); + + await SendJsonAsync("PATCH", () => $"guilds/{guildId}/voice-states/@me", args, bucket, options: options).ConfigureAwait(false); + } + + public async Task ModifyUserVoiceState(ulong guildId, ulong userId, ModifyVoiceStateParams args, RequestOptions options = null) + { + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + Preconditions.NotEqual(userId, 0, nameof(userId)); + + options = RequestOptions.CreateOrClone(options); + + var bucket = new BucketIds(); + + await SendJsonAsync("PATCH", () => $"guilds/{guildId}/voice-states/{userId}", args, bucket, options: options).ConfigureAwait(false); + } + #endregion + + #region Roles public async Task AddRoleAsync(ulong guildId, ulong userId, ulong roleId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -465,8 +740,9 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); await SendAsync("DELETE", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options).ConfigureAwait(false); } + #endregion - //Channel Messages + #region Channel Messages public async Task GetChannelMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -490,22 +766,12 @@ namespace Discord.API int limit = args.Limit.GetValueOrDefault(DiscordConfig.MaxMessagesPerBatch); ulong? relativeId = args.RelativeMessageId.IsSpecified ? args.RelativeMessageId.Value : (ulong?)null; - string relativeDir; - - switch (args.RelativeDirection.GetValueOrDefault(Direction.Before)) + var relativeDir = args.RelativeDirection.GetValueOrDefault(Direction.Before) switch { - case Direction.Before: - default: - relativeDir = "before"; - break; - case Direction.After: - relativeDir = "after"; - break; - case Direction.Around: - relativeDir = "around"; - break; - } - + Direction.After => "after", + Direction.Around => "around", + _ => "before", + }; var ids = new BucketIds(channelId: channelId); Expression> endpoint; if (relativeId != null) @@ -519,7 +785,7 @@ namespace Discord.API { Preconditions.NotNull(args, nameof(args)); Preconditions.NotEqual(channelId, 0, nameof(channelId)); - if (!args.Embed.IsSpecified || args.Embed.Value == null) + if ((!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) && (!args.Stickers.IsSpecified || args.Stickers.Value == null || args.Stickers.Value.Length == 0)) Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content)); if (args.Content?.Length > DiscordConfig.MaxMessageSize) @@ -541,12 +807,51 @@ namespace Discord.API if (!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content)); - if (args.Content?.Length > DiscordConfig.MaxMessageSize) + if (args.Content.IsSpecified && args.Content.Value?.Length > DiscordConfig.MaxMessageSize) + throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); + + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(webhookId: webhookId); + return await SendJsonAsync("POST", () => $"webhooks/{webhookId}/{AuthToken}?wait=true", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + } + + /// Message content is too long, length must be less or equal to . + /// This operation may only be called with a token. + public async Task ModifyWebhookMessageAsync(ulong webhookId, ulong messageId, ModifyWebhookMessageParams args, RequestOptions options = null) + { + if (AuthTokenType != TokenType.Webhook) + throw new InvalidOperationException($"This operation may only be called with a {nameof(TokenType.Webhook)} token."); + + Preconditions.NotNull(args, nameof(args)); + Preconditions.NotEqual(webhookId, 0, nameof(webhookId)); + Preconditions.NotEqual(messageId, 0, nameof(messageId)); + + if (args.Embeds.IsSpecified) + Preconditions.AtMost(args.Embeds.Value.Length, 10, nameof(args.Embeds), "A max of 10 Embeds are allowed."); + if (args.Content.IsSpecified && args.Content.Value.Length > DiscordConfig.MaxMessageSize) throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); options = RequestOptions.CreateOrClone(options); - return await SendJsonAsync("POST", () => $"webhooks/{webhookId}/{AuthToken}?wait=true", args, new BucketIds(), clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + var ids = new BucketIds(webhookId: webhookId); + await SendJsonAsync("PATCH", () => $"webhooks/{webhookId}/{AuthToken}/messages/{messageId}", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + } + + /// This operation may only be called with a token. + public async Task DeleteWebhookMessageAsync(ulong webhookId, ulong messageId, RequestOptions options = null) + { + if (AuthTokenType != TokenType.Webhook) + throw new InvalidOperationException($"This operation may only be called with a {nameof(TokenType.Webhook)} token."); + + Preconditions.NotEqual(webhookId, 0, nameof(webhookId)); + Preconditions.NotEqual(messageId, 0, nameof(messageId)); + + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(webhookId: webhookId); + await SendAsync("DELETE", () => $"webhooks/{webhookId}/{AuthToken}/messages/{messageId}", ids, options: options).ConfigureAwait(false); } + /// Message content is too long, length must be less or equal to . public async Task UploadFileAsync(ulong channelId, UploadFileParams args, RequestOptions options = null) { @@ -584,7 +889,8 @@ namespace Discord.API throw new ArgumentOutOfRangeException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content)); } - return await SendMultipartAsync("POST", () => $"webhooks/{webhookId}/{AuthToken}?wait=true", args.ToDictionary(), new BucketIds(), clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + var ids = new BucketIds(webhookId: webhookId); + return await SendMultipartAsync("POST", () => $"webhooks/{webhookId}/{AuthToken}?wait=true", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); } public async Task DeleteMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) { @@ -627,178 +933,535 @@ namespace Discord.API throw new ArgumentOutOfRangeException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content)); options = RequestOptions.CreateOrClone(options); - var ids = new BucketIds(channelId: channelId); - return await SendJsonAsync("PATCH", () => $"channels/{channelId}/messages/{messageId}", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + var ids = new BucketIds(channelId: channelId); + return await SendJsonAsync("PATCH", () => $"channels/{channelId}/messages/{messageId}", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + } + + public async Task ModifyMessageAsync(ulong channelId, ulong messageId, Rest.UploadFileParams args, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(messageId, 0, nameof(messageId)); + Preconditions.NotNull(args, nameof(args)); + if (args.Content.IsSpecified && args.Content.Value?.Length > DiscordConfig.MaxMessageSize) + throw new ArgumentOutOfRangeException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content)); + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(channelId: channelId); + return await SendMultipartAsync("PATCH", () => $"channels/{channelId}/messages/{messageId}", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + } + #endregion + + #region Stickers, Reactions, Crosspost, and Acks + public async Task GetStickerAsync(ulong id, RequestOptions options = null) + { + Preconditions.NotEqual(id, 0, nameof(id)); + + options = RequestOptions.CreateOrClone(options); + + return await NullifyNotFound(SendAsync("GET", () => $"stickers/{id}", new BucketIds(), options: options)).ConfigureAwait(false); + } + public async Task GetGuildStickerAsync(ulong guildId, ulong id, RequestOptions options = null) + { + Preconditions.NotEqual(id, 0, nameof(id)); + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + + options = RequestOptions.CreateOrClone(options); + + return await NullifyNotFound(SendAsync("GET", () => $"guilds/{guildId}/stickers/{id}", new BucketIds(guildId), options: options)).ConfigureAwait(false); + } + public async Task ListGuildStickersAsync(ulong guildId, RequestOptions options = null) + { + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + + options = RequestOptions.CreateOrClone(options); + + return await SendAsync("GET", () => $"guilds/{guildId}/stickers", new BucketIds(guildId), options: options).ConfigureAwait(false); + } + public async Task ListNitroStickerPacksAsync(RequestOptions options = null) + { + options = RequestOptions.CreateOrClone(options); + + return await SendAsync("GET", () => $"sticker-packs", new BucketIds(), options: options).ConfigureAwait(false); + } + public async Task CreateGuildStickerAsync(CreateStickerParams args, ulong guildId, RequestOptions options = null) + { + Preconditions.NotNull(args, nameof(args)); + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + + options = RequestOptions.CreateOrClone(options); + + return await SendMultipartAsync("POST", () => $"guilds/{guildId}/stickers", args.ToDictionary(), new BucketIds(guildId), options: options).ConfigureAwait(false); + } + public async Task ModifyStickerAsync(ModifyStickerParams args, ulong guildId, ulong stickerId, RequestOptions options = null) + { + Preconditions.NotNull(args, nameof(args)); + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + Preconditions.NotEqual(stickerId, 0, nameof(stickerId)); + + options = RequestOptions.CreateOrClone(options); + + return await SendJsonAsync("PATCH", () => $"guilds/{guildId}/stickers/{stickerId}", args, new BucketIds(guildId), options: options).ConfigureAwait(false); + } + public async Task DeleteStickerAsync(ulong guildId, ulong stickerId, RequestOptions options = null) + { + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + Preconditions.NotEqual(stickerId, 0, nameof(stickerId)); + + options = RequestOptions.CreateOrClone(options); + + await SendAsync("DELETE", () => $"guilds/{guildId}/stickers/{stickerId}", new BucketIds(guildId), options: options).ConfigureAwait(false); + } + + public async Task AddReactionAsync(ulong channelId, ulong messageId, string emoji, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(messageId, 0, nameof(messageId)); + Preconditions.NotNullOrWhitespace(emoji, nameof(emoji)); + + options = RequestOptions.CreateOrClone(options); + options.IsReactionBucket = true; + + var ids = new BucketIds(channelId: channelId); + + // @me is non-const to fool the ratelimiter, otherwise it will put add/remove in separate buckets + var me = "@me"; + await SendAsync("PUT", () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/{me}", ids, options: options).ConfigureAwait(false); + } + public async Task RemoveReactionAsync(ulong channelId, ulong messageId, ulong userId, string emoji, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(messageId, 0, nameof(messageId)); + Preconditions.NotNullOrWhitespace(emoji, nameof(emoji)); + + options = RequestOptions.CreateOrClone(options); + options.IsReactionBucket = true; + + var ids = new BucketIds(channelId: channelId); + + var user = CurrentUserId.HasValue ? (userId == CurrentUserId.Value ? "@me" : userId.ToString()) : userId.ToString(); + await SendAsync("DELETE", () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/{user}", ids, options: options).ConfigureAwait(false); + } + public async Task RemoveAllReactionsAsync(ulong channelId, ulong messageId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(messageId, 0, nameof(messageId)); + + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(channelId: channelId); + + await SendAsync("DELETE", () => $"channels/{channelId}/messages/{messageId}/reactions", ids, options: options).ConfigureAwait(false); + } + public async Task RemoveAllReactionsForEmoteAsync(ulong channelId, ulong messageId, string emoji, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(messageId, 0, nameof(messageId)); + Preconditions.NotNullOrWhitespace(emoji, nameof(emoji)); + + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(channelId: channelId); + + await SendAsync("DELETE", () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}", ids, options: options).ConfigureAwait(false); + } + public async Task> GetReactionUsersAsync(ulong channelId, ulong messageId, string emoji, GetReactionUsersParams args, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(messageId, 0, nameof(messageId)); + Preconditions.NotNullOrWhitespace(emoji, nameof(emoji)); + Preconditions.NotNull(args, nameof(args)); + Preconditions.GreaterThan(args.Limit, 0, nameof(args.Limit)); + Preconditions.AtMost(args.Limit, DiscordConfig.MaxUserReactionsPerBatch, nameof(args.Limit)); + Preconditions.GreaterThan(args.AfterUserId, 0, nameof(args.AfterUserId)); + options = RequestOptions.CreateOrClone(options); + + int limit = args.Limit.GetValueOrDefault(DiscordConfig.MaxUserReactionsPerBatch); + ulong afterUserId = args.AfterUserId.GetValueOrDefault(0); + + var ids = new BucketIds(channelId: channelId); + Expression> endpoint = () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}?limit={limit}&after={afterUserId}"; + return await SendAsync>("GET", endpoint, ids, options: options).ConfigureAwait(false); + } + public async Task AckMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(messageId, 0, nameof(messageId)); + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(channelId: channelId); + await SendAsync("POST", () => $"channels/{channelId}/messages/{messageId}/ack", ids, options: options).ConfigureAwait(false); + } + public async Task TriggerTypingIndicatorAsync(ulong channelId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(channelId: channelId); + await SendAsync("POST", () => $"channels/{channelId}/typing", ids, options: options).ConfigureAwait(false); + } + public async Task CrosspostAsync(ulong channelId, ulong messageId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(messageId, 0, nameof(messageId)); + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(channelId: channelId); + await SendAsync("POST", () => $"channels/{channelId}/messages/{messageId}/crosspost", ids, options: options).ConfigureAwait(false); + } + #endregion + + #region Channel Permissions + public async Task ModifyChannelPermissionsAsync(ulong channelId, ulong targetId, ModifyChannelPermissionsParams args, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(targetId, 0, nameof(targetId)); + Preconditions.NotNull(args, nameof(args)); + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(channelId: channelId); + await SendJsonAsync("PUT", () => $"channels/{channelId}/permissions/{targetId}", args, ids, options: options).ConfigureAwait(false); + } + public async Task DeleteChannelPermissionAsync(ulong channelId, ulong targetId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(targetId, 0, nameof(targetId)); + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(channelId: channelId); + await SendAsync("DELETE", () => $"channels/{channelId}/permissions/{targetId}", ids, options: options).ConfigureAwait(false); + } + #endregion + + #region Channel Pins + public async Task AddPinAsync(ulong channelId, ulong messageId, RequestOptions options = null) + { + Preconditions.GreaterThan(channelId, 0, nameof(channelId)); + Preconditions.GreaterThan(messageId, 0, nameof(messageId)); + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(channelId: channelId); + await SendAsync("PUT", () => $"channels/{channelId}/pins/{messageId}", ids, options: options).ConfigureAwait(false); + + } + public async Task RemovePinAsync(ulong channelId, ulong messageId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(messageId, 0, nameof(messageId)); + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(channelId: channelId); + await SendAsync("DELETE", () => $"channels/{channelId}/pins/{messageId}", ids, options: options).ConfigureAwait(false); + } + public async Task> GetPinsAsync(ulong channelId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(channelId: channelId); + return await SendAsync>("GET", () => $"channels/{channelId}/pins", ids, options: options).ConfigureAwait(false); + } + #endregion + + #region Channel Recipients + public async Task AddGroupRecipientAsync(ulong channelId, ulong userId, RequestOptions options = null) + { + Preconditions.GreaterThan(channelId, 0, nameof(channelId)); + Preconditions.GreaterThan(userId, 0, nameof(userId)); + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(channelId: channelId); + await SendAsync("PUT", () => $"channels/{channelId}/recipients/{userId}", ids, options: options).ConfigureAwait(false); + + } + public async Task RemoveGroupRecipientAsync(ulong channelId, ulong userId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(userId, 0, nameof(userId)); + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(channelId: channelId); + await SendAsync("DELETE", () => $"channels/{channelId}/recipients/{userId}", ids, options: options).ConfigureAwait(false); + } + #endregion + + #region Interactions + public async Task GetGlobalApplicationCommandsAsync(RequestOptions options = null) + { + options = RequestOptions.CreateOrClone(options); + + return await SendAsync("GET", () => $"applications/{CurrentUserId}/commands", new BucketIds(), options: options).ConfigureAwait(false); + } + + public async Task GetGlobalApplicationCommandAsync(ulong id, RequestOptions options = null) + { + Preconditions.NotEqual(id, 0, nameof(id)); + + options = RequestOptions.CreateOrClone(options); + + try + { + return await SendAsync("GET", () => $"applications/{CurrentUserId}/commands/{id}", new BucketIds(), options: options).ConfigureAwait(false); + } + catch (HttpException x) when (x.HttpCode == HttpStatusCode.NotFound) { return null; } + } + + public async Task CreateGlobalApplicationCommandAsync(CreateApplicationCommandParams command, RequestOptions options = null) + { + Preconditions.NotNull(command, nameof(command)); + Preconditions.AtMost(command.Name.Length, 32, nameof(command.Name)); + Preconditions.AtLeast(command.Name.Length, 1, nameof(command.Name)); + + if (command.Type == ApplicationCommandType.Slash) + { + Preconditions.NotNullOrEmpty(command.Description, nameof(command.Description)); + Preconditions.AtMost(command.Description.Length, 100, nameof(command.Description)); + Preconditions.AtLeast(command.Description.Length, 1, nameof(command.Description)); + } + + options = RequestOptions.CreateOrClone(options); + + return await SendJsonAsync("POST", () => $"applications/{CurrentUserId}/commands", command, new BucketIds(), options: options).ConfigureAwait(false); + } + public async Task ModifyGlobalApplicationCommandAsync(ModifyApplicationCommandParams command, ulong commandId, RequestOptions options = null) + { + options = RequestOptions.CreateOrClone(options); + + return await SendJsonAsync("PATCH", () => $"applications/{CurrentUserId}/commands/{commandId}", command, new BucketIds(), options: options).ConfigureAwait(false); + } + public async Task ModifyGlobalApplicationUserCommandAsync(ModifyApplicationCommandParams command, ulong commandId, RequestOptions options = null) + { + options = RequestOptions.CreateOrClone(options); + + return await SendJsonAsync("PATCH", () => $"applications/{CurrentUserId}/commands/{commandId}", command, new BucketIds(), options: options).ConfigureAwait(false); + } + public async Task ModifyGlobalApplicationMessageCommandAsync(ModifyApplicationCommandParams command, ulong commandId, RequestOptions options = null) + { + options = RequestOptions.CreateOrClone(options); + + return await SendJsonAsync("PATCH", () => $"applications/{CurrentUserId}/commands/{commandId}", command, new BucketIds(), options: options).ConfigureAwait(false); + } + public async Task DeleteGlobalApplicationCommandAsync(ulong commandId, RequestOptions options = null) + { + options = RequestOptions.CreateOrClone(options); + + await SendAsync("DELETE", () => $"applications/{CurrentUserId}/commands/{commandId}", new BucketIds(), options: options).ConfigureAwait(false); + } + + public async Task BulkOverwriteGlobalApplicationCommandsAsync(CreateApplicationCommandParams[] commands, RequestOptions options = null) + { + options = RequestOptions.CreateOrClone(options); + + return await SendJsonAsync("PUT", () => $"applications/{CurrentUserId}/commands", commands, new BucketIds(), options: options).ConfigureAwait(false); + } + + public async Task GetGuildApplicationCommandsAsync(ulong guildId, RequestOptions options = null) + { + options = RequestOptions.CreateOrClone(options); + + var bucket = new BucketIds(guildId: guildId); + + return await SendAsync("GET", () => $"applications/{CurrentUserId}/guilds/{guildId}/commands", bucket, options: options).ConfigureAwait(false); } - public async Task SuppressEmbedAsync(ulong channelId, ulong messageId, Rest.SuppressEmbedParams args, RequestOptions options = null) + public async Task GetGuildApplicationCommandAsync(ulong guildId, ulong commandId, RequestOptions options = null) { - Preconditions.NotEqual(channelId, 0, nameof(channelId)); - Preconditions.NotEqual(messageId, 0, nameof(messageId)); options = RequestOptions.CreateOrClone(options); - var ids = new BucketIds(channelId: channelId); - await SendJsonAsync("POST", () => $"channels/{channelId}/messages/{messageId}/suppress-embeds", args, ids, options: options).ConfigureAwait(false); + var bucket = new BucketIds(guildId: guildId); + + try + { + return await SendAsync("GET", () => $"applications/{CurrentUserId}/guilds/{guildId}/commands/{commandId}", bucket, options: options); + } + catch (HttpException x) when (x.HttpCode == HttpStatusCode.NotFound) { return null; } } - public async Task AddReactionAsync(ulong channelId, ulong messageId, string emoji, RequestOptions options = null) + public async Task CreateGuildApplicationCommandAsync(CreateApplicationCommandParams command, ulong guildId, RequestOptions options = null) { - Preconditions.NotEqual(channelId, 0, nameof(channelId)); - Preconditions.NotEqual(messageId, 0, nameof(messageId)); - Preconditions.NotNullOrWhitespace(emoji, nameof(emoji)); + Preconditions.NotNull(command, nameof(command)); + Preconditions.AtMost(command.Name.Length, 32, nameof(command.Name)); + Preconditions.AtLeast(command.Name.Length, 1, nameof(command.Name)); + + if (command.Type == ApplicationCommandType.Slash) + { + Preconditions.NotNullOrEmpty(command.Description, nameof(command.Description)); + Preconditions.AtMost(command.Description.Length, 100, nameof(command.Description)); + Preconditions.AtLeast(command.Description.Length, 1, nameof(command.Description)); + } options = RequestOptions.CreateOrClone(options); - options.IsReactionBucket = true; - var ids = new BucketIds(channelId: channelId); + var bucket = new BucketIds(guildId: guildId); - // @me is non-const to fool the ratelimiter, otherwise it will put add/remove in separate buckets - var me = "@me"; - await SendAsync("PUT", () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/{me}", ids, options: options).ConfigureAwait(false); + return await SendJsonAsync("POST", () => $"applications/{CurrentUserId}/guilds/{guildId}/commands", command, bucket, options: options).ConfigureAwait(false); } - public async Task RemoveReactionAsync(ulong channelId, ulong messageId, ulong userId, string emoji, RequestOptions options = null) + public async Task ModifyGuildApplicationCommandAsync(ModifyApplicationCommandParams command, ulong guildId, ulong commandId, RequestOptions options = null) { - Preconditions.NotEqual(channelId, 0, nameof(channelId)); - Preconditions.NotEqual(messageId, 0, nameof(messageId)); - Preconditions.NotNullOrWhitespace(emoji, nameof(emoji)); - options = RequestOptions.CreateOrClone(options); - options.IsReactionBucket = true; - var ids = new BucketIds(channelId: channelId); + var bucket = new BucketIds(guildId: guildId); - var user = CurrentUserId.HasValue ? (userId == CurrentUserId.Value ? "@me" : userId.ToString()) : userId.ToString(); - await SendAsync("DELETE", () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/{user}", ids, options: options).ConfigureAwait(false); + return await SendJsonAsync("PATCH", () => $"applications/{CurrentUserId}/guilds/{guildId}/commands/{commandId}", command, bucket, options: options).ConfigureAwait(false); } - public async Task RemoveAllReactionsAsync(ulong channelId, ulong messageId, RequestOptions options = null) + public async Task DeleteGuildApplicationCommandAsync(ulong guildId, ulong commandId, RequestOptions options = null) { - Preconditions.NotEqual(channelId, 0, nameof(channelId)); - Preconditions.NotEqual(messageId, 0, nameof(messageId)); - options = RequestOptions.CreateOrClone(options); - var ids = new BucketIds(channelId: channelId); + var bucket = new BucketIds(guildId: guildId); - await SendAsync("DELETE", () => $"channels/{channelId}/messages/{messageId}/reactions", ids, options: options).ConfigureAwait(false); + await SendAsync("DELETE", () => $"applications/{CurrentUserId}/guilds/{guildId}/commands/{commandId}", bucket, options: options).ConfigureAwait(false); } - public async Task> GetReactionUsersAsync(ulong channelId, ulong messageId, string emoji, GetReactionUsersParams args, RequestOptions options = null) + + public async Task BulkOverwriteGuildApplicationCommandsAsync(ulong guildId, CreateApplicationCommandParams[] commands, RequestOptions options = null) { - Preconditions.NotEqual(channelId, 0, nameof(channelId)); - Preconditions.NotEqual(messageId, 0, nameof(messageId)); - Preconditions.NotNullOrWhitespace(emoji, nameof(emoji)); - Preconditions.NotNull(args, nameof(args)); - Preconditions.GreaterThan(args.Limit, 0, nameof(args.Limit)); - Preconditions.AtMost(args.Limit, DiscordConfig.MaxUserReactionsPerBatch, nameof(args.Limit)); - Preconditions.GreaterThan(args.AfterUserId, 0, nameof(args.AfterUserId)); options = RequestOptions.CreateOrClone(options); - int limit = args.Limit.GetValueOrDefault(DiscordConfig.MaxUserReactionsPerBatch); - ulong afterUserId = args.AfterUserId.GetValueOrDefault(0); + var bucket = new BucketIds(guildId: guildId); - var ids = new BucketIds(channelId: channelId); - Expression> endpoint = () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}?limit={limit}&after={afterUserId}"; - return await SendAsync>("GET", endpoint, ids, options: options).ConfigureAwait(false); + return await SendJsonAsync("PUT", () => $"applications/{CurrentUserId}/guilds/{guildId}/commands", commands, bucket, options: options).ConfigureAwait(false); } - public async Task AckMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) + #endregion + + #region Interaction Responses + public async Task CreateInteractionResponseAsync(InteractionResponse response, ulong interactionId, string interactionToken, RequestOptions options = null) { - Preconditions.NotEqual(channelId, 0, nameof(channelId)); - Preconditions.NotEqual(messageId, 0, nameof(messageId)); + if (response.Data.IsSpecified && response.Data.Value.Content.IsSpecified) + Preconditions.AtMost(response.Data.Value.Content.Value?.Length ?? 0, 2000, nameof(response.Data.Value.Content)); + options = RequestOptions.CreateOrClone(options); - var ids = new BucketIds(channelId: channelId); - await SendAsync("POST", () => $"channels/{channelId}/messages/{messageId}/ack", ids, options: options).ConfigureAwait(false); + await SendJsonAsync("POST", () => $"interactions/{interactionId}/{interactionToken}/callback", response, new BucketIds(), options: options); } - public async Task TriggerTypingIndicatorAsync(ulong channelId, RequestOptions options = null) + public async Task CreateInteractionResponseAsync(UploadInteractionFileParams response, ulong interactionId, string interactionToken, RequestOptions options = null) { - Preconditions.NotEqual(channelId, 0, nameof(channelId)); + if ((!response.Embeds.IsSpecified || response.Embeds.Value == null || response.Embeds.Value.Length == 0) && !response.Files.Any()) + Preconditions.NotNullOrEmpty(response.Content, nameof(response.Content)); + + if (response.Content.IsSpecified && response.Content.Value.Length > DiscordConfig.MaxMessageSize) + throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(response.Content)); + options = RequestOptions.CreateOrClone(options); - var ids = new BucketIds(channelId: channelId); - await SendAsync("POST", () => $"channels/{channelId}/typing", ids, options: options).ConfigureAwait(false); + var ids = new BucketIds(); + await SendMultipartAsync("POST", () => $"interactions/{interactionId}/{interactionToken}/callback", response.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); } - public async Task CrosspostAsync(ulong channelId, ulong messageId, RequestOptions options = null) + public async Task GetInteractionResponseAsync(string interactionToken, RequestOptions options = null) { - Preconditions.NotEqual(channelId, 0, nameof(channelId)); - Preconditions.NotEqual(messageId, 0, nameof(messageId)); + Preconditions.NotNullOrEmpty(interactionToken, nameof(interactionToken)); + options = RequestOptions.CreateOrClone(options); - var ids = new BucketIds(channelId: channelId); - await SendAsync("POST", () => $"channels/{channelId}/messages/{messageId}/crosspost", ids, options: options).ConfigureAwait(false); + return await NullifyNotFound(SendAsync("GET", () => $"webhooks/{CurrentUserId}/{interactionToken}/messages/@original", new BucketIds(), options: options)).ConfigureAwait(false); } + public async Task ModifyInteractionResponseAsync(ModifyInteractionResponseParams args, string interactionToken, RequestOptions options = null) + { + options = RequestOptions.CreateOrClone(options); - //Channel Permissions - public async Task ModifyChannelPermissionsAsync(ulong channelId, ulong targetId, ModifyChannelPermissionsParams args, RequestOptions options = null) + return await SendJsonAsync("PATCH", () => $"webhooks/{CurrentUserId}/{interactionToken}/messages/@original", args, new BucketIds(), options: options); + } + public async Task DeleteInteractionResponseAsync(string interactionToken, RequestOptions options = null) { - Preconditions.NotEqual(channelId, 0, nameof(channelId)); - Preconditions.NotEqual(targetId, 0, nameof(targetId)); - Preconditions.NotNull(args, nameof(args)); options = RequestOptions.CreateOrClone(options); - var ids = new BucketIds(channelId: channelId); - await SendJsonAsync("PUT", () => $"channels/{channelId}/permissions/{targetId}", args, ids, options: options).ConfigureAwait(false); + await SendAsync("DELETE", () => $"webhooks/{CurrentUserId}/{interactionToken}/messages/@original", new BucketIds(), options: options); } - public async Task DeleteChannelPermissionAsync(ulong channelId, ulong targetId, RequestOptions options = null) + + public async Task CreateInteractionFollowupMessageAsync(CreateWebhookMessageParams args, string token, RequestOptions options = null) { - Preconditions.NotEqual(channelId, 0, nameof(channelId)); - Preconditions.NotEqual(targetId, 0, nameof(targetId)); + if ((!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) && !args.File.IsSpecified) + Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content)); + + if(args.Content.IsSpecified && args.Content.Value?.Length > DiscordConfig.MaxMessageSize) + throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); + options = RequestOptions.CreateOrClone(options); - var ids = new BucketIds(channelId: channelId); - await SendAsync("DELETE", () => $"channels/{channelId}/permissions/{targetId}", ids, options: options).ConfigureAwait(false); + if (!args.File.IsSpecified) + return await SendJsonAsync("POST", () => $"webhooks/{CurrentUserId}/{token}?wait=true", args, new BucketIds(), options: options).ConfigureAwait(false); + else + return await SendMultipartAsync("POST", () => $"webhooks/{CurrentUserId}/{token}?wait=true", args.ToDictionary(), new BucketIds(), options: options).ConfigureAwait(false); } - //Channel Pins - public async Task AddPinAsync(ulong channelId, ulong messageId, RequestOptions options = null) + public async Task CreateInteractionFollowupMessageAsync(UploadWebhookFileParams args, string token, RequestOptions options = null) { - Preconditions.GreaterThan(channelId, 0, nameof(channelId)); - Preconditions.GreaterThan(messageId, 0, nameof(messageId)); + if ((!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) && !args.Files.Any()) + Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content)); + + if (args.Content.IsSpecified && args.Content.Value?.Length > DiscordConfig.MaxMessageSize) + throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(); + return await SendMultipartAsync("POST", () => $"webhooks/{CurrentUserId}/{token}?wait=true", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + } - var ids = new BucketIds(channelId: channelId); - await SendAsync("PUT", () => $"channels/{channelId}/pins/{messageId}", ids, options: options).ConfigureAwait(false); + public async Task ModifyInteractionFollowupMessageAsync(ModifyInteractionResponseParams args, ulong id, string token, RequestOptions options = null) + { + Preconditions.NotNull(args, nameof(args)); + Preconditions.NotEqual(id, 0, nameof(id)); + + if (args.Content.IsSpecified && args.Content.Value?.Length > DiscordConfig.MaxMessageSize) + throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content)); + + options = RequestOptions.CreateOrClone(options); + return await SendJsonAsync("PATCH", () => $"webhooks/{CurrentUserId}/{token}/messages/{id}", args, new BucketIds(), options: options).ConfigureAwait(false); } - public async Task RemovePinAsync(ulong channelId, ulong messageId, RequestOptions options = null) + + public async Task DeleteInteractionFollowupMessageAsync(ulong id, string token, RequestOptions options = null) { - Preconditions.NotEqual(channelId, 0, nameof(channelId)); - Preconditions.NotEqual(messageId, 0, nameof(messageId)); + Preconditions.NotEqual(id, 0, nameof(id)); + options = RequestOptions.CreateOrClone(options); - var ids = new BucketIds(channelId: channelId); - await SendAsync("DELETE", () => $"channels/{channelId}/pins/{messageId}", ids, options: options).ConfigureAwait(false); + await SendAsync("DELETE", () => $"webhooks/{CurrentUserId}/{token}/messages/{id}", new BucketIds(), options: options).ConfigureAwait(false); } - public async Task> GetPinsAsync(ulong channelId, RequestOptions options = null) + #endregion + + #region Application Command permissions + public async Task GetGuildApplicationCommandPermissionsAsync(ulong guildId, RequestOptions options = null) { - Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + options = RequestOptions.CreateOrClone(options); - var ids = new BucketIds(channelId: channelId); - return await SendAsync>("GET", () => $"channels/{channelId}/pins", ids, options: options).ConfigureAwait(false); + return await SendAsync("GET", () => $"applications/{CurrentUserId}/guilds/{guildId}/commands/permissions", new BucketIds(), options: options).ConfigureAwait(false); } - //Channel Recipients - public async Task AddGroupRecipientAsync(ulong channelId, ulong userId, RequestOptions options = null) + public async Task GetGuildApplicationCommandPermissionAsync(ulong guildId, ulong commandId, RequestOptions options = null) { - Preconditions.GreaterThan(channelId, 0, nameof(channelId)); - Preconditions.GreaterThan(userId, 0, nameof(userId)); + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + Preconditions.NotEqual(commandId, 0, nameof(commandId)); + options = RequestOptions.CreateOrClone(options); - var ids = new BucketIds(channelId: channelId); - await SendAsync("PUT", () => $"channels/{channelId}/recipients/{userId}", ids, options: options).ConfigureAwait(false); + return await SendAsync("GET", () => $"applications/{CurrentUserId}/guilds/{guildId}/commands/{commandId}/permissions", new BucketIds(), options: options).ConfigureAwait(false); + } + + public async Task ModifyApplicationCommandPermissionsAsync(ModifyGuildApplicationCommandPermissionsParams permissions, ulong guildId, ulong commandId, RequestOptions options = null) + { + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + Preconditions.NotEqual(commandId, 0, nameof(commandId)); + options = RequestOptions.CreateOrClone(options); + + return await SendJsonAsync("PUT", () => $"applications/{CurrentUserId}/guilds/{guildId}/commands/{commandId}/permissions", permissions, new BucketIds(), options: options).ConfigureAwait(false); } - public async Task RemoveGroupRecipientAsync(ulong channelId, ulong userId, RequestOptions options = null) + + public async Task> BatchModifyApplicationCommandPermissionsAsync(ModifyGuildApplicationCommandPermissions[] permissions, ulong guildId, RequestOptions options = null) { - Preconditions.NotEqual(channelId, 0, nameof(channelId)); - Preconditions.NotEqual(userId, 0, nameof(userId)); + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + Preconditions.NotNull(permissions, nameof(permissions)); + options = RequestOptions.CreateOrClone(options); - var ids = new BucketIds(channelId: channelId); - await SendAsync("DELETE", () => $"channels/{channelId}/recipients/{userId}", ids, options: options).ConfigureAwait(false); + return await SendJsonAsync("PUT", () => $"applications/{CurrentUserId}/guilds/{guildId}/commands/permissions", permissions, new BucketIds(), options: options).ConfigureAwait(false); } + #endregion - //Guilds - public async Task GetGuildAsync(ulong guildId, RequestOptions options = null) + #region Guilds + public async Task GetGuildAsync(ulong guildId, bool withCounts, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); @@ -806,7 +1469,7 @@ namespace Discord.API try { var ids = new BucketIds(guildId: guildId); - return await SendAsync("GET", () => $"guilds/{guildId}", ids, options: options).ConfigureAwait(false); + return await SendAsync("GET", () => $"guilds/{guildId}?with_counts={(withCounts ? "true" : "false")}", ids, options: options).ConfigureAwait(false); } catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } } @@ -864,13 +1527,15 @@ namespace Discord.API Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); Preconditions.AtLeast(args.Days, 1, nameof(args.Days)); + string endpointRoleIds = args.IncludeRoleIds?.Length > 0 ? $"&include_roles={string.Join(",", args.IncludeRoleIds)}" : ""; options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendAsync("GET", () => $"guilds/{guildId}/prune?days={args.Days}", ids, options: options).ConfigureAwait(false); + return await SendAsync("GET", () => $"guilds/{guildId}/prune?days={args.Days}{endpointRoleIds}", ids, options: options).ConfigureAwait(false); } + #endregion - //Guild Bans + #region Guild Bans public async Task> GetGuildBansAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -885,8 +1550,12 @@ namespace Discord.API Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); - var ids = new BucketIds(guildId: guildId); - return await SendAsync("GET", () => $"guilds/{guildId}/bans/{userId}", ids, options: options).ConfigureAwait(false); + try + { + var ids = new BucketIds(guildId: guildId); + return await SendAsync("GET", () => $"guilds/{guildId}/bans/{userId}", ids, options: options).ConfigureAwait(false); + } + catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } } /// /// and must not be equal to zero. @@ -905,7 +1574,7 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); string reason = string.IsNullOrWhiteSpace(args.Reason) ? "" : $"&reason={Uri.EscapeDataString(args.Reason)}"; - await SendAsync("PUT", () => $"guilds/{guildId}/bans/{userId}?delete-message-days={args.DeleteMessageDays}{reason}", ids, options: options).ConfigureAwait(false); + await SendAsync("PUT", () => $"guilds/{guildId}/bans/{userId}?delete_message_days={args.DeleteMessageDays}{reason}", ids, options: options).ConfigureAwait(false); } /// and must not be equal to zero. public async Task RemoveGuildBanAsync(ulong guildId, ulong userId, RequestOptions options = null) @@ -917,10 +1586,11 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); await SendAsync("DELETE", () => $"guilds/{guildId}/bans/{userId}", ids, options: options).ConfigureAwait(false); } + #endregion - //Guild Embeds + #region Guild Widget /// must not be equal to zero. - public async Task GetGuildEmbedAsync(ulong guildId, RequestOptions options = null) + public async Task GetGuildWidgetAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); @@ -928,23 +1598,24 @@ namespace Discord.API try { var ids = new BucketIds(guildId: guildId); - return await SendAsync("GET", () => $"guilds/{guildId}/embed", ids, options: options).ConfigureAwait(false); + return await SendAsync("GET", () => $"guilds/{guildId}/widget", ids, options: options).ConfigureAwait(false); } catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } } /// must not be equal to zero. /// must not be . - public async Task ModifyGuildEmbedAsync(ulong guildId, Rest.ModifyGuildEmbedParams args, RequestOptions options = null) + public async Task ModifyGuildWidgetAsync(ulong guildId, Rest.ModifyGuildWidgetParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendJsonAsync("PATCH", () => $"guilds/{guildId}/embed", args, ids, options: options).ConfigureAwait(false); + return await SendJsonAsync("PATCH", () => $"guilds/{guildId}/widget", args, ids, options: options).ConfigureAwait(false); } + #endregion - //Guild Integrations + #region Guild Integrations /// must not be equal to zero. public async Task> GetGuildIntegrationsAsync(ulong guildId, RequestOptions options = null) { @@ -996,8 +1667,9 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); return await SendAsync("POST", () => $"guilds/{guildId}/integrations/{integrationId}/sync", ids, options: options).ConfigureAwait(false); } + #endregion - //Guild Invites + #region Guild Invites /// cannot be blank. /// must not be . public async Task GetInviteAsync(string inviteId, RequestOptions options = null) @@ -1062,6 +1734,12 @@ namespace Discord.API Preconditions.AtLeast(args.MaxUses, 0, nameof(args.MaxUses)); Preconditions.AtMost(args.MaxAge, 86400, nameof(args.MaxAge), "The maximum age of an invite must be less than or equal to a day (86400 seconds)."); + if (args.TargetType.IsSpecified) + { + Preconditions.NotEqual((int)args.TargetType.Value, (int)TargetUserType.Undefined, nameof(args.TargetType)); + if (args.TargetType.Value == TargetUserType.Stream) Preconditions.GreaterThan(args.TargetUserId, 0, nameof(args.TargetUserId)); + if (args.TargetType.Value == TargetUserType.EmbeddedApplication) Preconditions.GreaterThan(args.TargetApplicationId, 0, nameof(args.TargetUserId)); + } options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(channelId: channelId); @@ -1074,8 +1752,9 @@ namespace Discord.API return await SendAsync("DELETE", () => $"invites/{inviteId}", new BucketIds(), options: options).ConfigureAwait(false); } + #endregion - //Guild Members + #region Guild Members public async Task AddGuildMemberAsync(ulong guildId, ulong userId, AddGuildMemberParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -1157,8 +1836,25 @@ namespace Discord.API await SendJsonAsync("PATCH", () => $"guilds/{guildId}/members/{userId}", args, ids, options: options).ConfigureAwait(false); } } + public async Task> SearchGuildMembersAsync(ulong guildId, SearchGuildMembersParams args, RequestOptions options = null) + { + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + Preconditions.NotNull(args, nameof(args)); + Preconditions.GreaterThan(args.Limit, 0, nameof(args.Limit)); + Preconditions.AtMost(args.Limit, DiscordConfig.MaxUsersPerBatch, nameof(args.Limit)); + Preconditions.NotNullOrEmpty(args.Query, nameof(args.Query)); + options = RequestOptions.CreateOrClone(options); + + int limit = args.Limit.GetValueOrDefault(DiscordConfig.MaxUsersPerBatch); + string query = args.Query; + + var ids = new BucketIds(guildId: guildId); + Expression> endpoint = () => $"guilds/{guildId}/members/search?limit={limit}&query={query}"; + return await SendAsync>("GET", endpoint, ids, options: options).ConfigureAwait(false); + } + #endregion - //Guild Roles + #region Guild Roles public async Task> GetGuildRolesAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -1167,13 +1863,13 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); return await SendAsync>("GET", () => $"guilds/{guildId}/roles", ids, options: options).ConfigureAwait(false); } - public async Task CreateGuildRoleAsync(ulong guildId, RequestOptions options = null) + public async Task CreateGuildRoleAsync(ulong guildId, Rest.ModifyGuildRoleParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId); - return await SendAsync("POST", () => $"guilds/{guildId}/roles", ids, options: options).ConfigureAwait(false); + return await SendJsonAsync("POST", () => $"guilds/{guildId}/roles", args, ids, options: options).ConfigureAwait(false); } public async Task DeleteGuildRoleAsync(ulong guildId, ulong roleId, RequestOptions options = null) { @@ -1205,8 +1901,18 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); return await SendJsonAsync>("PATCH", () => $"guilds/{guildId}/roles", args, ids, options: options).ConfigureAwait(false); } + #endregion + + #region Guild emoji + public async Task> GetGuildEmotesAsync(ulong guildId, RequestOptions options = null) + { + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(guildId: guildId); + return await SendAsync>("GET", () => $"guilds/{guildId}/emojis", ids, options: options).ConfigureAwait(false); + } - //Guild emoji public async Task GetGuildEmoteAsync(ulong guildId, ulong emoteId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -1249,8 +1955,108 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); await SendAsync("DELETE", () => $"guilds/{guildId}/emojis/{emoteId}", ids, options: options).ConfigureAwait(false); } + #endregion + + #region Guild Events + + public async Task ListGuildScheduledEventsAsync(ulong guildId, RequestOptions options = null) + { + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(guildId: guildId); + return await SendAsync("GET", () => $"guilds/{guildId}/scheduled-events?with_user_count=true", ids, options: options).ConfigureAwait(false); + } + + public async Task GetGuildScheduledEventAsync(ulong eventId, ulong guildId, RequestOptions options = null) + { + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + Preconditions.NotEqual(eventId, 0, nameof(eventId)); + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(guildId: guildId); + + return await NullifyNotFound(SendAsync("GET", () => $"guilds/{guildId}/scheduled-events/{eventId}?with_user_count=true", ids, options: options)).ConfigureAwait(false); + } + + public async Task CreateGuildScheduledEventAsync(CreateGuildScheduledEventParams args, ulong guildId, RequestOptions options = null) + { + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + Preconditions.NotNull(args, nameof(args)); + + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(guildId: guildId); + + return await SendJsonAsync("POST", () => $"guilds/{guildId}/scheduled-events", args, ids, options: options).ConfigureAwait(false); + } + + public async Task ModifyGuildScheduledEventAsync(ModifyGuildScheduledEventParams args, ulong eventId, ulong guildId, RequestOptions options = null) + { + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + Preconditions.NotEqual(eventId, 0, nameof(eventId)); + Preconditions.NotNull(args, nameof(args)); + + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(guildId: guildId); + + return await SendJsonAsync("PATCH", () => $"guilds/{guildId}/scheduled-events/{eventId}", args, ids, options: options).ConfigureAwait(false); + } + + public async Task DeleteGuildScheduledEventAsync(ulong eventId, ulong guildId, RequestOptions options = null) + { + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + Preconditions.NotEqual(eventId, 0, nameof(eventId)); + + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(guildId: guildId); + + await SendAsync("DELETE", () => $"guilds/{guildId}/scheduled-events/{eventId}", ids, options: options).ConfigureAwait(false); + } + + public async Task GetGuildScheduledEventUsersAsync(ulong eventId, ulong guildId, int limit = 100, RequestOptions options = null) + { + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + Preconditions.NotEqual(eventId, 0, nameof(eventId)); + + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(guildId: guildId); + + return await SendAsync("GET", () => $"guilds/{guildId}/scheduled-events/{eventId}/users?limit={limit}&with_member=true", ids, options: options).ConfigureAwait(false); + } + + public async Task GetGuildScheduledEventUsersAsync(ulong eventId, ulong guildId, GetEventUsersParams args, RequestOptions options = null) + { + Preconditions.NotEqual(eventId, 0, nameof(eventId)); + Preconditions.NotNull(args, nameof(args)); + Preconditions.AtLeast(args.Limit, 0, nameof(args.Limit)); + Preconditions.AtMost(args.Limit, DiscordConfig.MaxMessagesPerBatch, nameof(args.Limit)); + options = RequestOptions.CreateOrClone(options); + + int limit = args.Limit.GetValueOrDefault(DiscordConfig.MaxGuildEventUsersPerBatch); + ulong? relativeId = args.RelativeUserId.IsSpecified ? args.RelativeUserId.Value : (ulong?)null; + var relativeDir = args.RelativeDirection.GetValueOrDefault(Direction.Before) switch + { + Direction.After => "after", + Direction.Around => "around", + _ => "before", + }; + var ids = new BucketIds(guildId: guildId); + Expression> endpoint; + if (relativeId != null) + endpoint = () => $"guilds/{guildId}/scheduled-events/{eventId}/users?with_member=true&limit={limit}&{relativeDir}={relativeId}"; + else + endpoint = () => $"guilds/{guildId}/scheduled-events/{eventId}/users?with_member=true&limit={limit}"; + + return await SendAsync("GET", endpoint, ids, options: options).ConfigureAwait(false); + } - //Users + #endregion + + #region Users public async Task GetUserAsync(ulong userId, RequestOptions options = null) { Preconditions.NotEqual(userId, 0, nameof(userId)); @@ -1262,8 +2068,9 @@ namespace Discord.API } catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } } + #endregion - //Current User/DMs + #region Current User/DMs public async Task GetMyUserAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); @@ -1322,8 +2129,9 @@ namespace Discord.API return await SendJsonAsync("POST", () => "users/@me/channels", args, new BucketIds(), options: options).ConfigureAwait(false); } + #endregion - //Voice Regions + #region Voice Regions public async Task> GetVoiceRegionsAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); @@ -1337,8 +2145,9 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); return await SendAsync>("GET", () => $"guilds/{guildId}/regions", ids, options: options).ConfigureAwait(false); } + #endregion - //Audit logs + #region Audit logs public async Task GetAuditLogsAsync(ulong guildId, GetAuditLogsParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -1367,12 +2176,13 @@ namespace Discord.API .Append(args.ActionType.Value); } - // still use string interp for the query w/o params, as this is necessary for CreateBucketId + // Still use string interp for the query w/o params, as this is necessary for CreateBucketId endpoint = () => $"guilds/{guildId}/audit-logs?limit={limit}{queryArgs.ToString()}"; return await SendAsync("GET", endpoint, ids, options: options).ConfigureAwait(false); } + #endregion - //Webhooks + #region Webhooks public async Task CreateWebhookAsync(ulong channelId, CreateWebhookParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -1435,8 +2245,9 @@ namespace Discord.API var ids = new BucketIds(channelId: channelId); return await SendAsync>("GET", () => $"channels/{channelId}/webhooks", ids, options: options).ConfigureAwait(false); } + #endregion - //Helpers + #region Helpers /// Client is not logged in. protected void CheckState() { @@ -1459,28 +2270,71 @@ namespace Discord.API return _serializer.Deserialize(reader); } + protected async Task NullifyNotFound(Task sendTask) where T : class + { + try + { + var result = await sendTask.ConfigureAwait(false); + + if (sendTask.Exception != null) + { + if (sendTask.Exception.InnerException is HttpException x) + { + if (x.HttpCode == HttpStatusCode.NotFound) + { + return null; + } + } + + throw sendTask.Exception; + } + else + return result; + } + catch (HttpException x) when (x.HttpCode == HttpStatusCode.NotFound) + { + return null; + } + } internal class BucketIds { public ulong GuildId { get; internal set; } public ulong ChannelId { get; internal set; } + public ulong WebhookId { get; internal set; } + public string HttpMethod { get; internal set; } - internal BucketIds(ulong guildId = 0, ulong channelId = 0) + internal BucketIds(ulong guildId = 0, ulong channelId = 0, ulong webhookId = 0) { GuildId = guildId; ChannelId = channelId; + WebhookId = webhookId; } + internal object[] ToArray() - => new object[] { GuildId, ChannelId }; + => new object[] { HttpMethod, GuildId, ChannelId, WebhookId }; + + internal Dictionary ToMajorParametersDictionary() + { + var dict = new Dictionary(); + if (GuildId != 0) + dict["GuildId"] = GuildId.ToString(); + if (ChannelId != 0) + dict["ChannelId"] = ChannelId.ToString(); + if (WebhookId != 0) + dict["WebhookId"] = WebhookId.ToString(); + return dict; + } internal static int? GetIndex(string name) { - switch (name) + return name switch { - case "guildId": return 0; - case "channelId": return 1; - default: - return null; - } + "httpMethod" => 0, + "guildId" => 1, + "channelId" => 2, + "webhookId" => 3, + _ => null, + }; } } @@ -1488,18 +2342,19 @@ namespace Discord.API { return endpointExpr.Compile()(); } - private static string GetBucketId(BucketIds ids, Expression> endpointExpr, string callingMethod) + private static BucketId GetBucketId(string httpMethod, BucketIds ids, Expression> endpointExpr, string callingMethod) { + ids.HttpMethod ??= httpMethod; return _bucketIdGenerators.GetOrAdd(callingMethod, x => CreateBucketId(endpointExpr))(ids); } - private static Func CreateBucketId(Expression> endpoint) + private static Func CreateBucketId(Expression> endpoint) { try { //Is this a constant string? if (endpoint.Body.NodeType == ExpressionType.Constant) - return x => (endpoint.Body as ConstantExpression).Value.ToString(); + return x => BucketId.Create(x.HttpMethod, (endpoint.Body as ConstantExpression).Value.ToString(), x.ToMajorParametersDictionary()); var builder = new StringBuilder(); var methodCall = endpoint.Body as MethodCallExpression; @@ -1515,7 +2370,7 @@ namespace Discord.API Array.Copy(elements, 0, methodArgs, 1, elements.Length); } - int endIndex = format.IndexOf('?'); //Dont include params + int endIndex = format.IndexOf('?'); //Don't include params if (endIndex == -1) endIndex = format.Length; @@ -1536,7 +2391,7 @@ namespace Discord.API var mappedId = BucketIds.GetIndex(fieldName); - if(!mappedId.HasValue && rightIndex != endIndex && format.Length > rightIndex + 1 && format[rightIndex + 1] == '/') //Ignore the next slash + if (!mappedId.HasValue && rightIndex != endIndex && format.Length > rightIndex + 1 && format[rightIndex + 1] == '/') //Ignore the next slash rightIndex++; if (mappedId.HasValue) @@ -1549,7 +2404,7 @@ namespace Discord.API format = builder.ToString(); - return x => string.Format(format, x.ToArray()); + return x => BucketId.Create(x.HttpMethod, string.Format(format, x.ToArray()), x.ToMajorParametersDictionary()); } catch (Exception ex) { @@ -1567,5 +2422,6 @@ namespace Discord.API return (expr as MemberExpression).Member.Name; } + #endregion } } diff --git a/src/Discord.Net.Rest/DiscordRestClient.cs b/src/Discord.Net.Rest/DiscordRestClient.cs index da4bb27d1..cd2033c8c 100644 --- a/src/Discord.Net.Rest/DiscordRestClient.cs +++ b/src/Discord.Net.Rest/DiscordRestClient.cs @@ -1,6 +1,13 @@ +//using Discord.Rest.Entities.Interactions; +using Discord.Net; +using Discord.Net.Converters; +using Discord.Net.ED25519; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Collections.Immutable; using System.IO; +using System.Text; using System.Threading.Tasks; namespace Discord.Rest @@ -10,13 +17,15 @@ namespace Discord.Rest /// public class DiscordRestClient : BaseDiscordClient, IDiscordClient { + #region DiscordRestClient private RestApplication _applicationInfo; + internal static JsonSerializer Serializer = new JsonSerializer() { ContractResolver = new DiscordContractResolver(), NullValueHandling = NullValueHandling.Include }; /// /// Gets the logged-in user. /// - public new RestSelfUser CurrentUser => base.CurrentUser as RestSelfUser; - + public new RestSelfUser CurrentUser { get => base.CurrentUser as RestSelfUser; internal set => base.CurrentUser = value; } + /// public DiscordRestClient() : this(new DiscordRestConfig()) { } /// @@ -28,10 +37,7 @@ namespace Discord.Rest internal DiscordRestClient(DiscordRestConfig config, API.DiscordRestApiClient api) : base(config, api) { } private static API.DiscordRestApiClient CreateApiClient(DiscordRestConfig config) - => new API.DiscordRestApiClient(config.RestClientProvider, - DiscordRestConfig.UserAgent, - rateLimitPrecision: config.RateLimitPrecision, - useSystemClock: config.UseSystemClock); + => new API.DiscordRestApiClient(config.RestClientProvider, DiscordRestConfig.UserAgent, serializer: Serializer, useSystemClock: config.UseSystemClock); internal override void Dispose(bool disposing) { @@ -56,6 +62,11 @@ namespace Discord.Rest ApiClient.CurrentUserId = user.Id; base.CurrentUser = RestSelfUser.Create(this, user); } + + internal void CreateRestSelfUser(API.User user) + { + base.CurrentUser = RestSelfUser.Create(this, user); + } /// internal override Task OnLogoutAsync() { @@ -63,9 +74,73 @@ namespace Discord.Rest return Task.Delay(0); } + #region Rest interactions + + public bool IsValidHttpInteraction(string publicKey, string signature, string timestamp, string body) + => IsValidHttpInteraction(publicKey, signature, timestamp, Encoding.UTF8.GetBytes(body)); + public bool IsValidHttpInteraction(string publicKey, string signature, string timestamp, byte[] body) + { + var key = HexConverter.HexToByteArray(publicKey); + var sig = HexConverter.HexToByteArray(signature); + var tsp = Encoding.UTF8.GetBytes(timestamp); + + var message = new List(); + message.AddRange(tsp); + message.AddRange(body); + + return IsValidHttpInteraction(key, sig, message.ToArray()); + } + + private bool IsValidHttpInteraction(byte[] publicKey, byte[] signature, byte[] message) + { + return Ed25519.Verify(signature, message, publicKey); + } + + /// + /// Creates a from a http message. + /// + /// The public key of your application + /// The signature sent with the interaction. + /// The timestamp sent with the interaction. + /// The body of the http message. + /// + /// A that represents the incoming http interaction. + /// + /// Thrown when the signature doesn't match the public key. + public Task ParseHttpInteractionAsync(string publicKey, string signature, string timestamp, string body) + => ParseHttpInteractionAsync(publicKey, signature, timestamp, Encoding.UTF8.GetBytes(body)); + + /// + /// Creates a from a http message. + /// + /// The public key of your application + /// The signature sent with the interaction. + /// The timestamp sent with the interaction. + /// The body of the http message. + /// + /// A that represents the incoming http interaction. + /// + /// Thrown when the signature doesn't match the public key. + public async Task ParseHttpInteractionAsync(string publicKey, string signature, string timestamp, byte[] body) + { + if (!IsValidHttpInteraction(publicKey, signature, timestamp, body)) + { + throw new BadSignatureException(); + } + + using (var textReader = new StringReader(Encoding.UTF8.GetString(body))) + using (var jsonReader = new JsonTextReader(textReader)) + { + var model = Serializer.Deserialize(jsonReader); + return await RestInteraction.CreateAsync(this, model); + } + } + + #endregion + public async Task GetApplicationInfoAsync(RequestOptions options = null) { - return _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this, options).ConfigureAwait(false)); + return _applicationInfo ??= await ClientHelper.GetApplicationInfoAsync(this, options).ConfigureAwait(false); } public Task GetChannelAsync(ulong id, RequestOptions options = null) @@ -84,15 +159,19 @@ namespace Discord.Rest => ClientHelper.GetInviteAsync(this, inviteId, options); public Task GetGuildAsync(ulong id, RequestOptions options = null) - => ClientHelper.GetGuildAsync(this, id, options); - public Task GetGuildEmbedAsync(ulong id, RequestOptions options = null) - => ClientHelper.GetGuildEmbedAsync(this, id, options); + => ClientHelper.GetGuildAsync(this, id, false, options); + public Task GetGuildAsync(ulong id, bool withCounts, RequestOptions options = null) + => ClientHelper.GetGuildAsync(this, id, withCounts, options); + public Task GetGuildWidgetAsync(ulong id, RequestOptions options = null) + => ClientHelper.GetGuildWidgetAsync(this, id, options); public IAsyncEnumerable> GetGuildSummariesAsync(RequestOptions options = null) => ClientHelper.GetGuildSummariesAsync(this, null, null, options); public IAsyncEnumerable> GetGuildSummariesAsync(ulong fromGuildId, int limit, RequestOptions options = null) => ClientHelper.GetGuildSummariesAsync(this, fromGuildId, limit, options); public Task> GetGuildsAsync(RequestOptions options = null) - => ClientHelper.GetGuildsAsync(this, options); + => ClientHelper.GetGuildsAsync(this, false, options); + public Task> GetGuildsAsync(bool withCounts, RequestOptions options = null) + => ClientHelper.GetGuildsAsync(this, withCounts, options); public Task CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null, RequestOptions options = null) => ClientHelper.CreateGuildAsync(this, name, region, jpegIcon, options); @@ -108,7 +187,39 @@ namespace Discord.Rest public Task GetWebhookAsync(ulong id, RequestOptions options = null) => ClientHelper.GetWebhookAsync(this, id, options); - //IDiscordClient + public Task CreateGlobalCommand(ApplicationCommandProperties properties, RequestOptions options = null) + => ClientHelper.CreateGlobalApplicationCommandAsync(this, properties, options); + public Task CreateGuildCommand(ApplicationCommandProperties properties, ulong guildId, RequestOptions options = null) + => ClientHelper.CreateGuildApplicationCommandAsync(this, guildId, properties, options); + public Task> GetGlobalApplicationCommands(RequestOptions options = null) + => ClientHelper.GetGlobalApplicationCommandsAsync(this, options); + public Task> GetGuildApplicationCommands(ulong guildId, RequestOptions options = null) + => ClientHelper.GetGuildApplicationCommandsAsync(this, guildId, options); + public Task> BulkOverwriteGlobalCommands(ApplicationCommandProperties[] commandProperties, RequestOptions options = null) + => ClientHelper.BulkOverwriteGlobalApplicationCommandAsync(this, commandProperties, options); + public Task> BulkOverwriteGuildCommands(ApplicationCommandProperties[] commandProperties, ulong guildId, RequestOptions options = null) + => ClientHelper.BulkOverwriteGuildApplicationCommandAsync(this, guildId, commandProperties, options); + public Task> BatchEditGuildCommandPermissions(ulong guildId, IDictionary permissions, RequestOptions options = null) + => InteractionHelper.BatchEditGuildCommandPermissionsAsync(this, guildId, permissions, options); + public Task DeleteAllGlobalCommandsAsync(RequestOptions options = null) + => InteractionHelper.DeleteAllGlobalCommandsAsync(this, options); + + public Task AddRoleAsync(ulong guildId, ulong userId, ulong roleId) + => ClientHelper.AddRoleAsync(this, guildId, userId, roleId); + public Task RemoveRoleAsync(ulong guildId, ulong userId, ulong roleId) + => ClientHelper.RemoveRoleAsync(this, guildId, userId, roleId); + + public Task AddReactionAsync(ulong channelId, ulong messageId, IEmote emote, RequestOptions options = null) + => MessageHelper.AddReactionAsync(channelId, messageId, emote, this, options); + public Task RemoveReactionAsync(ulong channelId, ulong messageId, ulong userId, IEmote emote, RequestOptions options = null) + => MessageHelper.RemoveReactionAsync(channelId, messageId, userId, emote, this, options); + public Task RemoveAllReactionsAsync(ulong channelId, ulong messageId, RequestOptions options = null) + => MessageHelper.RemoveAllReactionsAsync(channelId, messageId, this, options); + public Task RemoveAllReactionsForEmoteAsync(ulong channelId, ulong messageId, IEmote emote, RequestOptions options = null) + => MessageHelper.RemoveAllReactionsForEmoteAsync(channelId, messageId, emote, this, options); +#endregion + + #region IDiscordClient /// async Task IDiscordClient.GetApplicationInfoAsync(RequestOptions options) => await GetApplicationInfoAsync(options).ConfigureAwait(false); @@ -192,5 +303,13 @@ namespace Discord.Rest /// async Task IDiscordClient.GetWebhookAsync(ulong id, RequestOptions options) => await GetWebhookAsync(id, options).ConfigureAwait(false); + + /// + async Task> IDiscordClient.GetGlobalApplicationCommandsAsync(RequestOptions options) + => await GetGlobalApplicationCommands(options).ConfigureAwait(false); + /// + async Task IDiscordClient.GetGlobalApplicationCommandAsync(ulong id, RequestOptions options) + => await ClientHelper.GetGlobalApplicationCommandAsync(this, id, options).ConfigureAwait(false); + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/AuditLogHelper.cs b/src/Discord.Net.Rest/Entities/AuditLogs/AuditLogHelper.cs index 696917203..edbb2bea8 100644 --- a/src/Discord.Net.Rest/Entities/AuditLogs/AuditLogHelper.cs +++ b/src/Discord.Net.Rest/Entities/AuditLogs/AuditLogHelper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Model = Discord.API.AuditLog; @@ -51,6 +51,10 @@ namespace Discord.Rest [ActionType.MessageBulkDeleted] = MessageBulkDeleteAuditLogData.Create, [ActionType.MessagePinned] = MessagePinAuditLogData.Create, [ActionType.MessageUnpinned] = MessageUnpinAuditLogData.Create, + + [ActionType.ThreadCreate] = ThreadCreateAuditLogData.Create, + [ActionType.ThreadUpdate] = ThreadUpdateAuditLogData.Create, + [ActionType.ThreadDelete] = ThreadDeleteAuditLogData.Create, }; public static IAuditLogData CreateData(BaseDiscordClient discord, Model log, EntryModel entry) diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ChannelInfo.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ChannelInfo.cs index 0284b63f5..f50d9eeb3 100644 --- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ChannelInfo.cs +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ChannelInfo.cs @@ -5,13 +5,14 @@ namespace Discord.Rest /// public struct ChannelInfo { - internal ChannelInfo(string name, string topic, int? rateLimit, bool? nsfw, int? bitrate) + internal ChannelInfo(string name, string topic, int? rateLimit, bool? nsfw, int? bitrate, ChannelType? type) { Name = name; Topic = topic; SlowModeInterval = rateLimit; IsNsfw = nsfw; Bitrate = bitrate; + ChannelType = type; } /// @@ -53,5 +54,12 @@ namespace Discord.Rest /// null if this is not mentioned in this entry. /// public int? Bitrate { get; } + /// + /// Gets the type of this channel. + /// + /// + /// The channel type of this channel; null if not applicable. + /// + public ChannelType? ChannelType { get; } } } diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ChannelUpdateAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ChannelUpdateAuditLogData.cs index fa5233145..b2294f183 100644 --- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ChannelUpdateAuditLogData.cs +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ChannelUpdateAuditLogData.cs @@ -26,6 +26,7 @@ namespace Discord.Rest var rateLimitPerUserModel = changes.FirstOrDefault(x => x.ChangedProperty == "rate_limit_per_user"); var nsfwModel = changes.FirstOrDefault(x => x.ChangedProperty == "nsfw"); var bitrateModel = changes.FirstOrDefault(x => x.ChangedProperty == "bitrate"); + var typeModel = changes.FirstOrDefault(x => x.ChangedProperty == "type"); string oldName = nameModel?.OldValue?.ToObject(discord.ApiClient.Serializer), newName = nameModel?.NewValue?.ToObject(discord.ApiClient.Serializer); @@ -37,9 +38,11 @@ namespace Discord.Rest newNsfw = nsfwModel?.NewValue?.ToObject(discord.ApiClient.Serializer); int? oldBitrate = bitrateModel?.OldValue?.ToObject(discord.ApiClient.Serializer), newBitrate = bitrateModel?.NewValue?.ToObject(discord.ApiClient.Serializer); + ChannelType? oldType = typeModel?.OldValue?.ToObject(discord.ApiClient.Serializer), + newType = typeModel?.NewValue?.ToObject(discord.ApiClient.Serializer); - var before = new ChannelInfo(oldName, oldTopic, oldRateLimitPerUser, oldNsfw, oldBitrate); - var after = new ChannelInfo(newName, newTopic, newRateLimitPerUser, newNsfw, newBitrate); + var before = new ChannelInfo(oldName, oldTopic, oldRateLimitPerUser, oldNsfw, oldBitrate, oldType); + var after = new ChannelInfo(newName, newTopic, newRateLimitPerUser, newNsfw, newBitrate, newType); return new ChannelUpdateAuditLogData(entry.TargetId.Value, before, after); } diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/InviteCreateAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/InviteCreateAuditLogData.cs index 215a3c164..b177b2435 100644 --- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/InviteCreateAuditLogData.cs +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/InviteCreateAuditLogData.cs @@ -36,13 +36,17 @@ namespace Discord.Rest var maxAge = maxAgeModel.NewValue.ToObject(discord.ApiClient.Serializer); var code = codeModel.NewValue.ToObject(discord.ApiClient.Serializer); var temporary = temporaryModel.NewValue.ToObject(discord.ApiClient.Serializer); - var inviterId = inviterIdModel.NewValue.ToObject(discord.ApiClient.Serializer); var channelId = channelIdModel.NewValue.ToObject(discord.ApiClient.Serializer); var uses = usesModel.NewValue.ToObject(discord.ApiClient.Serializer); var maxUses = maxUsesModel.NewValue.ToObject(discord.ApiClient.Serializer); - var inviterInfo = log.Users.FirstOrDefault(x => x.Id == inviterId); - var inviter = RestUser.Create(discord, inviterInfo); + RestUser inviter = null; + if (inviterIdModel != null) + { + var inviterId = inviterIdModel.NewValue.ToObject(discord.ApiClient.Serializer); + var inviterInfo = log.Users.FirstOrDefault(x => x.Id == inviterId); + inviter = RestUser.Create(discord, inviterInfo); + } return new InviteCreateAuditLogData(maxAge, code, temporary, inviter, channelId, uses, maxUses); } @@ -70,10 +74,10 @@ namespace Discord.Rest /// public bool Temporary { get; } /// - /// Gets the user that created this invite. + /// Gets the user that created this invite if available. /// /// - /// A user that created this invite. + /// A user that created this invite or . /// public IUser Creator { get; } /// diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/InviteDeleteAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/InviteDeleteAuditLogData.cs index 5e49bb641..9d0aed12b 100644 --- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/InviteDeleteAuditLogData.cs +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/InviteDeleteAuditLogData.cs @@ -36,13 +36,17 @@ namespace Discord.Rest var maxAge = maxAgeModel.OldValue.ToObject(discord.ApiClient.Serializer); var code = codeModel.OldValue.ToObject(discord.ApiClient.Serializer); var temporary = temporaryModel.OldValue.ToObject(discord.ApiClient.Serializer); - var inviterId = inviterIdModel.OldValue.ToObject(discord.ApiClient.Serializer); var channelId = channelIdModel.OldValue.ToObject(discord.ApiClient.Serializer); var uses = usesModel.OldValue.ToObject(discord.ApiClient.Serializer); var maxUses = maxUsesModel.OldValue.ToObject(discord.ApiClient.Serializer); - var inviterInfo = log.Users.FirstOrDefault(x => x.Id == inviterId); - var inviter = RestUser.Create(discord, inviterInfo); + RestUser inviter = null; + if (inviterIdModel != null) + { + var inviterId = inviterIdModel.OldValue.ToObject(discord.ApiClient.Serializer); + var inviterInfo = log.Users.FirstOrDefault(x => x.Id == inviterId); + inviter = RestUser.Create(discord, inviterInfo); + } return new InviteDeleteAuditLogData(maxAge, code, temporary, inviter, channelId, uses, maxUses); } @@ -70,10 +74,10 @@ namespace Discord.Rest /// public bool Temporary { get; } /// - /// Gets the user that created this invite. + /// Gets the user that created this invite if available. /// /// - /// A user that created this invite. + /// A user that created this invite or . /// public IUser Creator { get; } /// diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MessagePinAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MessagePinAuditLogData.cs index 020171152..be66ac846 100644 --- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MessagePinAuditLogData.cs +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MessagePinAuditLogData.cs @@ -19,8 +19,14 @@ namespace Discord.Rest internal static MessagePinAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) { - var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId); - return new MessagePinAuditLogData(entry.Options.MessageId.Value, entry.Options.ChannelId.Value, RestUser.Create(discord, userInfo)); + RestUser user = null; + if (entry.TargetId.HasValue) + { + var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId); + user = RestUser.Create(discord, userInfo); + } + + return new MessagePinAuditLogData(entry.Options.MessageId.Value, entry.Options.ChannelId.Value, user); } /// @@ -38,10 +44,10 @@ namespace Discord.Rest /// public ulong ChannelId { get; } /// - /// Gets the user of the message that was pinned. + /// Gets the user of the message that was pinned if available. /// /// - /// A user object representing the user that created the pinned message. + /// A user object representing the user that created the pinned message or . /// public IUser Target { get; } } diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MessageUnpinAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MessageUnpinAuditLogData.cs index 1b3ff96f3..b4fa389cc 100644 --- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MessageUnpinAuditLogData.cs +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MessageUnpinAuditLogData.cs @@ -19,8 +19,14 @@ namespace Discord.Rest internal static MessageUnpinAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) { - var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId); - return new MessageUnpinAuditLogData(entry.Options.MessageId.Value, entry.Options.ChannelId.Value, RestUser.Create(discord, userInfo)); + RestUser user = null; + if (entry.TargetId.HasValue) + { + var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId); + user = RestUser.Create(discord, userInfo); + } + + return new MessageUnpinAuditLogData(entry.Options.MessageId.Value, entry.Options.ChannelId.Value, user); } /// @@ -38,10 +44,10 @@ namespace Discord.Rest /// public ulong ChannelId { get; } /// - /// Gets the user of the message that was unpinned. + /// Gets the user of the message that was unpinned if available. /// /// - /// A user object representing the user that created the unpinned message. + /// A user object representing the user that created the unpinned message or . /// public IUser Target { get; } } diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInfo.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInfo.cs new file mode 100644 index 000000000..3700796e6 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInfo.cs @@ -0,0 +1,30 @@ +namespace Discord.Rest +{ + /// + /// Represents information for a stage. + /// + public class StageInfo + { + /// + /// Gets the topic of the stage channel. + /// + public string Topic { get; } + + /// + /// Gets the privacy level of the stage channel. + /// + public StagePrivacyLevel? PrivacyLevel { get; } + + /// + /// Gets the user who started the stage channel. + /// + public IUser User { get; } + + internal StageInfo(IUser user, StagePrivacyLevel? level, string topic) + { + Topic = topic; + PrivacyLevel = level; + User = user; + } + } +} diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInstanceCreateAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInstanceCreateAuditLogData.cs new file mode 100644 index 000000000..eac99e87b --- /dev/null +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInstanceCreateAuditLogData.cs @@ -0,0 +1,50 @@ +using System.Linq; +using Model = Discord.API.AuditLog; +using EntryModel = Discord.API.AuditLogEntry; + +namespace Discord.Rest +{ + /// + /// Contains a piece of audit log data related to a stage going live. + /// + public class StageInstanceCreateAuditLogData : IAuditLogData + { + /// + /// Gets the topic of the stage channel. + /// + public string Topic { get; } + + /// + /// Gets the privacy level of the stage channel. + /// + public StagePrivacyLevel PrivacyLevel { get; } + + /// + /// Gets the user who started the stage channel. + /// + public IUser User { get; } + + /// + /// Gets the Id of the stage channel. + /// + public ulong StageChannelId { get; } + + internal StageInstanceCreateAuditLogData(string topic, StagePrivacyLevel privacyLevel, IUser user, ulong channelId) + { + Topic = topic; + PrivacyLevel = privacyLevel; + User = user; + StageChannelId = channelId; + } + + internal static StageInstanceCreateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) + { + var topic = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "topic").NewValue.ToObject(discord.ApiClient.Serializer); + var privacyLevel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "privacy_level").NewValue.ToObject(discord.ApiClient.Serializer); + var user = log.Users.FirstOrDefault(x => x.Id == entry.UserId); + var channelId = entry.Options.ChannelId; + + return new StageInstanceCreateAuditLogData(topic, privacyLevel, RestUser.Create(discord, user), channelId ?? 0); + } + } +} diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInstanceDeleteAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInstanceDeleteAuditLogData.cs new file mode 100644 index 000000000..d22c56010 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInstanceDeleteAuditLogData.cs @@ -0,0 +1,50 @@ +using System.Linq; +using Model = Discord.API.AuditLog; +using EntryModel = Discord.API.AuditLogEntry; + +namespace Discord.Rest +{ + /// + /// Contains a piece of audit log data related to a stage instance deleted. + /// + public class StageInstanceDeleteAuditLogData + { + /// + /// Gets the topic of the stage channel. + /// + public string Topic { get; } + + /// + /// Gets the privacy level of the stage channel. + /// + public StagePrivacyLevel PrivacyLevel { get; } + + /// + /// Gets the user who started the stage channel. + /// + public IUser User { get; } + + /// + /// Gets the Id of the stage channel. + /// + public ulong StageChannelId { get; } + + internal StageInstanceDeleteAuditLogData(string topic, StagePrivacyLevel privacyLevel, IUser user, ulong channelId) + { + Topic = topic; + PrivacyLevel = privacyLevel; + User = user; + StageChannelId = channelId; + } + + internal static StageInstanceDeleteAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) + { + var topic = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "topic").OldValue.ToObject(discord.ApiClient.Serializer); + var privacyLevel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "privacy_level").OldValue.ToObject(discord.ApiClient.Serializer); + var user = log.Users.FirstOrDefault(x => x.Id == entry.UserId); + var channelId = entry.Options.ChannelId; + + return new StageInstanceDeleteAuditLogData(topic, privacyLevel, RestUser.Create(discord, user), channelId ?? 0); + } + } +} diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInstanceUpdatedAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInstanceUpdatedAuditLogData.cs new file mode 100644 index 000000000..93a0344b2 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInstanceUpdatedAuditLogData.cs @@ -0,0 +1,51 @@ +using System.Linq; +using Model = Discord.API.AuditLog; +using EntryModel = Discord.API.AuditLogEntry; + +namespace Discord.Rest +{ + /// + /// Contains a piece of audit log data related to a stage instance update. + /// + public class StageInstanceUpdatedAuditLogData + { + /// + /// Gets the Id of the stage channel. + /// + public ulong StageChannelId { get; } + + /// + /// Gets the stage information before the changes. + /// + public StageInfo Before { get; } + + /// + /// Gets the stage information after the changes. + /// + public StageInfo After { get; } + + internal StageInstanceUpdatedAuditLogData(ulong channelId, StageInfo before, StageInfo after) + { + StageChannelId = channelId; + Before = before; + After = after; + } + + internal static StageInstanceUpdatedAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) + { + var channelId = entry.Options.ChannelId.Value; + + var topic = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "topic"); + var privacy = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "privacy"); + + var user = RestUser.Create(discord, log.Users.FirstOrDefault(x => x.Id == entry.UserId)); + + var oldTopic = topic?.OldValue.ToObject(); + var newTopic = topic?.NewValue.ToObject(); + var oldPrivacy = privacy?.OldValue.ToObject(); + var newPrivacy = privacy?.NewValue.ToObject(); + + return new StageInstanceUpdatedAuditLogData(channelId, new StageInfo(user, oldPrivacy, oldTopic), new StageInfo(user, newPrivacy, newTopic)); + } + } +} diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ThreadCreateAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ThreadCreateAuditLogData.cs new file mode 100644 index 000000000..f1cacd727 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ThreadCreateAuditLogData.cs @@ -0,0 +1,115 @@ +using System.Linq; + +using Model = Discord.API.AuditLog; +using EntryModel = Discord.API.AuditLogEntry; + +namespace Discord.Rest +{ + /// + /// Contains a piece of audit log data related to a thread creation. + /// + public class ThreadCreateAuditLogData : IAuditLogData + { + private ThreadCreateAuditLogData(IThreadChannel thread, ulong id, string name, ThreadType type, bool archived, + ThreadArchiveDuration autoArchiveDuration, bool locked, int? rateLimit) + { + Thread = thread; + ThreadId = id; + ThreadName = name; + ThreadType = type; + IsArchived = archived; + AutoArchiveDuration = autoArchiveDuration; + IsLocked = locked; + SlowModeInterval = rateLimit; + } + + internal static ThreadCreateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) + { + var changes = entry.Changes; + + var id = entry.TargetId.Value; + + var nameModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "name"); + var typeModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "type"); + + var archivedModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "archived"); + var autoArchiveDurationModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "auto_archive_duration"); + var lockedModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "locked"); + var rateLimitPerUserModel = changes.FirstOrDefault(x => x.ChangedProperty == "rate_limit_per_user"); + + var name = nameModel.NewValue.ToObject(discord.ApiClient.Serializer); + var type = typeModel.NewValue.ToObject(discord.ApiClient.Serializer); + + var archived = archivedModel.NewValue.ToObject(discord.ApiClient.Serializer); + var autoArchiveDuration = autoArchiveDurationModel.NewValue.ToObject(discord.ApiClient.Serializer); + var locked = lockedModel.NewValue.ToObject(discord.ApiClient.Serializer); + var rateLimit = rateLimitPerUserModel?.NewValue?.ToObject(discord.ApiClient.Serializer); + + var threadInfo = log.Threads.FirstOrDefault(x => x.Id == id); + var threadChannel = threadInfo == null ? null : RestThreadChannel.Create(discord, (IGuild)null, threadInfo); + + return new ThreadCreateAuditLogData(threadChannel, id, name, type, archived, autoArchiveDuration, locked, rateLimit); + } + + // Doc Note: Corresponds to the *current* data + + /// + /// Gets the thread that was created if it still exists. + /// + /// + /// A thread object representing the thread that was created if it still exists, otherwise returns null. + /// + public IThreadChannel Thread { get; } + /// + /// Gets the snowflake ID of the thread. + /// + /// + /// A representing the snowflake identifier for the thread. + /// + public ulong ThreadId { get; } + /// + /// Gets the name of the thread. + /// + /// + /// A string containing the name of the thread. + /// + public string ThreadName { get; } + /// + /// Gets the type of the thread. + /// + /// + /// The type of thread. + /// + public ThreadType ThreadType { get; } + /// + /// Gets the value that indicates whether the thread is archived. + /// + /// + /// true if this thread has the Archived flag enabled; otherwise false. + /// + public bool IsArchived { get; } + /// + /// Gets the auto archive duration of the thread. + /// + /// + /// The thread auto archive duration of the thread. + /// + public ThreadArchiveDuration AutoArchiveDuration { get; } + /// + /// Gets the value that indicates whether the thread is locked. + /// + /// + /// true if this thread has the Locked flag enabled; otherwise false. + /// + public bool IsLocked { get; } + /// + /// Gets the slow-mode delay of the thread. + /// + /// + /// An representing the time in seconds required before the user can send another + /// message; 0 if disabled. + /// null if this is not mentioned in this entry. + /// + public int? SlowModeInterval { get; } + } +} diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ThreadDeleteAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ThreadDeleteAuditLogData.cs new file mode 100644 index 000000000..962ec1773 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ThreadDeleteAuditLogData.cs @@ -0,0 +1,103 @@ +using System.Linq; + +using Model = Discord.API.AuditLog; +using EntryModel = Discord.API.AuditLogEntry; + +namespace Discord.Rest +{ + /// + /// Contains a piece of audit log data related to a thread deletion. + /// + public class ThreadDeleteAuditLogData : IAuditLogData + { + private ThreadDeleteAuditLogData(ulong id, string name, ThreadType type, bool archived, + ThreadArchiveDuration autoArchiveDuration, bool locked, int? rateLimit) + { + ThreadId = id; + ThreadName = name; + ThreadType = type; + IsArchived = archived; + AutoArchiveDuration = autoArchiveDuration; + IsLocked = locked; + SlowModeInterval = rateLimit; + } + + internal static ThreadDeleteAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) + { + var changes = entry.Changes; + + var id = entry.TargetId.Value; + var thread = log.Threads.FirstOrDefault(x => x.Id == id); + + var nameModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "name"); + var typeModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "type"); + + var archivedModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "archived"); + var autoArchiveDurationModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "auto_archive_duration"); + var lockedModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "locked"); + var rateLimitPerUserModel = changes.FirstOrDefault(x => x.ChangedProperty == "rate_limit_per_user"); + + var name = nameModel.OldValue.ToObject(discord.ApiClient.Serializer); + var type = typeModel.OldValue.ToObject(discord.ApiClient.Serializer); + + var archived = archivedModel.OldValue.ToObject(discord.ApiClient.Serializer); + var autoArchiveDuration = autoArchiveDurationModel.OldValue.ToObject(discord.ApiClient.Serializer); + var locked = lockedModel.OldValue.ToObject(discord.ApiClient.Serializer); + var rateLimit = rateLimitPerUserModel?.NewValue?.ToObject(discord.ApiClient.Serializer); + + return new ThreadDeleteAuditLogData(id, name, type, archived, autoArchiveDuration, locked, rateLimit); + } + + /// + /// Gets the snowflake ID of the deleted thread. + /// + /// + /// A representing the snowflake identifier for the deleted thread. + /// + public ulong ThreadId { get; } + /// + /// Gets the name of the deleted thread. + /// + /// + /// A string containing the name of the deleted thread. + /// + public string ThreadName { get; } + /// + /// Gets the type of the deleted thread. + /// + /// + /// The type of thread that was deleted. + /// + public ThreadType ThreadType { get; } + /// + /// Gets the value that indicates whether the deleted thread was archived. + /// + /// + /// true if this thread had the Archived flag enabled; otherwise false. + /// + public bool IsArchived { get; } + /// + /// Gets the thread auto archive duration of the deleted thread. + /// + /// + /// The thread auto archive duration of the thread that was deleted. + /// + public ThreadArchiveDuration AutoArchiveDuration { get; } + /// + /// Gets the value that indicates whether the deleted thread was locked. + /// + /// + /// true if this thread had the Locked flag enabled; otherwise false. + /// + public bool IsLocked { get; } + /// + /// Gets the slow-mode delay of the deleted thread. + /// + /// + /// An representing the time in seconds required before the user can send another + /// message; 0 if disabled. + /// null if this is not mentioned in this entry. + /// + public int? SlowModeInterval { get; } + } +} diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ThreadInfo.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ThreadInfo.cs new file mode 100644 index 000000000..0e01ba8a7 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ThreadInfo.cs @@ -0,0 +1,39 @@ +namespace Discord.Rest +{ + /// + /// Represents information for a thread. + /// + public class ThreadInfo + { + /// + /// Gets the name of the thread. + /// + public string Name { get; } + /// + /// Gets the value that indicates whether the thread is archived. + /// + public bool IsArchived { get; } + /// + /// Gets the auto archive duration of thread. + /// + public ThreadArchiveDuration AutoArchiveDuration { get; } + /// + /// Gets the value that indicates whether the thread is locked. + /// + public bool IsLocked { get; } + + /// + /// Gets the slow-mode delay of the ´thread. + /// + public int? SlowModeInterval { get; } + + internal ThreadInfo(string name, bool archived, ThreadArchiveDuration autoArchiveDuration, bool locked, int? rateLimit) + { + Name = name; + IsArchived = archived; + AutoArchiveDuration = autoArchiveDuration; + IsLocked = locked; + SlowModeInterval = rateLimit; + } + } +} diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ThreadUpdateAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ThreadUpdateAuditLogData.cs new file mode 100644 index 000000000..2b9b95418 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ThreadUpdateAuditLogData.cs @@ -0,0 +1,88 @@ +using System.Linq; + +using Model = Discord.API.AuditLog; +using EntryModel = Discord.API.AuditLogEntry; + +namespace Discord.Rest +{ + /// + /// Contains a piece of audit log data related to a thread update. + /// + public class ThreadUpdateAuditLogData : IAuditLogData + { + private ThreadUpdateAuditLogData(IThreadChannel thread, ThreadType type, ThreadInfo before, ThreadInfo after) + { + Thread = thread; + ThreadType = type; + Before = before; + After = After; + } + + internal static ThreadUpdateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) + { + var changes = entry.Changes; + + var id = entry.TargetId.Value; + + var nameModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "name"); + var typeModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "type"); + + var archivedModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "archived"); + var autoArchiveDurationModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "auto_archive_duration"); + var lockedModel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "locked"); + var rateLimitPerUserModel = changes.FirstOrDefault(x => x.ChangedProperty == "rate_limit_per_user"); + + var type = typeModel.OldValue.ToObject(discord.ApiClient.Serializer); + + var oldName = nameModel.OldValue.ToObject(discord.ApiClient.Serializer); + var oldArchived = archivedModel.OldValue.ToObject(discord.ApiClient.Serializer); + var oldAutoArchiveDuration = autoArchiveDurationModel.OldValue.ToObject(discord.ApiClient.Serializer); + var oldLocked = lockedModel.OldValue.ToObject(discord.ApiClient.Serializer); + var oldRateLimit = rateLimitPerUserModel?.OldValue?.ToObject(discord.ApiClient.Serializer); + var before = new ThreadInfo(oldName, oldArchived, oldAutoArchiveDuration, oldLocked, oldRateLimit); + + var newName = nameModel.NewValue.ToObject(discord.ApiClient.Serializer); + var newArchived = archivedModel.NewValue.ToObject(discord.ApiClient.Serializer); + var newAutoArchiveDuration = autoArchiveDurationModel.NewValue.ToObject(discord.ApiClient.Serializer); + var newLocked = lockedModel.NewValue.ToObject(discord.ApiClient.Serializer); + var newRateLimit = rateLimitPerUserModel?.NewValue?.ToObject(discord.ApiClient.Serializer); + var after = new ThreadInfo(newName, newArchived, newAutoArchiveDuration, newLocked, newRateLimit); + + var threadInfo = log.Threads.FirstOrDefault(x => x.Id == id); + var threadChannel = threadInfo == null ? null : RestThreadChannel.Create(discord, (IGuild)null, threadInfo); + + return new ThreadUpdateAuditLogData(threadChannel,type, before, after); + } + + // Doc Note: Corresponds to the *current* data + + /// + /// Gets the thread that was created if it still exists. + /// + /// + /// A thread object representing the thread that was created if it still exists, otherwise returns null. + /// + public IThreadChannel Thread { get; } + /// + /// Gets the type of the thread. + /// + /// + /// The type of thread. + /// + public ThreadType ThreadType { get; } + /// + /// Gets the thread information before the changes. + /// + /// + /// A thread information object representing the thread before the changes were made. + /// + public ThreadInfo Before { get; } + /// + /// Gets the thread information after the changes. + /// + /// + /// A thread information object representing the thread after the changes were made. + /// + public ThreadInfo After { get; } + } +} diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/RestAuditLogEntry.cs b/src/Discord.Net.Rest/Entities/AuditLogs/RestAuditLogEntry.cs index d604077f4..2176eab71 100644 --- a/src/Discord.Net.Rest/Entities/AuditLogs/RestAuditLogEntry.cs +++ b/src/Discord.Net.Rest/Entities/AuditLogs/RestAuditLogEntry.cs @@ -22,7 +22,7 @@ namespace Discord.Rest internal static RestAuditLogEntry Create(BaseDiscordClient discord, Model fullLog, EntryModel model) { - var userInfo = fullLog.Users.FirstOrDefault(x => x.Id == model.UserId); + var userInfo = model.UserId != null ? fullLog.Users.FirstOrDefault(x => x.Id == model.UserId) : null; IUser user = null; if (userInfo != null) user = RestUser.Create(discord, userInfo); diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index aa90b2eee..d2cc95d27 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -6,13 +6,13 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using Model = Discord.API.Channel; -using UserModel = Discord.API.User; +using StageInstance = Discord.API.StageInstance; namespace Discord.Rest { internal static class ChannelHelper { - //General + #region General public static async Task DeleteAsync(IChannel channel, BaseDiscordClient client, RequestOptions options) { @@ -28,7 +28,16 @@ namespace Discord.Rest { Name = args.Name, Position = args.Position, - CategoryId = args.CategoryId + CategoryId = args.CategoryId, + Overwrites = args.PermissionOverwrites.IsSpecified + ? args.PermissionOverwrites.Value.Select(overwrite => new API.Overwrite + { + TargetId = overwrite.TargetId, + TargetType = overwrite.TargetType, + Allow = overwrite.Permissions.AllowValue.ToString(), + Deny = overwrite.Permissions.DenyValue.ToString() + }).ToArray() + : Optional.Create(), }; return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); } @@ -46,6 +55,15 @@ namespace Discord.Rest Topic = args.Topic, IsNsfw = args.IsNsfw, SlowModeInterval = args.SlowModeInterval, + Overwrites = args.PermissionOverwrites.IsSpecified + ? args.PermissionOverwrites.Value.Select(overwrite => new API.Overwrite + { + TargetId = overwrite.TargetId, + TargetType = overwrite.TargetType, + Allow = overwrite.Permissions.AllowValue.ToString(), + Deny = overwrite.Permissions.DenyValue.ToString() + }).ToArray() + : Optional.Create(), }; return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); } @@ -59,14 +77,40 @@ namespace Discord.Rest { Bitrate = args.Bitrate, Name = args.Name, + RTCRegion = args.RTCRegion, Position = args.Position, CategoryId = args.CategoryId, - UserLimit = args.UserLimit.IsSpecified ? (args.UserLimit.Value ?? 0) : Optional.Create() + UserLimit = args.UserLimit.IsSpecified ? (args.UserLimit.Value ?? 0) : Optional.Create(), + Overwrites = args.PermissionOverwrites.IsSpecified + ? args.PermissionOverwrites.Value.Select(overwrite => new API.Overwrite + { + TargetId = overwrite.TargetId, + TargetType = overwrite.TargetType, + Allow = overwrite.Permissions.AllowValue.ToString(), + Deny = overwrite.Permissions.DenyValue.ToString() + }).ToArray() + : Optional.Create(), }; return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); } - //Invites + public static async Task ModifyAsync(IStageChannel channel, BaseDiscordClient client, + Action func, RequestOptions options = null) + { + var args = new StageInstanceProperties(); + func(args); + + var apiArgs = new ModifyStageInstanceParams() + { + PrivacyLevel = args.PrivacyLevel, + Topic = args.Topic + }; + + return await client.ApiClient.ModifyStageInstanceAsync(channel.Id, apiArgs, options); + } + #endregion + + #region Invites public static async Task> GetInvitesAsync(IGuildChannel channel, BaseDiscordClient client, RequestOptions options) { @@ -94,7 +138,56 @@ namespace Discord.Rest return RestInviteMetadata.Create(client, null, channel, model); } - //Messages + /// + /// may not be equal to zero. + /// -and- + /// and must be greater than zero. + /// -and- + /// must be lesser than 86400. + /// + public static async Task CreateInviteToStreamAsync(IGuildChannel channel, BaseDiscordClient client, + int? maxAge, int? maxUses, bool isTemporary, bool isUnique, IUser user, + RequestOptions options) + { + var args = new API.Rest.CreateChannelInviteParams + { + IsTemporary = isTemporary, + IsUnique = isUnique, + MaxAge = maxAge ?? 0, + MaxUses = maxUses ?? 0, + TargetType = TargetUserType.Stream, + TargetUserId = user.Id + }; + var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options).ConfigureAwait(false); + return RestInviteMetadata.Create(client, null, channel, model); + } + + /// + /// may not be equal to zero. + /// -and- + /// and must be greater than zero. + /// -and- + /// must be lesser than 86400. + /// + public static async Task CreateInviteToApplicationAsync(IGuildChannel channel, BaseDiscordClient client, + int? maxAge, int? maxUses, bool isTemporary, bool isUnique, ulong applicationId, + RequestOptions options) + { + var args = new API.Rest.CreateChannelInviteParams + { + IsTemporary = isTemporary, + IsUnique = isUnique, + MaxAge = maxAge ?? 0, + MaxUses = maxUses ?? 0, + TargetType = TargetUserType.EmbeddedApplication, + TargetApplicationId = applicationId + }; + var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options).ConfigureAwait(false); + return RestInviteMetadata.Create(client, null, channel, model); + } + #endregion + + #region Messages public static async Task GetMessageAsync(IMessageChannel channel, BaseDiscordClient client, ulong id, RequestOptions options) { @@ -103,18 +196,25 @@ namespace Discord.Rest var model = await client.ApiClient.GetChannelMessageAsync(channel.Id, id, options).ConfigureAwait(false); if (model == null) return null; - var author = GetAuthor(client, guild, model.Author.Value, model.WebhookId.ToNullable()); + var author = MessageHelper.GetAuthor(client, guild, model.Author.Value, model.WebhookId.ToNullable()); return RestMessage.Create(client, channel, author, model); } public static IAsyncEnumerable> GetMessagesAsync(IMessageChannel channel, BaseDiscordClient client, ulong? fromMessageId, Direction dir, int limit, RequestOptions options) { - if (dir == Direction.Around) - throw new NotImplementedException(); //TODO: Impl - var guildId = (channel as IGuildChannel)?.GuildId; var guild = guildId != null ? (client as IDiscordClient).GetGuildAsync(guildId.Value, CacheMode.CacheOnly).Result : null; + if (dir == Direction.Around && limit > DiscordConfig.MaxMessagesPerBatch) + { + int around = limit / 2; + if (fromMessageId.HasValue) + return GetMessagesAsync(channel, client, fromMessageId.Value + 1, Direction.Before, around + 1, options) //Need to include the message itself + .Concat(GetMessagesAsync(channel, client, fromMessageId, Direction.After, around, options)); + else //Shouldn't happen since there's no public overload for ulong? and Direction + return GetMessagesAsync(channel, client, null, Direction.Before, around + 1, options); + } + return new PagedAsyncEnumerable( DiscordConfig.MaxMessagesPerBatch, async (info, ct) => @@ -131,7 +231,7 @@ namespace Discord.Rest var builder = ImmutableArray.CreateBuilder(); foreach (var model in models) { - var author = GetAuthor(client, guild, model.Author.Value, model.WebhookId.ToNullable()); + var author = MessageHelper.GetAuthor(client, guild, model.Author.Value, model.WebhookId.ToNullable()); builder.Add(RestMessage.Create(client, channel, author, model)); } return builder.ToImmutable(); @@ -159,7 +259,7 @@ namespace Discord.Rest var builder = ImmutableArray.CreateBuilder(); foreach (var model in models) { - var author = GetAuthor(client, guild, model.Author.Value, model.WebhookId.ToNullable()); + var author = MessageHelper.GetAuthor(client, guild, model.Author.Value, model.WebhookId.ToNullable()); builder.Add(RestMessage.Create(client, channel, author, model)); } return builder.ToImmutable(); @@ -167,10 +267,15 @@ namespace Discord.Rest /// Message content is too long, length must be less or equal to . public static async Task SendMessageAsync(IMessageChannel channel, BaseDiscordClient client, - string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, RequestOptions options) + string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, RequestOptions options, Embed[] embeds) { + embeds ??= Array.Empty(); + if (embed != null) + embeds = new[] { embed }.Concat(embeds).ToArray(); + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed."); // check that user flag and user Id list are exclusive, same with role flag and role Id list if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue) @@ -188,7 +293,20 @@ namespace Discord.Rest } } - var args = new CreateMessageParams(text) { IsTTS = isTTS, Embed = embed?.ToModel(), AllowedMentions = allowedMentions?.ToModel() }; + if (stickers != null) + { + Preconditions.AtMost(stickers.Length, 3, nameof(stickers), "A max of 3 stickers are allowed."); + } + + var args = new CreateMessageParams(text) + { + IsTTS = isTTS, + Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional.Unspecified, + AllowedMentions = allowedMentions?.ToModel(), + MessageReference = messageReference?.ToModel(), + Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified, + Stickers = stickers?.Any() ?? false ? stickers.Select(x => x.Id).ToArray() : Optional.Unspecified + }; var model = await client.ApiClient.CreateMessageAsync(channel.Id, args, options).ConfigureAwait(false); return RestUserMessage.Create(client, channel, client.CurrentUser, model); } @@ -218,22 +336,85 @@ namespace Discord.Rest /// An I/O error occurred while opening the file. /// Message content is too long, length must be less or equal to . public static async Task SendFileAsync(IMessageChannel channel, BaseDiscordClient client, - string filePath, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler) + string filePath, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, RequestOptions options, bool isSpoiler, Embed[] embeds) { string filename = Path.GetFileName(filePath); using (var file = File.OpenRead(filePath)) - return await SendFileAsync(channel, client, file, filename, text, isTTS, embed, options, isSpoiler).ConfigureAwait(false); + return await SendFileAsync(channel, client, file, filename, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, isSpoiler, embeds).ConfigureAwait(false); } /// Message content is too long, length must be less or equal to . public static async Task SendFileAsync(IMessageChannel channel, BaseDiscordClient client, - Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler) + Stream stream, string filename, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, RequestOptions options, bool isSpoiler, Embed[] embeds) { - var args = new UploadFileParams(stream) { Filename = filename, Content = text, IsTTS = isTTS, Embed = embed != null ? embed.ToModel() : Optional.Unspecified, IsSpoiler = isSpoiler }; + using (var file = new FileAttachment(stream, filename, isSpoiler: isSpoiler)) + return await SendFileAsync(channel, client, file, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds).ConfigureAwait(false); + } + + /// Message content is too long, length must be less or equal to . + public static Task SendFileAsync(IMessageChannel channel, BaseDiscordClient client, + FileAttachment attachment, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, RequestOptions options, Embed[] embeds) + => SendFilesAsync(channel, client, new[] { attachment }, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); + + public static async Task SendFilesAsync(IMessageChannel channel, BaseDiscordClient client, + IEnumerable attachments, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, RequestOptions options, Embed[] embeds) + { + embeds ??= Array.Empty(); + if (embed != null) + embeds = new[] { embed }.Concat(embeds).ToArray(); + + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed."); + + foreach(var attachment in attachments) + { + Preconditions.NotNullOrEmpty(attachment.FileName, nameof(attachment.FileName), "File Name must not be empty or null"); + } + + if (channel is ITextChannel guildTextChannel) + { + var contentSize = (ulong)attachments.Sum(x => x.Stream.Length); + + if (contentSize > guildTextChannel.Guild.MaxUploadLimit) + { + throw new ArgumentOutOfRangeException(nameof(attachments), $"Collective file size exceeds the max file size of {guildTextChannel.Guild.MaxUploadLimit} bytes in that guild!"); + } + } + + // check that user flag and user Id list are exclusive, same with role flag and role Id list + if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue) + { + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) && + allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) + { + throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions)); + } + + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) && + allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) + { + throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions)); + } + } + + if (stickers != null) + { + Preconditions.AtMost(stickers.Length, 3, nameof(stickers), "A max of 3 stickers are allowed."); + } + + var args = new UploadFileParams(attachments.ToArray()) { Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, MessageReference = messageReference?.ToModel() ?? Optional.Unspecified, MessageComponent = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified, Stickers = stickers?.Any() ?? false ? stickers.Select(x => x.Id).ToArray() : Optional.Unspecified }; var model = await client.ApiClient.UploadFileAsync(channel.Id, args, options).ConfigureAwait(false); return RestUserMessage.Create(client, channel, client.CurrentUser, model); } + public static async Task ModifyMessageAsync(IMessageChannel channel, ulong messageId, Action func, + BaseDiscordClient client, RequestOptions options) + { + var msgModel = await MessageHelper.ModifyAsync(channel.Id, messageId, client, func, options).ConfigureAwait(false); + return RestUserMessage.Create(client, channel, msgModel.Author.IsSpecified ? RestUser.Create(client, msgModel.Author.Value) : client.CurrentUser, msgModel); + } + public static Task DeleteMessageAsync(IMessageChannel channel, ulong messageId, BaseDiscordClient client, RequestOptions options) => MessageHelper.DeleteAsync(channel.Id, messageId, client, options); @@ -264,18 +445,19 @@ namespace Discord.Rest await client.ApiClient.DeleteMessagesAsync(channel.Id, args, options).ConfigureAwait(false); } } + #endregion - //Permission Overwrites + #region Permission Overwrites public static async Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, IUser user, OverwritePermissions perms, RequestOptions options) { - var args = new ModifyChannelPermissionsParams("member", perms.AllowValue, perms.DenyValue); + var args = new ModifyChannelPermissionsParams((int)PermissionTarget.User, perms.AllowValue.ToString(), perms.DenyValue.ToString()); await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, user.Id, args, options).ConfigureAwait(false); } public static async Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, IRole role, OverwritePermissions perms, RequestOptions options) { - var args = new ModifyChannelPermissionsParams("role", perms.AllowValue, perms.DenyValue); + var args = new ModifyChannelPermissionsParams((int)PermissionTarget.Role, perms.AllowValue.ToString(), perms.DenyValue.ToString()); await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, role.Id, args, options).ConfigureAwait(false); } public static async Task RemovePermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, @@ -288,8 +470,9 @@ namespace Discord.Rest { await client.ApiClient.DeleteChannelPermissionAsync(channel.Id, role.Id, options).ConfigureAwait(false); } + #endregion - //Users + #region Users /// Resolving permissions requires the parent guild to be downloaded. public static async Task GetUserAsync(IGuildChannel channel, IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) @@ -334,8 +517,9 @@ namespace Discord.Rest count: limit ); } + #endregion - //Typing + #region Typing public static async Task TriggerTypingAsync(IMessageChannel channel, BaseDiscordClient client, RequestOptions options = null) { @@ -344,8 +528,9 @@ namespace Discord.Rest public static IDisposable EnterTypingState(IMessageChannel channel, BaseDiscordClient client, RequestOptions options) => new TypingNotifier(channel, options); + #endregion - //Webhooks + #region Webhooks public static async Task CreateWebhookAsync(ITextChannel channel, BaseDiscordClient client, string name, Stream avatar, RequestOptions options) { var args = new CreateWebhookParams { Name = name }; @@ -368,7 +553,9 @@ namespace Discord.Rest return models.Select(x => RestWebhook.Create(client, channel, x)) .ToImmutableArray(); } - // Categories + #endregion + + #region Categories public static async Task GetCategoryAsync(INestedChannel channel, BaseDiscordClient client, RequestOptions options) { // if no category id specified, return null @@ -382,30 +569,22 @@ namespace Discord.Rest public static async Task SyncPermissionsAsync(INestedChannel channel, BaseDiscordClient client, RequestOptions options) { var category = await GetCategoryAsync(channel, client, options).ConfigureAwait(false); - if (category == null) throw new InvalidOperationException("This channel does not have a parent channel."); + if (category == null) + throw new InvalidOperationException("This channel does not have a parent channel."); var apiArgs = new ModifyGuildChannelParams { Overwrites = category.PermissionOverwrites - .Select(overwrite => new API.Overwrite{ + .Select(overwrite => new API.Overwrite + { TargetId = overwrite.TargetId, TargetType = overwrite.TargetType, - Allow = overwrite.Permissions.AllowValue, - Deny = overwrite.Permissions.DenyValue + Allow = overwrite.Permissions.AllowValue.ToString(), + Deny = overwrite.Permissions.DenyValue.ToString() }).ToArray() }; await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); } - - //Helpers - private static IUser GetAuthor(BaseDiscordClient client, IGuild guild, UserModel model, ulong? webhookId) - { - IUser author = null; - if (guild != null) - author = guild.GetUserAsync(model.Id, CacheMode.CacheOnly).Result; - if (author == null) - author = RestUser.Create(client, guild, model, webhookId); - return author; - } + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs b/src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs index 195fa92df..1af936a57 100644 --- a/src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs @@ -24,17 +24,21 @@ namespace Discord.Rest /// Specifies if notifications are sent for mentioned users and roles in the message . /// If null, all mentioned roles and users will be notified. /// + /// The message references to be included. Used to reply to specific messages. + /// The message components to be included with this message. Used for interactions. + /// A collection of stickers to send with the message. + /// A array of s to send with this response. Max 10. /// /// A task that represents an asynchronous send operation for delivering the message. The task result /// contains the sent message. /// - new Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null); + new Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null); /// /// Sends a file to this message channel with an optional caption. /// /// - /// This method follows the same behavior as described in - /// . Please visit + /// This method follows the same behavior as described in + /// . Please visit /// its documentation for more details on this method. /// /// The file path of the file. @@ -42,16 +46,25 @@ namespace Discord.Rest /// Whether the message should be read aloud by Discord or not. /// The to be sent. /// The options to be used when sending the request. + /// Whether the message attachment should be hidden as a spoiler. + /// + /// Specifies if notifications are sent for mentioned users and roles in the message . + /// If null, all mentioned roles and users will be notified. + /// + /// The message references to be included. Used to reply to specific messages. + /// The message components to be included with this message. Used for interactions. + /// A collection of stickers to send with the message. + /// A array of s to send with this response. Max 10. /// /// A task that represents an asynchronous send operation for delivering the message. The task result /// contains the sent message. /// - new Task SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false); + new Task SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null); /// /// Sends a file to this message channel with an optional caption. /// /// - /// This method follows the same behavior as described in . + /// This method follows the same behavior as described in . /// Please visit its documentation for more details on this method. /// /// The of the file to be sent. @@ -60,11 +73,20 @@ namespace Discord.Rest /// Whether the message should be read aloud by Discord or not. /// The to be sent. /// The options to be used when sending the request. + /// Whether the message attachment should be hidden as a spoiler. + /// + /// Specifies if notifications are sent for mentioned users and roles in the message . + /// If null, all mentioned roles and users will be notified. + /// + /// The message references to be included. Used to reply to specific messages. + /// The message components to be included with this message. Used for interactions. + /// A collection of stickers to send with the message. + /// A array of s to send with this response. Max 10. /// /// A task that represents an asynchronous send operation for delivering the message. The task result /// contains the sent message. /// - new Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false); + new Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null); /// /// Gets a message from this message channel. diff --git a/src/Discord.Net.Rest/Entities/Channels/RestCategoryChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestCategoryChannel.cs index 177bde21d..9f944501b 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestCategoryChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestCategoryChannel.cs @@ -12,6 +12,7 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestCategoryChannel : RestGuildChannel, ICategoryChannel { + #region RestCategoryChannel internal RestCategoryChannel(BaseDiscordClient discord, IGuild guild, ulong id) : base(discord, guild, id) { @@ -24,8 +25,9 @@ namespace Discord.Rest } private string DebuggerDisplay => $"{Name} ({Id}, Category)"; + #endregion - //IChannel + #region IChannel /// /// This method is not supported with category channels. IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) @@ -34,5 +36,6 @@ namespace Discord.Rest /// This method is not supported with category channels. Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => throw new NotSupportedException(); + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs index 6f6a1f0d3..83c6d8bfb 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs @@ -11,6 +11,7 @@ namespace Discord.Rest /// public class RestChannel : RestEntity, IChannel, IUpdateable { + #region RestChannel /// public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); @@ -21,40 +22,55 @@ namespace Discord.Rest /// Unexpected channel type. internal static RestChannel Create(BaseDiscordClient discord, Model model) { - switch (model.Type) + return model.Type switch { - case ChannelType.News: - case ChannelType.Text: - case ChannelType.Voice: - return RestGuildChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model); - case ChannelType.DM: - case ChannelType.Group: - return CreatePrivate(discord, model) as RestChannel; - case ChannelType.Category: - return RestCategoryChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model); - default: - return new RestChannel(discord, model.Id); - } + ChannelType.News or + ChannelType.Text or + ChannelType.Voice or + ChannelType.Stage or + ChannelType.NewsThread or + ChannelType.PrivateThread or + ChannelType.PublicThread + => RestGuildChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model), + ChannelType.DM or ChannelType.Group => CreatePrivate(discord, model) as RestChannel, + ChannelType.Category => RestCategoryChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model), + _ => new RestChannel(discord, model.Id), + }; + } + internal static RestChannel Create(BaseDiscordClient discord, Model model, IGuild guild) + { + return model.Type switch + { + ChannelType.News or + ChannelType.Text or + ChannelType.Voice or + ChannelType.Stage or + ChannelType.NewsThread or + ChannelType.PrivateThread or + ChannelType.PublicThread + => RestGuildChannel.Create(discord, guild, model), + ChannelType.DM or ChannelType.Group => CreatePrivate(discord, model) as RestChannel, + ChannelType.Category => RestCategoryChannel.Create(discord, guild, model), + _ => new RestChannel(discord, model.Id), + }; } /// Unexpected channel type. internal static IRestPrivateChannel CreatePrivate(BaseDiscordClient discord, Model model) { - switch (model.Type) + return model.Type switch { - case ChannelType.DM: - return RestDMChannel.Create(discord, model); - case ChannelType.Group: - return RestGroupChannel.Create(discord, model); - default: - throw new InvalidOperationException($"Unexpected channel type: {model.Type}"); - } + ChannelType.DM => RestDMChannel.Create(discord, model), + ChannelType.Group => RestGroupChannel.Create(discord, model), + _ => throw new InvalidOperationException($"Unexpected channel type: {model.Type}"), + }; } internal virtual void Update(Model model) { } /// public virtual Task UpdateAsync(RequestOptions options = null) => Task.Delay(0); + #endregion - //IChannel + #region IChannel /// string IChannel.Name => null; @@ -64,5 +80,6 @@ namespace Discord.Rest /// IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => AsyncEnumerable.Empty>(); //Overridden + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs index 732af2d81..36b190e56 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs @@ -15,6 +15,7 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestDMChannel : RestChannel, IDMChannel, IRestPrivateChannel, IRestMessageChannel { + #region RestDMChannel /// /// Gets the current logged-in user. /// @@ -93,8 +94,8 @@ namespace Discord.Rest /// /// Message content is too long, length must be less or equal to . - public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, allowedMentions, options); + public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); /// /// @@ -121,12 +122,22 @@ namespace Discord.Rest /// is in an invalid format. /// An I/O error occurred while opening the file. /// Message content is too long, length must be less or equal to . - public Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) - => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, options, isSpoiler); + public Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, isSpoiler, embeds); /// /// Message content is too long, length must be less or equal to . - public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) - => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options, isSpoiler); + public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, isSpoiler, embeds); + + /// + /// Message content is too long, length must be less or equal to . + public Task SendFileAsync(FileAttachment attachment, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, attachment, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); + + /// + /// Message content is too long, length must be less or equal to . + public Task SendFilesAsync(IEnumerable attachments, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFilesAsync(this, Discord, attachments, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); /// public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) @@ -135,6 +146,10 @@ namespace Discord.Rest public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) => ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); + /// + public async Task ModifyMessageAsync(ulong messageId, Action func, RequestOptions options = null) + => await ChannelHelper.ModifyMessageAsync(this, messageId, func, Discord, options).ConfigureAwait(false); + /// public Task TriggerTypingAsync(RequestOptions options = null) => ChannelHelper.TriggerTypingAsync(this, Discord, options); @@ -150,20 +165,24 @@ namespace Discord.Rest /// public override string ToString() => $"@{Recipient}"; private string DebuggerDisplay => $"@{Recipient} ({Id}, DM)"; + #endregion - //IDMChannel + #region IDMChannel /// IUser IDMChannel.Recipient => Recipient; + #endregion - //IRestPrivateChannel + #region IRestPrivateChannel /// IReadOnlyCollection IRestPrivateChannel.Recipients => ImmutableArray.Create(Recipient); + #endregion - //IPrivateChannel + #region IPrivateChannel /// IReadOnlyCollection IPrivateChannel.Recipients => ImmutableArray.Create(Recipient); + #endregion - //IMessageChannel + #region IMessageChannel /// async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { @@ -200,16 +219,23 @@ namespace Discord.Rest async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) => await GetPinnedMessagesAsync(options).ConfigureAwait(false); /// - async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler) - => await SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler).ConfigureAwait(false); + async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + /// + async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + /// + async Task IMessageChannel.SendFileAsync(FileAttachment attachment, string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(attachment, text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); /// - async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler) - => await SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler).ConfigureAwait(false); + async Task IMessageChannel.SendFilesAsync(IEnumerable attachments, string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFilesAsync(attachments, text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); /// - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions) - => await SendMessageAsync(text, isTTS, embed, options, allowedMentions).ConfigureAwait(false); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendMessageAsync(text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + #endregion - //IChannel + #region IChannel /// string IChannel.Name => $"@{Recipient}"; @@ -219,5 +245,6 @@ namespace Discord.Rest /// IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs index 3c21bd95f..03858fbbe 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs @@ -16,11 +16,14 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestGroupChannel : RestChannel, IGroupChannel, IRestPrivateChannel, IRestMessageChannel, IRestAudioChannel { + #region RestGroupChannel private string _iconId; private ImmutableDictionary _users; /// public string Name { get; private set; } + /// + public string RTCRegion { get; private set; } public IReadOnlyCollection Users => _users.ToReadOnlyCollection(); public IReadOnlyCollection Recipients @@ -45,6 +48,8 @@ namespace Discord.Rest if (model.Recipients.IsSpecified) UpdateUsers(model.Recipients.Value); + + RTCRegion = model.RTCRegion.GetValueOrDefault(null); } internal void UpdateUsers(API.User[] models) { @@ -93,10 +98,14 @@ namespace Discord.Rest public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) => ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); + /// + public async Task ModifyMessageAsync(ulong messageId, Action func, RequestOptions options = null) + => await ChannelHelper.ModifyMessageAsync(this, messageId, func, Discord, options).ConfigureAwait(false); + /// /// Message content is too long, length must be less or equal to . - public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, allowedMentions, options); + public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); /// /// @@ -123,13 +132,20 @@ namespace Discord.Rest /// is in an invalid format. /// An I/O error occurred while opening the file. /// Message content is too long, length must be less or equal to . - public Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) - => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, options, isSpoiler); + public Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, isSpoiler, embeds); /// /// Message content is too long, length must be less or equal to . - public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) - => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options, isSpoiler); - + public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, isSpoiler, embeds); + /// + /// Message content is too long, length must be less or equal to . + public Task SendFileAsync(FileAttachment attachment, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, attachment, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); + /// + /// Message content is too long, length must be less or equal to . + public Task SendFilesAsync(IEnumerable attachments, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFilesAsync(this, Discord, attachments, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); /// public Task TriggerTypingAsync(RequestOptions options = null) => ChannelHelper.TriggerTypingAsync(this, Discord, options); @@ -139,14 +155,17 @@ namespace Discord.Rest public override string ToString() => Name; private string DebuggerDisplay => $"{Name} ({Id}, Group)"; + #endregion - //ISocketPrivateChannel + #region ISocketPrivateChannel IReadOnlyCollection IRestPrivateChannel.Recipients => Recipients; + #endregion - //IPrivateChannel + #region IPrivateChannel IReadOnlyCollection IPrivateChannel.Recipients => Recipients; + #endregion - //IMessageChannel + #region IMessageChannel async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) @@ -178,25 +197,32 @@ namespace Discord.Rest async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) => await GetPinnedMessagesAsync(options).ConfigureAwait(false); - async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler) - => await SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler).ConfigureAwait(false); - - async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler) - => await SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler).ConfigureAwait(false); + async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions) - => await SendMessageAsync(text, isTTS, embed, options, allowedMentions).ConfigureAwait(false); + async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + async Task IMessageChannel.SendFileAsync(FileAttachment attachment, string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(attachment, text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + async Task IMessageChannel.SendFilesAsync(IEnumerable attachments, string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFilesAsync(attachments, text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendMessageAsync(text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + #endregion - //IAudioChannel + #region IAudioChannel /// /// Connecting to a group channel is not supported. Task IAudioChannel.ConnectAsync(bool selfDeaf, bool selfMute, bool external) { throw new NotSupportedException(); } Task IAudioChannel.DisconnectAsync() { throw new NotSupportedException(); } + Task IAudioChannel.ModifyAsync(Action func, RequestOptions options) { throw new NotSupportedException(); } + #endregion - //IChannel + #region IChannel Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs index fdfee39ea..bc9d4110a 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs @@ -12,6 +12,7 @@ namespace Discord.Rest /// public class RestGuildChannel : RestChannel, IGuildChannel { + #region RestGuildChannel private ImmutableArray _overwrites; /// @@ -32,30 +33,34 @@ namespace Discord.Rest } internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, Model model) { - switch (model.Type) + return model.Type switch { - case ChannelType.News: - return RestNewsChannel.Create(discord, guild, model); - case ChannelType.Text: - return RestTextChannel.Create(discord, guild, model); - case ChannelType.Voice: - return RestVoiceChannel.Create(discord, guild, model); - case ChannelType.Category: - return RestCategoryChannel.Create(discord, guild, model); - default: - return new RestGuildChannel(discord, guild, model.Id); - } + ChannelType.News => RestNewsChannel.Create(discord, guild, model), + ChannelType.Text => RestTextChannel.Create(discord, guild, model), + ChannelType.Voice => RestVoiceChannel.Create(discord, guild, model), + ChannelType.Stage => RestStageChannel.Create(discord, guild, model), + ChannelType.Category => RestCategoryChannel.Create(discord, guild, model), + ChannelType.PublicThread or ChannelType.PrivateThread or ChannelType.NewsThread => RestThreadChannel.Create(discord, guild, model), + _ => new RestGuildChannel(discord, guild, model.Id), + }; } internal override void Update(Model model) { Name = model.Name.Value; - Position = model.Position.Value; - var overwrites = model.PermissionOverwrites.Value; - var newOverwrites = ImmutableArray.CreateBuilder(overwrites.Length); - for (int i = 0; i < overwrites.Length; i++) - newOverwrites.Add(overwrites[i].ToEntity()); - _overwrites = newOverwrites.ToImmutable(); + if (model.Position.IsSpecified) + { + Position = model.Position.Value; + } + + if (model.PermissionOverwrites.IsSpecified) + { + var overwrites = model.PermissionOverwrites.Value; + var newOverwrites = ImmutableArray.CreateBuilder(overwrites.Length); + for (int i = 0; i < overwrites.Length; i++) + newOverwrites.Add(overwrites[i].ToEntity()); + _overwrites = newOverwrites.ToImmutable(); + } } /// @@ -187,8 +192,9 @@ namespace Discord.Rest /// A string that is the name of this channel. /// public override string ToString() => Name; + #endregion - //IGuildChannel + #region IGuildChannel /// IGuild IGuildChannel.Guild { @@ -225,13 +231,15 @@ namespace Discord.Rest /// Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(null); //Overridden in Text/Voice + #endregion - //IChannel + #region IChannel /// IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => AsyncEnumerable.Empty>(); //Overridden in Text/Voice /// Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(null); //Overridden in Text/Voice + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestNewsChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestNewsChannel.cs index 8a334fae5..fad3358dc 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestNewsChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestNewsChannel.cs @@ -12,7 +12,7 @@ namespace Discord.Rest /// Represents a REST-based news channel in a guild that has the same properties as a . /// [DebuggerDisplay(@"{DebuggerDisplay,nq}")] - public class RestNewsChannel : RestTextChannel + public class RestNewsChannel : RestTextChannel, INewsChannel { internal RestNewsChannel(BaseDiscordClient discord, IGuild guild, ulong id) :base(discord, guild, id) diff --git a/src/Discord.Net.Rest/Entities/Channels/RestStageChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestStageChannel.cs new file mode 100644 index 000000000..c01df96fd --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Channels/RestStageChannel.cs @@ -0,0 +1,150 @@ +using Discord.API; +using Discord.API.Rest; +using System; +using System.Threading.Tasks; +using Model = Discord.API.Channel; + +namespace Discord.Rest +{ + /// + /// Represents a REST-based stage channel in a guild. + /// + public class RestStageChannel : RestVoiceChannel, IStageChannel + { + /// + public string Topic { get; private set; } + + /// + public StagePrivacyLevel? PrivacyLevel { get; private set; } + + /// + public bool? IsDiscoverableDisabled { get; private set; } + + /// + public bool IsLive { get; private set; } + internal RestStageChannel(BaseDiscordClient discord, IGuild guild, ulong id) + : base(discord, guild, id) { } + + internal new static RestStageChannel Create(BaseDiscordClient discord, IGuild guild, Model model) + { + var entity = new RestStageChannel(discord, guild, model.Id); + entity.Update(model); + return entity; + } + + internal void Update(StageInstance model, bool isLive = false) + { + IsLive = isLive; + if(isLive) + { + Topic = model.Topic; + PrivacyLevel = model.PrivacyLevel; + IsDiscoverableDisabled = model.DiscoverableDisabled; + } + else + { + Topic = null; + PrivacyLevel = null; + IsDiscoverableDisabled = null; + } + } + + /// + public async Task ModifyInstanceAsync(Action func, RequestOptions options = null) + { + var model = await ChannelHelper.ModifyAsync(this, Discord, func, options); + + Update(model, true); + } + + /// + public async Task StartStageAsync(string topic, StagePrivacyLevel privacyLevel = StagePrivacyLevel.GuildOnly, RequestOptions options = null) + { + var args = new CreateStageInstanceParams + { + ChannelId = Id, + PrivacyLevel = privacyLevel, + Topic = topic + }; + + var model = await Discord.ApiClient.CreateStageInstanceAsync(args, options); + + Update(model, true); + } + + /// + public async Task StopStageAsync(RequestOptions options = null) + { + await Discord.ApiClient.DeleteStageInstanceAsync(Id, options); + + Update(null); + } + + /// + public override async Task UpdateAsync(RequestOptions options = null) + { + await base.UpdateAsync(options); + + var model = await Discord.ApiClient.GetStageInstanceAsync(Id, options); + + Update(model, model != null); + } + + /// + public Task RequestToSpeakAsync(RequestOptions options = null) + { + var args = new ModifyVoiceStateParams + { + ChannelId = Id, + RequestToSpeakTimestamp = DateTimeOffset.UtcNow + }; + return Discord.ApiClient.ModifyMyVoiceState(Guild.Id, args, options); + } + + /// + public Task BecomeSpeakerAsync(RequestOptions options = null) + { + var args = new ModifyVoiceStateParams + { + ChannelId = Id, + Suppressed = false + }; + return Discord.ApiClient.ModifyMyVoiceState(Guild.Id, args, options); + } + + /// + public Task StopSpeakingAsync(RequestOptions options = null) + { + var args = new ModifyVoiceStateParams + { + ChannelId = Id, + Suppressed = true + }; + return Discord.ApiClient.ModifyMyVoiceState(Guild.Id, args, options); + } + + /// + public Task MoveToSpeakerAsync(IGuildUser user, RequestOptions options = null) + { + var args = new ModifyVoiceStateParams + { + ChannelId = Id, + Suppressed = false + }; + + return Discord.ApiClient.ModifyUserVoiceState(Guild.Id, user.Id, args); + } + + /// + public Task RemoveFromSpeakerAsync(IGuildUser user, RequestOptions options = null) + { + var args = new ModifyVoiceStateParams + { + ChannelId = Id, + Suppressed = true + }; + + return Discord.ApiClient.ModifyUserVoiceState(Guild.Id, user.Id, args); + } + } +} diff --git a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs index cecd0a4d2..f1bdee65c 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs @@ -14,10 +14,11 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestTextChannel : RestGuildChannel, IRestMessageChannel, ITextChannel { + #region RestTextChannel /// public string Topic { get; private set; } /// - public virtual int SlowModeInterval { get; private set; } + public virtual int SlowModeInterval { get; private set; } /// public ulong? CategoryId { get; private set; } @@ -41,13 +42,14 @@ namespace Discord.Rest { base.Update(model); CategoryId = model.CategoryId; - Topic = model.Topic.Value; - SlowModeInterval = model.SlowMode.Value; + Topic = model.Topic.GetValueOrDefault(); + if (model.SlowMode.IsSpecified) + SlowModeInterval = model.SlowMode.Value; IsNsfw = model.Nsfw.GetValueOrDefault(); } /// - public async Task ModifyAsync(Action func, RequestOptions options = null) + public virtual async Task ModifyAsync(Action func, RequestOptions options = null) { var model = await ChannelHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); Update(model); @@ -77,7 +79,7 @@ namespace Discord.Rest /// /// /// A paged collection containing a collection of guild users that can access this channel. Flattening the - /// paginated response into a collection of users with + /// paginated response into a collection of users with /// is required if you wish to access the users. /// public IAsyncEnumerable> GetUsersAsync(RequestOptions options = null) @@ -101,8 +103,8 @@ namespace Discord.Rest /// /// Message content is too long, length must be less or equal to . - public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, allowedMentions, options); + public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); /// /// @@ -129,13 +131,23 @@ namespace Discord.Rest /// is in an invalid format. /// An I/O error occurred while opening the file. /// Message content is too long, length must be less or equal to . - public Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) - => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, options, isSpoiler); + public Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, isSpoiler, embeds); /// /// Message content is too long, length must be less or equal to . - public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) - => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options, isSpoiler); + public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, isSpoiler, embeds); + + /// + /// Message content is too long, length must be less or equal to . + public Task SendFileAsync(FileAttachment attachment, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, attachment, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); + + /// + /// Message content is too long, length must be less or equal to . + public Task SendFilesAsync(IEnumerable attachments, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFilesAsync(this, Discord, attachments, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); /// public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) @@ -151,6 +163,10 @@ namespace Discord.Rest public Task DeleteMessagesAsync(IEnumerable messageIds, RequestOptions options = null) => ChannelHelper.DeleteMessagesAsync(this, Discord, messageIds, options); + /// + public async Task ModifyMessageAsync(ulong messageId, Action func, RequestOptions options = null) + => await ChannelHelper.ModifyMessageAsync(this, messageId, func, Discord, options).ConfigureAwait(false); + /// public Task TriggerTypingAsync(RequestOptions options = null) => ChannelHelper.TriggerTypingAsync(this, Discord, options); @@ -168,7 +184,7 @@ namespace Discord.Rest /// A task that represents the asynchronous creation operation. The task result contains the newly created /// webhook. /// - public Task CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null) + public virtual Task CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null) => ChannelHelper.CreateWebhookAsync(this, Discord, name, avatar, options); /// /// Gets a webhook available in this text channel. @@ -179,7 +195,7 @@ namespace Discord.Rest /// A task that represents the asynchronous get operation. The task result contains a webhook associated /// with the identifier; null if the webhook is not found. /// - public Task GetWebhookAsync(ulong id, RequestOptions options = null) + public virtual Task GetWebhookAsync(ulong id, RequestOptions options = null) => ChannelHelper.GetWebhookAsync(this, Discord, id, options); /// /// Gets the webhooks available in this text channel. @@ -189,7 +205,7 @@ namespace Discord.Rest /// A task that represents the asynchronous get operation. The task result contains a read-only collection /// of webhooks that is available in this channel. /// - public Task> GetWebhooksAsync(RequestOptions options = null) + public virtual Task> GetWebhooksAsync(RequestOptions options = null) => ChannelHelper.GetWebhooksAsync(this, Discord, options); /// @@ -200,23 +216,69 @@ namespace Discord.Rest /// A task that represents the asynchronous get operation. The task result contains the category channel /// representing the parent of this channel; null if none is set. /// - public Task GetCategoryAsync(RequestOptions options = null) + public virtual Task GetCategoryAsync(RequestOptions options = null) => ChannelHelper.GetCategoryAsync(this, Discord, options); /// public Task SyncPermissionsAsync(RequestOptions options = null) => ChannelHelper.SyncPermissionsAsync(this, Discord, options); + #endregion - //Invites + #region Invites /// - public async Task CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + public virtual async Task CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); + public virtual async Task CreateInviteToApplicationAsync(ulong applicationId, int? maxAge = 86400, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => await ChannelHelper.CreateInviteToApplicationAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, applicationId, options); + /// + public virtual async Task CreateInviteToApplicationAsync(DefaultApplications application, int? maxAge = 86400, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => await ChannelHelper.CreateInviteToApplicationAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, (ulong)application, options); + public virtual Task CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => throw new NotImplementedException(); /// - public async Task> GetInvitesAsync(RequestOptions options = null) + public virtual async Task> GetInvitesAsync(RequestOptions options = null) => await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); private string DebuggerDisplay => $"{Name} ({Id}, Text)"; - //ITextChannel + /// + /// Creates a thread within this . + /// + /// + /// When is the thread type will be based off of the + /// channel its created in. When called on a , it creates a . + /// When called on a , it creates a . The id of the created + /// thread will be the same as the id of the message, and as such a message can only have a + /// single thread created from it. + /// + /// The name of the thread. + /// + /// The type of the thread. + /// + /// Note: This parameter is not used if the parameter is not specified. + /// + /// + /// + /// The duration on which this thread archives after. + /// + /// Note: Options and + /// are only available for guilds that are boosted. You can check in the to see if the + /// guild has the THREE_DAY_THREAD_ARCHIVE and SEVEN_DAY_THREAD_ARCHIVE. + /// + /// + /// The message which to start the thread from. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous create operation. The task result contains a + /// + public virtual async Task CreateThreadAsync(string name, ThreadType type = ThreadType.PublicThread, + ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, IMessage message = null, bool? invitable = null, int? slowmode = null, RequestOptions options = null) + { + var model = await ThreadHelper.CreateThreadAsync(Discord, this, name, type, autoArchiveDuration, message, invitable, slowmode, options); + return RestThreadChannel.Create(Discord, Guild, model); + } + #endregion + + #region ITextChannel /// async Task ITextChannel.CreateWebhookAsync(string name, Stream avatar, RequestOptions options) => await CreateWebhookAsync(name, avatar, options).ConfigureAwait(false); @@ -227,7 +289,11 @@ namespace Discord.Rest async Task> ITextChannel.GetWebhooksAsync(RequestOptions options) => await GetWebhooksAsync(options).ConfigureAwait(false); - //IMessageChannel + async Task ITextChannel.CreateThreadAsync(string name, ThreadType type, ThreadArchiveDuration autoArchiveDuration, IMessage message, bool? invitable, int? slowmode, RequestOptions options) + => await CreateThreadAsync(name, type, autoArchiveDuration, message, invitable, slowmode, options); + #endregion + + #region IMessageChannel /// async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { @@ -266,17 +332,27 @@ namespace Discord.Rest => await GetPinnedMessagesAsync(options).ConfigureAwait(false); /// - async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler) - => await SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler).ConfigureAwait(false); + async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); /// - async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler) - => await SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler).ConfigureAwait(false); + async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + + /// + async Task IMessageChannel.SendFileAsync(FileAttachment attachment, string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(attachment, text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + + /// + async Task IMessageChannel.SendFilesAsync(IEnumerable attachments, string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFilesAsync(attachments, text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + /// - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions) - => await SendMessageAsync(text, isTTS, embed, options, allowedMentions).ConfigureAwait(false); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendMessageAsync(text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + #endregion - //IGuildChannel + #region IGuildChannel /// async Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) { @@ -293,8 +369,9 @@ namespace Discord.Rest else return AsyncEnumerable.Empty>(); } + #endregion - //IChannel + #region IChannel /// async Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) { @@ -311,8 +388,9 @@ namespace Discord.Rest else return AsyncEnumerable.Empty>(); } + #endregion - // INestedChannel + #region INestedChannel /// async Task INestedChannel.GetCategoryAsync(CacheMode mode, RequestOptions options) { @@ -320,5 +398,6 @@ namespace Discord.Rest return (await Guild.GetChannelAsync(CategoryId.Value, mode, options).ConfigureAwait(false)) as ICategoryChannel; return null; } + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestThreadChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestThreadChannel.cs new file mode 100644 index 000000000..63071b9a5 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Channels/RestThreadChannel.cs @@ -0,0 +1,223 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.IO; +using System.Threading.Tasks; +using Model = Discord.API.Channel; + +namespace Discord.Rest +{ + /// + /// Represents a thread channel received over REST. + /// + public class RestThreadChannel : RestTextChannel, IThreadChannel + { + public ThreadType Type { get; private set; } + /// + public bool HasJoined { get; private set; } + + /// + public bool IsArchived { get; private set; } + + /// + public ThreadArchiveDuration AutoArchiveDuration { get; private set; } + + /// + public DateTimeOffset ArchiveTimestamp { get; private set; } + + /// + public bool IsLocked { get; private set; } + + /// + public int MemberCount { get; private set; } + + /// + public int MessageCount { get; private set; } + + /// + /// Gets the parent text channel id. + /// + public ulong ParentChannelId { get; private set; } + + internal RestThreadChannel(BaseDiscordClient discord, IGuild guild, ulong id) + : base(discord, guild, id) { } + + internal new static RestThreadChannel Create(BaseDiscordClient discord, IGuild guild, Model model) + { + var entity = new RestThreadChannel(discord, guild, model.Id); + entity.Update(model); + return entity; + } + + internal override void Update(Model model) + { + base.Update(model); + + HasJoined = model.ThreadMember.IsSpecified; + + if (model.ThreadMetadata.IsSpecified) + { + IsArchived = model.ThreadMetadata.Value.Archived; + AutoArchiveDuration = model.ThreadMetadata.Value.AutoArchiveDuration; + ArchiveTimestamp = model.ThreadMetadata.Value.ArchiveTimestamp; + IsLocked = model.ThreadMetadata.Value.Locked.GetValueOrDefault(false); + } + + MemberCount = model.MemberCount.GetValueOrDefault(0); + MessageCount = model.MessageCount.GetValueOrDefault(0); + Type = (ThreadType)model.Type; + ParentChannelId = model.CategoryId.Value; + } + + /// + /// Gets a user within this thread. + /// + /// The id of the user to fetch. + /// The options to be used when sending the request. + /// + /// A task representing the asynchronous get operation. The task returns a + /// if found, otherwise . + /// + public new Task GetUserAsync(ulong userId, RequestOptions options = null) + => ThreadHelper.GetUserAsync(userId, this, Discord, options); + + /// + /// Gets a collection of users within this thread. + /// + /// The options to be used when sending the request. + /// + /// A task representing the asynchronous get operation. The task returns a + /// of 's. + /// + public new async Task> GetUsersAsync(RequestOptions options = null) + => (await ThreadHelper.GetUsersAsync(this, Discord, options).ConfigureAwait(false)).ToImmutableArray(); + + /// + public override async Task ModifyAsync(Action func, RequestOptions options = null) + { + var model = await ThreadHelper.ModifyAsync(this, Discord, func, options); + Update(model); + } + + /// + /// + /// This method is not supported in threads. + /// + public override Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task GetCategoryAsync(RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task> GetInvitesAsync(RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override OverwritePermissions? GetPermissionOverwrite(IRole role) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override OverwritePermissions? GetPermissionOverwrite(IUser user) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task GetWebhookAsync(ulong id, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task> GetWebhooksAsync(RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override IReadOnlyCollection PermissionOverwrites + => throw new NotSupportedException("This method is not supported in threads."); + + /// + public Task JoinAsync(RequestOptions options = null) + => Discord.ApiClient.JoinThreadAsync(Id, options); + + /// + public Task LeaveAsync(RequestOptions options = null) + => Discord.ApiClient.LeaveThreadAsync(Id, options); + + /// + public Task AddUserAsync(IGuildUser user, RequestOptions options = null) + => Discord.ApiClient.AddThreadMemberAsync(Id, user.Id, options); + + /// + public Task RemoveUserAsync(IGuildUser user, RequestOptions options = null) + => Discord.ApiClient.RemoveThreadMemberAsync(Id, user.Id, options); + } +} diff --git a/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs index 3f3aa96c6..bcf03a5bc 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs @@ -14,12 +14,18 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestVoiceChannel : RestGuildChannel, IVoiceChannel, IRestAudioChannel { + #region RestVoiceChannel /// public int Bitrate { get; private set; } /// public int? UserLimit { get; private set; } /// public ulong? CategoryId { get; private set; } + /// + public string RTCRegion { get; private set; } + + /// + public string Mention => MentionUtils.MentionChannel(Id); internal RestVoiceChannel(BaseDiscordClient discord, IGuild guild, ulong id) : base(discord, guild, id) @@ -36,8 +42,14 @@ namespace Discord.Rest { base.Update(model); CategoryId = model.CategoryId; - Bitrate = model.Bitrate.Value; - UserLimit = model.UserLimit.Value != 0 ? model.UserLimit.Value : (int?)null; + + if(model.Bitrate.IsSpecified) + Bitrate = model.Bitrate.Value; + + if(model.UserLimit.IsSpecified) + UserLimit = model.UserLimit.Value != 0 ? model.UserLimit.Value : (int?)null; + + RTCRegion = model.RTCRegion.GetValueOrDefault(null); } /// @@ -60,32 +72,46 @@ namespace Discord.Rest /// public Task SyncPermissionsAsync(RequestOptions options = null) => ChannelHelper.SyncPermissionsAsync(this, Discord, options); - - //Invites + #endregion + + #region Invites /// public async Task CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); /// + public async Task CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => await ChannelHelper.CreateInviteToApplicationAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, applicationId, options).ConfigureAwait(false); + /// + public virtual async Task CreateInviteToApplicationAsync(DefaultApplications application, int? maxAge = 86400, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => await ChannelHelper.CreateInviteToApplicationAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, (ulong)application, options); + /// + public async Task CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => await ChannelHelper.CreateInviteToStreamAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, user, options).ConfigureAwait(false); + /// public async Task> GetInvitesAsync(RequestOptions options = null) => await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); private string DebuggerDisplay => $"{Name} ({Id}, Voice)"; + #endregion - //IAudioChannel + #region IAudioChannel /// /// Connecting to a REST-based channel is not supported. Task IAudioChannel.ConnectAsync(bool selfDeaf, bool selfMute, bool external) { throw new NotSupportedException(); } Task IAudioChannel.DisconnectAsync() { throw new NotSupportedException(); } + Task IAudioChannel.ModifyAsync(Action func, RequestOptions options) { throw new NotSupportedException(); } + #endregion - //IGuildChannel + #region IGuildChannel /// Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(null); /// IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => AsyncEnumerable.Empty>(); + #endregion - // INestedChannel + #region INestedChannel /// async Task INestedChannel.GetCategoryAsync(CacheMode mode, RequestOptions options) { @@ -93,5 +119,6 @@ namespace Discord.Rest return (await Guild.GetChannelAsync(CategoryId.Value, mode, options).ConfigureAwait(false)) as ICategoryChannel; return null; } + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs new file mode 100644 index 000000000..e0074ecff --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs @@ -0,0 +1,77 @@ +using Discord.API.Rest; +using System; +using System.Linq; +using System.Threading.Tasks; +using Model = Discord.API.Channel; + +namespace Discord.Rest +{ + internal static class ThreadHelper + { + public static async Task CreateThreadAsync(BaseDiscordClient client, ITextChannel channel, string name, ThreadType type = ThreadType.PublicThread, + ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, IMessage message = null, bool? invitable = null, int? slowmode = null, RequestOptions options = null) + { + var features = channel.Guild.Features; + if (autoArchiveDuration == ThreadArchiveDuration.OneWeek && !features.HasFeature(GuildFeature.SevenDayThreadArchive)) + throw new ArgumentException($"The guild {channel.Guild.Name} does not have the SEVEN_DAY_THREAD_ARCHIVE feature!", nameof(autoArchiveDuration)); + + if (autoArchiveDuration == ThreadArchiveDuration.ThreeDays && !features.HasFeature(GuildFeature.ThreeDayThreadArchive)) + throw new ArgumentException($"The guild {channel.Guild.Name} does not have the THREE_DAY_THREAD_ARCHIVE feature!", nameof(autoArchiveDuration)); + + if (type == ThreadType.PrivateThread && !features.HasFeature(GuildFeature.PrivateThreads)) + throw new ArgumentException($"The guild {channel.Guild.Name} does not have the PRIVATE_THREADS feature!", nameof(type)); + + if (channel is INewsChannel && type != ThreadType.NewsThread) + throw new ArgumentException($"{nameof(type)} must be a {ThreadType.NewsThread} in News channels"); + + var args = new StartThreadParams + { + Name = name, + Duration = autoArchiveDuration, + Type = type, + Invitable = invitable.HasValue ? invitable.Value : Optional.Unspecified, + Ratelimit = slowmode.HasValue ? slowmode.Value : Optional.Unspecified, + }; + + Model model; + + if (message != null) + model = await client.ApiClient.StartThreadAsync(channel.Id, message.Id, args, options).ConfigureAwait(false); + else + model = await client.ApiClient.StartThreadAsync(channel.Id, args, options).ConfigureAwait(false); + + return model; + } + + public static async Task ModifyAsync(IThreadChannel channel, BaseDiscordClient client, + Action func, + RequestOptions options) + { + var args = new TextChannelProperties(); + func(args); + var apiArgs = new ModifyThreadParams + { + Name = args.Name, + Archived = args.Archived, + AutoArchiveDuration = args.AutoArchiveDuration, + Locked = args.Locked, + Slowmode = args.SlowModeInterval + }; + return await client.ApiClient.ModifyThreadAsync(channel.Id, apiArgs, options).ConfigureAwait(false); + } + + public static async Task GetUsersAsync(IThreadChannel channel, BaseDiscordClient client, RequestOptions options = null) + { + var users = await client.ApiClient.ListThreadMembersAsync(channel.Id, options); + + return users.Select(x => RestThreadUser.Create(client, channel.Guild, x, channel)).ToArray(); + } + + public static async Task GetUserAsync(ulong userId, IThreadChannel channel, BaseDiscordClient client, RequestOptions options = null) + { + var model = await client.ApiClient.GetThreadMemberAsync(channel.Id, userId, options).ConfigureAwait(false); + + return RestThreadUser.Create(client, channel.Guild, model, channel); + } + } +} diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index 790b1e5c3..ff16c31f1 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -4,16 +4,17 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using System.Threading.Tasks; -using EmbedModel = Discord.API.GuildEmbed; +using WidgetModel = Discord.API.GuildWidget; using Model = Discord.API.Guild; using RoleModel = Discord.API.Role; using ImageModel = Discord.API.Image; +using System.IO; namespace Discord.Rest { internal static class GuildHelper { - //General + #region General /// is null. public static async Task ModifyAsync(IGuild guild, BaseDiscordClient client, Action func, RequestOptions options) @@ -35,7 +36,8 @@ namespace Discord.Rest Banner = args.Banner.IsSpecified ? args.Banner.Value?.ToModel() : Optional.Create(), VerificationLevel = args.VerificationLevel, ExplicitContentFilter = args.ExplicitContentFilter, - SystemChannelFlags = args.SystemChannelFlags + SystemChannelFlags = args.SystemChannelFlags, + IsBoostProgressBarEnabled = args.IsBoostProgressBarEnabled }; if (args.AfkChannel.IsSpecified) @@ -80,14 +82,15 @@ namespace Discord.Rest return await client.ApiClient.ModifyGuildAsync(guild.Id, apiArgs, options).ConfigureAwait(false); } /// is null. - public static async Task ModifyEmbedAsync(IGuild guild, BaseDiscordClient client, - Action func, RequestOptions options) + public static async Task ModifyWidgetAsync(IGuild guild, BaseDiscordClient client, + Action func, RequestOptions options) { - if (func == null) throw new ArgumentNullException(nameof(func)); + if (func == null) + throw new ArgumentNullException(nameof(func)); - var args = new GuildEmbedProperties(); + var args = new GuildWidgetProperties(); func(args); - var apiArgs = new API.Rest.ModifyGuildEmbedParams + var apiArgs = new API.Rest.ModifyGuildWidgetParams { Enabled = args.Enabled }; @@ -97,7 +100,7 @@ namespace Discord.Rest else if (args.ChannelId.IsSpecified) apiArgs.ChannelId = args.ChannelId.Value; - return await client.ApiClient.ModifyGuildEmbedAsync(guild.Id, apiArgs, options).ConfigureAwait(false); + return await client.ApiClient.ModifyGuildWidgetAsync(guild.Id, apiArgs, options).ConfigureAwait(false); } public static async Task ReorderChannelsAsync(IGuild guild, BaseDiscordClient client, IEnumerable args, RequestOptions options) @@ -121,8 +124,18 @@ namespace Discord.Rest { await client.ApiClient.DeleteGuildAsync(guild.Id, options).ConfigureAwait(false); } + public static ulong GetUploadLimit(IGuild guild) + { + return guild.PremiumTier switch + { + PremiumTier.Tier2 => 50ul * 1000000, + PremiumTier.Tier3 => 100ul * 1000000, + _ => 8ul * 1000000 + }; + } + #endregion - //Bans + #region Bans public static async Task> GetBansAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) { @@ -132,7 +145,7 @@ namespace Discord.Rest public static async Task GetBanAsync(IGuild guild, BaseDiscordClient client, ulong userId, RequestOptions options) { var model = await client.ApiClient.GetGuildBanAsync(guild.Id, userId, options).ConfigureAwait(false); - return RestBan.Create(client, model); + return model == null ? null : RestBan.Create(client, model); } public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client, @@ -146,8 +159,9 @@ namespace Discord.Rest { await client.ApiClient.RemoveGuildBanAsync(guild.Id, userId, options).ConfigureAwait(false); } + #endregion - //Channels + #region Channels public static async Task GetChannelAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) { @@ -176,7 +190,17 @@ namespace Discord.Rest CategoryId = props.CategoryId, Topic = props.Topic, IsNsfw = props.IsNsfw, - Position = props.Position + Position = props.Position, + SlowModeInterval = props.SlowModeInterval, + Overwrites = props.PermissionOverwrites.IsSpecified + ? props.PermissionOverwrites.Value.Select(overwrite => new API.Overwrite + { + TargetId = overwrite.TargetId, + TargetType = overwrite.TargetType, + Allow = overwrite.Permissions.AllowValue.ToString(), + Deny = overwrite.Permissions.DenyValue.ToString() + }).ToArray() + : Optional.Create(), }; var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return RestTextChannel.Create(client, guild, model); @@ -195,11 +219,48 @@ namespace Discord.Rest CategoryId = props.CategoryId, Bitrate = props.Bitrate, UserLimit = props.UserLimit, - Position = props.Position + Position = props.Position, + Overwrites = props.PermissionOverwrites.IsSpecified + ? props.PermissionOverwrites.Value.Select(overwrite => new API.Overwrite + { + TargetId = overwrite.TargetId, + TargetType = overwrite.TargetType, + Allow = overwrite.Permissions.AllowValue.ToString(), + Deny = overwrite.Permissions.DenyValue.ToString() + }).ToArray() + : Optional.Create(), }; var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return RestVoiceChannel.Create(client, guild, model); } + public static async Task CreateStageChannelAsync(IGuild guild, BaseDiscordClient client, + string name, RequestOptions options, Action func = null) + { + if (name == null) + throw new ArgumentNullException(paramName: nameof(name)); + + var props = new VoiceChannelProperties(); + func?.Invoke(props); + + var args = new CreateGuildChannelParams(name, ChannelType.Stage) + { + CategoryId = props.CategoryId, + Bitrate = props.Bitrate, + UserLimit = props.UserLimit, + Position = props.Position, + Overwrites = props.PermissionOverwrites.IsSpecified + ? props.PermissionOverwrites.Value.Select(overwrite => new API.Overwrite + { + TargetId = overwrite.TargetId, + TargetType = overwrite.TargetType, + Allow = overwrite.Permissions.AllowValue.ToString(), + Deny = overwrite.Permissions.DenyValue.ToString() + }).ToArray() + : Optional.Create(), + }; + var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); + return RestStageChannel.Create(client, guild, model); + } /// is null. public static async Task CreateCategoryChannelAsync(IGuild guild, BaseDiscordClient client, string name, RequestOptions options, Action func = null) @@ -211,22 +272,33 @@ namespace Discord.Rest var args = new CreateGuildChannelParams(name, ChannelType.Category) { - Position = props.Position + Position = props.Position, + Overwrites = props.PermissionOverwrites.IsSpecified + ? props.PermissionOverwrites.Value.Select(overwrite => new API.Overwrite + { + TargetId = overwrite.TargetId, + TargetType = overwrite.TargetType, + Allow = overwrite.Permissions.AllowValue.ToString(), + Deny = overwrite.Permissions.DenyValue.ToString() + }).ToArray() + : Optional.Create(), }; var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return RestCategoryChannel.Create(client, guild, model); } + #endregion - //Voice Regions + #region Voice Regions public static async Task> GetVoiceRegionsAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) { var models = await client.ApiClient.GetGuildVoiceRegionsAsync(guild.Id, options).ConfigureAwait(false); return models.Select(x => RestVoiceRegion.Create(client, x)).ToImmutableArray(); } + #endregion - //Integrations + #region Integrations public static async Task> GetIntegrationsAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) { @@ -240,8 +312,24 @@ namespace Discord.Rest var model = await client.ApiClient.CreateGuildIntegrationAsync(guild.Id, args, options).ConfigureAwait(false); return RestGuildIntegration.Create(client, guild, model); } + #endregion - //Invites + #region Interactions + public static async Task> GetSlashCommandsAsync(IGuild guild, BaseDiscordClient client, + RequestOptions options) + { + var models = await client.ApiClient.GetGuildApplicationCommandsAsync(guild.Id, options); + return models.Select(x => RestGuildCommand.Create(client, x, guild.Id)).ToImmutableArray(); + } + public static async Task GetSlashCommandAsync(IGuild guild, ulong id, BaseDiscordClient client, + RequestOptions options) + { + var model = await client.ApiClient.GetGuildApplicationCommandAsync(guild.Id, id, options); + return RestGuildCommand.Create(client, model, guild.Id); + } + #endregion + + #region Invites public static async Task> GetInvitesAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) { @@ -254,32 +342,34 @@ namespace Discord.Rest var vanityModel = await client.ApiClient.GetVanityInviteAsync(guild.Id, options).ConfigureAwait(false); if (vanityModel == null) throw new InvalidOperationException("This guild does not have a vanity URL."); var inviteModel = await client.ApiClient.GetInviteAsync(vanityModel.Code, options).ConfigureAwait(false); + inviteModel.Uses = vanityModel.Uses; return RestInviteMetadata.Create(client, guild, null, inviteModel); } + #endregion - //Roles + #region Roles /// is null. public static async Task CreateRoleAsync(IGuild guild, BaseDiscordClient client, string name, GuildPermissions? permissions, Color? color, bool isHoisted, bool isMentionable, RequestOptions options) { if (name == null) throw new ArgumentNullException(paramName: nameof(name)); - var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id, options).ConfigureAwait(false); - var role = RestRole.Create(client, guild, model); - - await role.ModifyAsync(x => + var createGuildRoleParams = new API.Rest.ModifyGuildRoleParams { - x.Name = name; - x.Permissions = (permissions ?? role.Permissions); - x.Color = (color ?? Color.Default); - x.Hoist = isHoisted; - x.Mentionable = isMentionable; - }, options).ConfigureAwait(false); + Color = color?.RawValue ?? Optional.Create(), + Hoist = isHoisted, + Mentionable = isMentionable, + Name = name, + Permissions = permissions?.RawValue.ToString() ?? Optional.Create() + }; + + var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id, createGuildRoleParams, options).ConfigureAwait(false); - return role; + return RestRole.Create(client, guild, model); } + #endregion - //Users + #region Users public static async Task AddGuildUserAsync(IGuild guild, BaseDiscordClient client, ulong userId, string accessToken, Action func, RequestOptions options) { @@ -377,9 +467,9 @@ namespace Discord.Rest ); } public static async Task PruneUsersAsync(IGuild guild, BaseDiscordClient client, - int days, bool simulate, RequestOptions options) + int days, bool simulate, RequestOptions options, IEnumerable includeRoleIds) { - var args = new GuildPruneParams(days); + var args = new GuildPruneParams(days, includeRoleIds?.ToArray()); GetGuildPruneCountResponse model; if (simulate) model = await client.ApiClient.GetGuildPruneCountAsync(guild.Id, args, options).ConfigureAwait(false); @@ -387,8 +477,20 @@ namespace Discord.Rest model = await client.ApiClient.BeginGuildPruneAsync(guild.Id, args, options).ConfigureAwait(false); return model.Pruned; } + public static async Task> SearchUsersAsync(IGuild guild, BaseDiscordClient client, + string query, int? limit, RequestOptions options) + { + var apiArgs = new SearchGuildMembersParams + { + Query = query, + Limit = limit ?? Optional.Create() + }; + var models = await client.ApiClient.SearchGuildMembersAsync(guild.Id, apiArgs, options).ConfigureAwait(false); + return models.Select(x => RestGuildUser.Create(client, guild, x)).ToImmutableArray(); + } + #endregion - // Audit logs + #region Audit logs public static IAsyncEnumerable> GetAuditLogsAsync(IGuild guild, BaseDiscordClient client, ulong? from, int? limit, RequestOptions options, ulong? userId = null, ActionType? actionType = null) { @@ -420,8 +522,9 @@ namespace Discord.Rest count: limit ); } + #endregion - //Webhooks + #region Webhooks public static async Task GetWebhookAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) { var model = await client.ApiClient.GetWebhookAsync(id, options: options).ConfigureAwait(false); @@ -434,14 +537,20 @@ namespace Discord.Rest var models = await client.ApiClient.GetGuildWebhooksAsync(guild.Id, options).ConfigureAwait(false); return models.Select(x => RestWebhook.Create(client, guild, x)).ToImmutableArray(); } + #endregion - //Emotes + #region Emotes + public static async Task> GetEmotesAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) + { + var models = await client.ApiClient.GetGuildEmotesAsync(guild.Id, options).ConfigureAwait(false); + return models.Select(x => x.ToEntity()).ToImmutableArray(); + } public static async Task GetEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) { var emote = await client.ApiClient.GetGuildEmoteAsync(guild.Id, id, options).ConfigureAwait(false); return emote.ToEntity(); } - public static async Task CreateEmoteAsync(IGuild guild, BaseDiscordClient client, string name, Image image, Optional> roles, + public static async Task CreateEmoteAsync(IGuild guild, BaseDiscordClient client, string name, Image image, Optional> roles, RequestOptions options) { var apiargs = new CreateGuildEmoteParams @@ -456,7 +565,7 @@ namespace Discord.Rest return emote.ToEntity(); } /// is null. - public static async Task ModifyEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, Action func, + public static async Task ModifyEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, Action func, RequestOptions options) { if (func == null) throw new ArgumentNullException(paramName: nameof(func)); @@ -474,7 +583,310 @@ namespace Discord.Rest var emote = await client.ApiClient.ModifyGuildEmoteAsync(guild.Id, id, apiargs, options).ConfigureAwait(false); return emote.ToEntity(); } - public static Task DeleteEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) + public static Task DeleteEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) => client.ApiClient.DeleteGuildEmoteAsync(guild.Id, id, options); + + public static async Task CreateStickerAsync(BaseDiscordClient client, IGuild guild, string name, string description, IEnumerable tags, + Image image, RequestOptions options = null) + { + Preconditions.NotNull(name, nameof(name)); + Preconditions.NotNull(description, nameof(description)); + + Preconditions.AtLeast(name.Length, 2, nameof(name)); + Preconditions.AtLeast(description.Length, 2, nameof(description)); + + Preconditions.AtMost(name.Length, 30, nameof(name)); + Preconditions.AtMost(description.Length, 100, nameof(name)); + + var apiArgs = new CreateStickerParams() + { + Name = name, + Description = description, + File = image.Stream, + Tags = string.Join(", ", tags) + }; + + return await client.ApiClient.CreateGuildStickerAsync(apiArgs, guild.Id, options).ConfigureAwait(false); + } + + public static async Task CreateStickerAsync(BaseDiscordClient client, IGuild guild, string name, string description, IEnumerable tags, + Stream file, string filename, RequestOptions options = null) + { + Preconditions.NotNull(name, nameof(name)); + Preconditions.NotNull(description, nameof(description)); + Preconditions.NotNull(file, nameof(file)); + Preconditions.NotNull(filename, nameof(filename)); + + Preconditions.AtLeast(name.Length, 2, nameof(name)); + Preconditions.AtLeast(description.Length, 2, nameof(description)); + + Preconditions.AtMost(name.Length, 30, nameof(name)); + Preconditions.AtMost(description.Length, 100, nameof(name)); + + var apiArgs = new CreateStickerParams() + { + Name = name, + Description = description, + File = file, + Tags = string.Join(", ", tags), + FileName = filename + }; + + return await client.ApiClient.CreateGuildStickerAsync(apiArgs, guild.Id, options).ConfigureAwait(false); + } + + public static async Task ModifyStickerAsync(BaseDiscordClient client, ulong guildId, ISticker sticker, Action func, + RequestOptions options = null) + { + if (func == null) + throw new ArgumentNullException(paramName: nameof(func)); + + var props = new StickerProperties(); + func(props); + + var apiArgs = new ModifyStickerParams() + { + Description = props.Description, + Name = props.Name, + Tags = props.Tags.IsSpecified ? + string.Join(", ", props.Tags.Value) : + Optional.Unspecified + }; + + return await client.ApiClient.ModifyStickerAsync(apiArgs, guildId, sticker.Id, options).ConfigureAwait(false); + } + + public static async Task DeleteStickerAsync(BaseDiscordClient client, ulong guildId, ISticker sticker, RequestOptions options = null) + => await client.ApiClient.DeleteStickerAsync(guildId, sticker.Id, options).ConfigureAwait(false); + #endregion + + #region Events + + public static async Task> GetEventUsersAsync(BaseDiscordClient client, IGuildScheduledEvent guildEvent, int limit = 100, RequestOptions options = null) + { + var models = await client.ApiClient.GetGuildScheduledEventUsersAsync(guildEvent.Id, guildEvent.Guild.Id, limit, options).ConfigureAwait(false); + + return models.Select(x => RestUser.Create(client, guildEvent.Guild, x)).ToImmutableArray(); + } + + public static IAsyncEnumerable> GetEventUsersAsync(BaseDiscordClient client, IGuildScheduledEvent guildEvent, + ulong? fromUserId, int? limit, RequestOptions options) + { + return new PagedAsyncEnumerable( + DiscordConfig.MaxGuildEventUsersPerBatch, + async (info, ct) => + { + var args = new GetEventUsersParams + { + Limit = info.PageSize, + RelativeDirection = Direction.After, + }; + if (info.Position != null) + args.RelativeUserId = info.Position.Value; + var models = await client.ApiClient.GetGuildScheduledEventUsersAsync(guildEvent.Id, guildEvent.Guild.Id, args, options).ConfigureAwait(false); + return models + .Select(x => RestUser.Create(client, guildEvent.Guild, x)) + .ToImmutableArray(); + }, + nextPage: (info, lastPage) => + { + if (lastPage.Count != DiscordConfig.MaxGuildEventUsersPerBatch) + return false; + info.Position = lastPage.Max(x => x.Id); + return true; + }, + start: fromUserId, + count: limit + ); + } + + public static IAsyncEnumerable> GetEventUsersAsync(BaseDiscordClient client, IGuildScheduledEvent guildEvent, + ulong? fromUserId, Direction dir, int limit, RequestOptions options = null) + { + if (dir == Direction.Around && limit > DiscordConfig.MaxMessagesPerBatch) + { + int around = limit / 2; + if (fromUserId.HasValue) + return GetEventUsersAsync(client, guildEvent, fromUserId.Value + 1, Direction.Before, around + 1, options) //Need to include the message itself + .Concat(GetEventUsersAsync(client, guildEvent, fromUserId, Direction.After, around, options)); + else //Shouldn't happen since there's no public overload for ulong? and Direction + return GetEventUsersAsync(client, guildEvent, null, Direction.Before, around + 1, options); + } + + return new PagedAsyncEnumerable( + DiscordConfig.MaxGuildEventUsersPerBatch, + async (info, ct) => + { + var args = new GetEventUsersParams + { + RelativeDirection = dir, + Limit = info.PageSize + }; + if (info.Position != null) + args.RelativeUserId = info.Position.Value; + + var models = await client.ApiClient.GetGuildScheduledEventUsersAsync(guildEvent.Id, guildEvent.Guild.Id, args, options).ConfigureAwait(false); + var builder = ImmutableArray.CreateBuilder(); + foreach (var model in models) + { + builder.Add(RestUser.Create(client, guildEvent.Guild, model)); + } + return builder.ToImmutable(); + }, + nextPage: (info, lastPage) => + { + if (lastPage.Count != DiscordConfig.MaxGuildEventUsersPerBatch) + return false; + if (dir == Direction.Before) + info.Position = lastPage.Min(x => x.Id); + else + info.Position = lastPage.Max(x => x.Id); + return true; + }, + start: fromUserId, + count: limit + ); + } + + public static async Task ModifyGuildEventAsync(BaseDiscordClient client, Action func, + IGuildScheduledEvent guildEvent, RequestOptions options = null) + { + var args = new GuildScheduledEventsProperties(); + + func(args); + + if (args.Status.IsSpecified) + { + switch (args.Status.Value) + { + case GuildScheduledEventStatus.Active when guildEvent.Status != GuildScheduledEventStatus.Scheduled: + case GuildScheduledEventStatus.Completed when guildEvent.Status != GuildScheduledEventStatus.Active: + case GuildScheduledEventStatus.Cancelled when guildEvent.Status != GuildScheduledEventStatus.Scheduled: + throw new ArgumentException($"Cannot set event to {args.Status.Value} when events status is {guildEvent.Status}"); + } + } + + if (args.Type.IsSpecified) + { + // taken from https://discord.com/developers/docs/resources/guild-scheduled-event#modify-guild-scheduled-event + switch (args.Type.Value) + { + case GuildScheduledEventType.External: + if (!args.Location.IsSpecified) + throw new ArgumentException("Location must be specified for external events."); + if (!args.EndTime.IsSpecified) + throw new ArgumentException("End time must be specified for external events."); + if (!args.ChannelId.IsSpecified) + throw new ArgumentException("Channel id must be set to null!"); + if (args.ChannelId.Value != null) + throw new ArgumentException("Channel id must be set to null!"); + break; + } + } + + var apiArgs = new ModifyGuildScheduledEventParams() + { + ChannelId = args.ChannelId, + Description = args.Description, + EndTime = args.EndTime, + Name = args.Name, + PrivacyLevel = args.PrivacyLevel, + StartTime = args.StartTime, + Status = args.Status, + Type = args.Type + }; + + if(args.Location.IsSpecified) + { + apiArgs.EntityMetadata = new API.GuildScheduledEventEntityMetadata() + { + Location = args.Location, + }; + } + + return await client.ApiClient.ModifyGuildScheduledEventAsync(apiArgs, guildEvent.Id, guildEvent.Guild.Id, options).ConfigureAwait(false); + } + + public static async Task GetGuildEventAsync(BaseDiscordClient client, ulong id, IGuild guild, RequestOptions options = null) + { + var model = await client.ApiClient.GetGuildScheduledEventAsync(id, guild.Id, options).ConfigureAwait(false); + + if (model == null) + return null; + + return RestGuildEvent.Create(client, guild, model); + } + + public static async Task> GetGuildEventsAsync(BaseDiscordClient client, IGuild guild, RequestOptions options = null) + { + var models = await client.ApiClient.ListGuildScheduledEventsAsync(guild.Id, options).ConfigureAwait(false); + + return models.Select(x => RestGuildEvent.Create(client, guild, x)).ToImmutableArray(); + } + + public static async Task CreateGuildEventAsync(BaseDiscordClient client, IGuild guild, + string name, + GuildScheduledEventPrivacyLevel privacyLevel, + DateTimeOffset startTime, + GuildScheduledEventType type, + string description = null, + DateTimeOffset? endTime = null, + ulong? channelId = null, + string location = null, + RequestOptions options = null) + { + if(location != null) + { + Preconditions.AtMost(location.Length, 100, nameof(location)); + } + + switch (type) + { + case GuildScheduledEventType.Stage or GuildScheduledEventType.Voice when channelId == null: + throw new ArgumentException($"{nameof(channelId)} must not be null when type is {type}", nameof(channelId)); + case GuildScheduledEventType.External when channelId != null: + throw new ArgumentException($"{nameof(channelId)} must be null when using external event type", nameof(channelId)); + case GuildScheduledEventType.External when location == null: + throw new ArgumentException($"{nameof(location)} must not be null when using external event type", nameof(location)); + case GuildScheduledEventType.External when endTime == null: + throw new ArgumentException($"{nameof(endTime)} must not be null when using external event type", nameof(endTime)); + } + + if (startTime <= DateTimeOffset.Now) + throw new ArgumentOutOfRangeException(nameof(startTime), "The start time for an event cannot be in the past"); + + if (endTime != null && endTime <= startTime) + throw new ArgumentOutOfRangeException(nameof(endTime), $"{nameof(endTime)} cannot be before the start time"); + + var apiArgs = new CreateGuildScheduledEventParams() + { + ChannelId = channelId ?? Optional.Unspecified, + Description = description ?? Optional.Unspecified, + EndTime = endTime ?? Optional.Unspecified, + Name = name, + PrivacyLevel = privacyLevel, + StartTime = startTime, + Type = type + }; + + if(location != null) + { + apiArgs.EntityMetadata = new API.GuildScheduledEventEntityMetadata() + { + Location = location + }; + } + + var model = await client.ApiClient.CreateGuildScheduledEventAsync(apiArgs, guild.Id, options).ConfigureAwait(false); + + return RestGuildEvent.Create(client, guild, client.CurrentUser, model); + } + + public static async Task DeleteEventAsync(BaseDiscordClient client, IGuildScheduledEvent guildEvent, RequestOptions options = null) + { + await client.ApiClient.DeleteGuildScheduledEventAsync(guildEvent.Id, guildEvent.Guild.Id, options).ConfigureAwait(false); + } + + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestBan.cs b/src/Discord.Net.Rest/Entities/Guilds/RestBan.cs index ec8f60ae5..d77d3b626 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestBan.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestBan.cs @@ -9,6 +9,7 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestBan : IBan { + #region RestBan /// /// Gets the banned user. /// @@ -37,9 +38,11 @@ namespace Discord.Rest /// public override string ToString() => User.ToString(); private string DebuggerDisplay => $"{User}: {Reason}"; +#endregion - //IBan + #region IBan /// IUser IBan.User => User; + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index 900f5045e..d90372636 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -6,8 +6,9 @@ using System.Diagnostics; using System.Globalization; using System.Linq; using System.Threading.Tasks; -using EmbedModel = Discord.API.GuildEmbed; +using WidgetModel = Discord.API.GuildWidget; using Model = Discord.API.Guild; +using System.IO; namespace Discord.Rest { @@ -17,16 +18,17 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestGuild : RestEntity, IGuild, IUpdateable { + #region RestGuild private ImmutableDictionary _roles; private ImmutableArray _emotes; - private ImmutableArray _features; + private ImmutableArray _stickers; /// public string Name { get; private set; } /// public int AFKTimeout { get; private set; } /// - public bool IsEmbeddable { get; private set; } + public bool IsWidgetEnabled { get; private set; } /// public VerificationLevel VerificationLevel { get; private set; } /// @@ -39,10 +41,14 @@ namespace Discord.Rest /// public ulong? AFKChannelId { get; private set; } /// - public ulong? EmbedChannelId { get; private set; } + public ulong? WidgetChannelId { get; private set; } /// public ulong? SystemChannelId { get; private set; } /// + public ulong? RulesChannelId { get; private set; } + /// + public ulong? PublicUpdatesChannelId { get; private set; } + /// public ulong OwnerId { get; private set; } /// public string VoiceRegionId { get; private set; } @@ -50,6 +56,8 @@ namespace Discord.Rest public string IconId { get; private set; } /// public string SplashId { get; private set; } + /// + public string DiscoverySplashId { get; private set; } internal bool Available { get; private set; } /// public ulong? ApplicationId { get; private set; } @@ -67,21 +75,53 @@ namespace Discord.Rest public int PremiumSubscriptionCount { get; private set; } /// public string PreferredLocale { get; private set; } - + /// + public int? MaxPresences { get; private set; } + /// + public int? MaxMembers { get; private set; } + /// + public int? MaxVideoChannelUsers { get; private set; } + /// + public int? ApproximateMemberCount { get; private set; } + /// + public int? ApproximatePresenceCount { get; private set; } + /// + public int MaxBitrate + { + get + { + return PremiumTier switch + { + PremiumTier.Tier1 => 128000, + PremiumTier.Tier2 => 256000, + PremiumTier.Tier3 => 384000, + _ => 96000, + }; + } + } + /// + public ulong MaxUploadLimit + => GuildHelper.GetUploadLimit(this); + /// + public NsfwLevel NsfwLevel { get; private set; } + /// + public bool IsBoostProgressBarEnabled { get; private set; } /// public CultureInfo PreferredCulture { get; private set; } + /// + public GuildFeatures Features { get; private set; } /// public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); - [Obsolete("DefaultChannelId is deprecated, use GetDefaultChannelAsync")] - public ulong DefaultChannelId => Id; /// public string IconUrl => CDN.GetGuildIconUrl(Id, IconId); /// public string SplashUrl => CDN.GetGuildSplashUrl(Id, SplashId); /// - public string BannerUrl => CDN.GetGuildBannerUrl(Id, BannerId); + public string DiscoverySplashUrl => CDN.GetGuildDiscoverySplashUrl(Id, DiscoverySplashId); + /// + public string BannerUrl => CDN.GetGuildBannerUrl(Id, BannerId, ImageFormat.Auto); /// /// Gets the built-in role containing all users in this guild. @@ -94,8 +134,7 @@ namespace Discord.Rest public IReadOnlyCollection Roles => _roles.ToReadOnlyCollection(); /// public IReadOnlyCollection Emotes => _emotes; - /// - public IReadOnlyCollection Features => _features; + public IReadOnlyCollection Stickers => _stickers; internal RestGuild(BaseDiscordClient client, ulong id) : base(client, id) @@ -110,15 +149,20 @@ namespace Discord.Rest internal void Update(Model model) { AFKChannelId = model.AFKChannelId; - EmbedChannelId = model.EmbedChannelId; + if (model.WidgetChannelId.IsSpecified) + WidgetChannelId = model.WidgetChannelId.Value; SystemChannelId = model.SystemChannelId; + RulesChannelId = model.RulesChannelId; + PublicUpdatesChannelId = model.PublicUpdatesChannelId; AFKTimeout = model.AFKTimeout; - IsEmbeddable = model.EmbedEnabled; + if (model.WidgetEnabled.IsSpecified) + IsWidgetEnabled = model.WidgetEnabled.Value; IconId = model.Icon; Name = model.Name; OwnerId = model.OwnerId; VoiceRegionId = model.Region; SplashId = model.Splash; + DiscoverySplashId = model.DiscoverySplash; VerificationLevel = model.VerificationLevel; MfaLevel = model.MfaLevel; DefaultMessageNotifications = model.DefaultMessageNotifications; @@ -130,8 +174,21 @@ namespace Discord.Rest SystemChannelFlags = model.SystemChannelFlags; Description = model.Description; PremiumSubscriptionCount = model.PremiumSubscriptionCount.GetValueOrDefault(); + NsfwLevel = model.NsfwLevel; + if (model.MaxPresences.IsSpecified) + MaxPresences = model.MaxPresences.Value ?? 25000; + if (model.MaxMembers.IsSpecified) + MaxMembers = model.MaxMembers.Value; + if (model.MaxVideoChannelUsers.IsSpecified) + MaxVideoChannelUsers = model.MaxVideoChannelUsers.Value; PreferredLocale = model.PreferredLocale; PreferredCulture = new CultureInfo(PreferredLocale); + if (model.ApproximateMemberCount.IsSpecified) + ApproximateMemberCount = model.ApproximateMemberCount.Value; + if (model.ApproximatePresenceCount.IsSpecified) + ApproximatePresenceCount = model.ApproximatePresenceCount.Value; + if (model.IsBoostProgressBarEnabled.IsSpecified) + IsBoostProgressBarEnabled = model.IsBoostProgressBarEnabled.Value; if (model.Emojis != null) { @@ -143,10 +200,7 @@ namespace Discord.Rest else _emotes = ImmutableArray.Create(); - if (model.Features != null) - _features = model.Features.ToImmutableArray(); - else - _features = ImmutableArray.Create(); + Features = model.Features; var roles = ImmutableDictionary.CreateBuilder(); if (model.Roles != null) @@ -156,24 +210,56 @@ namespace Discord.Rest } _roles = roles.ToImmutable(); + if (model.Stickers != null) + { + var stickers = ImmutableArray.CreateBuilder(); + for (int i = 0; i < model.Stickers.Length; i++) + { + var sticker = model.Stickers[i]; + + var entity = CustomSticker.Create(Discord, sticker, this, sticker.User.IsSpecified ? sticker.User.Value.Id : null); + + stickers.Add(entity); + } + + _stickers = stickers.ToImmutable(); + } + else + _stickers = ImmutableArray.Create(); + Available = true; } - internal void Update(EmbedModel model) + internal void Update(WidgetModel model) { - EmbedChannelId = model.ChannelId; - IsEmbeddable = model.Enabled; + WidgetChannelId = model.ChannelId; + IsWidgetEnabled = model.Enabled; } + #endregion - //General + #region General /// public async Task UpdateAsync(RequestOptions options = null) - => Update(await Discord.ApiClient.GetGuildAsync(Id, options).ConfigureAwait(false)); + => Update(await Discord.ApiClient.GetGuildAsync(Id, false, options).ConfigureAwait(false)); + /// + /// Updates this object's properties with its current state. + /// + /// + /// If true, and + /// will be updated as well. + /// + /// The options to be used when sending the request. + /// + /// If is true, and + /// will be updated as well. + /// + public async Task UpdateAsync(bool withCounts, RequestOptions options = null) + => Update(await Discord.ApiClient.GetGuildAsync(Id, withCounts, options).ConfigureAwait(false)); /// public Task DeleteAsync(RequestOptions options = null) => GuildHelper.DeleteAsync(this, Discord, options); /// - /// is null. + /// is . public async Task ModifyAsync(Action func, RequestOptions options = null) { var model = await GuildHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); @@ -181,15 +267,15 @@ namespace Discord.Rest } /// - /// is null. - public async Task ModifyEmbedAsync(Action func, RequestOptions options = null) + /// is . + public async Task ModifyWidgetAsync(Action func, RequestOptions options = null) { - var model = await GuildHelper.ModifyEmbedAsync(this, Discord, func, options).ConfigureAwait(false); + var model = await GuildHelper.ModifyWidgetAsync(this, Discord, func, options).ConfigureAwait(false); Update(model); } /// - /// is null. + /// is . public async Task ReorderChannelsAsync(IEnumerable args, RequestOptions options = null) { var arr = args.ToArray(); @@ -205,13 +291,48 @@ namespace Discord.Rest role?.Update(model); } } - + /// public Task LeaveAsync(RequestOptions options = null) => GuildHelper.LeaveAsync(this, Discord, options); + #endregion + + #region Interactions + /// + /// Deletes all slash commands in the current guild. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous delete operation. + /// + public Task DeleteSlashCommandsAsync(RequestOptions options = null) + => InteractionHelper.DeleteAllGuildCommandsAsync(Discord, Id, options); - //Bans - //Bans + /// + /// Gets a collection of slash commands created by the current user in this guild. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a read-only collection of + /// slash commands created by the current user. + /// + public Task> GetSlashCommandsAsync(RequestOptions options = null) + => GuildHelper.GetSlashCommandsAsync(this, Discord, options); + + /// + /// Gets a slash command in the current guild. + /// + /// The unique identifier of the slash command. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a + /// slash command created by the current user. + /// + public Task GetSlashCommandAsync(ulong id, RequestOptions options = null) + => GuildHelper.GetSlashCommandAsync(this, id, Discord, options); + #endregion + + #region Bans /// /// Gets a collection of all users banned in this guild. /// @@ -230,7 +351,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains a ban object, which - /// contains the user information and the reason for the ban; null if the ban entry cannot be found. + /// contains the user information and the reason for the ban; if the ban entry cannot be found. /// public Task GetBanAsync(IUser user, RequestOptions options = null) => GuildHelper.GetBanAsync(this, Discord, user.Id, options); @@ -241,7 +362,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains a ban object, which - /// contains the user information and the reason for the ban; null if the ban entry cannot be found. + /// contains the user information and the reason for the ban; if the ban entry cannot be found. /// public Task GetBanAsync(ulong userId, RequestOptions options = null) => GuildHelper.GetBanAsync(this, Discord, userId, options); @@ -259,8 +380,9 @@ namespace Discord.Rest /// public Task RemoveBanAsync(ulong userId, RequestOptions options = null) => GuildHelper.RemoveBanAsync(this, Discord, userId, options); + #endregion - //Channels + #region Channels /// /// Gets a collection of all channels in this guild. /// @@ -279,7 +401,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the generic channel - /// associated with the specified ; null if none is found. + /// associated with the specified ; if none is found. /// public Task GetChannelAsync(ulong id, RequestOptions options = null) => GuildHelper.GetChannelAsync(this, Discord, id, options); @@ -291,7 +413,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the text channel - /// associated with the specified ; null if none is found. + /// associated with the specified ; if none is found. /// public async Task GetTextChannelAsync(ulong id, RequestOptions options = null) { @@ -313,6 +435,35 @@ namespace Discord.Rest return channels.OfType().ToImmutableArray(); } + /// + /// Gets a thread channel in this guild. + /// + /// The snowflake identifier for the thread channel. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the thread channel associated + /// with the specified ; if none is found. + /// + public async Task GetThreadChannelAsync(ulong id, RequestOptions options = null) + { + var channel = await GuildHelper.GetChannelAsync(this, Discord, id, options).ConfigureAwait(false); + return channel as RestThreadChannel; + } + + /// + /// Gets a collection of all thread in this guild. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a read-only collection of + /// threads found within this guild. + /// + public async Task> GetThreadChannelsAsync(RequestOptions options = null) + { + var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); + return channels.OfType().ToImmutableArray(); + } + /// /// Gets a voice channel in this guild. /// @@ -320,7 +471,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the voice channel associated - /// with the specified ; null if none is found. + /// with the specified ; if none is found. /// public async Task GetVoiceChannelAsync(ulong id, RequestOptions options = null) { @@ -341,6 +492,34 @@ namespace Discord.Rest var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); return channels.OfType().ToImmutableArray(); } + /// + /// Gets a stage channel in this guild + /// + /// The snowflake identifier for the stage channel. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the stage channel associated + /// with the specified ; if none is found. + /// + public async Task GetStageChannelAsync(ulong id, RequestOptions options = null) + { + var channel = await GuildHelper.GetChannelAsync(this, Discord, id, options).ConfigureAwait(false); + return channel as RestStageChannel; + } + + /// + /// Gets a collection of all stage channels in this guild. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a read-only collection of + /// stage channels found within this guild. + /// + public async Task> GetStageChannelsAsync(RequestOptions options = null) + { + var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); + return channels.OfType().ToImmutableArray(); + } /// /// Gets a collection of all category channels in this guild. @@ -362,7 +541,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the voice channel that the - /// AFK users will be moved to after they have idled for too long; null if none is set. + /// AFK users will be moved to after they have idled for too long; if none is set. /// public async Task GetAFKChannelAsync(RequestOptions options = null) { @@ -381,7 +560,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the first viewable text - /// channel in this guild; null if none is found. + /// channel in this guild; if none is found. /// public async Task GetDefaultChannelAsync(RequestOptions options = null) { @@ -394,28 +573,28 @@ namespace Discord.Rest } /// - /// Gets the embed channel (i.e. the channel set in the guild's widget settings) in this guild. + /// Gets the widget channel (i.e. the channel set in the guild's widget settings) in this guild. /// /// The options to be used when sending the request. /// - /// A task that represents the asynchronous get operation. The task result contains the embed channel set - /// within the server's widget settings; null if none is set. + /// A task that represents the asynchronous get operation. The task result contains the widget channel set + /// within the server's widget settings; if none is set. /// - public async Task GetEmbedChannelAsync(RequestOptions options = null) + public async Task GetWidgetChannelAsync(RequestOptions options = null) { - var embedId = EmbedChannelId; - if (embedId.HasValue) - return await GuildHelper.GetChannelAsync(this, Discord, embedId.Value, options).ConfigureAwait(false); + var widgetChannelId = WidgetChannelId; + if (widgetChannelId.HasValue) + return await GuildHelper.GetChannelAsync(this, Discord, widgetChannelId.Value, options).ConfigureAwait(false); return null; } /// - /// Gets the first viewable text channel in this guild. + /// Gets the text channel where guild notices such as welcome messages and boost events are posted. /// /// The options to be used when sending the request. /// - /// A task that represents the asynchronous get operation. The task result contains the first viewable text - /// channel in this guild; null if none is found. + /// A task that represents the asynchronous get operation. The task result contains the text channel + /// where guild notices such as welcome messages and boost events are post; if none is found. /// public async Task GetSystemChannelAsync(RequestOptions options = null) { @@ -427,6 +606,45 @@ namespace Discord.Rest } return null; } + + /// + /// Gets the text channel where Community guilds can display rules and/or guidelines. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the text channel + /// where Community guilds can display rules and/or guidelines; if none is set. + /// + public async Task GetRulesChannelAsync(RequestOptions options = null) + { + var rulesChannelId = RulesChannelId; + if (rulesChannelId.HasValue) + { + var channel = await GuildHelper.GetChannelAsync(this, Discord, rulesChannelId.Value, options).ConfigureAwait(false); + return channel as RestTextChannel; + } + return null; + } + + /// + /// Gets the text channel where admins and moderators of Community guilds receive notices from Discord. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the text channel where + /// admins and moderators of Community guilds receive notices from Discord; if none is set. + /// + public async Task GetPublicUpdatesChannelAsync(RequestOptions options = null) + { + var publicUpdatesChannelId = PublicUpdatesChannelId; + if (publicUpdatesChannelId.HasValue) + { + var channel = await GuildHelper.GetChannelAsync(this, Discord, publicUpdatesChannelId.Value, options).ConfigureAwait(false); + return channel as RestTextChannel; + } + return null; + } + /// /// Creates a new text channel in this guild. /// @@ -458,19 +676,31 @@ namespace Discord.Rest /// The name of the new channel. /// The delegate containing the properties to be applied to the channel upon its creation. /// The options to be used when sending the request. - /// is null. + /// is . /// /// The created voice channel. /// public Task CreateVoiceChannelAsync(string name, Action func = null, RequestOptions options = null) => GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options, func); /// + /// Creates a new stage channel in this guild. + /// + /// The new name for the stage channel. + /// The delegate containing the properties to be applied to the channel upon its creation. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the newly created + /// stage channel. + /// + public Task CreateStageChannelAsync(string name, Action func = null, RequestOptions options = null) + => GuildHelper.CreateStageChannelAsync(this, Discord, name, options, func); + /// /// Creates a category channel with the provided name. /// /// The name of the new channel. /// The delegate containing the properties to be applied to the channel upon its creation. /// The options to be used when sending the request. - /// is null. + /// is . /// /// The created category channel. /// @@ -487,14 +717,16 @@ namespace Discord.Rest /// public Task> GetVoiceRegionsAsync(RequestOptions options = null) => GuildHelper.GetVoiceRegionsAsync(this, Discord, options); + #endregion - //Integrations + #region Integrations public Task> GetIntegrationsAsync(RequestOptions options = null) => GuildHelper.GetIntegrationsAsync(this, Discord, options); public Task CreateIntegrationAsync(ulong id, string type, RequestOptions options = null) => GuildHelper.CreateIntegrationAsync(this, Discord, id, type, options); + #endregion - //Invites + #region Invites /// /// Gets a collection of all invites in this guild. /// @@ -514,14 +746,15 @@ namespace Discord.Rest /// public Task GetVanityInviteAsync(RequestOptions options = null) => GuildHelper.GetVanityInviteAsync(this, Discord, options); + #endregion - //Roles + #region Roles /// /// Gets a role in this guild. /// /// The snowflake identifier for the role. /// - /// A role that is associated with the specified ; null if none is found. + /// A role that is associated with the specified ; if none is found. /// public RestRole GetRole(ulong id) { @@ -555,8 +788,9 @@ namespace Discord.Rest _roles = _roles.Add(role.Id, role); return role; } + #endregion - //Users + #region Users /// /// Gets a collection of all users in this guild. /// @@ -585,7 +819,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the guild user - /// associated with the specified ; null if none is found. + /// associated with the specified ; if none is found. /// public Task GetUserAsync(ulong id, RequestOptions options = null) => GuildHelper.GetUserAsync(this, Discord, id, options); @@ -631,10 +865,28 @@ namespace Discord.Rest /// A task that represents the asynchronous prune operation. The task result contains the number of users to /// be or has been removed from this guild. /// - public Task PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null) - => GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options); + public Task PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null, IEnumerable includeRoleIds = null) + => GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options, includeRoleIds); + + /// + /// Gets a collection of users in this guild that the name or nickname starts with the + /// provided at . + /// + /// + /// The can not be higher than . + /// + /// The partial name or nickname to search. + /// The maximum number of users to be gotten. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a collection of guild + /// users that the name or nickname starts with the provided at . + /// + public Task> SearchUsersAsync(string query, int limit = DiscordConfig.MaxUsersPerBatch, RequestOptions options = null) + => GuildHelper.SearchUsersAsync(this, Discord, query, limit, options); + #endregion - //Audit logs + #region Audit logs /// /// Gets the specified number of audit log entries for this guild. /// @@ -649,8 +901,9 @@ namespace Discord.Rest /// public IAsyncEnumerable> GetAuditLogsAsync(int limit, RequestOptions options = null, ulong? beforeId = null, ulong? userId = null, ActionType? actionType = null) => GuildHelper.GetAuditLogsAsync(this, Discord, beforeId, limit, options, userId: userId, actionType: actionType); + #endregion - //Webhooks + #region Webhooks /// /// Gets a webhook found within this guild. /// @@ -658,7 +911,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the webhook with the - /// specified ; null if none is found. + /// specified ; if none is found. /// public Task GetWebhookAsync(ulong id, RequestOptions options = null) => GuildHelper.GetWebhookAsync(this, Discord, id, options); @@ -673,6 +926,59 @@ namespace Discord.Rest /// public Task> GetWebhooksAsync(RequestOptions options = null) => GuildHelper.GetWebhooksAsync(this, Discord, options); + #endregion + + #region Interactions + /// + /// Gets this guilds slash commands + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a read-only collection + /// of application commands found within the guild. + /// + public async Task> GetApplicationCommandsAsync (RequestOptions options = null) + => await ClientHelper.GetGuildApplicationCommandsAsync(Discord, Id, options).ConfigureAwait(false); + /// + /// Gets an application command within this guild with the specified id. + /// + /// The id of the application command to get. + /// The options to be used when sending the request. + /// + /// A ValueTask that represents the asynchronous get operation. The task result contains a + /// if found, otherwise . + /// + public async Task GetApplicationCommandAsync(ulong id, RequestOptions options = null) + => await ClientHelper.GetGuildApplicationCommandAsync(Discord, id, Id, options); + /// + /// Creates an application command within this guild. + /// + /// The properties to use when creating the command. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the command that was created. + /// + public async Task CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null) + { + var model = await InteractionHelper.CreateGuildCommandAsync(Discord, Id, properties, options); + + return RestGuildCommand.Create(Discord, model, Id); + } + /// + /// Overwrites the application commands within this guild. + /// + /// A collection of properties to use when creating the commands. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains a collection of commands that was created. + /// + public async Task> BulkOverwriteApplicationCommandsAsync(ApplicationCommandProperties[] properties, + RequestOptions options = null) + { + var models = await InteractionHelper.BulkOverwriteGuildCommandsAsync(Discord, Id, properties, options); + + return models.Select(x => RestGuildCommand.Create(Discord, x, Id)).ToImmutableArray(); + } /// /// Returns the name of the guild. @@ -682,8 +988,12 @@ namespace Discord.Rest /// public override string ToString() => Name; private string DebuggerDisplay => $"{Name} ({Id})"; + #endregion - //Emotes + #region Emotes + /// + public Task> GetEmotesAsync(RequestOptions options = null) + => GuildHelper.GetEmotesAsync(this, Discord, options); /// public Task GetEmoteAsync(ulong id, RequestOptions options = null) => GuildHelper.GetEmoteAsync(this, Discord, id, options); @@ -691,14 +1001,191 @@ namespace Discord.Rest public Task CreateEmoteAsync(string name, Image image, Optional> roles = default(Optional>), RequestOptions options = null) => GuildHelper.CreateEmoteAsync(this, Discord, name, image, roles, options); /// - /// is null. + /// is . public Task ModifyEmoteAsync(GuildEmote emote, Action func, RequestOptions options = null) => GuildHelper.ModifyEmoteAsync(this, Discord, emote.Id, func, options); + /// + /// Moves the user to the voice channel. + /// + /// The user to move. + /// the channel where the user gets moved to. + /// A task that represents the asynchronous operation for moving a user. + public Task MoveAsync(IGuildUser user, IVoiceChannel targetChannel) + => user.ModifyAsync(x => x.Channel = new Optional(targetChannel)); /// public Task DeleteEmoteAsync(GuildEmote emote, RequestOptions options = null) => GuildHelper.DeleteEmoteAsync(this, Discord, emote.Id, options); + #endregion + + #region Stickers + /// + /// Creates a new sticker in this guild. + /// + /// The name of the sticker. + /// The description of the sticker. + /// The tags of the sticker. + /// The image of the new emote. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the created sticker. + /// + public async Task CreateStickerAsync(string name, string description, IEnumerable tags, Image image, RequestOptions options = null) + { + var model = await GuildHelper.CreateStickerAsync(Discord, this, name, description, tags, image, options).ConfigureAwait(false); + + return CustomSticker.Create(Discord, model, this, model.User.IsSpecified ? model.User.Value.Id : null); + } + /// + /// Creates a new sticker in this guild + /// + /// The name of the sticker. + /// The description of the sticker. + /// The tags of the sticker. + /// The path of the file to upload. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the created sticker. + /// + public Task CreateStickerAsync(string name, string description, IEnumerable tags, string path, + RequestOptions options = null) + { + var fs = File.OpenRead(path); + return CreateStickerAsync(name, description, tags, fs, Path.GetFileName(fs.Name), options); + } + /// + /// Creates a new sticker in this guild + /// + /// The name of the sticker. + /// The description of the sticker. + /// The tags of the sticker. + /// The stream containing the file data. + /// The name of the file with the extension, ex: image.png. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the created sticker. + /// + public async Task CreateStickerAsync(string name, string description, IEnumerable tags, Stream stream, + string filename, RequestOptions options = null) + { + var model = await GuildHelper.CreateStickerAsync(Discord, this, name, description, tags, stream, filename, options).ConfigureAwait(false); + + return CustomSticker.Create(Discord, model, this, model.User.IsSpecified ? model.User.Value.Id : null); + } + /// + /// Gets a specific sticker within this guild. + /// + /// The id of the sticker to get. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the sticker found with the + /// specified ; if none is found. + /// + public async Task GetStickerAsync(ulong id, RequestOptions options = null) + { + var model = await Discord.ApiClient.GetGuildStickerAsync(Id, id, options).ConfigureAwait(false); + + if (model == null) + return null; + + return CustomSticker.Create(Discord, model, this, model.User.IsSpecified ? model.User.Value.Id : null); + } + /// + /// Gets a collection of all stickers within this guild. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a read-only collection + /// of stickers found within the guild. + /// + public async Task> GetStickersAsync(RequestOptions options = null) + { + var models = await Discord.ApiClient.ListGuildStickersAsync(Id, options).ConfigureAwait(false); + + if (models.Length == 0) + return null; + + List stickers = new List(); + + foreach(var model in models) + { + var entity = CustomSticker.Create(Discord, model, this, model.User.IsSpecified ? model.User.Value.Id : null); + stickers.Add(entity); + } + + return stickers.ToImmutableArray(); + } + /// + /// Deletes a sticker within this guild. + /// + /// The sticker to delete. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous removal operation. + /// + public Task DeleteStickerAsync(CustomSticker sticker, RequestOptions options = null) + => sticker.DeleteAsync(options); + #endregion + + #region Guild Events + + /// + /// Gets an event within this guild. + /// + /// The snowflake identifier for the event. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. + /// + public Task GetEventAsync(ulong id, RequestOptions options = null) + => GuildHelper.GetGuildEventAsync(Discord, id, this, options); + + /// + /// Gets all active events within this guild. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. + /// + public Task> GetEventsAsync(RequestOptions options = null) + => GuildHelper.GetGuildEventsAsync(Discord, this, options); + + /// + /// Creates an event within this guild. + /// + /// The name of the event. + /// The privacy level of the event. + /// The start time of the event. + /// The type of the event. + /// The description of the event. + /// The end time of the event. + /// + /// The channel id of the event. + /// + /// The event must have a type of or + /// in order to use this property. + /// + /// + /// A collection of speakers for the event. + /// The location of the event; links are supported + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous create operation. + /// + public Task CreateEventAsync( + string name, + DateTimeOffset startTime, + GuildScheduledEventType type, + GuildScheduledEventPrivacyLevel privacyLevel = GuildScheduledEventPrivacyLevel.Private, + string description = null, + DateTimeOffset? endTime = null, + ulong? channelId = null, + string location = null, + RequestOptions options = null) + => GuildHelper.CreateGuildEventAsync(Discord, this, name, privacyLevel, startTime, type, description, endTime, channelId, location, options); - //IGuild + #endregion + + #region IGuild /// bool IGuild.Available => Available; /// @@ -708,6 +1195,20 @@ namespace Discord.Rest /// IReadOnlyCollection IGuild.Roles => Roles; + IReadOnlyCollection IGuild.Stickers => Stickers; + + /// + async Task IGuild.CreateEventAsync(string name, DateTimeOffset startTime, GuildScheduledEventType type, GuildScheduledEventPrivacyLevel privacyLevel, string description, DateTimeOffset? endTime, ulong? channelId, string location, RequestOptions options) + => await CreateEventAsync(name, startTime, type, privacyLevel, description, endTime, channelId, location, options).ConfigureAwait(false); + + /// + async Task IGuild.GetEventAsync(ulong id, RequestOptions options) + => await GetEventAsync(id, options).ConfigureAwait(false); + + /// + async Task> IGuild.GetEventsAsync(RequestOptions options) + => await GetEventsAsync(options).ConfigureAwait(false); + /// async Task> IGuild.GetBansAsync(RequestOptions options) => await GetBansAsync(options).ConfigureAwait(false); @@ -751,6 +1252,22 @@ namespace Discord.Rest return null; } /// + async Task IGuild.GetThreadChannelAsync(ulong id, CacheMode mode, RequestOptions options) + { + if (mode == CacheMode.AllowDownload) + return await GetThreadChannelAsync(id, options).ConfigureAwait(false); + else + return null; + } + /// + async Task> IGuild.GetThreadChannelsAsync(CacheMode mode, RequestOptions options) + { + if (mode == CacheMode.AllowDownload) + return await GetThreadChannelsAsync(options).ConfigureAwait(false); + else + return null; + } + /// async Task> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) @@ -767,6 +1284,22 @@ namespace Discord.Rest return null; } /// + async Task IGuild.GetStageChannelAsync(ulong id, CacheMode mode, RequestOptions options ) + { + if (mode == CacheMode.AllowDownload) + return await GetStageChannelAsync(id, options).ConfigureAwait(false); + else + return null; + } + /// + async Task> IGuild.GetStageChannelsAsync(CacheMode mode, RequestOptions options) + { + if (mode == CacheMode.AllowDownload) + return await GetStageChannelsAsync(options).ConfigureAwait(false); + else + return null; + } + /// async Task IGuild.GetVoiceChannelAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) @@ -791,10 +1324,10 @@ namespace Discord.Rest return null; } /// - async Task IGuild.GetEmbedChannelAsync(CacheMode mode, RequestOptions options) + async Task IGuild.GetWidgetChannelAsync(CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetEmbedChannelAsync(options).ConfigureAwait(false); + return await GetWidgetChannelAsync(options).ConfigureAwait(false); else return null; } @@ -807,12 +1340,31 @@ namespace Discord.Rest return null; } /// + async Task IGuild.GetRulesChannelAsync(CacheMode mode, RequestOptions options) + { + if (mode == CacheMode.AllowDownload) + return await GetRulesChannelAsync(options).ConfigureAwait(false); + else + return null; + } + /// + async Task IGuild.GetPublicUpdatesChannelAsync(CacheMode mode, RequestOptions options) + { + if (mode == CacheMode.AllowDownload) + return await GetPublicUpdatesChannelAsync(options).ConfigureAwait(false); + else + return null; + } + /// async Task IGuild.CreateTextChannelAsync(string name, Action func, RequestOptions options) => await CreateTextChannelAsync(name, func, options).ConfigureAwait(false); /// async Task IGuild.CreateVoiceChannelAsync(string name, Action func, RequestOptions options) => await CreateVoiceChannelAsync(name, func, options).ConfigureAwait(false); /// + async Task IGuild.CreateStageChannelAsync(string name, Action func, RequestOptions options) + => await CreateStageChannelAsync(name, func, options).ConfigureAwait(false); + /// async Task IGuild.CreateCategoryAsync(string name, Action func, RequestOptions options) => await CreateCategoryChannelAsync(name, func, options).ConfigureAwait(false); @@ -848,6 +1400,13 @@ namespace Discord.Rest async Task IGuild.AddGuildUserAsync(ulong userId, string accessToken, Action func, RequestOptions options) => await AddGuildUserAsync(userId, accessToken, func, options); + /// + /// Disconnects the user from its current voice channel + /// + /// The user to disconnect. + /// A task that represents the asynchronous operation for disconnecting a user. + async Task IGuild.DisconnectAsync(IGuildUser user) => await user.ModifyAsync(x => x.Channel = new Optional()); + /// async Task IGuild.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) { @@ -884,6 +1443,14 @@ namespace Discord.Rest /// Downloading users is not supported for a REST-based guild. Task IGuild.DownloadUsersAsync() => throw new NotSupportedException(); + /// + async Task> IGuild.SearchUsersAsync(string query, int limit, CacheMode mode, RequestOptions options) + { + if (mode == CacheMode.AllowDownload) + return await SearchUsersAsync(query, limit, options).ConfigureAwait(false); + else + return ImmutableArray.Create(); + } async Task> IGuild.GetAuditLogsAsync(int limit, CacheMode cacheMode, RequestOptions options, ulong? beforeId, ulong? userId, ActionType? actionType) @@ -900,5 +1467,54 @@ namespace Discord.Rest /// async Task> IGuild.GetWebhooksAsync(RequestOptions options) => await GetWebhooksAsync(options).ConfigureAwait(false); + /// + async Task> IGuild.GetApplicationCommandsAsync (RequestOptions options) + => await GetApplicationCommandsAsync(options).ConfigureAwait(false); + /// + async Task IGuild.CreateStickerAsync(string name, string description, IEnumerable tags, Image image, RequestOptions options) + => await CreateStickerAsync(name, description, tags, image, options); + /// + async Task IGuild.CreateStickerAsync(string name, string description, IEnumerable tags, Stream stream, string filename, RequestOptions options) + => await CreateStickerAsync(name, description, tags, stream, filename, options); + /// + async Task IGuild.CreateStickerAsync(string name, string description, IEnumerable tags, string path, RequestOptions options) + => await CreateStickerAsync(name, description, tags, path, options); + /// + async Task IGuild.GetStickerAsync(ulong id, CacheMode mode, RequestOptions options) + { + if (mode != CacheMode.AllowDownload) + return null; + + return await GetStickerAsync(id, options); + } + /// + async Task> IGuild.GetStickersAsync(CacheMode mode, RequestOptions options) + { + if (mode != CacheMode.AllowDownload) + return null; + + return await GetStickersAsync(options); + } + /// + Task IGuild.DeleteStickerAsync(ICustomSticker sticker, RequestOptions options) + => sticker.DeleteAsync(); + /// + async Task IGuild.CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options) + => await CreateApplicationCommandAsync(properties, options); + /// + async Task> IGuild.BulkOverwriteApplicationCommandsAsync(ApplicationCommandProperties[] properties, + RequestOptions options) + => await BulkOverwriteApplicationCommandsAsync(properties, options); + /// + async Task IGuild.GetApplicationCommandAsync(ulong id, CacheMode mode, RequestOptions options) + { + if (mode == CacheMode.AllowDownload) + { + return await GetApplicationCommandAsync(id, options); + } + else + return null; + } + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuildEvent.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuildEvent.cs new file mode 100644 index 000000000..d3ec11fc6 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuildEvent.cs @@ -0,0 +1,188 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Model = Discord.API.GuildScheduledEvent; + +namespace Discord.Rest +{ + public class RestGuildEvent : RestEntity, IGuildScheduledEvent + { + /// + public IGuild Guild { get; private set; } + + /// + public ulong? ChannelId { get; private set; } + + /// + public IUser Creator { get; private set; } + + /// + public ulong CreatorId { get; private set; } + + /// + public string Name { get; private set; } + + /// + public string Description { get; private set; } + + /// + public DateTimeOffset StartTime { get; private set; } + + /// + public DateTimeOffset? EndTime { get; private set; } + + /// + public GuildScheduledEventPrivacyLevel PrivacyLevel { get; private set; } + + /// + public GuildScheduledEventStatus Status { get; private set; } + + /// + public GuildScheduledEventType Type { get; private set; } + + /// + public ulong? EntityId { get; private set; } + + /// + public string Location { get; private set; } + + /// + public int? UserCount { get; private set; } + + internal RestGuildEvent(BaseDiscordClient client, IGuild guild, ulong id) + : base(client, id) + { + Guild = guild; + } + + internal static RestGuildEvent Create(BaseDiscordClient client, IGuild guild, Model model) + { + var entity = new RestGuildEvent(client, guild, model.Id); + entity.Update(model); + return entity; + } + + internal static RestGuildEvent Create(BaseDiscordClient client, IGuild guild, IUser creator, Model model) + { + var entity = new RestGuildEvent(client, guild, model.Id); + entity.Update(model, creator); + return entity; + } + + internal void Update(Model model, IUser creator) + { + Update(model); + Creator = creator; + CreatorId = creator.Id; + } + + internal void Update(Model model) + { + if (model.Creator.IsSpecified) + { + Creator = RestUser.Create(Discord, model.Creator.Value); + } + + CreatorId = model.CreatorId.ToNullable() ?? 0; // should be changed? + ChannelId = model.ChannelId.IsSpecified ? model.ChannelId.Value : null; + Name = model.Name; + Description = model.Description.GetValueOrDefault(); + StartTime = model.ScheduledStartTime; + EndTime = model.ScheduledEndTime; + PrivacyLevel = model.PrivacyLevel; + Status = model.Status; + Type = model.EntityType; + EntityId = model.EntityId; + Location = model.EntityMetadata?.Location.GetValueOrDefault(); + UserCount = model.UserCount.ToNullable(); + } + + /// + public Task StartAsync(RequestOptions options = null) + => ModifyAsync(x => x.Status = GuildScheduledEventStatus.Active); + + /// + public Task EndAsync(RequestOptions options = null) + => ModifyAsync(x => x.Status = Status == GuildScheduledEventStatus.Scheduled + ? GuildScheduledEventStatus.Cancelled + : GuildScheduledEventStatus.Completed); + + /// + public Task DeleteAsync(RequestOptions options = null) + => GuildHelper.DeleteEventAsync(Discord, this, options); + + /// + public async Task ModifyAsync(Action func, RequestOptions options = null) + { + var model = await GuildHelper.ModifyGuildEventAsync(Discord, func, this, options).ConfigureAwait(false); + Update(model); + } + + /// + /// Gets a collection of N users interested in the event. + /// + /// + /// + /// The returned collection is an asynchronous enumerable object; one must call + /// to access the individual messages as a + /// collection. + /// + /// This method will attempt to fetch all users that are interested in the event. + /// The library will attempt to split up the requests according to and . + /// In other words, if there are 300 users, and the constant + /// is 100, the request will be split into 3 individual requests; thus returning 3 individual asynchronous + /// responses, hence the need of flattening. + /// + /// The options to be used when sending the request. + /// + /// Paged collection of users. + /// + public IAsyncEnumerable> GetUsersAsync(RequestOptions options = null) + => GuildHelper.GetEventUsersAsync(Discord, this, null, null, options); + + /// + /// Gets a collection of N users interested in the event. + /// + /// + /// + /// The returned collection is an asynchronous enumerable object; one must call + /// to access the individual users as a + /// collection. + /// + /// + /// Do not fetch too many users at once! This may cause unwanted preemptive rate limit or even actual + /// rate limit, causing your bot to freeze! + /// + /// This method will attempt to fetch the number of users specified under around + /// the user depending on the . The library will + /// attempt to split up the requests according to your and + /// . In other words, should the user request 500 users, + /// and the constant is 100, the request will + /// be split into 5 individual requests; thus returning 5 individual asynchronous responses, hence the need + /// of flattening. + /// + /// The ID of the starting user to get the users from. + /// The direction of the users to be gotten from. + /// The numbers of users to be gotten from. + /// The options to be used when sending the request. + /// + /// Paged collection of users. + /// + public IAsyncEnumerable> GetUsersAsync(ulong fromUserId, Direction dir, int limit = DiscordConfig.MaxGuildEventUsersPerBatch, RequestOptions options = null) + => GuildHelper.GetEventUsersAsync(Discord, this, fromUserId, dir, limit, options); + + #region IGuildScheduledEvent + + /// + IAsyncEnumerable> IGuildScheduledEvent.GetUsersAsync(RequestOptions options) + => GetUsersAsync(options); + /// + IAsyncEnumerable> IGuildScheduledEvent.GetUsersAsync(ulong fromUserId, Direction dir, int limit, RequestOptions options) + => GetUsersAsync(fromUserId, dir, limit, options); + + #endregion + } +} diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuildEmbed.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuildWidget.cs similarity index 65% rename from src/Discord.Net.Rest/Entities/Guilds/RestGuildEmbed.cs rename to src/Discord.Net.Rest/Entities/Guilds/RestGuildWidget.cs index 41c76eb06..065739c57 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuildEmbed.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuildWidget.cs @@ -1,22 +1,22 @@ using System.Diagnostics; -using Model = Discord.API.GuildEmbed; +using Model = Discord.API.GuildWidget; namespace Discord.Rest { [DebuggerDisplay(@"{DebuggerDisplay,nq}")] - public struct RestGuildEmbed + public struct RestGuildWidget { public bool IsEnabled { get; private set; } public ulong? ChannelId { get; private set; } - internal RestGuildEmbed(bool isEnabled, ulong? channelId) + internal RestGuildWidget(bool isEnabled, ulong? channelId) { ChannelId = channelId; IsEnabled = isEnabled; } - internal static RestGuildEmbed Create(Model model) + internal static RestGuildWidget Create(Model model) { - return new RestGuildEmbed(model.Enabled, model.ChannelId); + return new RestGuildWidget(model.Enabled, model.ChannelId); } public override string ToString() => ChannelId?.ToString() ?? "Unknown"; diff --git a/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBase.cs b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBase.cs new file mode 100644 index 000000000..2069b9913 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBase.cs @@ -0,0 +1,320 @@ +using Discord.Net.Rest; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DataModel = Discord.API.ApplicationCommandInteractionData; +using Model = Discord.API.Interaction; + +namespace Discord.Rest +{ + /// + /// Represents a REST-based base command interaction. + /// + public class RestCommandBase : RestInteraction + { + /// + /// Gets the name of the invoked command. + /// + public string CommandName + => Data.Name; + + /// + /// Gets the id of the invoked command. + /// + public ulong CommandId + => Data.Id; + + /// + /// The data associated with this interaction. + /// + internal new RestCommandBaseData Data { get; private set; } + + private object _lock = new object(); + + internal RestCommandBase(DiscordRestClient client, Model model) + : base(client, model.Id) + { + } + + internal new static async Task CreateAsync(DiscordRestClient client, Model model) + { + var entity = new RestCommandBase(client, model); + await entity.UpdateAsync(client, model).ConfigureAwait(false); + return entity; + } + + internal override async Task UpdateAsync(DiscordRestClient client, Model model) + { + await base.UpdateAsync(client, model).ConfigureAwait(false); + } + + /// + /// Responds to an Interaction with type . + /// + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// The request options for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// Message content is too long, length must be less or equal to . + /// The parameters provided were invalid or the token was invalid. + /// + /// A string that contains json to write back to the incoming http request. + /// + public override string Respond( + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + if (!InteractionHelper.CanSendResponse(this)) + throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!"); + + embeds ??= Array.Empty(); + if (embed != null) + embeds = new[] { embed }.Concat(embeds).ToArray(); + + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed."); + + // check that user flag and user Id list are exclusive, same with role flag and role Id list + if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue) + { + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) && + allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) + { + throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions)); + } + + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) && + allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) + { + throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions)); + } + } + + var response = new API.InteractionResponse + { + Type = InteractionResponseType.ChannelMessageWithSource, + Data = new API.InteractionCallbackData + { + Content = text ?? Optional.Unspecified, + AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, + Embeds = embeds.Select(x => x.ToModel()).ToArray(), + TTS = isTTS, + Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified, + Flags = ephemeral ? MessageFlags.Ephemeral : Optional.Unspecified + } + }; + + lock (_lock) + { + if (HasResponded) + { + throw new InvalidOperationException("Cannot respond twice to the same interaction"); + } + + HasResponded = true; + } + + return SerializePayload(response); + } + + /// + public override async Task FollowupAsync( + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + embeds ??= Array.Empty(); + if (embed != null) + embeds = new[] { embed }.Concat(embeds).ToArray(); + + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed."); + + var args = new API.Rest.CreateWebhookMessageParams + { + Content = text, + AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, + IsTTS = isTTS, + Embeds = embeds.Select(x => x.ToModel()).ToArray(), + Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified + }; + + if (ephemeral) + args.Flags = MessageFlags.Ephemeral; + + return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options); + } + + /// + public override async Task FollowupWithFileAsync( + Stream fileStream, + string fileName, + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + Preconditions.NotNull(fileStream, nameof(fileStream), "File Stream must have data"); + Preconditions.NotNullOrEmpty(fileName, nameof(fileName), "File Name must not be empty or null"); + + using(var file = new FileAttachment(fileStream, fileName)) + return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + } + + /// + public override async Task FollowupWithFileAsync( + string filePath, + string fileName = null, + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + Preconditions.NotNullOrEmpty(filePath, nameof(filePath), "Path must exist"); + + fileName ??= Path.GetFileName(filePath); + Preconditions.NotNullOrEmpty(fileName, nameof(fileName), "File Name must not be empty or null"); + + using (var file = new FileAttachment(File.OpenRead(filePath), fileName)) + return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + } + + /// + public override Task FollowupWithFileAsync( + FileAttachment attachment, + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + return FollowupWithFilesAsync(new FileAttachment[] { attachment }, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options); + } + + /// + public override async Task FollowupWithFilesAsync( + IEnumerable attachments, + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + embeds ??= Array.Empty(); + if (embed != null) + embeds = new[] { embed }.Concat(embeds).ToArray(); + + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed."); + + foreach (var attachment in attachments) + { + Preconditions.NotNullOrEmpty(attachment.FileName, nameof(attachment.FileName), "File Name must not be empty or null"); + } + + // check that user flag and user Id list are exclusive, same with role flag and role Id list + if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue) + { + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) && + allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) + { + throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions)); + } + + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) && + allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) + { + throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions)); + } + } + + var flags = MessageFlags.None; + + if (ephemeral) + flags |= MessageFlags.Ephemeral; + + var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray()) { Flags = flags, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified }; + return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false); + } + + /// + /// Acknowledges this interaction with the . + /// + /// + /// A string that contains json to write back to the incoming http request. + /// + public override string Defer(bool ephemeral = false, RequestOptions options = null) + { + if (!InteractionHelper.CanSendResponse(this)) + throw new TimeoutException($"Cannot defer an interaction after {InteractionHelper.ResponseTimeLimit} seconds!"); + + var response = new API.InteractionResponse + { + Type = InteractionResponseType.DeferredChannelMessageWithSource, + Data = new API.InteractionCallbackData + { + Flags = ephemeral ? MessageFlags.Ephemeral : Optional.Unspecified + } + }; + + lock (_lock) + { + if (HasResponded) + { + throw new InvalidOperationException("Cannot respond or defer twice to the same interaction"); + } + + HasResponded = true; + } + + return SerializePayload(response); + } + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBaseData.cs b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBaseData.cs new file mode 100644 index 000000000..4227c802a --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBaseData.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Model = Discord.API.ApplicationCommandInteractionData; + +namespace Discord.Rest +{ + /// + /// Represents the base data tied with the interaction. + /// + public class RestCommandBaseData : RestEntity, IApplicationCommandInteractionData where TOption : IApplicationCommandInteractionDataOption + { + /// + public string Name { get; private set; } + + /// + /// Gets a collection of received with this interaction. + /// + public virtual IReadOnlyCollection Options { get; internal set; } + + internal RestResolvableData ResolvableData; + + internal RestCommandBaseData(BaseDiscordClient client, Model model) + : base(client, model.Id) + { + } + + internal static async Task CreateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel) + { + var entity = new RestCommandBaseData(client, model); + await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); + return entity; + } + + internal virtual async Task UpdateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel) + { + Name = model.Name; + if (model.Resolved.IsSpecified && ResolvableData == null) + { + ResolvableData = new RestResolvableData(); + await ResolvableData.PopulateAsync(client, guild, channel, model).ConfigureAwait(false); + } + } + + IReadOnlyCollection IApplicationCommandInteractionData.Options + => (IReadOnlyCollection)Options; + } + + /// + /// Represents the base data tied with the interaction. + /// + public class RestCommandBaseData : RestCommandBaseData + { + internal RestCommandBaseData(DiscordRestClient client, Model model) + : base(client, model) { } + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestResolvableData.cs b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestResolvableData.cs new file mode 100644 index 000000000..710207ef9 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestResolvableData.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.Rest +{ + internal class RestResolvableData where T : API.IResolvable + { + internal readonly Dictionary GuildMembers + = new Dictionary(); + internal readonly Dictionary Users + = new Dictionary(); + internal readonly Dictionary Channels + = new Dictionary(); + internal readonly Dictionary Roles + = new Dictionary(); + internal readonly Dictionary Messages + = new Dictionary(); + + internal async Task PopulateAsync(DiscordRestClient discord, RestGuild guild, IRestMessageChannel channel, T model) + { + var resolved = model.Resolved.Value; + + if (resolved.Users.IsSpecified) + { + foreach (var user in resolved.Users.Value) + { + var restUser = RestUser.Create(discord, user.Value); + + Users.Add(ulong.Parse(user.Key), restUser); + } + } + + if (resolved.Channels.IsSpecified) + { + var channels = await guild.GetChannelsAsync().ConfigureAwait(false); + + foreach (var channelModel in resolved.Channels.Value) + { + var restChannel = channels.FirstOrDefault(x => x.Id == channelModel.Value.Id); + + restChannel.Update(channelModel.Value); + + Channels.Add(ulong.Parse(channelModel.Key), restChannel); + } + } + + if (resolved.Members.IsSpecified) + { + foreach (var member in resolved.Members.Value) + { + // pull the adjacent user model + member.Value.User = resolved.Users.Value.FirstOrDefault(x => x.Key == member.Key).Value; + var restMember = RestGuildUser.Create(discord, guild, member.Value); + + GuildMembers.Add(ulong.Parse(member.Key), restMember); + } + } + + if (resolved.Roles.IsSpecified) + { + foreach (var role in resolved.Roles.Value) + { + var restRole = RestRole.Create(discord, guild, role.Value); + + Roles.Add(ulong.Parse(role.Key), restRole); + } + } + + if (resolved.Messages.IsSpecified) + { + foreach (var msg in resolved.Messages.Value) + { + channel ??= (IRestMessageChannel)(Channels.FirstOrDefault(x => x.Key == msg.Value.ChannelId).Value ?? await discord.GetChannelAsync(msg.Value.ChannelId).ConfigureAwait(false)); + + RestUser author; + + if (msg.Value.Author.IsSpecified) + { + author = RestUser.Create(discord, msg.Value.Author.Value); + } + else + { + author = RestGuildUser.Create(discord, guild, msg.Value.Member.Value); + } + + var message = RestMessage.Create(discord, channel, author, msg.Value); + + Messages.Add(message.Id, message); + } + } + } + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommand.cs b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommand.cs new file mode 100644 index 000000000..7a85d2e0a --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommand.cs @@ -0,0 +1,48 @@ +using System.Threading.Tasks; +using DataModel = Discord.API.ApplicationCommandInteractionData; +using Model = Discord.API.Interaction; + +namespace Discord.Rest +{ + /// + /// Represents a REST-based message command interaction. + /// + public class RestMessageCommand : RestCommandBase, IMessageCommandInteraction, IDiscordInteraction + { + /// + /// The data associated with this interaction. + /// + public new RestMessageCommandData Data { get; private set; } + + internal RestMessageCommand(DiscordRestClient client, Model model) + : base(client, model) + { + + } + + internal new static async Task CreateAsync(DiscordRestClient client, Model model) + { + var entity = new RestMessageCommand(client, model); + await entity.UpdateAsync(client, model).ConfigureAwait(false); + return entity; + } + + internal override async Task UpdateAsync(DiscordRestClient client, Model model) + { + await base.UpdateAsync(client, model).ConfigureAwait(false); + + var dataModel = model.Data.IsSpecified + ? (DataModel)model.Data.Value + : null; + + Data = await RestMessageCommandData.CreateAsync(client, dataModel, Guild, Channel).ConfigureAwait(false); + } + + //IMessageCommandInteraction + /// + IMessageCommandInteractionData IMessageCommandInteraction.Data => Data; + //IApplicationCommandInteraction + /// + IApplicationCommandInteractionData IApplicationCommandInteraction.Data => Data; + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommandData.cs b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommandData.cs new file mode 100644 index 000000000..8eadab617 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/MessageCommands/RestMessageCommandData.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Model = Discord.API.ApplicationCommandInteractionData; + +namespace Discord.Rest +{ + /// + /// Represents the data for a . + /// + public class RestMessageCommandData : RestCommandBaseData, IMessageCommandInteractionData, IDiscordInteractionData + { + /// + /// Gets the message associated with this message command. + /// + public RestMessage Message + => ResolvableData?.Messages.FirstOrDefault().Value; + + /// + /// + /// Note Not implemented for + /// + public override IReadOnlyCollection Options + => throw new System.NotImplementedException(); + + internal RestMessageCommandData(DiscordRestClient client, Model model) + : base(client, model) { } + + internal new static async Task CreateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel) + { + var entity = new RestMessageCommandData(client, model); + await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); + return entity; + } + + //IMessageCommandInteractionData + /// + IMessage IMessageCommandInteractionData.Message => Message; + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommand.cs b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommand.cs new file mode 100644 index 000000000..7f55fd61b --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommand.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DataModel = Discord.API.ApplicationCommandInteractionData; +using Model = Discord.API.Interaction; + +namespace Discord.Rest +{ + /// + /// Represents a REST-based user command. + /// + public class RestUserCommand : RestCommandBase, IUserCommandInteraction, IDiscordInteraction + { + /// + /// Gets the data associated with this interaction. + /// + public new RestUserCommandData Data { get; private set; } + + internal RestUserCommand(DiscordRestClient client, Model model) + : base(client, model) + { + } + + internal new static async Task CreateAsync(DiscordRestClient client, Model model) + { + var entity = new RestUserCommand(client, model); + await entity.UpdateAsync(client, model).ConfigureAwait(false); + return entity; + } + + internal override async Task UpdateAsync(DiscordRestClient client, Model model) + { + await base.UpdateAsync(client, model).ConfigureAwait(false); + + var dataModel = model.Data.IsSpecified + ? (DataModel)model.Data.Value + : null; + + Data = await RestUserCommandData.CreateAsync(client, dataModel, Guild, Channel).ConfigureAwait(false); + } + + //IUserCommandInteractionData + /// + IUserCommandInteractionData IUserCommandInteraction.Data => Data; + + //IApplicationCommandInteraction + /// + IApplicationCommandInteractionData IApplicationCommandInteraction.Data => Data; + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommandData.cs b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommandData.cs new file mode 100644 index 000000000..7563eecc7 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/ContextMenuCommands/UserCommands/RestUserCommandData.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Model = Discord.API.ApplicationCommandInteractionData; + +namespace Discord.Rest +{ + /// + /// Represents the data for a . + /// + public class RestUserCommandData : RestCommandBaseData, IUserCommandInteractionData, IDiscordInteractionData + { + /// + /// Gets the user who this command targets. + /// + public RestUser Member + => (RestUser)ResolvableData.GuildMembers.Values.FirstOrDefault() ?? ResolvableData.Users.Values.FirstOrDefault(); + + /// + /// + /// Note Not implemented for + /// + public override IReadOnlyCollection Options + => throw new System.NotImplementedException(); + + internal RestUserCommandData(DiscordRestClient client, Model model) + : base(client, model) { } + + internal new static async Task CreateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel) + { + var entity = new RestUserCommandData(client, model); + await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); + return entity; + } + + //IUserCommandInteractionData + /// + IUser IUserCommandInteractionData.User => Member; + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs new file mode 100644 index 000000000..0cac07577 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs @@ -0,0 +1,562 @@ +using Discord.API; +using Discord.API.Rest; +using Discord.Net; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Threading.Tasks; + +namespace Discord.Rest +{ + internal static class InteractionHelper + { + public const double ResponseTimeLimit = 3; + public const double ResponseAndFollowupLimit = 15; + + #region InteractionHelper + public static bool CanSendResponse(IDiscordInteraction interaction) + { + return (DateTime.UtcNow - interaction.CreatedAt).TotalSeconds < ResponseTimeLimit; + } + public static bool CanRespondOrFollowup(IDiscordInteraction interaction) + { + return (DateTime.UtcNow - interaction.CreatedAt).TotalMinutes <= ResponseAndFollowupLimit; + } + + public static Task DeleteAllGuildCommandsAsync(BaseDiscordClient client, ulong guildId, RequestOptions options = null) + { + return client.ApiClient.BulkOverwriteGuildApplicationCommandsAsync(guildId, Array.Empty(), options); + } + + public static Task DeleteAllGlobalCommandsAsync(BaseDiscordClient client, RequestOptions options = null) + { + return client.ApiClient.BulkOverwriteGlobalApplicationCommandsAsync(Array.Empty(), options); + } + + public static async Task SendInteractionResponseAsync(BaseDiscordClient client, InteractionResponse response, + IDiscordInteraction interaction, IMessageChannel channel = null, RequestOptions options = null) + { + await client.ApiClient.CreateInteractionResponseAsync(response, interaction.Id, interaction.Token, options).ConfigureAwait(false); + } + + public static async Task SendInteractionResponseAsync(BaseDiscordClient client, UploadInteractionFileParams response, + IDiscordInteraction interaction, IMessageChannel channel = null, RequestOptions options = null) + { + await client.ApiClient.CreateInteractionResponseAsync(response, interaction.Id, interaction.Token, options).ConfigureAwait(false); + } + + public static async Task GetOriginalResponseAsync(BaseDiscordClient client, IMessageChannel channel, + IDiscordInteraction interaction, RequestOptions options = null) + { + var model = await client.ApiClient.GetInteractionResponseAsync(interaction.Token, options).ConfigureAwait(false); + if(model != null) + return RestInteractionMessage.Create(client, model, interaction.Token, channel); + return null; + } + + public static async Task SendFollowupAsync(BaseDiscordClient client, CreateWebhookMessageParams args, + string token, IMessageChannel channel, RequestOptions options = null) + { + var model = await client.ApiClient.CreateInteractionFollowupMessageAsync(args, token, options).ConfigureAwait(false); + + var entity = RestFollowupMessage.Create(client, model, token, channel); + return entity; + } + + public static async Task SendFollowupAsync(BaseDiscordClient client, UploadWebhookFileParams args, + string token, IMessageChannel channel, RequestOptions options = null) + { + var model = await client.ApiClient.CreateInteractionFollowupMessageAsync(args, token, options).ConfigureAwait(false); + + var entity = RestFollowupMessage.Create(client, model, token, channel); + return entity; + } + #endregion + + #region Global commands + public static async Task GetGlobalCommandAsync(BaseDiscordClient client, ulong id, + RequestOptions options = null) + { + var model = await client.ApiClient.GetGlobalApplicationCommandAsync(id, options).ConfigureAwait(false); + + return RestGlobalCommand.Create(client, model); + } + public static Task CreateGlobalCommandAsync(BaseDiscordClient client, + Action func, RequestOptions options = null) where TArg : ApplicationCommandProperties + { + var args = Activator.CreateInstance(typeof(TArg)); + func((TArg)args); + return CreateGlobalCommandAsync(client, (TArg)args, options); + } + public static async Task CreateGlobalCommandAsync(BaseDiscordClient client, + ApplicationCommandProperties arg, RequestOptions options = null) + { + Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); + + var model = new CreateApplicationCommandParams + { + Name = arg.Name.Value, + Type = arg.Type, + DefaultPermission = arg.IsDefaultPermission.IsSpecified + ? arg.IsDefaultPermission.Value + : Optional.Unspecified + }; + + if (arg is SlashCommandProperties slashProps) + { + Preconditions.NotNullOrEmpty(slashProps.Description, nameof(slashProps.Description)); + + model.Description = slashProps.Description.Value; + + model.Options = slashProps.Options.IsSpecified + ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() + : Optional.Unspecified; + } + + return await client.ApiClient.CreateGlobalApplicationCommandAsync(model, options).ConfigureAwait(false); + } + + public static async Task BulkOverwriteGlobalCommandsAsync(BaseDiscordClient client, + ApplicationCommandProperties[] args, RequestOptions options = null) + { + Preconditions.NotNull(args, nameof(args)); + + var models = new List(); + + foreach (var arg in args) + { + Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); + + var model = new CreateApplicationCommandParams + { + Name = arg.Name.Value, + Type = arg.Type, + DefaultPermission = arg.IsDefaultPermission.IsSpecified + ? arg.IsDefaultPermission.Value + : Optional.Unspecified + }; + + if (arg is SlashCommandProperties slashProps) + { + Preconditions.NotNullOrEmpty(slashProps.Description, nameof(slashProps.Description)); + + model.Description = slashProps.Description.Value; + + model.Options = slashProps.Options.IsSpecified + ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() + : Optional.Unspecified; + } + + models.Add(model); + } + + return await client.ApiClient.BulkOverwriteGlobalApplicationCommandsAsync(models.ToArray(), options).ConfigureAwait(false); + } + + public static async Task> BulkOverwriteGuildCommandsAsync(BaseDiscordClient client, ulong guildId, + ApplicationCommandProperties[] args, RequestOptions options = null) + { + Preconditions.NotNull(args, nameof(args)); + + var models = new List(); + + foreach (var arg in args) + { + Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); + + var model = new CreateApplicationCommandParams + { + Name = arg.Name.Value, + Type = arg.Type, + DefaultPermission = arg.IsDefaultPermission.IsSpecified + ? arg.IsDefaultPermission.Value + : Optional.Unspecified + }; + + if (arg is SlashCommandProperties slashProps) + { + Preconditions.NotNullOrEmpty(slashProps.Description, nameof(slashProps.Description)); + + model.Description = slashProps.Description.Value; + + model.Options = slashProps.Options.IsSpecified + ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() + : Optional.Unspecified; + } + + models.Add(model); + } + + return await client.ApiClient.BulkOverwriteGuildApplicationCommandsAsync(guildId, models.ToArray(), options).ConfigureAwait(false); + } + + private static TArg GetApplicationCommandProperties(IApplicationCommand command) + where TArg : ApplicationCommandProperties + { + bool isBaseClass = typeof(TArg) == typeof(ApplicationCommandProperties); + + switch (true) + { + case true when (typeof(TArg) == typeof(SlashCommandProperties) || isBaseClass) && command.Type == ApplicationCommandType.Slash: + return new SlashCommandProperties() as TArg; + case true when (typeof(TArg) == typeof(MessageCommandProperties) || isBaseClass) && command.Type == ApplicationCommandType.Message: + return new MessageCommandProperties() as TArg; + case true when (typeof(TArg) == typeof(UserCommandProperties) || isBaseClass) && command.Type == ApplicationCommandType.User: + return new UserCommandProperties() as TArg; + default: + throw new InvalidOperationException($"Cannot modify application command of type {command.Type} with the parameter type {typeof(TArg).FullName}"); + } + } + + public static Task ModifyGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command, + Action func, RequestOptions options = null) where TArg : ApplicationCommandProperties + { + var arg = GetApplicationCommandProperties(command); + func(arg); + return ModifyGlobalCommandAsync(client, command, arg, options); + } + + public static async Task ModifyGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command, + ApplicationCommandProperties args, RequestOptions options = null) + { + if (args.Name.IsSpecified) + { + Preconditions.AtMost(args.Name.Value.Length, 32, nameof(args.Name)); + Preconditions.AtLeast(args.Name.Value.Length, 1, nameof(args.Name)); + } + + var model = new ModifyApplicationCommandParams + { + Name = args.Name, + DefaultPermission = args.IsDefaultPermission.IsSpecified + ? args.IsDefaultPermission.Value + : Optional.Unspecified + }; + + if (args is SlashCommandProperties slashProps) + { + if (slashProps.Description.IsSpecified) + { + Preconditions.AtMost(slashProps.Description.Value.Length, 100, nameof(slashProps.Description)); + Preconditions.AtLeast(slashProps.Description.Value.Length, 1, nameof(slashProps.Description)); + } + + if (slashProps.Options.IsSpecified) + { + if (slashProps.Options.Value.Count > 10) + throw new ArgumentException("Option count must be 10 or less"); + } + + model.Description = slashProps.Description; + + model.Options = slashProps.Options.IsSpecified + ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() + : Optional.Unspecified; + } + + return await client.ApiClient.ModifyGlobalApplicationCommandAsync(model, command.Id, options).ConfigureAwait(false); + } + + public static async Task DeleteGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command, RequestOptions options = null) + { + Preconditions.NotNull(command, nameof(command)); + Preconditions.NotEqual(command.Id, 0, nameof(command.Id)); + + await client.ApiClient.DeleteGlobalApplicationCommandAsync(command.Id, options).ConfigureAwait(false); + } + #endregion + + #region Guild Commands + public static Task CreateGuildCommandAsync(BaseDiscordClient client, ulong guildId, + Action func, RequestOptions options) where TArg : ApplicationCommandProperties + { + var args = Activator.CreateInstance(typeof(TArg)); + func((TArg)args); + return CreateGuildCommandAsync(client, guildId, (TArg)args, options); + } + + public static async Task CreateGuildCommandAsync(BaseDiscordClient client, ulong guildId, + ApplicationCommandProperties arg, RequestOptions options = null) + { + var model = new CreateApplicationCommandParams + { + Name = arg.Name.Value, + Type = arg.Type, + DefaultPermission = arg.IsDefaultPermission.IsSpecified + ? arg.IsDefaultPermission.Value + : Optional.Unspecified + }; + + if (arg is SlashCommandProperties slashProps) + { + Preconditions.NotNullOrEmpty(slashProps.Description, nameof(slashProps.Description)); + + model.Description = slashProps.Description.Value; + + model.Options = slashProps.Options.IsSpecified + ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() + : Optional.Unspecified; + } + + return await client.ApiClient.CreateGuildApplicationCommandAsync(model, guildId, options).ConfigureAwait(false); + } + + public static Task ModifyGuildCommandAsync(BaseDiscordClient client, IApplicationCommand command, ulong guildId, + Action func, RequestOptions options = null) where TArg : ApplicationCommandProperties + { + var arg = GetApplicationCommandProperties(command); + func(arg); + return ModifyGuildCommandAsync(client, command, guildId, arg, options); + } + + public static async Task ModifyGuildCommandAsync(BaseDiscordClient client, IApplicationCommand command, ulong guildId, + ApplicationCommandProperties arg, RequestOptions options = null) + { + var model = new ModifyApplicationCommandParams + { + Name = arg.Name, + DefaultPermission = arg.IsDefaultPermission.IsSpecified + ? arg.IsDefaultPermission.Value + : Optional.Unspecified + }; + + if (arg is SlashCommandProperties slashProps) + { + Preconditions.NotNullOrEmpty(slashProps.Description, nameof(slashProps.Description)); + + model.Description = slashProps.Description.Value; + + model.Options = slashProps.Options.IsSpecified + ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() + : Optional.Unspecified; + } + + return await client.ApiClient.ModifyGuildApplicationCommandAsync(model, guildId, command.Id, options).ConfigureAwait(false); + } + + public static async Task DeleteGuildCommandAsync(BaseDiscordClient client, ulong guildId, IApplicationCommand command, RequestOptions options = null) + { + Preconditions.NotNull(command, nameof(command)); + Preconditions.NotEqual(command.Id, 0, nameof(command.Id)); + + await client.ApiClient.DeleteGuildApplicationCommandAsync(guildId, command.Id, options).ConfigureAwait(false); + } + + public static Task DeleteUnknownApplicationCommandAsync(BaseDiscordClient client, ulong? guildId, IApplicationCommand command, RequestOptions options = null) + { + return guildId.HasValue + ? DeleteGuildCommandAsync(client, guildId.Value, command, options) + : DeleteGlobalCommandAsync(client, command, options); + } + #endregion + + #region Responses + public static async Task ModifyFollowupMessageAsync(BaseDiscordClient client, RestFollowupMessage message, Action func, + RequestOptions options = null) + { + var args = new MessageProperties(); + func(args); + + var embed = args.Embed; + var embeds = args.Embeds; + + bool hasText = args.Content.IsSpecified ? !string.IsNullOrEmpty(args.Content.Value) : !string.IsNullOrEmpty(message.Content); + bool hasEmbeds = embed.IsSpecified && embed.Value != null || embeds.IsSpecified && embeds.Value?.Length > 0 || message.Embeds.Any(); + bool hasComponents = args.Components.IsSpecified && args.Components.Value != null; + + if (!hasComponents && !hasText && !hasEmbeds) + Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content)); + + var apiEmbeds = embed.IsSpecified || embeds.IsSpecified ? new List() : null; + + if (embed.IsSpecified && embed.Value != null) + { + apiEmbeds.Add(embed.Value.ToModel()); + } + + if (embeds.IsSpecified && embeds.Value != null) + { + apiEmbeds.AddRange(embeds.Value.Select(x => x.ToModel())); + } + + Preconditions.AtMost(apiEmbeds?.Count ?? 0, 10, nameof(args.Embeds), "A max of 10 embeds are allowed."); + + var apiArgs = new ModifyInteractionResponseParams + { + Content = args.Content, + Embeds = apiEmbeds?.ToArray() ?? Optional.Unspecified, + AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional.Unspecified, + Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional.Unspecified + }; + + return await client.ApiClient.ModifyInteractionFollowupMessageAsync(apiArgs, message.Id, message.Token, options).ConfigureAwait(false); + } + public static async Task DeleteFollowupMessageAsync(BaseDiscordClient client, RestFollowupMessage message, RequestOptions options = null) + => await client.ApiClient.DeleteInteractionFollowupMessageAsync(message.Id, message.Token, options); + public static async Task ModifyInteractionResponseAsync(BaseDiscordClient client, string token, Action func, + RequestOptions options = null) + { + var args = new MessageProperties(); + func(args); + + var embed = args.Embed; + var embeds = args.Embeds; + + bool hasText = !string.IsNullOrEmpty(args.Content.GetValueOrDefault()); + bool hasEmbeds = embed.IsSpecified && embed.Value != null || embeds.IsSpecified && embeds.Value?.Length > 0; + bool hasComponents = args.Components.IsSpecified && args.Components.Value != null; + + if (!hasComponents && !hasText && !hasEmbeds) + Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content)); + + var apiEmbeds = embed.IsSpecified || embeds.IsSpecified ? new List() : null; + + if (embed.IsSpecified && embed.Value != null) + { + apiEmbeds.Add(embed.Value.ToModel()); + } + + if (embeds.IsSpecified && embeds.Value != null) + { + apiEmbeds.AddRange(embeds.Value.Select(x => x.ToModel())); + } + + Preconditions.AtMost(apiEmbeds?.Count ?? 0, 10, nameof(args.Embeds), "A max of 10 embeds are allowed."); + + var apiArgs = new ModifyInteractionResponseParams + { + Content = args.Content, + Embeds = apiEmbeds?.ToArray() ?? Optional.Unspecified, + AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional.Unspecified, + Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional.Unspecified, + Flags = args.Flags + }; + + return await client.ApiClient.ModifyInteractionResponseAsync(apiArgs, token, options).ConfigureAwait(false); + } + + public static async Task DeleteInteractionResponseAsync(BaseDiscordClient client, RestInteractionMessage message, RequestOptions options = null) + => await client.ApiClient.DeleteInteractionFollowupMessageAsync(message.Id, message.Token, options); + + public static async Task DeleteInteractionResponseAsync(BaseDiscordClient client, IDiscordInteraction interaction, RequestOptions options = null) + => await client.ApiClient.DeleteInteractionFollowupMessageAsync(interaction.Id, interaction.Token, options); + + public static Task SendAutocompleteResultAsync(BaseDiscordClient client, IEnumerable result, ulong interactionId, + string interactionToken, RequestOptions options) + { + result ??= Array.Empty(); + + Preconditions.AtMost(result.Count(), 25, nameof(result), "A maximum of 25 choices are allowed!"); + + var apiArgs = new InteractionResponse + { + Type = InteractionResponseType.ApplicationCommandAutocompleteResult, + Data = new InteractionCallbackData + { + Choices = result.Any() + ? result.Select(x => new ApplicationCommandOptionChoice { Name = x.Name, Value = x.Value }).ToArray() + : Array.Empty() + } + }; + + return client.ApiClient.CreateInteractionResponseAsync(apiArgs, interactionId, interactionToken, options); + } + #endregion + + #region Guild permissions + public static async Task> GetGuildCommandPermissionsAsync(BaseDiscordClient client, + ulong guildId, RequestOptions options) + { + var models = await client.ApiClient.GetGuildApplicationCommandPermissionsAsync(guildId, options); + return models.Select(x => + new GuildApplicationCommandPermission(x.Id, x.ApplicationId, guildId, x.Permissions.Select( + y => new ApplicationCommandPermission(y.Id, y.Type, y.Permission)) + .ToArray()) + ).ToArray(); + } + + public static async Task GetGuildCommandPermissionAsync(BaseDiscordClient client, + ulong guildId, ulong commandId, RequestOptions options) + { + try + { + var model = await client.ApiClient.GetGuildApplicationCommandPermissionAsync(guildId, commandId, options); + return new GuildApplicationCommandPermission(model.Id, model.ApplicationId, guildId, model.Permissions.Select( + y => new ApplicationCommandPermission(y.Id, y.Type, y.Permission)).ToArray()); + } + catch (HttpException x) + { + if (x.HttpCode == HttpStatusCode.NotFound) + return null; + throw; + } + } + + public static async Task ModifyGuildCommandPermissionsAsync(BaseDiscordClient client, ulong guildId, ulong commandId, + ApplicationCommandPermission[] args, RequestOptions options) + { + Preconditions.NotNull(args, nameof(args)); + Preconditions.AtMost(args.Length, 10, nameof(args)); + Preconditions.AtLeast(args.Length, 0, nameof(args)); + + var permissionsList = new List(); + + foreach (var arg in args) + { + var permissions = new ApplicationCommandPermissions + { + Id = arg.TargetId, + Permission = arg.Permission, + Type = arg.TargetType + }; + + permissionsList.Add(permissions); + } + + var model = new ModifyGuildApplicationCommandPermissionsParams + { + Permissions = permissionsList.ToArray() + }; + + var apiModel = await client.ApiClient.ModifyApplicationCommandPermissionsAsync(model, guildId, commandId, options); + + return new GuildApplicationCommandPermission(apiModel.Id, apiModel.ApplicationId, guildId, apiModel.Permissions.Select( + x => new ApplicationCommandPermission(x.Id, x.Type, x.Permission)).ToArray()); + } + + public static async Task> BatchEditGuildCommandPermissionsAsync(BaseDiscordClient client, ulong guildId, + IDictionary args, RequestOptions options) + { + Preconditions.NotNull(args, nameof(args)); + Preconditions.NotEqual(args.Count, 0, nameof(args)); + + var models = new List(); + + foreach (var arg in args) + { + Preconditions.AtMost(arg.Value.Length, 10, nameof(args)); + + var model = new ModifyGuildApplicationCommandPermissions + { + Id = arg.Key, + Permissions = arg.Value.Select(x => new ApplicationCommandPermissions + { + Id = x.TargetId, + Permission = x.Permission, + Type = x.TargetType + }).ToArray() + }; + + models.Add(model); + } + + var apiModels = await client.ApiClient.BatchModifyApplicationCommandPermissionsAsync(models.ToArray(), guildId, options); + + return apiModels.Select( + x => new GuildApplicationCommandPermission(x.Id, x.ApplicationId, x.GuildId, x.Permissions.Select( + y => new ApplicationCommandPermission(y.Id, y.Type, y.Permission)).ToArray())).ToArray(); + } + #endregion + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs b/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs new file mode 100644 index 000000000..d9643079e --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs @@ -0,0 +1,456 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Model = Discord.API.Interaction; +using DataModel = Discord.API.MessageComponentInteractionData; +using System.IO; +using Discord.Net.Rest; + +namespace Discord.Rest +{ + /// + /// Represents a REST-based message component. + /// + public class RestMessageComponent : RestInteraction, IComponentInteraction, IDiscordInteraction + { + /// + /// Gets the data received with this interaction, contains the button that was clicked. + /// + public new RestMessageComponentData Data { get; } + + /// + /// Gets the message that contained the trigger for this interaction. + /// + public RestUserMessage Message { get; private set; } + + private object _lock = new object(); + + internal RestMessageComponent(BaseDiscordClient client, Model model) + : base(client, model.Id) + { + var dataModel = model.Data.IsSpecified + ? (DataModel)model.Data.Value + : null; + + Data = new RestMessageComponentData(dataModel); + } + + internal new static async Task CreateAsync(DiscordRestClient client, Model model) + { + var entity = new RestMessageComponent(client, model); + await entity.UpdateAsync(client, model).ConfigureAwait(false); + return entity; + } + internal override async Task UpdateAsync(DiscordRestClient discord, Model model) + { + await base.UpdateAsync(discord, model).ConfigureAwait(false); + + if (model.Message.IsSpecified && model.ChannelId.IsSpecified) + { + if (Message == null) + { + Message = RestUserMessage.Create(Discord, Channel, User, model.Message.Value); + } + } + } + /// + /// Responds to an Interaction with type . + /// + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// The request options for this response. + /// + /// A string that contains json to write back to the incoming http request. + /// + public override string Respond( + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + if (!InteractionHelper.CanSendResponse(this)) + throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!"); + + embeds ??= Array.Empty(); + if (embed != null) + embeds = new[] { embed }.Concat(embeds).ToArray(); + + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed."); + + // check that user flag and user Id list are exclusive, same with role flag and role Id list + if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue) + { + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) && + allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) + { + throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions)); + } + + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) && + allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) + { + throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions)); + } + } + + var response = new API.InteractionResponse + { + Type = InteractionResponseType.ChannelMessageWithSource, + Data = new API.InteractionCallbackData + { + Content = text ?? Optional.Unspecified, + AllowedMentions = allowedMentions?.ToModel(), + Embeds = embeds.Select(x => x.ToModel()).ToArray(), + TTS = isTTS, + Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified + } + }; + + if (ephemeral) + response.Data.Value.Flags = MessageFlags.Ephemeral; + + lock (_lock) + { + if (HasResponded) + { + throw new InvalidOperationException("Cannot respond, update, or defer twice to the same interaction"); + } + + HasResponded = true; + } + + return SerializePayload(response); + } + + /// + /// Updates the message which this component resides in with the type + /// + /// A delegate containing the properties to modify the message with. + /// The request options for this request. + /// A string that contains json to write back to the incoming http request. + public string Update(Action func, RequestOptions options = null) + { + var args = new MessageProperties(); + func(args); + + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + if (!InteractionHelper.CanSendResponse(this)) + throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!"); + + if (args.AllowedMentions.IsSpecified) + { + var allowedMentions = args.AllowedMentions.Value; + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions), "A max of 100 user Ids are allowed."); + } + + var embed = args.Embed; + var embeds = args.Embeds; + + bool hasText = args.Content.IsSpecified ? !string.IsNullOrEmpty(args.Content.Value) : !string.IsNullOrEmpty(Message.Content); + bool hasEmbeds = embed.IsSpecified && embed.Value != null || embeds.IsSpecified && embeds.Value?.Length > 0 || Message.Embeds.Any(); + + if (!hasText && !hasEmbeds) + Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content)); + + var apiEmbeds = embed.IsSpecified || embeds.IsSpecified ? new List() : null; + + if (embed.IsSpecified && embed.Value != null) + { + apiEmbeds.Add(embed.Value.ToModel()); + } + + if (embeds.IsSpecified && embeds.Value != null) + { + apiEmbeds.AddRange(embeds.Value.Select(x => x.ToModel())); + } + + Preconditions.AtMost(apiEmbeds?.Count ?? 0, 10, nameof(args.Embeds), "A max of 10 embeds are allowed."); + + // check that user flag and user Id list are exclusive, same with role flag and role Id list + if (args.AllowedMentions.IsSpecified && args.AllowedMentions.Value != null && args.AllowedMentions.Value.AllowedTypes.HasValue) + { + var allowedMentions = args.AllowedMentions.Value; + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) + && allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) + { + throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(args.AllowedMentions)); + } + + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) + && allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) + { + throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(args.AllowedMentions)); + } + } + + var response = new API.InteractionResponse + { + Type = InteractionResponseType.UpdateMessage, + Data = new API.InteractionCallbackData + { + Content = args.Content, + AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional.Unspecified, + Embeds = apiEmbeds?.ToArray() ?? Optional.Unspecified, + Components = args.Components.IsSpecified + ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty() + : Optional.Unspecified, + Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional.Unspecified : Optional.Unspecified + } + }; + + lock (_lock) + { + if (HasResponded) + { + throw new InvalidOperationException("Cannot respond, update, or defer twice to the same interaction"); + } + + HasResponded = true; + } + + return SerializePayload(response); + } + + /// + public override async Task FollowupAsync( + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + embeds ??= Array.Empty(); + if (embed != null) + embeds = new[] { embed }.Concat(embeds).ToArray(); + + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed."); + + var args = new API.Rest.CreateWebhookMessageParams + { + Content = text, + AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, + IsTTS = isTTS, + Embeds = embeds.Select(x => x.ToModel()).ToArray(), + Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified + }; + + if (ephemeral) + args.Flags = MessageFlags.Ephemeral; + + return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options); + } + + /// + public override async Task FollowupWithFileAsync( + Stream fileStream, + string fileName, + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + Preconditions.NotNull(fileStream, nameof(fileStream), "File Stream must have data"); + Preconditions.NotNullOrEmpty(fileName, nameof(fileName), "File Name must not be empty or null"); + + using(var file = new FileAttachment(fileStream, fileName)) + return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + } + + /// + public override async Task FollowupWithFileAsync( + string filePath, + string fileName = null, + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + Preconditions.NotNullOrEmpty(filePath, nameof(filePath), "Path must exist"); + + fileName ??= Path.GetFileName(filePath); + Preconditions.NotNullOrEmpty(fileName, nameof(fileName), "File Name must not be empty or null"); + + using(var file = new FileAttachment(File.OpenRead(filePath), fileName)) + return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + } + + /// + public override Task FollowupWithFileAsync( + FileAttachment attachment, + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + return FollowupWithFilesAsync(new FileAttachment[] { attachment }, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options); + } + + /// + public override async Task FollowupWithFilesAsync( + IEnumerable attachments, + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + embeds ??= Array.Empty(); + if (embed != null) + embeds = new[] { embed }.Concat(embeds).ToArray(); + + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed."); + + foreach (var attachment in attachments) + { + Preconditions.NotNullOrEmpty(attachment.FileName, nameof(attachment.FileName), "File Name must not be empty or null"); + } + + // check that user flag and user Id list are exclusive, same with role flag and role Id list + if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue) + { + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) && + allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) + { + throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions)); + } + + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) && + allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) + { + throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions)); + } + } + + var flags = MessageFlags.None; + + if (ephemeral) + flags |= MessageFlags.Ephemeral; + + var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray()) { Flags = flags, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified }; + return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false); + } + + /// + /// Defers an interaction and responds with type 5 () + /// + /// to send this message ephemerally, otherwise . + /// The request options for this request. + /// + /// A string that contains json to write back to the incoming http request. + /// + public string DeferLoading(bool ephemeral = false, RequestOptions options = null) + { + if (!InteractionHelper.CanSendResponse(this)) + throw new TimeoutException($"Cannot defer an interaction after {InteractionHelper.ResponseTimeLimit} seconds of no response/acknowledgement"); + + var response = new API.InteractionResponse + { + Type = InteractionResponseType.DeferredChannelMessageWithSource, + Data = ephemeral ? new API.InteractionCallbackData { Flags = MessageFlags.Ephemeral } : Optional.Unspecified + }; + + lock (_lock) + { + if (HasResponded) + { + throw new InvalidOperationException("Cannot respond or defer twice to the same interaction"); + } + + HasResponded = true; + } + + return SerializePayload(response); + } + + /// + /// + /// + /// + /// + /// + /// A string that contains json to write back to the incoming http request. + /// + /// + /// + public override string Defer(bool ephemeral = false, RequestOptions options = null) + { + if (!InteractionHelper.CanSendResponse(this)) + throw new TimeoutException($"Cannot defer an interaction after {InteractionHelper.ResponseTimeLimit} seconds of no response/acknowledgement"); + + var response = new API.InteractionResponse + { + Type = InteractionResponseType.DeferredUpdateMessage, + Data = ephemeral ? new API.InteractionCallbackData { Flags = MessageFlags.Ephemeral } : Optional.Unspecified + }; + + lock (_lock) + { + if (HasResponded) + { + throw new InvalidOperationException("Cannot respond or defer twice to the same interaction"); + } + + HasResponded = true; + } + + return SerializePayload(response); + } + + //IComponentInteraction + /// + IComponentInteractionData IComponentInteraction.Data => Data; + + /// + IUserMessage IComponentInteraction.Message => Message; + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponentData.cs b/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponentData.cs new file mode 100644 index 000000000..e865c208c --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponentData.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Model = Discord.API.MessageComponentInteractionData; + +namespace Discord.Rest +{ + /// + /// Represents data for a . + /// + public class RestMessageComponentData : IComponentInteractionData, IDiscordInteractionData + { + /// + /// Gets the components Custom Id that was clicked. + /// + public string CustomId { get; } + + /// + /// Gets the type of the component clicked. + /// + public ComponentType Type { get; } + + /// + /// Gets the value(s) of a interaction response. + /// + public IReadOnlyCollection Values { get; } + + internal RestMessageComponentData(Model model) + { + CustomId = model.CustomId; + Type = model.ComponentType; + Values = model.Values.GetValueOrDefault(); + } + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs new file mode 100644 index 000000000..c3edaf6ff --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Threading.Tasks; +using Model = Discord.API.ApplicationCommand; + +namespace Discord.Rest +{ + /// + /// Represents a Rest-based implementation of the . + /// + public abstract class RestApplicationCommand : RestEntity, IApplicationCommand + { + /// + public ulong ApplicationId { get; private set; } + + /// + public ApplicationCommandType Type { get; private set; } + + /// + public string Name { get; private set; } + + /// + public string Description { get; private set; } + + /// + public bool IsDefaultPermission { get; private set; } + + /// + /// The options of this command. + /// + public IReadOnlyCollection Options { get; private set; } + + /// + public DateTimeOffset CreatedAt + => SnowflakeUtils.FromSnowflake(Id); + + internal RestApplicationCommand(BaseDiscordClient client, ulong id) + : base(client, id) { } + + internal static RestApplicationCommand Create(BaseDiscordClient client, Model model, ulong? guildId) + { + return guildId.HasValue + ? RestGuildCommand.Create(client, model, guildId.Value) + : RestGlobalCommand.Create(client, model); + } + + internal virtual void Update(Model model) + { + Type = model.Type; + ApplicationId = model.ApplicationId; + Name = model.Name; + Description = model.Description; + IsDefaultPermission = model.DefaultPermissions.GetValueOrDefault(true); + + Options = model.Options.IsSpecified + ? model.Options.Value.Select(RestApplicationCommandOption.Create).ToImmutableArray() + : ImmutableArray.Create(); + } + + /// + public abstract Task DeleteAsync(RequestOptions options = null); + + /// + public Task ModifyAsync(Action func, RequestOptions options = null) + { + return ModifyAsync(func, options); + } + + /// + public abstract Task ModifyAsync(Action func, RequestOptions options = null) + where TArg : ApplicationCommandProperties; + + IReadOnlyCollection IApplicationCommand.Options => Options; + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandChoice.cs b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandChoice.cs new file mode 100644 index 000000000..a40491a2c --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandChoice.cs @@ -0,0 +1,22 @@ +using Model = Discord.API.ApplicationCommandOptionChoice; + +namespace Discord.Rest +{ + /// + /// Represents a Rest-based implementation of . + /// + public class RestApplicationCommandChoice : IApplicationCommandOptionChoice + { + /// + public string Name { get; } + + /// + public object Value { get; } + + internal RestApplicationCommandChoice(Model model) + { + Name = model.Name; + Value = model.Value; + } + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs new file mode 100644 index 000000000..1273b9a1e --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs @@ -0,0 +1,104 @@ +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using Model = Discord.API.ApplicationCommandOption; + +namespace Discord.Rest +{ + /// + /// Represents a Rest-based implementation of . + /// + public class RestApplicationCommandOption : IApplicationCommandOption + { + #region RestApplicationCommandOption + /// + public ApplicationCommandOptionType Type { get; private set; } + + /// + public string Name { get; private set; } + + /// + public string Description { get; private set; } + + /// + public bool? IsDefault { get; private set; } + + /// + public bool? IsRequired { get; private set; } + + /// + public bool? IsAutocomplete { get; private set; } + + /// + public double? MinValue { get; private set; } + + /// + public double? MaxValue { get; private set; } + + /// + /// A collection of 's for this command. + /// + public IReadOnlyCollection Choices { get; private set; } + + /// + /// A collection of 's for this command. + /// + public IReadOnlyCollection Options { get; private set; } + + /// + /// The allowed channel types for this option. + /// + public IReadOnlyCollection ChannelTypes { get; private set; } + + internal RestApplicationCommandOption() { } + + internal static RestApplicationCommandOption Create(Model model) + { + var options = new RestApplicationCommandOption(); + options.Update(model); + return options; + } + + internal void Update(Model model) + { + Type = model.Type; + Name = model.Name; + Description = model.Description; + + if (model.Default.IsSpecified) + IsDefault = model.Default.Value; + + if (model.Required.IsSpecified) + IsRequired = model.Required.Value; + + if (model.MinValue.IsSpecified) + MinValue = model.MinValue.Value; + + if (model.MaxValue.IsSpecified) + MaxValue = model.MaxValue.Value; + + if (model.Autocomplete.IsSpecified) + IsAutocomplete = model.Autocomplete.Value; + + Options = model.Options.IsSpecified + ? model.Options.Value.Select(Create).ToImmutableArray() + : ImmutableArray.Create(); + + Choices = model.Choices.IsSpecified + ? model.Choices.Value.Select(x => new RestApplicationCommandChoice(x)).ToImmutableArray() + : ImmutableArray.Create(); + + ChannelTypes = model.ChannelTypes.IsSpecified + ? model.ChannelTypes.Value.ToImmutableArray() + : ImmutableArray.Create(); + } + #endregion + + #region IApplicationCommandOption + IReadOnlyCollection IApplicationCommandOption.Options + => Options; + IReadOnlyCollection IApplicationCommandOption.Choices + => Choices; + #endregion + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestGlobalCommand.cs b/src/Discord.Net.Rest/Entities/Interactions/RestGlobalCommand.cs new file mode 100644 index 000000000..c319bcf34 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/RestGlobalCommand.cs @@ -0,0 +1,40 @@ +using System; +using System.Threading.Tasks; +using Model = Discord.API.ApplicationCommand; + +namespace Discord.Rest +{ + /// + /// Represents a Rest-based global application command. + /// + public class RestGlobalCommand : RestApplicationCommand + { + internal RestGlobalCommand(BaseDiscordClient client, ulong id) + : base(client, id) { } + + internal static RestGlobalCommand Create(BaseDiscordClient client, Model model) + { + var entity = new RestGlobalCommand(client, model.Id); + entity.Update(model); + return entity; + } + + /// + public override async Task DeleteAsync(RequestOptions options = null) + => await InteractionHelper.DeleteGlobalCommandAsync(Discord, this).ConfigureAwait(false); + + /// + /// Modifies this . + /// + /// The delegate containing the properties to modify the command with. + /// The options to be used when sending the request. + /// + /// The modified command. + /// + public override async Task ModifyAsync(Action func, RequestOptions options = null) + { + var cmd = await InteractionHelper.ModifyGlobalCommandAsync(Discord, this, func, options).ConfigureAwait(false); + Update(cmd); + } + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestGuildCommand.cs b/src/Discord.Net.Rest/Entities/Interactions/RestGuildCommand.cs new file mode 100644 index 000000000..00804e57e --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/RestGuildCommand.cs @@ -0,0 +1,83 @@ +using System; +using System.Threading.Tasks; +using Model = Discord.API.ApplicationCommand; + +namespace Discord.Rest +{ + /// + /// Represents a Rest-based guild application command. + /// + public class RestGuildCommand : RestApplicationCommand + { + /// + /// The guild Id where this command originates. + /// + public ulong GuildId { get; private set; } + + internal RestGuildCommand(BaseDiscordClient client, ulong id, ulong guildId) + : base(client, id) + { + GuildId = guildId; + } + + internal static RestGuildCommand Create(BaseDiscordClient client, Model model, ulong guildId) + { + var entity = new RestGuildCommand(client, model.Id, guildId); + entity.Update(model); + return entity; + } + + /// + public override async Task DeleteAsync(RequestOptions options = null) + => await InteractionHelper.DeleteGuildCommandAsync(Discord, GuildId, this).ConfigureAwait(false); + + /// + /// Modifies this . + /// + /// The delegate containing the properties to modify the command with. + /// The options to be used when sending the request. + /// + /// The modified command + /// + public override async Task ModifyAsync(Action func, RequestOptions options = null) + { + var model = await InteractionHelper.ModifyGuildCommandAsync(Discord, this, GuildId, func, options).ConfigureAwait(false); + Update(model); + } + + /// + /// Gets this commands permissions inside of the current guild. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a + /// object defining the permissions of the current slash command. + /// + public Task GetCommandPermission(RequestOptions options = null) + => InteractionHelper.GetGuildCommandPermissionAsync(Discord, GuildId, Id, options); + + /// + /// Modifies the current command permissions for this guild command. + /// + /// The permissions to overwrite. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. The task result contains a + /// object containing the modified permissions. + /// + public Task ModifyCommandPermissions(ApplicationCommandPermission[] permissions, RequestOptions options = null) + => InteractionHelper.ModifyGuildCommandPermissionsAsync(Discord, GuildId, Id, permissions, options); + + /// + /// Gets the guild that this slash command resides in. + /// + /// if you want the approximate member and presence counts for the guild, otherwise . + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a + /// . + /// + public Task GetGuild(bool withCounts = false, RequestOptions options = null) + => ClientHelper.GetGuildAsync(Discord, GuildId, withCounts, options); + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestInteraction.cs b/src/Discord.Net.Rest/Entities/Interactions/RestInteraction.cs new file mode 100644 index 000000000..de1fdb7c4 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/RestInteraction.cs @@ -0,0 +1,315 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Model = Discord.API.Interaction; +using DataModel = Discord.API.ApplicationCommandInteractionData; +using Newtonsoft.Json; + +namespace Discord.Rest +{ + /// + /// Represents a REST-based interaction. + /// + public abstract class RestInteraction : RestEntity, IDiscordInteraction + { + /// + public InteractionType Type { get; private set; } + + /// + public IDiscordInteractionData Data { get; private set; } + + /// + public string Token { get; private set; } + + /// + public int Version { get; private set; } + + /// + /// Gets the user who invoked the interaction. + /// + public RestUser User { get; private set; } + + /// + public DateTimeOffset CreatedAt { get; private set; } + + /// + /// if the token is valid for replying to, otherwise . + /// + public bool IsValidToken + => InteractionHelper.CanRespondOrFollowup(this); + + /// + /// Gets the channel that this interaction was executed in. + /// + public IRestMessageChannel Channel { get; private set; } + + /// + /// Gets the guild this interaction was executed in. + /// + public RestGuild Guild { get; private set; } + + /// + public bool HasResponded { get; protected set; } + + internal RestInteraction(BaseDiscordClient discord, ulong id) + : base(discord, id) + { + CreatedAt = discord.UseInteractionSnowflakeDate + ? SnowflakeUtils.FromSnowflake(Id) + : DateTime.UtcNow; + } + + internal static async Task CreateAsync(DiscordRestClient client, Model model) + { + if(model.Type == InteractionType.Ping) + { + return await RestPingInteraction.CreateAsync(client, model); + } + + if (model.Type == InteractionType.ApplicationCommand) + { + var dataModel = model.Data.IsSpecified + ? (DataModel)model.Data.Value + : null; + + if (dataModel == null) + return null; + + return dataModel.Type switch + { + ApplicationCommandType.Slash => await RestSlashCommand.CreateAsync(client, model).ConfigureAwait(false), + ApplicationCommandType.Message => await RestMessageCommand.CreateAsync(client, model).ConfigureAwait(false), + ApplicationCommandType.User => await RestUserCommand.CreateAsync(client, model).ConfigureAwait(false), + _ => null + }; + } + + if (model.Type == InteractionType.MessageComponent) + return await RestMessageComponent.CreateAsync(client, model).ConfigureAwait(false); + + if (model.Type == InteractionType.ApplicationCommandAutocomplete) + return await RestAutocompleteInteraction.CreateAsync(client, model).ConfigureAwait(false); + + return null; + } + + internal virtual async Task UpdateAsync(DiscordRestClient discord, Model model) + { + Data = model.Data.IsSpecified + ? model.Data.Value + : null; + Token = model.Token; + Version = model.Version; + Type = model.Type; + + if(Guild == null && model.GuildId.IsSpecified) + { + Guild = await discord.GetGuildAsync(model.GuildId.Value); + } + + if (User == null) + { + if (model.Member.IsSpecified && model.GuildId.IsSpecified) + { + User = RestGuildUser.Create(Discord, Guild, model.Member.Value); + } + else + { + User = RestUser.Create(Discord, model.User.Value); + } + } + + if(Channel == null && model.ChannelId.IsSpecified) + { + Channel = (IRestMessageChannel)await discord.GetChannelAsync(model.ChannelId.Value); + } + } + + internal string SerializePayload(object payload) + { + var json = new StringBuilder(); + using (var text = new StringWriter(json)) + using (var writer = new JsonTextWriter(text)) + DiscordRestClient.Serializer.Serialize(writer, payload); + + return json.ToString(); + } + + /// + public abstract string Defer(bool ephemeral = false, RequestOptions options = null); + /// + /// Gets the original response for this interaction. + /// + /// The request options for this request. + /// A that represents the initial response. + public Task GetOriginalResponseAsync(RequestOptions options = null) + => InteractionHelper.GetOriginalResponseAsync(Discord, Channel, this, options); + + /// + /// Edits original response for this interaction. + /// + /// A delegate containing the properties to modify the message with. + /// The request options for this request. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + public async Task ModifyOriginalResponseAsync(Action func, RequestOptions options = null) + { + var model = await InteractionHelper.ModifyInteractionResponseAsync(Discord, Token, func, options); + return RestInteractionMessage.Create(Discord, model, Token, Channel); + } + /// + public abstract string Respond(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); + + /// + /// Sends a followup message for this interaction. + /// + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// The request options for this response. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + public abstract Task FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); + + /// + /// Sends a followup message for this interaction. + /// + /// The text of the message to be sent. + /// The file to upload. + /// The file name of the attachment. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// The request options for this response. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + public abstract Task FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); + + /// + /// Sends a followup message for this interaction. + /// + /// The text of the message to be sent. + /// The file to upload. + /// The file name of the attachment. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// The request options for this response. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + public abstract Task FollowupWithFileAsync(string filePath, string fileName = null, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); + + /// + /// Sends a followup message for this interaction. + /// + /// The attachment containing the file and description. + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// The request options for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + public abstract Task FollowupWithFileAsync(FileAttachment attachment, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); + + /// + /// Sends a followup message for this interaction. + /// + /// A collection of attachments to upload. + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// The request options for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + public abstract Task FollowupWithFilesAsync(IEnumerable attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); + + /// + public Task DeleteOriginalResponseAsync(RequestOptions options = null) + => InteractionHelper.DeleteInteractionResponseAsync(Discord, this, options); + + #region IDiscordInteraction + /// + IUser IDiscordInteraction.User => User; + + /// + Task IDiscordInteraction.RespondAsync(string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options) + => Task.FromResult(Respond(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options)); + /// + Task IDiscordInteraction.DeferAsync(bool ephemeral, RequestOptions options) + => Task.FromResult(Defer(ephemeral, options)); + /// + async Task IDiscordInteraction.FollowupAsync(string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, + MessageComponent components, Embed embed, RequestOptions options) + => await FollowupAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + /// + async Task IDiscordInteraction.GetOriginalResponseAsync(RequestOptions options) + => await GetOriginalResponseAsync(options).ConfigureAwait(false); + /// + async Task IDiscordInteraction.ModifyOriginalResponseAsync(Action func, RequestOptions options) + => await ModifyOriginalResponseAsync(func, options).ConfigureAwait(false); + /// + async Task IDiscordInteraction.FollowupWithFileAsync(Stream fileStream, string fileName, string text, Embed[] embeds, bool isTTS, bool ephemeral, + AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options) + => await FollowupWithFileAsync(fileStream, fileName, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + /// + async Task IDiscordInteraction.FollowupWithFileAsync(string filePath, string text, string fileName, Embed[] embeds, bool isTTS, bool ephemeral, + AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options) + => await FollowupWithFileAsync(filePath, text, fileName, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + /// + async Task IDiscordInteraction.FollowupWithFileAsync(FileAttachment attachment, string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options) + => await FollowupWithFileAsync(attachment, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + /// + async Task IDiscordInteraction.FollowupWithFilesAsync(IEnumerable attachments, string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options) + => await FollowupWithFilesAsync(attachments, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + /// + Task IDiscordInteraction.RespondWithFilesAsync(IEnumerable attachments, string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options) => throw new NotSupportedException("REST-Based interactions don't support files."); + /// +#if NETCOREAPP3_0_OR_GREATER != true + /// + Task IDiscordInteraction.RespondWithFileAsync(Stream fileStream, string fileName, string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options) => throw new NotSupportedException("REST-Based interactions don't support files."); + /// + Task IDiscordInteraction.RespondWithFileAsync(string filePath, string fileName, string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options) => throw new NotSupportedException("REST-Based interactions don't support files."); + /// + Task IDiscordInteraction.RespondWithFileAsync(FileAttachment attachment, string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options) => throw new NotSupportedException("REST-Based interactions don't support files."); +#endif + #endregion + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestPingInteraction.cs b/src/Discord.Net.Rest/Entities/Interactions/RestPingInteraction.cs new file mode 100644 index 000000000..71d5a588c --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/RestPingInteraction.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Model = Discord.API.Interaction; + +namespace Discord.Rest +{ + /// + /// Represents a REST-based ping interaction. + /// + public class RestPingInteraction : RestInteraction, IDiscordInteraction + { + internal RestPingInteraction(BaseDiscordClient client, ulong id) + : base(client, id) + { + } + + internal static new async Task CreateAsync(DiscordRestClient client, Model model) + { + var entity = new RestPingInteraction(client, model.Id); + await entity.UpdateAsync(client, model); + return entity; + } + + public string AcknowledgePing() + { + var model = new API.InteractionResponse() + { + Type = InteractionResponseType.Pong + }; + + return SerializePayload(model); + } + + public override string Defer(bool ephemeral = false, RequestOptions options = null) => throw new NotSupportedException(); + public override string Respond(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) => throw new NotSupportedException(); + public override Task FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) => throw new NotSupportedException(); + public override Task FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) => throw new NotSupportedException(); + public override Task FollowupWithFileAsync(string filePath, string fileName = null, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) => throw new NotSupportedException(); + public override Task FollowupWithFileAsync(FileAttachment attachment, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) => throw new NotSupportedException(); + public override Task FollowupWithFilesAsync(IEnumerable attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) => throw new NotSupportedException(); + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteraction.cs b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteraction.cs new file mode 100644 index 000000000..44d0dc6ff --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteraction.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Model = Discord.API.Interaction; +using DataModel = Discord.API.AutocompleteInteractionData; +using System.IO; + +namespace Discord.Rest +{ + /// + /// Represents a REST-based autocomplete interaction. + /// + public class RestAutocompleteInteraction : RestInteraction, IAutocompleteInteraction, IDiscordInteraction + { + /// + /// Gets the autocomplete data of this interaction. + /// + public new RestAutocompleteInteractionData Data { get; } + + private object _lock = new object(); + + internal RestAutocompleteInteraction(DiscordRestClient client, Model model) + : base(client, model.Id) + { + var dataModel = model.Data.IsSpecified + ? (DataModel)model.Data.Value + : null; + + if (dataModel != null) + Data = new RestAutocompleteInteractionData(dataModel); + } + + internal new static async Task CreateAsync(DiscordRestClient client, Model model) + { + var entity = new RestAutocompleteInteraction(client, model); + await entity.UpdateAsync(client, model).ConfigureAwait(false); + return entity; + } + + /// + /// Responds to this interaction with a set of choices. + /// + /// + /// The set of choices for the user to pick from. + /// + /// A max of 25 choices are allowed. Passing for this argument will show the executing user that + /// there is no choices for their autocompleted input. + /// + /// + /// The request options for this response. + /// + /// A string that contains json to write back to the incoming http request. + /// + public string Respond(IEnumerable result, RequestOptions options = null) + { + if (!InteractionHelper.CanSendResponse(this)) + throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!"); + + lock (_lock) + { + if (HasResponded) + { + throw new InvalidOperationException("Cannot respond twice to the same interaction"); + } + + HasResponded = true; + } + + var model = new API.InteractionResponse + { + Type = InteractionResponseType.ApplicationCommandAutocompleteResult, + Data = new API.InteractionCallbackData + { + Choices = result.Any() + ? result.Select(x => new API.ApplicationCommandOptionChoice { Name = x.Name, Value = x.Value }).ToArray() + : Array.Empty() + } + }; + + return SerializePayload(model); + } + + /// + /// Responds to this interaction with a set of choices. + /// + /// The request options for this response. + /// + /// The set of choices for the user to pick from. + /// + /// A max of 25 choices are allowed. Passing for this argument will show the executing user that + /// there is no choices for their autocompleted input. + /// + /// + /// + /// A string that contains json to write back to the incoming http request. + /// + public string Respond(RequestOptions options = null, params AutocompleteResult[] result) + => Respond(result, options); + public override string Defer(bool ephemeral = false, RequestOptions options = null) + => throw new NotSupportedException("Autocomplete interactions don't support this method!"); + public override string Respond(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + => throw new NotSupportedException("Autocomplete interactions don't support this method!"); + public override Task FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + => throw new NotSupportedException("Autocomplete interactions don't support this method!"); + public override Task FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + => throw new NotSupportedException("Autocomplete interactions don't support this method!"); + public override Task FollowupWithFileAsync(string filePath, string fileName = null, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + => throw new NotSupportedException("Autocomplete interactions don't support this method!"); + public override Task FollowupWithFileAsync(FileAttachment attachment, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + => throw new NotSupportedException("Autocomplete interactions don't support this method!"); + public override Task FollowupWithFilesAsync(IEnumerable attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + => throw new NotSupportedException("Autocomplete interactions don't support this method!"); + + + //IAutocompleteInteraction + /// + IAutocompleteInteractionData IAutocompleteInteraction.Data => Data; + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteractionData.cs b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteractionData.cs new file mode 100644 index 000000000..135eb88ea --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteractionData.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DataModel = Discord.API.AutocompleteInteractionData; + +namespace Discord.Rest +{ + /// + /// Represents the data for a . + /// + public class RestAutocompleteInteractionData : IAutocompleteInteractionData + { + /// + /// Gets the name of the invoked command. + /// + public string CommandName { get; } + + /// + /// Gets the id of the invoked command. + /// + public ulong CommandId { get; } + + /// + /// Gets the type of the invoked command. + /// + public ApplicationCommandType Type { get; } + + /// + /// Gets the version of the invoked command. + /// + public ulong Version { get; } + + /// + /// Gets the current autocomplete option that is actively being filled out. + /// + public AutocompleteOption Current { get; } + + /// + /// Gets a collection of all the other options the executing users has filled out. + /// + public IReadOnlyCollection Options { get; } + + internal RestAutocompleteInteractionData(DataModel model) + { + var options = model.Options.SelectMany(GetOptions); + + Current = options.FirstOrDefault(x => x.Focused); + Options = options.ToImmutableArray(); + + if (Options.Count == 1 && Current == null) + Current = Options.FirstOrDefault(); + + CommandName = model.Name; + CommandId = model.Id; + Type = model.Type; + Version = model.Version; + } + + private List GetOptions(API.AutocompleteInteractionDataOption model) + { + var options = new List(); + + options.Add(new AutocompleteOption(model.Type, model.Name, model.Value.GetValueOrDefault(null), model.Focused.GetValueOrDefault(false))); + + if (model.Options.IsSpecified) + { + options.AddRange(model.Options.Value.SelectMany(GetOptions)); + } + + return options; + } + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestSlashCommand.cs b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestSlashCommand.cs new file mode 100644 index 000000000..21184fcf6 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestSlashCommand.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DataModel = Discord.API.ApplicationCommandInteractionData; +using Model = Discord.API.Interaction; + +namespace Discord.Rest +{ + /// + /// Represents a REST-based slash command. + /// + public class RestSlashCommand : RestCommandBase, ISlashCommandInteraction, IDiscordInteraction + { + /// + /// Gets the data associated with this interaction. + /// + public new RestSlashCommandData Data { get; private set; } + + internal RestSlashCommand(DiscordRestClient client, Model model) + : base(client, model) + { + } + + internal new static async Task CreateAsync(DiscordRestClient client, Model model) + { + var entity = new RestSlashCommand(client, model); + await entity.UpdateAsync(client, model).ConfigureAwait(false); + return entity; + } + + internal override async Task UpdateAsync(DiscordRestClient client, Model model) + { + await base.UpdateAsync(client, model).ConfigureAwait(false); + + var dataModel = model.Data.IsSpecified + ? (DataModel)model.Data.Value + : null; + + Data = await RestSlashCommandData.CreateAsync(client, dataModel, Guild, Channel).ConfigureAwait(false); + } + + //ISlashCommandInteraction + /// + IApplicationCommandInteractionData ISlashCommandInteraction.Data => Data; + + //IApplicationCommandInteraction + /// + IApplicationCommandInteractionData IApplicationCommandInteraction.Data => Data; + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestSlashCommandData.cs b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestSlashCommandData.cs new file mode 100644 index 000000000..f967cc628 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestSlashCommandData.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Model = Discord.API.ApplicationCommandInteractionData; + +namespace Discord.Rest +{ + + public class RestSlashCommandData : RestCommandBaseData, IDiscordInteractionData + { + internal RestSlashCommandData(DiscordRestClient client, Model model) + : base(client, model) { } + + internal static new async Task CreateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel) + { + var entity = new RestSlashCommandData(client, model); + await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); + return entity; + } + internal override async Task UpdateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel) + { + await base.UpdateAsync(client, model, guild, channel).ConfigureAwait(false); + + Options = model.Options.IsSpecified + ? model.Options.Value.Select(x => new RestSlashCommandDataOption(this, x)).ToImmutableArray() + : ImmutableArray.Create(); + } + } +} diff --git a/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestSlashCommandDataOption.cs b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestSlashCommandDataOption.cs new file mode 100644 index 000000000..bb931f68e --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestSlashCommandDataOption.cs @@ -0,0 +1,139 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Model = Discord.API.ApplicationCommandInteractionDataOption; + + +namespace Discord.Rest +{ + /// + /// Represents a REST-based option for a slash command. + /// + public class RestSlashCommandDataOption : IApplicationCommandInteractionDataOption + { + #region RestSlashCommandDataOption + /// + public string Name { get; private set; } + + /// + public object Value { get; private set; } + + /// + public ApplicationCommandOptionType Type { get; private set; } + + /// + /// Gets a collection of sub command options received for this sub command group. + /// + public IReadOnlyCollection Options { get; private set; } + + internal RestSlashCommandDataOption() { } + internal RestSlashCommandDataOption(RestSlashCommandData data, Model model) + { + Name = model.Name; + Type = model.Type; + + if (model.Value.IsSpecified) + { + switch (Type) + { + case ApplicationCommandOptionType.User: + case ApplicationCommandOptionType.Role: + case ApplicationCommandOptionType.Channel: + case ApplicationCommandOptionType.Mentionable: + if (ulong.TryParse($"{model.Value.Value}", out var valueId)) + { + switch (Type) + { + case ApplicationCommandOptionType.User: + { + var guildUser = data.ResolvableData.GuildMembers.FirstOrDefault(x => x.Key == valueId).Value; + + if (guildUser != null) + Value = guildUser; + else + Value = data.ResolvableData.Users.FirstOrDefault(x => x.Key == valueId).Value; + } + break; + case ApplicationCommandOptionType.Channel: + Value = data.ResolvableData.Channels.FirstOrDefault(x => x.Key == valueId).Value; + break; + case ApplicationCommandOptionType.Role: + Value = data.ResolvableData.Roles.FirstOrDefault(x => x.Key == valueId).Value; + break; + case ApplicationCommandOptionType.Mentionable: + { + if (data.ResolvableData.GuildMembers.Any(x => x.Key == valueId) || data.ResolvableData.Users.Any(x => x.Key == valueId)) + { + var guildUser = data.ResolvableData.GuildMembers.FirstOrDefault(x => x.Key == valueId).Value; + + if (guildUser != null) + Value = guildUser; + else + Value = data.ResolvableData.Users.FirstOrDefault(x => x.Key == valueId).Value; + } + else if (data.ResolvableData.Roles.Any(x => x.Key == valueId)) + { + Value = data.ResolvableData.Roles.FirstOrDefault(x => x.Key == valueId).Value; + } + } + break; + default: + Value = model.Value.Value; + break; + } + } + break; + case ApplicationCommandOptionType.String: + Value = model.Value.ToString(); + break; + case ApplicationCommandOptionType.Integer: + { + if (model.Value.Value is long val) + Value = val; + else if (long.TryParse(model.Value.Value.ToString(), out long res)) + Value = res; + } + break; + case ApplicationCommandOptionType.Boolean: + { + if (model.Value.Value is bool val) + Value = val; + else if (bool.TryParse(model.Value.Value.ToString(), out bool res)) + Value = res; + } + break; + case ApplicationCommandOptionType.Number: + { + if (model.Value.Value is int val) + Value = val; + else if (double.TryParse(model.Value.Value.ToString(), out double res)) + Value = res; + } + break; + } + } + + Options = model.Options.IsSpecified + ? model.Options.Value.Select(x => new RestSlashCommandDataOption(data, x)).ToImmutableArray() + : ImmutableArray.Create(); + } + #endregion + + #region Converters + public static explicit operator bool(RestSlashCommandDataOption option) + => (bool)option.Value; + public static explicit operator int(RestSlashCommandDataOption option) + => (int)option.Value; + public static explicit operator string(RestSlashCommandDataOption option) + => option.Value.ToString(); + #endregion + + #region IApplicationCommandInteractionDataOption + IReadOnlyCollection IApplicationCommandInteractionDataOption.Options + => Options; + #endregion + } +} diff --git a/src/Discord.Net.Rest/Entities/Invites/RestInvite.cs b/src/Discord.Net.Rest/Entities/Invites/RestInvite.cs index 153eb6c41..95b454c20 100644 --- a/src/Discord.Net.Rest/Entities/Invites/RestInvite.cs +++ b/src/Discord.Net.Rest/Entities/Invites/RestInvite.cs @@ -21,6 +21,12 @@ namespace Discord.Rest public ulong ChannelId { get; private set; } /// public ulong? GuildId { get; private set; } + /// + public IUser Inviter { get; private set; } + /// + public IUser TargetUser { get; private set; } + /// + public TargetUserType TargetUserType { get; private set; } internal IChannel Channel { get; } internal IGuild Guild { get; } @@ -50,6 +56,9 @@ namespace Discord.Rest MemberCount = model.MemberCount.IsSpecified ? model.MemberCount.Value : null; PresenceCount = model.PresenceCount.IsSpecified ? model.PresenceCount.Value : null; ChannelType = (ChannelType)model.Channel.Type; + Inviter = model.Inviter.IsSpecified ? RestUser.Create(Discord, model.Inviter.Value) : null; + TargetUser = model.TargetUser.IsSpecified ? RestUser.Create(Discord, model.TargetUser.Value) : null; + TargetUserType = model.TargetUserType.IsSpecified ? model.TargetUserType.Value : TargetUserType.Undefined; } /// diff --git a/src/Discord.Net.Rest/Entities/Invites/RestInviteMetadata.cs b/src/Discord.Net.Rest/Entities/Invites/RestInviteMetadata.cs index 55acd5f45..a0ed9ec81 100644 --- a/src/Discord.Net.Rest/Entities/Invites/RestInviteMetadata.cs +++ b/src/Discord.Net.Rest/Entities/Invites/RestInviteMetadata.cs @@ -6,10 +6,8 @@ namespace Discord.Rest /// Represents additional information regarding the REST-based invite object. public class RestInviteMetadata : RestInvite, IInviteMetadata { - private long? _createdAtTicks; + private long _createdAtTicks; - /// - public bool IsRevoked { get; private set; } /// public bool IsTemporary { get; private set; } /// @@ -18,10 +16,6 @@ namespace Discord.Rest public int? MaxUses { get; private set; } /// public int? Uses { get; private set; } - /// - /// Gets the user that created this invite. - /// - public RestUser Inviter { get; private set; } /// public DateTimeOffset? CreatedAt => DateTimeUtils.FromTicks(_createdAtTicks); @@ -39,16 +33,11 @@ namespace Discord.Rest internal void Update(Model model) { base.Update(model); - Inviter = model.Inviter != null ? RestUser.Create(Discord, model.Inviter) : null; - IsRevoked = model.Revoked; IsTemporary = model.Temporary; - MaxAge = model.MaxAge.IsSpecified ? model.MaxAge.Value : (int?)null; - MaxUses = model.MaxUses.IsSpecified ? model.MaxUses.Value : (int?)null; - Uses = model.Uses.IsSpecified ? model.Uses.Value : (int?)null; - _createdAtTicks = model.CreatedAt.IsSpecified ? model.CreatedAt.Value.UtcTicks : (long?)null; + MaxAge = model.MaxAge; + MaxUses = model.MaxUses; + Uses = model.Uses; + _createdAtTicks = model.CreatedAt.UtcTicks; } - - /// - IUser IInviteMetadata.Inviter => Inviter; } } diff --git a/src/Discord.Net.Rest/Entities/Messages/Attachment.cs b/src/Discord.Net.Rest/Entities/Messages/Attachment.cs index abe049180..4e4849c51 100644 --- a/src/Discord.Net.Rest/Entities/Messages/Attachment.cs +++ b/src/Discord.Net.Rest/Entities/Messages/Attachment.cs @@ -3,7 +3,7 @@ using Model = Discord.API.Attachment; namespace Discord { - /// + /// [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class Attachment : IAttachment { @@ -21,8 +21,10 @@ namespace Discord public int? Height { get; } /// public int? Width { get; } + /// + public bool Ephemeral { get; } - internal Attachment(ulong id, string filename, string url, string proxyUrl, int size, int? height, int? width) + internal Attachment(ulong id, string filename, string url, string proxyUrl, int size, int? height, int? width, bool? ephemeral) { Id = id; Filename = filename; @@ -31,12 +33,14 @@ namespace Discord Size = size; Height = height; Width = width; + Ephemeral = ephemeral.GetValueOrDefault(false); } internal static Attachment Create(Model model) { return new Attachment(model.Id, model.Filename, model.Url, model.ProxyUrl, model.Size, model.Height.IsSpecified ? model.Height.Value : (int?)null, - model.Width.IsSpecified ? model.Width.Value : (int?)null); + model.Width.IsSpecified ? model.Width.Value : (int?)null, + model.Ephemeral.ToNullable()); } /// diff --git a/src/Discord.Net.Rest/Entities/Messages/CustomSticker.cs b/src/Discord.Net.Rest/Entities/Messages/CustomSticker.cs new file mode 100644 index 000000000..6fd0f7700 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Messages/CustomSticker.cs @@ -0,0 +1,74 @@ +using System; +using System.Diagnostics; +using System.Threading.Tasks; +using Model = Discord.API.Sticker; + +namespace Discord.Rest +{ + /// + /// Represents a Rest-based custom sticker within a guild. + /// + [DebuggerDisplay(@"{DebuggerDisplay,nq}")] + public class CustomSticker : Sticker, ICustomSticker + { + /// + /// Gets the users id who uploaded the sticker. + /// + /// + /// In order to get the author id, the bot needs the MANAGE_EMOJIS_AND_STICKERS permission. + /// + public ulong? AuthorId { get; private set; } + + /// + /// Gets the guild that this custom sticker is in. + /// + /// + /// Note: This property can be if the sticker wasn't fetched from a guild. + /// + public RestGuild Guild { get; private set; } + + private ulong GuildId { get; set; } + + internal CustomSticker(BaseDiscordClient client, ulong id, RestGuild guild, ulong? authorId = null) + : base(client, id) + { + AuthorId = authorId; + Guild = guild; + } + internal CustomSticker(BaseDiscordClient client, ulong id, ulong guildId, ulong? authorId = null) + : base(client, id) + { + AuthorId = authorId; + GuildId = guildId; + } + + internal static CustomSticker Create(BaseDiscordClient client, Model model, RestGuild guild, ulong? authorId = null) + { + var entity = new CustomSticker(client, model.Id, guild, authorId); + entity.Update(model); + return entity; + } + + internal static CustomSticker Create(BaseDiscordClient client, Model model, ulong guildId, ulong? authorId = null) + { + var entity = new CustomSticker(client, model.Id, guildId, authorId); + entity.Update(model); + return entity; + } + + /// + public Task DeleteAsync(RequestOptions options = null) + => GuildHelper.DeleteStickerAsync(Discord, GuildId, this, options); + + /// + public async Task ModifyAsync(Action func, RequestOptions options = null) + { + var model = await GuildHelper.ModifyStickerAsync(Discord, GuildId, this, func, options); + Update(model); + } + + private string DebuggerDisplay => Guild != null ? $"{Name} in {Guild.Name} ({Id})" : $"{Name} ({Id})"; + + IGuild ICustomSticker.Guild => Guild; + } +} diff --git a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs index 57f8b2509..cd2a34f11 100644 --- a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs +++ b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs @@ -1,3 +1,4 @@ +using Discord.API; using Discord.API.Rest; using System; using System.Collections.Generic; @@ -6,6 +7,7 @@ using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; using Model = Discord.API.Message; +using UserModel = Discord.API.User; namespace Discord.Rest { @@ -23,26 +25,92 @@ namespace Discord.Rest /// Only the author of a message may modify the message. /// Message content is too long, length must be less or equal to . - public static async Task ModifyAsync(IMessage msg, BaseDiscordClient client, Action func, + public static Task ModifyAsync(IMessage msg, BaseDiscordClient client, Action func, RequestOptions options) - { - if (msg.Author.Id != client.CurrentUser.Id) - throw new InvalidOperationException("Only the author of a message may modify the message."); + => ModifyAsync(msg.Channel.Id, msg.Id, client, func, options); + public static async Task ModifyAsync(ulong channelId, ulong msgId, BaseDiscordClient client, Action func, + RequestOptions options) + { var args = new MessageProperties(); func(args); - bool hasText = args.Content.IsSpecified ? !string.IsNullOrEmpty(args.Content.Value) : !string.IsNullOrEmpty(msg.Content); - bool hasEmbed = args.Embed.IsSpecified ? args.Embed.Value != null : msg.Embeds.Any(); - if (!hasText && !hasEmbed) + var embed = args.Embed; + var embeds = args.Embeds; + + bool hasText = args.Content.IsSpecified && string.IsNullOrEmpty(args.Content.Value); + bool hasEmbeds = embed.IsSpecified && embed.Value != null || embeds.IsSpecified && embeds.Value?.Length > 0; + bool hasComponents = args.Components.IsSpecified && args.Components.Value != null; + bool hasAttachments = args.Attachments.IsSpecified; + bool hasFlags = args.Flags.IsSpecified; + + // No content needed if modifying flags + if ((!hasComponents && !hasText && !hasEmbeds && !hasAttachments) && !hasFlags) Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content)); - var apiArgs = new API.Rest.ModifyMessageParams + if (args.AllowedMentions.IsSpecified) { - Content = args.Content, - Embed = args.Embed.IsSpecified ? args.Embed.Value.ToModel() : Optional.Create() - }; - return await client.ApiClient.ModifyMessageAsync(msg.Channel.Id, msg.Id, apiArgs, options).ConfigureAwait(false); + AllowedMentions allowedMentions = args.AllowedMentions.Value; + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(args.Embeds.Value?.Length ?? 0, 10, nameof(args.Embeds), "A max of 10 embeds are allowed."); + + // check that user flag and user Id list are exclusive, same with role flag and role Id list + if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue) + { + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) && + allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) + { + throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions)); + } + + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) && + allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) + { + throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions)); + } + } + } + + var apiEmbeds = embed.IsSpecified || embeds.IsSpecified ? new List() : null; + + if (embed.IsSpecified && embed.Value != null) + { + apiEmbeds.Add(embed.Value.ToModel()); + } + + if (embeds.IsSpecified && embeds.Value != null) + { + apiEmbeds.AddRange(embeds.Value.Select(x => x.ToModel())); + } + + Preconditions.AtMost(apiEmbeds?.Count ?? 0, 10, nameof(args.Embeds), "A max of 10 embeds are allowed."); + + if(!args.Attachments.IsSpecified) + { + var apiArgs = new API.Rest.ModifyMessageParams + { + Content = args.Content, + Embeds = apiEmbeds?.ToArray() ?? Optional.Unspecified, + Flags = args.Flags.IsSpecified ? args.Flags.Value : Optional.Create(), + AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional.Create(), + Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty() : Optional.Unspecified, + }; + return await client.ApiClient.ModifyMessageAsync(channelId, msgId, apiArgs, options).ConfigureAwait(false); + } + else + { + var apiArgs = new UploadFileParams(args.Attachments.Value.ToArray()) + { + Content = args.Content, + Embeds = apiEmbeds?.ToArray() ?? Optional.Unspecified, + Flags = args.Flags.IsSpecified ? args.Flags.Value : Optional.Create(), + AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional.Create(), + MessageComponent = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty() : Optional.Unspecified + }; + + return await client.ApiClient.ModifyMessageAsync(channelId, msgId, apiArgs, options).ConfigureAwait(false); + } } public static Task DeleteAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) @@ -54,23 +122,29 @@ namespace Discord.Rest await client.ApiClient.DeleteMessageAsync(channelId, msgId, options).ConfigureAwait(false); } - public static async Task SuppressEmbedsAsync(IMessage msg, BaseDiscordClient client, bool suppress, RequestOptions options) + public static async Task AddReactionAsync(ulong channelId, ulong messageId, IEmote emote, BaseDiscordClient client, RequestOptions options) { - var apiArgs = new API.Rest.SuppressEmbedParams - { - Suppressed = suppress - }; - await client.ApiClient.SuppressEmbedAsync(msg.Channel.Id, msg.Id, apiArgs, options).ConfigureAwait(false); + await client.ApiClient.AddReactionAsync(channelId, messageId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false); } public static async Task AddReactionAsync(IMessage msg, IEmote emote, BaseDiscordClient client, RequestOptions options) { - await client.ApiClient.AddReactionAsync(msg.Channel.Id, msg.Id, emote is Emote e ? $"{e.Name}:{e.Id}" : emote.Name, options).ConfigureAwait(false); + await client.ApiClient.AddReactionAsync(msg.Channel.Id, msg.Id, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false); + } + + public static async Task RemoveReactionAsync(ulong channelId, ulong messageId, ulong userId, IEmote emote, BaseDiscordClient client, RequestOptions options) + { + await client.ApiClient.RemoveReactionAsync(channelId, messageId, userId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false); } public static async Task RemoveReactionAsync(IMessage msg, ulong userId, IEmote emote, BaseDiscordClient client, RequestOptions options) { - await client.ApiClient.RemoveReactionAsync(msg.Channel.Id, msg.Id, userId, emote is Emote e ? $"{e.Name}:{e.Id}" : emote.Name, options).ConfigureAwait(false); + await client.ApiClient.RemoveReactionAsync(msg.Channel.Id, msg.Id, userId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false); + } + + public static async Task RemoveAllReactionsAsync(ulong channelId, ulong messageId, BaseDiscordClient client, RequestOptions options) + { + await client.ApiClient.RemoveAllReactionsAsync(channelId, messageId, options).ConfigureAwait(false); } public static async Task RemoveAllReactionsAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) @@ -78,11 +152,21 @@ namespace Discord.Rest await client.ApiClient.RemoveAllReactionsAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false); } + public static async Task RemoveAllReactionsForEmoteAsync(ulong channelId, ulong messageId, IEmote emote, BaseDiscordClient client, RequestOptions options) + { + await client.ApiClient.RemoveAllReactionsForEmoteAsync(channelId, messageId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false); + } + + public static async Task RemoveAllReactionsForEmoteAsync(IMessage msg, IEmote emote, BaseDiscordClient client, RequestOptions options) + { + await client.ApiClient.RemoveAllReactionsForEmoteAsync(msg.Channel.Id, msg.Id, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false); + } + public static IAsyncEnumerable> GetReactionUsersAsync(IMessage msg, IEmote emote, int? limit, BaseDiscordClient client, RequestOptions options) { Preconditions.NotNull(emote, nameof(emote)); - var emoji = (emote is Emote e ? $"{e.Name}:{e.Id}" : emote.Name); + var emoji = (emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name)); return new PagedAsyncEnumerable( DiscordConfig.MaxUserReactionsPerBatch, @@ -109,7 +193,21 @@ namespace Discord.Rest }, count: limit ); + } + private static string UrlEncode(string text) + { +#if NET461 + return System.Net.WebUtility.UrlEncode(text); +#else + return System.Web.HttpUtility.UrlEncode(text); +#endif + } + public static string SanitizeMessage(IMessage message) + { + var newContent = MentionUtils.Resolve(message, 0, TagHandling.FullName, TagHandling.FullName, TagHandling.FullName, TagHandling.FullName, TagHandling.FullName); + newContent = Format.StripMarkDown(newContent); + return newContent; } public static async Task PinAsync(IMessage msg, BaseDiscordClient client, @@ -209,7 +307,7 @@ namespace Discord.Rest tags.Add(new Tag(TagType.Emoji, index, content.Length, emoji.Id, emoji)); else //Bad Tag { - index = index + 1; + index++; continue; } index = endIndex + 1; @@ -277,7 +375,7 @@ namespace Discord.Rest public static MessageSource GetSource(Model msg) { - if (msg.Type != MessageType.Default) + if (msg.Type != MessageType.Default && msg.Type != MessageType.Reply) return MessageSource.System; else if (msg.WebhookId.IsSpecified) return MessageSource.Webhook; @@ -294,5 +392,15 @@ namespace Discord.Rest { await client.ApiClient.CrosspostAsync(channelId, msgId, options).ConfigureAwait(false); } + + public static IUser GetAuthor(BaseDiscordClient client, IGuild guild, UserModel model, ulong? webhookId) + { + IUser author = null; + if (guild != null) + author = guild.GetUserAsync(model.Id, CacheMode.CacheOnly).Result; + if (author == null) + author = RestUser.Create(client, guild, model, webhookId); + return author; + } } } diff --git a/src/Discord.Net.Rest/Entities/Messages/RestFollowupMessage.cs b/src/Discord.Net.Rest/Entities/Messages/RestFollowupMessage.cs new file mode 100644 index 000000000..aa5dd5aeb --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Messages/RestFollowupMessage.cs @@ -0,0 +1,78 @@ +using System; +using System.Threading.Tasks; +using Model = Discord.API.Message; + +namespace Discord.Rest +{ + /// + /// Represents a REST-based follow up message sent by a bot responding to an interaction. + /// + public class RestFollowupMessage : RestUserMessage + { + // Token used to delete/modify this followup message + internal string Token { get; } + + internal RestFollowupMessage(BaseDiscordClient discord, ulong id, IUser author, string token, IMessageChannel channel) + : base(discord, id, channel, author, MessageSource.Bot) + { + Token = token; + } + + internal static RestFollowupMessage Create(BaseDiscordClient discord, Model model, string token, IMessageChannel channel) + { + var entity = new RestFollowupMessage(discord, model.Id, model.Author.IsSpecified ? RestUser.Create(discord, model.Author.Value) : discord.CurrentUser, token, channel); + entity.Update(model); + return entity; + } + + internal new void Update(Model model) + { + base.Update(model); + } + + /// + /// Deletes this object and all of it's children. + /// + /// A task that represents the asynchronous delete operation. + public Task DeleteAsync() + => InteractionHelper.DeleteFollowupMessageAsync(Discord, this); + + /// + /// Modifies this interaction followup message. + /// + /// + /// This method modifies this message with the specified properties. To see an example of this + /// method and what properties are available, please refer to . + /// + /// + /// The following example replaces the content of the message with Hello World!. + /// + /// await msg.ModifyAsync(x => x.Content = "Hello World!"); + /// + /// + /// A delegate containing the properties to modify the message with. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + /// The token used to modify/delete this message expired. + /// /// Something went wrong during the request. + public new async Task ModifyAsync(Action func, RequestOptions options = null) + { + try + { + var model = await InteractionHelper.ModifyFollowupMessageAsync(Discord, this, func, options).ConfigureAwait(false); + Update(model); + } + catch (Net.HttpException x) + { + if (x.HttpCode == System.Net.HttpStatusCode.NotFound) + { + throw new InvalidOperationException("The token of this message has expired!", x); + } + + throw; + } + } + } +} diff --git a/src/Discord.Net.Rest/Entities/Messages/RestInteractionMessage.cs b/src/Discord.Net.Rest/Entities/Messages/RestInteractionMessage.cs new file mode 100644 index 000000000..a055a69b4 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Messages/RestInteractionMessage.cs @@ -0,0 +1,78 @@ +using System; +using System.Threading.Tasks; +using MessageModel = Discord.API.Message; + +namespace Discord.Rest +{ + /// + /// Represents the initial REST-based response to an interaction. + /// + public class RestInteractionMessage : RestUserMessage + { + public InteractionResponseType ResponseType { get; private set; } + internal string Token { get; } + + internal RestInteractionMessage(BaseDiscordClient discord, ulong id, IUser author, string token, IMessageChannel channel) + : base(discord, id, channel, author, MessageSource.Bot) + { + Token = token; + } + + internal static RestInteractionMessage Create(BaseDiscordClient discord, MessageModel model, string token, IMessageChannel channel) + { + var entity = new RestInteractionMessage(discord, model.Id, model.Author.IsSpecified ? RestUser.Create(discord, model.Author.Value) : discord.CurrentUser, token, channel); + entity.Update(model); + return entity; + } + + internal new void Update(MessageModel model) + { + base.Update(model); + } + + /// + /// Deletes this object and all of it's children. + /// + /// A task that represents the asynchronous delete operation. + public Task DeleteAsync() + => InteractionHelper.DeleteInteractionResponseAsync(Discord, this); + + /// + /// Modifies this interaction response + /// + /// + /// This method modifies this message with the specified properties. To see an example of this + /// method and what properties are available, please refer to . + /// + /// + /// The following example replaces the content of the message with Hello World!. + /// + /// await msg.ModifyAsync(x => x.Content = "Hello World!"); + /// + /// + /// A delegate containing the properties to modify the message with. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + /// The token used to modify/delete this message expired. + /// /// Something went wrong during the request. + public new async Task ModifyAsync(Action func, RequestOptions options = null) + { + try + { + var model = await InteractionHelper.ModifyInteractionResponseAsync(Discord, Token, func, options).ConfigureAwait(false); + Update(model); + } + catch (Net.HttpException x) + { + if (x.HttpCode == System.Net.HttpStatusCode.NotFound) + { + throw new InvalidOperationException("The token of this message has expired!", x); + } + + throw; + } + } + } +} diff --git a/src/Discord.Net.Rest/Entities/Messages/RestMessage.cs b/src/Discord.Net.Rest/Entities/Messages/RestMessage.cs index b4a33c76c..c48a60aac 100644 --- a/src/Discord.Net.Rest/Entities/Messages/RestMessage.cs +++ b/src/Discord.Net.Rest/Entities/Messages/RestMessage.cs @@ -1,3 +1,4 @@ +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Collections.Immutable; @@ -14,6 +15,7 @@ namespace Discord.Rest { private long _timestampTicks; private ImmutableArray _reactions = ImmutableArray.Create(); + private ImmutableArray _userMentions = ImmutableArray.Create(); /// public IMessageChannel Channel { get; } @@ -27,6 +29,9 @@ namespace Discord.Rest /// public string Content { get; private set; } + /// + public string CleanContent => MessageHelper.SanitizeMessage(this); + /// public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); /// @@ -37,6 +42,9 @@ namespace Discord.Rest public virtual bool IsSuppressed => false; /// public virtual DateTimeOffset? EditedTimestamp => null; + /// + public virtual bool MentionedEveryone => false; + /// /// Gets a collection of the 's on the message. /// @@ -49,12 +57,10 @@ namespace Discord.Rest public virtual IReadOnlyCollection MentionedChannelIds => ImmutableArray.Create(); /// public virtual IReadOnlyCollection MentionedRoleIds => ImmutableArray.Create(); - /// - /// Gets a collection of the mentioned users in the message. - /// - public virtual IReadOnlyCollection MentionedUsers => ImmutableArray.Create(); /// public virtual IReadOnlyCollection Tags => ImmutableArray.Create(); + /// + public virtual IReadOnlyCollection Stickers => ImmutableArray.Create(); /// public DateTimeOffset Timestamp => DateTimeUtils.FromTicks(_timestampTicks); @@ -65,6 +71,22 @@ namespace Discord.Rest /// public MessageReference Reference { get; private set; } + /// + /// Gets the interaction this message is a response to. + /// + public MessageInteraction Interaction { get; private set; } + /// + public MessageFlags? Flags { get; private set; } + /// + public MessageType Type { get; private set; } + + /// + public IReadOnlyCollection Components { get; private set; } + /// + /// Gets a collection of the mentioned users in the message. + /// + public IReadOnlyCollection MentionedUsers => _userMentions; + internal RestMessage(BaseDiscordClient discord, ulong id, IMessageChannel channel, IUser author, MessageSource source) : base(discord, id) { @@ -74,13 +96,18 @@ namespace Discord.Rest } internal static RestMessage Create(BaseDiscordClient discord, IMessageChannel channel, IUser author, Model model) { - if (model.Type == MessageType.Default) + if (model.Type == MessageType.Default || + model.Type == MessageType.Reply || + model.Type == MessageType.ApplicationCommand || + model.Type == MessageType.ThreadStarterMessage) return RestUserMessage.Create(discord, channel, author, model); else return RestSystemMessage.Create(discord, channel, author, model); } internal virtual void Update(Model model) { + Type = model.Type; + if (model.Timestamp.IsSpecified) _timestampTicks = model.Timestamp.Value.UtcTicks; @@ -110,17 +137,70 @@ namespace Discord.Rest }; } - if(model.Reference.IsSpecified) + if (model.Reference.IsSpecified) { // Creates a new Reference from the API model Reference = new MessageReference { GuildId = model.Reference.Value.GuildId, - ChannelId = model.Reference.Value.ChannelId, + InternalChannelId = model.Reference.Value.ChannelId, MessageId = model.Reference.Value.MessageId }; } + if (model.Components.IsSpecified) + { + Components = model.Components.Value.Select(x => new ActionRowComponent(x.Components.Select(y => + { + switch (y.Type) + { + case ComponentType.Button: + { + var parsed = (API.ButtonComponent)y; + return new Discord.ButtonComponent( + parsed.Style, + parsed.Label.GetValueOrDefault(), + parsed.Emote.IsSpecified + ? parsed.Emote.Value.Id.HasValue + ? new Emote(parsed.Emote.Value.Id.Value, parsed.Emote.Value.Name, parsed.Emote.Value.Animated.GetValueOrDefault()) + : new Emoji(parsed.Emote.Value.Name) + : null, + parsed.CustomId.GetValueOrDefault(), + parsed.Url.GetValueOrDefault(), + parsed.Disabled.GetValueOrDefault()); + } + case ComponentType.SelectMenu: + { + var parsed = (API.SelectMenuComponent)y; + return new SelectMenuComponent( + parsed.CustomId, + parsed.Options.Select(z => new SelectMenuOption( + z.Label, + z.Value, + z.Description.GetValueOrDefault(), + z.Emoji.IsSpecified + ? z.Emoji.Value.Id.HasValue + ? new Emote(z.Emoji.Value.Id.Value, z.Emoji.Value.Name, z.Emoji.Value.Animated.GetValueOrDefault()) + : new Emoji(z.Emoji.Value.Name) + : null, + z.Default.ToNullable())).ToList(), + parsed.Placeholder.GetValueOrDefault(), + parsed.MinValues, + parsed.MaxValues, + parsed.Disabled + ); + } + default: + return null; + } + }).ToList())).ToImmutableArray(); + } + else + Components = new List(); + + if (model.Flags.IsSpecified) + Flags = model.Flags.Value; + if (model.Reactions.IsSpecified) { var value = model.Reactions.Value; @@ -136,8 +216,31 @@ namespace Discord.Rest } else _reactions = ImmutableArray.Create(); - } + if (model.Interaction.IsSpecified) + { + Interaction = new MessageInteraction(model.Interaction.Value.Id, + model.Interaction.Value.Type, + model.Interaction.Value.Name, + RestUser.Create(Discord, model.Interaction.Value.User)); + } + + if (model.UserMentions.IsSpecified) + { + var value = model.UserMentions.Value; + if (value.Length > 0) + { + var newMentions = ImmutableArray.CreateBuilder(value.Length); + for (int i = 0; i < value.Length; i++) + { + var val = value[i]; + if (val != null) + newMentions.Add(RestUser.Create(Discord, val)); + } + _userMentions = newMentions.ToImmutable(); + } + } + } /// public async Task UpdateAsync(RequestOptions options = null) { @@ -156,8 +259,6 @@ namespace Discord.Rest /// public override string ToString() => Content; - /// - MessageType IMessage.Type => MessageType.Default; IUser IMessage.Author => Author; /// IReadOnlyCollection IMessage.Attachments => Attachments; @@ -166,6 +267,15 @@ namespace Discord.Rest /// IReadOnlyCollection IMessage.MentionedUserIds => MentionedUsers.Select(x => x.Id).ToImmutableArray(); + /// + IReadOnlyCollection IMessage.Components => Components; + + /// + IMessageInteraction IMessage.Interaction => Interaction; + + /// + IReadOnlyCollection IMessage.Stickers => Stickers; + /// public IReadOnlyDictionary Reactions => _reactions.ToDictionary(x => x.Emote, x => new ReactionMetadata { ReactionCount = x.Count, IsMe = x.Me }); @@ -182,6 +292,9 @@ namespace Discord.Rest public Task RemoveAllReactionsAsync(RequestOptions options = null) => MessageHelper.RemoveAllReactionsAsync(this, Discord, options); /// + public Task RemoveAllReactionsForEmoteAsync(IEmote emote, RequestOptions options = null) + => MessageHelper.RemoveAllReactionsForEmoteAsync(this, emote, Discord, options); + /// public IAsyncEnumerable> GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null) => MessageHelper.GetReactionUsersAsync(this, emote, limit, Discord, options); } diff --git a/src/Discord.Net.Rest/Entities/Messages/RestSystemMessage.cs b/src/Discord.Net.Rest/Entities/Messages/RestSystemMessage.cs index 89a651eb7..1c59d4f45 100644 --- a/src/Discord.Net.Rest/Entities/Messages/RestSystemMessage.cs +++ b/src/Discord.Net.Rest/Entities/Messages/RestSystemMessage.cs @@ -9,9 +9,6 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestSystemMessage : RestMessage, ISystemMessage { - /// - public MessageType Type { get; private set; } - internal RestSystemMessage(BaseDiscordClient discord, ulong id, IMessageChannel channel, IUser author) : base(discord, id, channel, author, MessageSource.System) { @@ -25,8 +22,6 @@ namespace Discord.Rest internal override void Update(Model model) { base.Update(model); - - Type = model.Type; } private string DebuggerDisplay => $"{Author}: {Content} ({Id}, {Type})"; diff --git a/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs b/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs index ad2a65615..083a8e72c 100644 --- a/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs +++ b/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs @@ -13,32 +13,39 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestUserMessage : RestMessage, IUserMessage { - private bool _isMentioningEveryone, _isTTS, _isPinned, _isSuppressed; + private bool _isMentioningEveryone, _isTTS, _isPinned; private long? _editedTimestampTicks; + private IUserMessage _referencedMessage; private ImmutableArray _attachments = ImmutableArray.Create(); private ImmutableArray _embeds = ImmutableArray.Create(); private ImmutableArray _tags = ImmutableArray.Create(); + private ImmutableArray _roleMentionIds = ImmutableArray.Create(); + private ImmutableArray _stickers = ImmutableArray.Create(); /// public override bool IsTTS => _isTTS; /// public override bool IsPinned => _isPinned; /// - public override bool IsSuppressed => _isSuppressed; + public override bool IsSuppressed => Flags.HasValue && Flags.Value.HasFlag(MessageFlags.SuppressEmbeds); /// public override DateTimeOffset? EditedTimestamp => DateTimeUtils.FromTicks(_editedTimestampTicks); /// + public override bool MentionedEveryone => _isMentioningEveryone; + /// public override IReadOnlyCollection Attachments => _attachments; /// public override IReadOnlyCollection Embeds => _embeds; /// public override IReadOnlyCollection MentionedChannelIds => MessageHelper.FilterTagsByKey(TagType.ChannelMention, _tags); /// - public override IReadOnlyCollection MentionedRoleIds => MessageHelper.FilterTagsByKey(TagType.RoleMention, _tags); - /// - public override IReadOnlyCollection MentionedUsers => MessageHelper.FilterTagsByValue(TagType.UserMention, _tags); + public override IReadOnlyCollection MentionedRoleIds => _roleMentionIds; /// public override IReadOnlyCollection Tags => _tags; + /// + public override IReadOnlyCollection Stickers => _stickers; + /// + public IUserMessage ReferencedMessage => _referencedMessage; internal RestUserMessage(BaseDiscordClient discord, ulong id, IMessageChannel channel, IUser author, MessageSource source) : base(discord, id, channel, author, source) @@ -63,10 +70,8 @@ namespace Discord.Rest _editedTimestampTicks = model.EditedTimestamp.Value?.UtcTicks; if (model.MentionEveryone.IsSpecified) _isMentioningEveryone = model.MentionEveryone.Value; - if (model.Flags.IsSpecified) - { - _isSuppressed = model.Flags.Value.HasFlag(API.MessageFlags.Suppressed); - } + if (model.RoleMentions.IsSpecified) + _roleMentionIds = model.RoleMentions.Value.ToImmutableArray(); if (model.Attachments.IsSpecified) { @@ -96,30 +101,34 @@ namespace Discord.Rest _embeds = ImmutableArray.Create(); } - ImmutableArray mentions = ImmutableArray.Create(); - if (model.UserMentions.IsSpecified) + var guildId = (Channel as IGuildChannel)?.GuildId; + var guild = guildId != null ? (Discord as IDiscordClient).GetGuildAsync(guildId.Value, CacheMode.CacheOnly).Result : null; + if (model.Content.IsSpecified) + { + var text = model.Content.Value; + _tags = MessageHelper.ParseTags(text, null, guild, MentionedUsers); + model.Content = text; + } + + if (model.ReferencedMessage.IsSpecified && model.ReferencedMessage.Value != null) { - var value = model.UserMentions.Value; + var refMsg = model.ReferencedMessage.Value; + IUser refMsgAuthor = MessageHelper.GetAuthor(Discord, guild, refMsg.Author.Value, refMsg.WebhookId.ToNullable()); + _referencedMessage = RestUserMessage.Create(Discord, Channel, refMsgAuthor, refMsg); + } + + if (model.StickerItems.IsSpecified) + { + var value = model.StickerItems.Value; if (value.Length > 0) { - var newMentions = ImmutableArray.CreateBuilder(value.Length); + var stickers = ImmutableArray.CreateBuilder(value.Length); for (int i = 0; i < value.Length; i++) - { - var val = value[i]; - if (val.Object != null) - newMentions.Add(RestUser.Create(Discord, val.Object)); - } - mentions = newMentions.ToImmutable(); + stickers.Add(new StickerItem(Discord, value[i])); + _stickers = stickers.ToImmutable(); } - } - - if (model.Content.IsSpecified) - { - var text = model.Content.Value; - var guildId = (Channel as IGuildChannel)?.GuildId; - var guild = guildId != null ? (Discord as IDiscordClient).GetGuildAsync(guildId.Value, CacheMode.CacheOnly).Result : null; - _tags = MessageHelper.ParseTags(text, null, guild, mentions); - model.Content = text; + else + _stickers = ImmutableArray.Create(); } } @@ -136,9 +145,6 @@ namespace Discord.Rest /// public Task UnpinAsync(RequestOptions options = null) => MessageHelper.UnpinAsync(this, Discord, options); - /// - public Task ModifySuppressionAsync(bool suppressEmbeds, RequestOptions options = null) - => MessageHelper.SuppressEmbedsAsync(this, Discord, suppressEmbeds, options); public string Resolve(int startIndex, TagHandling userHandling = TagHandling.Name, TagHandling channelHandling = TagHandling.Name, TagHandling roleHandling = TagHandling.Name, TagHandling everyoneHandling = TagHandling.Ignore, TagHandling emojiHandling = TagHandling.Name) @@ -149,10 +155,10 @@ namespace Discord.Rest => MentionUtils.Resolve(this, 0, userHandling, channelHandling, roleHandling, everyoneHandling, emojiHandling); /// - /// This operation may only be called on a channel. + /// This operation may only be called on a channel. public async Task CrosspostAsync(RequestOptions options = null) { - if (!(Channel is RestNewsChannel)) + if (!(Channel is INewsChannel)) { throw new InvalidOperationException("Publishing (crossposting) is only valid in news channels."); } diff --git a/src/Discord.Net.Rest/Entities/Messages/Sticker.cs b/src/Discord.Net.Rest/Entities/Messages/Sticker.cs new file mode 100644 index 000000000..accdbe66a --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Messages/Sticker.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using Model = Discord.API.Sticker; + +namespace Discord.Rest +{ + /// + [DebuggerDisplay(@"{DebuggerDisplay,nq}")] + public class Sticker : RestEntity, ISticker + { + /// + public ulong PackId { get; protected set; } + /// + public string Name { get; protected set; } + /// + public string Description { get; protected set; } + /// + public IReadOnlyCollection Tags { get; protected set; } + /// + public StickerType Type { get; protected set; } + /// + public bool? IsAvailable { get; protected set; } + /// + public int? SortOrder { get; protected set; } + /// + public StickerFormatType Format { get; protected set; } + + /// + public string GetStickerUrl() + => CDN.GetStickerUrl(Id, Format); + + internal Sticker(BaseDiscordClient client, ulong id) + : base(client, id) { } + internal static Sticker Create(BaseDiscordClient client, Model model) + { + var entity = new Sticker(client, model.Id); + entity.Update(model); + return entity; + } + + internal void Update(Model model) + { + PackId = model.PackId; + Name = model.Name; + Description = model.Description; + Tags = model.Tags.IsSpecified ? model.Tags.Value.Split(',').Select(x => x.Trim()).ToArray() : Array.Empty(); + Type = model.Type; + SortOrder = model.SortValue; + IsAvailable = model.Available; + Format = model.FormatType; + } + + private string DebuggerDisplay => $"{Name} ({Id})"; + } +} diff --git a/src/Discord.Net.Rest/Entities/Messages/StickerItem.cs b/src/Discord.Net.Rest/Entities/Messages/StickerItem.cs new file mode 100644 index 000000000..0ce4f634b --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Messages/StickerItem.cs @@ -0,0 +1,39 @@ +using System.Threading.Tasks; +using Model = Discord.API.StickerItem; + +namespace Discord.Rest +{ + /// + /// Represents a partial sticker received in a message. + /// + public class StickerItem : RestEntity, IStickerItem + { + /// + public string Name { get; } + + /// + public StickerFormatType Format { get; } + + internal StickerItem(BaseDiscordClient client, Model model) + : base(client, model.Id) + { + Name = model.Name; + Format = model.FormatType; + } + + /// + /// Resolves this sticker item by fetching the from the API. + /// + /// + /// A task representing the download operation, the result of the task is a sticker object. + /// + public async Task ResolveStickerAsync() + { + var model = await Discord.ApiClient.GetStickerAsync(Id); + + return model.GuildId.IsSpecified + ? CustomSticker.Create(Discord, model, model.GuildId.Value, model.User.IsSpecified ? model.User.Value.Id : null) + : Sticker.Create(Discord, model); + } + } +} diff --git a/src/Discord.Net.Rest/Entities/RestApplication.cs b/src/Discord.Net.Rest/Entities/RestApplication.cs index d033978d0..8347a70da 100644 --- a/src/Discord.Net.Rest/Entities/RestApplication.cs +++ b/src/Discord.Net.Rest/Entities/RestApplication.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Collections.Immutable; using System.Diagnostics; using System.Threading.Tasks; using Model = Discord.API.Application; @@ -18,18 +20,30 @@ namespace Discord.Rest /// public string Description { get; private set; } /// - public string[] RPCOrigins { get; private set; } + public IReadOnlyCollection RPCOrigins { get; private set; } /// - public ulong Flags { get; private set; } - + public ApplicationFlags Flags { get; private set; } + /// + public bool IsBotPublic { get; private set; } + /// + public bool BotRequiresCodeGrant { get; private set; } + /// + public ITeam Team { get; private set; } /// public IUser Owner { get; private set; } - + /// + public string TermsOfService { get; private set; } + /// + public string PrivacyPolicy { get; private set; } /// public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); /// public string IconUrl => CDN.GetApplicationIconUrl(Id, _iconId); + public ApplicationInstallParams InstallParams { get; private set; } + + public IReadOnlyCollection Tags { get; private set; } + internal RestApplication(BaseDiscordClient discord, ulong id) : base(discord, id) { @@ -43,14 +57,23 @@ namespace Discord.Rest internal void Update(Model model) { Description = model.Description; - RPCOrigins = model.RPCOrigins; + RPCOrigins = model.RPCOrigins.IsSpecified ? model.RPCOrigins.Value.ToImmutableArray() : ImmutableArray.Empty; Name = model.Name; _iconId = model.Icon; + IsBotPublic = model.IsBotPublic; + BotRequiresCodeGrant = model.BotRequiresCodeGrant; + Tags = model.Tags.GetValueOrDefault(null)?.ToImmutableArray() ?? ImmutableArray.Empty; + PrivacyPolicy = model.PrivacyPolicy; + TermsOfService = model.TermsOfService; + var installParams = model.InstallParams.GetValueOrDefault(null); + InstallParams = new ApplicationInstallParams(installParams?.Scopes ?? new string[0], (GuildPermission?)installParams?.Permission ?? null); if (model.Flags.IsSpecified) - Flags = model.Flags.Value; //TODO: Do we still need this? + Flags = model.Flags.Value; if (model.Owner.IsSpecified) Owner = RestUser.Create(Discord, model.Owner.Value); + if (model.Team != null) + Team = RestTeam.Create(Discord, model.Team); } /// Unable to update this object from a different application token. diff --git a/src/Discord.Net.Rest/Entities/Roles/RestRole.cs b/src/Discord.Net.Rest/Entities/Roles/RestRole.cs index 7c1a3aaa2..a2ad4fd77 100644 --- a/src/Discord.Net.Rest/Entities/Roles/RestRole.cs +++ b/src/Discord.Net.Rest/Entities/Roles/RestRole.cs @@ -11,6 +11,7 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestRole : RestEntity, IRole { + #region RestRole internal IGuild Guild { get; } /// public Color Color { get; private set; } @@ -23,9 +24,15 @@ namespace Discord.Rest /// public string Name { get; private set; } /// + public string Icon { get; private set; } + /// /> + public Emoji Emoji { get; private set; } + /// public GuildPermissions Permissions { get; private set; } /// public int Position { get; private set; } + /// + public RoleTags Tags { get; private set; } /// public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); @@ -56,11 +63,23 @@ namespace Discord.Rest Position = model.Position; Color = new Color(model.Color); Permissions = new GuildPermissions(model.Permissions); + if (model.Tags.IsSpecified) + Tags = model.Tags.Value.ToEntity(); + + if (model.Icon.IsSpecified) + { + Icon = model.Icon.Value; + } + + if (model.Emoji.IsSpecified) + { + Emoji = new Emoji(model.Emoji.Value); + } } /// public async Task ModifyAsync(Action func, RequestOptions options = null) - { + { var model = await RoleHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); Update(model); } @@ -68,6 +87,10 @@ namespace Discord.Rest public Task DeleteAsync(RequestOptions options = null) => RoleHelper.DeleteAsync(this, Discord, options); + /// + public string GetIconUrl() + => CDN.GetGuildRoleIconUrl(Id, Icon); + /// public int CompareTo(IRole role) => RoleUtils.Compare(this, role); @@ -79,8 +102,9 @@ namespace Discord.Rest /// public override string ToString() => Name; private string DebuggerDisplay => $"{Name} ({Id})"; + #endregion - //IRole + #region IRole /// IGuild IRole.Guild { @@ -91,5 +115,6 @@ namespace Discord.Rest throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object."); } } + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs b/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs index d570f078b..3b2946a0d 100644 --- a/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs +++ b/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; using Model = Discord.API.Role; using BulkParams = Discord.API.Rest.ModifyGuildRolesParams; @@ -7,25 +7,49 @@ namespace Discord.Rest { internal static class RoleHelper { - //General + #region General public static async Task DeleteAsync(IRole role, BaseDiscordClient client, RequestOptions options) { await client.ApiClient.DeleteGuildRoleAsync(role.Guild.Id, role.Id, options).ConfigureAwait(false); } - public static async Task ModifyAsync(IRole role, BaseDiscordClient client, + public static async Task ModifyAsync(IRole role, BaseDiscordClient client, Action func, RequestOptions options) { var args = new RoleProperties(); func(args); + + if (args.Icon.IsSpecified || args.Emoji.IsSpecified) + { + role.Guild.Features.EnsureFeature(GuildFeature.RoleIcons); + + if (args.Icon.IsSpecified && args.Emoji.IsSpecified) + { + throw new ArgumentException("Emoji and Icon properties cannot be present on a role at the same time."); + } + } + var apiArgs = new API.Rest.ModifyGuildRoleParams { Color = args.Color.IsSpecified ? args.Color.Value.RawValue : Optional.Create(), Hoist = args.Hoist, Mentionable = args.Mentionable, Name = args.Name, - Permissions = args.Permissions.IsSpecified ? args.Permissions.Value.RawValue : Optional.Create() + Permissions = args.Permissions.IsSpecified ? args.Permissions.Value.RawValue.ToString() : Optional.Create(), + Icon = args.Icon.IsSpecified ? args.Icon.Value.Value.ToModel() : Optional.Unspecified, + Emoji = args.Emoji.GetValueOrDefault()?.Name ?? Optional.Unspecified }; + + if (args.Icon.IsSpecified && role.Emoji != null) + { + apiArgs.Emoji = null; + } + + if (args.Emoji.IsSpecified && !string.IsNullOrEmpty(role.Icon)) + { + apiArgs.Icon = null; + } + var model = await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, apiArgs, options).ConfigureAwait(false); if (args.Position.IsSpecified) @@ -36,5 +60,6 @@ namespace Discord.Rest } return model; } + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Teams/RestTeam.cs b/src/Discord.Net.Rest/Entities/Teams/RestTeam.cs new file mode 100644 index 000000000..43c9417cc --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Teams/RestTeam.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using Model = Discord.API.Team; + +namespace Discord.Rest +{ + public class RestTeam : RestEntity, ITeam + { + /// + public string IconUrl => _iconId != null ? CDN.GetTeamIconUrl(Id, _iconId) : null; + /// + public IReadOnlyList TeamMembers { get; private set; } + /// + public string Name { get; private set; } + /// + public ulong OwnerUserId { get; private set; } + + private string _iconId; + + internal RestTeam(BaseDiscordClient discord, ulong id) + : base(discord, id) + { + } + internal static RestTeam Create(BaseDiscordClient discord, Model model) + { + var entity = new RestTeam(discord, model.Id); + entity.Update(model); + return entity; + } + internal virtual void Update(Model model) + { + if (model.Icon.IsSpecified) + _iconId = model.Icon.Value; + Name = model.Name; + OwnerUserId = model.OwnerUserId; + TeamMembers = model.TeamMembers.Select(x => new RestTeamMember(Discord, x)).ToImmutableArray(); + } + } +} diff --git a/src/Discord.Net.Rest/Entities/Teams/RestTeamMember.cs b/src/Discord.Net.Rest/Entities/Teams/RestTeamMember.cs new file mode 100644 index 000000000..322bb6a3f --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Teams/RestTeamMember.cs @@ -0,0 +1,30 @@ +using System; +using Model = Discord.API.TeamMember; + +namespace Discord.Rest +{ + public class RestTeamMember : ITeamMember + { + /// + public MembershipState MembershipState { get; } + /// + public string[] Permissions { get; } + /// + public ulong TeamId { get; } + /// + public IUser User { get; } + + internal RestTeamMember(BaseDiscordClient discord, Model model) + { + MembershipState = model.MembershipState switch + { + API.MembershipState.Invited => MembershipState.Invited, + API.MembershipState.Accepted => MembershipState.Accepted, + _ => throw new InvalidOperationException("Invalid membership state"), + }; + Permissions = model.Permissions; + TeamId = model.TeamId; + User = RestUser.Create(discord, model.User); + } + } +} diff --git a/src/Discord.Net.Rest/Entities/Users/RestGroupUser.cs b/src/Discord.Net.Rest/Entities/Users/RestGroupUser.cs index 55e9843eb..40e45b135 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestGroupUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestGroupUser.cs @@ -1,3 +1,4 @@ +using System; using System.Diagnostics; using Model = Discord.API.User; @@ -9,6 +10,7 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestGroupUser : RestUser, IGroupUser { + #region RestGroupUser internal RestGroupUser(BaseDiscordClient discord, ulong id) : base(discord, id) { @@ -19,8 +21,9 @@ namespace Discord.Rest entity.Update(model); return entity; } +#endregion - //IVoiceState + #region IVoiceState /// bool IVoiceState.IsDeafened => false; /// @@ -37,5 +40,8 @@ namespace Discord.Rest string IVoiceState.VoiceSessionId => null; /// bool IVoiceState.IsStreaming => false; + /// + DateTimeOffset? IVoiceState.RequestToSpeakTimestamp => null; + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs b/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs index d6a8c2eda..09e7ec03a 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs @@ -14,12 +14,16 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestGuildUser : RestUser, IGuildUser { + #region RestGuildUser private long? _premiumSinceTicks; + private long? _timedOutTicks; private long? _joinedAtTicks; private ImmutableArray _roleIds; /// public string Nickname { get; private set; } + /// + public string GuildAvatarId { get; private set; } internal IGuild Guild { get; private set; } /// public bool IsDeafened { get; private set; } @@ -29,6 +33,32 @@ namespace Discord.Rest public DateTimeOffset? PremiumSince => DateTimeUtils.FromTicks(_premiumSinceTicks); /// public ulong GuildId => Guild.Id; + /// + public bool? IsPending { get; private set; } + /// + public int Hierarchy + { + get + { + if (Guild.OwnerId == Id) + return int.MaxValue; + + var orderedRoles = Guild.Roles.OrderByDescending(x => x.Position); + return orderedRoles.Where(x => RoleIds.Contains(x.Id)).Max(x => x.Position); + } + } + + /// + public DateTimeOffset? TimedOutUntil + { + get + { + if (!_timedOutTicks.HasValue || _timedOutTicks.Value < 0) + return null; + else + return DateTimeUtils.FromTicks(_timedOutTicks); + } + } /// /// Resolving permissions requires the parent guild to be downloaded. @@ -65,6 +95,8 @@ namespace Discord.Rest _joinedAtTicks = model.JoinedAt.Value.UtcTicks; if (model.Nick.IsSpecified) Nickname = model.Nick.Value; + if (model.Avatar.IsSpecified) + GuildAvatarId = model.Avatar.Value; if (model.Deaf.IsSpecified) IsDeafened = model.Deaf.Value; if (model.Mute.IsSpecified) @@ -73,6 +105,10 @@ namespace Discord.Rest UpdateRoles(model.Roles.Value); if (model.PremiumSince.IsSpecified) _premiumSinceTicks = model.PremiumSince.Value?.UtcTicks; + if (model.TimedOutUntil.IsSpecified) + _timedOutTicks = model.TimedOutUntil.Value?.UtcTicks; + if (model.Pending.IsSpecified) + IsPending = model.Pending.Value; } private void UpdateRoles(ulong[] roleIds) { @@ -108,17 +144,35 @@ namespace Discord.Rest public Task KickAsync(string reason = null, RequestOptions options = null) => UserHelper.KickAsync(this, Discord, reason, options); /// + public Task AddRoleAsync(ulong roleId, RequestOptions options = null) + => AddRolesAsync(new[] { roleId }, options); + /// public Task AddRoleAsync(IRole role, RequestOptions options = null) - => AddRolesAsync(new[] { role }, options); + => AddRoleAsync(role.Id, options); + /// + public Task AddRolesAsync(IEnumerable roleIds, RequestOptions options = null) + => UserHelper.AddRolesAsync(this, Discord, roleIds, options); /// public Task AddRolesAsync(IEnumerable roles, RequestOptions options = null) - => UserHelper.AddRolesAsync(this, Discord, roles, options); + => AddRolesAsync(roles.Select(x => x.Id), options); + /// + public Task RemoveRoleAsync(ulong roleId, RequestOptions options = null) + => RemoveRolesAsync(new[] { roleId }, options); /// public Task RemoveRoleAsync(IRole role, RequestOptions options = null) - => RemoveRolesAsync(new[] { role }, options); + => RemoveRoleAsync(role.Id, options); + /// + public Task RemoveRolesAsync(IEnumerable roleIds, RequestOptions options = null) + => UserHelper.RemoveRolesAsync(this, Discord, roleIds, options); /// public Task RemoveRolesAsync(IEnumerable roles, RequestOptions options = null) - => UserHelper.RemoveRolesAsync(this, Discord, roles, options); + => RemoveRolesAsync(roles.Select(x => x.Id)); + /// + public Task SetTimeOutAsync(TimeSpan span, RequestOptions options = null) + => UserHelper.SetTimeoutAsync(this, Discord, span, options); + /// + public Task RemoveTimeOutAsync(RequestOptions options = null) + => UserHelper.RemoveTimeOutAsync(this, Discord, options); /// /// Resolving permissions requires the parent guild to be downloaded. @@ -128,7 +182,11 @@ namespace Discord.Rest return new ChannelPermissions(Permissions.ResolveChannel(Guild, this, channel, guildPerms.RawValue)); } - //IGuildUser + public string GetGuildAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) + => CDN.GetGuildUserAvatarUrl(Id, GuildId, GuildAvatarId, size, format); +#endregion + + #region IGuildUser /// IGuild IGuildUser.Guild { @@ -139,8 +197,9 @@ namespace Discord.Rest throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object."); } } + #endregion - //IVoiceState + #region IVoiceState /// bool IVoiceState.IsSelfDeafened => false; /// @@ -153,5 +212,8 @@ namespace Discord.Rest string IVoiceState.VoiceSessionId => null; /// bool IVoiceState.IsStreaming => false; + /// + DateTimeOffset? IVoiceState.RequestToSpeakTimestamp => null; + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Users/RestThreadUser.cs b/src/Discord.Net.Rest/Entities/Users/RestThreadUser.cs new file mode 100644 index 000000000..82830dafd --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Users/RestThreadUser.cs @@ -0,0 +1,56 @@ +using System; +using System.Threading.Tasks; +using Model = Discord.API.ThreadMember; + +namespace Discord.Rest +{ + /// + /// Represents a thread user received over the REST api. + /// + public class RestThreadUser : RestEntity + { + /// + /// Gets the this user is in. + /// + public IThreadChannel Thread { get; } + + /// + /// Gets the timestamp for when this user joined this thread. + /// + public DateTimeOffset JoinedAt { get; private set; } + + /// + /// Gets the guild this user is in. + /// + public IGuild Guild { get; } + + internal RestThreadUser(BaseDiscordClient discord, IGuild guild, IThreadChannel channel, ulong id) + : base(discord, id) + { + Guild = guild; + Thread = channel; + } + + internal static RestThreadUser Create(BaseDiscordClient client, IGuild guild, Model model, IThreadChannel channel) + { + var entity = new RestThreadUser(client, guild, channel, model.UserId.Value); + entity.Update(model); + return entity; + } + + internal void Update(Model model) + { + JoinedAt = model.JoinTimestamp; + } + + /// + /// Gets the guild user for this thread user. + /// + /// + /// A task representing the asynchronous get operation. The task returns a + /// that represents the current thread user. + /// + public Task GetGuildUser() + => Guild.GetUserAsync(Id); + } +} diff --git a/src/Discord.Net.Rest/Entities/Users/RestUser.cs b/src/Discord.Net.Rest/Entities/Users/RestUser.cs index d5fffca94..70f990fe7 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestUser.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using System.Globalization; using System.Threading.Tasks; using Model = Discord.API.User; +using EventUserModel = Discord.API.GuildScheduledEventUser; +using System.Collections.Generic; namespace Discord.Rest { @@ -13,6 +15,7 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestUser : RestEntity, IUser, IUpdateable { + #region RestUser /// public bool IsBot { get; private set; } /// @@ -21,6 +24,12 @@ namespace Discord.Rest public ushort DiscriminatorValue { get; private set; } /// public string AvatarId { get; private set; } + /// + public string BannerId { get; private set; } + /// + public Color? AccentColor { get; private set; } + /// + public UserProperties? PublicFlags { get; private set; } /// public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); @@ -33,7 +42,9 @@ namespace Discord.Rest /// public virtual UserStatus Status => UserStatus.Offline; /// - public virtual IImmutableSet ActiveClients => ImmutableHashSet.Empty; + public virtual IReadOnlyCollection ActiveClients => ImmutableHashSet.Empty; + /// + public virtual IReadOnlyCollection Activities => ImmutableList.Empty; /// public virtual bool IsWebhook => false; @@ -53,16 +64,34 @@ namespace Discord.Rest entity.Update(model); return entity; } + internal static RestUser Create(BaseDiscordClient discord, IGuild guild, EventUserModel model) + { + if (model.Member.IsSpecified) + { + var member = model.Member.Value; + member.User = model.User; + return RestGuildUser.Create(discord, guild, member); + } + else + return RestUser.Create(discord, model.User); + } + internal virtual void Update(Model model) { if (model.Avatar.IsSpecified) AvatarId = model.Avatar.Value; + if (model.Banner.IsSpecified) + BannerId = model.Banner.Value; + if (model.AccentColor.IsSpecified) + AccentColor = model.AccentColor.Value; if (model.Discriminator.IsSpecified) DiscriminatorValue = ushort.Parse(model.Discriminator.Value, NumberStyles.None, CultureInfo.InvariantCulture); if (model.Bot.IsSpecified) IsBot = model.Bot.Value; if (model.Username.IsSpecified) Username = model.Username.Value; + if (model.PublicFlags.IsSpecified) + PublicFlags = model.PublicFlags.Value; } /// @@ -73,19 +102,23 @@ namespace Discord.Rest } /// - /// Returns a direct message channel to this user, or create one if it does not already exist. + /// Creates a direct message channel to this user. /// /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains a rest DM channel where the user is the recipient. /// - public Task GetOrCreateDMChannelAsync(RequestOptions options = null) + public Task CreateDMChannelAsync(RequestOptions options = null) => UserHelper.CreateDMChannelAsync(this, Discord, options); /// public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) => CDN.GetUserAvatarUrl(Id, AvatarId, size, format); + /// + public string GetBannerUrl(ImageFormat format = ImageFormat.Auto, ushort size = 256) + => CDN.GetUserBannerUrl(Id, BannerId, size, format); + /// public string GetDefaultAvatarUrl() => CDN.GetDefaultUserAvatarUrl(DiscriminatorValue); @@ -96,12 +129,14 @@ namespace Discord.Rest /// /// A string that resolves to Username#Discriminator of the user. /// - public override string ToString() => $"{Username}#{Discriminator}"; - private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; + public override string ToString() => Format.UsernameAndDiscriminator(this); + private string DebuggerDisplay => $"{Format.UsernameAndDiscriminator(this)} ({Id}{(IsBot ? ", Bot" : "")})"; + #endregion - //IUser + #region IUser /// - async Task IUser.GetOrCreateDMChannelAsync(RequestOptions options) - => await GetOrCreateDMChannelAsync(options).ConfigureAwait(false); + async Task IUser.CreateDMChannelAsync(RequestOptions options) + => await CreateDMChannelAsync(options).ConfigureAwait(false); + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs b/src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs index 8462cb8d4..4ef84c508 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs @@ -10,6 +10,7 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestWebhookUser : RestUser, IWebhookUser { + #region RestWebhookUser /// public ulong WebhookId { get; } internal IGuild Guild { get; } @@ -33,8 +34,9 @@ namespace Discord.Rest entity.Update(model); return entity; } +#endregion - //IGuildUser + #region IGuildUser /// IGuild IGuildUser.Guild { @@ -52,35 +54,60 @@ namespace Discord.Rest /// string IGuildUser.Nickname => null; /// + string IGuildUser.GuildAvatarId => null; + /// + string IGuildUser.GetGuildAvatarUrl(ImageFormat format, ushort size) => null; + /// + bool? IGuildUser.IsPending => null; + /// + int IGuildUser.Hierarchy => 0; + /// + DateTimeOffset? IGuildUser.TimedOutUntil => null; + /// GuildPermissions IGuildUser.GuildPermissions => GuildPermissions.Webhook; /// ChannelPermissions IGuildUser.GetPermissions(IGuildChannel channel) => Permissions.ToChannelPerms(channel, GuildPermissions.Webhook.RawValue); /// - Task IGuildUser.KickAsync(string reason, RequestOptions options) => + Task IGuildUser.KickAsync(string reason, RequestOptions options) => throw new NotSupportedException("Webhook users cannot be kicked."); /// - Task IGuildUser.ModifyAsync(Action func, RequestOptions options) => + Task IGuildUser.ModifyAsync(Action func, RequestOptions options) => throw new NotSupportedException("Webhook users cannot be modified."); - /// - Task IGuildUser.AddRoleAsync(IRole role, RequestOptions options) => + Task IGuildUser.AddRoleAsync(ulong role, RequestOptions options) => throw new NotSupportedException("Roles are not supported on webhook users."); - /// - Task IGuildUser.AddRolesAsync(IEnumerable roles, RequestOptions options) => + Task IGuildUser.AddRoleAsync(IRole role, RequestOptions options) => throw new NotSupportedException("Roles are not supported on webhook users."); - /// - Task IGuildUser.RemoveRoleAsync(IRole role, RequestOptions options) => + Task IGuildUser.AddRolesAsync(IEnumerable roles, RequestOptions options) => + throw new NotSupportedException("Roles are not supported on webhook users."); + /// + Task IGuildUser.AddRolesAsync(IEnumerable roles, RequestOptions options) => + throw new NotSupportedException("Roles are not supported on webhook users."); + /// + Task IGuildUser.RemoveRoleAsync(ulong role, RequestOptions options) => + throw new NotSupportedException("Roles are not supported on webhook users."); + /// + Task IGuildUser.RemoveRoleAsync(IRole role, RequestOptions options) => throw new NotSupportedException("Roles are not supported on webhook users."); - /// - Task IGuildUser.RemoveRolesAsync(IEnumerable roles, RequestOptions options) => + Task IGuildUser.RemoveRolesAsync(IEnumerable roles, RequestOptions options) => throw new NotSupportedException("Roles are not supported on webhook users."); + /// + Task IGuildUser.RemoveRolesAsync(IEnumerable roles, RequestOptions options) => + throw new NotSupportedException("Roles are not supported on webhook users."); + /// + Task IGuildUser.SetTimeOutAsync(TimeSpan span, RequestOptions options) => + throw new NotSupportedException("Timeouts are not supported on webhook users."); + /// + Task IGuildUser.RemoveTimeOutAsync(RequestOptions options) => + throw new NotSupportedException("Timeouts are not supported on webhook users."); + #endregion - //IVoiceState + #region IVoiceState /// bool IVoiceState.IsDeafened => false; /// @@ -97,5 +124,8 @@ namespace Discord.Rest string IVoiceState.VoiceSessionId => null; /// bool IVoiceState.IsStreaming => false; + /// + DateTimeOffset? IVoiceState.RequestToSpeakTimestamp => null; + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Users/UserHelper.cs b/src/Discord.Net.Rest/Entities/Users/UserHelper.cs index 58e8cd417..393effb2e 100644 --- a/src/Discord.Net.Rest/Entities/Users/UserHelper.cs +++ b/src/Discord.Net.Rest/Entities/Users/UserHelper.cs @@ -31,11 +31,16 @@ namespace Discord.Rest { var args = new GuildUserProperties(); func(args); + + if (args.TimedOutUntil.IsSpecified && args.TimedOutUntil.Value.Value.Offset > (new TimeSpan(28, 0, 0, 0))) + throw new ArgumentOutOfRangeException(nameof(args.TimedOutUntil), "Offset cannot be more than 28 days from the current date."); + var apiArgs = new API.Rest.ModifyGuildMemberParams { Deaf = args.Deaf, Mute = args.Mute, - Nickname = args.Nickname + Nickname = args.Nickname, + TimedOutUntil = args.TimedOutUntil }; if (args.Channel.IsSpecified) @@ -73,16 +78,38 @@ namespace Discord.Rest return RestDMChannel.Create(client, await client.ApiClient.CreateDMChannelAsync(args, options).ConfigureAwait(false)); } - public static async Task AddRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable roles, RequestOptions options) + public static async Task AddRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable roleIds, RequestOptions options) + { + foreach (var roleId in roleIds) + await client.ApiClient.AddRoleAsync(user.Guild.Id, user.Id, roleId, options).ConfigureAwait(false); + } + + public static async Task RemoveRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable roleIds, RequestOptions options) + { + foreach (var roleId in roleIds) + await client.ApiClient.RemoveRoleAsync(user.Guild.Id, user.Id, roleId, options).ConfigureAwait(false); + } + + public static async Task SetTimeoutAsync(IGuildUser user, BaseDiscordClient client, TimeSpan span, RequestOptions options) { - foreach (var role in roles) - await client.ApiClient.AddRoleAsync(user.Guild.Id, user.Id, role.Id, options).ConfigureAwait(false); + if (span.TotalDays > 28) // As its double, an exact value of 28 can be accepted. + throw new ArgumentOutOfRangeException(nameof(span), "Offset cannot be more than 28 days from the current date."); + if (span.Ticks <= 0) + throw new ArgumentOutOfRangeException(nameof(span), "Offset cannot hold no value or have a negative value."); + var apiArgs = new API.Rest.ModifyGuildMemberParams() + { + TimedOutUntil = DateTimeOffset.UtcNow.Add(span) + }; + await client.ApiClient.ModifyGuildMemberAsync(user.Guild.Id, user.Id, apiArgs, options).ConfigureAwait(false); } - public static async Task RemoveRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable roles, RequestOptions options) + public static async Task RemoveTimeOutAsync(IGuildUser user, BaseDiscordClient client, RequestOptions options) { - foreach (var role in roles) - await client.ApiClient.RemoveRoleAsync(user.Guild.Id, user.Id, role.Id, options).ConfigureAwait(false); + var apiArgs = new API.Rest.ModifyGuildMemberParams() + { + TimedOutUntil = null + }; + await client.ApiClient.ModifyGuildMemberAsync(user.Guild.Id, user.Id, apiArgs, options).ConfigureAwait(false); } } } diff --git a/src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs b/src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs index 1fdc95a63..f40b786cd 100644 --- a/src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs +++ b/src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs @@ -8,14 +8,15 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestWebhook : RestEntity, IWebhook, IUpdateable { + #region RestWebhook internal IGuild Guild { get; private set; } internal ITextChannel Channel { get; private set; } - /// - public ulong ChannelId { get; } /// public string Token { get; } + /// + public ulong ChannelId { get; private set; } /// public string Name { get; private set; } /// @@ -24,6 +25,8 @@ namespace Discord.Rest public ulong? GuildId { get; private set; } /// public IUser Creator { get; private set; } + /// + public ulong? ApplicationId { get; private set; } /// public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); @@ -56,6 +59,8 @@ namespace Discord.Rest internal void Update(Model model) { + if (ChannelId != model.ChannelId) + ChannelId = model.ChannelId; if (model.Avatar.IsSpecified) AvatarId = model.Avatar.Value; if (model.Creator.IsSpecified) @@ -64,6 +69,8 @@ namespace Discord.Rest GuildId = model.GuildId.Value; if (model.Name.IsSpecified) Name = model.Name.Value; + + ApplicationId = model.ApplicationId; } /// @@ -89,8 +96,9 @@ namespace Discord.Rest public override string ToString() => $"Webhook: {Name}:{Id}"; private string DebuggerDisplay => $"Webhook: {Name} ({Id})"; + #endregion - //IWebhook + #region IWebhook /// IGuild IWebhook.Guild => Guild ?? throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object."); @@ -100,5 +108,6 @@ namespace Discord.Rest /// Task IWebhook.ModifyAsync(Action func, RequestOptions options) => ModifyAsync(func, options); + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs b/src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs index 50e9cab78..0b61b6c22 100644 --- a/src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs +++ b/src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs @@ -33,6 +33,5 @@ namespace Discord.Rest { await client.ApiClient.DeleteWebhookAsync(webhook.Id, options).ConfigureAwait(false); } - } } diff --git a/src/Discord.Net.Rest/Extensions/EntityExtensions.cs b/src/Discord.Net.Rest/Extensions/EntityExtensions.cs index abdfc9d4f..4062cda3d 100644 --- a/src/Discord.Net.Rest/Extensions/EntityExtensions.cs +++ b/src/Discord.Net.Rest/Extensions/EntityExtensions.cs @@ -34,6 +34,13 @@ namespace Discord.Rest model.Thumbnail.IsSpecified ? model.Thumbnail.Value.ToEntity() : (EmbedThumbnail?)null, model.Fields.IsSpecified ? model.Fields.Value.Select(x => x.ToEntity()).ToImmutableArray() : ImmutableArray.Create()); } + public static RoleTags ToEntity(this API.RoleTags model) + { + return new RoleTags( + model.BotId.IsSpecified ? model.BotId.Value : null, + model.IntegrationId.IsSpecified ? model.IntegrationId.Value : null, + model.IsPremiumSubscriber.IsSpecified); + } public static API.Embed ToModel(this Embed entity) { if (entity == null) return null; @@ -61,13 +68,25 @@ namespace Discord.Rest model.Video = entity.Video.Value.ToModel(); return model; } + public static API.AllowedMentions ToModel(this AllowedMentions entity) { + if (entity == null) return null; return new API.AllowedMentions() { Parse = entity.AllowedTypes?.EnumerateMentionTypes().ToArray(), Roles = entity.RoleIds?.ToArray(), Users = entity.UserIds?.ToArray(), + RepliedUser = entity.MentionRepliedUser ?? Optional.Create(), + }; + } + public static API.MessageReference ToModel(this MessageReference entity) + { + return new API.MessageReference() + { + ChannelId = entity.InternalChannelId, + GuildId = entity.GuildId, + MessageId = entity.MessageId, }; } public static IEnumerable EnumerateMentionTypes(this AllowedMentionTypes mentionTypes) @@ -151,5 +170,48 @@ namespace Discord.Rest { return new Overwrite(model.TargetId, model.TargetType, new OverwritePermissions(model.Allow, model.Deny)); } + + public static API.Message ToMessage(this API.InteractionResponse model, IDiscordInteraction interaction) + { + if (model.Data.IsSpecified) + { + var data = model.Data.Value; + var messageModel = new API.Message + { + IsTextToSpeech = data.TTS, + Content = (data.Content.IsSpecified && data.Content.Value == null) ? Optional.Unspecified : data.Content, + Embeds = data.Embeds, + AllowedMentions = data.AllowedMentions, + Components = data.Components, + Flags = data.Flags, + }; + + if(interaction is IApplicationCommandInteraction command) + { + messageModel.Interaction = new API.MessageInteraction + { + Id = command.Id, + Name = command.Data.Name, + Type = InteractionType.ApplicationCommand, + User = new API.User + { + Username = command.User.Username, + Avatar = command.User.AvatarId, + Bot = command.User.IsBot, + Discriminator = command.User.Discriminator, + PublicFlags = command.User.PublicFlags.HasValue ? command.User.PublicFlags.Value : Optional.Unspecified, + Id = command.User.Id, + } + }; + } + + return messageModel; + } + + return new API.Message + { + Id = interaction.Id, + }; + } } } diff --git a/src/Discord.Net.Rest/Interactions/RestInteractionContext.cs b/src/Discord.Net.Rest/Interactions/RestInteractionContext.cs new file mode 100644 index 000000000..196c6133b --- /dev/null +++ b/src/Discord.Net.Rest/Interactions/RestInteractionContext.cs @@ -0,0 +1,112 @@ +using System; +using System.Threading.Tasks; + +namespace Discord.Rest +{ + /// + /// Represents a Rest based context of an . + /// + public class RestInteractionContext : IRestInteractionContext + where TInteraction : RestInteraction + { + /// + /// Gets the that the command will be executed with. + /// + public DiscordRestClient Client { get; } + + /// + /// Gets the the command originated from. + /// + /// + /// Will be null if the command is from a DM Channel. + /// + public RestGuild Guild { get; } + + /// + /// Gets the the command originated from. + /// + public IRestMessageChannel Channel { get; } + + /// + /// Gets the who executed the command. + /// + public RestUser User { get; } + + /// + /// Gets the the command was recieved with. + /// + public TInteraction Interaction { get; } + + /// + /// Gets or sets the callback to use when the service has outgoing json for the rest webhook. + /// + /// + /// If this property is the default callback will be used. + /// + public Func InteractionResponseCallback { get; set; } + + /// + /// Initializes a new . + /// + /// The underlying client. + /// The underlying interaction. + public RestInteractionContext(DiscordRestClient client, TInteraction interaction) + { + Client = client; + Guild = interaction.Guild; + Channel = interaction.Channel; + User = interaction.User; + Interaction = interaction; + } + + /// + /// Initializes a new . + /// + /// The underlying client. + /// The underlying interaction. + /// The callback for outgoing json. + public RestInteractionContext(DiscordRestClient client, TInteraction interaction, Func interactionResponseCallback) + : this(client, interaction) + { + InteractionResponseCallback = interactionResponseCallback; + } + + // IInterationContext + /// + IDiscordClient IInteractionContext.Client => Client; + + /// + IGuild IInteractionContext.Guild => Guild; + + /// + IMessageChannel IInteractionContext.Channel => Channel; + + /// + IUser IInteractionContext.User => User; + + /// + IDiscordInteraction IInteractionContext.Interaction => Interaction; + } + + /// + /// Represents a Rest based context of an . + /// + public class RestInteractionContext : RestInteractionContext + { + /// + /// Initializes a new . + /// + /// The underlying client. + /// The underlying interaction. + public RestInteractionContext(DiscordRestClient client, RestInteraction interaction) : base(client, interaction) { } + + /// + /// Initializes a new . + /// + /// The underlying client. + /// The underlying interaction. + /// The callback for outgoing json. + public RestInteractionContext(DiscordRestClient client, RestInteraction interaction, Func interactionResponseCallback) + : base(client, interaction, interactionResponseCallback) { } + } +} diff --git a/src/Discord.Net.Rest/Net/BadSignatureException.cs b/src/Discord.Net.Rest/Net/BadSignatureException.cs new file mode 100644 index 000000000..08672df8e --- /dev/null +++ b/src/Discord.Net.Rest/Net/BadSignatureException.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.Rest +{ + public class BadSignatureException : Exception + { + internal BadSignatureException() : base("Failed to verify authenticity of message: public key doesnt match signature") + { + + } + } +} diff --git a/src/Discord.Net.Rest/Net/Converters/ArrayConverter.cs b/src/Discord.Net.Rest/Net/Converters/ArrayConverter.cs index 3cededb7b..ce2e9b1f7 100644 --- a/src/Discord.Net.Rest/Net/Converters/ArrayConverter.cs +++ b/src/Discord.Net.Rest/Net/Converters/ArrayConverter.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; using System; using System.Collections.Generic; diff --git a/src/Discord.Net.Rest/Net/Converters/DiscordContractResolver.cs b/src/Discord.Net.Rest/Net/Converters/DiscordContractResolver.cs index a1ed20c6f..91ba22460 100644 --- a/src/Discord.Net.Rest/Net/Converters/DiscordContractResolver.cs +++ b/src/Discord.Net.Rest/Net/Converters/DiscordContractResolver.cs @@ -10,9 +10,10 @@ namespace Discord.Net.Converters { internal class DiscordContractResolver : DefaultContractResolver { + #region DiscordContractResolver private static readonly TypeInfo _ienumerable = typeof(IEnumerable).GetTypeInfo(); - private static readonly MethodInfo _shouldSerialize = typeof(DiscordContractResolver).GetTypeInfo().GetDeclaredMethod("ShouldSerialize"); - + private static readonly MethodInfo _shouldSerialize = typeof(DiscordContractResolver).GetTypeInfo().GetDeclaredMethod("ShouldSerialize"); + protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { var property = base.CreateProperty(member, memberSerialization); @@ -57,8 +58,9 @@ namespace Discord.Net.Converters else if (genericType == typeof(EntityOrId<>)) return MakeGenericConverter(property, propInfo, typeof(UInt64EntityOrIdConverter<>), type.GenericTypeArguments[0], depth); } + #endregion - //Primitives + #region Primitives bool hasInt53 = propInfo.GetCustomAttribute() != null; if (!hasInt53) { @@ -73,8 +75,6 @@ namespace Discord.Net.Converters } //Enums - if (type == typeof(PermissionTarget)) - return PermissionTargetConverter.Instance; if (type == typeof(UserStatus)) return UserStatusConverter.Instance; if (type == typeof(EmbedType)) @@ -83,6 +83,14 @@ namespace Discord.Net.Converters //Special if (type == typeof(API.Image)) return ImageConverter.Instance; + if (typeof(IMessageComponent).IsAssignableFrom(type)) + return MessageComponentConverter.Instance; + if (type == typeof(API.Interaction)) + return InteractionConverter.Instance; + if (type == typeof(API.DiscordError)) + return DiscordErrorConverter.Instance; + if (type == typeof(GuildFeatures)) + return GuildFeaturesConverter.Instance; //Entities var typeInfo = type.GetTypeInfo(); @@ -105,5 +113,6 @@ namespace Discord.Net.Converters var innerConverter = GetConverter(property, propInfo, innerType, depth + 1); return genericType.DeclaredConstructors.First().Invoke(new object[] { innerConverter }) as JsonConverter; } + #endregion } } diff --git a/src/Discord.Net.Rest/Net/Converters/DiscordErrorConverter.cs b/src/Discord.Net.Rest/Net/Converters/DiscordErrorConverter.cs new file mode 100644 index 000000000..772ddc6b2 --- /dev/null +++ b/src/Discord.Net.Rest/Net/Converters/DiscordErrorConverter.cs @@ -0,0 +1,88 @@ +using Discord.API; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.Net.Converters +{ + internal class DiscordErrorConverter : JsonConverter + { + public static DiscordErrorConverter Instance + => new DiscordErrorConverter(); + + public override bool CanConvert(Type objectType) => objectType == typeof(DiscordError); + + public override bool CanRead => true; + public override bool CanWrite => false; + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var obj = JObject.Load(reader); + var err = new API.DiscordError(); + + + var result = obj.GetValue("errors", StringComparison.OrdinalIgnoreCase); + result?.Parent.Remove(); + + // Populate the remaining properties. + using (var subReader = obj.CreateReader()) + { + serializer.Populate(subReader, err); + } + + if (result != null) + { + var innerReader = result.CreateReader(); + + var errors = ReadErrors(innerReader); + err.Errors = errors.ToArray(); + } + + return err; + } + + private List ReadErrors(JsonReader reader, string path = "") + { + List errs = new List(); + var obj = JObject.Load(reader); + var props = obj.Properties(); + foreach (var prop in props) + { + if (prop.Name == "_errors" && path == "") // root level error + { + errs.Add(new ErrorDetails() + { + Name = Optional.Unspecified, + Errors = prop.Value.ToObject() + }); + } + else if (prop.Name == "_errors") // path errors (not root level) + { + errs.Add(new ErrorDetails() + { + Name = path, + Errors = prop.Value.ToObject() + }); + } + else if(int.TryParse(prop.Name, out var i)) // array value + { + var r = prop.Value.CreateReader(); + errs.AddRange(ReadErrors(r, path + $"[{i}]")); + } + else // property name + { + var r = prop.Value.CreateReader(); + errs.AddRange(ReadErrors(r, path + $"{(path != "" ? "." : "")}{prop.Name[0].ToString().ToUpper() + new string(prop.Name.Skip(1).ToArray())}")); + } + } + + return errs; + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException(); + } +} diff --git a/src/Discord.Net.Rest/Net/Converters/EmbedTypeConverter.cs b/src/Discord.Net.Rest/Net/Converters/EmbedTypeConverter.cs index 1e03fb698..cacd2e2e1 100644 --- a/src/Discord.Net.Rest/Net/Converters/EmbedTypeConverter.cs +++ b/src/Discord.Net.Rest/Net/Converters/EmbedTypeConverter.cs @@ -13,28 +13,19 @@ namespace Discord.Net.Converters public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - switch ((string)reader.Value) + return (string)reader.Value switch { - case "rich": - return EmbedType.Rich; - case "link": - return EmbedType.Link; - case "video": - return EmbedType.Video; - case "image": - return EmbedType.Image; - case "gifv": - return EmbedType.Gifv; - case "article": - return EmbedType.Article; - case "tweet": - return EmbedType.Tweet; - case "html": - return EmbedType.Html; - case "application_news": // TODO 2.2 EmbedType.News - default: - return EmbedType.Unknown; - } + "rich" => EmbedType.Rich, + "link" => EmbedType.Link, + "video" => EmbedType.Video, + "image" => EmbedType.Image, + "gifv" => EmbedType.Gifv, + "article" => EmbedType.Article, + "tweet" => EmbedType.Tweet, + "html" => EmbedType.Html, + // TODO 2.2 EmbedType.News + _ => EmbedType.Unknown, + }; } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) diff --git a/src/Discord.Net.Rest/Net/Converters/GuildFeaturesConverter.cs b/src/Discord.Net.Rest/Net/Converters/GuildFeaturesConverter.cs new file mode 100644 index 000000000..22363199d --- /dev/null +++ b/src/Discord.Net.Rest/Net/Converters/GuildFeaturesConverter.cs @@ -0,0 +1,44 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; + +namespace Discord.Net.Converters +{ + internal class GuildFeaturesConverter : JsonConverter + { + public static GuildFeaturesConverter Instance + => new GuildFeaturesConverter(); + + public override bool CanConvert(Type objectType) => true; + public override bool CanWrite => false; + public override bool CanRead => true; + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var obj = JToken.Load(reader); + var arr = obj.ToObject(); + + GuildFeature features = GuildFeature.None; + List experimental = new(); + + foreach(var item in arr) + { + if (Enum.TryParse(string.Concat(item.Split('_')), true, out var result)) + { + features |= result; + } + else + { + experimental.Add(item); + } + } + + return new GuildFeatures(features, experimental.ToArray()); + } + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Discord.Net.Rest/Net/Converters/InteractionConverter.cs b/src/Discord.Net.Rest/Net/Converters/InteractionConverter.cs new file mode 100644 index 000000000..f7235841d --- /dev/null +++ b/src/Discord.Net.Rest/Net/Converters/InteractionConverter.cs @@ -0,0 +1,70 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; + +namespace Discord.Net.Converters +{ + internal class InteractionConverter : JsonConverter + { + public static InteractionConverter Instance => new InteractionConverter(); + + public override bool CanRead => true; + public override bool CanWrite => false; + public override bool CanConvert(Type objectType) => true; + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + if (reader.TokenType == JsonToken.Null) + return null; + + var obj = JObject.Load(reader); + var interaction = new API.Interaction(); + + + // Remove the data property for manual deserialization + var result = obj.GetValue("data", StringComparison.OrdinalIgnoreCase); + result?.Parent.Remove(); + + // Populate the remaining properties. + using (var subReader = obj.CreateReader()) + { + serializer.Populate(subReader, interaction); + } + + // Process the Result property + if (result != null) + { + switch (interaction.Type) + { + case InteractionType.ApplicationCommand: + { + var appCommandData = new API.ApplicationCommandInteractionData(); + serializer.Populate(result.CreateReader(), appCommandData); + interaction.Data = appCommandData; + } + break; + case InteractionType.MessageComponent: + { + var messageComponent = new API.MessageComponentInteractionData(); + serializer.Populate(result.CreateReader(), messageComponent); + interaction.Data = messageComponent; + } + break; + case InteractionType.ApplicationCommandAutocomplete: + { + var autocompleteData = new API.AutocompleteInteractionData(); + serializer.Populate(result.CreateReader(), autocompleteData); + interaction.Data = autocompleteData; + } + break; + } + } + else + interaction.Data = Optional.Unspecified; + + return interaction; + } + + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException(); + } +} diff --git a/src/Discord.Net.Rest/Net/Converters/MessageComponentConverter.cs b/src/Discord.Net.Rest/Net/Converters/MessageComponentConverter.cs new file mode 100644 index 000000000..0bf11a369 --- /dev/null +++ b/src/Discord.Net.Rest/Net/Converters/MessageComponentConverter.cs @@ -0,0 +1,40 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; + +namespace Discord.Net.Converters +{ + internal class MessageComponentConverter : JsonConverter + { + public static MessageComponentConverter Instance => new MessageComponentConverter(); + + public override bool CanRead => true; + public override bool CanWrite => false; + public override bool CanConvert(Type objectType) => true; + public override void WriteJson(JsonWriter writer, + object value, JsonSerializer serializer) + { + serializer.Serialize(writer, value); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var jsonObject = JObject.Load(reader); + var messageComponent = default(IMessageComponent); + switch ((ComponentType)jsonObject["type"].Value()) + { + case ComponentType.ActionRow: + messageComponent = new API.ActionRowComponent(); + break; + case ComponentType.Button: + messageComponent = new API.ButtonComponent(); + break; + case ComponentType.SelectMenu: + messageComponent = new API.SelectMenuComponent(); + break; + } + serializer.Populate(jsonObject.CreateReader(), messageComponent); + return messageComponent; + } + } +} diff --git a/src/Discord.Net.Rest/Net/Converters/PermissionTargetConverter.cs b/src/Discord.Net.Rest/Net/Converters/PermissionTargetConverter.cs deleted file mode 100644 index de2e379d7..000000000 --- a/src/Discord.Net.Rest/Net/Converters/PermissionTargetConverter.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Newtonsoft.Json; -using System; - -namespace Discord.Net.Converters -{ - internal class PermissionTargetConverter : JsonConverter - { - public static readonly PermissionTargetConverter Instance = new PermissionTargetConverter(); - - public override bool CanConvert(Type objectType) => true; - public override bool CanRead => true; - public override bool CanWrite => true; - - /// Unknown permission target. - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - switch ((string)reader.Value) - { - case "member": - return PermissionTarget.User; - case "role": - return PermissionTarget.Role; - default: - throw new JsonSerializationException("Unknown permission target."); - } - } - - /// Invalid permission target. - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - switch ((PermissionTarget)value) - { - case PermissionTarget.User: - writer.WriteValue("member"); - break; - case PermissionTarget.Role: - writer.WriteValue("role"); - break; - default: - throw new JsonSerializationException("Invalid permission target."); - } - } - } -} diff --git a/src/Discord.Net.Rest/Net/Converters/UnixTimestampConverter.cs b/src/Discord.Net.Rest/Net/Converters/UnixTimestampConverter.cs index 0b50cb166..876254fb9 100644 --- a/src/Discord.Net.Rest/Net/Converters/UnixTimestampConverter.cs +++ b/src/Discord.Net.Rest/Net/Converters/UnixTimestampConverter.cs @@ -27,7 +27,7 @@ namespace Discord.Net.Converters public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { - throw new NotImplementedException(); + writer.WriteValue(((DateTimeOffset)value).ToString("O")); } } } diff --git a/src/Discord.Net.Rest/Net/Converters/UserStatusConverter.cs b/src/Discord.Net.Rest/Net/Converters/UserStatusConverter.cs index c0a287c16..8a13e79a5 100644 --- a/src/Discord.Net.Rest/Net/Converters/UserStatusConverter.cs +++ b/src/Discord.Net.Rest/Net/Converters/UserStatusConverter.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; using System; namespace Discord.Net.Converters @@ -13,21 +13,15 @@ namespace Discord.Net.Converters public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - switch ((string)reader.Value) + return (string)reader.Value switch { - case "online": - return UserStatus.Online; - case "idle": - return UserStatus.Idle; - case "dnd": - return UserStatus.DoNotDisturb; - case "invisible": - return UserStatus.Invisible; //Should never happen - case "offline": - return UserStatus.Offline; - default: - throw new JsonSerializationException("Unknown user status"); - } + "online" => UserStatus.Online, + "idle" => UserStatus.Idle, + "dnd" => UserStatus.DoNotDisturb, + "invisible" => UserStatus.Invisible,//Should never happen + "offline" => UserStatus.Offline, + _ => throw new JsonSerializationException("Unknown user status"), + }; } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) diff --git a/src/Discord.Net.Rest/Net/DefaultRestClient.cs b/src/Discord.Net.Rest/Net/DefaultRestClient.cs index b5036d94e..ce32b085b 100644 --- a/src/Discord.Net.Rest/Net/DefaultRestClient.cs +++ b/src/Discord.Net.Rest/Net/DefaultRestClient.cs @@ -7,6 +7,7 @@ using System.IO; using System.Linq; using System.Net; using System.Net.Http; +using System.Net.Http.Headers; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -101,7 +102,7 @@ namespace Discord.Net.Rest switch (p.Value) { #pragma warning disable IDISP004 - case string stringValue: { content.Add(new StringContent(stringValue), p.Key); continue; } + case string stringValue: { content.Add(new StringContent(stringValue, Encoding.UTF8, "text/plain"), p.Key); continue; } case byte[] byteArrayValue: { content.Add(new ByteArrayContent(byteArrayValue), p.Key); continue; } case Stream streamValue: { content.Add(new StreamContent(streamValue), p.Key); continue; } case MultipartFile fileValue: @@ -116,11 +117,20 @@ namespace Discord.Net.Rest stream = memoryStream; #pragma warning restore IDISP001 } - content.Add(new StreamContent(stream), p.Key, fileValue.Filename); + + var streamContent = new StreamContent(stream); + var extension = fileValue.Filename.Split('.').Last(); + + if(fileValue.ContentType != null) + streamContent.Headers.ContentType = new MediaTypeHeaderValue(fileValue.ContentType); + + content.Add(streamContent, p.Key, fileValue.Filename); #pragma warning restore IDISP004 + continue; } - default: throw new InvalidOperationException($"Unsupported param type \"{p.Value.GetType().Name}\"."); + default: + throw new InvalidOperationException($"Unsupported param type \"{p.Value.GetType().Name}\"."); } } } @@ -148,15 +158,15 @@ namespace Discord.Net.Rest private static readonly HttpMethod Patch = new HttpMethod("PATCH"); private HttpMethod GetMethod(string method) { - switch (method) + return method switch { - case "DELETE": return HttpMethod.Delete; - case "GET": return HttpMethod.Get; - case "PATCH": return Patch; - case "POST": return HttpMethod.Post; - case "PUT": return HttpMethod.Put; - default: throw new ArgumentOutOfRangeException(nameof(method), $"Unknown HttpMethod: {method}"); - } + "DELETE" => HttpMethod.Delete, + "GET" => HttpMethod.Get, + "PATCH" => Patch, + "POST" => HttpMethod.Post, + "PUT" => HttpMethod.Put, + _ => throw new ArgumentOutOfRangeException(nameof(method), $"Unknown HttpMethod: {method}"), + }; } } } diff --git a/src/Discord.Net.Rest/Net/ED25519/Array16.cs b/src/Discord.Net.Rest/Net/ED25519/Array16.cs new file mode 100644 index 000000000..fca8616c5 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Array16.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; + +namespace Discord.Net.ED25519 +{ + // Array16 Salsa20 state + // Array16 SHA-512 block + internal struct Array16 + { + public T x0; + public T x1; + public T x2; + public T x3; + public T x4; + public T x5; + public T x6; + public T x7; + public T x8; + public T x9; + public T x10; + public T x11; + public T x12; + public T x13; + public T x14; + public T x15; + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Array8.cs b/src/Discord.Net.Rest/Net/ED25519/Array8.cs new file mode 100644 index 000000000..b563ac213 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Array8.cs @@ -0,0 +1,18 @@ +using System; + +namespace Discord.Net.ED25519 +{ + // Array8 Poly1305 key + // Array8 SHA-512 state/output + internal struct Array8 + { + public T x0; + public T x1; + public T x2; + public T x3; + public T x4; + public T x5; + public T x6; + public T x7; + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/ByteIntegerConverter.cs b/src/Discord.Net.Rest/Net/ED25519/ByteIntegerConverter.cs new file mode 100644 index 000000000..40c7624ba --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/ByteIntegerConverter.cs @@ -0,0 +1,55 @@ +using System; + +namespace Discord.Net.ED25519 +{ + // Loops? Arrays? Never heard of that stuff + // Library avoids unnecessary heap allocations and unsafe code + // so this ugly code becomes necessary :( + internal static class ByteIntegerConverter + { + public static ulong LoadBigEndian64(byte[] buf, int offset) + { + return + (ulong)(buf[offset + 7]) + | (((ulong)(buf[offset + 6])) << 8) + | (((ulong)(buf[offset + 5])) << 16) + | (((ulong)(buf[offset + 4])) << 24) + | (((ulong)(buf[offset + 3])) << 32) + | (((ulong)(buf[offset + 2])) << 40) + | (((ulong)(buf[offset + 1])) << 48) + | (((ulong)(buf[offset + 0])) << 56); + } + + public static void StoreBigEndian64(byte[] buf, int offset, ulong value) + { + buf[offset + 7] = unchecked((byte)value); + buf[offset + 6] = unchecked((byte)(value >> 8)); + buf[offset + 5] = unchecked((byte)(value >> 16)); + buf[offset + 4] = unchecked((byte)(value >> 24)); + buf[offset + 3] = unchecked((byte)(value >> 32)); + buf[offset + 2] = unchecked((byte)(value >> 40)); + buf[offset + 1] = unchecked((byte)(value >> 48)); + buf[offset + 0] = unchecked((byte)(value >> 56)); + } + + public static void Array16LoadBigEndian64(out Array16 output, byte[] input, int inputOffset) + { + output.x0 = LoadBigEndian64(input, inputOffset + 0); + output.x1 = LoadBigEndian64(input, inputOffset + 8); + output.x2 = LoadBigEndian64(input, inputOffset + 16); + output.x3 = LoadBigEndian64(input, inputOffset + 24); + output.x4 = LoadBigEndian64(input, inputOffset + 32); + output.x5 = LoadBigEndian64(input, inputOffset + 40); + output.x6 = LoadBigEndian64(input, inputOffset + 48); + output.x7 = LoadBigEndian64(input, inputOffset + 56); + output.x8 = LoadBigEndian64(input, inputOffset + 64); + output.x9 = LoadBigEndian64(input, inputOffset + 72); + output.x10 = LoadBigEndian64(input, inputOffset + 80); + output.x11 = LoadBigEndian64(input, inputOffset + 88); + output.x12 = LoadBigEndian64(input, inputOffset + 96); + output.x13 = LoadBigEndian64(input, inputOffset + 104); + output.x14 = LoadBigEndian64(input, inputOffset + 112); + output.x15 = LoadBigEndian64(input, inputOffset + 120); + } + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/CryptoBytes.cs b/src/Discord.Net.Rest/Net/ED25519/CryptoBytes.cs new file mode 100644 index 000000000..cfd64104d --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/CryptoBytes.cs @@ -0,0 +1,272 @@ +using System; +using System.Linq; +using System.Numerics; +using System.Runtime.CompilerServices; + +namespace Discord.Net.ED25519 +{ + internal class CryptoBytes + { + /// + /// Comparison of two arrays. + /// + /// The runtime of this method does not depend on the contents of the arrays. Using constant time + /// prevents timing attacks that allow an attacker to learn if the arrays have a common prefix. + /// + /// It is important to use such a constant time comparison when verifying MACs. + /// + /// Byte array + /// Byte array + /// True if arrays are equal + public static bool ConstantTimeEquals(byte[] x, byte[] y) + { + if (x.Length != y.Length) + return false; + return InternalConstantTimeEquals(x, 0, y, 0, x.Length) != 0; + } + + /// + /// Comparison of two array segments. + /// + /// The runtime of this method does not depend on the contents of the arrays. Using constant time + /// prevents timing attacks that allow an attacker to learn if the arrays have a common prefix. + /// + /// It is important to use such a constant time comparison when verifying MACs. + /// + /// Byte array segment + /// Byte array segment + /// True if contents of x and y are equal + public static bool ConstantTimeEquals(ArraySegment x, ArraySegment y) + { + if (x.Count != y.Count) + return false; + return InternalConstantTimeEquals(x.Array, x.Offset, y.Array, y.Offset, x.Count) != 0; + } + + /// + /// Comparison of two byte sequences. + /// + /// The runtime of this method does not depend on the contents of the arrays. Using constant time + /// prevents timing attacks that allow an attacker to learn if the arrays have a common prefix. + /// + /// It is important to use such a constant time comparison when verifying MACs. + /// + /// Byte array + /// Offset of byte sequence in the x array + /// Byte array + /// Offset of byte sequence in the y array + /// Lengh of byte sequence + /// True if sequences are equal + public static bool ConstantTimeEquals(byte[] x, int xOffset, byte[] y, int yOffset, int length) + { + return InternalConstantTimeEquals(x, xOffset, y, yOffset, length) != 0; + } + + private static uint InternalConstantTimeEquals(byte[] x, int xOffset, byte[] y, int yOffset, int length) + { + int differentbits = 0; + for (int i = 0; i < length; i++) + differentbits |= x[xOffset + i] ^ y[yOffset + i]; + return (1 & (unchecked((uint)differentbits - 1) >> 8)); + } + + /// + /// Overwrites the contents of the array, wiping the previous content. + /// + /// Byte array + public static void Wipe(byte[] data) + { + InternalWipe(data, 0, data.Length); + } + + /// + /// Overwrites the contents of the array, wiping the previous content. + /// + /// Byte array + /// Index of byte sequence + /// Length of byte sequence + public static void Wipe(byte[] data, int offset, int length) + { + InternalWipe(data, offset, length); + } + + /// + /// Overwrites the contents of the array segment, wiping the previous content. + /// + /// Byte array segment + public static void Wipe(ArraySegment data) + { + InternalWipe(data.Array, data.Offset, data.Count); + } + + // Secure wiping is hard + // * the GC can move around and copy memory + // Perhaps this can be avoided by using unmanaged memory or by fixing the position of the array in memory + // * Swap files and error dumps can contain secret information + // It seems possible to lock memory in RAM, no idea about error dumps + // * Compiler could optimize out the wiping if it knows that data won't be read back + // I hope this is enough, suppressing inlining + // but perhaps `RtlSecureZeroMemory` is needed + [MethodImpl(MethodImplOptions.NoInlining)] + internal static void InternalWipe(byte[] data, int offset, int count) + { + Array.Clear(data, offset, count); + } + + // shallow wipe of structs + [MethodImpl(MethodImplOptions.NoInlining)] + internal static void InternalWipe(ref T data) + where T : struct + { + data = default(T); + } + + /// + /// Constant-time conversion of the bytes array to an upper-case hex string. + /// Please see http://stackoverflow.com/a/14333437/445517 for the detailed explanation + /// + /// Byte array + /// Hex representation of byte array + public static string ToHexStringUpper(byte[] data) + { + if (data == null) + return null; + char[] c = new char[data.Length * 2]; + int b; + for (int i = 0; i < data.Length; i++) + { + b = data[i] >> 4; + c[i * 2] = (char)(55 + b + (((b - 10) >> 31) & -7)); + b = data[i] & 0xF; + c[i * 2 + 1] = (char)(55 + b + (((b - 10) >> 31) & -7)); + } + return new string(c); + } + + /// + /// Constant-time conversion of the bytes array to an lower-case hex string. + /// Please see http://stackoverflow.com/a/14333437/445517 for the detailed explanation. + /// + /// Byte array + /// Hex representation of byte array + public static string ToHexStringLower(byte[] data) + { + if (data == null) + return null; + char[] c = new char[data.Length * 2]; + int b; + for (int i = 0; i < data.Length; i++) + { + b = data[i] >> 4; + c[i * 2] = (char)(87 + b + (((b - 10) >> 31) & -39)); + b = data[i] & 0xF; + c[i * 2 + 1] = (char)(87 + b + (((b - 10) >> 31) & -39)); + } + return new string(c); + } + + /// + /// Converts the hex string to bytes. Case insensitive. + /// + /// Hex encoded byte sequence + /// Byte array + public static byte[] FromHexString(string hexString) + { + if (hexString == null) + return null; + if (hexString.Length % 2 != 0) + throw new FormatException("The hex string is invalid because it has an odd length"); + var result = new byte[hexString.Length / 2]; + for (int i = 0; i < result.Length; i++) + result[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16); + return result; + } + + /// + /// Encodes the bytes with the Base64 encoding. + /// More compact than hex, but it is case-sensitive and uses the special characters `+`, `/` and `=`. + /// + /// Byte array + /// Base 64 encoded data + public static string ToBase64String(byte[] data) + { + if (data == null) + return null; + return Convert.ToBase64String(data); + } + + /// + /// Decodes a Base64 encoded string back to bytes. + /// + /// Base 64 encoded data + /// Byte array + public static byte[] FromBase64String(string base64String) + { + if (base64String == null) + return null; + return Convert.FromBase64String(base64String); + } + + private const string strDigits = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; + + /// + /// Encode a byte sequence as a base58-encoded string + /// + /// Byte sequence + /// Encoding result + public static string Base58Encode(byte[] input) + { + // Decode byte[] to BigInteger + BigInteger intData = 0; + for (int i = 0; i < input.Length; i++) + { + intData = intData * 256 + input[i]; + } + + // Encode BigInteger to Base58 string + string result = ""; + while (intData > 0) + { + int remainder = (int)(intData % 58); + intData /= 58; + result = strDigits[remainder] + result; + } + + // Append `1` for each leading 0 byte + for (int i = 0; i < input.Length && input[i] == 0; i++) + { + result = '1' + result; + } + return result; + } + + /// + /// // Decode a base58-encoded string into byte array + /// + /// Base58 data string + /// Byte array + public static byte[] Base58Decode(string input) + { + // Decode Base58 string to BigInteger + BigInteger intData = 0; + for (int i = 0; i < input.Length; i++) + { + int digit = strDigits.IndexOf(input[i]); //Slow + if (digit < 0) + throw new FormatException(string.Format("Invalid Base58 character `{0}` at position {1}", input[i], i)); + intData = intData * 58 + digit; + } + + // Encode BigInteger to byte[] + // Leading zero bytes get encoded as leading `1` characters + int leadingZeroCount = input.TakeWhile(c => c == '1').Count(); + var leadingZeros = Enumerable.Repeat((byte)0, leadingZeroCount); + var bytesWithoutLeadingZeros = + intData.ToByteArray() + .Reverse()// to big endian + .SkipWhile(b => b == 0);//strip sign byte + var result = leadingZeros.Concat(bytesWithoutLeadingZeros).ToArray(); + return result; + } + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519.cs new file mode 100644 index 000000000..109620efd --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.Net.ED25519 +{ + internal static class Ed25519 + { + /// + /// Public Keys are 32 byte values. All possible values of this size a valid. + /// + public const int PublicKeySize = 32; + /// + /// Signatures are 64 byte values + /// + public const int SignatureSize = 64; + /// + /// Private key seeds are 32 byte arbitrary values. This is the form that should be generated and stored. + /// + public const int PrivateKeySeedSize = 32; + /// + /// A 64 byte expanded form of private key. This form is used internally to improve performance + /// + public const int ExpandedPrivateKeySize = 32 * 2; + + /// + /// Verify Ed25519 signature + /// + /// Signature bytes + /// Message + /// Public key + /// True if signature is valid, false if it's not + public static bool Verify(ArraySegment signature, ArraySegment message, ArraySegment publicKey) + { + if (signature.Count != SignatureSize) + throw new ArgumentException($"Sizeof signature doesnt match defined size of {SignatureSize}"); + + if (publicKey.Count != PublicKeySize) + throw new ArgumentException($"Sizeof public key doesnt match defined size of {PublicKeySize}"); + + return Ed25519Operations.crypto_sign_verify(signature.Array, signature.Offset, message.Array, message.Offset, message.Count, publicKey.Array, publicKey.Offset); + } + + /// + /// Verify Ed25519 signature + /// + /// Signature bytes + /// Message + /// Public key + /// True if signature is valid, false if it's not + public static bool Verify(byte[] signature, byte[] message, byte[] publicKey) + { + Preconditions.NotNull(signature, nameof(signature)); + Preconditions.NotNull(message, nameof(message)); + Preconditions.NotNull(publicKey, nameof(publicKey)); + if (signature.Length != SignatureSize) + throw new ArgumentException($"Sizeof signature doesnt match defined size of {SignatureSize}"); + + if (publicKey.Length != PublicKeySize) + throw new ArgumentException($"Sizeof public key doesnt match defined size of {PublicKeySize}"); + + return Ed25519Operations.crypto_sign_verify(signature, 0, message, 0, message.Length, publicKey, 0); + } + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Operations.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Operations.cs new file mode 100644 index 000000000..4d5ece1e5 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Operations.cs @@ -0,0 +1,45 @@ +using Discord.Net.ED25519.Ed25519Ref10; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.Net.ED25519 +{ + internal class Ed25519Operations + { + public static bool crypto_sign_verify( + byte[] sig, int sigoffset, + byte[] m, int moffset, int mlen, + byte[] pk, int pkoffset) + { + byte[] h; + byte[] checkr = new byte[32]; + GroupElementP3 A; + GroupElementP2 R; + + if ((sig[sigoffset + 63] & 224) != 0) + return false; + if (GroupOperations.ge_frombytes_negate_vartime(out A, pk, pkoffset) != 0) + return false; + + var hasher = new Sha512(); + hasher.Update(sig, sigoffset, 32); + hasher.Update(pk, pkoffset, 32); + hasher.Update(m, moffset, mlen); + h = hasher.Finalize(); + + ScalarOperations.sc_reduce(h); + + var sm32 = new byte[32]; + Array.Copy(sig, sigoffset + 32, sm32, 0, 32); + GroupOperations.ge_double_scalarmult_vartime(out R, h, ref A, sm32); + GroupOperations.ge_tobytes(checkr, 0, ref R); + var result = CryptoBytes.ConstantTimeEquals(checkr, 0, sig, sigoffset, 32); + CryptoBytes.Wipe(h); + CryptoBytes.Wipe(checkr); + return result; + } + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/FieldElement.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/FieldElement.cs new file mode 100644 index 000000000..d612ff5be --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/FieldElement.cs @@ -0,0 +1,23 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal struct FieldElement + { + internal int x0, x1, x2, x3, x4, x5, x6, x7, x8, x9; + + internal FieldElement(params int[] elements) + { + x0 = elements[0]; + x1 = elements[1]; + x2 = elements[2]; + x3 = elements[3]; + x4 = elements[4]; + x5 = elements[5]; + x6 = elements[6]; + x7 = elements[7]; + x8 = elements[8]; + x9 = elements[9]; + } + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/GroupElement.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/GroupElement.cs new file mode 100644 index 000000000..d54b5ada7 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/GroupElement.cs @@ -0,0 +1,63 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + /* + ge means group element. + + Here the group is the set of pairs (x,y) of field elements (see fe.h) + satisfying -x^2 + y^2 = 1 + d x^2y^2 + where d = -121665/121666. + + Representations: + ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z + ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT + ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T + ge_precomp (Duif): (y+x,y-x,2dxy) + */ + + internal struct GroupElementP2 + { + public FieldElement X; + public FieldElement Y; + public FieldElement Z; + } ; + + internal struct GroupElementP3 + { + public FieldElement X; + public FieldElement Y; + public FieldElement Z; + public FieldElement T; + } ; + + internal struct GroupElementP1P1 + { + public FieldElement X; + public FieldElement Y; + public FieldElement Z; + public FieldElement T; + } ; + + internal struct GroupElementPreComp + { + public FieldElement yplusx; + public FieldElement yminusx; + public FieldElement xy2d; + + public GroupElementPreComp(FieldElement yplusx, FieldElement yminusx, FieldElement xy2d) + { + this.yplusx = yplusx; + this.yminusx = yminusx; + this.xy2d = xy2d; + } + } ; + + internal struct GroupElementCached + { + public FieldElement YplusX; + public FieldElement YminusX; + public FieldElement Z; + public FieldElement T2d; + } ; +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/base.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/base.cs new file mode 100644 index 000000000..2a25504c9 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/base.cs @@ -0,0 +1,1355 @@ +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class LookupTables + { + /* base[i][j] = (j+1)*256^i*B */ + //32*8 + internal static GroupElementPreComp[][] Base = new GroupElementPreComp[][] + { + new[]{ + new GroupElementPreComp( + new FieldElement( 25967493,-14356035,29566456,3660896,-12694345,4014787,27544626,-11754271,-6079156,2047605 ), + new FieldElement( -12545711,934262,-2722910,3049990,-727428,9406986,12720692,5043384,19500929,-15469378 ), + new FieldElement( -8738181,4489570,9688441,-14785194,10184609,-12363380,29287919,11864899,-24514362,-4438546 ) + ), + new GroupElementPreComp( + new FieldElement( -12815894,-12976347,-21581243,11784320,-25355658,-2750717,-11717903,-3814571,-358445,-10211303 ), + new FieldElement( -21703237,6903825,27185491,6451973,-29577724,-9554005,-15616551,11189268,-26829678,-5319081 ), + new FieldElement( 26966642,11152617,32442495,15396054,14353839,-12752335,-3128826,-9541118,-15472047,-4166697 ) + ), + new GroupElementPreComp( + new FieldElement( 15636291,-9688557,24204773,-7912398,616977,-16685262,27787600,-14772189,28944400,-1550024 ), + new FieldElement( 16568933,4717097,-11556148,-1102322,15682896,-11807043,16354577,-11775962,7689662,11199574 ), + new FieldElement( 30464156,-5976125,-11779434,-15670865,23220365,15915852,7512774,10017326,-17749093,-9920357 ) + ), + new GroupElementPreComp( + new FieldElement( -17036878,13921892,10945806,-6033431,27105052,-16084379,-28926210,15006023,3284568,-6276540 ), + new FieldElement( 23599295,-8306047,-11193664,-7687416,13236774,10506355,7464579,9656445,13059162,10374397 ), + new FieldElement( 7798556,16710257,3033922,2874086,28997861,2835604,32406664,-3839045,-641708,-101325 ) + ), + new GroupElementPreComp( + new FieldElement( 10861363,11473154,27284546,1981175,-30064349,12577861,32867885,14515107,-15438304,10819380 ), + new FieldElement( 4708026,6336745,20377586,9066809,-11272109,6594696,-25653668,12483688,-12668491,5581306 ), + new FieldElement( 19563160,16186464,-29386857,4097519,10237984,-4348115,28542350,13850243,-23678021,-15815942 ) + ), + new GroupElementPreComp( + new FieldElement( -15371964,-12862754,32573250,4720197,-26436522,5875511,-19188627,-15224819,-9818940,-12085777 ), + new FieldElement( -8549212,109983,15149363,2178705,22900618,4543417,3044240,-15689887,1762328,14866737 ), + new FieldElement( -18199695,-15951423,-10473290,1707278,-17185920,3916101,-28236412,3959421,27914454,4383652 ) + ), + new GroupElementPreComp( + new FieldElement( 5153746,9909285,1723747,-2777874,30523605,5516873,19480852,5230134,-23952439,-15175766 ), + new FieldElement( -30269007,-3463509,7665486,10083793,28475525,1649722,20654025,16520125,30598449,7715701 ), + new FieldElement( 28881845,14381568,9657904,3680757,-20181635,7843316,-31400660,1370708,29794553,-1409300 ) + ), + new GroupElementPreComp( + new FieldElement( 14499471,-2729599,-33191113,-4254652,28494862,14271267,30290735,10876454,-33154098,2381726 ), + new FieldElement( -7195431,-2655363,-14730155,462251,-27724326,3941372,-6236617,3696005,-32300832,15351955 ), + new FieldElement( 27431194,8222322,16448760,-3907995,-18707002,11938355,-32961401,-2970515,29551813,10109425 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( -13657040,-13155431,-31283750,11777098,21447386,6519384,-2378284,-1627556,10092783,-4764171 ), + new FieldElement( 27939166,14210322,4677035,16277044,-22964462,-12398139,-32508754,12005538,-17810127,12803510 ), + new FieldElement( 17228999,-15661624,-1233527,300140,-1224870,-11714777,30364213,-9038194,18016357,4397660 ) + ), + new GroupElementPreComp( + new FieldElement( -10958843,-7690207,4776341,-14954238,27850028,-15602212,-26619106,14544525,-17477504,982639 ), + new FieldElement( 29253598,15796703,-2863982,-9908884,10057023,3163536,7332899,-4120128,-21047696,9934963 ), + new FieldElement( 5793303,16271923,-24131614,-10116404,29188560,1206517,-14747930,4559895,-30123922,-10897950 ) + ), + new GroupElementPreComp( + new FieldElement( -27643952,-11493006,16282657,-11036493,28414021,-15012264,24191034,4541697,-13338309,5500568 ), + new FieldElement( 12650548,-1497113,9052871,11355358,-17680037,-8400164,-17430592,12264343,10874051,13524335 ), + new FieldElement( 25556948,-3045990,714651,2510400,23394682,-10415330,33119038,5080568,-22528059,5376628 ) + ), + new GroupElementPreComp( + new FieldElement( -26088264,-4011052,-17013699,-3537628,-6726793,1920897,-22321305,-9447443,4535768,1569007 ), + new FieldElement( -2255422,14606630,-21692440,-8039818,28430649,8775819,-30494562,3044290,31848280,12543772 ), + new FieldElement( -22028579,2943893,-31857513,6777306,13784462,-4292203,-27377195,-2062731,7718482,14474653 ) + ), + new GroupElementPreComp( + new FieldElement( 2385315,2454213,-22631320,46603,-4437935,-15680415,656965,-7236665,24316168,-5253567 ), + new FieldElement( 13741529,10911568,-33233417,-8603737,-20177830,-1033297,33040651,-13424532,-20729456,8321686 ), + new FieldElement( 21060490,-2212744,15712757,-4336099,1639040,10656336,23845965,-11874838,-9984458,608372 ) + ), + new GroupElementPreComp( + new FieldElement( -13672732,-15087586,-10889693,-7557059,-6036909,11305547,1123968,-6780577,27229399,23887 ), + new FieldElement( -23244140,-294205,-11744728,14712571,-29465699,-2029617,12797024,-6440308,-1633405,16678954 ), + new FieldElement( -29500620,4770662,-16054387,14001338,7830047,9564805,-1508144,-4795045,-17169265,4904953 ) + ), + new GroupElementPreComp( + new FieldElement( 24059557,14617003,19037157,-15039908,19766093,-14906429,5169211,16191880,2128236,-4326833 ), + new FieldElement( -16981152,4124966,-8540610,-10653797,30336522,-14105247,-29806336,916033,-6882542,-2986532 ), + new FieldElement( -22630907,12419372,-7134229,-7473371,-16478904,16739175,285431,2763829,15736322,4143876 ) + ), + new GroupElementPreComp( + new FieldElement( 2379352,11839345,-4110402,-5988665,11274298,794957,212801,-14594663,23527084,-16458268 ), + new FieldElement( 33431127,-11130478,-17838966,-15626900,8909499,8376530,-32625340,4087881,-15188911,-14416214 ), + new FieldElement( 1767683,7197987,-13205226,-2022635,-13091350,448826,5799055,4357868,-4774191,-16323038 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( 6721966,13833823,-23523388,-1551314,26354293,-11863321,23365147,-3949732,7390890,2759800 ), + new FieldElement( 4409041,2052381,23373853,10530217,7676779,-12885954,21302353,-4264057,1244380,-12919645 ), + new FieldElement( -4421239,7169619,4982368,-2957590,30256825,-2777540,14086413,9208236,15886429,16489664 ) + ), + new GroupElementPreComp( + new FieldElement( 1996075,10375649,14346367,13311202,-6874135,-16438411,-13693198,398369,-30606455,-712933 ), + new FieldElement( -25307465,9795880,-2777414,14878809,-33531835,14780363,13348553,12076947,-30836462,5113182 ), + new FieldElement( -17770784,11797796,31950843,13929123,-25888302,12288344,-30341101,-7336386,13847711,5387222 ) + ), + new GroupElementPreComp( + new FieldElement( -18582163,-3416217,17824843,-2340966,22744343,-10442611,8763061,3617786,-19600662,10370991 ), + new FieldElement( 20246567,-14369378,22358229,-543712,18507283,-10413996,14554437,-8746092,32232924,16763880 ), + new FieldElement( 9648505,10094563,26416693,14745928,-30374318,-6472621,11094161,15689506,3140038,-16510092 ) + ), + new GroupElementPreComp( + new FieldElement( -16160072,5472695,31895588,4744994,8823515,10365685,-27224800,9448613,-28774454,366295 ), + new FieldElement( 19153450,11523972,-11096490,-6503142,-24647631,5420647,28344573,8041113,719605,11671788 ), + new FieldElement( 8678025,2694440,-6808014,2517372,4964326,11152271,-15432916,-15266516,27000813,-10195553 ) + ), + new GroupElementPreComp( + new FieldElement( -15157904,7134312,8639287,-2814877,-7235688,10421742,564065,5336097,6750977,-14521026 ), + new FieldElement( 11836410,-3979488,26297894,16080799,23455045,15735944,1695823,-8819122,8169720,16220347 ), + new FieldElement( -18115838,8653647,17578566,-6092619,-8025777,-16012763,-11144307,-2627664,-5990708,-14166033 ) + ), + new GroupElementPreComp( + new FieldElement( -23308498,-10968312,15213228,-10081214,-30853605,-11050004,27884329,2847284,2655861,1738395 ), + new FieldElement( -27537433,-14253021,-25336301,-8002780,-9370762,8129821,21651608,-3239336,-19087449,-11005278 ), + new FieldElement( 1533110,3437855,23735889,459276,29970501,11335377,26030092,5821408,10478196,8544890 ) + ), + new GroupElementPreComp( + new FieldElement( 32173121,-16129311,24896207,3921497,22579056,-3410854,19270449,12217473,17789017,-3395995 ), + new FieldElement( -30552961,-2228401,-15578829,-10147201,13243889,517024,15479401,-3853233,30460520,1052596 ), + new FieldElement( -11614875,13323618,32618793,8175907,-15230173,12596687,27491595,-4612359,3179268,-9478891 ) + ), + new GroupElementPreComp( + new FieldElement( 31947069,-14366651,-4640583,-15339921,-15125977,-6039709,-14756777,-16411740,19072640,-9511060 ), + new FieldElement( 11685058,11822410,3158003,-13952594,33402194,-4165066,5977896,-5215017,473099,5040608 ), + new FieldElement( -20290863,8198642,-27410132,11602123,1290375,-2799760,28326862,1721092,-19558642,-3131606 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( 7881532,10687937,7578723,7738378,-18951012,-2553952,21820786,8076149,-27868496,11538389 ), + new FieldElement( -19935666,3899861,18283497,-6801568,-15728660,-11249211,8754525,7446702,-5676054,5797016 ), + new FieldElement( -11295600,-3793569,-15782110,-7964573,12708869,-8456199,2014099,-9050574,-2369172,-5877341 ) + ), + new GroupElementPreComp( + new FieldElement( -22472376,-11568741,-27682020,1146375,18956691,16640559,1192730,-3714199,15123619,10811505 ), + new FieldElement( 14352098,-3419715,-18942044,10822655,32750596,4699007,-70363,15776356,-28886779,-11974553 ), + new FieldElement( -28241164,-8072475,-4978962,-5315317,29416931,1847569,-20654173,-16484855,4714547,-9600655 ) + ), + new GroupElementPreComp( + new FieldElement( 15200332,8368572,19679101,15970074,-31872674,1959451,24611599,-4543832,-11745876,12340220 ), + new FieldElement( 12876937,-10480056,33134381,6590940,-6307776,14872440,9613953,8241152,15370987,9608631 ), + new FieldElement( -4143277,-12014408,8446281,-391603,4407738,13629032,-7724868,15866074,-28210621,-8814099 ) + ), + new GroupElementPreComp( + new FieldElement( 26660628,-15677655,8393734,358047,-7401291,992988,-23904233,858697,20571223,8420556 ), + new FieldElement( 14620715,13067227,-15447274,8264467,14106269,15080814,33531827,12516406,-21574435,-12476749 ), + new FieldElement( 236881,10476226,57258,-14677024,6472998,2466984,17258519,7256740,8791136,15069930 ) + ), + new GroupElementPreComp( + new FieldElement( 1276410,-9371918,22949635,-16322807,-23493039,-5702186,14711875,4874229,-30663140,-2331391 ), + new FieldElement( 5855666,4990204,-13711848,7294284,-7804282,1924647,-1423175,-7912378,-33069337,9234253 ), + new FieldElement( 20590503,-9018988,31529744,-7352666,-2706834,10650548,31559055,-11609587,18979186,13396066 ) + ), + new GroupElementPreComp( + new FieldElement( 24474287,4968103,22267082,4407354,24063882,-8325180,-18816887,13594782,33514650,7021958 ), + new FieldElement( -11566906,-6565505,-21365085,15928892,-26158305,4315421,-25948728,-3916677,-21480480,12868082 ), + new FieldElement( -28635013,13504661,19988037,-2132761,21078225,6443208,-21446107,2244500,-12455797,-8089383 ) + ), + new GroupElementPreComp( + new FieldElement( -30595528,13793479,-5852820,319136,-25723172,-6263899,33086546,8957937,-15233648,5540521 ), + new FieldElement( -11630176,-11503902,-8119500,-7643073,2620056,1022908,-23710744,-1568984,-16128528,-14962807 ), + new FieldElement( 23152971,775386,27395463,14006635,-9701118,4649512,1689819,892185,-11513277,-15205948 ) + ), + new GroupElementPreComp( + new FieldElement( 9770129,9586738,26496094,4324120,1556511,-3550024,27453819,4763127,-19179614,5867134 ), + new FieldElement( -32765025,1927590,31726409,-4753295,23962434,-16019500,27846559,5931263,-29749703,-16108455 ), + new FieldElement( 27461885,-2977536,22380810,1815854,-23033753,-3031938,7283490,-15148073,-19526700,7734629 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( -8010264,-9590817,-11120403,6196038,29344158,-13430885,7585295,-3176626,18549497,15302069 ), + new FieldElement( -32658337,-6171222,-7672793,-11051681,6258878,13504381,10458790,-6418461,-8872242,8424746 ), + new FieldElement( 24687205,8613276,-30667046,-3233545,1863892,-1830544,19206234,7134917,-11284482,-828919 ) + ), + new GroupElementPreComp( + new FieldElement( 11334899,-9218022,8025293,12707519,17523892,-10476071,10243738,-14685461,-5066034,16498837 ), + new FieldElement( 8911542,6887158,-9584260,-6958590,11145641,-9543680,17303925,-14124238,6536641,10543906 ), + new FieldElement( -28946384,15479763,-17466835,568876,-1497683,11223454,-2669190,-16625574,-27235709,8876771 ) + ), + new GroupElementPreComp( + new FieldElement( -25742899,-12566864,-15649966,-846607,-33026686,-796288,-33481822,15824474,-604426,-9039817 ), + new FieldElement( 10330056,70051,7957388,-9002667,9764902,15609756,27698697,-4890037,1657394,3084098 ), + new FieldElement( 10477963,-7470260,12119566,-13250805,29016247,-5365589,31280319,14396151,-30233575,15272409 ) + ), + new GroupElementPreComp( + new FieldElement( -12288309,3169463,28813183,16658753,25116432,-5630466,-25173957,-12636138,-25014757,1950504 ), + new FieldElement( -26180358,9489187,11053416,-14746161,-31053720,5825630,-8384306,-8767532,15341279,8373727 ), + new FieldElement( 28685821,7759505,-14378516,-12002860,-31971820,4079242,298136,-10232602,-2878207,15190420 ) + ), + new GroupElementPreComp( + new FieldElement( -32932876,13806336,-14337485,-15794431,-24004620,10940928,8669718,2742393,-26033313,-6875003 ), + new FieldElement( -1580388,-11729417,-25979658,-11445023,-17411874,-10912854,9291594,-16247779,-12154742,6048605 ), + new FieldElement( -30305315,14843444,1539301,11864366,20201677,1900163,13934231,5128323,11213262,9168384 ) + ), + new GroupElementPreComp( + new FieldElement( -26280513,11007847,19408960,-940758,-18592965,-4328580,-5088060,-11105150,20470157,-16398701 ), + new FieldElement( -23136053,9282192,14855179,-15390078,-7362815,-14408560,-22783952,14461608,14042978,5230683 ), + new FieldElement( 29969567,-2741594,-16711867,-8552442,9175486,-2468974,21556951,3506042,-5933891,-12449708 ) + ), + new GroupElementPreComp( + new FieldElement( -3144746,8744661,19704003,4581278,-20430686,6830683,-21284170,8971513,-28539189,15326563 ), + new FieldElement( -19464629,10110288,-17262528,-3503892,-23500387,1355669,-15523050,15300988,-20514118,9168260 ), + new FieldElement( -5353335,4488613,-23803248,16314347,7780487,-15638939,-28948358,9601605,33087103,-9011387 ) + ), + new GroupElementPreComp( + new FieldElement( -19443170,-15512900,-20797467,-12445323,-29824447,10229461,-27444329,-15000531,-5996870,15664672 ), + new FieldElement( 23294591,-16632613,-22650781,-8470978,27844204,11461195,13099750,-2460356,18151676,13417686 ), + new FieldElement( -24722913,-4176517,-31150679,5988919,-26858785,6685065,1661597,-12551441,15271676,-15452665 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( 11433042,-13228665,8239631,-5279517,-1985436,-725718,-18698764,2167544,-6921301,-13440182 ), + new FieldElement( -31436171,15575146,30436815,12192228,-22463353,9395379,-9917708,-8638997,12215110,12028277 ), + new FieldElement( 14098400,6555944,23007258,5757252,-15427832,-12950502,30123440,4617780,-16900089,-655628 ) + ), + new GroupElementPreComp( + new FieldElement( -4026201,-15240835,11893168,13718664,-14809462,1847385,-15819999,10154009,23973261,-12684474 ), + new FieldElement( -26531820,-3695990,-1908898,2534301,-31870557,-16550355,18341390,-11419951,32013174,-10103539 ), + new FieldElement( -25479301,10876443,-11771086,-14625140,-12369567,1838104,21911214,6354752,4425632,-837822 ) + ), + new GroupElementPreComp( + new FieldElement( -10433389,-14612966,22229858,-3091047,-13191166,776729,-17415375,-12020462,4725005,14044970 ), + new FieldElement( 19268650,-7304421,1555349,8692754,-21474059,-9910664,6347390,-1411784,-19522291,-16109756 ), + new FieldElement( -24864089,12986008,-10898878,-5558584,-11312371,-148526,19541418,8180106,9282262,10282508 ) + ), + new GroupElementPreComp( + new FieldElement( -26205082,4428547,-8661196,-13194263,4098402,-14165257,15522535,8372215,5542595,-10702683 ), + new FieldElement( -10562541,14895633,26814552,-16673850,-17480754,-2489360,-2781891,6993761,-18093885,10114655 ), + new FieldElement( -20107055,-929418,31422704,10427861,-7110749,6150669,-29091755,-11529146,25953725,-106158 ) + ), + new GroupElementPreComp( + new FieldElement( -4234397,-8039292,-9119125,3046000,2101609,-12607294,19390020,6094296,-3315279,12831125 ), + new FieldElement( -15998678,7578152,5310217,14408357,-33548620,-224739,31575954,6326196,7381791,-2421839 ), + new FieldElement( -20902779,3296811,24736065,-16328389,18374254,7318640,6295303,8082724,-15362489,12339664 ) + ), + new GroupElementPreComp( + new FieldElement( 27724736,2291157,6088201,-14184798,1792727,5857634,13848414,15768922,25091167,14856294 ), + new FieldElement( -18866652,8331043,24373479,8541013,-701998,-9269457,12927300,-12695493,-22182473,-9012899 ), + new FieldElement( -11423429,-5421590,11632845,3405020,30536730,-11674039,-27260765,13866390,30146206,9142070 ) + ), + new GroupElementPreComp( + new FieldElement( 3924129,-15307516,-13817122,-10054960,12291820,-668366,-27702774,9326384,-8237858,4171294 ), + new FieldElement( -15921940,16037937,6713787,16606682,-21612135,2790944,26396185,3731949,345228,-5462949 ), + new FieldElement( -21327538,13448259,25284571,1143661,20614966,-8849387,2031539,-12391231,-16253183,-13582083 ) + ), + new GroupElementPreComp( + new FieldElement( 31016211,-16722429,26371392,-14451233,-5027349,14854137,17477601,3842657,28012650,-16405420 ), + new FieldElement( -5075835,9368966,-8562079,-4600902,-15249953,6970560,-9189873,16292057,-8867157,3507940 ), + new FieldElement( 29439664,3537914,23333589,6997794,-17555561,-11018068,-15209202,-15051267,-9164929,6580396 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( -12185861,-7679788,16438269,10826160,-8696817,-6235611,17860444,-9273846,-2095802,9304567 ), + new FieldElement( 20714564,-4336911,29088195,7406487,11426967,-5095705,14792667,-14608617,5289421,-477127 ), + new FieldElement( -16665533,-10650790,-6160345,-13305760,9192020,-1802462,17271490,12349094,26939669,-3752294 ) + ), + new GroupElementPreComp( + new FieldElement( -12889898,9373458,31595848,16374215,21471720,13221525,-27283495,-12348559,-3698806,117887 ), + new FieldElement( 22263325,-6560050,3984570,-11174646,-15114008,-566785,28311253,5358056,-23319780,541964 ), + new FieldElement( 16259219,3261970,2309254,-15534474,-16885711,-4581916,24134070,-16705829,-13337066,-13552195 ) + ), + new GroupElementPreComp( + new FieldElement( 9378160,-13140186,-22845982,-12745264,28198281,-7244098,-2399684,-717351,690426,14876244 ), + new FieldElement( 24977353,-314384,-8223969,-13465086,28432343,-1176353,-13068804,-12297348,-22380984,6618999 ), + new FieldElement( -1538174,11685646,12944378,13682314,-24389511,-14413193,8044829,-13817328,32239829,-5652762 ) + ), + new GroupElementPreComp( + new FieldElement( -18603066,4762990,-926250,8885304,-28412480,-3187315,9781647,-10350059,32779359,5095274 ), + new FieldElement( -33008130,-5214506,-32264887,-3685216,9460461,-9327423,-24601656,14506724,21639561,-2630236 ), + new FieldElement( -16400943,-13112215,25239338,15531969,3987758,-4499318,-1289502,-6863535,17874574,558605 ) + ), + new GroupElementPreComp( + new FieldElement( -13600129,10240081,9171883,16131053,-20869254,9599700,33499487,5080151,2085892,5119761 ), + new FieldElement( -22205145,-2519528,-16381601,414691,-25019550,2170430,30634760,-8363614,-31999993,-5759884 ), + new FieldElement( -6845704,15791202,8550074,-1312654,29928809,-12092256,27534430,-7192145,-22351378,12961482 ) + ), + new GroupElementPreComp( + new FieldElement( -24492060,-9570771,10368194,11582341,-23397293,-2245287,16533930,8206996,-30194652,-5159638 ), + new FieldElement( -11121496,-3382234,2307366,6362031,-135455,8868177,-16835630,7031275,7589640,8945490 ), + new FieldElement( -32152748,8917967,6661220,-11677616,-1192060,-15793393,7251489,-11182180,24099109,-14456170 ) + ), + new GroupElementPreComp( + new FieldElement( 5019558,-7907470,4244127,-14714356,-26933272,6453165,-19118182,-13289025,-6231896,-10280736 ), + new FieldElement( 10853594,10721687,26480089,5861829,-22995819,1972175,-1866647,-10557898,-3363451,-6441124 ), + new FieldElement( -17002408,5906790,221599,-6563147,7828208,-13248918,24362661,-2008168,-13866408,7421392 ) + ), + new GroupElementPreComp( + new FieldElement( 8139927,-6546497,32257646,-5890546,30375719,1886181,-21175108,15441252,28826358,-4123029 ), + new FieldElement( 6267086,9695052,7709135,-16603597,-32869068,-1886135,14795160,-7840124,13746021,-1742048 ), + new FieldElement( 28584902,7787108,-6732942,-15050729,22846041,-7571236,-3181936,-363524,4771362,-8419958 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( 24949256,6376279,-27466481,-8174608,-18646154,-9930606,33543569,-12141695,3569627,11342593 ), + new FieldElement( 26514989,4740088,27912651,3697550,19331575,-11472339,6809886,4608608,7325975,-14801071 ), + new FieldElement( -11618399,-14554430,-24321212,7655128,-1369274,5214312,-27400540,10258390,-17646694,-8186692 ) + ), + new GroupElementPreComp( + new FieldElement( 11431204,15823007,26570245,14329124,18029990,4796082,-31446179,15580664,9280358,-3973687 ), + new FieldElement( -160783,-10326257,-22855316,-4304997,-20861367,-13621002,-32810901,-11181622,-15545091,4387441 ), + new FieldElement( -20799378,12194512,3937617,-5805892,-27154820,9340370,-24513992,8548137,20617071,-7482001 ) + ), + new GroupElementPreComp( + new FieldElement( -938825,-3930586,-8714311,16124718,24603125,-6225393,-13775352,-11875822,24345683,10325460 ), + new FieldElement( -19855277,-1568885,-22202708,8714034,14007766,6928528,16318175,-1010689,4766743,3552007 ), + new FieldElement( -21751364,-16730916,1351763,-803421,-4009670,3950935,3217514,14481909,10988822,-3994762 ) + ), + new GroupElementPreComp( + new FieldElement( 15564307,-14311570,3101243,5684148,30446780,-8051356,12677127,-6505343,-8295852,13296005 ), + new FieldElement( -9442290,6624296,-30298964,-11913677,-4670981,-2057379,31521204,9614054,-30000824,12074674 ), + new FieldElement( 4771191,-135239,14290749,-13089852,27992298,14998318,-1413936,-1556716,29832613,-16391035 ) + ), + new GroupElementPreComp( + new FieldElement( 7064884,-7541174,-19161962,-5067537,-18891269,-2912736,25825242,5293297,-27122660,13101590 ), + new FieldElement( -2298563,2439670,-7466610,1719965,-27267541,-16328445,32512469,-5317593,-30356070,-4190957 ), + new FieldElement( -30006540,10162316,-33180176,3981723,-16482138,-13070044,14413974,9515896,19568978,9628812 ) + ), + new GroupElementPreComp( + new FieldElement( 33053803,199357,15894591,1583059,27380243,-4580435,-17838894,-6106839,-6291786,3437740 ), + new FieldElement( -18978877,3884493,19469877,12726490,15913552,13614290,-22961733,70104,7463304,4176122 ), + new FieldElement( -27124001,10659917,11482427,-16070381,12771467,-6635117,-32719404,-5322751,24216882,5944158 ) + ), + new GroupElementPreComp( + new FieldElement( 8894125,7450974,-2664149,-9765752,-28080517,-12389115,19345746,14680796,11632993,5847885 ), + new FieldElement( 26942781,-2315317,9129564,-4906607,26024105,11769399,-11518837,6367194,-9727230,4782140 ), + new FieldElement( 19916461,-4828410,-22910704,-11414391,25606324,-5972441,33253853,8220911,6358847,-1873857 ) + ), + new GroupElementPreComp( + new FieldElement( 801428,-2081702,16569428,11065167,29875704,96627,7908388,-4480480,-13538503,1387155 ), + new FieldElement( 19646058,5720633,-11416706,12814209,11607948,12749789,14147075,15156355,-21866831,11835260 ), + new FieldElement( 19299512,1155910,28703737,14890794,2925026,7269399,26121523,15467869,-26560550,5052483 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( -3017432,10058206,1980837,3964243,22160966,12322533,-6431123,-12618185,12228557,-7003677 ), + new FieldElement( 32944382,14922211,-22844894,5188528,21913450,-8719943,4001465,13238564,-6114803,8653815 ), + new FieldElement( 22865569,-4652735,27603668,-12545395,14348958,8234005,24808405,5719875,28483275,2841751 ) + ), + new GroupElementPreComp( + new FieldElement( -16420968,-1113305,-327719,-12107856,21886282,-15552774,-1887966,-315658,19932058,-12739203 ), + new FieldElement( -11656086,10087521,-8864888,-5536143,-19278573,-3055912,3999228,13239134,-4777469,-13910208 ), + new FieldElement( 1382174,-11694719,17266790,9194690,-13324356,9720081,20403944,11284705,-14013818,3093230 ) + ), + new GroupElementPreComp( + new FieldElement( 16650921,-11037932,-1064178,1570629,-8329746,7352753,-302424,16271225,-24049421,-6691850 ), + new FieldElement( -21911077,-5927941,-4611316,-5560156,-31744103,-10785293,24123614,15193618,-21652117,-16739389 ), + new FieldElement( -9935934,-4289447,-25279823,4372842,2087473,10399484,31870908,14690798,17361620,11864968 ) + ), + new GroupElementPreComp( + new FieldElement( -11307610,6210372,13206574,5806320,-29017692,-13967200,-12331205,-7486601,-25578460,-16240689 ), + new FieldElement( 14668462,-12270235,26039039,15305210,25515617,4542480,10453892,6577524,9145645,-6443880 ), + new FieldElement( 5974874,3053895,-9433049,-10385191,-31865124,3225009,-7972642,3936128,-5652273,-3050304 ) + ), + new GroupElementPreComp( + new FieldElement( 30625386,-4729400,-25555961,-12792866,-20484575,7695099,17097188,-16303496,-27999779,1803632 ), + new FieldElement( -3553091,9865099,-5228566,4272701,-5673832,-16689700,14911344,12196514,-21405489,7047412 ), + new FieldElement( 20093277,9920966,-11138194,-5343857,13161587,12044805,-32856851,4124601,-32343828,-10257566 ) + ), + new GroupElementPreComp( + new FieldElement( -20788824,14084654,-13531713,7842147,19119038,-13822605,4752377,-8714640,-21679658,2288038 ), + new FieldElement( -26819236,-3283715,29965059,3039786,-14473765,2540457,29457502,14625692,-24819617,12570232 ), + new FieldElement( -1063558,-11551823,16920318,12494842,1278292,-5869109,-21159943,-3498680,-11974704,4724943 ) + ), + new GroupElementPreComp( + new FieldElement( 17960970,-11775534,-4140968,-9702530,-8876562,-1410617,-12907383,-8659932,-29576300,1903856 ), + new FieldElement( 23134274,-14279132,-10681997,-1611936,20684485,15770816,-12989750,3190296,26955097,14109738 ), + new FieldElement( 15308788,5320727,-30113809,-14318877,22902008,7767164,29425325,-11277562,31960942,11934971 ) + ), + new GroupElementPreComp( + new FieldElement( -27395711,8435796,4109644,12222639,-24627868,14818669,20638173,4875028,10491392,1379718 ), + new FieldElement( -13159415,9197841,3875503,-8936108,-1383712,-5879801,33518459,16176658,21432314,12180697 ), + new FieldElement( -11787308,11500838,13787581,-13832590,-22430679,10140205,1465425,12689540,-10301319,-13872883 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( 5414091,-15386041,-21007664,9643570,12834970,1186149,-2622916,-1342231,26128231,6032912 ), + new FieldElement( -26337395,-13766162,32496025,-13653919,17847801,-12669156,3604025,8316894,-25875034,-10437358 ), + new FieldElement( 3296484,6223048,24680646,-12246460,-23052020,5903205,-8862297,-4639164,12376617,3188849 ) + ), + new GroupElementPreComp( + new FieldElement( 29190488,-14659046,27549113,-1183516,3520066,-10697301,32049515,-7309113,-16109234,-9852307 ), + new FieldElement( -14744486,-9309156,735818,-598978,-20407687,-5057904,25246078,-15795669,18640741,-960977 ), + new FieldElement( -6928835,-16430795,10361374,5642961,4910474,12345252,-31638386,-494430,10530747,1053335 ) + ), + new GroupElementPreComp( + new FieldElement( -29265967,-14186805,-13538216,-12117373,-19457059,-10655384,-31462369,-2948985,24018831,15026644 ), + new FieldElement( -22592535,-3145277,-2289276,5953843,-13440189,9425631,25310643,13003497,-2314791,-15145616 ), + new FieldElement( -27419985,-603321,-8043984,-1669117,-26092265,13987819,-27297622,187899,-23166419,-2531735 ) + ), + new GroupElementPreComp( + new FieldElement( -21744398,-13810475,1844840,5021428,-10434399,-15911473,9716667,16266922,-5070217,726099 ), + new FieldElement( 29370922,-6053998,7334071,-15342259,9385287,2247707,-13661962,-4839461,30007388,-15823341 ), + new FieldElement( -936379,16086691,23751945,-543318,-1167538,-5189036,9137109,730663,9835848,4555336 ) + ), + new GroupElementPreComp( + new FieldElement( -23376435,1410446,-22253753,-12899614,30867635,15826977,17693930,544696,-11985298,12422646 ), + new FieldElement( 31117226,-12215734,-13502838,6561947,-9876867,-12757670,-5118685,-4096706,29120153,13924425 ), + new FieldElement( -17400879,-14233209,19675799,-2734756,-11006962,-5858820,-9383939,-11317700,7240931,-237388 ) + ), + new GroupElementPreComp( + new FieldElement( -31361739,-11346780,-15007447,-5856218,-22453340,-12152771,1222336,4389483,3293637,-15551743 ), + new FieldElement( -16684801,-14444245,11038544,11054958,-13801175,-3338533,-24319580,7733547,12796905,-6335822 ), + new FieldElement( -8759414,-10817836,-25418864,10783769,-30615557,-9746811,-28253339,3647836,3222231,-11160462 ) + ), + new GroupElementPreComp( + new FieldElement( 18606113,1693100,-25448386,-15170272,4112353,10045021,23603893,-2048234,-7550776,2484985 ), + new FieldElement( 9255317,-3131197,-12156162,-1004256,13098013,-9214866,16377220,-2102812,-19802075,-3034702 ), + new FieldElement( -22729289,7496160,-5742199,11329249,19991973,-3347502,-31718148,9936966,-30097688,-10618797 ) + ), + new GroupElementPreComp( + new FieldElement( 21878590,-5001297,4338336,13643897,-3036865,13160960,19708896,5415497,-7360503,-4109293 ), + new FieldElement( 27736861,10103576,12500508,8502413,-3413016,-9633558,10436918,-1550276,-23659143,-8132100 ), + new FieldElement( 19492550,-12104365,-29681976,-852630,-3208171,12403437,30066266,8367329,13243957,8709688 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( 12015105,2801261,28198131,10151021,24818120,-4743133,-11194191,-5645734,5150968,7274186 ), + new FieldElement( 2831366,-12492146,1478975,6122054,23825128,-12733586,31097299,6083058,31021603,-9793610 ), + new FieldElement( -2529932,-2229646,445613,10720828,-13849527,-11505937,-23507731,16354465,15067285,-14147707 ) + ), + new GroupElementPreComp( + new FieldElement( 7840942,14037873,-33364863,15934016,-728213,-3642706,21403988,1057586,-19379462,-12403220 ), + new FieldElement( 915865,-16469274,15608285,-8789130,-24357026,6060030,-17371319,8410997,-7220461,16527025 ), + new FieldElement( 32922597,-556987,20336074,-16184568,10903705,-5384487,16957574,52992,23834301,6588044 ) + ), + new GroupElementPreComp( + new FieldElement( 32752030,11232950,3381995,-8714866,22652988,-10744103,17159699,16689107,-20314580,-1305992 ), + new FieldElement( -4689649,9166776,-25710296,-10847306,11576752,12733943,7924251,-2752281,1976123,-7249027 ), + new FieldElement( 21251222,16309901,-2983015,-6783122,30810597,12967303,156041,-3371252,12331345,-8237197 ) + ), + new GroupElementPreComp( + new FieldElement( 8651614,-4477032,-16085636,-4996994,13002507,2950805,29054427,-5106970,10008136,-4667901 ), + new FieldElement( 31486080,15114593,-14261250,12951354,14369431,-7387845,16347321,-13662089,8684155,-10532952 ), + new FieldElement( 19443825,11385320,24468943,-9659068,-23919258,2187569,-26263207,-6086921,31316348,14219878 ) + ), + new GroupElementPreComp( + new FieldElement( -28594490,1193785,32245219,11392485,31092169,15722801,27146014,6992409,29126555,9207390 ), + new FieldElement( 32382935,1110093,18477781,11028262,-27411763,-7548111,-4980517,10843782,-7957600,-14435730 ), + new FieldElement( 2814918,7836403,27519878,-7868156,-20894015,-11553689,-21494559,8550130,28346258,1994730 ) + ), + new GroupElementPreComp( + new FieldElement( -19578299,8085545,-14000519,-3948622,2785838,-16231307,-19516951,7174894,22628102,8115180 ), + new FieldElement( -30405132,955511,-11133838,-15078069,-32447087,-13278079,-25651578,3317160,-9943017,930272 ), + new FieldElement( -15303681,-6833769,28856490,1357446,23421993,1057177,24091212,-1388970,-22765376,-10650715 ) + ), + new GroupElementPreComp( + new FieldElement( -22751231,-5303997,-12907607,-12768866,-15811511,-7797053,-14839018,-16554220,-1867018,8398970 ), + new FieldElement( -31969310,2106403,-4736360,1362501,12813763,16200670,22981545,-6291273,18009408,-15772772 ), + new FieldElement( -17220923,-9545221,-27784654,14166835,29815394,7444469,29551787,-3727419,19288549,1325865 ) + ), + new GroupElementPreComp( + new FieldElement( 15100157,-15835752,-23923978,-1005098,-26450192,15509408,12376730,-3479146,33166107,-8042750 ), + new FieldElement( 20909231,13023121,-9209752,16251778,-5778415,-8094914,12412151,10018715,2213263,-13878373 ), + new FieldElement( 32529814,-11074689,30361439,-16689753,-9135940,1513226,22922121,6382134,-5766928,8371348 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( 9923462,11271500,12616794,3544722,-29998368,-1721626,12891687,-8193132,-26442943,10486144 ), + new FieldElement( -22597207,-7012665,8587003,-8257861,4084309,-12970062,361726,2610596,-23921530,-11455195 ), + new FieldElement( 5408411,-1136691,-4969122,10561668,24145918,14240566,31319731,-4235541,19985175,-3436086 ) + ), + new GroupElementPreComp( + new FieldElement( -13994457,16616821,14549246,3341099,32155958,13648976,-17577068,8849297,65030,8370684 ), + new FieldElement( -8320926,-12049626,31204563,5839400,-20627288,-1057277,-19442942,6922164,12743482,-9800518 ), + new FieldElement( -2361371,12678785,28815050,4759974,-23893047,4884717,23783145,11038569,18800704,255233 ) + ), + new GroupElementPreComp( + new FieldElement( -5269658,-1773886,13957886,7990715,23132995,728773,13393847,9066957,19258688,-14753793 ), + new FieldElement( -2936654,-10827535,-10432089,14516793,-3640786,4372541,-31934921,2209390,-1524053,2055794 ), + new FieldElement( 580882,16705327,5468415,-2683018,-30926419,-14696000,-7203346,-8994389,-30021019,7394435 ) + ), + new GroupElementPreComp( + new FieldElement( 23838809,1822728,-15738443,15242727,8318092,-3733104,-21672180,-3492205,-4821741,14799921 ), + new FieldElement( 13345610,9759151,3371034,-16137791,16353039,8577942,31129804,13496856,-9056018,7402518 ), + new FieldElement( 2286874,-4435931,-20042458,-2008336,-13696227,5038122,11006906,-15760352,8205061,1607563 ) + ), + new GroupElementPreComp( + new FieldElement( 14414086,-8002132,3331830,-3208217,22249151,-5594188,18364661,-2906958,30019587,-9029278 ), + new FieldElement( -27688051,1585953,-10775053,931069,-29120221,-11002319,-14410829,12029093,9944378,8024 ), + new FieldElement( 4368715,-3709630,29874200,-15022983,-20230386,-11410704,-16114594,-999085,-8142388,5640030 ) + ), + new GroupElementPreComp( + new FieldElement( 10299610,13746483,11661824,16234854,7630238,5998374,9809887,-16694564,15219798,-14327783 ), + new FieldElement( 27425505,-5719081,3055006,10660664,23458024,595578,-15398605,-1173195,-18342183,9742717 ), + new FieldElement( 6744077,2427284,26042789,2720740,-847906,1118974,32324614,7406442,12420155,1994844 ) + ), + new GroupElementPreComp( + new FieldElement( 14012521,-5024720,-18384453,-9578469,-26485342,-3936439,-13033478,-10909803,24319929,-6446333 ), + new FieldElement( 16412690,-4507367,10772641,15929391,-17068788,-4658621,10555945,-10484049,-30102368,-4739048 ), + new FieldElement( 22397382,-7767684,-9293161,-12792868,17166287,-9755136,-27333065,6199366,21880021,-12250760 ) + ), + new GroupElementPreComp( + new FieldElement( -4283307,5368523,-31117018,8163389,-30323063,3209128,16557151,8890729,8840445,4957760 ), + new FieldElement( -15447727,709327,-6919446,-10870178,-29777922,6522332,-21720181,12130072,-14796503,5005757 ), + new FieldElement( -2114751,-14308128,23019042,15765735,-25269683,6002752,10183197,-13239326,-16395286,-2176112 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( -19025756,1632005,13466291,-7995100,-23640451,16573537,-32013908,-3057104,22208662,2000468 ), + new FieldElement( 3065073,-1412761,-25598674,-361432,-17683065,-5703415,-8164212,11248527,-3691214,-7414184 ), + new FieldElement( 10379208,-6045554,8877319,1473647,-29291284,-12507580,16690915,2553332,-3132688,16400289 ) + ), + new GroupElementPreComp( + new FieldElement( 15716668,1254266,-18472690,7446274,-8448918,6344164,-22097271,-7285580,26894937,9132066 ), + new FieldElement( 24158887,12938817,11085297,-8177598,-28063478,-4457083,-30576463,64452,-6817084,-2692882 ), + new FieldElement( 13488534,7794716,22236231,5989356,25426474,-12578208,2350710,-3418511,-4688006,2364226 ) + ), + new GroupElementPreComp( + new FieldElement( 16335052,9132434,25640582,6678888,1725628,8517937,-11807024,-11697457,15445875,-7798101 ), + new FieldElement( 29004207,-7867081,28661402,-640412,-12794003,-7943086,31863255,-4135540,-278050,-15759279 ), + new FieldElement( -6122061,-14866665,-28614905,14569919,-10857999,-3591829,10343412,-6976290,-29828287,-10815811 ) + ), + new GroupElementPreComp( + new FieldElement( 27081650,3463984,14099042,-4517604,1616303,-6205604,29542636,15372179,17293797,960709 ), + new FieldElement( 20263915,11434237,-5765435,11236810,13505955,-10857102,-16111345,6493122,-19384511,7639714 ), + new FieldElement( -2830798,-14839232,25403038,-8215196,-8317012,-16173699,18006287,-16043750,29994677,-15808121 ) + ), + new GroupElementPreComp( + new FieldElement( 9769828,5202651,-24157398,-13631392,-28051003,-11561624,-24613141,-13860782,-31184575,709464 ), + new FieldElement( 12286395,13076066,-21775189,-1176622,-25003198,4057652,-32018128,-8890874,16102007,13205847 ), + new FieldElement( 13733362,5599946,10557076,3195751,-5557991,8536970,-25540170,8525972,10151379,10394400 ) + ), + new GroupElementPreComp( + new FieldElement( 4024660,-16137551,22436262,12276534,-9099015,-2686099,19698229,11743039,-33302334,8934414 ), + new FieldElement( -15879800,-4525240,-8580747,-2934061,14634845,-698278,-9449077,3137094,-11536886,11721158 ), + new FieldElement( 17555939,-5013938,8268606,2331751,-22738815,9761013,9319229,8835153,-9205489,-1280045 ) + ), + new GroupElementPreComp( + new FieldElement( -461409,-7830014,20614118,16688288,-7514766,-4807119,22300304,505429,6108462,-6183415 ), + new FieldElement( -5070281,12367917,-30663534,3234473,32617080,-8422642,29880583,-13483331,-26898490,-7867459 ), + new FieldElement( -31975283,5726539,26934134,10237677,-3173717,-605053,24199304,3795095,7592688,-14992079 ) + ), + new GroupElementPreComp( + new FieldElement( 21594432,-14964228,17466408,-4077222,32537084,2739898,6407723,12018833,-28256052,4298412 ), + new FieldElement( -20650503,-11961496,-27236275,570498,3767144,-1717540,13891942,-1569194,13717174,10805743 ), + new FieldElement( -14676630,-15644296,15287174,11927123,24177847,-8175568,-796431,14860609,-26938930,-5863836 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( 12962541,5311799,-10060768,11658280,18855286,-7954201,13286263,-12808704,-4381056,9882022 ), + new FieldElement( 18512079,11319350,-20123124,15090309,18818594,5271736,-22727904,3666879,-23967430,-3299429 ), + new FieldElement( -6789020,-3146043,16192429,13241070,15898607,-14206114,-10084880,-6661110,-2403099,5276065 ) + ), + new GroupElementPreComp( + new FieldElement( 30169808,-5317648,26306206,-11750859,27814964,7069267,7152851,3684982,1449224,13082861 ), + new FieldElement( 10342826,3098505,2119311,193222,25702612,12233820,23697382,15056736,-21016438,-8202000 ), + new FieldElement( -33150110,3261608,22745853,7948688,19370557,-15177665,-26171976,6482814,-10300080,-11060101 ) + ), + new GroupElementPreComp( + new FieldElement( 32869458,-5408545,25609743,15678670,-10687769,-15471071,26112421,2521008,-22664288,6904815 ), + new FieldElement( 29506923,4457497,3377935,-9796444,-30510046,12935080,1561737,3841096,-29003639,-6657642 ), + new FieldElement( 10340844,-6630377,-18656632,-2278430,12621151,-13339055,30878497,-11824370,-25584551,5181966 ) + ), + new GroupElementPreComp( + new FieldElement( 25940115,-12658025,17324188,-10307374,-8671468,15029094,24396252,-16450922,-2322852,-12388574 ), + new FieldElement( -21765684,9916823,-1300409,4079498,-1028346,11909559,1782390,12641087,20603771,-6561742 ), + new FieldElement( -18882287,-11673380,24849422,11501709,13161720,-4768874,1925523,11914390,4662781,7820689 ) + ), + new GroupElementPreComp( + new FieldElement( 12241050,-425982,8132691,9393934,32846760,-1599620,29749456,12172924,16136752,15264020 ), + new FieldElement( -10349955,-14680563,-8211979,2330220,-17662549,-14545780,10658213,6671822,19012087,3772772 ), + new FieldElement( 3753511,-3421066,10617074,2028709,14841030,-6721664,28718732,-15762884,20527771,12988982 ) + ), + new GroupElementPreComp( + new FieldElement( -14822485,-5797269,-3707987,12689773,-898983,-10914866,-24183046,-10564943,3299665,-12424953 ), + new FieldElement( -16777703,-15253301,-9642417,4978983,3308785,8755439,6943197,6461331,-25583147,8991218 ), + new FieldElement( -17226263,1816362,-1673288,-6086439,31783888,-8175991,-32948145,7417950,-30242287,1507265 ) + ), + new GroupElementPreComp( + new FieldElement( 29692663,6829891,-10498800,4334896,20945975,-11906496,-28887608,8209391,14606362,-10647073 ), + new FieldElement( -3481570,8707081,32188102,5672294,22096700,1711240,-33020695,9761487,4170404,-2085325 ), + new FieldElement( -11587470,14855945,-4127778,-1531857,-26649089,15084046,22186522,16002000,-14276837,-8400798 ) + ), + new GroupElementPreComp( + new FieldElement( -4811456,13761029,-31703877,-2483919,-3312471,7869047,-7113572,-9620092,13240845,10965870 ), + new FieldElement( -7742563,-8256762,-14768334,-13656260,-23232383,12387166,4498947,14147411,29514390,4302863 ), + new FieldElement( -13413405,-12407859,20757302,-13801832,14785143,8976368,-5061276,-2144373,17846988,-13971927 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( -2244452,-754728,-4597030,-1066309,-6247172,1455299,-21647728,-9214789,-5222701,12650267 ), + new FieldElement( -9906797,-16070310,21134160,12198166,-27064575,708126,387813,13770293,-19134326,10958663 ), + new FieldElement( 22470984,12369526,23446014,-5441109,-21520802,-9698723,-11772496,-11574455,-25083830,4271862 ) + ), + new GroupElementPreComp( + new FieldElement( -25169565,-10053642,-19909332,15361595,-5984358,2159192,75375,-4278529,-32526221,8469673 ), + new FieldElement( 15854970,4148314,-8893890,7259002,11666551,13824734,-30531198,2697372,24154791,-9460943 ), + new FieldElement( 15446137,-15806644,29759747,14019369,30811221,-9610191,-31582008,12840104,24913809,9815020 ) + ), + new GroupElementPreComp( + new FieldElement( -4709286,-5614269,-31841498,-12288893,-14443537,10799414,-9103676,13438769,18735128,9466238 ), + new FieldElement( 11933045,9281483,5081055,-5183824,-2628162,-4905629,-7727821,-10896103,-22728655,16199064 ), + new FieldElement( 14576810,379472,-26786533,-8317236,-29426508,-10812974,-102766,1876699,30801119,2164795 ) + ), + new GroupElementPreComp( + new FieldElement( 15995086,3199873,13672555,13712240,-19378835,-4647646,-13081610,-15496269,-13492807,1268052 ), + new FieldElement( -10290614,-3659039,-3286592,10948818,23037027,3794475,-3470338,-12600221,-17055369,3565904 ), + new FieldElement( 29210088,-9419337,-5919792,-4952785,10834811,-13327726,-16512102,-10820713,-27162222,-14030531 ) + ), + new GroupElementPreComp( + new FieldElement( -13161890,15508588,16663704,-8156150,-28349942,9019123,-29183421,-3769423,2244111,-14001979 ), + new FieldElement( -5152875,-3800936,-9306475,-6071583,16243069,14684434,-25673088,-16180800,13491506,4641841 ), + new FieldElement( 10813417,643330,-19188515,-728916,30292062,-16600078,27548447,-7721242,14476989,-12767431 ) + ), + new GroupElementPreComp( + new FieldElement( 10292079,9984945,6481436,8279905,-7251514,7032743,27282937,-1644259,-27912810,12651324 ), + new FieldElement( -31185513,-813383,22271204,11835308,10201545,15351028,17099662,3988035,21721536,-3148940 ), + new FieldElement( 10202177,-6545839,-31373232,-9574638,-32150642,-8119683,-12906320,3852694,13216206,14842320 ) + ), + new GroupElementPreComp( + new FieldElement( -15815640,-10601066,-6538952,-7258995,-6984659,-6581778,-31500847,13765824,-27434397,9900184 ), + new FieldElement( 14465505,-13833331,-32133984,-14738873,-27443187,12990492,33046193,15796406,-7051866,-8040114 ), + new FieldElement( 30924417,-8279620,6359016,-12816335,16508377,9071735,-25488601,15413635,9524356,-7018878 ) + ), + new GroupElementPreComp( + new FieldElement( 12274201,-13175547,32627641,-1785326,6736625,13267305,5237659,-5109483,15663516,4035784 ), + new FieldElement( -2951309,8903985,17349946,601635,-16432815,-4612556,-13732739,-15889334,-22258478,4659091 ), + new FieldElement( -16916263,-4952973,-30393711,-15158821,20774812,15897498,5736189,15026997,-2178256,-13455585 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( -8858980,-2219056,28571666,-10155518,-474467,-10105698,-3801496,278095,23440562,-290208 ), + new FieldElement( 10226241,-5928702,15139956,120818,-14867693,5218603,32937275,11551483,-16571960,-7442864 ), + new FieldElement( 17932739,-12437276,-24039557,10749060,11316803,7535897,22503767,5561594,-3646624,3898661 ) + ), + new GroupElementPreComp( + new FieldElement( 7749907,-969567,-16339731,-16464,-25018111,15122143,-1573531,7152530,21831162,1245233 ), + new FieldElement( 26958459,-14658026,4314586,8346991,-5677764,11960072,-32589295,-620035,-30402091,-16716212 ), + new FieldElement( -12165896,9166947,33491384,13673479,29787085,13096535,6280834,14587357,-22338025,13987525 ) + ), + new GroupElementPreComp( + new FieldElement( -24349909,7778775,21116000,15572597,-4833266,-5357778,-4300898,-5124639,-7469781,-2858068 ), + new FieldElement( 9681908,-6737123,-31951644,13591838,-6883821,386950,31622781,6439245,-14581012,4091397 ), + new FieldElement( -8426427,1470727,-28109679,-1596990,3978627,-5123623,-19622683,12092163,29077877,-14741988 ) + ), + new GroupElementPreComp( + new FieldElement( 5269168,-6859726,-13230211,-8020715,25932563,1763552,-5606110,-5505881,-20017847,2357889 ), + new FieldElement( 32264008,-15407652,-5387735,-1160093,-2091322,-3946900,23104804,-12869908,5727338,189038 ), + new FieldElement( 14609123,-8954470,-6000566,-16622781,-14577387,-7743898,-26745169,10942115,-25888931,-14884697 ) + ), + new GroupElementPreComp( + new FieldElement( 20513500,5557931,-15604613,7829531,26413943,-2019404,-21378968,7471781,13913677,-5137875 ), + new FieldElement( -25574376,11967826,29233242,12948236,-6754465,4713227,-8940970,14059180,12878652,8511905 ), + new FieldElement( -25656801,3393631,-2955415,-7075526,-2250709,9366908,-30223418,6812974,5568676,-3127656 ) + ), + new GroupElementPreComp( + new FieldElement( 11630004,12144454,2116339,13606037,27378885,15676917,-17408753,-13504373,-14395196,8070818 ), + new FieldElement( 27117696,-10007378,-31282771,-5570088,1127282,12772488,-29845906,10483306,-11552749,-1028714 ), + new FieldElement( 10637467,-5688064,5674781,1072708,-26343588,-6982302,-1683975,9177853,-27493162,15431203 ) + ), + new GroupElementPreComp( + new FieldElement( 20525145,10892566,-12742472,12779443,-29493034,16150075,-28240519,14943142,-15056790,-7935931 ), + new FieldElement( -30024462,5626926,-551567,-9981087,753598,11981191,25244767,-3239766,-3356550,9594024 ), + new FieldElement( -23752644,2636870,-5163910,-10103818,585134,7877383,11345683,-6492290,13352335,-10977084 ) + ), + new GroupElementPreComp( + new FieldElement( -1931799,-5407458,3304649,-12884869,17015806,-4877091,-29783850,-7752482,-13215537,-319204 ), + new FieldElement( 20239939,6607058,6203985,3483793,-18386976,-779229,-20723742,15077870,-22750759,14523817 ), + new FieldElement( 27406042,-6041657,27423596,-4497394,4996214,10002360,-28842031,-4545494,-30172742,-4805667 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( 11374242,12660715,17861383,-12540833,10935568,1099227,-13886076,-9091740,-27727044,11358504 ), + new FieldElement( -12730809,10311867,1510375,10778093,-2119455,-9145702,32676003,11149336,-26123651,4985768 ), + new FieldElement( -19096303,341147,-6197485,-239033,15756973,-8796662,-983043,13794114,-19414307,-15621255 ) + ), + new GroupElementPreComp( + new FieldElement( 6490081,11940286,25495923,-7726360,8668373,-8751316,3367603,6970005,-1691065,-9004790 ), + new FieldElement( 1656497,13457317,15370807,6364910,13605745,8362338,-19174622,-5475723,-16796596,-5031438 ), + new FieldElement( -22273315,-13524424,-64685,-4334223,-18605636,-10921968,-20571065,-7007978,-99853,-10237333 ) + ), + new GroupElementPreComp( + new FieldElement( 17747465,10039260,19368299,-4050591,-20630635,-16041286,31992683,-15857976,-29260363,-5511971 ), + new FieldElement( 31932027,-4986141,-19612382,16366580,22023614,88450,11371999,-3744247,4882242,-10626905 ), + new FieldElement( 29796507,37186,19818052,10115756,-11829032,3352736,18551198,3272828,-5190932,-4162409 ) + ), + new GroupElementPreComp( + new FieldElement( 12501286,4044383,-8612957,-13392385,-32430052,5136599,-19230378,-3529697,330070,-3659409 ), + new FieldElement( 6384877,2899513,17807477,7663917,-2358888,12363165,25366522,-8573892,-271295,12071499 ), + new FieldElement( -8365515,-4042521,25133448,-4517355,-6211027,2265927,-32769618,1936675,-5159697,3829363 ) + ), + new GroupElementPreComp( + new FieldElement( 28425966,-5835433,-577090,-4697198,-14217555,6870930,7921550,-6567787,26333140,14267664 ), + new FieldElement( -11067219,11871231,27385719,-10559544,-4585914,-11189312,10004786,-8709488,-21761224,8930324 ), + new FieldElement( -21197785,-16396035,25654216,-1725397,12282012,11008919,1541940,4757911,-26491501,-16408940 ) + ), + new GroupElementPreComp( + new FieldElement( 13537262,-7759490,-20604840,10961927,-5922820,-13218065,-13156584,6217254,-15943699,13814990 ), + new FieldElement( -17422573,15157790,18705543,29619,24409717,-260476,27361681,9257833,-1956526,-1776914 ), + new FieldElement( -25045300,-10191966,15366585,15166509,-13105086,8423556,-29171540,12361135,-18685978,4578290 ) + ), + new GroupElementPreComp( + new FieldElement( 24579768,3711570,1342322,-11180126,-27005135,14124956,-22544529,14074919,21964432,8235257 ), + new FieldElement( -6528613,-2411497,9442966,-5925588,12025640,-1487420,-2981514,-1669206,13006806,2355433 ), + new FieldElement( -16304899,-13605259,-6632427,-5142349,16974359,-10911083,27202044,1719366,1141648,-12796236 ) + ), + new GroupElementPreComp( + new FieldElement( -12863944,-13219986,-8318266,-11018091,-6810145,-4843894,13475066,-3133972,32674895,13715045 ), + new FieldElement( 11423335,-5468059,32344216,8962751,24989809,9241752,-13265253,16086212,-28740881,-15642093 ), + new FieldElement( -1409668,12530728,-6368726,10847387,19531186,-14132160,-11709148,7791794,-27245943,4383347 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( -28970898,5271447,-1266009,-9736989,-12455236,16732599,-4862407,-4906449,27193557,6245191 ), + new FieldElement( -15193956,5362278,-1783893,2695834,4960227,12840725,23061898,3260492,22510453,8577507 ), + new FieldElement( -12632451,11257346,-32692994,13548177,-721004,10879011,31168030,13952092,-29571492,-3635906 ) + ), + new GroupElementPreComp( + new FieldElement( 3877321,-9572739,32416692,5405324,-11004407,-13656635,3759769,11935320,5611860,8164018 ), + new FieldElement( -16275802,14667797,15906460,12155291,-22111149,-9039718,32003002,-8832289,5773085,-8422109 ), + new FieldElement( -23788118,-8254300,1950875,8937633,18686727,16459170,-905725,12376320,31632953,190926 ) + ), + new GroupElementPreComp( + new FieldElement( -24593607,-16138885,-8423991,13378746,14162407,6901328,-8288749,4508564,-25341555,-3627528 ), + new FieldElement( 8884438,-5884009,6023974,10104341,-6881569,-4941533,18722941,-14786005,-1672488,827625 ), + new FieldElement( -32720583,-16289296,-32503547,7101210,13354605,2659080,-1800575,-14108036,-24878478,1541286 ) + ), + new GroupElementPreComp( + new FieldElement( 2901347,-1117687,3880376,-10059388,-17620940,-3612781,-21802117,-3567481,20456845,-1885033 ), + new FieldElement( 27019610,12299467,-13658288,-1603234,-12861660,-4861471,-19540150,-5016058,29439641,15138866 ), + new FieldElement( 21536104,-6626420,-32447818,-10690208,-22408077,5175814,-5420040,-16361163,7779328,109896 ) + ), + new GroupElementPreComp( + new FieldElement( 30279744,14648750,-8044871,6425558,13639621,-743509,28698390,12180118,23177719,-554075 ), + new FieldElement( 26572847,3405927,-31701700,12890905,-19265668,5335866,-6493768,2378492,4439158,-13279347 ), + new FieldElement( -22716706,3489070,-9225266,-332753,18875722,-1140095,14819434,-12731527,-17717757,-5461437 ) + ), + new GroupElementPreComp( + new FieldElement( -5056483,16566551,15953661,3767752,-10436499,15627060,-820954,2177225,8550082,-15114165 ), + new FieldElement( -18473302,16596775,-381660,15663611,22860960,15585581,-27844109,-3582739,-23260460,-8428588 ), + new FieldElement( -32480551,15707275,-8205912,-5652081,29464558,2713815,-22725137,15860482,-21902570,1494193 ) + ), + new GroupElementPreComp( + new FieldElement( -19562091,-14087393,-25583872,-9299552,13127842,759709,21923482,16529112,8742704,12967017 ), + new FieldElement( -28464899,1553205,32536856,-10473729,-24691605,-406174,-8914625,-2933896,-29903758,15553883 ), + new FieldElement( 21877909,3230008,9881174,10539357,-4797115,2841332,11543572,14513274,19375923,-12647961 ) + ), + new GroupElementPreComp( + new FieldElement( 8832269,-14495485,13253511,5137575,5037871,4078777,24880818,-6222716,2862653,9455043 ), + new FieldElement( 29306751,5123106,20245049,-14149889,9592566,8447059,-2077124,-2990080,15511449,4789663 ), + new FieldElement( -20679756,7004547,8824831,-9434977,-4045704,-3750736,-5754762,108893,23513200,16652362 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( -33256173,4144782,-4476029,-6579123,10770039,-7155542,-6650416,-12936300,-18319198,10212860 ), + new FieldElement( 2756081,8598110,7383731,-6859892,22312759,-1105012,21179801,2600940,-9988298,-12506466 ), + new FieldElement( -24645692,13317462,-30449259,-15653928,21365574,-10869657,11344424,864440,-2499677,-16710063 ) + ), + new GroupElementPreComp( + new FieldElement( -26432803,6148329,-17184412,-14474154,18782929,-275997,-22561534,211300,2719757,4940997 ), + new FieldElement( -1323882,3911313,-6948744,14759765,-30027150,7851207,21690126,8518463,26699843,5276295 ), + new FieldElement( -13149873,-6429067,9396249,365013,24703301,-10488939,1321586,149635,-15452774,7159369 ) + ), + new GroupElementPreComp( + new FieldElement( 9987780,-3404759,17507962,9505530,9731535,-2165514,22356009,8312176,22477218,-8403385 ), + new FieldElement( 18155857,-16504990,19744716,9006923,15154154,-10538976,24256460,-4864995,-22548173,9334109 ), + new FieldElement( 2986088,-4911893,10776628,-3473844,10620590,-7083203,-21413845,14253545,-22587149,536906 ) + ), + new GroupElementPreComp( + new FieldElement( 4377756,8115836,24567078,15495314,11625074,13064599,7390551,10589625,10838060,-15420424 ), + new FieldElement( -19342404,867880,9277171,-3218459,-14431572,-1986443,19295826,-15796950,6378260,699185 ), + new FieldElement( 7895026,4057113,-7081772,-13077756,-17886831,-323126,-716039,15693155,-5045064,-13373962 ) + ), + new GroupElementPreComp( + new FieldElement( -7737563,-5869402,-14566319,-7406919,11385654,13201616,31730678,-10962840,-3918636,-9669325 ), + new FieldElement( 10188286,-15770834,-7336361,13427543,22223443,14896287,30743455,7116568,-21786507,5427593 ), + new FieldElement( 696102,13206899,27047647,-10632082,15285305,-9853179,10798490,-4578720,19236243,12477404 ) + ), + new GroupElementPreComp( + new FieldElement( -11229439,11243796,-17054270,-8040865,-788228,-8167967,-3897669,11180504,-23169516,7733644 ), + new FieldElement( 17800790,-14036179,-27000429,-11766671,23887827,3149671,23466177,-10538171,10322027,15313801 ), + new FieldElement( 26246234,11968874,32263343,-5468728,6830755,-13323031,-15794704,-101982,-24449242,10890804 ) + ), + new GroupElementPreComp( + new FieldElement( -31365647,10271363,-12660625,-6267268,16690207,-13062544,-14982212,16484931,25180797,-5334884 ), + new FieldElement( -586574,10376444,-32586414,-11286356,19801893,10997610,2276632,9482883,316878,13820577 ), + new FieldElement( -9882808,-4510367,-2115506,16457136,-11100081,11674996,30756178,-7515054,30696930,-3712849 ) + ), + new GroupElementPreComp( + new FieldElement( 32988917,-9603412,12499366,7910787,-10617257,-11931514,-7342816,-9985397,-32349517,7392473 ), + new FieldElement( -8855661,15927861,9866406,-3649411,-2396914,-16655781,-30409476,-9134995,25112947,-2926644 ), + new FieldElement( -2504044,-436966,25621774,-5678772,15085042,-5479877,-24884878,-13526194,5537438,-13914319 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( -11225584,2320285,-9584280,10149187,-33444663,5808648,-14876251,-1729667,31234590,6090599 ), + new FieldElement( -9633316,116426,26083934,2897444,-6364437,-2688086,609721,15878753,-6970405,-9034768 ), + new FieldElement( -27757857,247744,-15194774,-9002551,23288161,-10011936,-23869595,6503646,20650474,1804084 ) + ), + new GroupElementPreComp( + new FieldElement( -27589786,15456424,8972517,8469608,15640622,4439847,3121995,-10329713,27842616,-202328 ), + new FieldElement( -15306973,2839644,22530074,10026331,4602058,5048462,28248656,5031932,-11375082,12714369 ), + new FieldElement( 20807691,-7270825,29286141,11421711,-27876523,-13868230,-21227475,1035546,-19733229,12796920 ) + ), + new GroupElementPreComp( + new FieldElement( 12076899,-14301286,-8785001,-11848922,-25012791,16400684,-17591495,-12899438,3480665,-15182815 ), + new FieldElement( -32361549,5457597,28548107,7833186,7303070,-11953545,-24363064,-15921875,-33374054,2771025 ), + new FieldElement( -21389266,421932,26597266,6860826,22486084,-6737172,-17137485,-4210226,-24552282,15673397 ) + ), + new GroupElementPreComp( + new FieldElement( -20184622,2338216,19788685,-9620956,-4001265,-8740893,-20271184,4733254,3727144,-12934448 ), + new FieldElement( 6120119,814863,-11794402,-622716,6812205,-15747771,2019594,7975683,31123697,-10958981 ), + new FieldElement( 30069250,-11435332,30434654,2958439,18399564,-976289,12296869,9204260,-16432438,9648165 ) + ), + new GroupElementPreComp( + new FieldElement( 32705432,-1550977,30705658,7451065,-11805606,9631813,3305266,5248604,-26008332,-11377501 ), + new FieldElement( 17219865,2375039,-31570947,-5575615,-19459679,9219903,294711,15298639,2662509,-16297073 ), + new FieldElement( -1172927,-7558695,-4366770,-4287744,-21346413,-8434326,32087529,-1222777,32247248,-14389861 ) + ), + new GroupElementPreComp( + new FieldElement( 14312628,1221556,17395390,-8700143,-4945741,-8684635,-28197744,-9637817,-16027623,-13378845 ), + new FieldElement( -1428825,-9678990,-9235681,6549687,-7383069,-468664,23046502,9803137,17597934,2346211 ), + new FieldElement( 18510800,15337574,26171504,981392,-22241552,7827556,-23491134,-11323352,3059833,-11782870 ) + ), + new GroupElementPreComp( + new FieldElement( 10141598,6082907,17829293,-1947643,9830092,13613136,-25556636,-5544586,-33502212,3592096 ), + new FieldElement( 33114168,-15889352,-26525686,-13343397,33076705,8716171,1151462,1521897,-982665,-6837803 ), + new FieldElement( -32939165,-4255815,23947181,-324178,-33072974,-12305637,-16637686,3891704,26353178,693168 ) + ), + new GroupElementPreComp( + new FieldElement( 30374239,1595580,-16884039,13186931,4600344,406904,9585294,-400668,31375464,14369965 ), + new FieldElement( -14370654,-7772529,1510301,6434173,-18784789,-6262728,32732230,-13108839,17901441,16011505 ), + new FieldElement( 18171223,-11934626,-12500402,15197122,-11038147,-15230035,-19172240,-16046376,8764035,12309598 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( 5975908,-5243188,-19459362,-9681747,-11541277,14015782,-23665757,1228319,17544096,-10593782 ), + new FieldElement( 5811932,-1715293,3442887,-2269310,-18367348,-8359541,-18044043,-15410127,-5565381,12348900 ), + new FieldElement( -31399660,11407555,25755363,6891399,-3256938,14872274,-24849353,8141295,-10632534,-585479 ) + ), + new GroupElementPreComp( + new FieldElement( -12675304,694026,-5076145,13300344,14015258,-14451394,-9698672,-11329050,30944593,1130208 ), + new FieldElement( 8247766,-6710942,-26562381,-7709309,-14401939,-14648910,4652152,2488540,23550156,-271232 ), + new FieldElement( 17294316,-3788438,7026748,15626851,22990044,113481,2267737,-5908146,-408818,-137719 ) + ), + new GroupElementPreComp( + new FieldElement( 16091085,-16253926,18599252,7340678,2137637,-1221657,-3364161,14550936,3260525,-7166271 ), + new FieldElement( -4910104,-13332887,18550887,10864893,-16459325,-7291596,-23028869,-13204905,-12748722,2701326 ), + new FieldElement( -8574695,16099415,4629974,-16340524,-20786213,-6005432,-10018363,9276971,11329923,1862132 ) + ), + new GroupElementPreComp( + new FieldElement( 14763076,-15903608,-30918270,3689867,3511892,10313526,-21951088,12219231,-9037963,-940300 ), + new FieldElement( 8894987,-3446094,6150753,3013931,301220,15693451,-31981216,-2909717,-15438168,11595570 ), + new FieldElement( 15214962,3537601,-26238722,-14058872,4418657,-15230761,13947276,10730794,-13489462,-4363670 ) + ), + new GroupElementPreComp( + new FieldElement( -2538306,7682793,32759013,263109,-29984731,-7955452,-22332124,-10188635,977108,699994 ), + new FieldElement( -12466472,4195084,-9211532,550904,-15565337,12917920,19118110,-439841,-30534533,-14337913 ), + new FieldElement( 31788461,-14507657,4799989,7372237,8808585,-14747943,9408237,-10051775,12493932,-5409317 ) + ), + new GroupElementPreComp( + new FieldElement( -25680606,5260744,-19235809,-6284470,-3695942,16566087,27218280,2607121,29375955,6024730 ), + new FieldElement( 842132,-2794693,-4763381,-8722815,26332018,-12405641,11831880,6985184,-9940361,2854096 ), + new FieldElement( -4847262,-7969331,2516242,-5847713,9695691,-7221186,16512645,960770,12121869,16648078 ) + ), + new GroupElementPreComp( + new FieldElement( -15218652,14667096,-13336229,2013717,30598287,-464137,-31504922,-7882064,20237806,2838411 ), + new FieldElement( -19288047,4453152,15298546,-16178388,22115043,-15972604,12544294,-13470457,1068881,-12499905 ), + new FieldElement( -9558883,-16518835,33238498,13506958,30505848,-1114596,-8486907,-2630053,12521378,4845654 ) + ), + new GroupElementPreComp( + new FieldElement( -28198521,10744108,-2958380,10199664,7759311,-13088600,3409348,-873400,-6482306,-12885870 ), + new FieldElement( -23561822,6230156,-20382013,10655314,-24040585,-11621172,10477734,-1240216,-3113227,13974498 ), + new FieldElement( 12966261,15550616,-32038948,-1615346,21025980,-629444,5642325,7188737,18895762,12629579 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( 14741879,-14946887,22177208,-11721237,1279741,8058600,11758140,789443,32195181,3895677 ), + new FieldElement( 10758205,15755439,-4509950,9243698,-4879422,6879879,-2204575,-3566119,-8982069,4429647 ), + new FieldElement( -2453894,15725973,-20436342,-10410672,-5803908,-11040220,-7135870,-11642895,18047436,-15281743 ) + ), + new GroupElementPreComp( + new FieldElement( -25173001,-11307165,29759956,11776784,-22262383,-15820455,10993114,-12850837,-17620701,-9408468 ), + new FieldElement( 21987233,700364,-24505048,14972008,-7774265,-5718395,32155026,2581431,-29958985,8773375 ), + new FieldElement( -25568350,454463,-13211935,16126715,25240068,8594567,20656846,12017935,-7874389,-13920155 ) + ), + new GroupElementPreComp( + new FieldElement( 6028182,6263078,-31011806,-11301710,-818919,2461772,-31841174,-5468042,-1721788,-2776725 ), + new FieldElement( -12278994,16624277,987579,-5922598,32908203,1248608,7719845,-4166698,28408820,6816612 ), + new FieldElement( -10358094,-8237829,19549651,-12169222,22082623,16147817,20613181,13982702,-10339570,5067943 ) + ), + new GroupElementPreComp( + new FieldElement( -30505967,-3821767,12074681,13582412,-19877972,2443951,-19719286,12746132,5331210,-10105944 ), + new FieldElement( 30528811,3601899,-1957090,4619785,-27361822,-15436388,24180793,-12570394,27679908,-1648928 ), + new FieldElement( 9402404,-13957065,32834043,10838634,-26580150,-13237195,26653274,-8685565,22611444,-12715406 ) + ), + new GroupElementPreComp( + new FieldElement( 22190590,1118029,22736441,15130463,-30460692,-5991321,19189625,-4648942,4854859,6622139 ), + new FieldElement( -8310738,-2953450,-8262579,-3388049,-10401731,-271929,13424426,-3567227,26404409,13001963 ), + new FieldElement( -31241838,-15415700,-2994250,8939346,11562230,-12840670,-26064365,-11621720,-15405155,11020693 ) + ), + new GroupElementPreComp( + new FieldElement( 1866042,-7949489,-7898649,-10301010,12483315,13477547,3175636,-12424163,28761762,1406734 ), + new FieldElement( -448555,-1777666,13018551,3194501,-9580420,-11161737,24760585,-4347088,25577411,-13378680 ), + new FieldElement( -24290378,4759345,-690653,-1852816,2066747,10693769,-29595790,9884936,-9368926,4745410 ) + ), + new GroupElementPreComp( + new FieldElement( -9141284,6049714,-19531061,-4341411,-31260798,9944276,-15462008,-11311852,10931924,-11931931 ), + new FieldElement( -16561513,14112680,-8012645,4817318,-8040464,-11414606,-22853429,10856641,-20470770,13434654 ), + new FieldElement( 22759489,-10073434,-16766264,-1871422,13637442,-10168091,1765144,-12654326,28445307,-5364710 ) + ), + new GroupElementPreComp( + new FieldElement( 29875063,12493613,2795536,-3786330,1710620,15181182,-10195717,-8788675,9074234,1167180 ), + new FieldElement( -26205683,11014233,-9842651,-2635485,-26908120,7532294,-18716888,-9535498,3843903,9367684 ), + new FieldElement( -10969595,-6403711,9591134,9582310,11349256,108879,16235123,8601684,-139197,4242895 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( 22092954,-13191123,-2042793,-11968512,32186753,-11517388,-6574341,2470660,-27417366,16625501 ), + new FieldElement( -11057722,3042016,13770083,-9257922,584236,-544855,-7770857,2602725,-27351616,14247413 ), + new FieldElement( 6314175,-10264892,-32772502,15957557,-10157730,168750,-8618807,14290061,27108877,-1180880 ) + ), + new GroupElementPreComp( + new FieldElement( -8586597,-7170966,13241782,10960156,-32991015,-13794596,33547976,-11058889,-27148451,981874 ), + new FieldElement( 22833440,9293594,-32649448,-13618667,-9136966,14756819,-22928859,-13970780,-10479804,-16197962 ), + new FieldElement( -7768587,3326786,-28111797,10783824,19178761,14905060,22680049,13906969,-15933690,3797899 ) + ), + new GroupElementPreComp( + new FieldElement( 21721356,-4212746,-12206123,9310182,-3882239,-13653110,23740224,-2709232,20491983,-8042152 ), + new FieldElement( 9209270,-15135055,-13256557,-6167798,-731016,15289673,25947805,15286587,30997318,-6703063 ), + new FieldElement( 7392032,16618386,23946583,-8039892,-13265164,-1533858,-14197445,-2321576,17649998,-250080 ) + ), + new GroupElementPreComp( + new FieldElement( -9301088,-14193827,30609526,-3049543,-25175069,-1283752,-15241566,-9525724,-2233253,7662146 ), + new FieldElement( -17558673,1763594,-33114336,15908610,-30040870,-12174295,7335080,-8472199,-3174674,3440183 ), + new FieldElement( -19889700,-5977008,-24111293,-9688870,10799743,-16571957,40450,-4431835,4862400,1133 ) + ), + new GroupElementPreComp( + new FieldElement( -32856209,-7873957,-5422389,14860950,-16319031,7956142,7258061,311861,-30594991,-7379421 ), + new FieldElement( -3773428,-1565936,28985340,7499440,24445838,9325937,29727763,16527196,18278453,15405622 ), + new FieldElement( -4381906,8508652,-19898366,-3674424,-5984453,15149970,-13313598,843523,-21875062,13626197 ) + ), + new GroupElementPreComp( + new FieldElement( 2281448,-13487055,-10915418,-2609910,1879358,16164207,-10783882,3953792,13340839,15928663 ), + new FieldElement( 31727126,-7179855,-18437503,-8283652,2875793,-16390330,-25269894,-7014826,-23452306,5964753 ), + new FieldElement( 4100420,-5959452,-17179337,6017714,-18705837,12227141,-26684835,11344144,2538215,-7570755 ) + ), + new GroupElementPreComp( + new FieldElement( -9433605,6123113,11159803,-2156608,30016280,14966241,-20474983,1485421,-629256,-15958862 ), + new FieldElement( -26804558,4260919,11851389,9658551,-32017107,16367492,-20205425,-13191288,11659922,-11115118 ), + new FieldElement( 26180396,10015009,-30844224,-8581293,5418197,9480663,2231568,-10170080,33100372,-1306171 ) + ), + new GroupElementPreComp( + new FieldElement( 15121113,-5201871,-10389905,15427821,-27509937,-15992507,21670947,4486675,-5931810,-14466380 ), + new FieldElement( 16166486,-9483733,-11104130,6023908,-31926798,-1364923,2340060,-16254968,-10735770,-10039824 ), + new FieldElement( 28042865,-3557089,-12126526,12259706,-3717498,-6945899,6766453,-8689599,18036436,5803270 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( -817581,6763912,11803561,1585585,10958447,-2671165,23855391,4598332,-6159431,-14117438 ), + new FieldElement( -31031306,-14256194,17332029,-2383520,31312682,-5967183,696309,50292,-20095739,11763584 ), + new FieldElement( -594563,-2514283,-32234153,12643980,12650761,14811489,665117,-12613632,-19773211,-10713562 ) + ), + new GroupElementPreComp( + new FieldElement( 30464590,-11262872,-4127476,-12734478,19835327,-7105613,-24396175,2075773,-17020157,992471 ), + new FieldElement( 18357185,-6994433,7766382,16342475,-29324918,411174,14578841,8080033,-11574335,-10601610 ), + new FieldElement( 19598397,10334610,12555054,2555664,18821899,-10339780,21873263,16014234,26224780,16452269 ) + ), + new GroupElementPreComp( + new FieldElement( -30223925,5145196,5944548,16385966,3976735,2009897,-11377804,-7618186,-20533829,3698650 ), + new FieldElement( 14187449,3448569,-10636236,-10810935,-22663880,-3433596,7268410,-10890444,27394301,12015369 ), + new FieldElement( 19695761,16087646,28032085,12999827,6817792,11427614,20244189,-1312777,-13259127,-3402461 ) + ), + new GroupElementPreComp( + new FieldElement( 30860103,12735208,-1888245,-4699734,-16974906,2256940,-8166013,12298312,-8550524,-10393462 ), + new FieldElement( -5719826,-11245325,-1910649,15569035,26642876,-7587760,-5789354,-15118654,-4976164,12651793 ), + new FieldElement( -2848395,9953421,11531313,-5282879,26895123,-12697089,-13118820,-16517902,9768698,-2533218 ) + ), + new GroupElementPreComp( + new FieldElement( -24719459,1894651,-287698,-4704085,15348719,-8156530,32767513,12765450,4940095,10678226 ), + new FieldElement( 18860224,15980149,-18987240,-1562570,-26233012,-11071856,-7843882,13944024,-24372348,16582019 ), + new FieldElement( -15504260,4970268,-29893044,4175593,-20993212,-2199756,-11704054,15444560,-11003761,7989037 ) + ), + new GroupElementPreComp( + new FieldElement( 31490452,5568061,-2412803,2182383,-32336847,4531686,-32078269,6200206,-19686113,-14800171 ), + new FieldElement( -17308668,-15879940,-31522777,-2831,-32887382,16375549,8680158,-16371713,28550068,-6857132 ), + new FieldElement( -28126887,-5688091,16837845,-1820458,-6850681,12700016,-30039981,4364038,1155602,5988841 ) + ), + new GroupElementPreComp( + new FieldElement( 21890435,-13272907,-12624011,12154349,-7831873,15300496,23148983,-4470481,24618407,8283181 ), + new FieldElement( -33136107,-10512751,9975416,6841041,-31559793,16356536,3070187,-7025928,1466169,10740210 ), + new FieldElement( -1509399,-15488185,-13503385,-10655916,32799044,909394,-13938903,-5779719,-32164649,-15327040 ) + ), + new GroupElementPreComp( + new FieldElement( 3960823,-14267803,-28026090,-15918051,-19404858,13146868,15567327,951507,-3260321,-573935 ), + new FieldElement( 24740841,5052253,-30094131,8961361,25877428,6165135,-24368180,14397372,-7380369,-6144105 ), + new FieldElement( -28888365,3510803,-28103278,-1158478,-11238128,-10631454,-15441463,-14453128,-1625486,-6494814 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( 793299,-9230478,8836302,-6235707,-27360908,-2369593,33152843,-4885251,-9906200,-621852 ), + new FieldElement( 5666233,525582,20782575,-8038419,-24538499,14657740,16099374,1468826,-6171428,-15186581 ), + new FieldElement( -4859255,-3779343,-2917758,-6748019,7778750,11688288,-30404353,-9871238,-1558923,-9863646 ) + ), + new GroupElementPreComp( + new FieldElement( 10896332,-7719704,824275,472601,-19460308,3009587,25248958,14783338,-30581476,-15757844 ), + new FieldElement( 10566929,12612572,-31944212,11118703,-12633376,12362879,21752402,8822496,24003793,14264025 ), + new FieldElement( 27713862,-7355973,-11008240,9227530,27050101,2504721,23886875,-13117525,13958495,-5732453 ) + ), + new GroupElementPreComp( + new FieldElement( -23481610,4867226,-27247128,3900521,29838369,-8212291,-31889399,-10041781,7340521,-15410068 ), + new FieldElement( 4646514,-8011124,-22766023,-11532654,23184553,8566613,31366726,-1381061,-15066784,-10375192 ), + new FieldElement( -17270517,12723032,-16993061,14878794,21619651,-6197576,27584817,3093888,-8843694,3849921 ) + ), + new GroupElementPreComp( + new FieldElement( -9064912,2103172,25561640,-15125738,-5239824,9582958,32477045,-9017955,5002294,-15550259 ), + new FieldElement( -12057553,-11177906,21115585,-13365155,8808712,-12030708,16489530,13378448,-25845716,12741426 ), + new FieldElement( -5946367,10645103,-30911586,15390284,-3286982,-7118677,24306472,15852464,28834118,-7646072 ) + ), + new GroupElementPreComp( + new FieldElement( -17335748,-9107057,-24531279,9434953,-8472084,-583362,-13090771,455841,20461858,5491305 ), + new FieldElement( 13669248,-16095482,-12481974,-10203039,-14569770,-11893198,-24995986,11293807,-28588204,-9421832 ), + new FieldElement( 28497928,6272777,-33022994,14470570,8906179,-1225630,18504674,-14165166,29867745,-8795943 ) + ), + new GroupElementPreComp( + new FieldElement( -16207023,13517196,-27799630,-13697798,24009064,-6373891,-6367600,-13175392,22853429,-4012011 ), + new FieldElement( 24191378,16712145,-13931797,15217831,14542237,1646131,18603514,-11037887,12876623,-2112447 ), + new FieldElement( 17902668,4518229,-411702,-2829247,26878217,5258055,-12860753,608397,16031844,3723494 ) + ), + new GroupElementPreComp( + new FieldElement( -28632773,12763728,-20446446,7577504,33001348,-13017745,17558842,-7872890,23896954,-4314245 ), + new FieldElement( -20005381,-12011952,31520464,605201,2543521,5991821,-2945064,7229064,-9919646,-8826859 ), + new FieldElement( 28816045,298879,-28165016,-15920938,19000928,-1665890,-12680833,-2949325,-18051778,-2082915 ) + ), + new GroupElementPreComp( + new FieldElement( 16000882,-344896,3493092,-11447198,-29504595,-13159789,12577740,16041268,-19715240,7847707 ), + new FieldElement( 10151868,10572098,27312476,7922682,14825339,4723128,-32855931,-6519018,-10020567,3852848 ), + new FieldElement( -11430470,15697596,-21121557,-4420647,5386314,15063598,16514493,-15932110,29330899,-15076224 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( -25499735,-4378794,-15222908,-6901211,16615731,2051784,3303702,15490,-27548796,12314391 ), + new FieldElement( 15683520,-6003043,18109120,-9980648,15337968,-5997823,-16717435,15921866,16103996,-3731215 ), + new FieldElement( -23169824,-10781249,13588192,-1628807,-3798557,-1074929,-19273607,5402699,-29815713,-9841101 ) + ), + new GroupElementPreComp( + new FieldElement( 23190676,2384583,-32714340,3462154,-29903655,-1529132,-11266856,8911517,-25205859,2739713 ), + new FieldElement( 21374101,-3554250,-33524649,9874411,15377179,11831242,-33529904,6134907,4931255,11987849 ), + new FieldElement( -7732,-2978858,-16223486,7277597,105524,-322051,-31480539,13861388,-30076310,10117930 ) + ), + new GroupElementPreComp( + new FieldElement( -29501170,-10744872,-26163768,13051539,-25625564,5089643,-6325503,6704079,12890019,15728940 ), + new FieldElement( -21972360,-11771379,-951059,-4418840,14704840,2695116,903376,-10428139,12885167,8311031 ), + new FieldElement( -17516482,5352194,10384213,-13811658,7506451,13453191,26423267,4384730,1888765,-5435404 ) + ), + new GroupElementPreComp( + new FieldElement( -25817338,-3107312,-13494599,-3182506,30896459,-13921729,-32251644,-12707869,-19464434,-3340243 ), + new FieldElement( -23607977,-2665774,-526091,4651136,5765089,4618330,6092245,14845197,17151279,-9854116 ), + new FieldElement( -24830458,-12733720,-15165978,10367250,-29530908,-265356,22825805,-7087279,-16866484,16176525 ) + ), + new GroupElementPreComp( + new FieldElement( -23583256,6564961,20063689,3798228,-4740178,7359225,2006182,-10363426,-28746253,-10197509 ), + new FieldElement( -10626600,-4486402,-13320562,-5125317,3432136,-6393229,23632037,-1940610,32808310,1099883 ), + new FieldElement( 15030977,5768825,-27451236,-2887299,-6427378,-15361371,-15277896,-6809350,2051441,-15225865 ) + ), + new GroupElementPreComp( + new FieldElement( -3362323,-7239372,7517890,9824992,23555850,295369,5148398,-14154188,-22686354,16633660 ), + new FieldElement( 4577086,-16752288,13249841,-15304328,19958763,-14537274,18559670,-10759549,8402478,-9864273 ), + new FieldElement( -28406330,-1051581,-26790155,-907698,-17212414,-11030789,9453451,-14980072,17983010,9967138 ) + ), + new GroupElementPreComp( + new FieldElement( -25762494,6524722,26585488,9969270,24709298,1220360,-1677990,7806337,17507396,3651560 ), + new FieldElement( -10420457,-4118111,14584639,15971087,-15768321,8861010,26556809,-5574557,-18553322,-11357135 ), + new FieldElement( 2839101,14284142,4029895,3472686,14402957,12689363,-26642121,8459447,-5605463,-7621941 ) + ), + new GroupElementPreComp( + new FieldElement( -4839289,-3535444,9744961,2871048,25113978,3187018,-25110813,-849066,17258084,-7977739 ), + new FieldElement( 18164541,-10595176,-17154882,-1542417,19237078,-9745295,23357533,-15217008,26908270,12150756 ), + new FieldElement( -30264870,-7647865,5112249,-7036672,-1499807,-6974257,43168,-5537701,-32302074,16215819 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( -6898905,9824394,-12304779,-4401089,-31397141,-6276835,32574489,12532905,-7503072,-8675347 ), + new FieldElement( -27343522,-16515468,-27151524,-10722951,946346,16291093,254968,7168080,21676107,-1943028 ), + new FieldElement( 21260961,-8424752,-16831886,-11920822,-23677961,3968121,-3651949,-6215466,-3556191,-7913075 ) + ), + new GroupElementPreComp( + new FieldElement( 16544754,13250366,-16804428,15546242,-4583003,12757258,-2462308,-8680336,-18907032,-9662799 ), + new FieldElement( -2415239,-15577728,18312303,4964443,-15272530,-12653564,26820651,16690659,25459437,-4564609 ), + new FieldElement( -25144690,11425020,28423002,-11020557,-6144921,-15826224,9142795,-2391602,-6432418,-1644817 ) + ), + new GroupElementPreComp( + new FieldElement( -23104652,6253476,16964147,-3768872,-25113972,-12296437,-27457225,-16344658,6335692,7249989 ), + new FieldElement( -30333227,13979675,7503222,-12368314,-11956721,-4621693,-30272269,2682242,25993170,-12478523 ), + new FieldElement( 4364628,5930691,32304656,-10044554,-8054781,15091131,22857016,-10598955,31820368,15075278 ) + ), + new GroupElementPreComp( + new FieldElement( 31879134,-8918693,17258761,90626,-8041836,-4917709,24162788,-9650886,-17970238,12833045 ), + new FieldElement( 19073683,14851414,-24403169,-11860168,7625278,11091125,-19619190,2074449,-9413939,14905377 ), + new FieldElement( 24483667,-11935567,-2518866,-11547418,-1553130,15355506,-25282080,9253129,27628530,-7555480 ) + ), + new GroupElementPreComp( + new FieldElement( 17597607,8340603,19355617,552187,26198470,-3176583,4593324,-9157582,-14110875,15297016 ), + new FieldElement( 510886,14337390,-31785257,16638632,6328095,2713355,-20217417,-11864220,8683221,2921426 ), + new FieldElement( 18606791,11874196,27155355,-5281482,-24031742,6265446,-25178240,-1278924,4674690,13890525 ) + ), + new GroupElementPreComp( + new FieldElement( 13609624,13069022,-27372361,-13055908,24360586,9592974,14977157,9835105,4389687,288396 ), + new FieldElement( 9922506,-519394,13613107,5883594,-18758345,-434263,-12304062,8317628,23388070,16052080 ), + new FieldElement( 12720016,11937594,-31970060,-5028689,26900120,8561328,-20155687,-11632979,-14754271,-10812892 ) + ), + new GroupElementPreComp( + new FieldElement( 15961858,14150409,26716931,-665832,-22794328,13603569,11829573,7467844,-28822128,929275 ), + new FieldElement( 11038231,-11582396,-27310482,-7316562,-10498527,-16307831,-23479533,-9371869,-21393143,2465074 ), + new FieldElement( 20017163,-4323226,27915242,1529148,12396362,15675764,13817261,-9658066,2463391,-4622140 ) + ), + new GroupElementPreComp( + new FieldElement( -16358878,-12663911,-12065183,4996454,-1256422,1073572,9583558,12851107,4003896,12673717 ), + new FieldElement( -1731589,-15155870,-3262930,16143082,19294135,13385325,14741514,-9103726,7903886,2348101 ), + new FieldElement( 24536016,-16515207,12715592,-3862155,1511293,10047386,-3842346,-7129159,-28377538,10048127 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( -12622226,-6204820,30718825,2591312,-10617028,12192840,18873298,-7297090,-32297756,15221632 ), + new FieldElement( -26478122,-11103864,11546244,-1852483,9180880,7656409,-21343950,2095755,29769758,6593415 ), + new FieldElement( -31994208,-2907461,4176912,3264766,12538965,-868111,26312345,-6118678,30958054,8292160 ) + ), + new GroupElementPreComp( + new FieldElement( 31429822,-13959116,29173532,15632448,12174511,-2760094,32808831,3977186,26143136,-3148876 ), + new FieldElement( 22648901,1402143,-22799984,13746059,7936347,365344,-8668633,-1674433,-3758243,-2304625 ), + new FieldElement( -15491917,8012313,-2514730,-12702462,-23965846,-10254029,-1612713,-1535569,-16664475,8194478 ) + ), + new GroupElementPreComp( + new FieldElement( 27338066,-7507420,-7414224,10140405,-19026427,-6589889,27277191,8855376,28572286,3005164 ), + new FieldElement( 26287124,4821776,25476601,-4145903,-3764513,-15788984,-18008582,1182479,-26094821,-13079595 ), + new FieldElement( -7171154,3178080,23970071,6201893,-17195577,-4489192,-21876275,-13982627,32208683,-1198248 ) + ), + new GroupElementPreComp( + new FieldElement( -16657702,2817643,-10286362,14811298,6024667,13349505,-27315504,-10497842,-27672585,-11539858 ), + new FieldElement( 15941029,-9405932,-21367050,8062055,31876073,-238629,-15278393,-1444429,15397331,-4130193 ), + new FieldElement( 8934485,-13485467,-23286397,-13423241,-32446090,14047986,31170398,-1441021,-27505566,15087184 ) + ), + new GroupElementPreComp( + new FieldElement( -18357243,-2156491,24524913,-16677868,15520427,-6360776,-15502406,11461896,16788528,-5868942 ), + new FieldElement( -1947386,16013773,21750665,3714552,-17401782,-16055433,-3770287,-10323320,31322514,-11615635 ), + new FieldElement( 21426655,-5650218,-13648287,-5347537,-28812189,-4920970,-18275391,-14621414,13040862,-12112948 ) + ), + new GroupElementPreComp( + new FieldElement( 11293895,12478086,-27136401,15083750,-29307421,14748872,14555558,-13417103,1613711,4896935 ), + new FieldElement( -25894883,15323294,-8489791,-8057900,25967126,-13425460,2825960,-4897045,-23971776,-11267415 ), + new FieldElement( -15924766,-5229880,-17443532,6410664,3622847,10243618,20615400,12405433,-23753030,-8436416 ) + ), + new GroupElementPreComp( + new FieldElement( -7091295,12556208,-20191352,9025187,-17072479,4333801,4378436,2432030,23097949,-566018 ), + new FieldElement( 4565804,-16025654,20084412,-7842817,1724999,189254,24767264,10103221,-18512313,2424778 ), + new FieldElement( 366633,-11976806,8173090,-6890119,30788634,5745705,-7168678,1344109,-3642553,12412659 ) + ), + new GroupElementPreComp( + new FieldElement( -24001791,7690286,14929416,-168257,-32210835,-13412986,24162697,-15326504,-3141501,11179385 ), + new FieldElement( 18289522,-14724954,8056945,16430056,-21729724,7842514,-6001441,-1486897,-18684645,-11443503 ), + new FieldElement( 476239,6601091,-6152790,-9723375,17503545,-4863900,27672959,13403813,11052904,5219329 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( 20678546,-8375738,-32671898,8849123,-5009758,14574752,31186971,-3973730,9014762,-8579056 ), + new FieldElement( -13644050,-10350239,-15962508,5075808,-1514661,-11534600,-33102500,9160280,8473550,-3256838 ), + new FieldElement( 24900749,14435722,17209120,-15292541,-22592275,9878983,-7689309,-16335821,-24568481,11788948 ) + ), + new GroupElementPreComp( + new FieldElement( -3118155,-11395194,-13802089,14797441,9652448,-6845904,-20037437,10410733,-24568470,-1458691 ), + new FieldElement( -15659161,16736706,-22467150,10215878,-9097177,7563911,11871841,-12505194,-18513325,8464118 ), + new FieldElement( -23400612,8348507,-14585951,-861714,-3950205,-6373419,14325289,8628612,33313881,-8370517 ) + ), + new GroupElementPreComp( + new FieldElement( -20186973,-4967935,22367356,5271547,-1097117,-4788838,-24805667,-10236854,-8940735,-5818269 ), + new FieldElement( -6948785,-1795212,-32625683,-16021179,32635414,-7374245,15989197,-12838188,28358192,-4253904 ), + new FieldElement( -23561781,-2799059,-32351682,-1661963,-9147719,10429267,-16637684,4072016,-5351664,5596589 ) + ), + new GroupElementPreComp( + new FieldElement( -28236598,-3390048,12312896,6213178,3117142,16078565,29266239,2557221,1768301,15373193 ), + new FieldElement( -7243358,-3246960,-4593467,-7553353,-127927,-912245,-1090902,-4504991,-24660491,3442910 ), + new FieldElement( -30210571,5124043,14181784,8197961,18964734,-11939093,22597931,7176455,-18585478,13365930 ) + ), + new GroupElementPreComp( + new FieldElement( -7877390,-1499958,8324673,4690079,6261860,890446,24538107,-8570186,-9689599,-3031667 ), + new FieldElement( 25008904,-10771599,-4305031,-9638010,16265036,15721635,683793,-11823784,15723479,-15163481 ), + new FieldElement( -9660625,12374379,-27006999,-7026148,-7724114,-12314514,11879682,5400171,519526,-1235876 ) + ), + new GroupElementPreComp( + new FieldElement( 22258397,-16332233,-7869817,14613016,-22520255,-2950923,-20353881,7315967,16648397,7605640 ), + new FieldElement( -8081308,-8464597,-8223311,9719710,19259459,-15348212,23994942,-5281555,-9468848,4763278 ), + new FieldElement( -21699244,9220969,-15730624,1084137,-25476107,-2852390,31088447,-7764523,-11356529,728112 ) + ), + new GroupElementPreComp( + new FieldElement( 26047220,-11751471,-6900323,-16521798,24092068,9158119,-4273545,-12555558,-29365436,-5498272 ), + new FieldElement( 17510331,-322857,5854289,8403524,17133918,-3112612,-28111007,12327945,10750447,10014012 ), + new FieldElement( -10312768,3936952,9156313,-8897683,16498692,-994647,-27481051,-666732,3424691,7540221 ) + ), + new GroupElementPreComp( + new FieldElement( 30322361,-6964110,11361005,-4143317,7433304,4989748,-7071422,-16317219,-9244265,15258046 ), + new FieldElement( 13054562,-2779497,19155474,469045,-12482797,4566042,5631406,2711395,1062915,-5136345 ), + new FieldElement( -19240248,-11254599,-29509029,-7499965,-5835763,13005411,-6066489,12194497,32960380,1459310 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( 19852034,7027924,23669353,10020366,8586503,-6657907,394197,-6101885,18638003,-11174937 ), + new FieldElement( 31395534,15098109,26581030,8030562,-16527914,-5007134,9012486,-7584354,-6643087,-5442636 ), + new FieldElement( -9192165,-2347377,-1997099,4529534,25766844,607986,-13222,9677543,-32294889,-6456008 ) + ), + new GroupElementPreComp( + new FieldElement( -2444496,-149937,29348902,8186665,1873760,12489863,-30934579,-7839692,-7852844,-8138429 ), + new FieldElement( -15236356,-15433509,7766470,746860,26346930,-10221762,-27333451,10754588,-9431476,5203576 ), + new FieldElement( 31834314,14135496,-770007,5159118,20917671,-16768096,-7467973,-7337524,31809243,7347066 ) + ), + new GroupElementPreComp( + new FieldElement( -9606723,-11874240,20414459,13033986,13716524,-11691881,19797970,-12211255,15192876,-2087490 ), + new FieldElement( -12663563,-2181719,1168162,-3804809,26747877,-14138091,10609330,12694420,33473243,-13382104 ), + new FieldElement( 33184999,11180355,15832085,-11385430,-1633671,225884,15089336,-11023903,-6135662,14480053 ) + ), + new GroupElementPreComp( + new FieldElement( 31308717,-5619998,31030840,-1897099,15674547,-6582883,5496208,13685227,27595050,8737275 ), + new FieldElement( -20318852,-15150239,10933843,-16178022,8335352,-7546022,-31008351,-12610604,26498114,66511 ), + new FieldElement( 22644454,-8761729,-16671776,4884562,-3105614,-13559366,30540766,-4286747,-13327787,-7515095 ) + ), + new GroupElementPreComp( + new FieldElement( -28017847,9834845,18617207,-2681312,-3401956,-13307506,8205540,13585437,-17127465,15115439 ), + new FieldElement( 23711543,-672915,31206561,-8362711,6164647,-9709987,-33535882,-1426096,8236921,16492939 ), + new FieldElement( -23910559,-13515526,-26299483,-4503841,25005590,-7687270,19574902,10071562,6708380,-6222424 ) + ), + new GroupElementPreComp( + new FieldElement( 2101391,-4930054,19702731,2367575,-15427167,1047675,5301017,9328700,29955601,-11678310 ), + new FieldElement( 3096359,9271816,-21620864,-15521844,-14847996,-7592937,-25892142,-12635595,-9917575,6216608 ), + new FieldElement( -32615849,338663,-25195611,2510422,-29213566,-13820213,24822830,-6146567,-26767480,7525079 ) + ), + new GroupElementPreComp( + new FieldElement( -23066649,-13985623,16133487,-7896178,-3389565,778788,-910336,-2782495,-19386633,11994101 ), + new FieldElement( 21691500,-13624626,-641331,-14367021,3285881,-3483596,-25064666,9718258,-7477437,13381418 ), + new FieldElement( 18445390,-4202236,14979846,11622458,-1727110,-3582980,23111648,-6375247,28535282,15779576 ) + ), + new GroupElementPreComp( + new FieldElement( 30098053,3089662,-9234387,16662135,-21306940,11308411,-14068454,12021730,9955285,-16303356 ), + new FieldElement( 9734894,-14576830,-7473633,-9138735,2060392,11313496,-18426029,9924399,20194861,13380996 ), + new FieldElement( -26378102,-7965207,-22167821,15789297,-18055342,-6168792,-1984914,15707771,26342023,10146099 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( -26016874,-219943,21339191,-41388,19745256,-2878700,-29637280,2227040,21612326,-545728 ), + new FieldElement( -13077387,1184228,23562814,-5970442,-20351244,-6348714,25764461,12243797,-20856566,11649658 ), + new FieldElement( -10031494,11262626,27384172,2271902,26947504,-15997771,39944,6114064,33514190,2333242 ) + ), + new GroupElementPreComp( + new FieldElement( -21433588,-12421821,8119782,7219913,-21830522,-9016134,-6679750,-12670638,24350578,-13450001 ), + new FieldElement( -4116307,-11271533,-23886186,4843615,-30088339,690623,-31536088,-10406836,8317860,12352766 ), + new FieldElement( 18200138,-14475911,-33087759,-2696619,-23702521,-9102511,-23552096,-2287550,20712163,6719373 ) + ), + new GroupElementPreComp( + new FieldElement( 26656208,6075253,-7858556,1886072,-28344043,4262326,11117530,-3763210,26224235,-3297458 ), + new FieldElement( -17168938,-14854097,-3395676,-16369877,-19954045,14050420,21728352,9493610,18620611,-16428628 ), + new FieldElement( -13323321,13325349,11432106,5964811,18609221,6062965,-5269471,-9725556,-30701573,-16479657 ) + ), + new GroupElementPreComp( + new FieldElement( -23860538,-11233159,26961357,1640861,-32413112,-16737940,12248509,-5240639,13735342,1934062 ), + new FieldElement( 25089769,6742589,17081145,-13406266,21909293,-16067981,-15136294,-3765346,-21277997,5473616 ), + new FieldElement( 31883677,-7961101,1083432,-11572403,22828471,13290673,-7125085,12469656,29111212,-5451014 ) + ), + new GroupElementPreComp( + new FieldElement( 24244947,-15050407,-26262976,2791540,-14997599,16666678,24367466,6388839,-10295587,452383 ), + new FieldElement( -25640782,-3417841,5217916,16224624,19987036,-4082269,-24236251,-5915248,15766062,8407814 ), + new FieldElement( -20406999,13990231,15495425,16395525,5377168,15166495,-8917023,-4388953,-8067909,2276718 ) + ), + new GroupElementPreComp( + new FieldElement( 30157918,12924066,-17712050,9245753,19895028,3368142,-23827587,5096219,22740376,-7303417 ), + new FieldElement( 2041139,-14256350,7783687,13876377,-25946985,-13352459,24051124,13742383,-15637599,13295222 ), + new FieldElement( 33338237,-8505733,12532113,7977527,9106186,-1715251,-17720195,-4612972,-4451357,-14669444 ) + ), + new GroupElementPreComp( + new FieldElement( -20045281,5454097,-14346548,6447146,28862071,1883651,-2469266,-4141880,7770569,9620597 ), + new FieldElement( 23208068,7979712,33071466,8149229,1758231,-10834995,30945528,-1694323,-33502340,-14767970 ), + new FieldElement( 1439958,-16270480,-1079989,-793782,4625402,10647766,-5043801,1220118,30494170,-11440799 ) + ), + new GroupElementPreComp( + new FieldElement( -5037580,-13028295,-2970559,-3061767,15640974,-6701666,-26739026,926050,-1684339,-13333647 ), + new FieldElement( 13908495,-3549272,30919928,-6273825,-21521863,7989039,9021034,9078865,3353509,4033511 ), + new FieldElement( -29663431,-15113610,32259991,-344482,24295849,-12912123,23161163,8839127,27485041,7356032 ) + ), + }, + new[]{ + new GroupElementPreComp( + new FieldElement( 9661027,705443,11980065,-5370154,-1628543,14661173,-6346142,2625015,28431036,-16771834 ), + new FieldElement( -23839233,-8311415,-25945511,7480958,-17681669,-8354183,-22545972,14150565,15970762,4099461 ), + new FieldElement( 29262576,16756590,26350592,-8793563,8529671,-11208050,13617293,-9937143,11465739,8317062 ) + ), + new GroupElementPreComp( + new FieldElement( -25493081,-6962928,32500200,-9419051,-23038724,-2302222,14898637,3848455,20969334,-5157516 ), + new FieldElement( -20384450,-14347713,-18336405,13884722,-33039454,2842114,-21610826,-3649888,11177095,14989547 ), + new FieldElement( -24496721,-11716016,16959896,2278463,12066309,10137771,13515641,2581286,-28487508,9930240 ) + ), + new GroupElementPreComp( + new FieldElement( -17751622,-2097826,16544300,-13009300,-15914807,-14949081,18345767,-13403753,16291481,-5314038 ), + new FieldElement( -33229194,2553288,32678213,9875984,8534129,6889387,-9676774,6957617,4368891,9788741 ), + new FieldElement( 16660756,7281060,-10830758,12911820,20108584,-8101676,-21722536,-8613148,16250552,-11111103 ) + ), + new GroupElementPreComp( + new FieldElement( -19765507,2390526,-16551031,14161980,1905286,6414907,4689584,10604807,-30190403,4782747 ), + new FieldElement( -1354539,14736941,-7367442,-13292886,7710542,-14155590,-9981571,4383045,22546403,437323 ), + new FieldElement( 31665577,-12180464,-16186830,1491339,-18368625,3294682,27343084,2786261,-30633590,-14097016 ) + ), + new GroupElementPreComp( + new FieldElement( -14467279,-683715,-33374107,7448552,19294360,14334329,-19690631,2355319,-19284671,-6114373 ), + new FieldElement( 15121312,-15796162,6377020,-6031361,-10798111,-12957845,18952177,15496498,-29380133,11754228 ), + new FieldElement( -2637277,-13483075,8488727,-14303896,12728761,-1622493,7141596,11724556,22761615,-10134141 ) + ), + new GroupElementPreComp( + new FieldElement( 16918416,11729663,-18083579,3022987,-31015732,-13339659,-28741185,-12227393,32851222,11717399 ), + new FieldElement( 11166634,7338049,-6722523,4531520,-29468672,-7302055,31474879,3483633,-1193175,-4030831 ), + new FieldElement( -185635,9921305,31456609,-13536438,-12013818,13348923,33142652,6546660,-19985279,-3948376 ) + ), + new GroupElementPreComp( + new FieldElement( -32460596,11266712,-11197107,-7899103,31703694,3855903,-8537131,-12833048,-30772034,-15486313 ), + new FieldElement( -18006477,12709068,3991746,-6479188,-21491523,-10550425,-31135347,-16049879,10928917,3011958 ), + new FieldElement( -6957757,-15594337,31696059,334240,29576716,14796075,-30831056,-12805180,18008031,10258577 ) + ), + new GroupElementPreComp( + new FieldElement( -22448644,15655569,7018479,-4410003,-30314266,-1201591,-1853465,1367120,25127874,6671743 ), + new FieldElement( 29701166,-14373934,-10878120,9279288,-17568,13127210,21382910,11042292,25838796,4642684 ), + new FieldElement( -20430234,14955537,-24126347,8124619,-5369288,-5990470,30468147,-13900640,18423289,4177476 ) + ) + } + }; + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/base2.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/base2.cs new file mode 100644 index 000000000..c86de62a1 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/base2.cs @@ -0,0 +1,50 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class LookupTables + { + internal static readonly GroupElementPreComp[] Base2 = new GroupElementPreComp[]{ + new GroupElementPreComp( + new FieldElement( 25967493,-14356035,29566456,3660896,-12694345,4014787,27544626,-11754271,-6079156,2047605 ), + new FieldElement( -12545711,934262,-2722910,3049990,-727428,9406986,12720692,5043384,19500929,-15469378 ), + new FieldElement( -8738181,4489570,9688441,-14785194,10184609,-12363380,29287919,11864899,-24514362,-4438546 ) + ), + new GroupElementPreComp( + new FieldElement( 15636291,-9688557,24204773,-7912398,616977,-16685262,27787600,-14772189,28944400,-1550024 ), + new FieldElement( 16568933,4717097,-11556148,-1102322,15682896,-11807043,16354577,-11775962,7689662,11199574 ), + new FieldElement( 30464156,-5976125,-11779434,-15670865,23220365,15915852,7512774,10017326,-17749093,-9920357 ) + ), + new GroupElementPreComp( + new FieldElement( 10861363,11473154,27284546,1981175,-30064349,12577861,32867885,14515107,-15438304,10819380 ), + new FieldElement( 4708026,6336745,20377586,9066809,-11272109,6594696,-25653668,12483688,-12668491,5581306 ), + new FieldElement( 19563160,16186464,-29386857,4097519,10237984,-4348115,28542350,13850243,-23678021,-15815942 ) + ), + new GroupElementPreComp( + new FieldElement( 5153746,9909285,1723747,-2777874,30523605,5516873,19480852,5230134,-23952439,-15175766 ), + new FieldElement( -30269007,-3463509,7665486,10083793,28475525,1649722,20654025,16520125,30598449,7715701 ), + new FieldElement( 28881845,14381568,9657904,3680757,-20181635,7843316,-31400660,1370708,29794553,-1409300 ) + ), + new GroupElementPreComp( + new FieldElement( -22518993,-6692182,14201702,-8745502,-23510406,8844726,18474211,-1361450,-13062696,13821877 ), + new FieldElement( -6455177,-7839871,3374702,-4740862,-27098617,-10571707,31655028,-7212327,18853322,-14220951 ), + new FieldElement( 4566830,-12963868,-28974889,-12240689,-7602672,-2830569,-8514358,-10431137,2207753,-3209784 ) + ), + new GroupElementPreComp( + new FieldElement( -25154831,-4185821,29681144,7868801,-6854661,-9423865,-12437364,-663000,-31111463,-16132436 ), + new FieldElement( 25576264,-2703214,7349804,-11814844,16472782,9300885,3844789,15725684,171356,6466918 ), + new FieldElement( 23103977,13316479,9739013,-16149481,817875,-15038942,8965339,-14088058,-30714912,16193877 ) + ), + new GroupElementPreComp( + new FieldElement( -33521811,3180713,-2394130,14003687,-16903474,-16270840,17238398,4729455,-18074513,9256800 ), + new FieldElement( -25182317,-4174131,32336398,5036987,-21236817,11360617,22616405,9761698,-19827198,630305 ), + new FieldElement( -13720693,2639453,-24237460,-7406481,9494427,-5774029,-6554551,-15960994,-2449256,-14291300 ) + ), + new GroupElementPreComp( + new FieldElement( -3151181,-5046075,9282714,6866145,-31907062,-863023,-18940575,15033784,25105118,-7894876 ), + new FieldElement( -24326370,15950226,-31801215,-14592823,-11662737,-5090925,1573892,-2625887,2198790,-15804619 ), + new FieldElement( -3099351,10324967,-2241613,7453183,-5446979,-2735503,-13812022,-16236442,-32461234,-12290683 ) + ) + }; + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/d.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/d.cs new file mode 100644 index 000000000..b5a957307 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/d.cs @@ -0,0 +1,9 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class LookupTables + { + internal static FieldElement d = new FieldElement(-10913610, 13857413, -15372611, 6949391, 114729, -8787816, -6275908, -3247719, -18696448, -12055116); + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/d2.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/d2.cs new file mode 100644 index 000000000..5c6bb61e9 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/d2.cs @@ -0,0 +1,9 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class LookupTables + { + internal static FieldElement d2 = new FieldElement(-21827239, -5839606, -30745221, 13898782, 229458, 15978800, -12551817, -6495438, 29715968, 9444199); + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_0.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_0.cs new file mode 100644 index 000000000..632c1b942 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_0.cs @@ -0,0 +1,12 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class FieldOperations + { + public static void fe_0(out FieldElement h) + { + h = default(FieldElement); + } + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_1.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_1.cs new file mode 100644 index 000000000..dfed794b5 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_1.cs @@ -0,0 +1,13 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class FieldOperations + { + public static void fe_1(out FieldElement h) + { + h = default(FieldElement); + h.x0 = 1; + } + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_add.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_add.cs new file mode 100644 index 000000000..7eb6b9ff1 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_add.cs @@ -0,0 +1,64 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class FieldOperations + { + /* + h = f + g + Can overlap h with f or g. + + Preconditions: + |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. + |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. + + Postconditions: + |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. + */ + //void fe_add(fe h,const fe f,const fe g) + internal static void fe_add(out FieldElement h, ref FieldElement f, ref FieldElement g) + { + int f0 = f.x0; + int f1 = f.x1; + int f2 = f.x2; + int f3 = f.x3; + int f4 = f.x4; + int f5 = f.x5; + int f6 = f.x6; + int f7 = f.x7; + int f8 = f.x8; + int f9 = f.x9; + int g0 = g.x0; + int g1 = g.x1; + int g2 = g.x2; + int g3 = g.x3; + int g4 = g.x4; + int g5 = g.x5; + int g6 = g.x6; + int g7 = g.x7; + int g8 = g.x8; + int g9 = g.x9; + int h0 = f0 + g0; + int h1 = f1 + g1; + int h2 = f2 + g2; + int h3 = f3 + g3; + int h4 = f4 + g4; + int h5 = f5 + g5; + int h6 = f6 + g6; + int h7 = f7 + g7; + int h8 = f8 + g8; + int h9 = f9 + g9; + + h.x0 = h0; + h.x1 = h1; + h.x2 = h2; + h.x3 = h3; + h.x4 = h4; + h.x5 = h5; + h.x6 = h6; + h.x7 = h7; + h.x8 = h8; + h.x9 = h9; + } + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_cmov.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_cmov.cs new file mode 100644 index 000000000..765650694 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_cmov.cs @@ -0,0 +1,71 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class FieldOperations + { + /* + Replace (f,g) with (g,g) if b == 1; + replace (f,g) with (f,g) if b == 0. + + Preconditions: b in {0,1}. + */ + + //void fe_cmov(fe f,const fe g,unsigned int b) + internal static void fe_cmov(ref FieldElement f, ref FieldElement g, int b) + { + int f0 = f.x0; + int f1 = f.x1; + int f2 = f.x2; + int f3 = f.x3; + int f4 = f.x4; + int f5 = f.x5; + int f6 = f.x6; + int f7 = f.x7; + int f8 = f.x8; + int f9 = f.x9; + int g0 = g.x0; + int g1 = g.x1; + int g2 = g.x2; + int g3 = g.x3; + int g4 = g.x4; + int g5 = g.x5; + int g6 = g.x6; + int g7 = g.x7; + int g8 = g.x8; + int g9 = g.x9; + int x0 = f0 ^ g0; + int x1 = f1 ^ g1; + int x2 = f2 ^ g2; + int x3 = f3 ^ g3; + int x4 = f4 ^ g4; + int x5 = f5 ^ g5; + int x6 = f6 ^ g6; + int x7 = f7 ^ g7; + int x8 = f8 ^ g8; + int x9 = f9 ^ g9; + + b = -b; + x0 &= b; + x1 &= b; + x2 &= b; + x3 &= b; + x4 &= b; + x5 &= b; + x6 &= b; + x7 &= b; + x8 &= b; + x9 &= b; + f.x0 = f0 ^ x0; + f.x1 = f1 ^ x1; + f.x2 = f2 ^ x2; + f.x3 = f3 ^ x3; + f.x4 = f4 ^ x4; + f.x5 = f5 ^ x5; + f.x6 = f6 ^ x6; + f.x7 = f7 ^ x7; + f.x8 = f8 ^ x8; + f.x9 = f9 ^ x9; + } + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_cswap.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_cswap.cs new file mode 100644 index 000000000..50815dbfa --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_cswap.cs @@ -0,0 +1,79 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class FieldOperations + { + /* + Replace (f,g) with (g,f) if b == 1; + replace (f,g) with (f,g) if b == 0. + + Preconditions: b in {0,1}. + */ + public static void fe_cswap(ref FieldElement f, ref FieldElement g, uint b) + { + int f0 = f.x0; + int f1 = f.x1; + int f2 = f.x2; + int f3 = f.x3; + int f4 = f.x4; + int f5 = f.x5; + int f6 = f.x6; + int f7 = f.x7; + int f8 = f.x8; + int f9 = f.x9; + int g0 = g.x0; + int g1 = g.x1; + int g2 = g.x2; + int g3 = g.x3; + int g4 = g.x4; + int g5 = g.x5; + int g6 = g.x6; + int g7 = g.x7; + int g8 = g.x8; + int g9 = g.x9; + int x0 = f0 ^ g0; + int x1 = f1 ^ g1; + int x2 = f2 ^ g2; + int x3 = f3 ^ g3; + int x4 = f4 ^ g4; + int x5 = f5 ^ g5; + int x6 = f6 ^ g6; + int x7 = f7 ^ g7; + int x8 = f8 ^ g8; + int x9 = f9 ^ g9; + + int negb = unchecked((int)-b); + x0 &= negb; + x1 &= negb; + x2 &= negb; + x3 &= negb; + x4 &= negb; + x5 &= negb; + x6 &= negb; + x7 &= negb; + x8 &= negb; + x9 &= negb; + f.x0 = f0 ^ x0; + f.x1 = f1 ^ x1; + f.x2 = f2 ^ x2; + f.x3 = f3 ^ x3; + f.x4 = f4 ^ x4; + f.x5 = f5 ^ x5; + f.x6 = f6 ^ x6; + f.x7 = f7 ^ x7; + f.x8 = f8 ^ x8; + f.x9 = f9 ^ x9; + g.x0 = g0 ^ x0; + g.x1 = g1 ^ x1; + g.x2 = g2 ^ x2; + g.x3 = g3 ^ x3; + g.x4 = g4 ^ x4; + g.x5 = g5 ^ x5; + g.x6 = g6 ^ x6; + g.x7 = g7 ^ x7; + g.x8 = g8 ^ x8; + g.x9 = g9 ^ x9; + } + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_frombytes.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_frombytes.cs new file mode 100644 index 000000000..3689ff952 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_frombytes.cs @@ -0,0 +1,102 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class FieldOperations + { + private static long load_3(byte[] data, int offset) + { + uint result; + result = data[offset + 0]; + result |= (uint)data[offset + 1] << 8; + result |= (uint)data[offset + 2] << 16; + return (long)(ulong)result; + } + + private static long load_4(byte[] data, int offset) + { + uint result; + result = data[offset + 0]; + result |= (uint)data[offset + 1] << 8; + result |= (uint)data[offset + 2] << 16; + result |= (uint)data[offset + 3] << 24; + return (long)(ulong)result; + } + + // Ignores top bit of h. + internal static void fe_frombytes(out FieldElement h, byte[] data, int offset) + { + var h0 = load_4(data, offset); + var h1 = load_3(data, offset + 4) << 6; + var h2 = load_3(data, offset + 7) << 5; + var h3 = load_3(data, offset + 10) << 3; + var h4 = load_3(data, offset + 13) << 2; + var h5 = load_4(data, offset + 16); + var h6 = load_3(data, offset + 20) << 7; + var h7 = load_3(data, offset + 23) << 5; + var h8 = load_3(data, offset + 26) << 4; + var h9 = (load_3(data, offset + 29) & 8388607) << 2; + + var carry9 = (h9 + (1 << 24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25; + var carry1 = (h1 + (1 << 24)) >> 25; h2 += carry1; h1 -= carry1 << 25; + var carry3 = (h3 + (1 << 24)) >> 25; h4 += carry3; h3 -= carry3 << 25; + var carry5 = (h5 + (1 << 24)) >> 25; h6 += carry5; h5 -= carry5 << 25; + var carry7 = (h7 + (1 << 24)) >> 25; h8 += carry7; h7 -= carry7 << 25; + + var carry0 = (h0 + (1 << 25)) >> 26; h1 += carry0; h0 -= carry0 << 26; + var carry2 = (h2 + (1 << 25)) >> 26; h3 += carry2; h2 -= carry2 << 26; + var carry4 = (h4 + (1 << 25)) >> 26; h5 += carry4; h4 -= carry4 << 26; + var carry6 = (h6 + (1 << 25)) >> 26; h7 += carry6; h6 -= carry6 << 26; + var carry8 = (h8 + (1 << 25)) >> 26; h9 += carry8; h8 -= carry8 << 26; + + h.x0 = (int)h0; + h.x1 = (int)h1; + h.x2 = (int)h2; + h.x3 = (int)h3; + h.x4 = (int)h4; + h.x5 = (int)h5; + h.x6 = (int)h6; + h.x7 = (int)h7; + h.x8 = (int)h8; + h.x9 = (int)h9; + } + + // does NOT ignore top bit + internal static void fe_frombytes2(out FieldElement h, byte[] data, int offset) + { + var h0 = load_4(data, offset); + var h1 = load_3(data, offset + 4) << 6; + var h2 = load_3(data, offset + 7) << 5; + var h3 = load_3(data, offset + 10) << 3; + var h4 = load_3(data, offset + 13) << 2; + var h5 = load_4(data, offset + 16); + var h6 = load_3(data, offset + 20) << 7; + var h7 = load_3(data, offset + 23) << 5; + var h8 = load_3(data, offset + 26) << 4; + var h9 = load_3(data, offset + 29) << 2; + + var carry9 = (h9 + (1 << 24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25; + var carry1 = (h1 + (1 << 24)) >> 25; h2 += carry1; h1 -= carry1 << 25; + var carry3 = (h3 + (1 << 24)) >> 25; h4 += carry3; h3 -= carry3 << 25; + var carry5 = (h5 + (1 << 24)) >> 25; h6 += carry5; h5 -= carry5 << 25; + var carry7 = (h7 + (1 << 24)) >> 25; h8 += carry7; h7 -= carry7 << 25; + + var carry0 = (h0 + (1 << 25)) >> 26; h1 += carry0; h0 -= carry0 << 26; + var carry2 = (h2 + (1 << 25)) >> 26; h3 += carry2; h2 -= carry2 << 26; + var carry4 = (h4 + (1 << 25)) >> 26; h5 += carry4; h4 -= carry4 << 26; + var carry6 = (h6 + (1 << 25)) >> 26; h7 += carry6; h6 -= carry6 << 26; + var carry8 = (h8 + (1 << 25)) >> 26; h9 += carry8; h8 -= carry8 << 26; + + h.x0 = (int)h0; + h.x1 = (int)h1; + h.x2 = (int)h2; + h.x3 = (int)h3; + h.x4 = (int)h4; + h.x5 = (int)h5; + h.x6 = (int)h6; + h.x7 = (int)h7; + h.x8 = (int)h8; + h.x9 = (int)h9; + } + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_invert.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_invert.cs new file mode 100644 index 000000000..943133e07 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_invert.cs @@ -0,0 +1,128 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class FieldOperations + { + internal static void fe_invert(out FieldElement result, ref FieldElement z) + { + FieldElement t0, t1, t2, t3; + int i; + + /* qhasm: z2 = z1^2^1 */ + /* asm 1: fe_sq(>z2=fe#1,z2=fe#1,>z2=fe#1); */ + /* asm 2: fe_sq(>z2=t0,z2=t0,>z2=t0); */ + fe_sq(out t0, ref z); //for (i = 1; i < 1; ++i) fe_sq(out t0, ref t0); + + /* qhasm: z8 = z2^2^2 */ + /* asm 1: fe_sq(>z8=fe#2,z8=fe#2,>z8=fe#2); */ + /* asm 2: fe_sq(>z8=t1,z8=t1,>z8=t1); */ + fe_sq(out t1, ref t0); for (i = 1; i < 2; ++i) fe_sq(out t1, ref t1); + + /* qhasm: z9 = z1*z8 */ + /* asm 1: fe_mul(>z9=fe#2,z9=t1,z11=fe#1,z11=t0,z22=fe#3,z22=fe#3,>z22=fe#3); */ + /* asm 2: fe_sq(>z22=t2,z22=t2,>z22=t2); */ + fe_sq(out t2, ref t0); //for (i = 1; i < 1; ++i) fe_sq(out t2, ref t2); + + /* qhasm: z_5_0 = z9*z22 */ + /* asm 1: fe_mul(>z_5_0=fe#2,z_5_0=t1,z_10_5=fe#3,z_10_5=fe#3,>z_10_5=fe#3); */ + /* asm 2: fe_sq(>z_10_5=t2,z_10_5=t2,>z_10_5=t2); */ + fe_sq(out t2, ref t1); for (i = 1; i < 5; ++i) fe_sq(out t2, ref t2); + + /* qhasm: z_10_0 = z_10_5*z_5_0 */ + /* asm 1: fe_mul(>z_10_0=fe#2,z_10_0=t1,z_20_10=fe#3,z_20_10=fe#3,>z_20_10=fe#3); */ + /* asm 2: fe_sq(>z_20_10=t2,z_20_10=t2,>z_20_10=t2); */ + fe_sq(out t2, ref t1); for (i = 1; i < 10; ++i) fe_sq(out t2, ref t2); + + /* qhasm: z_20_0 = z_20_10*z_10_0 */ + /* asm 1: fe_mul(>z_20_0=fe#3,z_20_0=t2,z_40_20=fe#4,z_40_20=fe#4,>z_40_20=fe#4); */ + /* asm 2: fe_sq(>z_40_20=t3,z_40_20=t3,>z_40_20=t3); */ + fe_sq(out t3, ref t2); for (i = 1; i < 20; ++i) fe_sq(out t3, ref t3); + + /* qhasm: z_40_0 = z_40_20*z_20_0 */ + /* asm 1: fe_mul(>z_40_0=fe#3,z_40_0=t2,z_50_10=fe#3,z_50_10=fe#3,>z_50_10=fe#3); */ + /* asm 2: fe_sq(>z_50_10=t2,z_50_10=t2,>z_50_10=t2); */ + fe_sq(out t2, ref t2); for (i = 1; i < 10; ++i) fe_sq(out t2, ref t2); + + /* qhasm: z_50_0 = z_50_10*z_10_0 */ + /* asm 1: fe_mul(>z_50_0=fe#2,z_50_0=t1,z_100_50=fe#3,z_100_50=fe#3,>z_100_50=fe#3); */ + /* asm 2: fe_sq(>z_100_50=t2,z_100_50=t2,>z_100_50=t2); */ + fe_sq(out t2, ref t1); for (i = 1; i < 50; ++i) fe_sq(out t2, ref t2); + + /* qhasm: z_100_0 = z_100_50*z_50_0 */ + /* asm 1: fe_mul(>z_100_0=fe#3,z_100_0=t2,z_200_100=fe#4,z_200_100=fe#4,>z_200_100=fe#4); */ + /* asm 2: fe_sq(>z_200_100=t3,z_200_100=t3,>z_200_100=t3); */ + fe_sq(out t3, ref t2); for (i = 1; i < 100; ++i) fe_sq(out t3, ref t3); + + /* qhasm: z_200_0 = z_200_100*z_100_0 */ + /* asm 1: fe_mul(>z_200_0=fe#3,z_200_0=t2,z_250_50=fe#3,z_250_50=fe#3,>z_250_50=fe#3); */ + /* asm 2: fe_sq(>z_250_50=t2,z_250_50=t2,>z_250_50=t2); */ + fe_sq(out t2, ref t2); for (i = 1; i < 50; ++i) fe_sq(out t2, ref t2); + + /* qhasm: z_250_0 = z_250_50*z_50_0 */ + /* asm 1: fe_mul(>z_250_0=fe#2,z_250_0=t1,z_255_5=fe#2,z_255_5=fe#2,>z_255_5=fe#2); */ + /* asm 2: fe_sq(>z_255_5=t1,z_255_5=t1,>z_255_5=t1); */ + fe_sq(out t1, ref t1); for (i = 1; i < 5; ++i) fe_sq(out t1, ref t1); + + /* qhasm: z_255_21 = z_255_5*z11 */ + /* asm 1: fe_mul(>z_255_21=fe#12,z_255_21=out,> 31) ^ 1); + } + } +} \ No newline at end of file diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_mul.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_mul.cs new file mode 100644 index 000000000..4774cd5d5 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_mul.cs @@ -0,0 +1,263 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class FieldOperations + { + /* + h = f * g + Can overlap h with f or g. + + Preconditions: + |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc. + |g| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc. + + Postconditions: + |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc. + */ + + /* + Notes on implementation strategy: + + Using schoolbook multiplication. + Karatsuba would save a little in some cost models. + + Most multiplications by 2 and 19 are 32-bit precomputations; + cheaper than 64-bit postcomputations. + + There is one remaining multiplication by 19 in the carry chain; + one *19 precomputation can be merged into this, + but the resulting data flow is considerably less clean. + + There are 12 carries below. + 10 of them are 2-way parallelizable and vectorizable. + Can get away with 11 carries, but then data flow is much deeper. + + With tighter constraints on inputs can squeeze carries into int32. + */ + + internal static void fe_mul(out FieldElement h, ref FieldElement f, ref FieldElement g) + { + int f0 = f.x0; + int f1 = f.x1; + int f2 = f.x2; + int f3 = f.x3; + int f4 = f.x4; + int f5 = f.x5; + int f6 = f.x6; + int f7 = f.x7; + int f8 = f.x8; + int f9 = f.x9; + int g0 = g.x0; + int g1 = g.x1; + int g2 = g.x2; + int g3 = g.x3; + int g4 = g.x4; + int g5 = g.x5; + int g6 = g.x6; + int g7 = g.x7; + int g8 = g.x8; + int g9 = g.x9; + + int g1_19 = 19 * g1; /* 1.959375*2^29 */ + int g2_19 = 19 * g2; /* 1.959375*2^30; still ok */ + int g3_19 = 19 * g3; + int g4_19 = 19 * g4; + int g5_19 = 19 * g5; + int g6_19 = 19 * g6; + int g7_19 = 19 * g7; + int g8_19 = 19 * g8; + int g9_19 = 19 * g9; + + int f1_2 = 2 * f1; + int f3_2 = 2 * f3; + int f5_2 = 2 * f5; + int f7_2 = 2 * f7; + int f9_2 = 2 * f9; + + long f0g0 = f0 * (long)g0; + long f0g1 = f0 * (long)g1; + long f0g2 = f0 * (long)g2; + long f0g3 = f0 * (long)g3; + long f0g4 = f0 * (long)g4; + long f0g5 = f0 * (long)g5; + long f0g6 = f0 * (long)g6; + long f0g7 = f0 * (long)g7; + long f0g8 = f0 * (long)g8; + long f0g9 = f0 * (long)g9; + long f1g0 = f1 * (long)g0; + long f1g1_2 = f1_2 * (long)g1; + long f1g2 = f1 * (long)g2; + long f1g3_2 = f1_2 * (long)g3; + long f1g4 = f1 * (long)g4; + long f1g5_2 = f1_2 * (long)g5; + long f1g6 = f1 * (long)g6; + long f1g7_2 = f1_2 * (long)g7; + long f1g8 = f1 * (long)g8; + long f1g9_38 = f1_2 * (long)g9_19; + long f2g0 = f2 * (long)g0; + long f2g1 = f2 * (long)g1; + long f2g2 = f2 * (long)g2; + long f2g3 = f2 * (long)g3; + long f2g4 = f2 * (long)g4; + long f2g5 = f2 * (long)g5; + long f2g6 = f2 * (long)g6; + long f2g7 = f2 * (long)g7; + long f2g8_19 = f2 * (long)g8_19; + long f2g9_19 = f2 * (long)g9_19; + long f3g0 = f3 * (long)g0; + long f3g1_2 = f3_2 * (long)g1; + long f3g2 = f3 * (long)g2; + long f3g3_2 = f3_2 * (long)g3; + long f3g4 = f3 * (long)g4; + long f3g5_2 = f3_2 * (long)g5; + long f3g6 = f3 * (long)g6; + long f3g7_38 = f3_2 * (long)g7_19; + long f3g8_19 = f3 * (long)g8_19; + long f3g9_38 = f3_2 * (long)g9_19; + long f4g0 = f4 * (long)g0; + long f4g1 = f4 * (long)g1; + long f4g2 = f4 * (long)g2; + long f4g3 = f4 * (long)g3; + long f4g4 = f4 * (long)g4; + long f4g5 = f4 * (long)g5; + long f4g6_19 = f4 * (long)g6_19; + long f4g7_19 = f4 * (long)g7_19; + long f4g8_19 = f4 * (long)g8_19; + long f4g9_19 = f4 * (long)g9_19; + long f5g0 = f5 * (long)g0; + long f5g1_2 = f5_2 * (long)g1; + long f5g2 = f5 * (long)g2; + long f5g3_2 = f5_2 * (long)g3; + long f5g4 = f5 * (long)g4; + long f5g5_38 = f5_2 * (long)g5_19; + long f5g6_19 = f5 * (long)g6_19; + long f5g7_38 = f5_2 * (long)g7_19; + long f5g8_19 = f5 * (long)g8_19; + long f5g9_38 = f5_2 * (long)g9_19; + long f6g0 = f6 * (long)g0; + long f6g1 = f6 * (long)g1; + long f6g2 = f6 * (long)g2; + long f6g3 = f6 * (long)g3; + long f6g4_19 = f6 * (long)g4_19; + long f6g5_19 = f6 * (long)g5_19; + long f6g6_19 = f6 * (long)g6_19; + long f6g7_19 = f6 * (long)g7_19; + long f6g8_19 = f6 * (long)g8_19; + long f6g9_19 = f6 * (long)g9_19; + long f7g0 = f7 * (long)g0; + long f7g1_2 = f7_2 * (long)g1; + long f7g2 = f7 * (long)g2; + long f7g3_38 = f7_2 * (long)g3_19; + long f7g4_19 = f7 * (long)g4_19; + long f7g5_38 = f7_2 * (long)g5_19; + long f7g6_19 = f7 * (long)g6_19; + long f7g7_38 = f7_2 * (long)g7_19; + long f7g8_19 = f7 * (long)g8_19; + long f7g9_38 = f7_2 * (long)g9_19; + long f8g0 = f8 * (long)g0; + long f8g1 = f8 * (long)g1; + long f8g2_19 = f8 * (long)g2_19; + long f8g3_19 = f8 * (long)g3_19; + long f8g4_19 = f8 * (long)g4_19; + long f8g5_19 = f8 * (long)g5_19; + long f8g6_19 = f8 * (long)g6_19; + long f8g7_19 = f8 * (long)g7_19; + long f8g8_19 = f8 * (long)g8_19; + long f8g9_19 = f8 * (long)g9_19; + long f9g0 = f9 * (long)g0; + long f9g1_38 = f9_2 * (long)g1_19; + long f9g2_19 = f9 * (long)g2_19; + long f9g3_38 = f9_2 * (long)g3_19; + long f9g4_19 = f9 * (long)g4_19; + long f9g5_38 = f9_2 * (long)g5_19; + long f9g6_19 = f9 * (long)g6_19; + long f9g7_38 = f9_2 * (long)g7_19; + long f9g8_19 = f9 * (long)g8_19; + long f9g9_38 = f9_2 * (long)g9_19; + + long h0 = f0g0 + f1g9_38 + f2g8_19 + f3g7_38 + f4g6_19 + f5g5_38 + f6g4_19 + f7g3_38 + f8g2_19 + f9g1_38; + long h1 = f0g1 + f1g0 + f2g9_19 + f3g8_19 + f4g7_19 + f5g6_19 + f6g5_19 + f7g4_19 + f8g3_19 + f9g2_19; + long h2 = f0g2 + f1g1_2 + f2g0 + f3g9_38 + f4g8_19 + f5g7_38 + f6g6_19 + f7g5_38 + f8g4_19 + f9g3_38; + long h3 = f0g3 + f1g2 + f2g1 + f3g0 + f4g9_19 + f5g8_19 + f6g7_19 + f7g6_19 + f8g5_19 + f9g4_19; + long h4 = f0g4 + f1g3_2 + f2g2 + f3g1_2 + f4g0 + f5g9_38 + f6g8_19 + f7g7_38 + f8g6_19 + f9g5_38; + long h5 = f0g5 + f1g4 + f2g3 + f3g2 + f4g1 + f5g0 + f6g9_19 + f7g8_19 + f8g7_19 + f9g6_19; + long h6 = f0g6 + f1g5_2 + f2g4 + f3g3_2 + f4g2 + f5g1_2 + f6g0 + f7g9_38 + f8g8_19 + f9g7_38; + long h7 = f0g7 + f1g6 + f2g5 + f3g4 + f4g3 + f5g2 + f6g1 + f7g0 + f8g9_19 + f9g8_19; + long h8 = f0g8 + f1g7_2 + f2g6 + f3g5_2 + f4g4 + f5g3_2 + f6g2 + f7g1_2 + f8g0 + f9g9_38; + long h9 = f0g9 + f1g8 + f2g7 + f3g6 + f4g5 + f5g4 + f6g3 + f7g2 + f8g1 + f9g0; + + long carry0; + long carry1; + long carry2; + long carry3; + long carry4; + long carry5; + long carry6; + long carry7; + long carry8; + long carry9; + + /* + |h0| <= (1.65*1.65*2^52*(1+19+19+19+19)+1.65*1.65*2^50*(38+38+38+38+38)) + i.e. |h0| <= 1.4*2^60; narrower ranges for h2, h4, h6, h8 + |h1| <= (1.65*1.65*2^51*(1+1+19+19+19+19+19+19+19+19)) + i.e. |h1| <= 1.7*2^59; narrower ranges for h3, h5, h7, h9 + */ + + carry0 = (h0 + (long)(1 << 25)) >> 26; h1 += carry0; h0 -= carry0 << 26; + carry4 = (h4 + (long)(1 << 25)) >> 26; h5 += carry4; h4 -= carry4 << 26; + /* |h0| <= 2^25 */ + /* |h4| <= 2^25 */ + /* |h1| <= 1.71*2^59 */ + /* |h5| <= 1.71*2^59 */ + + carry1 = (h1 + (long)(1 << 24)) >> 25; h2 += carry1; h1 -= carry1 << 25; + carry5 = (h5 + (long)(1 << 24)) >> 25; h6 += carry5; h5 -= carry5 << 25; + /* |h1| <= 2^24; from now on fits into int32 */ + /* |h5| <= 2^24; from now on fits into int32 */ + /* |h2| <= 1.41*2^60 */ + /* |h6| <= 1.41*2^60 */ + + carry2 = (h2 + (long)(1 << 25)) >> 26; h3 += carry2; h2 -= carry2 << 26; + carry6 = (h6 + (long)(1 << 25)) >> 26; h7 += carry6; h6 -= carry6 << 26; + /* |h2| <= 2^25; from now on fits into int32 unchanged */ + /* |h6| <= 2^25; from now on fits into int32 unchanged */ + /* |h3| <= 1.71*2^59 */ + /* |h7| <= 1.71*2^59 */ + + carry3 = (h3 + (long)(1 << 24)) >> 25; h4 += carry3; h3 -= carry3 << 25; + carry7 = (h7 + (long)(1 << 24)) >> 25; h8 += carry7; h7 -= carry7 << 25; + /* |h3| <= 2^24; from now on fits into int32 unchanged */ + /* |h7| <= 2^24; from now on fits into int32 unchanged */ + /* |h4| <= 1.72*2^34 */ + /* |h8| <= 1.41*2^60 */ + + carry4 = (h4 + (long)(1 << 25)) >> 26; h5 += carry4; h4 -= carry4 << 26; + carry8 = (h8 + (long)(1 << 25)) >> 26; h9 += carry8; h8 -= carry8 << 26; + /* |h4| <= 2^25; from now on fits into int32 unchanged */ + /* |h8| <= 2^25; from now on fits into int32 unchanged */ + /* |h5| <= 1.01*2^24 */ + /* |h9| <= 1.71*2^59 */ + + carry9 = (h9 + (long)(1 << 24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25; + /* |h9| <= 2^24; from now on fits into int32 unchanged */ + /* |h0| <= 1.1*2^39 */ + + carry0 = (h0 + (long)(1 << 25)) >> 26; h1 += carry0; h0 -= carry0 << 26; + /* |h0| <= 2^25; from now on fits into int32 unchanged */ + /* |h1| <= 1.01*2^24 */ + + h.x0 = (int)h0; + h.x1 = (int)h1; + h.x2 = (int)h2; + h.x3 = (int)h3; + h.x4 = (int)h4; + h.x5 = (int)h5; + h.x6 = (int)h6; + h.x7 = (int)h7; + h.x8 = (int)h8; + h.x9 = (int)h9; + } + } +} \ No newline at end of file diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_mul121666.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_mul121666.cs new file mode 100644 index 000000000..2bbd3f688 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_mul121666.cs @@ -0,0 +1,67 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class FieldOperations + { + + /* + h = f * 121666 + Can overlap h with f. + + Preconditions: + |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. + + Postconditions: + |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. + */ + + public static void fe_mul121666(out FieldElement h, ref FieldElement f) + { + int f0 = f.x0; + int f1 = f.x1; + int f2 = f.x2; + int f3 = f.x3; + int f4 = f.x4; + int f5 = f.x5; + int f6 = f.x6; + int f7 = f.x7; + int f8 = f.x8; + int f9 = f.x9; + + var h0 = f0 * 121666L; + var h1 = f1 * 121666L; + var h2 = f2 * 121666L; + var h3 = f3 * 121666L; + var h4 = f4 * 121666L; + var h5 = f5 * 121666L; + var h6 = f6 * 121666L; + var h7 = f7 * 121666L; + var h8 = f8 * 121666L; + var h9 = f9 * 121666L; + + var carry9 = (h9 + (1 << 24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25; + var carry1 = (h1 + (1 << 24)) >> 25; h2 += carry1; h1 -= carry1 << 25; + var carry3 = (h3 + (1 << 24)) >> 25; h4 += carry3; h3 -= carry3 << 25; + var carry5 = (h5 + (1 << 24)) >> 25; h6 += carry5; h5 -= carry5 << 25; + var carry7 = (h7 + (1 << 24)) >> 25; h8 += carry7; h7 -= carry7 << 25; + + var carry0 = (h0 + (1 << 25)) >> 26; h1 += carry0; h0 -= carry0 << 26; + var carry2 = (h2 + (1 << 25)) >> 26; h3 += carry2; h2 -= carry2 << 26; + var carry4 = (h4 + (1 << 25)) >> 26; h5 += carry4; h4 -= carry4 << 26; + var carry6 = (h6 + (1 << 25)) >> 26; h7 += carry6; h6 -= carry6 << 26; + var carry8 = (h8 + (1 << 25)) >> 26; h9 += carry8; h8 -= carry8 << 26; + + h.x0 = (int)h0; + h.x1 = (int)h1; + h.x2 = (int)h2; + h.x3 = (int)h3; + h.x4 = (int)h4; + h.x5 = (int)h5; + h.x6 = (int)h6; + h.x7 = (int)h7; + h.x8 = (int)h8; + h.x9 = (int)h9; + } + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_neg.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_neg.cs new file mode 100644 index 000000000..9b3d18139 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_neg.cs @@ -0,0 +1,51 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class FieldOperations + { + /* + h = -f + + Preconditions: + |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. + + Postconditions: + |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. + */ + internal static void fe_neg(out FieldElement h, ref FieldElement f) + { + int f0 = f.x0; + int f1 = f.x1; + int f2 = f.x2; + int f3 = f.x3; + int f4 = f.x4; + int f5 = f.x5; + int f6 = f.x6; + int f7 = f.x7; + int f8 = f.x8; + int f9 = f.x9; + int h0 = -f0; + int h1 = -f1; + int h2 = -f2; + int h3 = -f3; + int h4 = -f4; + int h5 = -f5; + int h6 = -f6; + int h7 = -f7; + int h8 = -f8; + int h9 = -f9; + + h.x0 = h0; + h.x1 = h1; + h.x2 = h2; + h.x3 = h3; + h.x4 = h4; + h.x5 = h5; + h.x6 = h6; + h.x7 = h7; + h.x8 = h8; + h.x9 = h9; + } + } +} \ No newline at end of file diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_pow22523.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_pow22523.cs new file mode 100644 index 000000000..63bb33b59 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_pow22523.cs @@ -0,0 +1,125 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class FieldOperations + { + internal static void fe_pow22523(out FieldElement result, ref FieldElement z) + { + FieldElement t0, t1, t2; + int i; + + /* qhasm: z2 = z1^2^1 */ + /* asm 1: fe_sq(>z2=fe#1,z2=fe#1,>z2=fe#1); */ + /* asm 2: fe_sq(>z2=t0,z2=t0,>z2=t0); */ + fe_sq(out t0, ref z); //for (i = 1; i < 1; ++i) fe_sq(out t0, ref t0); + + /* qhasm: z8 = z2^2^2 */ + /* asm 1: fe_sq(>z8=fe#2,z8=fe#2,>z8=fe#2); */ + /* asm 2: fe_sq(>z8=t1,z8=t1,>z8=t1); */ + fe_sq(out t1, ref t0); for (i = 1; i < 2; ++i) fe_sq(out t1, ref t1); + + /* qhasm: z9 = z1*z8 */ + /* asm 1: fe_mul(>z9=fe#2,z9=t1,z11=fe#1,z11=t0,z22=fe#1,z22=fe#1,>z22=fe#1); */ + /* asm 2: fe_sq(>z22=t0,z22=t0,>z22=t0); */ + fe_sq(out t0, ref t0); //for (i = 1; i < 1; ++i) fe_sq(out t0, ref t0); + + /* qhasm: z_5_0 = z9*z22 */ + /* asm 1: fe_mul(>z_5_0=fe#1,z_5_0=t0,z_10_5=fe#2,z_10_5=fe#2,>z_10_5=fe#2); */ + /* asm 2: fe_sq(>z_10_5=t1,z_10_5=t1,>z_10_5=t1); */ + fe_sq(out t1, ref t0); for (i = 1; i < 5; ++i) fe_sq(out t1, ref t1); + + /* qhasm: z_10_0 = z_10_5*z_5_0 */ + /* asm 1: fe_mul(>z_10_0=fe#1,z_10_0=t0,z_20_10=fe#2,z_20_10=fe#2,>z_20_10=fe#2); */ + /* asm 2: fe_sq(>z_20_10=t1,z_20_10=t1,>z_20_10=t1); */ + fe_sq(out t1, ref t0); for (i = 1; i < 10; ++i) fe_sq(out t1, ref t1); + + /* qhasm: z_20_0 = z_20_10*z_10_0 */ + /* asm 1: fe_mul(>z_20_0=fe#2,z_20_0=t1,z_40_20=fe#3,z_40_20=fe#3,>z_40_20=fe#3); */ + /* asm 2: fe_sq(>z_40_20=t2,z_40_20=t2,>z_40_20=t2); */ + fe_sq(out t2, ref t1); for (i = 1; i < 20; ++i) fe_sq(out t2, ref t2); + + /* qhasm: z_40_0 = z_40_20*z_20_0 */ + /* asm 1: fe_mul(>z_40_0=fe#2,z_40_0=t1,z_50_10=fe#2,z_50_10=fe#2,>z_50_10=fe#2); */ + /* asm 2: fe_sq(>z_50_10=t1,z_50_10=t1,>z_50_10=t1); */ + fe_sq(out t1, ref t1); for (i = 1; i < 10; ++i) fe_sq(out t1, ref t1); + + /* qhasm: z_50_0 = z_50_10*z_10_0 */ + /* asm 1: fe_mul(>z_50_0=fe#1,z_50_0=t0,z_100_50=fe#2,z_100_50=fe#2,>z_100_50=fe#2); */ + /* asm 2: fe_sq(>z_100_50=t1,z_100_50=t1,>z_100_50=t1); */ + fe_sq(out t1, ref t0); for (i = 1; i < 50; ++i) fe_sq(out t1, ref t1); + + /* qhasm: z_100_0 = z_100_50*z_50_0 */ + /* asm 1: fe_mul(>z_100_0=fe#2,z_100_0=t1,z_200_100=fe#3,z_200_100=fe#3,>z_200_100=fe#3); */ + /* asm 2: fe_sq(>z_200_100=t2,z_200_100=t2,>z_200_100=t2); */ + fe_sq(out t2, ref t1); for (i = 1; i < 100; ++i) fe_sq(out t2, ref t2); + + /* qhasm: z_200_0 = z_200_100*z_100_0 */ + /* asm 1: fe_mul(>z_200_0=fe#2,z_200_0=t1,z_250_50=fe#2,z_250_50=fe#2,>z_250_50=fe#2); */ + /* asm 2: fe_sq(>z_250_50=t1,z_250_50=t1,>z_250_50=t1); */ + fe_sq(out t1, ref t1); for (i = 1; i < 50; ++i) fe_sq(out t1, ref t1); + + /* qhasm: z_250_0 = z_250_50*z_50_0 */ + /* asm 1: fe_mul(>z_250_0=fe#1,z_250_0=t0,z_252_2=fe#1,z_252_2=fe#1,>z_252_2=fe#1); */ + /* asm 2: fe_sq(>z_252_2=t0,z_252_2=t0,>z_252_2=t0); */ + fe_sq(out t0, ref t0); for (i = 1; i < 2; ++i) fe_sq(out t0, ref t0); + + /* qhasm: z_252_3 = z_252_2*z1 */ + /* asm 1: fe_mul(>z_252_3=fe#12,z_252_3=out,> 26; h1 += carry0; h0 -= carry0 << 26; + var carry4 = (h4 + (1 << 25)) >> 26; h5 += carry4; h4 -= carry4 << 26; + var carry1 = (h1 + (1 << 24)) >> 25; h2 += carry1; h1 -= carry1 << 25; + var carry5 = (h5 + (1 << 24)) >> 25; h6 += carry5; h5 -= carry5 << 25; + var carry2 = (h2 + (1 << 25)) >> 26; h3 += carry2; h2 -= carry2 << 26; + var carry6 = (h6 + (1 << 25)) >> 26; h7 += carry6; h6 -= carry6 << 26; + var carry3 = (h3 + (1 << 24)) >> 25; h4 += carry3; h3 -= carry3 << 25; + var carry7 = (h7 + (1 << 24)) >> 25; h8 += carry7; h7 -= carry7 << 25; + + carry4 = (h4 + (1 << 25)) >> 26; h5 += carry4; h4 -= carry4 << 26; + + var carry8 = (h8 + (1 << 25)) >> 26; h9 += carry8; h8 -= carry8 << 26; + var carry9 = (h9 + (1 << 24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25; + + carry0 = (h0 + (1 << 25)) >> 26; h1 += carry0; h0 -= carry0 << 26; + + h.x0 = (int)h0; + h.x1 = (int)h1; + h.x2 = (int)h2; + h.x3 = (int)h3; + h.x4 = (int)h4; + h.x5 = (int)h5; + h.x6 = (int)h6; + h.x7 = (int)h7; + h.x8 = (int)h8; + h.x9 = (int)h9; + } + } +} \ No newline at end of file diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_sq2.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_sq2.cs new file mode 100644 index 000000000..d1c2ee33d --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_sq2.cs @@ -0,0 +1,154 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class FieldOperations + { + /* +h = 2 * f * f +Can overlap h with f. + +Preconditions: + |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc. + +Postconditions: + |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc. +*/ + + /* + See fe_mul.c for discussion of implementation strategy. + */ + internal static void fe_sq2(out FieldElement h, ref FieldElement f) + { + int f0 = f.x0; + int f1 = f.x1; + int f2 = f.x2; + int f3 = f.x3; + int f4 = f.x4; + int f5 = f.x5; + int f6 = f.x6; + int f7 = f.x7; + int f8 = f.x8; + int f9 = f.x9; + + int f0_2 = 2 * f0; + int f1_2 = 2 * f1; + int f2_2 = 2 * f2; + int f3_2 = 2 * f3; + int f4_2 = 2 * f4; + int f5_2 = 2 * f5; + int f6_2 = 2 * f6; + int f7_2 = 2 * f7; + int f5_38 = 38 * f5; /* 1.959375*2^30 */ + int f6_19 = 19 * f6; /* 1.959375*2^30 */ + int f7_38 = 38 * f7; /* 1.959375*2^30 */ + int f8_19 = 19 * f8; /* 1.959375*2^30 */ + int f9_38 = 38 * f9; /* 1.959375*2^30 */ + + var f0f0 = f0 * (long)f0; + var f0f1_2 = f0_2 * (long)f1; + var f0f2_2 = f0_2 * (long)f2; + var f0f3_2 = f0_2 * (long)f3; + var f0f4_2 = f0_2 * (long)f4; + var f0f5_2 = f0_2 * (long)f5; + var f0f6_2 = f0_2 * (long)f6; + var f0f7_2 = f0_2 * (long)f7; + var f0f8_2 = f0_2 * (long)f8; + var f0f9_2 = f0_2 * (long)f9; + var f1f1_2 = f1_2 * (long)f1; + var f1f2_2 = f1_2 * (long)f2; + var f1f3_4 = f1_2 * (long)f3_2; + var f1f4_2 = f1_2 * (long)f4; + var f1f5_4 = f1_2 * (long)f5_2; + var f1f6_2 = f1_2 * (long)f6; + var f1f7_4 = f1_2 * (long)f7_2; + var f1f8_2 = f1_2 * (long)f8; + var f1f9_76 = f1_2 * (long)f9_38; + var f2f2 = f2 * (long)f2; + var f2f3_2 = f2_2 * (long)f3; + var f2f4_2 = f2_2 * (long)f4; + var f2f5_2 = f2_2 * (long)f5; + var f2f6_2 = f2_2 * (long)f6; + var f2f7_2 = f2_2 * (long)f7; + var f2f8_38 = f2_2 * (long)f8_19; + var f2f9_38 = f2 * (long)f9_38; + var f3f3_2 = f3_2 * (long)f3; + var f3f4_2 = f3_2 * (long)f4; + var f3f5_4 = f3_2 * (long)f5_2; + var f3f6_2 = f3_2 * (long)f6; + var f3f7_76 = f3_2 * (long)f7_38; + var f3f8_38 = f3_2 * (long)f8_19; + var f3f9_76 = f3_2 * (long)f9_38; + var f4f4 = f4 * (long)f4; + var f4f5_2 = f4_2 * (long)f5; + var f4f6_38 = f4_2 * (long)f6_19; + var f4f7_38 = f4 * (long)f7_38; + var f4f8_38 = f4_2 * (long)f8_19; + var f4f9_38 = f4 * (long)f9_38; + var f5f5_38 = f5 * (long)f5_38; + var f5f6_38 = f5_2 * (long)f6_19; + var f5f7_76 = f5_2 * (long)f7_38; + var f5f8_38 = f5_2 * (long)f8_19; + var f5f9_76 = f5_2 * (long)f9_38; + var f6f6_19 = f6 * (long)f6_19; + var f6f7_38 = f6 * (long)f7_38; + var f6f8_38 = f6_2 * (long)f8_19; + var f6f9_38 = f6 * (long)f9_38; + var f7f7_38 = f7 * (long)f7_38; + var f7f8_38 = f7_2 * (long)f8_19; + var f7f9_76 = f7_2 * (long)f9_38; + var f8f8_19 = f8 * (long)f8_19; + var f8f9_38 = f8 * (long)f9_38; + var f9f9_38 = f9 * (long)f9_38; + + var h0 = f0f0 + f1f9_76 + f2f8_38 + f3f7_76 + f4f6_38 + f5f5_38; + var h1 = f0f1_2 + f2f9_38 + f3f8_38 + f4f7_38 + f5f6_38; + var h2 = f0f2_2 + f1f1_2 + f3f9_76 + f4f8_38 + f5f7_76 + f6f6_19; + var h3 = f0f3_2 + f1f2_2 + f4f9_38 + f5f8_38 + f6f7_38; + var h4 = f0f4_2 + f1f3_4 + f2f2 + f5f9_76 + f6f8_38 + f7f7_38; + var h5 = f0f5_2 + f1f4_2 + f2f3_2 + f6f9_38 + f7f8_38; + var h6 = f0f6_2 + f1f5_4 + f2f4_2 + f3f3_2 + f7f9_76 + f8f8_19; + var h7 = f0f7_2 + f1f6_2 + f2f5_2 + f3f4_2 + f8f9_38; + var h8 = f0f8_2 + f1f7_4 + f2f6_2 + f3f5_4 + f4f4 + f9f9_38; + var h9 = f0f9_2 + f1f8_2 + f2f7_2 + f3f6_2 + f4f5_2; + + h0 += h0; + h1 += h1; + h2 += h2; + h3 += h3; + h4 += h4; + h5 += h5; + h6 += h6; + h7 += h7; + h8 += h8; + h9 += h9; + + var carry0 = (h0 + (1 << 25)) >> 26; h1 += carry0; h0 -= carry0 << 26; + var carry4 = (h4 + (1 << 25)) >> 26; h5 += carry4; h4 -= carry4 << 26; + var carry1 = (h1 + (1 << 24)) >> 25; h2 += carry1; h1 -= carry1 << 25; + var carry5 = (h5 + (1 << 24)) >> 25; h6 += carry5; h5 -= carry5 << 25; + var carry2 = (h2 + (1 << 25)) >> 26; h3 += carry2; h2 -= carry2 << 26; + var carry6 = (h6 + (1 << 25)) >> 26; h7 += carry6; h6 -= carry6 << 26; + var carry3 = (h3 + (1 << 24)) >> 25; h4 += carry3; h3 -= carry3 << 25; + var carry7 = (h7 + (1 << 24)) >> 25; h8 += carry7; h7 -= carry7 << 25; + + carry4 = (h4 + (1 << 25)) >> 26; h5 += carry4; h4 -= carry4 << 26; + + var carry8 = (h8 + (1 << 25)) >> 26; h9 += carry8; h8 -= carry8 << 26; + var carry9 = (h9 + (1 << 24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25; + + carry0 = (h0 + (1 << 25)) >> 26; h1 += carry0; h0 -= carry0 << 26; + + h.x0 = (int)h0; + h.x1 = (int)h1; + h.x2 = (int)h2; + h.x3 = (int)h3; + h.x4 = (int)h4; + h.x5 = (int)h5; + h.x6 = (int)h6; + h.x7 = (int)h7; + h.x8 = (int)h8; + h.x9 = (int)h9; + } + } +} \ No newline at end of file diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_sub.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_sub.cs new file mode 100644 index 000000000..f76e6d752 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_sub.cs @@ -0,0 +1,66 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class FieldOperations + { + /* + h = f - g + Can overlap h with f or g. + + Preconditions: + |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. + |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. + + Postconditions: + |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. + */ + + internal static void fe_sub(out FieldElement h, ref FieldElement f, ref FieldElement g) + { + int f0 = f.x0; + int f1 = f.x1; + int f2 = f.x2; + int f3 = f.x3; + int f4 = f.x4; + int f5 = f.x5; + int f6 = f.x6; + int f7 = f.x7; + int f8 = f.x8; + int f9 = f.x9; + + int g0 = g.x0; + int g1 = g.x1; + int g2 = g.x2; + int g3 = g.x3; + int g4 = g.x4; + int g5 = g.x5; + int g6 = g.x6; + int g7 = g.x7; + int g8 = g.x8; + int g9 = g.x9; + + int h0 = f0 - g0; + int h1 = f1 - g1; + int h2 = f2 - g2; + int h3 = f3 - g3; + int h4 = f4 - g4; + int h5 = f5 - g5; + int h6 = f6 - g6; + int h7 = f7 - g7; + int h8 = f8 - g8; + int h9 = f9 - g9; + + h.x0 = h0; + h.x1 = h1; + h.x2 = h2; + h.x3 = h3; + h.x4 = h4; + h.x5 = h5; + h.x6 = h6; + h.x7 = h7; + h.x8 = h8; + h.x9 = h9; + } + } +} \ No newline at end of file diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_tobytes.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_tobytes.cs new file mode 100644 index 000000000..601f88f28 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/fe_tobytes.cs @@ -0,0 +1,145 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class FieldOperations + { + /* + Preconditions: + |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. + + Write p=2^255-19; q=floor(h/p). + Basic claim: q = floor(2^(-255)(h + 19 2^(-25)h9 + 2^(-1))). + + Proof: + Have |h|<=p so |q|<=1 so |19^2 2^(-255) q|<1/4. + Also have |h-2^230 h9|<2^231 so |19 2^(-255)(h-2^230 h9)|<1/4. + + Write y=2^(-1)-19^2 2^(-255)q-19 2^(-255)(h-2^230 h9). + Then 0> 0); + s[offset + 1] = (byte) (h0 >> 8); + s[offset + 2] = (byte) (h0 >> 16); + s[offset + 3] = (byte) ((h0 >> 24) | (h1 << 2)); + s[offset + 4] = (byte) (h1 >> 6); + s[offset + 5] = (byte) (h1 >> 14); + s[offset + 6] = (byte) ((h1 >> 22) | (h2 << 3)); + s[offset + 7] = (byte) (h2 >> 5); + s[offset + 8] = (byte) (h2 >> 13); + s[offset + 9] = (byte) ((h2 >> 21) | (h3 << 5)); + s[offset + 10] = (byte) (h3 >> 3); + s[offset + 11] = (byte) (h3 >> 11); + s[offset + 12] = (byte) ((h3 >> 19) | (h4 << 6)); + s[offset + 13] = (byte) (h4 >> 2); + s[offset + 14] = (byte) (h4 >> 10); + s[offset + 15] = (byte) (h4 >> 18); + s[offset + 16] = (byte) (h5 >> 0); + s[offset + 17] = (byte) (h5 >> 8); + s[offset + 18] = (byte) (h5 >> 16); + s[offset + 19] = (byte) ((h5 >> 24) | (h6 << 1)); + s[offset + 20] = (byte) (h6 >> 7); + s[offset + 21] = (byte) (h6 >> 15); + s[offset + 22] = (byte) ((h6 >> 23) | (h7 << 3)); + s[offset + 23] = (byte) (h7 >> 5); + s[offset + 24] = (byte) (h7 >> 13); + s[offset + 25] = (byte) ((h7 >> 21) | (h8 << 4)); + s[offset + 26] = (byte) (h8 >> 4); + s[offset + 27] = (byte) (h8 >> 12); + s[offset + 28] = (byte) ((h8 >> 20) | (h9 << 6)); + s[offset + 29] = (byte) (h9 >> 2); + s[offset + 30] = (byte) (h9 >> 10); + s[offset + 31] = (byte) (h9 >> 18); + } + } + + internal static void fe_reduce(out FieldElement hr, ref FieldElement h) + { + int h0 = h.x0; + int h1 = h.x1; + int h2 = h.x2; + int h3 = h.x3; + int h4 = h.x4; + int h5 = h.x5; + int h6 = h.x6; + int h7 = h.x7; + int h8 = h.x8; + int h9 = h.x9; + + int q; + + q = (19 * h9 + (1 << 24)) >> 25; + q = (h0 + q) >> 26; + q = (h1 + q) >> 25; + q = (h2 + q) >> 26; + q = (h3 + q) >> 25; + q = (h4 + q) >> 26; + q = (h5 + q) >> 25; + q = (h6 + q) >> 26; + q = (h7 + q) >> 25; + q = (h8 + q) >> 26; + q = (h9 + q) >> 25; + + /* Goal: Output h-(2^255-19)q, which is between 0 and 2^255-20. */ + h0 += 19 * q; + /* Goal: Output h-2^255 q, which is between 0 and 2^255-20. */ + + var carry0 = h0 >> 26; h1 += carry0; h0 -= carry0 << 26; + var carry1 = h1 >> 25; h2 += carry1; h1 -= carry1 << 25; + var carry2 = h2 >> 26; h3 += carry2; h2 -= carry2 << 26; + var carry3 = h3 >> 25; h4 += carry3; h3 -= carry3 << 25; + var carry4 = h4 >> 26; h5 += carry4; h4 -= carry4 << 26; + var carry5 = h5 >> 25; h6 += carry5; h5 -= carry5 << 25; + var carry6 = h6 >> 26; h7 += carry6; h6 -= carry6 << 26; + var carry7 = h7 >> 25; h8 += carry7; h7 -= carry7 << 25; + var carry8 = h8 >> 26; h9 += carry8; h8 -= carry8 << 26; + var carry9 = h9 >> 25; h9 -= carry9 << 25; + /* h10 = carry9 */ + + hr.x0 = h0; + hr.x1 = h1; + hr.x2 = h2; + hr.x3 = h3; + hr.x4 = h4; + hr.x5 = h5; + hr.x6 = h6; + hr.x7 = h7; + hr.x8 = h8; + hr.x9 = h9; + } + } +} \ No newline at end of file diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/ge_add.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/ge_add.cs new file mode 100644 index 000000000..de8e08f12 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/ge_add.cs @@ -0,0 +1,73 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class GroupOperations + { + /* + r = p + q + */ + + internal static void ge_add(out GroupElementP1P1 r, ref GroupElementP3 p, ref GroupElementCached q) + { + FieldElement t0; + + /* qhasm: YpX1 = Y1+X1 */ + /* asm 1: fe_add(>YpX1=fe#1,YpX1=r.X,YmX1=fe#2,YmX1=r.Y,A=fe#3,A=r.Z,B=fe#2,B=r.Y,C=fe#4,C=r.T,ZZ=fe#1,ZZ=r.X,D=fe#5,D=t0,X3=fe#1,X3=r.X,Y3=fe#2,Y3=r.Y,Z3=fe#3,Z3=r.Z,T3=fe#4,T3=r.T,> 3] >> (i & 7))); + + for (int i = 0; i < 256; ++i) + { + if (r[i] != 0) + { + for (int b = 1; b <= 6 && (i + b) < 256; ++b) + { + if (r[i + b] != 0) + { + if (r[i] + (r[i + b] << b) <= 15) + { + r[i] += (sbyte)(r[i + b] << b); r[i + b] = 0; + } + else if (r[i] - (r[i + b] << b) >= -15) + { + r[i] -= (sbyte)(r[i + b] << b); + for (int k = i + b; k < 256; ++k) + { + if (r[k] == 0) + { + r[k] = 1; + break; + } + r[k] = 0; + } + } + else + break; + } + } + } + } + } + + /* + r = a * A + b * B + where a = a[0]+256*a[1]+...+256^31 a[31]. + and b = b[0]+256*b[1]+...+256^31 b[31]. + B is the Ed25519 base point (x,4/5) with x positive. + */ + + public static void ge_double_scalarmult_vartime(out GroupElementP2 r, byte[] a, ref GroupElementP3 A, byte[] b) + { + GroupElementPreComp[] Bi = LookupTables.Base2; + // todo: Perhaps remove these allocations? + sbyte[] aslide = new sbyte[256]; + sbyte[] bslide = new sbyte[256]; + GroupElementCached[] Ai = new GroupElementCached[8]; /* A,3A,5A,7A,9A,11A,13A,15A */ + GroupElementP1P1 t; + GroupElementP3 u; + GroupElementP3 A2; + int i; + + slide(aslide, a); + slide(bslide, b); + + ge_p3_to_cached(out Ai[0], ref A); + ge_p3_dbl(out t, ref A); ge_p1p1_to_p3(out A2, ref t); + ge_add(out t, ref A2, ref Ai[0]); ge_p1p1_to_p3(out u, ref t); ge_p3_to_cached(out Ai[1], ref u); + ge_add(out t, ref A2, ref Ai[1]); ge_p1p1_to_p3(out u, ref t); ge_p3_to_cached(out Ai[2], ref u); + ge_add(out t, ref A2, ref Ai[2]); ge_p1p1_to_p3(out u, ref t); ge_p3_to_cached(out Ai[3], ref u); + ge_add(out t, ref A2, ref Ai[3]); ge_p1p1_to_p3(out u, ref t); ge_p3_to_cached(out Ai[4], ref u); + ge_add(out t, ref A2, ref Ai[4]); ge_p1p1_to_p3(out u, ref t); ge_p3_to_cached(out Ai[5], ref u); + ge_add(out t, ref A2, ref Ai[5]); ge_p1p1_to_p3(out u, ref t); ge_p3_to_cached(out Ai[6], ref u); + ge_add(out t, ref A2, ref Ai[6]); ge_p1p1_to_p3(out u, ref t); ge_p3_to_cached(out Ai[7], ref u); + + ge_p2_0(out r); + + for (i = 255; i >= 0; --i) + { + if ((aslide[i] != 0) || (bslide[i] != 0)) break; + } + + for (; i >= 0; --i) + { + ge_p2_dbl(out t, ref r); + + if (aslide[i] > 0) + { + ge_p1p1_to_p3(out u, ref t); + ge_add(out t, ref u, ref Ai[aslide[i] / 2]); + } + else if (aslide[i] < 0) + { + ge_p1p1_to_p3(out u, ref t); + ge_sub(out t, ref u, ref Ai[(-aslide[i]) / 2]); + } + + if (bslide[i] > 0) + { + ge_p1p1_to_p3(out u, ref t); + ge_madd(out t, ref u, ref Bi[bslide[i] / 2]); + } + else if (bslide[i] < 0) + { + ge_p1p1_to_p3(out u, ref t); + ge_msub(out t, ref u, ref Bi[(-bslide[i]) / 2]); + } + + ge_p1p1_to_p2(out r, ref t); + } + } + + } +} \ No newline at end of file diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/ge_frombytes.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/ge_frombytes.cs new file mode 100644 index 000000000..2e7abe9d4 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/ge_frombytes.cs @@ -0,0 +1,50 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class GroupOperations + { + public static int ge_frombytes_negate_vartime(out GroupElementP3 h, byte[] data, int offset) + { + FieldElement u, v, v3, vxx, check; + + FieldOperations.fe_frombytes(out h.Y, data, offset); + FieldOperations.fe_1(out h.Z); + FieldOperations.fe_sq(out u, ref h.Y); + FieldOperations.fe_mul(out v, ref u, ref LookupTables.d); + FieldOperations.fe_sub(out u, ref u, ref h.Z); /* u = y^2-1 */ + FieldOperations.fe_add(out v, ref v, ref h.Z); /* v = dy^2+1 */ + + FieldOperations.fe_sq(out v3, ref v); + FieldOperations.fe_mul(out v3, ref v3, ref v); /* v3 = v^3 */ + FieldOperations.fe_sq(out h.X, ref v3); + FieldOperations.fe_mul(out h.X, ref h.X, ref v); + FieldOperations.fe_mul(out h.X, ref h.X, ref u); /* x = uv^7 */ + + FieldOperations.fe_pow22523(out h.X, ref h.X); /* x = (uv^7)^((q-5)/8) */ + FieldOperations.fe_mul(out h.X, ref h.X, ref v3); + FieldOperations.fe_mul(out h.X, ref h.X, ref u); /* x = uv^3(uv^7)^((q-5)/8) */ + + FieldOperations.fe_sq(out vxx, ref h.X); + FieldOperations.fe_mul(out vxx, ref vxx, ref v); + FieldOperations.fe_sub(out check, ref vxx, ref u); /* vx^2-u */ + if (FieldOperations.fe_isnonzero(ref check) != 0) + { + FieldOperations.fe_add(out check, ref vxx, ref u); /* vx^2+u */ + if (FieldOperations.fe_isnonzero(ref check) != 0) + { + h = default(GroupElementP3); + return -1; + } + FieldOperations.fe_mul(out h.X, ref h.X, ref LookupTables.sqrtm1); + } + + if (FieldOperations.fe_isnegative(ref h.X) == (data[offset + 31] >> 7)) + FieldOperations.fe_neg(out h.X, ref h.X); + + FieldOperations.fe_mul(out h.T, ref h.X, ref h.Y); + return 0; + } + + } +} \ No newline at end of file diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/ge_madd.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/ge_madd.cs new file mode 100644 index 000000000..547e17d86 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/ge_madd.cs @@ -0,0 +1,69 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class GroupOperations + { + /* + r = p + q + */ + public static void ge_madd(out GroupElementP1P1 r, ref GroupElementP3 p, ref GroupElementPreComp q) + { + FieldElement t0; + + /* qhasm: YpX1 = Y1+X1 */ + /* asm 1: fe_add(>YpX1=fe#1,YpX1=r.X,YmX1=fe#2,YmX1=r.Y,A=fe#3,A=r.Z,B=fe#2,B=r.Y,C=fe#4,C=r.T,D=fe#5,D=t0,X3=fe#1,X3=r.X,Y3=fe#2,Y3=r.Y,Z3=fe#3,Z3=r.Z,T3=fe#4,T3=r.T,YpX1=fe#1,YpX1=r.X,YmX1=fe#2,YmX1=r.Y,A=fe#3,A=r.Z,B=fe#2,B=r.Y,C=fe#4,C=r.T,D=fe#5,D=t0,X3=fe#1,X3=r.X,Y3=fe#2,Y3=r.Y,Z3=fe#3,Z3=r.Z,T3=fe#4,T3=r.T,XX=fe#1,XX=r.X,YY=fe#3,YY=r.Z,B=fe#4,B=r.T,A=fe#2,A=r.Y,AA=fe#5,AA=t0,Y3=fe#2,Y3=r.Y,Z3=fe#3,Z3=r.Z,X3=fe#1,X3=r.X,T3=fe#4,T3=r.T,>= 31; /* 1: yes; 0: no */ + return (byte)y; + } + + static byte negative(sbyte b) + { + var x = unchecked((ulong)b); /* 18446744073709551361..18446744073709551615: yes; 0..255: no */ + x >>= 63; /* 1: yes; 0: no */ + return (byte)x; + } + + static void cmov(ref GroupElementPreComp t, ref GroupElementPreComp u, byte b) + { + FieldOperations.fe_cmov(ref t.yplusx, ref u.yplusx, b); + FieldOperations.fe_cmov(ref t.yminusx, ref u.yminusx, b); + FieldOperations.fe_cmov(ref t.xy2d, ref u.xy2d, b); + } + + static void select(out GroupElementPreComp t, int pos, sbyte b) + { + GroupElementPreComp minust; + var bnegative = negative(b); + var babs = (byte)(b - (((-bnegative) & b) << 1)); + + ge_precomp_0(out t); + var table = LookupTables.Base[pos]; + cmov(ref t, ref table[0], equal(babs, 1)); + cmov(ref t, ref table[1], equal(babs, 2)); + cmov(ref t, ref table[2], equal(babs, 3)); + cmov(ref t, ref table[3], equal(babs, 4)); + cmov(ref t, ref table[4], equal(babs, 5)); + cmov(ref t, ref table[5], equal(babs, 6)); + cmov(ref t, ref table[6], equal(babs, 7)); + cmov(ref t, ref table[7], equal(babs, 8)); + minust.yplusx = t.yminusx; + minust.yminusx = t.yplusx; + FieldOperations.fe_neg(out minust.xy2d, ref t.xy2d); + cmov(ref t, ref minust, bnegative); + } + + /* + h = a * B + where a = a[0]+256*a[1]+...+256^31 a[31] + B is the Ed25519 base point (x,4/5) with x positive. + + Preconditions: + a[31] <= 127 + */ + + public static void ge_scalarmult_base(out GroupElementP3 h, byte[] a, int offset) + { + // todo: Perhaps remove this allocation + var e = new sbyte[64]; + sbyte carry; + + GroupElementP1P1 r; + GroupElementP2 s; + GroupElementPreComp t; + + for (int i = 0; i < 32; ++i) + { + e[2 * i + 0] = (sbyte)((a[offset + i] >> 0) & 15); + e[2 * i + 1] = (sbyte)((a[offset + i] >> 4) & 15); + } + /* each e[i] is between 0 and 15 */ + /* e[63] is between 0 and 7 */ + + carry = 0; + for (int i = 0; i < 63; ++i) + { + e[i] += carry; + carry = (sbyte)(e[i] + 8); + carry >>= 4; + e[i] -= (sbyte)(carry << 4); + } + e[63] += carry; + /* each e[i] is between -8 and 8 */ + + ge_p3_0(out h); + for (int i = 1; i < 64; i += 2) + { + select(out t, i / 2, e[i]); + ge_madd(out r, ref h, ref t); ge_p1p1_to_p3(out h, ref r); + } + + ge_p3_dbl(out r, ref h); ge_p1p1_to_p2(out s, ref r); + ge_p2_dbl(out r, ref s); ge_p1p1_to_p2(out s, ref r); + ge_p2_dbl(out r, ref s); ge_p1p1_to_p2(out s, ref r); + ge_p2_dbl(out r, ref s); ge_p1p1_to_p3(out h, ref r); + + for (int i = 0; i < 64; i += 2) + { + select(out t, i / 2, e[i]); + ge_madd(out r, ref h, ref t); ge_p1p1_to_p3(out h, ref r); + } + } + + } +} \ No newline at end of file diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/ge_sub.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/ge_sub.cs new file mode 100644 index 000000000..c0b9ba5a2 --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/ge_sub.cs @@ -0,0 +1,74 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class GroupOperations + { + /* + r = p - q + */ + + public static void ge_sub(out GroupElementP1P1 r, ref GroupElementP3 p, ref GroupElementCached q) + { + FieldElement t0; + + /* qhasm: YpX1 = Y1+X1 */ + /* asm 1: fe_add(>YpX1=fe#1,YpX1=r.X,YmX1=fe#2,YmX1=r.Y,A=fe#3,A=r.Z,B=fe#2,B=r.Y,C=fe#4,C=r.T,ZZ=fe#1,ZZ=r.X,D=fe#5,D=t0,X3=fe#1,X3=r.X,Y3=fe#2,Y3=r.Y,Z3=fe#3,Z3=r.Z,T3=fe#4,T3=r.T,> 5); + long a2 = 2097151 & (load_3(a, 5) >> 2); + long a3 = 2097151 & (load_4(a, 7) >> 7); + long a4 = 2097151 & (load_4(a, 10) >> 4); + long a5 = 2097151 & (load_3(a, 13) >> 1); + long a6 = 2097151 & (load_4(a, 15) >> 6); + long a7 = 2097151 & (load_3(a, 18) >> 3); + long a8 = 2097151 & load_3(a, 21); + long a9 = 2097151 & (load_4(a, 23) >> 5); + long a10 = 2097151 & (load_3(a, 26) >> 2); + long a11 = (load_4(a, 28) >> 7); + long b0 = 2097151 & load_3(b, 0); + long b1 = 2097151 & (load_4(b, 2) >> 5); + long b2 = 2097151 & (load_3(b, 5) >> 2); + long b3 = 2097151 & (load_4(b, 7) >> 7); + long b4 = 2097151 & (load_4(b, 10) >> 4); + long b5 = 2097151 & (load_3(b, 13) >> 1); + long b6 = 2097151 & (load_4(b, 15) >> 6); + long b7 = 2097151 & (load_3(b, 18) >> 3); + long b8 = 2097151 & load_3(b, 21); + long b9 = 2097151 & (load_4(b, 23) >> 5); + long b10 = 2097151 & (load_3(b, 26) >> 2); + long b11 = (load_4(b, 28) >> 7); + long c0 = 2097151 & load_3(c, 0); + long c1 = 2097151 & (load_4(c, 2) >> 5); + long c2 = 2097151 & (load_3(c, 5) >> 2); + long c3 = 2097151 & (load_4(c, 7) >> 7); + long c4 = 2097151 & (load_4(c, 10) >> 4); + long c5 = 2097151 & (load_3(c, 13) >> 1); + long c6 = 2097151 & (load_4(c, 15) >> 6); + long c7 = 2097151 & (load_3(c, 18) >> 3); + long c8 = 2097151 & load_3(c, 21); + long c9 = 2097151 & (load_4(c, 23) >> 5); + long c10 = 2097151 & (load_3(c, 26) >> 2); + long c11 = (load_4(c, 28) >> 7); + long s0; + long s1; + long s2; + long s3; + long s4; + long s5; + long s6; + long s7; + long s8; + long s9; + long s10; + long s11; + long s12; + long s13; + long s14; + long s15; + long s16; + long s17; + long s18; + long s19; + long s20; + long s21; + long s22; + long s23; + long carry0; + long carry1; + long carry2; + long carry3; + long carry4; + long carry5; + long carry6; + long carry7; + long carry8; + long carry9; + long carry10; + long carry11; + long carry12; + long carry13; + long carry14; + long carry15; + long carry16; + long carry17; + long carry18; + long carry19; + long carry20; + long carry21; + long carry22; + + s0 = c0 + a0 * b0; + s1 = c1 + a0 * b1 + a1 * b0; + s2 = c2 + a0 * b2 + a1 * b1 + a2 * b0; + s3 = c3 + a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0; + s4 = c4 + a0 * b4 + a1 * b3 + a2 * b2 + a3 * b1 + a4 * b0; + s5 = c5 + a0 * b5 + a1 * b4 + a2 * b3 + a3 * b2 + a4 * b1 + a5 * b0; + s6 = c6 + a0 * b6 + a1 * b5 + a2 * b4 + a3 * b3 + a4 * b2 + a5 * b1 + a6 * b0; + s7 = c7 + a0 * b7 + a1 * b6 + a2 * b5 + a3 * b4 + a4 * b3 + a5 * b2 + a6 * b1 + a7 * b0; + s8 = c8 + a0 * b8 + a1 * b7 + a2 * b6 + a3 * b5 + a4 * b4 + a5 * b3 + a6 * b2 + a7 * b1 + a8 * b0; + s9 = c9 + a0 * b9 + a1 * b8 + a2 * b7 + a3 * b6 + a4 * b5 + a5 * b4 + a6 * b3 + a7 * b2 + a8 * b1 + a9 * b0; + s10 = c10 + a0 * b10 + a1 * b9 + a2 * b8 + a3 * b7 + a4 * b6 + a5 * b5 + a6 * b4 + a7 * b3 + a8 * b2 + a9 * b1 + a10 * b0; + s11 = c11 + a0 * b11 + a1 * b10 + a2 * b9 + a3 * b8 + a4 * b7 + a5 * b6 + a6 * b5 + a7 * b4 + a8 * b3 + a9 * b2 + a10 * b1 + a11 * b0; + s12 = a1 * b11 + a2 * b10 + a3 * b9 + a4 * b8 + a5 * b7 + a6 * b6 + a7 * b5 + a8 * b4 + a9 * b3 + a10 * b2 + a11 * b1; + s13 = a2 * b11 + a3 * b10 + a4 * b9 + a5 * b8 + a6 * b7 + a7 * b6 + a8 * b5 + a9 * b4 + a10 * b3 + a11 * b2; + s14 = a3 * b11 + a4 * b10 + a5 * b9 + a6 * b8 + a7 * b7 + a8 * b6 + a9 * b5 + a10 * b4 + a11 * b3; + s15 = a4 * b11 + a5 * b10 + a6 * b9 + a7 * b8 + a8 * b7 + a9 * b6 + a10 * b5 + a11 * b4; + s16 = a5 * b11 + a6 * b10 + a7 * b9 + a8 * b8 + a9 * b7 + a10 * b6 + a11 * b5; + s17 = a6 * b11 + a7 * b10 + a8 * b9 + a9 * b8 + a10 * b7 + a11 * b6; + s18 = a7 * b11 + a8 * b10 + a9 * b9 + a10 * b8 + a11 * b7; + s19 = a8 * b11 + a9 * b10 + a10 * b9 + a11 * b8; + s20 = a9 * b11 + a10 * b10 + a11 * b9; + s21 = a10 * b11 + a11 * b10; + s22 = a11 * b11; + s23 = 0; + + carry0 = (s0 + (1 << 20)) >> 21; s1 += carry0; s0 -= carry0 << 21; + carry2 = (s2 + (1 << 20)) >> 21; s3 += carry2; s2 -= carry2 << 21; + carry4 = (s4 + (1 << 20)) >> 21; s5 += carry4; s4 -= carry4 << 21; + carry6 = (s6 + (1 << 20)) >> 21; s7 += carry6; s6 -= carry6 << 21; + carry8 = (s8 + (1 << 20)) >> 21; s9 += carry8; s8 -= carry8 << 21; + carry10 = (s10 + (1 << 20)) >> 21; s11 += carry10; s10 -= carry10 << 21; + carry12 = (s12 + (1 << 20)) >> 21; s13 += carry12; s12 -= carry12 << 21; + carry14 = (s14 + (1 << 20)) >> 21; s15 += carry14; s14 -= carry14 << 21; + carry16 = (s16 + (1 << 20)) >> 21; s17 += carry16; s16 -= carry16 << 21; + carry18 = (s18 + (1 << 20)) >> 21; s19 += carry18; s18 -= carry18 << 21; + carry20 = (s20 + (1 << 20)) >> 21; s21 += carry20; s20 -= carry20 << 21; + carry22 = (s22 + (1 << 20)) >> 21; s23 += carry22; s22 -= carry22 << 21; + + carry1 = (s1 + (1 << 20)) >> 21; s2 += carry1; s1 -= carry1 << 21; + carry3 = (s3 + (1 << 20)) >> 21; s4 += carry3; s3 -= carry3 << 21; + carry5 = (s5 + (1 << 20)) >> 21; s6 += carry5; s5 -= carry5 << 21; + carry7 = (s7 + (1 << 20)) >> 21; s8 += carry7; s7 -= carry7 << 21; + carry9 = (s9 + (1 << 20)) >> 21; s10 += carry9; s9 -= carry9 << 21; + carry11 = (s11 + (1 << 20)) >> 21; s12 += carry11; s11 -= carry11 << 21; + carry13 = (s13 + (1 << 20)) >> 21; s14 += carry13; s13 -= carry13 << 21; + carry15 = (s15 + (1 << 20)) >> 21; s16 += carry15; s15 -= carry15 << 21; + carry17 = (s17 + (1 << 20)) >> 21; s18 += carry17; s17 -= carry17 << 21; + carry19 = (s19 + (1 << 20)) >> 21; s20 += carry19; s19 -= carry19 << 21; + carry21 = (s21 + (1 << 20)) >> 21; s22 += carry21; s21 -= carry21 << 21; + + s11 += s23 * 666643; + s12 += s23 * 470296; + s13 += s23 * 654183; + s14 -= s23 * 997805; + s15 += s23 * 136657; + s16 -= s23 * 683901; + s23 = 0; + + s10 += s22 * 666643; + s11 += s22 * 470296; + s12 += s22 * 654183; + s13 -= s22 * 997805; + s14 += s22 * 136657; + s15 -= s22 * 683901; + s22 = 0; + + s9 += s21 * 666643; + s10 += s21 * 470296; + s11 += s21 * 654183; + s12 -= s21 * 997805; + s13 += s21 * 136657; + s14 -= s21 * 683901; + s21 = 0; + + s8 += s20 * 666643; + s9 += s20 * 470296; + s10 += s20 * 654183; + s11 -= s20 * 997805; + s12 += s20 * 136657; + s13 -= s20 * 683901; + s20 = 0; + + s7 += s19 * 666643; + s8 += s19 * 470296; + s9 += s19 * 654183; + s10 -= s19 * 997805; + s11 += s19 * 136657; + s12 -= s19 * 683901; + s19 = 0; + + s6 += s18 * 666643; + s7 += s18 * 470296; + s8 += s18 * 654183; + s9 -= s18 * 997805; + s10 += s18 * 136657; + s11 -= s18 * 683901; + s18 = 0; + + carry6 = (s6 + (1 << 20)) >> 21; s7 += carry6; s6 -= carry6 << 21; + carry8 = (s8 + (1 << 20)) >> 21; s9 += carry8; s8 -= carry8 << 21; + carry10 = (s10 + (1 << 20)) >> 21; s11 += carry10; s10 -= carry10 << 21; + carry12 = (s12 + (1 << 20)) >> 21; s13 += carry12; s12 -= carry12 << 21; + carry14 = (s14 + (1 << 20)) >> 21; s15 += carry14; s14 -= carry14 << 21; + carry16 = (s16 + (1 << 20)) >> 21; s17 += carry16; s16 -= carry16 << 21; + + carry7 = (s7 + (1 << 20)) >> 21; s8 += carry7; s7 -= carry7 << 21; + carry9 = (s9 + (1 << 20)) >> 21; s10 += carry9; s9 -= carry9 << 21; + carry11 = (s11 + (1 << 20)) >> 21; s12 += carry11; s11 -= carry11 << 21; + carry13 = (s13 + (1 << 20)) >> 21; s14 += carry13; s13 -= carry13 << 21; + carry15 = (s15 + (1 << 20)) >> 21; s16 += carry15; s15 -= carry15 << 21; + + s5 += s17 * 666643; + s6 += s17 * 470296; + s7 += s17 * 654183; + s8 -= s17 * 997805; + s9 += s17 * 136657; + s10 -= s17 * 683901; + s17 = 0; + + s4 += s16 * 666643; + s5 += s16 * 470296; + s6 += s16 * 654183; + s7 -= s16 * 997805; + s8 += s16 * 136657; + s9 -= s16 * 683901; + s16 = 0; + + s3 += s15 * 666643; + s4 += s15 * 470296; + s5 += s15 * 654183; + s6 -= s15 * 997805; + s7 += s15 * 136657; + s8 -= s15 * 683901; + s15 = 0; + + s2 += s14 * 666643; + s3 += s14 * 470296; + s4 += s14 * 654183; + s5 -= s14 * 997805; + s6 += s14 * 136657; + s7 -= s14 * 683901; + s14 = 0; + + s1 += s13 * 666643; + s2 += s13 * 470296; + s3 += s13 * 654183; + s4 -= s13 * 997805; + s5 += s13 * 136657; + s6 -= s13 * 683901; + s13 = 0; + + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + + carry0 = (s0 + (1 << 20)) >> 21; s1 += carry0; s0 -= carry0 << 21; + carry2 = (s2 + (1 << 20)) >> 21; s3 += carry2; s2 -= carry2 << 21; + carry4 = (s4 + (1 << 20)) >> 21; s5 += carry4; s4 -= carry4 << 21; + carry6 = (s6 + (1 << 20)) >> 21; s7 += carry6; s6 -= carry6 << 21; + carry8 = (s8 + (1 << 20)) >> 21; s9 += carry8; s8 -= carry8 << 21; + carry10 = (s10 + (1 << 20)) >> 21; s11 += carry10; s10 -= carry10 << 21; + + carry1 = (s1 + (1 << 20)) >> 21; s2 += carry1; s1 -= carry1 << 21; + carry3 = (s3 + (1 << 20)) >> 21; s4 += carry3; s3 -= carry3 << 21; + carry5 = (s5 + (1 << 20)) >> 21; s6 += carry5; s5 -= carry5 << 21; + carry7 = (s7 + (1 << 20)) >> 21; s8 += carry7; s7 -= carry7 << 21; + carry9 = (s9 + (1 << 20)) >> 21; s10 += carry9; s9 -= carry9 << 21; + carry11 = (s11 + (1 << 20)) >> 21; s12 += carry11; s11 -= carry11 << 21; + + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + + carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21; + carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21; + carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 << 21; + carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 << 21; + carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 << 21; + carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 << 21; + carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 << 21; + carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 << 21; + carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 << 21; + carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 << 21; + carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21; + carry11 = s11 >> 21; s12 += carry11; s11 -= carry11 << 21; + + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + + carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21; + carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21; + carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 << 21; + carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 << 21; + carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 << 21; + carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 << 21; + carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 << 21; + carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 << 21; + carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 << 21; + carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 << 21; + carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21; + + unchecked + { + s[0] = (byte)(s0 >> 0); + s[1] = (byte)(s0 >> 8); + s[2] = (byte)((s0 >> 16) | (s1 << 5)); + s[3] = (byte)(s1 >> 3); + s[4] = (byte)(s1 >> 11); + s[5] = (byte)((s1 >> 19) | (s2 << 2)); + s[6] = (byte)(s2 >> 6); + s[7] = (byte)((s2 >> 14) | (s3 << 7)); + s[8] = (byte)(s3 >> 1); + s[9] = (byte)(s3 >> 9); + s[10] = (byte)((s3 >> 17) | (s4 << 4)); + s[11] = (byte)(s4 >> 4); + s[12] = (byte)(s4 >> 12); + s[13] = (byte)((s4 >> 20) | (s5 << 1)); + s[14] = (byte)(s5 >> 7); + s[15] = (byte)((s5 >> 15) | (s6 << 6)); + s[16] = (byte)(s6 >> 2); + s[17] = (byte)(s6 >> 10); + s[18] = (byte)((s6 >> 18) | (s7 << 3)); + s[19] = (byte)(s7 >> 5); + s[20] = (byte)(s7 >> 13); + s[21] = (byte)(s8 >> 0); + s[22] = (byte)(s8 >> 8); + s[23] = (byte)((s8 >> 16) | (s9 << 5)); + s[24] = (byte)(s9 >> 3); + s[25] = (byte)(s9 >> 11); + s[26] = (byte)((s9 >> 19) | (s10 << 2)); + s[27] = (byte)(s10 >> 6); + s[28] = (byte)((s10 >> 14) | (s11 << 7)); + s[29] = (byte)(s11 >> 1); + s[30] = (byte)(s11 >> 9); + s[31] = (byte)(s11 >> 17); + } + } + } +} \ No newline at end of file diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/sc_reduce.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/sc_reduce.cs new file mode 100644 index 000000000..d3554455f --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/sc_reduce.cs @@ -0,0 +1,264 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + internal static partial class ScalarOperations + { + /* + Input: + s[0]+256*s[1]+...+256^63*s[63] = s + + Output: + s[0]+256*s[1]+...+256^31*s[31] = s mod l + where l = 2^252 + 27742317777372353535851937790883648493. + Overwrites s in place. + */ + + public static void sc_reduce(byte[] s) + { + long s0 = 2097151 & load_3(s, 0); + long s1 = 2097151 & (load_4(s, 2) >> 5); + long s2 = 2097151 & (load_3(s, 5) >> 2); + long s3 = 2097151 & (load_4(s, 7) >> 7); + long s4 = 2097151 & (load_4(s, 10) >> 4); + long s5 = 2097151 & (load_3(s, 13) >> 1); + long s6 = 2097151 & (load_4(s, 15) >> 6); + long s7 = 2097151 & (load_3(s, 18) >> 3); + long s8 = 2097151 & load_3(s, 21); + long s9 = 2097151 & (load_4(s, 23) >> 5); + long s10 = 2097151 & (load_3(s, 26) >> 2); + long s11 = 2097151 & (load_4(s, 28) >> 7); + long s12 = 2097151 & (load_4(s, 31) >> 4); + long s13 = 2097151 & (load_3(s, 34) >> 1); + long s14 = 2097151 & (load_4(s, 36) >> 6); + long s15 = 2097151 & (load_3(s, 39) >> 3); + long s16 = 2097151 & load_3(s, 42); + long s17 = 2097151 & (load_4(s, 44) >> 5); + long s18 = 2097151 & (load_3(s, 47) >> 2); + long s19 = 2097151 & (load_4(s, 49) >> 7); + long s20 = 2097151 & (load_4(s, 52) >> 4); + long s21 = 2097151 & (load_3(s, 55) >> 1); + long s22 = 2097151 & (load_4(s, 57) >> 6); + long s23 = (load_4(s, 60) >> 3); + + long carry0; + long carry1; + long carry2; + long carry3; + long carry4; + long carry5; + long carry6; + long carry7; + long carry8; + long carry9; + long carry10; + long carry11; + long carry12; + long carry13; + long carry14; + long carry15; + long carry16; + + s11 += s23 * 666643; + s12 += s23 * 470296; + s13 += s23 * 654183; + s14 -= s23 * 997805; + s15 += s23 * 136657; + s16 -= s23 * 683901; + s23 = 0; + + s10 += s22 * 666643; + s11 += s22 * 470296; + s12 += s22 * 654183; + s13 -= s22 * 997805; + s14 += s22 * 136657; + s15 -= s22 * 683901; + s22 = 0; + + s9 += s21 * 666643; + s10 += s21 * 470296; + s11 += s21 * 654183; + s12 -= s21 * 997805; + s13 += s21 * 136657; + s14 -= s21 * 683901; + s21 = 0; + + s8 += s20 * 666643; + s9 += s20 * 470296; + s10 += s20 * 654183; + s11 -= s20 * 997805; + s12 += s20 * 136657; + s13 -= s20 * 683901; + s20 = 0; + + s7 += s19 * 666643; + s8 += s19 * 470296; + s9 += s19 * 654183; + s10 -= s19 * 997805; + s11 += s19 * 136657; + s12 -= s19 * 683901; + s19 = 0; + + s6 += s18 * 666643; + s7 += s18 * 470296; + s8 += s18 * 654183; + s9 -= s18 * 997805; + s10 += s18 * 136657; + s11 -= s18 * 683901; + s18 = 0; + + carry6 = (s6 + (1 << 20)) >> 21; s7 += carry6; s6 -= carry6 << 21; + carry8 = (s8 + (1 << 20)) >> 21; s9 += carry8; s8 -= carry8 << 21; + carry10 = (s10 + (1 << 20)) >> 21; s11 += carry10; s10 -= carry10 << 21; + carry12 = (s12 + (1 << 20)) >> 21; s13 += carry12; s12 -= carry12 << 21; + carry14 = (s14 + (1 << 20)) >> 21; s15 += carry14; s14 -= carry14 << 21; + carry16 = (s16 + (1 << 20)) >> 21; s17 += carry16; s16 -= carry16 << 21; + + carry7 = (s7 + (1 << 20)) >> 21; s8 += carry7; s7 -= carry7 << 21; + carry9 = (s9 + (1 << 20)) >> 21; s10 += carry9; s9 -= carry9 << 21; + carry11 = (s11 + (1 << 20)) >> 21; s12 += carry11; s11 -= carry11 << 21; + carry13 = (s13 + (1 << 20)) >> 21; s14 += carry13; s13 -= carry13 << 21; + carry15 = (s15 + (1 << 20)) >> 21; s16 += carry15; s15 -= carry15 << 21; + + s5 += s17 * 666643; + s6 += s17 * 470296; + s7 += s17 * 654183; + s8 -= s17 * 997805; + s9 += s17 * 136657; + s10 -= s17 * 683901; + s17 = 0; + + s4 += s16 * 666643; + s5 += s16 * 470296; + s6 += s16 * 654183; + s7 -= s16 * 997805; + s8 += s16 * 136657; + s9 -= s16 * 683901; + s16 = 0; + + s3 += s15 * 666643; + s4 += s15 * 470296; + s5 += s15 * 654183; + s6 -= s15 * 997805; + s7 += s15 * 136657; + s8 -= s15 * 683901; + s15 = 0; + + s2 += s14 * 666643; + s3 += s14 * 470296; + s4 += s14 * 654183; + s5 -= s14 * 997805; + s6 += s14 * 136657; + s7 -= s14 * 683901; + s14 = 0; + + s1 += s13 * 666643; + s2 += s13 * 470296; + s3 += s13 * 654183; + s4 -= s13 * 997805; + s5 += s13 * 136657; + s6 -= s13 * 683901; + s13 = 0; + + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + + carry0 = (s0 + (1 << 20)) >> 21; s1 += carry0; s0 -= carry0 << 21; + carry2 = (s2 + (1 << 20)) >> 21; s3 += carry2; s2 -= carry2 << 21; + carry4 = (s4 + (1 << 20)) >> 21; s5 += carry4; s4 -= carry4 << 21; + carry6 = (s6 + (1 << 20)) >> 21; s7 += carry6; s6 -= carry6 << 21; + carry8 = (s8 + (1 << 20)) >> 21; s9 += carry8; s8 -= carry8 << 21; + carry10 = (s10 + (1 << 20)) >> 21; s11 += carry10; s10 -= carry10 << 21; + + carry1 = (s1 + (1 << 20)) >> 21; s2 += carry1; s1 -= carry1 << 21; + carry3 = (s3 + (1 << 20)) >> 21; s4 += carry3; s3 -= carry3 << 21; + carry5 = (s5 + (1 << 20)) >> 21; s6 += carry5; s5 -= carry5 << 21; + carry7 = (s7 + (1 << 20)) >> 21; s8 += carry7; s7 -= carry7 << 21; + carry9 = (s9 + (1 << 20)) >> 21; s10 += carry9; s9 -= carry9 << 21; + carry11 = (s11 + (1 << 20)) >> 21; s12 += carry11; s11 -= carry11 << 21; + + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + + carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21; + carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21; + carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 << 21; + carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 << 21; + carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 << 21; + carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 << 21; + carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 << 21; + carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 << 21; + carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 << 21; + carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 << 21; + carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21; + carry11 = s11 >> 21; s12 += carry11; s11 -= carry11 << 21; + + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + + carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21; + carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21; + carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 << 21; + carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 << 21; + carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 << 21; + carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 << 21; + carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 << 21; + carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 << 21; + carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 << 21; + carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 << 21; + carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21; + + unchecked + { + s[0] = (byte)(s0 >> 0); + s[1] = (byte)(s0 >> 8); + s[2] = (byte)((s0 >> 16) | (s1 << 5)); + s[3] = (byte)(s1 >> 3); + s[4] = (byte)(s1 >> 11); + s[5] = (byte)((s1 >> 19) | (s2 << 2)); + s[6] = (byte)(s2 >> 6); + s[7] = (byte)((s2 >> 14) | (s3 << 7)); + s[8] = (byte)(s3 >> 1); + s[9] = (byte)(s3 >> 9); + s[10] = (byte)((s3 >> 17) | (s4 << 4)); + s[11] = (byte)(s4 >> 4); + s[12] = (byte)(s4 >> 12); + s[13] = (byte)((s4 >> 20) | (s5 << 1)); + s[14] = (byte)(s5 >> 7); + s[15] = (byte)((s5 >> 15) | (s6 << 6)); + s[16] = (byte)(s6 >> 2); + s[17] = (byte)(s6 >> 10); + s[18] = (byte)((s6 >> 18) | (s7 << 3)); + s[19] = (byte)(s7 >> 5); + s[20] = (byte)(s7 >> 13); + s[21] = (byte)(s8 >> 0); + s[22] = (byte)(s8 >> 8); + s[23] = (byte)((s8 >> 16) | (s9 << 5)); + s[24] = (byte)(s9 >> 3); + s[25] = (byte)(s9 >> 11); + s[26] = (byte)((s9 >> 19) | (s10 << 2)); + s[27] = (byte)(s10 >> 6); + s[28] = (byte)((s10 >> 14) | (s11 << 7)); + s[29] = (byte)(s11 >> 1); + s[30] = (byte)(s11 >> 9); + s[31] = (byte)(s11 >> 17); + } + } + + } +} \ No newline at end of file diff --git a/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/scalarmult.cs b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/scalarmult.cs new file mode 100644 index 000000000..3a7d8feea --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Ed25519Ref10/scalarmult.cs @@ -0,0 +1,153 @@ +using System; + +namespace Discord.Net.ED25519.Ed25519Ref10 +{ + public static class MontgomeryOperations + { + public static void scalarmult( + byte[] q, int qoffset, + byte[] n, int noffset, + byte[] p, int poffset) + { + FieldElement p0, q0; + FieldOperations.fe_frombytes2(out p0, p, poffset); + scalarmult(out q0, n, noffset, ref p0); + FieldOperations.fe_tobytes(q, qoffset, ref q0); + } + + internal static void scalarmult( + out FieldElement q, + byte[] n, int noffset, + ref FieldElement p) + { + byte[] e = new byte[32];//ToDo: remove allocation + FieldElement x1, x2, x3; + FieldElement z2, z3; + FieldElement tmp0, tmp1; + + for (int i = 0; i < 32; ++i) + e[i] = n[noffset + i]; + ScalarOperations.sc_clamp(e, 0); + x1 = p; + FieldOperations.fe_1(out x2); + FieldOperations.fe_0(out z2); + x3 = x1; + FieldOperations.fe_1(out z3); + + uint swap = 0; + for (int pos = 254; pos >= 0; --pos) + { + uint b = (uint)(e[pos / 8] >> (pos & 7)); + b &= 1; + swap ^= b; + FieldOperations.fe_cswap(ref x2, ref x3, swap); + FieldOperations.fe_cswap(ref z2, ref z3, swap); + swap = b; + + /* qhasm: enter ladder */ + + /* qhasm: D = X3-Z3 */ + /* asm 1: fe_sub(>D=fe#5,D=tmp0,B=fe#6,B=tmp1,A=fe#1,A=x2,C=fe#2,C=z2,DA=fe#4,DA=z3,CB=fe#2,CB=z2,BB=fe#5,BB=tmp0,AA=fe#6,AA=tmp1,t0=fe#3,t0=x3,t1=fe#2,t1=z2,X4=fe#1,X4=x2,E=fe#6,E=tmp1,t2=fe#2,t2=z2,t3=fe#4,t3=z3,X5=fe#3,X5=x3,t4=fe#5,t4=tmp0,Z5=fe#4,x1,Z5=z3,x1,Z4=fe#2,Z4=z2, _state; + private readonly byte[] _buffer; + private ulong _totalBytes; + public const int BlockSize = 128; + private static readonly byte[] _padding = new byte[] { 0x80 }; + + /// + /// Allocation and initialization of the new SHA-512 object. + /// + public Sha512() + { + _buffer = new byte[BlockSize];//todo: remove allocation + Init(); + } + + /// + /// Performs an initialization of internal SHA-512 state. + /// + public void Init() + { + Sha512Internal.Sha512Init(out _state); + _totalBytes = 0; + } + + /// + /// Updates internal state with data from the provided array segment. + /// + /// Array segment + public void Update(ArraySegment data) + { + Update(data.Array, data.Offset, data.Count); + } + + /// + /// Updates internal state with data from the provided array. + /// + /// Array of bytes + /// Offset of byte sequence + /// Sequence length + public void Update(byte[] data, int index, int length) + { + + Array16 block; + int bytesInBuffer = (int)_totalBytes & (BlockSize - 1); + _totalBytes += (uint)length; + + if (_totalBytes >= ulong.MaxValue / 8) + throw new InvalidOperationException("Too much data"); + // Fill existing buffer + if (bytesInBuffer != 0) + { + var toCopy = Math.Min(BlockSize - bytesInBuffer, length); + Buffer.BlockCopy(data, index, _buffer, bytesInBuffer, toCopy); + index += toCopy; + length -= toCopy; + bytesInBuffer += toCopy; + if (bytesInBuffer == BlockSize) + { + ByteIntegerConverter.Array16LoadBigEndian64(out block, _buffer, 0); + Sha512Internal.Core(out _state, ref _state, ref block); + CryptoBytes.InternalWipe(_buffer, 0, _buffer.Length); + bytesInBuffer = 0; + } + } + // Hash complete blocks without copying + while (length >= BlockSize) + { + ByteIntegerConverter.Array16LoadBigEndian64(out block, data, index); + Sha512Internal.Core(out _state, ref _state, ref block); + index += BlockSize; + length -= BlockSize; + } + // Copy remainder into buffer + if (length > 0) + { + Buffer.BlockCopy(data, index, _buffer, bytesInBuffer, length); + } + } + + /// + /// Finalizes SHA-512 hashing + /// + /// Output buffer + public void Finalize(ArraySegment output) + { + Preconditions.NotNull(output.Array, nameof(output)); + if (output.Count != 64) + throw new ArgumentException("Output should be 64 in length"); + + Update(_padding, 0, _padding.Length); + Array16 block; + ByteIntegerConverter.Array16LoadBigEndian64(out block, _buffer, 0); + CryptoBytes.InternalWipe(_buffer, 0, _buffer.Length); + int bytesInBuffer = (int)_totalBytes & (BlockSize - 1); + if (bytesInBuffer > BlockSize - 16) + { + Sha512Internal.Core(out _state, ref _state, ref block); + block = default(Array16); + } + block.x15 = (_totalBytes - 1) * 8; + Sha512Internal.Core(out _state, ref _state, ref block); + + ByteIntegerConverter.StoreBigEndian64(output.Array, output.Offset + 0, _state.x0); + ByteIntegerConverter.StoreBigEndian64(output.Array, output.Offset + 8, _state.x1); + ByteIntegerConverter.StoreBigEndian64(output.Array, output.Offset + 16, _state.x2); + ByteIntegerConverter.StoreBigEndian64(output.Array, output.Offset + 24, _state.x3); + ByteIntegerConverter.StoreBigEndian64(output.Array, output.Offset + 32, _state.x4); + ByteIntegerConverter.StoreBigEndian64(output.Array, output.Offset + 40, _state.x5); + ByteIntegerConverter.StoreBigEndian64(output.Array, output.Offset + 48, _state.x6); + ByteIntegerConverter.StoreBigEndian64(output.Array, output.Offset + 56, _state.x7); + _state = default(Array8); + } + + /// + /// Finalizes SHA-512 hashing. + /// + /// Hash bytes + public byte[] Finalize() + { + var result = new byte[64]; + Finalize(new ArraySegment(result)); + return result; + } + + /// + /// Calculates SHA-512 hash value for the given bytes array. + /// + /// Data bytes array + /// Hash bytes + public static byte[] Hash(byte[] data) + { + return Hash(data, 0, data.Length); + } + + /// + /// Calculates SHA-512 hash value for the given bytes array. + /// + /// Data bytes array + /// Offset of byte sequence + /// Sequence length + /// Hash bytes + public static byte[] Hash(byte[] data, int index, int length) + { + var hasher = new Sha512(); + hasher.Update(data, index, length); + return hasher.Finalize(); + } + } +} diff --git a/src/Discord.Net.Rest/Net/ED25519/Sha512Internal.cs b/src/Discord.Net.Rest/Net/ED25519/Sha512Internal.cs new file mode 100644 index 000000000..df8842d8d --- /dev/null +++ b/src/Discord.Net.Rest/Net/ED25519/Sha512Internal.cs @@ -0,0 +1,447 @@ +using System; +using System.Collections.Generic; + +namespace Discord.Net.ED25519 +{ + internal static class Sha512Internal + { + private static readonly ulong[] K = new ulong[] + { + 0x428a2f98d728ae22,0x7137449123ef65cd,0xb5c0fbcfec4d3b2f,0xe9b5dba58189dbbc, + 0x3956c25bf348b538,0x59f111f1b605d019,0x923f82a4af194f9b,0xab1c5ed5da6d8118, + 0xd807aa98a3030242,0x12835b0145706fbe,0x243185be4ee4b28c,0x550c7dc3d5ffb4e2, + 0x72be5d74f27b896f,0x80deb1fe3b1696b1,0x9bdc06a725c71235,0xc19bf174cf692694, + 0xe49b69c19ef14ad2,0xefbe4786384f25e3,0x0fc19dc68b8cd5b5,0x240ca1cc77ac9c65, + 0x2de92c6f592b0275,0x4a7484aa6ea6e483,0x5cb0a9dcbd41fbd4,0x76f988da831153b5, + 0x983e5152ee66dfab,0xa831c66d2db43210,0xb00327c898fb213f,0xbf597fc7beef0ee4, + 0xc6e00bf33da88fc2,0xd5a79147930aa725,0x06ca6351e003826f,0x142929670a0e6e70, + 0x27b70a8546d22ffc,0x2e1b21385c26c926,0x4d2c6dfc5ac42aed,0x53380d139d95b3df, + 0x650a73548baf63de,0x766a0abb3c77b2a8,0x81c2c92e47edaee6,0x92722c851482353b, + 0xa2bfe8a14cf10364,0xa81a664bbc423001,0xc24b8b70d0f89791,0xc76c51a30654be30, + 0xd192e819d6ef5218,0xd69906245565a910,0xf40e35855771202a,0x106aa07032bbd1b8, + 0x19a4c116b8d2d0c8,0x1e376c085141ab53,0x2748774cdf8eeb99,0x34b0bcb5e19b48a8, + 0x391c0cb3c5c95a63,0x4ed8aa4ae3418acb,0x5b9cca4f7763e373,0x682e6ff3d6b2b8a3, + 0x748f82ee5defb2fc,0x78a5636f43172f60,0x84c87814a1f0ab72,0x8cc702081a6439ec, + 0x90befffa23631e28,0xa4506cebde82bde9,0xbef9a3f7b2c67915,0xc67178f2e372532b, + 0xca273eceea26619c,0xd186b8c721c0c207,0xeada7dd6cde0eb1e,0xf57d4f7fee6ed178, + 0x06f067aa72176fba,0x0a637dc5a2c898a6,0x113f9804bef90dae,0x1b710b35131c471b, + 0x28db77f523047d84,0x32caab7b40c72493,0x3c9ebe0a15c9bebc,0x431d67c49c100d4c, + 0x4cc5d4becb3e42b6,0x597f299cfc657e2a,0x5fcb6fab3ad6faec,0x6c44198c4a475817 + }; + + internal static void Sha512Init(out Array8 state) + { + state.x0 = 0x6a09e667f3bcc908; + state.x1 = 0xbb67ae8584caa73b; + state.x2 = 0x3c6ef372fe94f82b; + state.x3 = 0xa54ff53a5f1d36f1; + state.x4 = 0x510e527fade682d1; + state.x5 = 0x9b05688c2b3e6c1f; + state.x6 = 0x1f83d9abfb41bd6b; + state.x7 = 0x5be0cd19137e2179; + } + + internal static void Core(out Array8 outputState, ref Array8 inputState, ref Array16 input) + { + unchecked + { + var a = inputState.x0; + var b = inputState.x1; + var c = inputState.x2; + var d = inputState.x3; + var e = inputState.x4; + var f = inputState.x5; + var g = inputState.x6; + var h = inputState.x7; + + var w0 = input.x0; + var w1 = input.x1; + var w2 = input.x2; + var w3 = input.x3; + var w4 = input.x4; + var w5 = input.x5; + var w6 = input.x6; + var w7 = input.x7; + var w8 = input.x8; + var w9 = input.x9; + var w10 = input.x10; + var w11 = input.x11; + var w12 = input.x12; + var w13 = input.x13; + var w14 = input.x14; + var w15 = input.x15; + + int t = 0; + while (true) + { + ulong t1, t2; + + {//0 + t1 = h + + ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) + + //Sigma1(e) + ((e & f) ^ (~e & g)) + //Ch(e,f,g) + K[t] + w0; + t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) + + //Sigma0(a) + ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c) + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + t++; + } + {//1 + t1 = h + + ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) + + //Sigma1(e) + ((e & f) ^ (~e & g)) + //Ch(e,f,g) + K[t] + w1; + t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) + + //Sigma0(a) + ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c) + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + t++; + } + {//2 + t1 = h + + ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) + + //Sigma1(e) + ((e & f) ^ (~e & g)) + //Ch(e,f,g) + K[t] + w2; + t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) + + //Sigma0(a) + ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c) + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + t++; + } + {//3 + t1 = h + + ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) + + //Sigma1(e) + ((e & f) ^ (~e & g)) + //Ch(e,f,g) + K[t] + w3; + t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) + + //Sigma0(a) + ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c) + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + t++; + } + {//4 + t1 = h + + ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) + + //Sigma1(e) + ((e & f) ^ (~e & g)) + //Ch(e,f,g) + K[t] + w4; + t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) + + //Sigma0(a) + ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c) + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + t++; + } + {//5 + t1 = h + + ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) + + //Sigma1(e) + ((e & f) ^ (~e & g)) + //Ch(e,f,g) + K[t] + w5; + t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) + + //Sigma0(a) + ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c) + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + t++; + } + {//6 + t1 = h + + ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) + + //Sigma1(e) + ((e & f) ^ (~e & g)) + //Ch(e,f,g) + K[t] + w6; + t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) + + //Sigma0(a) + ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c) + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + t++; + } + {//7 + t1 = h + + ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) + + //Sigma1(e) + ((e & f) ^ (~e & g)) + //Ch(e,f,g) + K[t] + w7; + t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) + + //Sigma0(a) + ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c) + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + t++; + } + {//8 + t1 = h + + ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) + + //Sigma1(e) + ((e & f) ^ (~e & g)) + //Ch(e,f,g) + K[t] + w8; + t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) + + //Sigma0(a) + ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c) + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + t++; + } + {//9 + t1 = h + + ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) + + //Sigma1(e) + ((e & f) ^ (~e & g)) + //Ch(e,f,g) + K[t] + w9; + t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) + + //Sigma0(a) + ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c) + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + t++; + } + {//10 + t1 = h + + ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) + + //Sigma1(e) + ((e & f) ^ (~e & g)) + //Ch(e,f,g) + K[t] + w10; + t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) + + //Sigma0(a) + ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c) + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + t++; + } + {//11 + t1 = h + + ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) + + //Sigma1(e) + ((e & f) ^ (~e & g)) + //Ch(e,f,g) + K[t] + w11; + t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) + + //Sigma0(a) + ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c) + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + t++; + } + {//12 + t1 = h + + ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) + + //Sigma1(e) + ((e & f) ^ (~e & g)) + //Ch(e,f,g) + K[t] + w12; + t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) + + //Sigma0(a) + ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c) + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + t++; + } + {//13 + t1 = h + + ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) + + //Sigma1(e) + ((e & f) ^ (~e & g)) + //Ch(e,f,g) + K[t] + w13; + t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) + + //Sigma0(a) + ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c) + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + t++; + } + {//14 + t1 = h + + ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) + + //Sigma1(e) + ((e & f) ^ (~e & g)) + //Ch(e,f,g) + K[t] + w14; + t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) + + //Sigma0(a) + ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c) + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + t++; + } + {//15 + t1 = h + + ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) + + //Sigma1(e) + ((e & f) ^ (~e & g)) + //Ch(e,f,g) + K[t] + w15; + t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) + + //Sigma0(a) + ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c) + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + t++; + } + if (t == 80) + break; + + w0 += ((w14 >> 19) ^ (w14 << (64 - 19)) ^ (w14 >> 61) ^ (w14 << (64 - 61)) ^ (w14 >> 6)) + + w9 + + ((w1 >> 1) ^ (w1 << (64 - 1)) ^ (w1 >> 8) ^ (w1 << (64 - 8)) ^ (w1 >> 7)); + w1 += ((w15 >> 19) ^ (w15 << (64 - 19)) ^ (w15 >> 61) ^ (w15 << (64 - 61)) ^ (w15 >> 6)) + + w10 + + ((w2 >> 1) ^ (w2 << (64 - 1)) ^ (w2 >> 8) ^ (w2 << (64 - 8)) ^ (w2 >> 7)); + w2 += ((w0 >> 19) ^ (w0 << (64 - 19)) ^ (w0 >> 61) ^ (w0 << (64 - 61)) ^ (w0 >> 6)) + + w11 + + ((w3 >> 1) ^ (w3 << (64 - 1)) ^ (w3 >> 8) ^ (w3 << (64 - 8)) ^ (w3 >> 7)); + w3 += ((w1 >> 19) ^ (w1 << (64 - 19)) ^ (w1 >> 61) ^ (w1 << (64 - 61)) ^ (w1 >> 6)) + + w12 + + ((w4 >> 1) ^ (w4 << (64 - 1)) ^ (w4 >> 8) ^ (w4 << (64 - 8)) ^ (w4 >> 7)); + w4 += ((w2 >> 19) ^ (w2 << (64 - 19)) ^ (w2 >> 61) ^ (w2 << (64 - 61)) ^ (w2 >> 6)) + + w13 + + ((w5 >> 1) ^ (w5 << (64 - 1)) ^ (w5 >> 8) ^ (w5 << (64 - 8)) ^ (w5 >> 7)); + w5 += ((w3 >> 19) ^ (w3 << (64 - 19)) ^ (w3 >> 61) ^ (w3 << (64 - 61)) ^ (w3 >> 6)) + + w14 + + ((w6 >> 1) ^ (w6 << (64 - 1)) ^ (w6 >> 8) ^ (w6 << (64 - 8)) ^ (w6 >> 7)); + w6 += ((w4 >> 19) ^ (w4 << (64 - 19)) ^ (w4 >> 61) ^ (w4 << (64 - 61)) ^ (w4 >> 6)) + + w15 + + ((w7 >> 1) ^ (w7 << (64 - 1)) ^ (w7 >> 8) ^ (w7 << (64 - 8)) ^ (w7 >> 7)); + w7 += ((w5 >> 19) ^ (w5 << (64 - 19)) ^ (w5 >> 61) ^ (w5 << (64 - 61)) ^ (w5 >> 6)) + + w0 + + ((w8 >> 1) ^ (w8 << (64 - 1)) ^ (w8 >> 8) ^ (w8 << (64 - 8)) ^ (w8 >> 7)); + w8 += ((w6 >> 19) ^ (w6 << (64 - 19)) ^ (w6 >> 61) ^ (w6 << (64 - 61)) ^ (w6 >> 6)) + + w1 + + ((w9 >> 1) ^ (w9 << (64 - 1)) ^ (w9 >> 8) ^ (w9 << (64 - 8)) ^ (w9 >> 7)); + w9 += ((w7 >> 19) ^ (w7 << (64 - 19)) ^ (w7 >> 61) ^ (w7 << (64 - 61)) ^ (w7 >> 6)) + + w2 + + ((w10 >> 1) ^ (w10 << (64 - 1)) ^ (w10 >> 8) ^ (w10 << (64 - 8)) ^ (w10 >> 7)); + w10 += ((w8 >> 19) ^ (w8 << (64 - 19)) ^ (w8 >> 61) ^ (w8 << (64 - 61)) ^ (w8 >> 6)) + + w3 + + ((w11 >> 1) ^ (w11 << (64 - 1)) ^ (w11 >> 8) ^ (w11 << (64 - 8)) ^ (w11 >> 7)); + w11 += ((w9 >> 19) ^ (w9 << (64 - 19)) ^ (w9 >> 61) ^ (w9 << (64 - 61)) ^ (w9 >> 6)) + + w4 + + ((w12 >> 1) ^ (w12 << (64 - 1)) ^ (w12 >> 8) ^ (w12 << (64 - 8)) ^ (w12 >> 7)); + w12 += ((w10 >> 19) ^ (w10 << (64 - 19)) ^ (w10 >> 61) ^ (w10 << (64 - 61)) ^ (w10 >> 6)) + + w5 + + ((w13 >> 1) ^ (w13 << (64 - 1)) ^ (w13 >> 8) ^ (w13 << (64 - 8)) ^ (w13 >> 7)); + w13 += ((w11 >> 19) ^ (w11 << (64 - 19)) ^ (w11 >> 61) ^ (w11 << (64 - 61)) ^ (w11 >> 6)) + + w6 + + ((w14 >> 1) ^ (w14 << (64 - 1)) ^ (w14 >> 8) ^ (w14 << (64 - 8)) ^ (w14 >> 7)); + w14 += ((w12 >> 19) ^ (w12 << (64 - 19)) ^ (w12 >> 61) ^ (w12 << (64 - 61)) ^ (w12 >> 6)) + + w7 + + ((w15 >> 1) ^ (w15 << (64 - 1)) ^ (w15 >> 8) ^ (w15 << (64 - 8)) ^ (w15 >> 7)); + w15 += ((w13 >> 19) ^ (w13 << (64 - 19)) ^ (w13 >> 61) ^ (w13 << (64 - 61)) ^ (w13 >> 6)) + + w8 + + ((w0 >> 1) ^ (w0 << (64 - 1)) ^ (w0 >> 8) ^ (w0 << (64 - 8)) ^ (w0 >> 7)); + } + + outputState.x0 = inputState.x0 + a; + outputState.x1 = inputState.x1 + b; + outputState.x2 = inputState.x2 + c; + outputState.x3 = inputState.x3 + d; + outputState.x4 = inputState.x4 + e; + outputState.x5 = inputState.x5 + f; + outputState.x6 = inputState.x6 + g; + outputState.x7 = inputState.x7 + h; + } + } + } +} diff --git a/src/Discord.Net.Rest/Net/Queue/ClientBucket.cs b/src/Discord.Net.Rest/Net/Queue/ClientBucket.cs index cd9d8aa54..e726a08cf 100644 --- a/src/Discord.Net.Rest/Net/Queue/ClientBucket.cs +++ b/src/Discord.Net.Rest/Net/Queue/ClientBucket.cs @@ -10,14 +10,14 @@ namespace Discord.Net.Queue internal struct ClientBucket { private static readonly ImmutableDictionary DefsByType; - private static readonly ImmutableDictionary DefsById; + private static readonly ImmutableDictionary DefsById; static ClientBucket() { var buckets = new[] { - new ClientBucket(ClientBucketType.Unbucketed, "", 10, 10), - new ClientBucket(ClientBucketType.SendEdit, "", 10, 10) + new ClientBucket(ClientBucketType.Unbucketed, BucketId.Create(null, "", null), 10, 10), + new ClientBucket(ClientBucketType.SendEdit, BucketId.Create(null, "", null), 10, 10) }; var builder = ImmutableDictionary.CreateBuilder(); @@ -25,21 +25,21 @@ namespace Discord.Net.Queue builder.Add(bucket.Type, bucket); DefsByType = builder.ToImmutable(); - var builder2 = ImmutableDictionary.CreateBuilder(); + var builder2 = ImmutableDictionary.CreateBuilder(); foreach (var bucket in buckets) builder2.Add(bucket.Id, bucket); DefsById = builder2.ToImmutable(); } public static ClientBucket Get(ClientBucketType type) => DefsByType[type]; - public static ClientBucket Get(string id) => DefsById[id]; + public static ClientBucket Get(BucketId id) => DefsById[id]; public ClientBucketType Type { get; } - public string Id { get; } + public BucketId Id { get; } public int WindowCount { get; } public int WindowSeconds { get; } - public ClientBucket(ClientBucketType type, string id, int count, int seconds) + public ClientBucket(ClientBucketType type, BucketId id, int count, int seconds) { Type = type; Id = id; diff --git a/src/Discord.Net.Rest/Net/Queue/GatewayBucket.cs b/src/Discord.Net.Rest/Net/Queue/GatewayBucket.cs new file mode 100644 index 000000000..aa849018a --- /dev/null +++ b/src/Discord.Net.Rest/Net/Queue/GatewayBucket.cs @@ -0,0 +1,53 @@ +using System.Collections.Immutable; + +namespace Discord.Net.Queue +{ + public enum GatewayBucketType + { + Unbucketed = 0, + Identify = 1, + PresenceUpdate = 2, + } + internal struct GatewayBucket + { + private static readonly ImmutableDictionary DefsByType; + private static readonly ImmutableDictionary DefsById; + + static GatewayBucket() + { + var buckets = new[] + { + // Limit is 120/60s, but 3 will be reserved for heartbeats (2 for possible heartbeats in the same timeframe and a possible failure) + new GatewayBucket(GatewayBucketType.Unbucketed, BucketId.Create(null, "", null), 117, 60), + new GatewayBucket(GatewayBucketType.Identify, BucketId.Create(null, "", null), 1, 5), + new GatewayBucket(GatewayBucketType.PresenceUpdate, BucketId.Create(null, "", null), 5, 60), + }; + + var builder = ImmutableDictionary.CreateBuilder(); + foreach (var bucket in buckets) + builder.Add(bucket.Type, bucket); + DefsByType = builder.ToImmutable(); + + var builder2 = ImmutableDictionary.CreateBuilder(); + foreach (var bucket in buckets) + builder2.Add(bucket.Id, bucket); + DefsById = builder2.ToImmutable(); + } + + public static GatewayBucket Get(GatewayBucketType type) => DefsByType[type]; + public static GatewayBucket Get(BucketId id) => DefsById[id]; + + public GatewayBucketType Type { get; } + public BucketId Id { get; } + public int WindowCount { get; set; } + public int WindowSeconds { get; set; } + + public GatewayBucket(GatewayBucketType type, BucketId id, int count, int seconds) + { + Type = type; + Id = id; + WindowCount = count; + WindowSeconds = seconds; + } + } +} diff --git a/src/Discord.Net.Rest/Net/Queue/RequestQueue.cs b/src/Discord.Net.Rest/Net/Queue/RequestQueue.cs index 35d74e005..75e79eec2 100644 --- a/src/Discord.Net.Rest/Net/Queue/RequestQueue.cs +++ b/src/Discord.Net.Rest/Net/Queue/RequestQueue.cs @@ -13,9 +13,9 @@ namespace Discord.Net.Queue { internal class RequestQueue : IDisposable, IAsyncDisposable { - public event Func RateLimitTriggered; + public event Func RateLimitTriggered; - private readonly ConcurrentDictionary _buckets; + private readonly ConcurrentDictionary _buckets; private readonly SemaphoreSlim _tokenLock; private readonly CancellationTokenSource _cancelTokenSource; //Dispose token private CancellationTokenSource _clearToken; @@ -35,7 +35,7 @@ namespace Discord.Net.Queue _requestCancelToken = CancellationToken.None; _parentToken = CancellationToken.None; - _buckets = new ConcurrentDictionary(); + _buckets = new ConcurrentDictionary(); _cleanupTask = RunCleanup(); } @@ -83,16 +83,25 @@ namespace Discord.Net.Queue else request.Options.CancelToken = _requestCancelToken; - var bucket = GetOrCreateBucket(request.Options.BucketId, request); + var bucket = GetOrCreateBucket(request.Options, request); var result = await bucket.SendAsync(request).ConfigureAwait(false); createdTokenSource?.Dispose(); return result; } public async Task SendAsync(WebSocketRequest request) { - //TODO: Re-impl websocket buckets - request.CancelToken = _requestCancelToken; - await request.SendAsync().ConfigureAwait(false); + CancellationTokenSource createdTokenSource = null; + if (request.Options.CancelToken.CanBeCanceled) + { + createdTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_requestCancelToken, request.Options.CancelToken); + request.Options.CancelToken = createdTokenSource.Token; + } + else + request.Options.CancelToken = _requestCancelToken; + + var bucket = GetOrCreateBucket(request.Options, request); + await bucket.SendAsync(request).ConfigureAwait(false); + createdTokenSource?.Dispose(); } internal async Task EnterGlobalAsync(int id, RestRequest request) @@ -110,14 +119,53 @@ namespace Discord.Net.Queue { _waitUntil = DateTimeOffset.UtcNow.AddMilliseconds(info.RetryAfter.Value + (info.Lag?.TotalMilliseconds ?? 0.0)); } + internal async Task EnterGlobalAsync(int id, WebSocketRequest request) + { + //If this is a global request (unbucketed), it'll be dealt in EnterAsync + var requestBucket = GatewayBucket.Get(request.Options.BucketId); + if (requestBucket.Type == GatewayBucketType.Unbucketed) + return; + + //It's not a global request, so need to remove one from global (per-session) + var globalBucketType = GatewayBucket.Get(GatewayBucketType.Unbucketed); + var options = RequestOptions.CreateOrClone(request.Options); + options.BucketId = globalBucketType.Id; + var globalRequest = new WebSocketRequest(null, null, false, false, options); + var globalBucket = GetOrCreateBucket(options, globalRequest); + await globalBucket.TriggerAsync(id, globalRequest); + } - private RequestBucket GetOrCreateBucket(string id, RestRequest request) + private RequestBucket GetOrCreateBucket(RequestOptions options, IRequest request) + { + var bucketId = options.BucketId; + object obj = _buckets.GetOrAdd(bucketId, x => new RequestBucket(this, request, x)); + if (obj is BucketId hashBucket) + { + options.BucketId = hashBucket; + return (RequestBucket)_buckets.GetOrAdd(hashBucket, x => new RequestBucket(this, request, x)); + } + return (RequestBucket)obj; + } + internal async Task RaiseRateLimitTriggered(BucketId bucketId, RateLimitInfo? info, string endpoint) { - return _buckets.GetOrAdd(id, x => new RequestBucket(this, request, x)); + await RateLimitTriggered(bucketId, info, endpoint).ConfigureAwait(false); } - internal async Task RaiseRateLimitTriggered(string bucketId, RateLimitInfo? info) + internal (RequestBucket, BucketId) UpdateBucketHash(BucketId id, string discordHash) + { + if (!id.IsHashBucket) + { + var bucket = BucketId.Create(discordHash, id); + var hashReqQueue = (RequestBucket)_buckets.GetOrAdd(bucket, _buckets[id]); + _buckets.AddOrUpdate(id, bucket, (oldBucket, oldObj) => bucket); + return (hashReqQueue, bucket); + } + return (null, null); + } + + public void ClearGatewayBuckets() { - await RateLimitTriggered(bucketId, info).ConfigureAwait(false); + foreach (var gwBucket in (GatewayBucketType[])Enum.GetValues(typeof(GatewayBucketType))) + _buckets.TryRemove(GatewayBucket.Get(gwBucket).Id, out _); } private async Task RunCleanup() @@ -127,10 +175,15 @@ namespace Discord.Net.Queue while (!_cancelTokenSource.IsCancellationRequested) { var now = DateTimeOffset.UtcNow; - foreach (var bucket in _buckets.Select(x => x.Value)) + foreach (var bucket in _buckets.Where(x => x.Value is RequestBucket).Select(x => (RequestBucket)x.Value)) { if ((now - bucket.LastAttemptAt).TotalMinutes > 1.0) + { + if (bucket.Id.IsHashBucket) + foreach (var redirectBucket in _buckets.Where(x => x.Value == bucket.Id).Select(x => (BucketId)x.Value)) + _buckets.TryRemove(redirectBucket, out _); //remove redirections if hash bucket _buckets.TryRemove(bucket.Id, out _); + } } await Task.Delay(60000, _cancelTokenSource.Token).ConfigureAwait(false); //Runs each minute } diff --git a/src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs b/src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs index 771923cd4..408c8bbdb 100644 --- a/src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs +++ b/src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs @@ -1,10 +1,11 @@ +using Discord.API; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using System; #if DEBUG_LIMITS using System.Diagnostics; #endif using System.IO; +using System.Linq; using System.Net; using System.Threading; using System.Threading.Tasks; @@ -19,12 +20,13 @@ namespace Discord.Net.Queue private readonly RequestQueue _queue; private int _semaphore; private DateTimeOffset? _resetTick; + private RequestBucket _redirectBucket; - public string Id { get; private set; } + public BucketId Id { get; private set; } public int WindowCount { get; private set; } public DateTimeOffset LastAttemptAt { get; private set; } - public RequestBucket(RequestQueue queue, RestRequest request, string id) + public RequestBucket(RequestQueue queue, IRequest request, BucketId id) { _queue = queue; Id = id; @@ -33,6 +35,8 @@ namespace Discord.Net.Queue if (request.Options.IsClientBucket) WindowCount = ClientBucket.Get(request.Options.BucketId).WindowCount; + else if (request.Options.IsGatewayBucket) + WindowCount = GatewayBucket.Get(request.Options.BucketId).WindowCount; else WindowCount = 1; //Only allow one request until we get a header back _semaphore = WindowCount; @@ -52,6 +56,8 @@ namespace Discord.Net.Queue { await _queue.EnterGlobalAsync(id, request).ConfigureAwait(false); await EnterAsync(id, request).ConfigureAwait(false); + if (_redirectBucket != null) + return await _redirectBucket.SendAsync(request); #if DEBUG_LIMITS Debug.WriteLine($"[{id}] Sending..."); @@ -60,7 +66,9 @@ namespace Discord.Net.Queue try { var response = await request.SendAsync().ConfigureAwait(false); - info = new RateLimitInfo(response.Headers); + info = new RateLimitInfo(response.Headers, request.Endpoint); + + request.Options.ExecuteRatelimitCallback(info); if (response.StatusCode < (HttpStatusCode)200 || response.StatusCode >= (HttpStatusCode)300) { @@ -81,7 +89,7 @@ namespace Discord.Net.Queue #endif UpdateRateLimit(id, request, info, true); } - await _queue.RaiseRateLimitTriggered(Id, info).ConfigureAwait(false); + await _queue.RaiseRateLimitTriggered(Id, info, $"{request.Method} {request.Endpoint}").ConfigureAwait(false); continue; //Retry case HttpStatusCode.BadGateway: //502 #if DEBUG_LIMITS @@ -92,23 +100,27 @@ namespace Discord.Net.Queue continue; //Retry default: - int? code = null; - string reason = null; + API.DiscordError error = null; if (response.Stream != null) { try { - using (var reader = new StreamReader(response.Stream)) - using (var jsonReader = new JsonTextReader(reader)) - { - var json = JToken.Load(jsonReader); - try { code = json.Value("code"); } catch { }; - try { reason = json.Value("message"); } catch { }; - } + using var reader = new StreamReader(response.Stream); + using var jsonReader = new JsonTextReader(reader); + + error = Discord.Rest.DiscordRestClient.Serializer.Deserialize(jsonReader); } catch { } } - throw new HttpException(response.StatusCode, request, code, reason); + throw new HttpException( + response.StatusCode, + request, + error?.Code, + error?.Message, + error?.Errors.IsSpecified == true ? + error.Errors.Value.Select(x => new DiscordJsonError(x.Name.GetValueOrDefault("root"), x.Errors.Select(y => new DiscordError(y.Code, y.Message)).ToArray())).ToArray() : + null + ); } } else @@ -151,8 +163,68 @@ namespace Discord.Net.Queue } } } + public async Task SendAsync(WebSocketRequest request) + { + int id = Interlocked.Increment(ref nextId); +#if DEBUG_LIMITS + Debug.WriteLine($"[{id}] Start"); +#endif + LastAttemptAt = DateTimeOffset.UtcNow; + while (true) + { + await _queue.EnterGlobalAsync(id, request).ConfigureAwait(false); + await EnterAsync(id, request).ConfigureAwait(false); + +#if DEBUG_LIMITS + Debug.WriteLine($"[{id}] Sending..."); +#endif + try + { + await request.SendAsync().ConfigureAwait(false); + return; + } + catch (TimeoutException) + { +#if DEBUG_LIMITS + Debug.WriteLine($"[{id}] Timeout"); +#endif + if ((request.Options.RetryMode & RetryMode.RetryTimeouts) == 0) + throw; + + await Task.Delay(500).ConfigureAwait(false); + continue; //Retry + } + /*catch (Exception) + { +#if DEBUG_LIMITS + Debug.WriteLine($"[{id}] Error"); +#endif + if ((request.Options.RetryMode & RetryMode.RetryErrors) == 0) + throw; + + await Task.Delay(500); + continue; //Retry + }*/ + finally + { + UpdateRateLimit(id, request, default(RateLimitInfo), false); +#if DEBUG_LIMITS + Debug.WriteLine($"[{id}] Stop"); +#endif + } + } + } - private async Task EnterAsync(int id, RestRequest request) + internal async Task TriggerAsync(int id, IRequest request) + { +#if DEBUG_LIMITS + Debug.WriteLine($"[{id}] Trigger Bucket"); +#endif + await EnterAsync(id, request).ConfigureAwait(false); + UpdateRateLimit(id, request, default(RateLimitInfo), false); + } + + private async Task EnterAsync(int id, IRequest request) { int windowCount; DateTimeOffset? resetAt; @@ -160,6 +232,9 @@ namespace Discord.Net.Queue while (true) { + if (_redirectBucket != null) + break; + if (DateTimeOffset.UtcNow > request.TimeoutAt || request.Options.CancelToken.IsCancellationRequested) { if (!isRateLimited) @@ -175,12 +250,36 @@ namespace Discord.Net.Queue } DateTimeOffset? timeoutAt = request.TimeoutAt; - if (windowCount > 0 && Interlocked.Decrement(ref _semaphore) < 0) + int semaphore = Interlocked.Decrement(ref _semaphore); + if (windowCount > 0 && semaphore < 0) { if (!isRateLimited) { + bool ignoreRatelimit = false; isRateLimited = true; - await _queue.RaiseRateLimitTriggered(Id, null).ConfigureAwait(false); + switch (request) + { + case RestRequest restRequest: + await _queue.RaiseRateLimitTriggered(Id, null, $"{restRequest.Method} {restRequest.Endpoint}").ConfigureAwait(false); + break; + case WebSocketRequest webSocketRequest: + if (webSocketRequest.IgnoreLimit) + { + ignoreRatelimit = true; + break; + } + await _queue.RaiseRateLimitTriggered(Id, null, Id.Endpoint).ConfigureAwait(false); + break; + default: + throw new InvalidOperationException("Unknown request type"); + } + if (ignoreRatelimit) + { +#if DEBUG_LIMITS + Debug.WriteLine($"[{id}] Ignoring ratelimit"); +#endif + break; + } } ThrowRetryLimit(request); @@ -210,30 +309,61 @@ namespace Discord.Net.Queue } #if DEBUG_LIMITS else - Debug.WriteLine($"[{id}] Entered Semaphore ({_semaphore}/{WindowCount} remaining)"); + Debug.WriteLine($"[{id}] Entered Semaphore ({semaphore}/{WindowCount} remaining)"); #endif break; } } - private void UpdateRateLimit(int id, RestRequest request, RateLimitInfo info, bool is429) + private void UpdateRateLimit(int id, IRequest request, RateLimitInfo info, bool is429, bool redirected = false) { if (WindowCount == 0) return; lock (_lock) { + if (redirected) + { + Interlocked.Decrement(ref _semaphore); //we might still hit a real ratelimit if all tickets were already taken, can't do much about it since we didn't know they were the same +#if DEBUG_LIMITS + Debug.WriteLine($"[{id}] Decrease Semaphore"); +#endif + } bool hasQueuedReset = _resetTick != null; + + if (info.Bucket != null && !redirected) + { + (RequestBucket, BucketId) hashBucket = _queue.UpdateBucketHash(Id, info.Bucket); + if (!(hashBucket.Item1 is null) && !(hashBucket.Item2 is null)) + { + if (hashBucket.Item1 == this) //this bucket got promoted to a hash queue + { + Id = hashBucket.Item2; +#if DEBUG_LIMITS + Debug.WriteLine($"[{id}] Promoted to Hash Bucket ({hashBucket.Item2})"); +#endif + } + else + { + _redirectBucket = hashBucket.Item1; //this request should be part of another bucket, this bucket will be disabled, redirect everything + _redirectBucket.UpdateRateLimit(id, request, info, is429, redirected: true); //update the hash bucket ratelimit +#if DEBUG_LIMITS + Debug.WriteLine($"[{id}] Redirected to {_redirectBucket.Id}"); +#endif + return; + } + } + } + if (info.Limit.HasValue && WindowCount != info.Limit.Value) { WindowCount = info.Limit.Value; - _semaphore = info.Remaining.Value; + _semaphore = is429 ? 0 : info.Remaining.Value; #if DEBUG_LIMITS Debug.WriteLine($"[{id}] Upgraded Semaphore to {info.Remaining.Value}/{WindowCount}"); #endif } - var now = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); DateTimeOffset? resetTick = null; //Using X-RateLimit-Remaining causes a race condition @@ -245,21 +375,23 @@ namespace Discord.Net.Queue if (info.RetryAfter.HasValue) { //RetryAfter is more accurate than Reset, where available - resetTick = DateTimeOffset.UtcNow.AddMilliseconds(info.RetryAfter.Value); + resetTick = DateTimeOffset.UtcNow.AddSeconds(info.RetryAfter.Value); #if DEBUG_LIMITS Debug.WriteLine($"[{id}] Retry-After: {info.RetryAfter.Value} ({info.RetryAfter.Value} ms)"); #endif } - else if (info.ResetAfter.HasValue && (request.Options.UseSystemClock.HasValue ? !request.Options.UseSystemClock.Value : false)) - { - resetTick = DateTimeOffset.UtcNow.Add(info.ResetAfter.Value); - } + else if (info.ResetAfter.HasValue && (request.Options.UseSystemClock.HasValue && !request.Options.UseSystemClock.Value)) + { + resetTick = DateTimeOffset.UtcNow.Add(info.ResetAfter.Value); +#if DEBUG_LIMITS + Debug.WriteLine($"[{id}] Reset-After: {info.ResetAfter.Value} ({info.ResetAfter?.TotalMilliseconds} ms)"); +#endif + } else if (info.Reset.HasValue) { resetTick = info.Reset.Value.AddSeconds(info.Lag?.TotalSeconds ?? 1.0); - /* millisecond precision makes this unnecessary, retaining in case of regression - + /* millisecond precision makes this unnecessary, retaining in case of regression if (request.Options.IsReactionBucket) resetTick = DateTimeOffset.Now.AddMilliseconds(250); */ @@ -269,17 +401,34 @@ namespace Discord.Net.Queue Debug.WriteLine($"[{id}] X-RateLimit-Reset: {info.Reset.Value.ToUnixTimeSeconds()} ({diff} ms, {info.Lag?.TotalMilliseconds} ms lag)"); #endif } - else if (request.Options.IsClientBucket && request.Options.BucketId != null) + else if (request.Options.IsClientBucket && Id != null) + { + resetTick = DateTimeOffset.UtcNow.AddSeconds(ClientBucket.Get(Id).WindowSeconds); +#if DEBUG_LIMITS + Debug.WriteLine($"[{id}] Client Bucket ({ClientBucket.Get(Id).WindowSeconds * 1000} ms)"); +#endif + } + else if (request.Options.IsGatewayBucket && request.Options.BucketId != null) { - resetTick = DateTimeOffset.UtcNow.AddSeconds(ClientBucket.Get(request.Options.BucketId).WindowSeconds); + resetTick = DateTimeOffset.UtcNow.AddSeconds(GatewayBucket.Get(request.Options.BucketId).WindowSeconds); +#if DEBUG_LIMITS + Debug.WriteLine($"[{id}] Gateway Bucket ({GatewayBucket.Get(request.Options.BucketId).WindowSeconds * 1000} ms)"); +#endif + if (!hasQueuedReset) + { + _resetTick = resetTick; + LastAttemptAt = resetTick.Value; #if DEBUG_LIMITS - Debug.WriteLine($"[{id}] Client Bucket ({ClientBucket.Get(request.Options.BucketId).WindowSeconds * 1000} ms)"); + Debug.WriteLine($"[{id}] Reset in {(int)Math.Ceiling((resetTick - DateTimeOffset.UtcNow).Value.TotalMilliseconds)} ms"); #endif + var _ = QueueReset(id, (int)Math.Ceiling((_resetTick.Value - DateTimeOffset.UtcNow).TotalMilliseconds), request); + } + return; } if (resetTick == null) { - WindowCount = 0; //No rate limit info, disable limits on this bucket (should only ever happen with a user token) + WindowCount = 0; //No rate limit info, disable limits on this bucket #if DEBUG_LIMITS Debug.WriteLine($"[{id}] Disabled Semaphore"); #endif @@ -289,19 +438,19 @@ namespace Discord.Net.Queue if (!hasQueuedReset || resetTick > _resetTick) { _resetTick = resetTick; - LastAttemptAt = resetTick.Value; //Make sure we dont destroy this until after its been reset + LastAttemptAt = resetTick.Value; //Make sure we don't destroy this until after its been reset #if DEBUG_LIMITS Debug.WriteLine($"[{id}] Reset in {(int)Math.Ceiling((resetTick - DateTimeOffset.UtcNow).Value.TotalMilliseconds)} ms"); #endif if (!hasQueuedReset) { - var _ = QueueReset(id, (int)Math.Ceiling((_resetTick.Value - DateTimeOffset.UtcNow).TotalMilliseconds)); + var _ = QueueReset(id, (int)Math.Ceiling((_resetTick.Value - DateTimeOffset.UtcNow).TotalMilliseconds), request); } } } } - private async Task QueueReset(int id, int millis) + private async Task QueueReset(int id, int millis, IRequest request) { while (true) { @@ -310,7 +459,7 @@ namespace Discord.Net.Queue lock (_lock) { millis = (int)Math.Ceiling((_resetTick.Value - DateTimeOffset.UtcNow).TotalMilliseconds); - if (millis <= 0) //Make sure we havent gotten a more accurate reset time + if (millis <= 0) //Make sure we haven't gotten a more accurate reset time { #if DEBUG_LIMITS Debug.WriteLine($"[{id}] * Reset *"); @@ -323,7 +472,7 @@ namespace Discord.Net.Queue } } - private void ThrowRetryLimit(RestRequest request) + private void ThrowRetryLimit(IRequest request) { if ((request.Options.RetryMode & RetryMode.RetryRatelimit) == 0) throw new RateLimitedException(request); diff --git a/src/Discord.Net.Rest/Net/Queue/Requests/WebSocketRequest.cs b/src/Discord.Net.Rest/Net/Queue/Requests/WebSocketRequest.cs index 81eb40b31..ebebd7bef 100644 --- a/src/Discord.Net.Rest/Net/Queue/Requests/WebSocketRequest.cs +++ b/src/Discord.Net.Rest/Net/Queue/Requests/WebSocketRequest.cs @@ -9,22 +9,22 @@ namespace Discord.Net.Queue public class WebSocketRequest : IRequest { public IWebSocketClient Client { get; } - public string BucketId { get; } public byte[] Data { get; } public bool IsText { get; } + public bool IgnoreLimit { get; } public DateTimeOffset? TimeoutAt { get; } public TaskCompletionSource Promise { get; } public RequestOptions Options { get; } public CancellationToken CancelToken { get; internal set; } - public WebSocketRequest(IWebSocketClient client, string bucketId, byte[] data, bool isText, RequestOptions options) + public WebSocketRequest(IWebSocketClient client, byte[] data, bool isText, bool ignoreLimit, RequestOptions options) { Preconditions.NotNull(options, nameof(options)); Client = client; - BucketId = bucketId; Data = data; IsText = isText; + IgnoreLimit = ignoreLimit; Options = options; TimeoutAt = options.Timeout.HasValue ? DateTimeOffset.UtcNow.AddMilliseconds(options.Timeout.Value) : (DateTimeOffset?)null; Promise = new TaskCompletionSource(); diff --git a/src/Discord.Net.Rest/Net/RateLimitInfo.cs b/src/Discord.Net.Rest/Net/RateLimitInfo.cs index 13e9e39a7..c08f30c7b 100644 --- a/src/Discord.Net.Rest/Net/RateLimitInfo.cs +++ b/src/Discord.Net.Rest/Net/RateLimitInfo.cs @@ -4,18 +4,42 @@ using System.Globalization; namespace Discord.Net { - internal struct RateLimitInfo + /// + /// Represents a REST-Based ratelimit info. + /// + public struct RateLimitInfo : IRateLimitInfo { + /// public bool IsGlobal { get; } + + /// public int? Limit { get; } + + /// public int? Remaining { get; } + + /// public int? RetryAfter { get; } + + /// public DateTimeOffset? Reset { get; } - public TimeSpan? ResetAfter { get; } + + /// + public TimeSpan? ResetAfter { get; } + + /// + public string Bucket { get; } + + /// public TimeSpan? Lag { get; } - internal RateLimitInfo(Dictionary headers) + /// + public string Endpoint { get; } + + internal RateLimitInfo(Dictionary headers, string endpoint) { + Endpoint = endpoint; + IsGlobal = headers.TryGetValue("X-RateLimit-Global", out string temp) && bool.TryParse(temp, out var isGlobal) && isGlobal; Limit = headers.TryGetValue("X-RateLimit-Limit", out temp) && @@ -26,8 +50,9 @@ namespace Discord.Net double.TryParse(temp, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var reset) ? DateTimeOffset.FromUnixTimeMilliseconds((long)(reset * 1000)) : (DateTimeOffset?)null; RetryAfter = headers.TryGetValue("Retry-After", out temp) && int.TryParse(temp, NumberStyles.None, CultureInfo.InvariantCulture, out var retryAfter) ? retryAfter : (int?)null; - ResetAfter = headers.TryGetValue("X-RateLimit-Reset-After", out temp) && - float.TryParse(temp, out var resetAfter) ? TimeSpan.FromMilliseconds((long)(resetAfter * 1000)) : (TimeSpan?)null; + ResetAfter = headers.TryGetValue("X-RateLimit-Reset-After", out temp) && + double.TryParse(temp, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var resetAfter) ? TimeSpan.FromSeconds(resetAfter) : (TimeSpan?)null; + Bucket = headers.TryGetValue("X-RateLimit-Bucket", out temp) ? temp : null; Lag = headers.TryGetValue("Date", out temp) && DateTimeOffset.TryParse(temp, CultureInfo.InvariantCulture, DateTimeStyles.None, out var date) ? DateTimeOffset.UtcNow - date : (TimeSpan?)null; } diff --git a/src/Discord.Net.Rest/Utils/HexConverter.cs b/src/Discord.Net.Rest/Utils/HexConverter.cs new file mode 100644 index 000000000..ebd959dcb --- /dev/null +++ b/src/Discord.Net.Rest/Utils/HexConverter.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.Rest +{ + internal class HexConverter + { + public static byte[] HexToByteArray(string hex) + { + if (hex.Length % 2 == 1) + throw new Exception("The binary key cannot have an odd number of digits"); + + byte[] arr = new byte[hex.Length >> 1]; + + for (int i = 0; i < hex.Length >> 1; ++i) + { + arr[i] = (byte)((GetHexVal(hex[i << 1]) << 4) + (GetHexVal(hex[(i << 1) + 1]))); + } + + return arr; + } + private static int GetHexVal(char hex) + { + int val = (int)hex; + //For uppercase A-F letters: + //return val - (val < 58 ? 48 : 55); + //For lowercase a-f letters: + //return val - (val < 58 ? 48 : 87); + //Or the two combined, but a bit slower: + return val - (val < 58 ? 48 : (val < 97 ? 55 : 87)); + } + } +} diff --git a/src/Discord.Net.WebSocket/API/Gateway/ApplicationCommandCreatedUpdatedEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/ApplicationCommandCreatedUpdatedEvent.cs new file mode 100644 index 000000000..91dcbde11 --- /dev/null +++ b/src/Discord.Net.WebSocket/API/Gateway/ApplicationCommandCreatedUpdatedEvent.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace Discord.API.Gateway +{ + internal class ApplicationCommandCreatedUpdatedEvent : ApplicationCommand + { + [JsonProperty("guild_id")] + public Optional GuildId { get; set; } + } +} diff --git a/src/Discord.Net.WebSocket/API/Gateway/ExtendedGuild.cs b/src/Discord.Net.WebSocket/API/Gateway/ExtendedGuild.cs index 910f6d909..04ee38c0b 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/ExtendedGuild.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/ExtendedGuild.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; using System; @@ -8,18 +7,29 @@ namespace Discord.API.Gateway { [JsonProperty("unavailable")] public bool? Unavailable { get; set; } + [JsonProperty("member_count")] public int MemberCount { get; set; } + [JsonProperty("large")] public bool Large { get; set; } [JsonProperty("presences")] public Presence[] Presences { get; set; } + [JsonProperty("members")] public GuildMember[] Members { get; set; } + [JsonProperty("channels")] public Channel[] Channels { get; set; } + [JsonProperty("joined_at")] public DateTimeOffset JoinedAt { get; set; } + + [JsonProperty("threads")] + public new Channel[] Threads { get; set; } + + [JsonProperty("guild_scheduled_events")] + public GuildScheduledEvent[] GuildScheduledEvents { get; set; } } } diff --git a/src/Discord.Net.WebSocket/API/Gateway/GatewayOpCode.cs b/src/Discord.Net.WebSocket/API/Gateway/GatewayOpCode.cs index 13a2bb462..6f8bf48d4 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/GatewayOpCode.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/GatewayOpCode.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 namespace Discord.API.Gateway { internal enum GatewayOpCode : byte @@ -10,7 +9,7 @@ namespace Discord.API.Gateway /// C→S - Used to associate a connection with a token and specify configuration. Identify = 2, /// C→S - Used to update client's status and current game id. - StatusUpdate = 3, + PresenceUpdate = 3, /// C→S - Used to join a particular voice channel. VoiceStateUpdate = 4, /// C→S - Used to ensure the guild's voice server is alive. diff --git a/src/Discord.Net.WebSocket/API/Gateway/GuildBanEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/GuildBanEvent.cs index 59a3304dd..a8a72e791 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/GuildBanEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/GuildBanEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/Gateway/GuildEmojiUpdateEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/GuildEmojiUpdateEvent.cs index 715341dc5..33c10e648 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/GuildEmojiUpdateEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/GuildEmojiUpdateEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/Gateway/GuildJoinRequestDeleteEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/GuildJoinRequestDeleteEvent.cs new file mode 100644 index 000000000..cb6fc5f40 --- /dev/null +++ b/src/Discord.Net.WebSocket/API/Gateway/GuildJoinRequestDeleteEvent.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace Discord.API.Gateway +{ + internal class GuildJoinRequestDeleteEvent + { + [JsonProperty("user_id")] + public ulong UserId { get; set; } + [JsonProperty("guild_id")] + public ulong GuildId { get; set; } + } +} diff --git a/src/Discord.Net.WebSocket/API/Gateway/GuildMemberAddEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/GuildMemberAddEvent.cs index 350652faf..dd42978fc 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/GuildMemberAddEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/GuildMemberAddEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/Gateway/GuildMemberRemoveEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/GuildMemberRemoveEvent.cs index 501408a7f..ec7df8fd3 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/GuildMemberRemoveEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/GuildMemberRemoveEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/Gateway/GuildMemberUpdateEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/GuildMemberUpdateEvent.cs index a234d6da5..0f6fa6f37 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/GuildMemberUpdateEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/GuildMemberUpdateEvent.cs @@ -1,10 +1,13 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; +using System; namespace Discord.API.Gateway { internal class GuildMemberUpdateEvent : GuildMember { + [JsonProperty("joined_at")] + public new DateTimeOffset? JoinedAt { get; set; } + [JsonProperty("guild_id")] public ulong GuildId { get; set; } } diff --git a/src/Discord.Net.WebSocket/API/Gateway/GuildMembersChunkEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/GuildMembersChunkEvent.cs index e401d7fa1..26114bf54 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/GuildMembersChunkEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/GuildMembersChunkEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/Gateway/GuildRoleCreateEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/GuildRoleCreateEvent.cs index 3409b1c91..3b02164d5 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/GuildRoleCreateEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/GuildRoleCreateEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/Gateway/GuildRoleDeleteEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/GuildRoleDeleteEvent.cs index dbdaeff67..d9bdb9892 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/GuildRoleDeleteEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/GuildRoleDeleteEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/Gateway/GuildRoleUpdateEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/GuildRoleUpdateEvent.cs index b04ecb182..bb6a39620 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/GuildRoleUpdateEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/GuildRoleUpdateEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/Gateway/GuildScheduledEventUserAddRemoveEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/GuildScheduledEventUserAddRemoveEvent.cs new file mode 100644 index 000000000..3fc959125 --- /dev/null +++ b/src/Discord.Net.WebSocket/API/Gateway/GuildScheduledEventUserAddRemoveEvent.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.API.Gateway +{ + internal class GuildScheduledEventUserAddRemoveEvent + { + [JsonProperty("guild_scheduled_event_id")] + public ulong EventId { get; set; } + [JsonProperty("guild_id")] + public ulong GuildId { get; set; } + [JsonProperty("user_id")] + public ulong UserId { get; set; } + } +} diff --git a/src/Discord.Net.WebSocket/API/Gateway/GuildStickerUpdateEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/GuildStickerUpdateEvent.cs new file mode 100644 index 000000000..f0ecd3a4f --- /dev/null +++ b/src/Discord.Net.WebSocket/API/Gateway/GuildStickerUpdateEvent.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace Discord.API.Gateway +{ + internal class GuildStickerUpdateEvent + { + [JsonProperty("guild_id")] + public ulong GuildId { get; set; } + + [JsonProperty("stickers")] + public Sticker[] Stickers { get; set; } + } +} diff --git a/src/Discord.Net.WebSocket/API/Gateway/GuildSyncEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/GuildSyncEvent.cs index 6b2e6c02f..ba4c1ca60 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/GuildSyncEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/GuildSyncEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/Gateway/HelloEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/HelloEvent.cs index e1ed9463c..a53a96fd8 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/HelloEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/HelloEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/Gateway/IdentifyParams.cs b/src/Discord.Net.WebSocket/API/Gateway/IdentifyParams.cs index 1e0bf71c2..96c7cb32f 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/IdentifyParams.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/IdentifyParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; using System.Collections.Generic; @@ -15,7 +14,9 @@ namespace Discord.API.Gateway public int LargeThreshold { get; set; } [JsonProperty("shard")] public Optional ShardingParams { get; set; } - [JsonProperty("guild_subscriptions")] - public Optional GuildSubscriptions { get; set; } + [JsonProperty("presence")] + public Optional Presence { get; set; } + [JsonProperty("intents")] + public Optional Intents { get; set; } } } diff --git a/src/Discord.Net.WebSocket/API/Gateway/InviteCreateEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/InviteCreateEvent.cs new file mode 100644 index 000000000..e2ddd8816 --- /dev/null +++ b/src/Discord.Net.WebSocket/API/Gateway/InviteCreateEvent.cs @@ -0,0 +1,31 @@ +using Newtonsoft.Json; +using System; + +namespace Discord.API.Gateway +{ + internal class InviteCreateEvent + { + [JsonProperty("channel_id")] + public ulong ChannelId { get; set; } + [JsonProperty("code")] + public string Code { get; set; } + [JsonProperty("created_at")] + public DateTimeOffset CreatedAt { get; set; } + [JsonProperty("guild_id")] + public Optional GuildId { get; set; } + [JsonProperty("inviter")] + public Optional Inviter { get; set; } + [JsonProperty("max_age")] + public int MaxAge { get; set; } + [JsonProperty("max_uses")] + public int MaxUses { get; set; } + [JsonProperty("target_user")] + public Optional TargetUser { get; set; } + [JsonProperty("target_user_type")] + public Optional TargetUserType { get; set; } + [JsonProperty("temporary")] + public bool Temporary { get; set; } + [JsonProperty("uses")] + public int Uses { get; set; } + } +} diff --git a/src/Discord.Net.WebSocket/API/Gateway/InviteCreatedEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/InviteCreatedEvent.cs new file mode 100644 index 000000000..1613cdfa6 --- /dev/null +++ b/src/Discord.Net.WebSocket/API/Gateway/InviteCreatedEvent.cs @@ -0,0 +1,32 @@ +using Discord.API; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.API.Gateway +{ + internal class InviteCreatedEvent + { + [JsonProperty("channel_id")] + public ulong ChannelID { get; set; } + [JsonProperty("code")] + public string InviteCode { get; set; } + [JsonProperty("timestamp")] + public Optional RawTimestamp { get; set; } + [JsonProperty("guild_id")] + public ulong? GuildID { get; set; } + [JsonProperty("inviter")] + public Optional Inviter { get; set; } + [JsonProperty("max_age")] + public int RawAge { get; set; } + [JsonProperty("max_uses")] + public int MaxUsers { get; set; } + [JsonProperty("temporary")] + public bool TempInvite { get; set; } + [JsonProperty("uses")] + public int Uses { get; set; } + } +} diff --git a/src/Discord.Net.WebSocket/API/Gateway/InviteDeleteEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/InviteDeleteEvent.cs new file mode 100644 index 000000000..54bc75595 --- /dev/null +++ b/src/Discord.Net.WebSocket/API/Gateway/InviteDeleteEvent.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; + +namespace Discord.API.Gateway +{ + internal class InviteDeleteEvent + { + [JsonProperty("channel_id")] + public ulong ChannelId { get; set; } + [JsonProperty("code")] + public string Code { get; set; } + [JsonProperty("guild_id")] + public Optional GuildId { get; set; } + } +} diff --git a/src/Discord.Net.WebSocket/API/Gateway/InviteDeletedEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/InviteDeletedEvent.cs new file mode 100644 index 000000000..6bdd337f5 --- /dev/null +++ b/src/Discord.Net.WebSocket/API/Gateway/InviteDeletedEvent.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.WebSocket +{ + internal class InviteDeletedEvent + { + [JsonProperty("channel_id")] + public ulong ChannelID { get; set; } + [JsonProperty("guild_id")] + public Optional GuildID { get; set; } + [JsonProperty("code")] + public string Code { get; set; } + } +} diff --git a/src/Discord.Net.WebSocket/API/Gateway/MessageDeleteBulkEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/MessageDeleteBulkEvent.cs index a4cf7d7eb..c503e636d 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/MessageDeleteBulkEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/MessageDeleteBulkEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; using System.Collections.Generic; diff --git a/src/Discord.Net.WebSocket/API/Gateway/Reaction.cs b/src/Discord.Net.WebSocket/API/Gateway/Reaction.cs index 62de456e2..0d17cbff8 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/Reaction.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/Reaction.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Discord.API.Gateway { @@ -10,7 +10,11 @@ namespace Discord.API.Gateway public ulong MessageId { get; set; } [JsonProperty("channel_id")] public ulong ChannelId { get; set; } + [JsonProperty("guild_id")] + public Optional GuildId { get; set; } [JsonProperty("emoji")] public Emoji Emoji { get; set; } + [JsonProperty("member")] + public Optional Member { get; set; } } } diff --git a/src/Discord.Net.WebSocket/API/Gateway/ReadyEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/ReadyEvent.cs index ab92d8c36..5cd75dbee 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/ReadyEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/ReadyEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/Gateway/RecipientEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/RecipientEvent.cs index 336ffd029..778b5708c 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/RecipientEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/RecipientEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/Gateway/RemoveAllReactionsForEmoteEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/RemoveAllReactionsForEmoteEvent.cs new file mode 100644 index 000000000..7f804d3f5 --- /dev/null +++ b/src/Discord.Net.WebSocket/API/Gateway/RemoveAllReactionsForEmoteEvent.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Discord.API.Gateway +{ + internal class RemoveAllReactionsForEmoteEvent + { + [JsonProperty("channel_id")] + public ulong ChannelId { get; set; } + [JsonProperty("guild_id")] + public Optional GuildId { get; set; } + [JsonProperty("message_id")] + public ulong MessageId { get; set; } + [JsonProperty("emoji")] + public Emoji Emoji { get; set; } + } +} diff --git a/src/Discord.Net.WebSocket/API/Gateway/RequestMembersParams.cs b/src/Discord.Net.WebSocket/API/Gateway/RequestMembersParams.cs index 6a8d283ed..f7a63e330 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/RequestMembersParams.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/RequestMembersParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; using System.Collections.Generic; diff --git a/src/Discord.Net.WebSocket/API/Gateway/ResumeParams.cs b/src/Discord.Net.WebSocket/API/Gateway/ResumeParams.cs index ffb46327b..826e8fadd 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/ResumeParams.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/ResumeParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/Gateway/ResumedEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/ResumedEvent.cs index d1347beae..870ae7366 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/ResumedEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/ResumedEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/Gateway/StatusUpdateParams.cs b/src/Discord.Net.WebSocket/API/Gateway/StatusUpdateParams.cs index fc0964c17..cbde225d2 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/StatusUpdateParams.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/StatusUpdateParams.cs @@ -1,18 +1,18 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway { [JsonObject(MemberSerialization = MemberSerialization.OptIn)] - internal class StatusUpdateParams + internal class PresenceUpdateParams + { [JsonProperty("status")] public UserStatus Status { get; set; } - [JsonProperty("since"), Int53] + [JsonProperty("since", NullValueHandling = NullValueHandling.Include), Int53] public long? IdleSince { get; set; } [JsonProperty("afk")] public bool IsAFK { get; set; } - [JsonProperty("game")] - public Game Game { get; set; } + [JsonProperty("activities")] + public object[] Activities { get; set; } // TODO, change to interface later } } diff --git a/src/Discord.Net.WebSocket/API/Gateway/ThreadListSyncEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/ThreadListSyncEvent.cs new file mode 100644 index 000000000..5084f6c95 --- /dev/null +++ b/src/Discord.Net.WebSocket/API/Gateway/ThreadListSyncEvent.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace Discord.API.Gateway +{ + internal class ThreadListSyncEvent + { + [JsonProperty("guild_id")] + public ulong GuildId { get; set; } + + [JsonProperty("channel_ids")] + public Optional ChannelIds { get; set; } + + [JsonProperty("threads")] + public Channel[] Threads { get; set; } + + [JsonProperty("members")] + public ThreadMember[] Members { get; set; } + } +} diff --git a/src/Discord.Net.WebSocket/API/Gateway/ThreadMembersUpdate.cs b/src/Discord.Net.WebSocket/API/Gateway/ThreadMembersUpdate.cs new file mode 100644 index 000000000..83d2c0edd --- /dev/null +++ b/src/Discord.Net.WebSocket/API/Gateway/ThreadMembersUpdate.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; + +namespace Discord.API.Gateway +{ + internal class ThreadMembersUpdated + { + [JsonProperty("id")] + public ulong Id { get; set; } + + [JsonProperty("guild_id")] + public ulong GuildId { get; set; } + + [JsonProperty("member_count")] + public int MemberCount { get; set; } + + [JsonProperty("added_members")] + public Optional AddedMembers { get; set; } + + [JsonProperty("removed_member_ids")] + public Optional RemovedMemberIds { get; set; } + } +} diff --git a/src/Discord.Net.WebSocket/API/Gateway/TypingStartEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/TypingStartEvent.cs index 5ceae4b7a..729ea176f 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/TypingStartEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/TypingStartEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/Gateway/VoiceServerUpdateEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/VoiceServerUpdateEvent.cs index 29167c1cc..8df3f0108 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/VoiceServerUpdateEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/VoiceServerUpdateEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/Gateway/VoiceStateUpdateParams.cs b/src/Discord.Net.WebSocket/API/Gateway/VoiceStateUpdateParams.cs index 521160126..ad21b14f1 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/VoiceStateUpdateParams.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/VoiceStateUpdateParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/Gateway/WebhookUpdateEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/WebhookUpdateEvent.cs index e5c7afe41..c1e6d5385 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/WebhookUpdateEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/WebhookUpdateEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway diff --git a/src/Discord.Net.WebSocket/API/SocketFrame.cs b/src/Discord.Net.WebSocket/API/SocketFrame.cs index fae741432..11c82ec44 100644 --- a/src/Discord.Net.WebSocket/API/SocketFrame.cs +++ b/src/Discord.Net.WebSocket/API/SocketFrame.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API diff --git a/src/Discord.Net.WebSocket/API/Voice/IdentifyParams.cs b/src/Discord.Net.WebSocket/API/Voice/IdentifyParams.cs index d446867e1..508b70d70 100644 --- a/src/Discord.Net.WebSocket/API/Voice/IdentifyParams.cs +++ b/src/Discord.Net.WebSocket/API/Voice/IdentifyParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Voice diff --git a/src/Discord.Net.WebSocket/API/Voice/ReadyEvent.cs b/src/Discord.Net.WebSocket/API/Voice/ReadyEvent.cs index 7188cd8f7..fb910573a 100644 --- a/src/Discord.Net.WebSocket/API/Voice/ReadyEvent.cs +++ b/src/Discord.Net.WebSocket/API/Voice/ReadyEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; using System; @@ -15,7 +14,7 @@ namespace Discord.API.Voice [JsonProperty("modes")] public string[] Modes { get; set; } [JsonProperty("heartbeat_interval")] - [Obsolete("This field is errorneous and should not be used", true)] + [Obsolete("This field is erroneous and should not be used", true)] public int HeartbeatInterval { get; set; } } } diff --git a/src/Discord.Net.WebSocket/API/Voice/SelectProtocolParams.cs b/src/Discord.Net.WebSocket/API/Voice/SelectProtocolParams.cs index 8c577e5b5..2e9bd157a 100644 --- a/src/Discord.Net.WebSocket/API/Voice/SelectProtocolParams.cs +++ b/src/Discord.Net.WebSocket/API/Voice/SelectProtocolParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Voice diff --git a/src/Discord.Net.WebSocket/API/Voice/SessionDescriptionEvent.cs b/src/Discord.Net.WebSocket/API/Voice/SessionDescriptionEvent.cs index 45befadcf..043b9fe86 100644 --- a/src/Discord.Net.WebSocket/API/Voice/SessionDescriptionEvent.cs +++ b/src/Discord.Net.WebSocket/API/Voice/SessionDescriptionEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Voice diff --git a/src/Discord.Net.WebSocket/API/Voice/SpeakingEvent.cs b/src/Discord.Net.WebSocket/API/Voice/SpeakingEvent.cs index 0272a8f53..c1746e9ce 100644 --- a/src/Discord.Net.WebSocket/API/Voice/SpeakingEvent.cs +++ b/src/Discord.Net.WebSocket/API/Voice/SpeakingEvent.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Voice diff --git a/src/Discord.Net.WebSocket/API/Voice/SpeakingParams.cs b/src/Discord.Net.WebSocket/API/Voice/SpeakingParams.cs index abdf90667..e03bfc751 100644 --- a/src/Discord.Net.WebSocket/API/Voice/SpeakingParams.cs +++ b/src/Discord.Net.WebSocket/API/Voice/SpeakingParams.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Voice diff --git a/src/Discord.Net.WebSocket/API/Voice/UdpProtocolInfo.cs b/src/Discord.Net.WebSocket/API/Voice/UdpProtocolInfo.cs index 6f4719e7e..5e69a0370 100644 --- a/src/Discord.Net.WebSocket/API/Voice/UdpProtocolInfo.cs +++ b/src/Discord.Net.WebSocket/API/Voice/UdpProtocolInfo.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Voice diff --git a/src/Discord.Net.WebSocket/API/Voice/VoiceCloseCode.cs b/src/Discord.Net.WebSocket/API/Voice/VoiceCloseCode.cs new file mode 100644 index 000000000..498d595da --- /dev/null +++ b/src/Discord.Net.WebSocket/API/Voice/VoiceCloseCode.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.WebSocket +{ + /// + /// Represents generic op codes for voice disconnect. + /// + public enum VoiceCloseCode + { + /// + /// You sent an invalid opcode. + /// + UnknownOpcode = 4001, + /// + /// You sent an invalid payload in your identifying to the Gateway. + /// + DecodeFailure = 4002, + /// + /// You sent a payload before identifying with the Gateway. + /// + NotAuthenticated = 4003, + /// + /// The token you sent in your identify payload is incorrect. + /// + AuthenticationFailed = 4004, + /// + /// You sent more than one identify payload. Stahp. + /// + AlreadyAuthenticated = 4005, + /// + /// Your session is no longer valid. + /// + SessionNolongerValid = 4006, + /// + /// Your session has timed out. + /// + SessionTimeout = 4009, + /// + /// We can't find the server you're trying to connect to. + /// + ServerNotFound = 4011, + /// + /// We didn't recognize the protocol you sent. + /// + UnknownProtocol = 4012, + /// + /// Channel was deleted, you were kicked, voice server changed, or the main gateway session was dropped. Should not reconnect. + /// + Disconnected = 4014, + /// + /// The server crashed. Our bad! Try resuming. + /// + VoiceServerCrashed = 4015, + /// + /// We didn't recognize your encryption. + /// + UnknownEncryptionMode = 4016, + } +} diff --git a/src/Discord.Net.WebSocket/API/Voice/VoiceOpCode.cs b/src/Discord.Net.WebSocket/API/Voice/VoiceOpCode.cs index 67afe6173..94006505a 100644 --- a/src/Discord.Net.WebSocket/API/Voice/VoiceOpCode.cs +++ b/src/Discord.Net.WebSocket/API/Voice/VoiceOpCode.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 namespace Discord.API.Voice { internal enum VoiceOpCode : byte diff --git a/src/Discord.Net.WebSocket/Audio/AudioClient.cs b/src/Discord.Net.WebSocket/Audio/AudioClient.cs index 2210e019f..3549fb106 100644 --- a/src/Discord.Net.WebSocket/Audio/AudioClient.cs +++ b/src/Discord.Net.WebSocket/Audio/AudioClient.cs @@ -99,6 +99,12 @@ namespace Discord.Audio _token = token; await _connection.StartAsync().ConfigureAwait(false); } + + public IReadOnlyDictionary GetStreams() + { + return _streams.ToDictionary(pair => pair.Key, pair => pair.Value.Reader); + } + public async Task StopAsync() { await _connection.StopAsync().ConfigureAwait(false); @@ -379,7 +385,7 @@ namespace Discord.Audio private async Task RunHeartbeatAsync(int intervalMillis, CancellationToken cancelToken) { - //TODO: Clean this up when Discord's session patch is live + // TODO: Clean this up when Discord's session patch is live try { await _audioLogger.DebugAsync("Heartbeat Started").ConfigureAwait(false); diff --git a/src/Discord.Net.WebSocket/Audio/Streams/BufferedWriteStream.cs b/src/Discord.Net.WebSocket/Audio/Streams/BufferedWriteStream.cs index 16ad0ae89..25afde784 100644 --- a/src/Discord.Net.WebSocket/Audio/Streams/BufferedWriteStream.cs +++ b/src/Discord.Net.WebSocket/Audio/Streams/BufferedWriteStream.cs @@ -61,14 +61,17 @@ namespace Discord.Audio.Streams _task = Run(); } + protected override void Dispose(bool disposing) { if (disposing) { _disposeTokenSource?.Cancel(); _disposeTokenSource?.Dispose(); + _cancelTokenSource?.Cancel(); _cancelTokenSource?.Dispose(); _queueLock?.Dispose(); + _next.Dispose(); } base.Dispose(disposing); } @@ -122,7 +125,7 @@ namespace Discord.Audio.Streams timestamp += OpusEncoder.FrameSamplesPerChannel; } #if DEBUG - var _ = _logger?.DebugAsync("Buffer underrun"); + var _ = _logger?.DebugAsync("Buffer under run"); #endif } } diff --git a/src/Discord.Net.WebSocket/Audio/Streams/OpusDecodeStream.cs b/src/Discord.Net.WebSocket/Audio/Streams/OpusDecodeStream.cs index 1861e3554..ad1c285e8 100644 --- a/src/Discord.Net.WebSocket/Audio/Streams/OpusDecodeStream.cs +++ b/src/Discord.Net.WebSocket/Audio/Streams/OpusDecodeStream.cs @@ -68,10 +68,12 @@ namespace Discord.Audio.Streams protected override void Dispose(bool disposing) { - base.Dispose(disposing); - if (disposing) + { _decoder.Dispose(); + _next.Dispose(); + } + base.Dispose(disposing); } } } diff --git a/src/Discord.Net.WebSocket/Audio/Streams/OpusEncodeStream.cs b/src/Discord.Net.WebSocket/Audio/Streams/OpusEncodeStream.cs index 035b92b30..05d12b490 100644 --- a/src/Discord.Net.WebSocket/Audio/Streams/OpusEncodeStream.cs +++ b/src/Discord.Net.WebSocket/Audio/Streams/OpusEncodeStream.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading; using System.Threading.Tasks; @@ -89,10 +89,12 @@ namespace Discord.Audio.Streams protected override void Dispose(bool disposing) { - base.Dispose(disposing); - if (disposing) + { _encoder.Dispose(); + _next.Dispose(); + } + base.Dispose(disposing); } } } diff --git a/src/Discord.Net.WebSocket/Audio/Streams/RTPReadStream.cs b/src/Discord.Net.WebSocket/Audio/Streams/RTPReadStream.cs index 120f67e0d..1002502b6 100644 --- a/src/Discord.Net.WebSocket/Audio/Streams/RTPReadStream.cs +++ b/src/Discord.Net.WebSocket/Audio/Streams/RTPReadStream.cs @@ -76,5 +76,12 @@ namespace Discord.Audio.Streams (buffer[extensionOffset + 3]); return extensionOffset + 4 + (extensionLength * 4); } + + protected override void Dispose(bool disposing) + { + if (disposing) + _next.Dispose(); + base.Dispose(disposing); + } } } diff --git a/src/Discord.Net.WebSocket/Audio/Streams/RTPWriteStream.cs b/src/Discord.Net.WebSocket/Audio/Streams/RTPWriteStream.cs index ce407eada..7ecb56bee 100644 --- a/src/Discord.Net.WebSocket/Audio/Streams/RTPWriteStream.cs +++ b/src/Discord.Net.WebSocket/Audio/Streams/RTPWriteStream.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading; using System.Threading.Tasks; @@ -69,5 +69,12 @@ namespace Discord.Audio.Streams { await _next.ClearAsync(cancelToken).ConfigureAwait(false); } + + protected override void Dispose(bool disposing) + { + if (disposing) + _next.Dispose(); + base.Dispose(disposing); + } } } diff --git a/src/Discord.Net.WebSocket/Audio/Streams/SodiumDecryptStream.cs b/src/Discord.Net.WebSocket/Audio/Streams/SodiumDecryptStream.cs index 2b1a97f04..40cd6864e 100644 --- a/src/Discord.Net.WebSocket/Audio/Streams/SodiumDecryptStream.cs +++ b/src/Discord.Net.WebSocket/Audio/Streams/SodiumDecryptStream.cs @@ -44,5 +44,12 @@ namespace Discord.Audio.Streams { await _next.ClearAsync(cancelToken).ConfigureAwait(false); } + + protected override void Dispose(bool disposing) + { + if (disposing) + _next.Dispose(); + base.Dispose(disposing); + } } } diff --git a/src/Discord.Net.WebSocket/Audio/Streams/SodiumEncryptStream.cs b/src/Discord.Net.WebSocket/Audio/Streams/SodiumEncryptStream.cs index 8b3f0e302..fa1d34de5 100644 --- a/src/Discord.Net.WebSocket/Audio/Streams/SodiumEncryptStream.cs +++ b/src/Discord.Net.WebSocket/Audio/Streams/SodiumEncryptStream.cs @@ -60,5 +60,12 @@ namespace Discord.Audio.Streams { await _next.ClearAsync(cancelToken).ConfigureAwait(false); } + + protected override void Dispose(bool disposing) + { + if (disposing) + _next.Dispose(); + base.Dispose(disposing); + } } } diff --git a/src/Discord.Net.WebSocket/BaseSocketClient.Events.cs b/src/Discord.Net.WebSocket/BaseSocketClient.Events.cs index 908314f6a..29e13a2a1 100644 --- a/src/Discord.Net.WebSocket/BaseSocketClient.Events.cs +++ b/src/Discord.Net.WebSocket/BaseSocketClient.Events.cs @@ -1,3 +1,4 @@ +using Discord.Rest; using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -6,7 +7,7 @@ namespace Discord.WebSocket { public partial class BaseSocketClient { - //Channels + #region Channels /// Fired when a channel is created. /// /// @@ -23,7 +24,7 @@ namespace Discord.WebSocket /// /// - public event Func ChannelCreated + public event Func ChannelCreated { add { _channelCreatedEvent.Add(value); } remove { _channelCreatedEvent.Remove(value); } @@ -45,7 +46,8 @@ namespace Discord.WebSocket /// /// - public event Func ChannelDestroyed { + public event Func ChannelDestroyed + { add { _channelDestroyedEvent.Add(value); } remove { _channelDestroyedEvent.Remove(value); } } @@ -67,13 +69,15 @@ namespace Discord.WebSocket /// /// - public event Func ChannelUpdated { + public event Func ChannelUpdated + { add { _channelUpdatedEvent.Add(value); } remove { _channelUpdatedEvent.Remove(value); } - } + } internal readonly AsyncEvent> _channelUpdatedEvent = new AsyncEvent>(); + #endregion - //Messages + #region Messages /// Fired when a message is received. /// /// @@ -92,7 +96,8 @@ namespace Discord.WebSocket /// /// - public event Func MessageReceived { + public event Func MessageReceived + { add { _messageReceivedEvent.Add(value); } remove { _messageReceivedEvent.Remove(value); } } @@ -124,11 +129,13 @@ namespace Discord.WebSocket /// /// - public event Func, ISocketMessageChannel, Task> MessageDeleted { + + public event Func, Cacheable, Task> MessageDeleted + { add { _messageDeletedEvent.Add(value); } remove { _messageDeletedEvent.Remove(value); } } - internal readonly AsyncEvent, ISocketMessageChannel, Task>> _messageDeletedEvent = new AsyncEvent, ISocketMessageChannel, Task>>(); + internal readonly AsyncEvent, Cacheable, Task>> _messageDeletedEvent = new AsyncEvent, Cacheable, Task>>(); /// Fired when multiple messages are bulk deleted. /// /// @@ -155,12 +162,12 @@ namespace Discord.WebSocket /// parameter. /// /// - public event Func>, ISocketMessageChannel, Task> MessagesBulkDeleted + public event Func>, Cacheable, Task> MessagesBulkDeleted { add { _messagesBulkDeletedEvent.Add(value); } remove { _messagesBulkDeletedEvent.Remove(value); } } - internal readonly AsyncEvent>, ISocketMessageChannel, Task>> _messagesBulkDeletedEvent = new AsyncEvent>, ISocketMessageChannel, Task>>(); + internal readonly AsyncEvent>, Cacheable, Task>> _messagesBulkDeletedEvent = new AsyncEvent>, Cacheable, Task>>(); /// Fired when a message is updated. /// /// @@ -182,7 +189,8 @@ namespace Discord.WebSocket /// parameter. /// /// - public event Func, SocketMessage, ISocketMessageChannel, Task> MessageUpdated { + public event Func, SocketMessage, ISocketMessageChannel, Task> MessageUpdated + { add { _messageUpdatedEvent.Add(value); } remove { _messageUpdatedEvent.Remove(value); } } @@ -217,121 +225,242 @@ namespace Discord.WebSocket /// /// - public event Func, ISocketMessageChannel, SocketReaction, Task> ReactionAdded { + public event Func, Cacheable, SocketReaction, Task> ReactionAdded + { add { _reactionAddedEvent.Add(value); } remove { _reactionAddedEvent.Remove(value); } } - internal readonly AsyncEvent, ISocketMessageChannel, SocketReaction, Task>> _reactionAddedEvent = new AsyncEvent, ISocketMessageChannel, SocketReaction, Task>>(); + internal readonly AsyncEvent, Cacheable, SocketReaction, Task>> _reactionAddedEvent = new AsyncEvent, Cacheable, SocketReaction, Task>>(); /// Fired when a reaction is removed from a message. - public event Func, ISocketMessageChannel, SocketReaction, Task> ReactionRemoved { + public event Func, Cacheable, SocketReaction, Task> ReactionRemoved + { add { _reactionRemovedEvent.Add(value); } remove { _reactionRemovedEvent.Remove(value); } } - internal readonly AsyncEvent, ISocketMessageChannel, SocketReaction, Task>> _reactionRemovedEvent = new AsyncEvent, ISocketMessageChannel, SocketReaction, Task>>(); + internal readonly AsyncEvent, Cacheable, SocketReaction, Task>> _reactionRemovedEvent = new AsyncEvent, Cacheable, SocketReaction, Task>>(); /// Fired when all reactions to a message are cleared. - public event Func, ISocketMessageChannel, Task> ReactionsCleared { + public event Func, Cacheable, Task> ReactionsCleared + { add { _reactionsClearedEvent.Add(value); } remove { _reactionsClearedEvent.Remove(value); } } - internal readonly AsyncEvent, ISocketMessageChannel, Task>> _reactionsClearedEvent = new AsyncEvent, ISocketMessageChannel, Task>>(); + internal readonly AsyncEvent, Cacheable, Task>> _reactionsClearedEvent = new AsyncEvent, Cacheable, Task>>(); + /// + /// Fired when all reactions to a message with a specific emote are removed. + /// + /// + /// + /// This event is fired when all reactions to a message with a specific emote are removed. + /// The event handler must return a and accept a and + /// a as its parameters. + /// + /// + /// The channel where this message was sent will be passed into the parameter. + /// + /// + /// The emoji that all reactions had and were removed will be passed into the parameter. + /// + /// + public event Func, Cacheable, IEmote, Task> ReactionsRemovedForEmote + { + add { _reactionsRemovedForEmoteEvent.Add(value); } + remove { _reactionsRemovedForEmoteEvent.Remove(value); } + } + internal readonly AsyncEvent, Cacheable, IEmote, Task>> _reactionsRemovedForEmoteEvent = new AsyncEvent, Cacheable, IEmote, Task>>(); + #endregion - //Roles + #region Roles /// Fired when a role is created. - public event Func RoleCreated { + public event Func RoleCreated + { add { _roleCreatedEvent.Add(value); } remove { _roleCreatedEvent.Remove(value); } } internal readonly AsyncEvent> _roleCreatedEvent = new AsyncEvent>(); /// Fired when a role is deleted. - public event Func RoleDeleted { + public event Func RoleDeleted + { add { _roleDeletedEvent.Add(value); } remove { _roleDeletedEvent.Remove(value); } } internal readonly AsyncEvent> _roleDeletedEvent = new AsyncEvent>(); /// Fired when a role is updated. - public event Func RoleUpdated { + public event Func RoleUpdated + { add { _roleUpdatedEvent.Add(value); } remove { _roleUpdatedEvent.Remove(value); } } internal readonly AsyncEvent> _roleUpdatedEvent = new AsyncEvent>(); + #endregion - //Guilds + #region Guilds /// Fired when the connected account joins a guild. - public event Func JoinedGuild { + public event Func JoinedGuild + { add { _joinedGuildEvent.Add(value); } remove { _joinedGuildEvent.Remove(value); } } internal readonly AsyncEvent> _joinedGuildEvent = new AsyncEvent>(); /// Fired when the connected account leaves a guild. - public event Func LeftGuild { + public event Func LeftGuild + { add { _leftGuildEvent.Add(value); } remove { _leftGuildEvent.Remove(value); } } internal readonly AsyncEvent> _leftGuildEvent = new AsyncEvent>(); /// Fired when a guild becomes available. - public event Func GuildAvailable { + public event Func GuildAvailable + { add { _guildAvailableEvent.Add(value); } remove { _guildAvailableEvent.Remove(value); } } internal readonly AsyncEvent> _guildAvailableEvent = new AsyncEvent>(); /// Fired when a guild becomes unavailable. - public event Func GuildUnavailable { + public event Func GuildUnavailable + { add { _guildUnavailableEvent.Add(value); } remove { _guildUnavailableEvent.Remove(value); } } internal readonly AsyncEvent> _guildUnavailableEvent = new AsyncEvent>(); /// Fired when offline guild members are downloaded. - public event Func GuildMembersDownloaded { + public event Func GuildMembersDownloaded + { add { _guildMembersDownloadedEvent.Add(value); } remove { _guildMembersDownloadedEvent.Remove(value); } } internal readonly AsyncEvent> _guildMembersDownloadedEvent = new AsyncEvent>(); /// Fired when a guild is updated. - public event Func GuildUpdated { + public event Func GuildUpdated + { add { _guildUpdatedEvent.Add(value); } remove { _guildUpdatedEvent.Remove(value); } } internal readonly AsyncEvent> _guildUpdatedEvent = new AsyncEvent>(); + /// Fired when a user leaves without agreeing to the member screening + public event Func, SocketGuild, Task> GuildJoinRequestDeleted + { + add { _guildJoinRequestDeletedEvent.Add(value); } + remove { _guildJoinRequestDeletedEvent.Remove(value); } + } + internal readonly AsyncEvent, SocketGuild, Task>> _guildJoinRequestDeletedEvent = new AsyncEvent, SocketGuild, Task>>(); + #endregion + + #region Guild Events + + /// + /// Fired when a guild event is created. + /// + public event Func GuildScheduledEventCreated + { + add { _guildScheduledEventCreated.Add(value); } + remove { _guildScheduledEventCreated.Remove(value); } + } + internal readonly AsyncEvent> _guildScheduledEventCreated = new AsyncEvent>(); + + /// + /// Fired when a guild event is updated. + /// + public event Func, SocketGuildEvent, Task> GuildScheduledEventUpdated + { + add { _guildScheduledEventUpdated.Add(value); } + remove { _guildScheduledEventUpdated.Remove(value); } + } + internal readonly AsyncEvent, SocketGuildEvent, Task>> _guildScheduledEventUpdated = new AsyncEvent, SocketGuildEvent, Task>>(); + + + /// + /// Fired when a guild event is cancelled. + /// + public event Func GuildScheduledEventCancelled + { + add { _guildScheduledEventCancelled.Add(value); } + remove { _guildScheduledEventCancelled.Remove(value); } + } + internal readonly AsyncEvent> _guildScheduledEventCancelled = new AsyncEvent>(); + + /// + /// Fired when a guild event is completed. + /// + public event Func GuildScheduledEventCompleted + { + add { _guildScheduledEventCompleted.Add(value); } + remove { _guildScheduledEventCompleted.Remove(value); } + } + internal readonly AsyncEvent> _guildScheduledEventCompleted = new AsyncEvent>(); + + /// + /// Fired when a guild event is started. + /// + public event Func GuildScheduledEventStarted + { + add { _guildScheduledEventStarted.Add(value); } + remove { _guildScheduledEventStarted.Remove(value); } + } + internal readonly AsyncEvent> _guildScheduledEventStarted = new AsyncEvent>(); - //Users + public event Func, SocketGuildEvent, Task> GuildScheduledEventUserAdd + { + add { _guildScheduledEventUserAdd.Add(value); } + remove { _guildScheduledEventUserAdd.Remove(value); } + } + internal readonly AsyncEvent, SocketGuildEvent, Task>> _guildScheduledEventUserAdd = new AsyncEvent, SocketGuildEvent, Task>>(); + + public event Func, SocketGuildEvent, Task> GuildScheduledEventUserRemove + { + add { _guildScheduledEventUserRemove.Add(value); } + remove { _guildScheduledEventUserRemove.Remove(value); } + } + internal readonly AsyncEvent, SocketGuildEvent, Task>> _guildScheduledEventUserRemove = new AsyncEvent, SocketGuildEvent, Task>>(); + + + #endregion + + #region Users /// Fired when a user joins a guild. - public event Func UserJoined { + public event Func UserJoined + { add { _userJoinedEvent.Add(value); } remove { _userJoinedEvent.Remove(value); } } internal readonly AsyncEvent> _userJoinedEvent = new AsyncEvent>(); /// Fired when a user leaves a guild. - public event Func UserLeft { + public event Func UserLeft + { add { _userLeftEvent.Add(value); } remove { _userLeftEvent.Remove(value); } } - internal readonly AsyncEvent> _userLeftEvent = new AsyncEvent>(); + internal readonly AsyncEvent> _userLeftEvent = new AsyncEvent>(); /// Fired when a user is banned from a guild. - public event Func UserBanned { + public event Func UserBanned + { add { _userBannedEvent.Add(value); } remove { _userBannedEvent.Remove(value); } } internal readonly AsyncEvent> _userBannedEvent = new AsyncEvent>(); /// Fired when a user is unbanned from a guild. - public event Func UserUnbanned { + public event Func UserUnbanned + { add { _userUnbannedEvent.Add(value); } remove { _userUnbannedEvent.Remove(value); } } internal readonly AsyncEvent> _userUnbannedEvent = new AsyncEvent>(); /// Fired when a user is updated. - public event Func UserUpdated { + public event Func UserUpdated + { add { _userUpdatedEvent.Add(value); } remove { _userUpdatedEvent.Remove(value); } } internal readonly AsyncEvent> _userUpdatedEvent = new AsyncEvent>(); /// Fired when a guild member is updated, or a member presence is updated. - public event Func GuildMemberUpdated { + public event Func, SocketGuildUser, Task> GuildMemberUpdated + { add { _guildMemberUpdatedEvent.Add(value); } remove { _guildMemberUpdatedEvent.Remove(value); } } - internal readonly AsyncEvent> _guildMemberUpdatedEvent = new AsyncEvent>(); + internal readonly AsyncEvent, SocketGuildUser, Task>> _guildMemberUpdatedEvent = new AsyncEvent, SocketGuildUser, Task>>(); /// Fired when a user joins, leaves, or moves voice channels. - public event Func UserVoiceStateUpdated { + public event Func UserVoiceStateUpdated + { add { _userVoiceStateUpdatedEvent.Add(value); } remove { _userVoiceStateUpdatedEvent.Remove(value); } } @@ -339,33 +468,379 @@ namespace Discord.WebSocket /// Fired when the bot connects to a Discord voice server. public event Func VoiceServerUpdated { - add { _voiceServerUpdatedEvent.Add(value); } + add { _voiceServerUpdatedEvent.Add(value); } remove { _voiceServerUpdatedEvent.Remove(value); } } internal readonly AsyncEvent> _voiceServerUpdatedEvent = new AsyncEvent>(); /// Fired when the connected account is updated. - public event Func CurrentUserUpdated { + public event Func CurrentUserUpdated + { add { _selfUpdatedEvent.Add(value); } remove { _selfUpdatedEvent.Remove(value); } } internal readonly AsyncEvent> _selfUpdatedEvent = new AsyncEvent>(); /// Fired when a user starts typing. - public event Func UserIsTyping { + public event Func, Cacheable, Task> UserIsTyping + { add { _userIsTypingEvent.Add(value); } remove { _userIsTypingEvent.Remove(value); } } - internal readonly AsyncEvent> _userIsTypingEvent = new AsyncEvent>(); + internal readonly AsyncEvent, Cacheable, Task>> _userIsTypingEvent = new AsyncEvent, Cacheable, Task>>(); /// Fired when a user joins a group channel. - public event Func RecipientAdded { + public event Func RecipientAdded + { add { _recipientAddedEvent.Add(value); } remove { _recipientAddedEvent.Remove(value); } } internal readonly AsyncEvent> _recipientAddedEvent = new AsyncEvent>(); /// Fired when a user is removed from a group channel. - public event Func RecipientRemoved { + public event Func RecipientRemoved + { add { _recipientRemovedEvent.Add(value); } remove { _recipientRemovedEvent.Remove(value); } } internal readonly AsyncEvent> _recipientRemovedEvent = new AsyncEvent>(); + #endregion + + #region Presence + + /// Fired when a users presence is updated. + public event Func PresenceUpdated + { + add { _presenceUpdated.Add(value); } + remove { _presenceUpdated.Remove(value); } + } + internal readonly AsyncEvent> _presenceUpdated = new AsyncEvent>(); + + #endregion + + #region Invites + /// + /// Fired when an invite is created. + /// + /// + /// + /// This event is fired when an invite is created. The event handler must return a + /// and accept a as its parameter. + /// + /// + /// The invite created will be passed into the parameter. + /// + /// + public event Func InviteCreated + { + add { _inviteCreatedEvent.Add(value); } + remove { _inviteCreatedEvent.Remove(value); } + } + internal readonly AsyncEvent> _inviteCreatedEvent = new AsyncEvent>(); + /// + /// Fired when an invite is deleted. + /// + /// + /// + /// This event is fired when an invite is deleted. The event handler must return + /// a and accept a and + /// as its parameter. + /// + /// + /// The channel where this invite was created will be passed into the parameter. + /// + /// + /// The code of the deleted invite will be passed into the parameter. + /// + /// + public event Func InviteDeleted + { + add { _inviteDeletedEvent.Add(value); } + remove { _inviteDeletedEvent.Remove(value); } + } + internal readonly AsyncEvent> _inviteDeletedEvent = new AsyncEvent>(); + #endregion + + #region Interactions + /// + /// Fired when an Interaction is created. This event covers all types of interactions including but not limited to: buttons, select menus, slash commands, autocompletes. + /// + /// + /// + /// This event is fired when an interaction is created. The event handler must return a + /// and accept a as its parameter. + /// + /// + /// The interaction created will be passed into the parameter. + /// + /// + public event Func InteractionCreated + { + add { _interactionCreatedEvent.Add(value); } + remove { _interactionCreatedEvent.Remove(value); } + } + internal readonly AsyncEvent> _interactionCreatedEvent = new AsyncEvent>(); + + /// + /// Fired when a button is clicked and its interaction is received. + /// + public event Func ButtonExecuted + { + add => _buttonExecuted.Add(value); + remove => _buttonExecuted.Remove(value); + } + internal readonly AsyncEvent> _buttonExecuted = new AsyncEvent>(); + + /// + /// Fired when a select menu is used and its interaction is received. + /// + public event Func SelectMenuExecuted + { + add => _selectMenuExecuted.Add(value); + remove => _selectMenuExecuted.Remove(value); + } + internal readonly AsyncEvent> _selectMenuExecuted = new AsyncEvent>(); + /// + /// Fired when a slash command is used and its interaction is received. + /// + public event Func SlashCommandExecuted + { + add => _slashCommandExecuted.Add(value); + remove => _slashCommandExecuted.Remove(value); + } + internal readonly AsyncEvent> _slashCommandExecuted = new AsyncEvent>(); + + /// + /// Fired when a user command is used and its interaction is received. + /// + public event Func UserCommandExecuted + { + add => _userCommandExecuted.Add(value); + remove => _userCommandExecuted.Remove(value); + } + internal readonly AsyncEvent> _userCommandExecuted = new AsyncEvent>(); + + /// + /// Fired when a message command is used and its interaction is received. + /// + public event Func MessageCommandExecuted + { + add => _messageCommandExecuted.Add(value); + remove => _messageCommandExecuted.Remove(value); + } + internal readonly AsyncEvent> _messageCommandExecuted = new AsyncEvent>(); + /// + /// Fired when an autocomplete is used and its interaction is received. + /// + public event Func AutocompleteExecuted + { + add => _autocompleteExecuted.Add(value); + remove => _autocompleteExecuted.Remove(value); + } + internal readonly AsyncEvent> _autocompleteExecuted = new AsyncEvent>(); + + /// + /// Fired when a guild application command is created. + /// + /// + /// + /// This event is fired when an application command is created. The event handler must return a + /// and accept a as its parameter. + /// + /// + /// The command that was deleted will be passed into the parameter. + /// + /// + /// This event is an undocumented discord event and may break at any time, its not recommended to rely on this event + /// + /// + public event Func ApplicationCommandCreated + { + add { _applicationCommandCreated.Add(value); } + remove { _applicationCommandCreated.Remove(value); } + } + internal readonly AsyncEvent> _applicationCommandCreated = new AsyncEvent>(); + + /// + /// Fired when a guild application command is updated. + /// + /// + /// + /// This event is fired when an application command is updated. The event handler must return a + /// and accept a as its parameter. + /// + /// + /// The command that was deleted will be passed into the parameter. + /// + /// + /// This event is an undocumented discord event and may break at any time, its not recommended to rely on this event + /// + /// + public event Func ApplicationCommandUpdated + { + add { _applicationCommandUpdated.Add(value); } + remove { _applicationCommandUpdated.Remove(value); } + } + internal readonly AsyncEvent> _applicationCommandUpdated = new AsyncEvent>(); + + /// + /// Fired when a guild application command is deleted. + /// + /// + /// + /// This event is fired when an application command is deleted. The event handler must return a + /// and accept a as its parameter. + /// + /// + /// The command that was deleted will be passed into the parameter. + /// + /// + /// This event is an undocumented discord event and may break at any time, its not recommended to rely on this event + /// + /// + public event Func ApplicationCommandDeleted + { + add { _applicationCommandDeleted.Add(value); } + remove { _applicationCommandDeleted.Remove(value); } + } + internal readonly AsyncEvent> _applicationCommandDeleted = new AsyncEvent>(); + + /// + /// Fired when a thread is created within a guild, or when the current user is added to a thread. + /// + public event Func ThreadCreated + { + add { _threadCreated.Add(value); } + remove { _threadCreated.Remove(value); } + } + internal readonly AsyncEvent> _threadCreated = new AsyncEvent>(); + + /// + /// Fired when a thread is updated within a guild. + /// + public event Func, SocketThreadChannel, Task> ThreadUpdated + { + add { _threadUpdated.Add(value); } + remove { _threadUpdated.Remove(value); } + } + + internal readonly AsyncEvent, SocketThreadChannel, Task>> _threadUpdated = new(); + + /// + /// Fired when a thread is deleted. + /// + public event Func, Task> ThreadDeleted + { + add { _threadDeleted.Add(value); } + remove { _threadDeleted.Remove(value); } + } + internal readonly AsyncEvent, Task>> _threadDeleted = new AsyncEvent, Task>>(); + + /// + /// Fired when a user joins a thread + /// + public event Func ThreadMemberJoined + { + add { _threadMemberJoined.Add(value); } + remove { _threadMemberJoined.Remove(value); } + } + internal readonly AsyncEvent> _threadMemberJoined = new AsyncEvent>(); + + /// + /// Fired when a user leaves a thread + /// + public event Func ThreadMemberLeft + { + add { _threadMemberLeft.Add(value); } + remove { _threadMemberLeft.Remove(value); } + } + internal readonly AsyncEvent> _threadMemberLeft = new AsyncEvent>(); + + /// + /// Fired when a stage is started. + /// + public event Func StageStarted + { + add { _stageStarted.Add(value); } + remove { _stageStarted.Remove(value); } + } + internal readonly AsyncEvent> _stageStarted = new AsyncEvent>(); + + /// + /// Fired when a stage ends. + /// + public event Func StageEnded + { + add { _stageEnded.Add(value); } + remove { _stageEnded.Remove(value); } + } + internal readonly AsyncEvent> _stageEnded = new AsyncEvent>(); + + /// + /// Fired when a stage is updated. + /// + public event Func StageUpdated + { + add { _stageUpdated.Add(value); } + remove { _stageUpdated.Remove(value); } + } + internal readonly AsyncEvent> _stageUpdated = new AsyncEvent>(); + + /// + /// Fired when a user requests to speak within a stage channel. + /// + public event Func RequestToSpeak + { + add { _requestToSpeak.Add(value); } + remove { _requestToSpeak.Remove(value); } + } + internal readonly AsyncEvent> _requestToSpeak = new AsyncEvent>(); + + /// + /// Fired when a speaker is added in a stage channel. + /// + public event Func SpeakerAdded + { + add { _speakerAdded.Add(value); } + remove { _speakerAdded.Remove(value); } + } + internal readonly AsyncEvent> _speakerAdded = new AsyncEvent>(); + + /// + /// Fired when a speaker is removed from a stage channel. + /// + public event Func SpeakerRemoved + { + add { _speakerRemoved.Add(value); } + remove { _speakerRemoved.Remove(value); } + } + internal readonly AsyncEvent> _speakerRemoved = new AsyncEvent>(); + + /// + /// Fired when a sticker in a guild is created. + /// + public event Func GuildStickerCreated + { + add { _guildStickerCreated.Add(value); } + remove { _guildStickerCreated.Remove(value); } + } + internal readonly AsyncEvent> _guildStickerCreated = new AsyncEvent>(); + + /// + /// Fired when a sticker in a guild is updated. + /// + public event Func GuildStickerUpdated + { + add { _guildStickerUpdated.Add(value); } + remove { _guildStickerUpdated.Remove(value); } + } + internal readonly AsyncEvent> _guildStickerUpdated = new AsyncEvent>(); + + /// + /// Fired when a sticker in a guild is deleted. + /// + public event Func GuildStickerDeleted + { + add { _guildStickerDeleted.Add(value); } + remove { _guildStickerDeleted.Remove(value); } + } + internal readonly AsyncEvent> _guildStickerDeleted = new AsyncEvent>(); + #endregion } } diff --git a/src/Discord.Net.WebSocket/BaseSocketClient.cs b/src/Discord.Net.WebSocket/BaseSocketClient.cs index 548bb75bf..9e25ab382 100644 --- a/src/Discord.Net.WebSocket/BaseSocketClient.cs +++ b/src/Discord.Net.WebSocket/BaseSocketClient.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; @@ -11,6 +12,7 @@ namespace Discord.WebSocket /// public abstract partial class BaseSocketClient : BaseDiscordClient, IDiscordClient { + #region BaseSocketClient protected readonly DiscordSocketConfig BaseConfig; /// @@ -43,10 +45,14 @@ namespace Discord.WebSocket internal new DiscordSocketApiClient ApiClient => base.ApiClient as DiscordSocketApiClient; + /// + /// Gets a collection of default stickers. + /// + public abstract IReadOnlyCollection> DefaultStickerPacks { get; } /// /// Gets the current logged-in user. /// - public new SocketSelfUser CurrentUser { get => base.CurrentUser as SocketSelfUser; protected set => base.CurrentUser = value; } + public virtual new SocketSelfUser CurrentUser { get => base.CurrentUser as SocketSelfUser; protected set => base.CurrentUser = value; } /// /// Gets a collection of guilds that the user is currently in. /// @@ -69,20 +75,12 @@ namespace Discord.WebSocket /// A read-only collection of private channels that the user currently partakes in. /// public abstract IReadOnlyCollection PrivateChannels { get; } - /// - /// Gets a collection of available voice regions. - /// - /// - /// A read-only collection of voice regions that the user has access to. - /// - public abstract IReadOnlyCollection VoiceRegions { get; } internal BaseSocketClient(DiscordSocketConfig config, DiscordRestApiClient client) : base(config, client) => BaseConfig = config; private static DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config) => new DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent, - rateLimitPrecision: config.RateLimitPrecision, - useSystemClock: config.UseSystemClock); + useSystemClock: config.UseSystemClock); /// /// Gets a Discord application information for the logged-in user. @@ -162,14 +160,23 @@ namespace Discord.WebSocket /// public abstract SocketGuild GetGuild(ulong id); /// + /// Gets all voice regions. + /// + /// The options to be used when sending the request. + /// + /// A task that contains a read-only collection of REST-based voice regions. + /// + public abstract ValueTask> GetVoiceRegionsAsync(RequestOptions options = null); + /// /// Gets a voice region. /// /// The identifier of the voice region (e.g. eu-central ). + /// The options to be used when sending the request. /// - /// A REST-based voice region associated with the identifier; null if the voice region is not - /// found. + /// A task that contains a REST-based voice region associated with the identifier; null if the + /// voice region is not found. /// - public abstract RestVoiceRegion GetVoiceRegion(string id); + public abstract ValueTask GetVoiceRegionAsync(string id, RequestOptions options = null); /// public abstract Task StartAsync(); /// @@ -188,6 +195,12 @@ namespace Discord.WebSocket /// The name of the game. /// If streaming, the URL of the stream. Must be a valid Twitch URL. /// The type of the game. + /// + /// + /// Bot accounts cannot set as their activity + /// type and it will have no effect. + /// + /// /// /// A task that represents the asynchronous set operation. /// @@ -201,6 +214,10 @@ namespace Discord.WebSocket /// Discord will only accept setting of name and the type of activity. /// /// + /// Bot accounts cannot set as their activity + /// type and it will have no effect. + /// + /// /// Rich Presence cannot be set via this method or client. Rich Presence is strictly limited to RPC /// clients only. /// @@ -256,8 +273,19 @@ namespace Discord.WebSocket /// public Task GetInviteAsync(string inviteId, RequestOptions options = null) => ClientHelper.GetInviteAsync(this, inviteId, options ?? RequestOptions.Default); - - // IDiscordClient + /// + /// Gets a sticker. + /// + /// Whether or not to allow downloading from the api. + /// The id of the sticker to get. + /// The options to be used when sending the request. + /// + /// A if found, otherwise . + /// + public abstract Task GetStickerAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); +#endregion + + #region IDiscordClient /// async Task IDiscordClient.GetApplicationInfoAsync(RequestOptions options) => await GetApplicationInfoAsync(options).ConfigureAwait(false); @@ -296,10 +324,15 @@ namespace Discord.WebSocket => Task.FromResult(GetUser(username, discriminator)); /// - Task IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options) - => Task.FromResult(GetVoiceRegion(id)); + async Task IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options) + { + return await GetVoiceRegionAsync(id).ConfigureAwait(false); + } /// - Task> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options) - => Task.FromResult>(VoiceRegions); + async Task> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options) + { + return await GetVoiceRegionsAsync().ConfigureAwait(false); + } + #endregion } } diff --git a/src/Discord.Net.WebSocket/ClientState.cs b/src/Discord.Net.WebSocket/ClientState.cs index f2e370d02..c40ae3f92 100644 --- a/src/Discord.Net.WebSocket/ClientState.cs +++ b/src/Discord.Net.WebSocket/ClientState.cs @@ -16,12 +16,14 @@ namespace Discord.WebSocket private readonly ConcurrentDictionary _guilds; private readonly ConcurrentDictionary _users; private readonly ConcurrentHashSet _groupChannels; + private readonly ConcurrentDictionary _commands; internal IReadOnlyCollection Channels => _channels.ToReadOnlyCollection(); internal IReadOnlyCollection DMChannels => _dmChannels.ToReadOnlyCollection(); internal IReadOnlyCollection GroupChannels => _groupChannels.Select(x => GetChannel(x) as SocketGroupChannel).ToReadOnlyCollection(_groupChannels); internal IReadOnlyCollection Guilds => _guilds.ToReadOnlyCollection(); internal IReadOnlyCollection Users => _users.ToReadOnlyCollection(); + internal IReadOnlyCollection Commands => _commands.ToReadOnlyCollection(); internal IReadOnlyCollection PrivateChannels => _dmChannels.Select(x => x.Value as ISocketPrivateChannel).Concat( @@ -37,6 +39,7 @@ namespace Discord.WebSocket _guilds = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(guildCount * CollectionMultiplier)); _users = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(estimatedUsersCount * CollectionMultiplier)); _groupChannels = new ConcurrentHashSet(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(10 * CollectionMultiplier)); + _commands = new ConcurrentDictionary(); } internal SocketChannel GetChannel(ulong id) @@ -112,7 +115,7 @@ namespace Discord.WebSocket if (_guilds.TryRemove(id, out SocketGuild guild)) { guild.PurgeChannelCache(this); - guild.PurgeGuildUserCache(); + guild.PurgeUserCache(); return guild; } return null; @@ -137,7 +140,35 @@ namespace Discord.WebSocket internal void PurgeUsers() { foreach (var guild in _guilds.Values) - guild.PurgeGuildUserCache(); + guild.PurgeUserCache(); + } + + internal SocketApplicationCommand GetCommand(ulong id) + { + if (_commands.TryGetValue(id, out SocketApplicationCommand command)) + return command; + return null; + } + internal void AddCommand(SocketApplicationCommand command) + { + _commands[command.Id] = command; + } + internal SocketApplicationCommand GetOrAddCommand(ulong id, Func commandFactory) + { + return _commands.GetOrAdd(id, commandFactory); + } + internal SocketApplicationCommand RemoveCommand(ulong id) + { + if (_commands.TryRemove(id, out SocketApplicationCommand command)) + return command; + return null; + } + internal void PurgeCommands(Func precondition) + { + var ids = _commands.Where(x => precondition(x.Value)).Select(x => x.Key); + + foreach (var id in ids) + _commands.TryRemove(id, out var _); } } } diff --git a/src/Discord.Net.WebSocket/Commands/ShardedCommandContext.cs b/src/Discord.Net.WebSocket/Commands/ShardedCommandContext.cs index f970c32fc..905cd01a1 100644 --- a/src/Discord.Net.WebSocket/Commands/ShardedCommandContext.cs +++ b/src/Discord.Net.WebSocket/Commands/ShardedCommandContext.cs @@ -5,6 +5,7 @@ namespace Discord.Commands /// The sharded variant of , which may contain the client, user, guild, channel, and message. public class ShardedCommandContext : SocketCommandContext, ICommandContext { + #region ShardedCommandContext /// Gets the that the command is executed with. public new DiscordShardedClient Client { get; } @@ -17,9 +18,11 @@ namespace Discord.Commands /// Gets the shard ID of the command context. private static int GetShardId(DiscordShardedClient client, IGuild guild) => guild == null ? 0 : client.GetShardIdFor(guild); +#endregion - //ICommandContext + #region ICommandContext /// IDiscordClient ICommandContext.Client => Client; + #endregion } } diff --git a/src/Discord.Net.WebSocket/Commands/SocketCommandContext.cs b/src/Discord.Net.WebSocket/Commands/SocketCommandContext.cs index f4d517909..d7180873b 100644 --- a/src/Discord.Net.WebSocket/Commands/SocketCommandContext.cs +++ b/src/Discord.Net.WebSocket/Commands/SocketCommandContext.cs @@ -7,6 +7,7 @@ namespace Discord.Commands /// public class SocketCommandContext : ICommandContext { + #region SocketCommandContext /// /// Gets the that the command is executed with. /// @@ -46,8 +47,9 @@ namespace Discord.Commands User = msg.Author; Message = msg; } +#endregion - //ICommandContext + #region ICommandContext /// IDiscordClient ICommandContext.Client => Client; /// @@ -58,5 +60,6 @@ namespace Discord.Commands IUser ICommandContext.User => User; /// IUserMessage ICommandContext.Message => Message; + #endregion } } diff --git a/src/Discord.Net.WebSocket/ConnectionManager.cs b/src/Discord.Net.WebSocket/ConnectionManager.cs index 8c9c743cb..f304d4ea8 100644 --- a/src/Discord.Net.WebSocket/ConnectionManager.cs +++ b/src/Discord.Net.WebSocket/ConnectionManager.cs @@ -44,6 +44,8 @@ namespace Discord var ex2 = ex as WebSocketClosedException; if (ex2?.CloseCode == 4006) CriticalError(new Exception("WebSocket session expired", ex)); + else if (ex2?.CloseCode == 4014) + CriticalError(new Exception("WebSocket connection was closed", ex)); else Error(new Exception("WebSocket connection was closed", ex)); } @@ -55,6 +57,9 @@ namespace Discord public virtual async Task StartAsync() { + if (State != ConnectionState.Disconnected) + throw new InvalidOperationException("Cannot start an already running client."); + await AcquireConnectionLock().ConfigureAwait(false); var reconnectCancelToken = new CancellationTokenSource(); _reconnectCancelToken?.Dispose(); @@ -73,11 +78,6 @@ namespace Discord nextReconnectDelay = 1000; //Reset delay await _connectionPromise.Task.ConfigureAwait(false); } - catch (OperationCanceledException ex) - { - Cancel(); //In case this exception didn't come from another Error call - await DisconnectAsync(ex, !reconnectCancelToken.IsCancellationRequested).ConfigureAwait(false); - } catch (Exception ex) { Error(ex); //In case this exception didn't come from another Error call diff --git a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj index 26a249097..2ce89be5b 100644 --- a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj +++ b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj @@ -1,11 +1,12 @@ + Discord.Net.WebSocket Discord.WebSocket A core Discord.Net library containing the WebSocket client and models. - net461;netstandard2.0;netstandard2.1 - netstandard2.0;netstandard2.1 + net6.0;net5.0;net461;netstandard2.0;netstandard2.1 + net6.0;net5.0;netstandard2.0;netstandard2.1 true diff --git a/src/Discord.Net.WebSocket/DiscordShardedClient.Events.cs b/src/Discord.Net.WebSocket/DiscordShardedClient.Events.cs index c9e679669..50230572c 100644 --- a/src/Discord.Net.WebSocket/DiscordShardedClient.Events.cs +++ b/src/Discord.Net.WebSocket/DiscordShardedClient.Events.cs @@ -1,11 +1,11 @@ -using System; +using System; using System.Threading.Tasks; namespace Discord.WebSocket { public partial class DiscordShardedClient { - //General + #region General /// Fired when a shard is connected to the Discord gateway. public event Func ShardConnected { @@ -34,5 +34,6 @@ namespace Discord.WebSocket remove { _shardLatencyUpdatedEvent.Remove(value); } } private readonly AsyncEvent> _shardLatencyUpdatedEvent = new AsyncEvent>(); + #endregion } -} \ No newline at end of file +} diff --git a/src/Discord.Net.WebSocket/DiscordShardedClient.cs b/src/Discord.Net.WebSocket/DiscordShardedClient.cs index b61929210..ac0ca5b9f 100644 --- a/src/Discord.Net.WebSocket/DiscordShardedClient.cs +++ b/src/Discord.Net.WebSocket/DiscordShardedClient.cs @@ -6,18 +6,23 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using System.Threading; +using System.Collections.Immutable; namespace Discord.WebSocket { public partial class DiscordShardedClient : BaseSocketClient, IDiscordClient { + #region DiscordShardedClient private readonly DiscordSocketConfig _baseConfig; - private readonly SemaphoreSlim _connectionGroupLock; private readonly Dictionary _shardIdsToIndex; private readonly bool _automaticShards; private int[] _shardIds; private DiscordSocketClient[] _shards; + private ImmutableArray> _defaultStickers; private int _totalShards; + private SemaphoreSlim[] _identifySemaphores; + private object _semaphoreResetLock; + private Task _semaphoreResetTask; private bool _isDisposed; @@ -28,19 +33,32 @@ namespace Discord.WebSocket /// public override IActivity Activity { get => _shards[0].Activity; protected set { } } - internal new DiscordSocketApiClient ApiClient => base.ApiClient as DiscordSocketApiClient; + internal new DiscordSocketApiClient ApiClient + { + get + { + if (base.ApiClient.CurrentUserId == null) + base.ApiClient.CurrentUserId = CurrentUser?.Id; + + return base.ApiClient; + } + } + /// + public override IReadOnlyCollection> DefaultStickerPacks + => _defaultStickers.ToReadOnlyCollection(); + /// public override IReadOnlyCollection Guilds => GetGuilds().ToReadOnlyCollection(GetGuildCount); /// public override IReadOnlyCollection PrivateChannels => GetPrivateChannels().ToReadOnlyCollection(GetPrivateChannelCount); public IReadOnlyCollection Shards => _shards; - /// - public override IReadOnlyCollection VoiceRegions => _shards[0].VoiceRegions; /// /// Provides access to a REST-only client with a shared state from this client. /// - public override DiscordSocketRestClient Rest => _shards[0].Rest; + public override DiscordSocketRestClient Rest => _shards?[0].Rest; + + public override SocketSelfUser CurrentUser { get => _shards?.FirstOrDefault(x => x.CurrentUser != null)?.CurrentUser; protected set => throw new InvalidOperationException(); } /// Creates a new REST/WebSocket Discord client. public DiscordShardedClient() : this(null, new DiscordSocketConfig()) { } @@ -62,10 +80,11 @@ namespace Discord.WebSocket if (ids != null && config.TotalShards == null) throw new ArgumentException($"Custom ids are not supported when {nameof(config.TotalShards)} is not specified."); + _semaphoreResetLock = new object(); _shardIdsToIndex = new Dictionary(); config.DisplayInitialLog = false; _baseConfig = config; - _connectionGroupLock = new SemaphoreSlim(1, 1); + _defaultStickers = ImmutableArray.Create>(); if (config.TotalShards == null) _automaticShards = true; @@ -74,35 +93,69 @@ namespace Discord.WebSocket _totalShards = config.TotalShards.Value; _shardIds = ids ?? Enumerable.Range(0, _totalShards).ToArray(); _shards = new DiscordSocketClient[_shardIds.Length]; + _identifySemaphores = new SemaphoreSlim[config.IdentifyMaxConcurrency]; + for (int i = 0; i < config.IdentifyMaxConcurrency; i++) + _identifySemaphores[i] = new SemaphoreSlim(1, 1); for (int i = 0; i < _shardIds.Length; i++) { _shardIdsToIndex.Add(_shardIds[i], i); var newConfig = config.Clone(); newConfig.ShardId = _shardIds[i]; - _shards[i] = new DiscordSocketClient(newConfig, _connectionGroupLock, i != 0 ? _shards[0] : null); + _shards[i] = new DiscordSocketClient(newConfig, this, i != 0 ? _shards[0] : null); RegisterEvents(_shards[i], i == 0); } } } private static API.DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config) - => new API.DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent, - rateLimitPrecision: config.RateLimitPrecision); + => new API.DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent); + + internal async Task AcquireIdentifyLockAsync(int shardId, CancellationToken token) + { + int semaphoreIdx = shardId % _baseConfig.IdentifyMaxConcurrency; + await _identifySemaphores[semaphoreIdx].WaitAsync(token).ConfigureAwait(false); + } + + internal void ReleaseIdentifyLock() + { + lock (_semaphoreResetLock) + { + if (_semaphoreResetTask == null) + _semaphoreResetTask = ResetSemaphoresAsync(); + } + } + + private async Task ResetSemaphoresAsync() + { + await Task.Delay(5000).ConfigureAwait(false); + lock (_semaphoreResetLock) + { + foreach (var semaphore in _identifySemaphores) + if (semaphore.CurrentCount == 0) + semaphore.Release(); + _semaphoreResetTask = null; + } + } internal override async Task OnLoginAsync(TokenType tokenType, string token) { if (_automaticShards) { - var shardCount = await GetRecommendedShardCountAsync().ConfigureAwait(false); - _shardIds = Enumerable.Range(0, shardCount).ToArray(); + var botGateway = await GetBotGatewayAsync().ConfigureAwait(false); + _shardIds = Enumerable.Range(0, botGateway.Shards).ToArray(); _totalShards = _shardIds.Length; _shards = new DiscordSocketClient[_shardIds.Length]; + int maxConcurrency = botGateway.SessionStartLimit.MaxConcurrency; + _baseConfig.IdentifyMaxConcurrency = maxConcurrency; + _identifySemaphores = new SemaphoreSlim[maxConcurrency]; + for (int i = 0; i < maxConcurrency; i++) + _identifySemaphores[i] = new SemaphoreSlim(1, 1); for (int i = 0; i < _shardIds.Length; i++) { _shardIdsToIndex.Add(_shardIds[i], i); var newConfig = _baseConfig.Clone(); newConfig.ShardId = _shardIds[i]; newConfig.TotalShards = _totalShards; - _shards[i] = new DiscordSocketClient(newConfig, _connectionGroupLock, i != 0 ? _shards[0] : null); + _shards[i] = new DiscordSocketClient(newConfig, this, i != 0 ? _shards[0] : null); RegisterEvents(_shards[i], i == 0); } } @@ -110,6 +163,10 @@ namespace Discord.WebSocket //Assume thread safe: already in a connection lock for (int i = 0; i < _shards.Length; i++) await _shards[i].LoginAsync(tokenType, token); + + if(_defaultStickers.Length == 0 && _baseConfig.AlwaysDownloadDefaultStickers) + await DownloadDefaultStickersAsync().ConfigureAwait(false); + } internal override async Task OnLogoutAsync() { @@ -202,6 +259,67 @@ namespace Discord.WebSocket result += _shards[i].Guilds.Count; return result; } + /// + public override async Task GetStickerAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null) + { + var sticker = _defaultStickers.FirstOrDefault(x => x.Stickers.Any(y => y.Id == id))?.Stickers.FirstOrDefault(x => x.Id == id); + + if (sticker != null) + return sticker; + + foreach (var guild in Guilds) + { + sticker = await guild.GetStickerAsync(id, CacheMode.CacheOnly).ConfigureAwait(false); + + if (sticker != null) + return sticker; + } + + if (mode == CacheMode.CacheOnly) + return null; + + var model = await ApiClient.GetStickerAsync(id, options).ConfigureAwait(false); + + if (model == null) + return null; + + + if (model.GuildId.IsSpecified) + { + var guild = GetGuild(model.GuildId.Value); + sticker = guild.AddOrUpdateSticker(model); + return sticker; + } + else + { + return SocketSticker.Create(_shards[0], model); + } + } + private async Task DownloadDefaultStickersAsync() + { + var models = await ApiClient.ListNitroStickerPacksAsync().ConfigureAwait(false); + + var builder = ImmutableArray.CreateBuilder>(); + + foreach (var model in models.StickerPacks) + { + var stickers = model.Stickers.Select(x => SocketSticker.Create(_shards[0], x)); + + var pack = new StickerPack( + model.Name, + model.Id, + model.SkuId, + model.CoverStickerId.ToNullable(), + model.Description, + model.BannerAssetId, + stickers + ); + + builder.Add(pack); + } + + _defaultStickers = builder.ToImmutable(); + } /// public override SocketUser GetUser(ulong id) @@ -227,8 +345,16 @@ namespace Discord.WebSocket } /// - public override RestVoiceRegion GetVoiceRegion(string id) - => _shards[0].GetVoiceRegion(id); + public override async ValueTask> GetVoiceRegionsAsync(RequestOptions options = null) + { + return await _shards[0].GetVoiceRegionsAsync().ConfigureAwait(false); + } + + /// + public override async ValueTask GetVoiceRegionAsync(string id, RequestOptions options = null) + { + return await _shards[0].GetVoiceRegionAsync(id, options).ConfigureAwait(false); + } /// /// is @@ -288,14 +414,6 @@ namespace Discord.WebSocket } return Task.Delay(0); }; - if (isPrimary) - { - client.Ready += () => - { - CurrentUser = client.CurrentUser; - return Task.Delay(0); - }; - } client.Connected += () => _shardConnectedEvent.InvokeAsync(client); client.Disconnected += (exception) => _shardDisconnectedEvent.InvokeAsync(exception, client); @@ -313,6 +431,7 @@ namespace Discord.WebSocket client.ReactionAdded += (cache, channel, reaction) => _reactionAddedEvent.InvokeAsync(cache, channel, reaction); client.ReactionRemoved += (cache, channel, reaction) => _reactionRemovedEvent.InvokeAsync(cache, channel, reaction); client.ReactionsCleared += (cache, channel) => _reactionsClearedEvent.InvokeAsync(cache, channel); + client.ReactionsRemovedForEmote += (cache, channel, emote) => _reactionsRemovedForEmoteEvent.InvokeAsync(cache, channel, emote); client.RoleCreated += (role) => _roleCreatedEvent.InvokeAsync(role); client.RoleDeleted += (role) => _roleDeletedEvent.InvokeAsync(role); @@ -326,7 +445,7 @@ namespace Discord.WebSocket client.GuildUpdated += (oldGuild, newGuild) => _guildUpdatedEvent.InvokeAsync(oldGuild, newGuild); client.UserJoined += (user) => _userJoinedEvent.InvokeAsync(user); - client.UserLeft += (user) => _userLeftEvent.InvokeAsync(user); + client.UserLeft += (guild, user) => _userLeftEvent.InvokeAsync(guild, user); client.UserBanned += (user, guild) => _userBannedEvent.InvokeAsync(user, guild); client.UserUnbanned += (user, guild) => _userUnbannedEvent.InvokeAsync(user, guild); client.UserUpdated += (oldUser, newUser) => _userUpdatedEvent.InvokeAsync(oldUser, newUser); @@ -337,9 +456,51 @@ namespace Discord.WebSocket client.UserIsTyping += (oldUser, newUser) => _userIsTypingEvent.InvokeAsync(oldUser, newUser); client.RecipientAdded += (user) => _recipientAddedEvent.InvokeAsync(user); client.RecipientRemoved += (user) => _recipientRemovedEvent.InvokeAsync(user); + + client.InviteCreated += (invite) => _inviteCreatedEvent.InvokeAsync(invite); + client.InviteDeleted += (channel, invite) => _inviteDeletedEvent.InvokeAsync(channel, invite); + + client.InteractionCreated += (interaction) => _interactionCreatedEvent.InvokeAsync(interaction); + client.ButtonExecuted += (arg) => _buttonExecuted.InvokeAsync(arg); + client.SelectMenuExecuted += (arg) => _selectMenuExecuted.InvokeAsync(arg); + client.SlashCommandExecuted += (arg) => _slashCommandExecuted.InvokeAsync(arg); + client.UserCommandExecuted += (arg) => _userCommandExecuted.InvokeAsync(arg); + client.MessageCommandExecuted += (arg) => _messageCommandExecuted.InvokeAsync(arg); + client.AutocompleteExecuted += (arg) => _autocompleteExecuted.InvokeAsync(arg); + + client.ThreadUpdated += (thread1, thread2) => _threadUpdated.InvokeAsync(thread1, thread2); + client.ThreadCreated += (thread) => _threadCreated.InvokeAsync(thread); + client.ThreadDeleted += (thread) => _threadDeleted.InvokeAsync(thread); + + client.ThreadMemberJoined += (user) => _threadMemberJoined.InvokeAsync(user); + client.ThreadMemberLeft += (user) => _threadMemberLeft.InvokeAsync(user); + client.StageEnded += (stage) => _stageEnded.InvokeAsync(stage); + client.StageStarted += (stage) => _stageStarted.InvokeAsync(stage); + client.StageUpdated += (stage1, stage2) => _stageUpdated.InvokeAsync(stage1, stage2); + + client.RequestToSpeak += (stage, user) => _requestToSpeak.InvokeAsync(stage, user); + client.SpeakerAdded += (stage, user) => _speakerAdded.InvokeAsync(stage, user); + client.SpeakerRemoved += (stage, user) => _speakerRemoved.InvokeAsync(stage, user); + + client.GuildStickerCreated += (sticker) => _guildStickerCreated.InvokeAsync(sticker); + client.GuildStickerDeleted += (sticker) => _guildStickerDeleted.InvokeAsync(sticker); + client.GuildStickerUpdated += (before, after) => _guildStickerUpdated.InvokeAsync(before, after); + client.GuildJoinRequestDeleted += (userId, guildId) => _guildJoinRequestDeletedEvent.InvokeAsync(userId, guildId); + + client.GuildScheduledEventCancelled += (arg) => _guildScheduledEventCancelled.InvokeAsync(arg); + client.GuildScheduledEventCompleted += (arg) => _guildScheduledEventCompleted.InvokeAsync(arg); + client.GuildScheduledEventCreated += (arg) => _guildScheduledEventCreated.InvokeAsync(arg); + client.GuildScheduledEventUpdated += (arg1, arg2) => _guildScheduledEventUpdated.InvokeAsync(arg1, arg2); + client.GuildScheduledEventStarted += (arg) => _guildScheduledEventStarted.InvokeAsync(arg); + client.GuildScheduledEventUserAdd += (arg1, arg2) => _guildScheduledEventUserAdd.InvokeAsync(arg1, arg2); + client.GuildScheduledEventUserRemove += (arg1, arg2) => _guildScheduledEventUserRemove.InvokeAsync(arg1, arg2); } + #endregion + + #region IDiscordClient + /// + ISelfUser IDiscordClient.CurrentUser => CurrentUser; - //IDiscordClient /// async Task IDiscordClient.GetApplicationInfoAsync(RequestOptions options) => await GetApplicationInfoAsync().ConfigureAwait(false); @@ -377,12 +538,18 @@ namespace Discord.WebSocket => Task.FromResult(GetUser(username, discriminator)); /// - Task> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options) - => Task.FromResult>(VoiceRegions); + async Task> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options) + { + return await GetVoiceRegionsAsync().ConfigureAwait(false); + } /// - Task IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options) - => Task.FromResult(GetVoiceRegion(id)); + async Task IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options) + { + return await GetVoiceRegionAsync(id).ConfigureAwait(false); + } + #endregion + #region Dispose internal override void Dispose(bool disposing) { if (!_isDisposed) @@ -394,7 +561,6 @@ namespace Discord.WebSocket foreach (var client in _shards) client?.Dispose(); } - _connectionGroupLock?.Dispose(); } _isDisposed = true; diff --git a/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs b/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs index e81d89f48..bf15967d3 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Discord.API.Gateway; using Discord.Net.Queue; using Discord.Net.Rest; @@ -12,6 +11,7 @@ using System.IO.Compression; using System.Text; using System.Threading; using System.Threading.Tasks; +using GameModel = Discord.API.Game; namespace Discord.API { @@ -39,9 +39,8 @@ namespace Discord.API public DiscordSocketApiClient(RestClientProvider restClientProvider, WebSocketProvider webSocketProvider, string userAgent, string url = null, RetryMode defaultRetryMode = RetryMode.AlwaysRetry, JsonSerializer serializer = null, - RateLimitPrecision rateLimitPrecision = RateLimitPrecision.Second, bool useSystemClock = true) - : base(restClientProvider, userAgent, defaultRetryMode, serializer, rateLimitPrecision, useSystemClock) + : base(restClientProvider, userAgent, defaultRetryMode, serializer, useSystemClock) { _gatewayUrl = url; if (url != null) @@ -75,8 +74,15 @@ namespace Discord.API using (var jsonReader = new JsonTextReader(reader)) { var msg = _serializer.Deserialize(jsonReader); + if (msg != null) + { +#if DEBUG_PACKETS + Console.WriteLine($"<- {(GatewayOpCode)msg.Operation} [{msg.Type ?? "none"}] : {(msg.Payload as Newtonsoft.Json.Linq.JToken)?.ToString().Length}"); +#endif + await _receivedGatewayEvent.InvokeAsync((GatewayOpCode)msg.Operation, msg.Sequence, msg.Type, msg.Payload).ConfigureAwait(false); + } } } }; @@ -87,11 +93,21 @@ namespace Discord.API { var msg = _serializer.Deserialize(jsonReader); if (msg != null) + { +#if DEBUG_PACKETS + Console.WriteLine($"<- {(GatewayOpCode)msg.Operation} [{msg.Type ?? "none"}] : {(msg.Payload as Newtonsoft.Json.Linq.JToken)?.ToString().Length}"); +#endif + await _receivedGatewayEvent.InvokeAsync((GatewayOpCode)msg.Operation, msg.Sequence, msg.Type, msg.Payload).ConfigureAwait(false); + } } }; WebSocketClient.Closed += async ex => { +#if DEBUG_PACKETS + Console.WriteLine(ex); +#endif + await DisconnectAsync().ConfigureAwait(false); await _disconnectedEvent.InvokeAsync(ex).ConfigureAwait(false); }; @@ -159,6 +175,8 @@ namespace Discord.API if (WebSocketClient == null) throw new NotSupportedException("This client is not configured with WebSocket support."); + RequestQueue.ClearGatewayBuckets(); + //Re-create streams to reset the zlib state _compressed?.Dispose(); _decompressor?.Dispose(); @@ -178,6 +196,11 @@ namespace Discord.API var gatewayResponse = await GetGatewayAsync().ConfigureAwait(false); _gatewayUrl = $"{gatewayResponse.Url}?v={DiscordConfig.APIVersion}&encoding={DiscordSocketConfig.GatewayEncoding}&compress=zlib-stream"; } + +#if DEBUG_PACKETS + Console.WriteLine("Connecting to gateway: " + _gatewayUrl); +#endif + await WebSocketClient.ConnectAsync(_gatewayUrl).ConfigureAwait(false); ConnectionState = ConnectionState.Connected; @@ -213,14 +236,14 @@ namespace Discord.API catch { } if (ex is GatewayReconnectException) - await WebSocketClient.DisconnectAsync(4000); + await WebSocketClient.DisconnectAsync(4000).ConfigureAwait(false); else - await WebSocketClient.DisconnectAsync().ConfigureAwait(false); + await WebSocketClient.DisconnectAsync().ConfigureAwait(false); ConnectionState = ConnectionState.Disconnected; } - //Core + #region Core public Task SendGatewayAsync(GatewayOpCode opCode, object payload, RequestOptions options = null) => SendGatewayInternalAsync(opCode, payload, options); private async Task SendGatewayInternalAsync(GatewayOpCode opCode, object payload, RequestOptions options) @@ -232,27 +255,51 @@ namespace Discord.API payload = new SocketFrame { Operation = (int)opCode, Payload = payload }; if (payload != null) bytes = Encoding.UTF8.GetBytes(SerializeJson(payload)); - await RequestQueue.SendAsync(new WebSocketRequest(WebSocketClient, null, bytes, true, options)).ConfigureAwait(false); + + options.IsGatewayBucket = true; + if (options.BucketId == null) + options.BucketId = GatewayBucket.Get(GatewayBucketType.Unbucketed).Id; + await RequestQueue.SendAsync(new WebSocketRequest(WebSocketClient, bytes, true, opCode == GatewayOpCode.Heartbeat, options)).ConfigureAwait(false); await _sentGatewayMessageEvent.InvokeAsync(opCode).ConfigureAwait(false); + +#if DEBUG_PACKETS + Console.WriteLine($"-> {opCode}:\n{SerializeJson(payload)}"); +#endif } - public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, bool guildSubscriptions = true, RequestOptions options = null) + public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, GatewayIntents gatewayIntents = GatewayIntents.AllUnprivileged, (UserStatus, bool, long?, GameModel)? presence = null, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); var props = new Dictionary { - ["$device"] = "Discord.Net" + ["$device"] = "Discord.Net", + ["$os"] = Environment.OSVersion.Platform.ToString(), + [$"browser"] = "Discord.Net" }; var msg = new IdentifyParams() { Token = AuthToken, Properties = props, - LargeThreshold = largeThreshold, - GuildSubscriptions = guildSubscriptions + LargeThreshold = largeThreshold }; if (totalShards > 1) msg.ShardingParams = new int[] { shardID, totalShards }; + options.BucketId = GatewayBucket.Get(GatewayBucketType.Identify).Id; + + msg.Intents = (int)gatewayIntents; + + if (presence.HasValue) + { + msg.Presence = new PresenceUpdateParams + { + Status = presence.Value.Item1, + IsAFK = presence.Value.Item2, + IdleSince = presence.Value.Item3, + Activities = new object[] { presence.Value.Item4 } + }; + } + await SendGatewayAsync(GatewayOpCode.Identify, msg, options: options).ConfigureAwait(false); } public async Task SendResumeAsync(string sessionId, int lastSeq, RequestOptions options = null) @@ -271,17 +318,18 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); await SendGatewayAsync(GatewayOpCode.Heartbeat, lastSeq, options: options).ConfigureAwait(false); } - public async Task SendStatusUpdateAsync(UserStatus status, bool isAFK, long? since, Game game, RequestOptions options = null) + public async Task SendPresenceUpdateAsync(UserStatus status, bool isAFK, long? since, GameModel game, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - var args = new StatusUpdateParams + var args = new PresenceUpdateParams { Status = status, IdleSince = since, IsAFK = isAFK, - Game = game + Activities = new object[] { game } }; - await SendGatewayAsync(GatewayOpCode.StatusUpdate, args, options: options).ConfigureAwait(false); + options.BucketId = GatewayBucket.Get(GatewayBucketType.PresenceUpdate).Id; + await SendGatewayAsync(GatewayOpCode.PresenceUpdate, args, options: options).ConfigureAwait(false); } public async Task SendRequestMembersAsync(IEnumerable guildIds, RequestOptions options = null) { @@ -290,7 +338,6 @@ namespace Discord.API } public async Task SendVoiceStateUpdateAsync(ulong guildId, ulong? channelId, bool selfDeaf, bool selfMute, RequestOptions options = null) { - options = RequestOptions.CreateOrClone(options); var payload = new VoiceStateUpdateParams { GuildId = guildId, @@ -298,6 +345,12 @@ namespace Discord.API SelfDeaf = selfDeaf, SelfMute = selfMute }; + options = RequestOptions.CreateOrClone(options); + await SendGatewayAsync(GatewayOpCode.VoiceStateUpdate, payload, options: options).ConfigureAwait(false); + } + public async Task SendVoiceStateUpdateAsync(VoiceStateUpdateParams payload, RequestOptions options = null) + { + options = RequestOptions.CreateOrClone(options); await SendGatewayAsync(GatewayOpCode.VoiceStateUpdate, payload, options: options).ConfigureAwait(false); } public async Task SendGuildSyncAsync(IEnumerable guildIds, RequestOptions options = null) @@ -305,5 +358,6 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); await SendGatewayAsync(GatewayOpCode.GuildSync, guildIds, options: options).ConfigureAwait(false); } + #endregion } } diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.Events.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.Events.cs index 51dea5f9f..ab13d93db 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.Events.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.Events.cs @@ -6,7 +6,7 @@ namespace Discord.WebSocket { public partial class DiscordSocketClient { - //General + #region General /// Fired when connected to the Discord gateway. public event Func Connected { @@ -21,7 +21,13 @@ namespace Discord.WebSocket remove { _disconnectedEvent.Remove(value); } } private readonly AsyncEvent> _disconnectedEvent = new AsyncEvent>(); - /// Fired when guild data has finished downloading. + /// + /// Fired when guild data has finished downloading. + /// + /// + /// It is possible that some guilds might be unsynced if + /// was not long enough to receive all GUILD_AVAILABLEs before READY. + /// public event Func Ready { add { _readyEvent.Add(value); } @@ -39,5 +45,6 @@ namespace Discord.WebSocket internal DiscordSocketClient(DiscordSocketConfig config, DiscordRestApiClient client) : base(config, client) { } + #endregion } } diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index a21d3aef9..69c16f88a 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -24,9 +24,10 @@ namespace Discord.WebSocket /// public partial class DiscordSocketClient : BaseSocketClient, IDiscordClient { + #region DiscordSocketClient private readonly ConcurrentQueue _largeGuilds; - private readonly JsonSerializer _serializer; - private readonly SemaphoreSlim _connectionGroupLock; + internal readonly JsonSerializer _serializer; + private readonly DiscordShardedClient _shardedClient; private readonly DiscordSocketClient _parentClient; private readonly ConcurrentQueue _heartbeatTimes; private readonly ConnectionManager _connection; @@ -43,24 +44,28 @@ namespace Discord.WebSocket private DateTimeOffset? _statusSince; private RestApplication _applicationInfo; private bool _isDisposed; - private bool _guildSubscriptions; + private GatewayIntents _gatewayIntents; + private ImmutableArray> _defaultStickers; /// /// Provides access to a REST-only client with a shared state from this client. /// public override DiscordSocketRestClient Rest { get; } - /// Gets the shard of of this client. + /// Gets the shard of this client. public int ShardId { get; } /// Gets the current connection state of this client. public ConnectionState ConnectionState => _connection.State; /// public override int Latency { get; protected set; } /// - public override UserStatus Status { get; protected set; } = UserStatus.Online; + public override UserStatus Status { get => _status ?? UserStatus.Online; protected set => _status = value; } + private UserStatus? _status; /// - public override IActivity Activity { get; protected set; } + public override IActivity Activity { get => _activity.GetValueOrDefault(); protected set => _activity = Optional.Create(value); } + private Optional _activity; + #endregion - //From DiscordSocketConfig + // From DiscordSocketConfig internal int TotalShards { get; private set; } internal int MessageCacheSize { get; private set; } internal int LargeThreshold { get; private set; } @@ -69,11 +74,23 @@ namespace Discord.WebSocket internal WebSocketProvider WebSocketProvider { get; private set; } internal bool AlwaysDownloadUsers { get; private set; } internal int? HandlerTimeout { get; private set; } - internal bool? ExclusiveBulkDelete { get; private set; } - - internal new DiscordSocketApiClient ApiClient => base.ApiClient as DiscordSocketApiClient; + internal bool AlwaysDownloadDefaultStickers { get; private set; } + internal bool AlwaysResolveStickers { get; private set; } + internal bool LogGatewayIntentWarnings { get; private set; } + internal new DiscordSocketApiClient ApiClient => base.ApiClient; /// public override IReadOnlyCollection Guilds => State.Guilds; + /// + public override IReadOnlyCollection> DefaultStickerPacks + { + get + { + if (_shardedClient != null) + return _shardedClient.DefaultStickerPacks; + else + return _defaultStickers.ToReadOnlyCollection(); + } + } /// public override IReadOnlyCollection PrivateChannels => State.PrivateChannels; /// @@ -106,8 +123,6 @@ namespace Discord.WebSocket /// public IReadOnlyCollection GroupChannels => State.PrivateChannels.OfType().ToImmutableArray(); - /// - public override IReadOnlyCollection VoiceRegions => _voiceRegions.ToReadOnlyCollection(); /// /// Initializes a new REST/WebSocket-based Discord client. @@ -119,9 +134,9 @@ namespace Discord.WebSocket /// The configuration to be used with the client. #pragma warning disable IDISP004 public DiscordSocketClient(DiscordSocketConfig config) : this(config, CreateApiClient(config), null, null) { } - internal DiscordSocketClient(DiscordSocketConfig config, SemaphoreSlim groupLock, DiscordSocketClient parentClient) : this(config, CreateApiClient(config), groupLock, parentClient) { } + internal DiscordSocketClient(DiscordSocketConfig config, DiscordShardedClient shardedClient, DiscordSocketClient parentClient) : this(config, CreateApiClient(config), shardedClient, parentClient) { } #pragma warning restore IDISP004 - private DiscordSocketClient(DiscordSocketConfig config, API.DiscordSocketApiClient client, SemaphoreSlim groupLock, DiscordSocketClient parentClient) + private DiscordSocketClient(DiscordSocketConfig config, API.DiscordSocketApiClient client, DiscordShardedClient shardedClient, DiscordSocketClient parentClient) : base(config, client) { ShardId = config.ShardId ?? 0; @@ -131,12 +146,15 @@ namespace Discord.WebSocket UdpSocketProvider = config.UdpSocketProvider; WebSocketProvider = config.WebSocketProvider; AlwaysDownloadUsers = config.AlwaysDownloadUsers; + AlwaysDownloadDefaultStickers = config.AlwaysDownloadDefaultStickers; + AlwaysResolveStickers = config.AlwaysResolveStickers; + LogGatewayIntentWarnings = config.LogGatewayIntentWarnings; HandlerTimeout = config.HandlerTimeout; - ExclusiveBulkDelete = config.ExclusiveBulkDelete; State = new ClientState(0, 0); Rest = new DiscordSocketRestClient(config, ApiClient); _heartbeatTimes = new ConcurrentQueue(); - _guildSubscriptions = config.GuildSubscriptions; + _gatewayIntents = config.GatewayIntents; + _defaultStickers = ImmutableArray.Create>(); _stateLock = new SemaphoreSlim(1, 1); _gatewayLogger = LogManager.CreateLogger(ShardId == 0 && TotalShards == 1 ? "Gateway" : $"Shard #{ShardId}"); @@ -146,7 +164,7 @@ namespace Discord.WebSocket _connection.Disconnected += (ex, recon) => TimedInvokeAsync(_disconnectedEvent, nameof(Disconnected), ex); _nextAudioId = 1; - _connectionGroupLock = groupLock; + _shardedClient = shardedClient; _parentClient = parentClient; _serializer = new JsonSerializer { ContractResolver = new DiscordContractResolver() }; @@ -167,19 +185,17 @@ namespace Discord.WebSocket GuildAvailable += g => { - if (ConnectionState == ConnectionState.Connected && AlwaysDownloadUsers && !g.HasAllMembers) + if (_guildDownloadTask?.IsCompleted == true && ConnectionState == ConnectionState.Connected && AlwaysDownloadUsers && !g.HasAllMembers) { var _ = g.DownloadUsersAsync(); } return Task.Delay(0); }; - _voiceRegions = ImmutableDictionary.Create(); _largeGuilds = new ConcurrentQueue(); } private static API.DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config) - => new API.DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent, config.GatewayHost, - rateLimitPrecision: config.RateLimitPrecision); + => new API.DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent, config.GatewayHost); /// internal override void Dispose(bool disposing) { @@ -197,6 +213,7 @@ namespace Discord.WebSocket base.Dispose(disposing); } + internal override async ValueTask DisposeAsync(bool disposing) { if (!_isDisposed) @@ -219,21 +236,42 @@ namespace Discord.WebSocket /// internal override async Task OnLoginAsync(TokenType tokenType, string token) { - if (_parentClient == null) + if (_shardedClient == null && _defaultStickers.Length == 0 && AlwaysDownloadDefaultStickers) { - var voiceRegions = await ApiClient.GetVoiceRegionsAsync(new RequestOptions { IgnoreState = true, RetryMode = RetryMode.AlwaysRetry }).ConfigureAwait(false); - _voiceRegions = voiceRegions.Select(x => RestVoiceRegion.Create(this, x)).ToImmutableDictionary(x => x.Id); + var models = await ApiClient.ListNitroStickerPacksAsync().ConfigureAwait(false); + + var builder = ImmutableArray.CreateBuilder>(); + + foreach (var model in models.StickerPacks) + { + var stickers = model.Stickers.Select(x => SocketSticker.Create(this, x)); + + var pack = new StickerPack( + model.Name, + model.Id, + model.SkuId, + model.CoverStickerId.ToNullable(), + model.Description, + model.BannerAssetId, + stickers + ); + + builder.Add(pack); + } + + _defaultStickers = builder.ToImmutable(); } - else - _voiceRegions = _parentClient._voiceRegions; - await Rest.OnLoginAsync(tokenType, token); + + if(LogGatewayIntentWarnings) + await LogGatewayIntentsWarning().ConfigureAwait(false); } + /// internal override async Task OnLogoutAsync() { await StopAsync().ConfigureAwait(false); _applicationInfo = null; - _voiceRegions = ImmutableDictionary.Create(); + _voiceRegions = null; await Rest.OnLogoutAsync(); } @@ -246,8 +284,12 @@ namespace Discord.WebSocket private async Task OnConnectingAsync() { - if (_connectionGroupLock != null) - await _connectionGroupLock.WaitAsync(_connection.CancelToken).ConfigureAwait(false); + bool locked = false; + if (_shardedClient != null && _sessionId == null) + { + await _shardedClient.AcquireIdentifyLockAsync(ShardId, _connection.CancelToken).ConfigureAwait(false); + locked = true; + } try { await _gatewayLogger.DebugAsync("Connecting ApiClient").ConfigureAwait(false); @@ -261,23 +303,17 @@ namespace Discord.WebSocket else { await _gatewayLogger.DebugAsync("Identifying").ConfigureAwait(false); - await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, guildSubscriptions: _guildSubscriptions).ConfigureAwait(false); + await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, gatewayIntents: _gatewayIntents, presence: BuildCurrentStatus()).ConfigureAwait(false); } - - //Wait for READY - await _connection.WaitAsync().ConfigureAwait(false); - - await _gatewayLogger.DebugAsync("Sending Status").ConfigureAwait(false); - await SendStatusAsync().ConfigureAwait(false); } finally { - if (_connectionGroupLock != null) - { - await Task.Delay(5000).ConfigureAwait(false); - _connectionGroupLock.Release(); - } + if (locked) + _shardedClient.ReleaseIdentifyLock(); } + + //Wait for READY + await _connection.WaitAsync().ConfigureAwait(false); } private async Task OnDisconnectingAsync(Exception ex) { @@ -316,7 +352,7 @@ namespace Discord.WebSocket /// public override async Task GetApplicationInfoAsync(RequestOptions options = null) - => _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this, options ?? RequestOptions.Default).ConfigureAwait(false)); + => _applicationInfo ??= await ClientHelper.GetApplicationInfoAsync(this, options ?? RequestOptions.Default).ConfigureAwait(false); /// public override SocketGuild GetGuild(ulong id) @@ -326,13 +362,51 @@ namespace Discord.WebSocket public override SocketChannel GetChannel(ulong id) => State.GetChannel(id); /// + /// Gets a generic channel from the cache or does a rest request if unavailable. + /// + /// + /// + /// var channel = await _client.GetChannelAsync(381889909113225237); + /// if (channel != null && channel is IMessageChannel msgChannel) + /// { + /// await msgChannel.SendMessageAsync($"{msgChannel} is created at {msgChannel.CreatedAt}"); + /// } + /// + /// + /// The snowflake identifier of the channel (e.g. `381889909113225237`). + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the channel associated + /// with the snowflake identifier; null when the channel cannot be found. + /// + public async ValueTask GetChannelAsync(ulong id, RequestOptions options = null) + => GetChannel(id) ?? (IChannel)await ClientHelper.GetChannelAsync(this, id, options).ConfigureAwait(false); + /// + /// Gets a user from the cache or does a rest request if unavailable. + /// + /// + /// + /// var user = await _client.GetUserAsync(168693960628371456); + /// if (user != null) + /// Console.WriteLine($"{user} is created at {user.CreatedAt}."; + /// + /// + /// The snowflake identifier of the user (e.g. `168693960628371456`). + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the user associated with + /// the snowflake identifier; null if the user is not found. + /// + public async ValueTask GetUserAsync(ulong id, RequestOptions options = null) + => await ClientHelper.GetUserAsync(this, id, options).ConfigureAwait(false); + /// /// Clears all cached channels from the client. /// public void PurgeChannelCache() => State.PurgeAllChannels(); /// /// Clears cached DM channels from the client. /// - public void PurgeDMChannelCache() => State.PurgeDMChannels(); + public void PurgeDMChannelCache() => RemoveDMChannels(); /// public override SocketUser GetUser(ulong id) @@ -340,18 +414,94 @@ namespace Discord.WebSocket /// public override SocketUser GetUser(string username, string discriminator) => State.Users.FirstOrDefault(x => x.Discriminator == discriminator && x.Username == username); + + /// + /// Gets a global application command. + /// + /// The id of the command. + /// The options to be used when sending the request. + /// + /// A ValueTask that represents the asynchronous get operation. The task result contains the application command if found, otherwise + /// . + /// + public async ValueTask GetGlobalApplicationCommandAsync(ulong id, RequestOptions options = null) + { + var command = State.GetCommand(id); + + if (command != null) + return command; + + var model = await ApiClient.GetGlobalApplicationCommandAsync(id, options); + + if (model == null) + return null; + + command = SocketApplicationCommand.Create(this, model); + + State.AddCommand(command); + + return command; + } + /// + /// Gets a collection of all global commands. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a read-only collection of global + /// application commands. + /// + public async Task> GetGlobalApplicationCommandsAsync(RequestOptions options = null) + { + var commands = (await ApiClient.GetGlobalApplicationCommandsAsync(options)).Select(x => SocketApplicationCommand.Create(this, x)); + + foreach(var command in commands) + { + State.AddCommand(command); + } + + return commands.ToImmutableArray(); + } + + public async Task CreateGlobalApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null) + { + var model = await InteractionHelper.CreateGlobalCommandAsync(this, properties, options).ConfigureAwait(false); + + var entity = State.GetOrAddCommand(model.Id, (id) => SocketApplicationCommand.Create(this, model)); + + //Update it in case it was cached + entity.Update(model); + + return entity; + } + public async Task> BulkOverwriteGlobalApplicationCommandsAsync( + ApplicationCommandProperties[] properties, RequestOptions options = null) + { + var models = await InteractionHelper.BulkOverwriteGlobalCommandsAsync(this, properties, options); + + var entities = models.Select(x => SocketApplicationCommand.Create(this, x)); + + //Purge our previous commands + State.PurgeCommands(x => x.IsGlobalCommand); + + foreach(var entity in entities) + { + State.AddCommand(entity); + } + + return entities.ToImmutableArray(); + } + /// /// Clears cached users from the client. /// public void PurgeUserCache() => State.PurgeUsers(); internal SocketGlobalUser GetOrCreateUser(ClientState state, Discord.API.User model) { - return state.GetOrAddUser(model.Id, x => - { - var user = SocketGlobalUser.Create(this, state, model); - user.GlobalUser.AddRef(); - return user; - }); + return state.GetOrAddUser(model.Id, x => SocketGlobalUser.Create(this, state, model)); + } + internal SocketUser GetOrCreateTemporaryUser(ClientState state, Discord.API.User model) + { + return state.GetUser(model.Id) ?? (SocketUser)SocketUnknownUser.Create(this, state, model); } internal SocketGlobalUser GetOrCreateSelfUser(ClientState state, Discord.API.User model) { @@ -366,12 +516,85 @@ namespace Discord.WebSocket internal void RemoveUser(ulong id) => State.RemoveUser(id); + /// + public override async Task GetStickerAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null) + { + var sticker = _defaultStickers.FirstOrDefault(x => x.Stickers.Any(y => y.Id == id))?.Stickers.FirstOrDefault(x => x.Id == id); + + if (sticker != null) + return sticker; + + foreach(var guild in Guilds) + { + sticker = await guild.GetStickerAsync(id, CacheMode.CacheOnly).ConfigureAwait(false); + + if (sticker != null) + return sticker; + } + + if (mode == CacheMode.CacheOnly) + return null; + + var model = await ApiClient.GetStickerAsync(id, options).ConfigureAwait(false); + + if(model == null) + return null; + + + if (model.GuildId.IsSpecified) + { + var guild = State.GetGuild(model.GuildId.Value); + + //Since the sticker can be from another guild, check if we are in the guild or its in the cache + if (guild != null) + sticker = guild.AddOrUpdateSticker(model); + else + sticker = SocketSticker.Create(this, model); + return sticker; + } + else + { + return SocketSticker.Create(this, model); + } + } + + /// + /// Gets a sticker. + /// + /// The unique identifier of the sticker. + /// A sticker if found, otherwise . + public SocketSticker GetSticker(ulong id) + => GetStickerAsync(id, CacheMode.CacheOnly).GetAwaiter().GetResult(); + + /// + public override async ValueTask> GetVoiceRegionsAsync(RequestOptions options = null) + { + if (_parentClient == null) + { + if (_voiceRegions == null) + { + options = RequestOptions.CreateOrClone(options); + options.IgnoreState = true; + var voiceRegions = await ApiClient.GetVoiceRegionsAsync(options).ConfigureAwait(false); + _voiceRegions = voiceRegions.Select(x => RestVoiceRegion.Create(this, x)).ToImmutableDictionary(x => x.Id); + } + return _voiceRegions.ToReadOnlyCollection(); + } + return await _parentClient.GetVoiceRegionsAsync().ConfigureAwait(false); + } + /// - public override RestVoiceRegion GetVoiceRegion(string id) + public override async ValueTask GetVoiceRegionAsync(string id, RequestOptions options = null) { - if (_voiceRegions.TryGetValue(id, out RestVoiceRegion region)) - return region; - return null; + if (_parentClient == null) + { + if (_voiceRegions == null) + await GetVoiceRegionsAsync().ConfigureAwait(false); + if (_voiceRegions.TryGetValue(id, out RestVoiceRegion region)) + return region; + return null; + } + return await _parentClient.GetVoiceRegionAsync(id, options).ConfigureAwait(false); } /// @@ -379,6 +602,8 @@ namespace Discord.WebSocket { if (ConnectionState == ConnectionState.Connected) { + EnsureGatewayIntent(GatewayIntents.GuildMembers); + //Race condition leads to guilds being requested twice, probably okay await ProcessUserDownloadsAsync(guilds.Select(x => GetGuild(x.Id)).Where(x => x != null)).ConfigureAwait(false); } @@ -387,7 +612,7 @@ namespace Discord.WebSocket { var cachedGuilds = guilds.ToImmutableArray(); - const short batchSize = 50; + const short batchSize = 1; ulong[] batchIds = new ulong[Math.Min(batchSize, cachedGuilds.Length)]; Task[] batchTasks = new Task[batchIds.Length]; int batchCount = (cachedGuilds.Length + (batchSize - 1)) / batchSize; @@ -395,7 +620,7 @@ namespace Discord.WebSocket for (int i = 0, k = 0; i < batchCount; i++) { bool isLast = i == batchCount - 1; - int count = isLast ? (batchIds.Length - (batchCount - 1) * batchSize) : batchSize; + int count = isLast ? (cachedGuilds.Length - (batchCount - 1) * batchSize) : batchSize; for (int j = 0; j < count; j++, k++) { @@ -465,30 +690,97 @@ namespace Discord.WebSocket { if (CurrentUser == null) return; - var status = Status; + var activities = _activity.IsSpecified ? ImmutableList.Create(_activity.Value) : null; + CurrentUser.Presence = new SocketPresence(Status, null, activities); + + var presence = BuildCurrentStatus() ?? (UserStatus.Online, false, null, null); + + await ApiClient.SendPresenceUpdateAsync( + status: presence.Item1, + isAFK: presence.Item2, + since: presence.Item3, + game: presence.Item4).ConfigureAwait(false); + } + + private (UserStatus, bool, long?, GameModel)? BuildCurrentStatus() + { + var status = _status; var statusSince = _statusSince; - CurrentUser.Presence = new SocketPresence(status, Activity, null); + var activity = _activity; - var gameModel = new GameModel(); - // Discord only accepts rich presence over RPC, don't even bother building a payload - if (Activity is RichGame) - throw new NotSupportedException("Outgoing Rich Presences are not supported via WebSocket."); + if (status == null && !activity.IsSpecified) + return null; - if (Activity != null) + GameModel game = null; + //Discord only accepts rich presence over RPC, don't even bother building a payload + + if (activity.GetValueOrDefault() != null) { + var gameModel = new GameModel(); + if (activity.Value is RichGame) + throw new NotSupportedException("Outgoing Rich Presences are not supported via WebSocket."); gameModel.Name = Activity.Name; gameModel.Type = Activity.Type; if (Activity is StreamingGame streamGame) gameModel.StreamUrl = streamGame.Url; + game = gameModel; + } + else if (activity.IsSpecified) + game = null; + + return (status ?? UserStatus.Online, + status == UserStatus.AFK, + statusSince != null ? _statusSince.Value.ToUnixTimeMilliseconds() : (long?)null, + game); + } + + private async Task LogGatewayIntentsWarning() + { + if(_gatewayIntents.HasFlag(GatewayIntents.GuildPresences) && !_presenceUpdated.HasSubscribers) + { + await _gatewayLogger.WarningAsync("You're using the GuildPresences intent without listening to the PresenceUpdate event, consider removing the intent from your config.").ConfigureAwait(false); + } + + if(!_gatewayIntents.HasFlag(GatewayIntents.GuildPresences) && _presenceUpdated.HasSubscribers) + { + await _gatewayLogger.WarningAsync("You're using the PresenceUpdate event without specifying the GuildPresences intent, consider adding the intent to your config.").ConfigureAwait(false); + } + + bool hasGuildScheduledEventsSubscribers = + _guildScheduledEventCancelled.HasSubscribers || + _guildScheduledEventUserRemove.HasSubscribers || + _guildScheduledEventCompleted.HasSubscribers || + _guildScheduledEventCreated.HasSubscribers || + _guildScheduledEventStarted.HasSubscribers || + _guildScheduledEventUpdated.HasSubscribers || + _guildScheduledEventUserAdd.HasSubscribers; + + if(_gatewayIntents.HasFlag(GatewayIntents.GuildScheduledEvents) && !hasGuildScheduledEventsSubscribers) + { + await _gatewayLogger.WarningAsync("You're using the GuildScheduledEvents gateway intent without listening to any events related to that intent, consider removing the intent from your config.").ConfigureAwait(false); + } + + if(!_gatewayIntents.HasFlag(GatewayIntents.GuildScheduledEvents) && hasGuildScheduledEventsSubscribers) + { + await _gatewayLogger.WarningAsync("You're using events related to the GuildScheduledEvents gateway intent without specifying the intent, consider adding the intent to your config.").ConfigureAwait(false); + } + + bool hasInviteEventSubscribers = + _inviteCreatedEvent.HasSubscribers || + _inviteDeletedEvent.HasSubscribers; + + if (_gatewayIntents.HasFlag(GatewayIntents.GuildInvites) && !hasInviteEventSubscribers) + { + await _gatewayLogger.WarningAsync("You're using the GuildInvites gateway intent without listening to any events related to that intent, consider removing the intent from your config.").ConfigureAwait(false); } - await ApiClient.SendStatusUpdateAsync( - status, - status == UserStatus.AFK, - statusSince != null ? _statusSince.Value.ToUnixTimeMilliseconds() : (long?)null, - gameModel).ConfigureAwait(false); + if (!_gatewayIntents.HasFlag(GatewayIntents.GuildInvites) && hasInviteEventSubscribers) + { + await _gatewayLogger.WarningAsync("You're using events related to the GuildInvites gateway intent without specifying the intent, consider adding the intent to your config.").ConfigureAwait(false); + } } + #region ProcessMessageAsync private async Task ProcessMessageAsync(GatewayOpCode opCode, int? seq, string type, object payload) { if (seq != null) @@ -536,7 +828,20 @@ namespace Discord.WebSocket _sessionId = null; _lastSeq = 0; - await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards).ConfigureAwait(false); + if (_shardedClient != null) + { + await _shardedClient.AcquireIdentifyLockAsync(ShardId, _connection.CancelToken).ConfigureAwait(false); + try + { + await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, gatewayIntents: _gatewayIntents, presence: BuildCurrentStatus()).ConfigureAwait(false); + } + finally + { + _shardedClient.ReleaseIdentifyLock(); + } + } + else + await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, gatewayIntents: _gatewayIntents, presence: BuildCurrentStatus()).ConfigureAwait(false); } break; case GatewayOpCode.Reconnect: @@ -548,7 +853,7 @@ namespace Discord.WebSocket case GatewayOpCode.Dispatch: switch (type) { - //Connection + #region Connection case "READY": { try @@ -559,7 +864,11 @@ namespace Discord.WebSocket var state = new ClientState(data.Guilds.Length, data.PrivateChannels.Length); var currentUser = SocketSelfUser.Create(this, state, data.User); + Rest.CreateRestSelfUser(data.User); + var activities = _activity.IsSpecified ? ImmutableList.Create(_activity.Value) : null; + currentUser.Presence = new SocketPresence(Status, null, activities); ApiClient.CurrentUserId = currentUser.Id; + Rest.CurrentUser = RestSelfUser.Create(this, data.User); int unavailableGuilds = 0; for (int i = 0; i < data.Guilds.Length; i++) { @@ -596,6 +905,9 @@ namespace Discord.WebSocket else if (_connection.CancelToken.IsCancellationRequested) return; + if (BaseConfig.AlwaysDownloadUsers) + _ = DownloadUsersAsync(Guilds.Where(x => x.IsAvailable && !x.HasAllMembers)); + await TimedInvokeAsync(_readyEvent, nameof(Ready)).ConfigureAwait(false); await _gatewayLogger.InfoAsync("Ready").ConfigureAwait(false); }); @@ -618,8 +930,9 @@ namespace Discord.WebSocket await _gatewayLogger.InfoAsync("Resumed previous session").ConfigureAwait(false); } break; + #endregion - //Guilds + #region Guilds case "GUILD_CREATE": { var data = (payload as JToken).ToObject(_serializer); @@ -709,7 +1022,8 @@ namespace Discord.WebSocket break; case "GUILD_SYNC": { - await _gatewayLogger.DebugAsync("Received Dispatch (GUILD_SYNC)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync("Ignored Dispatch (GUILD_SYNC)").ConfigureAwait(false); + /*await _gatewayLogger.DebugAsync("Received Dispatch (GUILD_SYNC)").ConfigureAwait(false); //TODO remove? userbot related var data = (payload as JToken).ToObject(_serializer); var guild = State.GetGuild(data.Id); if (guild != null) @@ -726,7 +1040,7 @@ namespace Discord.WebSocket { await UnknownGuildAsync(type, data.Id).ConfigureAwait(false); return; - } + }*/ } break; case "GUILD_DELETE": @@ -768,8 +1082,62 @@ namespace Discord.WebSocket } } break; + case "GUILD_STICKERS_UPDATE": + { + await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_STICKERS_UPDATE)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + + var guild = State.GetGuild(data.GuildId); + + if (guild == null) + { + await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false); + return; + } + + var newStickers = data.Stickers.Where(x => !guild.Stickers.Any(y => y.Id == x.Id)); + var deletedStickers = guild.Stickers.Where(x => !data.Stickers.Any(y => y.Id == x.Id)); + var updatedStickers = data.Stickers.Select(x => + { + var s = guild.Stickers.FirstOrDefault(y => y.Id == x.Id); + if (s == null) + return null; + + var e = s.Equals(x); + if (!e) + { + return (s, x) as (SocketCustomSticker Entity, API.Sticker Model)?; + } + else + { + return null; + } + }).Where(x => x.HasValue).Select(x => x.Value).ToArray(); + + foreach (var model in newStickers) + { + var entity = guild.AddSticker(model); + await TimedInvokeAsync(_guildStickerCreated, nameof(GuildStickerCreated), entity); + } + foreach (var sticker in deletedStickers) + { + var entity = guild.RemoveSticker(sticker.Id); + await TimedInvokeAsync(_guildStickerDeleted, nameof(GuildStickerDeleted), entity); + } + foreach (var entityModelPair in updatedStickers) + { + var before = entityModelPair.Entity.Clone(); + + entityModelPair.Entity.Update(entityModelPair.Model); + + await TimedInvokeAsync(_guildStickerUpdated, nameof(GuildStickerUpdated), before, entityModelPair.Entity); + } + } + break; + #endregion - //Channels + #region Channels case "CHANNEL_CREATE": { await _gatewayLogger.DebugAsync("Received Dispatch (CHANNEL_CREATE)").ConfigureAwait(false); @@ -871,8 +1239,9 @@ namespace Discord.WebSocket } } break; + #endregion - //Members + #region Members case "GUILD_MEMBER_ADD": { await _gatewayLogger.DebugAsync("Received Dispatch (GUILD_MEMBER_ADD)").ConfigureAwait(false); @@ -917,17 +1286,24 @@ namespace Discord.WebSocket if (user != null) { + var globalBefore = user.GlobalUser.Clone(); + if (user.GlobalUser.Update(State, data.User)) + { + //Global data was updated, trigger UserUpdated + await TimedInvokeAsync(_userUpdatedEvent, nameof(UserUpdated), globalBefore, user).ConfigureAwait(false); + } + var before = user.Clone(); user.Update(State, data); - await TimedInvokeAsync(_guildMemberUpdatedEvent, nameof(GuildMemberUpdated), before, user).ConfigureAwait(false); + + var cacheableBefore = new Cacheable(before, user.Id, true, () => null); + await TimedInvokeAsync(_guildMemberUpdatedEvent, nameof(GuildMemberUpdated), cacheableBefore, user).ConfigureAwait(false); } else { - if (!guild.HasAllMembers) - await IncompleteGuildUserAsync(type, data.User.Id, data.GuildId).ConfigureAwait(false); - else - await UnknownGuildUserAsync(type, data.User.Id, data.GuildId).ConfigureAwait(false); - return; + user = guild.AddOrUpdateUser(data); + var cacheableBefore = new Cacheable(user, user.Id, true, () => null); + await TimedInvokeAsync(_guildMemberUpdatedEvent, nameof(GuildMemberUpdated), cacheableBefore, user).ConfigureAwait(false); } } else @@ -945,7 +1321,7 @@ namespace Discord.WebSocket var guild = State.GetGuild(data.GuildId); if (guild != null) { - var user = guild.RemoveUser(data.User.Id); + SocketUser user = guild.RemoveUser(data.User.Id); guild.MemberCount--; if (!guild.IsSynced) @@ -954,16 +1330,14 @@ namespace Discord.WebSocket return; } + user ??= State.GetUser(data.User.Id); + if (user != null) - await TimedInvokeAsync(_userLeftEvent, nameof(UserLeft), user).ConfigureAwait(false); + user.Update(State, data.User); else - { - if (!guild.HasAllMembers) - await IncompleteGuildUserAsync(type, data.User.Id, data.GuildId).ConfigureAwait(false); - else - await UnknownGuildUserAsync(type, data.User.Id, data.GuildId).ConfigureAwait(false); - return; - } + user = State.GetOrAddUser(data.User.Id, (x) => SocketGlobalUser.Create(this, State, data.User)); + + await TimedInvokeAsync(_userLeftEvent, nameof(UserLeft), guild, user).ConfigureAwait(false); } else { @@ -996,6 +1370,32 @@ namespace Discord.WebSocket } } break; + case "GUILD_JOIN_REQUEST_DELETE": + { + await _gatewayLogger.DebugAsync("Received Dispatch (GUILD_JOIN_REQUEST_DELETE)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + + var guild = State.GetGuild(data.GuildId); + + if (guild == null) + { + await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false); + return; + } + + var user = guild.RemoveUser(data.UserId); + guild.MemberCount--; + + var cacheableUser = new Cacheable(user, data.UserId, user != null, () => Task.FromResult((SocketGuildUser)null)); + + await TimedInvokeAsync(_guildJoinRequestDeletedEvent, nameof(GuildJoinRequestDeleted), cacheableUser, guild).ConfigureAwait(false); + } + break; + #endregion + + #region DM Channels + case "CHANNEL_RECIPIENT_ADD": { await _gatewayLogger.DebugAsync("Received Dispatch (CHANNEL_RECIPIENT_ADD)").ConfigureAwait(false); @@ -1037,7 +1437,9 @@ namespace Discord.WebSocket } break; - //Roles + #endregion + + #region Roles case "GUILD_ROLE_CREATE": { await _gatewayLogger.DebugAsync("Received Dispatch (GUILD_ROLE_CREATE)").ConfigureAwait(false); @@ -1129,8 +1531,9 @@ namespace Discord.WebSocket } } break; + #endregion - //Bans + #region Bans case "GUILD_BAN_ADD": { await _gatewayLogger.DebugAsync("Received Dispatch (GUILD_BAN_ADD)").ConfigureAwait(false); @@ -1183,63 +1586,71 @@ namespace Discord.WebSocket } } break; + #endregion - //Messages + #region Messages case "MESSAGE_CREATE": { await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_CREATE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); - if (State.GetChannel(data.ChannelId) is ISocketMessageChannel channel) + var channel = GetChannel(data.ChannelId) as ISocketMessageChannel; + + var guild = (channel as SocketGuildChannel)?.Guild; + if (guild != null && !guild.IsSynced) { - var guild = (channel as SocketGuildChannel)?.Guild; - if (guild != null && !guild.IsSynced) + await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false); + return; + } + + if (channel == null) + { + if (!data.GuildId.IsSpecified) // assume it is a DM { - await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false); - return; + channel = CreateDMChannel(data.ChannelId, data.Author.Value, State); } - - SocketUser author; - if (guild != null) + else { - if (data.WebhookId.IsSpecified) - author = SocketWebhookUser.Create(guild, State, data.Author.Value, data.WebhookId.Value); - else - author = guild.GetUser(data.Author.Value.Id); + await UnknownChannelAsync(type, data.ChannelId).ConfigureAwait(false); + return; } + } + + SocketUser author; + if (guild != null) + { + if (data.WebhookId.IsSpecified) + author = SocketWebhookUser.Create(guild, State, data.Author.Value, data.WebhookId.Value); else - author = (channel as SocketChannel).GetUser(data.Author.Value.Id); + author = guild.GetUser(data.Author.Value.Id); + } + else + author = (channel as SocketChannel).GetUser(data.Author.Value.Id); - if (author == null) + if (author == null) + { + if (guild != null) { - if (guild != null) + if (data.Member.IsSpecified) // member isn't always included, but use it when we can { - if (data.Member.IsSpecified) // member isn't always included, but use it when we can - { - data.Member.Value.User = data.Author.Value; - author = guild.AddOrUpdateUser(data.Member.Value); - } - else - author = guild.AddOrUpdateUser(data.Author.Value); // user has no guild-specific data + data.Member.Value.User = data.Author.Value; + author = guild.AddOrUpdateUser(data.Member.Value); } - else if (channel is SocketGroupChannel) - author = (channel as SocketGroupChannel).GetOrAddUser(data.Author.Value); else - { - await UnknownChannelUserAsync(type, data.Author.Value.Id, channel.Id).ConfigureAwait(false); - return; - } + author = guild.AddOrUpdateUser(data.Author.Value); // user has no guild-specific data + } + else if (channel is SocketGroupChannel groupChannel) + author = groupChannel.GetOrAddUser(data.Author.Value); + else + { + await UnknownChannelUserAsync(type, data.Author.Value.Id, channel.Id).ConfigureAwait(false); + return; } - - var msg = SocketMessage.Create(this, State, author, channel, data); - SocketChannelHelper.AddMessage(channel, this, msg); - await TimedInvokeAsync(_messageReceivedEvent, nameof(MessageReceived), msg).ConfigureAwait(false); - } - else - { - await UnknownChannelAsync(type, data.ChannelId).ConfigureAwait(false); - return; } + + var msg = SocketMessage.Create(this, State, author, channel, data); + SocketChannelHelper.AddMessage(channel, this, msg); + await TimedInvokeAsync(_messageReceivedEvent, nameof(MessageReceived), msg).ConfigureAwait(false); } break; case "MESSAGE_UPDATE": @@ -1247,46 +1658,534 @@ namespace Discord.WebSocket await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_UPDATE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); - if (State.GetChannel(data.ChannelId) is ISocketMessageChannel channel) + var channel = GetChannel(data.ChannelId) as ISocketMessageChannel; + + var guild = (channel as SocketGuildChannel)?.Guild; + if (guild != null && !guild.IsSynced) + { + await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false); + return; + } + + SocketMessage before = null, after = null; + SocketMessage cachedMsg = channel?.GetCachedMessage(data.Id); + bool isCached = cachedMsg != null; + if (isCached) + { + before = cachedMsg.Clone(); + cachedMsg.Update(State, data); + after = cachedMsg; + } + else + { + //Edited message isn't in cache, create a detached one + SocketUser author; + if (data.Author.IsSpecified) + { + if (guild != null) + { + if (data.WebhookId.IsSpecified) + author = SocketWebhookUser.Create(guild, State, data.Author.Value, data.WebhookId.Value); + else + author = guild.GetUser(data.Author.Value.Id); + } + else + author = (channel as SocketChannel)?.GetUser(data.Author.Value.Id); + + if (author == null) + { + if (guild != null) + { + if (data.Member.IsSpecified) // member isn't always included, but use it when we can + { + data.Member.Value.User = data.Author.Value; + author = guild.AddOrUpdateUser(data.Member.Value); + } + else + author = guild.AddOrUpdateUser(data.Author.Value); // user has no guild-specific data + } + else if (channel is SocketGroupChannel groupChannel) + author = groupChannel.GetOrAddUser(data.Author.Value); + } + } + else + // Message author wasn't specified in the payload, so create a completely anonymous unknown user + author = new SocketUnknownUser(this, id: 0); + + if (channel == null) + { + if (!data.GuildId.IsSpecified) // assume it is a DM + { + if (data.Author.IsSpecified) + { + var dmChannel = CreateDMChannel(data.ChannelId, data.Author.Value, State); + channel = dmChannel; + author = dmChannel.Recipient; + } + else + channel = CreateDMChannel(data.ChannelId, author, State); + } + else + { + await UnknownChannelAsync(type, data.ChannelId).ConfigureAwait(false); + return; + } + } + + after = SocketMessage.Create(this, State, author, channel, data); + } + var cacheableBefore = new Cacheable(before, data.Id, isCached, async () => await channel.GetMessageAsync(data.Id).ConfigureAwait(false)); + + await TimedInvokeAsync(_messageUpdatedEvent, nameof(MessageUpdated), cacheableBefore, after, channel).ConfigureAwait(false); + } + break; + case "MESSAGE_DELETE": + { + await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_DELETE)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + var channel = GetChannel(data.ChannelId) as ISocketMessageChannel; + + var guild = (channel as SocketGuildChannel)?.Guild; + if (!(guild?.IsSynced ?? true)) + { + await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false); + return; + } + + SocketMessage msg = null; + if (channel != null) + msg = SocketChannelHelper.RemoveMessage(channel, this, data.Id); + var cacheableMsg = new Cacheable(msg, data.Id, msg != null, () => Task.FromResult((IMessage)null)); + var cacheableChannel = new Cacheable(channel, data.ChannelId, channel != null, async () => await GetChannelAsync(data.ChannelId).ConfigureAwait(false) as IMessageChannel); + + await TimedInvokeAsync(_messageDeletedEvent, nameof(MessageDeleted), cacheableMsg, cacheableChannel).ConfigureAwait(false); + } + break; + case "MESSAGE_REACTION_ADD": + { + await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_REACTION_ADD)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + var channel = GetChannel(data.ChannelId) as ISocketMessageChannel; + + var cachedMsg = channel?.GetCachedMessage(data.MessageId) as SocketUserMessage; + bool isMsgCached = cachedMsg != null; + IUser user = null; + if (channel != null) + user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly).ConfigureAwait(false); + + var optionalMsg = !isMsgCached + ? Optional.Create() + : Optional.Create(cachedMsg); + + if (data.Member.IsSpecified) { var guild = (channel as SocketGuildChannel)?.Guild; - if (guild != null && !guild.IsSynced) + + if (guild != null) + user = guild.AddOrUpdateUser(data.Member.Value); + } + else + user = GetUser(data.UserId); + + var optionalUser = user is null + ? Optional.Create() + : Optional.Create(user); + + var cacheableChannel = new Cacheable(channel, data.ChannelId, channel != null, async () => await GetChannelAsync(data.ChannelId).ConfigureAwait(false) as IMessageChannel); + var cacheableMsg = new Cacheable(cachedMsg, data.MessageId, isMsgCached, async () => + { + var channelObj = await cacheableChannel.GetOrDownloadAsync().ConfigureAwait(false); + return await channelObj.GetMessageAsync(data.MessageId).ConfigureAwait(false) as IUserMessage; + }); + var reaction = SocketReaction.Create(data, channel, optionalMsg, optionalUser); + + cachedMsg?.AddReaction(reaction); + + await TimedInvokeAsync(_reactionAddedEvent, nameof(ReactionAdded), cacheableMsg, cacheableChannel, reaction).ConfigureAwait(false); + } + break; + case "MESSAGE_REACTION_REMOVE": + { + await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_REACTION_REMOVE)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + var channel = GetChannel(data.ChannelId) as ISocketMessageChannel; + + var cachedMsg = channel?.GetCachedMessage(data.MessageId) as SocketUserMessage; + bool isMsgCached = cachedMsg != null; + IUser user = null; + if (channel != null) + user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly).ConfigureAwait(false); + else if (!data.GuildId.IsSpecified) + user = GetUser(data.UserId); + + var optionalMsg = !isMsgCached + ? Optional.Create() + : Optional.Create(cachedMsg); + + var optionalUser = user is null + ? Optional.Create() + : Optional.Create(user); + + var cacheableChannel = new Cacheable(channel, data.ChannelId, channel != null, async () => await GetChannelAsync(data.ChannelId).ConfigureAwait(false) as IMessageChannel); + var cacheableMsg = new Cacheable(cachedMsg, data.MessageId, isMsgCached, async () => + { + var channelObj = await cacheableChannel.GetOrDownloadAsync().ConfigureAwait(false); + return await channelObj.GetMessageAsync(data.MessageId).ConfigureAwait(false) as IUserMessage; + }); + var reaction = SocketReaction.Create(data, channel, optionalMsg, optionalUser); + + cachedMsg?.RemoveReaction(reaction); + + await TimedInvokeAsync(_reactionRemovedEvent, nameof(ReactionRemoved), cacheableMsg, cacheableChannel, reaction).ConfigureAwait(false); + } + break; + case "MESSAGE_REACTION_REMOVE_ALL": + { + await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_REACTION_REMOVE_ALL)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + var channel = GetChannel(data.ChannelId) as ISocketMessageChannel; + + var cacheableChannel = new Cacheable(channel, data.ChannelId, channel != null, async () => await GetChannelAsync(data.ChannelId).ConfigureAwait(false) as IMessageChannel); + var cachedMsg = channel?.GetCachedMessage(data.MessageId) as SocketUserMessage; + bool isMsgCached = cachedMsg != null; + var cacheableMsg = new Cacheable(cachedMsg, data.MessageId, isMsgCached, async () => + { + var channelObj = await cacheableChannel.GetOrDownloadAsync().ConfigureAwait(false); + return await channelObj.GetMessageAsync(data.MessageId).ConfigureAwait(false) as IUserMessage; + }); + + cachedMsg?.ClearReactions(); + + await TimedInvokeAsync(_reactionsClearedEvent, nameof(ReactionsCleared), cacheableMsg, cacheableChannel).ConfigureAwait(false); + } + break; + case "MESSAGE_REACTION_REMOVE_EMOJI": + { + await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_REACTION_REMOVE_EMOJI)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + var channel = GetChannel(data.ChannelId) as ISocketMessageChannel; + + var cachedMsg = channel?.GetCachedMessage(data.MessageId) as SocketUserMessage; + bool isMsgCached = cachedMsg != null; + + var optionalMsg = !isMsgCached + ? Optional.Create() + : Optional.Create(cachedMsg); + + var cacheableChannel = new Cacheable(channel, data.ChannelId, channel != null, async () => await GetChannelAsync(data.ChannelId).ConfigureAwait(false) as IMessageChannel); + var cacheableMsg = new Cacheable(cachedMsg, data.MessageId, isMsgCached, async () => + { + var channelObj = await cacheableChannel.GetOrDownloadAsync().ConfigureAwait(false); + return await channelObj.GetMessageAsync(data.MessageId).ConfigureAwait(false) as IUserMessage; + }); + var emote = data.Emoji.ToIEmote(); + + cachedMsg?.RemoveReactionsForEmote(emote); + + await TimedInvokeAsync(_reactionsRemovedForEmoteEvent, nameof(ReactionsRemovedForEmote), cacheableMsg, cacheableChannel, emote).ConfigureAwait(false); + } + break; + case "MESSAGE_DELETE_BULK": + { + await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_DELETE_BULK)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + var channel = GetChannel(data.ChannelId) as ISocketMessageChannel; + + var guild = (channel as SocketGuildChannel)?.Guild; + if (!(guild?.IsSynced ?? true)) + { + await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false); + return; + } + + var cacheableChannel = new Cacheable(channel, data.ChannelId, channel != null, async () => await GetChannelAsync(data.ChannelId).ConfigureAwait(false) as IMessageChannel); + var cacheableList = new List>(data.Ids.Length); + foreach (ulong id in data.Ids) + { + SocketMessage msg = null; + if (channel != null) + msg = SocketChannelHelper.RemoveMessage(channel, this, id); + bool isMsgCached = msg != null; + var cacheableMsg = new Cacheable(msg, id, isMsgCached, () => Task.FromResult((IMessage)null)); + cacheableList.Add(cacheableMsg); + } + + await TimedInvokeAsync(_messagesBulkDeletedEvent, nameof(MessagesBulkDeleted), cacheableList, cacheableChannel).ConfigureAwait(false); + } + break; + #endregion + + #region Statuses + case "PRESENCE_UPDATE": + { + await _gatewayLogger.DebugAsync("Received Dispatch (PRESENCE_UPDATE)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + + SocketUser user = null; + + if (data.GuildId.IsSpecified) + { + var guild = State.GetGuild(data.GuildId.Value); + if (guild == null) + { + await UnknownGuildAsync(type, data.GuildId.Value).ConfigureAwait(false); + return; + } + if (!guild.IsSynced) { await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false); return; } - SocketMessage before = null, after = null; - SocketMessage cachedMsg = channel.GetCachedMessage(data.Id); - bool isCached = cachedMsg != null; - if (isCached) + user = guild.GetUser(data.User.Id); + if (user == null) { - before = cachedMsg.Clone(); - cachedMsg.Update(State, data); - after = cachedMsg; + if (data.Status == UserStatus.Offline) + { + return; + } + user = guild.AddOrUpdateUser(data); } else { - //Edited message isnt in cache, create a detached one - SocketUser author; - if (data.Author.IsSpecified) + var globalBefore = user.GlobalUser.Clone(); + if (user.GlobalUser.Update(State, data.User)) { - if (guild != null) - author = guild.GetUser(data.Author.Value.Id); - else - author = (channel as SocketChannel).GetUser(data.Author.Value.Id); - if (author == null) - author = SocketUnknownUser.Create(this, State, data.Author.Value); + //Global data was updated, trigger UserUpdated + await TimedInvokeAsync(_userUpdatedEvent, nameof(UserUpdated), globalBefore, user).ConfigureAwait(false); } - else - // Message author wasn't specified in the payload, so create a completely anonymous unknown user - author = new SocketUnknownUser(this, id: 0); + } + } + else + { + user = State.GetUser(data.User.Id); + if (user == null) + { + await UnknownGlobalUserAsync(type, data.User.Id).ConfigureAwait(false); + return; + } + } + + var before = user.Presence?.Clone(); + user.Update(State, data.User); + user.Update(data); + await TimedInvokeAsync(_presenceUpdated, nameof(PresenceUpdated), user, before, user.Presence).ConfigureAwait(false); + } + break; + case "TYPING_START": + { + await _gatewayLogger.DebugAsync("Received Dispatch (TYPING_START)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + var channel = GetChannel(data.ChannelId) as ISocketMessageChannel; + + var guild = (channel as SocketGuildChannel)?.Guild; + if (!(guild?.IsSynced ?? true)) + { + await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false); + return; + } + + var cacheableChannel = new Cacheable(channel, data.ChannelId, channel != null, async () => await GetChannelAsync(data.ChannelId).ConfigureAwait(false) as IMessageChannel); + + var user = (channel as SocketChannel)?.GetUser(data.UserId); + if (user == null) + { + if (guild != null) + user = guild.AddOrUpdateUser(data.Member); + } + var cacheableUser = new Cacheable(user, data.UserId, user != null, async () => await GetUserAsync(data.UserId).ConfigureAwait(false)); + + await TimedInvokeAsync(_userIsTypingEvent, nameof(UserIsTyping), cacheableUser, cacheableChannel).ConfigureAwait(false); + } + break; + #endregion + + #region Users + case "USER_UPDATE": + { + await _gatewayLogger.DebugAsync("Received Dispatch (USER_UPDATE)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + if (data.Id == CurrentUser.Id) + { + var before = CurrentUser.Clone(); + CurrentUser.Update(State, data); + await TimedInvokeAsync(_selfUpdatedEvent, nameof(CurrentUserUpdated), before, CurrentUser).ConfigureAwait(false); + } + else + { + await _gatewayLogger.WarningAsync("Received USER_UPDATE for wrong user.").ConfigureAwait(false); + return; + } + } + break; + #endregion + + #region Voice + case "VOICE_STATE_UPDATE": + { + await _gatewayLogger.DebugAsync("Received Dispatch (VOICE_STATE_UPDATE)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + SocketUser user; + SocketVoiceState before, after; + if (data.GuildId != null) + { + var guild = State.GetGuild(data.GuildId.Value); + if (guild == null) + { + await UnknownGuildAsync(type, data.GuildId.Value).ConfigureAwait(false); + return; + } + else if (!guild.IsSynced) + { + await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false); + return; + } + + if (data.ChannelId != null) + { + before = guild.GetVoiceState(data.UserId)?.Clone() ?? SocketVoiceState.Default; + after = await guild.AddOrUpdateVoiceStateAsync(State, data).ConfigureAwait(false); + /*if (data.UserId == CurrentUser.Id) + { + var _ = guild.FinishJoinAudioChannel().ConfigureAwait(false); + }*/ + } + else + { + before = await guild.RemoveVoiceStateAsync(data.UserId).ConfigureAwait(false) ?? SocketVoiceState.Default; + after = SocketVoiceState.Create(null, data); + } - after = SocketMessage.Create(this, State, author, channel, data); + //Per g250k, this should always be sent, but apparently not always + user = guild.GetUser(data.UserId) + ?? (data.Member.IsSpecified ? guild.AddOrUpdateUser(data.Member.Value) : null); + if (user == null) + { + await UnknownGuildUserAsync(type, data.UserId, guild.Id).ConfigureAwait(false); + return; + } + } + else + { + var groupChannel = GetChannel(data.ChannelId.Value) as SocketGroupChannel; + if (groupChannel == null) + { + await UnknownChannelAsync(type, data.ChannelId.Value).ConfigureAwait(false); + return; + } + if (data.ChannelId != null) + { + before = groupChannel.GetVoiceState(data.UserId)?.Clone() ?? SocketVoiceState.Default; + after = groupChannel.AddOrUpdateVoiceState(State, data); + } + else + { + before = groupChannel.RemoveVoiceState(data.UserId) ?? SocketVoiceState.Default; + after = SocketVoiceState.Create(null, data); + } + user = groupChannel.GetUser(data.UserId); + if (user == null) + { + await UnknownChannelUserAsync(type, data.UserId, groupChannel.Id).ConfigureAwait(false); + return; } - var cacheableBefore = new Cacheable(before, data.Id, isCached, async () => await channel.GetMessageAsync(data.Id).ConfigureAwait(false)); + } + + if (user is SocketGuildUser guildUser && data.ChannelId.HasValue) + { + SocketStageChannel stage = guildUser.Guild.GetStageChannel(data.ChannelId.Value); - await TimedInvokeAsync(_messageUpdatedEvent, nameof(MessageUpdated), cacheableBefore, after, channel).ConfigureAwait(false); + if (stage != null && before.VoiceChannel != null && after.VoiceChannel != null) + { + if (!before.RequestToSpeakTimestamp.HasValue && after.RequestToSpeakTimestamp.HasValue) + { + await TimedInvokeAsync(_requestToSpeak, nameof(RequestToSpeak), stage, guildUser); + return; + } + if(before.IsSuppressed && !after.IsSuppressed) + { + await TimedInvokeAsync(_speakerAdded, nameof(SpeakerAdded), stage, guildUser); + return; + } + if(!before.IsSuppressed && after.IsSuppressed) + { + await TimedInvokeAsync(_speakerRemoved, nameof(SpeakerRemoved), stage, guildUser); + } + } + } + + await TimedInvokeAsync(_userVoiceStateUpdatedEvent, nameof(UserVoiceStateUpdated), user, before, after).ConfigureAwait(false); + } + break; + case "VOICE_SERVER_UPDATE": + { + await _gatewayLogger.DebugAsync("Received Dispatch (VOICE_SERVER_UPDATE)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + var guild = State.GetGuild(data.GuildId); + var isCached = guild != null; + var cachedGuild = new Cacheable(guild, data.GuildId, isCached, + () => Task.FromResult(State.GetGuild(data.GuildId) as IGuild)); + + var voiceServer = new SocketVoiceServer(cachedGuild, data.Endpoint, data.Token); + await TimedInvokeAsync(_voiceServerUpdatedEvent, nameof(UserVoiceStateUpdated), voiceServer).ConfigureAwait(false); + + if (isCached) + { + var endpoint = data.Endpoint; + + //Only strip out the port if the endpoint contains it + var portBegin = endpoint.LastIndexOf(':'); + if (portBegin > 0) + endpoint = endpoint.Substring(0, portBegin); + + var _ = guild.FinishConnectAudio(endpoint, data.Token).ConfigureAwait(false); + } + else + { + await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false); + } + + } + break; + #endregion + + #region Invites + case "INVITE_CREATE": + { + await _gatewayLogger.DebugAsync("Received Dispatch (INVITE_CREATE)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + if (State.GetChannel(data.ChannelId) is SocketGuildChannel channel) + { + var guild = channel.Guild; + if (!guild.IsSynced) + { + await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false); + return; + } + + SocketGuildUser inviter = data.Inviter.IsSpecified + ? (guild.GetUser(data.Inviter.Value.Id) ?? guild.AddOrUpdateUser(data.Inviter.Value)) + : null; + + SocketUser target = data.TargetUser.IsSpecified + ? (guild.GetUser(data.TargetUser.Value.Id) ?? (SocketUser)SocketUnknownUser.Create(this, State, data.TargetUser.Value)) + : null; + + var invite = SocketInvite.Create(this, guild, channel, inviter, target, data); + + await TimedInvokeAsync(_inviteCreatedEvent, nameof(InviteCreated), invite).ConfigureAwait(false); } else { @@ -1295,25 +2194,21 @@ namespace Discord.WebSocket } } break; - case "MESSAGE_DELETE": + case "INVITE_DELETE": { - await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_DELETE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync("Received Dispatch (INVITE_DELETE)").ConfigureAwait(false); - var data = (payload as JToken).ToObject(_serializer); - if (State.GetChannel(data.ChannelId) is ISocketMessageChannel channel) + var data = (payload as JToken).ToObject(_serializer); + if (State.GetChannel(data.ChannelId) is SocketGuildChannel channel) { - var guild = (channel as SocketGuildChannel)?.Guild; - if (!(guild?.IsSynced ?? true)) + var guild = channel.Guild; + if (!guild.IsSynced) { await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false); return; } - var msg = SocketChannelHelper.RemoveMessage(channel, this, data.Id); - bool isCached = msg != null; - var cacheable = new Cacheable(msg, data.Id, isCached, async () => await channel.GetMessageAsync(data.Id).ConfigureAwait(false)); - - await TimedInvokeAsync(_messageDeletedEvent, nameof(MessageDeleted), cacheable, channel).ConfigureAwait(false); + await TimedInvokeAsync(_inviteDeletedEvent, nameof(InviteDeleted), channel, data.Code).ConfigureAwait(false); } else { @@ -1322,352 +2217,527 @@ namespace Discord.WebSocket } } break; - case "MESSAGE_REACTION_ADD": + #endregion + + #region Interactions + case "INTERACTION_CREATE": { - await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_REACTION_ADD)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync("Received Dispatch (INTERACTION_CREATE)").ConfigureAwait(false); - var data = (payload as JToken).ToObject(_serializer); - if (State.GetChannel(data.ChannelId) is ISocketMessageChannel channel) + var data = (payload as JToken).ToObject(_serializer); + + SocketChannel channel = null; + if(data.ChannelId.IsSpecified) + { + channel = State.GetChannel(data.ChannelId.Value); + } + else if (data.User.IsSpecified) { - var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage; - bool isCached = cachedMsg != null; - var user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly).ConfigureAwait(false); + channel = State.GetDMChannel(data.User.Value.Id); + } - var optionalMsg = !isCached - ? Optional.Create() - : Optional.Create(cachedMsg); + if (channel == null) + { + var channelModel = await Rest.ApiClient.GetChannelAsync(data.ChannelId.Value); - var optionalUser = user is null - ? Optional.Create() - : Optional.Create(user); + if (data.GuildId.IsSpecified) + channel = SocketTextChannel.Create(State.GetGuild(data.GuildId.Value), State, channelModel); + else + channel = (SocketChannel)SocketChannel.CreatePrivate(this, State, channelModel); - var reaction = SocketReaction.Create(data, channel, optionalMsg, optionalUser); - var cacheable = new Cacheable(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId).ConfigureAwait(false) as IUserMessage); + State.AddChannel(channel); + } - cachedMsg?.AddReaction(reaction); + if (channel is ISocketMessageChannel textChannel) + { + var guild = (channel as SocketGuildChannel)?.Guild; + if (guild != null && !guild.IsSynced) + { + await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false); + return; + } - await TimedInvokeAsync(_reactionAddedEvent, nameof(ReactionAdded), cacheable, channel, reaction).ConfigureAwait(false); + var interaction = SocketInteraction.Create(this, data, channel as ISocketMessageChannel); + + await TimedInvokeAsync(_interactionCreatedEvent, nameof(InteractionCreated), interaction).ConfigureAwait(false); + + switch (interaction) + { + case SocketSlashCommand slashCommand: + await TimedInvokeAsync(_slashCommandExecuted, nameof(SlashCommandExecuted), slashCommand).ConfigureAwait(false); + break; + case SocketMessageComponent messageComponent: + if(messageComponent.Data.Type == ComponentType.SelectMenu) + await TimedInvokeAsync(_selectMenuExecuted, nameof(SelectMenuExecuted), messageComponent).ConfigureAwait(false); + if(messageComponent.Data.Type == ComponentType.Button) + await TimedInvokeAsync(_buttonExecuted, nameof(ButtonExecuted), messageComponent).ConfigureAwait(false); + break; + case SocketUserCommand userCommand: + await TimedInvokeAsync(_userCommandExecuted, nameof(UserCommandExecuted), userCommand).ConfigureAwait(false); + break; + case SocketMessageCommand messageCommand: + await TimedInvokeAsync(_messageCommandExecuted, nameof(MessageCommandExecuted), messageCommand).ConfigureAwait(false); + break; + case SocketAutocompleteInteraction autocomplete: + await TimedInvokeAsync(_autocompleteExecuted, nameof(AutocompleteExecuted), autocomplete).ConfigureAwait(false); + break; + } } else { - await UnknownChannelAsync(type, data.ChannelId).ConfigureAwait(false); + await UnknownChannelAsync(type, data.ChannelId.Value).ConfigureAwait(false); return; } } break; - case "MESSAGE_REACTION_REMOVE": + case "APPLICATION_COMMAND_CREATE": { - await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_REACTION_REMOVE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync("Received Dispatch (APPLICATION_COMMAND_CREATE)").ConfigureAwait(false); - var data = (payload as JToken).ToObject(_serializer); - if (State.GetChannel(data.ChannelId) is ISocketMessageChannel channel) + var data = (payload as JToken).ToObject(_serializer); + + if (data.GuildId.IsSpecified) { - var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage; - bool isCached = cachedMsg != null; - var user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly).ConfigureAwait(false); + var guild = State.GetGuild(data.GuildId.Value); + if (guild == null) + { + await UnknownGuildAsync(type, data.GuildId.Value).ConfigureAwait(false); + return; + } + } - var optionalMsg = !isCached - ? Optional.Create() - : Optional.Create(cachedMsg); + var applicationCommand = SocketApplicationCommand.Create(this, data); - var optionalUser = user is null - ? Optional.Create() - : Optional.Create(user); + State.AddCommand(applicationCommand); - var reaction = SocketReaction.Create(data, channel, optionalMsg, optionalUser); - var cacheable = new Cacheable(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId).ConfigureAwait(false) as IUserMessage); + await TimedInvokeAsync(_applicationCommandCreated, nameof(ApplicationCommandCreated), applicationCommand).ConfigureAwait(false); + } + break; + case "APPLICATION_COMMAND_UPDATE": + { + await _gatewayLogger.DebugAsync("Received Dispatch (APPLICATION_COMMAND_UPDATE)").ConfigureAwait(false); - cachedMsg?.RemoveReaction(reaction); + var data = (payload as JToken).ToObject(_serializer); - await TimedInvokeAsync(_reactionRemovedEvent, nameof(ReactionRemoved), cacheable, channel, reaction).ConfigureAwait(false); + if (data.GuildId.IsSpecified) + { + var guild = State.GetGuild(data.GuildId.Value); + if (guild == null) + { + await UnknownGuildAsync(type, data.GuildId.Value).ConfigureAwait(false); + return; + } + } + + var applicationCommand = SocketApplicationCommand.Create(this, data); + + State.AddCommand(applicationCommand); + + await TimedInvokeAsync(_applicationCommandUpdated, nameof(ApplicationCommandUpdated), applicationCommand).ConfigureAwait(false); + } + break; + case "APPLICATION_COMMAND_DELETE": + { + await _gatewayLogger.DebugAsync("Received Dispatch (APPLICATION_COMMAND_DELETE)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + + if (data.GuildId.IsSpecified) + { + var guild = State.GetGuild(data.GuildId.Value); + if (guild == null) + { + await UnknownGuildAsync(type, data.GuildId.Value).ConfigureAwait(false); + return; + } + } + + var applicationCommand = SocketApplicationCommand.Create(this, data); + + State.RemoveCommand(applicationCommand.Id); + + await TimedInvokeAsync(_applicationCommandDeleted, nameof(ApplicationCommandDeleted), applicationCommand).ConfigureAwait(false); + } + break; + #endregion + + #region Threads + case "THREAD_CREATE": + { + await _gatewayLogger.DebugAsync("Received Dispatch (THREAD_CREATE)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + + var guild = State.GetGuild(data.GuildId.Value); + + if (guild == null) + { + await UnknownGuildAsync(type, data.GuildId.Value); + return; + } + + SocketThreadChannel threadChannel = null; + + if ((threadChannel = guild.ThreadChannels.FirstOrDefault(x => x.Id == data.Id)) != null) + { + threadChannel.Update(State, data); + + if(data.ThreadMember.IsSpecified) + threadChannel.AddOrUpdateThreadMember(data.ThreadMember.Value, guild.CurrentUser); } else { - await UnknownChannelAsync(type, data.ChannelId).ConfigureAwait(false); + threadChannel = (SocketThreadChannel)guild.AddChannel(State, data); + if (data.ThreadMember.IsSpecified) + threadChannel.AddOrUpdateThreadMember(data.ThreadMember.Value, guild.CurrentUser); + } + + await TimedInvokeAsync(_threadCreated, nameof(ThreadCreated), threadChannel).ConfigureAwait(false); + } + + break; + case "THREAD_UPDATE": + { + await _gatewayLogger.DebugAsync("Received Dispatch (THREAD_UPDATE)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + var guild = State.GetGuild(data.GuildId.Value); + if (guild == null) + { + await UnknownGuildAsync(type, data.GuildId.Value); return; } + + var threadChannel = guild.ThreadChannels.FirstOrDefault(x => x.Id == data.Id); + var before = threadChannel != null + ? new Cacheable(threadChannel.Clone(), data.Id, true, () => Task.FromResult((SocketThreadChannel)null)) + : new Cacheable(null, data.Id, false, () => Task.FromResult((SocketThreadChannel)null)); + + if (threadChannel != null) + { + threadChannel.Update(State, data); + + if (data.ThreadMember.IsSpecified) + threadChannel.AddOrUpdateThreadMember(data.ThreadMember.Value, guild.CurrentUser); + } + else + { + //Thread is updated but was not cached, likely meaning the thread was unarchived. + threadChannel = (SocketThreadChannel)guild.AddChannel(State, data); + if (data.ThreadMember.IsSpecified) + threadChannel.AddOrUpdateThreadMember(data.ThreadMember.Value, guild.CurrentUser); + } + + if (!(guild?.IsSynced ?? true)) + { + await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false); + return; + } + + await TimedInvokeAsync(_threadUpdated, nameof(ThreadUpdated), before, threadChannel).ConfigureAwait(false); } break; - case "MESSAGE_REACTION_REMOVE_ALL": + case "THREAD_DELETE": { - await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_REACTION_REMOVE_ALL)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync("Received Dispatch (THREAD_DELETE)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + + var guild = State.GetGuild(data.GuildId.Value); + + if(guild == null) + { + await UnknownGuildAsync(type, data.GuildId.Value).ConfigureAwait(false); + return; + } + + var thread = (SocketThreadChannel)guild.GetChannel(data.Id); + + var cacheable = new Cacheable(thread, data.Id, thread != null, null); + + await TimedInvokeAsync(_threadDeleted, nameof(ThreadDeleted), cacheable).ConfigureAwait(false); + } + break; + case "THREAD_LIST_SYNC": + { + await _gatewayLogger.DebugAsync("Received Dispatch (THREAD_LIST_SYNC)").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + + var guild = State.GetGuild(data.GuildId); + + if(guild == null) + { + await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false); + return; + } + + foreach(var thread in data.Threads) + { + var entity = guild.ThreadChannels.FirstOrDefault(x => x.Id == thread.Id); + + if(entity == null) + { + entity = (SocketThreadChannel)guild.AddChannel(State, thread); + } + else + { + entity.Update(State, thread); + } + + foreach(var member in data.Members.Where(x => x.Id.Value == entity.Id)) + { + var guildMember = guild.GetUser(member.Id.Value); + + entity.AddOrUpdateThreadMember(member, guildMember); + } + } + } + break; + case "THREAD_MEMBER_UPDATE": + { + await _gatewayLogger.DebugAsync("Received Dispatch (THREAD_MEMBER_UPDATE)").ConfigureAwait(false); - var data = (payload as JToken).ToObject(_serializer); - if (State.GetChannel(data.ChannelId) is ISocketMessageChannel channel) - { - var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage; - bool isCached = cachedMsg != null; - var cacheable = new Cacheable(cachedMsg, data.MessageId, isCached, async () => (await channel.GetMessageAsync(data.MessageId).ConfigureAwait(false)) as IUserMessage); + var data = (payload as JToken).ToObject(_serializer); - cachedMsg?.ClearReactions(); + var thread = (SocketThreadChannel)State.GetChannel(data.Id.Value); - await TimedInvokeAsync(_reactionsClearedEvent, nameof(ReactionsCleared), cacheable, channel).ConfigureAwait(false); - } - else + if (thread == null) { - await UnknownChannelAsync(type, data.ChannelId).ConfigureAwait(false); + await UnknownChannelAsync(type, data.Id.Value); return; } + + thread.AddOrUpdateThreadMember(data, thread.Guild.CurrentUser); } + break; - case "MESSAGE_DELETE_BULK": + case "THREAD_MEMBERS_UPDATE": { - await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_DELETE_BULK)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync("Received Dispatch (THREAD_MEMBERS_UPDATE)").ConfigureAwait(false); - if (!ExclusiveBulkDelete.HasValue) - { - await _gatewayLogger.WarningAsync("A bulk delete event has been received, but the event handling behavior has not been set. " + - "To suppress this message, set the ExclusiveBulkDelete configuration property. " + - "This message will appear only once."); - ExclusiveBulkDelete = false; - } + var data = (payload as JToken).ToObject(_serializer); - var data = (payload as JToken).ToObject(_serializer); - if (State.GetChannel(data.ChannelId) is ISocketMessageChannel channel) - { - var guild = (channel as SocketGuildChannel)?.Guild; - if (!(guild?.IsSynced ?? true)) - { - await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false); - return; - } + var guild = State.GetGuild(data.GuildId); - var cacheableList = new List>(data.Ids.Length); - foreach (ulong id in data.Ids) - { - var msg = SocketChannelHelper.RemoveMessage(channel, this, id); - bool isCached = msg != null; - var cacheable = new Cacheable(msg, id, isCached, async () => await channel.GetMessageAsync(id).ConfigureAwait(false)); - cacheableList.Add(cacheable); + if (guild == null) + { + await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false); + return; + } - if (!ExclusiveBulkDelete ?? false) // this shouldn't happen, but we'll play it safe anyways - await TimedInvokeAsync(_messageDeletedEvent, nameof(MessageDeleted), cacheable, channel).ConfigureAwait(false); - } + var thread = (SocketThreadChannel)guild.GetChannel(data.Id); - await TimedInvokeAsync(_messagesBulkDeletedEvent, nameof(MessagesBulkDeleted), cacheableList, channel).ConfigureAwait(false); - } - else + if(thread == null) { - await UnknownChannelAsync(type, data.ChannelId).ConfigureAwait(false); + await UnknownChannelAsync(type, data.Id); return; } - } - break; - //Statuses - case "PRESENCE_UPDATE": - { - await _gatewayLogger.DebugAsync("Received Dispatch (PRESENCE_UPDATE)").ConfigureAwait(false); + IReadOnlyCollection leftUsers = null; + IReadOnlyCollection joinUsers = null; - var data = (payload as JToken).ToObject(_serializer); - if (data.GuildId.IsSpecified) + if (data.RemovedMemberIds.IsSpecified) { - var guild = State.GetGuild(data.GuildId.Value); - if (guild == null) - { - await UnknownGuildAsync(type, data.GuildId.Value).ConfigureAwait(false); - return; - } - if (!guild.IsSynced) - { - await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false); - return; - } + leftUsers = thread.RemoveUsers(data.RemovedMemberIds.Value); + } - var user = guild.GetUser(data.User.Id); - if (user == null) - { - if (data.Status == UserStatus.Offline) - { - return; - } - user = guild.AddOrUpdateUser(data); - } - else + if (data.AddedMembers.IsSpecified) + { + List newThreadMembers = new List(); + foreach(var threadMember in data.AddedMembers.Value) { - var globalBefore = user.GlobalUser.Clone(); - if (user.GlobalUser.Update(State, data.User)) + SocketGuildUser guildMember; + + guildMember = guild.GetUser(threadMember.UserId.Value); + + if(guildMember == null) { - //Global data was updated, trigger UserUpdated - await TimedInvokeAsync(_userUpdatedEvent, nameof(UserUpdated), globalBefore, user).ConfigureAwait(false); + await UnknownGuildUserAsync("THREAD_MEMBERS_UPDATE", threadMember.UserId.Value, guild.Id); } + else + newThreadMembers.Add(thread.AddOrUpdateThreadMember(threadMember, guildMember)); } - var before = user.Clone(); - user.Update(State, data, true); - await TimedInvokeAsync(_guildMemberUpdatedEvent, nameof(GuildMemberUpdated), before, user).ConfigureAwait(false); + if (newThreadMembers.Any()) + joinUsers = newThreadMembers.ToImmutableArray(); } - else + + if (leftUsers != null) { - var globalUser = State.GetUser(data.User.Id); - if (globalUser == null) + foreach(var threadUser in leftUsers) { - await UnknownGlobalUserAsync(type, data.User.Id).ConfigureAwait(false); - return; + await TimedInvokeAsync(_threadMemberLeft, nameof(ThreadMemberLeft), threadUser).ConfigureAwait(false); } - - var before = globalUser.Clone(); - globalUser.Update(State, data.User); - globalUser.Update(State, data); - await TimedInvokeAsync(_userUpdatedEvent, nameof(UserUpdated), before, globalUser).ConfigureAwait(false); } - } - break; - case "TYPING_START": - { - await _gatewayLogger.DebugAsync("Received Dispatch (TYPING_START)").ConfigureAwait(false); - var data = (payload as JToken).ToObject(_serializer); - if (State.GetChannel(data.ChannelId) is ISocketMessageChannel channel) + if(joinUsers != null) { - var guild = (channel as SocketGuildChannel)?.Guild; - if (!(guild?.IsSynced ?? true)) - { - await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false); - return; - } - - var user = (channel as SocketChannel).GetUser(data.UserId); - if (user == null) + foreach(var threadUser in joinUsers) { - if (guild != null) - user = guild.AddOrUpdateUser(data.Member); + await TimedInvokeAsync(_threadMemberJoined, nameof(ThreadMemberJoined), threadUser).ConfigureAwait(false); } - if (user != null) - await TimedInvokeAsync(_userIsTypingEvent, nameof(UserIsTyping), user, channel).ConfigureAwait(false); } } + break; + #endregion - //Users - case "USER_UPDATE": + #region Stage Channels + case "STAGE_INSTANCE_CREATE" or "STAGE_INSTANCE_UPDATE" or "STAGE_INSTANCE_DELETE": { - await _gatewayLogger.DebugAsync("Received Dispatch (USER_UPDATE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch ({type})").ConfigureAwait(false); - var data = (payload as JToken).ToObject(_serializer); - if (data.Id == CurrentUser.Id) + var data = (payload as JToken).ToObject(_serializer); + + var guild = State.GetGuild(data.GuildId); + + if(guild == null) { - var before = CurrentUser.Clone(); - CurrentUser.Update(State, data); - await TimedInvokeAsync(_selfUpdatedEvent, nameof(CurrentUserUpdated), before, CurrentUser).ConfigureAwait(false); + await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false); + return; } - else + + var stageChannel = guild.GetStageChannel(data.ChannelId); + + if(stageChannel == null) { - await _gatewayLogger.WarningAsync("Received USER_UPDATE for wrong user.").ConfigureAwait(false); + await UnknownChannelAsync(type, data.ChannelId).ConfigureAwait(false); return; } - } - break; - //Voice - case "VOICE_STATE_UPDATE": - { - await _gatewayLogger.DebugAsync("Received Dispatch (VOICE_STATE_UPDATE)").ConfigureAwait(false); + SocketStageChannel before = type == "STAGE_INSTANCE_UPDATE" ? stageChannel.Clone() : null; - var data = (payload as JToken).ToObject(_serializer); - SocketUser user; - SocketVoiceState before, after; - if (data.GuildId != null) + stageChannel.Update(data, type == "STAGE_INSTANCE_CREATE"); + + switch (type) { - var guild = State.GetGuild(data.GuildId.Value); - if (guild == null) - { - await UnknownGuildAsync(type, data.GuildId.Value).ConfigureAwait(false); + case "STAGE_INSTANCE_CREATE": + await TimedInvokeAsync(_stageStarted, nameof(StageStarted), stageChannel).ConfigureAwait(false); return; - } - else if (!guild.IsSynced) - { - await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false); + case "STAGE_INSTANCE_DELETE": + await TimedInvokeAsync(_stageEnded, nameof(StageEnded), stageChannel).ConfigureAwait(false); return; - } - - if (data.ChannelId != null) - { - before = guild.GetVoiceState(data.UserId)?.Clone() ?? SocketVoiceState.Default; - after = await guild.AddOrUpdateVoiceStateAsync(State, data).ConfigureAwait(false); - /*if (data.UserId == CurrentUser.Id) - { - var _ = guild.FinishJoinAudioChannel().ConfigureAwait(false); - }*/ - } - else - { - before = await guild.RemoveVoiceStateAsync(data.UserId).ConfigureAwait(false) ?? SocketVoiceState.Default; - after = SocketVoiceState.Create(null, data); - } - - // per g250k, this should always be sent, but apparently not always - user = guild.GetUser(data.UserId) - ?? (data.Member.IsSpecified ? guild.AddOrUpdateUser(data.Member.Value) : null); - if (user == null) - { - await UnknownGuildUserAsync(type, data.UserId, guild.Id).ConfigureAwait(false); + case "STAGE_INSTANCE_UPDATE": + await TimedInvokeAsync(_stageUpdated, nameof(StageUpdated), before, stageChannel).ConfigureAwait(false); return; - } } - else + } + break; + #endregion + + #region Guild Scheduled Events + case "GUILD_SCHEDULED_EVENT_CREATE": + { + await _gatewayLogger.DebugAsync($"Received Dispatch ({type})").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + + var guild = State.GetGuild(data.GuildId); + + if (guild == null) { - var groupChannel = State.GetChannel(data.ChannelId.Value) as SocketGroupChannel; - if (groupChannel == null) - { - await UnknownChannelAsync(type, data.ChannelId.Value).ConfigureAwait(false); - return; - } - if (data.ChannelId != null) - { - before = groupChannel.GetVoiceState(data.UserId)?.Clone() ?? SocketVoiceState.Default; - after = groupChannel.AddOrUpdateVoiceState(State, data); - } - else - { - before = groupChannel.RemoveVoiceState(data.UserId) ?? SocketVoiceState.Default; - after = SocketVoiceState.Create(null, data); - } - user = groupChannel.GetUser(data.UserId); - if (user == null) - { - await UnknownChannelUserAsync(type, data.UserId, groupChannel.Id).ConfigureAwait(false); - return; - } + await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false); + return; } - await TimedInvokeAsync(_userVoiceStateUpdatedEvent, nameof(UserVoiceStateUpdated), user, before, after).ConfigureAwait(false); + var newEvent = guild.AddOrUpdateEvent(data); + + await TimedInvokeAsync(_guildScheduledEventCreated, nameof(GuildScheduledEventCreated), newEvent).ConfigureAwait(false); } break; - case "VOICE_SERVER_UPDATE": + case "GUILD_SCHEDULED_EVENT_UPDATE": { - await _gatewayLogger.DebugAsync("Received Dispatch (VOICE_SERVER_UPDATE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch ({type})").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); - var data = (payload as JToken).ToObject(_serializer); var guild = State.GetGuild(data.GuildId); - var isCached = guild != null; - var cachedGuild = new Cacheable(guild, data.GuildId, isCached, - () => Task.FromResult(State.GetGuild(data.GuildId) as IGuild)); - var voiceServer = new SocketVoiceServer(cachedGuild, data.Endpoint, data.Token); - await TimedInvokeAsync(_voiceServerUpdatedEvent, nameof(UserVoiceStateUpdated), voiceServer).ConfigureAwait(false); + if (guild == null) + { + await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false); + return; + } - if (isCached) + var before = guild.GetEvent(data.Id)?.Clone(); + + var beforeCacheable = new Cacheable(before, data.Id, before != null, () => Task.FromResult((SocketGuildEvent)null)); + + var after = guild.AddOrUpdateEvent(data); + + if((before != null ? before.Status != GuildScheduledEventStatus.Completed : true) && data.Status == GuildScheduledEventStatus.Completed) { - var endpoint = data.Endpoint; + await TimedInvokeAsync(_guildScheduledEventCompleted, nameof(GuildScheduledEventCompleted), after).ConfigureAwait(false); + } + else if((before != null ? before.Status != GuildScheduledEventStatus.Active : false) && data.Status == GuildScheduledEventStatus.Active) + { + await TimedInvokeAsync(_guildScheduledEventStarted, nameof(GuildScheduledEventStarted), after).ConfigureAwait(false); + } + else await TimedInvokeAsync(_guildScheduledEventUpdated, nameof(GuildScheduledEventUpdated), beforeCacheable, after).ConfigureAwait(false); + } + break; + case "GUILD_SCHEDULED_EVENT_DELETE": + { + await _gatewayLogger.DebugAsync($"Received Dispatch ({type})").ConfigureAwait(false); - //Only strip out the port if the endpoint contains it - var portBegin = endpoint.LastIndexOf(':'); - if (portBegin > 0) - endpoint = endpoint.Substring(0, portBegin); + var data = (payload as JToken).ToObject(_serializer); - var _ = guild.FinishConnectAudio(endpoint, data.Token).ConfigureAwait(false); + var guild = State.GetGuild(data.GuildId); + + if (guild == null) + { + await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false); + return; } - else + + var guildEvent = guild.RemoveEvent(data.Id) ?? SocketGuildEvent.Create(this, guild, data); + + await TimedInvokeAsync(_guildScheduledEventCancelled, nameof(GuildScheduledEventCancelled), guildEvent).ConfigureAwait(false); + } + break; + case "GUILD_SCHEDULED_EVENT_USER_ADD" or "GUILD_SCHEDULED_EVENT_USER_REMOVE": + { + await _gatewayLogger.DebugAsync($"Received Dispatch ({type})").ConfigureAwait(false); + + var data = (payload as JToken).ToObject(_serializer); + + var guild = State.GetGuild(data.GuildId); + + if(guild == null) { await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false); + return; + } + + var guildEvent = guild.GetEvent(data.EventId); + + if (guildEvent == null) + { + await UnknownGuildEventAsync(type, data.EventId, data.GuildId).ConfigureAwait(false); + return; } + var user = (SocketUser)guild.GetUser(data.UserId) ?? State.GetUser(data.UserId); + + var cacheableUser = new Cacheable(user, data.UserId, user != null, () => Rest.GetUserAsync(data.UserId)); + + switch (type) + { + case "GUILD_SCHEDULED_EVENT_USER_ADD": + await TimedInvokeAsync(_guildScheduledEventUserAdd, nameof(GuildScheduledEventUserAdd), cacheableUser, guildEvent).ConfigureAwait(false); + break; + case "GUILD_SCHEDULED_EVENT_USER_REMOVE": + await TimedInvokeAsync(_guildScheduledEventUserRemove, nameof(GuildScheduledEventUserRemove), cacheableUser, guildEvent).ConfigureAwait(false); + break; + } } break; - //Ignored (User only) + #endregion + + #region Ignored (User only) case "CHANNEL_PINS_ACK": await _gatewayLogger.DebugAsync("Ignored Dispatch (CHANNEL_PINS_ACK)").ConfigureAwait(false); break; @@ -1689,11 +2759,13 @@ namespace Discord.WebSocket case "WEBHOOKS_UPDATE": await _gatewayLogger.DebugAsync("Ignored Dispatch (WEBHOOKS_UPDATE)").ConfigureAwait(false); break; + #endregion - //Others + #region Others default: await _gatewayLogger.WarningAsync($"Unknown Dispatch ({type})").ConfigureAwait(false); break; + #endregion } break; default: @@ -1706,6 +2778,7 @@ namespace Discord.WebSocket await _gatewayLogger.ErrorAsync($"Error handling {opCode}{(type != null ? $" ({type})" : "")}", ex).ConfigureAwait(false); } } + #endregion private async Task RunHeartbeatAsync(int intervalMillis, CancellationToken cancelToken) { @@ -1761,7 +2834,7 @@ namespace Discord.WebSocket try { await logger.DebugAsync("GuildDownloader Started").ConfigureAwait(false); - while ((_unavailableGuildCount != 0) && (Environment.TickCount - _lastGuildAvailableTime < 2000)) + while ((_unavailableGuildCount != 0) && (Environment.TickCount - _lastGuildAvailableTime < BaseConfig.MaxWaitBetweenGuildAvailablesBeforeReady)) await Task.Delay(500, cancelToken).ConfigureAwait(false); await logger.DebugAsync("GuildDownloader Stopped").ConfigureAwait(false); } @@ -1797,24 +2870,45 @@ namespace Discord.WebSocket { var channel = SocketChannel.CreatePrivate(this, state, model); state.AddChannel(channel as SocketChannel); - if (channel is SocketDMChannel dm) - dm.Recipient.GlobalUser.DMChannel = dm; - return channel; } + internal SocketDMChannel CreateDMChannel(ulong channelId, API.User model, ClientState state) + { + return SocketDMChannel.Create(this, state, channelId, model); + } + internal SocketDMChannel CreateDMChannel(ulong channelId, SocketUser user, ClientState state) + { + return new SocketDMChannel(this, channelId, user); + } internal ISocketPrivateChannel RemovePrivateChannel(ulong id) { var channel = State.RemoveChannel(id) as ISocketPrivateChannel; if (channel != null) { - if (channel is SocketDMChannel dmChannel) - dmChannel.Recipient.GlobalUser.DMChannel = null; - foreach (var recipient in channel.Recipients) recipient.GlobalUser.RemoveRef(this); } return channel; } + internal void RemoveDMChannels() + { + var channels = State.DMChannels; + State.PurgeDMChannels(); + foreach (var channel in channels) + channel.Recipient.GlobalUser.RemoveRef(this); + } + + internal void EnsureGatewayIntent(GatewayIntents intents) + { + if (!_gatewayIntents.HasFlag(intents)) + { + var vals = Enum.GetValues(typeof(GatewayIntents)).Cast(); + + var missingValues = vals.Where(x => intents.HasFlag(x) && !_gatewayIntents.HasFlag(x)); + + throw new InvalidOperationException($"Missing required gateway intent{(missingValues.Count() > 1 ? "s" : "")} {string.Join(", ", missingValues.Select(x => x.ToString()))} in order to execute this operation."); + } + } private async Task GuildAvailableAsync(SocketGuild guild) { @@ -1956,6 +3050,12 @@ namespace Discord.WebSocket string details = $"{evnt} Guild={guildId}"; await _gatewayLogger.WarningAsync($"Unknown Guild ({details}).").ConfigureAwait(false); } + + private async Task UnknownGuildEventAsync(string evnt, ulong eventId, ulong guildId) + { + string details = $"{evnt} Event={eventId} Guild={guildId}"; + await _gatewayLogger.WarningAsync($"Unknown Guild Event ({details}).").ConfigureAwait(false); + } private async Task UnsyncedGuildAsync(string evnt, ulong guildId) { string details = $"{evnt} Guild={guildId}"; @@ -1964,14 +3064,14 @@ namespace Discord.WebSocket internal int GetAudioId() => _nextAudioId++; - //IDiscordClient + #region IDiscordClient /// async Task IDiscordClient.GetApplicationInfoAsync(RequestOptions options) => await GetApplicationInfoAsync().ConfigureAwait(false); /// - Task IDiscordClient.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options) - => Task.FromResult(GetChannel(id)); + async Task IDiscordClient.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options) + => mode == CacheMode.AllowDownload ? await GetChannelAsync(id, options).ConfigureAwait(false) : GetChannel(id); /// Task> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(PrivateChannels); @@ -2001,18 +3101,25 @@ namespace Discord.WebSocket => await CreateGuildAsync(name, region, jpegIcon).ConfigureAwait(false); /// - Task IDiscordClient.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) - => Task.FromResult(GetUser(id)); + async Task IDiscordClient.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) + => mode == CacheMode.AllowDownload ? await GetUserAsync(id, options).ConfigureAwait(false) : GetUser(id); /// Task IDiscordClient.GetUserAsync(string username, string discriminator, RequestOptions options) => Task.FromResult(GetUser(username, discriminator)); /// - Task> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options) - => Task.FromResult>(VoiceRegions); + async Task> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options) + => await GetVoiceRegionsAsync(options).ConfigureAwait(false); + /// + async Task IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options) + => await GetVoiceRegionAsync(id, options).ConfigureAwait(false); + + /// + async Task IDiscordClient.GetGlobalApplicationCommandAsync(ulong id, RequestOptions options) + => await GetGlobalApplicationCommandAsync(id, options); /// - Task IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options) - => Task.FromResult(GetVoiceRegion(id)); + async Task> IDiscordClient.GetGlobalApplicationCommandsAsync(RequestOptions options) + => await GetGlobalApplicationCommandsAsync(options); /// async Task IDiscordClient.StartAsync() @@ -2020,5 +3127,6 @@ namespace Discord.WebSocket /// async Task IDiscordClient.StopAsync() => await StopAsync().ConfigureAwait(false); + #endregion } } diff --git a/src/Discord.Net.WebSocket/DiscordSocketConfig.cs b/src/Discord.Net.WebSocket/DiscordSocketConfig.cs index 98ab0ef9b..f0e6dc857 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketConfig.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketConfig.cs @@ -45,19 +45,44 @@ namespace Discord.WebSocket /// Gets or sets the ID for this shard. Must be less than . /// public int? ShardId { get; set; } = null; + /// /// Gets or sets the total number of shards for this application. /// + /// + /// If this is left in a sharded client the bot will get the recommended shard + /// count from discord and use that. + /// public int? TotalShards { get; set; } = null; + /// + /// Gets or sets whether or not the client should download the default stickers on startup. + /// + /// + /// When this is set to default stickers arn't present and cannot be resolved by the client. + /// This will make all default stickers have the type of . + /// + public bool AlwaysDownloadDefaultStickers { get; set; } = false; + + /// + /// Gets or sets whether or not the client should automatically resolve the stickers sent on a message. + /// + /// + /// Note if a sticker isn't cached the client will preform a rest request to resolve it. This + /// may be very rest heavy depending on your bots size, it isn't recommended to use this with large scale bots as you + /// can get ratelimited easily. + /// + public bool AlwaysResolveStickers { get; set; } = false; + /// /// Gets or sets the number of messages per channel that should be kept in cache. Setting this to zero /// disables the message cache entirely. /// public int MessageCacheSize { get; set; } = 0; + /// /// Gets or sets the max number of users a guild may have for offline users to be included in the READY - /// packet. Max is 250. + /// packet. The maximum value allowed is 250. /// public int LargeThreshold { get; set; } = 250; @@ -65,6 +90,7 @@ namespace Discord.WebSocket /// Gets or sets the provider used to generate new WebSocket connections. /// public WebSocketProvider WebSocketProvider { get; set; } + /// /// Gets or sets the provider used to generate new UDP sockets. /// @@ -76,7 +102,7 @@ namespace Discord.WebSocket /// /// /// By default, the Discord gateway will only send offline members if a guild has less than a certain number - /// of members (determined by in this library). This behaviour is why + /// of members (determined by in this library). This behavior is why /// sometimes a user may be missing from the WebSocket cache for collections such as /// . /// @@ -87,7 +113,7 @@ namespace Discord.WebSocket /// /// /// For more information, please see - /// Request Guild Members + /// Request Guild Members /// on the official Discord API documentation. /// /// @@ -95,37 +121,75 @@ namespace Discord.WebSocket /// traffic. If you are using the command system, the default user TypeReader may fail to find the user /// due to this issue. This may be resolved at v3 of the library. Until then, you may want to consider /// overriding the TypeReader and use - /// + /// /// or /// as a backup. /// /// public bool AlwaysDownloadUsers { get; set; } = false; + /// - /// Gets or sets the timeout for event handlers, in milliseconds, after which a warning will be logged. Null - /// disables this check. + /// Gets or sets the timeout for event handlers, in milliseconds, after which a warning will be logged. + /// Setting this property to nulldisables this check. /// public int? HandlerTimeout { get; set; } = 3000; /// - /// Gets or sets the behavior for on bulk deletes. - /// - /// If true, the event will not be raised for bulk deletes, and - /// only the will be raised. - /// - /// If false, both events will be raised. - /// - /// If unset, both events will be raised, but a warning will be raised the first time a bulk delete event is received. + /// Gets or sets the maximum identify concurrency. /// - public bool? ExclusiveBulkDelete { get; set; } = null; + /// + /// This information is provided by Discord. + /// It is only used when using a and auto-sharding is disabled. + /// + public int IdentifyMaxConcurrency { get; set; } = 1; + + /// + /// Gets or sets the maximum wait time in milliseconds between GUILD_AVAILABLE events before firing READY. + /// If zero, READY will fire as soon as it is received and all guilds will be unavailable. + /// + /// + /// This property is measured in milliseconds; negative values will throw an exception. + /// If a guild is not received before READY, it will be unavailable. + /// + /// + /// A representing the maximum wait time in milliseconds between GUILD_AVAILABLE events + /// before firing READY. + /// + /// Value must be at least 0. + public int MaxWaitBetweenGuildAvailablesBeforeReady + { + get + { + return maxWaitForGuildAvailable; + } + + set + { + Preconditions.AtLeast(value, 0, nameof(MaxWaitBetweenGuildAvailablesBeforeReady)); + maxWaitForGuildAvailable = value; + } + } + + private int maxWaitForGuildAvailable = 10000; + + /// + /// Gets or sets gateway intents to limit what events are sent from Discord. + /// The default is . + /// + /// + /// For more information, please see + /// GatewayIntents + /// on the official Discord API documentation. + /// + public GatewayIntents GatewayIntents { get; set; } = GatewayIntents.AllUnprivileged; /// - /// Gets or sets enabling dispatching of guild subscription events e.g. presence and typing events. + /// Gets or sets whether or not to log warnings related to guild intents and events. /// - public bool GuildSubscriptions { get; set; } = true; + public bool LogGatewayIntentWarnings { get; set; } = true; /// - /// Initializes a default configuration. + /// Initializes a new instance of the class with the default configuration. /// public DiscordSocketConfig() { diff --git a/src/Discord.Net.WebSocket/DiscordVoiceApiClient.cs b/src/Discord.Net.WebSocket/DiscordVoiceApiClient.cs index f78145dbe..62d95402a 100644 --- a/src/Discord.Net.WebSocket/DiscordVoiceApiClient.cs +++ b/src/Discord.Net.WebSocket/DiscordVoiceApiClient.cs @@ -1,4 +1,3 @@ -#pragma warning disable CS1591 using Discord.API; using Discord.API.Voice; using Discord.Net.Converters; @@ -18,6 +17,7 @@ namespace Discord.Audio { internal class DiscordVoiceAPIClient : IDisposable { + #region DiscordVoiceAPIClient public const int MaxBitrate = 128 * 1024; public const string Mode = "xsalsa20_poly1305"; @@ -126,8 +126,9 @@ namespace Discord.Audio await _udp.SendAsync(data, offset, bytes).ConfigureAwait(false); await _sentDataEvent.InvokeAsync(bytes).ConfigureAwait(false); } + #endregion - //WebSocket + #region WebSocket public async Task SendHeartbeatAsync(RequestOptions options = null) { await SendAsync(VoiceOpCode.Heartbeat, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), options: options).ConfigureAwait(false); @@ -208,10 +209,12 @@ namespace Discord.Audio } private async Task DisconnectInternalAsync() { - if (ConnectionState == ConnectionState.Disconnected) return; + if (ConnectionState == ConnectionState.Disconnected) + return; ConnectionState = ConnectionState.Disconnecting; - try { _connectCancelToken?.Cancel(false); } + try + { _connectCancelToken?.Cancel(false); } catch { } //Wait for tasks to complete @@ -220,8 +223,9 @@ namespace Discord.Audio ConnectionState = ConnectionState.Disconnected; } + #endregion - //Udp + #region Udp public async Task SendDiscoveryAsync(uint ssrc) { var packet = new byte[70]; @@ -252,8 +256,9 @@ namespace Discord.Audio { _udp.SetDestination(ip, port); } + #endregion - //Helpers + #region Helpers private static double ToMilliseconds(Stopwatch stopwatch) => Math.Round((double)stopwatch.ElapsedTicks / (double)Stopwatch.Frequency * 1000.0, 2); private string SerializeJson(object value) { @@ -269,5 +274,6 @@ namespace Discord.Audio using (JsonReader reader = new JsonTextReader(text)) return _serializer.Deserialize(reader); } + #endregion } } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs index 378478dcc..3e9b635de 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs @@ -33,16 +33,20 @@ namespace Discord.WebSocket /// Specifies if notifications are sent for mentioned users and roles in the message . /// If null, all mentioned roles and users will be notified. /// + /// The message references to be included. Used to reply to specific messages. + /// The message components to be included with this message. Used for interactions. + /// A collection of stickers to send with the message. + /// A array of s to send with this response. Max 10. /// /// A task that represents an asynchronous send operation for delivering the message. The task result /// contains the sent message. /// - new Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null); + new Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null); /// /// Sends a file to this message channel with an optional caption. /// /// - /// This method follows the same behavior as described in . + /// This method follows the same behavior as described in . /// Please visit its documentation for more details on this method. /// /// The file path of the file. @@ -51,16 +55,24 @@ namespace Discord.WebSocket /// The to be sent. /// The options to be used when sending the request. /// Whether the message attachment should be hidden as a spoiler. + /// + /// Specifies if notifications are sent for mentioned users and roles in the message . + /// If null, all mentioned roles and users will be notified. + /// + /// The message references to be included. Used to reply to specific messages. + /// The message components to be included with this message. Used for interactions. + /// A collection of stickers to send with the file. + /// A array of s to send with this response. Max 10. /// /// A task that represents an asynchronous send operation for delivering the message. The task result /// contains the sent message. /// - new Task SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false); + new Task SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null); /// /// Sends a file to this message channel with an optional caption. /// /// - /// This method follows the same behavior as described in . + /// This method follows the same behavior as described in . /// Please visit its documentation for more details on this method. /// /// The of the file to be sent. @@ -70,11 +82,19 @@ namespace Discord.WebSocket /// The to be sent. /// The options to be used when sending the request. /// Whether the message attachment should be hidden as a spoiler. + /// + /// Specifies if notifications are sent for mentioned users and roles in the message . + /// If null, all mentioned roles and users will be notified. + /// + /// The message references to be included. Used to reply to specific messages. + /// The message components to be included with this message. Used for interactions. + /// A collection of stickers to send with the file. + /// A array of s to send with this response. Max 10. /// /// A task that represents an asynchronous send operation for delivering the message. The task result /// contains the sent message. /// - new Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false); + new Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null); /// /// Gets a cached message from this channel. diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketCategoryChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketCategoryChannel.cs index b90c1976a..9c7dd4fbd 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketCategoryChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketCategoryChannel.cs @@ -14,6 +14,7 @@ namespace Discord.WebSocket [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class SocketCategoryChannel : SocketGuildChannel, ICategoryChannel { + #region SocketCategoryChannel /// public override IReadOnlyCollection Users => Guild.Users.Where(x => Permissions.GetValue( @@ -41,8 +42,9 @@ namespace Discord.WebSocket entity.Update(state, model); return entity; } + #endregion - //Users + #region Users /// public override SocketGuildUser GetUser(ulong id) { @@ -59,21 +61,24 @@ namespace Discord.WebSocket private string DebuggerDisplay => $"{Name} ({Id}, Category)"; internal new SocketCategoryChannel Clone() => MemberwiseClone() as SocketCategoryChannel; + #endregion - // IGuildChannel + #region IGuildChannel /// IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); /// Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); + #endregion - //IChannel + #region IChannel /// IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); /// Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); + #endregion } } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs index 13c0c9b4f..758ee9271 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs @@ -13,6 +13,7 @@ namespace Discord.WebSocket [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public abstract class SocketChannel : SocketEntity, IChannel { + #region SocketChannel /// /// Gets when the channel is created. /// @@ -30,19 +31,17 @@ namespace Discord.WebSocket /// Unexpected channel type is created. internal static ISocketPrivateChannel CreatePrivate(DiscordSocketClient discord, ClientState state, Model model) { - switch (model.Type) + return model.Type switch { - case ChannelType.DM: - return SocketDMChannel.Create(discord, state, model); - case ChannelType.Group: - return SocketGroupChannel.Create(discord, state, model); - default: - throw new InvalidOperationException($"Unexpected channel type: {model.Type}"); - } + ChannelType.DM => SocketDMChannel.Create(discord, state, model), + ChannelType.Group => SocketGroupChannel.Create(discord, state, model), + _ => throw new InvalidOperationException($"Unexpected channel type: {model.Type}"), + }; } internal abstract void Update(ClientState state, Model model); + #endregion - //User + #region User /// /// Gets a generic user from this channel. /// @@ -56,8 +55,9 @@ namespace Discord.WebSocket private string DebuggerDisplay => $"Unknown ({Id}, Channel)"; internal SocketChannel Clone() => MemberwiseClone() as SocketChannel; + #endregion - //IChannel + #region IChannel /// string IChannel.Name => null; @@ -67,5 +67,6 @@ namespace Discord.WebSocket /// IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => AsyncEnumerable.Empty>(); //Overridden + #endregion } } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs index e6339b6d9..ccbf9b2b6 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs @@ -11,23 +11,11 @@ namespace Discord.WebSocket public static IAsyncEnumerable> GetMessagesAsync(ISocketMessageChannel channel, DiscordSocketClient discord, MessageCache messages, ulong? fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options) { - if (dir == Direction.Around) - throw new NotImplementedException(); //TODO: Impl - - IReadOnlyCollection cachedMessages = null; - IAsyncEnumerable> result = null; - if (dir == Direction.After && fromMessageId == null) return AsyncEnumerable.Empty>(); - if (dir == Direction.Before || mode == CacheMode.CacheOnly) - { - if (messages != null) //Cache enabled - cachedMessages = messages.GetMany(fromMessageId, dir, limit); - else - cachedMessages = ImmutableArray.Create(); - result = ImmutableArray.Create(cachedMessages).ToAsyncEnumerable>(); - } + var cachedMessages = GetCachedMessages(channel, discord, messages, fromMessageId, dir, limit); + var result = ImmutableArray.Create(cachedMessages).ToAsyncEnumerable>(); if (dir == Direction.Before) { @@ -38,18 +26,35 @@ namespace Discord.WebSocket //Download remaining messages ulong? minId = cachedMessages.Count > 0 ? cachedMessages.Min(x => x.Id) : fromMessageId; var downloadedMessages = ChannelHelper.GetMessagesAsync(channel, discord, minId, dir, limit, options); - return result.Concat(downloadedMessages); + if (cachedMessages.Count != 0) + return result.Concat(downloadedMessages); + else + return downloadedMessages; } - else + else if (dir == Direction.After) { - if (mode == CacheMode.CacheOnly) + limit -= cachedMessages.Count; + if (mode == CacheMode.CacheOnly || limit <= 0) return result; - //Dont use cache in this case + //Download remaining messages + ulong maxId = cachedMessages.Count > 0 ? cachedMessages.Max(x => x.Id) : fromMessageId.Value; + var downloadedMessages = ChannelHelper.GetMessagesAsync(channel, discord, maxId, dir, limit, options); + if (cachedMessages.Count != 0) + return result.Concat(downloadedMessages); + else + return downloadedMessages; + } + else //Direction.Around + { + if (mode == CacheMode.CacheOnly || limit <= cachedMessages.Count) + return result; + + //Cache isn't useful here since Discord will send them anyways return ChannelHelper.GetMessagesAsync(channel, discord, fromMessageId, dir, limit, options); } } - public static IReadOnlyCollection GetCachedMessages(SocketChannel channel, DiscordSocketClient discord, MessageCache messages, + public static IReadOnlyCollection GetCachedMessages(ISocketMessageChannel channel, DiscordSocketClient discord, MessageCache messages, ulong? fromMessageId, Direction dir, int limit) { if (messages != null) //Cache enabled @@ -65,6 +70,7 @@ namespace Discord.WebSocket { case SocketDMChannel dmChannel: dmChannel.AddMessage(msg); break; case SocketGroupChannel groupChannel: groupChannel.AddMessage(msg); break; + case SocketThreadChannel threadChannel: threadChannel.AddMessage(msg); break; case SocketTextChannel textChannel: textChannel.AddMessage(msg); break; default: throw new NotSupportedException($"Unexpected {nameof(ISocketMessageChannel)} type."); } @@ -73,13 +79,13 @@ namespace Discord.WebSocket public static SocketMessage RemoveMessage(ISocketMessageChannel channel, DiscordSocketClient discord, ulong id) { - switch (channel) + return channel switch { - case SocketDMChannel dmChannel: return dmChannel.RemoveMessage(id); - case SocketGroupChannel groupChannel: return groupChannel.RemoveMessage(id); - case SocketTextChannel textChannel: return textChannel.RemoveMessage(id); - default: throw new NotSupportedException($"Unexpected {nameof(ISocketMessageChannel)} type."); - } + SocketDMChannel dmChannel => dmChannel.RemoveMessage(id), + SocketGroupChannel groupChannel => groupChannel.RemoveMessage(id), + SocketTextChannel textChannel => textChannel.RemoveMessage(id), + _ => throw new NotSupportedException($"Unexpected {nameof(ISocketMessageChannel)} type."), + }; } } } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs index 11259a31e..f4fe12755 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs @@ -16,32 +16,28 @@ namespace Discord.WebSocket [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class SocketDMChannel : SocketChannel, IDMChannel, ISocketPrivateChannel, ISocketMessageChannel { - private readonly MessageCache _messages; - + #region SocketDMChannel /// /// Gets the recipient of the channel. /// public SocketUser Recipient { get; } /// - public IReadOnlyCollection CachedMessages => _messages?.Messages ?? ImmutableArray.Create(); + public IReadOnlyCollection CachedMessages => ImmutableArray.Create(); /// /// Gets a collection that is the current logged-in user and the recipient. /// public new IReadOnlyCollection Users => ImmutableArray.Create(Discord.CurrentUser, Recipient); - internal SocketDMChannel(DiscordSocketClient discord, ulong id, SocketGlobalUser recipient) + internal SocketDMChannel(DiscordSocketClient discord, ulong id, SocketUser recipient) : base(discord, id) { Recipient = recipient; - recipient.GlobalUser.AddRef(); - if (Discord.MessageCacheSize > 0) - _messages = new MessageCache(Discord); } internal static SocketDMChannel Create(DiscordSocketClient discord, ClientState state, Model model) { - var entity = new SocketDMChannel(discord, model.Id, discord.GetOrCreateUser(state, model.Recipients.Value[0])); + var entity = new SocketDMChannel(discord, model.Id, discord.GetOrCreateTemporaryUser(state, model.Recipients.Value[0])); entity.Update(state, model); return entity; } @@ -49,15 +45,26 @@ namespace Discord.WebSocket { Recipient.Update(state, model.Recipients.Value[0]); } + internal static SocketDMChannel Create(DiscordSocketClient discord, ClientState state, ulong channelId, API.User recipient) + { + var entity = new SocketDMChannel(discord, channelId, discord.GetOrCreateTemporaryUser(state, recipient)); + entity.Update(state, recipient); + return entity; + } + internal void Update(ClientState state, API.User recipient) + { + Recipient.Update(state, recipient); + } /// public Task CloseAsync(RequestOptions options = null) => ChannelHelper.DeleteAsync(this, Discord, options); + #endregion - //Messages + #region Messages /// public SocketMessage GetCachedMessage(ulong id) - => _messages?.Get(id); + => null; /// /// Gets the message associated with the given . /// @@ -68,10 +75,7 @@ namespace Discord.WebSocket /// public async Task GetMessageAsync(ulong id, RequestOptions options = null) { - IMessage msg = _messages?.Get(id); - if (msg == null) - msg = await ChannelHelper.GetMessageAsync(this, Discord, id, options).ConfigureAwait(false); - return msg; + return await ChannelHelper.GetMessageAsync(this, Discord, id, options).ConfigureAwait(false); } /// @@ -87,7 +91,7 @@ namespace Discord.WebSocket /// Paged collection of messages. /// public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload, options); + => ChannelHelper.GetMessagesAsync(this, Discord, null, Direction.Before, limit, options); /// /// Gets a collection of messages in this channel. /// @@ -103,7 +107,7 @@ namespace Discord.WebSocket /// Paged collection of messages. /// public IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload, options); + => ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit, options); /// /// Gets a collection of messages in this channel. /// @@ -119,32 +123,41 @@ namespace Discord.WebSocket /// Paged collection of messages. /// public IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload, options); + => ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit, options); /// public IReadOnlyCollection GetCachedMessages(int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, null, Direction.Before, limit); + => ImmutableArray.Create(); /// public IReadOnlyCollection GetCachedMessages(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessageId, dir, limit); + => ImmutableArray.Create(); /// public IReadOnlyCollection GetCachedMessages(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessage.Id, dir, limit); + => ImmutableArray.Create(); /// public Task> GetPinnedMessagesAsync(RequestOptions options = null) => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); /// /// Message content is too long, length must be less or equal to . - public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, allowedMentions, options); + public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); /// - public Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) - => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, options, isSpoiler); + public Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, isSpoiler, embeds); + /// + /// Message content is too long, length must be less or equal to . + public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, isSpoiler, embeds); /// /// Message content is too long, length must be less or equal to . - public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) - => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options, isSpoiler); + public Task SendFileAsync(FileAttachment attachment, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, attachment, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); + /// + /// Message content is too long, length must be less or equal to . + public Task SendFilesAsync(IEnumerable attachments, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFilesAsync(this, Discord, attachments, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); + /// public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) => ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); @@ -152,6 +165,10 @@ namespace Discord.WebSocket public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) => ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); + /// + public async Task ModifyMessageAsync(ulong messageId, Action func, RequestOptions options = null) + => await ChannelHelper.ModifyMessageAsync(this, messageId, func, Discord, options).ConfigureAwait(false); + /// public Task TriggerTypingAsync(RequestOptions options = null) => ChannelHelper.TriggerTypingAsync(this, Discord, options); @@ -160,11 +177,15 @@ namespace Discord.WebSocket => ChannelHelper.EnterTypingState(this, Discord, options); internal void AddMessage(SocketMessage msg) - => _messages?.Add(msg); + { + } internal SocketMessage RemoveMessage(ulong id) - => _messages?.Remove(id); + { + return null; + } + #endregion - //Users + #region Users /// /// Gets a user in this channel from the provided . /// @@ -188,26 +209,31 @@ namespace Discord.WebSocket public override string ToString() => $"@{Recipient}"; private string DebuggerDisplay => $"@{Recipient} ({Id}, DM)"; internal new SocketDMChannel Clone() => MemberwiseClone() as SocketDMChannel; + #endregion - //SocketChannel + #region SocketChannel /// internal override IReadOnlyCollection GetUsersInternal() => Users; /// internal override SocketUser GetUserInternal(ulong id) => GetUser(id); + #endregion - //IDMChannel + #region IDMChannel /// IUser IDMChannel.Recipient => Recipient; + #endregion - //ISocketPrivateChannel + #region ISocketPrivateChannel /// IReadOnlyCollection ISocketPrivateChannel.Recipients => ImmutableArray.Create(Recipient); + #endregion - //IPrivateChannel + #region IPrivateChannel /// IReadOnlyCollection IPrivateChannel.Recipients => ImmutableArray.Create(Recipient); + #endregion - //IMessageChannel + #region IMessageChannel /// async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { @@ -218,27 +244,34 @@ namespace Discord.WebSocket } /// IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, mode, options); + => mode == CacheMode.CacheOnly ? null : GetMessagesAsync(limit, options); /// IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, mode, options); + => mode == CacheMode.CacheOnly ? null : GetMessagesAsync(fromMessageId, dir, limit, options); /// IAsyncEnumerable> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, mode, options); + => mode == CacheMode.CacheOnly ? null : GetMessagesAsync(fromMessage.Id, dir, limit, options); /// async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) => await GetPinnedMessagesAsync(options).ConfigureAwait(false); /// - async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler) - => await SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler).ConfigureAwait(false); + async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + /// + async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + /// + async Task IMessageChannel.SendFileAsync(FileAttachment attachment, string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(attachment, text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); /// - async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler) - => await SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler).ConfigureAwait(false); + async Task IMessageChannel.SendFilesAsync(IEnumerable attachments, string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFilesAsync(attachments, text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); /// - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions) - => await SendMessageAsync(text, isTTS, embed, options, allowedMentions).ConfigureAwait(false); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendMessageAsync(text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + #endregion - //IChannel + #region IChannel /// string IChannel.Name => $"@{Recipient}"; @@ -248,5 +281,6 @@ namespace Discord.WebSocket /// IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); + #endregion } } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs index c57c37db2..c8137784f 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs @@ -20,6 +20,7 @@ namespace Discord.WebSocket [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class SocketGroupChannel : SocketChannel, IGroupChannel, ISocketPrivateChannel, ISocketMessageChannel, ISocketAudioChannel { + #region SocketGroupChannel private readonly MessageCache _messages; private readonly ConcurrentDictionary _voiceStates; @@ -29,9 +30,20 @@ namespace Discord.WebSocket /// public string Name { get; private set; } + /// + public string RTCRegion { get; private set; } + /// public IReadOnlyCollection CachedMessages => _messages?.Messages ?? ImmutableArray.Create(); + + /// + /// Returns a collection representing all of the users in the group. + /// public new IReadOnlyCollection Users => _users.ToReadOnlyCollection(); + + /// + /// Returns a collection representing all users in the group, not including the client. + /// public IReadOnlyCollection Recipients => _users.Select(x => x.Value).Where(x => x.Id != Discord.CurrentUser.Id).ToReadOnlyCollection(() => _users.Count - 1); @@ -58,6 +70,8 @@ namespace Discord.WebSocket if (model.Recipients.IsSpecified) UpdateUsers(state, model.Recipients.Value); + + RTCRegion = model.RTCRegion.GetValueOrDefault(null); } private void UpdateUsers(ClientState state, UserModel[] models) { @@ -76,8 +90,9 @@ namespace Discord.WebSocket { throw new NotSupportedException("Voice is not yet supported for group channels."); } +#endregion - //Messages + #region Messages /// public SocketMessage GetCachedMessage(ulong id) => _messages?.Get(id); @@ -163,15 +178,24 @@ namespace Discord.WebSocket /// /// Message content is too long, length must be less or equal to . - public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, allowedMentions, options); + public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); /// - public Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) - => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, options, isSpoiler); + public Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, isSpoiler, embeds); + /// + /// Message content is too long, length must be less or equal to . + public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, isSpoiler, embeds); + /// + /// Message content is too long, length must be less or equal to . + public Task SendFileAsync(FileAttachment attachment, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, attachment, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); /// - public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) - => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options, isSpoiler); + /// Message content is too long, length must be less or equal to . + public Task SendFilesAsync(IEnumerable attachments, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFilesAsync(this, Discord, attachments, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); /// public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) @@ -180,6 +204,10 @@ namespace Discord.WebSocket public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) => ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); + /// + public async Task ModifyMessageAsync(ulong messageId, Action func, RequestOptions options = null) + => await ChannelHelper.ModifyMessageAsync(this, messageId, func, Discord, options).ConfigureAwait(false); + /// public Task TriggerTypingAsync(RequestOptions options = null) => ChannelHelper.TriggerTypingAsync(this, Discord, options); @@ -191,8 +219,9 @@ namespace Discord.WebSocket => _messages?.Add(msg); internal SocketMessage RemoveMessage(ulong id) => _messages?.Remove(id); + #endregion - //Users + #region Users /// /// Gets a user from this group. /// @@ -227,8 +256,9 @@ namespace Discord.WebSocket } return null; } + #endregion - //Voice States + #region Voice States internal SocketVoiceState AddOrUpdateVoiceState(ClientState state, VoiceStateModel model) { var voiceChannel = state.GetChannel(model.ChannelId.Value) as SocketVoiceChannel; @@ -255,22 +285,26 @@ namespace Discord.WebSocket public override string ToString() => Name; private string DebuggerDisplay => $"{Name} ({Id}, Group)"; internal new SocketGroupChannel Clone() => MemberwiseClone() as SocketGroupChannel; + #endregion - //SocketChannel + #region SocketChannel /// internal override IReadOnlyCollection GetUsersInternal() => Users; /// internal override SocketUser GetUserInternal(ulong id) => GetUser(id); + #endregion - //ISocketPrivateChannel + #region ISocketPrivateChannel /// IReadOnlyCollection ISocketPrivateChannel.Recipients => Recipients; + #endregion - //IPrivateChannel + #region IPrivateChannel /// IReadOnlyCollection IPrivateChannel.Recipients => Recipients; + #endregion - //IMessageChannel + #region IMessageChannel /// async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { @@ -293,27 +327,38 @@ namespace Discord.WebSocket => await GetPinnedMessagesAsync(options).ConfigureAwait(false); /// - async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler) - => await SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler).ConfigureAwait(false); + async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + /// + async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); /// - async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler) - => await SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler).ConfigureAwait(false); + async Task IMessageChannel.SendFileAsync(FileAttachment attachment, string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(attachment, text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + /// + async Task IMessageChannel.SendFilesAsync(IEnumerable attachments, string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFilesAsync(attachments, text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + /// - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions) - => await SendMessageAsync(text, isTTS, embed, options, allowedMentions).ConfigureAwait(false); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendMessageAsync(text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + #endregion - //IAudioChannel + #region IAudioChannel /// /// Connecting to a group channel is not supported. Task IAudioChannel.ConnectAsync(bool selfDeaf, bool selfMute, bool external) { throw new NotSupportedException(); } Task IAudioChannel.DisconnectAsync() { throw new NotSupportedException(); } + Task IAudioChannel.ModifyAsync(Action func, RequestOptions options) { throw new NotSupportedException(); } + #endregion - //IChannel + #region IChannel /// Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); /// IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); + #endregion } } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs index c65f3be05..d38a8975b 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs @@ -15,6 +15,7 @@ namespace Discord.WebSocket [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class SocketGuildChannel : SocketChannel, IGuildChannel { + #region SocketGuildChannel private ImmutableArray _overwrites; /// @@ -27,7 +28,7 @@ namespace Discord.WebSocket /// public string Name { get; private set; } /// - public int Position { get; private set; } + public int Position { get; private set; } /// public virtual IReadOnlyCollection PermissionOverwrites => _overwrites; @@ -46,27 +47,24 @@ namespace Discord.WebSocket } internal static SocketGuildChannel Create(SocketGuild guild, ClientState state, Model model) { - switch (model.Type) + return model.Type switch { - case ChannelType.News: - return SocketNewsChannel.Create(guild, state, model); - case ChannelType.Text: - return SocketTextChannel.Create(guild, state, model); - case ChannelType.Voice: - return SocketVoiceChannel.Create(guild, state, model); - case ChannelType.Category: - return SocketCategoryChannel.Create(guild, state, model); - default: - return new SocketGuildChannel(guild.Discord, model.Id, guild); - } + ChannelType.News => SocketNewsChannel.Create(guild, state, model), + ChannelType.Text => SocketTextChannel.Create(guild, state, model), + ChannelType.Voice => SocketVoiceChannel.Create(guild, state, model), + ChannelType.Category => SocketCategoryChannel.Create(guild, state, model), + ChannelType.PrivateThread or ChannelType.PublicThread or ChannelType.NewsThread => SocketThreadChannel.Create(guild, state, model), + ChannelType.Stage => SocketStageChannel.Create(guild, state, model), + _ => new SocketGuildChannel(guild.Discord, model.Id, guild), + }; } /// internal override void Update(ClientState state, Model model) { Name = model.Name.Value; - Position = model.Position.Value; - - var overwrites = model.PermissionOverwrites.Value; + Position = model.Position.GetValueOrDefault(0); + + var overwrites = model.PermissionOverwrites.GetValueOrDefault(new API.Overwrite[0]); var newOverwrites = ImmutableArray.CreateBuilder(overwrites.Length); for (int i = 0; i < overwrites.Length; i++) newOverwrites.Add(overwrites[i].ToEntity()); @@ -125,7 +123,6 @@ namespace Discord.WebSocket public virtual async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null) { await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, permissions, options).ConfigureAwait(false); - _overwrites = _overwrites.Add(new Overwrite(user.Id, PermissionTarget.User, new OverwritePermissions(permissions.AllowValue, permissions.DenyValue))); } /// @@ -140,7 +137,6 @@ namespace Discord.WebSocket public virtual async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null) { await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, permissions, options).ConfigureAwait(false); - _overwrites = _overwrites.Add(new Overwrite(role.Id, PermissionTarget.Role, new OverwritePermissions(permissions.AllowValue, permissions.DenyValue))); } /// /// Removes the permission overwrite for the given user, if one exists. @@ -153,15 +149,6 @@ namespace Discord.WebSocket public virtual async Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null) { await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options).ConfigureAwait(false); - - for (int i = 0; i < _overwrites.Length; i++) - { - if (_overwrites[i].TargetId == user.Id) - { - _overwrites = _overwrites.RemoveAt(i); - return; - } - } } /// /// Removes the permission overwrite for the given role, if one exists. @@ -174,15 +161,6 @@ namespace Discord.WebSocket public virtual async Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null) { await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options).ConfigureAwait(false); - - for (int i = 0; i < _overwrites.Length; i++) - { - if (_overwrites[i].TargetId == role.Id) - { - _overwrites = _overwrites.RemoveAt(i); - return; - } - } } public new virtual SocketGuildUser GetUser(ulong id) => null; @@ -196,14 +174,16 @@ namespace Discord.WebSocket public override string ToString() => Name; private string DebuggerDisplay => $"{Name} ({Id}, Guild)"; internal new SocketGuildChannel Clone() => MemberwiseClone() as SocketGuildChannel; +#endregion - //SocketChannel + #region SocketChannel /// internal override IReadOnlyCollection GetUsersInternal() => Users; /// internal override SocketUser GetUserInternal(ulong id) => GetUser(id); + #endregion - //IGuildChannel + #region IGuildChannel /// IGuild IGuildChannel.Guild => Guild; /// @@ -234,13 +214,15 @@ namespace Discord.WebSocket /// Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); + #endregion - //IChannel + #region IChannel /// IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); //Overridden in Text/Voice /// Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); //Overridden in Text/Voice + #endregion } } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketNewsChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketNewsChannel.cs index 815a99ce7..eed8f9374 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketNewsChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketNewsChannel.cs @@ -15,7 +15,7 @@ namespace Discord.WebSocket /// /// [DebuggerDisplay(@"{DebuggerDisplay,nq}")] - public class SocketNewsChannel : SocketTextChannel + public class SocketNewsChannel : SocketTextChannel, INewsChannel { internal SocketNewsChannel(DiscordSocketClient discord, ulong id, SocketGuild guild) :base(discord, id, guild) @@ -35,5 +35,6 @@ namespace Discord.WebSocket /// public override int SlowModeInterval => throw new NotSupportedException("News channels do not support Slow Mode."); + } } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketStageChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketStageChannel.cs new file mode 100644 index 000000000..91bca5054 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketStageChannel.cs @@ -0,0 +1,158 @@ +using Discord.Rest; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Threading.Tasks; +using Model = Discord.API.Channel; +using StageInstance = Discord.API.StageInstance; + +namespace Discord.WebSocket +{ + /// + /// Represents a stage channel received over the gateway. + /// + public class SocketStageChannel : SocketVoiceChannel, IStageChannel + { + /// + public string Topic { get; private set; } + + /// + public StagePrivacyLevel? PrivacyLevel { get; private set; } + + /// + public bool? IsDiscoverableDisabled { get; private set; } + + /// + public bool IsLive { get; private set; } + + /// + /// Returns if the current user is a speaker within the stage, otherwise . + /// + public bool IsSpeaker + => !Guild.CurrentUser.IsSuppressed; + + /// + /// Gets a collection of users who are speakers within the stage. + /// + public IReadOnlyCollection Speakers + => Users.Where(x => !x.IsSuppressed).ToImmutableArray(); + + internal new SocketStageChannel Clone() => MemberwiseClone() as SocketStageChannel; + + internal SocketStageChannel(DiscordSocketClient discord, ulong id, SocketGuild guild) + : base(discord, id, guild) { } + + internal new static SocketStageChannel Create(SocketGuild guild, ClientState state, Model model) + { + var entity = new SocketStageChannel(guild.Discord, model.Id, guild); + entity.Update(state, model); + return entity; + } + + internal void Update(StageInstance model, bool isLive = false) + { + IsLive = isLive; + if (isLive) + { + Topic = model.Topic; + PrivacyLevel = model.PrivacyLevel; + IsDiscoverableDisabled = model.DiscoverableDisabled; + } + else + { + Topic = null; + PrivacyLevel = null; + IsDiscoverableDisabled = null; + } + } + + /// + public async Task StartStageAsync(string topic, StagePrivacyLevel privacyLevel = StagePrivacyLevel.GuildOnly, RequestOptions options = null) + { + var args = new API.Rest.CreateStageInstanceParams + { + ChannelId = Id, + Topic = topic, + PrivacyLevel = privacyLevel + }; + + var model = await Discord.ApiClient.CreateStageInstanceAsync(args, options).ConfigureAwait(false); + + Update(model, true); + } + + /// + public async Task ModifyInstanceAsync(Action func, RequestOptions options = null) + { + var model = await ChannelHelper.ModifyAsync(this, Discord, func, options); + + Update(model, true); + } + + /// + public async Task StopStageAsync(RequestOptions options = null) + { + await Discord.ApiClient.DeleteStageInstanceAsync(Id, options); + + Update(null); + } + + /// + public Task RequestToSpeakAsync(RequestOptions options = null) + { + var args = new API.Rest.ModifyVoiceStateParams + { + ChannelId = Id, + RequestToSpeakTimestamp = DateTimeOffset.UtcNow + }; + return Discord.ApiClient.ModifyMyVoiceState(Guild.Id, args, options); + } + + /// + public Task BecomeSpeakerAsync(RequestOptions options = null) + { + var args = new API.Rest.ModifyVoiceStateParams + { + ChannelId = Id, + Suppressed = false + }; + return Discord.ApiClient.ModifyMyVoiceState(Guild.Id, args, options); + } + + /// + public Task StopSpeakingAsync(RequestOptions options = null) + { + var args = new API.Rest.ModifyVoiceStateParams + { + ChannelId = Id, + Suppressed = true + }; + return Discord.ApiClient.ModifyMyVoiceState(Guild.Id, args, options); + } + + /// + public Task MoveToSpeakerAsync(IGuildUser user, RequestOptions options = null) + { + var args = new API.Rest.ModifyVoiceStateParams + { + ChannelId = Id, + Suppressed = false + }; + + return Discord.ApiClient.ModifyUserVoiceState(Guild.Id, user.Id, args); + } + + /// + public Task RemoveFromSpeakerAsync(IGuildUser user, RequestOptions options = null) + { + var args = new API.Rest.ModifyVoiceStateParams + { + ChannelId = Id, + Suppressed = true + }; + + return Discord.ApiClient.ModifyUserVoiceState(Guild.Id, user.Id, args); + } + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs index 1b3b5bcd7..55085899d 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs @@ -16,6 +16,7 @@ namespace Discord.WebSocket [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class SocketTextChannel : SocketGuildChannel, ITextChannel, ISocketMessageChannel { + #region SocketTextChannel private readonly MessageCache _messages; /// @@ -50,6 +51,12 @@ namespace Discord.WebSocket Permissions.ResolveChannel(Guild, x, this, Permissions.ResolveGuild(Guild, x)), ChannelPermission.ViewChannel)).ToImmutableArray(); + /// + /// Gets a collection of threads within this text channel. + /// + public IReadOnlyCollection Threads + => Guild.ThreadChannels.Where(x => x.ParentChannel.Id == Id).ToImmutableArray(); + internal SocketTextChannel(DiscordSocketClient discord, ulong id, SocketGuild guild) : base(discord, id, guild) { @@ -66,16 +73,59 @@ namespace Discord.WebSocket { base.Update(state, model); CategoryId = model.CategoryId; - Topic = model.Topic.Value; + Topic = model.Topic.GetValueOrDefault(); SlowModeInterval = model.SlowMode.GetValueOrDefault(); // some guilds haven't been patched to include this yet? _nsfw = model.Nsfw.GetValueOrDefault(); } /// - public Task ModifyAsync(Action func, RequestOptions options = null) + public virtual Task ModifyAsync(Action func, RequestOptions options = null) => ChannelHelper.ModifyAsync(this, Discord, func, options); - //Messages + /// + /// Creates a thread within this . + /// + /// + /// When is the thread type will be based off of the + /// channel its created in. When called on a , it creates a . + /// When called on a , it creates a . The id of the created + /// thread will be the same as the id of the message, and as such a message can only have a + /// single thread created from it. + /// + /// The name of the thread. + /// + /// The type of the thread. + /// + /// Note: This parameter is not used if the parameter is not specified. + /// + /// + /// + /// The duration on which this thread archives after. + /// + /// Note: Options and + /// are only available for guilds that are boosted. You can check in the to see if the + /// guild has the THREE_DAY_THREAD_ARCHIVE and SEVEN_DAY_THREAD_ARCHIVE. + /// + /// + /// The message which to start the thread from. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous create operation. The task result contains a + /// + public virtual async Task CreateThreadAsync(string name, ThreadType type = ThreadType.PublicThread, + ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, IMessage message = null, bool? invitable = null, int? slowmode = null, RequestOptions options = null) + { + var model = await ThreadHelper.CreateThreadAsync(Discord, this, name, type, autoArchiveDuration, message, invitable, slowmode, options); + + var thread = (SocketThreadChannel)Guild.AddOrUpdateChannel(Discord.State, model); + + await thread.DownloadUsersAsync(); + + return thread; + } +#endregion + + #region Messages /// public SocketMessage GetCachedMessage(ulong id) => _messages?.Get(id); @@ -161,17 +211,27 @@ namespace Discord.WebSocket /// /// Message content is too long, length must be less or equal to . - public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, allowedMentions, options); + public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); + + /// + public Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, isSpoiler, embeds); + + /// + /// Message content is too long, length must be less or equal to . + public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, isSpoiler, embeds); /// - public Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) - => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, options, isSpoiler); + /// Message content is too long, length must be less or equal to . + public Task SendFileAsync(FileAttachment attachment, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFileAsync(this, Discord, attachment, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); /// /// Message content is too long, length must be less or equal to . - public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) - => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options, isSpoiler); + public Task SendFilesAsync(IEnumerable attachments, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null) + => ChannelHelper.SendFilesAsync(this, Discord, attachments, text, isTTS, embed, allowedMentions, messageReference, components, stickers, options, embeds); /// public Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) @@ -180,6 +240,10 @@ namespace Discord.WebSocket public Task DeleteMessagesAsync(IEnumerable messageIds, RequestOptions options = null) => ChannelHelper.DeleteMessagesAsync(this, Discord, messageIds, options); + /// + public async Task ModifyMessageAsync(ulong messageId, Action func, RequestOptions options = null) + => await ChannelHelper.ModifyMessageAsync(this, messageId, func, Discord, options).ConfigureAwait(false); + /// public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) => ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); @@ -198,8 +262,9 @@ namespace Discord.WebSocket => _messages?.Add(msg); internal SocketMessage RemoveMessage(ulong id) => _messages?.Remove(id); + #endregion - //Users + #region Users /// public override SocketGuildUser GetUser(ulong id) { @@ -213,8 +278,9 @@ namespace Discord.WebSocket } return null; } + #endregion - //Webhooks + #region Webhooks /// /// Creates a webhook in this text channel. /// @@ -225,7 +291,7 @@ namespace Discord.WebSocket /// A task that represents the asynchronous creation operation. The task result contains the newly created /// webhook. /// - public Task CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null) + public virtual Task CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null) => ChannelHelper.CreateWebhookAsync(this, Discord, name, avatar, options); /// /// Gets a webhook available in this text channel. @@ -236,7 +302,7 @@ namespace Discord.WebSocket /// A task that represents the asynchronous get operation. The task result contains a webhook associated /// with the identifier; null if the webhook is not found. /// - public Task GetWebhookAsync(ulong id, RequestOptions options = null) + public virtual Task GetWebhookAsync(ulong id, RequestOptions options = null) => ChannelHelper.GetWebhookAsync(this, Discord, id, options); /// /// Gets the webhooks available in this text channel. @@ -246,21 +312,32 @@ namespace Discord.WebSocket /// A task that represents the asynchronous get operation. The task result contains a read-only collection /// of webhooks that is available in this channel. /// - public Task> GetWebhooksAsync(RequestOptions options = null) + public virtual Task> GetWebhooksAsync(RequestOptions options = null) => ChannelHelper.GetWebhooksAsync(this, Discord, options); + #endregion - //Invites + #region Invites /// - public async Task CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + public virtual async Task CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); /// - public async Task> GetInvitesAsync(RequestOptions options = null) + public virtual async Task CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => await ChannelHelper.CreateInviteToApplicationAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, applicationId, options).ConfigureAwait(false); + /// + public virtual async Task CreateInviteToApplicationAsync(DefaultApplications application, int? maxAge = 86400, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => await ChannelHelper.CreateInviteToApplicationAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, (ulong)application, options); + /// + public virtual async Task CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => await ChannelHelper.CreateInviteToStreamAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, user, options).ConfigureAwait(false); + /// + public virtual async Task> GetInvitesAsync(RequestOptions options = null) => await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); private string DebuggerDisplay => $"{Name} ({Id}, Text)"; internal new SocketTextChannel Clone() => MemberwiseClone() as SocketTextChannel; + #endregion - //ITextChannel + #region ITextChannel /// async Task ITextChannel.CreateWebhookAsync(string name, Stream avatar, RequestOptions options) => await CreateWebhookAsync(name, avatar, options).ConfigureAwait(false); @@ -270,16 +347,21 @@ namespace Discord.WebSocket /// async Task> ITextChannel.GetWebhooksAsync(RequestOptions options) => await GetWebhooksAsync(options).ConfigureAwait(false); + /// + async Task ITextChannel.CreateThreadAsync(string name, ThreadType type, ThreadArchiveDuration autoArchiveDuration, IMessage message, bool? invitable, int? slowmode, RequestOptions options) + => await CreateThreadAsync(name, type, autoArchiveDuration, message, invitable, slowmode, options); + #endregion - //IGuildChannel + #region IGuildChannel /// Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); /// IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); + #endregion - //IMessageChannel + #region IMessageChannel /// async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { @@ -302,18 +384,26 @@ namespace Discord.WebSocket => await GetPinnedMessagesAsync(options).ConfigureAwait(false); /// - async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler) - => await SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler).ConfigureAwait(false); + async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + /// + async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + /// + async Task IMessageChannel.SendFileAsync(FileAttachment attachment, string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFileAsync(attachment, text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); /// - async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler) - => await SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler).ConfigureAwait(false); + async Task IMessageChannel.SendFilesAsync(IEnumerable attachments, string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendFilesAsync(attachments, text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); /// - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions) - => await SendMessageAsync(text, isTTS, embed, options, allowedMentions).ConfigureAwait(false); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageReference messageReference, MessageComponent components, ISticker[] stickers, Embed[] embeds) + => await SendMessageAsync(text, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds).ConfigureAwait(false); + #endregion - // INestedChannel + #region INestedChannel /// Task INestedChannel.GetCategoryAsync(CacheMode mode, RequestOptions options) => Task.FromResult(Category); + #endregion } } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketThreadChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketThreadChannel.cs new file mode 100644 index 000000000..7fcafc14a --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketThreadChannel.cs @@ -0,0 +1,339 @@ +using Discord.Rest; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Model = Discord.API.Channel; +using ThreadMember = Discord.API.ThreadMember; +using System.Collections.Concurrent; + +namespace Discord.WebSocket +{ + /// + /// Represents a thread channel inside of a guild. + /// + [DebuggerDisplay(@"{DebuggerDisplay,nq}")] + public class SocketThreadChannel : SocketTextChannel, IThreadChannel + { + /// + public ThreadType Type { get; private set; } + + /// + /// Gets the owner of the current thread. + /// + public SocketThreadUser Owner { get; private set; } + + /// + /// Gets the current users within this thread. + /// + public SocketThreadUser CurrentUser + => Users.FirstOrDefault(x => x.Id == Discord.CurrentUser.Id); + + /// + public bool HasJoined { get; private set; } + + /// + /// if this thread is private, otherwise + /// + public bool IsPrivateThread + => Type == ThreadType.PrivateThread; + + /// + /// Gets the parent channel this thread resides in. + /// + public SocketTextChannel ParentChannel { get; private set; } + + /// + public int MessageCount { get; private set; } + + /// + public int MemberCount { get; private set; } + + /// + public bool IsArchived { get; private set; } + + /// + public DateTimeOffset ArchiveTimestamp { get; private set; } + + /// + public ThreadArchiveDuration AutoArchiveDuration { get; private set; } + + /// + public bool IsLocked { get; private set; } + + /// + /// Gets a collection of cached users within this thread. + /// + public new IReadOnlyCollection Users => + _members.Values.ToImmutableArray(); + + private readonly ConcurrentDictionary _members; + + private string DebuggerDisplay => $"{Name} ({Id}, Thread)"; + + private bool _usersDownloaded; + + private readonly object _downloadLock = new object(); + + internal SocketThreadChannel(DiscordSocketClient discord, SocketGuild guild, ulong id, SocketTextChannel parent) + : base(discord, id, guild) + { + ParentChannel = parent; + _members = new ConcurrentDictionary(); + } + + internal new static SocketThreadChannel Create(SocketGuild guild, ClientState state, Model model) + { + var parent = (SocketTextChannel)guild.GetChannel(model.CategoryId.Value); + var entity = new SocketThreadChannel(guild.Discord, guild, model.Id, parent); + entity.Update(state, model); + return entity; + } + + internal override void Update(ClientState state, Model model) + { + base.Update(state, model); + + Type = (ThreadType)model.Type; + MessageCount = model.MessageCount.GetValueOrDefault(-1); + MemberCount = model.MemberCount.GetValueOrDefault(-1); + + if (model.ThreadMetadata.IsSpecified) + { + IsArchived = model.ThreadMetadata.Value.Archived; + ArchiveTimestamp = model.ThreadMetadata.Value.ArchiveTimestamp; + AutoArchiveDuration = model.ThreadMetadata.Value.AutoArchiveDuration; + IsLocked = model.ThreadMetadata.Value.Locked.GetValueOrDefault(false); + } + + if (model.OwnerId.IsSpecified) + { + Owner = GetUser(model.OwnerId.Value); + } + + HasJoined = model.ThreadMember.IsSpecified; + } + + internal IReadOnlyCollection RemoveUsers(ulong[] users) + { + List threadUsers = new(); + + foreach (var userId in users) + { + if (_members.TryRemove(userId, out var user)) + threadUsers.Add(user); + } + + return threadUsers.ToImmutableArray(); + } + + internal SocketThreadUser AddOrUpdateThreadMember(ThreadMember model, SocketGuildUser guildMember) + { + if (_members.TryGetValue(model.UserId.Value, out SocketThreadUser member)) + member.Update(model); + else + { + member = SocketThreadUser.Create(Guild, this, model, guildMember); + member.GlobalUser.AddRef(); + _members[member.Id] = member; + } + return member; + } + + /// + public new SocketThreadUser GetUser(ulong id) + { + var user = Users.FirstOrDefault(x => x.Id == id); + return user; + } + + /// + /// Gets all users inside this thread. + /// + /// + /// If all users are not downloaded then this method will call and return the result. + /// + /// The options to be used when sending the request. + /// A task representing the download operation. + public async Task> GetUsersAsync(RequestOptions options = null) + { + // download all users if we havent + if (!_usersDownloaded) + { + await DownloadUsersAsync(options); + _usersDownloaded = true; + } + + return Users; + } + + /// + /// Downloads all users that have access to this thread. + /// + /// The options to be used when sending the request. + /// A task representing the asynchronous download operation. + public async Task DownloadUsersAsync(RequestOptions options = null) + { + var users = await Discord.ApiClient.ListThreadMembersAsync(Id, options); + + lock (_downloadLock) + { + foreach (var threadMember in users) + { + var guildUser = Guild.GetUser(threadMember.UserId.Value); + + AddOrUpdateThreadMember(threadMember, guildUser); + } + } + } + + internal new SocketThreadChannel Clone() => MemberwiseClone() as SocketThreadChannel; + + /// + public Task JoinAsync(RequestOptions options = null) + => Discord.ApiClient.JoinThreadAsync(Id, options); + + /// + public Task LeaveAsync(RequestOptions options = null) + => Discord.ApiClient.LeaveThreadAsync(Id, options); + + /// + /// Adds a user to this thread. + /// + /// The to add. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous operation of adding a member to a thread. + /// + public Task AddUserAsync(IGuildUser user, RequestOptions options = null) + => Discord.ApiClient.AddThreadMemberAsync(Id, user.Id, options); + + /// + /// Removes a user from this thread. + /// + /// The to remove from this thread. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous operation of removing a user from this thread. + /// + public Task RemoveUserAsync(IGuildUser user, RequestOptions options = null) + => Discord.ApiClient.RemoveThreadMemberAsync(Id, user.Id, options); + + /// + /// + /// This method is not supported in threads. + /// + public override Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task> GetInvitesAsync(RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override OverwritePermissions? GetPermissionOverwrite(IRole role) + => ParentChannel.GetPermissionOverwrite(role); + + /// + /// + /// This method is not supported in threads. + /// + public override OverwritePermissions? GetPermissionOverwrite(IUser user) + => ParentChannel.GetPermissionOverwrite(user); + + /// + /// + /// This method is not supported in threads. + /// + public override Task GetWebhookAsync(ulong id, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task> GetWebhooksAsync(RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task ModifyAsync(Action func, RequestOptions options = null) + => ThreadHelper.ModifyAsync(this, Discord, func, options); + + /// + /// + /// This method is not supported in threads. + /// + public override Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override IReadOnlyCollection PermissionOverwrites + => throw new NotSupportedException("This method is not supported in threads."); + + /// + /// + /// This method is not supported in threads. + /// + public override Task SyncPermissionsAsync(RequestOptions options = null) + => throw new NotSupportedException("This method is not supported in threads."); + + string IChannel.Name => Name; + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs index 9fff6c207..00003d4ed 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs @@ -16,10 +16,14 @@ namespace Discord.WebSocket [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class SocketVoiceChannel : SocketGuildChannel, IVoiceChannel, ISocketAudioChannel { + #region SocketVoiceChannel /// public int Bitrate { get; private set; } /// public int? UserLimit { get; private set; } + /// + public string RTCRegion { get; private set; } + /// public ulong? CategoryId { get; private set; } /// @@ -30,11 +34,20 @@ namespace Discord.WebSocket /// public ICategoryChannel Category => CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null; + + /// + public string Mention => MentionUtils.MentionChannel(Id); + /// public Task SyncPermissionsAsync(RequestOptions options = null) => ChannelHelper.SyncPermissionsAsync(this, Discord, options); - /// + /// + /// Gets a collection of users that are currently connected to this voice channel. + /// + /// + /// A read-only collection of users that are currently connected to this voice channel. + /// public override IReadOnlyCollection Users => Guild.Users.Where(x => x.VoiceChannel?.Id == Id).ToImmutableArray(); @@ -55,6 +68,7 @@ namespace Discord.WebSocket CategoryId = model.CategoryId; Bitrate = model.Bitrate.Value; UserLimit = model.UserLimit.Value != 0 ? model.UserLimit.Value : (int?)null; + RTCRegion = model.RTCRegion.GetValueOrDefault(null); } /// @@ -71,6 +85,12 @@ namespace Discord.WebSocket public async Task DisconnectAsync() => await Guild.DisconnectAudioAsync(); + /// + public async Task ModifyAsync(Action func, RequestOptions options = null) + { + await Guild.ModifyAudioAsync(Id, func, options).ConfigureAwait(false); + } + /// public override SocketGuildUser GetUser(ulong id) { @@ -79,29 +99,42 @@ namespace Discord.WebSocket return user; return null; } +#endregion - //Invites + #region Invites /// public async Task CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); /// + public async Task CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => await ChannelHelper.CreateInviteToApplicationAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, applicationId, options).ConfigureAwait(false); + /// + public virtual async Task CreateInviteToApplicationAsync(DefaultApplications application, int? maxAge = 86400, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => await ChannelHelper.CreateInviteToApplicationAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, (ulong)application, options); + /// + public async Task CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => await ChannelHelper.CreateInviteToStreamAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, user, options).ConfigureAwait(false); + /// public async Task> GetInvitesAsync(RequestOptions options = null) => await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); private string DebuggerDisplay => $"{Name} ({Id}, Voice)"; internal new SocketVoiceChannel Clone() => MemberwiseClone() as SocketVoiceChannel; + #endregion - //IGuildChannel + #region IGuildChannel /// Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); /// IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); + #endregion - // INestedChannel + #region INestedChannel /// Task INestedChannel.GetCategoryAsync(CacheMode mode, RequestOptions options) => Task.FromResult(Category); + #endregion } } diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index cdba2b67d..48b4bb5bc 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -1,3 +1,4 @@ +using Discord.API.Gateway; using Discord.Audio; using Discord.Rest; using System; @@ -19,6 +20,9 @@ using PresenceModel = Discord.API.Presence; using RoleModel = Discord.API.Role; using UserModel = Discord.API.User; using VoiceStateModel = Discord.API.VoiceState; +using StickerModel = Discord.API.Sticker; +using EventModel = Discord.API.GuildScheduledEvent; +using System.IO; namespace Discord.WebSocket { @@ -28,17 +32,21 @@ namespace Discord.WebSocket [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class SocketGuild : SocketEntity, IGuild, IDisposable { + #region SocketGuild #pragma warning disable IDISP002, IDISP006 private readonly SemaphoreSlim _audioLock; private TaskCompletionSource _syncPromise, _downloaderPromise; private TaskCompletionSource _audioConnectPromise; - private ConcurrentHashSet _channels; + private ConcurrentDictionary _channels; private ConcurrentDictionary _members; private ConcurrentDictionary _roles; private ConcurrentDictionary _voiceStates; + private ConcurrentDictionary _stickers; + private ConcurrentDictionary _events; private ImmutableArray _emotes; - private ImmutableArray _features; + private AudioClient _audioClient; + private VoiceStateUpdateParams _voiceStateUpdateParams; #pragma warning restore IDISP002, IDISP006 /// @@ -46,7 +54,7 @@ namespace Discord.WebSocket /// public int AFKTimeout { get; private set; } /// - public bool IsEmbeddable { get; private set; } + public bool IsWidgetEnabled { get; private set; } /// public VerificationLevel VerificationLevel { get; private set; } /// @@ -82,8 +90,10 @@ namespace Discord.WebSocket public ulong? ApplicationId { get; internal set; } internal ulong? AFKChannelId { get; private set; } - internal ulong? EmbedChannelId { get; private set; } + internal ulong? WidgetChannelId { get; private set; } internal ulong? SystemChannelId { get; private set; } + internal ulong? RulesChannelId { get; private set; } + internal ulong? PublicUpdatesChannelId { get; private set; } /// public ulong OwnerId { get; private set; } /// Gets the user that owns this guild. @@ -95,6 +105,8 @@ namespace Discord.WebSocket /// public string SplashId { get; private set; } /// + public string DiscoverySplashId { get; private set; } + /// public PremiumTier PremiumTier { get; private set; } /// public string BannerId { get; private set; } @@ -108,9 +120,20 @@ namespace Discord.WebSocket public int PremiumSubscriptionCount { get; private set; } /// public string PreferredLocale { get; private set; } - + /// + public int? MaxPresences { get; private set; } + /// + public int? MaxMembers { get; private set; } + /// + public int? MaxVideoChannelUsers { get; private set; } + /// + public NsfwLevel NsfwLevel { get; private set; } /// public CultureInfo PreferredCulture { get; private set; } + /// + public bool IsBoostProgressBarEnabled { get; private set; } + /// + public GuildFeatures Features { get; private set; } /// public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); @@ -119,9 +142,11 @@ namespace Discord.WebSocket /// public string SplashUrl => CDN.GetGuildSplashUrl(Id, SplashId); /// - public string BannerUrl => CDN.GetGuildBannerUrl(Id, BannerId); + public string DiscoverySplashUrl => CDN.GetGuildDiscoverySplashUrl(Id, DiscoverySplashId); + /// + public string BannerUrl => CDN.GetGuildBannerUrl(Id, BannerId, ImageFormat.Auto); /// Indicates whether the client has all the members downloaded to the local guild cache. - public bool HasAllMembers => MemberCount == DownloadedMemberCount;// _downloaderPromise.Task.IsCompleted; + public bool HasAllMembers => MemberCount <= DownloadedMemberCount;// _downloaderPromise.Task.IsCompleted; /// Indicates whether the guild cache is synced to this guild. public bool IsSynced => _syncPromise.Task.IsCompleted; public Task SyncPromise => _syncPromise.Task; @@ -152,7 +177,7 @@ namespace Discord.WebSocket /// /// /// A that the AFK users will be moved to after they have idled for too - /// long; null if none is set. + /// long; if none is set. /// public SocketVoiceChannel AFKChannel { @@ -162,17 +187,34 @@ namespace Discord.WebSocket return id.HasValue ? GetVoiceChannel(id.Value) : null; } } + /// + public int MaxBitrate + { + get + { + return PremiumTier switch + { + PremiumTier.Tier1 => 128000, + PremiumTier.Tier2 => 256000, + PremiumTier.Tier3 => 384000, + _ => 96000, + }; + } + } + /// + public ulong MaxUploadLimit + => GuildHelper.GetUploadLimit(this); /// - /// Gets the embed channel (i.e. the channel set in the guild's widget settings) in this guild. + /// Gets the widget channel (i.e. the channel set in the guild's widget settings) in this guild. /// /// - /// A channel set within the server's widget settings; null if none is set. + /// A channel set within the server's widget settings; if none is set. /// - public SocketGuildChannel EmbedChannel + public SocketGuildChannel WidgetChannel { get { - var id = EmbedChannelId; + var id = WidgetChannelId; return id.HasValue ? GetChannel(id.Value) : null; } } @@ -180,7 +222,7 @@ namespace Discord.WebSocket /// Gets the system channel where randomized welcome messages are sent in this guild. /// /// - /// A text channel where randomized welcome messages will be sent to; null if none is set. + /// A text channel where randomized welcome messages will be sent to; if none is set. /// public SocketTextChannel SystemChannel { @@ -191,6 +233,36 @@ namespace Discord.WebSocket } } /// + /// Gets the channel with the guild rules. + /// + /// + /// A text channel with the guild rules; if none is set. + /// + public SocketTextChannel RulesChannel + { + get + { + var id = RulesChannelId; + return id.HasValue ? GetTextChannel(id.Value) : null; + } + } + /// + /// Gets the channel where admins and moderators of Community guilds receive + /// notices from Discord. + /// + /// + /// A text channel where admins and moderators of Community guilds receive + /// notices from Discord; if none is set. + /// + public SocketTextChannel PublicUpdatesChannel + { + get + { + var id = PublicUpdatesChannelId; + return id.HasValue ? GetTextChannel(id.Value) : null; + } + } + /// /// Gets a collection of all text channels in this guild. /// /// @@ -207,6 +279,14 @@ namespace Discord.WebSocket public IReadOnlyCollection VoiceChannels => Channels.OfType().ToImmutableArray(); /// + /// Gets a collection of all stage channels in this guild. + /// + /// + /// A read-only collection of stage channels found within this guild. + /// + public IReadOnlyCollection StageChannels + => Channels.OfType().ToImmutableArray(); + /// /// Gets a collection of all category channels in this guild. /// /// @@ -215,6 +295,14 @@ namespace Discord.WebSocket public IReadOnlyCollection CategoryChannels => Channels.OfType().ToImmutableArray(); /// + /// Gets a collection of all thread channels in this guild. + /// + /// + /// A read-only collection of thread channels found within this guild. + /// + public IReadOnlyCollection ThreadChannels + => Channels.OfType().ToImmutableArray(); + /// /// Gets the current logged-in user. /// public SocketGuildUser CurrentUser => _members.TryGetValue(Discord.CurrentUser.Id, out SocketGuildUser member) ? member : null; @@ -237,13 +325,16 @@ namespace Discord.WebSocket { var channels = _channels; var state = Discord.State; - return channels.Select(x => state.GetChannel(x) as SocketGuildChannel).Where(x => x != null).ToReadOnlyCollection(channels); + return channels.Select(x => x.Value).Where(x => x != null).ToReadOnlyCollection(channels); } } /// public IReadOnlyCollection Emotes => _emotes; - /// - public IReadOnlyCollection Features => _features; + /// + /// Gets a collection of all custom stickers for this guild. + /// + public IReadOnlyCollection Stickers + => _stickers.Select(x => x.Value).ToImmutableArray(); /// /// Gets a collection of users in this guild. /// @@ -274,12 +365,22 @@ namespace Discord.WebSocket /// public IReadOnlyCollection Roles => _roles.ToReadOnlyCollection(); + /// + /// Gets a collection of all events within this guild. + /// + /// + /// This field is based off of caching alone, since there is no events returned on the guild model. + /// + /// + /// A read-only collection of guild events found within this guild. + /// + public IReadOnlyCollection Events => _events.ToReadOnlyCollection(); + internal SocketGuild(DiscordSocketClient client, ulong id) : base(client, id) { _audioLock = new SemaphoreSlim(1, 1); _emotes = ImmutableArray.Create(); - _features = ImmutableArray.Create(); } internal static SocketGuild Create(DiscordSocketClient discord, ClientState state, ExtendedModel model) { @@ -292,8 +393,10 @@ namespace Discord.WebSocket IsAvailable = !(model.Unavailable ?? false); if (!IsAvailable) { + if(_events == null) + _events = new ConcurrentDictionary(); if (_channels == null) - _channels = new ConcurrentHashSet(); + _channels = new ConcurrentDictionary(); if (_members == null) _members = new ConcurrentDictionary(); if (_roles == null) @@ -309,15 +412,23 @@ namespace Discord.WebSocket Update(state, model as Model); - var channels = new ConcurrentHashSet(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.Channels.Length * 1.05)); + var channels = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.Channels.Length * 1.05)); { for (int i = 0; i < model.Channels.Length; i++) { var channel = SocketGuildChannel.Create(this, state, model.Channels[i]); state.AddChannel(channel); - channels.TryAdd(channel.Id); + channels.TryAdd(channel.Id, channel); + } + + for(int i = 0; i < model.Threads.Length; i++) + { + var threadChannel = SocketThreadChannel.Create(this, state, model.Threads[i]); + state.AddChannel(threadChannel); + channels.TryAdd(threadChannel.Id, threadChannel); } } + _channels = channels; var members = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.Members.Length * 1.05)); @@ -325,7 +436,8 @@ namespace Discord.WebSocket for (int i = 0; i < model.Members.Length; i++) { var member = SocketGuildUser.Create(this, state, model.Members[i]); - members.TryAdd(member.Id, member); + if (members.TryAdd(member.Id, member)) + member.GlobalUser.AddRef(); } DownloadedMemberCount = members.Count; @@ -351,6 +463,17 @@ namespace Discord.WebSocket } _voiceStates = voiceStates; + var events = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.GuildScheduledEvents.Length * 1.05)); + { + for (int i = 0; i < model.GuildScheduledEvents.Length; i++) + { + var guildEvent = SocketGuildEvent.Create(Discord, this, model.GuildScheduledEvents[i]); + events.TryAdd(guildEvent.Id, guildEvent); + } + } + _events = events; + + _syncPromise = new TaskCompletionSource(); _downloaderPromise = new TaskCompletionSource(); var _ = _syncPromise.TrySetResultAsync(true); @@ -360,15 +483,20 @@ namespace Discord.WebSocket internal void Update(ClientState state, Model model) { AFKChannelId = model.AFKChannelId; - EmbedChannelId = model.EmbedChannelId; + if (model.WidgetChannelId.IsSpecified) + WidgetChannelId = model.WidgetChannelId.Value; SystemChannelId = model.SystemChannelId; + RulesChannelId = model.RulesChannelId; + PublicUpdatesChannelId = model.PublicUpdatesChannelId; AFKTimeout = model.AFKTimeout; - IsEmbeddable = model.EmbedEnabled; + if (model.WidgetEnabled.IsSpecified) + IsWidgetEnabled = model.WidgetEnabled.Value; IconId = model.Icon; Name = model.Name; OwnerId = model.OwnerId; VoiceRegionId = model.Region; SplashId = model.Splash; + DiscoverySplashId = model.DiscoverySplash; VerificationLevel = model.VerificationLevel; MfaLevel = model.MfaLevel; DefaultMessageNotifications = model.DefaultMessageNotifications; @@ -380,9 +508,17 @@ namespace Discord.WebSocket SystemChannelFlags = model.SystemChannelFlags; Description = model.Description; PremiumSubscriptionCount = model.PremiumSubscriptionCount.GetValueOrDefault(); + NsfwLevel = model.NsfwLevel; + if (model.MaxPresences.IsSpecified) + MaxPresences = model.MaxPresences.Value ?? 25000; + if (model.MaxMembers.IsSpecified) + MaxMembers = model.MaxMembers.Value; + if (model.MaxVideoChannelUsers.IsSpecified) + MaxVideoChannelUsers = model.MaxVideoChannelUsers.Value; PreferredLocale = model.PreferredLocale; - PreferredCulture = new CultureInfo(PreferredLocale); - + PreferredCulture = PreferredLocale == null ? null : new CultureInfo(PreferredLocale); + if (model.IsBoostProgressBarEnabled.IsSpecified) + IsBoostProgressBarEnabled = model.IsBoostProgressBarEnabled.Value; if (model.Emojis != null) { var emojis = ImmutableArray.CreateBuilder(model.Emojis.Length); @@ -393,10 +529,7 @@ namespace Discord.WebSocket else _emotes = ImmutableArray.Create(); - if (model.Features != null) - _features = model.Features.ToImmutableArray(); - else - _features = ImmutableArray.Create(); + Features = model.Features; var roles = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.Roles.Length * 1.05)); if (model.Roles != null) @@ -408,8 +541,27 @@ namespace Discord.WebSocket } } _roles = roles; + + if (model.Stickers != null) + { + var stickers = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.Stickers.Length * 1.05)); + for (int i = 0; i < model.Stickers.Length; i++) + { + var sticker = model.Stickers[i]; + if (sticker.User.IsSpecified) + AddOrUpdateUser(sticker.User.Value); + + var entity = SocketCustomSticker.Create(Discord, sticker, this, sticker.User.IsSpecified ? sticker.User.Value.Id : null); + + stickers.TryAdd(sticker.Id, entity); + } + + _stickers = stickers; + } + else + _stickers = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, 7); } - internal void Update(ClientState state, GuildSyncModel model) + /*internal void Update(ClientState state, GuildSyncModel model) //TODO remove? userbot related { var members = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.Members.Length * 1.05)); { @@ -429,9 +581,9 @@ namespace Discord.WebSocket _members = members; var _ = _syncPromise.TrySetResultAsync(true); - /*if (!model.Large) - _ = _downloaderPromise.TrySetResultAsync(true);*/ - } + //if (!model.Large) + // _ = _downloaderPromise.TrySetResultAsync(true); + }*/ internal void Update(ClientState state, EmojiUpdateModel model) { @@ -440,21 +592,22 @@ namespace Discord.WebSocket emotes.Add(model.Emojis[i].ToEntity()); _emotes = emotes.ToImmutable(); } + #endregion - //General + #region General /// public Task DeleteAsync(RequestOptions options = null) => GuildHelper.DeleteAsync(this, Discord, options); /// - /// is null. + /// is . public Task ModifyAsync(Action func, RequestOptions options = null) => GuildHelper.ModifyAsync(this, Discord, func, options); /// - /// is null. - public Task ModifyEmbedAsync(Action func, RequestOptions options = null) - => GuildHelper.ModifyEmbedAsync(this, Discord, func, options); + /// is . + public Task ModifyWidgetAsync(Action func, RequestOptions options = null) + => GuildHelper.ModifyWidgetAsync(this, Discord, func, options); /// public Task ReorderChannelsAsync(IEnumerable args, RequestOptions options = null) => GuildHelper.ReorderChannelsAsync(this, Discord, args, options); @@ -465,8 +618,9 @@ namespace Discord.WebSocket /// public Task LeaveAsync(RequestOptions options = null) => GuildHelper.LeaveAsync(this, Discord, options); + #endregion - //Bans + #region Bans /// /// Gets a collection of all users banned in this guild. /// @@ -485,7 +639,7 @@ namespace Discord.WebSocket /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains a ban object, which - /// contains the user information and the reason for the ban; null if the ban entry cannot be found. + /// contains the user information and the reason for the ban; if the ban entry cannot be found. /// public Task GetBanAsync(IUser user, RequestOptions options = null) => GuildHelper.GetBanAsync(this, Discord, user.Id, options); @@ -496,7 +650,7 @@ namespace Discord.WebSocket /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains a ban object, which - /// contains the user information and the reason for the ban; null if the ban entry cannot be found. + /// contains the user information and the reason for the ban; if the ban entry cannot be found. /// public Task GetBanAsync(ulong userId, RequestOptions options = null) => GuildHelper.GetBanAsync(this, Discord, userId, options); @@ -514,14 +668,15 @@ namespace Discord.WebSocket /// public Task RemoveBanAsync(ulong userId, RequestOptions options = null) => GuildHelper.RemoveBanAsync(this, Discord, userId, options); + #endregion - //Channels + #region Channels /// /// Gets a channel in this guild. /// /// The snowflake identifier for the channel. /// - /// A generic channel associated with the specified ; null if none is found. + /// A generic channel associated with the specified ; if none is found. /// public SocketGuildChannel GetChannel(ulong id) { @@ -535,25 +690,44 @@ namespace Discord.WebSocket /// /// The snowflake identifier for the text channel. /// - /// A text channel associated with the specified ; null if none is found. + /// A text channel associated with the specified ; if none is found. /// public SocketTextChannel GetTextChannel(ulong id) => GetChannel(id) as SocketTextChannel; /// + /// Gets a thread in this guild. + /// + /// The snowflake identifier for the thread. + /// + /// A thread channel associated with the specified ; if none is found. + /// + public SocketThreadChannel GetThreadChannel(ulong id) + => GetChannel(id) as SocketThreadChannel; + + /// /// Gets a voice channel in this guild. /// /// The snowflake identifier for the voice channel. /// - /// A voice channel associated with the specified ; null if none is found. + /// A voice channel associated with the specified ; if none is found. /// public SocketVoiceChannel GetVoiceChannel(ulong id) => GetChannel(id) as SocketVoiceChannel; /// + /// Gets a stage channel in this guild. + /// + /// The snowflake identifier for the stage channel. + /// + /// A stage channel associated with the specified ; if none is found. + /// + public SocketStageChannel GetStageChannel(ulong id) + => GetChannel(id) as SocketStageChannel; + /// /// Gets a category channel in this guild. /// /// The snowflake identifier for the category channel. /// - /// A category channel associated with the specified ; null if none is found. + /// A category channel associated with the specified ; if none is found. /// public SocketCategoryChannel GetCategoryChannel(ulong id) => GetChannel(id) as SocketCategoryChannel; @@ -589,20 +763,33 @@ namespace Discord.WebSocket /// The new name for the voice channel. /// The delegate containing the properties to be applied to the channel upon its creation. /// The options to be used when sending the request. - /// is null. + /// is . /// /// A task that represents the asynchronous creation operation. The task result contains the newly created /// voice channel. /// public Task CreateVoiceChannelAsync(string name, Action func = null, RequestOptions options = null) => GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options, func); + + /// + /// Creates a new stage channel in this guild. + /// + /// The new name for the stage channel. + /// The delegate containing the properties to be applied to the channel upon its creation. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the newly created + /// stage channel. + /// + public Task CreateStageChannelAsync(string name, Action func = null, RequestOptions options = null) + => GuildHelper.CreateStageChannelAsync(this, Discord, name, options, func); /// /// Creates a new channel category in this guild. /// /// The new name for the category. /// The delegate containing the properties to be applied to the channel upon its creation. /// The options to be used when sending the request. - /// is null. + /// is . /// /// A task that represents the asynchronous creation operation. The task result contains the newly created /// category channel. @@ -613,25 +800,40 @@ namespace Discord.WebSocket internal SocketGuildChannel AddChannel(ClientState state, ChannelModel model) { var channel = SocketGuildChannel.Create(this, state, model); - _channels.TryAdd(model.Id); + _channels.TryAdd(model.Id, channel); state.AddChannel(channel); return channel; } + + internal SocketGuildChannel AddOrUpdateChannel(ClientState state, ChannelModel model) + { + if (_channels.TryGetValue(model.Id, out SocketGuildChannel channel)) + channel.Update(Discord.State, model); + else + { + channel = SocketGuildChannel.Create(this, Discord.State, model); + _channels[channel.Id] = channel; + state.AddChannel(channel); + } + return channel; + } + internal SocketGuildChannel RemoveChannel(ClientState state, ulong id) { - if (_channels.TryRemove(id)) + if (_channels.TryRemove(id, out var _)) return state.RemoveChannel(id) as SocketGuildChannel; return null; } internal void PurgeChannelCache(ClientState state) { foreach (var channelId in _channels) - state.RemoveChannel(channelId); + state.RemoveChannel(channelId.Key); _channels.Clear(); } + #endregion - //Voice Regions + #region Voice Regions /// /// Gets a collection of all the voice regions this guild can access. /// @@ -642,14 +844,124 @@ namespace Discord.WebSocket /// public Task> GetVoiceRegionsAsync(RequestOptions options = null) => GuildHelper.GetVoiceRegionsAsync(this, Discord, options); + #endregion - //Integrations + #region Integrations public Task> GetIntegrationsAsync(RequestOptions options = null) => GuildHelper.GetIntegrationsAsync(this, Discord, options); public Task CreateIntegrationAsync(ulong id, string type, RequestOptions options = null) => GuildHelper.CreateIntegrationAsync(this, Discord, id, type, options); + #endregion + + #region Interactions + /// + /// Deletes all application commands in the current guild. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous delete operation. + /// + public Task DeleteApplicationCommandsAsync(RequestOptions options = null) + => InteractionHelper.DeleteAllGuildCommandsAsync(Discord, Id, options); + + /// + /// Gets a collection of slash commands created by the current user in this guild. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a read-only collection of + /// slash commands created by the current user. + /// + public async Task> GetApplicationCommandsAsync(RequestOptions options = null) + { + var commands = (await Discord.ApiClient.GetGuildApplicationCommandsAsync(Id, options)).Select(x => SocketApplicationCommand.Create(Discord, x, Id)); + + foreach (var command in commands) + { + Discord.State.AddCommand(command); + } + + return commands.ToImmutableArray(); + } + + /// + /// Gets an application command within this guild with the specified id. + /// + /// The id of the application command to get. + /// The that determines whether the object should be fetched from cache. + /// The options to be used when sending the request. + /// + /// A ValueTask that represents the asynchronous get operation. The task result contains a + /// if found, otherwise . + /// + public async ValueTask GetApplicationCommandAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null) + { + var command = Discord.State.GetCommand(id); + + if (command != null) + return command; + + if (mode == CacheMode.CacheOnly) + return null; + + var model = await Discord.ApiClient.GetGlobalApplicationCommandAsync(id, options); + + if (model == null) + return null; + + command = SocketApplicationCommand.Create(Discord, model, Id); + + Discord.State.AddCommand(command); + + return command; + } + + /// + /// Creates an application command within this guild. + /// + /// The properties to use when creating the command. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the command that was created. + /// + public async Task CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null) + { + var model = await InteractionHelper.CreateGuildCommandAsync(Discord, Id, properties, options); + + var entity = Discord.State.GetOrAddCommand(model.Id, (id) => SocketApplicationCommand.Create(Discord, model)); + + entity.Update(model); + + return entity; + } + + /// + /// Overwrites the application commands within this guild. + /// + /// A collection of properties to use when creating the commands. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains a collection of commands that was created. + /// + public async Task> BulkOverwriteApplicationCommandAsync(ApplicationCommandProperties[] properties, + RequestOptions options = null) + { + var models = await InteractionHelper.BulkOverwriteGuildCommandsAsync(Discord, Id, properties, options); + + var entities = models.Select(x => SocketApplicationCommand.Create(Discord, x)); + + Discord.State.PurgeCommands(x => !x.IsGlobalCommand && x.Guild.Id == Id); + + foreach(var entity in entities) + { + Discord.State.AddCommand(entity); + } + + return entities.ToImmutableArray(); + } + #endregion - //Invites + #region Invites /// /// Gets a collection of all invites in this guild. /// @@ -666,18 +978,19 @@ namespace Discord.WebSocket /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the partial metadata of - /// the vanity invite found within this guild; null if none is found. + /// the vanity invite found within this guild; if none is found. /// public Task GetVanityInviteAsync(RequestOptions options = null) => GuildHelper.GetVanityInviteAsync(this, Discord, options); + #endregion - //Roles + #region Roles /// /// Gets a role in this guild. /// /// The snowflake identifier for the role. /// - /// A role that is associated with the specified ; null if none is found. + /// A role that is associated with the specified ; if none is found. /// public SocketRole GetRole(ulong id) { @@ -699,7 +1012,7 @@ namespace Discord.WebSocket /// Whether the role is separated from others on the sidebar. /// Whether the role can be mentioned. /// The options to be used when sending the request. - /// is null. + /// is . /// /// A task that represents the asynchronous creation operation. The task result contains the newly created /// role. @@ -720,7 +1033,45 @@ namespace Discord.WebSocket return null; } - //Users + internal SocketRole AddOrUpdateRole(RoleModel model) + { + if (_roles.TryGetValue(model.Id, out SocketRole role)) + _roles[model.Id].Update(Discord.State, model); + else + role = AddRole(model); + + return role; + } + + internal SocketCustomSticker AddSticker(StickerModel model) + { + if (model.User.IsSpecified) + AddOrUpdateUser(model.User.Value); + + var sticker = SocketCustomSticker.Create(Discord, model, this, model.User.IsSpecified ? model.User.Value.Id : null); + _stickers[model.Id] = sticker; + return sticker; + } + + internal SocketCustomSticker AddOrUpdateSticker(StickerModel model) + { + if (_stickers.TryGetValue(model.Id, out SocketCustomSticker sticker)) + _stickers[model.Id].Update(model); + else + sticker = AddSticker(model); + + return sticker; + } + + internal SocketCustomSticker RemoveSticker(ulong id) + { + if (_stickers.TryRemove(id, out SocketCustomSticker sticker)) + return sticker; + return null; + } + #endregion + + #region Users /// public Task AddGuildUserAsync(ulong id, string accessToken, Action func = null, RequestOptions options = null) => GuildHelper.AddGuildUserAsync(this, Discord, id, accessToken, func, options); @@ -731,13 +1082,13 @@ namespace Discord.WebSocket /// /// This method retrieves a user found within this guild. /// - /// This may return null in the WebSocket implementation due to incomplete user collection in + /// This may return in the WebSocket implementation due to incomplete user collection in /// large guilds. /// /// /// The snowflake identifier of the user. /// - /// A guild user associated with the specified ; null if none is found. + /// A guild user associated with the specified ; if none is found. /// public SocketGuildUser GetUser(ulong id) { @@ -746,8 +1097,8 @@ namespace Discord.WebSocket return null; } /// - public Task PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null) - => GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options); + public Task PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null, IEnumerable includeRoleIds = null) + => GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options, includeRoleIds); internal SocketGuildUser AddOrUpdateUser(UserModel model) { @@ -769,16 +1120,10 @@ namespace Discord.WebSocket else { member = SocketGuildUser.Create(this, Discord.State, model); - if (member == null) - throw new InvalidOperationException("SocketGuildUser.Create failed to produce a member"); // TODO 2.2rel: delete this - if (member.GlobalUser == null) - throw new InvalidOperationException("Member was created without global user"); // TODO 2.2rel: delete this member.GlobalUser.AddRef(); _members[member.Id] = member; DownloadedMemberCount++; } - if (member == null) - throw new InvalidOperationException("AddOrUpdateUser failed to produce a user"); // TODO 2.2rel: delete this return member; } internal SocketGuildUser AddOrUpdateUser(PresenceModel model) @@ -804,21 +1149,29 @@ namespace Discord.WebSocket } return null; } - internal void PurgeGuildUserCache() - { - var members = Users; - var self = CurrentUser; - _members.Clear(); - if (self != null) - _members.TryAdd(self.Id, self); - DownloadedMemberCount = _members.Count; + /// + /// Purges this guild's user cache. + /// + public void PurgeUserCache() => PurgeUserCache(_ => true); + /// + /// Purges this guild's user cache. + /// + /// The predicate used to select which users to clear. + public void PurgeUserCache(Func predicate) + { + var membersToPurge = Users.Where(x => predicate.Invoke(x) && x?.Id != Discord.CurrentUser.Id); + var membersToKeep = Users.Where(x => !predicate.Invoke(x) || x?.Id == Discord.CurrentUser.Id); - foreach (var member in members) - { - if (member.Id != self?.Id) + foreach (var member in membersToPurge) + if(_members.TryRemove(member.Id, out _)) member.GlobalUser.RemoveRef(Discord); - } + + foreach (var member in membersToKeep) + _members.TryAdd(member.Id, member); + + _downloaderPromise = new TaskCompletionSource(); + DownloadedMemberCount = _members.Count; } /// @@ -850,7 +1203,134 @@ namespace Discord.WebSocket _downloaderPromise.TrySetResultAsync(true); } - //Audit logs + /// + /// Gets a collection of users in this guild that the name or nickname starts with the + /// provided at . + /// + /// + /// The can not be higher than . + /// + /// The partial name or nickname to search. + /// The maximum number of users to be gotten. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a collection of guild + /// users that the name or nickname starts with the provided at . + /// + public Task> SearchUsersAsync(string query, int limit = DiscordConfig.MaxUsersPerBatch, RequestOptions options = null) + => GuildHelper.SearchUsersAsync(this, Discord, query, limit, options); + #endregion + + #region Guild Events + + /// + /// Gets an event in this guild. + /// + /// The snowflake identifier for the event. + /// + /// An event that is associated with the specified ; if none is found. + /// + public SocketGuildEvent GetEvent(ulong id) + { + if (_events.TryGetValue(id, out SocketGuildEvent value)) + return value; + return null; + } + + internal SocketGuildEvent RemoveEvent(ulong id) + { + if (_events.TryRemove(id, out SocketGuildEvent value)) + return value; + return null; + } + + internal SocketGuildEvent AddOrUpdateEvent(EventModel model) + { + if (_events.TryGetValue(model.Id, out SocketGuildEvent value)) + value.Update(model); + else + { + value = SocketGuildEvent.Create(Discord, this, model); + _events[model.Id] = value; + } + return value; + } + + /// + /// Gets an event within this guild. + /// + /// The snowflake identifier for the event. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. + /// + public Task GetEventAsync(ulong id, RequestOptions options = null) + => GuildHelper.GetGuildEventAsync(Discord, id, this, options); + + /// + /// Gets all active events within this guild. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. + /// + public Task> GetEventsAsync(RequestOptions options = null) + => GuildHelper.GetGuildEventsAsync(Discord, this, options); + + /// + /// Creates an event within this guild. + /// + /// The name of the event. + /// The privacy level of the event. + /// The start time of the event. + /// The type of the event. + /// The description of the event. + /// The end time of the event. + /// + /// The channel id of the event. + /// + /// The event must have a type of or + /// in order to use this property. + /// + /// + /// A collection of speakers for the event. + /// The location of the event; links are supported + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous create operation. + /// + public Task CreateEventAsync( + string name, + DateTimeOffset startTime, + GuildScheduledEventType type, + GuildScheduledEventPrivacyLevel privacyLevel = GuildScheduledEventPrivacyLevel.Private, + string description = null, + DateTimeOffset? endTime = null, + ulong? channelId = null, + string location = null, + RequestOptions options = null) + { + // requirements taken from https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-permissions-requirements + switch (type) + { + case GuildScheduledEventType.Stage: + CurrentUser.GuildPermissions.Ensure(GuildPermission.ManageEvents | GuildPermission.ManageChannels | GuildPermission.MuteMembers | GuildPermission.MoveMembers); + break; + case GuildScheduledEventType.Voice: + CurrentUser.GuildPermissions.Ensure(GuildPermission.ManageEvents | GuildPermission.ViewChannel | GuildPermission.Connect); + break; + case GuildScheduledEventType.External: + CurrentUser.GuildPermissions.Ensure(GuildPermission.ManageEvents); + break; + } + + return GuildHelper.CreateGuildEventAsync(Discord, this, name, privacyLevel, startTime, type, description, endTime, channelId, location, options); + } + + + #endregion + + #region Audit logs /// /// Gets the specified number of audit log entries for this guild. /// @@ -865,8 +1345,9 @@ namespace Discord.WebSocket /// public IAsyncEnumerable> GetAuditLogsAsync(int limit, RequestOptions options = null, ulong? beforeId = null, ulong? userId = null, ActionType? actionType = null) => GuildHelper.GetAuditLogsAsync(this, Discord, beforeId, limit, options, userId: userId, actionType: actionType); + #endregion - //Webhooks + #region Webhooks /// /// Gets a webhook found within this guild. /// @@ -874,7 +1355,7 @@ namespace Discord.WebSocket /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the webhook with the - /// specified ; null if none is found. + /// specified ; if none is found. /// public Task GetWebhookAsync(ulong id, RequestOptions options = null) => GuildHelper.GetWebhookAsync(this, Discord, id, options); @@ -888,8 +1369,12 @@ namespace Discord.WebSocket /// public Task> GetWebhooksAsync(RequestOptions options = null) => GuildHelper.GetWebhooksAsync(this, Discord, options); + #endregion - //Emotes + #region Emotes + /// + public Task> GetEmotesAsync(RequestOptions options = null) + => GuildHelper.GetEmotesAsync(this, Discord, options); /// public Task GetEmoteAsync(ulong id, RequestOptions options = null) => GuildHelper.GetEmoteAsync(this, Discord, id, options); @@ -897,14 +1382,161 @@ namespace Discord.WebSocket public Task CreateEmoteAsync(string name, Image image, Optional> roles = default(Optional>), RequestOptions options = null) => GuildHelper.CreateEmoteAsync(this, Discord, name, image, roles, options); /// - /// is null. + /// is . public Task ModifyEmoteAsync(GuildEmote emote, Action func, RequestOptions options = null) => GuildHelper.ModifyEmoteAsync(this, Discord, emote.Id, func, options); /// public Task DeleteEmoteAsync(GuildEmote emote, RequestOptions options = null) => GuildHelper.DeleteEmoteAsync(this, Discord, emote.Id, options); - //Voice States + /// + /// Moves the user to the voice channel. + /// + /// The user to move. + /// the channel where the user gets moved to. + /// A task that represents the asynchronous operation for moving a user. + public Task MoveAsync(IGuildUser user, IVoiceChannel targetChannel) + => user.ModifyAsync(x => x.Channel = new Optional(targetChannel)); + + /// + /// Disconnects the user from its current voice channel + /// + /// The user to disconnect. + /// A task that represents the asynchronous operation for disconnecting a user. + async Task IGuild.DisconnectAsync(IGuildUser user) => await user.ModifyAsync(x => x.Channel = new Optional()); + #endregion + + #region Stickers + /// + /// Gets a specific sticker within this guild. + /// + /// The id of the sticker to get. + /// The that determines whether the object should be fetched from cache. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the sticker found with the + /// specified ; if none is found. + /// + public async ValueTask GetStickerAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null) + { + var sticker = _stickers.FirstOrDefault(x => x.Key == id); + + if (sticker.Value != null) + return sticker.Value; + + if (mode == CacheMode.CacheOnly) + return null; + + var model = await Discord.ApiClient.GetGuildStickerAsync(Id, id, options).ConfigureAwait(false); + + if (model == null) + return null; + + return AddOrUpdateSticker(model); + } + /// + /// Gets a specific sticker within this guild. + /// + /// The id of the sticker to get. + /// A sticker, if none is found then . + public SocketCustomSticker GetSticker(ulong id) + => GetStickerAsync(id, CacheMode.CacheOnly).GetAwaiter().GetResult(); + /// + /// Gets a collection of all stickers within this guild. + /// + /// The that determines whether the object should be fetched from cache. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains a read-only collection + /// of stickers found within the guild. + /// + public async ValueTask> GetStickersAsync(CacheMode mode = CacheMode.AllowDownload, + RequestOptions options = null) + { + if (Stickers.Count > 0) + return Stickers; + + if (mode == CacheMode.CacheOnly) + return ImmutableArray.Create(); + + var models = await Discord.ApiClient.ListGuildStickersAsync(Id, options).ConfigureAwait(false); + + List stickers = new(); + + foreach (var model in models) + { + stickers.Add(AddOrUpdateSticker(model)); + } + + return stickers; + } + /// + /// Creates a new sticker in this guild. + /// + /// The name of the sticker. + /// The description of the sticker. + /// The tags of the sticker. + /// The image of the new emote. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the created sticker. + /// + public async Task CreateStickerAsync(string name, string description, IEnumerable tags, Image image, + RequestOptions options = null) + { + var model = await GuildHelper.CreateStickerAsync(Discord, this, name, description, tags, image, options).ConfigureAwait(false); + + return AddOrUpdateSticker(model); + } + /// + /// Creates a new sticker in this guild + /// + /// The name of the sticker. + /// The description of the sticker. + /// The tags of the sticker. + /// The path of the file to upload. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the created sticker. + /// + public Task CreateStickerAsync(string name, string description, IEnumerable tags, string path, + RequestOptions options = null) + { + var fs = File.OpenRead(path); + return CreateStickerAsync(name, description, tags, fs, Path.GetFileName(fs.Name), options); + } + /// + /// Creates a new sticker in this guild + /// + /// The name of the sticker. + /// The description of the sticker. + /// The tags of the sticker. + /// The stream containing the file data. + /// The name of the file with the extension, ex: image.png. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous creation operation. The task result contains the created sticker. + /// + public async Task CreateStickerAsync(string name, string description, IEnumerable tags, Stream stream, + string filename, RequestOptions options = null) + { + var model = await GuildHelper.CreateStickerAsync(Discord, this, name, description, tags, stream, filename, options).ConfigureAwait(false); + + return AddOrUpdateSticker(model); + } + /// + /// Deletes a sticker within this guild. + /// + /// The sticker to delete. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous removal operation. + /// + public Task DeleteStickerAsync(SocketCustomSticker sticker, RequestOptions options = null) + => sticker.DeleteAsync(options); + #endregion + + #region Voice States internal async Task AddOrUpdateVoiceStateAsync(ClientState state, VoiceStateModel model) { var voiceChannel = state.GetChannel(model.ChannelId.Value) as SocketVoiceChannel; @@ -948,8 +1580,9 @@ namespace Discord.WebSocket } return null; } + #endregion - //Audio + #region Audio internal AudioInStream GetAudioStream(ulong userId) { return _audioClient?.GetInputStream(userId); @@ -965,11 +1598,19 @@ namespace Discord.WebSocket promise = new TaskCompletionSource(); _audioConnectPromise = promise; + _voiceStateUpdateParams = new VoiceStateUpdateParams + { + GuildId = Id, + ChannelId = channelId, + SelfDeaf = selfDeaf, + SelfMute = selfMute + }; + if (external) { #pragma warning disable IDISP001 var _ = promise.TrySetResultAsync(null); - await Discord.ApiClient.SendVoiceStateUpdateAsync(Id, channelId, selfDeaf, selfMute).ConfigureAwait(false); + await Discord.ApiClient.SendVoiceStateUpdateAsync(_voiceStateUpdateParams).ConfigureAwait(false); return null; #pragma warning restore IDISP001 } @@ -1004,7 +1645,7 @@ namespace Discord.WebSocket #pragma warning restore IDISP003 } - await Discord.ApiClient.SendVoiceStateUpdateAsync(Id, channelId, selfDeaf, selfMute).ConfigureAwait(false); + await Discord.ApiClient.SendVoiceStateUpdateAsync(_voiceStateUpdateParams).ConfigureAwait(false); } catch { @@ -1051,10 +1692,41 @@ namespace Discord.WebSocket await Discord.ApiClient.SendVoiceStateUpdateAsync(Id, null, false, false).ConfigureAwait(false); _audioClient?.Dispose(); _audioClient = null; + _voiceStateUpdateParams = null; + } + + internal async Task ModifyAudioAsync(ulong channelId, Action func, RequestOptions options) + { + await _audioLock.WaitAsync().ConfigureAwait(false); + try + { + await ModifyAudioInternalAsync(channelId, func, options).ConfigureAwait(false); + } + finally + { + _audioLock.Release(); + } } + + private async Task ModifyAudioInternalAsync(ulong channelId, Action func, RequestOptions options) + { + if (_voiceStateUpdateParams == null || _voiceStateUpdateParams.ChannelId != channelId) + throw new InvalidOperationException("Cannot modify properties of not connected audio channel"); + + var props = new AudioChannelProperties(); + func(props); + + if (props.SelfDeaf.IsSpecified) + _voiceStateUpdateParams.SelfDeaf = props.SelfDeaf.Value; + if (props.SelfMute.IsSpecified) + _voiceStateUpdateParams.SelfMute = props.SelfMute.Value; + + await Discord.ApiClient.SendVoiceStateUpdateAsync(_voiceStateUpdateParams, options).ConfigureAwait(false); + } + internal async Task FinishConnectAudio(string url, string token) { - //TODO: Mem Leak: Disconnected/Connected handlers arent cleaned up + //TODO: Mem Leak: Disconnected/Connected handlers aren't cleaned up var voiceState = GetVoiceState(Discord.CurrentUser.Id).Value; await _audioLock.WaitAsync().ConfigureAwait(false); @@ -1103,8 +1775,9 @@ namespace Discord.WebSocket public override string ToString() => Name; private string DebuggerDisplay => $"{Name} ({Id})"; internal SocketGuild Clone() => MemberwiseClone() as SocketGuild; + #endregion - //IGuild + #region IGuild /// ulong? IGuild.AFKChannelId => AFKChannelId; /// @@ -1112,16 +1785,32 @@ namespace Discord.WebSocket /// bool IGuild.Available => true; /// - ulong IGuild.DefaultChannelId => DefaultChannel?.Id ?? 0; - /// - ulong? IGuild.EmbedChannelId => EmbedChannelId; + ulong? IGuild.WidgetChannelId => WidgetChannelId; /// ulong? IGuild.SystemChannelId => SystemChannelId; /// + ulong? IGuild.RulesChannelId => RulesChannelId; + /// + ulong? IGuild.PublicUpdatesChannelId => PublicUpdatesChannelId; + /// IRole IGuild.EveryoneRole => EveryoneRole; /// IReadOnlyCollection IGuild.Roles => Roles; - + /// + int? IGuild.ApproximateMemberCount => null; + /// + int? IGuild.ApproximatePresenceCount => null; + /// + IReadOnlyCollection IGuild.Stickers => Stickers; + /// + async Task IGuild.CreateEventAsync(string name, DateTimeOffset startTime, GuildScheduledEventType type, GuildScheduledEventPrivacyLevel privacyLevel, string description, DateTimeOffset? endTime, ulong? channelId, string location, RequestOptions options) + => await CreateEventAsync(name, startTime, type, privacyLevel, description, endTime, channelId, location, options).ConfigureAwait(false); + /// + async Task IGuild.GetEventAsync(ulong id, RequestOptions options) + => await GetEventAsync(id, options).ConfigureAwait(false); + /// + async Task> IGuild.GetEventsAsync(RequestOptions options) + => await GetEventsAsync(options).ConfigureAwait(false); /// async Task> IGuild.GetBansAsync(RequestOptions options) => await GetBansAsync(options).ConfigureAwait(false); @@ -1145,33 +1834,54 @@ namespace Discord.WebSocket Task IGuild.GetTextChannelAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetTextChannel(id)); /// + Task IGuild.GetThreadChannelAsync(ulong id, CacheMode mode, RequestOptions options) + => Task.FromResult(GetThreadChannel(id)); + /// + Task> IGuild.GetThreadChannelsAsync(CacheMode mode, RequestOptions options) + => Task.FromResult>(ThreadChannels); + /// Task> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(VoiceChannels); /// - Task> IGuild.GetCategoriesAsync(CacheMode mode , RequestOptions options) + Task> IGuild.GetCategoriesAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(CategoryChannels); /// Task IGuild.GetVoiceChannelAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetVoiceChannel(id)); /// + Task IGuild.GetStageChannelAsync(ulong id, CacheMode mode, RequestOptions options) + => Task.FromResult(GetStageChannel(id)); + /// + Task> IGuild.GetStageChannelsAsync(CacheMode mode, RequestOptions options) + => Task.FromResult>(StageChannels); + /// Task IGuild.GetAFKChannelAsync(CacheMode mode, RequestOptions options) => Task.FromResult(AFKChannel); /// Task IGuild.GetDefaultChannelAsync(CacheMode mode, RequestOptions options) => Task.FromResult(DefaultChannel); /// - Task IGuild.GetEmbedChannelAsync(CacheMode mode, RequestOptions options) - => Task.FromResult(EmbedChannel); + Task IGuild.GetWidgetChannelAsync(CacheMode mode, RequestOptions options) + => Task.FromResult(WidgetChannel); /// Task IGuild.GetSystemChannelAsync(CacheMode mode, RequestOptions options) => Task.FromResult(SystemChannel); /// + Task IGuild.GetRulesChannelAsync(CacheMode mode, RequestOptions options) + => Task.FromResult(RulesChannel); + /// + Task IGuild.GetPublicUpdatesChannelAsync(CacheMode mode, RequestOptions options) + => Task.FromResult(PublicUpdatesChannel); + /// async Task IGuild.CreateTextChannelAsync(string name, Action func, RequestOptions options) => await CreateTextChannelAsync(name, func, options).ConfigureAwait(false); /// async Task IGuild.CreateVoiceChannelAsync(string name, Action func, RequestOptions options) => await CreateVoiceChannelAsync(name, func, options).ConfigureAwait(false); /// + async Task IGuild.CreateStageChannelAsync(string name, Action func, RequestOptions options) + => await CreateStageChannelAsync(name, func, options).ConfigureAwait(false); + /// async Task IGuild.CreateCategoryAsync(string name, Action func, RequestOptions options) => await CreateCategoryChannelAsync(name, func, options).ConfigureAwait(false); @@ -1224,6 +1934,14 @@ namespace Discord.WebSocket /// Task IGuild.GetOwnerAsync(CacheMode mode, RequestOptions options) => Task.FromResult(Owner); + /// + async Task> IGuild.SearchUsersAsync(string query, int limit, CacheMode mode, RequestOptions options) + { + if (mode == CacheMode.AllowDownload) + return await SearchUsersAsync(query, limit, options).ConfigureAwait(false); + else + return ImmutableArray.Create(); + } /// async Task> IGuild.GetAuditLogsAsync(int limit, CacheMode cacheMode, RequestOptions options, @@ -1241,6 +1959,37 @@ namespace Discord.WebSocket /// async Task> IGuild.GetWebhooksAsync(RequestOptions options) => await GetWebhooksAsync(options).ConfigureAwait(false); + /// + async Task> IGuild.GetApplicationCommandsAsync (RequestOptions options) + => await GetApplicationCommandsAsync(options).ConfigureAwait(false); + /// + async Task IGuild.CreateStickerAsync(string name, string description, IEnumerable tags, Image image, RequestOptions options) + => await CreateStickerAsync(name, description, tags, image, options); + /// + async Task IGuild.CreateStickerAsync(string name, string description, IEnumerable tags, Stream stream, string filename, RequestOptions options) + => await CreateStickerAsync(name, description, tags, stream, filename, options); + /// + async Task IGuild.CreateStickerAsync(string name, string description, IEnumerable tags, string path, RequestOptions options) + => await CreateStickerAsync(name, description, tags, path, options); + /// + async Task IGuild.GetStickerAsync(ulong id, CacheMode mode, RequestOptions options) + => await GetStickerAsync(id, mode, options); + /// + async Task> IGuild.GetStickersAsync(CacheMode mode, RequestOptions options) + => await GetStickersAsync(mode, options); + /// + Task IGuild.DeleteStickerAsync(ICustomSticker sticker, RequestOptions options) + => DeleteStickerAsync(_stickers[sticker.Id], options); + /// + async Task IGuild.GetApplicationCommandAsync(ulong id, CacheMode mode, RequestOptions options) + => await GetApplicationCommandAsync(id, mode, options); + /// + async Task IGuild.CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options) + => await CreateApplicationCommandAsync(properties, options); + /// + async Task> IGuild.BulkOverwriteApplicationCommandsAsync(ApplicationCommandProperties[] properties, + RequestOptions options) + => await BulkOverwriteApplicationCommandAsync(properties, options); void IDisposable.Dispose() { @@ -1248,5 +1997,6 @@ namespace Discord.WebSocket _audioLock?.Dispose(); _audioClient?.Dispose(); } + #endregion } } diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuildEvent.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuildEvent.cs new file mode 100644 index 000000000..df619e4ca --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuildEvent.cs @@ -0,0 +1,218 @@ +using Discord.Rest; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Model = Discord.API.GuildScheduledEvent; + +namespace Discord.WebSocket +{ + /// + /// Represents a WebSocket-based guild event. + /// + public class SocketGuildEvent : SocketEntity, IGuildScheduledEvent + { + /// + /// Gets the guild of the event. + /// + public SocketGuild Guild { get; private set; } + + /// + /// Gets the channel of the event. + /// + public SocketGuildChannel Channel { get; private set; } + + /// + /// Gets the user who created the event. + /// + public SocketGuildUser Creator { get; private set; } + + /// + public string Name { get; private set; } + + /// + public string Description { get; private set; } + + /// + public DateTimeOffset StartTime { get; private set; } + + /// + public DateTimeOffset? EndTime { get; private set; } + + /// + public GuildScheduledEventPrivacyLevel PrivacyLevel { get; private set; } + + /// + public GuildScheduledEventStatus Status { get; private set; } + + /// + public GuildScheduledEventType Type { get; private set; } + + /// + public ulong? EntityId { get; private set; } + + /// + public string Location { get; private set; } + + /// + public int? UserCount { get; private set; } + + internal SocketGuildEvent(DiscordSocketClient client, SocketGuild guild, ulong id) + : base(client, id) + { + Guild = guild; + } + + internal static SocketGuildEvent Create(DiscordSocketClient client, SocketGuild guild, Model model) + { + var entity = new SocketGuildEvent(client, guild, model.Id); + entity.Update(model); + return entity; + } + + internal void Update(Model model) + { + if (model.ChannelId.IsSpecified && model.ChannelId.Value != null) + { + Channel = Guild.GetChannel(model.ChannelId.Value.Value); + } + + if (model.CreatorId.IsSpecified) + { + var guildUser = Guild.GetUser(model.CreatorId.Value); + + if(guildUser != null) + { + if(model.Creator.IsSpecified) + guildUser.Update(Discord.State, model.Creator.Value); + + Creator = guildUser; + } + else if (guildUser == null && model.Creator.IsSpecified) + { + guildUser = SocketGuildUser.Create(Guild, Discord.State, model.Creator.Value); + Creator = guildUser; + } + } + + Name = model.Name; + Description = model.Description.GetValueOrDefault(); + + EntityId = model.EntityId; + Location = model.EntityMetadata?.Location.GetValueOrDefault(); + Type = model.EntityType; + + PrivacyLevel = model.PrivacyLevel; + EndTime = model.ScheduledEndTime; + StartTime = model.ScheduledStartTime; + Status = model.Status; + UserCount = model.UserCount.ToNullable(); + } + + /// + public Task DeleteAsync(RequestOptions options = null) + => GuildHelper.DeleteEventAsync(Discord, this, options); + + /// + public Task StartAsync(RequestOptions options = null) + => ModifyAsync(x => x.Status = GuildScheduledEventStatus.Active); + + /// + public Task EndAsync(RequestOptions options = null) + => ModifyAsync(x => x.Status = Status == GuildScheduledEventStatus.Scheduled + ? GuildScheduledEventStatus.Cancelled + : GuildScheduledEventStatus.Completed); + + /// + public async Task ModifyAsync(Action func, RequestOptions options = null) + { + var model = await GuildHelper.ModifyGuildEventAsync(Discord, func, this, options).ConfigureAwait(false); + Update(model); + } + + /// + /// Gets a collection of users that are interested in this event. + /// + /// The amount of users to fetch. + /// The options to be used when sending the request. + /// + /// A read-only collection of users. + /// + public Task> GetUsersAsync(int limit = 100, RequestOptions options = null) + => GuildHelper.GetEventUsersAsync(Discord, this, limit, options); + + /// + /// Gets a collection of N users interested in the event. + /// + /// + /// + /// The returned collection is an asynchronous enumerable object; one must call + /// to access the individual messages as a + /// collection. + /// + /// This method will attempt to fetch all users that are interested in the event. + /// The library will attempt to split up the requests according to and . + /// In other words, if there are 300 users, and the constant + /// is 100, the request will be split into 3 individual requests; thus returning 3 individual asynchronous + /// responses, hence the need of flattening. + /// + /// The options to be used when sending the request. + /// + /// Paged collection of users. + /// + public IAsyncEnumerable> GetUsersAsync(RequestOptions options = null) + => GuildHelper.GetEventUsersAsync(Discord, this, null, null, options); + + /// + /// Gets a collection of N users interested in the event. + /// + /// + /// + /// The returned collection is an asynchronous enumerable object; one must call + /// to access the individual users as a + /// collection. + /// + /// + /// Do not fetch too many users at once! This may cause unwanted preemptive rate limit or even actual + /// rate limit, causing your bot to freeze! + /// + /// This method will attempt to fetch the number of users specified under around + /// the user depending on the . The library will + /// attempt to split up the requests according to your and + /// . In other words, should the user request 500 users, + /// and the constant is 100, the request will + /// be split into 5 individual requests; thus returning 5 individual asynchronous responses, hence the need + /// of flattening. + /// + /// The ID of the starting user to get the users from. + /// The direction of the users to be gotten from. + /// The numbers of users to be gotten from. + /// The options to be used when sending the request. + /// + /// Paged collection of users. + /// + public IAsyncEnumerable> GetUsersAsync(ulong fromUserId, Direction dir, int limit = DiscordConfig.MaxGuildEventUsersPerBatch, RequestOptions options = null) + => GuildHelper.GetEventUsersAsync(Discord, this, fromUserId, dir, limit, options); + + internal SocketGuildEvent Clone() => MemberwiseClone() as SocketGuildEvent; + + #region IGuildScheduledEvent + + /// + IAsyncEnumerable> IGuildScheduledEvent.GetUsersAsync(RequestOptions options) + => GetUsersAsync(options); + /// + IAsyncEnumerable> IGuildScheduledEvent.GetUsersAsync(ulong fromUserId, Direction dir, int limit, RequestOptions options) + => GetUsersAsync(fromUserId, dir, limit, options); + /// + IGuild IGuildScheduledEvent.Guild => Guild; + /// + IUser IGuildScheduledEvent.Creator => Creator; + /// + ulong? IGuildScheduledEvent.ChannelId => Channel?.Id; + + #endregion + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommand.cs new file mode 100644 index 000000000..fee33f8cb --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommand.cs @@ -0,0 +1,49 @@ +using DataModel = Discord.API.ApplicationCommandInteractionData; +using Model = Discord.API.Interaction; + +namespace Discord.WebSocket +{ + /// + /// Represents a Websocket-based slash command received over the gateway. + /// + public class SocketMessageCommand : SocketCommandBase, IMessageCommandInteraction, IDiscordInteraction + { + /// + /// The data associated with this interaction. + /// + public new SocketMessageCommandData Data { get; } + + internal SocketMessageCommand(DiscordSocketClient client, Model model, ISocketMessageChannel channel) + : base(client, model, channel) + { + var dataModel = model.Data.IsSpecified + ? (DataModel)model.Data.Value + : null; + + ulong? guildId = null; + if (Channel is SocketGuildChannel guildChannel) + guildId = guildChannel.Guild.Id; + + Data = SocketMessageCommandData.Create(client, dataModel, model.Id, guildId); + } + + internal new static SocketInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel) + { + var entity = new SocketMessageCommand(client, model, channel); + entity.Update(model); + return entity; + } + + //IMessageCommandInteraction + /// + IMessageCommandInteractionData IMessageCommandInteraction.Data => Data; + + //IDiscordInteraction + /// + IDiscordInteractionData IDiscordInteraction.Data => Data; + + //IApplicationCommandInteraction + /// + IApplicationCommandInteractionData IApplicationCommandInteraction.Data => Data; + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommandData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommandData.cs new file mode 100644 index 000000000..71a30b44a --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/MessageCommands/SocketMessageCommandData.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; +using System.Linq; +using Model = Discord.API.ApplicationCommandInteractionData; + +namespace Discord.WebSocket +{ + /// + /// Represents the data tied with the interaction. + /// + public class SocketMessageCommandData : SocketCommandBaseData, IMessageCommandInteractionData, IDiscordInteractionData + { + /// + /// Gets the message associated with this message command. + /// + public SocketMessage Message + => ResolvableData?.Messages.FirstOrDefault().Value; + + /// + /// + /// Note Not implemented for + /// + public override IReadOnlyCollection Options + => throw new System.NotImplementedException(); + + internal SocketMessageCommandData(DiscordSocketClient client, Model model, ulong? guildId) + : base(client, model, guildId) { } + + internal new static SocketMessageCommandData Create(DiscordSocketClient client, Model model, ulong id, ulong? guildId) + { + var entity = new SocketMessageCommandData(client, model, guildId); + entity.Update(model); + return entity; + } + + //IMessageCommandInteractionData + /// + IMessage IMessageCommandInteractionData.Message => Message; + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommand.cs new file mode 100644 index 000000000..75e8ebff9 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommand.cs @@ -0,0 +1,49 @@ +using DataModel = Discord.API.ApplicationCommandInteractionData; +using Model = Discord.API.Interaction; + +namespace Discord.WebSocket +{ + /// + /// Represents a Websocket-based slash command received over the gateway. + /// + public class SocketUserCommand : SocketCommandBase, IUserCommandInteraction, IDiscordInteraction + { + /// + /// The data associated with this interaction. + /// + public new SocketUserCommandData Data { get; } + + internal SocketUserCommand(DiscordSocketClient client, Model model, ISocketMessageChannel channel) + : base(client, model, channel) + { + var dataModel = model.Data.IsSpecified + ? (DataModel)model.Data.Value + : null; + + ulong? guildId = null; + if (Channel is SocketGuildChannel guildChannel) + guildId = guildChannel.Guild.Id; + + Data = SocketUserCommandData.Create(client, dataModel, model.Id, guildId); + } + + internal new static SocketInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel) + { + var entity = new SocketUserCommand(client, model, channel); + entity.Update(model); + return entity; + } + + //IUserCommandInteraction + /// + IUserCommandInteractionData IUserCommandInteraction.Data => Data; + + //IDiscordInteraction + /// + IDiscordInteractionData IDiscordInteraction.Data => Data; + + //IApplicationCommandInteraction + /// + IApplicationCommandInteractionData IApplicationCommandInteraction.Data => Data; + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommandData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommandData.cs new file mode 100644 index 000000000..eaebbcb06 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/ContextMenuCommands/UserCommands/SocketUserCommandData.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; +using System.Linq; +using Model = Discord.API.ApplicationCommandInteractionData; + +namespace Discord.WebSocket +{ + /// + /// Represents the data tied with the interaction. + /// + public class SocketUserCommandData : SocketCommandBaseData, IUserCommandInteractionData, IDiscordInteractionData + { + /// + /// Gets the user who this command targets. + /// + public SocketUser Member + => (SocketUser)ResolvableData.GuildMembers.Values.FirstOrDefault() ?? ResolvableData.Users.Values.FirstOrDefault(); + + /// + /// + /// Note Not implemented for + /// + public override IReadOnlyCollection Options + => throw new System.NotImplementedException(); + + internal SocketUserCommandData(DiscordSocketClient client, Model model, ulong? guildId) + : base(client, model, guildId) { } + + internal new static SocketUserCommandData Create(DiscordSocketClient client, Model model, ulong id, ulong? guildId) + { + var entity = new SocketUserCommandData(client, model, guildId); + entity.Update(model); + return entity; + } + + //IUserCommandInteractionData + /// + IUser IUserCommandInteractionData.User => Member; + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs b/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs new file mode 100644 index 000000000..862c792a8 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs @@ -0,0 +1,452 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Model = Discord.API.Interaction; +using DataModel = Discord.API.MessageComponentInteractionData; +using Discord.Rest; +using System.Collections.Generic; +using Discord.Net.Rest; +using System.IO; + +namespace Discord.WebSocket +{ + /// + /// Represents a Websocket-based interaction type for Message Components. + /// + public class SocketMessageComponent : SocketInteraction, IComponentInteraction, IDiscordInteraction + { + /// + /// Gets the data received with this interaction, contains the button that was clicked. + /// + public new SocketMessageComponentData Data { get; } + + /// + /// Gets the message that contained the trigger for this interaction. + /// + public SocketUserMessage Message { get; private set; } + + private object _lock = new object(); + public override bool HasResponded { get; internal set; } = false; + + internal SocketMessageComponent(DiscordSocketClient client, Model model, ISocketMessageChannel channel) + : base(client, model.Id, channel) + { + var dataModel = model.Data.IsSpecified + ? (DataModel)model.Data.Value + : null; + + Data = new SocketMessageComponentData(dataModel); + } + + internal new static SocketMessageComponent Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel) + { + var entity = new SocketMessageComponent(client, model, channel); + entity.Update(model); + return entity; + } + internal override void Update(Model model) + { + base.Update(model); + + if (model.Message.IsSpecified) + { + if (Message == null) + { + SocketUser author = null; + if (Channel is SocketGuildChannel channel) + { + if (model.Message.Value.WebhookId.IsSpecified) + author = SocketWebhookUser.Create(channel.Guild, Discord.State, model.Message.Value.Author.Value, model.Message.Value.WebhookId.Value); + else if (model.Message.Value.Author.IsSpecified) + author = channel.Guild.GetUser(model.Message.Value.Author.Value.Id); + } + else if (model.Message.Value.Author.IsSpecified) + author = (Channel as SocketChannel).GetUser(model.Message.Value.Author.Value.Id); + + Message = SocketUserMessage.Create(Discord, Discord.State, author, Channel, model.Message.Value); + } + else + { + Message.Update(Discord.State, model.Message.Value); + } + } + } + public override async Task RespondWithFilesAsync( + IEnumerable attachments, + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + if (!InteractionHelper.CanSendResponse(this)) + throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!"); + + embeds ??= Array.Empty(); + if (embed != null) + embeds = new[] { embed }.Concat(embeds).ToArray(); + + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed."); + + // check that user flag and user Id list are exclusive, same with role flag and role Id list + if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue) + { + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) && + allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) + { + throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions)); + } + + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) && + allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) + { + throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions)); + } + } + + var response = new API.Rest.UploadInteractionFileParams(attachments?.ToArray()) + { + Type = InteractionResponseType.ChannelMessageWithSource, + Content = text ?? Optional.Unspecified, + AllowedMentions = allowedMentions != null ? allowedMentions?.ToModel() : Optional.Unspecified, + Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional.Unspecified, + IsTTS = isTTS, + MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified, + Flags = ephemeral ? MessageFlags.Ephemeral : Optional.Unspecified + }; + + lock (_lock) + { + if (HasResponded) + { + throw new InvalidOperationException("Cannot respond, update, or defer the same interaction twice"); + } + } + + await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false); + HasResponded = true; + } + + /// + public override async Task RespondAsync( + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + if (!InteractionHelper.CanSendResponse(this)) + throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!"); + + embeds ??= Array.Empty(); + if (embed != null) + embeds = new[] { embed }.Concat(embeds).ToArray(); + + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed."); + + // check that user flag and user Id list are exclusive, same with role flag and role Id list + if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue) + { + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) && + allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) + { + throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions)); + } + + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) && + allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) + { + throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions)); + } + } + + var response = new API.InteractionResponse + { + Type = InteractionResponseType.ChannelMessageWithSource, + Data = new API.InteractionCallbackData + { + Content = text ?? Optional.Unspecified, + AllowedMentions = allowedMentions?.ToModel(), + Embeds = embeds.Select(x => x.ToModel()).ToArray(), + TTS = isTTS, + Flags = ephemeral ? MessageFlags.Ephemeral : Optional.Unspecified, + Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified + } + }; + + lock (_lock) + { + if (HasResponded) + { + throw new InvalidOperationException("Cannot respond, update, or defer twice to the same interaction"); + } + } + + await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false); + HasResponded = true; + } + + /// + /// Updates the message which this component resides in with the type + /// + /// A delegate containing the properties to modify the message with. + /// The request options for this request. + /// A task that represents the asynchronous operation of updating the message. + public async Task UpdateAsync(Action func, RequestOptions options = null) + { + var args = new MessageProperties(); + func(args); + + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + if (!InteractionHelper.CanSendResponse(this)) + throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!"); + + if (args.AllowedMentions.IsSpecified) + { + var allowedMentions = args.AllowedMentions.Value; + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions), "A max of 100 user Ids are allowed."); + } + + var embed = args.Embed; + var embeds = args.Embeds; + + bool hasText = args.Content.IsSpecified ? !string.IsNullOrEmpty(args.Content.Value) : !string.IsNullOrEmpty(Message.Content); + bool hasEmbeds = embed.IsSpecified && embed.Value != null || embeds.IsSpecified && embeds.Value?.Length > 0 || Message.Embeds.Any(); + + if (!hasText && !hasEmbeds) + Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content)); + + var apiEmbeds = embed.IsSpecified || embeds.IsSpecified ? new List() : null; + + if (embed.IsSpecified && embed.Value != null) + { + apiEmbeds.Add(embed.Value.ToModel()); + } + + if (embeds.IsSpecified && embeds.Value != null) + { + apiEmbeds.AddRange(embeds.Value.Select(x => x.ToModel())); + } + + Preconditions.AtMost(apiEmbeds?.Count ?? 0, 10, nameof(args.Embeds), "A max of 10 embeds are allowed."); + + // check that user flag and user Id list are exclusive, same with role flag and role Id list + if (args.AllowedMentions.IsSpecified && args.AllowedMentions.Value != null && args.AllowedMentions.Value.AllowedTypes.HasValue) + { + var allowedMentions = args.AllowedMentions.Value; + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) + && allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) + { + throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(args.AllowedMentions)); + } + + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) + && allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) + { + throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(args.AllowedMentions)); + } + } + + var response = new API.InteractionResponse + { + Type = InteractionResponseType.UpdateMessage, + Data = new API.InteractionCallbackData + { + Content = args.Content, + AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional.Unspecified, + Embeds = apiEmbeds?.ToArray() ?? Optional.Unspecified, + Components = args.Components.IsSpecified + ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty() + : Optional.Unspecified, + Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional.Unspecified : Optional.Unspecified + } + }; + + lock (_lock) + { + if (HasResponded) + { + throw new InvalidOperationException("Cannot respond, update, or defer twice to the same interaction"); + } + } + + await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false); + HasResponded = true; + } + + /// + public override async Task FollowupAsync( + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + embeds ??= Array.Empty(); + if (embed != null) + embeds = new[] { embed }.Concat(embeds).ToArray(); + + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed."); + + var args = new API.Rest.CreateWebhookMessageParams + { + Content = text, + AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, + IsTTS = isTTS, + Embeds = embeds.Select(x => x.ToModel()).ToArray(), + Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified + }; + + if (ephemeral) + args.Flags = MessageFlags.Ephemeral; + + return await InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options); + } + + /// + public override async Task FollowupWithFilesAsync( + IEnumerable attachments, + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + embeds ??= Array.Empty(); + if (embed != null) + embeds = new[] { embed }.Concat(embeds).ToArray(); + + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed."); + + foreach (var attachment in attachments) + { + Preconditions.NotNullOrEmpty(attachment.FileName, nameof(attachment.FileName), "File Name must not be empty or null"); + } + + // check that user flag and user Id list are exclusive, same with role flag and role Id list + if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue) + { + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) && + allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) + { + throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions)); + } + + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) && + allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) + { + throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions)); + } + } + + var flags = MessageFlags.None; + + if (ephemeral) + flags |= MessageFlags.Ephemeral; + + var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray()) { Flags = flags, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified }; + return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false); + } + + /// + /// Defers an interaction and responds with type 5 () + /// + /// to send this message ephemerally, otherwise . + /// The request options for this request. + /// + /// A task that represents the asynchronous operation of acknowledging the interaction. + /// + public async Task DeferLoadingAsync(bool ephemeral = false, RequestOptions options = null) + { + if (!InteractionHelper.CanSendResponse(this)) + throw new TimeoutException($"Cannot defer an interaction after {InteractionHelper.ResponseTimeLimit} seconds of no response/acknowledgement"); + + var response = new API.InteractionResponse + { + Type = InteractionResponseType.DeferredChannelMessageWithSource, + Data = ephemeral ? new API.InteractionCallbackData { Flags = MessageFlags.Ephemeral } : Optional.Unspecified + }; + + lock (_lock) + { + if (HasResponded) + { + throw new InvalidOperationException("Cannot respond or defer twice to the same interaction"); + } + } + + await Discord.Rest.ApiClient.CreateInteractionResponseAsync(response, Id, Token, options).ConfigureAwait(false); + HasResponded = true; + } + + /// + public override async Task DeferAsync(bool ephemeral = false, RequestOptions options = null) + { + if (!InteractionHelper.CanSendResponse(this)) + throw new TimeoutException($"Cannot defer an interaction after {InteractionHelper.ResponseTimeLimit} seconds of no response/acknowledgement"); + + var response = new API.InteractionResponse + { + Type = InteractionResponseType.DeferredUpdateMessage, + Data = ephemeral ? new API.InteractionCallbackData { Flags = MessageFlags.Ephemeral } : Optional.Unspecified + }; + + lock (_lock) + { + if (HasResponded) + { + throw new InvalidOperationException("Cannot respond or defer twice to the same interaction"); + } + } + + await Discord.Rest.ApiClient.CreateInteractionResponseAsync(response, Id, Token, options).ConfigureAwait(false); + HasResponded = true; + } + + //IComponentInteraction + /// + IComponentInteractionData IComponentInteraction.Data => Data; + + /// + IUserMessage IComponentInteraction.Message => Message; + + //IDiscordInteraction + /// + IDiscordInteractionData IDiscordInteraction.Data => Data; + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponentData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponentData.cs new file mode 100644 index 000000000..71e1d0395 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponentData.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; +using Model = Discord.API.MessageComponentInteractionData; + +namespace Discord.WebSocket +{ + /// + /// Represents the data sent with a . + /// + public class SocketMessageComponentData : IComponentInteractionData + { + /// + /// Gets the components Custom Id that was clicked. + /// + public string CustomId { get; } + + /// + /// Gets the type of the component clicked. + /// + public ComponentType Type { get; } + + /// + /// Gets the value(s) of a interaction response. + /// + public IReadOnlyCollection Values { get; } + + internal SocketMessageComponentData(Model model) + { + CustomId = model.CustomId; + Type = model.ComponentType; + Values = model.Values.GetValueOrDefault(); + } + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteraction.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteraction.cs new file mode 100644 index 000000000..6058bdafd --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteraction.cs @@ -0,0 +1,111 @@ +using Discord.Rest; +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using Model = Discord.API.Interaction; +using DataModel = Discord.API.AutocompleteInteractionData; + +namespace Discord.WebSocket +{ + /// + /// Represents a received over the gateway. + /// + public class SocketAutocompleteInteraction : SocketInteraction, IAutocompleteInteraction, IDiscordInteraction + { + /// + /// The autocomplete data of this interaction. + /// + public new SocketAutocompleteInteractionData Data { get; } + + public override bool HasResponded { get; internal set; } + private object _lock = new object(); + + internal SocketAutocompleteInteraction(DiscordSocketClient client, Model model, ISocketMessageChannel channel) + : base(client, model.Id, channel) + { + var dataModel = model.Data.IsSpecified + ? (DataModel)model.Data.Value + : null; + + if (dataModel != null) + Data = new SocketAutocompleteInteractionData(dataModel); + } + + internal new static SocketAutocompleteInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel) + { + var entity = new SocketAutocompleteInteraction(client, model, channel); + entity.Update(model); + return entity; + } + + /// + /// Responds to this interaction with a set of choices. + /// + /// + /// The set of choices for the user to pick from. + /// + /// A max of 25 choices are allowed. Passing for this argument will show the executing user that + /// there is no choices for their autocompleted input. + /// + /// + /// The request options for this response. + /// + /// A task that represents the asynchronous operation of responding to this interaction. + /// + public async Task RespondAsync(IEnumerable result, RequestOptions options = null) + { + if (!InteractionHelper.CanSendResponse(this)) + throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!"); + + lock (_lock) + { + if (HasResponded) + { + throw new InvalidOperationException("Cannot respond twice to the same interaction"); + } + } + + await InteractionHelper.SendAutocompleteResultAsync(Discord, result, Id, Token, options).ConfigureAwait(false); + lock (_lock) + { + HasResponded = true; + } + } + + /// + /// Responds to this interaction with a set of choices. + /// + /// The request options for this response. + /// + /// The set of choices for the user to pick from. + /// + /// A max of 25 choices are allowed. Passing for this argument will show the executing user that + /// there is no choices for their autocompleted input. + /// + /// + /// + /// A task that represents the asynchronous operation of responding to this interaction. + /// + public Task RespondAsync(RequestOptions options = null, params AutocompleteResult[] result) + => RespondAsync(result, options); + public override Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + => throw new NotSupportedException("Autocomplete interactions don't support this method!"); + public override Task FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + => throw new NotSupportedException("Autocomplete interactions don't support this method!"); + public override Task FollowupWithFilesAsync(IEnumerable attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + => throw new NotSupportedException("Autocomplete interactions don't support this method!"); + public override Task DeferAsync(bool ephemeral = false, RequestOptions options = null) + => throw new NotSupportedException("Autocomplete interactions don't support this method!"); + public override Task RespondWithFilesAsync(IEnumerable attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + => throw new NotSupportedException("Autocomplete interactions don't support this method!"); + + //IAutocompleteInteraction + /// + IAutocompleteInteractionData IAutocompleteInteraction.Data => Data; + + //IDiscordInteraction + /// + IDiscordInteractionData IDiscordInteraction.Data => Data; + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteractionData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteractionData.cs new file mode 100644 index 000000000..1d9803c02 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketAutocompleteInteractionData.cs @@ -0,0 +1,73 @@ +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using DataModel = Discord.API.AutocompleteInteractionData; + +namespace Discord.WebSocket +{ + /// + /// Represents data for a slash commands autocomplete interaction. + /// + public class SocketAutocompleteInteractionData : IAutocompleteInteractionData, IDiscordInteractionData + { + /// + /// Gets the name of the invoked command. + /// + public string CommandName { get; } + + /// + /// Gets the id of the invoked command. + /// + public ulong CommandId { get; } + + /// + /// Gets the type of the invoked command. + /// + public ApplicationCommandType Type { get; } + + /// + /// Gets the version of the invoked command. + /// + public ulong Version { get; } + + /// + /// Gets the current autocomplete option that is actively being filled out. + /// + public AutocompleteOption Current { get; } + + /// + /// Gets a collection of all the other options the executing users has filled out. + /// + public IReadOnlyCollection Options { get; } + + internal SocketAutocompleteInteractionData(DataModel model) + { + var options = model.Options.SelectMany(GetOptions); + + Current = options.FirstOrDefault(x => x.Focused); + Options = options.ToImmutableArray(); + + if (Options.Count == 1 && Current == null) + Current = Options.FirstOrDefault(); + + CommandName = model.Name; + CommandId = model.Id; + Type = model.Type; + Version = model.Version; + } + + private List GetOptions(API.AutocompleteInteractionDataOption model) + { + var options = new List(); + + options.Add(new AutocompleteOption(model.Type, model.Name, model.Value.GetValueOrDefault(null), model.Focused.GetValueOrDefault(false))); + + if (model.Options.IsSpecified) + { + options.AddRange(model.Options.Value.SelectMany(GetOptions)); + } + + return options; + } + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketSlashCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketSlashCommand.cs new file mode 100644 index 000000000..5934a3864 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketSlashCommand.cs @@ -0,0 +1,49 @@ +using DataModel = Discord.API.ApplicationCommandInteractionData; +using Model = Discord.API.Interaction; + +namespace Discord.WebSocket +{ + /// + /// Represents a Websocket-based slash command received over the gateway. + /// + public class SocketSlashCommand : SocketCommandBase, ISlashCommandInteraction, IDiscordInteraction + { + /// + /// The data associated with this interaction. + /// + public new SocketSlashCommandData Data { get; } + + internal SocketSlashCommand(DiscordSocketClient client, Model model, ISocketMessageChannel channel) + : base(client, model, channel) + { + var dataModel = model.Data.IsSpecified + ? (DataModel)model.Data.Value + : null; + + ulong? guildId = null; + if (Channel is SocketGuildChannel guildChannel) + guildId = guildChannel.Guild.Id; + + Data = SocketSlashCommandData.Create(client, dataModel, guildId); + } + + internal new static SocketInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel) + { + var entity = new SocketSlashCommand(client, model, channel); + entity.Update(model); + return entity; + } + + //ISlashCommandInteraction + /// + IApplicationCommandInteractionData ISlashCommandInteraction.Data => Data; + + //IDiscordInteraction + /// + IDiscordInteractionData IDiscordInteraction.Data => Data; + + //IApplicationCommandInteraction + /// + IApplicationCommandInteractionData IApplicationCommandInteraction.Data => Data; + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketSlashCommandData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketSlashCommandData.cs new file mode 100644 index 000000000..c385ce825 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketSlashCommandData.cs @@ -0,0 +1,30 @@ +using System.Collections.Immutable; +using System.Linq; +using Model = Discord.API.ApplicationCommandInteractionData; + +namespace Discord.WebSocket +{ + /// + /// Represents the data tied with the interaction. + /// + public class SocketSlashCommandData : SocketCommandBaseData, IDiscordInteractionData + { + internal SocketSlashCommandData(DiscordSocketClient client, Model model, ulong? guildId) + : base(client, model, guildId) { } + + internal static SocketSlashCommandData Create(DiscordSocketClient client, Model model, ulong? guildId) + { + var entity = new SocketSlashCommandData(client, model, guildId); + entity.Update(model); + return entity; + } + internal override void Update(Model model) + { + base.Update(model); + + Options = model.Options.IsSpecified + ? model.Options.Value.Select(x => new SocketSlashCommandDataOption(this, x)).ToImmutableArray() + : ImmutableArray.Create(); + } + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketSlashCommandDataOption.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketSlashCommandDataOption.cs new file mode 100644 index 000000000..265eda75b --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SlashCommands/SocketSlashCommandDataOption.cs @@ -0,0 +1,135 @@ +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using Model = Discord.API.ApplicationCommandInteractionDataOption; + +namespace Discord.WebSocket +{ + /// + /// Represents a Websocket-based received by the gateway. + /// + public class SocketSlashCommandDataOption : IApplicationCommandInteractionDataOption + { + #region SocketSlashCommandDataOption + /// + public string Name { get; private set; } + + /// + public object Value { get; private set; } + + /// + public ApplicationCommandOptionType Type { get; private set; } + + /// + /// The sub command options received for this sub command group. + /// + public IReadOnlyCollection Options { get; private set; } + + internal SocketSlashCommandDataOption() { } + internal SocketSlashCommandDataOption(SocketSlashCommandData data, Model model) + { + Name = model.Name; + Type = model.Type; + + if (model.Value.IsSpecified) + { + switch (Type) + { + case ApplicationCommandOptionType.User: + case ApplicationCommandOptionType.Role: + case ApplicationCommandOptionType.Channel: + case ApplicationCommandOptionType.Mentionable: + if (ulong.TryParse($"{model.Value.Value}", out var valueId)) + { + switch (Type) + { + case ApplicationCommandOptionType.User: + { + var guildUser = data.ResolvableData.GuildMembers.FirstOrDefault(x => x.Key == valueId).Value; + + if (guildUser != null) + Value = guildUser; + else + Value = data.ResolvableData.Users.FirstOrDefault(x => x.Key == valueId).Value; + } + break; + case ApplicationCommandOptionType.Channel: + Value = data.ResolvableData.Channels.FirstOrDefault(x => x.Key == valueId).Value; + break; + case ApplicationCommandOptionType.Role: + Value = data.ResolvableData.Roles.FirstOrDefault(x => x.Key == valueId).Value; + break; + case ApplicationCommandOptionType.Mentionable: + { + if (data.ResolvableData.GuildMembers.Any(x => x.Key == valueId) || data.ResolvableData.Users.Any(x => x.Key == valueId)) + { + var guildUser = data.ResolvableData.GuildMembers.FirstOrDefault(x => x.Key == valueId).Value; + + if (guildUser != null) + Value = guildUser; + else + Value = data.ResolvableData.Users.FirstOrDefault(x => x.Key == valueId).Value; + } + else if (data.ResolvableData.Roles.Any(x => x.Key == valueId)) + { + Value = data.ResolvableData.Roles.FirstOrDefault(x => x.Key == valueId).Value; + } + } + break; + default: + Value = model.Value.Value; + break; + } + } + break; + case ApplicationCommandOptionType.String: + Value = model.Value.ToString(); + break; + case ApplicationCommandOptionType.Integer: + { + if (model.Value.Value is long val) + Value = val; + else if (long.TryParse(model.Value.Value.ToString(), out long res)) + Value = res; + } + break; + case ApplicationCommandOptionType.Boolean: + { + if (model.Value.Value is bool val) + Value = val; + else if (bool.TryParse(model.Value.Value.ToString(), out bool res)) + Value = res; + } + break; + case ApplicationCommandOptionType.Number: + { + if (model.Value.Value is int val) + Value = val; + else if (double.TryParse(model.Value.Value.ToString(), out double res)) + Value = res; + } + break; + } + } + + Options = model.Options.IsSpecified + ? model.Options.Value.Select(x => new SocketSlashCommandDataOption(data, x)).ToImmutableArray() + : ImmutableArray.Create(); + } + #endregion + + #region Converters + public static explicit operator bool(SocketSlashCommandDataOption option) + => (bool)option.Value; + public static explicit operator int(SocketSlashCommandDataOption option) + => (int)option.Value; + public static explicit operator string(SocketSlashCommandDataOption option) + => option.Value.ToString(); + #endregion + + #region IApplicationCommandInteractionDataOption + IReadOnlyCollection IApplicationCommandInteractionDataOption.Options + => Options; + #endregion + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommand.cs new file mode 100644 index 000000000..d986a93f3 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommand.cs @@ -0,0 +1,116 @@ +using Discord.Rest; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Threading.Tasks; +using GatewayModel = Discord.API.Gateway.ApplicationCommandCreatedUpdatedEvent; +using Model = Discord.API.ApplicationCommand; + +namespace Discord.WebSocket +{ + /// + /// Represents a Websocket-based . + /// + public class SocketApplicationCommand : SocketEntity, IApplicationCommand + { + #region SocketApplicationCommand + /// + /// if this command is a global command, otherwise . + /// + public bool IsGlobalCommand + => Guild == null; + + /// + public ulong ApplicationId { get; private set; } + + /// + public string Name { get; private set; } + + /// + public ApplicationCommandType Type { get; private set; } + + /// + public string Description { get; private set; } + + /// + public bool IsDefaultPermission { get; private set; } + + /// + /// A collection of 's for this command. + /// + /// + /// If the is not a slash command, this field will be an empty collection. + /// + public IReadOnlyCollection Options { get; private set; } + + /// + public DateTimeOffset CreatedAt + => SnowflakeUtils.FromSnowflake(Id); + + /// + /// Returns the guild this command resides in, if this command is a global command then it will return + /// + public SocketGuild Guild + => GuildId.HasValue ? Discord.GetGuild(GuildId.Value) : null; + + private ulong? GuildId { get; set; } + + internal SocketApplicationCommand(DiscordSocketClient client, ulong id, ulong? guildId) + : base(client, id) + { + GuildId = guildId; + } + internal static SocketApplicationCommand Create(DiscordSocketClient client, GatewayModel model) + { + var entity = new SocketApplicationCommand(client, model.Id, model.GuildId.ToNullable()); + entity.Update(model); + return entity; + } + + internal static SocketApplicationCommand Create(DiscordSocketClient client, Model model, ulong? guildId = null) + { + var entity = new SocketApplicationCommand(client, model.Id, guildId); + entity.Update(model); + return entity; + } + + internal void Update(Model model) + { + ApplicationId = model.ApplicationId; + Description = model.Description; + Name = model.Name; + IsDefaultPermission = model.DefaultPermissions.GetValueOrDefault(true); + Type = model.Type; + + Options = model.Options.IsSpecified + ? model.Options.Value.Select(SocketApplicationCommandOption.Create).ToImmutableArray() + : ImmutableArray.Create(); + } + + /// + public Task DeleteAsync(RequestOptions options = null) + => InteractionHelper.DeleteUnknownApplicationCommandAsync(Discord, GuildId, this, options); + + /// + public Task ModifyAsync(Action func, RequestOptions options = null) + { + return ModifyAsync(func, options); + } + + /// + public async Task ModifyAsync(Action func, RequestOptions options = null) where TArg : ApplicationCommandProperties + { + var command = IsGlobalCommand + ? await InteractionHelper.ModifyGlobalCommandAsync(Discord, this, func, options).ConfigureAwait(false) + : await InteractionHelper.ModifyGuildCommandAsync(Discord, this, GuildId.Value, func, options); + + Update(command); + } + #endregion + + #region IApplicationCommand + IReadOnlyCollection IApplicationCommand.Options => Options; + #endregion + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandChoice.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandChoice.cs new file mode 100644 index 000000000..e70efa27b --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandChoice.cs @@ -0,0 +1,29 @@ +using Model = Discord.API.ApplicationCommandOptionChoice; + +namespace Discord.WebSocket +{ + /// + /// Represents a choice for a . + /// + public class SocketApplicationCommandChoice : IApplicationCommandOptionChoice + { + /// + public string Name { get; private set; } + + /// + public object Value { get; private set; } + + internal SocketApplicationCommandChoice() { } + internal static SocketApplicationCommandChoice Create(Model model) + { + var entity = new SocketApplicationCommandChoice(); + entity.Update(model); + return entity; + } + internal void Update(Model model) + { + Name = model.Name; + Value = model.Value; + } + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandOption.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandOption.cs new file mode 100644 index 000000000..bdb03c8b0 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandOption.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using Model = Discord.API.ApplicationCommandOption; + +namespace Discord.WebSocket +{ + /// + /// Represents an option for a . + /// + public class SocketApplicationCommandOption : IApplicationCommandOption + { + /// + public string Name { get; private set; } + + /// + public ApplicationCommandOptionType Type { get; private set; } + + /// + public string Description { get; private set; } + + /// + public bool? IsDefault { get; private set; } + + /// + public bool? IsRequired { get; private set; } + + public bool? IsAutocomplete { get; private set; } + + /// + public double? MinValue { get; private set; } + + /// + public double? MaxValue { get; private set; } + + /// + /// Choices for string and int types for the user to pick from. + /// + public IReadOnlyCollection Choices { get; private set; } + + /// + /// If the option is a subcommand or subcommand group type, this nested options will be the parameters. + /// + public IReadOnlyCollection Options { get; private set; } + + /// + /// The allowed channel types for this option. + /// + public IReadOnlyCollection ChannelTypes { get; private set; } + + internal SocketApplicationCommandOption() { } + internal static SocketApplicationCommandOption Create(Model model) + { + var entity = new SocketApplicationCommandOption(); + entity.Update(model); + return entity; + } + + internal void Update(Model model) + { + Name = model.Name; + Type = model.Type; + Description = model.Description; + + IsDefault = model.Default.ToNullable(); + + IsRequired = model.Required.ToNullable(); + + MinValue = model.MinValue.ToNullable(); + + MaxValue = model.MaxValue.ToNullable(); + + IsAutocomplete = model.Autocomplete.ToNullable(); + + Choices = model.Choices.IsSpecified + ? model.Choices.Value.Select(SocketApplicationCommandChoice.Create).ToImmutableArray() + : ImmutableArray.Create(); + + Options = model.Options.IsSpecified + ? model.Options.Value.Select(Create).ToImmutableArray() + : ImmutableArray.Create(); + + ChannelTypes = model.ChannelTypes.IsSpecified + ? model.ChannelTypes.Value.ToImmutableArray() + : ImmutableArray.Create(); + } + + IReadOnlyCollection IApplicationCommandOption.Choices => Choices; + IReadOnlyCollection IApplicationCommandOption.Options => Options; + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs new file mode 100644 index 000000000..330d6d7a4 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs @@ -0,0 +1,324 @@ +using Discord.Net.Rest; +using Discord.Rest; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using DataModel = Discord.API.ApplicationCommandInteractionData; +using Model = Discord.API.Interaction; + +namespace Discord.WebSocket +{ + /// + /// Base class for User, Message, and Slash command interactions. + /// + public class SocketCommandBase : SocketInteraction + { + /// + /// Gets the name of the invoked command. + /// + public string CommandName + => Data.Name; + + /// + /// Gets the id of the invoked command. + /// + public ulong CommandId + => Data.Id; + + /// + /// The data associated with this interaction. + /// + internal new SocketCommandBaseData Data { get; } + + public override bool HasResponded { get; internal set; } + + private object _lock = new object(); + + internal SocketCommandBase(DiscordSocketClient client, Model model, ISocketMessageChannel channel) + : base(client, model.Id, channel) + { + var dataModel = model.Data.IsSpecified + ? (DataModel)model.Data.Value + : null; + + ulong? guildId = null; + if (Channel is SocketGuildChannel guildChannel) + guildId = guildChannel.Guild.Id; + + Data = SocketCommandBaseData.Create(client, dataModel, model.Id, guildId); + } + + internal new static SocketInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel) + { + var entity = new SocketCommandBase(client, model, channel); + entity.Update(model); + return entity; + } + + internal override void Update(Model model) + { + var data = model.Data.IsSpecified + ? (DataModel)model.Data.Value + : null; + + Data.Update(data); + + base.Update(model); + } + + /// + public override async Task RespondAsync( + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + if (!InteractionHelper.CanSendResponse(this)) + throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!"); + + embeds ??= Array.Empty(); + if (embed != null) + embeds = new[] { embed }.Concat(embeds).ToArray(); + + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed."); + + // check that user flag and user Id list are exclusive, same with role flag and role Id list + if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue) + { + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) && + allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) + { + throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions)); + } + + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) && + allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) + { + throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions)); + } + } + + var response = new API.InteractionResponse + { + Type = InteractionResponseType.ChannelMessageWithSource, + Data = new API.InteractionCallbackData + { + Content = text ?? Optional.Unspecified, + AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, + Embeds = embeds.Select(x => x.ToModel()).ToArray(), + TTS = isTTS, + Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified, + Flags = ephemeral ? MessageFlags.Ephemeral : Optional.Unspecified + } + }; + + lock (_lock) + { + if (HasResponded) + { + throw new InvalidOperationException("Cannot respond twice to the same interaction"); + } + } + + await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false); + HasResponded = true; + } + + public override async Task RespondWithFilesAsync( + IEnumerable attachments, + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + if (!InteractionHelper.CanSendResponse(this)) + throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!"); + + embeds ??= Array.Empty(); + if (embed != null) + embeds = new[] { embed }.Concat(embeds).ToArray(); + + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed."); + + // check that user flag and user Id list are exclusive, same with role flag and role Id list + if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue) + { + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) && + allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) + { + throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions)); + } + + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) && + allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) + { + throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions)); + } + } + + var response = new API.Rest.UploadInteractionFileParams(attachments?.ToArray()) + { + Type = InteractionResponseType.ChannelMessageWithSource, + Content = text ?? Optional.Unspecified, + AllowedMentions = allowedMentions != null ? allowedMentions?.ToModel() : Optional.Unspecified, + Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional.Unspecified, + IsTTS = isTTS, + Flags = ephemeral ? MessageFlags.Ephemeral : Optional.Unspecified, + MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified + }; + + lock (_lock) + { + if (HasResponded) + { + throw new InvalidOperationException("Cannot respond, update, or defer the same interaction twice"); + } + } + + await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false); + HasResponded = true; + } + + /// + public override async Task FollowupAsync( + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + embeds ??= Array.Empty(); + if (embed != null) + embeds = new[] { embed }.Concat(embeds).ToArray(); + + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed."); + + var args = new API.Rest.CreateWebhookMessageParams + { + Content = text ?? Optional.Unspecified, + AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, + IsTTS = isTTS, + Embeds = embeds.Select(x => x.ToModel()).ToArray(), + Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified + }; + + if (ephemeral) + args.Flags = MessageFlags.Ephemeral; + + return await InteractionHelper.SendFollowupAsync(Discord.Rest, args, Token, Channel, options); + } + + /// + public override async Task FollowupWithFilesAsync( + IEnumerable attachments, + string text = null, + Embed[] embeds = null, + bool isTTS = false, + bool ephemeral = false, + AllowedMentions allowedMentions = null, + MessageComponent components = null, + Embed embed = null, + RequestOptions options = null) + { + if (!IsValidToken) + throw new InvalidOperationException("Interaction token is no longer valid"); + + embeds ??= Array.Empty(); + if (embed != null) + embeds = new[] { embed }.Concat(embeds).ToArray(); + + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed."); + + foreach (var attachment in attachments) + { + Preconditions.NotNullOrEmpty(attachment.FileName, nameof(attachment.FileName), "File Name must not be empty or null"); + } + + // check that user flag and user Id list are exclusive, same with role flag and role Id list + if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue) + { + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) && + allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) + { + throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions)); + } + + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) && + allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) + { + throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions)); + } + } + + var flags = MessageFlags.None; + + if (ephemeral) + flags |= MessageFlags.Ephemeral; + + var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray()) { Flags = flags, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified }; + return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false); + } + + /// + /// Acknowledges this interaction with the . + /// + /// + /// A task that represents the asynchronous operation of acknowledging the interaction. + /// + public override async Task DeferAsync(bool ephemeral = false, RequestOptions options = null) + { + if (!InteractionHelper.CanSendResponse(this)) + throw new TimeoutException($"Cannot defer an interaction after {InteractionHelper.ResponseTimeLimit} seconds!"); + + var response = new API.InteractionResponse + { + Type = InteractionResponseType.DeferredChannelMessageWithSource, + Data = new API.InteractionCallbackData + { + Flags = ephemeral ? MessageFlags.Ephemeral : Optional.Unspecified + } + }; + + lock (_lock) + { + if (HasResponded) + { + throw new InvalidOperationException("Cannot respond or defer twice to the same interaction"); + } + } + + await Discord.Rest.ApiClient.CreateInteractionResponseAsync(response, Id, Token, options).ConfigureAwait(false); + HasResponded = true; + } + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBaseData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBaseData.cs new file mode 100644 index 000000000..cb2f01f5f --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBaseData.cs @@ -0,0 +1,58 @@ +using System.Collections.Generic; +using Model = Discord.API.ApplicationCommandInteractionData; + +namespace Discord.WebSocket +{ + /// + /// Represents the base data tied with the interaction. + /// + public class SocketCommandBaseData : SocketEntity, IApplicationCommandInteractionData where TOption : IApplicationCommandInteractionDataOption + { + /// + public string Name { get; private set; } + + /// + /// The received with this interaction. + /// + public virtual IReadOnlyCollection Options { get; internal set; } + + internal readonly SocketResolvableData ResolvableData; + + private ApplicationCommandType Type { get; set; } + + internal SocketCommandBaseData(DiscordSocketClient client, Model model, ulong? guildId) + : base(client, model.Id) + { + Type = model.Type; + + if (model.Resolved.IsSpecified) + { + ResolvableData = new SocketResolvableData(client, guildId, model); + } + } + + internal static SocketCommandBaseData Create(DiscordSocketClient client, Model model, ulong id, ulong? guildId) + { + var entity = new SocketCommandBaseData(client, model, guildId); + entity.Update(model); + return entity; + } + + internal virtual void Update(Model model) + { + Name = model.Name; + } + + IReadOnlyCollection IApplicationCommandInteractionData.Options + => (IReadOnlyCollection)Options; + } + + /// + /// Represents the base data tied with the interaction. + /// + public class SocketCommandBaseData : SocketCommandBaseData + { + internal SocketCommandBaseData(DiscordSocketClient client, Model model, ulong? guildId) + : base(client, model, guildId) { } + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketResolvableData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketResolvableData.cs new file mode 100644 index 000000000..c065637ca --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketResolvableData.cs @@ -0,0 +1,109 @@ +using System.Collections.Generic; + +namespace Discord.WebSocket +{ + internal class SocketResolvableData where T : API.IResolvable + { + internal readonly Dictionary GuildMembers + = new Dictionary(); + internal readonly Dictionary Users + = new Dictionary(); + internal readonly Dictionary Channels + = new Dictionary(); + internal readonly Dictionary Roles + = new Dictionary(); + + internal readonly Dictionary Messages + = new Dictionary(); + + internal SocketResolvableData(DiscordSocketClient discord, ulong? guildId, T model) + { + var guild = guildId.HasValue ? discord.GetGuild(guildId.Value) : null; + + var resolved = model.Resolved.Value; + + if (resolved.Users.IsSpecified) + { + foreach (var user in resolved.Users.Value) + { + var socketUser = discord.GetOrCreateUser(discord.State, user.Value); + + Users.Add(ulong.Parse(user.Key), socketUser); + } + } + + if (resolved.Channels.IsSpecified) + { + foreach (var channel in resolved.Channels.Value) + { + SocketChannel socketChannel = guild != null + ? guild.GetChannel(channel.Value.Id) + : discord.GetChannel(channel.Value.Id); + + if (socketChannel == null) + { + var channelModel = guild != null + ? discord.Rest.ApiClient.GetChannelAsync(guild.Id, channel.Value.Id).ConfigureAwait(false).GetAwaiter().GetResult() + : discord.Rest.ApiClient.GetChannelAsync(channel.Value.Id).ConfigureAwait(false).GetAwaiter().GetResult(); + + socketChannel = guild != null + ? SocketGuildChannel.Create(guild, discord.State, channelModel) + : (SocketChannel)SocketChannel.CreatePrivate(discord, discord.State, channelModel); + } + + discord.State.AddChannel(socketChannel); + Channels.Add(ulong.Parse(channel.Key), socketChannel); + } + } + + if (resolved.Members.IsSpecified) + { + foreach (var member in resolved.Members.Value) + { + member.Value.User = resolved.Users.Value[member.Key]; + var user = guild.AddOrUpdateUser(member.Value); + GuildMembers.Add(ulong.Parse(member.Key), user); + } + } + + if (resolved.Roles.IsSpecified) + { + foreach (var role in resolved.Roles.Value) + { + var socketRole = guild.AddOrUpdateRole(role.Value); + Roles.Add(ulong.Parse(role.Key), socketRole); + } + } + + if (resolved.Messages.IsSpecified) + { + foreach (var msg in resolved.Messages.Value) + { + var channel = discord.GetChannel(msg.Value.ChannelId) as ISocketMessageChannel; + + SocketUser author; + if (guild != null) + { + if (msg.Value.WebhookId.IsSpecified) + author = SocketWebhookUser.Create(guild, discord.State, msg.Value.Author.Value, msg.Value.WebhookId.Value); + else + author = guild.GetUser(msg.Value.Author.Value.Id); + } + else + author = (channel as SocketChannel).GetUser(msg.Value.Author.Value.Id); + + if (channel == null) + { + if (!msg.Value.GuildId.IsSpecified) // assume it is a DM + { + channel = discord.CreateDMChannel(msg.Value.ChannelId, msg.Value.Author.Value, discord.State); + } + } + + var message = SocketMessage.Create(discord, discord.State, author, channel, msg.Value); + Messages.Add(message.Id, message); + } + } + } + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs new file mode 100644 index 000000000..8250b6825 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs @@ -0,0 +1,407 @@ +using Discord.Rest; +using System; +using System.Threading.Tasks; +using Model = Discord.API.Interaction; +using DataModel = Discord.API.ApplicationCommandInteractionData; +using System.IO; +using System.Collections.Generic; + +namespace Discord.WebSocket +{ + /// + /// Represents an Interaction received over the gateway. + /// + public abstract class SocketInteraction : SocketEntity, IDiscordInteraction + { + #region SocketInteraction + /// + /// The this interaction was used in. + /// + public ISocketMessageChannel Channel { get; private set; } + + /// + /// The who triggered this interaction. + /// + public SocketUser User { get; private set; } + + /// + /// The type of this interaction. + /// + public InteractionType Type { get; private set; } + + /// + /// The token used to respond to this interaction. + /// + public string Token { get; private set; } + + /// + /// The data sent with this interaction. + /// + public IDiscordInteractionData Data { get; private set; } + + /// + /// The version of this interaction. + /// + public int Version { get; private set; } + + /// + public DateTimeOffset CreatedAt { get; private set; } + + /// + /// Gets whether or not this interaction has been responded to. + /// + /// + /// This property is locally set -- if you're running multiple bots + /// off the same token then this property won't be in sync with them. + /// + public abstract bool HasResponded { get; internal set; } + + /// + /// if the token is valid for replying to, otherwise . + /// + public bool IsValidToken + => InteractionHelper.CanRespondOrFollowup(this); + + internal SocketInteraction(DiscordSocketClient client, ulong id, ISocketMessageChannel channel) + : base(client, id) + { + Channel = channel; + + CreatedAt = client.UseInteractionSnowflakeDate + ? SnowflakeUtils.FromSnowflake(Id) + : DateTime.UtcNow; + } + + internal static SocketInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel) + { + if (model.Type == InteractionType.ApplicationCommand) + { + var dataModel = model.Data.IsSpecified + ? (DataModel)model.Data.Value + : null; + + if (dataModel == null) + return null; + + return dataModel.Type switch + { + ApplicationCommandType.Slash => SocketSlashCommand.Create(client, model, channel), + ApplicationCommandType.Message => SocketMessageCommand.Create(client, model, channel), + ApplicationCommandType.User => SocketUserCommand.Create(client, model, channel), + _ => null + }; + } + + if (model.Type == InteractionType.MessageComponent) + return SocketMessageComponent.Create(client, model, channel); + + if (model.Type == InteractionType.ApplicationCommandAutocomplete) + return SocketAutocompleteInteraction.Create(client, model, channel); + + return null; + } + + internal virtual void Update(Model model) + { + Data = model.Data.IsSpecified + ? model.Data.Value + : null; + Token = model.Token; + Version = model.Version; + Type = model.Type; + + if (User == null) + { + if (model.Member.IsSpecified && model.GuildId.IsSpecified) + { + User = SocketGuildUser.Create(Discord.State.GetGuild(model.GuildId.Value), Discord.State, model.Member.Value); + } + else + { + User = SocketGlobalUser.Create(Discord, Discord.State, model.User.Value); + } + } + } + + /// + /// Responds to an Interaction with type . + /// + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// The request options for this response. + /// Message content is too long, length must be less or equal to . + /// The parameters provided were invalid or the token was invalid. + public abstract Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, + bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); + + /// + /// Responds to this interaction with a file attachment. + /// + /// The file to upload. + /// The file name of the attachment. + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// The request options for this response. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + public async Task RespondWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + { + using (var file = new FileAttachment(fileStream, fileName)) + { + await RespondWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + } + } + + /// + /// Responds to this interaction with a file attachment. + /// + /// The file to upload. + /// The file name of the attachment. + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// The request options for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + public async Task RespondWithFileAsync(string filePath, string fileName = null, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + { + using (var file = new FileAttachment(filePath, fileName)) + { + await RespondWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + } + } + + /// + /// Responds to this interaction with a file attachment. + /// + /// The attachment containing the file and description. + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// The request options for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + public Task RespondWithFileAsync(FileAttachment attachment, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + => RespondWithFilesAsync(new FileAttachment[] { attachment }, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options); + + /// + /// Responds to this interaction with a collection of file attachments. + /// + /// A collection of attachments to upload. + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// The request options for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + public abstract Task RespondWithFilesAsync(IEnumerable attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); + + /// + /// Sends a followup message for this interaction. + /// + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// The request options for this response. + /// + /// The sent message. + /// + public abstract Task FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); + + /// + /// Sends a followup message for this interaction. + /// + /// The text of the message to be sent. + /// The file to upload. + /// The file name of the attachment. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// The request options for this response. + /// + /// The sent message. + /// + public async Task FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + { + using (var file = new FileAttachment(fileStream, fileName)) + { + return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + } + } + + /// + /// Sends a followup message for this interaction. + /// + /// The text of the message to be sent. + /// The file to upload. + /// The file name of the attachment. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// The request options for this response. + /// + /// The sent message. + /// + public async Task FollowupWithFileAsync(string filePath, string fileName = null, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + { + using (var file = new FileAttachment(filePath, fileName)) + { + return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + } + } + + /// + /// Sends a followup message for this interaction. + /// + /// The attachment containing the file and description. + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// The request options for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + public Task FollowupWithFileAsync(FileAttachment attachment, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null) + => FollowupWithFilesAsync(new FileAttachment[] { attachment }, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options); + + /// + /// Sends a followup message for this interaction. + /// + /// A collection of attachments to upload. + /// The text of the message to be sent. + /// A array of embeds to send with this response. Max 10. + /// if the message should be read out by a text-to-speech reader, otherwise . + /// if the response should be hidden to everyone besides the invoker of the command, otherwise . + /// The allowed mentions for this response. + /// The request options for this response. + /// A to be sent with this response. + /// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored. + /// + /// A task that represents an asynchronous send operation for delivering the message. The task result + /// contains the sent message. + /// + public abstract Task FollowupWithFilesAsync(IEnumerable attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, + AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null); + + /// + /// Gets the original response for this interaction. + /// + /// The request options for this request. + /// A that represents the initial response. + public Task GetOriginalResponseAsync(RequestOptions options = null) + => InteractionHelper.GetOriginalResponseAsync(Discord, Channel, this, options); + + /// + /// Edits original response for this interaction. + /// + /// A delegate containing the properties to modify the message with. + /// The request options for this request. + /// A that represents the initial response. + public async Task ModifyOriginalResponseAsync(Action func, RequestOptions options = null) + { + var model = await InteractionHelper.ModifyInteractionResponseAsync(Discord, Token, func, options); + return RestInteractionMessage.Create(Discord, model, Token, Channel); + } + + /// + public Task DeleteOriginalResponseAsync(RequestOptions options = null) + => InteractionHelper.DeleteInteractionResponseAsync(Discord, this, options); + + /// + /// Acknowledges this interaction. + /// + /// to send this message ephemerally, otherwise . + /// The request options for this request. + /// + /// A task that represents the asynchronous operation of acknowledging the interaction. + /// + public abstract Task DeferAsync(bool ephemeral = false, RequestOptions options = null); + + #endregion + + #region IDiscordInteraction + /// + IUser IDiscordInteraction.User => User; + + /// + async Task IDiscordInteraction.GetOriginalResponseAsync(RequestOptions options) + => await GetOriginalResponseAsync(options).ConfigureAwait(false); + /// + async Task IDiscordInteraction.ModifyOriginalResponseAsync(Action func, RequestOptions options) + => await ModifyOriginalResponseAsync(func, options).ConfigureAwait(false); + /// + async Task IDiscordInteraction.RespondAsync(string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options) + => await RespondAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + /// + async Task IDiscordInteraction.FollowupAsync(string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options) + => await FollowupAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + /// + async Task IDiscordInteraction.FollowupWithFilesAsync(IEnumerable attachments, string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options) + => await FollowupWithFilesAsync(attachments, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); +#if NETCOREAPP3_0_OR_GREATER != true + /// + async Task IDiscordInteraction.FollowupWithFileAsync(Stream fileStream, string fileName, string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options) + => await FollowupWithFileAsync(fileStream, fileName, text, embeds, isTTS, ephemeral, allowedMentions, components, embed).ConfigureAwait(false); + /// + async Task IDiscordInteraction.FollowupWithFileAsync(string filePath, string fileName, string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options) + => await FollowupWithFileAsync(filePath, fileName, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); + /// + async Task IDiscordInteraction.FollowupWithFileAsync(FileAttachment attachment, string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions, MessageComponent components, Embed embed, RequestOptions options) + => await FollowupWithFileAsync(attachment, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options).ConfigureAwait(false); +#endif + #endregion + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Invites/SocketInvite.cs b/src/Discord.Net.WebSocket/Entities/Invites/SocketInvite.cs new file mode 100644 index 000000000..2b64e170e --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Invites/SocketInvite.cs @@ -0,0 +1,146 @@ +using Discord.Rest; +using System; +using System.Diagnostics; +using System.Threading.Tasks; +using Model = Discord.API.Gateway.InviteCreateEvent; + +namespace Discord.WebSocket +{ + /// + /// Represents a WebSocket-based invite to a guild. + /// + [DebuggerDisplay(@"{DebuggerDisplay,nq}")] + public class SocketInvite : SocketEntity, IInviteMetadata + { + private long _createdAtTicks; + + /// + public ulong ChannelId { get; private set; } + /// + /// Gets the channel where this invite was created. + /// + public SocketGuildChannel Channel { get; private set; } + /// + public ulong? GuildId { get; private set; } + /// + /// Gets the guild where this invite was created. + /// + public SocketGuild Guild { get; private set; } + /// + ChannelType IInvite.ChannelType + { + get + { + return Channel switch + { + IVoiceChannel voiceChannel => ChannelType.Voice, + ICategoryChannel categoryChannel => ChannelType.Category, + IDMChannel dmChannel => ChannelType.DM, + IGroupChannel groupChannel => ChannelType.Group, + INewsChannel newsChannel => ChannelType.News, + ITextChannel textChannel => ChannelType.Text, + _ => throw new InvalidOperationException("Invalid channel type."), + }; + } + } + /// + string IInvite.ChannelName => Channel.Name; + /// + string IInvite.GuildName => Guild.Name; + /// + int? IInvite.PresenceCount => throw new NotImplementedException(); + /// + int? IInvite.MemberCount => throw new NotImplementedException(); + /// + public bool IsTemporary { get; private set; } + /// + int? IInviteMetadata.MaxAge { get => MaxAge; } + /// + int? IInviteMetadata.MaxUses { get => MaxUses; } + /// + int? IInviteMetadata.Uses { get => Uses; } + /// + /// Gets the time (in seconds) until the invite expires. + /// + public int MaxAge { get; private set; } + /// + /// Gets the max number of uses this invite may have. + /// + public int MaxUses { get; private set; } + /// + /// Gets the number of times this invite has been used. + /// + public int Uses { get; private set; } + /// + /// Gets the user that created this invite if available. + /// + public SocketGuildUser Inviter { get; private set; } + /// + DateTimeOffset? IInviteMetadata.CreatedAt => DateTimeUtils.FromTicks(_createdAtTicks); + /// + /// Gets when this invite was created. + /// + public DateTimeOffset CreatedAt => DateTimeUtils.FromTicks(_createdAtTicks); + /// + /// Gets the user targeted by this invite if available. + /// + public SocketUser TargetUser { get; private set; } + /// + /// Gets the type of the user targeted by this invite. + /// + public TargetUserType TargetUserType { get; private set; } + + /// + public string Code => Id; + /// + public string Url => $"{DiscordConfig.InviteUrl}{Code}"; + + internal SocketInvite(DiscordSocketClient discord, SocketGuild guild, SocketGuildChannel channel, SocketGuildUser inviter, SocketUser target, string id) + : base(discord, id) + { + Guild = guild; + Channel = channel; + Inviter = inviter; + TargetUser = target; + } + internal static SocketInvite Create(DiscordSocketClient discord, SocketGuild guild, SocketGuildChannel channel, SocketGuildUser inviter, SocketUser target, Model model) + { + var entity = new SocketInvite(discord, guild, channel, inviter, target, model.Code); + entity.Update(model); + return entity; + } + internal void Update(Model model) + { + ChannelId = model.ChannelId; + GuildId = model.GuildId.IsSpecified ? model.GuildId.Value : Guild.Id; + IsTemporary = model.Temporary; + MaxAge = model.MaxAge; + MaxUses = model.MaxUses; + Uses = model.Uses; + _createdAtTicks = model.CreatedAt.UtcTicks; + TargetUserType = model.TargetUserType.IsSpecified ? model.TargetUserType.Value : TargetUserType.Undefined; + } + + /// + public Task DeleteAsync(RequestOptions options = null) + => InviteHelper.DeleteAsync(this, Discord, options); + + /// + /// Gets the URL of the invite. + /// + /// + /// A string that resolves to the Url of the invite. + /// + public override string ToString() => Url; + private string DebuggerDisplay => $"{Url} ({Guild?.Name} / {Channel.Name})"; + + /// + IGuild IInvite.Guild => Guild; + /// + IChannel IInvite.Channel => Channel; + /// + IUser IInvite.Inviter => Inviter; + /// + IUser IInvite.TargetUser => TargetUser; + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Messages/MessageCache.cs b/src/Discord.Net.WebSocket/Entities/Messages/MessageCache.cs index 24e46df46..6baf56879 100644 --- a/src/Discord.Net.WebSocket/Entities/Messages/MessageCache.cs +++ b/src/Discord.Net.WebSocket/Entities/Messages/MessageCache.cs @@ -56,11 +56,23 @@ namespace Discord.WebSocket cachedMessageIds = _orderedMessages; else if (dir == Direction.Before) cachedMessageIds = _orderedMessages.Where(x => x < fromMessageId.Value); - else + else if (dir == Direction.After) cachedMessageIds = _orderedMessages.Where(x => x > fromMessageId.Value); + else //Direction.Around + { + if (!_messages.TryGetValue(fromMessageId.Value, out SocketMessage msg)) + return ImmutableArray.Empty; + int around = limit / 2; + var before = GetMany(fromMessageId, Direction.Before, around); + var after = GetMany(fromMessageId, Direction.After, around).Reverse(); + + return after.Concat(new SocketMessage[] { msg }).Concat(before).ToImmutableArray(); + } if (dir == Direction.Before) cachedMessageIds = cachedMessageIds.Reverse(); + if (dir == Direction.Around) //Only happens if fromMessageId is null, should only get "around" and itself (+1) + limit = limit / 2 + 1; return cachedMessageIds .Select(x => diff --git a/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs b/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs index 7900b7ee7..4be9f4c5a 100644 --- a/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs +++ b/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs @@ -1,4 +1,5 @@ using Discord.Rest; +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Collections.Immutable; @@ -13,8 +14,10 @@ namespace Discord.WebSocket /// public abstract class SocketMessage : SocketEntity, IMessage { + #region SocketMessage private long _timestampTicks; private readonly List _reactions = new List(); + private ImmutableArray _userMentions = ImmutableArray.Create(); /// /// Gets the author of this message. @@ -36,6 +39,9 @@ namespace Discord.WebSocket /// public string Content { get; private set; } + /// + public string CleanContent => MessageHelper.SanitizeMessage(this); + /// public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); /// @@ -46,6 +52,8 @@ namespace Discord.WebSocket public virtual bool IsSuppressed => false; /// public virtual DateTimeOffset? EditedTimestamp => null; + /// + public virtual bool MentionedEveryone => false; /// public MessageActivity Activity { get; private set; } @@ -56,6 +64,20 @@ namespace Discord.WebSocket /// public MessageReference Reference { get; private set; } + /// + public IReadOnlyCollection Components { get; private set; } + + /// + /// Gets the interaction this message is a response to. + /// + public MessageInteraction Interaction { get; private set; } + + /// + public MessageFlags? Flags { get; private set; } + + /// + public MessageType Type { get; private set; } + /// /// Returns all attachments included in this message. /// @@ -84,18 +106,19 @@ namespace Discord.WebSocket /// Collection of WebSocket-based roles. /// public virtual IReadOnlyCollection MentionedRoles => ImmutableArray.Create(); + /// + public virtual IReadOnlyCollection Tags => ImmutableArray.Create(); + /// + public virtual IReadOnlyCollection Stickers => ImmutableArray.Create(); + /// + public IReadOnlyDictionary Reactions => _reactions.GroupBy(r => r.Emote).ToDictionary(x => x.Key, x => new ReactionMetadata { ReactionCount = x.Count(), IsMe = x.Any(y => y.UserId == Discord.CurrentUser.Id) }); /// /// Returns the users mentioned in this message. /// /// /// Collection of WebSocket-based users. /// - public virtual IReadOnlyCollection MentionedUsers => ImmutableArray.Create(); - /// - public virtual IReadOnlyCollection Tags => ImmutableArray.Create(); - /// - public IReadOnlyDictionary Reactions => _reactions.GroupBy(r => r.Emote).ToDictionary(x => x.Key, x => new ReactionMetadata { ReactionCount = x.Count(), IsMe = x.Any(y => y.UserId == Discord.CurrentUser.Id) }); - + public IReadOnlyCollection MentionedUsers => _userMentions; /// public DateTimeOffset Timestamp => DateTimeUtils.FromTicks(_timestampTicks); @@ -108,18 +131,25 @@ namespace Discord.WebSocket } internal static SocketMessage Create(DiscordSocketClient discord, ClientState state, SocketUser author, ISocketMessageChannel channel, Model model) { - if (model.Type == MessageType.Default) + if (model.Type == MessageType.Default || + model.Type == MessageType.Reply || + model.Type == MessageType.ApplicationCommand || + model.Type == MessageType.ThreadStarterMessage) return SocketUserMessage.Create(discord, state, author, channel, model); else return SocketSystemMessage.Create(discord, state, author, channel, model); } internal virtual void Update(ClientState state, Model model) { + Type = model.Type; + if (model.Timestamp.IsSpecified) _timestampTicks = model.Timestamp.Value.UtcTicks; if (model.Content.IsSpecified) + { Content = model.Content.Value; + } if (model.Application.IsSpecified) { @@ -140,7 +170,7 @@ namespace Discord.WebSocket Activity = new MessageActivity() { Type = model.Activity.Value.Type.Value, - PartyId = model.Activity.Value.PartyId.Value + PartyId = model.Activity.Value.PartyId.GetValueOrDefault() }; } @@ -150,10 +180,93 @@ namespace Discord.WebSocket Reference = new MessageReference { GuildId = model.Reference.Value.GuildId, - ChannelId = model.Reference.Value.ChannelId, + InternalChannelId = model.Reference.Value.ChannelId, MessageId = model.Reference.Value.MessageId }; } + + if (model.Components.IsSpecified) + { + Components = model.Components.Value.Select(x => new ActionRowComponent(x.Components.Select(y => + { + switch (y.Type) + { + case ComponentType.Button: + { + var parsed = (API.ButtonComponent)y; + return new Discord.ButtonComponent( + parsed.Style, + parsed.Label.GetValueOrDefault(), + parsed.Emote.IsSpecified + ? parsed.Emote.Value.Id.HasValue + ? new Emote(parsed.Emote.Value.Id.Value, parsed.Emote.Value.Name, parsed.Emote.Value.Animated.GetValueOrDefault()) + : new Emoji(parsed.Emote.Value.Name) + : null, + parsed.CustomId.GetValueOrDefault(), + parsed.Url.GetValueOrDefault(), + parsed.Disabled.GetValueOrDefault()); + } + case ComponentType.SelectMenu: + { + var parsed = (API.SelectMenuComponent)y; + return new SelectMenuComponent( + parsed.CustomId, + parsed.Options.Select(z => new SelectMenuOption( + z.Label, + z.Value, + z.Description.GetValueOrDefault(), + z.Emoji.IsSpecified + ? z.Emoji.Value.Id.HasValue + ? new Emote(z.Emoji.Value.Id.Value, z.Emoji.Value.Name, z.Emoji.Value.Animated.GetValueOrDefault()) + : new Emoji(z.Emoji.Value.Name) + : null, + z.Default.ToNullable())).ToList(), + parsed.Placeholder.GetValueOrDefault(), + parsed.MinValues, + parsed.MaxValues, + parsed.Disabled + ); + } + default: + return null; + } + }).ToList())).ToImmutableArray(); + } + else + Components = new List(); + + if (model.UserMentions.IsSpecified) + { + var value = model.UserMentions.Value; + if (value.Length > 0) + { + var newMentions = ImmutableArray.CreateBuilder(value.Length); + for (int i = 0; i < value.Length; i++) + { + var val = value[i]; + if (val != null) + { + var user = Channel.GetUserAsync(val.Id, CacheMode.CacheOnly).GetAwaiter().GetResult() as SocketUser; + if (user != null) + newMentions.Add(user); + else + newMentions.Add(SocketUnknownUser.Create(Discord, state, val)); + } + } + _userMentions = newMentions.ToImmutable(); + } + } + + if (model.Interaction.IsSpecified) + { + Interaction = new MessageInteraction(model.Interaction.Value.Id, + model.Interaction.Value.Type, + model.Interaction.Value.Name, + SocketGlobalUser.Create(Discord, state, model.Interaction.Value.User)); + } + + if (model.Flags.IsSpecified) + Flags = model.Flags.Value; } /// @@ -168,15 +281,14 @@ namespace Discord.WebSocket /// public override string ToString() => Content; internal SocketMessage Clone() => MemberwiseClone() as SocketMessage; +#endregion - //IMessage + #region IMessage /// IUser IMessage.Author => Author; /// IMessageChannel IMessage.Channel => Channel; /// - MessageType IMessage.Type => MessageType.Default; - /// IReadOnlyCollection IMessage.Attachments => Attachments; /// IReadOnlyCollection IMessage.Embeds => Embeds; @@ -187,6 +299,16 @@ namespace Discord.WebSocket /// IReadOnlyCollection IMessage.MentionedUserIds => MentionedUsers.Select(x => x.Id).ToImmutableArray(); + /// + IReadOnlyCollection IMessage.Components => Components; + + /// + IMessageInteraction IMessage.Interaction => Interaction; + + /// + IReadOnlyCollection IMessage.Stickers => Stickers; + + internal void AddReaction(SocketReaction reaction) { _reactions.Add(reaction); @@ -200,6 +322,10 @@ namespace Discord.WebSocket { _reactions.Clear(); } + internal void RemoveReactionsForEmote(IEmote emote) + { + _reactions.RemoveAll(x => x.Emote.Equals(emote)); + } /// public Task AddReactionAsync(IEmote emote, RequestOptions options = null) @@ -214,7 +340,11 @@ namespace Discord.WebSocket public Task RemoveAllReactionsAsync(RequestOptions options = null) => MessageHelper.RemoveAllReactionsAsync(this, Discord, options); /// + public Task RemoveAllReactionsForEmoteAsync(IEmote emote, RequestOptions options = null) + => MessageHelper.RemoveAllReactionsForEmoteAsync(this, emote, Discord, options); + /// public IAsyncEnumerable> GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null) => MessageHelper.GetReactionUsersAsync(this, emote, limit, Discord, options); + #endregion } } diff --git a/src/Discord.Net.WebSocket/Entities/Messages/SocketSystemMessage.cs b/src/Discord.Net.WebSocket/Entities/Messages/SocketSystemMessage.cs index d0ce5025b..ec22a7703 100644 --- a/src/Discord.Net.WebSocket/Entities/Messages/SocketSystemMessage.cs +++ b/src/Discord.Net.WebSocket/Entities/Messages/SocketSystemMessage.cs @@ -9,9 +9,6 @@ namespace Discord.WebSocket [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class SocketSystemMessage : SocketMessage, ISystemMessage { - /// - public MessageType Type { get; private set; } - internal SocketSystemMessage(DiscordSocketClient discord, ulong id, ISocketMessageChannel channel, SocketUser author) : base(discord, id, channel, author, MessageSource.System) { @@ -25,8 +22,6 @@ namespace Discord.WebSocket internal override void Update(ClientState state, Model model) { base.Update(state, model); - - Type = model.Type; } private string DebuggerDisplay => $"{Author}: {Content} ({Id}, {Type})"; diff --git a/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs b/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs index e1f0f74dc..e5776a089 100644 --- a/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs +++ b/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs @@ -15,21 +15,26 @@ namespace Discord.WebSocket [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class SocketUserMessage : SocketMessage, IUserMessage { - private bool _isMentioningEveryone, _isTTS, _isPinned, _isSuppressed; + private bool _isMentioningEveryone, _isTTS, _isPinned; private long? _editedTimestampTicks; + private IUserMessage _referencedMessage; private ImmutableArray _attachments = ImmutableArray.Create(); private ImmutableArray _embeds = ImmutableArray.Create(); private ImmutableArray _tags = ImmutableArray.Create(); - + private ImmutableArray _roleMentions = ImmutableArray.Create(); + private ImmutableArray _stickers = ImmutableArray.Create(); + /// public override bool IsTTS => _isTTS; /// public override bool IsPinned => _isPinned; /// - public override bool IsSuppressed => _isSuppressed; + public override bool IsSuppressed => Flags.HasValue && Flags.Value.HasFlag(MessageFlags.SuppressEmbeds); /// public override DateTimeOffset? EditedTimestamp => DateTimeUtils.FromTicks(_editedTimestampTicks); /// + public override bool MentionedEveryone => _isMentioningEveryone; + /// public override IReadOnlyCollection Attachments => _attachments; /// public override IReadOnlyCollection Embeds => _embeds; @@ -38,9 +43,11 @@ namespace Discord.WebSocket /// public override IReadOnlyCollection MentionedChannels => MessageHelper.FilterTagsByValue(TagType.ChannelMention, _tags); /// - public override IReadOnlyCollection MentionedRoles => MessageHelper.FilterTagsByValue(TagType.RoleMention, _tags); + public override IReadOnlyCollection MentionedRoles => _roleMentions; /// - public override IReadOnlyCollection MentionedUsers => MessageHelper.FilterTagsByValue(TagType.UserMention, _tags); + public override IReadOnlyCollection Stickers => _stickers; + /// + public IUserMessage ReferencedMessage => _referencedMessage; internal SocketUserMessage(DiscordSocketClient discord, ulong id, ISocketMessageChannel channel, SocketUser author, MessageSource source) : base(discord, id, channel, author, source) @@ -57,6 +64,8 @@ namespace Discord.WebSocket { base.Update(state, model); + SocketGuild guild = (Channel as SocketGuildChannel)?.Guild; + if (model.IsTextToSpeech.IsSpecified) _isTTS = model.IsTextToSpeech.Value; if (model.Pinned.IsSpecified) @@ -65,10 +74,8 @@ namespace Discord.WebSocket _editedTimestampTicks = model.EditedTimestamp.Value?.UtcTicks; if (model.MentionEveryone.IsSpecified) _isMentioningEveryone = model.MentionEveryone.Value; - if (model.Flags.IsSpecified) - { - _isSuppressed = model.Flags.Value.HasFlag(API.MessageFlags.Suppressed); - } + if (model.RoleMentions.IsSpecified) + _roleMentions = model.RoleMentions.Value.Select(x => guild.GetRole(x)).ToImmutableArray(); if (model.Attachments.IsSpecified) { @@ -98,29 +105,72 @@ namespace Discord.WebSocket _embeds = ImmutableArray.Create(); } - IReadOnlyCollection mentions = ImmutableArray.Create(); //Is passed to ParseTags to get real mention collection - if (model.UserMentions.IsSpecified) + if (model.Content.IsSpecified) { - var value = model.UserMentions.Value; - if (value.Length > 0) + var text = model.Content.Value; + _tags = MessageHelper.ParseTags(text, Channel, guild, MentionedUsers); + model.Content = text; + } + + if (model.ReferencedMessage.IsSpecified && model.ReferencedMessage.Value != null) + { + var refMsg = model.ReferencedMessage.Value; + ulong? webhookId = refMsg.WebhookId.ToNullable(); + SocketUser refMsgAuthor = null; + if (refMsg.Author.IsSpecified) { - var newMentions = ImmutableArray.CreateBuilder(value.Length); - for (int i = 0; i < value.Length; i++) + if (guild != null) { - var val = value[i]; - if (val.Object != null) - newMentions.Add(SocketUnknownUser.Create(Discord, state, val.Object)); + if (webhookId != null) + refMsgAuthor = SocketWebhookUser.Create(guild, state, refMsg.Author.Value, webhookId.Value); + else + refMsgAuthor = guild.GetUser(refMsg.Author.Value.Id); } - mentions = newMentions.ToImmutable(); + else + refMsgAuthor = (Channel as SocketChannel).GetUser(refMsg.Author.Value.Id); + if (refMsgAuthor == null) + refMsgAuthor = SocketUnknownUser.Create(Discord, state, refMsg.Author.Value); } + else + // Message author wasn't specified in the payload, so create a completely anonymous unknown user + refMsgAuthor = new SocketUnknownUser(Discord, id: 0); + _referencedMessage = SocketUserMessage.Create(Discord, state, refMsgAuthor, Channel, refMsg); } - if (model.Content.IsSpecified) + if (model.StickerItems.IsSpecified) { - var text = model.Content.Value; - var guild = (Channel as SocketGuildChannel)?.Guild; - _tags = MessageHelper.ParseTags(text, Channel, guild, mentions); - model.Content = text; + var value = model.StickerItems.Value; + if (value.Length > 0) + { + var stickers = ImmutableArray.CreateBuilder(value.Length); + for (int i = 0; i < value.Length; i++) + { + var stickerItem = value[i]; + SocketSticker sticker = null; + + if (guild != null) + sticker = guild.GetSticker(stickerItem.Id); + + if (sticker == null) + sticker = Discord.GetSticker(stickerItem.Id); + + // if they want to auto resolve + if (Discord.AlwaysResolveStickers) + { + sticker = Task.Run(async () => await Discord.GetStickerAsync(stickerItem.Id).ConfigureAwait(false)).GetAwaiter().GetResult(); + } + + // if its still null, create an unknown + if (sticker == null) + sticker = SocketUnknownSticker.Create(Discord, stickerItem); + + stickers.Add(sticker); + } + + _stickers = stickers.ToImmutable(); + } + else + _stickers = ImmutableArray.Create(); } } @@ -136,9 +186,6 @@ namespace Discord.WebSocket /// public Task UnpinAsync(RequestOptions options = null) => MessageHelper.UnpinAsync(this, Discord, options); - /// - public Task ModifySuppressionAsync(bool suppressEmbeds, RequestOptions options = null) - => MessageHelper.SuppressEmbedsAsync(this, Discord, suppressEmbeds, options); public string Resolve(int startIndex, TagHandling userHandling = TagHandling.Name, TagHandling channelHandling = TagHandling.Name, TagHandling roleHandling = TagHandling.Name, TagHandling everyoneHandling = TagHandling.Ignore, TagHandling emojiHandling = TagHandling.Name) @@ -149,10 +196,10 @@ namespace Discord.WebSocket => MentionUtils.Resolve(this, 0, userHandling, channelHandling, roleHandling, everyoneHandling, emojiHandling); /// - /// This operation may only be called on a channel. + /// This operation may only be called on a channel. public async Task CrosspostAsync(RequestOptions options = null) { - if (!(Channel is SocketNewsChannel)) + if (!(Channel is INewsChannel)) { throw new InvalidOperationException("Publishing (crossposting) is only valid in news channels."); } diff --git a/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs b/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs index b5e26ad78..1e90b8f5c 100644 --- a/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs +++ b/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs @@ -1,6 +1,6 @@ using Discord.Rest; using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; @@ -14,6 +14,7 @@ namespace Discord.WebSocket [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class SocketRole : SocketEntity, IRole { + #region SocketRole /// /// Gets the guild that owns this role. /// @@ -32,10 +33,16 @@ namespace Discord.WebSocket public bool IsMentionable { get; private set; } /// public string Name { get; private set; } + /// + public Emoji Emoji { get; private set; } + /// + public string Icon { get; private set; } /// public GuildPermissions Permissions { get; private set; } /// public int Position { get; private set; } + /// + public RoleTags Tags { get; private set; } /// public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); @@ -48,7 +55,11 @@ namespace Discord.WebSocket public bool IsEveryone => Id == Guild.Id; /// public string Mention => IsEveryone ? "@everyone" : MentionUtils.MentionRole(Id); - public IEnumerable Members + + /// + /// Returns an IEnumerable containing all that have this role. + /// + public IEnumerable Members => Guild.Users.Where(x => x.Roles.Any(r => r.Id == Id)); internal SocketRole(SocketGuild guild, ulong id) @@ -71,6 +82,18 @@ namespace Discord.WebSocket Position = model.Position; Color = new Color(model.Color); Permissions = new GuildPermissions(model.Permissions); + if (model.Tags.IsSpecified) + Tags = model.Tags.Value.ToEntity(); + + if (model.Icon.IsSpecified) + { + Icon = model.Icon.Value; + } + + if (model.Emoji.IsSpecified) + { + Emoji = new Emoji(model.Emoji.Value); + } } /// @@ -80,6 +103,10 @@ namespace Discord.WebSocket public Task DeleteAsync(RequestOptions options = null) => RoleHelper.DeleteAsync(this, Discord, options); + /// + public string GetIconUrl() + => CDN.GetGuildRoleIconUrl(Id, Icon); + /// /// Gets the name of the role. /// @@ -92,9 +119,11 @@ namespace Discord.WebSocket /// public int CompareTo(IRole role) => RoleUtils.Compare(this, role); + #endregion - //IRole + #region IRole /// IGuild IRole.Guild => Guild; + #endregion } } diff --git a/src/Discord.Net.WebSocket/Entities/Stickers/SocketCustomSticker.cs b/src/Discord.Net.WebSocket/Entities/Stickers/SocketCustomSticker.cs new file mode 100644 index 000000000..6a5104012 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Stickers/SocketCustomSticker.cs @@ -0,0 +1,81 @@ +using Discord.Rest; +using System; +using System.Diagnostics; +using System.Threading.Tasks; +using Model = Discord.API.Sticker; + +namespace Discord.WebSocket +{ + /// + /// Represents a custom sticker within a guild received over the gateway. + /// + [DebuggerDisplay(@"{DebuggerDisplay,nq}")] + public class SocketCustomSticker : SocketSticker, ICustomSticker + { + #region SocketCustomSticker + /// + /// Gets the user that uploaded the guild sticker. + /// + /// + /// + /// This may return in the WebSocket implementation due to incomplete user collection in + /// large guilds, or the bot doesn't have the MANAGE_EMOJIS_AND_STICKERS permission. + /// + /// + public SocketGuildUser Author + => AuthorId.HasValue ? Guild.GetUser(AuthorId.Value) : null; + + /// + /// Gets the guild the sticker was created in. + /// + public SocketGuild Guild { get; } + + /// + public ulong? AuthorId { get; set; } + + internal SocketCustomSticker(DiscordSocketClient client, ulong id, SocketGuild guild, ulong? authorId = null) + : base(client, id) + { + Guild = guild; + AuthorId = authorId; + } + + internal static SocketCustomSticker Create(DiscordSocketClient client, Model model, SocketGuild guild, ulong? authorId = null) + { + var entity = new SocketCustomSticker(client, model.Id, guild, authorId); + entity.Update(model); + return entity; + } + + /// + public async Task ModifyAsync(Action func, RequestOptions options = null) + { + if (!Guild.CurrentUser.GuildPermissions.Has(GuildPermission.ManageEmojisAndStickers)) + throw new InvalidOperationException($"Missing permission {nameof(GuildPermission.ManageEmojisAndStickers)}"); + + var model = await GuildHelper.ModifyStickerAsync(Discord, Guild.Id, this, func, options); + + Update(model); + } + + /// + public async Task DeleteAsync(RequestOptions options = null) + { + await GuildHelper.DeleteStickerAsync(Discord, Guild.Id, this, options); + Guild.RemoveSticker(Id); + } + + internal SocketCustomSticker Clone() => MemberwiseClone() as SocketCustomSticker; + + private new string DebuggerDisplay => Guild == null ? base.DebuggerDisplay : $"{Name} in {Guild.Name} ({Id})"; + #endregion + + #region ICustomSticker + ulong? ICustomSticker.AuthorId + => AuthorId; + + IGuild ICustomSticker.Guild + => Guild; + #endregion + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Stickers/SocketSticker.cs b/src/Discord.Net.WebSocket/Entities/Stickers/SocketSticker.cs new file mode 100644 index 000000000..b9c122cce --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Stickers/SocketSticker.cs @@ -0,0 +1,98 @@ +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Diagnostics; +using System.Linq; +using Model = Discord.API.Sticker; + +namespace Discord.WebSocket +{ + /// + /// Represents a general sticker received over the gateway. + /// + [DebuggerDisplay(@"{DebuggerDisplay,nq}")] + public class SocketSticker : SocketEntity, ISticker + { + /// + public virtual ulong PackId { get; private set; } + + /// + public string Name { get; protected set; } + + /// + public virtual string Description { get; private set; } + + /// + public virtual IReadOnlyCollection Tags { get; private set; } + + /// + public virtual StickerType Type { get; private set; } + + /// + public StickerFormatType Format { get; protected set; } + + /// + public virtual bool? IsAvailable { get; protected set; } + + /// + public virtual int? SortOrder { get; private set; } + + /// + public string GetStickerUrl() + => CDN.GetStickerUrl(Id, Format); + + internal SocketSticker(DiscordSocketClient client, ulong id) + : base(client, id) { } + + internal static SocketSticker Create(DiscordSocketClient client, Model model) + { + var entity = model.GuildId.IsSpecified + ? new SocketCustomSticker(client, model.Id, client.GetGuild(model.GuildId.Value), model.User.IsSpecified ? model.User.Value.Id : null) + : new SocketSticker(client, model.Id); + + entity.Update(model); + return entity; + } + + internal virtual void Update(Model model) + { + Name = model.Name; + Description = model.Description; + PackId = model.PackId; + IsAvailable = model.Available; + Format = model.FormatType; + Type = model.Type; + SortOrder = model.SortValue; + + Tags = model.Tags.IsSpecified + ? model.Tags.Value.Split(',').Select(x => x.Trim()).ToImmutableArray() + : ImmutableArray.Create(); + } + + internal string DebuggerDisplay => $"{Name} ({Id})"; + + /// + public override bool Equals(object obj) + { + if (obj is Model stickerModel) + { + return stickerModel.Name == Name && + stickerModel.Description == Description && + stickerModel.FormatType == Format && + stickerModel.Id == Id && + stickerModel.PackId == PackId && + stickerModel.Type == Type && + stickerModel.SortValue == SortOrder && + stickerModel.Available == IsAvailable && + (!stickerModel.Tags.IsSpecified || stickerModel.Tags.Value == string.Join(", ", Tags)); + } + + return base.Equals(obj); + } + + /// + public override int GetHashCode() + { + return base.GetHashCode(); + } + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Stickers/SocketUnknownSticker.cs b/src/Discord.Net.WebSocket/Entities/Stickers/SocketUnknownSticker.cs new file mode 100644 index 000000000..ca7d2d0f1 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Stickers/SocketUnknownSticker.cs @@ -0,0 +1,64 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Threading.Tasks; +using Model = Discord.API.StickerItem; + +namespace Discord.WebSocket +{ + /// + /// Represents an unknown sticker received over the gateway. + /// + [DebuggerDisplay(@"{DebuggerDisplay,nq}")] + public class SocketUnknownSticker : SocketSticker + { + /// + public override IReadOnlyCollection Tags + => null; + + /// + public override string Description + => null; + + /// + public override ulong PackId + => 0; + /// + public override bool? IsAvailable + => null; + + /// + public override int? SortOrder + => null; + + /// + public new StickerType? Type + => null; + + internal SocketUnknownSticker(DiscordSocketClient client, ulong id) + : base(client, id) { } + + internal static SocketUnknownSticker Create(DiscordSocketClient client, Model model) + { + var entity = new SocketUnknownSticker(client, model.Id); + entity.Update(model); + return entity; + } + + internal void Update(Model model) + { + Name = model.Name; + Format = model.FormatType; + } + + /// + /// Attempts to try to find the sticker. + /// + /// + /// The sticker representing this unknown stickers Id, if none is found then . + /// + public Task ResolveAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null) + => Discord.GetStickerAsync(Id, mode, options); + + private new string DebuggerDisplay => $"{Name} ({Id})"; + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketGlobalUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketGlobalUser.cs index 48de7552a..525ae0b34 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketGlobalUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketGlobalUser.cs @@ -1,7 +1,6 @@ using System.Diagnostics; using System.Linq; using Model = Discord.API.User; -using PresenceModel = Discord.API.Presence; namespace Discord.WebSocket { @@ -12,7 +11,6 @@ namespace Discord.WebSocket public override string Username { get; internal set; } public override ushort DiscriminatorValue { get; internal set; } public override string AvatarId { get; internal set; } - public SocketDMChannel DMChannel { get; internal set; } internal override SocketPresence Presence { get; set; } public override bool IsWebhook => false; @@ -48,12 +46,6 @@ namespace Discord.WebSocket discord.RemoveUser(Id); } } - - internal void Update(ClientState state, PresenceModel model) - { - Presence = SocketPresence.Create(model); - DMChannel = state.DMChannels.FirstOrDefault(x => x.Recipient.Id == Id); - } private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Global)"; internal new SocketGlobalUser Clone() => MemberwiseClone() as SocketGlobalUser; diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketGroupUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketGroupUser.cs index 676c0a86c..fe19a41ec 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketGroupUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketGroupUser.cs @@ -1,11 +1,16 @@ +using System; using System.Diagnostics; using Model = Discord.API.User; namespace Discord.WebSocket { + /// + /// Represents a WebSocket-based group user. + /// [DebuggerDisplay("{DebuggerDisplay,nq}")] public class SocketGroupUser : SocketUser, IGroupUser { + #region SocketGroupUser /// /// Gets the group channel of the user. /// @@ -45,8 +50,9 @@ namespace Discord.WebSocket private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Group)"; internal new SocketGroupUser Clone() => MemberwiseClone() as SocketGroupUser; + #endregion - //IVoiceState + #region IVoiceState /// bool IVoiceState.IsDeafened => false; /// @@ -63,5 +69,8 @@ namespace Discord.WebSocket string IVoiceState.VoiceSessionId => null; /// bool IVoiceState.IsStreaming => false; + /// + DateTimeOffset? IVoiceState.RequestToSpeakTimestamp => null; + #endregion } } diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs index e5dbfa01d..1e5a98aeb 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs @@ -18,7 +18,9 @@ namespace Discord.WebSocket [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class SocketGuildUser : SocketUser, IGuildUser { + #region SocketGuildUser private long? _premiumSinceTicks; + private long? _timedOutTicks; private long? _joinedAtTicks; private ImmutableArray _roleIds; @@ -29,7 +31,8 @@ namespace Discord.WebSocket public SocketGuild Guild { get; } /// public string Nickname { get; private set; } - + /// + public string GuildAvatarId { get; private set; } /// public override bool IsBot { get { return GlobalUser.IsBot; } internal set { GlobalUser.IsBot = value; } } /// @@ -38,6 +41,7 @@ namespace Discord.WebSocket public override ushort DiscriminatorValue { get { return GlobalUser.DiscriminatorValue; } internal set { GlobalUser.DiscriminatorValue = value; } } /// public override string AvatarId { get { return GlobalUser.AvatarId; } internal set { GlobalUser.AvatarId = value; } } + /// public GuildPermissions GuildPermissions => new GuildPermissions(Permissions.ResolveGuild(Guild, this)); internal override SocketPresence Presence { get; set; } @@ -56,12 +60,18 @@ namespace Discord.WebSocket public bool IsMuted => VoiceState?.IsMuted ?? false; /// public bool IsStreaming => VoiceState?.IsStreaming ?? false; + /// + public DateTimeOffset? RequestToSpeakTimestamp => VoiceState?.RequestToSpeakTimestamp ?? null; + /// + public bool? IsPending { get; private set; } + + /// public DateTimeOffset? JoinedAt => DateTimeUtils.FromTicks(_joinedAtTicks); /// /// Returns a collection of roles that the user possesses. /// - public IReadOnlyCollection Roles + public IReadOnlyCollection Roles => _roleIds.Select(id => Guild.GetRole(id)).Where(x => x != null).ToReadOnlyCollection(() => _roleIds.Length); /// /// Returns the voice channel the user is in, or null if none. @@ -80,12 +90,23 @@ namespace Discord.WebSocket public AudioInStream AudioStream => Guild.GetAudioStream(Id); /// public DateTimeOffset? PremiumSince => DateTimeUtils.FromTicks(_premiumSinceTicks); + /// + public DateTimeOffset? TimedOutUntil + { + get + { + if (!_timedOutTicks.HasValue || _timedOutTicks.Value < 0) + return null; + else + return DateTimeUtils.FromTicks(_timedOutTicks); + } + } /// /// Returns the position of the user within the role hierarchy. /// /// - /// The returned value equal to the position of the highest role the user has, or + /// The returned value equal to the position of the highest role the user has, or /// if user is the server owner. /// public int Hierarchy @@ -123,12 +144,16 @@ namespace Discord.WebSocket { var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model.User)); entity.Update(state, model); + if (!model.Roles.IsSpecified) + entity.UpdateRoles(new ulong[0]); return entity; } internal static SocketGuildUser Create(SocketGuild guild, ClientState state, PresenceModel model) { var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model.User)); entity.Update(state, model, false); + if (!model.Roles.IsSpecified) + entity.UpdateRoles(new ulong[0]); return entity; } internal void Update(ClientState state, MemberModel model) @@ -138,23 +163,39 @@ namespace Discord.WebSocket _joinedAtTicks = model.JoinedAt.Value.UtcTicks; if (model.Nick.IsSpecified) Nickname = model.Nick.Value; + if (model.Avatar.IsSpecified) + GuildAvatarId = model.Avatar.Value; if (model.Roles.IsSpecified) UpdateRoles(model.Roles.Value); if (model.PremiumSince.IsSpecified) _premiumSinceTicks = model.PremiumSince.Value?.UtcTicks; + if (model.TimedOutUntil.IsSpecified) + _timedOutTicks = model.TimedOutUntil.Value?.UtcTicks; + if (model.Pending.IsSpecified) + IsPending = model.Pending.Value; } internal void Update(ClientState state, PresenceModel model, bool updatePresence) { if (updatePresence) { - Presence = SocketPresence.Create(model); - GlobalUser.Update(state, model); + Update(model); } if (model.Nick.IsSpecified) Nickname = model.Nick.Value; if (model.Roles.IsSpecified) UpdateRoles(model.Roles.Value); + if (model.PremiumSince.IsSpecified) + _premiumSinceTicks = model.PremiumSince.Value?.UtcTicks; } + + internal override void Update(PresenceModel model) + { + Presence ??= new SocketPresence(); + + Presence.Update(model); + GlobalUser.Update(model); + } + private void UpdateRoles(ulong[] roleIds) { var roles = ImmutableArray.CreateBuilder(roleIds.Length + 1); @@ -171,26 +212,46 @@ namespace Discord.WebSocket public Task KickAsync(string reason = null, RequestOptions options = null) => UserHelper.KickAsync(this, Discord, reason, options); /// + public Task AddRoleAsync(ulong roleId, RequestOptions options = null) + => AddRolesAsync(new[] { roleId }, options); + /// public Task AddRoleAsync(IRole role, RequestOptions options = null) - => AddRolesAsync(new[] { role }, options); + => AddRoleAsync(role.Id, options); + /// + public Task AddRolesAsync(IEnumerable roleIds, RequestOptions options = null) + => UserHelper.AddRolesAsync(this, Discord, roleIds, options); /// public Task AddRolesAsync(IEnumerable roles, RequestOptions options = null) - => UserHelper.AddRolesAsync(this, Discord, roles, options); + => AddRolesAsync(roles.Select(x => x.Id), options); + /// + public Task RemoveRoleAsync(ulong roleId, RequestOptions options = null) + => RemoveRolesAsync(new[] { roleId }, options); /// public Task RemoveRoleAsync(IRole role, RequestOptions options = null) - => RemoveRolesAsync(new[] { role }, options); + => RemoveRoleAsync(role.Id, options); + /// + public Task RemoveRolesAsync(IEnumerable roleIds, RequestOptions options = null) + => UserHelper.RemoveRolesAsync(this, Discord, roleIds, options); /// public Task RemoveRolesAsync(IEnumerable roles, RequestOptions options = null) - => UserHelper.RemoveRolesAsync(this, Discord, roles, options); - + => RemoveRolesAsync(roles.Select(x => x.Id)); + /// + public Task SetTimeOutAsync(TimeSpan span, RequestOptions options = null) + => UserHelper.SetTimeoutAsync(this, Discord, span, options); + /// + public Task RemoveTimeOutAsync(RequestOptions options = null) + => UserHelper.RemoveTimeOutAsync(this, Discord, options); /// public ChannelPermissions GetPermissions(IGuildChannel channel) => new ChannelPermissions(Permissions.ResolveChannel(Guild, this, channel, GuildPermissions.RawValue)); + public string GetGuildAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) + => CDN.GetGuildUserAvatarUrl(Id, Guild.Id, GuildAvatarId, size, format); private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Guild)"; internal new SocketGuildUser Clone() => MemberwiseClone() as SocketGuildUser; + #endregion - //IGuildUser + #region IGuildUser /// IGuild IGuildUser.Guild => Guild; /// @@ -201,5 +262,6 @@ namespace Discord.WebSocket //IVoiceState /// IVoiceChannel IVoiceState.VoiceChannel => VoiceChannel; + #endregion } } diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketPresence.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketPresence.cs index 52f111303..5250e15ad 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketPresence.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketPresence.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; +using System.Linq; using Model = Discord.API.Presence; namespace Discord.WebSocket @@ -10,25 +11,37 @@ namespace Discord.WebSocket /// Represents the WebSocket user's presence status. This may include their online status and their activity. /// [DebuggerDisplay(@"{DebuggerDisplay,nq}")] - public struct SocketPresence : IPresence + public class SocketPresence : IPresence { /// - public UserStatus Status { get; } + public UserStatus Status { get; private set; } /// - public IActivity Activity { get; } + public IReadOnlyCollection ActiveClients { get; private set; } /// - public IImmutableSet ActiveClients { get; } - internal SocketPresence(UserStatus status, IActivity activity, IImmutableSet activeClients) + public IReadOnlyCollection Activities { get; private set; } + + internal SocketPresence() { } + internal SocketPresence(UserStatus status, IImmutableSet activeClients, IImmutableList activities) { Status = status; - Activity= activity; - ActiveClients = activeClients; + ActiveClients = activeClients ?? ImmutableHashSet.Empty; + Activities = activities ?? ImmutableList.Empty; } + internal static SocketPresence Create(Model model) { - var clients = ConvertClientTypesDict(model.ClientStatus.GetValueOrDefault()); - return new SocketPresence(model.Status, model.Game?.ToEntity(), clients); + var entity = new SocketPresence(); + entity.Update(model); + return entity; } + + internal void Update(Model model) + { + Status = model.Status; + ActiveClients = ConvertClientTypesDict(model.ClientStatus.GetValueOrDefault()) ?? ImmutableArray.Empty; + Activities = ConvertActivitiesList(model.Activities) ?? ImmutableArray.Empty; + } + /// /// Creates a new containing all of the client types /// where a user is active from the data supplied in the Presence update frame. @@ -40,7 +53,7 @@ namespace Discord.WebSocket /// /// A collection of all s that this user is active. /// - private static IImmutableSet ConvertClientTypesDict(IDictionary clientTypesDict) + private static IReadOnlyCollection ConvertClientTypesDict(IDictionary clientTypesDict) { if (clientTypesDict == null || clientTypesDict.Count == 0) return ImmutableHashSet.Empty; @@ -53,6 +66,25 @@ namespace Discord.WebSocket } return set.ToImmutableHashSet(); } + /// + /// Creates a new containing all the activities + /// that a user has from the data supplied in the Presence update frame. + /// + /// + /// A list of . + /// + /// + /// A list of all that this user currently has available. + /// + private static IImmutableList ConvertActivitiesList(IList activities) + { + if (activities == null || activities.Count == 0) + return ImmutableList.Empty; + var list = new List(); + foreach (var activity in activities) + list.Add(activity.ToEntity()); + return list.ToImmutableList(); + } /// /// Gets the status of the user. @@ -61,8 +93,8 @@ namespace Discord.WebSocket /// A string that resolves to . /// public override string ToString() => Status.ToString(); - private string DebuggerDisplay => $"{Status}{(Activity != null ? $", {Activity.Name}": "")}"; + private string DebuggerDisplay => $"{Status}{(Activities?.FirstOrDefault()?.Name ?? "")}"; - internal SocketPresence Clone() => this; + internal SocketPresence Clone() => MemberwiseClone() as SocketPresence; } } diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketThreadUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketThreadUser.cs new file mode 100644 index 000000000..461cdded0 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketThreadUser.cs @@ -0,0 +1,207 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Model = Discord.API.ThreadMember; +using System.Collections.Immutable; + +namespace Discord.WebSocket +{ + /// + /// Represents a thread user received over the gateway. + /// + public class SocketThreadUser : SocketUser, IGuildUser + { + /// + /// Gets the this user is in. + /// + public SocketThreadChannel Thread { get; private set; } + + /// + /// Gets the timestamp for when this user joined this thread. + /// + public DateTimeOffset ThreadJoinedAt { get; private set; } + + /// + /// Gets the guild this user is in. + /// + public SocketGuild Guild { get; private set; } + + /// + public DateTimeOffset? JoinedAt + => GuildUser.JoinedAt; + + /// + public string Nickname + => GuildUser.Nickname; + + /// + public DateTimeOffset? PremiumSince + => GuildUser.PremiumSince; + + /// + public DateTimeOffset? TimedOutUntil + => GuildUser.TimedOutUntil; + + /// + public bool? IsPending + => GuildUser.IsPending; + /// + public int Hierarchy + => GuildUser.Hierarchy; + + /// + public override string AvatarId + { + get => GuildUser.AvatarId; + internal set => GuildUser.AvatarId = value; + } + /// + public string GuildAvatarId + => GuildUser.GuildAvatarId; + + /// + public override ushort DiscriminatorValue + { + get => GuildUser.DiscriminatorValue; + internal set => GuildUser.DiscriminatorValue = value; + } + + /// + public override bool IsBot + { + get => GuildUser.IsBot; + internal set => GuildUser.IsBot = value; + } + + /// + public override bool IsWebhook + => GuildUser.IsWebhook; + + /// + public override string Username + { + get => GuildUser.Username; + internal set => GuildUser.Username = value; + } + + /// + public bool IsDeafened + => GuildUser.IsDeafened; + + /// + public bool IsMuted + => GuildUser.IsMuted; + + /// + public bool IsSelfDeafened + => GuildUser.IsSelfDeafened; + + /// + public bool IsSelfMuted + => GuildUser.IsSelfMuted; + + /// + public bool IsSuppressed + => GuildUser.IsSuppressed; + + /// + public IVoiceChannel VoiceChannel + => GuildUser.VoiceChannel; + + /// + public string VoiceSessionId + => GuildUser.VoiceSessionId; + + /// + public bool IsStreaming + => GuildUser.IsStreaming; + + /// + public DateTimeOffset? RequestToSpeakTimestamp + => GuildUser.RequestToSpeakTimestamp; + + private SocketGuildUser GuildUser { get; set; } + + internal SocketThreadUser(SocketGuild guild, SocketThreadChannel thread, SocketGuildUser member) + : base(guild.Discord, member.Id) + { + Thread = thread; + Guild = guild; + GuildUser = member; + } + + internal static SocketThreadUser Create(SocketGuild guild, SocketThreadChannel thread, Model model, SocketGuildUser member) + { + var entity = new SocketThreadUser(guild, thread, member); + entity.Update(model); + return entity; + } + + internal void Update(Model model) + { + ThreadJoinedAt = model.JoinTimestamp; + } + + /// + public ChannelPermissions GetPermissions(IGuildChannel channel) => GuildUser.GetPermissions(channel); + + /// + public Task KickAsync(string reason = null, RequestOptions options = null) => GuildUser.KickAsync(reason, options); + + /// + public Task ModifyAsync(Action func, RequestOptions options = null) => GuildUser.ModifyAsync(func, options); + + /// + public Task AddRoleAsync(ulong roleId, RequestOptions options = null) => GuildUser.AddRoleAsync(roleId, options); + + /// + public Task AddRoleAsync(IRole role, RequestOptions options = null) => GuildUser.AddRoleAsync(role, options); + + /// + public Task AddRolesAsync(IEnumerable roleIds, RequestOptions options = null) => GuildUser.AddRolesAsync(roleIds, options); + + /// + public Task AddRolesAsync(IEnumerable roles, RequestOptions options = null) => GuildUser.AddRolesAsync(roles, options); + + /// + public Task RemoveRoleAsync(ulong roleId, RequestOptions options = null) => GuildUser.RemoveRoleAsync(roleId, options); + + /// + public Task RemoveRoleAsync(IRole role, RequestOptions options = null) => GuildUser.RemoveRoleAsync(role, options); + + /// + public Task RemoveRolesAsync(IEnumerable roleIds, RequestOptions options = null) => GuildUser.RemoveRolesAsync(roleIds, options); + + /// + public Task RemoveRolesAsync(IEnumerable roles, RequestOptions options = null) => GuildUser.RemoveRolesAsync(roles, options); + /// + public Task SetTimeOutAsync(TimeSpan span, RequestOptions options = null) => GuildUser.SetTimeOutAsync(span, options); + + /// + public Task RemoveTimeOutAsync(RequestOptions options = null) => GuildUser.RemoveTimeOutAsync(options); + /// + GuildPermissions IGuildUser.GuildPermissions => GuildUser.GuildPermissions; + + /// + IGuild IGuildUser.Guild => Guild; + + /// + ulong IGuildUser.GuildId => Guild.Id; + + /// + IReadOnlyCollection IGuildUser.RoleIds => GuildUser.Roles.Select(x => x.Id).ToImmutableArray(); + + string IGuildUser.GetGuildAvatarUrl(ImageFormat format, ushort size) => GuildUser.GetGuildAvatarUrl(format, size); + + internal override SocketGlobalUser GlobalUser => GuildUser.GlobalUser; + + internal override SocketPresence Presence { get => GuildUser.Presence; set => GuildUser.Presence = value; } + + /// + /// Gets the guild user of this thread user. + /// + /// + public static explicit operator SocketGuildUser(SocketThreadUser user) => user.GuildUser; + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketUnknownUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketUnknownUser.cs index 840a1c30b..a15f7e747 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketUnknownUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketUnknownUser.cs @@ -19,9 +19,10 @@ namespace Discord.WebSocket public override ushort DiscriminatorValue { get; internal set; } /// public override string AvatarId { get; internal set; } + /// public override bool IsBot { get; internal set; } - + /// public override bool IsWebhook => false; /// diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs index b830ce79c..b14993991 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Threading.Tasks; using Discord.Rest; using Model = Discord.API.User; +using PresenceModel = Discord.API.Presence; namespace Discord.WebSocket { @@ -26,6 +27,8 @@ namespace Discord.WebSocket public abstract string AvatarId { get; internal set; } /// public abstract bool IsWebhook { get; } + /// + public UserProperties? PublicFlags { get; private set; } internal abstract SocketGlobalUser GlobalUser { get; } internal abstract SocketPresence Presence { get; set; } @@ -36,11 +39,11 @@ namespace Discord.WebSocket /// public string Mention => MentionUtils.MentionUser(Id); /// - public IActivity Activity => Presence.Activity; - /// public UserStatus Status => Presence.Status; /// - public IImmutableSet ActiveClients => Presence.ActiveClients ?? ImmutableHashSet.Empty; + public IReadOnlyCollection ActiveClients => Presence.ActiveClients ?? ImmutableHashSet.Empty; + /// + public IReadOnlyCollection Activities => Presence.Activities ?? ImmutableList.Empty; /// /// Gets mutual guilds shared with this user. /// @@ -56,6 +59,7 @@ namespace Discord.WebSocket } internal virtual bool Update(ClientState state, Model model) { + Presence ??= new SocketPresence(); bool hasChanges = false; if (model.Avatar.IsSpecified && model.Avatar.Value != AvatarId) { @@ -81,12 +85,23 @@ namespace Discord.WebSocket Username = model.Username.Value; hasChanges = true; } + if (model.PublicFlags.IsSpecified && model.PublicFlags.Value != PublicFlags) + { + PublicFlags = model.PublicFlags.Value; + hasChanges = true; + } return hasChanges; } + internal virtual void Update(PresenceModel model) + { + Presence ??= new SocketPresence(); + Presence.Update(model); + } + /// - public async Task GetOrCreateDMChannelAsync(RequestOptions options = null) - => GlobalUser.DMChannel ?? await UserHelper.CreateDMChannelAsync(this, Discord, options).ConfigureAwait(false) as IDMChannel; + public async Task CreateDMChannelAsync(RequestOptions options = null) + => await UserHelper.CreateDMChannelAsync(this, Discord, options).ConfigureAwait(false); /// public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) @@ -102,8 +117,8 @@ namespace Discord.WebSocket /// /// The full name of the user. /// - public override string ToString() => $"{Username}#{Discriminator}"; - private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; + public override string ToString() => Format.UsernameAndDiscriminator(this); + private string DebuggerDisplay => $"{Format.UsernameAndDiscriminator(this)} ({Id}{(IsBot ? ", Bot" : "")})"; internal SocketUser Clone() => MemberwiseClone() as SocketUser; } } diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketVoiceState.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketVoiceState.cs index 5bf36e796..816a839fc 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketVoiceState.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketVoiceState.cs @@ -13,7 +13,7 @@ namespace Discord.WebSocket /// /// Initializes a default with everything set to null or false. /// - public static readonly SocketVoiceState Default = new SocketVoiceState(null, null, false, false, false, false, false, false); + public static readonly SocketVoiceState Default = new SocketVoiceState(null, null, null, false, false, false, false, false, false); [Flags] private enum Flags : byte @@ -35,6 +35,8 @@ namespace Discord.WebSocket public SocketVoiceChannel VoiceChannel { get; } /// public string VoiceSessionId { get; } + /// + public DateTimeOffset? RequestToSpeakTimestamp { get; private set; } /// public bool IsMuted => (_voiceStates & Flags.Muted) != 0; @@ -48,11 +50,13 @@ namespace Discord.WebSocket public bool IsSelfDeafened => (_voiceStates & Flags.SelfDeafened) != 0; /// public bool IsStreaming => (_voiceStates & Flags.SelfStream) != 0; + - internal SocketVoiceState(SocketVoiceChannel voiceChannel, string sessionId, bool isSelfMuted, bool isSelfDeafened, bool isMuted, bool isDeafened, bool isSuppressed, bool isStream) + internal SocketVoiceState(SocketVoiceChannel voiceChannel, DateTimeOffset? requestToSpeak, string sessionId, bool isSelfMuted, bool isSelfDeafened, bool isMuted, bool isDeafened, bool isSuppressed, bool isStream) { VoiceChannel = voiceChannel; VoiceSessionId = sessionId; + RequestToSpeakTimestamp = requestToSpeak; Flags voiceStates = Flags.Normal; if (isSelfMuted) @@ -71,7 +75,7 @@ namespace Discord.WebSocket } internal static SocketVoiceState Create(SocketVoiceChannel voiceChannel, Model model) { - return new SocketVoiceState(voiceChannel, model.SessionId, model.SelfMute, model.SelfDeaf, model.Mute, model.Deaf, model.Suppress, model.SelfStream); + return new SocketVoiceState(voiceChannel, model.RequestToSpeakTimestamp.IsSpecified ? model.RequestToSpeakTimestamp.Value : null, model.SessionId, model.SelfMute, model.SelfDeaf, model.Mute, model.Deaf, model.Suppress, model.SelfStream); } /// diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs index 8819fe1b4..cf820b80e 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs @@ -13,6 +13,7 @@ namespace Discord.WebSocket [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class SocketWebhookUser : SocketUser, IWebhookUser { + #region SocketWebhookUser /// Gets the guild of this webhook. public SocketGuild Guild { get; } /// @@ -24,6 +25,8 @@ namespace Discord.WebSocket public override ushort DiscriminatorValue { get; internal set; } /// public override string AvatarId { get; internal set; } + + /// public override bool IsBot { get; internal set; } @@ -31,7 +34,7 @@ namespace Discord.WebSocket public override bool IsWebhook => true; /// internal override SocketPresence Presence { get { return new SocketPresence(UserStatus.Offline, null, null); } set { } } - internal override SocketGlobalUser GlobalUser => + internal override SocketGlobalUser GlobalUser => throw new NotSupportedException(); internal SocketWebhookUser(SocketGuild guild, ulong id, ulong webhookId) @@ -49,9 +52,9 @@ namespace Discord.WebSocket private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Webhook)"; internal new SocketWebhookUser Clone() => MemberwiseClone() as SocketWebhookUser; +#endregion - - //IGuildUser + #region IGuildUser /// IGuild IGuildUser.Guild => Guild; /// @@ -63,43 +66,82 @@ namespace Discord.WebSocket /// string IGuildUser.Nickname => null; /// + string IGuildUser.GuildAvatarId => null; + /// + string IGuildUser.GetGuildAvatarUrl(ImageFormat format, ushort size) => null; + /// DateTimeOffset? IGuildUser.PremiumSince => null; /// + DateTimeOffset? IGuildUser.TimedOutUntil => null; + /// + bool? IGuildUser.IsPending => null; + /// + int IGuildUser.Hierarchy => 0; + /// GuildPermissions IGuildUser.GuildPermissions => GuildPermissions.Webhook; /// ChannelPermissions IGuildUser.GetPermissions(IGuildChannel channel) => Permissions.ToChannelPerms(channel, GuildPermissions.Webhook.RawValue); /// /// Webhook users cannot be kicked. - Task IGuildUser.KickAsync(string reason, RequestOptions options) => + Task IGuildUser.KickAsync(string reason, RequestOptions options) => throw new NotSupportedException("Webhook users cannot be kicked."); /// /// Webhook users cannot be modified. - Task IGuildUser.ModifyAsync(Action func, RequestOptions options) => + Task IGuildUser.ModifyAsync(Action func, RequestOptions options) => throw new NotSupportedException("Webhook users cannot be modified."); /// /// Roles are not supported on webhook users. - Task IGuildUser.AddRoleAsync(IRole role, RequestOptions options) => + Task IGuildUser.AddRoleAsync(ulong roleId, RequestOptions options) => throw new NotSupportedException("Roles are not supported on webhook users."); /// /// Roles are not supported on webhook users. - Task IGuildUser.AddRolesAsync(IEnumerable roles, RequestOptions options) => + Task IGuildUser.AddRoleAsync(IRole role, RequestOptions options) => throw new NotSupportedException("Roles are not supported on webhook users."); /// /// Roles are not supported on webhook users. - Task IGuildUser.RemoveRoleAsync(IRole role, RequestOptions options) => + Task IGuildUser.AddRolesAsync(IEnumerable roleIds, RequestOptions options) => throw new NotSupportedException("Roles are not supported on webhook users."); /// /// Roles are not supported on webhook users. - Task IGuildUser.RemoveRolesAsync(IEnumerable roles, RequestOptions options) => + Task IGuildUser.AddRolesAsync(IEnumerable roles, RequestOptions options) => throw new NotSupportedException("Roles are not supported on webhook users."); - //IVoiceState + /// + /// Roles are not supported on webhook users. + Task IGuildUser.RemoveRoleAsync(ulong roleId, RequestOptions options) => + throw new NotSupportedException("Roles are not supported on webhook users."); + + /// + /// Roles are not supported on webhook users. + Task IGuildUser.RemoveRoleAsync(IRole role, RequestOptions options) => + throw new NotSupportedException("Roles are not supported on webhook users."); + + /// + /// Roles are not supported on webhook users. + Task IGuildUser.RemoveRolesAsync(IEnumerable roles, RequestOptions options) => + throw new NotSupportedException("Roles are not supported on webhook users."); + + /// + /// Roles are not supported on webhook users. + Task IGuildUser.RemoveRolesAsync(IEnumerable roles, RequestOptions options) => + throw new NotSupportedException("Roles are not supported on webhook users."); + /// + /// Timeouts are not supported on webhook users. + Task IGuildUser.SetTimeOutAsync(TimeSpan span, RequestOptions options) => + throw new NotSupportedException("Timeouts are not supported on webhook users."); + /// + /// Timeouts are not supported on webhook users. + Task IGuildUser.RemoveTimeOutAsync(RequestOptions options) => + throw new NotSupportedException("Timeouts are not supported on webhook users."); + #endregion + + #region IVoiceState /// bool IVoiceState.IsDeafened => false; /// @@ -116,5 +158,8 @@ namespace Discord.WebSocket string IVoiceState.VoiceSessionId => null; /// bool IVoiceState.IsStreaming => false; + /// + DateTimeOffset? IVoiceState.RequestToSpeakTimestamp => null; + #endregion } } diff --git a/src/Discord.Net.WebSocket/Extensions/EntityExtensions.cs b/src/Discord.Net.WebSocket/Extensions/EntityExtensions.cs index cbe575075..46f5c1a26 100644 --- a/src/Discord.Net.WebSocket/Extensions/EntityExtensions.cs +++ b/src/Discord.Net.WebSocket/Extensions/EntityExtensions.cs @@ -9,7 +9,7 @@ namespace Discord.WebSocket { public static IActivity ToEntity(this API.Game model) { - // Custom Status Game + #region Custom Status Game if (model.Id.IsSpecified && model.Id.Value == "custom") { return new CustomStatusGame() @@ -21,13 +21,14 @@ namespace Discord.WebSocket CreatedAt = DateTimeOffset.FromUnixTimeMilliseconds(model.CreatedAt.Value), }; } + #endregion - // Spotify Game + #region Spotify Game if (model.SyncId.IsSpecified) { var assets = model.Assets.GetValueOrDefault()?.ToEntity(); string albumText = assets?[1]?.Text; - string albumArtId = assets?[1]?.ImageId?.Replace("spotify:",""); + string albumArtId = assets?[1]?.ImageId?.Replace("spotify:", ""); var timestamps = model.Timestamps.IsSpecified ? model.Timestamps.Value.ToEntity() : null; return new SpotifyGame { @@ -37,7 +38,7 @@ namespace Discord.WebSocket TrackUrl = CDN.GetSpotifyDirectUrl(model.SyncId.Value), AlbumTitle = albumText, TrackTitle = model.Details.GetValueOrDefault(), - Artists = model.State.GetValueOrDefault()?.Split(';').Select(x=>x?.Trim()).ToImmutableArray(), + Artists = model.State.GetValueOrDefault()?.Split(';').Select(x => x?.Trim()).ToImmutableArray(), StartedAt = timestamps?.Start, EndsAt = timestamps?.End, Duration = timestamps?.End - timestamps?.Start, @@ -46,8 +47,9 @@ namespace Discord.WebSocket Flags = model.Flags.GetValueOrDefault(), }; } + #endregion - // Rich Game + #region Rich Game if (model.ApplicationId.IsSpecified) { ulong appId = model.ApplicationId.Value; @@ -66,7 +68,9 @@ namespace Discord.WebSocket Flags = model.Flags.GetValueOrDefault() }; } - // Stream Game + #endregion + + #region Stream Game if (model.StreamUrl.IsSpecified) { return new StreamingGame( @@ -77,10 +81,13 @@ namespace Discord.WebSocket Details = model.Details.GetValueOrDefault() }; } - // Normal Game + #endregion + + #region Normal Game return new Game(model.Name, model.Type.GetValueOrDefault() ?? ActivityType.Playing, model.Flags.IsSpecified ? model.Flags.Value : ActivityProperties.None, model.Details.GetValueOrDefault()); + #endregion } // (Small, Large) diff --git a/src/Discord.Net.WebSocket/GatewayReconnectException.cs b/src/Discord.Net.WebSocket/GatewayReconnectException.cs index 1a8024558..c5b15e007 100644 --- a/src/Discord.Net.WebSocket/GatewayReconnectException.cs +++ b/src/Discord.Net.WebSocket/GatewayReconnectException.cs @@ -3,18 +3,15 @@ using System; namespace Discord.WebSocket { /// - /// An exception thrown when the gateway client has been requested to - /// reconnect. + /// The exception thrown when the gateway client has been requested to reconnect. /// public class GatewayReconnectException : Exception { /// - /// Creates a new instance of the - /// type. + /// Initializes a new instance of the class with the reconnection + /// message. /// - /// - /// The reason why the gateway has been requested to reconnect. - /// + /// The reason why the gateway has been requested to reconnect. public GatewayReconnectException(string message) : base(message) { } diff --git a/src/Discord.Net.WebSocket/Interactions/ShardedInteractionContext.cs b/src/Discord.Net.WebSocket/Interactions/ShardedInteractionContext.cs new file mode 100644 index 000000000..ac0524172 --- /dev/null +++ b/src/Discord.Net.WebSocket/Interactions/ShardedInteractionContext.cs @@ -0,0 +1,43 @@ +using Discord.WebSocket; + +namespace Discord.Interactions +{ + /// + /// The sharded variant of . + /// + public class ShardedInteractionContext : SocketInteractionContext, IInteractionContext + where TInteraction : SocketInteraction + { + /// + /// Gets the that the command will be executed with. + /// + public new DiscordShardedClient Client { get; } + + /// + /// Initializes a . + /// + /// The underlying client. + /// The underlying interaction. + public ShardedInteractionContext (DiscordShardedClient client, TInteraction interaction) + : base(client.GetShard(GetShardId(client, ( interaction.User as SocketGuildUser )?.Guild)), interaction) + { + Client = client; + } + + private static int GetShardId (DiscordShardedClient client, IGuild guild) + => guild == null ? 0 : client.GetShardIdFor(guild); + } + + /// + /// The sharded variant of . + /// + public class ShardedInteractionContext : ShardedInteractionContext + { + /// + /// Initializes a . + /// + /// The underlying client. + /// The underlying interaction. + public ShardedInteractionContext(DiscordShardedClient client, SocketInteraction interaction) : base(client, interaction) { } + } +} diff --git a/src/Discord.Net.WebSocket/Interactions/SocketInteractionContext.cs b/src/Discord.Net.WebSocket/Interactions/SocketInteractionContext.cs new file mode 100644 index 000000000..4cd9ef264 --- /dev/null +++ b/src/Discord.Net.WebSocket/Interactions/SocketInteractionContext.cs @@ -0,0 +1,82 @@ +using Discord.WebSocket; + +namespace Discord.Interactions +{ + /// + /// Represents a Web-Socket based context of an . + /// + public class SocketInteractionContext : IInteractionContext + where TInteraction : SocketInteraction + { + /// + /// Gets the that the command will be executed with. + /// + public DiscordSocketClient Client { get; } + + /// + /// Gets the the command originated from. + /// + /// + /// Will be null if the command is from a DM Channel. + /// + public SocketGuild Guild { get; } + + /// + /// Gets the the command originated from. + /// + public ISocketMessageChannel Channel { get; } + + /// + /// Gets the who executed the command. + /// + public SocketUser User { get; } + + /// + /// Gets the the command was recieved with. + /// + public TInteraction Interaction { get; } + + /// + /// Initializes a new . + /// + /// The underlying client. + /// The underlying interaction. + public SocketInteractionContext(DiscordSocketClient client, TInteraction interaction) + { + Client = client; + Channel = interaction.Channel; + Guild = (interaction.User as SocketGuildUser)?.Guild; + User = interaction.User; + Interaction = interaction; + } + + // IInteractionContext + /// + IDiscordClient IInteractionContext.Client => Client; + + /// + IGuild IInteractionContext.Guild => Guild; + + /// + IMessageChannel IInteractionContext.Channel => Channel; + + /// + IUser IInteractionContext.User => User; + + /// + IDiscordInteraction IInteractionContext.Interaction => Interaction; + } + + /// + /// Represents a Web-Socket based context of an + /// + public class SocketInteractionContext : SocketInteractionContext + { + /// + /// Initializes a new + /// + /// The underlying client + /// The underlying interaction + public SocketInteractionContext(DiscordSocketClient client, SocketInteraction interaction) : base(client, interaction) { } + } +} diff --git a/src/Discord.Net.WebSocket/Net/DefaultWebSocketClient.cs b/src/Discord.Net.WebSocket/Net/DefaultWebSocketClient.cs index 4723ae57a..82e2f0573 100644 --- a/src/Discord.Net.WebSocket/Net/DefaultWebSocketClient.cs +++ b/src/Discord.Net.WebSocket/Net/DefaultWebSocketClient.cs @@ -108,11 +108,11 @@ namespace Discord.Net.WebSockets } private async Task DisconnectInternalAsync(int closeCode = 1000, bool isDisposing = false) { + _isDisconnecting = true; + try { _disconnectTokenSource.Cancel(false); } catch { } - _isDisconnecting = true; - if (_client != null) { if (!isDisposing) @@ -166,7 +166,14 @@ namespace Discord.Net.WebSockets public async Task SendAsync(byte[] data, int index, int count, bool isText) { - await _lock.WaitAsync().ConfigureAwait(false); + try + { + await _lock.WaitAsync(_cancelToken).ConfigureAwait(false); + } + catch (TaskCanceledException) + { + return; + } try { if (_client == null) return; @@ -201,7 +208,7 @@ namespace Discord.Net.WebSockets { while (!cancelToken.IsCancellationRequested) { - WebSocketReceiveResult socketResult = await _client.ReceiveAsync(buffer, CancellationToken.None).ConfigureAwait(false); + WebSocketReceiveResult socketResult = await _client.ReceiveAsync(buffer, cancelToken).ConfigureAwait(false); byte[] result; int resultCount; diff --git a/src/Discord.Net.Webhook/Discord.Net.Webhook.csproj b/src/Discord.Net.Webhook/Discord.Net.Webhook.csproj index f1db66363..df920b7dc 100644 --- a/src/Discord.Net.Webhook/Discord.Net.Webhook.csproj +++ b/src/Discord.Net.Webhook/Discord.Net.Webhook.csproj @@ -1,10 +1,11 @@ + Discord.Net.Webhook Discord.Webhook A core Discord.Net library containing the Webhook client and models. - netstandard2.0;netstandard2.1 + net6.0;net5.0;netstandard2.0;netstandard2.1 diff --git a/src/Discord.Net.Webhook/DiscordWebhookClient.cs b/src/Discord.Net.Webhook/DiscordWebhookClient.cs index 353345ded..cb24f9ea1 100644 --- a/src/Discord.Net.Webhook/DiscordWebhookClient.cs +++ b/src/Discord.Net.Webhook/DiscordWebhookClient.cs @@ -33,7 +33,7 @@ namespace Discord.Webhook : this(webhookUrl, new DiscordRestConfig()) { } // regex pattern to match webhook urls - private static Regex WebhookUrlRegex = new Regex(@"^.*(discord|discordapp)\.com\/api\/webhooks\/([\d]+)\/([a-z0-9_-]+)$", RegexOptions.Compiled | RegexOptions.IgnoreCase); + private static Regex WebhookUrlRegex = new Regex(@"^.*(discord|discordapp)\.com\/api\/webhooks\/([\d]+)\/([a-z0-9_-]+)$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); /// Creates a new Webhook Discord client. public DiscordWebhookClient(ulong webhookId, string webhookToken, DiscordRestConfig config) @@ -60,8 +60,7 @@ namespace Discord.Webhook /// Thrown if the is null or whitespace. public DiscordWebhookClient(string webhookUrl, DiscordRestConfig config) : this(config) { - string token; - ParseWebhookUrl(webhookUrl, out _webhookId, out token); + ParseWebhookUrl(webhookUrl, out _webhookId, out string token); ApiClient.LoginAsync(TokenType.Webhook, token).GetAwaiter().GetResult(); Webhook = WebhookClientHelper.GetWebhookAsync(this, _webhookId).GetAwaiter().GetResult(); } @@ -74,12 +73,12 @@ namespace Discord.Webhook _restLogger = LogManager.CreateLogger("Rest"); - ApiClient.RequestQueue.RateLimitTriggered += async (id, info) => + ApiClient.RequestQueue.RateLimitTriggered += async (id, info, endpoint) => { if (info == null) - await _restLogger.VerboseAsync($"Preemptive Rate limit triggered: {id ?? "null"}").ConfigureAwait(false); + await _restLogger.VerboseAsync($"Preemptive Rate limit triggered: {endpoint} {(id.IsHashBucket ? $"(Bucket: {id.BucketHash})" : "")}").ConfigureAwait(false); else - await _restLogger.WarningAsync($"Rate limit triggered: {id ?? "null"}").ConfigureAwait(false); + await _restLogger.WarningAsync($"Rate limit triggered: {endpoint} {(id.IsHashBucket ? $"(Bucket: {id.BucketHash})" : "")}").ConfigureAwait(false); }; ApiClient.SentRequest += async (method, endpoint, millis) => await _restLogger.VerboseAsync($"{method} {endpoint}: {millis} ms").ConfigureAwait(false); } @@ -88,19 +87,71 @@ namespace Discord.Webhook /// Sends a message to the channel for this webhook. /// Returns the ID of the created message. public Task SendMessageAsync(string text = null, bool isTTS = false, IEnumerable embeds = null, - string username = null, string avatarUrl = null, RequestOptions options = null) - => WebhookClientHelper.SendMessageAsync(this, text, isTTS, embeds, username, avatarUrl, options); + string username = null, string avatarUrl = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageComponent components = null) + => WebhookClientHelper.SendMessageAsync(this, text, isTTS, embeds, username, avatarUrl, allowedMentions, options, components); + + /// + /// Modifies a message posted using this webhook. + /// + /// + /// This method can only modify messages that were sent using the same webhook. + /// + /// ID of the modified message. + /// A delegate containing the properties to modify the message with. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + public Task ModifyMessageAsync(ulong messageId, Action func, RequestOptions options = null) + => WebhookClientHelper.ModifyMessageAsync(this, messageId, func, options); + + /// + /// Deletes a message posted using this webhook. + /// + /// + /// This method can only delete messages that were sent using the same webhook. + /// + /// ID of the deleted message. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous deletion operation. + /// + public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) + => WebhookClientHelper.DeleteMessageAsync(this, messageId, options); /// Sends a message to the channel for this webhook with an attachment. /// Returns the ID of the created message. public Task SendFileAsync(string filePath, string text, bool isTTS = false, - IEnumerable embeds = null, string username = null, string avatarUrl = null, RequestOptions options = null, bool isSpoiler = false) - => WebhookClientHelper.SendFileAsync(this, filePath, text, isTTS, embeds, username, avatarUrl, options, isSpoiler); + IEnumerable embeds = null, string username = null, string avatarUrl = null, + RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, + MessageComponent components = null) + => WebhookClientHelper.SendFileAsync(this, filePath, text, isTTS, embeds, username, avatarUrl, + allowedMentions, options, isSpoiler, components); /// Sends a message to the channel for this webhook with an attachment. /// Returns the ID of the created message. public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, - IEnumerable embeds = null, string username = null, string avatarUrl = null, RequestOptions options = null, bool isSpoiler = false) - => WebhookClientHelper.SendFileAsync(this, stream, filename, text, isTTS, embeds, username, avatarUrl, options, isSpoiler); + IEnumerable embeds = null, string username = null, string avatarUrl = null, + RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, + MessageComponent components = null) + => WebhookClientHelper.SendFileAsync(this, stream, filename, text, isTTS, embeds, username, + avatarUrl, allowedMentions, options, isSpoiler, components); + + /// Sends a message to the channel for this webhook with an attachment. + /// Returns the ID of the created message. + public Task SendFileAsync(FileAttachment attachment, string text, bool isTTS = false, + IEnumerable embeds = null, string username = null, string avatarUrl = null, + RequestOptions options = null, AllowedMentions allowedMentions = null, MessageComponent components = null) + => WebhookClientHelper.SendFileAsync(this, attachment, text, isTTS, embeds, username, + avatarUrl, allowedMentions, components, options); + + /// Sends a message to the channel for this webhook with an attachment. + /// Returns the ID of the created message. + public Task SendFilesAsync(IEnumerable attachments, string text, bool isTTS = false, + IEnumerable embeds = null, string username = null, string avatarUrl = null, + RequestOptions options = null, AllowedMentions allowedMentions = null, MessageComponent components = null) + => WebhookClientHelper.SendFilesAsync(this, attachments, text, isTTS, embeds, username, avatarUrl, + allowedMentions, components, options); + /// Modifies the properties of this webhook. public Task ModifyWebhookAsync(Action func, RequestOptions options = null) diff --git a/src/Discord.Net.Webhook/Entities/Messages/WebhookMessageProperties.cs b/src/Discord.Net.Webhook/Entities/Messages/WebhookMessageProperties.cs new file mode 100644 index 000000000..ca2ff10a0 --- /dev/null +++ b/src/Discord.Net.Webhook/Entities/Messages/WebhookMessageProperties.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; + +namespace Discord.Webhook +{ + /// + /// Properties that are used to modify an Webhook message with the specified changes. + /// + public class WebhookMessageProperties + { + /// + /// Gets or sets the content of the message. + /// + /// + /// This must be less than the constant defined by . + /// + public Optional Content { get; set; } + /// + /// Gets or sets the embed array that the message should display. + /// + public Optional> Embeds { get; set; } + /// + /// Gets or sets the allowed mentions of the message. + /// + public Optional AllowedMentions { get; set; } + /// + /// Gets or sets the components that the message should display. + /// + public Optional Components { get; set; } + } +} diff --git a/src/Discord.Net.Webhook/Entities/Webhooks/RestInternalWebhook.cs b/src/Discord.Net.Webhook/Entities/Webhooks/RestInternalWebhook.cs index 60cb89ee2..2a5c4786e 100644 --- a/src/Discord.Net.Webhook/Entities/Webhooks/RestInternalWebhook.cs +++ b/src/Discord.Net.Webhook/Entities/Webhooks/RestInternalWebhook.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Diagnostics; using System.Threading.Tasks; using Model = Discord.API.Webhook; @@ -11,12 +11,13 @@ namespace Discord.Webhook private DiscordWebhookClient _client; public ulong Id { get; } - public ulong ChannelId { get; } public string Token { get; } + public ulong ChannelId { get; private set; } public string Name { get; private set; } public string AvatarId { get; private set; } public ulong? GuildId { get; private set; } + public ulong? ApplicationId { get; private set; } public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); @@ -36,12 +37,16 @@ namespace Discord.Webhook internal void Update(Model model) { + if (ChannelId != model.ChannelId) + ChannelId = model.ChannelId; if (model.Avatar.IsSpecified) AvatarId = model.Avatar.Value; if (model.GuildId.IsSpecified) GuildId = model.GuildId.Value; if (model.Name.IsSpecified) Name = model.Name.Value; + + ApplicationId = model.ApplicationId; } public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) diff --git a/src/Discord.Net.Webhook/WebhookClientHelper.cs b/src/Discord.Net.Webhook/WebhookClientHelper.cs index 311d58bda..a9d5a25da 100644 --- a/src/Discord.Net.Webhook/WebhookClientHelper.cs +++ b/src/Discord.Net.Webhook/WebhookClientHelper.cs @@ -20,37 +20,128 @@ namespace Discord.Webhook throw new InvalidOperationException("Could not find a webhook with the supplied credentials."); return RestInternalWebhook.Create(client, model); } - public static async Task SendMessageAsync(DiscordWebhookClient client, - string text, bool isTTS, IEnumerable embeds, string username, string avatarUrl, RequestOptions options) + public static async Task SendMessageAsync(DiscordWebhookClient client, + string text, bool isTTS, IEnumerable embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options, MessageComponent components) { - var args = new CreateWebhookMessageParams(text) { IsTTS = isTTS }; + var args = new CreateWebhookMessageParams + { + Content = text, + IsTTS = isTTS + }; + if (embeds != null) args.Embeds = embeds.Select(x => x.ToModel()).ToArray(); if (username != null) args.Username = username; if (avatarUrl != null) args.AvatarUrl = avatarUrl; + if (allowedMentions != null) + args.AllowedMentions = allowedMentions.ToModel(); + if (components != null) + args.Components = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray(); var model = await client.ApiClient.CreateWebhookMessageAsync(client.Webhook.Id, args, options: options).ConfigureAwait(false); return model.Id; } - public static async Task SendFileAsync(DiscordWebhookClient client, string filePath, string text, bool isTTS, - IEnumerable embeds, string username, string avatarUrl, RequestOptions options, bool isSpoiler) + public static async Task ModifyMessageAsync(DiscordWebhookClient client, ulong messageId, + Action func, RequestOptions options) + { + var args = new WebhookMessageProperties(); + func(args); + + if (args.AllowedMentions.IsSpecified) + { + var allowedMentions = args.AllowedMentions.Value; + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), + "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), + "A max of 100 user Ids are allowed."); + + // check that user flag and user Id list are exclusive, same with role flag and role Id list + if (allowedMentions?.AllowedTypes != null) + { + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) && + allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) + { + throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", + nameof(allowedMentions)); + } + + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) && + allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) + { + throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", + nameof(allowedMentions)); + } + } + } + + var apiArgs = new ModifyWebhookMessageParams + { + Content = args.Content.IsSpecified ? args.Content.Value : Optional.Create(), + Embeds = + args.Embeds.IsSpecified + ? args.Embeds.Value.Select(embed => embed.ToModel()).ToArray() + : Optional.Create(), + AllowedMentions = args.AllowedMentions.IsSpecified + ? args.AllowedMentions.Value.ToModel() + : Optional.Create(), + Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional.Unspecified, + }; + + await client.ApiClient.ModifyWebhookMessageAsync(client.Webhook.Id, messageId, apiArgs, options) + .ConfigureAwait(false); + } + public static async Task DeleteMessageAsync(DiscordWebhookClient client, ulong messageId, RequestOptions options) + { + await client.ApiClient.DeleteWebhookMessageAsync(client.Webhook.Id, messageId, options).ConfigureAwait(false); + } + public static async Task SendFileAsync(DiscordWebhookClient client, string filePath, string text, bool isTTS, + IEnumerable embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options, bool isSpoiler, MessageComponent components) { string filename = Path.GetFileName(filePath); using (var file = File.OpenRead(filePath)) - return await SendFileAsync(client, file, filename, text, isTTS, embeds, username, avatarUrl, options, isSpoiler).ConfigureAwait(false); + return await SendFileAsync(client, file, filename, text, isTTS, embeds, username, avatarUrl, allowedMentions, options, isSpoiler, components).ConfigureAwait(false); } - public static async Task SendFileAsync(DiscordWebhookClient client, Stream stream, string filename, string text, bool isTTS, - IEnumerable embeds, string username, string avatarUrl, RequestOptions options, bool isSpoiler) + public static Task SendFileAsync(DiscordWebhookClient client, Stream stream, string filename, string text, bool isTTS, + IEnumerable embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options, bool isSpoiler, + MessageComponent components) + => SendFileAsync(client, new FileAttachment(stream, filename, isSpoiler: isSpoiler), text, isTTS, embeds, username, avatarUrl, allowedMentions, components, options); + + public static Task SendFileAsync(DiscordWebhookClient client, FileAttachment attachment, string text, bool isTTS, IEnumerable embeds, string username, string avatarUrl, AllowedMentions allowedMentions, MessageComponent components, RequestOptions options) + => SendFilesAsync(client, new FileAttachment[] { attachment }, text, isTTS, embeds, username, avatarUrl, allowedMentions, components, options); + + public static async Task SendFilesAsync(DiscordWebhookClient client, + IEnumerable attachments, string text, bool isTTS, IEnumerable embeds, string username, string avatarUrl, AllowedMentions allowedMentions, MessageComponent components, RequestOptions options) { - var args = new UploadWebhookFileParams(stream) { Filename = filename, Content = text, IsTTS = isTTS, IsSpoiler = isSpoiler }; - if (username != null) - args.Username = username; - if (avatarUrl != null) - args.AvatarUrl = avatarUrl; - if (embeds != null) - args.Embeds = embeds.Select(x => x.ToModel()).ToArray(); + embeds ??= Array.Empty(); + + Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); + Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); + Preconditions.AtMost(embeds.Count(), 10, nameof(embeds), "A max of 10 embeds are allowed."); + + foreach (var attachment in attachments) + { + Preconditions.NotNullOrEmpty(attachment.FileName, nameof(attachment.FileName), "File Name must not be empty or null"); + } + + // check that user flag and user Id list are exclusive, same with role flag and role Id list + if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue) + { + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) && + allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) + { + throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions)); + } + + if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) && + allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) + { + throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions)); + } + } + + var args = new UploadWebhookFileParams(attachments.ToArray()) {AvatarUrl = avatarUrl, Username = username, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified }; var msg = await client.ApiClient.UploadWebhookFileAsync(client.Webhook.Id, args, options).ConfigureAwait(false); return msg.Id; } diff --git a/src/Discord.Net/Discord.Net.nuspec b/src/Discord.Net/Discord.Net.nuspec index 5c5ea4072..b208ca6be 100644 --- a/src/Discord.Net/Discord.Net.nuspec +++ b/src/Discord.Net/Discord.Net.nuspec @@ -2,7 +2,7 @@ Discord.Net - 2.3.0-dev$suffix$ + 3.1.0$suffix$ Discord.Net Discord.Net Contributors foxbot @@ -13,27 +13,46 @@ false https://github.com/RogueException/Discord.Net/raw/dev/docs/marketing/logo/PackageLogo.png + + + + + + + + + + + + + + + + - - - - - - + + + + + + + - - - - - + + + + + + - - - - - - + + + + + + + - + \ No newline at end of file diff --git a/stylecop.json b/stylecop.json new file mode 100644 index 000000000..bb9056963 --- /dev/null +++ b/stylecop.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "indentation": { + "indentationSize": 4, + "tabSize": 4, + "useTabs": false + }, + "documentationRules": { + "documentExposedElements": true, + "documentInternalElements": false, + "documentPrivateElements": false, + "documentInterfaces": true, + "documentPrivateFields": true, + "xmlHeader": false, + "documentationCulture": "en-US" + } + } +} diff --git a/test/Discord.Net.Analyzers.Tests/Discord.Net.Analyzers.Tests.csproj b/test/Discord.Net.Analyzers.Tests/Discord.Net.Analyzers.Tests.csproj index bc587657c..460a2c9e9 100644 --- a/test/Discord.Net.Analyzers.Tests/Discord.Net.Analyzers.Tests.csproj +++ b/test/Discord.Net.Analyzers.Tests/Discord.Net.Analyzers.Tests.csproj @@ -1,7 +1,7 @@ - + - netcoreapp3.0 + net6.0 false @@ -10,15 +10,15 @@ + - - - + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Discord.Net.Analyzers.Tests/Helpers/CodeFixVerifier.Helper.cs b/test/Discord.Net.Analyzers.Tests/Helpers/CodeFixVerifier.Helper.cs index 0f73d0643..42f7b08c1 100644 --- a/test/Discord.Net.Analyzers.Tests/Helpers/CodeFixVerifier.Helper.cs +++ b/test/Discord.Net.Analyzers.Tests/Helpers/CodeFixVerifier.Helper.cs @@ -18,7 +18,7 @@ namespace TestHelper /// Apply the inputted CodeAction to the inputted document. /// Meant to be used to apply codefixes. /// - /// The Document to apply the fix on + /// The Document to apply the fix on. /// A CodeAction that will be applied to the Document. /// A Document with the changes from the CodeAction private static Document ApplyFix(Document document, CodeAction codeAction) @@ -33,8 +33,8 @@ namespace TestHelper /// Note: Considers Diagnostics to be the same if they have the same Ids. In the case of multiple diagnostics with the same Id in a row, /// this method may not necessarily return the new one. /// - /// The Diagnostics that existed in the code before the CodeFix was applied - /// The Diagnostics that exist in the code after the CodeFix was applied + /// The Diagnostics that existed in the code before the CodeFix was applied. + /// The Diagnostics that exist in the code after the CodeFix was applied. /// A list of Diagnostics that only surfaced in the code after the CodeFix was applied private static IEnumerable GetNewDiagnostics(IEnumerable diagnostics, IEnumerable newDiagnostics) { @@ -61,7 +61,7 @@ namespace TestHelper /// /// Get the existing compiler diagnostics on the inputted document. /// - /// The Document to run the compiler diagnostic analyzers on + /// The Document to run the compiler diagnostic analyzers on. /// The compiler diagnostics that were found in the code private static IEnumerable GetCompilerDiagnostics(Document document) { @@ -71,7 +71,7 @@ namespace TestHelper /// /// Given a document, turn it into a string based on the syntax root /// - /// The Document to be converted to a string + /// The Document to be converted to a string. /// A string containing the syntax of the Document after formatting private static string GetStringFromDocument(Document document) { diff --git a/test/Discord.Net.Analyzers.Tests/Helpers/DiagnosticResult.cs b/test/Discord.Net.Analyzers.Tests/Helpers/DiagnosticResult.cs index 5ae6f528e..87d915494 100644 --- a/test/Discord.Net.Analyzers.Tests/Helpers/DiagnosticResult.cs +++ b/test/Discord.Net.Analyzers.Tests/Helpers/DiagnosticResult.cs @@ -20,9 +20,9 @@ namespace TestHelper throw new ArgumentOutOfRangeException(nameof(column), "column must be >= -1"); } - this.Path = path; - this.Line = line; - this.Column = column; + Path = path; + Line = line; + Column = column; } public string Path { get; } @@ -41,16 +41,16 @@ namespace TestHelper { get { - if (this.locations == null) + if (locations == null) { - this.locations = new DiagnosticResultLocation[] { }; + locations = new DiagnosticResultLocation[] { }; } - return this.locations; + return locations; } set { - this.locations = value; + locations = value; } } @@ -64,7 +64,7 @@ namespace TestHelper { get { - return this.Locations.Length > 0 ? this.Locations[0].Path : ""; + return Locations.Length > 0 ? Locations[0].Path : ""; } } @@ -72,7 +72,7 @@ namespace TestHelper { get { - return this.Locations.Length > 0 ? this.Locations[0].Line : -1; + return Locations.Length > 0 ? Locations[0].Line : -1; } } @@ -80,7 +80,7 @@ namespace TestHelper { get { - return this.Locations.Length > 0 ? this.Locations[0].Column : -1; + return Locations.Length > 0 ? Locations[0].Column : -1; } } } diff --git a/test/Discord.Net.Analyzers.Tests/Helpers/DiagnosticVerifier.Helper.cs b/test/Discord.Net.Analyzers.Tests/Helpers/DiagnosticVerifier.Helper.cs index 99654f12c..23bb319a6 100644 --- a/test/Discord.Net.Analyzers.Tests/Helpers/DiagnosticVerifier.Helper.cs +++ b/test/Discord.Net.Analyzers.Tests/Helpers/DiagnosticVerifier.Helper.cs @@ -35,9 +35,9 @@ namespace TestHelper /// /// Given classes in the form of strings, their language, and an IDiagnosticAnlayzer to apply to it, return the diagnostics found in the string after converting it to a document. /// - /// Classes in the form of strings - /// The language the source classes are in - /// The analyzer to be run on the sources + /// Classes in the form of strings. + /// The language the source classes are in. + /// The analyzer to be run on the sources. /// An IEnumerable of Diagnostics that surfaced in the source code, sorted by Location private static Diagnostic[] GetSortedDiagnostics(string[] sources, string language, DiagnosticAnalyzer analyzer) { @@ -48,8 +48,8 @@ namespace TestHelper /// Given an analyzer and a document to apply it to, run the analyzer and gather an array of diagnostics found in it. /// The returned diagnostics are then ordered by location in the source document. /// - /// The analyzer to run on the documents - /// The Documents that the analyzer will be run on + /// The analyzer to run on the documents. + /// The Documents that the analyzer will be run on. /// An IEnumerable of Diagnostics that surfaced in the source code, sorted by Location protected static Diagnostic[] GetSortedDiagnosticsFromDocuments(DiagnosticAnalyzer analyzer, Document[] documents) { @@ -93,7 +93,7 @@ namespace TestHelper /// /// Sort diagnostics by location in source document /// - /// The list of Diagnostics to be sorted + /// The list of Diagnostics to be sorted. /// An IEnumerable containing the Diagnostics in order of Location private static Diagnostic[] SortDiagnostics(IEnumerable diagnostics) { @@ -106,8 +106,8 @@ namespace TestHelper /// /// Given an array of strings as sources and a language, turn them into a project and return the documents and spans of it. /// - /// Classes in the form of strings - /// The language the source code is in + /// Classes in the form of strings. + /// The language the source code is in. /// A Tuple containing the Documents produced from the sources and their TextSpans if relevant private static Document[] GetDocuments(string[] sources, string language) { @@ -130,8 +130,8 @@ namespace TestHelper /// /// Create a Document from a string through creating a project that contains it. /// - /// Classes in the form of a string - /// The language the source code is in + /// Classes in the form of a string. + /// The language the source code is in. /// A Document created from the source string protected static Document CreateDocument(string source, string language = LanguageNames.CSharp) { @@ -141,8 +141,8 @@ namespace TestHelper /// /// Create a project using the inputted strings as sources. /// - /// Classes in the form of strings - /// The language the source code is in + /// Classes in the form of strings. + /// The language the source code is in. /// A Project created out of the Documents created from the source strings private static Project CreateProject(string[] sources, string language = LanguageNames.CSharp) { @@ -187,7 +187,7 @@ namespace TestHelper private static HashSet RecursiveReferencedAssemblies(Assembly a, HashSet assemblies = null) { - assemblies = assemblies ?? new HashSet(); + assemblies ??= new HashSet(); if (assemblies.Add(a)) { foreach (var referencedAssemblyName in a.GetReferencedAssemblies()) diff --git a/test/Discord.Net.Analyzers.Tests/Verifiers/CodeFixVerifier.cs b/test/Discord.Net.Analyzers.Tests/Verifiers/CodeFixVerifier.cs index 5d057b610..d1cb6cd1b 100644 --- a/test/Discord.Net.Analyzers.Tests/Verifiers/CodeFixVerifier.cs +++ b/test/Discord.Net.Analyzers.Tests/Verifiers/CodeFixVerifier.cs @@ -1,4 +1,4 @@ -using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; @@ -38,10 +38,10 @@ namespace TestHelper /// /// Called to test a C# codefix when applied on the inputted string as a source /// - /// A class in the form of a string before the CodeFix was applied to it - /// A class in the form of a string after the CodeFix was applied to it - /// Index determining which codefix to apply if there are multiple - /// A bool controlling whether or not the test will fail if the CodeFix introduces other warnings after being applied + /// A class in the form of a string before the CodeFix was applied to it. + /// A class in the form of a string after the CodeFix was applied to it. + /// Index determining which codefix to apply if there are multiple. + /// A bool controlling whether or not the test will fail if the CodeFix introduces other warnings after being applied. protected void VerifyCSharpFix(string oldSource, string newSource, int? codeFixIndex = null, bool allowNewCompilerDiagnostics = false) { VerifyFix(LanguageNames.CSharp, GetCSharpDiagnosticAnalyzer(), GetCSharpCodeFixProvider(), oldSource, newSource, codeFixIndex, allowNewCompilerDiagnostics); @@ -50,10 +50,10 @@ namespace TestHelper /// /// Called to test a VB codefix when applied on the inputted string as a source /// - /// A class in the form of a string before the CodeFix was applied to it - /// A class in the form of a string after the CodeFix was applied to it - /// Index determining which codefix to apply if there are multiple - /// A bool controlling whether or not the test will fail if the CodeFix introduces other warnings after being applied + /// A class in the form of a string before the CodeFix was applied to it. + /// A class in the form of a string after the CodeFix was applied to it. + /// Index determining which codefix to apply if there are multiple. + /// A bool controlling whether or not the test will fail if the CodeFix introduces other warnings after being applied. protected void VerifyBasicFix(string oldSource, string newSource, int? codeFixIndex = null, bool allowNewCompilerDiagnostics = false) { VerifyFix(LanguageNames.VisualBasic, GetBasicDiagnosticAnalyzer(), GetBasicCodeFixProvider(), oldSource, newSource, codeFixIndex, allowNewCompilerDiagnostics); @@ -65,13 +65,13 @@ namespace TestHelper /// Then gets the string after the codefix is applied and compares it with the expected result. /// Note: If any codefix causes new diagnostics to show up, the test fails unless allowNewCompilerDiagnostics is set to true. /// - /// The language the source code is in - /// The analyzer to be applied to the source code - /// The codefix to be applied to the code wherever the relevant Diagnostic is found - /// A class in the form of a string before the CodeFix was applied to it - /// A class in the form of a string after the CodeFix was applied to it - /// Index determining which codefix to apply if there are multiple - /// A bool controlling whether or not the test will fail if the CodeFix introduces other warnings after being applied + /// The language the source code is in. + /// The analyzer to be applied to the source code. + /// The codefix to be applied to the code wherever the relevant Diagnostic is found. + /// A class in the form of a string before the CodeFix was applied to it. + /// A class in the form of a string after the CodeFix was applied to it. + /// Index determining which codefix to apply if there are multiple. + /// A bool controlling whether or not the test will fail if the CodeFix introduces other warnings after being applied. private void VerifyFix(string language, DiagnosticAnalyzer analyzer, CodeFixProvider codeFixProvider, string oldSource, string newSource, int? codeFixIndex, bool allowNewCompilerDiagnostics) { var document = CreateDocument(oldSource, language); @@ -126,4 +126,4 @@ namespace TestHelper Assert.Equal(newSource, actual); } } -} \ No newline at end of file +} diff --git a/test/Discord.Net.Analyzers.Tests/Verifiers/DiagnosticVerifier.cs b/test/Discord.Net.Analyzers.Tests/Verifiers/DiagnosticVerifier.cs index 3564093f8..9b0219a63 100644 --- a/test/Discord.Net.Analyzers.Tests/Verifiers/DiagnosticVerifier.cs +++ b/test/Discord.Net.Analyzers.Tests/Verifiers/DiagnosticVerifier.cs @@ -37,8 +37,8 @@ namespace TestHelper /// Called to test a C# DiagnosticAnalyzer when applied on the single inputted string as a source /// Note: input a DiagnosticResult for each Diagnostic expected /// - /// A class in the form of a string to run the analyzer on - /// DiagnosticResults that should appear after the analyzer is run on the source + /// A class in the form of a string to run the analyzer on. + /// DiagnosticResults that should appear after the analyzer is run on the source. protected void VerifyCSharpDiagnostic(string source, params DiagnosticResult[] expected) { VerifyDiagnostics(new[] { source }, LanguageNames.CSharp, GetCSharpDiagnosticAnalyzer(), expected); @@ -48,8 +48,8 @@ namespace TestHelper /// Called to test a VB DiagnosticAnalyzer when applied on the single inputted string as a source /// Note: input a DiagnosticResult for each Diagnostic expected /// - /// A class in the form of a string to run the analyzer on - /// DiagnosticResults that should appear after the analyzer is run on the source + /// A class in the form of a string to run the analyzer on. + /// DiagnosticResults that should appear after the analyzer is run on the source. protected void VerifyBasicDiagnostic(string source, params DiagnosticResult[] expected) { VerifyDiagnostics(new[] { source }, LanguageNames.VisualBasic, GetBasicDiagnosticAnalyzer(), expected); @@ -59,8 +59,8 @@ namespace TestHelper /// Called to test a C# DiagnosticAnalyzer when applied on the inputted strings as a source /// Note: input a DiagnosticResult for each Diagnostic expected /// - /// An array of strings to create source documents from to run the analyzers on - /// DiagnosticResults that should appear after the analyzer is run on the sources + /// An array of strings to create source documents from to run the analyzers on. + /// DiagnosticResults that should appear after the analyzer is run on the sources. protected void VerifyCSharpDiagnostic(string[] sources, params DiagnosticResult[] expected) { VerifyDiagnostics(sources, LanguageNames.CSharp, GetCSharpDiagnosticAnalyzer(), expected); @@ -70,8 +70,8 @@ namespace TestHelper /// Called to test a VB DiagnosticAnalyzer when applied on the inputted strings as a source /// Note: input a DiagnosticResult for each Diagnostic expected /// - /// An array of strings to create source documents from to run the analyzers on - /// DiagnosticResults that should appear after the analyzer is run on the sources + /// An array of strings to create source documents from to run the analyzers on. + /// DiagnosticResults that should appear after the analyzer is run on the sources. protected void VerifyBasicDiagnostic(string[] sources, params DiagnosticResult[] expected) { VerifyDiagnostics(sources, LanguageNames.VisualBasic, GetBasicDiagnosticAnalyzer(), expected); @@ -81,10 +81,10 @@ namespace TestHelper /// General method that gets a collection of actual diagnostics found in the source after the analyzer is run, /// then verifies each of them. /// - /// An array of strings to create source documents from to run the analyzers on - /// The language of the classes represented by the source strings - /// The analyzer to be run on the source code - /// DiagnosticResults that should appear after the analyzer is run on the sources + /// An array of strings to create source documents from to run the analyzers on. + /// The language of the classes represented by the source strings. + /// The analyzer to be run on the source code. + /// DiagnosticResults that should appear after the analyzer is run on the sources. private void VerifyDiagnostics(string[] sources, string language, DiagnosticAnalyzer analyzer, params DiagnosticResult[] expected) { var diagnostics = GetSortedDiagnostics(sources, language, analyzer); @@ -98,9 +98,9 @@ namespace TestHelper /// Checks each of the actual Diagnostics found and compares them with the corresponding DiagnosticResult in the array of expected results. /// Diagnostics are considered equal only if the DiagnosticResultLocation, Id, Severity, and Message of the DiagnosticResult match the actual diagnostic. /// - /// The Diagnostics found by the compiler after running the analyzer on the source code - /// The analyzer that was being run on the sources - /// Diagnostic Results that should have appeared in the code + /// The Diagnostics found by the compiler after running the analyzer on the source code. + /// The analyzer that was being run on the sources. + /// Diagnostic Results that should have appeared in the code. private static void VerifyDiagnosticResults(IEnumerable actualResults, DiagnosticAnalyzer analyzer, params DiagnosticResult[] expectedResults) { int expectedCount = expectedResults.Length; @@ -173,10 +173,10 @@ namespace TestHelper /// /// Helper method to VerifyDiagnosticResult that checks the location of a diagnostic and compares it with the location in the expected DiagnosticResult. /// - /// The analyzer that was being run on the sources - /// The diagnostic that was found in the code - /// The Location of the Diagnostic found in the code - /// The DiagnosticResultLocation that should have been found + /// The analyzer that was being run on the sources. + /// The diagnostic that was found in the code. + /// The Location of the Diagnostic found in the code. + /// The DiagnosticResultLocation that should have been found. private static void VerifyDiagnosticLocation(DiagnosticAnalyzer analyzer, Diagnostic diagnostic, Location actual, DiagnosticResultLocation expected) { var actualSpan = actual.GetLineSpan(); @@ -215,8 +215,8 @@ namespace TestHelper /// /// Helper method to format a Diagnostic into an easily readable string /// - /// The analyzer that this verifier tests - /// The Diagnostics to be formatted + /// The analyzer that this verifier tests. + /// The Diagnostics to be formatted. /// The Diagnostics formatted as a string private static string FormatDiagnostics(DiagnosticAnalyzer analyzer, params Diagnostic[] diagnostics) { diff --git a/test/Discord.Net.Tests.Integration/ChannelsTests.cs b/test/Discord.Net.Tests.Integration/ChannelsTests.cs index 3bf60772f..9bb30c4ef 100644 --- a/test/Discord.Net.Tests.Integration/ChannelsTests.cs +++ b/test/Discord.Net.Tests.Integration/ChannelsTests.cs @@ -19,7 +19,7 @@ namespace Discord public ChannelsTests(RestGuildFixture guildFixture, ITestOutputHelper output) { guild = guildFixture.Guild; - this.output = output; + output = output; output.WriteLine($"RestGuildFixture using guild: {guild.Id}"); // capture all console output guildFixture.Client.Log += LogAsync; diff --git a/test/Discord.Net.Tests.Integration/Discord.Net.Tests.Integration.csproj b/test/Discord.Net.Tests.Integration/Discord.Net.Tests.Integration.csproj index c571059ef..0f399ab68 100644 --- a/test/Discord.Net.Tests.Integration/Discord.Net.Tests.Integration.csproj +++ b/test/Discord.Net.Tests.Integration/Discord.Net.Tests.Integration.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1 + net6.0 false @@ -10,14 +10,13 @@ - - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Discord.Net.Tests.Integration/GuildTests.cs b/test/Discord.Net.Tests.Integration/GuildTests.cs index 40394a3a0..c309b0ed1 100644 --- a/test/Discord.Net.Tests.Integration/GuildTests.cs +++ b/test/Discord.Net.Tests.Integration/GuildTests.cs @@ -18,7 +18,7 @@ namespace Discord { client = guildFixture.Client; guild = guildFixture.Guild; - this.output = output; + output = output; output.WriteLine($"RestGuildFixture using guild: {guild.Id}"); guildFixture.Client.Log += LogAsync; } diff --git a/test/Discord.Net.Tests.Unit/ChannelPermissionsTests.cs b/test/Discord.Net.Tests.Unit/ChannelPermissionsTests.cs index a3566590a..2cab8fa21 100644 --- a/test/Discord.Net.Tests.Unit/ChannelPermissionsTests.cs +++ b/test/Discord.Net.Tests.Unit/ChannelPermissionsTests.cs @@ -85,6 +85,10 @@ namespace Discord AssertFlag(() => new ChannelPermissions(stream: true), ChannelPermission.Stream); AssertFlag(() => new ChannelPermissions(manageRoles: true), ChannelPermission.ManageRoles); AssertFlag(() => new ChannelPermissions(manageWebhooks: true), ChannelPermission.ManageWebhooks); + AssertFlag(() => new ChannelPermissions(useApplicationCommands: true), ChannelPermission.UseApplicationCommands); + AssertFlag(() => new ChannelPermissions(createPrivateThreads: true), ChannelPermission.CreatePrivateThreads); + AssertFlag(() => new ChannelPermissions(createPublicThreads: true), ChannelPermission.CreatePublicThreads); + AssertFlag(() => new ChannelPermissions(sendMessagesInThreads: true), ChannelPermission.SendMessagesInThreads); } /// diff --git a/test/Discord.Net.Tests.Unit/ColorTests.cs b/test/Discord.Net.Tests.Unit/ColorTests.cs index 87c76e4e2..46d8feabb 100644 --- a/test/Discord.Net.Tests.Unit/ColorTests.cs +++ b/test/Discord.Net.Tests.Unit/ColorTests.cs @@ -10,12 +10,11 @@ namespace Discord /// public class ColorTests { - [Fact] public void Color_New() { Assert.Equal(0u, new Color().RawValue); Assert.Equal(uint.MinValue, new Color(uint.MinValue).RawValue); - Assert.Equal(uint.MaxValue, new Color(uint.MaxValue).RawValue); + Assert.Throws(() => new Color(uint.MaxValue)); } [Fact] public void Color_Default() diff --git a/test/Discord.Net.Tests.Unit/Discord.Net.Tests.Unit.csproj b/test/Discord.Net.Tests.Unit/Discord.Net.Tests.Unit.csproj index 357bf9531..ec06c3c3d 100644 --- a/test/Discord.Net.Tests.Unit/Discord.Net.Tests.Unit.csproj +++ b/test/Discord.Net.Tests.Unit/Discord.Net.Tests.Unit.csproj @@ -1,7 +1,7 @@ - + - netcoreapp3.0 + net6.0 false @@ -9,13 +9,12 @@ - - + - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Discord.Net.Tests.Unit/EmbedBuilderTests.cs b/test/Discord.Net.Tests.Unit/EmbedBuilderTests.cs index 12ec1a0bd..83c6ede19 100644 --- a/test/Discord.Net.Tests.Unit/EmbedBuilderTests.cs +++ b/test/Discord.Net.Tests.Unit/EmbedBuilderTests.cs @@ -9,9 +9,9 @@ namespace Discord /// public class EmbedBuilderTests { - private const string name = "chrisj"; - private const string icon = "https://meowpuffygottem.fun/blob.png"; - private const string url = "https://meowpuffygottem.fun/"; + private const string Name = "chrisj"; + private const string Icon = "https://meowpuffygottem.fun/blob.png"; + private const string Url = "https://meowpuffygottem.fun/"; /// /// Tests the behavior of . @@ -24,12 +24,12 @@ namespace Discord Assert.Null(builder.Author); builder = new EmbedBuilder() - .WithAuthor(name, icon, url); + .WithAuthor(Name, Icon, Url); Assert.NotNull(builder.Author); - Assert.Equal(name, builder.Author.Name); - Assert.Equal(icon, builder.Author.IconUrl); - Assert.Equal(url, builder.Author.Url); + Assert.Equal(Name, builder.Author.Name); + Assert.Equal(Icon, builder.Author.IconUrl); + Assert.Equal(Url, builder.Author.Url); } /// @@ -39,15 +39,15 @@ namespace Discord public void WithAuthor_AuthorBuilder() { var author = new EmbedAuthorBuilder() - .WithIconUrl(icon) - .WithName(name) - .WithUrl(url); + .WithIconUrl(Icon) + .WithName(Name) + .WithUrl(Url); var builder = new EmbedBuilder() .WithAuthor(author); Assert.NotNull(builder.Author); - Assert.Equal(name, builder.Author.Name); - Assert.Equal(icon, builder.Author.IconUrl); - Assert.Equal(url, builder.Author.Url); + Assert.Equal(Name, builder.Author.Name); + Assert.Equal(Icon, builder.Author.IconUrl); + Assert.Equal(Url, builder.Author.Url); } /// @@ -58,13 +58,13 @@ namespace Discord { var builder = new EmbedBuilder() .WithAuthor((author) => - author.WithIconUrl(icon) - .WithName(name) - .WithUrl(url)); + author.WithIconUrl(Icon) + .WithName(Name) + .WithUrl(Url)); Assert.NotNull(builder.Author); - Assert.Equal(name, builder.Author.Name); - Assert.Equal(icon, builder.Author.IconUrl); - Assert.Equal(url, builder.Author.Url); + Assert.Equal(Name, builder.Author.Name); + Assert.Equal(Icon, builder.Author.IconUrl); + Assert.Equal(Url, builder.Author.Url); } /// @@ -74,12 +74,12 @@ namespace Discord public void EmbedAuthorBuilder() { var builder = new EmbedAuthorBuilder() - .WithIconUrl(icon) - .WithName(name) - .WithUrl(url); - Assert.Equal(icon, builder.IconUrl); - Assert.Equal(name, builder.Name); - Assert.Equal(url, builder.Url); + .WithIconUrl(Icon) + .WithName(Name) + .WithUrl(Url); + Assert.Equal(Icon, builder.IconUrl); + Assert.Equal(Name, builder.Name); + Assert.Equal(Url, builder.Url); } /// @@ -95,8 +95,10 @@ namespace Discord { Assert.Throws(() => { - var builder = new EmbedBuilder(); - builder.Title = title; + var builder = new EmbedBuilder + { + Title = title + }; }); Assert.Throws(() => { @@ -113,8 +115,10 @@ namespace Discord [InlineData("jVyLChmA7aBZozXQuZ3VDEcwW6zOq0nteOVYBZi31ny73rpXfSSBXR4Jw6FiplDKQseKskwRMuBZkUewrewqAbkBZpslHirvC5nEzRySoDIdTRnkVvTXZUXg75l3bQCjuuHxDd6DfrY8ihd6yZX1Y0XFeg239YBcYV4TpL9uQ8H3HFYxrWhLlG2PRVjUmiglP5iXkawszNwMVm1SZ5LZT4jkMZHxFegVi7170d16iaPWOovu50aDDHy087XBtLKV")] public void Tile_Valid(string title) { - var builder = new EmbedBuilder(); - builder.Title = title; + var builder = new EmbedBuilder + { + Title = title + }; new EmbedBuilder().WithTitle(title); } @@ -126,15 +130,17 @@ namespace Discord { IEnumerable GetInvalid() { - yield return new string('a', 2049); + yield return new string('a', 4097); } foreach (var description in GetInvalid()) { Assert.Throws(() => new EmbedBuilder().WithDescription(description)); Assert.Throws(() => { - var b = new EmbedBuilder(); - b.Description = description; + var b = new EmbedBuilder + { + Description = description + }; }); } } @@ -149,21 +155,23 @@ namespace Discord { yield return string.Empty; yield return null; - yield return new string('a', 2048); + yield return new string('a', 4096); } foreach (var description in GetValid()) { var b = new EmbedBuilder().WithDescription(description); Assert.Equal(description, b.Description); - b = new EmbedBuilder(); - b.Description = description; + b = new EmbedBuilder + { + Description = description + }; Assert.Equal(description, b.Description); } } /// - /// Tests that valid urls do not throw any exceptions. + /// Tests that valid url's do not throw any exceptions. /// /// The url to set. [Theory] @@ -181,51 +189,17 @@ namespace Discord Assert.Equal(result.ImageUrl, url); Assert.Equal(result.ThumbnailUrl, url); - result = new EmbedBuilder(); - result.Url = url; - result.ImageUrl = url; - result.ThumbnailUrl = url; + result = new EmbedBuilder + { + Url = url, + ImageUrl = url, + ThumbnailUrl = url + }; Assert.Equal(result.Url, url); Assert.Equal(result.ImageUrl, url); Assert.Equal(result.ThumbnailUrl, url); } - /// - /// Tests that invalid urls throw an . - /// - /// The url to set. - [Theory] - [InlineData(" ")] - [InlineData("not a url")] - public void Url_Invalid(string url) - { - Assert.Throws(() - => new EmbedBuilder() - .WithUrl(url)); - Assert.Throws(() - => new EmbedBuilder() - .WithImageUrl(url)); - Assert.Throws(() - => new EmbedBuilder() - .WithThumbnailUrl(url)); - - Assert.Throws(() => - { - var b = new EmbedBuilder(); - b.Url = url; - }); - Assert.Throws(() => - { - var b = new EmbedBuilder(); - b.ImageUrl = url; - }); - Assert.Throws(() => - { - var b = new EmbedBuilder(); - b.ThumbnailUrl = url; - }); - } - /// /// Tests the value of the property when there are no fields set. /// @@ -243,15 +217,15 @@ namespace Discord public void Length() { var e = new EmbedBuilder() - .WithAuthor(name, icon, url) + .WithAuthor(Name, Icon, Url) .WithColor(Color.Blue) .WithDescription("This is the test description.") - .WithFooter("This is the footer", url) - .WithImageUrl(url) - .WithThumbnailUrl(url) + .WithFooter("This is the footer", Url) + .WithImageUrl(Url) + .WithThumbnailUrl(Url) .WithTimestamp(DateTimeOffset.MinValue) .WithTitle("This is the title") - .WithUrl(url) + .WithUrl(Url) .AddField("Field 1", "Inline", true) .AddField("Field 2", "Not Inline", false); Assert.Equal(100, e.Length); @@ -289,11 +263,11 @@ namespace Discord var e = new EmbedBuilder() .WithFooter(x => { - x.IconUrl = url; - x.Text = name; + x.IconUrl = Url; + x.Text = Name; }); - Assert.Equal(url, e.Footer.IconUrl); - Assert.Equal(name, e.Footer.Text); + Assert.Equal(Url, e.Footer.IconUrl); + Assert.Equal(Name, e.Footer.Text); } /// @@ -304,18 +278,20 @@ namespace Discord { var footer = new EmbedFooterBuilder() { - IconUrl = url, - Text = name + IconUrl = Url, + Text = Name }; var e = new EmbedBuilder() .WithFooter(footer); - Assert.Equal(url, e.Footer.IconUrl); - Assert.Equal(name, e.Footer.Text); + Assert.Equal(Url, e.Footer.IconUrl); + Assert.Equal(Name, e.Footer.Text); // use the property - e = new EmbedBuilder(); - e.Footer = footer; - Assert.Equal(url, e.Footer.IconUrl); - Assert.Equal(name, e.Footer.Text); + e = new EmbedBuilder + { + Footer = footer + }; + Assert.Equal(Url, e.Footer.IconUrl); + Assert.Equal(Name, e.Footer.Text); } /// @@ -325,9 +301,9 @@ namespace Discord public void WithFooter_Strings() { var e = new EmbedBuilder() - .WithFooter(name, url); - Assert.Equal(url, e.Footer.IconUrl); - Assert.Equal(name, e.Footer.Text); + .WithFooter(Name, Url); + Assert.Equal(Url, e.Footer.IconUrl); + Assert.Equal(Name, e.Footer.Text); } /// @@ -337,28 +313,10 @@ namespace Discord public void EmbedFooterBuilder() { var footer = new EmbedFooterBuilder() - .WithIconUrl(url) - .WithText(name); - Assert.Equal(url, footer.IconUrl); - Assert.Equal(name, footer.Text); - } - /// - /// Tests that invalid URLs throw an . - /// - [Fact] - public void EmbedFooterBuilder_InvalidURL() - { - IEnumerable InvalidUrls() - { - yield return "not a url"; - } - foreach (var url in InvalidUrls()) - { - Assert.Throws(() => - { - new EmbedFooterBuilder().WithIconUrl(url); - }); - } + .WithIconUrl(Url) + .WithText(Name); + Assert.Equal(Url, footer.IconUrl); + Assert.Equal(Name, footer.Text); } /// /// Tests that invalid text throws an . @@ -429,10 +387,12 @@ namespace Discord Assert.Equal("value", e.Value); Assert.True(e.IsInline); // use the properties - e = new EmbedFieldBuilder(); - e.IsInline = true; - e.Name = "name"; - e.Value = "value"; + e = new EmbedFieldBuilder + { + IsInline = true, + Name = "name", + Value = "value" + }; Assert.Equal("name", e.Name); Assert.Equal("value", e.Value); Assert.True(e.IsInline); diff --git a/test/Discord.Net.Tests.Unit/FormatTests.cs b/test/Discord.Net.Tests.Unit/FormatTests.cs index 2a5adbaae..c015c7e15 100644 --- a/test/Discord.Net.Tests.Unit/FormatTests.cs +++ b/test/Discord.Net.Tests.Unit/FormatTests.cs @@ -59,5 +59,20 @@ namespace Discord { Assert.Equal(expected, Format.BlockQuote(input)); } + + [Theory] + [InlineData("", "")] + [InlineData("\n", "\n")] + [InlineData("**hi**", "hi")] + [InlineData("__uwu__", "uwu")] + [InlineData(">>__uwu__", "uwu")] + [InlineData("```uwu```", "uwu")] + [InlineData("~uwu~", "uwu")] + [InlineData("berries __and__ *Cream**, I'm a little lad who loves berries and cream", "berries and Cream, I'm a little lad who loves berries and cream")] + public void StripMarkdown(string input, string expected) + { + var test = Format.StripMarkDown(input); + Assert.Equal(expected, test); + } } } diff --git a/test/Discord.Net.Tests.Unit/GuildPermissionsTests.cs b/test/Discord.Net.Tests.Unit/GuildPermissionsTests.cs index f0611fa24..ce5d0eb84 100644 --- a/test/Discord.Net.Tests.Unit/GuildPermissionsTests.cs +++ b/test/Discord.Net.Tests.Unit/GuildPermissionsTests.cs @@ -69,6 +69,7 @@ namespace Discord AssertFlag(() => new GuildPermissions(manageGuild: true), GuildPermission.ManageGuild); AssertFlag(() => new GuildPermissions(addReactions: true), GuildPermission.AddReactions); AssertFlag(() => new GuildPermissions(viewAuditLog: true), GuildPermission.ViewAuditLog); + AssertFlag(() => new GuildPermissions(viewGuildInsights: true), GuildPermission.ViewGuildInsights); AssertFlag(() => new GuildPermissions(viewChannel: true), GuildPermission.ViewChannel); AssertFlag(() => new GuildPermissions(sendMessages: true), GuildPermission.SendMessages); AssertFlag(() => new GuildPermissions(sendTTSMessages: true), GuildPermission.SendTTSMessages); @@ -90,7 +91,15 @@ namespace Discord AssertFlag(() => new GuildPermissions(manageNicknames: true), GuildPermission.ManageNicknames); AssertFlag(() => new GuildPermissions(manageRoles: true), GuildPermission.ManageRoles); AssertFlag(() => new GuildPermissions(manageWebhooks: true), GuildPermission.ManageWebhooks); - AssertFlag(() => new GuildPermissions(manageEmojis: true), GuildPermission.ManageEmojis); + AssertFlag(() => new GuildPermissions(manageEmojisAndStickers: true), GuildPermission.ManageEmojisAndStickers); + AssertFlag(() => new GuildPermissions(useApplicationCommands: true), GuildPermission.UseApplicationCommands); + AssertFlag(() => new GuildPermissions(requestToSpeak: true), GuildPermission.RequestToSpeak); + AssertFlag(() => new GuildPermissions(manageEvents: true), GuildPermission.ManageEvents); + AssertFlag(() => new GuildPermissions(manageThreads: true), GuildPermission.ManageThreads); + AssertFlag(() => new GuildPermissions(createPublicThreads: true), GuildPermission.CreatePublicThreads); + AssertFlag(() => new GuildPermissions(createPrivateThreads: true), GuildPermission.CreatePrivateThreads); + AssertFlag(() => new GuildPermissions(useExternalStickers: true), GuildPermission.UseExternalStickers); + AssertFlag(() => new GuildPermissions(moderateMembers: true), GuildPermission.ModerateMembers); } /// @@ -141,6 +150,7 @@ namespace Discord AssertUtil(GuildPermission.ManageGuild, x => x.ManageGuild, (p, enable) => p.Modify(manageGuild: enable)); AssertUtil(GuildPermission.AddReactions, x => x.AddReactions, (p, enable) => p.Modify(addReactions: enable)); AssertUtil(GuildPermission.ViewAuditLog, x => x.ViewAuditLog, (p, enable) => p.Modify(viewAuditLog: enable)); + AssertUtil(GuildPermission.ViewGuildInsights, x => x.ViewGuildInsights, (p, enable) => p.Modify(viewGuildInsights: enable)); AssertUtil(GuildPermission.ViewChannel, x => x.ViewChannel, (p, enable) => p.Modify(viewChannel: enable)); AssertUtil(GuildPermission.SendMessages, x => x.SendMessages, (p, enable) => p.Modify(sendMessages: enable)); AssertUtil(GuildPermission.SendTTSMessages, x => x.SendTTSMessages, (p, enable) => p.Modify(sendTTSMessages: enable)); @@ -159,7 +169,15 @@ namespace Discord AssertUtil(GuildPermission.ManageNicknames, x => x.ManageNicknames, (p, enable) => p.Modify(manageNicknames: enable)); AssertUtil(GuildPermission.ManageRoles, x => x.ManageRoles, (p, enable) => p.Modify(manageRoles: enable)); AssertUtil(GuildPermission.ManageWebhooks, x => x.ManageWebhooks, (p, enable) => p.Modify(manageWebhooks: enable)); - AssertUtil(GuildPermission.ManageEmojis, x => x.ManageEmojis, (p, enable) => p.Modify(manageEmojis: enable)); + AssertUtil(GuildPermission.ManageEmojisAndStickers, x => x.ManageEmojisAndStickers, (p, enable) => p.Modify(manageEmojisAndStickers: enable)); + AssertUtil(GuildPermission.UseApplicationCommands, x => x.UseApplicationCommands, (p, enable) => p.Modify(useApplicationCommands: enable)); + AssertUtil(GuildPermission.RequestToSpeak, x => x.RequestToSpeak, (p, enable) => p.Modify(requestToSpeak: enable)); + AssertUtil(GuildPermission.ManageEvents, x => x.ManageEvents, (p, enable) => p.Modify(manageEvents: enable)); + AssertUtil(GuildPermission.ManageThreads, x => x.ManageThreads, (p, enable) => p.Modify(manageThreads: enable)); + AssertUtil(GuildPermission.CreatePublicThreads, x => x.CreatePublicThreads, (p, enable) => p.Modify(createPublicThreads: enable)); + AssertUtil(GuildPermission.CreatePrivateThreads, x => x.CreatePrivateThreads, (p, enable) => p.Modify(createPrivateThreads: enable)); + AssertUtil(GuildPermission.UseExternalStickers, x => x.UseExternalStickers, (p, enable) => p.Modify(useExternalStickers: enable)); + AssertUtil(GuildPermission.ModerateMembers, x => x.ModerateMembers, (p, enable) => p.Modify(moderateMembers: enable)); } } } diff --git a/test/Discord.Net.Tests.Unit/MentionUtilsTests.cs b/test/Discord.Net.Tests.Unit/MentionUtilsTests.cs index 52f35fd9c..abd1191c8 100644 --- a/test/Discord.Net.Tests.Unit/MentionUtilsTests.cs +++ b/test/Discord.Net.Tests.Unit/MentionUtilsTests.cs @@ -47,9 +47,7 @@ namespace Discord var parsed = MentionUtils.ParseUser(user); Assert.Equal(id, parsed); - // also check tryparse - ulong result; - Assert.True(MentionUtils.TryParseUser(user, out result)); + Assert.True(MentionUtils.TryParseUser(user, out ulong result)); Assert.Equal(id, result); } [Theory] @@ -75,9 +73,7 @@ namespace Discord var parsed = MentionUtils.ParseChannel(channel); Assert.Equal(id, parsed); - // also check tryparse - ulong result; - Assert.True(MentionUtils.TryParseChannel(channel, out result)); + Assert.True(MentionUtils.TryParseChannel(channel, out ulong result)); Assert.Equal(id, result); } [Theory] @@ -103,9 +99,7 @@ namespace Discord var parsed = MentionUtils.ParseRole(role); Assert.Equal(id, parsed); - // also check tryparse - ulong result; - Assert.True(MentionUtils.TryParseRole(role, out result)); + Assert.True(MentionUtils.TryParseRole(role, out ulong result)); Assert.Equal(id, result); } [Theory] diff --git a/test/Discord.Net.Tests.Unit/MockedEntities/MockedDMChannel.cs b/test/Discord.Net.Tests.Unit/MockedEntities/MockedDMChannel.cs index c8d68fb4d..519bab4d9 100644 --- a/test/Discord.Net.Tests.Unit/MockedEntities/MockedDMChannel.cs +++ b/test/Discord.Net.Tests.Unit/MockedEntities/MockedDMChannel.cs @@ -33,6 +33,11 @@ namespace Discord throw new NotImplementedException(); } + public Task ModifyMessageAsync(ulong messageId, Action func, RequestOptions options = null) + { + throw new NotImplementedException(); + } + public IDisposable EnterTypingState(RequestOptions options = null) { throw new NotImplementedException(); @@ -73,24 +78,15 @@ namespace Discord throw new NotImplementedException(); } - public Task SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) - { - throw new NotImplementedException(); - } - - public Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) - { - throw new NotImplementedException(); - } - - public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null) - { - throw new NotImplementedException(); - } - public Task TriggerTypingAsync(RequestOptions options = null) { throw new NotImplementedException(); } + + public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent component = null, ISticker[] stickers = null, Embed[] embeds = null) => throw new NotImplementedException(); + public Task SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent component = null, ISticker[] stickers = null, Embed[] embeds = null) => throw new NotImplementedException(); + public Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent component = null, ISticker[] stickers = null, Embed[] embeds = null) => throw new NotImplementedException(); + public Task SendFileAsync(FileAttachment attachment, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent component = null, ISticker[] stickers = null, Embed[] embeds = null) => throw new NotImplementedException(); + public Task SendFilesAsync(IEnumerable attachments, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent component = null, ISticker[] stickers = null, Embed[] embeds = null) => throw new NotImplementedException(); } } diff --git a/test/Discord.Net.Tests.Unit/MockedEntities/MockedGroupChannel.cs b/test/Discord.Net.Tests.Unit/MockedEntities/MockedGroupChannel.cs index 5a26b713f..9c94efffa 100644 --- a/test/Discord.Net.Tests.Unit/MockedEntities/MockedGroupChannel.cs +++ b/test/Discord.Net.Tests.Unit/MockedEntities/MockedGroupChannel.cs @@ -16,6 +16,8 @@ namespace Discord public ulong Id => throw new NotImplementedException(); + public string RTCRegion => throw new NotImplementedException(); + public Task ConnectAsync(bool selfDeaf = false, bool selfMute = false, bool external = false) { throw new NotImplementedException(); @@ -31,11 +33,21 @@ namespace Discord throw new NotImplementedException(); } + public Task ModifyMessageAsync(ulong messageId, Action func, RequestOptions options = null) + { + throw new NotImplementedException(); + } + public Task DisconnectAsync() { throw new NotImplementedException(); } + public Task ModifyAsync(Action func, RequestOptions options) + { + throw new NotImplementedException(); + } + public IDisposable EnterTypingState(RequestOptions options = null) { throw new NotImplementedException(); @@ -81,17 +93,17 @@ namespace Discord throw new NotImplementedException(); } - public Task SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) + public Task SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent component = null, ISticker[] stickers = null, Embed[] embeds = null) { throw new NotImplementedException(); } - public Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) + public Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent component = null, ISticker[] stickers = null, Embed[] embeds = null) { throw new NotImplementedException(); } - public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null) + public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent component = null, ISticker[] stickers = null, Embed[] embeds = null) { throw new NotImplementedException(); } @@ -100,5 +112,8 @@ namespace Discord { throw new NotImplementedException(); } + + public Task SendFileAsync(FileAttachment attachment, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent component = null, ISticker[] stickers = null, Embed[] embeds = null) => throw new NotImplementedException(); + public Task SendFilesAsync(IEnumerable attachments, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent component = null, ISticker[] stickers = null, Embed[] embeds = null) => throw new NotImplementedException(); } } diff --git a/test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs b/test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs index a57c72899..ad0af04b2 100644 --- a/test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs +++ b/test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs @@ -46,6 +46,10 @@ namespace Discord { throw new NotImplementedException(); } + public Task CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => throw new NotImplementedException(); + public Task CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => throw new NotImplementedException(); public Task CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null) { @@ -77,6 +81,11 @@ namespace Discord throw new NotImplementedException(); } + public Task ModifyMessageAsync(ulong messageId, Action func, RequestOptions options = null) + { + throw new NotImplementedException(); + } + public IDisposable EnterTypingState(RequestOptions options = null) { throw new NotImplementedException(); @@ -167,17 +176,17 @@ namespace Discord throw new NotImplementedException(); } - public Task SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) + public Task SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent component = null, ISticker[] stickers = null, Embed[] embeds = null) { throw new NotImplementedException(); } - public Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) + public Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent component = null, ISticker[] stickers = null, Embed[] embeds = null) { throw new NotImplementedException(); } - public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null) + public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent component = null, ISticker[] stickers = null, Embed[] embeds = null) { throw new NotImplementedException(); } @@ -201,5 +210,10 @@ namespace Discord { throw new NotImplementedException(); } + + public Task SendFileAsync(FileAttachment attachment, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent component = null, ISticker[] stickers = null, Embed[] embeds = null) => throw new NotImplementedException(); + public Task SendFilesAsync(IEnumerable attachments, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent component = null, ISticker[] stickers = null, Embed[] embeds = null) => throw new NotImplementedException(); + public Task CreateThreadAsync(string name, ThreadType type = ThreadType.PublicThread, ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, IMessage message = null, bool? invitable = null, int? slowmode = null, RequestOptions options = null) => throw new NotImplementedException(); + public Task CreateInviteToApplicationAsync(DefaultApplications application, int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) => throw new NotImplementedException(); } } diff --git a/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs b/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs index eb617125d..533b1b1b5 100644 --- a/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs +++ b/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs @@ -12,6 +12,8 @@ namespace Discord public int? UserLimit => throw new NotImplementedException(); + public string Mention => throw new NotImplementedException(); + public ulong? CategoryId => throw new NotImplementedException(); public int Position => throw new NotImplementedException(); @@ -25,9 +27,10 @@ namespace Discord public string Name => throw new NotImplementedException(); public DateTimeOffset CreatedAt => throw new NotImplementedException(); - public ulong Id => throw new NotImplementedException(); + public string RTCRegion => throw new NotImplementedException(); + public Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null) { throw new NotImplementedException(); @@ -47,6 +50,11 @@ namespace Discord { throw new NotImplementedException(); } + public Task CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => throw new NotImplementedException(); + public Task CreateInviteToApplicationAsync(DefaultApplications application, int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) => throw new NotImplementedException(); + public Task CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) + => throw new NotImplementedException(); public Task DeleteAsync(RequestOptions options = null) { @@ -58,6 +66,11 @@ namespace Discord throw new NotImplementedException(); } + public Task ModifyAsync(Action func, RequestOptions options) + { + throw new NotImplementedException(); + } + public Task GetCategoryAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null) { throw new NotImplementedException(); diff --git a/test/Discord.Net.Tests.Unit/TimeSpanTypeReaderTests.cs b/test/Discord.Net.Tests.Unit/TimeSpanTypeReaderTests.cs new file mode 100644 index 000000000..4cd9cae09 --- /dev/null +++ b/test/Discord.Net.Tests.Unit/TimeSpanTypeReaderTests.cs @@ -0,0 +1,70 @@ +using Discord.Commands; +using System; +using Xunit; + +namespace Discord +{ + public class TimeSpanTypeReaderTests + { + [Theory] + [InlineData("4d3h2m1s", false)] // tests format "%d'd'%h'h'%m'm'%s's'" + [InlineData("4d3h2m", false)] // tests format "%d'd'%h'h'%m'm'" + [InlineData("4d3h1s", false)] // tests format "%d'd'%h'h'%s's'" + [InlineData("4d3h", false)] // tests format "%d'd'%h'h'" + [InlineData("4d2m1s", false)] // tests format "%d'd'%m'm'%s's'" + [InlineData("4d2m", false)] // tests format "%d'd'%m'm'" + [InlineData("4d1s", false)] // tests format "%d'd'%s's'" + [InlineData("4d", false)] // tests format "%d'd'" + [InlineData("3h2m1s", false)] // tests format "%h'h'%m'm'%s's'" + [InlineData("3h2m", false)] // tests format "%h'h'%m'm'" + [InlineData("3h1s", false)] // tests format "%h'h'%s's'" + [InlineData("3h", false)] // tests format "%h'h'" + [InlineData("2m1s", false)] // tests format "%m'm'%s's'" + [InlineData("2m", false)] // tests format "%m'm'" + [InlineData("1s", false)] // tests format "%s's'" + // Negatives + [InlineData("-4d3h2m1s", true)] // tests format "-%d'd'%h'h'%m'm'%s's'" + [InlineData("-4d3h2m", true)] // tests format "-%d'd'%h'h'%m'm'" + [InlineData("-4d3h1s", true)] // tests format "-%d'd'%h'h'%s's'" + [InlineData("-4d3h", true)] // tests format "-%d'd'%h'h'" + [InlineData("-4d2m1s", true)] // tests format "-%d'd'%m'm'%s's'" + [InlineData("-4d2m", true)] // tests format "-%d'd'%m'm'" + [InlineData("-4d1s", true)] // tests format "-%d'd'%s's'" + [InlineData("-4d", true)] // tests format "-%d'd'" + [InlineData("-3h2m1s", true)] // tests format "-%h'h'%m'm'%s's'" + [InlineData("-3h2m", true)] // tests format "-%h'h'%m'm'" + [InlineData("-3h1s", true)] // tests format "-%h'h'%s's'" + [InlineData("-3h", true)] // tests format "-%h'h'" + [InlineData("-2m1s", true)] // tests format "-%m'm'%s's'" + [InlineData("-2m", true)] // tests format "-%m'm'" + [InlineData("-1s", true)] // tests format "-%s's'" + public void TestTimeSpanParse(string input, bool isNegative) + { + var reader = new TimeSpanTypeReader(); + var result = reader.ReadAsync(null, input, null).Result; + Assert.True(result.IsSuccess); + + var actual = (TimeSpan)result.BestMatch; + Assert.True(actual != TimeSpan.Zero); + + if (isNegative) + { + Assert.True(actual < TimeSpan.Zero); + + Assert.True(actual.Seconds == 0 || actual.Seconds == -1); + Assert.True(actual.Minutes == 0 || actual.Minutes == -2); + Assert.True(actual.Hours == 0 || actual.Hours == -3); + Assert.True(actual.Days == 0 || actual.Days == -4); + } + else + { + Assert.True(actual > TimeSpan.Zero); + + Assert.True(actual.Seconds == 0 || actual.Seconds == 1); + Assert.True(actual.Minutes == 0 || actual.Minutes == 2); + Assert.True(actual.Hours == 0 || actual.Hours == 3); + Assert.True(actual.Days == 0 || actual.Days == 4); + } + } + } +} diff --git a/test/Discord.Net.Tests.Unit/TokenUtilsTests.cs b/test/Discord.Net.Tests.Unit/TokenUtilsTests.cs index bbfbfe754..4306fa9e2 100644 --- a/test/Discord.Net.Tests.Unit/TokenUtilsTests.cs +++ b/test/Discord.Net.Tests.Unit/TokenUtilsTests.cs @@ -83,7 +83,7 @@ namespace Discord public void BotTokenDoesNotThrowExceptions(string token) { // This example token is pulled from the Discord Docs - // https://discordapp.com/developers/docs/reference#authentication-example-bot-token-authorization-header + // https://discord.com/developers/docs/reference#authentication-example-bot-token-authorization-header // should not throw any exception TokenUtils.ValidateToken(TokenType.Bot, token); } @@ -127,8 +127,6 @@ namespace Discord /// The type is treated as an invalid . /// [Theory] - // TokenType.User - [InlineData(0)] // out of range TokenType [InlineData(-1)] [InlineData(4)] diff --git a/test/Discord.Net.Tests/Tests.DiscordWebhookClient.cs b/test/Discord.Net.Tests/Tests.DiscordWebhookClient.cs index 039525afc..52c39005b 100644 --- a/test/Discord.Net.Tests/Tests.DiscordWebhookClient.cs +++ b/test/Discord.Net.Tests/Tests.DiscordWebhookClient.cs @@ -12,18 +12,18 @@ namespace Discord public class DiscordWebhookClientTests { [Theory] - [InlineData("https://discordapp.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK", + [InlineData("https://discord.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK", 123412347732897802, "_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")] // ptb, canary, etc will have slightly different urls - [InlineData("https://ptb.discordapp.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK", + [InlineData("https://ptb.discord.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK", 123412347732897802, "_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")] - [InlineData("https://canary.discordapp.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK", + [InlineData("https://canary.discord.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK", 123412347732897802, "_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")] // don't care about https - [InlineData("http://canary.discordapp.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK", + [InlineData("http://canary.discord.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK", 123412347732897802, "_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")] // this is the minimum that the regex cares about - [InlineData("discordapp.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK", + [InlineData("discord.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK", 123412347732897802, "_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")] public void TestWebhook_Valid(string webhookurl, ulong expectedId, string expectedToken) { @@ -48,7 +48,7 @@ namespace Discord [Theory] [InlineData("123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK")] // trailing slash - [InlineData("https://discordapp.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK/")] + [InlineData("https://discord.com/api/webhooks/123412347732897802/_abcde123456789-ABCDEFGHIJKLMNOP12345678-abcdefghijklmnopABCDEFGHIJK/")] public void TestWebhook_Invalid(string webhookurl) { Assert.Throws(() => diff --git a/voice-natives/README.md b/voice-natives/README.md new file mode 100644 index 000000000..a89fad45f --- /dev/null +++ b/voice-natives/README.md @@ -0,0 +1,12 @@ +# Voice binaries + +These binaries were taken from the [DSharpPlus](https://dsharpplus.github.io/natives/index.html) website and are temporary until we resolve the old url for them. + +**NOTE**: You need to rename libopus.dll to opus.dll before use, otherwise audio client will complain about missing libraries. + +#### Licenses + +| Library | License | +| :-------: | :-------------------------------------------------------- | +| Opus | https://opus-codec.org/license/ | +| libsodium | https://github.com/jedisct1/libsodium/blob/master/LICENSE | diff --git a/voice-natives/vnext_natives_win32_x64.zip b/voice-natives/vnext_natives_win32_x64.zip new file mode 100644 index 000000000..a447803e5 Binary files /dev/null and b/voice-natives/vnext_natives_win32_x64.zip differ diff --git a/voice-natives/vnext_natives_win32_x86.zip b/voice-natives/vnext_natives_win32_x86.zip new file mode 100644 index 000000000..35522e1ec Binary files /dev/null and b/voice-natives/vnext_natives_win32_x86.zip differ