Search in sources :

Example 1 with ShardMonitorEvent

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();
            }
        }
    }
}
Also used : Player(net.kodehawa.mantarobot.data.entities.Player) ShardMonitorEvent(net.kodehawa.mantarobot.core.ShardMonitorEvent) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)

Example 2 with ShardMonitorEvent

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);
    }
}
Also used : ExceptionEvent(net.dv8tion.jda.core.events.ExceptionEvent) GuildJoinEvent(net.dv8tion.jda.core.events.guild.GuildJoinEvent) StatusChangeEvent(net.dv8tion.jda.core.events.StatusChangeEvent) GuildMemberJoinEvent(net.dv8tion.jda.core.events.guild.member.GuildMemberJoinEvent) GuildMemberLeaveEvent(net.dv8tion.jda.core.events.guild.member.GuildMemberLeaveEvent) GuildMessageUpdateEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageUpdateEvent) GuildLeaveEvent(net.dv8tion.jda.core.events.guild.GuildLeaveEvent) GuildBanEvent(net.dv8tion.jda.core.events.guild.GuildBanEvent) ShardMonitorEvent(net.kodehawa.mantarobot.core.ShardMonitorEvent) GuildMessageDeleteEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageDeleteEvent) GuildUnbanEvent(net.dv8tion.jda.core.events.guild.GuildUnbanEvent) DisconnectEvent(net.dv8tion.jda.core.events.DisconnectEvent) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)

Aggregations

GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)2 ShardMonitorEvent (net.kodehawa.mantarobot.core.ShardMonitorEvent)2 DisconnectEvent (net.dv8tion.jda.core.events.DisconnectEvent)1 ExceptionEvent (net.dv8tion.jda.core.events.ExceptionEvent)1 StatusChangeEvent (net.dv8tion.jda.core.events.StatusChangeEvent)1 GuildBanEvent (net.dv8tion.jda.core.events.guild.GuildBanEvent)1 GuildJoinEvent (net.dv8tion.jda.core.events.guild.GuildJoinEvent)1 GuildLeaveEvent (net.dv8tion.jda.core.events.guild.GuildLeaveEvent)1 GuildUnbanEvent (net.dv8tion.jda.core.events.guild.GuildUnbanEvent)1 GuildMemberJoinEvent (net.dv8tion.jda.core.events.guild.member.GuildMemberJoinEvent)1 GuildMemberLeaveEvent (net.dv8tion.jda.core.events.guild.member.GuildMemberLeaveEvent)1 GuildMessageDeleteEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageDeleteEvent)1 GuildMessageUpdateEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageUpdateEvent)1 Player (net.kodehawa.mantarobot.data.entities.Player)1