net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent Java Examples

The following examples show how to use net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessageListener.java    From SkyBot with GNU Affero General Public License v3.0 6 votes vote down vote up
void onGuildMessageUpdate(GuildMessageUpdateEvent event) {
    if (topicContains(event.getChannel(), PROFANITY_FILTER_DISABLE_FLAG)) {
        return;
    }

    this.handlerThread.submit(() -> {
        final DunctebotGuild guild = new DunctebotGuild(event.getGuild(), variables);
        final GuildSettings settings = guild.getSettings();

        if (guild.getSelfMember().hasPermission(Permission.MESSAGE_MANAGE) &&
            !Objects.requireNonNull(event.getMember()).hasPermission(Permission.MESSAGE_MANAGE)) {

            if (blacklistedWordCheck(guild, event.getMessage(), event.getMember(), settings.getBlacklistedWords())) {
                return;
            }

            checkSwearFilter(event.getMessage(), event, guild);
        }
    });
}
 
Example #2
Source File: ReadyShutdownListener.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onEvent(@Nonnull GenericEvent event) {
    if (event instanceof ReadyEvent) {
        this.onReady((ReadyEvent) event);
    } else if (event instanceof GuildMessageUpdateEvent) {
        this.onGuildMessageUpdate((GuildMessageUpdateEvent) event);
    } else if (event instanceof GuildMessageReceivedEvent) {
        this.onGuildMessageReceived((GuildMessageReceivedEvent) event);
    }
}
 
Example #3
Source File: HistoryListener.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onGuildMessageUpdate(GuildMessageUpdateEvent event) {
    if (!event.getAuthor().isBot()) {
        historyService.onMessageUpdate(event.getMessage());
    }
}
 
Example #4
Source File: MantaroListener.java    From MantaroBot with GNU General Public License v3.0 4 votes vote down vote up
private void logEdit(GuildMessageUpdateEvent event) {
    try {
        String hour = df.format(new Date(System.currentTimeMillis()));
        final ManagedDatabase db = MantaroData.db();
        final GuildData guildData = db.getGuild(event.getGuild()).getData();
        String logChannel = guildData.getGuildLogChannel();

        if (logChannel != null) {
            TextChannel tc = event.getGuild().getTextChannelById(logChannel);
            if (tc == null)
                return;

            User author = event.getAuthor();
            CachedMessage editedMessage = messageCache.get(event.getMessage().getIdLong(), Optional::empty).orElse(null);

            if (editedMessage != null && !editedMessage.getContent().isEmpty() && !event.getChannel().getId().equals(logChannel)) {
                //Update message in cache in any case.
                messageCache.put(event.getMessage().getIdLong(), Optional.of(new CachedMessage(event.getAuthor().getIdLong(), event.getMessage().getContentDisplay())));

                if (guildData.getLogExcludedChannels().contains(event.getChannel().getId())) {
                    return;
                }

                if (guildData.getModlogBlacklistedPeople().contains(editedMessage.getAuthor().getId())) {
                    return;
                }

                //Don't log if content is equal but update in cache (cc: message is still relevant).
                if (event.getMessage().getContentDisplay().equals(editedMessage.getContent()))
                    return;

                if (!guildData.getModLogBlacklistWords().isEmpty()) {
                    //This is not efficient at all I'm pretty sure, is there a better way?
                    List<String> splitMessage = Arrays.asList(editedMessage.getContent().split("\\s+"));
                    if (guildData.getModLogBlacklistWords().stream().anyMatch(splitMessage::contains)) {
                        return;
                    }
                }

                String message;
                if (guildData.getEditMessageLog() != null) {
                    message = new DynamicModifiers()
                            .set("hour", hour)
                            .set("old", editedMessage.getContent().replace("```", ""))
                            .set("new", event.getMessage().getContentDisplay().replace("```", ""))
                            .mapEvent("event", event)
                            .mapChannel("event.channel", event.getChannel())
                            .mapUser("event.user", editedMessage.getAuthor())
                            .mapMessage("event.message", event.getMessage())
                            .resolve(guildData.getEditMessageLog());
                } else {
                    message = String.format(EmoteReference.WARNING + "`[%s]` Message (ID: %s) created by **%s#%s** in channel **%s** was modified.\n```diff\n-%s\n+%s```",
                            hour, event.getMessage().getId(), author.getName(), author.getDiscriminator(), event.getChannel().getName(), editedMessage.getContent().replace("```", ""), event.getMessage().getContentDisplay().replace("```", ""));
                }

                tc.sendMessage(message).queue();

                logTotal++;
            }
        }
    } catch (Exception e) {
        if (!(e instanceof NullPointerException) && !(e instanceof IllegalArgumentException) && !(e instanceof CacheLoader.InvalidCacheLoadException) && !(e instanceof PermissionException)) {
            log.warn("Unexpected error while logging a edit.", e);
        }
    }
}
 
Example #5
Source File: MessageUpdateHandler.java    From JDA with Apache License 2.0 4 votes vote down vote up
private Long handleMessage(DataObject content)
{
    Message message;
    try
    {
        message = getJDA().getEntityBuilder().createMessage(content);
    }
    catch (IllegalArgumentException e)
    {
        switch (e.getMessage())
        {
            case EntityBuilder.MISSING_CHANNEL:
            {
                final long channelId = content.getLong("channel_id");
                getJDA().getEventCache().cache(EventCache.Type.CHANNEL, channelId, responseNumber, allContent, this::handle);
                EventCache.LOG.debug("Received a message update for a channel that JDA does not currently have cached");
                return null;
            }
            case EntityBuilder.MISSING_USER:
            {
                final long authorId = content.getObject("author").getLong("id");
                getJDA().getEventCache().cache(EventCache.Type.USER, authorId, responseNumber, allContent, this::handle);
                EventCache.LOG.debug("Received a message update for a user that JDA does not currently have cached");
                return null;
            }
            default:
                throw e;
        }
    }

    switch (message.getChannelType())
    {
        case TEXT:
        {
            TextChannel channel = message.getTextChannel();
            if (getJDA().getGuildSetupController().isLocked(channel.getGuild().getIdLong()))
                return channel.getGuild().getIdLong();
            getJDA().handleEvent(
                    new GuildMessageUpdateEvent(
                            getJDA(), responseNumber,
                            message));
            break;
        }
        case PRIVATE:
        {
            getJDA().handleEvent(
                    new PrivateMessageUpdateEvent(
                            getJDA(), responseNumber,
                            message));
            break;
        }
        case GROUP:
        {
            WebSocketClient.LOG.warn("Received a MESSAGE_UPDATE for a group which is not supported");
            break;
        }

        default:
            WebSocketClient.LOG.warn("Received a MESSAGE_UPDATE with a unknown MessageChannel ChannelType. JSON: {}", content);
            return null;
    }

    //Combo event
    getJDA().handleEvent(
            new MessageUpdateEvent(
                    getJDA(), responseNumber,
                    message));
    return null;
}