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);
}
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;
}
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.";
}
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();
}
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;
}
Aggregations