Search in sources :

Example 16 with UserObject

use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.

the class JoinMessageInfo method execute.

@Override
public String execute(String args, CommandObject command) {
    int index;
    List<JoinMessage> messages = command.guild.channelData.getJoinMessages();
    XEmbedBuilder builder = new XEmbedBuilder(command);
    try {
        index = Integer.parseInt(args);
    } catch (NumberFormatException e) {
        return "> Not a valid number.";
    }
    index--;
    if (index < 0 || index >= messages.size()) {
        return "> Could not find message.";
    }
    JoinMessage message = messages.get(index);
    builder.withTitle("Message #" + (index + 1));
    builder.withDesc(message.getContent());
    UserObject user = new UserObject(message.getCreator(), command.guild);
    if (user.get() == null) {
        builder.withFooterText("Could not find user.");
    } else {
        builder.withFooterText("Creator: @" + user.username);
        builder.withFooterIcon(user.getAvatarURL());
    }
    builder.send(command.channel);
    return null;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) JoinMessage(com.github.vaerys.objects.JoinMessage) UserObject(com.github.vaerys.masterobjects.UserObject)

Example 17 with UserObject

use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.

the class EditXp method execute.

@Override
public String execute(String args, CommandObject command) {
    String[] splitArgs = args.split(" ");
    boolean xpChanged = false;
    UserObject user = Utility.getUser(command, splitArgs[0], false);
    if (user == null)
        return "> Could not find user.";
    if (Utility.testUserHierarchy(user, command.user, command.guild)) {
        return "> You do not have permission to edit " + user.displayName + "'s pixels.";
    }
    long pixelAmount;
    try {
        if (isSubType(command)) {
            if (splitArgs.length < 2)
                return getMissingArgsSubCommand(command);
            pixelAmount = Long.parseLong(splitArgs[1]);
        } else {
            if (splitArgs.length < 3)
                return missingArgs(command);
            pixelAmount = Long.parseLong(splitArgs[2]);
        }
    } catch (NumberFormatException e) {
        String value = isSubType(command) ? splitArgs[1] : splitArgs[2];
        return "> **" + value + "** Not a valid Number.";
    }
    if (pixelAmount < 0)
        return "> I don't know what negative pixels are. What are you trying to do?";
    if (pixelAmount > Constants.PIXELS_CAP)
        return "> That's too many pixels for me to be working with. (Max: " + Constants.PIXELS_CAP + ")";
    ProfileObject profile = user.getProfile(command.guild);
    if (profile == null)
        return "> " + user.displayName + " doesn't have a profile yet.";
    String out;
    if (SET_XP.isSubCommand(command)) {
        out = setXp(profile, pixelAmount, user);
        xpChanged = true;
    } else if (ADD_XP.isSubCommand(command)) {
        out = addXp(profile, pixelAmount, user);
        xpChanged = true;
    } else if (DEL_XP.isSubCommand(command)) {
        out = delXp(profile, pixelAmount, user);
        xpChanged = true;
    } else {
        String modif = splitArgs[1].toLowerCase();
        switch(modif) {
            case "+":
            case "add":
                out = addXp(profile, pixelAmount, user);
                xpChanged = true;
                break;
            case "-":
            case "rem":
            case "sub":
                out = delXp(profile, pixelAmount, user);
                xpChanged = true;
                break;
            case "=":
            case "set":
                out = setXp(profile, pixelAmount, user);
                xpChanged = true;
                break;
            default:
                out = "> Invalid modifier. Valid modifiers are **[+/-/=]** or **add/sub/set**";
                break;
        }
    }
    if (xpChanged) {
        profile.removeLevelFloor();
        GuildHandler.checkUsersRoles(user.longID, command.guild);
    }
    return out;
}
Also used : UserObject(com.github.vaerys.masterobjects.UserObject) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 18 with UserObject

use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.

the class SetXp 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 xp = Long.parseLong(xpArgs.getRest());
        ProfileObject userObject = user.getProfile(command.guild);
        if (userObject != null) {
            userObject.setXp(xp);
            userObject.removeLevelFloor();
            GuildHandler.checkUsersRoles(user.longID, command.guild);
            return "> " + user.displayName + "'s Pixels is now set to: **" + xp + "**";
        } else {
            return "> User does not have a profile.";
        }
    } 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 19 with UserObject

use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.

the class TopUserForRole method execute.

@Override
public String execute(String args, CommandObject command) {
    // init index value
    int index = 1;
    // try to get role.
    IRole role = GuildHandler.getRoleFromName(args, command.guild.get());
    if (role == null) {
        try {
            // if role get fails, try again, but this time assume the first "word" is the rank the user wants to get.
            index = Integer.parseInt(new SplitFirstObject(args).getFirstWord());
        } catch (NumberFormatException e) {
            // not a valid number, can't find role, bork.
            return "> Invalid Role";
        }
        // remove index from string, try to get role again.
        args = new SplitFirstObject(args).getRest();
        role = GuildHandler.getRoleFromName(args, command.guild.get());
        if (role == null)
            return "> Invalid Role.";
    }
    IMessage working = RequestHandler.sendMessage("`Working...`", command.channel.get()).get();
    // populate list with users with role defined.
    List<Long> userIDs = command.guild.get().getUsersByRole(role).stream().map(IUser::getLongID).collect(Collectors.toList());
    if (userIDs.isEmpty()) {
        RequestHandler.deleteMessage(working);
        return "> Could not find any users with that role!";
    }
    userIDs.removeIf(f -> PixelHandler.rank(command.guild.users, command.guild.get(), f) == -1);
    userIDs.sort((o1, o2) -> {
        long rank1 = PixelHandler.rank(command.guild.users, command.guild.get(), o1);
        long rank2 = PixelHandler.rank(command.guild.users, command.guild.get(), o2);
        return Long.compare(rank1, rank2);
    });
    if (userIDs.size() == 0)
        return "> Could not find any ranked users with that role.";
    if (index > userIDs.size()) {
        RequestHandler.deleteMessage(working);
        return "> There's only " + userIDs.size() + (userIDs.size() == 1 ? " user" : " users") + " with that role.";
    }
    if (index == 1) {
        // show an embed with the top (at most) 5 users instead.
        RequestHandler.deleteMessage(working);
        getEmbed(command, role, userIDs);
        return null;
    }
    ProfileObject topUserProfile = command.guild.users.getUserByID(userIDs.get(index - 1));
    UserObject topUser = topUserProfile.getUser(command.guild);
    NumberFormat nf = NumberFormat.getInstance();
    RequestHandler.deleteMessage(working);
    return "> @" + topUser.username + ", **Pixels:** " + nf.format(topUserProfile.getXP()) + ", **Level:** " + topUserProfile.getCurrentLevel() + ", **User ID:** " + topUser.longID;
}
Also used : IRole(sx.blah.discord.handle.obj.IRole) IMessage(sx.blah.discord.handle.obj.IMessage) UserObject(com.github.vaerys.masterobjects.UserObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject) ProfileObject(com.github.vaerys.objects.ProfileObject) NumberFormat(java.text.NumberFormat)

Example 20 with UserObject

use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.

the class TopUserForRole method getEmbed.

private void getEmbed(CommandObject command, IRole role, List<Long> userIDs) {
    XEmbedBuilder embed = new XEmbedBuilder(command);
    int showing = (userIDs.size() > 5 ? 5 : userIDs.size());
    embed.withTitle("Top " + (userIDs.size() == 1 ? " user" : showing + " users") + " for role " + role.getName());
    embed.withFooterText("Total ranked users with this role: " + userIDs.size());
    ProfileObject userProfile;
    UserObject userObject;
    NumberFormat nf = NumberFormat.getInstance();
    String titlef = "#%s. %s";
    String contentf = "**XP:** %s\t**Level:** %s\n**UID:** %s";
    for (int i = 0; i < showing; i++) {
        userProfile = command.guild.users.getUserByID(userIDs.get(i));
        userObject = userProfile.getUser(command.guild);
        embed.appendField(String.format(titlef, i + 1, userObject.displayName), String.format(contentf, nf.format(userProfile.getXP()), userProfile.getCurrentLevel(), userObject.longID), false);
    }
    embed.send(command.channel);
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) UserObject(com.github.vaerys.masterobjects.UserObject) ProfileObject(com.github.vaerys.objects.ProfileObject) NumberFormat(java.text.NumberFormat)

Aggregations

UserObject (com.github.vaerys.masterobjects.UserObject)28 ProfileObject (com.github.vaerys.objects.ProfileObject)13 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)10 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)8 IRole (sx.blah.discord.handle.obj.IRole)5 CommandObject (com.github.vaerys.commands.CommandObject)4 ChannelSetting (com.github.vaerys.enums.ChannelSetting)4 SAILType (com.github.vaerys.enums.SAILType)4 ArrayList (java.util.ArrayList)4 UserSetting (com.github.vaerys.enums.UserSetting)3 RequestHandler (com.github.vaerys.handlers.RequestHandler)3 StringHandler (com.github.vaerys.handlers.StringHandler)3 GuildObject (com.github.vaerys.masterobjects.GuildObject)3 Command (com.github.vaerys.templates.Command)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ReactionEmoji (sx.blah.discord.handle.impl.obj.ReactionEmoji)3 IChannel (sx.blah.discord.handle.obj.IChannel)3 IMessage (sx.blah.discord.handle.obj.IMessage)3 GuildHandler (com.github.vaerys.handlers.GuildHandler)2