Search in sources :

Example 21 with CommandObject

use of com.github.vaerys.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.

the class ListModifs method getList.

public static XEmbedBuilder getList(CommandObject command) {
    String title = "> Here are the Modifier roles you can choose from:";
    List<String> list = command.guild.getModifierRoles().stream().map(iRole -> iRole.getName()).collect(Collectors.toList());
    XEmbedBuilder builder = new XEmbedBuilder(command);
    builder.withTitle(title);
    builder.withDesc("```\n" + Utility.listFormatter(list, true) + "```\n" + get(ModifierRoles.class).missingArgs(command));
    return builder;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) List(java.util.List) CommandObject(com.github.vaerys.commands.CommandObject) RequestHandler(com.github.vaerys.handlers.RequestHandler) ChannelSetting(com.github.vaerys.enums.ChannelSetting) SAILType(com.github.vaerys.enums.SAILType) Permissions(sx.blah.discord.handle.obj.Permissions) Command(com.github.vaerys.templates.Command) Utility(com.github.vaerys.main.Utility) Collectors(java.util.stream.Collectors) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder)

Example 22 with CommandObject

use of com.github.vaerys.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.

the class ListRoles method getList.

public static XEmbedBuilder getList(CommandObject command) {
    String title = "> Here are the Cosmetic roles you can choose from:";
    List<String> list = command.guild.getCosmeticRoles().stream().map(iRole -> iRole.getName()).collect(Collectors.toList());
    XEmbedBuilder builder = new XEmbedBuilder(command);
    builder.withTitle(title);
    builder.withDesc("```\n" + Utility.listFormatter(list, true) + "```\n" + get(CosmeticRoles.class).missingArgs(command));
    return builder;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) List(java.util.List) CommandObject(com.github.vaerys.commands.CommandObject) RequestHandler(com.github.vaerys.handlers.RequestHandler) ChannelSetting(com.github.vaerys.enums.ChannelSetting) SAILType(com.github.vaerys.enums.SAILType) Permissions(sx.blah.discord.handle.obj.Permissions) Command(com.github.vaerys.templates.Command) Utility(com.github.vaerys.main.Utility) Collectors(java.util.stream.Collectors) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder)

Example 23 with CommandObject

use of com.github.vaerys.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.

the class ArtHandler method checkList.

private static void checkList(CommandObject command) {
    List<Long> pinnedMessages = command.guild.channelData.getPinnedMessages();
    List<TrackLikes> likes = command.guild.channelData.getLikes();
    List<IMessage> channelpins = RequestBuffer.request(() -> command.channel.get().getPinnedMessages()).get();
    List<IMessage> markedForUnpin = new LinkedList<>();
    int pinLimit = command.guild.config.pinLimit;
    int tries = 0;
    ListIterator iterator = pinnedMessages.listIterator();
    List<Long> channelPinsLong = channelpins.stream().map(iMessage -> iMessage.getLongID()).collect(Collectors.toList());
    try {
        while (iterator.hasNext()) {
            long item = (long) iterator.next();
            if (!channelPinsLong.contains(item)) {
                iterator.remove();
            }
        }
    } catch (ConcurrentModificationException e) {
        return;
    }
    while (pinnedMessages.size() > pinLimit && tries < 50) {
        for (IMessage p : channelpins) {
            if (pinnedMessages.contains(p.getLongID()) && pinnedMessages.get(0) == p.getLongID()) {
                // adds the pin to the messages to be unpinned
                markedForUnpin.add(p);
                removePin(p, pinnedMessages);
            }
        }
        tries++;
    }
    tries = 0;
    for (IMessage message : markedForUnpin) {
        try {
            if (message.isPinned()) {
                RequestBuffer.request(() -> command.channel.get().unpin(message)).get();
                command.guild.sendDebugLog(command.setMessage(message), "ART_PINNED", "UNPIN", "PIN TOTAL = " + command.channel.getPinCount() + "/" + command.guild.config.pinLimit);
            }
        } catch (DiscordException e) {
            if (!e.getMessage().contains("Message is not pinned!")) {
                throw (e);
            }
        }
    }
    tries++;
    iterator = likes.listIterator();
    while (iterator.hasNext()) {
        TrackLikes like = (TrackLikes) iterator.next();
        if (!pinnedMessages.contains(like.getMessageID())) {
            iterator.remove();
        }
    }
}
Also used : RequestBuffer(sx.blah.discord.util.RequestBuffer) java.util(java.util) CommandObject(com.github.vaerys.commands.CommandObject) Logger(org.slf4j.Logger) TrackLikes(com.github.vaerys.objects.TrackLikes) ChannelSetting(com.github.vaerys.enums.ChannelSetting) LoggerFactory(org.slf4j.LoggerFactory) UserSetting(com.github.vaerys.enums.UserSetting) Constants(com.github.vaerys.main.Constants) Collectors(java.util.stream.Collectors) IMessage(sx.blah.discord.handle.obj.IMessage) IUser(sx.blah.discord.handle.obj.IUser) IChannel(sx.blah.discord.handle.obj.IChannel) UserObject(com.github.vaerys.masterobjects.UserObject) ProfileObject(com.github.vaerys.objects.ProfileObject) DiscordException(sx.blah.discord.util.DiscordException) IReaction(sx.blah.discord.handle.obj.IReaction) Utility(com.github.vaerys.main.Utility) IMessage(sx.blah.discord.handle.obj.IMessage) TrackLikes(com.github.vaerys.objects.TrackLikes) DiscordException(sx.blah.discord.util.DiscordException)

Example 24 with CommandObject

use of com.github.vaerys.commands.CommandObject 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 25 with CommandObject

use of com.github.vaerys.commands.CommandObject in project DiscordSailv2 by Vaerys-Dawn.

the class GuildToggle method validate.

public String validate() {
    StringBuilder response = new StringBuilder();
    boolean isError = false;
    response.append(Utility.formatError(this));
    String prefix;
    if (isModule())
        prefix = "Module";
    else
        prefix = "Setting";
    if (name() == null) {
        response.append("   > " + prefix + " type is empty.\n");
        isError = true;
    }
    if (desc(new CommandObject()) == null || desc(new CommandObject()).isEmpty()) {
        response.append("   > " + prefix + " description is empty.\n");
        isError = true;
    }
    if (isError) {
        return response.toString();
    } else {
        return null;
    }
}
Also used : CommandObject(com.github.vaerys.commands.CommandObject)

Aggregations

CommandObject (com.github.vaerys.commands.CommandObject)26 Collectors (java.util.stream.Collectors)13 SAILType (com.github.vaerys.enums.SAILType)12 ChannelSetting (com.github.vaerys.enums.ChannelSetting)11 Utility (com.github.vaerys.main.Utility)11 Command (com.github.vaerys.templates.Command)10 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)9 List (java.util.List)9 Permissions (sx.blah.discord.handle.obj.Permissions)9 RequestHandler (com.github.vaerys.handlers.RequestHandler)7 GuildHandler (com.github.vaerys.handlers.GuildHandler)6 ArrayList (java.util.ArrayList)6 UserObject (com.github.vaerys.masterobjects.UserObject)5 SubCommandObject (com.github.vaerys.objects.SubCommandObject)5 EventSubscriber (sx.blah.discord.api.events.EventSubscriber)5 GuildObject (com.github.vaerys.masterobjects.GuildObject)4 ZonedDateTime (java.time.ZonedDateTime)4 java.util (java.util)4 IChannel (sx.blah.discord.handle.obj.IChannel)4 IRole (sx.blah.discord.handle.obj.IRole)4