Search in sources :

Example 6 with SplitFirstObject

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

the class Report method report.

public static String report(String args, CommandObject command, boolean isSilent) {
    List<IChannel> channels = command.guild.getChannelsByType(ChannelSetting.ADMIN);
    if (channels.size() != 0) {
        IChannel channel = channels.get(0);
        SplitFirstObject split = new SplitFirstObject(args);
        UserObject reported = Utility.getUser(command, split.getFirstWord(), false, false);
        if (reported == null) {
            return "> Cannot send report. Could not find user.";
        }
        if (reported.longID == command.user.longID) {
            return "> You can't report yourself.";
        }
        if (channel != null) {
            StringBuilder builder = new StringBuilder();
            IRole roleToMention = command.guild.getRoleByID(command.guild.config.getRoleToMentionID());
            if (roleToMention != null) {
                builder.append(roleToMention.mention() + "\n");
            }
            if (isSilent) {
                builder.append("**User Report - Silent**\n");
            } else {
                builder.append("**User Report**\n");
            }
            split.editRestReplace(split.getRest(), Utility.convertMentionToText(split.getRest()));
            String reason = split.getRest();
            if (split.getRest() == null) {
                reason = "No reason given.";
            }
            builder.append("Reporter: " + command.user.get().mention() + "\nReported: " + reported.get().mention() + "\nReason: `" + reason + "`");
            builder.append("\n" + command.channel.get().mention());
            IMessage message = RequestHandler.sendMessage(builder.toString(), channel).get();
            if (message == null) {
                return "> User report was not be sent. Looks like I can't send messages to " + channel.mention() + ".";
            } else {
                return "> User Report sent.";
            }
        }
        return "> Your report could not be sent as the server does not have an admin channel set up at this time.";
    } else {
        return "> Your report could not be sent as the server does not have an admin channel set up at this time.";
    }
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) 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)

Example 7 with SplitFirstObject

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

the class EditJoinMessage method execute.

@Override
public String execute(String args, CommandObject command) {
    int index;
    SplitFirstObject splitArgs = new SplitFirstObject(args);
    List<JoinMessage> messages = command.guild.channelData.getJoinMessages();
    try {
        index = Integer.parseInt(splitArgs.getFirstWord());
    } catch (NumberFormatException e) {
        return "> Not a valid number.";
    }
    index--;
    if (index < 0 || index >= messages.size()) {
        return "> Could not find message.";
    }
    if (splitArgs.getRest() == null) {
        return "> Could not find any content to edit with.";
    }
    if (!splitArgs.getRest().contains("<user>"))
        return "> Could not find <user> tag.";
    for (JoinMessage m : messages) {
        if (m.getContent().equals(splitArgs.getRest())) {
            return "> New Contents matches another Custom join message's contents, cannot have duplicate messages.";
        }
    }
    JoinMessage message = messages.get(index);
    message.setContent(splitArgs.getRest());
    return "> Contents edited.";
}
Also used : JoinMessage(com.github.vaerys.objects.JoinMessage) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 8 with SplitFirstObject

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

the class ManagePixelRoles method execute.

@Override
public String execute(String args, CommandObject command) {
    if (args.equalsIgnoreCase("list")) {
        XEmbedBuilder builder = new XEmbedBuilder(command);
        builder.withTitle("Pixel Roles");
        IRole xpDenied = command.guild.getXPDeniedRole();
        IRole topTen = command.guild.getTopTenRole();
        List<RewardRoleObject> rewardRoles = command.guild.config.getRewardRoles();
        if (xpDenied == null && topTen == null && rewardRoles.size() == 0) {
            return "> No roles are set up.\n" + missingArgs(command);
        }
        String desc = "";
        if (rewardRoles.size() != 0) {
            desc += "**Reward Roles**";
            for (RewardRoleObject r : rewardRoles) {
                desc += "\n> **" + command.guild.getRoleByID(r.getRoleID()).getName() + "** -> Level: **" + r.getLevel() + "**";
            }
            desc += "\n\n";
        }
        if (topTen != null) {
            desc += "**Top Ten Role**: " + topTen.getName() + "\n\n";
        }
        if (xpDenied != null) {
            desc += "**Pixel Denied Role**: " + xpDenied.getName();
        }
        builder.withDesc(desc);
        builder.send(command.channel);
        return null;
    }
    SplitFirstObject mode = new SplitFirstObject(args);
    IRole role = GuildHandler.getRoleFromName(mode.getRest(), command.guild.get());
    if (role == null) {
        return "> **" + mode.getRest() + "** is not a valid Role name.";
    }
    try {
        long level = Long.parseLong(mode.getFirstWord());
        if (level > 256 || level <= 0) {
            return "> Level must be between 1-256.";
        }
        for (RewardRoleObject r : command.guild.config.getRewardRoles()) {
            if (r.getLevel() == level) {
                return "> That level already has a reward set.";
            }
            if (r.getRoleID() == role.getLongID()) {
                r.setLevel(level);
                return "> Level to obtain **" + role.getName() + "** is now set to level **" + level + "**.";
            }
        }
        command.guild.config.getRewardRoles().add(new RewardRoleObject(role.getLongID(), level));
        return "> The role **" + role.getName() + "** will now be awarded at level **" + level + "**.";
    } catch (NumberFormatException e) {
        switch(mode.getFirstWord().toLowerCase()) {
            case "xpdenied":
                for (RewardRoleObject r : command.guild.config.getRewardRoles()) {
                    if (r.getRoleID() == role.getLongID()) {
                        return "> **" + role.getName() + "** is already set as a reward role.";
                    }
                }
                if (role.getLongID() == command.guild.config.topTenRoleID) {
                    return "> **" + role.getName() + "** is already set as the server's TopTen role.";
                }
                command.guild.config.xpDeniedRoleID = role.getLongID();
                return "> **" + role.getName() + "** is now the server's XpDenied role.";
            case "topten":
                for (RewardRoleObject r : command.guild.config.getRewardRoles()) {
                    if (r.getRoleID() == role.getLongID()) {
                        return "> **" + role.getName() + "** is already set as a reward role.";
                    }
                }
                if (role.getLongID() == command.guild.config.xpDeniedRoleID) {
                    return "> **" + role.getName() + "** is already set as the server's xpDenied role.";
                }
                command.guild.config.topTenRoleID = role.getLongID();
                return "> **" + role.getName() + "** is now the server's TopTen role.";
            case "remove":
                if (role.getLongID() == command.guild.config.xpDeniedRoleID) {
                    command.guild.config.xpDeniedRoleID = -1;
                    return "> **" + role.getName() + "** is no longer the server's xpDenied role.";
                } else if (role.getLongID() == command.guild.config.topTenRoleID) {
                    command.guild.config.topTenRoleID = -1;
                    return "> **" + role.getName() + "** is no longer the server's Top Ten role.";
                }
                for (RewardRoleObject r : command.guild.config.getRewardRoles()) {
                    if (r.getRoleID() == role.getLongID()) {
                        command.guild.config.getRewardRoles().remove(r);
                        return "> **" + role.getName() + "** is no longer set as a reward role.";
                    }
                }
                return "> **" + role.getName() + "** is not a valid Pixel role.";
            default:
                return "> Invalid Mode.\n" + modes + Utility.getCommandInfo(this, command);
        }
    }
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) RewardRoleObject(com.github.vaerys.objects.RewardRoleObject) IRole(sx.blah.discord.handle.obj.IRole) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 9 with SplitFirstObject

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

the class SetLevelUpReaction method execute.

@Override
public String execute(String args, CommandObject command) {
    MessageTokenizer messageTokenizer = new MessageTokenizer(command.message.get());
    Emoji emoji = EmojiManager.getByUnicode(new SplitFirstObject(args).getFirstWord());
    IEmoji customEmoji = null;
    if (args.equalsIgnoreCase("Remove")) {
        command.guild.config.levelUpReaction = "null";
        return "> Level Up reaction was removed.";
    }
    if (messageTokenizer.hasNextEmoji()) {
        customEmoji = messageTokenizer.nextEmoji().getEmoji();
    }
    if (emoji == null && customEmoji == null) {
        return "> Not a valid Emoji.";
    } else if (emoji != null) {
        command.guild.config.levelUpReaction = emoji.getUnicode();
        return "> The message a user sent to level up will now be reacted with " + emoji.getUnicode() + ".";
    } else {
        command.guild.config.levelUpReaction = customEmoji.getStringID();
        return "> The message a user sent to level up will now be reacted with " + customEmoji.toString() + ".";
    }
}
Also used : MessageTokenizer(sx.blah.discord.util.MessageTokenizer) IEmoji(sx.blah.discord.handle.obj.IEmoji) Emoji(com.vdurmont.emoji.Emoji) IEmoji(sx.blah.discord.handle.obj.IEmoji) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 10 with SplitFirstObject

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

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