use of net.dv8tion.jda.core.events.Event in project MantaroBot by Mantaro.
the class MantaroListener method onUserJoin.
private void onUserJoin(GuildMemberJoinEvent event) {
try {
String role = MantaroData.db().getGuild(event.getGuild()).getData().getGuildAutoRole();
DBGuild dbg = MantaroData.db().getGuild(event.getGuild());
GuildData data = dbg.getData();
String hour = df.format(new Date(System.currentTimeMillis()));
if (role != null) {
try {
event.getGuild().getController().addRolesToMember(event.getMember(), event.getGuild().getRoleById(role)).queue(s -> log.debug("Successfully added a new role to " + event.getMember()));
} catch (PermissionException e) {
MantaroData.db().getGuild(event.getGuild()).getData().setGuildAutoRole(null);
MantaroData.db().getGuild(event.getGuild()).save();
event.getGuild().getOwner().getUser().openPrivateChannel().queue(messageChannel -> messageChannel.sendMessage("Removed autorole since I don't have the permissions to assign that role").queue());
}
}
String logChannel = MantaroData.db().getGuild(event.getGuild()).getData().getGuildLogChannel();
if (logChannel != null) {
TextChannel tc = event.getGuild().getTextChannelById(logChannel);
tc.sendMessage(String.format("`[%s]` 📣 `%s#%s` just joined `%s` `(User #%d | ID:%s)`", hour, event.getMember().getEffectiveName(), event.getMember().getUser().getDiscriminator(), event.getGuild().getName(), event.getGuild().getMembers().size(), event.getGuild().getId())).queue();
logTotal++;
}
String joinChannel = MantaroData.db().getGuild(event.getGuild()).getData().getLogJoinLeaveChannel();
String joinMessage = MantaroData.db().getGuild(event.getGuild()).getData().getJoinMessage();
if (joinChannel != null && joinMessage != null) {
TextChannel tc = event.getGuild().getTextChannelById(joinChannel);
if (joinMessage.contains("$(")) {
Map<String, String> dynamicMap = new HashMap<>();
map("event", dynamicMap, event);
joinMessage = dynamicResolve(joinMessage, dynamicMap);
}
int c = joinMessage.indexOf(':');
if (c != -1) {
String m = joinMessage.substring(0, c);
String v = joinMessage.substring(c + 1);
if (m.equals("embed")) {
EmbedJSON embed;
try {
embed = GsonDataManager.gson(false).fromJson('{' + v + '}', EmbedJSON.class);
} catch (Exception ignored) {
tc.sendMessage(EmoteReference.ERROR2 + "The string ``{" + v + "}`` isn't a valid JSON.").queue();
return;
}
tc.sendMessage(embed.gen(event)).queue();
return;
}
}
tc.sendMessage(joinMessage).queue();
}
} catch (Exception e) {
}
}
Aggregations