use of com.github.vaerys.templates.Command in project DiscordSailv2 by Vaerys-Dawn.
the class SetupHandler method handleCommand.
/**
* Handle commands in the Setup Mode DMs.
*
* @param command The {@link CommandObject} associated with this setup.
* @param args The contents of the message sent.
* @return false if command isn't run, otherwise true.
*/
private static boolean handleCommand(CommandObject command, String args) {
List<Command> commands = Globals.getSetupCommands();
IChannel currentChannel = command.channel.get();
String commandArgs;
for (Command c : commands) {
if (c.isCall(args, command)) {
commandArgs = c.getArgs(args, command);
// log command
MessageHandler.handleLogging(command, c, commandArgs);
if (c.requiresArgs && (commandArgs == null || commandArgs.isEmpty())) {
RequestHandler.sendMessage(Utility.getCommandInfo(c, command), currentChannel);
return true;
}
RequestBuffer.request(() -> command.channel.get().setTypingStatus(true)).get();
String response = c.execute(commandArgs, command);
RequestHandler.sendMessage(response, currentChannel);
RequestBuffer.request(() -> command.channel.get().setTypingStatus(false)).get();
return true;
}
}
return false;
}
use of com.github.vaerys.templates.Command in project DiscordSailv2 by Vaerys-Dawn.
the class SettingsStage method stepText.
@Override
public void stepText(CommandObject command) {
StringHandler output = new StringHandler();
output.append("Next step is to pick which settings you want to use.\n").append("There's a lot of settings in modules, and those will be set there.\n").append("Here's a list of the settings that aren't tied to any specific module.\n");
// Get the settings and modules.
List<GuildToggle> globalToggles = ToggleInit.getToggles(false);
List<GuildToggle> modules = ToggleInit.getToggles(true);
// Sort settings
globalToggles.sort(Comparator.comparing(GuildToggle::name));
// Init additional vars
List<String> enabled = new ArrayList<>();
List<String> disabled = new ArrayList<>();
String format = "\t> **%s** - %s\n";
// skip debug mode after it's defaulted to off:
if (!new DebugMode().getDefault()) {
globalToggles.removeIf(t -> t.name() == SAILType.DEBUG_MODE);
}
// Filter toggles that are not part of modules.
List<SAILType> types = new LinkedList<>();
modules.forEach(t -> types.addAll(t.settings.stream().map(s -> s.name()).collect(Collectors.toList())));
ListIterator iterator = globalToggles.listIterator();
while (iterator.hasNext()) {
GuildToggle toggle = (GuildToggle) iterator.next();
if (types.contains(toggle.name())) {
// Is part of a module, remove from list
iterator.remove();
} else {
// is not, get extra information...
if (toggle.enabled(command.guild.config))
enabled.add(toggle.name().toString());
else
disabled.add(toggle.name().toString());
// append to list of things.
output.appendFormatted(format, toggle.name().toString(), toggle.shortDesc(command));
}
}
// Send message
output.append("\nYou can switch settings on and off with **" + Command.get(Toggle.class).getCommand(command) + "** and get more info on each setting with **" + Command.get(HelpSettings.class).getCommand(command) + "**.");
// Append additional enabled/disabled state info.
XEmbedBuilder embed = new XEmbedBuilder(command);
embed.withTitle("Global Settings");
embed.appendField("Enabled", "```" + Utility.listFormatter(enabled, true) + "```", false);
embed.appendField("Disabled", "```" + Utility.listFormatter(disabled, true) + "```", false);
RequestHandler.sendEmbedMessage(output.toString(), embed, command.channel);
}
use of com.github.vaerys.templates.Command in project DiscordSailv2 by Vaerys-Dawn.
the class Utility method getUser.
public static UserObject getUser(CommandObject command, String args, boolean doContains, boolean hasProfile) {
if (args != null && !args.isEmpty()) {
IUser user = null;
IUser conUser = null;
String toTest;
if (args.split(" ").length != 1) {
toTest = escapeRegex(args);
} else {
toTest = escapeRegex(args).replace("_", "[_| ]");
}
List<IUser> guildUsers = command.guild.getUsers();
guildUsers.sort(Comparator.comparing(o -> o.getRolesForGuild(command.guild.get()).size()));
Collections.reverse(guildUsers);
for (IUser u : guildUsers) {
if (user != null) {
break;
}
try {
UserObject object = new UserObject(u, command.guild, true);
if (hasProfile) {
ProfileObject profile = object.getProfile(command.guild);
if (profile == null || profile.isEmpty())
continue;
}
if ((u.getName() + "#" + u.getDiscriminator()).matches("(?i)" + toTest)) {
user = u;
}
if (u.getName().matches("(?i)" + toTest) && user == null) {
user = u;
}
String displayName = u.getDisplayName(command.guild.get());
if (displayName.matches("(?i)" + toTest) && user == null) {
user = u;
}
if (doContains && conUser == null) {
if (u.getName().matches("(?i).*" + toTest + ".*")) {
conUser = u;
}
if (displayName.matches("(?i).*" + toTest + ".*") && conUser == null) {
conUser = u;
}
}
} catch (PatternSyntaxException e) {
// continue.
}
}
UserObject userObject = null;
try {
long uID = Long.parseLong(args);
return new UserObject(uID, command.guild);
} catch (NumberFormatException e) {
if (command.message.get().getMentions().size() > 0) {
user = command.message.get().getMentions().get(0);
}
}
if (user == null && doContains) {
user = conUser;
}
if (user != null) {
userObject = new UserObject(user, command.guild);
}
return userObject;
}
return null;
}
use of com.github.vaerys.templates.Command in project DiscordSailv2 by Vaerys-Dawn.
the class CreatorHandler method creatorCommands.
@EventSubscriber
public void creatorCommands(MessageReceivedEvent event) {
if (event.getAuthor().getLongID() != Globals.creatorID)
return;
List<Command> commands;
CommandObject command = new CommandObject(event.getMessage());
if (event.getChannel().isPrivate()) {
commands = new ArrayList<>(Globals.getCreatorCommands(true));
} else {
commands = new ArrayList<>(Globals.getCreatorCommands(false));
}
String message = event.getMessage().getContent();
for (Command c : commands) {
if (c.isCall(message, command)) {
String args = c.getArgs(message, command);
RequestHandler.sendMessage(c.execute(args, command), command.channel.get());
MessageHandler.handleLogging(command, c, args);
return;
}
}
}
use of com.github.vaerys.templates.Command in project DiscordSailv2 by Vaerys-Dawn.
the class MessageHandler method handleCommand.
// Command Handler
private boolean handleCommand(CommandObject command, String args) {
List<Command> commands = new ArrayList<>(command.guild.commands);
IChannel currentChannel = command.channel.get();
String commandArgs;
for (Command c : commands) {
if (c.isCall(args, command)) {
commandArgs = c.getArgs(args, command);
// log command
command.guild.sendDebugLog(command, "COMMAND", c.getCommand(command), c.getArgs(args, command));
// test if user has permissions
if (!GuildHandler.testForPerms(command, c.perms)) {
RequestHandler.sendMessage(command.user.notAllowed, currentChannel);
return true;
}
// check if it is a valid channel
if (!currentChannel.isPrivate()) {
if (c.channel != null && !GuildHandler.testForPerms(command, Permissions.MANAGE_CHANNELS)) {
List<IChannel> channels = command.guild.getChannelsByType(c.channel);
if (channels.size() != 0 && !channels.contains(command.channel.get())) {
List<String> list = Utility.getChannelMentions(command.user.getVisibleChannels(channels));
RequestHandler.sendMessage(Utility.getChannelMessage(list), command.channel.get());
return true;
}
}
}
if (c.requiresArgs && (commandArgs == null || commandArgs.isEmpty())) {
RequestHandler.sendMessage(Utility.getCommandInfo(c, command), currentChannel);
return true;
}
// command logging
handleLogging(command, c, commandArgs);
RequestBuffer.request(() -> command.channel.get().setTypingStatus(true)).get();
// if (!command.channel.getToggles().getTypingStatus()) {
// command.channel.getToggles().toggleTypingStatus();
// }
String response = c.execute(commandArgs, command);
RequestHandler.sendMessage(response, currentChannel);
RequestBuffer.request(() -> command.channel.get().setTypingStatus(false)).get();
return true;
}
}
return false;
}
Aggregations