Search in sources :

Example 21 with SplitFirstObject

use of com.github.vaerys.objects.SplitFirstObject in project DiscordSailv2 by Vaerys-Dawn.

the class MentionCommand method getArgs.

@Override
public String getArgs(String args, CommandObject command) {
    SplitFirstObject mention = new SplitFirstObject(args);
    SplitFirstObject call = new SplitFirstObject(mention.getRest());
    if (call.getRest() == null) {
        return "";
    }
    return call.getRest();
}
Also used : SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 22 with SplitFirstObject

use of com.github.vaerys.objects.SplitFirstObject in project DiscordSailv2 by Vaerys-Dawn.

the class MentionCommand method isCall.

@Override
public boolean isCall(String args, CommandObject command) {
    if (command.guild.client.bot == null) {
        command.guild.sendDebugLog(command, "MENTION_COMMAND", "BOT_NULL", command.message.getContent());
        return false;
    }
    SplitFirstObject mention = new SplitFirstObject(args);
    if (mention.getRest() == null) {
        return false;
    }
    List<IUser> users = command.message.getMentions();
    IUser bot = command.client.bot.get();
    if (bot == null || !users.contains(bot)) {
        return false;
    }
    SplitFirstObject call = new SplitFirstObject(mention.getRest());
    for (String s : names) {
        String regex = "^(<@|<@!)" + command.client.bot.longID + "> " + s.toLowerCase();
        String toMatch = mention.getFirstWord() + " " + call.getFirstWord().toLowerCase();
        Matcher matcher = Pattern.compile(regex).matcher(toMatch);
        if (matcher.matches()) {
            return true;
        }
    }
    return false;
}
Also used : Matcher(java.util.regex.Matcher) IUser(sx.blah.discord.handle.obj.IUser) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 23 with SplitFirstObject

use of com.github.vaerys.objects.SplitFirstObject in project DiscordSailv2 by Vaerys-Dawn.

the class EditCC method execute.

@Override
public String execute(String args, CommandObject command) {
    ProfileObject object = command.guild.users.getUserByID(command.user.longID);
    if (object != null && object.getSettings().contains(UserSetting.DENY_MAKE_CC)) {
        return "> " + command.user.mention() + ", You have been denied the modification of custom commands.";
    }
    SplitFirstObject getName = new SplitFirstObject(args);
    String rest = getName.getRest();
    if (rest == null) {
        rest = "";
    }
    if (command.message.get().getAttachments().size() != 0) {
        String testLink = command.message.get().getAttachments().get(0).getUrl();
        if (Utility.isImageLink(testLink)) {
            if (rest.length() > 0) {
                rest += " ";
            }
            rest += "<embedImage>{" + testLink + "}";
        } else {
            return "> Custom command attachment must be a valid Image.";
        }
    }
    SplitFirstObject getMode = new SplitFirstObject(rest);
    String mode = getMode.getFirstWord();
    String content = getMode.getRest();
    CCommandObject customCommand = command.guild.customCommands.getCommand(getName.getFirstWord());
    if (customCommand == null) {
        return "> Command Not found.";
    }
    boolean canBypass = GuildHandler.testForPerms(command, Permissions.MANAGE_MESSAGES);
    boolean isAuthor = command.user.longID == customCommand.getUserID();
    // test if can edit
    if ((customCommand.isLocked() && !canBypass) || (!canBypass && !isAuthor)) {
        return "> You do not have permission to edit this command.";
    }
    if (command.guild.customCommands.checkblackList(args) != null) {
        return command.guild.customCommands.checkblackList(args);
    }
    if (customCommand.isLocked() && !canBypass) {
        return "> This command is locked and cannot be edited.";
    }
    switch(mode.toLowerCase()) {
        case "replace":
            return CCEditModes.replace(customCommand, content, command);
        case "toembed":
            return CCEditModes.toEmbed(customCommand);
        case "append":
            return CCEditModes.append(customCommand, content, command);
        case "delet":
        case "delcall":
            return CCEditModes.deleteTag(customCommand);
        case "shitpost":
            return CCEditModes.shitPost(customCommand, command, command.user.get(), command.guild.get());
        case "lock":
            return CCEditModes.lock(customCommand, command, command.user.get(), command.guild.get());
        case "addsearch":
            return CCEditModes.addSearchTag(customCommand, content);
        case "removesearch":
            return CCEditModes.removeSearchTag(customCommand, content);
        default:
            if (content == null || content.isEmpty()) {
                return CCEditModes.replace(customCommand, mode, command);
            } else {
                return CCEditModes.replace(customCommand, mode + " " + content, command);
            }
    }
}
Also used : CCommandObject(com.github.vaerys.objects.CCommandObject) ProfileObject(com.github.vaerys.objects.ProfileObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 24 with SplitFirstObject

use of com.github.vaerys.objects.SplitFirstObject in project DiscordSailv2 by Vaerys-Dawn.

the class NewCC method execute.

@Override
public String execute(String args, CommandObject command) {
    ProfileObject object = command.guild.users.getUserByID(command.user.longID);
    if (object != null && object.getSettings().contains(UserSetting.DENY_MAKE_CC)) {
        return "> " + command.user.mention() + ", You have been denied the creation of custom commands.";
    }
    if (command.guild.getChannelsByType(ChannelSetting.CC_DENIED).contains(command.channel.get()))
        return "> This Channel has CCs Denied, You cannot create ccs here.";
    boolean isShitpost = false;
    boolean isLocked = false;
    SplitFirstObject splitFirst = new SplitFirstObject(args);
    List<IChannel> shitpostChannels = command.guild.getChannelsByType(ChannelSetting.SHITPOST);
    if (shitpostChannels != null) {
        for (IChannel channel : shitpostChannels) {
            if (command.channel.longID == channel.getLongID()) {
                isShitpost = true;
            }
        }
    }
    if (object.getSettings().contains(UserSetting.AUTO_SHITPOST)) {
        isShitpost = true;
    }
    String nameCC = splitFirst.getFirstWord();
    String argsCC = splitFirst.getRest();
    if (handleNameFilter(command, nameCC)) {
        return "> Custom Commands cannot have the same name as built-in commands.";
    }
    if ((argsCC == null || argsCC.isEmpty()) && command.message.get().getAttachments().size() == 0) {
        return "> Custom command contents cannot be blank.";
    }
    if (command.message.get().getAttachments().size() != 0) {
        String testLink = command.message.get().getAttachments().get(0).getUrl();
        if (Utility.isImageLink(testLink)) {
            if (argsCC == null || argsCC.isEmpty()) {
                argsCC = "<embedImage>{" + testLink + "}";
            } else {
                argsCC += "<embedImage>{" + testLink + "}";
            }
        } else {
            return "> Custom command attachment must be a valid Image.";
        }
    }
    if (nameCC.contains("\n")) {
        return "> Command name cannot contain Newlines.";
    }
    if (argsCC.contains("<shitpost>")) {
        argsCC.replace("<shitpost>", "");
        isShitpost = true;
    }
    if (argsCC.contains("<lock>") && GuildHandler.testForPerms(command, Permissions.MANAGE_MESSAGES)) {
        argsCC.replace("<lock>", "");
        isLocked = true;
    }
    return command.guild.customCommands.addCommand(isLocked, nameCC, argsCC, isShitpost, command);
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) ProfileObject(com.github.vaerys.objects.ProfileObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 25 with SplitFirstObject

use of com.github.vaerys.objects.SplitFirstObject in project DiscordSailv2 by Vaerys-Dawn.

the class EventSetup method addAvatar.

private String addAvatar(TimedEvent event, String rest, CommandObject command) {
    if (rest == null) {
        return imageAvatar(event, command, null);
    }
    SplitFirstObject daySplit = new SplitFirstObject(rest);
    DayOfWeek day;
    try {
        day = DayOfWeek.valueOf(daySplit.getFirstWord().toUpperCase());
    } catch (IllegalArgumentException e) {
        return "> Invalid Day.";
    }
    if (daySplit.getRest() == null) {
        return imageAvatar(event, command, day);
    } else {
        String url = daySplit.getRest();
        if (Utility.isImageLink(url) && !url.endsWith(".gif")) {
            return event.setAvatar(url, day);
        } else
            return "> Invalid Image.";
    }
}
Also used : DayOfWeek(java.time.DayOfWeek) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Aggregations

SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)26 UserObject (com.github.vaerys.masterobjects.UserObject)10 ProfileObject (com.github.vaerys.objects.ProfileObject)10 IRole (sx.blah.discord.handle.obj.IRole)5 DayOfWeek (java.time.DayOfWeek)4 IChannel (sx.blah.discord.handle.obj.IChannel)4 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)3 IMessage (sx.blah.discord.handle.obj.IMessage)3 CCommandObject (com.github.vaerys.objects.CCommandObject)2 DailyMessage (com.github.vaerys.objects.DailyMessage)2 RewardRoleObject (com.github.vaerys.objects.RewardRoleObject)2 IUser (sx.blah.discord.handle.obj.IUser)2 UserSetting (com.github.vaerys.enums.UserSetting)1 MessageHandler (com.github.vaerys.handlers.MessageHandler)1 StringHandler (com.github.vaerys.handlers.StringHandler)1 CharacterObject (com.github.vaerys.objects.CharacterObject)1 JoinMessage (com.github.vaerys.objects.JoinMessage)1 TimedEvent (com.github.vaerys.objects.TimedEvent)1 UserLinkObject (com.github.vaerys.objects.UserLinkObject)1 TagObject (com.github.vaerys.templates.TagObject)1