Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/java/com/diamondfire/helpbot/HelpBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import com.diamondfire.helpbot.bot.HelpBotInstance;
import com.diamondfire.helpbot.df.codeinfo.codedatabase.changelog.CodeDifferenceHandler;
import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.CodeDatabase;
import com.diamondfire.helpbot.sys.tag.TagHandler;

import javax.security.auth.login.LoginException;
import java.io.IOException;

public class HelpBot {

public static void main(String[] args) throws LoginException {
public static void main(String[] args) throws LoginException, IOException {
CodeDatabase.initialize();
TagHandler.cacheJson();
HelpBotInstance.initialize();
CodeDifferenceHandler.refresh();
}
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@

import com.diamondfire.helpbot.bot.command.CommandHandler;
import com.diamondfire.helpbot.bot.command.impl.codeblock.*;
import com.diamondfire.helpbot.bot.command.impl.other.*;
import com.diamondfire.helpbot.bot.command.impl.other.StoreCommand;
import com.diamondfire.helpbot.bot.command.impl.other.dev.*;
import com.diamondfire.helpbot.bot.command.impl.other.dumps.*;
import com.diamondfire.helpbot.bot.command.impl.other.fun.*;
import com.diamondfire.helpbot.bot.command.impl.other.info.*;
import com.diamondfire.helpbot.bot.command.impl.other.mod.*;
import com.diamondfire.helpbot.bot.command.impl.other.tag.TagCommand;
import com.diamondfire.helpbot.bot.command.impl.other.util.*;
import com.diamondfire.helpbot.bot.command.impl.stats.*;
import com.diamondfire.helpbot.bot.command.impl.stats.graph.*;
import com.diamondfire.helpbot.bot.command.impl.stats.individualized.*;
import com.diamondfire.helpbot.bot.command.impl.stats.metrics.*;
import com.diamondfire.helpbot.bot.command.impl.stats.plot.*;
import com.diamondfire.helpbot.bot.command.impl.stats.support.*;
import com.diamondfire.helpbot.bot.command.impl.stats.top.*;
import com.diamondfire.helpbot.bot.config.Config;
import com.diamondfire.helpbot.bot.events.*;
import com.diamondfire.helpbot.sys.tasks.TaskRegistry;
Expand Down Expand Up @@ -117,7 +126,8 @@ public static void initialize() throws LoginException {
new DailySessionsCommand(),
new EightBallCommand(),
new OcrCommand(),
new JoinsCommand()
new JoinsCommand(),
new TagCommand()
);

JDABuilder builder = JDABuilder.createDefault(config.getToken())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.diamondfire.helpbot.bot.command;

import com.diamondfire.helpbot.bot.HelpBotInstance;
import com.diamondfire.helpbot.bot.command.disable.DisableCommandHandler;
import com.diamondfire.helpbot.bot.command.executor.CommandExecutor;
import com.diamondfire.helpbot.bot.command.impl.Command;
Expand Down Expand Up @@ -44,8 +43,12 @@ public void register(Command... commands) {

}

public void run(CommandEvent e, String[] args) {
COMMAND_EXECUTOR.run(e, args);
}

public void run(CommandEvent e) {
COMMAND_EXECUTOR.run(e);
run(e, e.getRawArgs());
}

public HashMap<String, Command> getCommands() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions;

import com.diamondfire.helpbot.bot.command.impl.Command;
import com.diamondfire.helpbot.bot.HelpBotInstance;
import com.diamondfire.helpbot.bot.command.impl.*;
import com.diamondfire.helpbot.bot.events.CommandEvent;
import com.diamondfire.helpbot.util.FormatUtil;

public class ArgumentException extends Exception {
Expand All @@ -16,11 +18,17 @@ public String getEmbedMessage() {
return message;
}

public void setContext(Command command, int pos) {
public void setContext(Command command, int pos, CommandEvent event) {
String[] args = FormatUtil.getArgumentDisplay(command.getHelpContext());
args[pos] = "**" + args[pos] + "**";
String argMessage = FormatUtil.displayCommand(command) + " " + String.join(" ", args);

if (command instanceof SubCommand) {
String prefix = HelpBotInstance.getConfig().getPrefix();

argMessage = event.getRawArgs()[0] + " " + argMessage.substring(prefix.length());
}

message = argMessage + "\n\n" + getMessage();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.diamondfire.helpbot.bot.command.argument.impl.parsing.*;
import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*;
import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.*;
import com.diamondfire.helpbot.bot.events.CommandEvent;

public class AlternateArgumentParser<A> extends ArgumentParser<AlternateArgumentContainer<A>, A> {

Expand All @@ -11,10 +12,10 @@ public AlternateArgumentParser(AlternateArgumentContainer<A> container) {
}

@Override
public ParsedArgument<?> parse(String identifier, ArgumentStack.RawArgumentStack args) throws ArgumentException {
public ParsedArgument<?> parse(String identifier, ArgumentStack.RawArgumentStack args, CommandEvent event) throws ArgumentException {
for (ArgumentContainer<?> container : getContainer().getAlternatives()) {
try {
return new ParsedArgument<>(identifier, container.getParser().parse(identifier, args).getValue());
return new ParsedArgument<>(identifier, container.getParser().parse(identifier, args, event).getValue());
} catch (ArgumentException ignored) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*;
import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.ArgumentContainer;
import com.diamondfire.helpbot.bot.command.impl.Command;
import com.diamondfire.helpbot.bot.events.CommandEvent;

import java.util.*;

Expand All @@ -16,7 +17,7 @@ public ArgumentParser(T container) {
this.container = container;
}

public static ParsedArgumentSet parseArgs(Command command, String[] args) throws ArgumentException {
public static ParsedArgumentSet parseArgs(Command command, String[] args, CommandEvent event) throws ArgumentException {
Map<String, ParsedArgument<?>> parsedArgs = new HashMap<>();
ArgumentStack stack = new ArgumentStack(command.getArguments().getArguments(), Arrays.asList(args));
int arguments = stack.getArguments().size();
Expand All @@ -28,25 +29,25 @@ public static ParsedArgumentSet parseArgs(Command command, String[] args) throws
String identifier = argument.getIdentifier();

try {
parsedArgs.put(identifier, argumentContainer.getParser().parse(identifier, rawArguments));
parsedArgs.put(identifier, argumentContainer.getParser().parse(identifier, rawArguments, event));
rawArguments.pushStack();
} catch (MissingArgumentException exception) {
if (argumentContainer.isOptional()) {
parsedArgs.put(identifier, new ParsedArgument<>(identifier, argumentContainer.getDefaultValue()));
} else {
exception.setContext(command, i);
exception.setContext(command, i, event);
throw exception;
}
} catch (MalformedArgumentException exception) {
exception.setContext(command, i);
exception.setContext(command, i, event);
throw exception;
}
}

return new ParsedArgumentSet(parsedArgs);
}

public abstract ParsedArgument<?> parse(String identifier, ArgumentStack.RawArgumentStack args) throws ArgumentException;
public abstract ParsedArgument<?> parse(String identifier, ArgumentStack.RawArgumentStack args, CommandEvent event) throws ArgumentException;

protected T getContainer() {
return container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*;
import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.MultiArgumentContainer;
import com.diamondfire.helpbot.bot.command.argument.impl.types.Argument;
import com.diamondfire.helpbot.bot.events.CommandEvent;

import java.util.*;

Expand All @@ -14,15 +15,15 @@ public MultiArgumentParser(MultiArgumentContainer<A> container) {
}

@Override
public ParsedArgument<?> parse(String identifier, ArgumentStack.RawArgumentStack args) throws ArgumentException {
public ParsedArgument<?> parse(String identifier, ArgumentStack.RawArgumentStack args, CommandEvent event) throws ArgumentException {
Deque<String> rawArgs = args.popStack();
List<A> approvedArgumentValues = new ArrayList<>();
Argument<A> arg = getContainer().getArgument();
int arguments = rawArgs.size();

for (int i = 0; i < arguments; i++) {
try {
approvedArgumentValues.add(arg.parseValue(rawArgs));
approvedArgumentValues.add(arg.parseValue(rawArgs, event));
} catch (Exception e) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*;
import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer;
import com.diamondfire.helpbot.bot.command.argument.impl.types.Argument;
import com.diamondfire.helpbot.bot.events.CommandEvent;

import java.util.Deque;

Expand All @@ -15,14 +16,14 @@ public SingleArgumentParser(SingleArgumentContainer<A> container) {
}

@Override
public ParsedArgument<?> parse(String identifier, ArgumentStack.RawArgumentStack args) throws ArgumentException {
public ParsedArgument<?> parse(String identifier, ArgumentStack.RawArgumentStack args, CommandEvent event) throws ArgumentException {
Deque<String> rawArgs = args.popStack();
Argument<A> arg = getContainer().getArgument();

if (rawArgs.peek() == null) {
throw new MissingArgumentException("Expected an argument, but got nothing.");
}

return new ParsedArgument<>(identifier, arg.parseValue(rawArgs));
return new ParsedArgument<>(identifier, arg.parseValue(rawArgs, event));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException;
import com.diamondfire.helpbot.bot.command.argument.impl.types.Argument;
import com.diamondfire.helpbot.bot.events.CommandEvent;
import org.jetbrains.annotations.NotNull;

import java.util.Deque;

public class MessageArgument implements Argument<String> {

@Override
public String parseValue(@NotNull Deque<String> args) throws ArgumentException {
public String parseValue(@NotNull Deque<String> args, CommandEvent event) throws ArgumentException {
return String.join(" ", args);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.diamondfire.helpbot.bot.command.argument.impl.types;

import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*;
import com.diamondfire.helpbot.bot.events.CommandEvent;
import org.jetbrains.annotations.NotNull;

import java.util.*;
Expand All @@ -18,7 +19,7 @@ public AbstractOffsetArgument(boolean reverse) {
}

@Override
protected Date parse(@NotNull String argument) throws ArgumentException {
protected Date parse(@NotNull String argument, CommandEvent event) throws ArgumentException {
Calendar calendar = Calendar.getInstance();
int offset = 0;
boolean modified = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.diamondfire.helpbot.bot.command.argument.impl.types;

import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException;
import com.diamondfire.helpbot.bot.events.CommandEvent;
import org.jetbrains.annotations.NotNull;

import java.util.Deque;

public abstract class AbstractSimpleValueArgument<T> implements Argument<T> {

@Override
public T parseValue(@NotNull Deque<String> args) throws ArgumentException {
return parse(args.pop());
public T parseValue(@NotNull Deque<String> args, CommandEvent event) throws ArgumentException {
return parse(args.pop(), event);
}

protected abstract T parse(@NotNull String argument) throws ArgumentException;
protected abstract T parse(@NotNull String argument, CommandEvent event) throws ArgumentException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException;
import com.diamondfire.helpbot.bot.events.CommandEvent;
import org.jetbrains.annotations.NotNull;

import java.util.Deque;
Expand All @@ -14,7 +15,7 @@
*/
public interface Argument<T> {

T parseValue(@NotNull Deque<String> args) throws ArgumentException;
T parseValue(@NotNull Deque<String> args, CommandEvent event) throws ArgumentException;

}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.diamondfire.helpbot.bot.command.argument.impl.types;

import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException;
import com.diamondfire.helpbot.bot.events.CommandEvent;
import com.diamondfire.helpbot.util.Util;
import org.jetbrains.annotations.NotNull;

Expand All @@ -20,8 +21,8 @@ public ClampedIntegerArgument(int min, int max) {
}

@Override
public Integer parse(@NotNull String msg) throws ArgumentException {
int num = super.parse(msg);
public Integer parse(@NotNull String msg, CommandEvent event) throws ArgumentException {
int num = super.parse(msg, event);

if (num <= max && num >= min) {
return num;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.diamondfire.helpbot.bot.command.argument.impl.types;

import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*;
import com.diamondfire.helpbot.bot.events.CommandEvent;
import org.jetbrains.annotations.NotNull;

import java.text.*;
Expand All @@ -19,7 +20,7 @@ public DateArgument(String format) {
}

@Override
public Date parse(@NotNull String msg) throws ArgumentException {
public Date parse(@NotNull String msg, CommandEvent event) throws ArgumentException {
try {
return format.parse(msg);
} catch (ParseException parseException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*;
import com.diamondfire.helpbot.bot.events.CommandEvent;
import com.diamondfire.helpbot.util.JaroWinkler;
import org.jetbrains.annotations.NotNull;

Expand All @@ -26,7 +27,7 @@ public DefinedObjectArgument(boolean trailing, @NotNull T... options) {
}

@Override
public T parseValue(@NotNull Deque<String> args) throws ArgumentException {
public T parseValue(@NotNull Deque<String> args, CommandEvent event) throws ArgumentException {
String compareString;
if (trailing) {
compareString = String.join(" ", args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.diamondfire.helpbot.bot.command.argument.impl.types;

import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.MalformedArgumentException;
import com.diamondfire.helpbot.bot.events.CommandEvent;
import net.dv8tion.jda.api.utils.MiscUtil;
import org.jetbrains.annotations.NotNull;

Expand All @@ -11,7 +12,7 @@ public class DiscordUserArgument extends AbstractSimpleValueArgument<Long> {
private final Pattern pattern = Pattern.compile("<@!?(\\d+)>");

@Override
public Long parse(@NotNull String msg) throws MalformedArgumentException {
public Long parse(@NotNull String msg, CommandEvent event) throws MalformedArgumentException {

try {
return Long.parseLong(msg);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.diamondfire.helpbot.bot.command.argument.impl.types;

import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.*;
import com.diamondfire.helpbot.bot.events.CommandEvent;
import org.jetbrains.annotations.NotNull;

public class IntegerArgument extends AbstractSimpleValueArgument<Integer> {

@Override
public Integer parse(@NotNull String msg) throws ArgumentException {
public Integer parse(@NotNull String msg, CommandEvent event) throws ArgumentException {
try {
return Integer.parseInt(msg);
} catch (NumberFormatException exception) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.diamondfire.helpbot.bot.command.argument.impl.types;

import com.diamondfire.helpbot.bot.command.argument.impl.parsing.exceptions.ArgumentException;
import com.diamondfire.helpbot.bot.events.CommandEvent;
import org.jetbrains.annotations.NotNull;

public class LongArgument extends AbstractSimpleValueArgument<Long>{

@Override
protected Long parse(@NotNull String argument) throws ArgumentException {
protected Long parse(@NotNull String argument, CommandEvent event) throws ArgumentException {
return Long.parseLong(argument);
}
}
Loading