use of net.dv8tion.jda.api.events.role.RoleCreateEvent in project JDA by DV8FromTheWorld.
the class GuildRoleCreateHandler method handleInternally.
@Override
protected Long handleInternally(DataObject content) {
final long guildId = content.getLong("guild_id");
if (getJDA().getGuildSetupController().isLocked(guildId))
return guildId;
GuildImpl guild = (GuildImpl) getJDA().getGuildById(guildId);
if (guild == null) {
getJDA().getEventCache().cache(EventCache.Type.GUILD, guildId, responseNumber, allContent, this::handle);
EventCache.LOG.debug("GUILD_ROLE_CREATE was received for a Guild that is not yet cached: {}", content);
return null;
}
Role newRole = getJDA().getEntityBuilder().createRole(guild, content.getObject("role"), guild.getIdLong());
getJDA().handleEvent(new RoleCreateEvent(getJDA(), responseNumber, newRole));
return null;
}
use of net.dv8tion.jda.api.events.role.RoleCreateEvent in project Sx4 by sx4-discord-bot.
the class LoggerHandler method onRoleCreate.
public void onRoleCreate(RoleCreateEvent event) {
Guild guild = event.getGuild();
Role role = event.getRole();
LoggerEvent loggerEvent = LoggerEvent.ROLE_CREATE;
LoggerContext loggerContext = new LoggerContext().setRole(role);
WebhookEmbedBuilder embed = new WebhookEmbedBuilder();
embed.setDescription(String.format("The role %s has been created", role.getAsMention()));
embed.setColor(this.bot.getConfig().getGreen());
embed.setTimestamp(Instant.now());
embed.setAuthor(new EmbedAuthor(guild.getName(), guild.getIconUrl(), null));
embed.setFooter(new EmbedFooter(String.format("Role ID: %s", role.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 (!role.isManaged() && guild.getSelfMember().hasPermission(Permission.VIEW_AUDIT_LOGS)) {
this.retrieveAuditLogsDelayed(guild, ActionType.ROLE_CREATE).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() == role.getIdLong()).map(AuditLogEntry::getUser).findFirst().orElse(null);
if (moderator != null) {
loggerContext.setModerator(moderator);
embed.setDescription(String.format("The role %s has been created by **%s**", role.getAsMention(), moderator.getAsTag()));
}
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
});
} else {
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
}
});
}
Aggregations