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

The following examples show how to use net.dv8tion.jda.api.events.message.guild.GuildMessageDeleteEvent. 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: HistoryListener.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onGuildMessageDelete(GuildMessageDeleteEvent event) {
    if (!actionsHolderService.isOwnDeleted(event.getChannel().getId(), event.getMessageId())) {
        historyService.onMessageDelete(event.getChannel(), event.getMessageId());
    }
}
 
Example #2
Source File: CommandReactionListener.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onGuildMessageDelete(@Nonnull GuildMessageDeleteEvent event) {
    transactionHandler.runInTransaction(() -> reactionRepository.deleteByMessageId(event.getMessageIdLong()));
}
 
Example #3
Source File: MantaroListener.java    From MantaroBot with GNU General Public License v3.0 4 votes vote down vote up
private void logDelete(GuildMessageDeleteEvent event) {
    try {
        String hour = df.format(new Date(System.currentTimeMillis()));
        final ManagedDatabase db = MantaroData.db();

        final DBGuild dbGuild = db.getGuild(event.getGuild());
        final GuildData data = dbGuild.getData();

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

            CachedMessage deletedMessage = messageCache.get(event.getMessageIdLong(), Optional::empty).orElse(null);
            if (deletedMessage != null && !deletedMessage.getContent().isEmpty() && !event.getChannel().getId().equals(logChannel) && !deletedMessage.getAuthor().getId().equals(event.getJDA().getSelfUser().getId())) {
                if (data.getModlogBlacklistedPeople().contains(deletedMessage.getAuthor().getId())) {
                    return;
                }

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

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

                String message;
                if (data.getDeleteMessageLog() != null) {
                    message = new DynamicModifiers()
                            .set("hour", hour)
                            .set("content", deletedMessage.getContent().replace("```", ""))
                            .mapEvent("event", event)
                            .mapChannel("event.channel", event.getChannel())
                            .mapUser("event.user", deletedMessage.getAuthor())
                            .set("event.message.id", event.getMessageId())
                            .resolve(data.getDeleteMessageLog());
                } else {
                    message = String.format(EmoteReference.WARNING + "`[%s]` Message (ID: %s) created by **%s#%s** (ID: %s) in channel **%s** was deleted.\n" +
                            "```diff\n-%s```", hour, event.getMessageId(), deletedMessage.getAuthor().getName(), deletedMessage.getAuthor().getDiscriminator(), deletedMessage.getAuthor().getId(), event.getChannel().getName(), deletedMessage.getContent().replace("```", ""));
                }

                logTotal++;
                tc.sendMessage(message).queue();
            }
        }
    } catch (Exception e) {
        if (!(e instanceof IllegalArgumentException) && !(e instanceof NullPointerException) && !(e instanceof CacheLoader.InvalidCacheLoadException) && !(e instanceof PermissionException)) {
            log.warn("Unexpected exception while logging a deleted message.", e);
        }
    }
}
 
Example #4
Source File: MessageDeleteHandler.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Override
protected Long handleInternally(DataObject content)
{
    final long messageId = content.getLong("id");
    final long channelId = content.getLong("channel_id");

    MessageChannel channel = getJDA().getTextChannelById(channelId);
    if (channel == null)
    {
        channel = getJDA().getPrivateChannelById(channelId);
    }
    if (channel == null)
    {
        channel = getJDA().getFakePrivateChannelMap().get(channelId);
    }
    if (channel == null)
    {
        getJDA().getEventCache().cache(EventCache.Type.CHANNEL, channelId, responseNumber, allContent, this::handle);
        EventCache.LOG.debug("Got message delete for a channel/group that is not yet cached. ChannelId: {}", channelId);
        return null;
    }

    if (channel instanceof TextChannel)
    {
        TextChannelImpl tChan = (TextChannelImpl) channel;
        if (getJDA().getGuildSetupController().isLocked(tChan.getGuild().getIdLong()))
            return tChan.getGuild().getIdLong();
        if (tChan.hasLatestMessage() && messageId == channel.getLatestMessageIdLong())
            tChan.setLastMessageId(0); // Reset latest message id as it was deleted.
        getJDA().handleEvent(
                new GuildMessageDeleteEvent(
                        getJDA(), responseNumber,
                        messageId, tChan));
    }
    else
    {
        PrivateChannelImpl pChan = (PrivateChannelImpl) channel;
        if (channel.hasLatestMessage() && messageId == channel.getLatestMessageIdLong())
            pChan.setLastMessageId(0); // Reset latest message id as it was deleted.
        getJDA().handleEvent(
                new PrivateMessageDeleteEvent(
                        getJDA(), responseNumber,
                        messageId, pChan));
    }

    //Combo event
    getJDA().handleEvent(
            new MessageDeleteEvent(
                    getJDA(), responseNumber,
                    messageId, channel));
    return null;
}