use of com.github.vaerys.commands.CommandObject 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.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.
the class CreatorHandler method restart.
@EventSubscriber
public void restart(MessageReceivedEvent event) {
CommandObject command = new CommandObject(event.getMessage());
Restart restart = new Restart();
if (restart.isCall(event.getMessage().getContent(), command)) {
List<Long> auth = new LinkedList<>();
try {
List<String> toParse = FileHandler.readFromFile(Constants.FILE_AUTH_TO_RESTART);
auth.addAll(toParse.stream().map(Long::parseUnsignedLong).collect(Collectors.toList()));
} catch (NumberFormatException e) {
// do nothing
}
auth.add(Globals.creatorID);
if (auth.contains(event.getAuthor().getLongID())) {
restart.execute("", command);
return;
}
}
}
use of com.github.vaerys.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.
the class JoinHandler method customJoinMessages.
/**
* Send A special message to the specified JoinMessage channel that welcomes the user to the server.
*
* @param user The user that joined. ({@link UserObject})
* @param content The Guild that the user joined. ({@link GuildObject})
*/
public static void customJoinMessages(GuildObject content, IUser user) {
IChannel channel = content.getChannelByType(ChannelSetting.JOIN_CHANNEL);
if (channel == null)
return;
Random random = new Random();
List<JoinMessage> joinMessageList = content.channelData.getJoinMessages();
if (joinMessageList.size() == 0)
return;
JoinMessage message = joinMessageList.get(random.nextInt(joinMessageList.size()));
String response = message.getContent(new CommandObject(content, channel, user));
RequestHandler.sendMessage(response, channel);
}
use of com.github.vaerys.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.
the class LoggingHandler method doMessageEditLog.
public static void doMessageEditLog(MessageUpdateEvent event) {
CommandObject command = new CommandObject(event.getMessage());
IUser ourUser = command.client.bot.get();
if (!shouldLog(command))
return;
if (command.guild.config.editLogging) {
// formats how long ago this was.
String formatted;
String oldContent;
String newContent;
StringBuilder response = new StringBuilder();
ZonedDateTime oldMessageTime = event.getOldMessage().getTimestamp().atZone(ZoneOffset.UTC);
ZonedDateTime newMessageTime = event.getNewMessage().getEditedTimestamp().get().atZone(ZoneOffset.UTC);
int charLimit;
long difference = newMessageTime.toEpochSecond() - oldMessageTime.toEpochSecond();
if (command.guild.config.useTimeStamps) {
formatted = "at `" + Utility.formatTimestamp(oldMessageTime) + " - UTC`";
} else {
formatted = "from " + Utility.formatTimeDifference(difference);
}
response.append("> **@" + command.user.username + "'s** Message " + formatted + " was **Edited** in channel: " + command.channel.get().mention() + ". ");
// remove excess text that would cause a max char limit error.
if (command.message.get().getContent().isEmpty()) {
return;
}
if (command.guild.config.extendEditLog) {
charLimit = 900;
} else {
charLimit = 1800;
}
if (event.getOldMessage().getContent().length() > charLimit) {
oldContent = Utility.unFormatMentions(event.getOldMessage()).substring(0, charLimit) + "...";
} else {
oldContent = Utility.unFormatMentions(event.getOldMessage());
}
if (event.getNewMessage().getContent().length() > charLimit) {
newContent = Utility.unFormatMentions(event.getNewMessage()).substring(0, charLimit) + "...";
} else {
newContent = Utility.unFormatMentions(event.getNewMessage());
}
response.append("**\nMessage's Old Contents:**\n" + oldContent);
if (command.guild.config.extendEditLog) {
response.append("\n**Message's New Contents:**\n" + newContent);
}
Utility.sendLog(response.toString(), command.guild, false);
}
}
use of com.github.vaerys.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.
the class SubCommandObject method getHelpDesc.
public String getHelpDesc(CommandObject command) {
StringHandler builder = new StringHandler();
builder.append(description + "\n");
builder.append("**Type: **" + type.toString() + ".");
// display permissions
if (permissions != null && permissions.length != 0) {
builder.append("\n**Perms: **");
ArrayList<String> permList = new ArrayList<>(permissions.length);
for (Permissions p : permissions) {
permList.add(Utility.enumToString(p));
}
builder.append(Utility.listFormatter(permList, true));
}
if (names.length > 1) {
List<String> aliases = Arrays.asList(names).stream().map(s -> command.guild.config.getPrefixCommand() + s).collect(Collectors.toList());
aliases.remove(0);
builder.append("\n**Aliases:** " + Utility.listFormatter(aliases, true));
}
return builder.toString();
}
Aggregations