use of com.sx4.bot.events.mod.UnbanEvent in project Sx4 by sx4-discord-bot.
the class TemporaryBanManager method removeBanAndGet.
public DeleteOneModel<Document> removeBanAndGet(long guildId, long userId, boolean automatic) {
ShardManager shardManager = this.bot.getShardManager();
Guild guild = shardManager.getGuildById(guildId);
if (guild == null) {
return null;
}
User user = shardManager.getUserById(userId);
Member member = user == null ? null : guild.getMember(user);
if (automatic && member == null) {
guild.unban(User.fromId(userId)).reason("Ban length served").queue();
}
if (automatic) {
Reason reason = new Reason("Ban length served");
UnbanEvent event = new UnbanEvent(guild.getSelfMember(), user == null ? UserReference.fromId(userId) : user, reason);
this.bot.getModActionManager().onModAction(event);
}
this.deleteExecutor(guildId, userId);
return new DeleteOneModel<>(Filters.and(Filters.eq("guildId", guildId), Filters.eq("userId", userId)));
}
use of com.sx4.bot.events.mod.UnbanEvent in project Sx4 by sx4-discord-bot.
the class UnbanCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "user") String userArgument, @Argument(value = "reason", endless = true, nullDefault = true) Reason reason) {
SearchUtility.getBan(event.getGuild(), userArgument).whenComplete((ban, exception) -> {
if (ban == null) {
event.replyFailure("I could not find that banned user").queue();
return;
}
User user = ban.getUser();
event.getGuild().unban(user).reason(ModUtility.getAuditReason(reason, event.getAuthor())).submit().whenComplete(($, unbanException) -> {
if (unbanException instanceof ErrorResponseException && ((ErrorResponseException) unbanException).getErrorResponse() == ErrorResponse.UNKNOWN_BAN) {
event.replyFailure("That user is not banned").queue();
return;
}
event.replySuccess("**" + user.getAsTag() + "** has been unbanned").queue();
event.getBot().getModActionManager().onModAction(new UnbanEvent(event.getMember(), user, reason));
event.getBot().getTemporaryBanManager().removeBan(event.getGuild().getIdLong(), user.getIdLong(), false);
});
});
}
Aggregations