Search in sources :

Example 26 with ProfileObject

use of com.github.vaerys.objects.ProfileObject 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 27 with ProfileObject

use of com.github.vaerys.objects.ProfileObject 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 28 with ProfileObject

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

the class UserInfo method execute.

@Override
public String execute(String args, CommandObject command) {
    UserObject user;
    if (args == null || args.isEmpty()) {
        user = command.user;
    } else {
        user = Utility.getUser(command, args, true);
    }
    if (user == null) {
        return "> Could not find user.";
    }
    ProfileObject profile = user.getProfile(command.guild);
    if (profile == null && user.get().isBot()) {
        if (user.get().getPresence().getStatus().equals(StatusType.OFFLINE) || user.get().getPresence().getStatus().equals(StatusType.UNKNOWN)) {
            return "> Could not get a profile for " + user.displayName + ".";
        }
        profile = new ProfileObject(user.longID);
        command.guild.users.addUser(profile);
    } else if (profile == null) {
        return "> Could not get a profile for " + user.displayName + ".";
    }
    if (!GuildHandler.testForPerms(command, Permissions.ADMINISTRATOR) && (user.isPrivateProfile(command.guild) && user.longID != command.user.longID)) {
        return "> " + user.displayName + " has set their profile to private.";
    }
    // start of the profile builder.
    XEmbedBuilder builder = new XEmbedBuilder(user);
    List<IRole> roles = user.roles;
    ArrayList<String> roleNames = new ArrayList<>();
    ArrayList<String> links = new ArrayList<>();
    // If user is a bot it will display the image below as the user avatar icon.
    if (user.get().isBot()) {
        builder.withAuthorIcon("http://i.imgur.com/aRJpAP4.png");
    }
    // sets title to user Display Name;
    builder.withAuthorName(user.displayName);
    // sets thumbnail to user Avatar.
    builder.withThumbnail(user.get().getAvatarURL());
    // gets the age of the account.
    long nowUTC = ZonedDateTime.now(ZoneOffset.UTC).toEpochSecond();
    ZonedDateTime creationDate = user.get().getCreationDate().atZone(ZoneId.systemDefault()).withZoneSameInstant(ZoneOffset.UTC);
    long creationUTC = creationDate.toEpochSecond();
    long difference = nowUTC - creationUTC;
    // collect role names;
    roleNames.addAll(roles.stream().filter(role -> !role.isEveryoneRole()).map(IRole::getName).collect(Collectors.toList()));
    if (profile.getLinks() != null && profile.getLinks().size() > 0) {
        links.addAll(profile.getLinks().stream().map(link -> link.toString()).collect(Collectors.toList()));
    }
    // builds desc
    StringBuilder desc = new StringBuilder();
    StringBuilder footer = new StringBuilder();
    if (profile.getSettings().contains(UserSetting.READ_RULES) && command.guild.config.readRuleReward) {
        builder.withFooterIcon(Constants.STICKER_STAR_URL);
    // builder.withFooterIcon("https://emojipedia-us.s3.amazonaws.com/thumbs/120/twitter/120/glowing-star_1f31f.png");
    }
    if (command.guild.config.userInfoShowsDate) {
        builder.withTimestamp(user.get().getCreationDate());
        footer.append("UserID: " + profile.getUserID() + ", Creation Date");
    // desc.append("**Account Created: **" + creationDate.format(formatter));
    } else {
        desc.append("**Account Created: **" + Utility.formatTimeDifference(difference));
        footer.append("User ID: " + profile.getUserID());
    }
    builder.withFooterText(footer.toString());
    desc.append("\n**Gender: **" + profile.getGender());
    boolean showLevel = true;
    boolean showCC = command.guild.config.moduleCC;
    if (!command.guild.config.modulePixels || profile.getXP() == 0) {
        showLevel = false;
    }
    if (showCC && !showLevel) {
        desc.append("\n**Custom Commands: **" + command.guild.customCommands.getUserCommandCount(user, command.guild));
    } else if (showLevel && !showCC) {
        desc.append("\n**Level: **" + PixelHandler.xpToLevel(profile.getXP()));
    } else if (showLevel && showCC) {
        desc.append("\n**Custom Commands: **" + command.guild.customCommands.getUserCommandCount(user, command.guild) + indent + indent + indent + "**Level: **" + PixelHandler.xpToLevel(profile.getXP()));
    }
    desc.append("\n**Roles: **" + Utility.listFormatter(roleNames, true));
    desc.append("\n\n*" + profile.getQuote() + "*");
    desc.append("\n" + Utility.listFormatter(links, true));
    if (user.isPatron) {
        builder.withAuthorIcon(Constants.PATREON_ICON_URL);
    }
    builder.withDesc(desc.toString());
    // sends Message
    if (user.getProfile(command.guild).getSettings().contains(UserSetting.PRIVATE_PROFILE)) {
        RequestHandler.sendEmbedMessage("", builder, command.user.get().getOrCreatePMChannel());
        return "> Profile sent to your Direct messages.";
    }
    RequestHandler.sendEmbedMessage("", builder, command.channel.get());
    return null;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) CommandObject(com.github.vaerys.commands.CommandObject) RequestHandler(com.github.vaerys.handlers.RequestHandler) IRole(sx.blah.discord.handle.obj.IRole) StatusType(sx.blah.discord.handle.obj.StatusType) ZonedDateTime(java.time.ZonedDateTime) ChannelSetting(com.github.vaerys.enums.ChannelSetting) SAILType(com.github.vaerys.enums.SAILType) UserSetting(com.github.vaerys.enums.UserSetting) GuildHandler(com.github.vaerys.handlers.GuildHandler) Constants(com.github.vaerys.main.Constants) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) ArrayList(java.util.ArrayList) List(java.util.List) UserObject(com.github.vaerys.masterobjects.UserObject) Permissions(sx.blah.discord.handle.obj.Permissions) ProfileObject(com.github.vaerys.objects.ProfileObject) PixelHandler(com.github.vaerys.handlers.PixelHandler) Command(com.github.vaerys.templates.Command) ZoneOffset(java.time.ZoneOffset) Utility(com.github.vaerys.main.Utility) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) ArrayList(java.util.ArrayList) UserObject(com.github.vaerys.masterobjects.UserObject) ProfileObject(com.github.vaerys.objects.ProfileObject) IRole(sx.blah.discord.handle.obj.IRole) ZonedDateTime(java.time.ZonedDateTime)

Example 29 with ProfileObject

use of com.github.vaerys.objects.ProfileObject 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 30 with ProfileObject

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

the class PixelHandler method getRewardCount.

public static int getRewardCount(GuildObject object, long userID) {
    if (!object.config.modulePixels)
        return 4;
    ProfileObject userObject = object.users.getUserByID(userID);
    if (userObject == null) {
        return 0;
    }
    List<RewardRoleObject> userRewards = object.config.getAllRewards(userObject.getCurrentLevel());
    List<RewardRoleObject> allRewards = object.config.getRewardRoles();
    if (userRewards.size() == 0) {
        return 0;
    } else {
        if (allRewards.size() < 4) {
            float value = (userRewards.size() * 100.0f) / allRewards.size();
            value = value / 25;
            return (int) value;
        } else {
            if (userRewards.size() > 4) {
                return 4;
            } else {
                return userRewards.size();
            }
        }
    }
}
Also used : RewardRoleObject(com.github.vaerys.objects.RewardRoleObject) ProfileObject(com.github.vaerys.objects.ProfileObject)

Aggregations

ProfileObject (com.github.vaerys.objects.ProfileObject)34 UserObject (com.github.vaerys.masterobjects.UserObject)13 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)10 ArrayList (java.util.ArrayList)7 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)5 IChannel (sx.blah.discord.handle.obj.IChannel)5 UserSetting (com.github.vaerys.enums.UserSetting)4 RewardRoleObject (com.github.vaerys.objects.RewardRoleObject)4 IMessage (sx.blah.discord.handle.obj.IMessage)4 IUser (sx.blah.discord.handle.obj.IUser)4 CCommandObject (com.github.vaerys.objects.CCommandObject)3 ListIterator (java.util.ListIterator)3 IRole (sx.blah.discord.handle.obj.IRole)3 CommandObject (com.github.vaerys.commands.CommandObject)2 GuildObject (com.github.vaerys.masterobjects.GuildObject)2 TrackLikes (com.github.vaerys.objects.TrackLikes)2 NumberFormat (java.text.NumberFormat)2 ZonedDateTime (java.time.ZonedDateTime)2 ChannelSetting (com.github.vaerys.enums.ChannelSetting)1 SAILType (com.github.vaerys.enums.SAILType)1