From 9d6ccc33442c90bcf3e5d0483e1e226be77d93a0 Mon Sep 17 00:00:00 2001 From: Pingex Date: Mon, 26 Dec 2016 18:08:25 +0100 Subject: [PATCH] More context --- .../java/net/pingex/dcf/commands/Context.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/main/java/net/pingex/dcf/commands/Context.java b/src/main/java/net/pingex/dcf/commands/Context.java index 0ee1bd5..608d6e8 100644 --- a/src/main/java/net/pingex/dcf/commands/Context.java +++ b/src/main/java/net/pingex/dcf/commands/Context.java @@ -1,7 +1,9 @@ package net.pingex.dcf.commands; import sx.blah.discord.api.IDiscordClient; +import sx.blah.discord.handle.obj.IChannel; import sx.blah.discord.handle.obj.IMessage; +import sx.blah.discord.handle.obj.IUser; import java.util.List; /** @@ -19,6 +21,16 @@ public class Context */ private List arguments; + /** + * User to audit against + */ + private IUser user; + + /** + * Channel to audit against + */ + private IChannel channel; + /** * The originating reference message */ @@ -29,10 +41,38 @@ public class Context */ private IDiscordClient client; + /** + * Construct a context using the provided message. user and channel will be derived from the message. + * @param command Command being executed. + * @param arguments Its arguments. + * @param originatingMessage The messaged used to invoke the command. + * @param client Discord client. + */ public Context(Command command, List arguments, IMessage originatingMessage, IDiscordClient client) { this.command = command; this.arguments = arguments; + this.user = originatingMessage.getAuthor(); + this.channel = originatingMessage.getChannel(); + this.originatingMessage = originatingMessage; + this.client = client; + } + + /** + * Construct a context using explicit user and channel. The provided message is here for reference. + * @param command Command being executed. + * @param arguments Its arguments. + * @param user User invoking the command. + * @param channel Channel used to invoke the command. + * @param originatingMessage The messaged used to invoke the command. + * @param client Discord client. + */ + public Context(Command command, List arguments, IUser user, IChannel channel, IMessage originatingMessage, IDiscordClient client) + { + this.command = command; + this.arguments = arguments; + this.user = user; + this.channel = channel; this.originatingMessage = originatingMessage; this.client = client; } @@ -47,6 +87,16 @@ public class Context return arguments; } + public IUser getUser() + { + return user; + } + + public IChannel getChannel() + { + return channel; + } + public IMessage getOriginatingMessage() { return originatingMessage;