Search in sources :

Example 1 with GuildMessageUpdateEvent

use of net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent in project Gary by help-chat.

the class LoggingHandler method execute.

@Override
protected void execute(GenericEvent event) {
    switch(EventsEnum.fromEvent(event)) {
        case MEMBER_JOIN:
            GuildMemberJoinEvent e = (GuildMemberJoinEvent) event;
            log(EventsEnum.MEMBER_JOIN, e.getJDA(), e.getGuild(), e.getUser());
            break;
        case MEMBER_LEAVE:
            if (!wasBan) {
                GuildMemberLeaveEvent e2 = (GuildMemberLeaveEvent) event;
                log(EventsEnum.MEMBER_LEAVE, e2.getJDA(), e2.getGuild(), e2.getUser());
            } else {
                wasBan = false;
            }
            break;
        case MEMBER_BANNED:
            wasBan = true;
            GuildBanEvent e3 = (GuildBanEvent) event;
            log(EventsEnum.MEMBER_BANNED, e3.getJDA(), e3.getGuild(), e3.getUser());
            break;
        case MESSAGE_EDIT:
            GuildMessageUpdateEvent e5 = (GuildMessageUpdateEvent) event;
            if (!e5.getAuthor().isBot() && StringUtils.equalsIgnoreCase(e5.getChannel().getName(), Constants.CHANNELS)) {
                log(EventsEnum.MESSAGE_EDIT, e5.getJDA(), e5.getGuild(), e5.getAuthor(), e5.getChannel(), e5.getMessage());
            }
            break;
        case MESSAGE_DELETE:
            GuildMessageDeleteEvent e6 = (GuildMessageDeleteEvent) event;
            if ((StringUtils.equalsIgnoreCase(e6.getChannel().getName(), Constants.CHANNELS))) {
                log(EventsEnum.MESSAGE_DELETE, e6.getJDA(), e6.getGuild(), MessageUtils.getAuthor(e6.getMessageIdLong()), e6.getChannel(), e6.getMessageIdLong(), MessageUtils.getMessage(e6.getMessageIdLong()));
            }
            break;
        case MESSAGE_BULK_DELETE:
            MessageBulkDeleteEvent e7 = (MessageBulkDeleteEvent) event;
            if ((StringUtils.equalsIgnoreCase(e7.getChannel().getName(), Constants.CHANNELS))) {
                log(EventsEnum.MESSAGE_BULK_DELETE, e7.getJDA(), e7.getGuild(), e7.getChannel(), e7.getMessageIds());
            }
            break;
        case VOICE_JOIN:
            GuildVoiceJoinEvent e8 = (GuildVoiceJoinEvent) event;
            log(EventsEnum.VOICE_JOIN, e8.getJDA(), e8.getGuild(), e8.getMember().getUser(), e8.getChannelJoined());
            break;
    }
}
Also used : GuildBanEvent(net.dv8tion.jda.api.events.guild.GuildBanEvent) GuildVoiceJoinEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent) GuildMemberJoinEvent(net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent) GuildMessageDeleteEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageDeleteEvent) MessageBulkDeleteEvent(net.dv8tion.jda.api.events.message.MessageBulkDeleteEvent) GuildMemberLeaveEvent(net.dv8tion.jda.api.events.guild.member.GuildMemberLeaveEvent) GuildMessageUpdateEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent)

Example 2 with GuildMessageUpdateEvent

use of net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent in project TechDiscordBot by TechsCode-Team.

the class WordBlacklistModule method onMessageUpdate.

@SubscribeEvent
public void onMessageUpdate(GuildMessageUpdateEvent e) {
    if (e.getMember() == null || e.getAuthor().isBot() || IGNORED_CATEGORIES.query().stream().anyMatch(c -> c.getId().equals(e.getChannel().getParent().getId())))
        return;
    if (runMatcher(e.getMessage().getContentRaw().toLowerCase())) {
        e.getMessage().delete().queue();
        new TechEmbedBuilder("Blocked Word(s)").color(Color.RED).text("Your message contained a world which is in our blacklist.\n\nIf you think this is a mistake, take a look at our [**word blacklist**](" + URL + ").").sendTemporary(e.getChannel(), 10, TimeUnit.SECONDS);
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) GuildMessageReceivedEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent) TechEmbedBuilder(me.TechsCode.TechDiscordBot.util.TechEmbedBuilder) GuildMessageUpdateEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent) TechDiscordBot(me.TechsCode.TechDiscordBot.TechDiscordBot) URL(java.net.URL) Category(net.dv8tion.jda.api.entities.Category) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Member(net.dv8tion.jda.api.entities.Member) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) Requirement(me.TechsCode.TechDiscordBot.objects.Requirement) SubscribeEvent(net.dv8tion.jda.api.hooks.SubscribeEvent) List(java.util.List) Matcher(java.util.regex.Matcher) Module(me.TechsCode.TechDiscordBot.module.Module) BufferedReader(java.io.BufferedReader) Pattern(java.util.regex.Pattern) DefinedQuery(me.TechsCode.TechDiscordBot.objects.DefinedQuery) Query(me.TechsCode.TechDiscordBot.objects.Query) TechEmbedBuilder(me.TechsCode.TechDiscordBot.util.TechEmbedBuilder) SubscribeEvent(net.dv8tion.jda.api.hooks.SubscribeEvent)

Example 3 with GuildMessageUpdateEvent

use of net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent in project TechDiscordBot by TechsCode-Team.

the class UrlWhitelistModule method onMessageUpdate.

@SubscribeEvent
public void onMessageUpdate(GuildMessageUpdateEvent e) {
    if (e.getMember() == null || e.getAuthor().isBot() || e.getMember().getRoles().contains(STAFF_ROLE.query().first()) || IGNORED_CATEGORIES.query().stream().anyMatch(c -> c.getId().equals(e.getChannel().getParent().getId())))
        return;
    boolean block = checkMessage(e.getMessage().getContentRaw());
    if (block) {
        e.getMessage().delete().queue();
        new TechEmbedBuilder("Blocked URL(s)").color(Color.RED).text("Your message contained a URL which is not in our whitelist.\n\nIf you think this is a mistake, take a look at our [**link whitelist**](" + URL + ").").sendTemporary(e.getChannel(), 10, TimeUnit.SECONDS);
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) GuildMessageReceivedEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent) TechEmbedBuilder(me.TechsCode.TechDiscordBot.util.TechEmbedBuilder) GuildMessageUpdateEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent) TechDiscordBot(me.TechsCode.TechDiscordBot.TechDiscordBot) URL(java.net.URL) Category(net.dv8tion.jda.api.entities.Category) Set(java.util.Set) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) Requirement(me.TechsCode.TechDiscordBot.objects.Requirement) SubscribeEvent(net.dv8tion.jda.api.hooks.SubscribeEvent) List(java.util.List) Matcher(java.util.regex.Matcher) Role(net.dv8tion.jda.api.entities.Role) Module(me.TechsCode.TechDiscordBot.module.Module) BufferedReader(java.io.BufferedReader) Pattern(java.util.regex.Pattern) DefinedQuery(me.TechsCode.TechDiscordBot.objects.DefinedQuery) Query(me.TechsCode.TechDiscordBot.objects.Query) LinkedHashSet(java.util.LinkedHashSet) TechEmbedBuilder(me.TechsCode.TechDiscordBot.util.TechEmbedBuilder) SubscribeEvent(net.dv8tion.jda.api.hooks.SubscribeEvent)

Aggregations

GuildMessageUpdateEvent (net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent)3 java.awt (java.awt)2 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 HttpURLConnection (java.net.HttpURLConnection)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 TechDiscordBot (me.TechsCode.TechDiscordBot.TechDiscordBot)2 Module (me.TechsCode.TechDiscordBot.module.Module)2 DefinedQuery (me.TechsCode.TechDiscordBot.objects.DefinedQuery)2 Query (me.TechsCode.TechDiscordBot.objects.Query)2 Requirement (me.TechsCode.TechDiscordBot.objects.Requirement)2 TechEmbedBuilder (me.TechsCode.TechDiscordBot.util.TechEmbedBuilder)2 Category (net.dv8tion.jda.api.entities.Category)2 GuildMessageReceivedEvent (net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent)2 SubscribeEvent (net.dv8tion.jda.api.hooks.SubscribeEvent)2