Skip to content

Commit

Permalink
Add a config option to limit the amount of custom pings an user can have
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed May 27, 2024
1 parent ae4d585 commit 4467f96
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ class CustomPings extends ModuleConfiguration {
* The channel in which to create ping private threads if a member does not have DMs enabled.
*/
long pingThreadsChannel

/**
* The maximum amount of custom pings an user can have.
* {@code -1} means indefinite
*/
int limit = 100
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.neoforged.camelot.commands.PaginatableCommand;
import net.neoforged.camelot.db.schemas.Ping;
import net.neoforged.camelot.db.transactionals.PingsDAO;
import net.neoforged.camelot.module.CustomPingsModule;
import org.jetbrains.annotations.Nullable;

import java.util.List;
Expand Down Expand Up @@ -66,6 +67,16 @@ protected void execute(SlashCommandEvent event) {
return;
}

final var pingAmount = Database.pings().withExtension(PingsDAO.class,
db -> db.getAllPingsOf(event.getUser().getIdLong(), event.getGuild().getIdLong()))
.size();

final var config = BotMain.getModule(CustomPingsModule.class).config();
if (config.getLimit() >= 0 && pingAmount >= config.getLimit()) {
event.reply(STR."You have already reached your limit of **\{config.getLimit()}** custom pings.").setEphemeral(true).queue();
return;
}

Database.pings().useExtension(PingsDAO.class, db -> db.insert(
event.getGuild().getIdLong(), event.getUser().getIdLong(),
regex, event.getOption("message", "", OptionMapping::getAsString)
Expand Down

0 comments on commit 4467f96

Please sign in to comment.