Search in sources :

Example 16 with SplitFirstObject

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

the class SetLevel method execute.

@Override
public String execute(String args, CommandObject command) {
    SplitFirstObject xpArgs = new SplitFirstObject(args);
    UserObject user = Utility.getUser(command, xpArgs.getFirstWord(), false);
    if (user == null) {
        return "> Could not find user.";
    }
    try {
        long level = Long.parseLong(xpArgs.getRest());
        if (level > Constants.LEVEL_CAP)
            return "> No... " + level + " Is way too many levels. Im not setting your level that high.";
        long xp = PixelHandler.totalXPForLevel(level);
        ProfileObject userObject = user.getProfile(command.guild);
        if (userObject == null) {
            return "> User does not have a profile.";
        }
        if (Utility.testUserHierarchy(user, command.user, command.guild)) {
            return "> You do not have permission to edit " + user.displayName + "'s pixels.";
        }
        userObject.setXp(xp);
        userObject.removeLevelFloor();
        GuildHandler.checkUsersRoles(user.longID, command.guild);
        return "> " + user.displayName + "'s Level is now set to: **" + level + "**";
    } catch (NumberFormatException e) {
        return "> Invalid number";
    }
}
Also used : UserObject(com.github.vaerys.masterobjects.UserObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 17 with SplitFirstObject

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

the class SetQuote method execute.

@Override
public String execute(String args, CommandObject command) {
    UserObject user = command.user;
    String quote = args;
    boolean adminEdit = false;
    if (ADMIN_EDIT.isSubCommand(command)) {
        if (GuildHandler.testForPerms(command, Permissions.MANAGE_MESSAGES)) {
            SplitFirstObject userCall = new SplitFirstObject(quote);
            user = Utility.getUser(command, userCall.getFirstWord(), false, true);
            if (user == null)
                return "> Could not find user.";
            quote = userCall.getRest();
            adminEdit = true;
        } else {
            return command.user.notAllowed;
        }
    }
    int maxLength = 140;
    if (user.isPatron) {
        maxLength += 140;
    }
    ProfileObject u = user.getProfile(command.guild);
    quote = Utility.removeFun(quote);
    if (quote == null || quote.isEmpty())
        return "> You can't have an empty quote.";
    for (String s : quote.split(" ")) {
        if (!Utility.checkURL(s)) {
            return "> Cannot add quote. Malicious link found.";
        }
    }
    if (adminEdit) {
        if (quote.length() > maxLength) {
            return "> Quote is too long...\n(must be under " + maxLength + " chars)";
        }
        u.setQuote(quote);
        return "> " + user.displayName + "'s Quote Edited.";
    } else {
        if (quote.length() > maxLength) {
            return "> Your Quote is too long...\n(must be under " + maxLength + " chars)";
        }
        u.setQuote(quote);
        return "> Quote Edited.";
    }
}
Also used : UserObject(com.github.vaerys.masterobjects.UserObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 18 with SplitFirstObject

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

the class Respond method execute.

@Override
public String execute(String args, CommandObject command) {
    SplitFirstObject response = new SplitFirstObject(args);
    IUser recipient = command.client.get().getUserByID(Utility.stringLong(response.getFirstWord()));
    return sendDM(response.getRest(), command, recipient, command.user.username + ": ");
}
Also used : IUser(sx.blah.discord.handle.obj.IUser) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 19 with SplitFirstObject

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

the class EditLinks method execute.

@Override
public String execute(String args, CommandObject command) {
    UserObject user = command.user;
    SplitFirstObject userCall = new SplitFirstObject(args);
    boolean adminEdit = false;
    if (GuildHandler.testForPerms(command, ADMIN_EDIT.getPermissions()) || GuildHandler.canBypass(command.user.get(), command.guild.get())) {
        user = Utility.getUser(command, userCall.getFirstWord(), false);
        if (user != null && userCall.getRest() != null && user.getProfile(command.guild) != null) {
            adminEdit = true;
        } else {
            user = command.user;
        }
    }
    SplitFirstObject linkName;
    if (adminEdit) {
        linkName = new SplitFirstObject(userCall.getRest());
    } else {
        linkName = new SplitFirstObject(args);
    }
    ProfileObject userObject = user.getProfile(command.guild);
    if (userObject == null) {
        return "> " + user.displayName + " Has not Spoken yet thus they have nothing to edit.";
    }
    userObject.setLinks();
    for (UserLinkObject link : userObject.getLinks()) {
        if (link.getName().equalsIgnoreCase(linkName.getFirstWord())) {
            userObject.getLinks().remove(link);
            if (adminEdit) {
                return "> " + user.displayName + "'s Link was removed.";
            } else {
                return "> Link removed.";
            }
        }
    }
    int maxLinks = 5;
    if (user.isPatron) {
        maxLinks += 5;
    }
    if (linkName.getRest() == null) {
        return "> Cannot add link, Must specify a URL.";
    } else {
        if (userObject.getLinks().size() >= maxLinks) {
            if (adminEdit) {
                return "> " + user.displayName + " already has " + maxLinks + " links, a link must be removed to add a new one.";
            } else {
                return "> You already have " + maxLinks + " links, you must remove one to add a new one.";
            }
        }
        if (linkName.getFirstWord().length() > 15) {
            return "> Link Name too long. (Max 15 chars)";
        }
        if (Utility.checkURL(linkName.getRest())) {
            try {
                new URL(linkName.getRest());
                userObject.getLinks().add(new UserLinkObject(linkName.getFirstWord(), linkName.getRest()));
                if (adminEdit) {
                    return "> New link added for " + user.displayName + ".";
                } else {
                    return "> New link added.";
                }
            } catch (MalformedURLException e) {
                return "> Cannot add link, Invalid URL.";
            }
        } else {
            return "> Cannot add link, Invalid URL.";
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) UserObject(com.github.vaerys.masterobjects.UserObject) UserLinkObject(com.github.vaerys.objects.UserLinkObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject) ProfileObject(com.github.vaerys.objects.ProfileObject) URL(java.net.URL)

Example 20 with SplitFirstObject

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

the class NewDailyMessage method execute.

@Override
public String execute(String args, CommandObject command) {
    try {
        SplitFirstObject day = new SplitFirstObject(args);
        DayOfWeek dayOfWeek = DayOfWeek.valueOf(day.getFirstWord().toUpperCase());
        if (day.getRest() != null) {
            IMessage working = RequestHandler.sendMessage("`Working...`", command.channel.get()).get();
            QueueHandler.addToQueue(command, day.getRest(), dayOfWeek, Constants.QUEUE_DAILY);
            RequestHandler.deleteMessage(working);
            return "> Request Sent.";
        } else {
            return Utility.getCommandInfo(this, command);
        }
    } catch (IllegalArgumentException e) {
        return "> Not a valid Day of the week.";
    }
}
Also used : DayOfWeek(java.time.DayOfWeek) IMessage(sx.blah.discord.handle.obj.IMessage) 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