Search in sources :

Example 1 with SplitFirstObject

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

the class DailyMsg method execute.

@Override
public String execute(String args, CommandObject command) {
    SplitFirstObject uIDString = new SplitFirstObject(args);
    try {
        long uID = Long.parseLong(uIDString.getFirstWord());
        DailyMessage messageObject = null;
        for (DailyMessage u : Globals.getDailyMessages().getMessages()) {
            if (u.getUID() == uID) {
                messageObject = u;
            }
        }
        if (messageObject == null) {
            return "> Could not find daily message with that UID.";
        }
        SplitFirstObject mode = null;
        String totest;
        if (uIDString.getRest() == null) {
            totest = "empty";
        } else {
            mode = new SplitFirstObject(uIDString.getRest());
            totest = mode.getFirstWord();
        }
        switch(totest.toLowerCase()) {
            case "edit":
                if (mode.getRest() == null) {
                    return "> Missing args";
                }
                messageObject.setContents(mode.getRest());
                return "> Daily Message contents updated";
            case "delete":
                ListIterator iterator = Globals.getDailyMessages().getMessages().listIterator();
                while (iterator.hasNext()) {
                    DailyMessage object = (DailyMessage) iterator.next();
                    if (object.getUID() == uID) {
                        iterator.remove();
                    }
                }
                return "> Daily Message Deleted";
            case "moveday":
                if (mode.getRest() == null) {
                    return "> Missing args";
                }
                String day = mode.getRest().toUpperCase();
                try {
                    DayOfWeek dayOfWeek = DayOfWeek.valueOf(day);
                    messageObject.setDay(dayOfWeek);
                    return "> Moved message to " + dayOfWeek + ".";
                } catch (IllegalArgumentException e) {
                    return "> Not a valid day of the week.";
                }
            case "info":
                RequestHandler.sendEmbedMessage("", getInfo(messageObject, command), command.channel.get());
                return null;
            default:
                RequestHandler.sendEmbedMessage("", getInfo(messageObject, command), command.channel.get());
                return null;
        }
    } catch (NumberFormatException e) {
        return "> Invalid UID.";
    }
}
Also used : DayOfWeek(java.time.DayOfWeek) DailyMessage(com.github.vaerys.objects.DailyMessage) ListIterator(java.util.ListIterator) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 2 with SplitFirstObject

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

the class EventSetup method addMessage.

private String addMessage(TimedEvent event, String rest, CommandObject command) {
    if (rest == null)
        return "> Missing arguments.\n" + getModes();
    SplitFirstObject messageID = new SplitFirstObject(rest);
    if (messageID.getRest() == null)
        return "> Missing arguments.\n" + getModes();
    for (DailyMessage m : event.getMessages()) {
        if (m.getSpecialID().equalsIgnoreCase(messageID.getFirstWord())) {
            return "> Message Id already in use.";
        }
    }
    DayOfWeek day = null;
    SplitFirstObject message = new SplitFirstObject(messageID.getRest());
    try {
        day = DayOfWeek.valueOf(message.getFirstWord().toUpperCase());
    } catch (IllegalArgumentException e) {
    // do nothing
    }
    if (day == null) {
        event.getMessages().add(new DailyMessage(message.getAll(), day, command.user.longID, messageID.getFirstWord()));
    } else {
        event.getMessages().add(new DailyMessage(message.getRest(), day, command.user.longID, messageID.getFirstWord()));
    }
    event.setSpecialMessages(true);
    return "> New message added.";
}
Also used : DayOfWeek(java.time.DayOfWeek) DailyMessage(com.github.vaerys.objects.DailyMessage) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 3 with SplitFirstObject

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

the class EditChar method execute.

@Override
public String execute(String args, CommandObject command) {
    SplitFirstObject charName = new SplitFirstObject(args);
    if (charName.getRest() == null || charName.getRest().isEmpty()) {
        return "> Mode Not Specified";
    }
    SplitFirstObject mode = new SplitFirstObject(charName.getRest());
    for (CharacterObject c : command.guild.characters.getCharacters(command.guild.get())) {
        if (c.getName().equalsIgnoreCase(charName.getFirstWord())) {
            if (c.getUserID() == command.user.longID || GuildHandler.canBypass(command.user.get(), command.guild.get())) {
                String rest = mode.getRest();
                if (rest == null) {
                    rest = "";
                }
                command.setAuthor(command.guild.getUserByID(c.getUserID()));
                switch(mode.getFirstWord().toLowerCase()) {
                    case "age":
                        return CharEditModes.age(rest, c, command);
                    case "gender":
                        return CharEditModes.gender(rest, c, command);
                    case "avatar":
                        return CharEditModes.avatar(rest, c, command);
                    case "bio":
                        return CharEditModes.desc(rest, c, command);
                    case "longdesc":
                        return CharEditModes.longDesc(rest, c);
                    case "weight":
                        return CharEditModes.weight(rest, c, command);
                    case "height":
                        return CharEditModes.height(rest, c, command);
                    default:
                        return "> Mode not Valid.";
                }
            } else {
                return command.user.notAllowed;
            }
        }
    }
    return "> Char with that name not found.";
}
Also used : CharacterObject(com.github.vaerys.objects.CharacterObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 4 with SplitFirstObject

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

the class Sudo method execute.

@Override
public String execute(String args, CommandObject command) {
    if (!command.guild.config.debugMode)
        return "> Debug mode is disabled. No Sudo for you missy.";
    SplitFirstObject sudo = new SplitFirstObject(args);
    UserObject user = Utility.getUser(command, sudo.getFirstWord(), false, false);
    if (user == null) {
        return "> Could not find user.";
    }
    command.setAuthor(user.get());
    if (sudo.getRest() == null) {
        return "> You need to specify some arguments.";
    }
    try {
        new MessageHandler(sudo.getRest(), command, false);
    } catch (Exception e) {
        String errorPos = "";
        for (StackTraceElement s : e.getStackTrace()) {
            if (s.toString().contains("com.github.vaerys")) {
                errorPos = s.toString();
                break;
            }
        }
        StringBuilder builder = new StringBuilder();
        builder.append("> I caught an Error, Please send this Error message and the message that caused this error " + "to my **Direct Messages** so my developer can look at it and try to solve the issue.\n```\n");
        builder.append(e.getClass().getName());
        builder.append(": " + e.getMessage());
        if (!errorPos.isEmpty()) {
            builder.append("\n" + Constants.PREFIX_INDENT + "at " + errorPos);
        }
        builder.append("```");
        RequestHandler.sendMessage(builder.toString(), command.channel.get());
        Utility.sendStack(e);
    }
    return null;
}
Also used : MessageHandler(com.github.vaerys.handlers.MessageHandler) UserObject(com.github.vaerys.masterobjects.UserObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 5 with SplitFirstObject

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

the class SetGender 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)) {
        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;
    }
    int maxLength = 20;
    if (user.isPatron) {
        maxLength += 20;
    }
    ProfileObject u = user.getProfile(command.guild);
    quote = Utility.removeFun(quote);
    if (quote == null || quote.isEmpty())
        return "> You can't have an empty gender.";
    if (adminEdit) {
        if (quote.length() > maxLength) {
            return "> Gender's Length is too long...\n(Must be under " + maxLength + " chars)";
        }
        u.setGender(quote);
        return "> " + user.displayName + "'s Gender Edited";
    } else {
        if (quote.length() > maxLength) {
            return "> Your Gender's Length is too long...\n(Must be under " + maxLength + " chars)";
        }
        u.setGender(quote);
        return "> Gender Edited";
    }
}
Also used : UserObject(com.github.vaerys.masterobjects.UserObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject) ProfileObject(com.github.vaerys.objects.ProfileObject)

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