Search in sources :

Example 1 with GuildMemberRoleAddEvent

use of net.dv8tion.jda.core.events.guild.member.GuildMemberRoleAddEvent in project MantaroBot by Mantaro.

the class MantaroListener method onEvent.

@Override
public void onEvent(Event event) {
    if (event instanceof ShardMonitorEvent) {
        if (MantaroBot.getInstance().getShardedMantaro().getShards()[shardId].getEventManager().getLastJDAEventTimeDiff() > 30000)
            return;
        ((ShardMonitorEvent) event).alive(shardId, ShardMonitorEvent.MANTARO_LISTENER);
        return;
    }
    if (event instanceof GuildMessageReceivedEvent) {
        MantaroBot.getInstance().getStatsClient().increment("messages_received");
        GuildMessageReceivedEvent e = (GuildMessageReceivedEvent) event;
        onMessage(e);
        return;
    }
    if (event instanceof GuildMemberJoinEvent) {
        shard.getThreadPool().execute(() -> onUserJoin((GuildMemberJoinEvent) event));
        return;
    }
    if (event instanceof GuildMemberLeaveEvent) {
        shard.getThreadPool().execute(() -> onUserLeave((GuildMemberLeaveEvent) event));
        return;
    }
    // Doesn't run on the thread pool as there's no need for it.
    if (event instanceof GuildMemberRoleAddEvent) {
        // It only runs on the thread pool if needed.
        handleNewPatron((GuildMemberRoleAddEvent) event);
    }
    if (event instanceof GuildMessageUpdateEvent) {
        logEdit((GuildMessageUpdateEvent) event);
        return;
    }
    if (event instanceof GuildMessageDeleteEvent) {
        logDelete((GuildMessageDeleteEvent) event);
        return;
    }
    if (event instanceof GuildUnbanEvent) {
        logUnban((GuildUnbanEvent) event);
        return;
    }
    if (event instanceof GuildBanEvent) {
        logBan((GuildBanEvent) event);
        return;
    }
    // Internal events
    if (event instanceof GuildJoinEvent) {
        GuildJoinEvent e = (GuildJoinEvent) event;
        if (e.getGuild().getSelfMember().getJoinDate().isBefore(OffsetDateTime.now().minusSeconds(30)))
            return;
        onJoin(e);
        if (MantaroCore.hasLoadedCompletely()) {
            MantaroBot.getInstance().getStatsClient().gauge("guilds", MantaroBot.getInstance().getGuildCache().size());
            MantaroBot.getInstance().getStatsClient().gauge("users", MantaroBot.getInstance().getUserCache().size());
        }
        return;
    }
    if (event instanceof GuildLeaveEvent) {
        onLeave((GuildLeaveEvent) event);
        if (MantaroCore.hasLoadedCompletely()) {
            MantaroBot.getInstance().getStatsClient().gauge("guilds", MantaroBot.getInstance().getGuildCache().size());
            MantaroBot.getInstance().getStatsClient().gauge("users", MantaroBot.getInstance().getUserCache().size());
        }
        return;
    }
    // debug
    if (event instanceof StatusChangeEvent) {
        logStatusChange((StatusChangeEvent) event);
        return;
    }
    if (event instanceof DisconnectEvent) {
        onDisconnect((DisconnectEvent) event);
        return;
    }
    if (event instanceof ExceptionEvent) {
        MantaroBot.getInstance().getStatsClient().increment("exceptions");
        onException((ExceptionEvent) event);
        return;
    }
    if (event instanceof HttpRequestEvent) {
        MantaroBot.getInstance().getStatsClient().incrementCounter("http_requests");
        return;
    }
    if (event instanceof ReconnectedEvent) {
        MantaroBot.getInstance().getStatsClient().increment("shard.reconnect");
        MantaroBot.getInstance().getStatsClient().recordEvent(com.timgroup.statsd.Event.builder().withTitle("shard.reconnect").withText("Shard reconnected").withDate(new Date()).build());
        return;
    }
    if (event instanceof ResumedEvent) {
        MantaroBot.getInstance().getStatsClient().increment("shard.resume");
        MantaroBot.getInstance().getStatsClient().recordEvent(com.timgroup.statsd.Event.builder().withTitle("shard.resume").withText("Shard resumed").withDate(new Date()).build());
    }
}
Also used : GuildJoinEvent(net.dv8tion.jda.core.events.guild.GuildJoinEvent) HttpRequestEvent(net.dv8tion.jda.core.events.http.HttpRequestEvent) GuildMemberJoinEvent(net.dv8tion.jda.core.events.guild.member.GuildMemberJoinEvent) GuildMemberRoleAddEvent(net.dv8tion.jda.core.events.guild.member.GuildMemberRoleAddEvent) 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) Date(java.util.Date) GuildBanEvent(net.dv8tion.jda.core.events.guild.GuildBanEvent) ShardMonitorEvent(net.kodehawa.mantarobot.core.listeners.events.ShardMonitorEvent) GuildMessageDeleteEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageDeleteEvent) GuildUnbanEvent(net.dv8tion.jda.core.events.guild.GuildUnbanEvent) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)

Aggregations

Date (java.util.Date)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 GuildMemberRoleAddEvent (net.dv8tion.jda.core.events.guild.member.GuildMemberRoleAddEvent)1 HttpRequestEvent (net.dv8tion.jda.core.events.http.HttpRequestEvent)1 GuildMessageDeleteEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageDeleteEvent)1 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)1 GuildMessageUpdateEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageUpdateEvent)1 ShardMonitorEvent (net.kodehawa.mantarobot.core.listeners.events.ShardMonitorEvent)1