Search in sources :

Example 26 with UserObject

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

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

use of com.github.vaerys.masterobjects.UserObject 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)

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