use of stream.flarebot.flarebot.objects.Welcome in project FlareBot by FlareBot.
the class Events method onGuildMemberJoin.
@Override
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
if (event.getMember().getUser().isBot() || event.getMember().getUser().isFake())
return;
PlayerCache cache = flareBot.getPlayerCache(event.getMember().getUser().getId());
cache.setLastSeen(LocalDateTime.now());
GuildWrapper wrapper = FlareBotManager.instance().getGuild(event.getGuild().getId());
if (wrapper == null)
return;
if (wrapper.isBlocked())
return;
if (flareBot.getManager().getGuild(event.getGuild().getId()).getWelcome() != null) {
Welcome welcome = wrapper.getWelcome();
if ((welcome.getChannelId() != null && Getters.getChannelById(welcome.getChannelId()) != null) || welcome.isDmEnabled()) {
if (welcome.getChannelId() != null && Getters.getChannelById(welcome.getChannelId()) != null && welcome.isGuildEnabled()) {
TextChannel channel = Getters.getChannelById(welcome.getChannelId());
if (channel == null || !channel.canTalk()) {
welcome.setGuildEnabled(false);
MessageUtils.sendPM(event.getGuild().getOwner().getUser(), "Cannot send welcome messages in " + (channel == null ? welcome.getChannelId() : channel.getAsMention()) + " due to this, welcomes have been disabled!");
return;
}
if (welcome.isGuildEnabled()) {
String guildMsg = VariableUtils.parseVariables(welcome.getRandomGuildMessage(), wrapper, null, event.getUser());
// Deprecated values
guildMsg = guildMsg.replace("%user%", event.getMember().getUser().getName()).replace("%guild%", event.getGuild().getName()).replace("%mention%", event.getMember().getUser().getAsMention());
channel.sendMessage(guildMsg).queue();
if (guildMsg.contains("%user%") || guildMsg.contains("%guild%") || guildMsg.contains("%mention%")) {
MessageUtils.sendPM(event.getGuild().getOwner().getUser(), "Your guild welcome message contains deprecated variables! " + "Please check the docs at the link below for a list of all the " + "variables you can use!\n" + "https://docs.flarebot.stream/variables");
}
}
}
if (welcome.isDmEnabled()) {
// We can't DM other bots.
if (event.getMember().getUser().isBot())
return;
String dmMsg = VariableUtils.parseVariables(welcome.getRandomDmMessage(), wrapper, null, event.getUser());
// Deprecated values
dmMsg = dmMsg.replace("%user%", event.getMember().getUser().getName()).replace("%guild%", event.getGuild().getName()).replace("%mention%", event.getMember().getUser().getAsMention());
MessageUtils.sendPM(event.getMember().getUser(), dmMsg);
if (dmMsg.contains("%user%") || dmMsg.contains("%guild%") || dmMsg.contains("%mention%")) {
MessageUtils.sendPM(event.getGuild().getOwner().getUser(), "Your DM welcome message contains deprecated variables! " + "Please check the docs at the link below for a list of all the " + "variables you can use!\n" + "https://docs.flarebot.stream/variables");
}
}
} else
welcome.setGuildEnabled(false);
}
if (event.getMember().getUser().isBot())
return;
if (!wrapper.getAutoAssignRoles().isEmpty()) {
Set<String> autoAssignRoles = wrapper.getAutoAssignRoles();
List<Role> roles = new ArrayList<>();
for (String s : autoAssignRoles) {
Role role = event.getGuild().getRoleById(s);
if (role != null) {
roles.add(role);
} else
autoAssignRoles.remove(s);
}
try {
event.getGuild().getController().addRolesToMember(event.getMember(), roles).queue((n) -> {
}, e1 -> handle(e1, event, roles));
StringBuilder sb = new StringBuilder("```\n");
for (Role role : roles) {
sb.append(role.getName()).append(" (").append(role.getId()).append(")\n");
}
sb.append("```");
ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.FLAREBOT_AUTOASSIGN_ROLE, event.getUser(), new MessageEmbed.Field("Roles", sb.toString(), false));
} catch (Exception e1) {
handle(e1, event, roles);
}
}
}
Aggregations