Search in sources :

Example 6 with CommandObject

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;
        }
    }
}
Also used : CommandObject(com.github.vaerys.commands.CommandObject) Command(com.github.vaerys.templates.Command) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 7 with CommandObject

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;
        }
    }
}
Also used : CommandObject(com.github.vaerys.commands.CommandObject) Restart(com.github.vaerys.commands.creator.Restart) LinkedList(java.util.LinkedList) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 8 with CommandObject

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);
}
Also used : CommandObject(com.github.vaerys.commands.CommandObject) IChannel(sx.blah.discord.handle.obj.IChannel) Random(java.util.Random) JoinMessage(com.github.vaerys.objects.JoinMessage)

Example 9 with CommandObject

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);
    }
}
Also used : CommandObject(com.github.vaerys.commands.CommandObject) ZonedDateTime(java.time.ZonedDateTime)

Example 10 with CommandObject

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();
}
Also used : Arrays(java.util.Arrays) List(java.util.List) CommandObject(com.github.vaerys.commands.CommandObject) StringHandler(com.github.vaerys.handlers.StringHandler) SAILType(com.github.vaerys.enums.SAILType) Permissions(sx.blah.discord.handle.obj.Permissions) Pattern(java.util.regex.Pattern) GuildHandler(com.github.vaerys.handlers.GuildHandler) Utility(com.github.vaerys.main.Utility) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Permissions(sx.blah.discord.handle.obj.Permissions) StringHandler(com.github.vaerys.handlers.StringHandler)

Aggregations

CommandObject (com.github.vaerys.commands.CommandObject)26 Collectors (java.util.stream.Collectors)13 SAILType (com.github.vaerys.enums.SAILType)12 ChannelSetting (com.github.vaerys.enums.ChannelSetting)11 Utility (com.github.vaerys.main.Utility)11 Command (com.github.vaerys.templates.Command)10 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)9 List (java.util.List)9 Permissions (sx.blah.discord.handle.obj.Permissions)9 RequestHandler (com.github.vaerys.handlers.RequestHandler)7 GuildHandler (com.github.vaerys.handlers.GuildHandler)6 ArrayList (java.util.ArrayList)6 UserObject (com.github.vaerys.masterobjects.UserObject)5 SubCommandObject (com.github.vaerys.objects.SubCommandObject)5 EventSubscriber (sx.blah.discord.api.events.EventSubscriber)5 GuildObject (com.github.vaerys.masterobjects.GuildObject)4 ZonedDateTime (java.time.ZonedDateTime)4 java.util (java.util)4 IChannel (sx.blah.discord.handle.obj.IChannel)4 IRole (sx.blah.discord.handle.obj.IRole)4