Search in sources :

Example 11 with CommandObject

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

the class GetGlobalStats method execute.

@Override
public String execute(String args, CommandObject command) {
    ArrayList<ToggleStatsObject> toggleStats = new ArrayList<>();
    ArrayList<String> outToggles = new ArrayList<>();
    ArrayList<String> outModules = new ArrayList<>();
    // ArrayList<ChannelStatsObject> channelStats = new ArrayList<>();
    for (GuildToggle g : Globals.getGuildToggles()) {
        toggleStats.add(new ToggleStatsObject(g.name().toString(), g.isModule()));
    }
    // for (ChannelSetting c : Globals.getChannelSettings()) {
    // channelStats.add(new ChannelStatsObject(c.type(), c.isSetting()));
    // }
    long totalXpUsers = 0;
    long totalXP = 0;
    for (GuildObject g : Globals.getGuilds()) {
        CommandObject object = command.setGuild(g.get());
        for (ToggleStatsObject s : toggleStats) {
            for (GuildToggle t : object.guild.toggles) {
                if (t.name().toString().equalsIgnoreCase(s.getToggle())) {
                    if (t.isModule()) {
                        s.addOne();
                    } else if (t.enabled(object.guild.config) != t.getDefault()) {
                        s.addOne();
                    }
                }
            }
        }
        // }
        if (command.guild.config.modulePixels) {
            for (ProfileObject o : command.guild.users.getProfiles()) {
                if (o.getXP() != 0) {
                    totalXP += o.getXP();
                    totalXpUsers++;
                }
            }
        }
    }
    for (ToggleStatsObject t : toggleStats) {
        String formatted = t.getToggle() + ": " + t.getCount();
        if (t.isModule()) {
            outModules.add(formatted);
        } else {
            outToggles.add(formatted);
        }
    }
    StringBuilder output = new StringBuilder();
    output.append("**[GLOBAL STATS]**");
    output.append("\n\n**[TOGGLE STATS]**\n");
    output.append(Utility.listFormatter(outToggles, false));
    output.append("\n\n**[MODULE STATS]**\n");
    output.append(Utility.listFormatter(outModules, false));
    output.append("\n\n**[PIXEL STATS]**");
    output.append("\nAvg Pixels: " + totalXP / totalXpUsers);
    command.user.sendDm(output.toString());
    return "> Data sent to Your DMs";
// int totalGlobalUsers = 0;
// int totalAvg = 0;
// for (IGuild guild : command.client.getGuilds()) {
// StringBuilder builder = new StringBuilder();
// long totalUsers = 0;
// long totalMessage = 0;
// long totalMessageAvg = 0;
// long topGuild = 0;
// long bottomGuild = 0;
// String topUser = null;
// String bottomUser = null;
// GuildContentObject content = Globals.getGuildContent(guild.getLongID());
// for (UserTypeObject user : content.getGuildUsers().getProfiles()) {
// if (bottomGuild == 0) {
// bottomGuild = user.getXP();
// bottomUser = user.getID();
// } else if (bottomGuild > user.getXP()) {
// bottomGuild = user.getXP();
// bottomUser = user.getID();
// }
// if (topGuild == 0) {
// topGuild = user.getXP();
// topUser = user.getID();
// } else if (topGuild < user.getXP()) {
// topGuild = user.getXP();
// topUser = user.getID();
// }
// totalMessage += user.getXP();
// totalGlobalUsers++;
// totalUsers++;
// }
// builder.append("**Guild: " + guild.getNames() + "**");
// IUser topIUser = command.client.getUserByID(topUser);
// IUser bottomIUser = command.client.getUserByID(bottomUser);
// if (topIUser != null && bottomIUser != null) {
// builder.append("\nTop User = @" + command.client.getUserByID(topUser).getNames() + "#" + command.client.getUserByID(topUser).getDiscriminator());
// builder.append(" With Total Messages " + topGuild);
// builder.append("\nBottom User = @" + command.client.getUserByID(bottomUser).getNames() + "#" + command.client.getUserByID(bottomUser).getDiscriminator());
// builder.append(" With Total Messages " + bottomGuild);
// builder.append("\nGuild Avg = " + totalMessageAvg / totalUsers);
// builder.append("\nTotal Guild Messages = " + totalMessage);
// builder.append("\nTotal Users = " + totalUsers);
// Utility.sendDM(builder.toString(), command.authorSID);
// }
// try {
// Thread.sleep(2000);
// } catch (InterruptedException e) {
// Utility.sendStack(e);
// }
// }
// StringBuilder builder = new StringBuilder("**Global Stats**");
// builder.append("\nGlobal profiles = " + totalGlobalUsers);
// builder.append("\nGlobal Avg = " + totalAvg / totalGlobalUsers);
// Utility.sendDM(builder.toString(), command.authorSID);
// return null;
}
Also used : CommandObject(com.github.vaerys.commands.CommandObject) GuildObject(com.github.vaerys.masterobjects.GuildObject) GuildToggle(com.github.vaerys.templates.GuildToggle) ToggleStatsObject(com.github.vaerys.objects.ToggleStatsObject) ArrayList(java.util.ArrayList) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 12 with CommandObject

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

the class ListChars method execute.

@Override
public String execute(String args, CommandObject command) {
    XEmbedBuilder builder = new XEmbedBuilder(command);
    UserObject user = command.user;
    String title = "> Here are all of your characters.";
    // get user
    if (args != null && !args.isEmpty()) {
        user = Utility.getUser(command, args, true);
        if (user == null) {
            return "> Could not find user.";
        }
        if (user.longID != command.user.longID) {
            title = "> Here are all of @" + user.displayName + "'s Characters.";
        }
    }
    // check private
    if (user.isPrivateProfile(command.guild) && user.longID != command.user.longID) {
        return "> User has set their profile to private.";
    }
    // generate list
    List<String> list = user.characters.stream().map(c -> c.getName()).collect(Collectors.toList());
    // give message if empty
    if (list.size() == 0) {
        return "> You do not have any characters yet. Create one with **" + new UpdateChar().getUsage(command) + "**.";
    }
    // build embed data
    builder.withTitle(title);
    builder.withDesc("```\n" + Utility.listFormatter(list, true) + "```\n" + new CharInfo().missingArgs(command));
    builder.withFooterText(user.characters.size() + "/" + command.guild.characters.maxCharsForUser(user, command.guild) + " Slots used.");
    // send private char list
    if (user.getProfile(command.guild).getSettings().contains(UserSetting.PRIVATE_PROFILE)) {
        RequestHandler.sendEmbedMessage("", builder, command.user.get().getOrCreatePMChannel());
        return "> Char list sent to your Direct messages.";
    }
    // send regular
    RequestHandler.sendEmbedMessage("", builder, command.channel.get());
    return null;
}
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) UserObject(com.github.vaerys.masterobjects.UserObject) SAILType(com.github.vaerys.enums.SAILType) Permissions(sx.blah.discord.handle.obj.Permissions) UserSetting(com.github.vaerys.enums.UserSetting) Command(com.github.vaerys.templates.Command) Utility(com.github.vaerys.main.Utility) Collectors(java.util.stream.Collectors) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) UserObject(com.github.vaerys.masterobjects.UserObject)

Example 13 with CommandObject

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

the class UpdateChar method execute.

@Override
public String execute(String args, CommandObject command) {
    List<CharacterObject> userChars = command.user.characters;
    String charName = args.split(" ")[0];
    CharacterObject selectedChar = command.guild.characters.getCharByName(charName);
    List<IRole> cosmeticRoles = command.user.getCosmeticRoles(command);
    List<Long> cosmeticRoleIDs = cosmeticRoles.stream().map(iRole -> iRole.getLongID()).collect(Collectors.toList());
    String cosmeticString = command.guild.config.moduleRoles ? " and cosmetic roles" : "";
    if (selectedChar != null) {
        if (selectedChar.getUserID() != command.user.longID) {
            return "> That is not your character you cannot update it.";
        }
        if (selectedChar.getNickname().equals(command.user.displayName) && selectedChar.getRoleIDs().containsAll(cosmeticRoleIDs)) {
            return "> You haven't updated your details since the last time this character was updated.\n" + "Characters use your nickname " + cosmeticString + " to use as data.";
        }
        selectedChar.update(command.user.displayName, cosmeticRoles);
        String response = "> Your character has been updated using your nickname" + cosmeticString + ".";
        if (!UPDATE_CHAR.isSubCommand(command)) {
            response += "\nIf you were attempting to create a new character and not edit this character you need to specify a different character ID.";
        }
        return response;
    } else {
        int maxChars = command.guild.characters.maxCharsForUser(command);
        int rewardCount = command.user.getRewardValue(command);
        if (userChars.size() == maxChars) {
            if (command.guild.config.modulePixels && command.guild.config.xpGain && rewardCount != 4) {
                return "> You have reached the maximum allowed characters for your level," + " you will have to either rank up or delete an old character to make room.";
            }
            return "> You have reached the maximum allowed characters. You will have to delete an old character to make room.";
        }
        command.guild.characters.addChar(charName, cosmeticRoles, command.user);
        int remainingSlots = (maxChars - userChars.size() - 1);
        String response = "> New Character Created using your nickname " + cosmeticString + " to fill in data." + "\n(" + remainingSlots + " Character slot";
        if (remainingSlots != 1)
            response += "s";
        response += " remaining)";
        if (!UPDATE_CHAR.isSubCommand(command)) {
            response += "\nTo update the name";
            if (command.guild.config.moduleRoles)
                response += " or roles";
            response += " linked to this character just run this command again.";
        }
        return response;
    }
}
Also used : SubCommandObject(com.github.vaerys.objects.SubCommandObject) List(java.util.List) CommandObject(com.github.vaerys.commands.CommandObject) IRole(sx.blah.discord.handle.obj.IRole) CharacterObject(com.github.vaerys.objects.CharacterObject) 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) Collectors(java.util.stream.Collectors) CharacterObject(com.github.vaerys.objects.CharacterObject) IRole(sx.blah.discord.handle.obj.IRole)

Example 14 with CommandObject

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

the class UpdateRolePerms method execute.

@Override
public String execute(String args, CommandObject command) {
    List<IRole> parentRole = GuildHandler.getRolesByName(command.guild.get(), args);
    EnumSet parentPerms = command.guild.get().getEveryoneRole().getPermissions();
    ArrayList<String> permList = new ArrayList<>();
    IMessage workingMsg = RequestHandler.sendMessage("`Working...`", command.channel.get()).get();
    if (parentRole.size() != 0) {
        if (command.guild.config.isRoleCosmetic(parentRole.get(0).getLongID())) {
            parentPerms = parentRole.get(0).getPermissions();
        }
    }
    for (IRole r : command.guild.get().getRoles()) {
        if (command.guild.config.isRoleCosmetic(r.getLongID())) {
            if (!r.getPermissions().containsAll(parentPerms)) {
                EnumSet finalParentPerms = parentPerms;
                RequestBuffer.request(() -> r.changePermissions(finalParentPerms));
            }
        }
    }
    for (Object p : parentPerms.toArray()) {
        permList.add(p.toString());
    }
    RequestHandler.deleteMessage(workingMsg);
    return "> Cosmetic Roles Perms set to : " + Utility.listFormatter(permList, true);
}
Also used : IRole(sx.blah.discord.handle.obj.IRole) EnumSet(java.util.EnumSet) IMessage(sx.blah.discord.handle.obj.IMessage) ArrayList(java.util.ArrayList) CommandObject(com.github.vaerys.commands.CommandObject)

Example 15 with CommandObject

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

the class Command method validate.

public String validate() {
    StringBuilder response = new StringBuilder();
    boolean isError = false;
    response.append(Utility.formatError(this));
    if (names.length == 0 || names[0].isEmpty()) {
        response.append("   > Command name is empty.\n");
        isError = true;
    }
    if (description(new CommandObject()) == null || description(new CommandObject()).isEmpty()) {
        response.append("   > Command description is empty.\n");
        isError = true;
    }
    if (type == null) {
        response.append("   > Command type is empty.\n");
        isError = true;
    }
    if (requiresArgs && (usage == null || usage.isEmpty())) {
        response.append("   > Command usage is null when requiresArgs is true.\n");
        isError = true;
    }
    if (isError) {
        return response.toString();
    } else {
        return null;
    }
}
Also used : CommandObject(com.github.vaerys.commands.CommandObject) SubCommandObject(com.github.vaerys.objects.SubCommandObject)

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