commitpull/988/head17a4af71eeAuthor: Still Hsu <341464@gmail.com> Date: Tue May 29 17:15:10 2018 +0800 Add documentation for new API version & few events commitf4fb027ea9Merge:d74c52873acf2a9aAuthor: Still Hsu <341464@gmail.com> Date: Tue May 29 08:25:41 2018 +0800 Merge remote-tracking branch 'upstream/dev' into docs/faq-n-patches-offline commit3acf2a9a6bAuthor: HelpfulStranger999 <helpfulstranger999@gmail.com> Date: Mon May 28 14:59:30 2018 -0500 Refactors readMessages, fixing from #1033 (#1075) commit513a489bf8Author: Christopher F <foxbot@protonmail.com> Date: Mon May 28 15:45:42 2018 -0400 codefix: add VoiceAPIVersion constant to DiscordConfig commit9ba38d7796Author: Christopher F <foxbot@protonmail.com> Date: Mon May 28 15:35:59 2018 -0400 api: upgrade audio client to VoiceWS v3 commit64d8938ed5Author: Christopher F <foxbot@protonmail.com> Date: Mon May 28 15:25:46 2018 -0400 fix: Discord does not always send the member on VOICE_STATE_UPDATE some guilds aren't on g250k yet? not sure commitaeb3095593Author: FiniteReality <digpoealternate@gmail.com> Date: Mon May 28 17:48:38 2018 +0100 Remove Debug.Print call causing tests to fail Forgot to hit save properly... Whoops. commita718a7d3c2Author: Christopher F <foxbot@protonmail.com> Date: Mon May 28 12:45:49 2018 -0400 cleanup: Remove ChannelHelper#IsNsfw Closes #1074 This code was not referenced anywhere in the active codebase. commit0c7cb73b06Author: FiniteReality <digpoealternate@gmail.com> Date: Mon May 28 17:41:05 2018 +0100 Fix permission-related ViewChannel tests commit415e2f7739Author: FiniteReality <digpoealternate@gmail.com> Date: Mon May 28 17:14:18 2018 +0100 Fix analyzer warnings with tests Use (actual, expected) format for Assert.Equal, fixes analyzer warnings commitb0042606b6Author: FiniteReality <digpoealternate@gmail.com> Date: Mon May 28 17:13:59 2018 +0100 Move RpcCategoryChannel into the correct project commit683b3f2701Author: FiniteReality <digpoealternate@gmail.com> Date: Mon May 28 17:12:28 2018 +0100 Mark ChannelHelper.IsNsfw Obsolete Discord no longer treats channels prefixed with 'nsfw' as NSFW, so we no longer need to have this check. commitd74c52873fMerge:341b9588237ad0f8Author: Still Hsu <341464@gmail.com> Date: Mon May 28 11:48:47 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit237ad0f867Author: Christopher F <foxbot@protonmail.com> Date: Sun May 27 18:00:51 2018 -0400 Revert "fix: Properly rethrow exceptions in SocketGuild audio client" This reverts commitadf4da19fc. Someone hasn't written c# in a while commitadf4da19fcAuthor: Christopher F <foxbot@protonmail.com> Date: Sun May 27 17:56:14 2018 -0400 fix: Properly rethrow exceptions in SocketGuild audio client commitc0c565fd7eAuthor: Christopher F <foxbot@protonmail.com> Date: Sun May 27 16:45:54 2018 -0400 retain fallback case for if user is still null commit8fb2c71814Author: Christopher F <foxbot@protonmail.com> Date: Sun May 27 16:37:17 2018 -0400 Add new member objects to events commit341b9588d6Author: Still Hsu <341464@gmail.com> Date: Sun May 27 19:01:04 2018 +0800 Add documentation commit2df635e025Merge:180b20dd9995cab4Author: Still Hsu <341464@gmail.com> Date: Sun May 27 18:25:51 2018 +0800 Merge pull request #1 from Chris-Johnston/better-documentation-for-quotation-mark-aliases Improve XML docs for commands quotation mark aliases feature commit180b20dd02Author: Still Hsu <341464@gmail.com> Date: Sun May 27 18:19:20 2018 +0800 Add documentation for new INestedChannel commite9f72b6eceAuthor: Still Hsu <341464@gmail.com> Date: Sun May 27 18:18:52 2018 +0800 Fix missing service provider in example commit9995cab40cMerge:a8d3031b1a146afbAuthor: Chris Johnston <chris@thejohnstons.net> Date: Sun May 27 01:11:17 2018 -0700 Merge branch 'docs/faq-n-patches-offline' into better-documentation-for-quotation-mark-aliases commita8d3031b2dAuthor: Chris Johnston <chris@thejohnstons.net> Date: Sat May 26 23:32:40 2018 -0700 Add explanation that if " is removed then it wont work commitcb7c6d3546Author: Chris Johnston <chris@thejohnstons.net> Date: Sat May 26 23:29:32 2018 -0700 Add reference to CommandServiceConfig from the util docs' commit110b97513fAuthor: Chris Johnston <chris@thejohnstons.net> Date: Sat May 26 23:15:01 2018 -0700 Add more XML comments to quotation mark alias map stuff, including an example commit1a146afbe1Merge:cb57ada8a06e2126Author: Still Hsu <341464@gmail.com> Date: Sun May 27 11:25:10 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commita06e21261cAuthor: Chris Johnston <chris@thejohnstons.net> Date: Sat May 26 11:15:09 2018 -0700 Fix ChannelPermissions Modify parameter to be correct default value (#1003) * fix channel permissions modify parameter to use nullable boolean, correct default value * Add general tests for the ChannelPermissions.Modify method to test default values * remove unused cast in tests * add guildpermission modify no param tests * Add no-param modify tests for OverwritePermissions * fix inconsistent parameters in GuildPermissions cstr * Adjust formatting of methods and cstrs with many parameters * remove temp file that was included. no idea what that is * Fix System dependency I should really stop fixing merge conflicts in the github website. commitf9cbff5e42Author: Chris Johnston <chris@thejohnstons.net> Date: Sat May 26 11:06:35 2018 -0700 Fix #995, Move Category Implementation from IGuildChannel to INestedChannel (#1004) * Fix #995 ICategoryChannel.CategoryID throws NotSupportedException * Add tests * change run mode of TestChannelCategories * Add throw for GetCategoryAsync * Add xml doc explaining why exception is thrown * Add test coverage for text and voice channel categories * initial implementation of INestedChannel * more implementation of INestedChannel design * Add case in RestChannel Create for Category type * set the CategoryID for RestVoiceChannel * rewrite channel category tests to work with existing pattern * remove outdated todo * Make IVoiceChannel implement INestedChannel * remove redundant interface implementation * Add c#7 feature from feedback * Remove redundant GetCategoryAsync methods from socket entities * Added configureawait to async methods * change signature of interface GetCategoryAsync * Add check for cachemode in rest channel GetCategory * remove redundant IGuildChannel interface from ITextChannel and IVoiceChannel commit4d8764e124Author: FiniteReality <digpoealternate@gmail.com> Date: Sat May 26 14:11:49 2018 +0100 Refactor RoleInfo types into separate classes - Fixes indentation with a few files (looks like a bad copy+paste job) - Renames RoleInfo to RoleEditInfo - Moves RoleInfo from MemberRoleAuditLogData into its own class All of this should improve docs. commitcb57ada8d9Author: Still Hsu <341464@gmail.com> Date: Sat May 26 21:03:07 2018 +0800 Add partial documentation for audit log objects commitafda0cd172Author: Still Hsu <341464@gmail.com> Date: Sat May 26 20:47:21 2018 +0800 Add documentation for some REST-based objects commit098ead93d9Author: Still Hsu <341464@gmail.com> Date: Sat May 26 16:33:38 2018 +0800 Add partial documentation for audit log impl commit5d1621a9c5Author: Still Hsu <341464@gmail.com> Date: Sat May 26 16:06:20 2018 +0800 Fix xml docs error commit596b47e1b8Merge:3f572cccfa759a22Author: Still Hsu <341464@gmail.com> Date: Sat May 26 15:54:08 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit3f572ccc0dMerge:73ebc025a9983026Author: Still Hsu <341464@gmail.com> Date: Sat May 26 15:32:38 2018 +0800 Merge branch 'docs/faq-n-patches-offline' of https://github.com/Still34/Discord.Net into docs/faq-n-patches-offline commit73ebc02580Author: Still Hsu <341464@gmail.com> Date: Sat May 26 15:32:23 2018 +0800 Fix light theme link color commitfa759a22eaAuthor: Chris Johnston <chris@thejohnstons.net> Date: Fri May 25 06:38:59 2018 -0700 Remove Build Warnings for Obsolete Guild Permission Read Messages (#1067) - Replaces the usages of `ReadMessages` with `ViewChannel` - Renames the read message parameters of `GuildPermissions#Modify` to be view channel as well commitbbbac85c46Author: Hawx <Hawxy@users.noreply.github.com> Date: Fri May 25 20:14:28 2018 +0800 Update Dependencies and support NS2.0 builds (#1046) * Update deps, fix test warnings. * Support ns2.0 * Fix typo * Remove ns1.1 support * Net.Http and Net.Websockets.Client are not needed in ns2.0 * Move to net46 per volt * Remove ns1.3 constants commit5f084adf94Author: HelpfulStranger999 <helpfulstranger999@gmail.com> Date: Thu May 24 19:17:19 2018 -0500 Deprecates ReadMessages, introduces ViewChannel (#1033) * Deprecates ReadMessages, introduces ViewChannel * Adds period and comma somehow missed commitbc6009ec72Author: Still Hsu <341464@gmail.com> Date: Fri May 25 08:08:51 2018 +0800 Implement IMessageChannel#DeleteMessageAsync (#996) * Implement DeleteMessageAsync * Refer to MessageHelper instead of duplicating call * Fix refactor error commitcee71ef35aAuthor: Chris Johnston <chris@thejohnstons.net> Date: Thu May 24 17:07:37 2018 -0700 Add support for parsing multiple types of quotation marks in commands, Fix #942 (#943) * Add ability to support different types of quotation marks * Added normal quotation mark to list of aliases, removed single quote mark * clean up leftover changes from testing * change quotation mark parsing to use a map of matching pairs * remove commented out code * Fix conventions of the command parser utility functions * change storage type of alias dictionary to be IReadOnlyDictionary * revert type of CommandServiceConfig QuotationMarkAliasMap to Dictionary * minor formatting changes to CommandParser * remove unnecessary whitespace * Move aliases outside of CommandInfo class * copy IReadOnlyDictionary to ImmutableDictionary * minor syntax changes in CommandServiceConfig * add newline before namespace for consistency * newline formatting tweak * simplification of GetMatch method for CommandParser * add more quote unicode punctuation pairs * add check for null value when building ImmutableDictionary * Move default alias map into a separate source file * Ensure that the collection passed into command service is not null commitb52af7ae7cAuthor: Joe4evr <jii.geugten@gmail.com> Date: Fri May 25 01:59:32 2018 +0200 Add a dedicated TimeSpan reader so it doesn't suck (#1005) * Add a dedicated TimeSpan reader so it doesn't suck * Pass input as lower case commitc275e57528Author: o Acid Chicken (硫硫▒~E▒▒▒~O) <root@acid-chicken.com> Date: Thu May 24 19:52:25 2018 -0400 Add support casting System.Drawing.Color to Discord.Color commitfa33034267Author: Acid Chicken (硫酸鶏) <root@acid-chicken.com> Date: Sun Apr 29 13:50:56 2018 +0900 Use built-in symbol refs: https://github.com/RogueException/Discord.Net/pull/1043#issuecomment-385223999 commit27ea826685Author: Acid Chicken (硫酸鶏) <root@acid-chicken.com> Date: Sun Apr 29 11:29:31 2018 +0900 Add support casting System.Drawing.Color to Discord.Color commit1ab9de2497Merge:f5bb99c7a4d1e2bcAuthor: Acid Chicken (硫酸鶏) <root@acid-chicken.com> Date: Sun Apr 29 10:16:46 2018 +0900 Merge remote-tracking branch 'upstream/dev' into dev commitf5bb99c77dMerge:3be8e40db8b59d97Author: Acid Chicken (硫酸鶏) <root@acid-chicken.com> Date: Tue Apr 10 11:07:36 2018 +0900 Merge remote-tracking branch 'upstream/dev' into dev commit3be8e40d38Merge:c692306f9d77a3cdAuthor: Acid Chicken (硫酸鶏) <root@acid-chicken.com> Date: Sun Jan 7 15:05:31 2018 +0900 Merge remote-tracking branch 'upstream/dev' into dev commitc692306fccAuthor: Acid Chicken (硫酸鶏) <root@acid-chicken.com> Date: Sat Nov 11 10:49:00 2017 +0900 Add target of the internal fields commit2d08f9a655Author: Acid Chicken (硫酸鶏) <root@acid-chicken.com> Date: Sat Nov 11 10:17:42 2017 +0900 Add some more extension commit4f19b835ffAuthor: Acid Chicken (硫酸鶏) <root@acid-chicken.com> Date: Sat Nov 11 01:19:11 2017 +0900 Add naming rules commitaf756cd9feAuthor: Acid Chicken (硫酸鶏) <root@acid-chicken.com> Date: Sat Nov 11 00:35:30 2017 +0900 Add basic .NET style rules commit503ece558bAuthor: Acid Chicken (硫酸鶏) <root@acid-chicken.com> Date: Fri Nov 10 22:36:52 2017 +0900 Add EditorConfig commit5023357a60Author: Christopher F <foxbot@protonmail.com> Date: Thu May 24 19:36:33 2018 -0400 codefix #1020: RequestOptions should always be sorted last commitbf5275e071Author: Joe4evr <jii.geugten@gmail.com> Date: Thu May 24 19:36:00 2018 -0400 Add ability to specify parameters on channel creation (#1020) commit07bca5b31aAuthor: Joe4evr <jii.geugten@gmail.com> Date: Fri Apr 6 09:44:50 2018 +0200 Add ability to specify parameters on channel creation commit0ba8b063adAuthor: HelpfulStranger999 <helpfulstranger999@gmail.com> Date: Thu May 24 19:23:44 2018 -0400 Makes text parameter of sending messages optional (#1042) commit114e5b431bAuthor: HelpfulStranger999 <helpfulstranger999@gmail.com> Date: Sat Apr 28 19:08:35 2018 -0500 Fixes lack of default value for tts commit1fd8c70c53Author: HelpfulStranger999 <helpfulstranger999@gmail.com> Date: Sat Apr 28 15:21:11 2018 -0500 Makes text parameter of sending messages optional commit79811d0e61Author: HelpfulStranger999 <helpfulstranger999@gmail.com> Date: Thu May 24 17:35:38 2018 -0500 Paginate reactions - solved #1007 (#1022) * Cleaned up and refactored slightly * Resolves #971 * Adds support for default avatars and resolves #971 * Amendment * Final amendment * Paginating reactions * Amendments based on feedback * Further amendment based on review * Final(?) amendment * Removes default limit and after user id * Removes fromUserId; cleans up model creation; replaces function with individual parameters commita9983026f0Author: Still Hsu <341464@gmail.com> Date: Tue May 22 10:15:49 2018 +0800 Add event docs - MessageReceived - ChannelUpdated/Destroyed/Created commitdece19d895Merge:fdaa689ae764dafeAuthor: Still Hsu <341464@gmail.com> Date: Mon May 21 11:47:47 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commitfdaa689ae8Author: Still Hsu <341464@gmail.com> Date: Wed May 9 06:04:59 2018 +0800 Add explanation for RunMode commitea82c2537eAuthor: Still Hsu <341464@gmail.com> Date: Tue May 8 16:30:48 2018 +0800 Initial proofread of the articles commit124f1a267cMerge:2555721897c89310Author: Still Hsu <341464@gmail.com> Date: Tue May 8 05:02:01 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit25557218dbAuthor: Still Hsu <341464@gmail.com> Date: Sun May 6 16:11:19 2018 +0800 Add details to SpotifyGame commitc7b236ddf5Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:58:23 2018 +0800 Add more IGuild docs commit1bb06cc37bAuthor: Still Hsu <341464@gmail.com> Date: Sun May 6 15:40:31 2018 +0800 Replace all langword placements with code block commitac47d84ea7Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:22:17 2018 +0800 Replace langword null to code block null instead - Because DocFX sucks at rendering langword commit0b15bbc54dAuthor: Still Hsu <341464@gmail.com> Date: Sun May 6 15:20:34 2018 +0800 Add XML docs commit65d4e4360eAuthor: Still Hsu <341464@gmail.com> Date: Sun May 6 06:57:53 2018 +0800 Add BaseSocketClient docs commit8f64c04599Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:37:55 2018 +0800 Replace note block commitd8bb9e7aaaAuthor: Still Hsu <341464@gmail.com> Date: Sun May 6 06:31:50 2018 +0800 Add warning for bulk-delete endpoint commitadae5ffc9eAuthor: Still Hsu <341464@gmail.com> Date: Sun May 6 06:07:28 2018 +0800 Fix missing Username prop commit3e591972caAuthor: Still Hsu <341464@gmail.com> Date: Sun May 6 06:01:34 2018 +0800 Add properties examples to overwrite commit0ad66f6765Author: Still Hsu <341464@gmail.com> Date: Sun May 6 04:55:15 2018 +0800 Fix minor consistencies & redundant impl commit124efdf7e6Author: Still Hsu <341464@gmail.com> Date: Sun May 6 04:40:14 2018 +0800 XML Docs commit3aa5d363deAuthor: Still Hsu <341464@gmail.com> Date: Sat May 5 18:22:46 2018 +0800 Add 'last modified' plugin Source: https://github.com/Still34/DocFx.Plugin.LastModified Licensed under MIT License commit2014870dc0Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:57:40 2018 +0800 Fix letter-casing for files commitf27d659ebeAuthor: Still Hsu <341464@gmail.com> Date: Sat May 5 15:50:00 2018 +0800 Document exposed TypeReaders commit5a824a5695Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:44:15 2018 +0800 Add missing exceptions commitc2de0c055fAuthor: Still Hsu <341464@gmail.com> Date: Sat May 5 15:40:16 2018 +0800 Fix seealso for preconditions and add missing descriptions commit3a7d7ee955Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:36:22 2018 +0800 Minor fixes in documentations + Fix unescaped '<' + Fix typo commit45839bd982Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:29:47 2018 +0800 Add XML Docs commit9e6254600cMerge:aea06788bb4bb138Author: Still Hsu <341464@gmail.com> Date: Sat May 5 14:48:13 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commitaea067884cMerge:27dc48319ddd7090Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:51:07 2018 +0800 Merge branch 'docs/faq-n-patches-offline' of https://github.com/Still34/Discord.Net into docs/faq-n-patches-offline commit27dc4831e8Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:50:27 2018 +0800 Add XML Docs commitbaa8beb382Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:49:42 2018 +0800 Add XML Docs commit089f97a010Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:43:04 2018 +0800 Add details regarding userbot support commit9ddd70906aMerge:f197174f7cfed7ffAuthor: Still Hsu <341464@gmail.com> Date: Fri May 4 09:37:04 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commitf197174fccAuthor: Still Hsu <341464@gmail.com> Date: Fri May 4 09:36:53 2018 +0800 Fix embed docs consistency commit157acc4695Author: Still Hsu <341464@gmail.com> Date: Thu May 3 23:03:35 2018 +0800 Add tag examples commit57ea571a81Author: Still Hsu <341464@gmail.com> Date: Thu May 3 22:48:33 2018 +0800 Fix sample link & add missing pictures commit6769c37ad7Author: Still Hsu <341464@gmail.com> Date: Thu May 3 22:39:26 2018 +0800 Compress some assets & add OAuth2 URL generator
| @@ -16,13 +16,7 @@ | |||
| <PropertyGroup Condition=" '$(BuildNumber)' != '' And $(IsTagBuild) != 'true' "> | |||
| <VersionSuffix Condition=" '$(VersionSuffix)' != '' ">$(VersionSuffix)-$(BuildNumber)</VersionSuffix> | |||
| <VersionSuffix Condition=" '$(VersionSuffix)' == '' ">build-$(BuildNumber)</VersionSuffix> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' Or '$(TargetFramework)' == 'net45' "> | |||
| <DefineConstants>$(DefineConstants);FILESYSTEM;DEFAULTUDPCLIENT;DEFAULTWEBSOCKET</DefineConstants> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' "> | |||
| <DefineConstants>$(DefineConstants);FORMATSTR;UNIXTIME;MSTRYBUFFER;UDPDISPOSE</DefineConstants> | |||
| </PropertyGroup> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | |||
| <NoWarn>$(NoWarn);CS1573;CS1591</NoWarn> | |||
| <WarningsAsErrors>true</WarningsAsErrors> | |||
| @@ -10,11 +10,24 @@ body { | |||
| overflow: visible; | |||
| } | |||
| /* links */ | |||
| a:active, a:hover, a:visited { | |||
| color: #0078d7; | |||
| } | |||
| a { | |||
| color: #0050c5; | |||
| cursor: pointer; | |||
| text-decoration: none; | |||
| word-wrap: break-word; | |||
| } | |||
| /* code */ | |||
| code { | |||
| color: #222f3d; | |||
| background-color: #f9f9f9; | |||
| color: #3b5269; | |||
| background-color: #ececec; | |||
| border-radius: 4px; | |||
| padding: 3px 7px; | |||
| } | |||
| @@ -43,7 +43,7 @@ | |||
| "globalMetadata": { | |||
| "_appTitle": "Discord.Net Documentation", | |||
| "_appFooter": "Discord.Net (c) 2015-2018 2.0.0-beta", | |||
| "_enableSearch": true, | |||
| "_enableSearch": true | |||
| }, | |||
| "noLangKeyword": false, | |||
| "xrefService": [ | |||
| @@ -1,12 +1,14 @@ | |||
| public class CommandHandle | |||
| public class CommandHandler | |||
| { | |||
| private readonly DiscordSocketClient _client; | |||
| private readonly CommandService _commands; | |||
| private readonly IServiceProvider _services; | |||
| public CommandHandle(DiscordSocketClient client) | |||
| public CommandHandler(IServiceProvider services) | |||
| { | |||
| _client = client; | |||
| _commands = new CommandService(); | |||
| _services = services; | |||
| _commands = services.GetRequiredService<CommandService>(); | |||
| _client = services.GetRequiredService<DiscordSocketClient>(); | |||
| } | |||
| public async Task InstallCommandsAsync() | |||
| @@ -6,7 +6,7 @@ | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.0-preview1-final" /> | |||
| <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| @@ -7,7 +7,7 @@ | |||
| <TargetFramework>netstandard1.3</TargetFramework> | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <PackageReference Include="Microsoft.CodeAnalysis" Version="2.6.0" /> | |||
| <PackageReference Include="Microsoft.CodeAnalysis" Version="2.8.0" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <ProjectReference Include="..\Discord.Net.Commands\Discord.Net.Commands.csproj" /> | |||
| @@ -1,4 +1,5 @@ | |||
| using System; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Collections.Immutable; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| @@ -13,8 +14,7 @@ namespace Discord.Commands | |||
| Parameter, | |||
| QuotedParameter | |||
| } | |||
| public static async Task<ParseResult> ParseArgsAsync(CommandInfo command, ICommandContext context, IServiceProvider services, string input, int startPos) | |||
| public static async Task<ParseResult> ParseArgsAsync(CommandInfo command, ICommandContext context, bool ignoreExtraArgs, IServiceProvider services, string input, int startPos, IReadOnlyDictionary<char, char> aliasMap) | |||
| { | |||
| ParameterInfo curParam = null; | |||
| StringBuilder argBuilder = new StringBuilder(input.Length); | |||
| @@ -24,7 +24,27 @@ namespace Discord.Commands | |||
| var argList = ImmutableArray.CreateBuilder<TypeReaderResult>(); | |||
| var paramList = ImmutableArray.CreateBuilder<TypeReaderResult>(); | |||
| bool isEscaping = false; | |||
| char c; | |||
| char c, matchQuote = '\0'; | |||
| // local helper functions | |||
| bool IsOpenQuote(IReadOnlyDictionary<char, char> dict, char ch) | |||
| { | |||
| // return if the key is contained in the dictionary if it is populated | |||
| if (dict.Count != 0) | |||
| return dict.ContainsKey(ch); | |||
| // or otherwise if it is the default double quote | |||
| return c == '\"'; | |||
| } | |||
| char GetMatch(IReadOnlyDictionary<char, char> dict, char ch) | |||
| { | |||
| // get the corresponding value for the key, if it exists | |||
| // and if the dictionary is populated | |||
| if (dict.Count != 0 && dict.TryGetValue(c, out var value)) | |||
| return value; | |||
| // or get the default pair of the default double quote | |||
| return '\"'; | |||
| } | |||
| for (int curPos = startPos; curPos <= endPos; curPos++) | |||
| { | |||
| @@ -74,9 +94,11 @@ namespace Discord.Commands | |||
| argBuilder.Append(c); | |||
| continue; | |||
| } | |||
| if (c == '\"') | |||
| if (IsOpenQuote(aliasMap, c)) | |||
| { | |||
| curPart = ParserPart.QuotedParameter; | |||
| matchQuote = GetMatch(aliasMap, c); | |||
| continue; | |||
| } | |||
| curPart = ParserPart.Parameter; | |||
| @@ -97,7 +119,7 @@ namespace Discord.Commands | |||
| } | |||
| else if (curPart == ParserPart.QuotedParameter) | |||
| { | |||
| if (c == '\"') | |||
| if (c == matchQuote) | |||
| { | |||
| argString = argBuilder.ToString(); //Remove quotes | |||
| lastArgEndPos = curPos + 1; | |||
| @@ -1,4 +1,4 @@ | |||
| using System; | |||
| using System; | |||
| using System.Collections.Concurrent; | |||
| using System.Collections.Generic; | |||
| using System.Collections.Immutable; | |||
| @@ -38,6 +38,7 @@ namespace Discord.Commands | |||
| internal readonly RunMode _defaultRunMode; | |||
| internal readonly Logger _cmdLogger; | |||
| internal readonly LogManager _logManager; | |||
| internal readonly IReadOnlyDictionary<char, char> _quotationMarkAliasMap; | |||
| /// <summary> | |||
| /// Represents all modules loaded within <see cref="CommandService" />. | |||
| @@ -73,6 +74,7 @@ namespace Discord.Commands | |||
| _ignoreExtraArgs = config.IgnoreExtraArgs; | |||
| _separatorChar = config.SeparatorChar; | |||
| _defaultRunMode = config.DefaultRunMode; | |||
| _quotationMarkAliasMap = (config.QuotationMarkAliasMap ?? new Dictionary<char, char>()).ToImmutableDictionary(); | |||
| if (_defaultRunMode == RunMode.Default) | |||
| throw new InvalidOperationException("The default run mode cannot be set to Default."); | |||
| @@ -93,6 +95,10 @@ namespace Discord.Commands | |||
| _defaultTypeReaders[typeof(Nullable<>).MakeGenericType(type)] = NullableTypeReader.Create(type, _defaultTypeReaders[type]); | |||
| } | |||
| var tsreader = new TimeSpanTypeReader(); | |||
| _defaultTypeReaders[typeof(TimeSpan)] = tsreader; | |||
| _defaultTypeReaders[typeof(TimeSpan?)] = NullableTypeReader.Create(typeof(TimeSpan), tsreader); | |||
| _defaultTypeReaders[typeof(string)] = | |||
| new PrimitiveTypeReader<string>((string x, out string y) => { y = x; return true; }, 0); | |||
| @@ -447,7 +453,6 @@ namespace Discord.Commands | |||
| public async Task<IResult> ExecuteAsync(ICommandContext context, string input, IServiceProvider services, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) | |||
| { | |||
| services = services ?? EmptyServiceProvider.Instance; | |||
| var searchResult = Search(context, input); | |||
| if (!searchResult.IsSuccess) | |||
| return searchResult; | |||
| @@ -1,4 +1,5 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| namespace Discord.Commands | |||
| { | |||
| @@ -34,8 +35,27 @@ namespace Discord.Commands | |||
| public bool ThrowOnError { get; set; } = true; | |||
| /// <summary> | |||
| /// Gets or sets whether extra parameters should be ignored. | |||
| /// Collection of aliases for matching pairs of string delimiters. | |||
| /// The dictionary stores the opening delimiter as a key, and the matching closing delimiter as the value. | |||
| /// If no value is supplied <see cref="QuotationAliasUtils.GetDefaultAliasMap"/> will be used, which contains | |||
| /// many regional equivalents. | |||
| /// Only values that are specified in this map will be used as string delimiters, so if " is removed then | |||
| /// it won't be used. | |||
| /// If this map is set to null or empty, the default delimiter of " will be used. | |||
| /// </summary> | |||
| /// <example> | |||
| /// <code language="C#"> | |||
| /// QuotationMarkAliasMap = new Dictionary<char, char%gt;() | |||
| /// { | |||
| /// {'\"', '\"' }, | |||
| /// {'“', '”' }, | |||
| /// {'「', '」' }, | |||
| /// } | |||
| /// </code> | |||
| /// </example> | |||
| public Dictionary<char, char> QuotationMarkAliasMap { get; set; } = QuotationAliasUtils.GetDefaultAliasMap; | |||
| /// <summary> Determines whether extra parameters should be ignored. </summary> | |||
| public bool IgnoreExtraArgs { get; set; } = false; | |||
| } | |||
| } | |||
| @@ -1,15 +1,19 @@ | |||
| <Project Sdk="Microsoft.NET.Sdk"> | |||
| <Project Sdk="Microsoft.NET.Sdk"> | |||
| <Import Project="../../Discord.Net.targets" /> | |||
| <PropertyGroup> | |||
| <AssemblyName>Discord.Net.Commands</AssemblyName> | |||
| <RootNamespace>Discord.Commands</RootNamespace> | |||
| <Description>A Discord.Net extension adding support for bot commands.</Description> | |||
| <TargetFrameworks>netstandard1.1;netstandard1.3</TargetFrameworks> | |||
| <TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net46;netstandard1.3;netstandard2.0</TargetFrameworks> | |||
| <TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.3;netstandard2.0</TargetFrameworks> | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <ProjectReference Include="..\Discord.Net.Core\Discord.Net.Core.csproj" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' "> | |||
| <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" /> | |||
| </ItemGroup> | |||
| <ItemGroup Condition=" '$(TargetFramework)' != 'netstandard2.0' "> | |||
| <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" /> | |||
| </ItemGroup> | |||
| </Project> | |||
| @@ -1,4 +1,4 @@ | |||
| using Discord.Commands.Builders; | |||
| using Discord.Commands.Builders; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Collections.Immutable; | |||
| @@ -172,7 +172,8 @@ namespace Discord.Commands | |||
| return ParseResult.FromError(preconditionResult); | |||
| string input = searchResult.Text.Substring(startIndex); | |||
| return await CommandParser.ParseArgsAsync(this, context, services, input, 0).ConfigureAwait(false); | |||
| return await CommandParser.ParseArgsAsync(this, context, _commandService._ignoreExtraArgs, services, input, 0, _commandService._quotationMarkAliasMap).ConfigureAwait(false); | |||
| } | |||
| public Task<IResult> ExecuteAsync(ICommandContext context, ParseResult parseResult, IServiceProvider services) | |||
| @@ -1,4 +1,4 @@ | |||
| using System; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Collections.Immutable; | |||
| @@ -29,7 +29,7 @@ namespace Discord.Commands | |||
| parserBuilder[typeof(decimal)] = (TryParseDelegate<decimal>)decimal.TryParse; | |||
| parserBuilder[typeof(DateTime)] = (TryParseDelegate<DateTime>)DateTime.TryParse; | |||
| parserBuilder[typeof(DateTimeOffset)] = (TryParseDelegate<DateTimeOffset>)DateTimeOffset.TryParse; | |||
| parserBuilder[typeof(TimeSpan)] = (TryParseDelegate<TimeSpan>)TimeSpan.TryParse; | |||
| //parserBuilder[typeof(TimeSpan)] = (TryParseDelegate<TimeSpan>)TimeSpan.TryParse; | |||
| parserBuilder[typeof(char)] = (TryParseDelegate<char>)char.TryParse; | |||
| return parserBuilder.ToImmutable(); | |||
| } | |||
| @@ -0,0 +1,35 @@ | |||
| using System; | |||
| using System.Globalization; | |||
| using System.Threading.Tasks; | |||
| namespace Discord.Commands | |||
| { | |||
| internal class TimeSpanTypeReader : TypeReader | |||
| { | |||
| private static readonly string[] _formats = new[] | |||
| { | |||
| "%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<TypeReaderResult> 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")); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,97 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Text; | |||
| using System.Globalization; | |||
| namespace Discord.Commands | |||
| { | |||
| /// <summary> | |||
| /// Utility class which contains the default matching pairs of quotation marks for CommandServiceConfig | |||
| /// </summary> | |||
| internal static class QuotationAliasUtils | |||
| { | |||
| /// <summary> | |||
| /// A default map of open-close pairs of quotation marks. | |||
| /// Contains many regional and Unicode equivalents. | |||
| /// Used in the <see cref="CommandServiceConfig"/>. | |||
| /// </summary> | |||
| /// <seealso cref="CommandServiceConfig.QuotationMarkAliasMap"/> | |||
| internal static Dictionary<char, char> GetDefaultAliasMap | |||
| { | |||
| get | |||
| { | |||
| // Output of a gist provided by https://gist.github.com/ufcpp | |||
| // https://gist.github.com/ufcpp/5b2cf9a9bf7d0b8743714a0b88f7edc5 | |||
| // This was not used for the implementation because of incompatibility with netstandard1.1 | |||
| return new Dictionary<char, char> { | |||
| {'\"', '\"' }, | |||
| {'«', '»' }, | |||
| {'‘', '’' }, | |||
| {'“', '”' }, | |||
| {'„', '‟' }, | |||
| {'‹', '›' }, | |||
| {'‚', '‛' }, | |||
| {'《', '》' }, | |||
| {'〈', '〉' }, | |||
| {'「', '」' }, | |||
| {'『', '』' }, | |||
| {'〝', '〞' }, | |||
| {'﹁', '﹂' }, | |||
| {'﹃', '﹄' }, | |||
| {'"', '"' }, | |||
| {''', ''' }, | |||
| {'「', '」' }, | |||
| {'(', ')' }, | |||
| {'༺', '༻' }, | |||
| {'༼', '༽' }, | |||
| {'᚛', '᚜' }, | |||
| {'⁅', '⁆' }, | |||
| {'⌈', '⌉' }, | |||
| {'⌊', '⌋' }, | |||
| {'❨', '❩' }, | |||
| {'❪', '❫' }, | |||
| {'❬', '❭' }, | |||
| {'❮', '❯' }, | |||
| {'❰', '❱' }, | |||
| {'❲', '❳' }, | |||
| {'❴', '❵' }, | |||
| {'⟅', '⟆' }, | |||
| {'⟦', '⟧' }, | |||
| {'⟨', '⟩' }, | |||
| {'⟪', '⟫' }, | |||
| {'⟬', '⟭' }, | |||
| {'⟮', '⟯' }, | |||
| {'⦃', '⦄' }, | |||
| {'⦅', '⦆' }, | |||
| {'⦇', '⦈' }, | |||
| {'⦉', '⦊' }, | |||
| {'⦋', '⦌' }, | |||
| {'⦍', '⦎' }, | |||
| {'⦏', '⦐' }, | |||
| {'⦑', '⦒' }, | |||
| {'⦓', '⦔' }, | |||
| {'⦕', '⦖' }, | |||
| {'⦗', '⦘' }, | |||
| {'⧘', '⧙' }, | |||
| {'⧚', '⧛' }, | |||
| {'⧼', '⧽' }, | |||
| {'⸂', '⸃' }, | |||
| {'⸄', '⸅' }, | |||
| {'⸉', '⸊' }, | |||
| {'⸌', '⸍' }, | |||
| {'⸜', '⸝' }, | |||
| {'⸠', '⸡' }, | |||
| {'⸢', '⸣' }, | |||
| {'⸤', '⸥' }, | |||
| {'⸦', '⸧' }, | |||
| {'⸨', '⸩' }, | |||
| {'【', '】'}, | |||
| {'〔', '〕' }, | |||
| {'〖', '〗' }, | |||
| {'〘', '〙' }, | |||
| {'〚', '〛' } | |||
| }; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,15 +1,15 @@ | |||
| <Project Sdk="Microsoft.NET.Sdk"> | |||
| <Project Sdk="Microsoft.NET.Sdk"> | |||
| <Import Project="../../Discord.Net.targets" /> | |||
| <PropertyGroup> | |||
| <AssemblyName>Discord.Net.Core</AssemblyName> | |||
| <RootNamespace>Discord</RootNamespace> | |||
| <Description>The core components for the Discord.Net library.</Description> | |||
| <TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net45;netstandard1.1;netstandard1.3</TargetFrameworks> | |||
| <TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.1;netstandard1.3</TargetFrameworks> | |||
| <TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net46;netstandard1.3;netstandard2.0</TargetFrameworks> | |||
| <TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.3;netstandard2.0</TargetFrameworks> | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <PackageReference Include="Newtonsoft.Json" Version="10.0.2" /> | |||
| <PackageReference Include="System.Collections.Immutable" Version="1.3.1" /> | |||
| <PackageReference Include="Newtonsoft.Json" Version="11.0.2" /> | |||
| <PackageReference Include="System.Collections.Immutable" Version="1.4.0" /> | |||
| <PackageReference Include="System.Interactive.Async" Version="3.1.1" /> | |||
| </ItemGroup> | |||
| </Project> | |||
| @@ -11,13 +11,21 @@ namespace Discord | |||
| /// Returns the API version Discord.Net uses. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A 32-bit integer representing the API version that Discord.Net uses to communicate with Discord. | |||
| /// An <see cref="int"/> representing the API version that Discord.Net uses to communicate with Discord. | |||
| /// <para>A list of available API version can be seen on the official | |||
| /// <see href="https://discordapp.com/developers/docs/reference#api-versioning">Discord API documentation</see> | |||
| /// .</para> | |||
| /// </returns> | |||
| public const int APIVersion = 6; | |||
| /// <summary> | |||
| /// Returns the Voice API version Discord.Net uses. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="int"/> representing the API version that Discord.Net uses to communicate with Discord's | |||
| /// voice server. | |||
| /// </returns> | |||
| public const int VoiceAPIVersion = 3; | |||
| /// <summary> | |||
| /// Gets the Discord.Net version, including the build number. | |||
| /// </summary> | |||
| /// <returns> | |||
| @@ -93,6 +101,19 @@ namespace Discord | |||
| /// The maximum number of guilds that can be gotten per-batch. | |||
| /// </returns> | |||
| public const int MaxGuildsPerBatch = 100; | |||
| /// <summary> | |||
| /// Returns the max user reactions allowed to be in a request. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// The maximum number of user reactions that can be gotten per-batch. | |||
| /// </returns> | |||
| public const int MaxUserReactionsPerBatch = 100; | |||
| /// <summary> | |||
| /// Returns the max audit log entries allowed to be in a request. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// The maximum number of audit log entries that can be gotten per-batch. | |||
| /// </returns> | |||
| public const int MaxAuditLogEntriesPerBatch = 100; | |||
| /// <summary> | |||
| @@ -12,15 +12,26 @@ namespace Discord | |||
| /// <summary> | |||
| /// Gets the description of the asset. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the description of the asset. | |||
| /// </returns> | |||
| public string Text { get; internal set; } | |||
| /// <summary> | |||
| /// Gets the image ID of the asset. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the unique image identifier of the asset. | |||
| /// </returns> | |||
| public string ImageId { get; internal set; } | |||
| /// <summary> | |||
| /// Returns the image URL of the asset, or <c>null</c> when the application ID does not exist. | |||
| /// Returns the image URL of the asset. | |||
| /// </summary> | |||
| /// <param name="size">The size of the image to return in. This can be any power of two between 16 and 2048.</param> | |||
| /// <param name="format">The format to return.</param> | |||
| /// <returns> | |||
| /// A string pointing to the image URL of the asset; <c>null</c> when the application ID does not exist. | |||
| /// </returns> | |||
| public string GetImageUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) | |||
| => ApplicationId.HasValue ? CDN.GetRichAssetUrl(ApplicationId.Value, ImageId, size, format) : null; | |||
| } | |||
| @@ -10,11 +10,17 @@ namespace Discord | |||
| /// <summary> | |||
| /// Gets the ID of the party. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the unique identifier of the party. | |||
| /// </returns> | |||
| public string Id { get; internal set; } | |||
| public long Members { get; internal set; } | |||
| /// <summary> | |||
| /// Gets the party's current and maximum size. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A <see cref="long"/> representing the capacity of the party. | |||
| /// </returns> | |||
| public long Capacity { get; internal set; } | |||
| } | |||
| } | |||
| @@ -8,10 +8,16 @@ namespace Discord | |||
| /// <summary> | |||
| /// Gets the name of the activity. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the name of the activity that the user is doing. | |||
| /// </returns> | |||
| string Name { get; } | |||
| /// <summary> | |||
| /// Gets the type of the activity. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// The type of activity. | |||
| /// </returns> | |||
| ActivityType Type { get; } | |||
| } | |||
| } | |||
| @@ -1,50 +1,122 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| /// <summary> | |||
| /// The action type within a <see cref="IAuditLogEntry"/> | |||
| /// Representing a type of action within an <see cref="IAuditLogEntry"/>. | |||
| /// </summary> | |||
| public enum ActionType | |||
| { | |||
| /// <summary> | |||
| /// this guild was updated. | |||
| /// </summary> | |||
| GuildUpdated = 1, | |||
| /// <summary> | |||
| /// A channel was created. | |||
| /// </summary> | |||
| ChannelCreated = 10, | |||
| /// <summary> | |||
| /// A channel was updated. | |||
| /// </summary> | |||
| ChannelUpdated = 11, | |||
| /// <summary> | |||
| /// A channel was deleted. | |||
| /// </summary> | |||
| ChannelDeleted = 12, | |||
| /// <summary> | |||
| /// A permission overwrite was created for a channel. | |||
| /// </summary> | |||
| OverwriteCreated = 13, | |||
| /// <summary> | |||
| /// A permission overwrite was updated for a channel. | |||
| /// </summary> | |||
| OverwriteUpdated = 14, | |||
| /// <summary> | |||
| /// A permission overwrite was deleted for a channel. | |||
| /// </summary> | |||
| OverwriteDeleted = 15, | |||
| /// <summary> | |||
| /// A user was kicked from this guild. | |||
| /// </summary> | |||
| Kick = 20, | |||
| /// <summary> | |||
| /// A prune took place in this guild. | |||
| /// </summary> | |||
| Prune = 21, | |||
| /// <summary> | |||
| /// A user banned another user from this guild. | |||
| /// </summary> | |||
| Ban = 22, | |||
| /// <summary> | |||
| /// A user unbanned another user from this guild. | |||
| /// </summary> | |||
| Unban = 23, | |||
| /// <summary> | |||
| /// A guild member whose information was updated. | |||
| /// </summary> | |||
| MemberUpdated = 24, | |||
| /// <summary> | |||
| /// A guild member's role collection was updated. | |||
| /// </summary> | |||
| MemberRoleUpdated = 25, | |||
| /// <summary> | |||
| /// A role was created in this guild. | |||
| /// </summary> | |||
| RoleCreated = 30, | |||
| /// <summary> | |||
| /// A role was updated in this guild. | |||
| /// </summary> | |||
| RoleUpdated = 31, | |||
| /// <summary> | |||
| /// A role was deleted from this guild. | |||
| /// </summary> | |||
| RoleDeleted = 32, | |||
| /// <summary> | |||
| /// An invite was created in this guild. | |||
| /// </summary> | |||
| InviteCreated = 40, | |||
| /// <summary> | |||
| /// An invite was updated in this guild. | |||
| /// </summary> | |||
| InviteUpdated = 41, | |||
| /// <summary> | |||
| /// An invite was deleted from this guild. | |||
| /// </summary> | |||
| InviteDeleted = 42, | |||
| /// <summary> | |||
| /// A Webhook was created in this guild. | |||
| /// </summary> | |||
| WebhookCreated = 50, | |||
| /// <summary> | |||
| /// A Webhook was updated in this guild. | |||
| /// </summary> | |||
| WebhookUpdated = 51, | |||
| /// <summary> | |||
| /// A Webhook was deleted from this guild. | |||
| /// </summary> | |||
| WebhookDeleted = 52, | |||
| /// <summary> | |||
| /// An emoji was created in this guild. | |||
| /// </summary> | |||
| EmojiCreated = 60, | |||
| /// <summary> | |||
| /// An emoji was updated in this guild. | |||
| /// </summary> | |||
| EmojiUpdated = 61, | |||
| /// <summary> | |||
| /// An emoji was deleted from this guild. | |||
| /// </summary> | |||
| EmojiDeleted = 62, | |||
| /// <summary> | |||
| /// A message was deleted from this guild. | |||
| /// </summary> | |||
| MessageDeleted = 72 | |||
| } | |||
| } | |||
| @@ -1,13 +1,7 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| /// <summary> | |||
| /// Represents data applied to an <see cref="IAuditLogEntry"/> | |||
| /// Represents data applied to an <see cref="IAuditLogEntry" />. | |||
| /// </summary> | |||
| public interface IAuditLogData | |||
| { } | |||
| @@ -1,34 +1,40 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| /// <summary> | |||
| /// Represents an entry in an audit log | |||
| /// Represents a generic audit log entry. | |||
| /// </summary> | |||
| public interface IAuditLogEntry : IEntity<ulong> | |||
| { | |||
| /// <summary> | |||
| /// The action which occured to create this entry | |||
| /// Gets the action which occurred to create this entry. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// The type of action for this audit log entry. | |||
| /// </returns> | |||
| ActionType Action { get; } | |||
| /// <summary> | |||
| /// The data for this entry. May be <see cref="null"/> if no data was available. | |||
| /// Gets the data for this entry. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="IAuditLogData" /> for this audit log entry; <c>null</c> if no data is available. | |||
| /// </returns> | |||
| IAuditLogData Data { get; } | |||
| /// <summary> | |||
| /// The user responsible for causing the changes | |||
| /// Gets the user responsible for causing the changes. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A user object. | |||
| /// </returns> | |||
| IUser User { get; } | |||
| /// <summary> | |||
| /// The reason behind the change. May be <see cref="null"/> if no reason was provided. | |||
| /// Gets the reason behind the change. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the reason for the change; <c>null</c> if none is provided. | |||
| /// </returns> | |||
| string Reason { get; } | |||
| } | |||
| } | |||
| @@ -11,16 +11,32 @@ namespace Discord | |||
| /// <summary> | |||
| /// Gets the name of this channel. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the name of this channel. | |||
| /// </returns> | |||
| string Name { get; } | |||
| /// <summary> | |||
| /// Gets a collection of all users in this channel. | |||
| /// </summary> | |||
| /// <param name="mode">The <see cref="CacheMode"/> that determines whether the object should be fetched from cache.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// A paged collection containing a collection of users that can access this channel. Flattening the | |||
| /// paginated response into a collection of users with | |||
| /// <see cref="AsyncEnumerableExtensions.FlattenAsync{T}"/> is required if you wish to access the users. | |||
| /// </returns> | |||
| IAsyncEnumerable<IReadOnlyCollection<IUser>> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Gets a user in this channel with the provided ID. | |||
| /// Gets a user in this channel. | |||
| /// </summary> | |||
| /// <param name="id">The snowflake identifier of the user (e.g. 168693960628371456).</param> | |||
| /// <param name="mode">The <see cref="CacheMode"/> that determines whether the object should be fetched from cache.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// An awaitable <see cref="Task"/> containing a user object that represents the user. | |||
| /// </returns> | |||
| Task<IUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||
| } | |||
| } | |||
| @@ -20,29 +20,18 @@ namespace Discord | |||
| /// </returns> | |||
| int Position { get; } | |||
| /// <summary> | |||
| /// Gets the parent ID (category) of this channel in the guild's channel list. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// The parent category ID associated with this channel, or <c>null</c> if none is set. | |||
| /// </returns> | |||
| ulong? CategoryId { get; } | |||
| /// <summary> | |||
| /// Gets the parent channel (category) of this channel. | |||
| /// </summary> | |||
| Task<ICategoryChannel> GetCategoryAsync(); | |||
| /// <summary> | |||
| /// Gets the guild associated with this channel. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// The guild that this channel belongs to. | |||
| /// A guild that this channel belongs to. | |||
| /// </returns> | |||
| IGuild Guild { get; } | |||
| /// <summary> | |||
| /// Gets the guild ID associated with this channel. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// The guild ID that this channel belongs to. | |||
| /// A guild snowflake identifier for the guild that this channel belongs to. | |||
| /// </returns> | |||
| ulong GuildId { get; } | |||
| /// <summary> | |||
| @@ -66,16 +55,25 @@ namespace Discord | |||
| /// If <c>true</c>, a user accepting this invite will be kicked from the guild after closing their client. | |||
| /// </param> | |||
| /// <param name="isUnique"> | |||
| /// If <c>true</c>, don't try to reuse a similar invite (useful for creating many unique one time use invites). | |||
| /// If <c>true</c>, don't try to reuse a similar invite (useful for creating many unique one time use | |||
| /// invites). | |||
| /// </param> | |||
| /// <param name="options"> | |||
| /// The options to be used when sending the request. | |||
| /// </param> | |||
| /// <returns> | |||
| /// An awaitable <see cref="Task"/> containing an invite metadata object containing information for the | |||
| /// created invite. | |||
| /// </returns> | |||
| Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Returns a collection of all invites to this channel. | |||
| /// </summary> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// An awaitable <see cref="Task"/> containing a read-only collection of invite metadata that are created | |||
| /// for this channel. | |||
| /// </returns> | |||
| Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null); | |||
| /// <summary> | |||
| @@ -83,29 +81,44 @@ namespace Discord | |||
| /// </summary> | |||
| /// <param name="func">The properties to modify the channel with.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// An awaitable <see cref="Task"/>. | |||
| /// </returns> | |||
| Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Gets the permission overwrite for a specific role, or <c>null</c> if one does not exist. | |||
| /// </summary> | |||
| /// <param name="role">The role to get the overwrite from.</param> | |||
| /// <returns> | |||
| /// An overwrite object for the targeted role; <c>null</c> if none is set. | |||
| /// </returns> | |||
| OverwritePermissions? GetPermissionOverwrite(IRole role); | |||
| /// <summary> | |||
| /// Gets the permission overwrite for a specific user, or <c>null</c> if one does not exist. | |||
| /// </summary> | |||
| /// <param name="user">The user to get the overwrite from.</param> | |||
| /// <returns> | |||
| /// An overwrite object for the targeted user; <c>null</c> if none is set. | |||
| /// </returns> | |||
| OverwritePermissions? GetPermissionOverwrite(IUser user); | |||
| /// <summary> | |||
| /// Removes the permission overwrite for the given role, if one exists. | |||
| /// </summary> | |||
| /// <param name="role">The role to remove the overwrite from.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// An awaitable <see cref="Task"/>. | |||
| /// </returns> | |||
| Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Removes the permission overwrite for the given user, if one exists. | |||
| /// </summary> | |||
| /// <param name="user">The user to remove the overwrite from.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// An awaitable <see cref="Task"/>. | |||
| /// </returns> | |||
| Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null); | |||
| /// <summary> | |||
| @@ -114,6 +127,9 @@ namespace Discord | |||
| /// <param name="role">The role to add the overwrite to.</param> | |||
| /// <param name="permissions">The overwrite to add to the role.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// An awaitable <see cref="Task"/>. | |||
| /// </returns> | |||
| Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Adds or updates the permission overwrite for the given user. | |||
| @@ -121,6 +137,9 @@ namespace Discord | |||
| /// <param name="user">The user to add the overwrite to.</param> | |||
| /// <param name="permissions">The overwrite to add to the user.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// An awaitable <see cref="Task"/>. | |||
| /// </returns> | |||
| Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null); | |||
| /// <summary> | |||
| @@ -130,6 +149,11 @@ namespace Discord | |||
| /// The <see cref="CacheMode" /> that determines whether the object should be fetched from cache. | |||
| /// </param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// A paged collection containing a collection of guild users that can access this channel. Flattening the | |||
| /// paginated response into a collection of users with | |||
| /// <see cref="AsyncEnumerableExtensions.FlattenAsync{T}"/> is required if you wish to access the users. | |||
| /// </returns> | |||
| new IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Gets a user in this channel with the provided ID. | |||
| @@ -139,6 +163,9 @@ namespace Discord | |||
| /// The <see cref="CacheMode" /> that determines whether the object should be fetched from cache. | |||
| /// </param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// An awaitable <see cref="Task"/> containing a guild user object that represents the user. | |||
| /// </returns> | |||
| new Task<IGuildUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||
| } | |||
| } | |||
| @@ -20,8 +20,7 @@ namespace Discord | |||
| /// <returns> | |||
| /// An awaitable Task containing the message sent to the channel. | |||
| /// </returns> | |||
| Task<IUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null); | |||
| #if FILESYSTEM | |||
| Task<IUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Sends a file to this message channel with an optional caption. | |||
| /// </summary> | |||
| @@ -39,7 +38,6 @@ namespace Discord | |||
| /// An awaitable Task containing the message sent to the channel. | |||
| /// </returns> | |||
| Task<IUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null); | |||
| #endif | |||
| /// <summary> | |||
| /// Sends a file to this message channel with an optional caption. | |||
| /// </summary> | |||
| @@ -121,6 +119,11 @@ namespace Discord | |||
| /// </returns> | |||
| Task<IReadOnlyCollection<IMessage>> GetPinnedMessagesAsync(RequestOptions options = null); | |||
| /// <summary> Deletes a message based on the message ID in this channel. </summary> | |||
| Task DeleteMessageAsync(ulong messageId, RequestOptions options = null); | |||
| /// <summary> Deletes a message based on the provided message in this channel. </summary> | |||
| Task DeleteMessageAsync(IMessage message, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Broadcasts the "user is typing" message to all users in this channel, lasting 10 seconds. | |||
| /// </summary> | |||
| @@ -0,0 +1,28 @@ | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| /// <summary> | |||
| /// Represents a type of guild channel that can be nested within a category. | |||
| /// </summary> | |||
| public interface INestedChannel : IGuildChannel | |||
| { | |||
| /// <summary> | |||
| /// Gets the parent (category) ID of this channel in the guild's channel list. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="System.UInt64"/> representing the snowflake identifier of the parent of this channel; | |||
| /// <c>null</c> if none is set. | |||
| /// </returns> | |||
| ulong? CategoryId { get; } | |||
| /// <summary> | |||
| /// Gets the parent (category) channel of this channel. | |||
| /// </summary> | |||
| /// <param name="mode">The <see cref="CacheMode"/> that determines whether the object should be fetched from cache.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <remarks> | |||
| /// A category channel representing the parent of this channel; <c>null</c> if none is set. | |||
| /// </remarks> | |||
| Task<ICategoryChannel> GetCategoryAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||
| } | |||
| } | |||
| @@ -8,7 +8,7 @@ namespace Discord | |||
| /// <summary> | |||
| /// Represents a generic channel in a guild that can send and receive messages. | |||
| /// </summary> | |||
| public interface ITextChannel : IMessageChannel, IMentionable, IGuildChannel | |||
| public interface ITextChannel : IMessageChannel, IMentionable, INestedChannel | |||
| { | |||
| /// <summary> | |||
| /// Determines whether the channel is NSFW. | |||
| @@ -80,7 +80,7 @@ namespace Discord | |||
| /// </summary> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// A collection of webhooks. | |||
| /// An awaitable <see cref="Task"/> containing a collection of webhooks. | |||
| /// </returns> | |||
| Task<IReadOnlyCollection<IWebhook>> GetWebhooksAsync(RequestOptions options = null); | |||
| } | |||
| @@ -4,9 +4,9 @@ using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| /// <summary> | |||
| /// Represents a voice channel in a guild. | |||
| /// Represents a generic voice channel in a guild. | |||
| /// </summary> | |||
| public interface IVoiceChannel : IGuildChannel, IAudioChannel | |||
| public interface IVoiceChannel : INestedChannel, IAudioChannel | |||
| { | |||
| /// <summary> | |||
| /// Gets the bitrate, in bits per second, clients in this voice channel are requested to use. | |||
| @@ -8,10 +8,16 @@ namespace Discord | |||
| /// <summary> | |||
| /// Gets the ID of the channel to apply this position to. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A <see cref="ulong"/> representing the snowflake identififer of this channel. | |||
| /// </returns> | |||
| public ulong Id { get; } | |||
| /// <summary> | |||
| /// Gets the new zero-based position of this channel. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="int"/> representing the new position of this channel. | |||
| /// </returns> | |||
| public int Position { get; } | |||
| /// <summary> Creates a <see cref="ReorderChannelProperties"/> used to reorder a channel. </summary> | |||
| @@ -8,10 +8,16 @@ namespace Discord | |||
| /// <summary> | |||
| /// Gets the banned user. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A user that was banned. | |||
| /// </returns> | |||
| IUser User { get; } | |||
| /// <summary> | |||
| /// Gets the reason why the user is banned. | |||
| /// Gets the reason why the user is banned if specified. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the reason behind the ban; <c>null</c> if none is specified. | |||
| /// </returns> | |||
| string Reason { get; } | |||
| } | |||
| } | |||
| @@ -22,7 +22,8 @@ namespace Discord | |||
| /// automatically moved to the AFK voice channel. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// The amount of time in seconds for a user to be marked as inactive and moved into the AFK voice channel. | |||
| /// An <see cref="Int32"/> representing the amount of time in seconds for a user to be marked as inactive | |||
| /// and moved into the AFK voice channel. | |||
| /// </returns> | |||
| int AFKTimeout { get; } | |||
| /// <summary> | |||
| @@ -94,8 +95,12 @@ namespace Discord | |||
| bool Available { get; } | |||
| /// <summary> | |||
| /// Gets the ID of the AFK voice channel for this guild, or <c>null</c> if none is set. | |||
| /// Gets the ID of the AFK voice channel for this guild. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="UInt64" /> representing the snowflake identifier of the AFK voice channel; <c>null</c> if | |||
| /// none is set. | |||
| /// </returns> | |||
| ulong? AFKChannelId { get; } | |||
| /// <summary> | |||
| /// Gets the ID of the the default channel for this guild. | |||
| @@ -214,18 +219,20 @@ namespace Discord | |||
| /// Gets a ban object for a banned user. | |||
| /// </summary> | |||
| /// <param name="user">The banned user.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// An awaitable <see cref="Task"/> containing the ban object, which contains the user information and the | |||
| /// reason for the ban; <c>null<c/> if the ban entry cannot be found. | |||
| /// reason for the ban; <c>null</c> if the ban entry cannot be found. | |||
| /// </returns> | |||
| Task<IBan> GetBanAsync(IUser user, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Gets a ban object for a banned user. | |||
| /// </summary> | |||
| /// <param name="userId">The snowflake identifier for the banned user.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// An awaitable <see cref="Task"/> containing the ban object, which contains the user information and the | |||
| /// reason for the ban; <c>null<c/> if the ban entry cannot be found. | |||
| /// reason for the ban; <c>null</c> if the ban entry cannot be found. | |||
| /// </returns> | |||
| Task<IBan> GetBanAsync(ulong userId, RequestOptions options = null); | |||
| /// <summary> | |||
| @@ -406,24 +413,27 @@ namespace Discord | |||
| /// <c>null</c> if none is set. | |||
| /// </returns> | |||
| Task<IGuildChannel> GetEmbedChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Creates a new text channel. | |||
| /// </summary> | |||
| /// <param name="name">The new name for the text channel.</param> | |||
| /// <param name="func">The delegate containing the properties to be applied to the channel upon its creation.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// An awaitable <see cref="Task"/> containing the newly created text channel. | |||
| /// </returns> | |||
| Task<ITextChannel> CreateTextChannelAsync(string name, RequestOptions options = null); | |||
| Task<ITextChannel> CreateTextChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Creates a new voice channel. | |||
| /// </summary> | |||
| /// <param name="name">The new name for the voice channel.</param> | |||
| /// <param name="func">The delegate containing the properties to be applied to the channel upon its creation.</param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// An awaitable <see cref="Task"/> containing the newly created voice channel. | |||
| /// </returns> | |||
| Task<IVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null); | |||
| Task<IVoiceChannel> CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func = null, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Creates a new channel category. | |||
| /// </summary> | |||
| @@ -537,7 +547,17 @@ namespace Discord | |||
| /// </returns> | |||
| Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null); | |||
| /// <summary> Gets the specified number of audit log entries for this guild. </summary> | |||
| /// <summary> | |||
| /// Gets the specified number of audit log entries for this guild. | |||
| /// </summary> | |||
| /// <param name="limit">The number of audit log entries to fetch.</param> | |||
| /// <param name="mode"> | |||
| /// The <see cref="CacheMode" /> that determines whether the object should be fetched from cache. | |||
| /// </param> | |||
| /// <param name="options">The options to be used when sending the request.</param> | |||
| /// <returns> | |||
| /// An awaitable <see cref="Task"/> containing a collection of requested audit log entries. | |||
| /// </returns> | |||
| Task<IReadOnlyCollection<IAuditLogEntry>> GetAuditLogAsync(int limit = DiscordConfig.MaxAuditLogEntriesPerBatch, | |||
| CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||
| @@ -1,4 +1,3 @@ | |||
| using System; | |||
| using System.IO; | |||
| namespace Discord | |||
| { | |||
| @@ -22,7 +21,7 @@ namespace Discord | |||
| { | |||
| Stream = stream; | |||
| } | |||
| #if FILESYSTEM | |||
| /// <summary> | |||
| /// Create the image from a file path. | |||
| /// </summary> | |||
| @@ -31,21 +30,21 @@ namespace Discord | |||
| /// <see cref="File.OpenRead"/>. | |||
| /// </remarks> | |||
| /// <param name="path">The path to the file.</param> | |||
| /// <exception cref="ArgumentException"> | |||
| /// <exception cref="System.ArgumentException"> | |||
| /// <paramref name="path" /> is a zero-length string, contains only white space, or contains one or more invalid | |||
| /// characters as defined by <see cref="Path.GetInvalidPathChars" />. | |||
| /// </exception> | |||
| /// <exception cref="ArgumentNullException"><paramref name="path" /> is <c>null</c>.</exception> | |||
| /// <exception cref="System.ArgumentNullException"><paramref name="path" /> is <c>null</c>.</exception> | |||
| /// <exception cref="PathTooLongException"> | |||
| /// 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. | |||
| /// </exception> | |||
| /// <exception cref="NotSupportedException"><paramref name="path" /> is in an invalid format.</exception> | |||
| /// <exception cref="System.NotSupportedException"><paramref name="path" /> is in an invalid format.</exception> | |||
| /// <exception cref="DirectoryNotFoundException"> | |||
| /// The specified <paramref name="path"/> is invalid, (for example, it is on an unmapped drive). | |||
| /// </exception> | |||
| /// <exception cref="UnauthorizedAccessException"> | |||
| /// <exception cref="System.UnauthorizedAccessException"> | |||
| /// <paramref name="path" /> specified a directory.-or- The caller does not have the required permission. | |||
| /// </exception> | |||
| /// <exception cref="FileNotFoundException">The file specified in <paramref name="path" /> was not found. | |||
| @@ -55,6 +54,6 @@ namespace Discord | |||
| { | |||
| Stream = File.OpenRead(path); | |||
| } | |||
| #endif | |||
| } | |||
| } | |||
| @@ -1,5 +1,3 @@ | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| /// <summary> | |||
| @@ -10,44 +8,76 @@ namespace Discord | |||
| /// <summary> | |||
| /// Gets the unique identifier for this invite. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the invite code (e.g. <c>FTqNnyS</c>). | |||
| /// </returns> | |||
| string Code { get; } | |||
| /// <summary> | |||
| /// Gets the URL used to accept this invite, using Code. | |||
| /// Gets the URL used to accept this invite using <see cref="Code"/>. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the full invite URL (e.g. <c>https://discord.gg/FTqNnyS</c>). | |||
| /// </returns> | |||
| string Url { get; } | |||
| /// <summary> | |||
| /// Gets the channel this invite is linked to. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A generic channel that the invite points to. | |||
| /// </returns> | |||
| IChannel Channel { get; } | |||
| /// <summary> | |||
| /// Gets the ID of the channel this invite is linked to. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="ulong"/> representing the channel snowflake identifier that the invite points to. | |||
| /// </returns> | |||
| ulong ChannelId { get; } | |||
| /// <summary> | |||
| /// Gets the name of the channel this invite is linked to. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the name of the channel that the invite points to. | |||
| /// </returns> | |||
| string ChannelName { get; } | |||
| /// <summary> | |||
| /// Gets the guild this invite is linked to. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A guild object representing the guild that the invite points to. | |||
| /// </returns> | |||
| IGuild Guild { get; } | |||
| /// <summary> | |||
| /// Gets the ID of the guild this invite is linked to. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="ulong"/> representing the guild snowflake identifier that the invite points to. | |||
| /// </returns> | |||
| ulong GuildId { get; } | |||
| /// <summary> | |||
| /// Gets the name of the guild this invite is linked to. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the name of the guild that the invite points to. | |||
| /// </returns> | |||
| string GuildName { get; } | |||
| /// <summary> | |||
| /// Gets the approximated count of online members in the guild. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="System.Int32" /> representing the approximated online member count of the guild that the | |||
| /// invite points to; <c>null</c> if one cannot be obtained. | |||
| /// </returns> | |||
| int? PresenceCount { get; } | |||
| /// <summary> | |||
| /// Gets the approximated count of total members in the guild. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="System.Int32" /> representing the approximated total member count of the guild that the | |||
| /// invite points to; <c>null</c> if one cannot be obtained. | |||
| /// </returns> | |||
| int? MemberCount { get; } | |||
| } | |||
| } | |||
| @@ -2,37 +2,63 @@ using System; | |||
| namespace Discord | |||
| { | |||
| /// <summary> Represents additional information regarding the generic invite object. </summary> | |||
| /// <summary> | |||
| /// Represents additional information regarding the generic invite object. | |||
| /// </summary> | |||
| public interface IInviteMetadata : IInvite | |||
| { | |||
| /// <summary> | |||
| /// Gets the user that created this invite. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A user that created this invite. | |||
| /// </returns> | |||
| IUser Inviter { get; } | |||
| /// <summary> | |||
| /// Returns <c>true</c> if this invite was revoked. | |||
| /// Determines whether the invite has been revoked. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// <c>true</c> if this invite was revoked; otherwise <c>false</c>. | |||
| /// </returns> | |||
| bool IsRevoked { get; } | |||
| /// <summary> | |||
| /// Returns <c>true</c> if users accepting this invite will be removed from the guild when they | |||
| /// log off. | |||
| /// Determines whether the invite is a temporary one (i.e. whether the invite will be removed from the guild | |||
| /// when the user logs off). | |||
| /// </summary> | |||
| /// <returns> | |||
| /// <c>true</c> if users accepting this invite will be removed from the guild when they log off; otherwise | |||
| /// <c>false</c>. | |||
| /// </returns> | |||
| bool IsTemporary { get; } | |||
| /// <summary> | |||
| /// Gets the time (in seconds) until the invite expires, or <c>null</c> if it never expires. | |||
| /// Gets the time (in seconds) until the invite expires. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="int"/> representing the time in seconds until this invite expires; <c>null</c> if this | |||
| /// invite never expires. | |||
| /// </returns> | |||
| int? MaxAge { get; } | |||
| /// <summary> | |||
| /// Gets the max amount of times this invite may be used, or <c>null</c> if there is no limit. | |||
| /// Gets the max number of uses this invite may have. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="int"/> representing the number of uses this invite may be accepted until it is removed | |||
| /// from the guild; <c>null</c> if none is set. | |||
| /// </returns> | |||
| int? MaxUses { get; } | |||
| /// <summary> | |||
| /// Gets the amount of times this invite has been used. | |||
| /// Gets the number of times this invite has been used. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="int"/> representing the number of times this invite has been used. | |||
| /// </returns> | |||
| int Uses { get; } | |||
| /// <summary> | |||
| /// Gets when this invite was created. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A <see cref="DateTimeOffset"/> representing the time of which the invite was first created. | |||
| /// </returns> | |||
| DateTimeOffset CreatedAt { get; } | |||
| } | |||
| } | |||
| @@ -42,7 +42,7 @@ namespace Discord | |||
| /// <summary> | |||
| /// Gets all users that reacted to a message with a given emote. | |||
| /// </summary> | |||
| Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emoji, int limit = 100, ulong? afterUserId = null, RequestOptions options = null); | |||
| IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emoji, int limit, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Transforms this message's text into a human-readable form by resolving its tags. | |||
| @@ -88,12 +88,27 @@ namespace Discord | |||
| /// <summary> Creates a new <see cref="ChannelPermissions"/> with the provided packed value. </summary> | |||
| public ChannelPermissions(ulong rawValue) { RawValue = rawValue; } | |||
| private ChannelPermissions(ulong initialValue, bool? createInstantInvite = null, bool? manageChannel = null, | |||
| private ChannelPermissions(ulong initialValue, | |||
| bool? createInstantInvite = null, | |||
| bool? manageChannel = null, | |||
| bool? addReactions = null, | |||
| bool? viewChannel = null, bool? sendMessages = null, bool? sendTTSMessages = null, bool? manageMessages = null, | |||
| bool? embedLinks = null, bool? attachFiles = null, bool? readMessageHistory = null, bool? mentionEveryone = null, | |||
| bool? useExternalEmojis = null, bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null, | |||
| bool? moveMembers = null, bool? useVoiceActivation = null, bool? manageRoles = null, bool? manageWebhooks = null) | |||
| bool? viewChannel = null, | |||
| bool? sendMessages = null, | |||
| bool? sendTTSMessages = null, | |||
| bool? manageMessages = null, | |||
| bool? embedLinks = null, | |||
| bool? attachFiles = null, | |||
| bool? readMessageHistory = null, | |||
| bool? mentionEveryone = null, | |||
| bool? useExternalEmojis = null, | |||
| bool? connect = null, | |||
| bool? speak = null, | |||
| bool? muteMembers = null, | |||
| bool? deafenMembers = null, | |||
| bool? moveMembers = null, | |||
| bool? useVoiceActivation = null, | |||
| bool? manageRoles = null, | |||
| bool? manageWebhooks = null) | |||
| { | |||
| ulong value = initialValue; | |||
| @@ -122,27 +137,75 @@ namespace Discord | |||
| } | |||
| /// <summary> Creates a new <see cref="ChannelPermissions"/> with the provided permissions. </summary> | |||
| public ChannelPermissions(bool createInstantInvite = false, bool manageChannel = false, | |||
| public ChannelPermissions( | |||
| bool createInstantInvite = false, | |||
| bool manageChannel = false, | |||
| bool addReactions = false, | |||
| bool viewChannel = false, bool sendMessages = false, bool sendTTSMessages = false, bool manageMessages = false, | |||
| bool embedLinks = false, bool attachFiles = false, bool readMessageHistory = false, bool mentionEveryone = false, | |||
| bool useExternalEmojis = false, bool connect = false, bool speak = false, bool muteMembers = false, bool deafenMembers = false, | |||
| bool moveMembers = false, bool useVoiceActivation = false, bool manageRoles = false, bool manageWebhooks = false) | |||
| bool viewChannel = false, | |||
| bool sendMessages = false, | |||
| bool sendTTSMessages = false, | |||
| bool manageMessages = false, | |||
| bool embedLinks = false, | |||
| bool attachFiles = false, | |||
| bool readMessageHistory = false, | |||
| bool mentionEveryone = false, | |||
| bool useExternalEmojis = false, | |||
| bool connect = false, | |||
| bool speak = false, | |||
| bool muteMembers = false, | |||
| bool deafenMembers = false, | |||
| bool moveMembers = false, | |||
| bool useVoiceActivation = false, | |||
| bool manageRoles = false, | |||
| bool manageWebhooks = false) | |||
| : this(0, createInstantInvite, manageChannel, addReactions, viewChannel, sendMessages, sendTTSMessages, manageMessages, | |||
| embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, | |||
| speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, manageRoles, manageWebhooks) | |||
| { } | |||
| /// <summary> Creates a new <see cref="ChannelPermissions"/> from this one, changing the provided non-null permissions. </summary> | |||
| public ChannelPermissions Modify(bool? createInstantInvite = null, bool? manageChannel = null, | |||
| public ChannelPermissions Modify( | |||
| bool? createInstantInvite = null, | |||
| bool? manageChannel = null, | |||
| bool? addReactions = null, | |||
| bool? viewChannel = null, bool? sendMessages = null, bool? sendTTSMessages = null, bool? manageMessages = null, | |||
| bool? embedLinks = null, bool? attachFiles = null, bool? readMessageHistory = null, bool? mentionEveryone = null, | |||
| bool useExternalEmojis = false, bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null, | |||
| bool? moveMembers = null, bool? useVoiceActivation = null, bool? manageRoles = null, bool? manageWebhooks = null) | |||
| => new ChannelPermissions(RawValue, createInstantInvite, manageChannel, addReactions, viewChannel, sendMessages, sendTTSMessages, manageMessages, | |||
| embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, | |||
| speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, manageRoles, manageWebhooks); | |||
| bool? viewChannel = null, | |||
| bool? sendMessages = null, | |||
| bool? sendTTSMessages = null, | |||
| bool? manageMessages = null, | |||
| bool? embedLinks = null, | |||
| bool? attachFiles = null, | |||
| bool? readMessageHistory = null, | |||
| bool? mentionEveryone = null, | |||
| bool? useExternalEmojis = null, | |||
| bool? connect = null, | |||
| bool? speak = null, | |||
| bool? muteMembers = null, | |||
| bool? deafenMembers = null, | |||
| bool? moveMembers = null, | |||
| bool? useVoiceActivation = null, | |||
| bool? manageRoles = null, | |||
| bool? manageWebhooks = null) | |||
| => new ChannelPermissions(RawValue, | |||
| createInstantInvite, | |||
| manageChannel, | |||
| addReactions, | |||
| viewChannel, | |||
| sendMessages, | |||
| sendTTSMessages, | |||
| manageMessages, | |||
| embedLinks, | |||
| attachFiles, | |||
| readMessageHistory, | |||
| mentionEveryone, | |||
| useExternalEmojis, | |||
| connect, | |||
| speak, | |||
| muteMembers, | |||
| deafenMembers, | |||
| moveMembers, | |||
| useVoiceActivation, | |||
| manageRoles, | |||
| manageWebhooks); | |||
| public bool Has(ChannelPermission permission) => Permissions.GetValue(RawValue, permission); | |||
| @@ -41,13 +41,9 @@ namespace Discord | |||
| /// Allows for viewing of audit logs. | |||
| /// </summary> | |||
| ViewAuditLog = 0x00_00_00_80, | |||
| /// <summary> | |||
| /// Allows for reading of message. | |||
| /// </summary> | |||
| ReadMessages = 0x00_00_04_00, | |||
| /// <summary> | |||
| /// Allows for sending messages in a channel. | |||
| /// </summary> | |||
| [Obsolete("Use ViewChannel instead.")] | |||
| ReadMessages = ViewChannel, | |||
| ViewChannel = 0x00_00_04_00, | |||
| SendMessages = 0x00_00_08_00, | |||
| /// <summary> | |||
| /// Allows for sending of text-to-speech messages. | |||
| @@ -1,3 +1,4 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Diagnostics; | |||
| @@ -34,9 +35,12 @@ namespace Discord | |||
| /// <summary> If <c>true</c>, a user may view the audit log. </summary> | |||
| public bool ViewAuditLog => Permissions.GetValue(RawValue, GuildPermission.ViewAuditLog); | |||
| /// <summary> If <c>true</c>, a user may join channels. </summary> | |||
| public bool ReadMessages => Permissions.GetValue(RawValue, GuildPermission.ReadMessages); | |||
| /// <summary> If <c>true</c>, a user may send messages. </summary> | |||
| /// <summary> If True, a user may join channels. </summary> | |||
| [Obsolete("Use ViewChannel instead.")] | |||
| public bool ReadMessages => ViewChannel; | |||
| /// <summary> If True, a user may view channels. </summary> | |||
| public bool ViewChannel => Permissions.GetValue(RawValue, GuildPermission.ViewChannel); | |||
| /// <summary> If True, a user may send messages. </summary> | |||
| public bool SendMessages => Permissions.GetValue(RawValue, GuildPermission.SendMessages); | |||
| /// <summary> If <c>true</c>, a user may send text-to-speech messages. </summary> | |||
| public bool SendTTSMessages => Permissions.GetValue(RawValue, GuildPermission.SendTTSMessages); | |||
| @@ -80,14 +84,35 @@ namespace Discord | |||
| /// <summary> Creates a new <see cref="GuildPermissions"/> with the provided packed value. </summary> | |||
| public GuildPermissions(ulong rawValue) { RawValue = rawValue; } | |||
| private GuildPermissions(ulong initialValue, bool? createInstantInvite = null, bool? kickMembers = null, | |||
| bool? banMembers = null, bool? administrator = null, bool? manageChannels = null, bool? manageGuild = null, | |||
| bool? addReactions = null, bool? viewAuditLog = null, | |||
| bool? readMessages = null, bool? sendMessages = null, bool? sendTTSMessages = null, bool? manageMessages = null, | |||
| bool? embedLinks = null, bool? attachFiles = null, bool? readMessageHistory = null, bool? mentionEveryone = null, | |||
| bool? useExternalEmojis = null, bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null, | |||
| bool? moveMembers = null, bool? useVoiceActivation = null, bool? changeNickname = null, bool? manageNicknames = null, | |||
| bool? manageRoles = null, bool? manageWebhooks = null, bool? manageEmojis = null) | |||
| private GuildPermissions(ulong initialValue, | |||
| bool? createInstantInvite = null, | |||
| bool? kickMembers = null, | |||
| bool? banMembers = null, | |||
| bool? administrator = null, | |||
| bool? manageChannels = null, | |||
| bool? manageGuild = null, | |||
| bool? addReactions = null, | |||
| bool? viewAuditLog = null, | |||
| bool? viewChannel = null, | |||
| bool? sendMessages = null, | |||
| bool? sendTTSMessages = null, | |||
| bool? manageMessages = null, | |||
| bool? embedLinks = null, | |||
| bool? attachFiles = null, | |||
| bool? readMessageHistory = null, | |||
| bool? mentionEveryone = null, | |||
| bool? useExternalEmojis = null, | |||
| bool? connect = null, | |||
| bool? speak = null, | |||
| bool? muteMembers = null, | |||
| bool? deafenMembers = null, | |||
| bool? moveMembers = null, | |||
| bool? useVoiceActivation = null, | |||
| bool? changeNickname = null, | |||
| bool? manageNicknames = null, | |||
| bool? manageRoles = null, | |||
| bool? manageWebhooks = null, | |||
| bool? manageEmojis = null) | |||
| { | |||
| ulong value = initialValue; | |||
| @@ -99,7 +124,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, readMessages, GuildPermission.ReadMessages); | |||
| Permissions.SetValue(ref value, viewChannel, GuildPermission.ViewChannel); | |||
| Permissions.SetValue(ref value, sendMessages, GuildPermission.SendMessages); | |||
| Permissions.SetValue(ref value, sendTTSMessages, GuildPermission.SendTTSMessages); | |||
| Permissions.SetValue(ref value, manageMessages, GuildPermission.ManageMessages); | |||
| @@ -124,34 +149,98 @@ namespace Discord | |||
| } | |||
| /// <summary> Creates a new <see cref="GuildPermissions"/> with the provided permissions. </summary> | |||
| public GuildPermissions(bool createInstantInvite = false, bool kickMembers = false, | |||
| bool banMembers = false, bool administrator = false, bool manageChannels = false, bool manageGuild = false, | |||
| bool addReactions = false, bool viewAuditLog = false, | |||
| bool readMessages = false, bool sendMessages = false, bool sendTTSMessages = false, bool manageMessages = false, | |||
| bool embedLinks = false, bool attachFiles = false, bool readMessageHistory = false, bool mentionEveryone = false, | |||
| bool useExternalEmojis = false, bool connect = false, bool speak = false, bool muteMembers = false, bool deafenMembers = false, | |||
| bool moveMembers = false, bool useVoiceActivation = false, bool? changeNickname = false, bool? manageNicknames = false, | |||
| bool manageRoles = false, bool manageWebhooks = false, bool manageEmojis = false) | |||
| : this(0, createInstantInvite: createInstantInvite, manageRoles: manageRoles, kickMembers: kickMembers, banMembers: banMembers, | |||
| administrator: administrator, manageChannels: manageChannels, manageGuild: manageGuild, addReactions: addReactions, | |||
| viewAuditLog: viewAuditLog, readMessages: readMessages, sendMessages: sendMessages, sendTTSMessages: sendTTSMessages, | |||
| manageMessages: manageMessages, embedLinks: embedLinks, attachFiles: attachFiles, readMessageHistory: readMessageHistory, | |||
| mentionEveryone: mentionEveryone, useExternalEmojis: useExternalEmojis, connect: connect, speak: speak, muteMembers: muteMembers, | |||
| deafenMembers: deafenMembers, moveMembers: moveMembers, useVoiceActivation: useVoiceActivation, changeNickname: changeNickname, | |||
| manageNicknames: manageNicknames, manageWebhooks: manageWebhooks, manageEmojis: manageEmojis) | |||
| public GuildPermissions( | |||
| bool createInstantInvite = false, | |||
| bool kickMembers = false, | |||
| bool banMembers = false, | |||
| bool administrator = false, | |||
| bool manageChannels = false, | |||
| bool manageGuild = false, | |||
| bool addReactions = false, | |||
| bool viewAuditLog = false, | |||
| bool viewChannel = false, | |||
| bool sendMessages = false, | |||
| bool sendTTSMessages = false, | |||
| bool manageMessages = false, | |||
| bool embedLinks = false, | |||
| bool attachFiles = false, | |||
| bool readMessageHistory = false, | |||
| bool mentionEveryone = false, | |||
| bool useExternalEmojis = false, | |||
| bool connect = false, | |||
| bool speak = false, | |||
| bool muteMembers = false, | |||
| bool deafenMembers = false, | |||
| bool moveMembers = false, | |||
| bool useVoiceActivation = false, | |||
| bool changeNickname = false, | |||
| bool manageNicknames = false, | |||
| bool manageRoles = false, | |||
| bool manageWebhooks = false, | |||
| bool manageEmojis = false) | |||
| : this(0, | |||
| createInstantInvite: createInstantInvite, | |||
| manageRoles: manageRoles, | |||
| kickMembers: kickMembers, | |||
| banMembers: banMembers, | |||
| administrator: administrator, | |||
| manageChannels: manageChannels, | |||
| manageGuild: manageGuild, | |||
| addReactions: addReactions, | |||
| viewAuditLog: viewAuditLog, | |||
| viewChannel: viewChannel, | |||
| sendMessages: sendMessages, | |||
| sendTTSMessages: sendTTSMessages, | |||
| manageMessages: manageMessages, | |||
| embedLinks: embedLinks, | |||
| attachFiles: attachFiles, | |||
| readMessageHistory: readMessageHistory, | |||
| mentionEveryone: mentionEveryone, | |||
| useExternalEmojis: useExternalEmojis, | |||
| connect: connect, | |||
| speak: speak, | |||
| muteMembers: muteMembers, | |||
| deafenMembers: deafenMembers, | |||
| moveMembers: moveMembers, | |||
| useVoiceActivation: useVoiceActivation, | |||
| changeNickname: changeNickname, | |||
| manageNicknames: manageNicknames, | |||
| manageWebhooks: manageWebhooks, | |||
| manageEmojis: manageEmojis) | |||
| { } | |||
| /// <summary> Creates a new <see cref="GuildPermissions"/> from this one, changing the provided non-null permissions. </summary> | |||
| public GuildPermissions Modify(bool? createInstantInvite = null, bool? kickMembers = null, | |||
| bool? banMembers = null, bool? administrator = null, bool? manageChannels = null, bool? manageGuild = null, | |||
| bool? addReactions = null, bool? viewAuditLog = null, | |||
| bool? readMessages = null, bool? sendMessages = null, bool? sendTTSMessages = null, bool? manageMessages = null, | |||
| bool? embedLinks = null, bool? attachFiles = null, bool? readMessageHistory = null, bool? mentionEveryone = null, | |||
| bool? useExternalEmojis = null, bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null, | |||
| bool? moveMembers = null, bool? useVoiceActivation = null, bool? changeNickname = null, bool? manageNicknames = null, | |||
| bool? manageRoles = null, bool? manageWebhooks = null, bool? manageEmojis = null) | |||
| public GuildPermissions Modify( | |||
| bool? createInstantInvite = null, | |||
| bool? kickMembers = null, | |||
| bool? banMembers = null, | |||
| bool? administrator = null, | |||
| bool? manageChannels = null, | |||
| bool? manageGuild = null, | |||
| bool? addReactions = null, | |||
| bool? viewAuditLog = null, | |||
| bool? viewChannel = null, | |||
| bool? sendMessages = null, | |||
| bool? sendTTSMessages = null, | |||
| bool? manageMessages = null, | |||
| bool? embedLinks = null, | |||
| bool? attachFiles = null, | |||
| bool? readMessageHistory = null, | |||
| bool? mentionEveryone = null, | |||
| bool? useExternalEmojis = null, | |||
| bool? connect = null, | |||
| bool? speak = null, | |||
| bool? muteMembers = null, | |||
| bool? deafenMembers = null, | |||
| bool? moveMembers = null, | |||
| bool? useVoiceActivation = null, | |||
| bool? changeNickname = null, | |||
| bool? manageNicknames = null, | |||
| bool? manageRoles = null, | |||
| bool? manageWebhooks = null, | |||
| bool? manageEmojis = null) | |||
| => new GuildPermissions(RawValue, createInstantInvite, kickMembers, banMembers, administrator, manageChannels, manageGuild, addReactions, | |||
| viewAuditLog, readMessages, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles, | |||
| viewAuditLog, viewChannel, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles, | |||
| readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers, moveMembers, | |||
| useVoiceActivation, changeNickname, manageNicknames, manageRoles, manageWebhooks, manageEmojis); | |||
| @@ -84,12 +84,26 @@ namespace Discord | |||
| DenyValue = denyValue; | |||
| } | |||
| private OverwritePermissions(ulong allowValue, ulong denyValue, PermValue? createInstantInvite = null, PermValue? manageChannel = null, | |||
| private OverwritePermissions(ulong allowValue, ulong denyValue, | |||
| PermValue? createInstantInvite = null, | |||
| PermValue? manageChannel = null, | |||
| PermValue? addReactions = null, | |||
| PermValue? viewChannel = null, PermValue? sendMessages = null, PermValue? sendTTSMessages = null, PermValue? manageMessages = null, | |||
| PermValue? embedLinks = null, PermValue? attachFiles = null, PermValue? readMessageHistory = null, PermValue? mentionEveryone = null, | |||
| PermValue? useExternalEmojis = null, PermValue? connect = null, PermValue? speak = null, PermValue? muteMembers = null, | |||
| PermValue? deafenMembers = null, PermValue? moveMembers = null, PermValue? useVoiceActivation = null, PermValue? manageRoles = null, | |||
| PermValue? viewChannel = null, | |||
| PermValue? sendMessages = null, | |||
| PermValue? sendTTSMessages = null, | |||
| PermValue? manageMessages = null, | |||
| PermValue? embedLinks = null, | |||
| PermValue? attachFiles = null, | |||
| PermValue? readMessageHistory = null, | |||
| PermValue? mentionEveryone = null, | |||
| PermValue? useExternalEmojis = null, | |||
| PermValue? connect = null, | |||
| PermValue? speak = null, | |||
| PermValue? muteMembers = null, | |||
| PermValue? deafenMembers = null, | |||
| PermValue? moveMembers = null, | |||
| PermValue? useVoiceActivation = null, | |||
| PermValue? manageRoles = null, | |||
| PermValue? manageWebhooks = null) | |||
| { | |||
| Permissions.SetValue(ref allowValue, ref denyValue, createInstantInvite, ChannelPermission.CreateInstantInvite); | |||
| @@ -120,13 +134,28 @@ namespace Discord | |||
| /// <summary> | |||
| /// Creates a new <see cref="ChannelPermissions" /> with the provided permissions. | |||
| /// </summary> | |||
| public OverwritePermissions(PermValue createInstantInvite = PermValue.Inherit, PermValue manageChannel = PermValue.Inherit, | |||
| public OverwritePermissions( | |||
| PermValue createInstantInvite = PermValue.Inherit, | |||
| PermValue manageChannel = PermValue.Inherit, | |||
| PermValue addReactions = PermValue.Inherit, | |||
| PermValue readMessages = PermValue.Inherit, PermValue sendMessages = PermValue.Inherit, PermValue sendTTSMessages = PermValue.Inherit, PermValue manageMessages = PermValue.Inherit, | |||
| PermValue embedLinks = PermValue.Inherit, PermValue attachFiles = PermValue.Inherit, PermValue readMessageHistory = PermValue.Inherit, PermValue mentionEveryone = PermValue.Inherit, | |||
| PermValue useExternalEmojis = PermValue.Inherit, PermValue connect = PermValue.Inherit, PermValue speak = PermValue.Inherit, PermValue muteMembers = PermValue.Inherit, PermValue deafenMembers = PermValue.Inherit, | |||
| PermValue moveMembers = PermValue.Inherit, PermValue useVoiceActivation = PermValue.Inherit, PermValue manageRoles = PermValue.Inherit, PermValue manageWebhooks = PermValue.Inherit) | |||
| : this(0, 0, createInstantInvite, manageChannel, addReactions, readMessages, sendMessages, sendTTSMessages, manageMessages, | |||
| PermValue viewChannel = PermValue.Inherit, | |||
| PermValue sendMessages = PermValue.Inherit, | |||
| PermValue sendTTSMessages = PermValue.Inherit, | |||
| PermValue manageMessages = PermValue.Inherit, | |||
| PermValue embedLinks = PermValue.Inherit, | |||
| PermValue attachFiles = PermValue.Inherit, | |||
| PermValue readMessageHistory = PermValue.Inherit, | |||
| PermValue mentionEveryone = PermValue.Inherit, | |||
| PermValue useExternalEmojis = PermValue.Inherit, | |||
| PermValue connect = PermValue.Inherit, | |||
| PermValue speak = PermValue.Inherit, | |||
| PermValue muteMembers = PermValue.Inherit, | |||
| PermValue deafenMembers = PermValue.Inherit, | |||
| PermValue moveMembers = PermValue.Inherit, | |||
| PermValue useVoiceActivation = PermValue.Inherit, | |||
| PermValue manageRoles = PermValue.Inherit, | |||
| PermValue manageWebhooks = 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) { } | |||
| @@ -134,13 +163,28 @@ namespace Discord | |||
| /// Creates a new <see cref="OverwritePermissions" /> from this one, changing the provided non-null | |||
| /// permissions. | |||
| /// </summary> | |||
| public OverwritePermissions Modify(PermValue? createInstantInvite = null, PermValue? manageChannel = null, | |||
| public OverwritePermissions Modify( | |||
| PermValue? createInstantInvite = null, | |||
| PermValue? manageChannel = null, | |||
| PermValue? addReactions = null, | |||
| PermValue? readMessages = null, PermValue? sendMessages = null, PermValue? sendTTSMessages = null, PermValue? manageMessages = null, | |||
| PermValue? embedLinks = null, PermValue? attachFiles = null, PermValue? readMessageHistory = null, PermValue? mentionEveryone = null, | |||
| PermValue? useExternalEmojis = null, PermValue? connect = null, PermValue? speak = null, PermValue? muteMembers = null, PermValue? deafenMembers = null, | |||
| PermValue? moveMembers = null, PermValue? useVoiceActivation = null, PermValue? manageRoles = null, PermValue? manageWebhooks = null) | |||
| => new OverwritePermissions(AllowValue, DenyValue, createInstantInvite, manageChannel, addReactions, readMessages, sendMessages, sendTTSMessages, manageMessages, | |||
| PermValue? viewChannel = null, | |||
| PermValue? sendMessages = null, | |||
| PermValue? sendTTSMessages = null, | |||
| PermValue? manageMessages = null, | |||
| PermValue? embedLinks = null, | |||
| PermValue? attachFiles = null, | |||
| PermValue? readMessageHistory = null, | |||
| PermValue? mentionEveryone = null, | |||
| PermValue? useExternalEmojis = null, | |||
| PermValue? connect = null, | |||
| PermValue? speak = null, | |||
| PermValue? muteMembers = null, | |||
| PermValue? deafenMembers = null, | |||
| PermValue? moveMembers = null, | |||
| PermValue? useVoiceActivation = null, | |||
| PermValue? manageRoles = null, | |||
| PermValue? manageWebhooks = 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); | |||
| @@ -1,5 +1,8 @@ | |||
| using System; | |||
| using System.Diagnostics; | |||
| #if NETSTANDARD2_0 || NET45 | |||
| using StandardColor = System.Drawing.Color; | |||
| #endif | |||
| namespace Discord | |||
| { | |||
| @@ -125,6 +128,13 @@ namespace Discord | |||
| (uint)(b * 255.0f); | |||
| } | |||
| #if NETSTANDARD2_0 || NET45 | |||
| 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); | |||
| #endif | |||
| /// <summary> | |||
| /// Gets the hexadecimal representation of the color (e.g. <c>#000ccc</c>). | |||
| /// </summary> | |||
| @@ -18,7 +18,7 @@ namespace Discord | |||
| /// An awaitable Task containing the message sent to the channel. | |||
| /// </returns> | |||
| public static async Task<IUserMessage> SendMessageAsync(this IUser user, | |||
| string text, | |||
| string text = null, | |||
| bool isTTS = false, | |||
| Embed embed = null, | |||
| RequestOptions options = null) | |||
| @@ -55,7 +55,6 @@ namespace Discord | |||
| return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(stream, filename, text, isTTS, embed, options).ConfigureAwait(false); | |||
| } | |||
| #if FILESYSTEM | |||
| /// <summary> | |||
| /// Sends a file via DM with an optional caption. | |||
| /// </summary> | |||
| @@ -81,7 +80,7 @@ namespace Discord | |||
| { | |||
| return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false); | |||
| } | |||
| #endif | |||
| /// <summary> | |||
| /// Bans the provided user from the guild and optionally prunes their recent messages. | |||
| /// </summary> | |||
| @@ -41,7 +41,7 @@ namespace Discord.Logging | |||
| // ignored | |||
| } | |||
| } | |||
| #if FORMATSTR | |||
| public async Task LogAsync(LogSeverity severity, string source, FormattableString message, Exception ex = null) | |||
| { | |||
| try | |||
| @@ -51,52 +51,49 @@ namespace Discord.Logging | |||
| } | |||
| catch { } | |||
| } | |||
| #endif | |||
| public Task ErrorAsync(string source, Exception ex) | |||
| => LogAsync(LogSeverity.Error, source, ex); | |||
| public Task ErrorAsync(string source, string message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Error, source, message, ex); | |||
| #if FORMATSTR | |||
| public Task ErrorAsync(string source, FormattableString message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Error, source, message, ex); | |||
| #endif | |||
| public Task WarningAsync(string source, Exception ex) | |||
| => LogAsync(LogSeverity.Warning, source, ex); | |||
| public Task WarningAsync(string source, string message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Warning, source, message, ex); | |||
| #if FORMATSTR | |||
| public Task WarningAsync(string source, FormattableString message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Warning, source, message, ex); | |||
| #endif | |||
| public Task InfoAsync(string source, Exception ex) | |||
| => LogAsync(LogSeverity.Info, source, ex); | |||
| public Task InfoAsync(string source, string message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Info, source, message, ex); | |||
| #if FORMATSTR | |||
| public Task InfoAsync(string source, FormattableString message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Info, source, message, ex); | |||
| #endif | |||
| public Task VerboseAsync(string source, Exception ex) | |||
| => LogAsync(LogSeverity.Verbose, source, ex); | |||
| public Task VerboseAsync(string source, string message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Verbose, source, message, ex); | |||
| #if FORMATSTR | |||
| public Task VerboseAsync(string source, FormattableString message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Verbose, source, message, ex); | |||
| #endif | |||
| public Task DebugAsync(string source, Exception ex) | |||
| => LogAsync(LogSeverity.Debug, source, ex); | |||
| public Task DebugAsync(string source, string message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Debug, source, message, ex); | |||
| #if FORMATSTR | |||
| public Task DebugAsync(string source, FormattableString message, Exception ex = null) | |||
| => LogAsync(LogSeverity.Debug, source, message, ex); | |||
| #endif | |||
| public Logger CreateLogger(string name) => new Logger(this, name); | |||
| @@ -1,4 +1,4 @@ | |||
| using System; | |||
| using System; | |||
| using System.Threading.Tasks; | |||
| namespace Discord.Logging | |||
| @@ -20,54 +20,53 @@ namespace Discord.Logging | |||
| => _manager.LogAsync(severity, Name, exception); | |||
| public Task LogAsync(LogSeverity severity, string message, Exception exception = null) | |||
| => _manager.LogAsync(severity, Name, message, exception); | |||
| #if FORMATSTR | |||
| public Task LogAsync(LogSeverity severity, FormattableString message, Exception exception = null) | |||
| => _manager.LogAsync(severity, Name, message, exception); | |||
| #endif | |||
| public Task ErrorAsync(Exception exception) | |||
| => _manager.ErrorAsync(Name, exception); | |||
| public Task ErrorAsync(string message, Exception exception = null) | |||
| => _manager.ErrorAsync(Name, message, exception); | |||
| #if FORMATSTR | |||
| public Task ErrorAsync(FormattableString message, Exception exception = null) | |||
| => _manager.ErrorAsync(Name, message, exception); | |||
| #endif | |||
| public Task WarningAsync(Exception exception) | |||
| => _manager.WarningAsync(Name, exception); | |||
| public Task WarningAsync(string message, Exception exception = null) | |||
| => _manager.WarningAsync(Name, message, exception); | |||
| #if FORMATSTR | |||
| public Task WarningAsync(FormattableString message, Exception exception = null) | |||
| => _manager.WarningAsync(Name, message, exception); | |||
| #endif | |||
| public Task InfoAsync(Exception exception) | |||
| => _manager.InfoAsync(Name, exception); | |||
| public Task InfoAsync(string message, Exception exception = null) | |||
| => _manager.InfoAsync(Name, message, exception); | |||
| #if FORMATSTR | |||
| public Task InfoAsync(FormattableString message, Exception exception = null) | |||
| => _manager.InfoAsync(Name, message, exception); | |||
| #endif | |||
| public Task VerboseAsync(Exception exception) | |||
| => _manager.VerboseAsync(Name, exception); | |||
| public Task VerboseAsync(string message, Exception exception = null) | |||
| => _manager.VerboseAsync(Name, message, exception); | |||
| #if FORMATSTR | |||
| public Task VerboseAsync(FormattableString message, Exception exception = null) | |||
| => _manager.VerboseAsync(Name, message, exception); | |||
| #endif | |||
| public Task DebugAsync(Exception exception) | |||
| => _manager.DebugAsync(Name, exception); | |||
| public Task DebugAsync(string message, Exception exception = null) | |||
| => _manager.DebugAsync(Name, message, exception); | |||
| #if FORMATSTR | |||
| public Task DebugAsync(FormattableString message, Exception exception = null) | |||
| => _manager.DebugAsync(Name, message, exception); | |||
| #endif | |||
| } | |||
| } | |||
| @@ -25,9 +25,12 @@ namespace Discord | |||
| public RetryMode? RetryMode { get; set; } | |||
| public bool HeaderOnly { get; internal set; } | |||
| /// <summary> | |||
| /// Gets or sets the reason for this action in the guild's audit log. Note that this property may not apply | |||
| /// to every action. | |||
| /// Gets or sets the reason for this action in the guild's audit log. | |||
| /// </summary> | |||
| /// <remarks> | |||
| /// Gets or sets the reason that will be written to the guild's audit log if applicable. This may not apply | |||
| /// to all actions. | |||
| /// </remarks> | |||
| public string AuditLogReason { get; set; } | |||
| internal bool IgnoreState { get; set; } | |||
| @@ -1,57 +1,14 @@ | |||
| using System; | |||
| using System; | |||
| namespace Discord | |||
| { | |||
| //Source: https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/DateTimeOffset.cs | |||
| internal static class DateTimeUtils | |||
| { | |||
| #if !UNIXTIME | |||
| private const long UnixEpochTicks = 621_355_968_000_000_000; | |||
| private const long UnixEpochSeconds = 62_135_596_800; | |||
| private const long UnixEpochMilliseconds = 62_135_596_800_000; | |||
| #endif | |||
| public static DateTimeOffset FromTicks(long ticks) | |||
| => new DateTimeOffset(ticks, TimeSpan.Zero); | |||
| public static DateTimeOffset? FromTicks(long? ticks) | |||
| => ticks != null ? new DateTimeOffset(ticks.Value, TimeSpan.Zero) : (DateTimeOffset?)null; | |||
| public static DateTimeOffset FromUnixSeconds(long seconds) | |||
| { | |||
| #if UNIXTIME | |||
| return DateTimeOffset.FromUnixTimeSeconds(seconds); | |||
| #else | |||
| long ticks = seconds * TimeSpan.TicksPerSecond + UnixEpochTicks; | |||
| return new DateTimeOffset(ticks, TimeSpan.Zero); | |||
| #endif | |||
| } | |||
| public static DateTimeOffset FromUnixMilliseconds(long milliseconds) | |||
| { | |||
| #if UNIXTIME | |||
| return DateTimeOffset.FromUnixTimeMilliseconds(milliseconds); | |||
| #else | |||
| long ticks = milliseconds * TimeSpan.TicksPerMillisecond + UnixEpochTicks; | |||
| return new DateTimeOffset(ticks, TimeSpan.Zero); | |||
| #endif | |||
| } | |||
| public static long ToUnixSeconds(DateTimeOffset dto) | |||
| { | |||
| #if UNIXTIME | |||
| return dto.ToUnixTimeSeconds(); | |||
| #else | |||
| long seconds = dto.UtcDateTime.Ticks / TimeSpan.TicksPerSecond; | |||
| return seconds - UnixEpochSeconds; | |||
| #endif | |||
| } | |||
| public static long ToUnixMilliseconds(DateTimeOffset dto) | |||
| { | |||
| #if UNIXTIME | |||
| return dto.ToUnixTimeMilliseconds(); | |||
| #else | |||
| long milliseconds = dto.UtcDateTime.Ticks / TimeSpan.TicksPerMillisecond; | |||
| return milliseconds - UnixEpochMilliseconds; | |||
| #endif | |||
| } | |||
| } | |||
| } | |||
| @@ -5,8 +5,8 @@ namespace Discord | |||
| public static class SnowflakeUtils | |||
| { | |||
| public static DateTimeOffset FromSnowflake(ulong value) | |||
| => DateTimeUtils.FromUnixMilliseconds((long)((value >> 22) + 1420070400000UL)); | |||
| => DateTimeOffset.FromUnixTimeMilliseconds((long)((value >> 22) + 1420070400000UL)); | |||
| public static ulong ToSnowflake(DateTimeOffset value) | |||
| => ((ulong)DateTimeUtils.ToUnixMilliseconds(value) - 1420070400000UL) << 22; | |||
| => ((ulong)value.ToUnixTimeMilliseconds() - 1420070400000UL) << 22; | |||
| } | |||
| } | |||
| @@ -1,4 +1,4 @@ | |||
| #pragma warning disable CS1591 | |||
| #pragma warning disable CS1591 | |||
| using Newtonsoft.Json; | |||
| using System; | |||
| @@ -12,10 +12,16 @@ namespace Discord.API | |||
| public MessageType Type { get; set; } | |||
| [JsonProperty("channel_id")] | |||
| public ulong ChannelId { get; set; } | |||
| // ALWAYS sent on WebSocket messages | |||
| [JsonProperty("guild_id")] | |||
| public Optional<ulong> GuildId { get; set; } | |||
| [JsonProperty("webhook_id")] | |||
| public Optional<ulong> WebhookId { get; set; } | |||
| [JsonProperty("author")] | |||
| public Optional<User> Author { get; set; } | |||
| // ALWAYS sent on WebSocket messages | |||
| [JsonProperty("member")] | |||
| public Optional<GuildMember> Member { get; set; } | |||
| [JsonProperty("content")] | |||
| public Optional<string> Content { get; set; } | |||
| [JsonProperty("timestamp")] | |||
| @@ -1,4 +1,4 @@ | |||
| #pragma warning disable CS1591 | |||
| #pragma warning disable CS1591 | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API | |||
| @@ -11,6 +11,9 @@ namespace Discord.API | |||
| public ulong? ChannelId { get; set; } | |||
| [JsonProperty("user_id")] | |||
| public ulong UserId { get; set; } | |||
| // ALWAYS sent over WebSocket, never on REST | |||
| [JsonProperty("member")] | |||
| public Optional<GuildMember> Member { get; set; } | |||
| [JsonProperty("session_id")] | |||
| public string SessionId { get; set; } | |||
| [JsonProperty("deaf")] | |||
| @@ -1,4 +1,4 @@ | |||
| #pragma warning disable CS1591 | |||
| #pragma warning disable CS1591 | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API.Rest | |||
| @@ -10,9 +10,20 @@ namespace Discord.API.Rest | |||
| public string Name { get; } | |||
| [JsonProperty("type")] | |||
| public ChannelType Type { get; } | |||
| [JsonProperty("parent_id")] | |||
| public Optional<ulong?> CategoryId { get; set; } | |||
| //Text channels | |||
| [JsonProperty("topic")] | |||
| public Optional<string> Topic { get; set; } | |||
| [JsonProperty("nsfw")] | |||
| public Optional<bool> IsNsfw { get; set; } | |||
| //Voice channels | |||
| [JsonProperty("bitrate")] | |||
| public Optional<int> Bitrate { get; set; } | |||
| [JsonProperty("user_limit")] | |||
| public Optional<int?> UserLimit { get; set; } | |||
| public CreateGuildChannelParams(string name, ChannelType type) | |||
| { | |||
| @@ -1,4 +1,4 @@ | |||
| namespace Discord.API.Rest | |||
| namespace Discord.API.Rest | |||
| { | |||
| internal class GetReactionUsersParams | |||
| { | |||
| @@ -1,20 +1,19 @@ | |||
| <Project Sdk="Microsoft.NET.Sdk"> | |||
| <Project Sdk="Microsoft.NET.Sdk"> | |||
| <Import Project="../../Discord.Net.targets" /> | |||
| <PropertyGroup> | |||
| <AssemblyName>Discord.Net.Rest</AssemblyName> | |||
| <RootNamespace>Discord.Rest</RootNamespace> | |||
| <Description>A core Discord.Net library containing the REST client and models.</Description> | |||
| <TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net45;netstandard1.1;netstandard1.3</TargetFrameworks> | |||
| <TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.1;netstandard1.3</TargetFrameworks> | |||
| <TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net46;netstandard1.3;netstandard2.0</TargetFrameworks> | |||
| <TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.3;netstandard2.0</TargetFrameworks> | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <ProjectReference Include="..\Discord.Net.Core\Discord.Net.Core.csproj" /> | |||
| </ItemGroup> | |||
| <ItemGroup Condition=" '$(TargetFramework)' != 'net45' "> | |||
| <PackageReference Include="System.Net.Http" Version="4.3.2" /> | |||
| <!-- https://github.com/dotnet/corefx/issues/19535 --> | |||
| <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' "> | |||
| <PackageReference Include="System.Net.Http" Version="4.3.3" /> | |||
| </ItemGroup> | |||
| <ItemGroup Condition=" '$(TargetFramework)' == 'net45' "> | |||
| <ItemGroup Condition=" '$(TargetFramework)' == 'net46' "> | |||
| <Reference Include="System.Net.Http" /> | |||
| </ItemGroup> | |||
| </Project> | |||
| @@ -630,11 +630,11 @@ namespace Discord.API | |||
| Preconditions.NotNullOrWhitespace(emoji, nameof(emoji)); | |||
| Preconditions.NotNull(args, nameof(args)); | |||
| Preconditions.GreaterThan(args.Limit, 0, nameof(args.Limit)); | |||
| Preconditions.AtMost(args.Limit, DiscordConfig.MaxUsersPerBatch, 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(int.MaxValue); | |||
| int limit = args.Limit.GetValueOrDefault(DiscordConfig.MaxUserReactionsPerBatch); | |||
| ulong afterUserId = args.AfterUserId.GetValueOrDefault(0); | |||
| var ids = new BucketIds(channelId: channelId); | |||
| @@ -1,10 +1,13 @@ | |||
| using System.Linq; | |||
| using System.Linq; | |||
| using Model = Discord.API.AuditLog; | |||
| using EntryModel = Discord.API.AuditLogEntry; | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents a piece of audit log data related to a ban. | |||
| /// </summary> | |||
| public class BanAuditLogData : IAuditLogData | |||
| { | |||
| private BanAuditLogData(IUser user) | |||
| @@ -18,6 +21,12 @@ namespace Discord.Rest | |||
| return new BanAuditLogData(RestUser.Create(discord, userInfo)); | |||
| } | |||
| /// <summary> | |||
| /// Gets the user that was banned. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A user object representing the banned user. | |||
| /// </returns> | |||
| public IUser Target { get; } | |||
| } | |||
| } | |||
| @@ -1,4 +1,3 @@ | |||
| using Newtonsoft.Json.Linq; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| @@ -7,6 +6,9 @@ using EntryModel = Discord.API.AuditLogEntry; | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents a piece of audit log data related to a channel creation. | |||
| /// </summary> | |||
| public class ChannelCreateAuditLogData : IAuditLogData | |||
| { | |||
| private ChannelCreateAuditLogData(ulong id, string name, ChannelType type, IReadOnlyCollection<Overwrite> overwrites) | |||
| @@ -44,9 +46,33 @@ namespace Discord.Rest | |||
| return new ChannelCreateAuditLogData(entry.TargetId.Value, name, type, overwrites.ToReadOnlyCollection()); | |||
| } | |||
| /// <summary> | |||
| /// Gets the snowflake ID of the created channel. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="ulong"/> representing the snowflake identifier for the created channel. | |||
| /// </returns> | |||
| public ulong ChannelId { get; } | |||
| /// <summary> | |||
| /// Gets the name of the created channel. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the name of the created channel. | |||
| /// </returns> | |||
| public string ChannelName { get; } | |||
| /// <summary> | |||
| /// Gets the type of the created channel. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// The type of channel that was created. | |||
| /// </returns> | |||
| public ChannelType ChannelType { get; } | |||
| /// <summary> | |||
| /// Gets a collection of permission overwrites that was assigned to the created channel. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A collection of permission <see cref="Overwrite" />. | |||
| /// </returns> | |||
| public IReadOnlyCollection<Overwrite> Overwrites { get; } | |||
| } | |||
| } | |||
| @@ -1,14 +1,14 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| using Model = Discord.API.AuditLog; | |||
| using EntryModel = Discord.API.AuditLogEntry; | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents a piece of audit log data related to a channel deletion. | |||
| /// </summary> | |||
| public class ChannelDeleteAuditLogData : IAuditLogData | |||
| { | |||
| private ChannelDeleteAuditLogData(ulong id, string name, ChannelType type, IReadOnlyCollection<Overwrite> overwrites) | |||
| @@ -37,9 +37,33 @@ namespace Discord.Rest | |||
| return new ChannelDeleteAuditLogData(id, name, type, overwrites.ToReadOnlyCollection()); | |||
| } | |||
| /// <summary> | |||
| /// Gets the snowflake ID of the deleted channel. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="ulong"/> representing the snowflake identifier for the deleted channel. | |||
| /// </returns> | |||
| public ulong ChannelId { get; } | |||
| /// <summary> | |||
| /// Gets the name of the deleted channel. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the name of the deleted channel. | |||
| /// </returns> | |||
| public string ChannelName { get; } | |||
| /// <summary> | |||
| /// Gets the type of the deleted channel. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// The type of channel that was deleted. | |||
| /// </returns> | |||
| public ChannelType ChannelType { get; } | |||
| /// <summary> | |||
| /// Gets a collection of permission overwrites that was assigned to the deleted channel. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A collection of permission <see cref="Overwrite" />. | |||
| /// </returns> | |||
| public IReadOnlyCollection<Overwrite> Overwrites { get; } | |||
| } | |||
| } | |||
| @@ -1,5 +1,8 @@ | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents information for a channel. | |||
| /// </summary> | |||
| public struct ChannelInfo | |||
| { | |||
| internal ChannelInfo(string name, string topic, int? bitrate, int? limit) | |||
| @@ -10,9 +13,35 @@ namespace Discord.Rest | |||
| UserLimit = limit; | |||
| } | |||
| /// <summary> | |||
| /// Gets the name of this channel. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the name of this channel. | |||
| /// </returns> | |||
| public string Name { get; } | |||
| /// <summary> | |||
| /// Gets the topic of this channel. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the topic of this channel, if any. | |||
| /// </returns> | |||
| public string Topic { get; } | |||
| /// <summary> | |||
| /// Gets the bitrate of this channel if applicable. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="System.Int32"/> representing the bitrate set for the voice channel; <c>null</c> if not | |||
| /// applicable. | |||
| /// </returns> | |||
| public int? Bitrate { get; } | |||
| /// <summary> | |||
| /// Gets the number of users allowed to be in this channel if applicable. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="System.Int32" /> representing the number of users allowed to be in this voice channel; | |||
| /// <c>null</c> if not applicable. | |||
| /// </returns> | |||
| public int? UserLimit { get; } | |||
| } | |||
| } | |||
| @@ -1,10 +1,13 @@ | |||
| using System.Linq; | |||
| using System.Linq; | |||
| using Model = Discord.API.AuditLog; | |||
| using EntryModel = Discord.API.AuditLogEntry; | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents a piece of audit log data related to a channel update. | |||
| /// </summary> | |||
| public class ChannelUpdateAuditLogData : IAuditLogData | |||
| { | |||
| private ChannelUpdateAuditLogData(ulong id, ChannelInfo before, ChannelInfo after) | |||
| @@ -38,8 +41,14 @@ namespace Discord.Rest | |||
| return new ChannelUpdateAuditLogData(entry.TargetId.Value, before, after); | |||
| } | |||
| /// <summary> | |||
| /// Gets the snowflake ID of the updated channel. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="ulong"/> representing the snowflake identifier for the updated channel. | |||
| /// </returns> | |||
| public ulong ChannelId { get; } | |||
| public ChannelInfo Before { get; set; } | |||
| public ChannelInfo After { get; set; } | |||
| public ChannelInfo Before { get; } | |||
| public ChannelInfo After { get; } | |||
| } | |||
| } | |||
| @@ -1,14 +1,13 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| using Model = Discord.API.AuditLog; | |||
| using EntryModel = Discord.API.AuditLogEntry; | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents a piece of audit log data related to an emoji creation. | |||
| /// </summary> | |||
| public class EmoteCreateAuditLogData : IAuditLogData | |||
| { | |||
| private EmoteCreateAuditLogData(ulong id, string name) | |||
| @@ -25,7 +24,19 @@ namespace Discord.Rest | |||
| return new EmoteCreateAuditLogData(entry.TargetId.Value, emoteName); | |||
| } | |||
| /// <summary> | |||
| /// Gets the snowflake ID of the created emoji. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="System.UInt64"/> representing the snowflake identifier for the created emoji. | |||
| /// </returns> | |||
| public ulong EmoteId { get; } | |||
| /// <summary> | |||
| /// Gets the name of the created emoji. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the name of the created emoji. | |||
| /// </returns> | |||
| public string Name { get; } | |||
| } | |||
| } | |||
| @@ -1,10 +1,13 @@ | |||
| using System.Linq; | |||
| using System.Linq; | |||
| using Model = Discord.API.AuditLog; | |||
| using EntryModel = Discord.API.AuditLogEntry; | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents a piece of audit log data related to an emoji deletion. | |||
| /// </summary> | |||
| public class EmoteDeleteAuditLogData : IAuditLogData | |||
| { | |||
| private EmoteDeleteAuditLogData(ulong id, string name) | |||
| @@ -22,7 +25,19 @@ namespace Discord.Rest | |||
| return new EmoteDeleteAuditLogData(entry.TargetId.Value, emoteName); | |||
| } | |||
| /// <summary> | |||
| /// Gets the snowflake ID of the deleted emoji. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="System.UInt64"/> representing the snowflake identifier for the deleted emoji. | |||
| /// </returns> | |||
| public ulong EmoteId { get; } | |||
| /// <summary> | |||
| /// Gets the name of the deleted emoji. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the name of the deleted emoji. | |||
| /// </returns> | |||
| public string Name { get; } | |||
| } | |||
| } | |||
| @@ -1,10 +1,13 @@ | |||
| using System.Linq; | |||
| using System.Linq; | |||
| using Model = Discord.API.AuditLog; | |||
| using EntryModel = Discord.API.AuditLogEntry; | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents a piece of audit log data related to an emoji update. | |||
| /// </summary> | |||
| public class EmoteUpdateAuditLogData : IAuditLogData | |||
| { | |||
| private EmoteUpdateAuditLogData(ulong id, string oldName, string newName) | |||
| @@ -24,8 +27,26 @@ namespace Discord.Rest | |||
| return new EmoteUpdateAuditLogData(entry.TargetId.Value, oldName, newName); | |||
| } | |||
| /// <summary> | |||
| /// Gets the snowflake ID of the updated emoji. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="System.UInt64"/> representing the snowflake identifier of the updated emoji. | |||
| /// </returns> | |||
| public ulong EmoteId { get; } | |||
| /// <summary> | |||
| /// Gets the new name of the updated emoji. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the new name of the updated emoji. | |||
| /// </returns> | |||
| public string NewName { get; } | |||
| /// <summary> | |||
| /// Gets the old name of the updated emoji. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the old name of the updated emoji. | |||
| /// </returns> | |||
| public string OldName { get; } | |||
| } | |||
| } | |||
| @@ -1,5 +1,8 @@ | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents information for a guild. | |||
| /// </summary> | |||
| public struct GuildInfo | |||
| { | |||
| internal GuildInfo(int? afkTimeout, DefaultMessageNotifications? defaultNotifs, | |||
| @@ -18,14 +21,66 @@ namespace Discord.Rest | |||
| ContentFilterLevel = filter; | |||
| } | |||
| /// <summary> | |||
| /// Gets the amount of time (in seconds) a user must be inactive in a voice channel for until they are | |||
| /// automatically moved to the AFK voice channel. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="int"/> representing the amount of time in seconds for a user to be marked as inactive | |||
| /// and moved into the AFK voice channel. | |||
| /// </returns> | |||
| public int? AfkTimeout { get; } | |||
| /// <summary> | |||
| /// Gets the default message notifications for users who haven't explicitly set their notification settings. | |||
| /// </summary> | |||
| public DefaultMessageNotifications? DefaultMessageNotifications { get; } | |||
| /// <summary> | |||
| /// Gets the ID of the AFK voice channel for this guild. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="ulong"/> representing the snowflake identifier of the AFK voice channel; <c>null</c> if | |||
| /// none is set. | |||
| /// </returns> | |||
| public ulong? AfkChannelId { get; } | |||
| /// <summary> | |||
| /// Gets the name of this guild. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the name of this guild. | |||
| /// </returns> | |||
| public string Name { get; } | |||
| /// <summary> | |||
| /// Gets the ID of the region hosting this guild's voice channels. | |||
| /// </summary> | |||
| public string RegionId { get; } | |||
| /// <summary> | |||
| /// Gets the ID of this guild's icon. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the identifier for the splash image; <c>null</c> if none is set. | |||
| /// </returns> | |||
| public string IconHash { get; } | |||
| /// <summary> | |||
| /// Gets the level of requirements a user must fulfill before being allowed to post messages in this guild. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// The level of requirements. | |||
| /// </returns> | |||
| public VerificationLevel? VerificationLevel { get; } | |||
| /// <summary> | |||
| /// Gets the owner of this guild. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A user object representing the owner of this guild. | |||
| /// </returns> | |||
| public IUser Owner { get; } | |||
| /// <summary> | |||
| /// Gets the level of Multi-Factor Authentication requirements a user must fulfill before being allowed to | |||
| /// perform administrative actions in this guild. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// The level of MFA requirement. | |||
| /// </returns> | |||
| public MfaLevel? MfaLevel { get; } | |||
| public int? ContentFilterLevel { get; } | |||
| } | |||
| @@ -1,10 +1,13 @@ | |||
| using System.Linq; | |||
| using System.Linq; | |||
| using Model = Discord.API.AuditLog; | |||
| using EntryModel = Discord.API.AuditLogEntry; | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents a piece of audit log data related to a guild update. | |||
| /// </summary> | |||
| public class GuildUpdateAuditLogData : IAuditLogData | |||
| { | |||
| private GuildUpdateAuditLogData(GuildInfo before, GuildInfo after) | |||
| @@ -73,7 +76,19 @@ namespace Discord.Rest | |||
| return new GuildUpdateAuditLogData(before, after); | |||
| } | |||
| /// <summary> | |||
| /// Gets the guild information before the changes. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An information object containing the original guild information before the changes were made. | |||
| /// </returns> | |||
| public GuildInfo Before { get; } | |||
| /// <summary> | |||
| /// Gets the guild information after the changes. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An information object containing the guild information after the changes were made. | |||
| /// </returns> | |||
| public GuildInfo After { get; } | |||
| } | |||
| } | |||
| @@ -1,10 +1,13 @@ | |||
| using System.Linq; | |||
| using System.Linq; | |||
| using Model = Discord.API.AuditLog; | |||
| using EntryModel = Discord.API.AuditLogEntry; | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents a piece of audit log data related to an invite creation. | |||
| /// </summary> | |||
| public class InviteCreateAuditLogData : IAuditLogData | |||
| { | |||
| private InviteCreateAuditLogData(int maxAge, string code, bool temporary, IUser inviter, ulong channelId, int uses, int maxUses) | |||
| @@ -44,12 +47,57 @@ namespace Discord.Rest | |||
| return new InviteCreateAuditLogData(maxAge, code, temporary, inviter, channelId, uses, maxUses); | |||
| } | |||
| /// <summary> | |||
| /// Gets the time (in seconds) until the invite expires. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="int"/> representing the time in seconds until this invite expires. | |||
| /// </returns> | |||
| public int MaxAge { get; } | |||
| /// <summary> | |||
| /// Gets the unique identifier for this invite. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the invite code (e.g. <c>FTqNnyS</c>). | |||
| /// </returns> | |||
| public string Code { get; } | |||
| /// <summary> | |||
| /// Determines whether the invite is a temporary one (i.e. whether the invite will be removed from the guild | |||
| /// when the user logs off). | |||
| /// </summary> | |||
| /// <returns> | |||
| /// <c>true</c> if users accepting this invite will be removed from the guild when they log off; otherwise | |||
| /// <c>false</c>. | |||
| /// </returns> | |||
| public bool Temporary { get; } | |||
| /// <summary> | |||
| /// Gets the user that created this invite. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A user that created this invite. | |||
| /// </returns> | |||
| public IUser Creator { get; } | |||
| /// <summary> | |||
| /// Gets the ID of the channel this invite is linked to. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="ulong"/> representing the channel snowflake identifier that the invite points to. | |||
| /// </returns> | |||
| public ulong ChannelId { get; } | |||
| /// <summary> | |||
| /// Gets the number of times this invite has been used. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="int"/> representing the number of times this invite has been used. | |||
| /// </returns> | |||
| public int Uses { get; } | |||
| /// <summary> | |||
| /// Gets the max number of uses this invite may have. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="int"/> representing the number of uses this invite may be accepted until it is removed | |||
| /// from the guild; <c>null</c> if none is set. | |||
| /// </returns> | |||
| public int MaxUses { get; } | |||
| } | |||
| } | |||
| @@ -1,10 +1,13 @@ | |||
| using System.Linq; | |||
| using System.Linq; | |||
| using Model = Discord.API.AuditLog; | |||
| using EntryModel = Discord.API.AuditLogEntry; | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents a piece of audit log data related to an invite removal. | |||
| /// </summary> | |||
| public class InviteDeleteAuditLogData : IAuditLogData | |||
| { | |||
| private InviteDeleteAuditLogData(int maxAge, string code, bool temporary, IUser inviter, ulong channelId, int uses, int maxUses) | |||
| @@ -44,12 +47,57 @@ namespace Discord.Rest | |||
| return new InviteDeleteAuditLogData(maxAge, code, temporary, inviter, channelId, uses, maxUses); | |||
| } | |||
| /// <summary> | |||
| /// Gets the time (in seconds) until the invite expires. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="int"/> representing the time in seconds until this invite expires. | |||
| /// </returns> | |||
| public int MaxAge { get; } | |||
| /// <summary> | |||
| /// Gets the unique identifier for this invite. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the invite code (e.g. <c>FTqNnyS</c>). | |||
| /// </returns> | |||
| public string Code { get; } | |||
| /// <summary> | |||
| /// Determines whether the invite is a temporary one (i.e. whether the invite will be removed from the guild | |||
| /// when the user logs off). | |||
| /// </summary> | |||
| /// <returns> | |||
| /// <c>true</c> if users accepting this invite will be removed from the guild when they log off; otherwise | |||
| /// <c>false</c>. | |||
| /// </returns> | |||
| public bool Temporary { get; } | |||
| /// <summary> | |||
| /// Gets the user that created this invite. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A user that created this invite. | |||
| /// </returns> | |||
| public IUser Creator { get; } | |||
| /// <summary> | |||
| /// Gets the ID of the channel this invite is linked to. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="ulong"/> representing the channel snowflake identifier that the invite points to. | |||
| /// </returns> | |||
| public ulong ChannelId { get; } | |||
| /// <summary> | |||
| /// Gets the number of times this invite has been used. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="int"/> representing the number of times this invite has been used. | |||
| /// </returns> | |||
| public int Uses { get; } | |||
| /// <summary> | |||
| /// Gets the max number of uses this invite may have. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="int"/> representing the number of uses this invite may be accepted until it is removed | |||
| /// from the guild; <c>null</c> if none is set. | |||
| /// </returns> | |||
| public int MaxUses { get; } | |||
| } | |||
| } | |||
| @@ -1,5 +1,8 @@ | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents information for an invite. | |||
| /// </summary> | |||
| public struct InviteInfo | |||
| { | |||
| internal InviteInfo(int? maxAge, string code, bool? temporary, ulong? channelId, int? maxUses) | |||
| @@ -11,10 +14,45 @@ namespace Discord.Rest | |||
| MaxUses = maxUses; | |||
| } | |||
| /// <summary> | |||
| /// Gets the time (in seconds) until the invite expires. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="int"/> representing the time in seconds until this invite expires; <c>null</c> if this | |||
| /// invite never expires or not specified. | |||
| /// </returns> | |||
| public int? MaxAge { get; } | |||
| /// <summary> | |||
| /// Gets the unique identifier for this invite. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the invite code (e.g. <c>FTqNnyS</c>). | |||
| /// </returns> | |||
| public string Code { get; } | |||
| /// <summary> | |||
| /// Determines whether the invite is a temporary one (i.e. whether the invite will be removed from the guild | |||
| /// when the user logs off). | |||
| /// </summary> | |||
| /// <returns> | |||
| /// <c>true</c> if users accepting this invite will be removed from the guild when they log off, | |||
| /// <c>false</c> if not; <c>null</c> if not specified. | |||
| /// </returns> | |||
| public bool? Temporary { get; } | |||
| /// <summary> | |||
| /// Gets the ID of the channel this invite is linked to. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="ulong"/> representing the channel snowflake identifier that the invite points to; | |||
| /// <c>null</c> if not specified. | |||
| /// </returns> | |||
| public ulong? ChannelId { get; } | |||
| /// <summary> | |||
| /// Gets the max number of uses this invite may have. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// An <see cref="int"/> representing the number of uses this invite may be accepted until it is removed | |||
| /// from the guild; <c>null</c> if none is specified. | |||
| /// </returns> | |||
| public int? MaxUses { get; } | |||
| } | |||
| } | |||
| @@ -1,4 +1,3 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| @@ -9,7 +8,7 @@ namespace Discord.Rest | |||
| { | |||
| public class MemberRoleAuditLogData : IAuditLogData | |||
| { | |||
| private MemberRoleAuditLogData(IReadOnlyCollection<RoleInfo> roles, IUser target) | |||
| private MemberRoleAuditLogData(IReadOnlyCollection<MemberRoleEditInfo> roles, IUser target) | |||
| { | |||
| Roles = roles; | |||
| Target = target; | |||
| @@ -21,7 +20,7 @@ namespace Discord.Rest | |||
| var roleInfos = changes.SelectMany(x => x.NewValue.ToObject<API.Role[]>(), | |||
| (model, role) => new { model.ChangedProperty, Role = role }) | |||
| .Select(x => new RoleInfo(x.Role.Name, x.Role.Id, x.ChangedProperty == "$add")) | |||
| .Select(x => new MemberRoleEditInfo(x.Role.Name, x.Role.Id, x.ChangedProperty == "$add")) | |||
| .ToList(); | |||
| var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId); | |||
| @@ -30,21 +29,7 @@ namespace Discord.Rest | |||
| return new MemberRoleAuditLogData(roleInfos.ToReadOnlyCollection(), user); | |||
| } | |||
| public IReadOnlyCollection<RoleInfo> Roles { get; } | |||
| public IReadOnlyCollection<MemberRoleEditInfo> Roles { get; } | |||
| public IUser Target { get; } | |||
| public struct RoleInfo | |||
| { | |||
| internal RoleInfo(string name, ulong roleId, bool added) | |||
| { | |||
| Name = name; | |||
| RoleId = roleId; | |||
| Added = added; | |||
| } | |||
| public string Name { get; } | |||
| public ulong RoleId { get; } | |||
| public bool Added { get; } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,16 @@ | |||
| namespace Discord.Rest | |||
| { | |||
| public struct MemberRoleEditInfo | |||
| { | |||
| internal MemberRoleEditInfo(string name, ulong roleId, bool added) | |||
| { | |||
| Name = name; | |||
| RoleId = roleId; | |||
| Added = added; | |||
| } | |||
| public string Name { get; } | |||
| public ulong RoleId { get; } | |||
| public bool Added { get; } | |||
| } | |||
| } | |||
| @@ -1,8 +1,7 @@ | |||
| using System.Linq; | |||
| using System.Linq; | |||
| using Model = Discord.API.AuditLog; | |||
| using EntryModel = Discord.API.AuditLogEntry; | |||
| using ChangeModel = Discord.API.AuditLogChange; | |||
| namespace Discord.Rest | |||
| { | |||
| @@ -1,13 +1,7 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| using Model = Discord.API.AuditLog; | |||
| using EntryModel = Discord.API.AuditLogEntry; | |||
| using ChangeModel = Discord.API.AuditLogChange; | |||
| using OptionModel = Discord.API.AuditLogOptions; | |||
| namespace Discord.Rest | |||
| { | |||
| @@ -7,7 +7,7 @@ namespace Discord.Rest | |||
| { | |||
| public class RoleCreateAuditLogData : IAuditLogData | |||
| { | |||
| private RoleCreateAuditLogData(ulong id, RoleInfo props) | |||
| private RoleCreateAuditLogData(ulong id, RoleEditInfo props) | |||
| { | |||
| RoleId = id; | |||
| Properties = props; | |||
| @@ -38,10 +38,10 @@ namespace Discord.Rest | |||
| permissions = new GuildPermissions(permissionsRaw.Value); | |||
| return new RoleCreateAuditLogData(entry.TargetId.Value, | |||
| new RoleInfo(color, mentionable, hoist, name, permissions)); | |||
| new RoleEditInfo(color, mentionable, hoist, name, permissions)); | |||
| } | |||
| public ulong RoleId { get; } | |||
| public RoleInfo Properties { get; } | |||
| public RoleEditInfo Properties { get; } | |||
| } | |||
| } | |||
| @@ -7,7 +7,7 @@ namespace Discord.Rest | |||
| { | |||
| public class RoleDeleteAuditLogData : IAuditLogData | |||
| { | |||
| private RoleDeleteAuditLogData(ulong id, RoleInfo props) | |||
| private RoleDeleteAuditLogData(ulong id, RoleEditInfo props) | |||
| { | |||
| RoleId = id; | |||
| Properties = props; | |||
| @@ -38,10 +38,10 @@ namespace Discord.Rest | |||
| permissions = new GuildPermissions(permissionsRaw.Value); | |||
| return new RoleDeleteAuditLogData(entry.TargetId.Value, | |||
| new RoleInfo(color, mentionable, hoist, name, permissions)); | |||
| new RoleEditInfo(color, mentionable, hoist, name, permissions)); | |||
| } | |||
| public ulong RoleId { get; } | |||
| public RoleInfo Properties { get; } | |||
| public RoleEditInfo Properties { get; } | |||
| } | |||
| } | |||
| @@ -0,0 +1,21 @@ | |||
| namespace Discord.Rest | |||
| { | |||
| public struct RoleEditInfo | |||
| { | |||
| internal RoleEditInfo(Color? color, bool? mentionable, bool? hoist, string name, | |||
| GuildPermissions? permissions) | |||
| { | |||
| Color = color; | |||
| Mentionable = mentionable; | |||
| Hoist = hoist; | |||
| Name = name; | |||
| Permissions = permissions; | |||
| } | |||
| public Color? Color { get; } | |||
| public bool? Mentionable { get; } | |||
| public bool? Hoist { get; } | |||
| public string Name { get; } | |||
| public GuildPermissions? Permissions { get; } | |||
| } | |||
| } | |||
| @@ -1,21 +0,0 @@ | |||
| namespace Discord.Rest | |||
| { | |||
| public struct RoleInfo | |||
| { | |||
| internal RoleInfo(Color? color, bool? mentionable, bool? hoist, string name, | |||
| GuildPermissions? permissions) | |||
| { | |||
| Color = color; | |||
| Mentionable = mentionable; | |||
| Hoist = hoist; | |||
| Name = name; | |||
| Permissions = permissions; | |||
| } | |||
| public Color? Color { get; } | |||
| public bool? Mentionable { get; } | |||
| public bool? Hoist { get; } | |||
| public string Name { get; } | |||
| public GuildPermissions? Permissions { get; } | |||
| } | |||
| } | |||
| @@ -7,7 +7,7 @@ namespace Discord.Rest | |||
| { | |||
| public class RoleUpdateAuditLogData : IAuditLogData | |||
| { | |||
| private RoleUpdateAuditLogData(ulong id, RoleInfo oldProps, RoleInfo newProps) | |||
| private RoleUpdateAuditLogData(ulong id, RoleEditInfo oldProps, RoleEditInfo newProps) | |||
| { | |||
| RoleId = id; | |||
| Before = oldProps; | |||
| @@ -49,14 +49,14 @@ namespace Discord.Rest | |||
| if (newPermissionsRaw.HasValue) | |||
| newPermissions = new GuildPermissions(newPermissionsRaw.Value); | |||
| var oldProps = new RoleInfo(oldColor, oldMentionable, oldHoist, oldName, oldPermissions); | |||
| var newProps = new RoleInfo(newColor, newMentionable, newHoist, newName, newPermissions); | |||
| var oldProps = new RoleEditInfo(oldColor, oldMentionable, oldHoist, oldName, oldPermissions); | |||
| var newProps = new RoleEditInfo(newColor, newMentionable, newHoist, newName, newPermissions); | |||
| return new RoleUpdateAuditLogData(entry.TargetId.Value, oldProps, newProps); | |||
| } | |||
| public ulong RoleId { get; } | |||
| public RoleInfo Before { get; } | |||
| public RoleInfo After { get; } | |||
| public RoleEditInfo Before { get; } | |||
| public RoleEditInfo After { get; } | |||
| } | |||
| } | |||
| @@ -1,8 +1,4 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| using Model = Discord.API.AuditLog; | |||
| using EntryModel = Discord.API.AuditLogEntry; | |||
| @@ -1,8 +1,4 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| using Model = Discord.API.AuditLog; | |||
| using EntryModel = Discord.API.AuditLogEntry; | |||
| @@ -1,10 +1,13 @@ | |||
| using System.Linq; | |||
| using System.Linq; | |||
| using Model = Discord.API.AuditLog; | |||
| using EntryModel = Discord.API.AuditLogEntry; | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents a REST-based audit log entry. | |||
| /// </summary> | |||
| public class RestAuditLogEntry : RestEntity<ulong>, IAuditLogEntry | |||
| { | |||
| private RestAuditLogEntry(BaseDiscordClient discord, Model fullLog, EntryModel model, IUser user) | |||
| @@ -162,7 +162,6 @@ namespace Discord.Rest | |||
| return RestUserMessage.Create(client, channel, client.CurrentUser, model); | |||
| } | |||
| #if FILESYSTEM | |||
| /// <exception cref="ArgumentException"> | |||
| /// <paramref name="filePath" /> is a zero-length string, contains only white space, or contains one or more | |||
| /// invalid characters as defined by <see cref="System.IO.Path.InvalidPathChars" />. | |||
| @@ -194,7 +193,7 @@ namespace Discord.Rest | |||
| using (var file = File.OpenRead(filePath)) | |||
| return await SendFileAsync(channel, client, file, filename, text, isTTS, embed, options).ConfigureAwait(false); | |||
| } | |||
| #endif | |||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | |||
| public static async Task<RestUserMessage> SendFileAsync(IMessageChannel channel, BaseDiscordClient client, | |||
| Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options) | |||
| @@ -204,6 +203,10 @@ namespace Discord.Rest | |||
| return RestUserMessage.Create(client, channel, client.CurrentUser, model); | |||
| } | |||
| public static Task DeleteMessageAsync(IMessageChannel channel, ulong messageId, BaseDiscordClient client, | |||
| RequestOptions options) | |||
| => MessageHelper.DeleteAsync(channel.Id, messageId, client, options); | |||
| public static async Task DeleteMessagesAsync(ITextChannel channel, BaseDiscordClient client, | |||
| IEnumerable<ulong> messageIds, RequestOptions options) | |||
| { | |||
| @@ -334,6 +337,16 @@ namespace Discord.Rest | |||
| return models.Select(x => RestWebhook.Create(client, channel, x)) | |||
| .ToImmutableArray(); | |||
| } | |||
| // Categories | |||
| public static async Task<ICategoryChannel> GetCategoryAsync(INestedChannel channel, BaseDiscordClient client, RequestOptions options) | |||
| { | |||
| // if no category id specified, return null | |||
| if (!channel.CategoryId.HasValue) | |||
| return null; | |||
| // CategoryId will contain a value here | |||
| var model = await client.ApiClient.GetChannelAsync(channel.CategoryId.Value, options).ConfigureAwait(false); | |||
| return RestCategoryChannel.Create(client, model) as ICategoryChannel; | |||
| } | |||
| //Helpers | |||
| private static IUser GetAuthor(BaseDiscordClient client, IGuild guild, UserModel model, ulong? webhookId) | |||
| @@ -345,10 +358,5 @@ namespace Discord.Rest | |||
| author = RestUser.Create(client, guild, model, webhookId); | |||
| return author; | |||
| } | |||
| public static bool IsNsfw(IChannel channel) | |||
| => IsNsfw(channel.Name); | |||
| public static bool IsNsfw(string channelName) => | |||
| channelName == "nsfw" || channelName.StartsWith("nsfw-"); | |||
| } | |||
| } | |||
| @@ -19,8 +19,7 @@ namespace Discord.Rest | |||
| /// <returns> | |||
| /// An awaitable Task containing the message sent to the channel. | |||
| /// </returns> | |||
| new Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null); | |||
| #if FILESYSTEM | |||
| new Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Sends a file to this message channel, with an optional caption. | |||
| /// </summary> | |||
| @@ -38,7 +37,6 @@ namespace Discord.Rest | |||
| /// An awaitable Task containing the message sent to the channel. | |||
| /// </returns> | |||
| new Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null); | |||
| #endif | |||
| /// <summary> | |||
| /// Sends a file to this message channel, with an optional caption. | |||
| /// </summary> | |||
| @@ -28,14 +28,6 @@ namespace Discord.Rest | |||
| // IGuildChannel | |||
| /// <inheritdoc /> | |||
| /// <exception cref="NotSupportedException">This method is not supported with category channels.</exception> | |||
| IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | |||
| => throw new NotSupportedException(); | |||
| /// <inheritdoc /> | |||
| /// <exception cref="NotSupportedException">This method is not supported with category channels.</exception> | |||
| Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||
| => throw new NotSupportedException(); | |||
| /// <inheritdoc /> | |||
| /// <exception cref="NotSupportedException">This method is not supported with category channels.</exception> | |||
| Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options) | |||
| => throw new NotSupportedException(); | |||
| /// <inheritdoc /> | |||
| @@ -6,6 +6,9 @@ using Model = Discord.API.Channel; | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents a generic REST-based channel. | |||
| /// </summary> | |||
| public class RestChannel : RestEntity<ulong>, IChannel, IUpdateable | |||
| { | |||
| /// <inheritdoc /> | |||
| @@ -26,6 +29,8 @@ namespace Discord.Rest | |||
| 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); | |||
| } | |||
| @@ -10,7 +10,7 @@ using Model = Discord.API.Channel; | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents a REST-based DM channel. | |||
| /// Represents a REST-based direct-message channel. | |||
| /// </summary> | |||
| [DebuggerDisplay(@"{DebuggerDisplay,nq}")] | |||
| public class RestDMChannel : RestChannel, IDMChannel, IRestPrivateChannel, IRestMessageChannel | |||
| @@ -74,17 +74,49 @@ namespace Discord.Rest | |||
| => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | |||
| /// <inheritdoc /> | |||
| public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | |||
| public Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||
| => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | |||
| #if FILESYSTEM | |||
| /// <inheritdoc /> | |||
| /// <exception cref="ArgumentException"> | |||
| /// <paramref name="filePath" /> is a zero-length string, contains only white space, or contains one or more | |||
| /// invalid characters as defined by <see cref="System.IO.Path.InvalidPathChars" />. | |||
| /// </exception> | |||
| /// <exception cref="ArgumentNullException"> | |||
| /// <paramref name="filePath" /> is <c>null</c>. | |||
| /// </exception> | |||
| /// <exception cref="PathTooLongException"> | |||
| /// 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. | |||
| /// </exception> | |||
| /// <exception cref="DirectoryNotFoundException"> | |||
| /// The specified path is invalid, (for example, it is on an unmapped drive). | |||
| /// </exception> | |||
| /// <exception cref="UnauthorizedAccessException"> | |||
| /// <paramref name="filePath" /> specified a directory.-or- The caller does not have the required permission. | |||
| /// </exception> | |||
| /// <exception cref="FileNotFoundException"> | |||
| /// The file specified in <paramref name="filePath" /> was not found. | |||
| /// </exception> | |||
| /// <exception cref="NotSupportedException"><paramref name="filePath" /> is in an invalid format.</exception> | |||
| /// <exception cref="IOException">An I/O error occurred while opening the file.</exception> | |||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | |||
| public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||
| => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, options); | |||
| #endif | |||
| /// <inheritdoc /> | |||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | |||
| public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||
| => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); | |||
| /// <inheritdoc /> | |||
| public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) | |||
| => ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); | |||
| /// <inheritdoc /> | |||
| public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) | |||
| => ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); | |||
| /// <inheritdoc /> | |||
| public Task TriggerTypingAsync(RequestOptions options = null) | |||
| => ChannelHelper.TriggerTypingAsync(this, Discord, options); | |||
| @@ -143,12 +175,9 @@ namespace Discord.Rest | |||
| async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) | |||
| => await GetPinnedMessagesAsync(options).ConfigureAwait(false); | |||
| #if FILESYSTEM | |||
| /// <inheritdoc /> | |||
| async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options) | |||
| => await SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false); | |||
| #endif | |||
| /// <inheritdoc /> | |||
| async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options) | |||
| => await SendFileAsync(stream, filename, text, isTTS, embed, options).ConfigureAwait(false); | |||
| /// <inheritdoc /> | |||
| @@ -83,11 +83,18 @@ namespace Discord.Rest | |||
| public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) | |||
| => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | |||
| /// <inheritdoc /> | |||
| public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) | |||
| => ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); | |||
| /// <inheritdoc /> | |||
| public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) | |||
| => ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); | |||
| /// <inheritdoc /> | |||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | |||
| public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||
| public Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||
| => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | |||
| #if FILESYSTEM | |||
| /// <inheritdoc /> | |||
| /// <exception cref="ArgumentException"> | |||
| /// <paramref name="filePath" /> is a zero-length string, contains only white space, or contains one or more | |||
| @@ -115,7 +122,6 @@ namespace Discord.Rest | |||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | |||
| public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||
| => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, options); | |||
| #endif | |||
| /// <inheritdoc /> | |||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | |||
| public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||
| @@ -168,10 +174,9 @@ namespace Discord.Rest | |||
| async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) | |||
| => await GetPinnedMessagesAsync(options).ConfigureAwait(false); | |||
| #if FILESYSTEM | |||
| async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options) | |||
| => await SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false); | |||
| #endif | |||
| async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options) | |||
| => await SendFileAsync(stream, filename, text, isTTS, embed, options).ConfigureAwait(false); | |||
| async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options) | |||
| @@ -8,7 +8,7 @@ using Model = Discord.API.Channel; | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents a private REST group channel. | |||
| /// Represents a private REST-based group channel. | |||
| /// </summary> | |||
| public class RestGuildChannel : RestChannel, IGuildChannel | |||
| { | |||
| @@ -23,8 +23,6 @@ namespace Discord.Rest | |||
| /// <inheritdoc /> | |||
| public int Position { get; private set; } | |||
| /// <inheritdoc /> | |||
| public ulong? CategoryId { get; private set; } | |||
| /// <inheritdoc /> | |||
| public ulong GuildId => Guild.Id; | |||
| internal RestGuildChannel(BaseDiscordClient discord, IGuild guild, ulong id) | |||
| @@ -43,7 +41,6 @@ namespace Discord.Rest | |||
| case ChannelType.Category: | |||
| return RestCategoryChannel.Create(discord, guild, model); | |||
| default: | |||
| // TODO: Channel categories | |||
| return new RestGuildChannel(discord, guild, model.Id); | |||
| } | |||
| } | |||
| @@ -75,14 +72,6 @@ namespace Discord.Rest | |||
| public Task DeleteAsync(RequestOptions options = null) | |||
| => ChannelHelper.DeleteAsync(this, Discord, options); | |||
| /// <inheritdoc /> | |||
| public async Task<ICategoryChannel> GetCategoryAsync() | |||
| { | |||
| if (CategoryId.HasValue) | |||
| return (await Guild.GetChannelAsync(CategoryId.Value).ConfigureAwait(false)) as ICategoryChannel; | |||
| return null; | |||
| } | |||
| public OverwritePermissions? GetPermissionOverwrite(IUser user) | |||
| { | |||
| for (int i = 0; i < _overwrites.Length; i++) | |||
| @@ -8,15 +8,22 @@ using Model = Discord.API.Channel; | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents a REST-based channel in a guild that can send and receive messages. | |||
| /// </summary> | |||
| [DebuggerDisplay(@"{DebuggerDisplay,nq}")] | |||
| public class RestTextChannel : RestGuildChannel, IRestMessageChannel, ITextChannel | |||
| { | |||
| /// <inheritdoc /> | |||
| public string Topic { get; private set; } | |||
| public ulong? CategoryId { get; private set; } | |||
| /// <inheritdoc /> | |||
| public string Mention => MentionUtils.MentionChannel(Id); | |||
| private bool _nsfw; | |||
| public bool IsNsfw => _nsfw || ChannelHelper.IsNsfw(this); | |||
| /// <inheritdoc /> | |||
| public bool IsNsfw => _nsfw; | |||
| internal RestTextChannel(BaseDiscordClient discord, IGuild guild, ulong id) | |||
| : base(discord, guild, id) | |||
| @@ -31,11 +38,12 @@ namespace Discord.Rest | |||
| internal override void Update(Model model) | |||
| { | |||
| base.Update(model); | |||
| CategoryId = model.CategoryId; | |||
| Topic = model.Topic.Value; | |||
| _nsfw = model.Nsfw.GetValueOrDefault(); | |||
| } | |||
| /// <inheritdoc /> | |||
| public async Task ModifyAsync(Action<TextChannelProperties> func, RequestOptions options = null) | |||
| { | |||
| var model = await ChannelHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); | |||
| @@ -47,36 +55,80 @@ namespace Discord.Rest | |||
| public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(RequestOptions options = null) | |||
| => ChannelHelper.GetUsersAsync(this, Guild, Discord, null, null, options); | |||
| /// <inheritdoc /> | |||
| public Task<RestMessage> GetMessageAsync(ulong id, RequestOptions options = null) | |||
| => ChannelHelper.GetMessageAsync(this, Discord, id, options); | |||
| /// <inheritdoc /> | |||
| public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) | |||
| => ChannelHelper.GetMessagesAsync(this, Discord, null, Direction.Before, limit, options); | |||
| /// <inheritdoc /> | |||
| public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) | |||
| => ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit, options); | |||
| /// <inheritdoc /> | |||
| public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) | |||
| => ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit, options); | |||
| /// <inheritdoc /> | |||
| public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) | |||
| => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | |||
| public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||
| /// <inheritdoc /> | |||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | |||
| public Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||
| => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | |||
| #if FILESYSTEM | |||
| /// <inheritdoc /> | |||
| /// <exception cref="ArgumentException"> | |||
| /// <paramref name="filePath" /> is a zero-length string, contains only white space, or contains one or more | |||
| /// invalid characters as defined by <see cref="System.IO.Path.InvalidPathChars" />. | |||
| /// </exception> | |||
| /// <exception cref="ArgumentNullException"> | |||
| /// <paramref name="filePath" /> is <c>null</c>. | |||
| /// </exception> | |||
| /// <exception cref="PathTooLongException"> | |||
| /// 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. | |||
| /// </exception> | |||
| /// <exception cref="DirectoryNotFoundException"> | |||
| /// The specified path is invalid, (for example, it is on an unmapped drive). | |||
| /// </exception> | |||
| /// <exception cref="UnauthorizedAccessException"> | |||
| /// <paramref name="filePath" /> specified a directory.-or- The caller does not have the required permission. | |||
| /// </exception> | |||
| /// <exception cref="FileNotFoundException"> | |||
| /// The file specified in <paramref name="filePath" /> was not found. | |||
| /// </exception> | |||
| /// <exception cref="NotSupportedException"><paramref name="filePath" /> is in an invalid format.</exception> | |||
| /// <exception cref="IOException">An I/O error occurred while opening the file.</exception> | |||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | |||
| public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||
| => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, options); | |||
| #endif | |||
| /// <inheritdoc /> | |||
| /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> | |||
| public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||
| => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); | |||
| /// <inheritdoc /> | |||
| public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) | |||
| => ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); | |||
| /// <inheritdoc /> | |||
| public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) | |||
| => ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); | |||
| /// <inheritdoc /> | |||
| public Task DeleteMessagesAsync(IEnumerable<IMessage> messages, RequestOptions options = null) | |||
| => ChannelHelper.DeleteMessagesAsync(this, Discord, messages.Select(x => x.Id), options); | |||
| /// <inheritdoc /> | |||
| public Task DeleteMessagesAsync(IEnumerable<ulong> messageIds, RequestOptions options = null) | |||
| => ChannelHelper.DeleteMessagesAsync(this, Discord, messageIds, options); | |||
| /// <inheritdoc /> | |||
| public Task TriggerTypingAsync(RequestOptions options = null) | |||
| => ChannelHelper.TriggerTypingAsync(this, Discord, options); | |||
| public IDisposable EnterTypingState(RequestOptions options = null) | |||
| => ChannelHelper.EnterTypingState(this, Discord, options); | |||
| public Task<RestWebhook> CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null) | |||
| => ChannelHelper.CreateWebhookAsync(this, Discord, name, avatar, options); | |||
| public Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null) | |||
| @@ -84,17 +136,24 @@ namespace Discord.Rest | |||
| public Task<IReadOnlyCollection<RestWebhook>> GetWebhooksAsync(RequestOptions options = null) | |||
| => ChannelHelper.GetWebhooksAsync(this, Discord, options); | |||
| public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null) | |||
| => ChannelHelper.GetCategoryAsync(this, Discord, options); | |||
| private string DebuggerDisplay => $"{Name} ({Id}, Text)"; | |||
| //ITextChannel | |||
| /// <inheritdoc /> | |||
| async Task<IWebhook> ITextChannel.CreateWebhookAsync(string name, Stream avatar, RequestOptions options) | |||
| => await CreateWebhookAsync(name, avatar, options).ConfigureAwait(false); | |||
| /// <inheritdoc /> | |||
| async Task<IWebhook> ITextChannel.GetWebhookAsync(ulong id, RequestOptions options) | |||
| => await GetWebhookAsync(id, options).ConfigureAwait(false); | |||
| /// <inheritdoc /> | |||
| async Task<IReadOnlyCollection<IWebhook>> ITextChannel.GetWebhooksAsync(RequestOptions options) | |||
| => await GetWebhooksAsync(options).ConfigureAwait(false); | |||
| //IMessageChannel | |||
| /// <inheritdoc /> | |||
| async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) | |||
| { | |||
| if (mode == CacheMode.AllowDownload) | |||
| @@ -102,6 +161,7 @@ namespace Discord.Rest | |||
| else | |||
| return null; | |||
| } | |||
| /// <inheritdoc /> | |||
| IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options) | |||
| { | |||
| if (mode == CacheMode.AllowDownload) | |||
| @@ -109,6 +169,8 @@ namespace Discord.Rest | |||
| else | |||
| return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>(); | |||
| } | |||
| /// <inheritdoc /> | |||
| IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options) | |||
| { | |||
| if (mode == CacheMode.AllowDownload) | |||
| @@ -116,6 +178,7 @@ namespace Discord.Rest | |||
| else | |||
| return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>(); | |||
| } | |||
| /// <inheritdoc /> | |||
| IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options) | |||
| { | |||
| if (mode == CacheMode.AllowDownload) | |||
| @@ -123,21 +186,26 @@ namespace Discord.Rest | |||
| else | |||
| return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>(); | |||
| } | |||
| /// <inheritdoc /> | |||
| async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) | |||
| => await GetPinnedMessagesAsync(options).ConfigureAwait(false); | |||
| #if FILESYSTEM | |||
| /// <inheritdoc /> | |||
| async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options) | |||
| => await SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false); | |||
| #endif | |||
| /// <inheritdoc /> | |||
| async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options) | |||
| => await SendFileAsync(stream, filename, text, isTTS, embed, options).ConfigureAwait(false); | |||
| /// <inheritdoc /> | |||
| async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options) | |||
| => await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false); | |||
| /// <inheritdoc /> | |||
| IDisposable IMessageChannel.EnterTypingState(RequestOptions options) | |||
| => EnterTypingState(options); | |||
| //IGuildChannel | |||
| /// <inheritdoc /> | |||
| async Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||
| { | |||
| if (mode == CacheMode.AllowDownload) | |||
| @@ -145,6 +213,7 @@ namespace Discord.Rest | |||
| else | |||
| return null; | |||
| } | |||
| /// <inheritdoc /> | |||
| IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | |||
| { | |||
| if (mode == CacheMode.AllowDownload) | |||
| @@ -154,6 +223,7 @@ namespace Discord.Rest | |||
| } | |||
| //IChannel | |||
| /// <inheritdoc /> | |||
| async Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||
| { | |||
| if (mode == CacheMode.AllowDownload) | |||
| @@ -161,6 +231,7 @@ namespace Discord.Rest | |||
| else | |||
| return null; | |||
| } | |||
| /// <inheritdoc /> | |||
| IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | |||
| { | |||
| if (mode == CacheMode.AllowDownload) | |||
| @@ -168,5 +239,13 @@ namespace Discord.Rest | |||
| else | |||
| return AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); | |||
| } | |||
| // INestedChannel | |||
| async Task<ICategoryChannel> INestedChannel.GetCategoryAsync(CacheMode mode, RequestOptions options) | |||
| { | |||
| if (CategoryId.HasValue && mode == CacheMode.AllowDownload) | |||
| return (await Guild.GetChannelAsync(CategoryId.Value, mode, options).ConfigureAwait(false)) as ICategoryChannel; | |||
| return null; | |||
| } | |||
| } | |||
| } | |||
| @@ -8,11 +8,17 @@ using Model = Discord.API.Channel; | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents a REST-based voice channel in a guild. | |||
| /// </summary> | |||
| [DebuggerDisplay(@"{DebuggerDisplay,nq}")] | |||
| public class RestVoiceChannel : RestGuildChannel, IVoiceChannel, IRestAudioChannel | |||
| { | |||
| /// <inheritdoc /> | |||
| public int Bitrate { get; private set; } | |||
| /// <inheritdoc /> | |||
| public int? UserLimit { get; private set; } | |||
| public ulong? CategoryId { get; private set; } | |||
| internal RestVoiceChannel(BaseDiscordClient discord, IGuild guild, ulong id) | |||
| : base(discord, guild, id) | |||
| @@ -24,20 +30,25 @@ namespace Discord.Rest | |||
| entity.Update(model); | |||
| return entity; | |||
| } | |||
| /// <inheritdoc /> | |||
| internal override void Update(Model model) | |||
| { | |||
| base.Update(model); | |||
| CategoryId = model.CategoryId; | |||
| Bitrate = model.Bitrate.Value; | |||
| UserLimit = model.UserLimit.Value != 0 ? model.UserLimit.Value : (int?)null; | |||
| } | |||
| /// <inheritdoc /> | |||
| public async Task ModifyAsync(Action<VoiceChannelProperties> func, RequestOptions options = null) | |||
| { | |||
| var model = await ChannelHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); | |||
| Update(model); | |||
| } | |||
| public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null) | |||
| => ChannelHelper.GetCategoryAsync(this, Discord, options); | |||
| private string DebuggerDisplay => $"{Name} ({Id}, Voice)"; | |||
| //IAudioChannel | |||
| @@ -46,9 +57,19 @@ namespace Discord.Rest | |||
| Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction) => throw new NotSupportedException(); | |||
| //IGuildChannel | |||
| /// <inheritdoc /> | |||
| Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IGuildUser>(null); | |||
| /// <inheritdoc /> | |||
| IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | |||
| => AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); | |||
| // INestedChannel | |||
| async Task<ICategoryChannel> INestedChannel.GetCategoryAsync(CacheMode mode, RequestOptions options) | |||
| { | |||
| if (CategoryId.HasValue && mode == CacheMode.AllowDownload) | |||
| return (await Guild.GetChannelAsync(CategoryId.Value, mode, options).ConfigureAwait(false)) as ICategoryChannel; | |||
| return null; | |||
| } | |||
| } | |||
| } | |||
| @@ -33,15 +33,19 @@ namespace Discord.Rest | |||
| public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) | |||
| => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | |||
| public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS, Embed embed = null, RequestOptions options = null) | |||
| public Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||
| => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | |||
| #if FILESYSTEM | |||
| public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS, Embed embed = null, RequestOptions options = null) | |||
| public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||
| => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, options); | |||
| #endif | |||
| public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed = null, RequestOptions options = null) | |||
| public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||
| => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); | |||
| public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) | |||
| => ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); | |||
| public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) | |||
| => ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); | |||
| public Task TriggerTypingAsync(RequestOptions options = null) | |||
| => ChannelHelper.TriggerTypingAsync(this, Discord, options); | |||
| public IDisposable EnterTypingState(RequestOptions options = null) | |||
| @@ -81,10 +85,9 @@ namespace Discord.Rest | |||
| async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) | |||
| => await GetPinnedMessagesAsync(options).ConfigureAwait(false); | |||
| #if FILESYSTEM | |||
| async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options) | |||
| => await SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false); | |||
| #endif | |||
| => await SendFileAsync(filePath, text, isTTS, embed, options); | |||
| async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options) | |||
| => await SendFileAsync(stream, filename, text, isTTS, embed, options).ConfigureAwait(false); | |||
| async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options) | |||
| @@ -147,21 +147,37 @@ namespace Discord.Rest | |||
| } | |||
| /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | |||
| public static async Task<RestTextChannel> CreateTextChannelAsync(IGuild guild, BaseDiscordClient client, | |||
| string name, RequestOptions options) | |||
| string name, RequestOptions options, Action<TextChannelProperties> func = null) | |||
| { | |||
| if (name == null) throw new ArgumentNullException(nameof(name)); | |||
| var args = new CreateGuildChannelParams(name, ChannelType.Text); | |||
| var props = new TextChannelProperties(); | |||
| func?.Invoke(props); | |||
| var args = new CreateGuildChannelParams(name, ChannelType.Text) | |||
| { | |||
| CategoryId = props.CategoryId, | |||
| Topic = props.Topic, | |||
| IsNsfw = props.IsNsfw | |||
| }; | |||
| var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | |||
| return RestTextChannel.Create(client, guild, model); | |||
| } | |||
| /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | |||
| public static async Task<RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client, | |||
| string name, RequestOptions options) | |||
| string name, RequestOptions options, Action<VoiceChannelProperties> func = null) | |||
| { | |||
| if (name == null) throw new ArgumentNullException(nameof(name)); | |||
| var args = new CreateGuildChannelParams(name, ChannelType.Voice); | |||
| var props = new VoiceChannelProperties(); | |||
| func?.Invoke(props); | |||
| var args = new CreateGuildChannelParams(name, ChannelType.Voice) | |||
| { | |||
| CategoryId = props.CategoryId, | |||
| Bitrate = props.Bitrate, | |||
| UserLimit = props.UserLimit | |||
| }; | |||
| var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | |||
| return RestVoiceChannel.Create(client, guild, model); | |||
| } | |||
| @@ -3,9 +3,18 @@ using Model = Discord.API.Ban; | |||
| namespace Discord.Rest | |||
| { | |||
| /// <summary> | |||
| /// Represents a REST-based ban object. | |||
| /// </summary> | |||
| [DebuggerDisplay(@"{DebuggerDisplay,nq}")] | |||
| public class RestBan : IBan | |||
| { | |||
| /// <summary> | |||
| /// Gets the banned user. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A generic <see cref="RestUser"/> object that was banned. | |||
| /// </returns> | |||
| public RestUser User { get; } | |||
| /// <inheritdoc /> | |||
| public string Reason { get; } | |||
| @@ -20,6 +29,12 @@ namespace Discord.Rest | |||
| return new RestBan(RestUser.Create(client, model.User), model.Reason); | |||
| } | |||
| /// <summary> | |||
| /// Gets the name of the banned user. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A string containing the name of the user that was banned. | |||
| /// </returns> | |||
| public override string ToString() => User.ToString(); | |||
| private string DebuggerDisplay => $"{User}: {Reason}"; | |||
| @@ -258,10 +258,10 @@ namespace Discord.Rest | |||
| } | |||
| return null; | |||
| } | |||
| public Task<RestTextChannel> CreateTextChannelAsync(string name, RequestOptions options = null) | |||
| => GuildHelper.CreateTextChannelAsync(this, Discord, name, options); | |||
| public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null) | |||
| => GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options); | |||
| public Task<RestTextChannel> CreateTextChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null) | |||
| => GuildHelper.CreateTextChannelAsync(this, Discord, name, options, func); | |||
| public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func = null, RequestOptions options = null) | |||
| => GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options, func); | |||
| public Task<RestCategoryChannel> CreateCategoryChannelAsync(string name, RequestOptions options = null) | |||
| => GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options); | |||
| @@ -448,11 +448,11 @@ namespace Discord.Rest | |||
| return null; | |||
| } | |||
| /// <inheritdoc /> | |||
| async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, RequestOptions options) | |||
| => await CreateTextChannelAsync(name, options).ConfigureAwait(false); | |||
| async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, Action<TextChannelProperties> func, RequestOptions options) | |||
| => await CreateTextChannelAsync(name, func, options).ConfigureAwait(false); | |||
| /// <inheritdoc /> | |||
| async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) | |||
| => await CreateVoiceChannelAsync(name, options).ConfigureAwait(false); | |||
| async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func, RequestOptions options) | |||
| => await CreateVoiceChannelAsync(name, func, options).ConfigureAwait(false); | |||
| /// <inheritdoc /> | |||
| async Task<ICategoryChannel> IGuild.CreateCategoryAsync(string name, RequestOptions options) | |||
| => await CreateCategoryChannelAsync(name, options).ConfigureAwait(false); | |||
| @@ -27,10 +27,12 @@ namespace Discord.Rest | |||
| }; | |||
| return await client.ApiClient.ModifyMessageAsync(msg.Channel.Id, msg.Id, apiArgs, options).ConfigureAwait(false); | |||
| } | |||
| public static async Task DeleteAsync(IMessage msg, BaseDiscordClient client, | |||
| public static Task DeleteAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) | |||
| => DeleteAsync(msg.Channel.Id, msg.Id, client, options); | |||
| public static async Task DeleteAsync(ulong channelId, ulong msgId, BaseDiscordClient client, | |||
| RequestOptions options) | |||
| { | |||
| await client.ApiClient.DeleteMessageAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false); | |||
| await client.ApiClient.DeleteMessageAsync(channelId, msgId, options).ConfigureAwait(false); | |||
| } | |||
| public static async Task AddReactionAsync(IMessage msg, IEmote emote, BaseDiscordClient client, RequestOptions options) | |||
| @@ -48,13 +50,38 @@ namespace Discord.Rest | |||
| await client.ApiClient.RemoveAllReactionsAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false); | |||
| } | |||
| public static async Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IMessage msg, IEmote emote, | |||
| Action<GetReactionUsersParams> func, BaseDiscordClient client, RequestOptions options) | |||
| public static IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IMessage msg, IEmote emote, | |||
| int? limit, BaseDiscordClient client, RequestOptions options) | |||
| { | |||
| var args = new GetReactionUsersParams(); | |||
| func(args); | |||
| string emoji = (emote is Emote e ? $"{e.Name}:{e.Id}" : emote.Name); | |||
| return (await client.ApiClient.GetReactionUsersAsync(msg.Channel.Id, msg.Id, emoji, args, options).ConfigureAwait(false)).Select(u => RestUser.Create(client, u)).ToImmutableArray(); | |||
| Preconditions.NotNull(emote, nameof(emote)); | |||
| var emoji = (emote is Emote e ? $"{e.Name}:{e.Id}" : emote.Name); | |||
| return new PagedAsyncEnumerable<IUser>( | |||
| DiscordConfig.MaxUserReactionsPerBatch, | |||
| async (info, ct) => | |||
| { | |||
| var args = new GetReactionUsersParams | |||
| { | |||
| Limit = info.PageSize | |||
| }; | |||
| if (info.Position != null) | |||
| args.AfterUserId = info.Position.Value; | |||
| var models = await client.ApiClient.GetReactionUsersAsync(msg.Channel.Id, msg.Id, emoji, args, options).ConfigureAwait(false); | |||
| return models.Select(x => RestUser.Create(client, x)).ToImmutableArray(); | |||
| }, | |||
| nextPage: (info, lastPage) => | |||
| { | |||
| if (lastPage.Count != DiscordConfig.MaxUsersPerBatch) | |||
| return false; | |||
| info.Position = lastPage.Max(x => x.Id); | |||
| return true; | |||
| }, | |||
| count: limit | |||
| ); | |||
| } | |||
| public static async Task PinAsync(IMessage msg, BaseDiscordClient client, | |||
| @@ -151,9 +151,9 @@ namespace Discord.Rest | |||
| public Task RemoveAllReactionsAsync(RequestOptions options = null) | |||
| => MessageHelper.RemoveAllReactionsAsync(this, Discord, options); | |||
| /// <inheritdoc /> | |||
| public Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit = 100, ulong? afterUserId = null, RequestOptions options = null) | |||
| => MessageHelper.GetReactionUsersAsync(this, emote, x => { x.Limit = limit; x.AfterUserId = afterUserId ?? Optional.Create<ulong>(); }, Discord, options); | |||
| public IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null) | |||
| => MessageHelper.GetReactionUsersAsync(this, emote, limit, Discord, options); | |||
| /// <inheritdoc /> | |||
| public Task PinAsync(RequestOptions options = null) | |||
| => MessageHelper.PinAsync(this, Discord, options); | |||
| @@ -1,4 +1,4 @@ | |||
| using Discord.API; | |||
| using Discord.API; | |||
| using Newtonsoft.Json; | |||
| using Newtonsoft.Json.Serialization; | |||
| using System; | |||
| @@ -25,7 +25,6 @@ namespace Discord.Net.Converters | |||
| if (converter != null) | |||
| { | |||
| property.Converter = converter; | |||
| property.MemberConverter = converter; | |||
| } | |||
| } | |||
| else | |||
| @@ -230,7 +230,7 @@ namespace Discord.Net.Queue | |||
| #endif | |||
| } | |||
| var now = DateTimeUtils.ToUnixSeconds(DateTimeOffset.UtcNow); | |||
| var now = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); | |||
| DateTimeOffset? resetTick = null; | |||
| //Using X-RateLimit-Remaining causes a race condition | |||
| @@ -21,7 +21,7 @@ namespace Discord.Net | |||
| Remaining = headers.TryGetValue("X-RateLimit-Remaining", out temp) && | |||
| int.TryParse(temp, out var remaining) ? remaining : (int?)null; | |||
| Reset = headers.TryGetValue("X-RateLimit-Reset", out temp) && | |||
| int.TryParse(temp, out var reset) ? DateTimeUtils.FromUnixSeconds(reset) : (DateTimeOffset?)null; | |||
| int.TryParse(temp, out var reset) ? DateTimeOffset.FromUnixTimeSeconds(reset) : (DateTimeOffset?)null; | |||
| RetryAfter = headers.TryGetValue("Retry-After", out temp) && | |||
| int.TryParse(temp, out var retryAfter) ? retryAfter : (int?)null; | |||
| Lag = headers.TryGetValue("Date", out temp) && | |||
| @@ -1,4 +1,4 @@ | |||
| #pragma warning disable CS1591 | |||
| #pragma warning disable CS1591 | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API.Gateway | |||
| @@ -9,6 +9,10 @@ namespace Discord.API.Gateway | |||
| public ulong UserId { get; set; } | |||
| [JsonProperty("channel_id")] | |||
| public ulong ChannelId { get; set; } | |||
| [JsonProperty("guild_id")] | |||
| public ulong GuildId { get; set; } | |||
| [JsonProperty("member")] | |||
| public GuildMember Member { get; set; } | |||
| [JsonProperty("timestamp")] | |||
| public int Timestamp { get; set; } | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API.Voice | |||
| { | |||
| internal class HelloEvent | |||
| { | |||
| [JsonProperty("heartbeat_interval")] | |||
| public int HeartbeatInterval { get; set; } | |||
| } | |||
| } | |||
| @@ -1,5 +1,6 @@ | |||
| #pragma warning disable CS1591 | |||
| #pragma warning disable CS1591 | |||
| using Newtonsoft.Json; | |||
| using System; | |||
| namespace Discord.API.Voice | |||
| { | |||
| @@ -14,6 +15,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)] | |||
| public int HeartbeatInterval { get; set; } | |||
| } | |||
| } | |||
| @@ -1,4 +1,4 @@ | |||
| #pragma warning disable CS1591 | |||
| #pragma warning disable CS1591 | |||
| namespace Discord.API.Voice | |||
| { | |||
| internal enum VoiceOpCode : byte | |||
| @@ -11,11 +11,19 @@ namespace Discord.API.Voice | |||
| Ready = 2, | |||
| /// <summary> C→S - Used to keep the connection alive and measure latency. </summary> | |||
| Heartbeat = 3, | |||
| /// <summary> C←S - Used to reply to a client's heartbeat. </summary> | |||
| HeartbeatAck = 3, | |||
| /// <summary> C←S - Used to provide an encryption key to the client. </summary> | |||
| SessionDescription = 4, | |||
| /// <summary> C↔S - Used to inform that a certain user is speaking. </summary> | |||
| Speaking = 5 | |||
| Speaking = 5, | |||
| /// <summary> C←S - Used to reply to a client's heartbeat. </summary> | |||
| HeartbeatAck = 6, | |||
| /// <summary> C→S - Used to resume a connection. </summary> | |||
| Resume = 7, | |||
| /// <summary> C←S - Used to inform the client the heartbeat interval. </summary> | |||
| Hello = 8, | |||
| /// <summary> C←S - Used to acknowledge a resumed connection. </summary> | |||
| Resumed = 9, | |||
| /// <summary> C←S - Used to notify that a client has disconnected. </summary> | |||
| ClientDisconnect = 13, | |||
| } | |||
| } | |||