Update docs to reflect IMessage->IUserMessage

As changed in 23a0316252
This commit is contained in:
Christopher F
2016-08-27 22:16:51 -04:00
parent 23a0316252
commit 8406bd8f73
12 changed files with 21 additions and 19 deletions

View File

@@ -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<TypeReaderResult> Read(IMessage context, string input)`.
Next, satisfy the `TypeReader` class by overriding `Task<TypeReaderResult> Read(IUserMessage context, string input)`.
>[!NOTE]
>In many cases, Visual Studio can fill this in for you, using the "Implement Abstract Class" IntelliSense hint.

View File

@@ -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)]

View File

@@ -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)

View File

@@ -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. */
}

View File

@@ -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) { }
}

View File

@@ -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

View File

@@ -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();

View File

@@ -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) { }
}

View File

@@ -8,7 +8,7 @@ public class RequireOwnerAttribute : PreconditionAttribute
public readonly ulong OwnerId = 66078337084162048;
// Override the CheckPermissions method
public override Task<PreconditionResult> CheckPermissions(IMessage context, Command executingCommand, object moduleInstance)
public override Task<PreconditionResult> 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."));

View File

@@ -3,5 +3,5 @@ public class AdminModule
{
[Command("ban")]
[RequirePermission(GuildPermission.BanMembers)]
public async Task Ban(IMessage msg) { }
public async Task Ban(IUserMessage msg) { }
}

View File

@@ -3,7 +3,7 @@ using Discord.Commands;
public class BooleanTypeReader : TypeReader
{
public override Task<TypeReaderResult> Read(IMessage context, string input)
public override Task<TypeReaderResult> Read(IUserMessage context, string input)
{
bool result;
if (bool.TryParse(input, out result))

View File

@@ -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_)