use of com.github.vaerys.enums.UserSetting in project DiscordSailv2 by Vaerys-Dawn.
the class PixelHandler method handleMessage.
/**
* Handles the sending of the level up message
*
* @param user the user that leveled up.
* @param object the container for all relevant API content.
* @param reward reward object that contains info on the reward they have received.
*/
private static void handleMessage(ProfileObject user, CommandObject object, RewardRoleObject reward) {
UserSetting defaultOverride = object.guild.config.defaultLevelMode;
UserSetting userState = user.getLevelState();
boolean rankedUp = reward != null;
IChannel levelChannel = object.guild.getChannelByType(ChannelSetting.LEVEL_UP);
IChannel currentChannel = object.channel.get();
IChannel dmChannel = object.user.getDmChannel();
IMessage levelMessage = null;
// force override
if (userState == null || defaultOverride == DONT_SEND_LVLUP || defaultOverride == SEND_LVLUP_DMS) {
userState = defaultOverride;
}
// get custom level up message.
StringHandler levelUpMessage = new StringHandler(object.guild.config.levelUpMessage);
// handle level up tags
for (TagObject t : TagList.getType(TagType.LEVEL)) {
levelUpMessage.setContent(t.handleTag(levelUpMessage.toString(), object, ""));
}
// build rank up message
if (rankedUp) {
levelUpMessage.replace("%s", "");
if (user.getSettings().contains(HIT_LEVEL_FLOOR)) {
levelUpMessage.appendFront("Welcome Back.\n");
levelUpMessage.append("\nYour **@%s** role has been returned to you.");
user.getSettings().remove(HIT_LEVEL_FLOOR);
} else {
levelUpMessage.append("\nYou have been granted the **@%s** role for reaching this level.");
}
levelUpMessage.format(reward.getRole(object).getName());
}
if (user.getCurrentLevel() == 1) {
levelUpMessage.appendFormatted("\n\n> If you want to change where these messages are sent or want" + " to remove them completely you can change that with `%s`.", Command.get(ProfileSettings.class).getUsage(object));
}
// do send message
switch(userState) {
case SEND_LVLUP_CURRENT_CHANNEL:
levelMessage = sendLevelMessage(levelUpMessage.toString(), currentChannel, rankedUp, false);
break;
case SEND_LVLUP_RANK_CHANNEL:
if (levelChannel == null) {
levelMessage = sendLevelMessage(levelUpMessage.toString(), currentChannel, rankedUp, false);
} else {
sendLevelMessage(levelUpMessage.toString(), levelChannel, rankedUp, true);
}
break;
case SEND_LVLUP_DMS:
sendLevelMessage(levelUpMessage.toString(), dmChannel, rankedUp, true);
break;
}
// self destruct level messages
if (levelMessage != null) {
selfDestruct(levelMessage, user, object);
}
}
Aggregations