use of net.dv8tion.jda.api.events.guild.GuildUnbanEvent in project JDA by DV8FromTheWorld.
the class GuildBanHandler method handleInternally.
@Override
protected Long handleInternally(DataObject content) {
final long id = content.getLong("guild_id");
if (getJDA().getGuildSetupController().isLocked(id))
return id;
DataObject userJson = content.getObject("user");
GuildImpl guild = (GuildImpl) getJDA().getGuildById(id);
if (guild == null) {
getJDA().getEventCache().cache(EventCache.Type.GUILD, id, responseNumber, allContent, this::handle);
EventCache.LOG.debug("Received Guild Member {} event for a Guild not yet cached.", JDALogger.getLazyString(() -> banned ? "Ban" : "Unban"));
return null;
}
User user = getJDA().getEntityBuilder().createUser(userJson);
if (banned) {
getJDA().handleEvent(new GuildBanEvent(getJDA(), responseNumber, guild, user));
} else {
getJDA().handleEvent(new GuildUnbanEvent(getJDA(), responseNumber, guild, user));
}
return null;
}
use of net.dv8tion.jda.api.events.guild.GuildUnbanEvent in project Sx4 by sx4-discord-bot.
the class LoggerHandler method onGuildUnban.
public void onGuildUnban(GuildUnbanEvent event) {
Guild guild = event.getGuild();
User user = event.getUser();
LoggerEvent loggerEvent = LoggerEvent.MEMBER_UNBANNED;
LoggerContext loggerContext = new LoggerContext().setUser(user);
WebhookEmbedBuilder embed = new WebhookEmbedBuilder();
embed.setDescription(String.format("`%s` has been unbanned", user.getName()));
embed.setColor(this.bot.getConfig().getGreen());
embed.setTimestamp(Instant.now());
embed.setAuthor(new EmbedAuthor(user.getAsTag(), user.getEffectiveAvatarUrl(), null));
embed.setFooter(new EmbedFooter(String.format("User ID: %s", user.getId()), null));
this.bot.getMongo().aggregateLoggers(this.getPipeline(guild.getIdLong())).whenComplete((documents, exception) -> {
if (ExceptionUtility.sendErrorMessage(exception)) {
return;
}
if (documents.isEmpty()) {
return;
}
Document data = documents.get(0);
List<Document> loggers = LoggerUtility.getValidLoggers(data.getList("loggers", Document.class), loggerEvent, loggerContext);
if (loggers.isEmpty()) {
return;
}
if (guild.getSelfMember().hasPermission(Permission.VIEW_AUDIT_LOGS)) {
this.retrieveAuditLogsDelayed(guild, ActionType.UNBAN).whenComplete((logs, auditException) -> {
User moderator = logs == null ? null : logs.stream().filter(e -> Duration.between(e.getTimeCreated(), ZonedDateTime.now(ZoneOffset.UTC)).toSeconds() <= 5).filter(e -> e.getTargetIdLong() == user.getIdLong()).map(AuditLogEntry::getUser).findFirst().orElse(null);
if (moderator != null) {
loggerContext.setModerator(moderator);
embed.setDescription(String.format("`%s` has been unbanned by **%s**", user.getName(), moderator.getAsTag()));
}
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
});
} else {
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
}
});
}
Aggregations