diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index a1e97dd..69a33e3 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.fpghoti Biscuit - 1.1 + 1.2 src/main/java diff --git a/pom.xml b/pom.xml index 845ecd0..bc7a462 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.fpghoti Biscuit - 1.1 + 1.2 src/main/java @@ -80,6 +80,11 @@ + + org.apache.commons + commons-configuration2 + 2.7 + org.spigotmc spigot-api diff --git a/src/main/java/com/fpghoti/biscuit/Main.java b/src/main/java/com/fpghoti/biscuit/Main.java index 2030792..6e1ab32 100644 --- a/src/main/java/com/fpghoti/biscuit/Main.java +++ b/src/main/java/com/fpghoti/biscuit/Main.java @@ -12,11 +12,10 @@ import com.fpghoti.biscuit.commands.client.AddCommand; import com.fpghoti.biscuit.commands.client.ChanIDCommand; import com.fpghoti.biscuit.commands.client.ChnameCommand; import com.fpghoti.biscuit.commands.client.DivideCommand; -import com.fpghoti.biscuit.commands.client.DontNotifyCommand; +import com.fpghoti.biscuit.commands.client.ToggleRoleCommand; import com.fpghoti.biscuit.commands.client.HelpCommand; import com.fpghoti.biscuit.commands.client.MultiplyCommand; import com.fpghoti.biscuit.commands.client.NotSpammerCommand; -import com.fpghoti.biscuit.commands.client.NotifyCommand; import com.fpghoti.biscuit.commands.client.PingCommand; import com.fpghoti.biscuit.commands.client.PowerCommand; import com.fpghoti.biscuit.commands.client.RecentSpammersCommand; @@ -29,7 +28,6 @@ import com.fpghoti.biscuit.commands.console.SayCommand; import com.fpghoti.biscuit.commands.console.ShutdownConsoleCommand; import com.fpghoti.biscuit.config.ConfigRetrieval; import com.fpghoti.biscuit.config.PropertiesRetrieval; -import com.fpghoti.biscuit.global.Properties; import com.fpghoti.biscuit.listener.DMListener; import com.fpghoti.biscuit.listener.JoinListener; import com.fpghoti.biscuit.listener.MessageDeleteListener; @@ -77,9 +75,9 @@ public class Main { jda.addEventListener(new DMListener()); String link = "NULL"; - Properties.naughtyList = ConfigRetrieval.getFromConfig("NaughtyList"); - Properties.customdefaultrole = ConfigRetrieval.getFromConfig("UseCustomDefaultRole").equalsIgnoreCase("true"); - Properties.roleName = ConfigRetrieval.getFromConfig("DefaultRoleName"); +// Properties.naughtyList = ConfigRetrieval.getFromConfig("NaughtyList"); +// Properties.customdefaultrole = ConfigRetrieval.getFromConfig("UseCustomDefaultRole").equalsIgnoreCase("true"); +// Properties.roleName = ConfigRetrieval.getFromConfig("DefaultRoleName"); biscuit.addTimer(new ChatCountTimer()); biscuit.addTimer(new BotMsgRemoveTimer()); @@ -103,8 +101,7 @@ public class Main { commands.add(new ChanIDCommand()); commands.add(new UIDCommand()); commands.add(new ChnameCommand()); - commands.add(new NotifyCommand()); - commands.add(new DontNotifyCommand()); + commands.add(new ToggleRoleCommand()); commands.add(new SquareRootCommand()); commands.add(new AddCommand()); commands.add(new SubtractCommand()); diff --git a/src/main/java/com/fpghoti/biscuit/api/API.java b/src/main/java/com/fpghoti/biscuit/api/API.java deleted file mode 100644 index b0c0992..0000000 --- a/src/main/java/com/fpghoti/biscuit/api/API.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.fpghoti.biscuit.api; - -import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.Main; - -public class API { - - public static Biscuit getBiscuit() { - return Main.biscuit; - } - -} diff --git a/src/main/java/com/fpghoti/biscuit/commands/CommandListener.java b/src/main/java/com/fpghoti/biscuit/commands/CommandListener.java index ed8d781..44880e1 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/CommandListener.java +++ b/src/main/java/com/fpghoti/biscuit/commands/CommandListener.java @@ -5,10 +5,12 @@ import java.util.Scanner; import org.slf4j.Logger; import com.fpghoti.biscuit.Main; -import com.fpghoti.biscuit.api.API; import com.fpghoti.biscuit.config.PropertiesRetrieval; +import com.fpghoti.biscuit.util.PermUtil; import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.entities.ChannelType; +import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; @@ -17,15 +19,27 @@ public class CommandListener extends ListenerAdapter implements Runnable { public Scanner sc; public JDA jda; Logger log = Main.log; - + @Override public void onMessageReceived(MessageReceivedEvent event){ - if(!event.getAuthor().isBot() && event.getMessage().getContentDisplay().startsWith(PropertiesRetrieval.getCommandSignifier()) && event.getMessage().getAuthor().getId() != event.getJDA().getSelfUser().getId()){ - //log.info("True"); - API.getBiscuit().getCommandManager().parse(event.getMessage().getContentRaw().toLowerCase(), event); + if (event.isFromType(ChannelType.TEXT)) { + if(PermUtil.isAdmin(event.getMember()) || !PropertiesRetrieval.restrictCmdChannels() || (PropertiesRetrieval.restrictCmdChannels() && isBotChannel(event.getTextChannel()))) { + if(!event.getAuthor().isBot() && event.getMessage().getContentDisplay().startsWith(PropertiesRetrieval.getCommandSignifier()) && event.getMessage().getAuthor().getId() != event.getJDA().getSelfUser().getId()){ + Main.getBiscuit().getCommandManager().parse(event.getMessage().getContentRaw().toLowerCase(), event); + } + } } } + private boolean isBotChannel(TextChannel c) { + for(String s : PropertiesRetrieval.getCmdChannels()) { + if(s.equals(c.getName())) { + return true; + } + } + return false; + } + public void run() { while(sc.hasNextLine()) { @@ -41,7 +55,7 @@ public class CommandListener extends ListenerAdapter implements Runnable { private void runCommand(String label, String[] args) { log.info(label); - API.getBiscuit().getCommandManager().dispatch(label, args); + Main.getBiscuit().getCommandManager().dispatch(label, args); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/CommandManager.java b/src/main/java/com/fpghoti/biscuit/commands/CommandManager.java index 7dff390..2524185 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/CommandManager.java +++ b/src/main/java/com/fpghoti/biscuit/commands/CommandManager.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.List; import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.config.PropertiesRetrieval; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; @@ -73,7 +73,7 @@ public class CommandManager { } public void commandReply(MessageReceivedEvent e, String msg) { - Biscuit b = API.getBiscuit(); + Biscuit b = Main.getBiscuit(); if(e != null) { b.say(e.getTextChannel(), msg); }else { diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/AddCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/AddCommand.java index 7388964..a089e4c 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/AddCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/AddCommand.java @@ -1,7 +1,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.commands.ClientCommand; import com.fpghoti.biscuit.config.PropertiesRetrieval; import com.fpghoti.biscuit.util.Util; @@ -21,7 +21,7 @@ public class AddCommand extends ClientCommand{ @Override public void execute(String[] args, MessageReceivedEvent event) { - Biscuit b = API.getBiscuit(); + Biscuit b = Main.getBiscuit(); b.log(event.getAuthor().getName() + " issued a command: -add"); if(args[0] != null && Util.isDeciDigit(args[0]) && args[1] != null && Util.isDeciDigit(args[1])) { double num = Double.parseDouble(args[0]); diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/ChanIDCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/ChanIDCommand.java index dd2bd16..75c0ed0 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/ChanIDCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/ChanIDCommand.java @@ -1,7 +1,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.commands.ClientCommand; import com.fpghoti.biscuit.config.PropertiesRetrieval; @@ -20,7 +20,7 @@ public class ChanIDCommand extends ClientCommand{ @Override public void execute(String[] args, MessageReceivedEvent event) { - Biscuit b = API.getBiscuit(); + Biscuit b = Main.getBiscuit(); b.log(event.getAuthor().getName() + " issued a command: -chanid"); String id = event.getTextChannel().getId(); event.getTextChannel().sendMessage(id).queue(); diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/ChnameCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/ChnameCommand.java index ab7ae99..4fc632c 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/ChnameCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/ChnameCommand.java @@ -1,7 +1,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.commands.ClientCommand; import com.fpghoti.biscuit.config.PropertiesRetrieval; import com.fpghoti.biscuit.util.PermUtil; @@ -21,7 +21,7 @@ public class ChnameCommand extends ClientCommand{ @Override public void execute(String[] args, MessageReceivedEvent event) { - Biscuit b = API.getBiscuit(); + Biscuit b = Main.getBiscuit(); b.log(event.getAuthor().getName() + " issued a command: -chname"); if(PermUtil.isMod(event.getMember()) || PermUtil.canMute(event.getMember())) { event.getTextChannel().sendMessage("DEBUG: " + event.getTextChannel().getName()).queue(); diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/DivideCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/DivideCommand.java index cb1b9d5..a4a7a51 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/DivideCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/DivideCommand.java @@ -1,7 +1,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.commands.ClientCommand; import com.fpghoti.biscuit.config.PropertiesRetrieval; import com.fpghoti.biscuit.util.Util; @@ -22,7 +22,7 @@ public class DivideCommand extends ClientCommand{ @Override public void execute(String[] args, MessageReceivedEvent event) { - Biscuit b = API.getBiscuit(); + Biscuit b = Main.getBiscuit(); b.log(event.getAuthor().getName() + " issued a command: -divide"); if(args[0] != null && Util.isDeciDigit(args[0]) && args[1] != null && Util.isDeciDigit(args[1])) { double num = Double.parseDouble(args[0]); diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/DontNotifyCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/DontNotifyCommand.java deleted file mode 100644 index 0c2c990..0000000 --- a/src/main/java/com/fpghoti/biscuit/commands/client/DontNotifyCommand.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.fpghoti.biscuit.commands.client; - -import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.api.API; -import com.fpghoti.biscuit.commands.ClientCommand; -import com.fpghoti.biscuit.config.PropertiesRetrieval; - -import net.dv8tion.jda.api.entities.Emote; -import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.events.message.MessageReceivedEvent; - -public class DontNotifyCommand extends ClientCommand{ - - public DontNotifyCommand() { - name = "Don't Notify"; - description = "Puts user in Don't Notify status."; - usage = PropertiesRetrieval.getCommandSignifier() + "dontnotify"; - minArgs = 0; - maxArgs = 0; - identifiers.add("dontnotify"); - } - - @Override - public void execute(String[] args, MessageReceivedEvent event) { - Biscuit b = API.getBiscuit(); - if(!event.getAuthor().isBot()) { - b.log(event.getAuthor().getName() + " issued a command: -dontnotify"); - Role role = null; - for(Role r : event.getGuild().getRoles()) { - if(r.getName().toLowerCase().contains(PropertiesRetrieval.getDontNotify())) { - role = r; - } - } - if(role == null) { - b.error("Cannot find role!"); - return; - } - - Emote done = null; - for(Emote e : event.getGuild().getEmotes()) { - if(e.getName().contains(PropertiesRetrieval.getDoneEmote())) { - done = e; - } - } - if(done == null) { - b.error("Cannot find emote!"); - return; - } - - event.getGuild().addRoleToMember(event.getMember(), role).queue(); - event.getMessage().addReaction(done).queue(); - } - - } - -} diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/MultiplyCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/MultiplyCommand.java index 3c5ba21..5c88941 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/MultiplyCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/MultiplyCommand.java @@ -1,7 +1,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.commands.ClientCommand; import com.fpghoti.biscuit.config.PropertiesRetrieval; import com.fpghoti.biscuit.util.Util; @@ -22,7 +22,7 @@ public class MultiplyCommand extends ClientCommand{ @Override public void execute(String[] args, MessageReceivedEvent event) { - Biscuit b = API.getBiscuit(); + Biscuit b = Main.getBiscuit(); b.log(event.getAuthor().getName() + " issued a command: -multiply"); if(args[0] != null && Util.isDeciDigit(args[0]) && args[1] != null && Util.isDeciDigit(args[1])) { double num = Double.parseDouble(args[0]); diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/NotSpammerCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/NotSpammerCommand.java index ccbd161..1061457 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/NotSpammerCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/NotSpammerCommand.java @@ -1,7 +1,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.commands.ClientCommand; import com.fpghoti.biscuit.config.PropertiesRetrieval; import com.fpghoti.biscuit.global.SpamRecords; @@ -24,7 +24,7 @@ public class NotSpammerCommand extends ClientCommand{ @Override public void execute(String[] args, MessageReceivedEvent event) { - Biscuit b = API.getBiscuit(); + Biscuit b = Main.getBiscuit(); b.log(event.getAuthor().getName() + " issued a command: -notspammer " + args[0]); for(Member m : event.getMessage().getMentionedMembers()){ User u = m.getUser(); diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/NotifyCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/NotifyCommand.java deleted file mode 100644 index f2feb85..0000000 --- a/src/main/java/com/fpghoti/biscuit/commands/client/NotifyCommand.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.fpghoti.biscuit.commands.client; - -import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.api.API; -import com.fpghoti.biscuit.commands.ClientCommand; -import com.fpghoti.biscuit.config.PropertiesRetrieval; - -import net.dv8tion.jda.api.entities.Emote; -import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.events.message.MessageReceivedEvent; - -public class NotifyCommand extends ClientCommand{ - - public NotifyCommand() { - name = "Notify"; - description = "Puts user in Notify status."; - usage = PropertiesRetrieval.getCommandSignifier() + "notify"; - minArgs = 0; - maxArgs = 0; - identifiers.add("notify"); - } - - @Override - public void execute(String[] args, MessageReceivedEvent event) { - Biscuit b = API.getBiscuit(); - if(!event.getAuthor().isBot()) { - b.log(event.getAuthor().getName() + " issued a command: -notify"); - Role role = null; - for(Role r : event.getGuild().getRoles()) { - if(r.getName().toLowerCase().contains(PropertiesRetrieval.getDontNotify())) { - role = r; - } - } - if(role == null) { - b.error("Cannot find role!"); - return; - } - - Emote done = null; - for(Emote e : event.getGuild().getEmotes()) { - if(e.getName().contains(PropertiesRetrieval.getDoneEmote())) { - done = e; - } - } - if(done == null) { - b.error("Cannot find emote!"); - return; - } - - event.getGuild().removeRoleFromMember(event.getMember(),role).queue(); - event.getMessage().addReaction(done).queue(); - } - - } - -} diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/PingCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/PingCommand.java index 879a9e9..31de742 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/PingCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/PingCommand.java @@ -1,7 +1,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.commands.ClientCommand; import com.fpghoti.biscuit.config.PropertiesRetrieval; @@ -20,7 +20,7 @@ public class PingCommand extends ClientCommand{ @Override public void execute(String[] args, MessageReceivedEvent event) { - Biscuit b = API.getBiscuit(); + Biscuit b = Main.getBiscuit(); b.log(event.getAuthor().getName() + " issued a command: -ping"); event.getTextChannel().sendMessage("Pong!").queue(); } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/PowerCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/PowerCommand.java index 8e4e5ce..b295a4f 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/PowerCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/PowerCommand.java @@ -1,7 +1,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.commands.ClientCommand; import com.fpghoti.biscuit.config.PropertiesRetrieval; import com.fpghoti.biscuit.util.Util; @@ -22,7 +22,7 @@ public class PowerCommand extends ClientCommand{ @Override public void execute(String[] args, MessageReceivedEvent event) { - Biscuit b = API.getBiscuit(); + Biscuit b = Main.getBiscuit(); b.log(event.getAuthor().getName() + " issued a command: -power"); if(args[0] != null && Util.isDeciDigit(args[0]) && args[1] != null && Util.isDeciDigit(args[1])) { double num = Double.parseDouble(args[0]); diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/RecentSpammersCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/RecentSpammersCommand.java index d9100b8..8b6c9d3 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/RecentSpammersCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/RecentSpammersCommand.java @@ -1,7 +1,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.commands.ClientCommand; import com.fpghoti.biscuit.config.PropertiesRetrieval; import com.fpghoti.biscuit.global.SpamRecords; @@ -22,7 +22,7 @@ public class RecentSpammersCommand extends ClientCommand{ @Override public void execute(String[] args, MessageReceivedEvent event) { - Biscuit b = API.getBiscuit(); + Biscuit b = Main.getBiscuit(); b.log(event.getAuthor().getName() + " issued a command: -recentspammers"); String msg = "Recent spammers:"; for( User u: SpamRecords.spammers){ diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/SoftMuteCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/SoftMuteCommand.java index 56343dd..2ea298a 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/SoftMuteCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/SoftMuteCommand.java @@ -1,7 +1,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.commands.ClientCommand; import com.fpghoti.biscuit.config.PropertiesRetrieval; import com.fpghoti.biscuit.global.SpamRecords; @@ -24,7 +24,7 @@ public class SoftMuteCommand extends ClientCommand{ @Override public void execute(String[] args, MessageReceivedEvent event) { - Biscuit b = API.getBiscuit(); + Biscuit b = Main.getBiscuit(); b.log(event.getAuthor().getName() + " issued a command: -softmute " + args[0]); for(Member m : event.getMessage().getMentionedMembers()){ User u = m.getUser(); diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/SquareRootCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/SquareRootCommand.java index a0f3c91..22dad41 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/SquareRootCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/SquareRootCommand.java @@ -1,7 +1,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.commands.ClientCommand; import com.fpghoti.biscuit.config.PropertiesRetrieval; import com.fpghoti.biscuit.util.Util; @@ -22,7 +22,7 @@ public class SquareRootCommand extends ClientCommand{ @Override public void execute(String[] args, MessageReceivedEvent event) { - Biscuit b = API.getBiscuit(); + Biscuit b = Main.getBiscuit(); b.log(event.getAuthor().getName() + " issued a command: -squareroot"); if(args[0] != null && Util.isDeciDigit(args[0])) { double num = Double.parseDouble(args[0]); diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/SubtractCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/SubtractCommand.java index e560dba..6fcef0c 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/SubtractCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/SubtractCommand.java @@ -1,7 +1,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.commands.ClientCommand; import com.fpghoti.biscuit.config.PropertiesRetrieval; import com.fpghoti.biscuit.util.Util; @@ -22,7 +22,7 @@ public class SubtractCommand extends ClientCommand{ @Override public void execute(String[] args, MessageReceivedEvent event) { - Biscuit b = API.getBiscuit(); + Biscuit b = Main.getBiscuit(); b.log(event.getAuthor().getName() + " issued a command: -subtract"); if(args[0] != null && Util.isDeciDigit(args[0]) && args[1] != null && Util.isDeciDigit(args[1])) { double num = Double.parseDouble(args[0]); diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/ToggleRoleCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/ToggleRoleCommand.java new file mode 100644 index 0000000..2c905d9 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/client/ToggleRoleCommand.java @@ -0,0 +1,75 @@ +package com.fpghoti.biscuit.commands.client; + +import com.fpghoti.biscuit.Biscuit; +import com.fpghoti.biscuit.Main; +import com.fpghoti.biscuit.commands.ClientCommand; +import com.fpghoti.biscuit.config.PropertiesRetrieval; +import com.fpghoti.biscuit.util.PermUtil; + +import net.dv8tion.jda.api.entities.Emote; +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; + +public class ToggleRoleCommand extends ClientCommand{ + + public ToggleRoleCommand() { + name = "ToggleRole"; + description = "Toggles specified role on/off"; + usage = PropertiesRetrieval.getCommandSignifier() + "togglerole "; + minArgs = 1; + maxArgs = 1; + identifiers.add("togglerole"); + identifiers.add("tr"); + } + + @Override + public void execute(String[] args, MessageReceivedEvent event) { + Biscuit b = Main.getBiscuit(); + if(!event.getAuthor().isBot()) { + b.log(event.getAuthor().getName() + " issued a command: -togglerole " + args[0]); + + String rolename = ""; + + for(String s : PropertiesRetrieval.getToggleRoles()) { + if(s.equalsIgnoreCase(args[0])) { + rolename = s; + } + } + + if(rolename.equals("")) { + event.getTextChannel().sendMessage("Sorry! This role either cannot be toggled or does not exist!").queue(); + return; + } + + Role role = null; + for(Role r : event.getGuild().getRoles()) { + if(r.getName().toLowerCase().equalsIgnoreCase(rolename)) { + role = r; + } + } + if(role == null) { + b.error("Cannot find role!"); + return; + } + + Emote done = null; + for(Emote e : event.getGuild().getEmotes()) { + if(e.getName().contains(PropertiesRetrieval.getDoneEmote())) { + done = e; + } + } + if(done == null) { + b.error("Cannot find emote!"); + return; + } + if(PermUtil.hasRole(event.getMember(), role)){ + event.getGuild().removeRoleFromMember(event.getMember(),role).queue(); + }else { + event.getGuild().addRoleToMember(event.getMember(), role).queue(); + } + event.getMessage().addReaction(done).queue(); + } + + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/UIDCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/UIDCommand.java index 2cc2202..02c0995 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/UIDCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/UIDCommand.java @@ -1,7 +1,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.commands.ClientCommand; import com.fpghoti.biscuit.config.PropertiesRetrieval; import com.fpghoti.biscuit.util.PermUtil; @@ -23,7 +23,7 @@ public class UIDCommand extends ClientCommand{ @Override public void execute(String[] args, MessageReceivedEvent event) { - Biscuit b = API.getBiscuit(); + Biscuit b = Main.getBiscuit(); b.log(event.getAuthor().getName() + " issued a command: -uid " + args[0]); for(Member m : event.getMessage().getMentionedMembers()){ User u = m.getUser(); diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/UnSoftMuteCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/UnSoftMuteCommand.java index 6081820..68969fd 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/UnSoftMuteCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/UnSoftMuteCommand.java @@ -1,7 +1,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Biscuit; -import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.commands.ClientCommand; import com.fpghoti.biscuit.config.PropertiesRetrieval; import com.fpghoti.biscuit.global.SpamRecords; @@ -24,7 +24,7 @@ public class UnSoftMuteCommand extends ClientCommand{ @Override public void execute(String[] args, MessageReceivedEvent event) { - Biscuit b = API.getBiscuit(); + Biscuit b = Main.getBiscuit(); b.log(event.getAuthor().getName() + " issued a command: -unsoftmute " + args[0]); for(Member m : event.getMessage().getMentionedMembers()){ User u = m.getUser(); diff --git a/src/main/java/com/fpghoti/biscuit/commands/console/SayCommand.java b/src/main/java/com/fpghoti/biscuit/commands/console/SayCommand.java index 2173407..f378b20 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/console/SayCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/console/SayCommand.java @@ -2,7 +2,6 @@ package com.fpghoti.biscuit.commands.console; import com.fpghoti.biscuit.Biscuit; import com.fpghoti.biscuit.Main; -import com.fpghoti.biscuit.api.API; import com.fpghoti.biscuit.commands.ConsoleCommand; import net.dv8tion.jda.api.entities.Guild; @@ -23,7 +22,7 @@ public class SayCommand extends ConsoleCommand{ } public void execute(String[] args) { - Biscuit b = API.getBiscuit(); + Biscuit b = Main.getBiscuit(); if(args.length > 0) { String target = args[0]; String message = ""; diff --git a/src/main/java/com/fpghoti/biscuit/commands/console/ShutdownConsoleCommand.java b/src/main/java/com/fpghoti/biscuit/commands/console/ShutdownConsoleCommand.java index a2e630b..d61f3c5 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/console/ShutdownConsoleCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/console/ShutdownConsoleCommand.java @@ -2,7 +2,6 @@ package com.fpghoti.biscuit.commands.console; import com.fpghoti.biscuit.Biscuit; import com.fpghoti.biscuit.Main; -import com.fpghoti.biscuit.api.API; import com.fpghoti.biscuit.commands.ConsoleCommand; public class ShutdownConsoleCommand extends ConsoleCommand{ @@ -17,7 +16,7 @@ public class ShutdownConsoleCommand extends ConsoleCommand{ } public void execute(String[] args) { - Biscuit b = API.getBiscuit(); + Biscuit b = Main.getBiscuit(); if(args.length == 0) { Main.shutdown(); }else{ diff --git a/src/main/java/com/fpghoti/biscuit/config/ConfigRetrieval.java b/src/main/java/com/fpghoti/biscuit/config/ConfigRetrieval.java index 002ae6a..c26088e 100644 --- a/src/main/java/com/fpghoti/biscuit/config/ConfigRetrieval.java +++ b/src/main/java/com/fpghoti/biscuit/config/ConfigRetrieval.java @@ -2,21 +2,31 @@ package com.fpghoti.biscuit.config; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.StringWriter; import java.nio.file.Files; import java.nio.file.Path; import java.util.Properties; +import org.apache.commons.configuration2.PropertiesConfiguration; +import org.apache.commons.configuration2.PropertiesConfigurationLayout; +import org.apache.commons.configuration2.ex.ConfigurationException; import org.slf4j.Logger; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.PluginCore; public class ConfigRetrieval { - + static Logger log = Main.log; - + public static void generateConfig() { File config; if(Main.isPlugin) { @@ -36,40 +46,94 @@ public class ConfigRetrieval { } catch (Exception e) { e.printStackTrace(); } + }else { + boolean added = false; + PropertiesConfiguration prop = new PropertiesConfiguration(); + PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(); + prop.setLayout(layout); + try { + layout.load(prop, new FileReader(config)); + FileWriter fw = new FileWriter(config); + added = updateConfig(prop); + layout.save(prop, fw); + if(added) { + Main.log.info("The above options have been added to config.properties! For information on what each " + + "option does, check out the Biscuit wiki."); + } + } catch (ConfigurationException e) { + e.printStackTrace(); + Main.log.error("There was an issue preparing the config for updates."); + return; + } catch (IOException e) { + e.printStackTrace(); + Main.log.error("There was an issue preparing the config for updates."); + return; + } } } - + + private static boolean updateConfig(PropertiesConfiguration prop) { + boolean added = false; + added = addProperty("Command-Signifier", "-", prop, added); + added = addProperty("ChatLog", "true", prop, added); + added = addProperty("AllowSpamPunish", "true", prop, added); + added = addProperty("Channels-To-Not-Chatlog", "ignore_me,ignore_me2,ignore_me3", prop, added); + added = addProperty("Bot-Token", "", prop, added); + added = addProperty("NaughtyList", "piff,word123,another1", prop, added); + added = addProperty("Restrict-Cmd-Channels", "false", prop, added); + added = addProperty("CmdChannels", "bot,bot2,bot3", prop, added); + added = addProperty("ToggleRoles", "role1,role2,role3", prop, added); + added = addProperty("UseCustomDefaultRole", "true", prop, added); + added = addProperty("DefaultRoleName", "Standard", prop, added); + added = addProperty("Done-Emote", "ActionComplete", prop, added); + added = addProperty("Captcha", "false", prop, added); + added = addProperty("Captcha-Reward-Role", "cleared", prop, added); + added = addProperty("No-Captcha-Kick", "false", prop, added); + added = addProperty("No-Captcha-Kick-Time", "10", prop, added); + + return added; + } + + private static boolean addProperty(String key, String value, PropertiesConfiguration prop, boolean added) { + if(prop.getProperty(key) == null) { + Main.log.info("IMPORTANT: A new option has been added to the configuration file: " + key); + prop.addProperty(key, value); + return true; + } + return added; + } + public static String getFromConfig(String property){ - String setting = ""; + String setting = ""; - Properties prop = new Properties(); - InputStream input = null; - - File config; - - if(Main.isPlugin) { - config = new File(PluginCore.plugin.getDataFolder(), "config.properties"); - }else { - config = new File("config.properties"); - } + Properties prop = new Properties(); + InputStream input = null; + File config; + + if(Main.isPlugin) { + config = new File(PluginCore.plugin.getDataFolder(), "config.properties"); + }else { + config = new File("config.properties"); + } + + try { + input = new FileInputStream(config); + prop.load(input); + setting = prop.getProperty(property); + } catch (IOException ex) { + ex.printStackTrace(); + } finally { + if (input != null) { try { - input = new FileInputStream(config); - prop.load(input); - setting = prop.getProperty(property); - } catch (IOException ex) { - ex.printStackTrace(); - } finally { - if (input != null) { - try { - input.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } + input.close(); + } catch (IOException e) { + e.printStackTrace(); } + } + } - return setting; + return setting; } } diff --git a/src/main/java/com/fpghoti/biscuit/config/PropertiesRetrieval.java b/src/main/java/com/fpghoti/biscuit/config/PropertiesRetrieval.java index 4adc677..2e796d6 100644 --- a/src/main/java/com/fpghoti/biscuit/config/PropertiesRetrieval.java +++ b/src/main/java/com/fpghoti/biscuit/config/PropertiesRetrieval.java @@ -25,6 +25,11 @@ public class PropertiesRetrieval { return value.equalsIgnoreCase("true"); } + public static boolean customDefaultRole(){ + String value = ConfigRetrieval.getFromConfig("UseCustomDefaultRole"); + return value.equalsIgnoreCase("true"); + } + public static String getCaptchaReward(){ return ConfigRetrieval.getFromConfig("Captcha-Reward-Role"); } @@ -50,5 +55,22 @@ public class PropertiesRetrieval { String value = ConfigRetrieval.getFromConfig("ChatLog"); return value.equalsIgnoreCase("true"); } + + public static String[] getNaughtyWords(){ + return ConfigRetrieval.getFromConfig("NaughtyList").replace(" ", "").split(","); + } + + public static boolean restrictCmdChannels(){ + String value = ConfigRetrieval.getFromConfig("Restrict-Cmd-Channels"); + return value.equalsIgnoreCase("true"); + } + + public static String[] getCmdChannels(){ + return ConfigRetrieval.getFromConfig("CmdChannels").replace(" ", "").split(","); + } + + public static String[] getToggleRoles(){ + return ConfigRetrieval.getFromConfig("ToggleRoles").replace(" ", "").split(","); + } } diff --git a/src/main/java/com/fpghoti/biscuit/global/Properties.java b/src/main/java/com/fpghoti/biscuit/global/Properties.java deleted file mode 100644 index d75ad07..0000000 --- a/src/main/java/com/fpghoti/biscuit/global/Properties.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.fpghoti.biscuit.global; - -public class Properties { - - public static String naughtyList = "piff"; - public static String twnaughtyList = "piff"; - public static boolean customdefaultrole = false; - public static String roleName = ""; - -} diff --git a/src/main/java/com/fpghoti/biscuit/listener/JoinListener.java b/src/main/java/com/fpghoti/biscuit/listener/JoinListener.java index c5cbce5..2c84651 100644 --- a/src/main/java/com/fpghoti/biscuit/listener/JoinListener.java +++ b/src/main/java/com/fpghoti/biscuit/listener/JoinListener.java @@ -4,7 +4,6 @@ import org.slf4j.Logger; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.config.PropertiesRetrieval; -import com.fpghoti.biscuit.global.Properties; import com.fpghoti.biscuit.user.PreUser; import net.dv8tion.jda.api.entities.Role; @@ -20,12 +19,12 @@ public class JoinListener extends ListenerAdapter { public void onGuildMemberJoin(GuildMemberJoinEvent event) { User user = event.getMember().getUser(); log.info("MEMBER JOINED: " + user.getName() + " " + user.getAsMention()); - if(Properties.customdefaultrole) { + if(PropertiesRetrieval.customDefaultRole()) { if(!event.getMember().getUser().isBot()) { log.info("Issuing a role.."); Role role = null; for(Role r : event.getGuild().getRoles()) { - if(r.getName().contains(Properties.roleName)) { + if(r.getName().equals(PropertiesRetrieval.getDefaultRole())) { role = r; } } diff --git a/src/main/java/com/fpghoti/biscuit/util/ChatFilter.java b/src/main/java/com/fpghoti/biscuit/util/ChatFilter.java index ec41a1f..f9c81cc 100644 --- a/src/main/java/com/fpghoti/biscuit/util/ChatFilter.java +++ b/src/main/java/com/fpghoti/biscuit/util/ChatFilter.java @@ -1,6 +1,6 @@ package com.fpghoti.biscuit.util; -import com.fpghoti.biscuit.global.Properties; +import com.fpghoti.biscuit.config.PropertiesRetrieval; public class ChatFilter { @@ -34,46 +34,7 @@ public class ChatFilter { } word2 = wordp; word2 = word2.replaceAll("\\p{Punct}+", "").replaceAll("1", "i").replaceAll("5", "s").replaceAll("6", "g").replaceAll("3", "e"); - String[] list = Properties.naughtyList.split(","); - for(String item : list){ - if(word.equalsIgnoreCase(item) || word.equalsIgnoreCase(item + "s")){ - return true; - } - } - word2 = null; - return false; - } - - - public static Boolean isTWNaughty(String sentence){ - for(String s : sentence.split(" ")){ - if(isTWNaughtyWord(s)){ - return true; - } - } - return false; - } - - public static Boolean isTWNaughtyWord(String word){ - String wordp = ""; - String word2 = word.toLowerCase(); - if(word2.length() >= 2 && word2.charAt(word2.length() -1) == '!'){ - for(int i = 0; i < word2.length() -1; i++ ){ - wordp += word2.charAt(i); - } - word2 = wordp; - } - wordp = ""; - for(int i = 0; i < word2.length(); i++ ){ - if(word2.charAt(i) != '!'){ - wordp += word2.charAt(i); - }else{ - wordp += 'i'; - } - } - word2 = wordp; - word2 = word2.replaceAll("\\p{Punct}+", "").replaceAll("1", "i").replaceAll("5", "s").replaceAll("6", "g").replaceAll("3", "e"); - String[] list = Properties.twnaughtyList.split(","); + String[] list = PropertiesRetrieval.getNaughtyWords(); for(String item : list){ if(word.equalsIgnoreCase(item) || word.equalsIgnoreCase(item + "s")){ return true; diff --git a/src/main/java/com/fpghoti/biscuit/util/PermUtil.java b/src/main/java/com/fpghoti/biscuit/util/PermUtil.java index 133a70e..0da54ec 100644 --- a/src/main/java/com/fpghoti/biscuit/util/PermUtil.java +++ b/src/main/java/com/fpghoti/biscuit/util/PermUtil.java @@ -5,7 +5,7 @@ import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; public class PermUtil { - + public static boolean isAdmin(Member member){ if(member.hasPermission(Permission.ADMINISTRATOR)){ return true; @@ -27,6 +27,16 @@ public class PermUtil { return false; } + public static boolean hasRole(Member member, Role role){ + for(Role r : member.getRoles()){ + if(r.getName().equals(role.getName())){ + return true; + } + } + + return false; + } + public static boolean canMute(Member member){ if(member.hasPermission(Permission.MESSAGE_MANAGE)){ return true; diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index 9ec533b..196f42b 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -1,44 +1,51 @@ #Change this to redefine the main command signifier character/String -Command-Signifier:- +Command-Signifier = - #Set to false to disable chat logging -ChatLog:true +ChatLog = true #Automatically places spammers in spam mode -AllowSpamPunish:true +AllowSpamPunish = true -Channels-To-Not-Chatlog:ignore_me +Channels-To-Not-Chatlog = ignore_me,ignore_me2,ignore_me3 #Bot token provided by Discord -Bot-Token: +Bot-Token = #Normal channels will have messages with these words deleted by the bot -NaughtyList:piff +NaughtyList = piff,word123,another1 + +#Set to true if you want to limit the channels bot commands can be done in +#Admins will be able to bypass this +Restrict-Cmd-Channels = false + +#Channels to restrict bot commands to +CmdChannels = bot,bot2,bot3 + +#Allow users to toggle these roles +ToggleRoles = role1,role2,role3 #Bot can automatically assign role upon user join -UseCustomDefaultRole:true +UseCustomDefaultRole = true #Does nothing if UseCustomDefaultRole is off -DefaultRoleName:Standard +DefaultRoleName = Standard -#Emote to react with when action is complete -Done-Emote:ActionComplete - -#Role to disable notifications -Dont-Notify-Role:dont_notify +#Custom Emote to react with when action is complete +Done-Emote = ActionComplete #Set true to enable captcha #Use with UseCustomDefaultRole enabled #Will require user to have that role for captcha check #Role will be replaced with reward role on clear -Captcha=false +Captcha = false #Reward this role when captcha cleared -Captcha-Reward-Role:cleared +Captcha-Reward-Role = cleared #Kick if Captcha is not completed in a timely manner -No-Captcha-Kick:false +No-Captcha-Kick = false #Kick user after this number of minutes has passed without captcha clear #Due to the way the countdown works, the kick may not happen until at most one minute after -No-Captcha-Kick-Time:10 \ No newline at end of file +No-Captcha-Kick-Time = 10 \ No newline at end of file