Search in sources :

Example 11 with SplitFirstObject

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

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

the class CCHandler method handleCommand.

public static void handleCommand(String args, CommandObject command) {
    // cc lockout handling
    SplitFirstObject commandName = new SplitFirstObject(args);
    CCommandObject commandObject = command.guild.customCommands.getCommand(commandName.getFirstWord(), command);
    String ccArgs = commandName.getRest();
    if (ccArgs == null) {
        ccArgs = "";
    }
    if (commandObject == null)
        return;
    List<IChannel> ccDenied = command.guild.getChannelsByType(ChannelSetting.CC_DENIED);
    if (ccDenied.contains(command.channel.get())) {
        RequestHandler.sendMessage("> Custom Command usage has been disabled for this channel.", command.channel);
        return;
    }
    ProfileObject object = command.guild.users.getUserByID(command.user.longID);
    if (object != null && object.getSettings().contains(UserSetting.DENY_USE_CCS)) {
        RequestHandler.sendMessage("> Nothing interesting happens. `(ERROR: 403)`", command.channel.get());
        return;
    }
    command.guild.sendDebugLog(command, "CUSTOM_COMMAND", commandObject.getName(command), ccArgs);
    String contents = commandObject.getContents(true);
    // shitpost handling
    if (commandObject.isShitPost() && command.guild.config.shitPostFiltering && !GuildHandler.testForPerms(command, Permissions.MANAGE_CHANNELS)) {
        List<IChannel> channels = command.guild.getChannelsByType(ChannelSetting.SHITPOST);
        if (channels.size() != 0 && !channels.contains(command.channel.get())) {
            channels = command.user.getVisibleChannels(channels);
            List<String> channelMentions = Utility.getChannelMentions(channels);
            RequestHandler.sendMessage(Utility.getChannelMessage(channelMentions), command.channel.get());
            return;
        }
    }
    // tag handling
    for (TagObject t : TagList.getType(TagType.CC)) {
        contents = t.handleTag(contents, command, ccArgs);
        if (contents == null)
            return;
    }
    RequestHandler.sendMessage(contents, command.channel.get());
}
Also used : CCommandObject(com.github.vaerys.objects.CCommandObject) IChannel(sx.blah.discord.handle.obj.IChannel) TagObject(com.github.vaerys.templates.TagObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 13 with SplitFirstObject

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

the class Mute method execute.

@Override
public String execute(String args, CommandObject command) {
    SplitFirstObject userCall = new SplitFirstObject(args);
    IRole mutedRole = command.guild.getMutedRole();
    UserObject muted = Utility.getUser(command, userCall.getFirstWord(), false, false);
    if (muted == null)
        return "> Could not find user";
    if (muted.getProfile(command.guild) == null)
        muted.addProfile(command.guild);
    if (mutedRole == null)
        return "> Muted role is not configured.";
    // Un mute subtype
    if (UN_MUTE.isSubCommand(command)) {
        if (!muted.roles.contains(mutedRole))
            return "> " + muted.displayName + " is not muted.";
        command.guild.users.unMuteUser(muted.longID, command.guild.longID);
        return "> " + muted.displayName + " was UnMuted.";
    }
    if (muted.longID == command.user.longID)
        return "> Don't try to mute yourself you numpty.";
    if (!Utility.testUserHierarchy(command.client.bot.get(), mutedRole, command.guild.get()))
        return "> Cannot Mute " + muted.displayName + ". **" + mutedRole.getName() + "** role has a higher hierarchy than me.";
    if (!Utility.testUserHierarchy(command.user.get(), muted.get(), command.guild.get()))
        return "> Cannot Mute/UnMute " + muted.displayName + ". User hierarchy higher than yours.";
    StringHandler reason = new StringHandler(userCall.getRest());
    long timeSecs = Utility.getRepeatTimeValue(reason);
    boolean isStrike = false;
    // if (reason.toString().isEmpty()) return "> Reason Cannot be empty";
    // mute the offender
    command.guild.users.muteUser(muted.longID, timeSecs, command.guild.longID);
    // build the response
    // time value
    String timeValue = "";
    if (timeSecs > 0) {
        timeValue = Utility.formatTime(timeSecs, true);
    }
    if (Pattern.compile("(^⚠ | ⚠|⚠)").matcher(reason.toString()).find()) {
        reason.replaceRegex("(^⚠ | ⚠|⚠)", "");
        isStrike = true;
    }
    // setup muted messages
    // name was muted for timevalue;
    String msgFormat = "> **%s** was muted%s";
    // > name was muted for timevalue by mod in channel with `reason`;
    String adminMsg = " by %s in %s with reason `%s`.";
    // name muted with reason `reason` for timevalue in channel;
    String modnote = "Muted by %s. Reason: `%s`. Time: %s. Channel: %s.";
    IChannel adminChannel = command.guild.getChannelByType(ChannelSetting.ADMIN);
    if (reason.toString().isEmpty())
        reason.setContent("No reason given");
    // final responses:
    String responseTime = !timeValue.isEmpty() ? " for " + timeValue : "";
    String response = String.format(msgFormat, muted.mention(), responseTime);
    if (adminChannel != null) {
        RequestHandler.sendMessage(response + String.format(adminMsg, command.user.displayName, command.channel.mention, reason), adminChannel);
    }
    muted.getProfile(command.guild).addSailModNote(String.format(modnote, command.user.displayName, reason, timeValue, command.channel.mention), command, isStrike);
    return response + ".";
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) IRole(sx.blah.discord.handle.obj.IRole) UserObject(com.github.vaerys.masterobjects.UserObject) StringHandler(com.github.vaerys.handlers.StringHandler) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 14 with SplitFirstObject

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

the class UserSettings method execute.

@Override
public String execute(String args, CommandObject command) {
    if (args == null || args.isEmpty())
        return settings(command) + "\n\n" + missingArgs(command);
    SplitFirstObject split = new SplitFirstObject(args);
    UserObject user = Utility.getUser(command, split.getFirstWord(), false);
    if (user == null) {
        return "> Could not find user.";
    }
    ProfileObject profile = user.getProfile(command.guild);
    if (profile != null) {
        if (split.getRest() == null || split.getRest().equalsIgnoreCase("list")) {
            return sendList("", profile, command, user, false);
        }
        UserSetting toTest = UserSetting.get(split.getRest());
        if (toTest == null)
            return "> Not a valid user setting.\n" + settings(command);
        if (command.guild.config.modulePixels) {
            switch(toTest) {
                case DENIED_XP:
                    return toggleSetting(profile, UserSetting.DENIED_XP, "> **" + user.displayName + "** will now gain xp again.", "> **" + user.displayName + "** will no longer gain XP.");
                case DONT_SHOW_LEADERBOARD:
                    return toggleSetting(profile, UserSetting.DONT_SHOW_LEADERBOARD, "> **" + user.displayName + "'s** rank is now visible.", "> **" + user.displayName + "** will no longer show their rank.");
                case DONT_DECAY:
                    return toggleSetting(profile, UserSetting.DONT_DECAY, "> **" + user.displayName + "** will now have pixel decay.", "> **" + user.displayName + "** will no longer have pixel decay.");
                case DENY_AUTO_ROLE:
                    return toggleSetting(profile, UserSetting.DENY_AUTO_ROLE, "> **" + user.displayName + "** will now automatically be granted roles.", "> **" + user.displayName + "** will no longer automatically be granted roles.");
            }
        }
        if (command.guild.config.moduleCC) {
            switch(toTest) {
                case DENY_MAKE_CC:
                    return toggleSetting(profile, UserSetting.DENY_MAKE_CC, "> **" + user.displayName + "** can now make custom commands.", "> **" + user.displayName + "** can no longer make custom commands.");
                case DENY_USE_CCS:
                    return toggleSetting(profile, UserSetting.DENY_USE_CCS, "> **" + user.displayName + "** can now use custom commands.", "> **" + user.displayName + "** can no longer use custom commands.");
                case AUTO_SHITPOST:
                    return toggleSetting(profile, UserSetting.AUTO_SHITPOST, "> **" + user.displayName + "** no longer has the shitpost tag automatically added to all of their new Custom Commands.", "> **" + user.displayName + "** now has the shitpost tag automatically added to all of their new Custom Commands.");
            }
        }
        if (command.guild.config.artPinning) {
            switch(toTest) {
                case DENY_ART_PINNING:
                    return toggleSetting(profile, UserSetting.DENY_ART_PINNING, "> **" + user.displayName + "** can now pin art.", "> **" + user.displayName + "** can no longer pin art.");
            }
        }
        switch(toTest) {
            case DENY_INVITES:
                return toggleSetting(profile, UserSetting.DENY_INVITES, "> **" + user.displayName + "** can now post instant invites.", "> **" + user.displayName + "** can no longer post instant invites.");
            default:
                String response = (split.getRest() == null || split.getRest().isEmpty()) ? "" : "> Not a valid User Setting.\n\n";
                if (profile.getSettings().size() == 0) {
                    return response + "> **" + user.displayName + "** has no settings attached to their profile.\n\n" + settings(command) + "\n\n" + Utility.getCommandInfo(this, command);
                } else {
                    return sendList(response, profile, command, user, true);
                }
        }
    } else {
        return "> Invalid user.";
    }
}
Also used : UserObject(com.github.vaerys.masterobjects.UserObject) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject) ProfileObject(com.github.vaerys.objects.ProfileObject) UserSetting(com.github.vaerys.enums.UserSetting)

Example 15 with SplitFirstObject

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

the class PixelHelp method execute.

@Override
public String execute(String args, CommandObject command) {
    if (args.equalsIgnoreCase("Decay") && command.guild.config.xpDecay)
        return decay(command);
    if (args.equalsIgnoreCase("Rules"))
        return rules(command);
    SplitFirstObject obe = new SplitFirstObject(args);
    String mode = obe.getFirstWord();
    switch(mode.toLowerCase()) {
        case "leveltoxp":
        case "level2xp":
        case "level->xp":
            return levelToXp(obe.getRest());
        case "xptolevel":
        case "xp2level":
        case "xp->level":
            return xpToLevel(obe.getRest());
        default:
            StringBuilder builder = new StringBuilder();
            XEmbedBuilder embed = new XEmbedBuilder(command);
            embed.withTitle("Pixel System Information.");
            embed.withDescription("Pixels are " + command.client.bot.displayName + "'s" + " form of xp, you can gain " + (int) (command.guild.config.xpRate * command.guild.config.xpModifier) + "xp" + " once per minute by sending a message that meets all of the specific message rules.\n\n");
            if (command.guild.config.getRewardRoles().size() != 0) {
                for (RewardRoleObject r : command.guild.config.getRewardRoles()) {
                    IRole reward = command.guild.getRoleByID(r.getRoleID());
                    if (reward == null) {
                        break;
                    }
                    builder.append("\n> **" + reward.getName() + "** -> Level: **" + r.getLevel() + "**");
                }
                embed.appendField("Reward Roles:", builder.toString(), true);
            }
            if (command.guild.config.xpModifier != 1) {
                embed.appendField("\n**Current Xp Modifier:**\n", "> **x" + command.guild.config.xpModifier + "**.\n", true);
            }
            int random = new Random().nextInt(25);
            if (random == 1) {
                embed.withThumbnail(Constants.RANK_UP_IMAGE_URL);
            } else {
                embed.withThumbnail(Constants.LEVEL_UP_IMAGE_URL);
            }
            embed.appendField("Pixel and Level Calculators:", getModes(command) + "\n\n" + Utility.getCommandInfo(this, command), false);
            RequestHandler.sendEmbedMessage("", embed, command.channel.get());
            return null;
    }
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) RewardRoleObject(com.github.vaerys.objects.RewardRoleObject) IRole(sx.blah.discord.handle.obj.IRole) Random(java.util.Random) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

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