use of net.kodehawa.mantarobot.core.listeners.entities.CachedMessage in project MantaroBot by Mantaro.
the class MantaroListener method logEdit.
private void logEdit(GuildMessageUpdateEvent event) {
try {
String hour = df.format(new Date(System.currentTimeMillis()));
String logChannel = MantaroData.db().getGuild(event.getGuild()).getData().getGuildLogChannel();
if (logChannel != null) {
TextChannel tc = event.getGuild().getTextChannelById(logChannel);
if (tc == null)
return;
User author = event.getAuthor();
CachedMessage editedMessage = CommandListener.getMessageCache().get(event.getMessage().getId(), Optional::empty).orElse(null);
if (editedMessage != null && !editedMessage.getContent().isEmpty() && !event.getChannel().getId().equals(logChannel)) {
if (MantaroData.db().getGuild(event.getGuild()).getData().getLogExcludedChannels().contains(event.getChannel().getId())) {
return;
}
if (MantaroData.db().getGuild(event.getGuild()).getData().getModlogBlacklistedPeople().contains(editedMessage.getAuthor().getId())) {
return;
}
tc.sendMessage(String.format(EmoteReference.WARNING + "`[%s]` Message created by **%s#%s** in channel **%s** was modified.\n```diff\n-%s\n+%s```", hour, author.getName(), author.getDiscriminator(), event.getChannel().getName(), editedMessage.getContent().replace("```", ""), event.getMessage().getContentDisplay().replace("```", ""))).queue();
CommandListener.getMessageCache().put(event.getMessage().getId(), Optional.of(new CachedMessage(event.getAuthor().getIdLong(), event.getMessage().getContentDisplay())));
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);
}
}
}
use of net.kodehawa.mantarobot.core.listeners.entities.CachedMessage in project MantaroBot by Mantaro.
the class CommandListener method onEvent.
@Override
public void onEvent(Event event) {
if (event instanceof ShardMonitorEvent) {
if (MantaroBot.getInstance().getShardedMantaro().getShards()[shardId].getEventManager().getLastJDAEventTimeDiff() > 30000)
return;
// Hey, this listener is alive! (This won't pass if somehow this is blocked)
((ShardMonitorEvent) event).alive(shardId, ShardMonitorEvent.COMMAND_LISTENER);
return;
}
if (event instanceof GuildMessageReceivedEvent) {
GuildMessageReceivedEvent msg = (GuildMessageReceivedEvent) event;
// Inserts a cached message into the cache. This only holds the id and the content, and is way lighter than saving the entire jda object.
messageCache.put(msg.getMessage().getId(), Optional.of(new CachedMessage(msg.getAuthor().getIdLong(), msg.getMessage().getContentDisplay())));
// Ignore myself and bots.
if (msg.getAuthor().isBot() || msg.getAuthor().equals(msg.getJDA().getSelfUser()))
return;
shard.getCommandPool().execute(() -> onCommand(msg));
}
}
use of net.kodehawa.mantarobot.core.listeners.entities.CachedMessage in project MantaroBot by Mantaro.
the class MantaroListener method logDelete.
private void logDelete(GuildMessageDeleteEvent event) {
try {
String hour = df.format(new Date(System.currentTimeMillis()));
String logChannel = MantaroData.db().getGuild(event.getGuild()).getData().getGuildLogChannel();
if (logChannel != null) {
TextChannel tc = event.getGuild().getTextChannelById(logChannel);
if (tc == null)
return;
CachedMessage deletedMessage = CommandListener.getMessageCache().get(event.getMessageId(), Optional::empty).orElse(null);
if (deletedMessage != null && !deletedMessage.getContent().isEmpty() && !event.getChannel().getId().equals(logChannel) && !deletedMessage.getAuthor().getId().equals(event.getJDA().getSelfUser().getId())) {
if (MantaroData.db().getGuild(event.getGuild()).getData().getModlogBlacklistedPeople().contains(deletedMessage.getAuthor().getId())) {
return;
}
if (MantaroData.db().getGuild(event.getGuild()).getData().getLogExcludedChannels().contains(event.getChannel().getId())) {
return;
}
logTotal++;
tc.sendMessage(String.format(EmoteReference.WARNING + "`[%s]` Message created by **%s#%s** in channel **%s** was deleted.\n" + "```diff\n-%s```", hour, deletedMessage.getAuthor().getName(), deletedMessage.getAuthor().getDiscriminator(), event.getChannel().getName(), deletedMessage.getContent().replace("```", ""))).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);
}
}
}
Aggregations