From 8406bd8f73de926630a921cac2bee451198af0e4 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sat, 27 Aug 2016 22:16:51 -0400 Subject: [PATCH] Update docs to reflect IMessage->IUserMessage As changed in 23a0316252ffda6cea56dcafed38f21a0116fb3b --- docs/guides/commands.md | 6 +++--- docs/guides/samples.md | 2 +- docs/guides/samples/command_handler.cs | 5 ++++- docs/guides/samples/faq/send_message.cs | 3 +-- docs/guides/samples/groups.cs | 4 ++-- docs/guides/samples/joining_audio.cs | 2 +- docs/guides/samples/module.cs | 6 +++--- docs/guides/samples/require_context.cs | 4 ++-- docs/guides/samples/require_owner.cs | 2 +- docs/guides/samples/require_permission.cs | 2 +- docs/guides/samples/typereader.cs | 2 +- docs/migrating.md | 2 +- 12 files changed, 21 insertions(+), 19 deletions(-) diff --git a/docs/guides/commands.md b/docs/guides/commands.md index 04d027f69..ef2a15f85 100644 --- a/docs/guides/commands.md +++ b/docs/guides/commands.md @@ -21,7 +21,7 @@ attributes. All commands belong to a Module. (See the below section for creating modules.) All commands in a module must be defined as an `Task`, with at least one argument, -being the @Discord.IMessage representing the context of the command. +being the @Discord.IUserMessage representing the context of the command. To add parameters to your command, add additional arguments to the `Task` of the command. You are _not_ required to accept all arguments as `String`, they will be automatically parsed @@ -149,13 +149,13 @@ By default, the following Types are supported arguments: - IUser/IGuildUser - IChannel/IGuildChannel/ITextChannel/IVoiceChannel/IGroupChannel - IRole -- IMessage +- IMessage/IUserMessage ### Creating a Type Readers To create a TypeReader, create a new class that imports @Discord and @Discord.Commands . Ensure your class inherits from @Discord.Commands.TypeReader -Next, satisfy the `TypeReader` class by overriding `Task Read(IMessage context, string input)`. +Next, satisfy the `TypeReader` class by overriding `Task Read(IUserMessage context, string input)`. >[!NOTE] >In many cases, Visual Studio can fill this in for you, using the "Implement Abstract Class" IntelliSense hint. diff --git a/docs/guides/samples.md b/docs/guides/samples.md index b03e709de..dd0d7164e 100644 --- a/docs/guides/samples.md +++ b/docs/guides/samples.md @@ -19,6 +19,6 @@ title: Samples [!code-csharp[Message to Channel](samples/faq/send_message.cs)] -#### Retrieving an IGuild from an IMessage +#### Retrieving an IGuild from an IUserMessage [!code-csharp[Message to Guild](samples/faq/guild_from_message.cs)] \ No newline at end of file diff --git a/docs/guides/samples/command_handler.cs b/docs/guides/samples/command_handler.cs index a062dcc37..020470427 100644 --- a/docs/guides/samples/command_handler.cs +++ b/docs/guides/samples/command_handler.cs @@ -33,8 +33,11 @@ public class Program // Discover all of the commands in this assembly and load them. await commands.LoadAssembly(Assembly.GetEntryAssembly()); } - public async Task HandleCommand(IMessage msg) + public async Task HandleCommand(IMessage paramMessage) { + // Cast paramMessage to an IUserMessage, return if the message was a System message. + var msg = paramMessage as IUserMessage; + if (msg == null) return; // Internal integer, marks where the command begins int argPos = 0; // Get the current user (used for Mention parsing) diff --git a/docs/guides/samples/faq/send_message.cs b/docs/guides/samples/faq/send_message.cs index 3f92afc76..d24c1cf6b 100644 --- a/docs/guides/samples/faq/send_message.cs +++ b/docs/guides/samples/faq/send_message.cs @@ -2,6 +2,5 @@ public async Task SendMessageToChannel(ulong ChannelId) { var channel = await _client.GetChannelAsync(ChannelId) as IMessageChannel; await channel?.SendMessageAsync("aaaaaaaaahhh!!!") - /* ^ This question mark is used to indicate that 'channel' may sometimes be null, and - in cases that it is null, we will do nothing here. */ + /* ^ This question mark is used to indicate that 'channel' may sometimes be null, and in cases that it is null, we will do nothing here. */ } \ No newline at end of file diff --git a/docs/guides/samples/groups.cs b/docs/guides/samples/groups.cs index 4bcedf82b..4967af608 100644 --- a/docs/guides/samples/groups.cs +++ b/docs/guides/samples/groups.cs @@ -6,10 +6,10 @@ public class AdminModule { // ~admin mod ban foxbot#0282 [Command("ban")] - public async Task Ban(IMessage msg, IGuildUser user) { } + public async Task Ban(IUserMessage msg, IGuildUser user) { } } // ~admin clean 100 [Command("clean")] - public async Task Clean(IMessage msg, int count = 100) { } + public async Task Clean(IUserMessage msg, int count = 100) { } } \ No newline at end of file diff --git a/docs/guides/samples/joining_audio.cs b/docs/guides/samples/joining_audio.cs index 7fd6d1b26..52248757f 100644 --- a/docs/guides/samples/joining_audio.cs +++ b/docs/guides/samples/joining_audio.cs @@ -3,7 +3,7 @@ private IAudioClient _audio; // Create a Join command, that will join the parameter or the user's current voice channel [Command("join")] -public async Task JoinChannel(IMessage msg, +public async Task JoinChannel(IUserMessage msg, IVoiceChannel channel = null) { // Get the audio channel diff --git a/docs/guides/samples/module.cs b/docs/guides/samples/module.cs index 1330c201c..9de35aa6e 100644 --- a/docs/guides/samples/module.cs +++ b/docs/guides/samples/module.cs @@ -7,7 +7,7 @@ public class Info { // ~say hello -> hello [Command("say"), Description("Echos a message.")] - public async Task Say(IMessage msg, + public async Task Say(IUserMessage msg, [Unparsed, Description("The text to echo")] string echo) { await msg.Channel.SendMessageAsync(echo); @@ -20,7 +20,7 @@ public class Sample { // ~sample square 20 -> [Command("square"), Description("Squares a number.")] - public async Task Square(IMessage msg, + public async Task Square(IUserMessage msg, [Description("The number to square.")] int num) { await msg.Channel.SendMessageAsync($"{num}^2 = {Math.Pow(num, 2)}"); @@ -34,7 +34,7 @@ public class Sample // ~sample whois 96642168176807936 --> Khionu#8708 [Command("userinfo"), Description("Returns info about the current user, or the user parameter, if one passed.")] [Alias("user", "whois")] - public async Task UserInfo(IMessage msg, + public async Task UserInfo(IUserMessage msg, [Description("The (optional) user to get info for")] IUser user = null) { var userInfo = user ?? await Program.Client.GetCurrentUserAsync(); diff --git a/docs/guides/samples/require_context.cs b/docs/guides/samples/require_context.cs index c9d5e5672..ee02db8e8 100644 --- a/docs/guides/samples/require_context.cs +++ b/docs/guides/samples/require_context.cs @@ -3,9 +3,9 @@ public class InfoModule { // Constrain this command to Guilds [RequireContext(ContextType.Guild)] - public async Task Whois(IMessage msg, IGuildUser user) { } + public async Task Whois(IUserMessage msg, IGuildUser user) { } // Constrain this command to either Guilds or DMs [RequireContext(ContextType.Guild | ContextType.DM)] - public async Task Info(IMessage msg) { } + public async Task Info(IUserMessage msg) { } } \ No newline at end of file diff --git a/docs/guides/samples/require_owner.cs b/docs/guides/samples/require_owner.cs index 90f07819f..ede18d25f 100644 --- a/docs/guides/samples/require_owner.cs +++ b/docs/guides/samples/require_owner.cs @@ -8,7 +8,7 @@ public class RequireOwnerAttribute : PreconditionAttribute public readonly ulong OwnerId = 66078337084162048; // Override the CheckPermissions method - public override Task CheckPermissions(IMessage context, Command executingCommand, object moduleInstance) + public override Task CheckPermissions(IUserMessage context, Command executingCommand, object moduleInstance) { // If the author of the message is '66078337084162048', return success; otherwise fail. return Task.FromResult(context.Author.Id == OwnerId ? PreconditionResult.FromSuccess() : PreconditionResult.FromError("You must be the owner of the bot.")); diff --git a/docs/guides/samples/require_permission.cs b/docs/guides/samples/require_permission.cs index 77666d470..136b80088 100644 --- a/docs/guides/samples/require_permission.cs +++ b/docs/guides/samples/require_permission.cs @@ -3,5 +3,5 @@ public class AdminModule { [Command("ban")] [RequirePermission(GuildPermission.BanMembers)] - public async Task Ban(IMessage msg) { } + public async Task Ban(IUserMessage msg) { } } \ No newline at end of file diff --git a/docs/guides/samples/typereader.cs b/docs/guides/samples/typereader.cs index 73dd674cb..c5b958283 100644 --- a/docs/guides/samples/typereader.cs +++ b/docs/guides/samples/typereader.cs @@ -3,7 +3,7 @@ using Discord.Commands; public class BooleanTypeReader : TypeReader { - public override Task Read(IMessage context, string input) + public override Task Read(IUserMessage context, string input) { bool result; if (bool.TryParse(input, out result)) diff --git a/docs/migrating.md b/docs/migrating.md index 5abceb46c..f73d5e8c0 100644 --- a/docs/migrating.md +++ b/docs/migrating.md @@ -36,7 +36,7 @@ Below is a table that compares most common 0.9 entities to their 1.0 counterpart | ChannelType.Voice | @Discord.IVoiceChannel | This applies only to Voice Channels in Guilds | User | @Discord.IGuildUser | This applies only to users belonging to a Guild* | Profile | @Discord.ISelfUser -| Message | @Discord.IMessage +| Message | @Discord.IUserMessage \* To retrieve an @Discord.IGuildUser, you must retrieve the user from an @Discord.IGuild. [IDiscordClient.GetUserAsync](xref:Discord.IDiscordClient#Discord_IDiscordClient_GetUserAsync_System_UInt64_)