use of net.kodehawa.mantarobot.core.ShardMonitorEvent in project MantaroBot by Mantaro.
the class CommandListener 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.COMMAND_LISTENER);
return;
}
if (event instanceof GuildMessageReceivedEvent) {
GuildMessageReceivedEvent msg = (GuildMessageReceivedEvent) event;
messageCache.put(msg.getMessage().getId(), Optional.of(msg.getMessage()));
if (msg.getAuthor().isBot() || msg.getAuthor().equals(msg.getJDA().getSelfUser()))
return;
Async.thread("Cmd:" + msg.getAuthor().getName() + "#" + msg.getAuthor().getDiscriminator() + ":" + msg.getMessage().getRawContent(), () -> onCommand(msg));
if (random.nextInt(15) > 10) {
if (((GuildMessageReceivedEvent) event).getMember() == null)
return;
Player player = MantaroData.db().getPlayer(((GuildMessageReceivedEvent) event).getMember());
if (player != null) {
//kill me
if (player.getLevel() == 0)
player.setLevel(1);
player.getData().setExperience(player.getData().getExperience() + Math.round(random.nextInt(6)));
if (player.getData().getExperience() > (player.getLevel() * Math.log10(player.getLevel()) * 1000)) {
player.setLevel(player.getLevel() + 1);
}
player.saveAsync();
}
}
}
}
use of net.kodehawa.mantarobot.core.ShardMonitorEvent 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