Search in sources :

Example 6 with ProfileObject

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

the class ArtHandler method pinLiked.

/**
 * Handles the granting of xp to user's when their art has a :heart: reaction applied to their
 * message that was pinned with the artPinning module.
 *
 * @param command Used to parse in the variables needed to access the guild, channel, message,
 *                and user objects. these objects allows access to the api.
 * @param reacted the user that added a reaction.
 * @param owner   the user that owns the message.
 */
public static void pinLiked(CommandObject command, UserObject reacted, UserObject owner) {
    List<IChannel> channelIDS = command.guild.getChannelsByType(ChannelSetting.ART);
    // exit if not pinning art
    if (!command.guild.config.artPinning)
        return;
    // exit if pixels is off
    if (!command.guild.config.modulePixels)
        return;
    // exit if xp gain is off
    if (!command.guild.config.xpGain)
        return;
    // exit if liking art is off
    if (!command.guild.config.likeArt)
        return;
    // exit if message owner is a bot
    if (owner.get().isBot())
        return;
    // exit if there is no art channel
    if (channelIDS.size() == 0)
        return;
    // exit if this is not the art channel
    if (channelIDS.get(0).getLongID() != command.channel.longID)
        return;
    // you cant give yourself pixels via your own art
    if (owner.longID == reacted.longID)
        return;
    // exit if not pinned art
    if (!command.guild.channelData.getPinnedMessages().contains(command.message.longID))
        return;
    TrackLikes messageLikes = command.guild.channelData.getLiked(command.message.longID);
    // some thing weird happened if this is null unless its a legacy pin
    if (messageLikes == null)
        return;
    // cant like the same thing more than once
    if (messageLikes.getUsers().contains(reacted.longID))
        return;
    ProfileObject profile = owner.getProfile(command.guild);
    // exit if profile doesn't exist
    if (profile == null)
        return;
    // exit if the user should not gain pixels
    if (profile.getSettings().contains(UserSetting.NO_XP_GAIN) || profile.getSettings().contains(UserSetting.DENIED_XP))
        return;
    logger.trace(reacted.displayName + " just gave " + owner.displayName + " some pixels for liking their art.");
    // grant user xp for their nice art.
    profile.addXP(5, command.guild.config);
    messageLikes.getUsers().add(reacted.longID);
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) TrackLikes(com.github.vaerys.objects.TrackLikes) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 7 with ProfileObject

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

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

the class ResetRuleCode method execute.

@Override
public String execute(String args, CommandObject command) {
    IMessage working = RequestHandler.sendMessage("`Working...`", command.channel).get();
    for (ProfileObject p : command.guild.users.profiles) {
        if (p.getSettings().size() != 0) {
            p.getSettings().remove(UserSetting.READ_RULES);
        }
    }
    for (IUser u : command.guild.getUsers()) {
        GuildHandler.checkUsersRoles(u.getLongID(), command.guild);
    }
    RequestHandler.deleteMessage(working);
    return "Done. The Rule code tag has been removed off all profiles.";
}
Also used : IMessage(sx.blah.discord.handle.obj.IMessage) IUser(sx.blah.discord.handle.obj.IUser) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 9 with ProfileObject

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

the class ProfileSettings method execute.

@Override
public String execute(String args, CommandObject command) {
    String message = "> Your Level messages will now be sent to ";
    ProfileObject userObject = command.guild.users.getUserByID(command.user.longID);
    StringBuilder builder = new StringBuilder();
    boolean pixels = command.guild.config.modulePixels;
    boolean levelChannel = command.guild.getChannelsByType(ChannelSetting.LEVEL_UP).size() != 0;
    String error = getSettings(command) + "\n" + Utility.getCommandInfo(this, command);
    for (String s : args.split(" ")) {
        UserSetting toTest = UserSetting.get(s);
        if (toTest == null) {
            return error;
        }
        if (pixels && levelChannel && toTest == UserSetting.SEND_LVLUP_RANK_CHANNEL) {
            IChannel levelUp = command.guild.getChannelByType(ChannelSetting.LEVEL_UP);
            if (levelUp != null) {
                removeLevelSettings(userObject);
                userObject.getSettings().add(UserSetting.SEND_LVLUP_RANK_CHANNEL);
                builder.append(message + levelUp.mention() + ".");
            } else {
                removeLevelSettings(userObject);
                userObject.getSettings().add(UserSetting.SEND_LVLUP_CURRENT_CHANNEL);
                builder.append(message + "the current channel.");
            }
        } else if (pixels && toTest == UserSetting.SEND_LVLUP_CURRENT_CHANNEL) {
            removeLevelSettings(userObject);
            userObject.getSettings().add(UserSetting.SEND_LVLUP_CURRENT_CHANNEL);
            builder.append(message + "the current channel.");
        } else if (pixels && toTest == UserSetting.SEND_LVLUP_DMS) {
            removeLevelSettings(userObject);
            userObject.getSettings().add(UserSetting.SEND_LVLUP_DMS);
            builder.append(message + "your Direct messages.");
        } else if (pixels && toTest == UserSetting.DONT_SEND_LVLUP) {
            removeLevelSettings(userObject);
            userObject.getSettings().add(UserSetting.DONT_SEND_LVLUP);
            builder.append("> You will no longer see any level up messages.");
        } else if (pixels && toTest == UserSetting.NO_XP_GAIN) {
            builder.append(toggleSetting(userObject, UserSetting.NO_XP_GAIN, "> You will now gain Xp again.", "> You will no longer gain XP"));
        } else if (pixels && toTest == UserSetting.HIDE_RANK) {
            builder.append(toggleSetting(userObject, UserSetting.HIDE_RANK, "> Your rank is now visible.", "> Your rank is now hidden."));
        } else if (pixels && toTest == UserSetting.NO_LEVEL_UP_REACTIONS) {
            builder.append(toggleSetting(userObject, UserSetting.NO_LEVEL_UP_REACTIONS, "> You will now get reactions added to the message that leveled you up.", "> You will no longer get reactions added to the message that leveled you up."));
        } else if (toTest == UserSetting.PRIVATE_PROFILE) {
            builder.append(toggleSetting(userObject, UserSetting.PRIVATE_PROFILE, "> Your profile is now public.", "> Your profile is now private."));
        } else {
            if (!builder.toString().contains(error)) {
                builder.append(error);
            }
        }
        if (!builder.toString().endsWith("\n")) {
            builder.append("\n");
        }
    }
    return builder.toString();
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) ProfileObject(com.github.vaerys.objects.ProfileObject) UserSetting(com.github.vaerys.enums.UserSetting)

Example 10 with ProfileObject

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

the class RulesCode method execute.

@Override
public String execute(String args, CommandObject command) {
    if (command.guild.config.getRuleCode() == null) {
        return "> no rule code exists try again later.";
    }
    command.message.delete();
    ProfileObject profile = command.user.getProfile(command.guild);
    if (profile == null)
        return "> **" + command.user.displayName + "** An error occurred, You do not have a profile yet. please dm me this error as this should never happen.";
    if (profile.getSettings().contains(UserSetting.READ_RULES))
        return "> **" + command.user.displayName + "** You have already guessed the code correctly.";
    if (args.equalsIgnoreCase(command.guild.config.getRuleCode())) {
        profile.getSettings().add(UserSetting.READ_RULES);
        String response = "> Congratulations you have guessed the Rule Code correctly, A Star";
        if (command.guild.config.xpGain) {
            response += " and " + (int) (200 * command.guild.config.xpModifier) + " Pixels have been added to your profile.";
            profile.addXP(200, command.guild.config);
        } else {
            response += " has been added to your profile.";
        }
        IRole ruleReward = command.guild.getRuleCodeRole();
        if (ruleReward != null) {
            response += "\nYou have also been granted the **" + ruleReward.getName() + "** Role.";
        }
        GuildHandler.checkUsersRoles(command.user.longID, command.guild);
        command.user.sendDm(response);
        return null;
    }
    int diff = (command.guild.config.getRuleCode().length() / 4);
    if (diff < 2)
        diff += 2;
    if (!Pattern.compile("\\[(.|\n)*]").matcher(command.guild.config.getRuleCode()).matches() && Pattern.compile("\\[(.|\n)*]").matcher(args).matches()) {
        command.user.sendDm("> That was not the right code, please try again.\n" + "The brackets are not part of the code.");
    } else if ((Math.abs(command.guild.config.getRuleCode().length() - args.length()) <= diff) && (StringUtils.containsIgnoreCase(command.guild.config.getRuleCode(), args) || (StringUtils.containsIgnoreCase(args, command.guild.config.getRuleCode())))) {
        command.user.sendDm("> That was not the code, but you were getting close.");
        return null;
    } else {
        command.user.sendDm("> That was not the right code, please try again.\n");
    }
    return null;
}
Also used : IRole(sx.blah.discord.handle.obj.IRole) ProfileObject(com.github.vaerys.objects.ProfileObject)

Aggregations

ProfileObject (com.github.vaerys.objects.ProfileObject)34 UserObject (com.github.vaerys.masterobjects.UserObject)13 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)10 ArrayList (java.util.ArrayList)7 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)5 IChannel (sx.blah.discord.handle.obj.IChannel)5 UserSetting (com.github.vaerys.enums.UserSetting)4 RewardRoleObject (com.github.vaerys.objects.RewardRoleObject)4 IMessage (sx.blah.discord.handle.obj.IMessage)4 IUser (sx.blah.discord.handle.obj.IUser)4 CCommandObject (com.github.vaerys.objects.CCommandObject)3 ListIterator (java.util.ListIterator)3 IRole (sx.blah.discord.handle.obj.IRole)3 CommandObject (com.github.vaerys.commands.CommandObject)2 GuildObject (com.github.vaerys.masterobjects.GuildObject)2 TrackLikes (com.github.vaerys.objects.TrackLikes)2 NumberFormat (java.text.NumberFormat)2 ZonedDateTime (java.time.ZonedDateTime)2 ChannelSetting (com.github.vaerys.enums.ChannelSetting)1 SAILType (com.github.vaerys.enums.SAILType)1