diff --git a/src/main/java/com/jagrosh/vortex/Vortex.java b/src/main/java/com/jagrosh/vortex/Vortex.java index d67f25a..29c2b0d 100644 --- a/src/main/java/com/jagrosh/vortex/Vortex.java +++ b/src/main/java/com/jagrosh/vortex/Vortex.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 John Grosh (jagrosh). + * Copyright 2018 John Grosh (jagrosh). * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -123,7 +123,7 @@ // Settings new SetupCmd(this), - new SetstrikesCmd(this), + new PunishmentCmd(this), new MessagelogCmd(this), new ModlogCmd(this), new ServerlogCmd(this), @@ -134,6 +134,8 @@ // Automoderation new AntiinviteCmd(this), + //new AnticopypastaCmd(this), + new AntirefCmd(this), new MaxlinesCmd(this), new MaxmentionsCmd(this), new AntiduplicateCmd(this), diff --git a/src/main/java/com/jagrosh/vortex/automod/AutoMod.java b/src/main/java/com/jagrosh/vortex/automod/AutoMod.java index 58c35a8..4e7cde7 100644 --- a/src/main/java/com/jagrosh/vortex/automod/AutoMod.java +++ b/src/main/java/com/jagrosh/vortex/automod/AutoMod.java @@ -47,7 +47,7 @@ public class AutoMod { private final static Pattern INVITES = Pattern.compile("discord\\s?(?:\\.\\s?gg|app\\s?.\\s?com\\s?\\/\\s?invite)\\s?\\/\\s?([A-Z0-9-]{2,18})",Pattern.CASE_INSENSITIVE); - //private final static Pattern REF = Pattern.compile(""); + private final static Pattern REF = Pattern.compile("https?:\\/\\/(\\S+[?&]ref=|wn.nr\\/)\\S+", Pattern.CASE_INSENSITIVE); private final static String CONDENSER = "(.+?)\\s*(\\1\\s*)+"; private final static Logger LOG = LoggerFactory.getLogger("AutoMod"); @@ -276,6 +276,18 @@ } } + // prevent referral links + if(settings.refStrikes > 0) + { + Matcher m = REF.matcher(message.getContentRaw()); + if(m.find()) + { + strikeTotal += settings.refStrikes; + reason.append(", Referral link"); + shouldDelete = true; + } + } + // anti-invite if(settings.inviteStrikes > 0 && preventInvites) { diff --git a/src/main/java/com/jagrosh/vortex/commands/automod/AnticopypastaCmd.java b/src/main/java/com/jagrosh/vortex/commands/automod/AnticopypastaCmd.java new file mode 100644 index 0000000..523a735 --- /dev/null +++ b/src/main/java/com/jagrosh/vortex/commands/automod/AnticopypastaCmd.java @@ -0,0 +1,67 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.jagrosh.vortex.commands.automod; + +import com.jagrosh.jdautilities.command.Command; +import com.jagrosh.jdautilities.command.CommandEvent; +import net.dv8tion.jda.core.Permission; +import com.jagrosh.vortex.Vortex; +import com.jagrosh.vortex.database.managers.AutomodManager; +import com.jagrosh.vortex.database.managers.PunishmentManager; + +/** + * + * @author John Grosh (john.a.grosh@gmail.com) + */ +public class AnticopypastaCmd extends Command +{ + private final Vortex vortex; + + public AnticopypastaCmd(Vortex vortex) + { + this.vortex = vortex; + this.name = "anticopypasta"; + this.guildOnly = true; + this.aliases = new String[]{"antipasta","anti-copypasta"}; + this.category = new Category("AutoMod"); + this.arguments = ""; + this.help = "sets strikes for posting copypastas"; + this.userPermissions = new Permission[]{Permission.MANAGE_SERVER}; + } + + @Override + protected void execute(CommandEvent event) + { + if(event.getArgs().isEmpty()) + { + event.replyError("Please provide a number of strikes!"); + return; + } + int numstrikes; + try + { + numstrikes = Integer.parseInt(event.getArgs()); + } + catch(NumberFormatException ex) + { + if(event.getArgs().equalsIgnoreCase("none") || event.getArgs().equalsIgnoreCase("off")) + numstrikes = 0; + else + { + event.replyError("`"+event.getArgs()+"` is not a valid integer!"); + return; + } + } + if(numstrikes<0 || numstrikes>AutomodManager.MAX_STRIKES) + { + event.replyError("The number of strikes must be between 0 and "+AutomodManager.MAX_STRIKES); + return; + } + 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 : "")); + } +} diff --git a/src/main/java/com/jagrosh/vortex/commands/automod/AntirefCmd.java b/src/main/java/com/jagrosh/vortex/commands/automod/AntirefCmd.java new file mode 100644 index 0000000..f5116bd --- /dev/null +++ b/src/main/java/com/jagrosh/vortex/commands/automod/AntirefCmd.java @@ -0,0 +1,67 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.jagrosh.vortex.commands.automod; + +import com.jagrosh.jdautilities.command.Command; +import com.jagrosh.jdautilities.command.CommandEvent; +import net.dv8tion.jda.core.Permission; +import com.jagrosh.vortex.Vortex; +import com.jagrosh.vortex.database.managers.AutomodManager; +import com.jagrosh.vortex.database.managers.PunishmentManager; + +/** + * + * @author John Grosh (john.a.grosh@gmail.com) + */ +public class AntirefCmd extends Command +{ + private final Vortex vortex; + + public AntirefCmd(Vortex vortex) + { + this.vortex = vortex; + this.name = "antireferral"; + this.guildOnly = true; + this.aliases = new String[]{"antiref","antirefferal","antirefferral","anti-ref","anti-referral"}; + this.category = new Category("AutoMod"); + this.arguments = ""; + this.help = "sets strikes for posting referral and malicious links"; + this.userPermissions = new Permission[]{Permission.MANAGE_SERVER}; + } + + @Override + protected void execute(CommandEvent event) + { + if(event.getArgs().isEmpty()) + { + event.replyError("Please provide a number of strikes!"); + return; + } + int numstrikes; + try + { + numstrikes = Integer.parseInt(event.getArgs()); + } + catch(NumberFormatException ex) + { + if(event.getArgs().equalsIgnoreCase("none") || event.getArgs().equalsIgnoreCase("off")) + numstrikes = 0; + else + { + event.replyError("`"+event.getArgs()+"` is not a valid integer!"); + return; + } + } + if(numstrikes<0 || numstrikes>AutomodManager.MAX_STRIKES) + { + event.replyError("The number of strikes must be between 0 and "+AutomodManager.MAX_STRIKES); + return; + } + 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 : "")); + } +} diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/CleanCmd.java b/src/main/java/com/jagrosh/vortex/commands/moderation/CleanCmd.java index a641f2a..fd17c8e 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/CleanCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/CleanCmd.java @@ -22,12 +22,10 @@ import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.vortex.Vortex; import com.jagrosh.vortex.commands.ModCommand; -import com.jagrosh.vortex.database.managers.GuildSettingsDataManager.GuildSettings; import java.util.LinkedList; import net.dv8tion.jda.core.Permission; import net.dv8tion.jda.core.entities.Message; import net.dv8tion.jda.core.entities.MessageHistory; -import com.jagrosh.vortex.utils.FormatUtil; import com.jagrosh.vortex.utils.LogUtil; import net.dv8tion.jda.core.EmbedBuilder; import net.dv8tion.jda.core.entities.TextChannel; @@ -39,11 +37,11 @@ public class CleanCmd extends ModCommand { private final Pattern LINK_PATTERN = Pattern.compile("https?:\\/\\/.+"); - private final Pattern QUOTES_PATTERN = Pattern.compile("\"(.*?)\"", Pattern.DOTALL); + private final Pattern QUOTES_PATTERN = Pattern.compile("[\"“](.*?)[\"“]", Pattern.DOTALL); private final Pattern CODE_PATTERN = Pattern.compile("`(.*?)`", Pattern.DOTALL); private final Pattern MENTION_PATTERN = Pattern.compile("<@!?(\\d{17,22})>"); - private final Pattern ID_PATTERN = Pattern.compile("(?:^|\\s)(\\d{17,22})(?:$|\\s)"); - private final Pattern NUM_PATTERN = Pattern.compile("(?:^|\\s)(\\d{1,4})(?:$|\\s)"); + private final Pattern ID_PATTERN = Pattern.compile("\\b(\\d{17,22})\\b"); + private final Pattern NUM_PATTERN = Pattern.compile("\\b(\\d{1,4})\\b"); private final String week2limit = " Note: Messages older than 2 weeks cannot be cleaned."; private final String noparams = "**No valid cleaning paramaters included!**\n" +"This command is to remove many messages quickly. Pinned messages are ignored. " diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/ReasonCmd.java b/src/main/java/com/jagrosh/vortex/commands/moderation/ReasonCmd.java index 2c6ee06..8f96624 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/ReasonCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/ReasonCmd.java @@ -78,7 +78,7 @@ event.replyError("I am unable to Read, Write or retrieve History in the modlog!"); break; case -3: - event.replyError("Case `"+fcaseNum+"` could not be found in the modlog!"); + event.replyError("Case `"+fcaseNum+"` could not be found among the recent cases in the modlog!"); break; case -4: event.replyError("A recent case with no reason could not be found in the modlog!"); diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/PunishmentCmd.java b/src/main/java/com/jagrosh/vortex/commands/settings/PunishmentCmd.java new file mode 100644 index 0000000..a66120b --- /dev/null +++ b/src/main/java/com/jagrosh/vortex/commands/settings/PunishmentCmd.java @@ -0,0 +1,143 @@ +/* + * Copyright 2018 John Grosh (john.a.grosh@gmail.com). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.vortex.commands.settings; + +import com.jagrosh.jdautilities.command.Command; +import com.jagrosh.jdautilities.command.CommandEvent; +import com.jagrosh.vortex.Action; +import com.jagrosh.vortex.Constants; +import com.jagrosh.vortex.Vortex; +import com.jagrosh.vortex.database.managers.PunishmentManager; +import com.jagrosh.vortex.utils.FormatUtil; +import com.jagrosh.vortex.utils.OtherUtil; +import net.dv8tion.jda.core.EmbedBuilder; +import net.dv8tion.jda.core.MessageBuilder; +import net.dv8tion.jda.core.Permission; + +/** + * + * @author John Grosh (john.a.grosh@gmail.com) + */ +public class PunishmentCmd extends Command +{ + private final static String SETTING_STRIKES = "\n\nUsage: `"+Constants.PREFIX+"setstrikes [time]`\n" + + "`` - the number of strikes at which to perform the action\n" + + "`` - the action, such as `None`, `Kick`, `Mute`, `Softban`, or `Ban`\n" + + "`[time]` - optional, the amount of time to keep the user muted or banned\n" + + "Do not include <> nor [] in your commands!\n\n" + + "The `"+Constants.PREFIX+"settings` command can be used to view current punishments."; + private final Vortex vortex; + + public PunishmentCmd(Vortex vortex) + { + this.vortex = vortex; + this.name = "punishment"; + this.help = "sets strikes for a punishment"; + this.aliases = new String[]{"setstrikes","setstrike","punishments"}; + this.arguments = " [time]"; + this.category = new Category("Settings"); + this.guildOnly = true; + this.userPermissions = new Permission[]{Permission.MANAGE_SERVER}; + } + + @Override + protected void execute(CommandEvent event) + { + String[] parts = event.getArgs().split("\\s+", 3); + if(parts.length<2) + { + event.replyError("Please include a number of strikes and an action to perform!"+SETTING_STRIKES); + return; + } + int numstrikes; + try + { + numstrikes = Integer.parseInt(parts[0]); + } + catch(NumberFormatException ex) + { + event.replyError("`"+parts[0]+"` is not a valid integer!"+SETTING_STRIKES); + return; + } + if(numstrikes<1 || numstrikes>PunishmentManager.MAX_STRIKES) + { + event.replyError("`` must be between 1 and "+PunishmentManager.MAX_STRIKES+"!"+SETTING_STRIKES); + return; + } + String successMessage; + switch(parts[1].toLowerCase()) + { + case "none": + { + vortex.getDatabase().actions.removeAction(event.getGuild(), numstrikes); + successMessage = "No action will be taken on `"+numstrikes+"` strikes."; + break; + } + case "tempmute": + case "temp-mute": + case "mute": + { + int minutes = parts.length>2 ? OtherUtil.parseTime(parts[2])/60 : 0; + if(minutes<0) + { + event.replyError("Temp-Mute time cannot be negative!"); + return; + } + vortex.getDatabase().actions.setAction(event.getGuild(), numstrikes, Action.MUTE, minutes); + successMessage = "Users will now be `muted` "+(minutes>0 ? "for "+FormatUtil.secondsToTime(minutes*60)+" " : "")+"upon reaching `"+numstrikes+"` strikes."; + break; + } + case "kick": + { + vortex.getDatabase().actions.setAction(event.getGuild(), numstrikes, Action.KICK); + successMessage = "Users will now be `kicked` upon reaching `"+numstrikes+"` strikes."; + break; + } + case "softban": + { + vortex.getDatabase().actions.setAction(event.getGuild(), numstrikes, Action.SOFTBAN); + successMessage = "Users will now be `softbanned` upon reaching `"+numstrikes+"` strikes."; + break; + } + case "tempban": + case "temp-ban": + case "ban": + { + int minutes = parts.length>2 ? OtherUtil.parseTime(parts[2])/60 : 0; + if(minutes<0) + { + event.replyError("Temp-Ban time cannot be negative!"); + return; + } + vortex.getDatabase().actions.setAction(event.getGuild(), numstrikes, Action.BAN, minutes); + successMessage = "Users will now be `banned` "+(minutes>0 ? "for "+FormatUtil.secondsToTime(minutes*60)+" " : "")+"upon reaching `"+numstrikes+"` strikes."; + break; + } + default: + { + event.replyError("`"+parts[1]+"` is not a valid action!"+SETTING_STRIKES); + return; + } + } + event.reply(new MessageBuilder() + .append(event.getClient().getSuccess()) + .append(" ").append(FormatUtil.filterEveryone(successMessage)) + .setEmbed(new EmbedBuilder().setColor(event.getSelfMember().getColor()) + .addField(vortex.getDatabase().actions.getAllPunishmentsDisplay(event.getGuild())) + .build()) + .build()); + } +} diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/SetstrikesCmd.java b/src/main/java/com/jagrosh/vortex/commands/settings/SetstrikesCmd.java deleted file mode 100644 index 73403b3..0000000 --- a/src/main/java/com/jagrosh/vortex/commands/settings/SetstrikesCmd.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2018 John Grosh (john.a.grosh@gmail.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jagrosh.vortex.commands.settings; - -import com.jagrosh.jdautilities.command.Command; -import com.jagrosh.jdautilities.command.CommandEvent; -import com.jagrosh.vortex.Action; -import com.jagrosh.vortex.Constants; -import com.jagrosh.vortex.Vortex; -import com.jagrosh.vortex.database.managers.PunishmentManager; -import com.jagrosh.vortex.utils.FormatUtil; -import com.jagrosh.vortex.utils.OtherUtil; -import net.dv8tion.jda.core.EmbedBuilder; -import net.dv8tion.jda.core.MessageBuilder; -import net.dv8tion.jda.core.Permission; - -/** - * - * @author John Grosh (john.a.grosh@gmail.com) - */ -public class SetstrikesCmd extends Command -{ - private final static String SETTING_STRIKES = "\n\nUsage: `"+Constants.PREFIX+"setstrikes [time]`\n" - + "`` - the number of strikes at which to perform the action\n" - + "`` - the action, such as `None`, `Kick`, `Mute`, `Softban`, or `Ban`\n" - + "`[time]` - optional, the amount of time to keep the user muted or banned\n" - + "Do not include <> nor [] in your commands!"; - private final Vortex vortex; - - public SetstrikesCmd(Vortex vortex) - { - this.vortex = vortex; - this.name = "setstrikes"; - this.help = "sets strikes for a punishment"; - this.aliases = new String[]{"setstrike"}; - this.arguments = " [time]"; - this.category = new Category("Settings"); - this.guildOnly = true; - this.userPermissions = new Permission[]{Permission.MANAGE_SERVER}; - } - - @Override - protected void execute(CommandEvent event) - { - String[] parts = event.getArgs().split("\\s+", 3); - if(parts.length<2) - { - event.replyError("Please include a number of strikes and an action to perform!"+SETTING_STRIKES); - return; - } - int numstrikes; - try - { - numstrikes = Integer.parseInt(parts[0]); - } - catch(NumberFormatException ex) - { - event.replyError("`"+parts[0]+"` is not a valid integer!"+SETTING_STRIKES); - return; - } - if(numstrikes<1 || numstrikes>PunishmentManager.MAX_STRIKES) - { - event.replyError("`` must be between 1 and "+PunishmentManager.MAX_STRIKES+"!"+SETTING_STRIKES); - return; - } - String successMessage; - switch(parts[1].toLowerCase()) - { - case "none": - { - vortex.getDatabase().actions.removeAction(event.getGuild(), numstrikes); - successMessage = "No action will be taken on `"+numstrikes+"` strikes."; - break; - } - case "tempmute": - case "temp-mute": - case "mute": - { - int minutes = parts.length>2 ? OtherUtil.parseTime(parts[2])/60 : 0; - if(minutes<0) - { - event.replyError("Temp-Mute time cannot be negative!"); - return; - } - vortex.getDatabase().actions.setAction(event.getGuild(), numstrikes, Action.MUTE, minutes); - successMessage = "Users will now be `muted` "+(minutes>0 ? "for "+FormatUtil.secondsToTime(minutes*60)+" " : "")+"upon reaching `"+numstrikes+"` strikes."; - break; - } - case "kick": - { - vortex.getDatabase().actions.setAction(event.getGuild(), numstrikes, Action.KICK); - successMessage = "Users will now be `kicked` upon reaching `"+numstrikes+"` strikes."; - break; - } - case "softban": - { - vortex.getDatabase().actions.setAction(event.getGuild(), numstrikes, Action.SOFTBAN); - successMessage = "Users will now be `softbanned` upon reaching `"+numstrikes+"` strikes."; - break; - } - case "tempban": - case "temp-ban": - case "ban": - { - int minutes = parts.length>2 ? OtherUtil.parseTime(parts[2])/60 : 0; - if(minutes<0) - { - event.replyError("Temp-Ban time cannot be negative!"); - return; - } - vortex.getDatabase().actions.setAction(event.getGuild(), numstrikes, Action.BAN, minutes); - successMessage = "Users will now be `banned` "+(minutes>0 ? "for "+FormatUtil.secondsToTime(minutes*60)+" " : "")+"upon reaching `"+numstrikes+"` strikes."; - break; - } - default: - { - event.replyError("`"+parts[1]+"` is not a valid action!"+SETTING_STRIKES); - return; - } - } - event.reply(new MessageBuilder() - .append(event.getClient().getSuccess()) - .append(" ").append(FormatUtil.filterEveryone(successMessage)) - .setEmbed(new EmbedBuilder().setColor(event.getSelfMember().getColor()) - .addField(vortex.getDatabase().actions.getAllPunishmentsDisplay(event.getGuild())) - .build()) - .build()); - } -} diff --git a/src/main/java/com/jagrosh/vortex/database/managers/AutomodManager.java b/src/main/java/com/jagrosh/vortex/database/managers/AutomodManager.java index 4f723c7..67c2d65 100644 --- a/src/main/java/com/jagrosh/vortex/database/managers/AutomodManager.java +++ b/src/main/java/com/jagrosh/vortex/database/managers/AutomodManager.java @@ -47,6 +47,7 @@ public final static SQLColumn INVITE_STRIKES = new IntegerColumn("INVITE_STRIKES", false, 0); public final static SQLColumn REF_STRIKES = new IntegerColumn("REF_STRIKES", false, 0); + public final static SQLColumn COPYPASTA_STRIKES = new IntegerColumn("COPYPASTA_STRIKES", false, 0); public final static SQLColumn DUPE_STRIKES = new IntegerColumn("DUPE_STRIKES", false, 0); public final static SQLColumn DUPE_DELETE_THRESH = new IntegerColumn("DUPE_DELETE_THRESH", false, 0); @@ -75,9 +76,10 @@ { AutomodSettings settings = getSettings(guild); return new Field(SETTINGS_TITLE, - "__Anti-Invite__\n" + (settings.inviteStrikes==0 + "__Anti-Advertisement__\n" + (settings.inviteStrikes==0 && settings.refStrikes==0 ? "Disabled\n\n" - : "Strikes: **" + settings.inviteStrikes + "**\n\n") + : "Invite Link Strikes: **" + settings.inviteStrikes + "**\n" + + "Referral Link Strikes: **" + settings.refStrikes + "**\n\n") + "__Anti-Duplicate__\n" + (settings.useAntiDuplicate() ? "Strike Threshold: **" + settings.dupeStrikeThresh + "**\n" + "Delete Threshold: **" + settings.dupeDeleteThresh + "**\n" + @@ -87,9 +89,10 @@ ? "Disabled\n\n" : "Max User Mentions: " + (settings.maxMentions==0 ? "None\n" : "**" + settings.maxMentions + "**\n") + "Max Role Mentions: " + (settings.maxRoleMentions==0 ? "None\n\n" : "**" + settings.maxRoleMentions + "**\n\n")) - + "__Spam Prevention__\n" + (settings.maxLines==0 + + "__Spam Prevention__\n" + (settings.maxLines==0 && settings.copypastaStrikes==0 ? "Disabled\n\n" - : "Max Lines / Message: **"+settings.maxLines+"**\n\n") + : "Max Lines / Message: "+(settings.maxLines==0 ? "Disabled\n" : "**"+settings.maxLines+"**\n") + + "Copypasta Strikes: **" + settings.copypastaStrikes + "**\n\n") + "__Auto Anti-Raid Mode__\n" + (settings.useAutoRaidMode() ? "**" + settings.raidmodeNumber + "** joins / **" + settings.raidmodeTime + "** seconds\n" : "Disabled\n") @@ -233,6 +236,26 @@ }); } + public void setCopypastaStrikes(Guild guild, int strikes) + { + invalidateCache(guild); + readWrite(selectAll(GUILD_ID.is(guild.getIdLong())), rs -> + { + if(rs.next()) + { + COPYPASTA_STRIKES.updateValue(rs, strikes); + rs.updateRow(); + } + else + { + rs.moveToInsertRow(); + GUILD_ID.updateValue(rs, guild.getIdLong()); + COPYPASTA_STRIKES.updateValue(rs, strikes); + rs.insertRow(); + } + }); + } + public void setDupeSettings(Guild guild, int strikes, int deleteThresh, int strikeThresh) { invalidateCache(guild); @@ -267,8 +290,7 @@ public final int maxMentions, maxRoleMentions; public final int maxLines; public final int raidmodeNumber, raidmodeTime; - public final int inviteStrikes; - public final int refStrikes; + public final int inviteStrikes, refStrikes, copypastaStrikes; public final int dupeStrikes, dupeDeleteThresh, dupeStrikeThresh; private AutomodSettings() @@ -280,31 +302,25 @@ this.raidmodeTime = 0; this.inviteStrikes = 0; this.refStrikes = 0; + this.copypastaStrikes = 0; this.dupeStrikes = 0; this.dupeDeleteThresh = 0; this.dupeStrikeThresh = 0; } - private AutomodSettings(int maxMentions, int maxRoleMentions, int maxNewlines, int raidmodeNumber, int raidmodeTime, - int inviteStrikes, int refStrikes, int dupeStrikes, int dupeDeleteThresh, int dupeStrikeThresh) - { - this.maxMentions = maxMentions; - this.maxRoleMentions = maxRoleMentions; - this.maxLines = maxNewlines; - this.raidmodeNumber = raidmodeNumber; - this.raidmodeTime = raidmodeTime; - this.inviteStrikes = inviteStrikes; - this.refStrikes = refStrikes; - this.dupeStrikes = dupeStrikes; - this.dupeDeleteThresh = dupeDeleteThresh; - this.dupeStrikeThresh = dupeStrikeThresh; - } - private AutomodSettings(ResultSet rs) throws SQLException { - this(MAX_MENTIONS.getValue(rs), MAX_ROLE_MENTIONS.getValue(rs), MAX_LINES.getValue(rs), RAIDMODE_NUMBER.getValue(rs), RAIDMODE_TIME.getValue(rs), - INVITE_STRIKES.getValue(rs), REF_STRIKES.getValue(rs), DUPE_STRIKES.getValue(rs), DUPE_DELETE_THRESH.getValue(rs), - DUPE_STRIKE_THRESH.getValue(rs)); + this.maxMentions = MAX_MENTIONS.getValue(rs); + this.maxRoleMentions = MAX_ROLE_MENTIONS.getValue(rs); + this.maxLines = MAX_LINES.getValue(rs); + this.raidmodeNumber = RAIDMODE_NUMBER.getValue(rs); + this.raidmodeTime = RAIDMODE_TIME.getValue(rs); + this.inviteStrikes = INVITE_STRIKES.getValue(rs); + this.refStrikes = REF_STRIKES.getValue(rs); + this.copypastaStrikes = COPYPASTA_STRIKES.getValue(rs); + this.dupeStrikes = DUPE_STRIKES.getValue(rs); + this.dupeDeleteThresh = DUPE_DELETE_THRESH.getValue(rs); + this.dupeStrikeThresh = DUPE_STRIKE_THRESH.getValue(rs); } public boolean useAutoRaidMode() diff --git a/src/main/java/com/jagrosh/vortex/utils/LogUtil.java b/src/main/java/com/jagrosh/vortex/utils/LogUtil.java index 79d83ba..846129e 100644 --- a/src/main/java/com/jagrosh/vortex/utils/LogUtil.java +++ b/src/main/java/com/jagrosh/vortex/utils/LogUtil.java @@ -49,8 +49,8 @@ private final static String MODLOG_USER_FORMAT = LOG_TIME + MODLOG_CASE + EMOJI + MODERATOR + ACTION + TARGET_USER + REASON; private final static String MODLOG_TIME_FORMAT = LOG_TIME + MODLOG_CASE + EMOJI + MODERATOR + ACTION + TARGET_USER + " for %s" + REASON; private final static String MODLOG_CLEAN_FORMAT = LOG_TIME + MODLOG_CASE + EMOJI + MODERATOR + ACTION + " `%d` messages in %s\n`[Criteria]` %s" + REASON; - private final static String MODLOG_STRIKE_FORMAT = LOG_TIME + MODLOG_CASE + EMOJI + MODERATOR + " gave `%d` strikes `[%d ➡ %d]` to" + TARGET_USER + REASON; - private final static String MODLOG_PARDON_FORMAT = LOG_TIME + MODLOG_CASE + EMOJI + MODERATOR + " pardoned `%d` strikes `[%d ➡ %d]` from" + TARGET_USER + REASON; + private final static String MODLOG_STRIKE_FORMAT = LOG_TIME + MODLOG_CASE + EMOJI + MODERATOR + " gave `%d` strikes `[%d → %d]` to" + TARGET_USER + REASON; + private final static String MODLOG_PARDON_FORMAT = LOG_TIME + MODLOG_CASE + EMOJI + MODERATOR + " pardoned `%d` strikes `[%d → %d]` from" + TARGET_USER + REASON; private final static String MODLOG_RAID_FORMAT = LOG_TIME + MODLOG_CASE + EMOJI + MODERATOR + " `%s` anti-raid mode" + REASON; private final static String BASICLOG_FORMAT = LOG_TIME + EMOJI + " %s";