From 3f8c64f1dbe3d5db0a0cdd29c6cfaf50e6d5e6fc Mon Sep 17 00:00:00 2001 From: Michaili K Date: Sun, 11 Oct 2020 17:01:14 +0200 Subject: [PATCH 1/9] Add reset command --- src/main/java/com/jagrosh/vortex/Vortex.java | 1 + .../vortex/commands/settings/ResetCmd.java | 213 ++++++++++++++++++ .../database/managers/AutomodManager.java | 10 + .../managers/GuildSettingsDataManager.java | 9 + .../database/managers/IgnoreManager.java | 9 + .../database/managers/PunishmentManager.java | 9 + .../database/managers/StrikeManager.java | 9 + 7 files changed, 260 insertions(+) create mode 100644 src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java diff --git a/src/main/java/com/jagrosh/vortex/Vortex.java b/src/main/java/com/jagrosh/vortex/Vortex.java index 75a5f6e0..5e142516 100644 --- a/src/main/java/com/jagrosh/vortex/Vortex.java +++ b/src/main/java/com/jagrosh/vortex/Vortex.java @@ -142,6 +142,7 @@ public Vortex() throws Exception new ModroleCmd(this), new PrefixCmd(this), new SettingsCmd(this), + new ResetCmd(this), // Automoderation new AntiinviteCmd(this), diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java b/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java new file mode 100644 index 00000000..894fecef --- /dev/null +++ b/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java @@ -0,0 +1,213 @@ +/* + * 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.jdautilities.menu.ButtonMenu; +import com.jagrosh.vortex.Vortex; +import net.dv8tion.jda.core.Permission; +import net.dv8tion.jda.core.exceptions.PermissionException; + +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; + +/** + * + * @author Michaili K (mysteriouscursor+git@protonmail.com) + */ +public class ResetCmd extends Command +{ + private final Vortex vortex; + + private static final String CONFIRM_RESET_EMOJI = "\u2705"; // ✅ + private static final String CANCEL_RESET_EMOJI = "\u274c"; // ❌ + + public ResetCmd(Vortex vortex) + { + this.vortex = vortex; + this.name = "reset"; + this.help = "reset vortex settings/data to default"; + this.arguments = ""; + this.category = new Category("Settings"); + this.guildOnly = true; + this.userPermissions = new Permission[]{Permission.MANAGE_SERVER}; + } + + @Override + protected void execute(CommandEvent event) + { + if(event.getArgs().isEmpty()) + { + event.replyError("Please include the section to reset"); + return; + } + + ButtonMenu.Builder menuBuilder = new ButtonMenu.Builder() + .addChoice(CONFIRM_RESET_EMOJI) + .addChoice(CANCEL_RESET_EMOJI) + .setUsers(event.getAuthor()) + .setTimeout(30, TimeUnit.SECONDS) + .setEventWaiter(vortex.getEventWaiter()) + .setFinalAction(m -> { + try + { + m.clearReactions().queue(); + } + catch (PermissionException ignored) + { + } + }); + + Callable callable; + + switch (event.getArgs().toLowerCase()) + { + case "automod": + menuBuilder.setDescription( + "**Reset Automod**\n" + + "You are about to reset Automod.\n" + + "This will result in all Automod settings to be disabled.\n" + + "Filters aren't affected by this reset.\n\n" + + "Are you sure you want to reset all Automod settings?" + ); + callable = () -> + { + vortex.getDatabase().automod.reset(event.getGuild()); + return null; + }; + break; + + + case "filters": + menuBuilder.setDescription( + "**Reset Filters**\n" + + "You are about to remove all filters.\n" + + "Are you sure you want to remove all Filters?" + ); + callable = () -> + { + vortex.getDatabase().filters.deleteAllFilters(event.getGuild().getIdLong()); + return null; + }; + break; + + + case "settings": + menuBuilder.setDescription( + "**Reset Settings**\n" + + "You are about to reset all Server Settings.\n" + + "This will result in raid mode being disabled & Server Settings like mod role & logs to be reset.\n" + + "Punishments, Automod, Ignored roles/channels & Filters aren't affected by this reset.\n" + + "Are you sure you want to reset all Server Settings?" + ); + callable = () -> + { + vortex.getDatabase().settings.reset(event.getGuild()); + return null; + }; + break; + + + case "ignores": + menuBuilder.setDescription( + "**Reset Ignores**\n" + + "You are about to reset ignored channels & roles.\n" + + "This will result in AutoMod no longer ignoring any channels & roles added to the ignore list.\n" + + "Are you sure you want to reset all ignored channels & roles?" + ); + callable = () -> + { + vortex.getDatabase().ignores.unignoreAll(event.getGuild()); + return null; + }; + break; + + + case "punishments": + menuBuilder.setDescription( + "**Reset Punishments**\n" + + "You are about to reset all punishments.\n" + + "This will result in all punishments being removed & as such, strikes no longer mute, kick or ban members.\n" + + "Are you sure you want to reset all punishments?" + ); + callable = () -> + { + vortex.getDatabase().actions.removeAllActions(event.getGuild()); + return null; + }; + break; + + case "strikes": + menuBuilder.setDescription( + "**Reset Strikes**\n" + + "You are about to reset **__all__** strikes.\n" + + "This will result in all strikes being pardoned from all members.\n" + + "No bans or mutes will be lifted.\n" + + "Are you sure you want to reset all strikes?" + ); + callable = () -> + { + vortex.getDatabase().strikes.resetAllStrikes(event.getGuild()); + return null; + }; + break; + + case "all": + menuBuilder.setDescription( + "**Reset All**\n" + + "You are about to reset **__all__** settings & strikes.\n" + + "This will result in Automod, settings, filters, punishments & strikes to be reset.\n" + + "No bans or mutes will be lifted.\n" + + "Are you sure you want to reset all settings & strikes?" + ); + callable = () -> + { + vortex.getDatabase().automod.reset(event.getGuild()); + vortex.getDatabase().filters.deleteAllFilters(event.getGuild().getIdLong()); + vortex.getDatabase().settings.reset(event.getGuild()); + vortex.getDatabase().ignores.unignoreAll(event.getGuild()); + vortex.getDatabase().actions.removeAllActions(event.getGuild()); + vortex.getDatabase().strikes.resetAllStrikes(event.getGuild()); + return null; + }; + break; + + default: + event.replyError("Unknown section"); + return; + } + + menuBuilder + .setAction(reactionEmote -> + { + if (reactionEmote.getName().equals(CONFIRM_RESET_EMOJI)) + { + try + { + callable.call(); + event.replySuccess("Reset successful"); + } + catch (Exception e) + { + event.replyError("An error occurred while resetting"); + } + } + }) + .build() + .display(event.getTextChannel()); + } +} 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 92281513..f8a5bd48 100644 --- a/src/main/java/com/jagrosh/vortex/database/managers/AutomodManager.java +++ b/src/main/java/com/jagrosh/vortex/database/managers/AutomodManager.java @@ -383,6 +383,16 @@ public void setDehoistChar(Guild guild, char dehoistChar) } }); } + + public void reset(Guild guild) + { + invalidateCache(guild); + readWrite(selectAll(GUILD_ID.is(guild.getIdLong())), rs -> + { + if(rs.next()) + rs.deleteRow(); + }); + } private void invalidateCache(Guild guild) { diff --git a/src/main/java/com/jagrosh/vortex/database/managers/GuildSettingsDataManager.java b/src/main/java/com/jagrosh/vortex/database/managers/GuildSettingsDataManager.java index b6a46eb7..04c927dc 100644 --- a/src/main/java/com/jagrosh/vortex/database/managers/GuildSettingsDataManager.java +++ b/src/main/java/com/jagrosh/vortex/database/managers/GuildSettingsDataManager.java @@ -296,6 +296,15 @@ public void setTimezone(Guild guild, ZoneId zone) } }); } + + public void reset(Guild guild) + { + readWrite(selectAll(GUILD_ID.is(guild.getIdLong())), rs -> + { + if(rs.next()) + rs.deleteRow(); + }); + } public void enableRaidMode(Guild guild) { diff --git a/src/main/java/com/jagrosh/vortex/database/managers/IgnoreManager.java b/src/main/java/com/jagrosh/vortex/database/managers/IgnoreManager.java index 8f0c80c9..9ed69e55 100644 --- a/src/main/java/com/jagrosh/vortex/database/managers/IgnoreManager.java +++ b/src/main/java/com/jagrosh/vortex/database/managers/IgnoreManager.java @@ -152,6 +152,15 @@ public boolean unignore(Role role) return false; }); } + + public void unignoreAll(Guild guild) + { + readWrite(selectAll(GUILD_ID.is(guild.getIdLong())), rs -> + { + while(rs.next()) + rs.deleteRow(); + }); + } private void invalidateCache(Guild guild) { diff --git a/src/main/java/com/jagrosh/vortex/database/managers/PunishmentManager.java b/src/main/java/com/jagrosh/vortex/database/managers/PunishmentManager.java index 79946f5d..129c72d0 100644 --- a/src/main/java/com/jagrosh/vortex/database/managers/PunishmentManager.java +++ b/src/main/java/com/jagrosh/vortex/database/managers/PunishmentManager.java @@ -93,6 +93,15 @@ public void removeAction(Guild guild, int numStrikes) rs.deleteRow(); }); } + + public void removeAllActions(Guild guild) + { + readWrite(selectAll(GUILD_ID.is(guild.getIdLong())), rs -> + { + while(rs.next()) + rs.deleteRow(); + }); + } public void setAction(Guild guild, int numStrikes, Action action) { diff --git a/src/main/java/com/jagrosh/vortex/database/managers/StrikeManager.java b/src/main/java/com/jagrosh/vortex/database/managers/StrikeManager.java index 9dee2c33..ca7e7b6a 100644 --- a/src/main/java/com/jagrosh/vortex/database/managers/StrikeManager.java +++ b/src/main/java/com/jagrosh/vortex/database/managers/StrikeManager.java @@ -117,4 +117,13 @@ public JSONObject getAllStrikesJson(Guild guild) getAllStrikes(guild).entrySet().forEach(e -> obj.put(Long.toString(e.getKey()), e.getValue())); return obj; } + + public void resetAllStrikes(Guild guild) + { + readWrite(selectAll(GUILD_ID.is(guild.getIdLong())), rs -> + { + while(rs.next()) + rs.deleteRow(); + }); + } } From b5410bea97681a57f889809722c2f00df398d44c Mon Sep 17 00:00:00 2001 From: Michaili K Date: Sun, 11 Oct 2020 20:50:50 +0200 Subject: [PATCH 2/9] Add a 60-second cooldown --- src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java b/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java index 894fecef..6a73de85 100644 --- a/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java @@ -45,6 +45,7 @@ public ResetCmd(Vortex vortex) this.category = new Category("Settings"); this.guildOnly = true; this.userPermissions = new Permission[]{Permission.MANAGE_SERVER}; + this.cooldown = 60; } @Override From 6b46782588accb88d3f667071257fe6aa208b209 Mon Sep 17 00:00:00 2001 From: Michaili K Date: Sun, 11 Oct 2020 21:18:31 +0200 Subject: [PATCH 3/9] Replace callables with a (custom) throwable consumer --- .../vortex/commands/settings/ResetCmd.java | 62 +++++++------------ 1 file changed, 21 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java b/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java index 6a73de85..33461285 100644 --- a/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java @@ -20,9 +20,9 @@ import com.jagrosh.jdautilities.menu.ButtonMenu; import com.jagrosh.vortex.Vortex; import net.dv8tion.jda.core.Permission; +import net.dv8tion.jda.core.entities.Guild; import net.dv8tion.jda.core.exceptions.PermissionException; -import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; /** @@ -73,7 +73,7 @@ protected void execute(CommandEvent event) } }); - Callable callable; + ThrowableConsumer consumer; switch (event.getArgs().toLowerCase()) { @@ -85,11 +85,7 @@ protected void execute(CommandEvent event) "Filters aren't affected by this reset.\n\n" + "Are you sure you want to reset all Automod settings?" ); - callable = () -> - { - vortex.getDatabase().automod.reset(event.getGuild()); - return null; - }; + consumer = (guild) -> vortex.getDatabase().automod.reset(guild); break; @@ -99,11 +95,7 @@ protected void execute(CommandEvent event) "You are about to remove all filters.\n" + "Are you sure you want to remove all Filters?" ); - callable = () -> - { - vortex.getDatabase().filters.deleteAllFilters(event.getGuild().getIdLong()); - return null; - }; + consumer = (guild) -> vortex.getDatabase().filters.deleteAllFilters(guild.getIdLong()); break; @@ -115,11 +107,7 @@ protected void execute(CommandEvent event) "Punishments, Automod, Ignored roles/channels & Filters aren't affected by this reset.\n" + "Are you sure you want to reset all Server Settings?" ); - callable = () -> - { - vortex.getDatabase().settings.reset(event.getGuild()); - return null; - }; + consumer = (guild) -> vortex.getDatabase().settings.reset(guild); break; @@ -130,11 +118,7 @@ protected void execute(CommandEvent event) "This will result in AutoMod no longer ignoring any channels & roles added to the ignore list.\n" + "Are you sure you want to reset all ignored channels & roles?" ); - callable = () -> - { - vortex.getDatabase().ignores.unignoreAll(event.getGuild()); - return null; - }; + consumer = (guild) -> vortex.getDatabase().ignores.unignoreAll(guild); break; @@ -145,11 +129,7 @@ protected void execute(CommandEvent event) "This will result in all punishments being removed & as such, strikes no longer mute, kick or ban members.\n" + "Are you sure you want to reset all punishments?" ); - callable = () -> - { - vortex.getDatabase().actions.removeAllActions(event.getGuild()); - return null; - }; + consumer = (guild) -> vortex.getDatabase().actions.removeAllActions(guild); break; case "strikes": @@ -160,11 +140,7 @@ protected void execute(CommandEvent event) "No bans or mutes will be lifted.\n" + "Are you sure you want to reset all strikes?" ); - callable = () -> - { - vortex.getDatabase().strikes.resetAllStrikes(event.getGuild()); - return null; - }; + consumer = (guild) -> vortex.getDatabase().strikes.resetAllStrikes(guild); break; case "all": @@ -175,15 +151,14 @@ protected void execute(CommandEvent event) "No bans or mutes will be lifted.\n" + "Are you sure you want to reset all settings & strikes?" ); - callable = () -> + consumer = (guild) -> { - vortex.getDatabase().automod.reset(event.getGuild()); - vortex.getDatabase().filters.deleteAllFilters(event.getGuild().getIdLong()); - vortex.getDatabase().settings.reset(event.getGuild()); - vortex.getDatabase().ignores.unignoreAll(event.getGuild()); - vortex.getDatabase().actions.removeAllActions(event.getGuild()); - vortex.getDatabase().strikes.resetAllStrikes(event.getGuild()); - return null; + vortex.getDatabase().automod.reset(guild); + vortex.getDatabase().filters.deleteAllFilters(guild.getIdLong()); + vortex.getDatabase().settings.reset(guild); + vortex.getDatabase().ignores.unignoreAll(guild); + vortex.getDatabase().actions.removeAllActions(guild); + vortex.getDatabase().strikes.resetAllStrikes(guild); }; break; @@ -199,7 +174,7 @@ protected void execute(CommandEvent event) { try { - callable.call(); + consumer.call(event.getGuild()); event.replySuccess("Reset successful"); } catch (Exception e) @@ -211,4 +186,9 @@ protected void execute(CommandEvent event) .build() .display(event.getTextChannel()); } + + private interface ThrowableConsumer + { + void call(T t) throws Exception; + } } From 12b07e9aba274741ab09c03aa435a877f8fc9c0e Mon Sep 17 00:00:00 2001 From: Michaili K Date: Sun, 11 Oct 2020 21:31:31 +0200 Subject: [PATCH 4/9] Use description var to set description for the menu --- .../vortex/commands/settings/ResetCmd.java | 79 ++++++++----------- 1 file changed, 34 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java b/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java index 33461285..23f24206 100644 --- a/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java @@ -74,83 +74,71 @@ protected void execute(CommandEvent event) }); ThrowableConsumer consumer; + String description; switch (event.getArgs().toLowerCase()) { case "automod": - menuBuilder.setDescription( - "**Reset Automod**\n" + - "You are about to reset Automod.\n" + - "This will result in all Automod settings to be disabled.\n" + - "Filters aren't affected by this reset.\n\n" + - "Are you sure you want to reset all Automod settings?" - ); + description = "**Reset Automod**\n" + + "You are about to reset Automod.\n" + + "This will result in all Automod settings to be disabled.\n" + + "Filters aren't affected by this reset.\n\n" + + "Are you sure you want to reset all Automod settings?"; + consumer = (guild) -> vortex.getDatabase().automod.reset(guild); break; case "filters": - menuBuilder.setDescription( - "**Reset Filters**\n" + - "You are about to remove all filters.\n" + - "Are you sure you want to remove all Filters?" - ); + description = "**Reset Filters**\n" + + "You are about to remove all filters.\n" + + "Are you sure you want to remove all Filters?"; consumer = (guild) -> vortex.getDatabase().filters.deleteAllFilters(guild.getIdLong()); break; case "settings": - menuBuilder.setDescription( - "**Reset Settings**\n" + - "You are about to reset all Server Settings.\n" + - "This will result in raid mode being disabled & Server Settings like mod role & logs to be reset.\n" + - "Punishments, Automod, Ignored roles/channels & Filters aren't affected by this reset.\n" + - "Are you sure you want to reset all Server Settings?" - ); + description = "**Reset Settings**\n" + + "You are about to reset all Server Settings.\n" + + "This will result in raid mode being disabled & Server Settings like mod role & logs to be reset.\n" + + "Punishments, Automod, Ignored roles/channels & Filters aren't affected by this reset.\n" + + "Are you sure you want to reset all Server Settings?"; consumer = (guild) -> vortex.getDatabase().settings.reset(guild); break; case "ignores": - menuBuilder.setDescription( - "**Reset Ignores**\n" + - "You are about to reset ignored channels & roles.\n" + - "This will result in AutoMod no longer ignoring any channels & roles added to the ignore list.\n" + - "Are you sure you want to reset all ignored channels & roles?" - ); + description = "**Reset Ignores**\n" + + "You are about to reset ignored channels & roles.\n" + + "This will result in AutoMod no longer ignoring any channels & roles added to the ignore list.\n" + + "Are you sure you want to reset all ignored channels & roles?"; consumer = (guild) -> vortex.getDatabase().ignores.unignoreAll(guild); break; case "punishments": - menuBuilder.setDescription( - "**Reset Punishments**\n" + - "You are about to reset all punishments.\n" + - "This will result in all punishments being removed & as such, strikes no longer mute, kick or ban members.\n" + - "Are you sure you want to reset all punishments?" - ); + description = "**Reset Punishments**\n" + + "You are about to reset all punishments.\n" + + "This will result in all punishments being removed & as such, strikes no longer mute, kick or ban members.\n" + + "Are you sure you want to reset all punishments?"; consumer = (guild) -> vortex.getDatabase().actions.removeAllActions(guild); break; case "strikes": - menuBuilder.setDescription( - "**Reset Strikes**\n" + - "You are about to reset **__all__** strikes.\n" + - "This will result in all strikes being pardoned from all members.\n" + - "No bans or mutes will be lifted.\n" + - "Are you sure you want to reset all strikes?" - ); + description = "**Reset Strikes**\n" + + "You are about to reset **__all__** strikes.\n" + + "This will result in all strikes being pardoned from all members.\n" + + "No bans or mutes will be lifted.\n" + + "Are you sure you want to reset all strikes?"; consumer = (guild) -> vortex.getDatabase().strikes.resetAllStrikes(guild); break; case "all": - menuBuilder.setDescription( - "**Reset All**\n" + - "You are about to reset **__all__** settings & strikes.\n" + - "This will result in Automod, settings, filters, punishments & strikes to be reset.\n" + - "No bans or mutes will be lifted.\n" + - "Are you sure you want to reset all settings & strikes?" - ); + description = "**Reset All**\n" + + "You are about to reset **__all__** settings & strikes.\n" + + "This will result in Automod, settings, filters, punishments & strikes to be reset.\n" + + "No bans or mutes will be lifted.\n" + + "Are you sure you want to reset all settings & strikes?"; consumer = (guild) -> { vortex.getDatabase().automod.reset(guild); @@ -168,6 +156,7 @@ protected void execute(CommandEvent event) } menuBuilder + .setDescription(description) .setAction(reactionEmote -> { if (reactionEmote.getName().equals(CONFIRM_RESET_EMOJI)) From 1a2f925d113c5df1c78eefdde93955e2d2029867 Mon Sep 17 00:00:00 2001 From: Michaili K Date: Wed, 18 Nov 2020 16:17:33 +0100 Subject: [PATCH 5/9] Fix imports for JDA4 --- .../java/com/jagrosh/vortex/commands/settings/ResetCmd.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java b/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java index 23f24206..df85c3cb 100644 --- a/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java @@ -19,9 +19,9 @@ import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.menu.ButtonMenu; import com.jagrosh.vortex.Vortex; -import net.dv8tion.jda.core.Permission; -import net.dv8tion.jda.core.entities.Guild; -import net.dv8tion.jda.core.exceptions.PermissionException; +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.exceptions.PermissionException; import java.util.concurrent.TimeUnit; From ea0784949f1ce8f2e09f2e552019c23b9ffa4d04 Mon Sep 17 00:00:00 2001 From: Michaili K Date: Wed, 18 Nov 2020 16:18:13 +0100 Subject: [PATCH 6/9] Invalidate guild cache on reset --- .../vortex/database/managers/GuildSettingsDataManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/jagrosh/vortex/database/managers/GuildSettingsDataManager.java b/src/main/java/com/jagrosh/vortex/database/managers/GuildSettingsDataManager.java index dcc83b11..cb72dfcb 100644 --- a/src/main/java/com/jagrosh/vortex/database/managers/GuildSettingsDataManager.java +++ b/src/main/java/com/jagrosh/vortex/database/managers/GuildSettingsDataManager.java @@ -298,6 +298,7 @@ public void setTimezone(Guild guild, ZoneId zone) public void reset(Guild guild) { + invalidateCache(guild); readWrite(selectAll(GUILD_ID.is(guild.getIdLong())), rs -> { if(rs.next()) From d7bc1d85e15c15b0e81b19723d4df6cf7695657c Mon Sep 17 00:00:00 2001 From: Michaili K Date: Wed, 18 Nov 2020 20:53:51 +0100 Subject: [PATCH 7/9] Limit reset command to administrators Co-authored-by: John Grosh --- .../java/com/jagrosh/vortex/commands/settings/ResetCmd.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java b/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java index df85c3cb..cba3f67e 100644 --- a/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java @@ -44,7 +44,7 @@ public ResetCmd(Vortex vortex) this.arguments = ""; this.category = new Category("Settings"); this.guildOnly = true; - this.userPermissions = new Permission[]{Permission.MANAGE_SERVER}; + this.userPermissions = new Permission[]{Permission.ADMINISTRATOR}; this.cooldown = 60; } From 4bddd34dd5144ac8c9990b34f67cf06b9bdd9a6d Mon Sep 17 00:00:00 2001 From: Michaili K Date: Wed, 18 Nov 2020 20:54:32 +0100 Subject: [PATCH 8/9] Invalidate ignore cache when unignoring all channels & roles Co-authored-by: John Grosh --- .../java/com/jagrosh/vortex/database/managers/IgnoreManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/jagrosh/vortex/database/managers/IgnoreManager.java b/src/main/java/com/jagrosh/vortex/database/managers/IgnoreManager.java index 56f83f1f..7c537aa1 100644 --- a/src/main/java/com/jagrosh/vortex/database/managers/IgnoreManager.java +++ b/src/main/java/com/jagrosh/vortex/database/managers/IgnoreManager.java @@ -155,6 +155,7 @@ public boolean unignore(Role role) public void unignoreAll(Guild guild) { + invalidateCache(guild); readWrite(selectAll(GUILD_ID.is(guild.getIdLong())), rs -> { while(rs.next()) From a849af108765ef680c98e0dda5e257a8dc730064 Mon Sep 17 00:00:00 2001 From: Michaili K Date: Thu, 19 Nov 2020 21:21:39 +0100 Subject: [PATCH 9/9] Reset invite whitelists when resetting automod or all --- .../com/jagrosh/vortex/commands/settings/ResetCmd.java | 8 ++++++-- .../database/managers/InviteWhitelistManager.java | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java b/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java index cba3f67e..c7b5fc02 100644 --- a/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/settings/ResetCmd.java @@ -81,11 +81,14 @@ protected void execute(CommandEvent event) case "automod": description = "**Reset Automod**\n" + "You are about to reset Automod.\n" + - "This will result in all Automod settings to be disabled.\n" + + "This will result in all Automod settings to be disabled/reset.\n" + "Filters aren't affected by this reset.\n\n" + "Are you sure you want to reset all Automod settings?"; - consumer = (guild) -> vortex.getDatabase().automod.reset(guild); + consumer = (guild) -> { + vortex.getDatabase().automod.reset(guild); + vortex.getDatabase().inviteWhitelist.removeAll(guild); + }; break; @@ -142,6 +145,7 @@ protected void execute(CommandEvent event) consumer = (guild) -> { vortex.getDatabase().automod.reset(guild); + vortex.getDatabase().inviteWhitelist.removeAll(guild); vortex.getDatabase().filters.deleteAllFilters(guild.getIdLong()); vortex.getDatabase().settings.reset(guild); vortex.getDatabase().ignores.unignoreAll(guild); diff --git a/src/main/java/com/jagrosh/vortex/database/managers/InviteWhitelistManager.java b/src/main/java/com/jagrosh/vortex/database/managers/InviteWhitelistManager.java index bcc89285..5a079503 100644 --- a/src/main/java/com/jagrosh/vortex/database/managers/InviteWhitelistManager.java +++ b/src/main/java/com/jagrosh/vortex/database/managers/InviteWhitelistManager.java @@ -118,6 +118,16 @@ public void removeAllFromWhitelist(Guild guild, Collection whitelistIds) } } + public void removeAll(Guild guild) + { + invalidateCache(guild); + readWrite(selectAll(GUILD_ID.is(guild.getIdLong())), rs -> + { + while(rs.next()) + rs.deleteRow(); + }); + } + public List readWhitelist(Guild guild) { if(cache.contains(guild.getIdLong()))