Search in sources :

Example 1 with WarnRepository

use of net.javadiscord.javabot.systems.moderation.warn.dao.WarnRepository in project JavaBot by Java-Discord.

the class WarnsCommand method handleSlashCommandInteraction.

@Override
public ReplyCallbackAction handleSlashCommandInteraction(SlashCommandInteractionEvent event) throws ResponseException {
    OptionMapping warnsOption = event.getOption("user");
    Member member = warnsOption == null ? event.getMember() : warnsOption.getAsMember();
    if (member == null)
        return Responses.error(event, "Member is missing.");
    LocalDateTime cutoff = LocalDateTime.now().minusDays(Bot.config.get(event.getGuild()).getModeration().getWarnTimeoutDays());
    try (var con = Bot.dataSource.getConnection()) {
        return event.replyEmbeds(buildWarnsEmbed(new WarnRepository(con).getWarnsByUserId(member.getIdLong(), cutoff), member));
    } catch (SQLException e) {
        throw ResponseException.error("Could not get warns from user: " + member.getUser().getAsTag(), e);
    }
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) LocalDateTime(java.time.LocalDateTime) SQLException(java.sql.SQLException) Member(net.dv8tion.jda.api.entities.Member) WarnRepository(net.javadiscord.javabot.systems.moderation.warn.dao.WarnRepository)

Example 2 with WarnRepository

use of net.javadiscord.javabot.systems.moderation.warn.dao.WarnRepository in project JavaBot by Java-Discord.

the class WarnsCommand method handleUserContextCommandInteraction.

@Override
public ReplyCallbackAction handleUserContextCommandInteraction(UserContextInteractionEvent event) throws ResponseException {
    LocalDateTime cutoff = LocalDateTime.now().minusDays(Bot.config.get(event.getGuild()).getModeration().getWarnTimeoutDays());
    Member member = event.getTargetMember();
    try (var con = Bot.dataSource.getConnection()) {
        return event.replyEmbeds(buildWarnsEmbed(new WarnRepository(con).getWarnsByUserId(member.getIdLong(), cutoff), member));
    } catch (SQLException e) {
        throw ResponseException.error("Could not get warns from user: " + member.getUser().getAsTag(), e);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) SQLException(java.sql.SQLException) Member(net.dv8tion.jda.api.entities.Member) WarnRepository(net.javadiscord.javabot.systems.moderation.warn.dao.WarnRepository)

Aggregations

SQLException (java.sql.SQLException)2 LocalDateTime (java.time.LocalDateTime)2 Member (net.dv8tion.jda.api.entities.Member)2 WarnRepository (net.javadiscord.javabot.systems.moderation.warn.dao.WarnRepository)2 OptionMapping (net.dv8tion.jda.api.interactions.commands.OptionMapping)1