use of net.dv8tion.jda.core.events.guild.member.GuildMemberJoinEvent 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) {
}
}
use of net.dv8tion.jda.core.events.guild.member.GuildMemberJoinEvent in project MantaroBot by Mantaro.
the class MantaroListener method onEvent.
@Override
public void onEvent(Event event) {
if (event instanceof ShardMonitorEvent) {
if (MantaroBot.getInstance().getShards()[shardId].getEventManager().getLastJDAEventTimeDiff() > 120000)
return;
((ShardMonitorEvent) event).alive(shardId, ShardMonitorEvent.MANTARO_LISTENER);
return;
}
if (event instanceof GuildMessageReceivedEvent) {
GuildMessageReceivedEvent e = (GuildMessageReceivedEvent) event;
Async.thread("BirthdayThread", () -> onMessage(e));
return;
}
//Log intensifies
if (event instanceof GuildMessageUpdateEvent) {
Async.thread("LogThread(Edit)", () -> logEdit((GuildMessageUpdateEvent) event));
return;
}
if (event instanceof GuildMessageDeleteEvent) {
Async.thread("LogThread(Delete)", () -> logDelete((GuildMessageDeleteEvent) event));
return;
}
if (event instanceof GuildMemberJoinEvent) {
Async.thread("LogThread(Join)", () -> onUserJoin((GuildMemberJoinEvent) event));
return;
}
if (event instanceof GuildMemberLeaveEvent) {
Async.thread("LogThread(Leave)", () -> onUserLeave((GuildMemberLeaveEvent) event));
return;
}
if (event instanceof GuildUnbanEvent) {
Async.thread("LogThread(Unban)", () -> logUnban((GuildUnbanEvent) event));
return;
}
if (event instanceof GuildBanEvent) {
Async.thread("LogThread(Ban)", () -> logBan((GuildBanEvent) event));
return;
}
if (event instanceof GuildJoinEvent) {
Async.thread("LogThread(GuildJoin)", () -> onJoin((GuildJoinEvent) event));
return;
}
if (event instanceof GuildLeaveEvent) {
Async.thread("LogThread(GuildLeave)", () -> onLeave((GuildLeaveEvent) event));
}
//debug
if (event instanceof StatusChangeEvent) {
logStatusChange((StatusChangeEvent) event);
}
if (event instanceof DisconnectEvent) {
onDisconnect((DisconnectEvent) event);
}
if (event instanceof ExceptionEvent) {
onException((ExceptionEvent) event);
}
}
Aggregations