diff --git a/src/main/java/com/jagrosh/vortex/commands/automod/AnticopypastaCmd.java b/src/main/java/com/jagrosh/vortex/commands/automod/AnticopypastaCmd.java index a7c609f..f560f55 100644 --- a/src/main/java/com/jagrosh/vortex/commands/automod/AnticopypastaCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/automod/AnticopypastaCmd.java @@ -19,8 +19,8 @@ import com.jagrosh.jdautilities.command.CommandEvent; import net.dv8tion.jda.api.Permission; import com.jagrosh.vortex.Vortex; +import com.jagrosh.vortex.commands.CommandExceptionListener; import com.jagrosh.vortex.database.managers.AutomodManager; -import com.jagrosh.vortex.database.managers.PunishmentManager; import com.jagrosh.vortex.utils.FormatUtil; /** @@ -66,13 +66,13 @@ return; } } + if(numstrikes<0 || numstrikes>AutomodManager.MAX_STRIKES) - { - event.replyError("The number of strikes must be between 0 and "+AutomodManager.MAX_STRIKES); - return; - } + throw new CommandExceptionListener.CommandErrorException("The number of strikes must be between 0 and "+AutomodManager.MAX_STRIKES); + if(numstrikes > 0 && !vortex.getDatabase().actions.hasPunishments(event.getGuild())) + throw new CommandExceptionListener.CommandErrorException("Anti-Copypasta cannot be enabled without first setting at least one punishment."); + vortex.getDatabase().automod.setCopypastaStrikes(event.getGuild(), numstrikes); - boolean also = vortex.getDatabase().actions.useDefaultSettings(event.getGuild()); - event.replySuccess("Users will now receive `"+numstrikes+"` strikes for posting copypastas."+(also ? PunishmentManager.DEFAULT_SETUP_MESSAGE : "")); + event.replySuccess("Users will now receive `"+numstrikes+"` strikes for posting copypastas."); } } diff --git a/src/main/java/com/jagrosh/vortex/commands/automod/AntiduplicateCmd.java b/src/main/java/com/jagrosh/vortex/commands/automod/AntiduplicateCmd.java index ff72560..18ae9e3 100644 --- a/src/main/java/com/jagrosh/vortex/commands/automod/AntiduplicateCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/automod/AntiduplicateCmd.java @@ -19,7 +19,7 @@ import com.jagrosh.jdautilities.command.CommandEvent; import net.dv8tion.jda.api.Permission; import com.jagrosh.vortex.Vortex; -import com.jagrosh.vortex.database.managers.PunishmentManager; +import com.jagrosh.vortex.commands.CommandExceptionListener; /** * @@ -97,10 +97,10 @@ event.replySuccess("Anti-Duplicate has been disabled."); return; } + if(!vortex.getDatabase().actions.hasPunishments(event.getGuild())) + throw new CommandExceptionListener.CommandErrorException("Anti-Duplicate cannot be enabled without first setting at least one punishment."); vortex.getDatabase().automod.setDupeSettings(event.getGuild(), strikes, deleteThreshold, strikeThreshold); - boolean also = vortex.getDatabase().actions.useDefaultSettings(event.getGuild()); event.replySuccess("Anti-Duplicate will now delete duplicates starting at duplicate **"+deleteThreshold - +"** and begin assigning **"+strikes+"** strikes for each duplicate starting at duplicate **"+strikeThreshold+"**." - +(also ? PunishmentManager.DEFAULT_SETUP_MESSAGE : "")); + +"** and begin assigning **"+strikes+"** strikes for each duplicate starting at duplicate **"+strikeThreshold+"**."); } } diff --git a/src/main/java/com/jagrosh/vortex/commands/automod/AntieveryoneCmd.java b/src/main/java/com/jagrosh/vortex/commands/automod/AntieveryoneCmd.java index d69f155..84d7465 100644 --- a/src/main/java/com/jagrosh/vortex/commands/automod/AntieveryoneCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/automod/AntieveryoneCmd.java @@ -19,6 +19,7 @@ import com.jagrosh.jdautilities.command.CommandEvent; import net.dv8tion.jda.api.Permission; import com.jagrosh.vortex.Vortex; +import com.jagrosh.vortex.commands.CommandExceptionListener; import com.jagrosh.vortex.database.managers.AutomodManager; import com.jagrosh.vortex.database.managers.PunishmentManager; import com.jagrosh.vortex.utils.FormatUtil; @@ -67,14 +68,12 @@ } } if(numstrikes<0 || numstrikes>AutomodManager.MAX_STRIKES) - { - event.replyError("The number of strikes must be between 0 and "+AutomodManager.MAX_STRIKES); - return; - } + throw new CommandExceptionListener.CommandErrorException("The number of strikes must be between 0 and " + AutomodManager.MAX_STRIKES); + if(numstrikes > 0 && !vortex.getDatabase().actions.hasPunishments(event.getGuild())) + throw new CommandExceptionListener.CommandErrorException("Anti-Everyone cannot be enabled without first setting at least one punishment."); + vortex.getDatabase().automod.setEveryoneStrikes(event.getGuild(), numstrikes); - boolean also = vortex.getDatabase().actions.useDefaultSettings(event.getGuild()); event.replySuccess("Users will now receive `"+numstrikes+"` strikes for attempting to ping @\u0435veryone/here. " // cyrillic e - + "This also considers pingable roles called 'everyone' and 'here'. This will not affect users that actually " - + "have permission to ping everyone."+(also ? PunishmentManager.DEFAULT_SETUP_MESSAGE : "")); + + "This also considers pingable roles called 'everyone' and 'here'. This will not affect users that actually "); } } diff --git a/src/main/java/com/jagrosh/vortex/commands/automod/AntiinviteCmd.java b/src/main/java/com/jagrosh/vortex/commands/automod/AntiinviteCmd.java index 20b5c71..820fc25 100644 --- a/src/main/java/com/jagrosh/vortex/commands/automod/AntiinviteCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/automod/AntiinviteCmd.java @@ -19,6 +19,7 @@ import com.jagrosh.jdautilities.command.CommandEvent; import net.dv8tion.jda.api.Permission; import com.jagrosh.vortex.Vortex; +import com.jagrosh.vortex.commands.CommandExceptionListener; import com.jagrosh.vortex.database.managers.AutomodManager; import com.jagrosh.vortex.database.managers.PunishmentManager; import com.jagrosh.vortex.utils.FormatUtil; @@ -68,12 +69,11 @@ } } if(numstrikes<0 || numstrikes>AutomodManager.MAX_STRIKES) - { - event.replyError("The number of strikes must be between 0 and "+AutomodManager.MAX_STRIKES); - return; - } + throw new CommandExceptionListener.CommandErrorException("The number of strikes must be between 0 and "+AutomodManager.MAX_STRIKES); + if(numstrikes > 0 && !vortex.getDatabase().actions.hasPunishments(event.getGuild())) + throw new CommandExceptionListener.CommandErrorException("Anti-Invite cannot be enabled without first setting at least one punishment."); + vortex.getDatabase().automod.setInviteStrikes(event.getGuild(), numstrikes); - boolean also = vortex.getDatabase().actions.useDefaultSettings(event.getGuild()); - event.replySuccess("Users will now receive `"+numstrikes+"` strikes for posting invite links."+(also ? PunishmentManager.DEFAULT_SETUP_MESSAGE : "")); + event.replySuccess("Users will now receive `"+numstrikes+"` strikes for posting invite links."); } } diff --git a/src/main/java/com/jagrosh/vortex/commands/automod/AntirefCmd.java b/src/main/java/com/jagrosh/vortex/commands/automod/AntirefCmd.java index 6493911..0ef42cf 100644 --- a/src/main/java/com/jagrosh/vortex/commands/automod/AntirefCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/automod/AntirefCmd.java @@ -19,6 +19,7 @@ import com.jagrosh.jdautilities.command.CommandEvent; import net.dv8tion.jda.api.Permission; import com.jagrosh.vortex.Vortex; +import com.jagrosh.vortex.commands.CommandExceptionListener; import com.jagrosh.vortex.database.managers.AutomodManager; import com.jagrosh.vortex.database.managers.PunishmentManager; import com.jagrosh.vortex.utils.FormatUtil; @@ -67,12 +68,11 @@ } } if(numstrikes<0 || numstrikes>AutomodManager.MAX_STRIKES) - { - event.replyError("The number of strikes must be between 0 and "+AutomodManager.MAX_STRIKES); - return; - } + throw new CommandExceptionListener.CommandErrorException("The number of strikes must be between 0 and "+AutomodManager.MAX_STRIKES); + if(numstrikes > 0 && !vortex.getDatabase().actions.hasPunishments(event.getGuild())) + throw new CommandExceptionListener.CommandErrorException("Anti-Referral cannot be enabled without first setting at least one punishment."); + vortex.getDatabase().automod.setRefStrikes(event.getGuild(), numstrikes); - boolean also = vortex.getDatabase().actions.useDefaultSettings(event.getGuild()); - event.replySuccess("Users will now receive `"+numstrikes+"` strikes for posting referral links or other malicious links."+(also ? PunishmentManager.DEFAULT_SETUP_MESSAGE : "")); + event.replySuccess("Users will now receive `"+numstrikes+"` strikes for posting referral links or other malicious links."); } } diff --git a/src/main/java/com/jagrosh/vortex/commands/automod/AutodehoistCmd.java b/src/main/java/com/jagrosh/vortex/commands/automod/AutodehoistCmd.java index b039870..05f58a3 100644 --- a/src/main/java/com/jagrosh/vortex/commands/automod/AutodehoistCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/automod/AutodehoistCmd.java @@ -67,7 +67,6 @@ throw new CommandExceptionListener.CommandErrorException("Provided symbol must be one character of the following: "+OtherUtil.DEHOIST_JOINED); vortex.getDatabase().automod.setDehoistChar(event.getGuild(), symbol); - boolean also = vortex.getDatabase().actions.useDefaultSettings(event.getGuild()); - event.replySuccess("Users will now be dehoisted if their effective name starts with `"+symbol+"` or higher."+(also ? PunishmentManager.DEFAULT_SETUP_MESSAGE : "")); + event.replySuccess("Users will now be dehoisted if their effective name starts with `"+symbol+"` or higher."); } } diff --git a/src/main/java/com/jagrosh/vortex/commands/automod/MaxlinesCmd.java b/src/main/java/com/jagrosh/vortex/commands/automod/MaxlinesCmd.java index 65c84f2..a9ccd40 100644 --- a/src/main/java/com/jagrosh/vortex/commands/automod/MaxlinesCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/automod/MaxlinesCmd.java @@ -19,6 +19,7 @@ import com.jagrosh.jdautilities.command.CommandEvent; import net.dv8tion.jda.api.Permission; import com.jagrosh.vortex.Vortex; +import com.jagrosh.vortex.commands.CommandExceptionListener; import com.jagrosh.vortex.database.managers.PunishmentManager; import com.jagrosh.vortex.utils.FormatUtil; @@ -65,17 +66,16 @@ return; } } - if(maxlines<0) - { - event.replyError("The maximum number of lines must be a positive integer!"); - return; - } + if(maxlines < 0) + throw new CommandExceptionListener.CommandErrorException("The maximum number of lines must be a positive integer!"); + if(maxlines > 0 && !vortex.getDatabase().actions.hasPunishments(event.getGuild())) + throw new CommandExceptionListener.CommandErrorException("Max Lines cannot be enabled without first setting at least one punishment."); + vortex.getDatabase().automod.setMaxLines(event.getGuild(), maxlines); - boolean also = vortex.getDatabase().actions.useDefaultSettings(event.getGuild()); if(maxlines==0) event.replySuccess("There is now no maximum line limit."); else event.replySuccess("Messages longer than `"+maxlines+"` lines will now be automatically deleted, " - + "and users will receive strikes for every additional multiple of up to `"+maxlines+"` lines."+(also ? PunishmentManager.DEFAULT_SETUP_MESSAGE : "")); + + "and users will receive strikes for every additional multiple of up to `"+maxlines+"` lines."); } } diff --git a/src/main/java/com/jagrosh/vortex/commands/automod/MaxmentionsCmd.java b/src/main/java/com/jagrosh/vortex/commands/automod/MaxmentionsCmd.java index ca6d68d..a94b040 100644 --- a/src/main/java/com/jagrosh/vortex/commands/automod/MaxmentionsCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/automod/MaxmentionsCmd.java @@ -19,6 +19,7 @@ import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.vortex.Constants; import com.jagrosh.vortex.Vortex; +import com.jagrosh.vortex.commands.CommandExceptionListener; import net.dv8tion.jda.api.Permission; import com.jagrosh.vortex.database.managers.AutomodManager; import com.jagrosh.vortex.database.managers.PunishmentManager; @@ -61,17 +62,14 @@ try { short num = Short.parseShort(event.getArgs()); - if(num GUILD_ID = new LongColumn("GUILD_ID", false, 0L); public static final SQLColumn NUM_STRIKES = new IntegerColumn("NUM_STRIKES", false, 0); @@ -66,7 +66,7 @@ return GUILD_ID+", "+NUM_STRIKES; } - public boolean useDefaultSettings(Guild guild) // only activates if none set + /*public boolean useDefaultSettings(Guild guild) // only activates if none set { return readWrite(selectAll(GUILD_ID.is(guild.getId())), rs -> { @@ -83,7 +83,7 @@ } return true; }); - } + }*/ public void removeAction(Guild guild, int numStrikes) { @@ -132,6 +132,11 @@ }); } + public boolean hasPunishments(Guild guild) + { + return read(selectAll(GUILD_ID.is(guild.getId())), rs -> {return rs.next();}); + } + public List getAllPunishments(Guild guild) { return read(selectAll(GUILD_ID.is(guild.getId())), rs ->