use of net.dv8tion.jda.api.audit.AuditLogEntry in project Sx4 by sx4-discord-bot.
the class ServerLogHandler method onGuildJoin.
public void onGuildJoin(GuildJoinEvent event) {
ShardManager manager = event.getJDA().getShardManager();
Member owner = event.getGuild().getOwner();
WebhookEmbedBuilder embed = new WebhookEmbedBuilder().setColor(this.bot.getConfig().getGreen()).setThumbnailUrl(event.getGuild().getIconUrl()).setTimestamp(Instant.now()).setDescription(String.format("I am now in %,d servers and connected to %,d users", manager.getGuildCache().size(), manager.getUserCache().size())).setAuthor(new WebhookEmbed.EmbedAuthor("Joined Server!", event.getJDA().getSelfUser().getEffectiveAvatarUrl(), null)).addField(new WebhookEmbed.EmbedField(true, "Server Name", event.getGuild().getName())).addField(new WebhookEmbed.EmbedField(true, "Server ID", event.getGuild().getId())).addField(new WebhookEmbed.EmbedField(true, "Server Owner", (owner == null ? "Anonymous#0000" : owner.getUser().getAsTag()) + "\n" + event.getGuild().getOwnerId())).addField(new WebhookEmbed.EmbedField(true, "Server Members", String.format("%,d member%s", event.getGuild().getMemberCount(), event.getGuild().getMemberCount() == 1 ? "" : "s")));
this.webhook.send(embed.build());
if (event.getGuild().getSelfMember().hasPermission(Permission.VIEW_AUDIT_LOGS)) {
event.getGuild().retrieveAuditLogs().type(ActionType.BOT_ADD).queueAfter(500, TimeUnit.MILLISECONDS, audits -> {
AuditLogEntry audit = audits.stream().filter(auditLog -> auditLog.getTargetIdLong() == event.getJDA().getSelfUser().getIdLong()).filter(auditLog -> Duration.between(auditLog.getTimeCreated(), ZonedDateTime.now(ZoneOffset.UTC)).toSeconds() <= 5).findFirst().orElse(null);
if (audit != null) {
audit.getUser().openPrivateChannel().flatMap(channel -> channel.sendMessage("Thanks for adding me to your server!\nThe default prefix is `s?` however if that doesn't work use `@Sx4#1617 prefix` to check your current prefixes\nAll my info and commands can be found in `s?help`\nIf you need any help feel free to join the support server: https://discord.gg/PqJNcfB")).queue();
}
});
}
}
use of net.dv8tion.jda.api.audit.AuditLogEntry in project Sx4 by sx4-discord-bot.
the class LoggerHandler method onGuildVoiceGuildMute.
public void onGuildVoiceGuildMute(GuildVoiceGuildMuteEvent event) {
Guild guild = event.getGuild();
Member member = event.getMember();
User user = member.getUser();
GuildVoiceState voiceState = event.getVoiceState();
VoiceChannel channel = voiceState.getChannel();
boolean muted = voiceState.isGuildMuted();
LoggerEvent loggerEvent = muted ? LoggerEvent.MEMBER_SERVER_VOICE_MUTE : LoggerEvent.MEMBER_SERVER_VOICE_UNMUTE;
LoggerContext loggerContext = new LoggerContext().setUser(user).setChannel(channel == null ? 0L : channel.getIdLong());
WebhookEmbedBuilder embed = new WebhookEmbedBuilder();
embed.setDescription(String.format("`%s` has been %s", member.getEffectiveName(), muted ? "muted" : "unmuted"));
embed.setTimestamp(Instant.now());
embed.setAuthor(new EmbedAuthor(member.getUser().getAsTag(), member.getUser().getEffectiveAvatarUrl(), null));
embed.setFooter(new EmbedFooter(String.format("User ID: %s", user.getId()), null));
embed.setColor(muted ? this.bot.getConfig().getRed() : this.bot.getConfig().getGreen());
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.MEMBER_UPDATE).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() == member.getUser().getIdLong()).filter(e -> e.getChangeByKey(AuditLogKey.MEMBER_MUTE) != null).map(AuditLogEntry::getUser).findFirst().orElse(null);
if (moderator != null) {
loggerContext.setModerator(moderator);
embed.setDescription(String.format("`%s` has been %s by **%s**", member.getEffectiveName(), muted ? "muted" : "unmuted", moderator.getAsTag()));
}
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
});
} else {
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
}
});
}
Aggregations