commit ffd6e5978b1841036b6dc203ece2ec12c23d4ef0 Author: thmsdy Date: Wed Oct 2 04:42:00 2019 -0500 Initial Commit diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..d19be42 --- /dev/null +++ b/.classpath @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f3069e --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +target/ +Bot/ +logs/ +bin/ +testconfig.properties \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..75d8dcc --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + Biscuit + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..df46a9a --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..14b697b --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/config.properties b/config.properties new file mode 100644 index 0000000..6ba2895 --- /dev/null +++ b/config.properties @@ -0,0 +1,19 @@ +#Change this to redefine the main command signifier character/String +Command-Signifier:- + +#Automatically places spammers in spam mode +AllowSpamPunish:true + +Channels-To-Not-Chatlog:ignore_me + +#Bot token provided by Discord +Bot-Token: + +#Normal channels will have messages with these words deleted by the bot +NaughtyList:piff + +#Bot can automatically assign role upon user join +UseCustomDefaultRole:true + +#Does nothing if UseCustomDefaultRole is off +DefaultRoleName:Standard diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml new file mode 100644 index 0000000..99ff5fc --- /dev/null +++ b/dependency-reduced-pom.xml @@ -0,0 +1,122 @@ + + + 4.0.0 + com.fpghoti + MrBouncer + 3.0 + + src/main/java + + + true + src/main/resources + + + + + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + + maven-jar-plugin + 2.4 + + + + com.fpghoti.mrbouncer.MrBouncer + + + + + + maven-shade-plugin + 3.1.0 + + + package + + shade + + + true + + + + + + + + + oss.sonatype.org + https://oss.sonatype.org/content/repositories/snapshots/ + + + jcenter + jcenter-bintray + http://jcenter.bintray.com + + + + false + + soluvas-public-thirdparty + http://nexus.bippo.co.id/nexus/content/repositories/soluvas-public-thirdparty/ + + + + + net.java.dev.jna + jna + 4.5.0 + pom + compile + + + org.json + json + 20171018 + pom + compile + + + net.sf.trove4j + trove4j + 3.0.3 + pom + compile + + + org.apache.commons + commons-collections4 + 4.1 + pom + compile + + + org.apache.commons + commons-lang3 + 3.6 + pom + compile + + + com.squareup.okhttp + okhttp + 2.7.5 + pom + compile + + + com.neovisionaries + nv-websocket-client + 2.3 + pom + compile + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..bb7007f --- /dev/null +++ b/pom.xml @@ -0,0 +1,158 @@ + + + 4.0.0 + com.fpghoti + Biscuit + ALPHA-0.1 + + src/main/java + + + src/main/resources + true + + + + + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + com.fpghoti.biscuit.Biscuit + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 + + + package + + shade + + + true + + + + + + + + + oss.sonatype.org + https://oss.sonatype.org/content/repositories/snapshots/ + + + jcenter + jcenter-bintray + https://jcenter.bintray.com + + + soluvas-public-thirdparty + http://nexus.bippo.co.id/nexus/content/repositories/soluvas-public-thirdparty/ + + false + + + + + + com.squareup.okio + okio + 2.4.0 + + + ch.qos.logback + logback-core + 1.2.3 + + + ch.qos.logback + logback-classic + 1.2.3 + + + com.jcabi + jcabi-aspects + 0.22.6 + + + joda-time + joda-time + 2.3 + + + net.dv8tion + JDA + 4.0.0_46 + + + net.java.dev.jna + jna + 4.5.0 + pom + + + org.json + json + 20171018 + pom + + + net.sf.trove4j + trove4j + 3.0.3 + pom + + + org.apache.commons + commons-collections4 + 4.1 + pom + + + org.apache.commons + commons-lang3 + 3.6 + pom + + + com.squareup.okhttp + okhttp + 2.7.5 + pom + + + com.neovisionaries + nv-websocket-client + 2.3 + pom + + + javax.activation + activation + 1.1.1 + + + javax.mail + mail + 1.4.7 + + + \ No newline at end of file diff --git a/src/main/java/com/fpghoti/biscuit/Biscuit.java b/src/main/java/com/fpghoti/biscuit/Biscuit.java new file mode 100644 index 0000000..079c8c8 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/Biscuit.java @@ -0,0 +1,75 @@ +package com.fpghoti.biscuit; + +import java.util.ArrayList; +import java.util.List; +import java.util.Timer; + +import org.slf4j.Logger; + +import com.fpghoti.biscuit.commands.CommandManager; +import com.fpghoti.biscuit.timer.BiscuitTimer; + +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.entities.TextChannel; + +public class Biscuit { + + private JDA jda; + private Logger logger; + private CommandManager commandManager; + private Timer timer; + private List timers; + + public Biscuit(JDA jda, Logger log) { + this.jda = jda; + this.logger = log; + + commandManager = new CommandManager(); + timer = new Timer(); + timers = new ArrayList(); + } + + public void log(String message) { + logger.info(message); + } + + public void warn(String message) { + logger.warn(message); + } + + public void error(String message) { + logger.error(message); + } + + public JDA getJDA() { + return jda; + } + + public CommandManager getCommandManager() { + return commandManager; + } + + public void say(TextChannel channel, String message) { + channel.sendMessage(message).queue(); + } + + + public void loadTimers() { + timer.cancel(); + timer = new Timer(); + for(BiscuitTimer t : timers) { + timer.schedule(t,t.getDelay(), t.getPeriod()); + } + } + + public void addTimer(BiscuitTimer bt) { + timers.add(bt); + } + + public void removeTimer(BiscuitTimer bt) { + timers.remove(bt); + } + + + +} diff --git a/src/main/java/com/fpghoti/biscuit/Main.java b/src/main/java/com/fpghoti/biscuit/Main.java new file mode 100644 index 0000000..acbe4f9 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/Main.java @@ -0,0 +1,144 @@ +package com.fpghoti.biscuit; + +import java.util.List; +import java.util.Scanner; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fpghoti.biscuit.commands.BaseCommand; +import com.fpghoti.biscuit.commands.CommandListener; +import com.fpghoti.biscuit.commands.client.ChanIDCommand; +import com.fpghoti.biscuit.commands.client.ChnameCommand; +import com.fpghoti.biscuit.commands.client.DontNotifyCommand; +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.RecentSpammersCommand; +import com.fpghoti.biscuit.commands.client.ShutDownCommand; +import com.fpghoti.biscuit.commands.client.SoftMuteCommand; +import com.fpghoti.biscuit.commands.client.UIDCommand; +import com.fpghoti.biscuit.commands.client.UnSoftMuteCommand; +import com.fpghoti.biscuit.commands.console.SayCommand; +import com.fpghoti.biscuit.config.ConfigRetrieval; +import com.fpghoti.biscuit.config.PropertiesRetrieval; +import com.fpghoti.biscuit.global.Properties; +import com.fpghoti.biscuit.listener.JoinListener; +import com.fpghoti.biscuit.listener.MessageDeleteListener; +import com.fpghoti.biscuit.listener.MessageEditListener; +import com.fpghoti.biscuit.listener.MessageReceiveListener; +import com.fpghoti.biscuit.timer.task.BotMsgRemoveTimer; +import com.fpghoti.biscuit.timer.task.ChatCountTimer; +import com.fpghoti.biscuit.timer.task.FastMsgRemoveTimer; +import com.fpghoti.biscuit.timer.task.SlowMsgRemoveTimer; +import com.fpghoti.biscuit.timer.task.SoftMuteTimer; + +import ch.qos.logback.core.rolling.RollingFileAppender; +import ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy; +import net.dv8tion.jda.api.AccountType; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.JDABuilder; + +public class Main { + + private static JDA jda; + + public RollingFileAppender we; + public SizeAndTimeBasedRollingPolicy wes; + + public static final Logger log = LoggerFactory.getLogger("ch.qos.logback.core.ConsoleAppender"); + public static Scanner sc; + public static Biscuit biscuit; + + + public static void main(String[] args){ + ConfigRetrieval.generateConfig(); + log.info("========================= Welcome to Biscuit ========================="); + startJDA(); + biscuit = new Biscuit(jda, log); + startCommandListener(); + + jda.addEventListener(new MessageReceiveListener()); + jda.addEventListener(new MessageEditListener()); + jda.addEventListener(new MessageDeleteListener()); + jda.addEventListener(new JoinListener()); + + String link = "NULL"; + 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()); + biscuit.addTimer(new FastMsgRemoveTimer()); + biscuit.addTimer(new SlowMsgRemoveTimer()); + biscuit.addTimer(new SoftMuteTimer()); + + biscuit.loadTimers(); + + List commands = biscuit.getCommandManager().getCommands(); + + //Client + + commands.add(new PingCommand()); + commands.add(new SoftMuteCommand()); + commands.add(new UnSoftMuteCommand()); + commands.add(new NotSpammerCommand()); + commands.add(new RecentSpammersCommand()); + commands.add(new ChanIDCommand()); + commands.add(new ShutDownCommand()); + commands.add(new UIDCommand()); + commands.add(new ChnameCommand()); + commands.add(new NotifyCommand()); + commands.add(new DontNotifyCommand()); + + //Console + + commands.add(new SayCommand()); + + link = "https://discordapp.com/oauth2/authorize?&client_id=" + jda.getSelfUser().getId() + "&scope=bot"; + log.info("Connection successful!"); + log.info("Startup successful!"); + log.info("You can add this bot to Discord using this link:"); + log.info(link); + log.info("======================================================================"); + log.info("CHAT LOGS BEGIN HERE:"); + } + + private static void startJDA() { + String token = PropertiesRetrieval.getToken(); + log.info("Connecting bot to Discord."); + try{ + jda = new JDABuilder(AccountType.BOT).setToken(token).build(); + try { + jda.awaitReady(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + jda.setAutoReconnect(true); + }catch(Exception e){ + e.printStackTrace(); + log.error("There was an issue connecting to Discord. Bot shutting down!"); + shutdown(); + } + } + + private static void startCommandListener() { + sc = new Scanner(System.in); + CommandListener cl = new CommandListener(); + cl.sc = sc; + cl.jda = jda; + jda.addEventListener(cl); + new Thread(cl).start(); + } + + + public static void shutdown() { + log.info("Shutting down..."); + sc.close(); + System.exit(0); + } + + + +} diff --git a/src/main/java/com/fpghoti/biscuit/api/API.java b/src/main/java/com/fpghoti/biscuit/api/API.java new file mode 100644 index 0000000..b0c0992 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/api/API.java @@ -0,0 +1,12 @@ +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/BaseCommand.java b/src/main/java/com/fpghoti/biscuit/commands/BaseCommand.java new file mode 100644 index 0000000..7b3bf8c --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/BaseCommand.java @@ -0,0 +1,86 @@ +package com.fpghoti.biscuit.commands; + +import java.util.ArrayList; +import java.util.List; + +public abstract class BaseCommand{ + + protected String name; + protected String description; + protected String usage; + protected int minArgs; + protected int maxArgs; + protected List identifiers; + protected List notes; + + public BaseCommand() { + this.identifiers = new ArrayList(); + this.notes = new ArrayList(); + } + + public abstract CommandType getType(); + + public String[] validate(String input, StringBuilder identifier) { + String match = matchIdentifier(input); + + if (match != null) { + identifier = identifier.append(match); + int i = identifier.length(); + String[] args = input.substring(i).trim().split(" "); + if (args[0].isEmpty()) { + args = new String[0]; + } + int l = args.length; + if (l >= minArgs && l <= maxArgs) { + return args; + } + } + return null; + } + + public String matchIdentifier(String input) { + String lower = input.toLowerCase(); + + int index = -1; + int n = identifiers.size(); + for (int i = 0; i < n; i++) { + String identifier = identifiers.get(i).toLowerCase(); + if (lower.matches(identifier + "(\\s+.*|\\s*)")) { + if (index == -1 || identifier.length() > identifiers.get(index).length()) { + index = i; + } + } + } + + if (index != -1) { + return identifiers.get(index); + } else { + return null; + } + } + + public List getIdentifiers() { + return identifiers; + } + + public void setIdentifiers(List identifiers) { + this.identifiers = identifiers; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public String getUsage() { + return usage; + } + + public List getNotes() { + return notes; + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/commands/ClientCommand.java b/src/main/java/com/fpghoti/biscuit/commands/ClientCommand.java new file mode 100644 index 0000000..d99dc2f --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/ClientCommand.java @@ -0,0 +1,17 @@ +package com.fpghoti.biscuit.commands; + +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; + +public abstract class ClientCommand extends BaseCommand{ + + public boolean called(String[] args, MessageReceivedEvent event) { + return true; + } + + public abstract void execute(String[] args, MessageReceivedEvent event); + + public CommandType getType() { + return CommandType.CLIENT; + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/commands/CommandListener.java b/src/main/java/com/fpghoti/biscuit/commands/CommandListener.java new file mode 100644 index 0000000..328569d --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/CommandListener.java @@ -0,0 +1,47 @@ +package com.fpghoti.biscuit.commands; + +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 net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; + +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); + } + } + + public void run() { + + while(sc.hasNextLine()) { + String command = sc.nextLine(); + String label = command.split(" ")[0]; + String[] args = new String[command.split(" ").length - 1]; + for(int i = 1; i < command.split(" ").length; i++) { + args[i - 1] = command.split(" ")[i]; + } + runCommand(label, args); + } + } + + private void runCommand(String label, String[] args) { + log.info(label); + API.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 new file mode 100644 index 0000000..7dff390 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/CommandManager.java @@ -0,0 +1,97 @@ +package com.fpghoti.biscuit.commands; + +import java.util.ArrayList; +import java.util.List; + +import com.fpghoti.biscuit.Biscuit; +import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.config.PropertiesRetrieval; + +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; + +public class CommandManager { + + private List commands = new ArrayList(); + + public void parse(String message, MessageReceivedEvent e){ + ArrayList split = new ArrayList(); + String fixed = message.replaceFirst(PropertiesRetrieval.getCommandSignifier(), ""); + String[] splitMsg = fixed.split(" "); + for(String s: splitMsg){ + split.add(s); + } + String label = split.get(0); + String[] args = new String[split.size() - 1]; + split.subList(1, split.size()).toArray(args); + + dispatch(e, label, args); + } + + + public boolean dispatch(String label, String[] args) { + return dispatch(null,label,args); + } + + public boolean dispatch(MessageReceivedEvent e, String label, String[] args) { + String input = label + " "; + for (String s : args) { + input += s + " "; + } + + BaseCommand match = null; + String[] trimmedArgs = null; + StringBuilder identifier = new StringBuilder(); + + for(BaseCommand cmd : commands) { + StringBuilder tmpIdentifier = new StringBuilder(); + String[] tmpArgs = cmd.validate(input, tmpIdentifier); + if (tmpIdentifier.length() > identifier.length()) { + identifier = tmpIdentifier; + match = cmd; + trimmedArgs = tmpArgs; + } + } + + if(match != null) { + if (trimmedArgs == null || (trimmedArgs.length > 0 && trimmedArgs[0].equals("?"))) { + commandReply(e, "``Command:" + " " + match.getName() + "``"); + commandReply(e, "``Description:" + " " + match.getDescription() + "``"); + commandReply(e, "``Usage:" + " " + match.getUsage() + "``"); + List notes = match.getNotes(); + for (String note : notes) { + commandReply(e, note); + } + } else { + if(match instanceof ClientCommand && e != null) { + ((ClientCommand)match).execute(trimmedArgs, e); + }else if(match instanceof ConsoleCommand && e == null) { + ((ConsoleCommand)match).execute(trimmedArgs); + } + } + } + return true; + } + + public void commandReply(MessageReceivedEvent e, String msg) { + Biscuit b = API.getBiscuit(); + if(e != null) { + b.say(e.getTextChannel(), msg); + }else { + b.log(msg); + } + + } + + public void addCommand(BaseCommand command) { + commands.add(command); + } + + public void removeCommand(BaseCommand command) { + commands.remove(command); + } + + public List getCommands() { + return commands; + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/commands/CommandType.java b/src/main/java/com/fpghoti/biscuit/commands/CommandType.java new file mode 100644 index 0000000..33dcdbf --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/CommandType.java @@ -0,0 +1,6 @@ +package com.fpghoti.biscuit.commands; + +public enum CommandType { + CLIENT, + CONSOLE +} diff --git a/src/main/java/com/fpghoti/biscuit/commands/ConsoleCommand.java b/src/main/java/com/fpghoti/biscuit/commands/ConsoleCommand.java new file mode 100644 index 0000000..26dcb82 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/ConsoleCommand.java @@ -0,0 +1,10 @@ +package com.fpghoti.biscuit.commands; + +public abstract class ConsoleCommand extends BaseCommand{ + + public abstract void execute(String[] args); + + public CommandType getType() { + return CommandType.CONSOLE; + } +} diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/ChanIDCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/ChanIDCommand.java new file mode 100644 index 0000000..4351a62 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/client/ChanIDCommand.java @@ -0,0 +1,28 @@ +package com.fpghoti.biscuit.commands.client; + +import com.fpghoti.biscuit.Biscuit; +import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.commands.ClientCommand; + +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; + +public class ChanIDCommand extends ClientCommand{ + + public ChanIDCommand() { + name = "Channel ID"; + description = "Retrieves the channel ID."; + usage = "-chanid"; + minArgs = 0; + maxArgs = 0; + identifiers.add("chanid"); + } + + @Override + public void execute(String[] args, MessageReceivedEvent event) { + Biscuit b = API.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 new file mode 100644 index 0000000..f7440f7 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/client/ChnameCommand.java @@ -0,0 +1,30 @@ +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.util.PermUtil; + +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; + +public class ChnameCommand extends ClientCommand{ + + public ChnameCommand() { + name = "Channel Name"; + description = "Retrieves the channel name."; + usage = "-chname"; + minArgs = 0; + maxArgs = 0; + identifiers.add("chname"); + } + + @Override + public void execute(String[] args, MessageReceivedEvent event) { + Biscuit b = API.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/DontNotifyCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/DontNotifyCommand.java new file mode 100644 index 0000000..933a24a --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/client/DontNotifyCommand.java @@ -0,0 +1,55 @@ +package com.fpghoti.biscuit.commands.client; + +import com.fpghoti.biscuit.Biscuit; +import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.commands.ClientCommand; + +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 = "-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("don't notify")) { + role = r; + } + } + if(role == null) { + b.error("Cannot find role!"); + return; + } + + Emote done = null; + for(Emote e : event.getGuild().getEmotes()) { + if(e.getName().contains("ActionComplete")) { + 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/NotSpammerCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/NotSpammerCommand.java new file mode 100644 index 0000000..7c67235 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/client/NotSpammerCommand.java @@ -0,0 +1,38 @@ +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.global.SpamRecords; +import com.fpghoti.biscuit.util.PermUtil; + +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; + +public class NotSpammerCommand extends ClientCommand{ + + public NotSpammerCommand() { + name = "Not Spammer"; + description = "Delists user as spammer."; + usage = "-notspammer @"; + minArgs = 1; + maxArgs = 1; + identifiers.add("notspammer"); + } + + @Override + public void execute(String[] args, MessageReceivedEvent event) { + Biscuit b = API.getBiscuit(); + b.log(event.getAuthor().getName() + " issued a command: -notspammer " + args[0]); + for(Member m : event.getMessage().getMentionedMembers()){ + User u = m.getUser(); + String s = u.getAsMention(); + if(event.getChannel().getName().equals("public-spam-test") || (PermUtil.isMod(event.getMember()) || PermUtil.canMute(event.getMember()))) { + SpamRecords.spammers.remove(u); + event.getTextChannel().sendMessage(s+ " is no longer flagged as spam.").queue(); + } + } + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/NotifyCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/NotifyCommand.java new file mode 100644 index 0000000..5498bac --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/client/NotifyCommand.java @@ -0,0 +1,55 @@ +package com.fpghoti.biscuit.commands.client; + +import com.fpghoti.biscuit.Biscuit; +import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.commands.ClientCommand; + +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 = "-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("don't notify")) { + role = r; + } + } + if(role == null) { + b.error("Cannot find role!"); + return; + } + + Emote done = null; + for(Emote e : event.getGuild().getEmotes()) { + if(e.getName().contains("ActionComplete")) { + 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 new file mode 100644 index 0000000..09889de --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/client/PingCommand.java @@ -0,0 +1,27 @@ +package com.fpghoti.biscuit.commands.client; + +import com.fpghoti.biscuit.Biscuit; +import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.commands.ClientCommand; + +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; + +public class PingCommand extends ClientCommand{ + + public PingCommand() { + name = "Ping"; + description = "Pings the bot."; + usage = "-ping"; + minArgs = 0; + maxArgs = 0; + identifiers.add("ping"); + } + + @Override + public void execute(String[] args, MessageReceivedEvent event) { + Biscuit b = API.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/RecentSpammersCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/RecentSpammersCommand.java new file mode 100644 index 0000000..f0ba055 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/client/RecentSpammersCommand.java @@ -0,0 +1,34 @@ +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.global.SpamRecords; + +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; + +public class RecentSpammersCommand extends ClientCommand{ + + public RecentSpammersCommand() { + name = "Recent Spammers"; + description = "Retrieves a list of recent spammers."; + usage = "-recentspammers"; + minArgs = 0; + maxArgs = 0; + identifiers.add("recentspammers"); + } + + @Override + public void execute(String[] args, MessageReceivedEvent event) { + Biscuit b = API.getBiscuit(); + b.log(event.getAuthor().getName() + " issued a command: -recentspammers"); + String msg = "Recent spammers:"; + for( User u: SpamRecords.spammers){ + msg = msg + " " + u.getAsMention(); + } + event.getTextChannel().sendMessage(msg).queue(); + + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/ShutDownCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/ShutDownCommand.java new file mode 100644 index 0000000..3302319 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/client/ShutDownCommand.java @@ -0,0 +1,32 @@ +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.util.PermUtil; + +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; + +public class ShutDownCommand extends ClientCommand{ + + public ShutDownCommand() { + name = "Shut Down"; + description = "Shuts down the bot."; + usage = "-shutdown"; + minArgs = 0; + maxArgs = 0; + identifiers.add("shutdown"); + } + + @Override + public void execute(String[] args, MessageReceivedEvent event) { + Biscuit b = API.getBiscuit(); + b.log(event.getAuthor().getName() + " issued a command: -shutdown"); + if(PermUtil.isAdmin(event.getMember())) { + + event.getTextChannel().sendMessage("Shutting down Mr. Bouncer...").queue(); + + } + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/SoftMuteCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/SoftMuteCommand.java new file mode 100644 index 0000000..2de877f --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/client/SoftMuteCommand.java @@ -0,0 +1,39 @@ +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.global.SpamRecords; +import com.fpghoti.biscuit.util.PermUtil; + +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; + +public class SoftMuteCommand extends ClientCommand{ + + public SoftMuteCommand() { + name = "Soft Mute"; + description = "Soft mutes a user. In this state, they will only be able to send a message every two minutes."; + usage = "-softmute @"; + minArgs = 1; + maxArgs = 1; + identifiers.add("softmute"); + } + + @Override + public void execute(String[] args, MessageReceivedEvent event) { + Biscuit b = API.getBiscuit(); + b.log(event.getAuthor().getName() + " issued a command: -softmute " + args[0]); + for(Member m : event.getMessage().getMentionedMembers()){ + User u = m.getUser(); + String s = u.getAsMention(); + if(event.getChannel().getName().equals("public-softmute-test") || (PermUtil.isMod(event.getMember()) || PermUtil.canMute(event.getMember()))) { + SpamRecords.softmute.add(u); + u.openPrivateChannel().queue(); + event.getTextChannel().sendMessage(s+ " is now soft-muted. They will now be only able to send one message every two minutes.").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 new file mode 100644 index 0000000..00dff41 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/client/UIDCommand.java @@ -0,0 +1,35 @@ +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.util.PermUtil; + +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; + +public class UIDCommand extends ClientCommand{ + + public UIDCommand() { + name = "User ID"; + description = "Retrieves a user's ID."; + usage = "-uid @"; + minArgs = 1; + maxArgs = 1; + identifiers.add("uid"); + } + + @Override + public void execute(String[] args, MessageReceivedEvent event) { + Biscuit b = API.getBiscuit(); + b.log(event.getAuthor().getName() + " issued a command: -uid " + args[0]); + for(Member m : event.getMessage().getMentionedMembers()){ + User u = m.getUser(); + String s = u.getAsMention(); + if(PermUtil.isMod(event.getMember()) || PermUtil.canMute(event.getMember())) + event.getTextChannel().sendMessage("DEBUG: " + s+ " retrieved.").queue(); + } + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/UnSoftMuteCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/UnSoftMuteCommand.java new file mode 100644 index 0000000..aed6c9a --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/client/UnSoftMuteCommand.java @@ -0,0 +1,38 @@ +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.global.SpamRecords; +import com.fpghoti.biscuit.util.PermUtil; + +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; + +public class UnSoftMuteCommand extends ClientCommand{ + + public UnSoftMuteCommand() { + name = "Un Soft Mute"; + description = "Removes a soft mute from a user."; + usage = "-unsoftmute @"; + minArgs = 1; + maxArgs = 1; + identifiers.add("unsoftmute"); + } + + @Override + public void execute(String[] args, MessageReceivedEvent event) { + Biscuit b = API.getBiscuit(); + b.log(event.getAuthor().getName() + " issued a command: -unsoftmute " + args[0]); + for(Member m : event.getMessage().getMentionedMembers()){ + User u = m.getUser(); + String s = u.getAsMention(); + if(event.getChannel().getName().equals("public-softmute-test") || (PermUtil.isMod(event.getMember()) || PermUtil.canMute(event.getMember()))) { + SpamRecords.softmute.remove(u); + event.getTextChannel().sendMessage(s+ " is no longer soft-muted.").queue(); + } + } + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/commands/console/SayCommand.java b/src/main/java/com/fpghoti/biscuit/commands/console/SayCommand.java new file mode 100644 index 0000000..a8cbc5c --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/commands/console/SayCommand.java @@ -0,0 +1,50 @@ +package com.fpghoti.biscuit.commands.console; + +import com.fpghoti.biscuit.Biscuit; +import com.fpghoti.biscuit.api.API; +import com.fpghoti.biscuit.commands.ConsoleCommand; + +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.TextChannel; + +public class SayCommand extends ConsoleCommand{ + + public SayCommand() { + name = "Say"; + description = "Makes bot send message on specified channel."; + usage = "say "; + minArgs = 2; + maxArgs = 2000; + identifiers.add("say"); + } + + public void execute(String[] args) { + Biscuit b = API.getBiscuit(); + if(args.length > 0) { + String target = args[0]; + String message = ""; + if(args.length > 1) { + message = args[1]; + if(args.length > 2) { + for(int i = 2; i < args.length; i++) { + message = message + " " + args[i]; + } + } + for(Guild guild : b.getJDA().getGuilds()) { + + for(TextChannel c : guild.getTextChannels()) { + if(c.getName().equalsIgnoreCase(target) || c.getName().equalsIgnoreCase("#" + target)) { + c.sendMessage(message).queue(); + } + } + + } + }else{ + b.log("INCORRECT USAGE! TRY: say " + target + " "); + } + }else{ + b.log("INCORRECT USAGE! TRY: say "); + } + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/config/ConfigRetrieval.java b/src/main/java/com/fpghoti/biscuit/config/ConfigRetrieval.java new file mode 100644 index 0000000..492a333 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/config/ConfigRetrieval.java @@ -0,0 +1,80 @@ +package com.fpghoti.biscuit.config; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Properties; + +import org.slf4j.Logger; + +import com.fpghoti.biscuit.Main; + +public class ConfigRetrieval { + + static Logger log = Main.log; + + public static void generateConfig(){ + Properties prop = new Properties(); + OutputStream output = null; + + try { + FileInputStream inputStream = + new FileInputStream("config.properties"); + inputStream.close(); + + } + catch(FileNotFoundException ex) { + log.info("config.ini missing...\nCreating file..."); + + try { + output = new FileOutputStream("config.properties"); + prop.setProperty("Bot-Token", ""); + prop.setProperty("AllowSpamPunish", "true"); + prop.store(output, null); + + } catch (IOException io) { + io.printStackTrace(); + } finally { + if (output != null) { + try { + output.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + catch(IOException ex) { + log.info("CANNOT READ CONFIG!"); + } + } + + public static String getFromConfig(String property){ + String setting = ""; + + Properties prop = new Properties(); + InputStream input = null; + + try { + input = new FileInputStream("config.properties"); + prop.load(input); + setting = prop.getProperty(property); + } catch (IOException ex) { + ex.printStackTrace(); + } finally { + if (input != null) { + try { + input.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + return setting; + + } +} diff --git a/src/main/java/com/fpghoti/biscuit/config/PropertiesRetrieval.java b/src/main/java/com/fpghoti/biscuit/config/PropertiesRetrieval.java new file mode 100644 index 0000000..e414387 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/config/PropertiesRetrieval.java @@ -0,0 +1,60 @@ +package com.fpghoti.biscuit.config; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +public class PropertiesRetrieval { + + public static String getToken(){ + String token = ""; + + Properties prop = new Properties(); + InputStream input = null; + + try { + input = new FileInputStream("config.properties"); + prop.load(input); + token = prop.getProperty("Bot-Token"); + } catch (IOException ex) { + ex.printStackTrace(); + } finally { + if (input != null) { + try { + input.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + return token; + } + + public static String getCommandSignifier(){ + String signifier = ""; + + Properties prop = new Properties(); + InputStream input = null; + + try { + input = new FileInputStream("config.properties"); + prop.load(input); + signifier = signifier + prop.getProperty("Command-Signifier").charAt(0); + } catch (IOException ex) { + ex.printStackTrace(); + } finally { + if (input != null) { + try { + input.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + return signifier; + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/global/MessageQueue.java b/src/main/java/com/fpghoti/biscuit/global/MessageQueue.java new file mode 100644 index 0000000..9d88337 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/global/MessageQueue.java @@ -0,0 +1,19 @@ +package com.fpghoti.biscuit.global; + +import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; + +import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.User; + +public class MessageQueue { + + public static HashMap chatssent = new HashMap<>(); + public static HashMap spammsgs = new HashMap<>(); + public static HashMap chatssent10s = new HashMap<>(); + public static HashMap chatssent2m = new HashMap<>(); + public static ConcurrentHashMap removemessages = new ConcurrentHashMap<>(); + public static ConcurrentHashMap fastremovemessages = new ConcurrentHashMap<>(); + public static ConcurrentHashMap slowremovemessages = new ConcurrentHashMap<>(); + +} diff --git a/src/main/java/com/fpghoti/biscuit/global/Properties.java b/src/main/java/com/fpghoti/biscuit/global/Properties.java new file mode 100644 index 0000000..d75ad07 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/global/Properties.java @@ -0,0 +1,10 @@ +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/global/SpamRecords.java b/src/main/java/com/fpghoti/biscuit/global/SpamRecords.java new file mode 100644 index 0000000..50b3572 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/global/SpamRecords.java @@ -0,0 +1,13 @@ +package com.fpghoti.biscuit.global; + +import java.util.ArrayList; +import java.util.List; + +import net.dv8tion.jda.api.entities.User; + +public class SpamRecords { + public static List spammers = new ArrayList<>(); + public static List elist = new ArrayList<>(); + public static List warnedspm = new ArrayList<>(); + public static List softmute = new ArrayList<>(); +} diff --git a/src/main/java/com/fpghoti/biscuit/listener/JoinListener.java b/src/main/java/com/fpghoti/biscuit/listener/JoinListener.java new file mode 100644 index 0000000..a191279 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/listener/JoinListener.java @@ -0,0 +1,40 @@ +package com.fpghoti.biscuit.listener; + +import org.slf4j.Logger; + +import com.fpghoti.biscuit.Main; +import com.fpghoti.biscuit.global.Properties; + +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; + +public class JoinListener extends ListenerAdapter { + + Logger log = Main.log; + + @Override + public void onGuildMemberJoin(GuildMemberJoinEvent event) { + log.info("MEMBER JOINED: " + event.getMember().getUser().getName()); + if(Properties.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)) { + role = r; + } + } + if(role == null) { + log.error("Cannot find role!"); + return; + } + + event.getGuild().addRoleToMember(event.getMember(), role).queue(); + + } + } + } + + +} \ No newline at end of file diff --git a/src/main/java/com/fpghoti/biscuit/listener/MessageDeleteListener.java b/src/main/java/com/fpghoti/biscuit/listener/MessageDeleteListener.java new file mode 100644 index 0000000..7cfdb95 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/listener/MessageDeleteListener.java @@ -0,0 +1,22 @@ +package com.fpghoti.biscuit.listener; + +import org.slf4j.Logger; + +import com.fpghoti.biscuit.Main; +import com.fpghoti.biscuit.util.Util; + +import net.dv8tion.jda.api.events.message.MessageDeleteEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; + +public class MessageDeleteListener extends ListenerAdapter { + + Logger log = Main.log; + + @Override + public void onMessageDelete(MessageDeleteEvent event) { + if(Util.isLoggable(event.getTextChannel())) { + log.info("MESSAGE DELETED - MSGID: " + event.getMessageId()); + } + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/listener/MessageEditListener.java b/src/main/java/com/fpghoti/biscuit/listener/MessageEditListener.java new file mode 100644 index 0000000..ffc7071 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/listener/MessageEditListener.java @@ -0,0 +1,22 @@ +package com.fpghoti.biscuit.listener; + +import org.slf4j.Logger; + +import com.fpghoti.biscuit.Main; +import com.fpghoti.biscuit.util.Util; + +import net.dv8tion.jda.api.events.message.MessageUpdateEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; + +public class MessageEditListener extends ListenerAdapter { + + Logger log = Main.log; + + @Override + public void onMessageUpdate(MessageUpdateEvent event) { + if(Util.isLoggable(event.getTextChannel()) && (!event.getAuthor().getName().equalsIgnoreCase("jbot") && !event.getAuthor().isBot())) { + log.info("MESSAGE EDITED - MSGID: " + event.getMessageId() + "- @" + event.getAuthor().getName() + " " + event.getAuthor().getAsMention() + " - CHANNEL: #" + event.getChannel().getName() + " - NEW TEXT - " + event.getMessage().getContentDisplay()); + } + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/listener/MessageReceiveListener.java b/src/main/java/com/fpghoti/biscuit/listener/MessageReceiveListener.java new file mode 100644 index 0000000..13eefe5 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/listener/MessageReceiveListener.java @@ -0,0 +1,113 @@ +package com.fpghoti.biscuit.listener; + +import org.slf4j.Logger; + +import com.fpghoti.biscuit.Main; +import com.fpghoti.biscuit.config.ConfigRetrieval; +import com.fpghoti.biscuit.global.MessageQueue; +import com.fpghoti.biscuit.global.SpamRecords; +import com.fpghoti.biscuit.util.ChatFilter; +import com.fpghoti.biscuit.util.Util; + +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import net.dv8tion.jda.api.exceptions.PermissionException; +import net.dv8tion.jda.api.hooks.ListenerAdapter; + +public class MessageReceiveListener extends ListenerAdapter{ + + Logger log = Main.log; + + @Override + public void onMessageReceived(MessageReceivedEvent event){ + + if(Util.isLoggable(event.getTextChannel())) { + log.info( "NEW MSG - MSGID: " + event.getMessageId() + "- @" + event.getAuthor().getName() + " " + event.getAuthor().getAsMention() + " - CHANNEL: #" + event.getChannel().getName() + " - " + event.getMessage().getContentDisplay()); + } + + if(event.getAuthor().isBot() && event.getMessage().getContentRaw().contains("This message contains words not appropriate for this channel.") || (ChatFilter.isNaughty(event.getMessage().getContentDisplay()))){ + MessageQueue.removemessages.put(event.getMessage().getId(), event.getTextChannel()); + } + + //staff channels do not need filtering, as the filter could actually be a hinderance + if(!event.getChannel().getName().toLowerCase().contains("staff") && ChatFilter.isNaughty(event.getMessage().getContentDisplay())){ + String text = event.getMessage().getContentDisplay(); + log.info("Removed Msg - REASON NAUGHTY WORD(S) - by " + event.getAuthor().getName() + ": " + text); + event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + " This message contains words not appropriate for this channel.").complete(); + MessageQueue.fastremovemessages.put(event.getMessage().getId(), event.getTextChannel()); + } + + if(!event.getAuthor().isBot() && !MessageQueue.chatssent.containsKey(event.getAuthor())){ + MessageQueue.chatssent.put(event.getAuthor(), 0); + } + + if(!event.getAuthor().isBot() && !MessageQueue.spammsgs.containsKey(event.getAuthor())){ + MessageQueue.spammsgs.put(event.getAuthor(), 0); + } + + if(!MessageQueue.chatssent10s.containsKey(event.getAuthor()) && SpamRecords.spammers.contains(event.getAuthor())){ + MessageQueue.chatssent10s.put(event.getAuthor(), 0); + } + + if(!MessageQueue.chatssent2m.containsKey(event.getAuthor()) && SpamRecords.softmute.contains(event.getAuthor())){ + MessageQueue.chatssent2m.put(event.getAuthor(), 0); + } + + if(!event.getAuthor().isBot()){ + MessageQueue.spammsgs.put(event.getAuthor(), MessageQueue.spammsgs.get(event.getAuthor()) + 1); + MessageQueue.chatssent.put(event.getAuthor(), MessageQueue.chatssent.get(event.getAuthor()) + 1); + if(SpamRecords.softmute.contains(event.getAuthor())){ + MessageQueue.chatssent2m.put(event.getAuthor(), MessageQueue.chatssent2m.get(event.getAuthor()) + 1); + } + if(SpamRecords.spammers.contains(event.getAuthor())){ + MessageQueue.chatssent10s.put(event.getAuthor(), MessageQueue.chatssent10s.get(event.getAuthor()) + 1); + } + } + if(SpamRecords.softmute.contains(event.getAuthor()) && MessageQueue.chatssent2m.get(event.getAuthor()) > 1){ + String text = event.getMessage().getContentDisplay(); + log.info("Removed Msg - REASON SOFTMUTED - by " + event.getAuthor().getName() + ": " + text); + MessageQueue.fastremovemessages.put(event.getMessage().getId(), event.getTextChannel()); + } + if(SpamRecords.spammers.contains(event.getAuthor())){ + if(MessageQueue.chatssent10s.get(event.getAuthor()) > 1){ + String text = event.getMessage().getContentDisplay(); + log.info("Removed Msg - REASON FLAGGED AS SPAM - by " + event.getAuthor().getName() + ": " + text); + MessageQueue.fastremovemessages.put(event.getMessage().getId(), event.getTextChannel()); + } + } + + if(ConfigRetrieval.getFromConfig("AllowSpamPunish").equalsIgnoreCase("true")){ + if(!event.getAuthor().isBot() && !SpamRecords.softmute.contains(event.getAuthor()) && !MessageQueue.chatssent.isEmpty() && MessageQueue.chatssent.get(event.getAuthor()) > 7){ + if(!SpamRecords.spammers.contains(event.getAuthor())){ + if(event.getGuild().getSelfMember().hasPermission(Permission.NICKNAME_MANAGE)){ + try{ + //ignores music channels so that music bots can operate normally + if(!event.getChannel().getName().toLowerCase().contains("music")){ + if(SpamRecords.warnedspm.contains(event.getAuthor())){ + MessageQueue.removemessages.put(event.getMessage().getId(), event.getTextChannel()); + SpamRecords.spammers.add(event.getAuthor()); + event.getTextChannel().sendMessage("*Flagging " + event.getAuthor().getAsMention() + " as spam!*").queue(); + log.info("User " + event.getAuthor().getName() + " has been flagged as spam!"); + }else{ + MessageQueue.chatssent.remove(event.getAuthor()); + SpamRecords.warnedspm.add(event.getAuthor()); + event.getTextChannel().sendMessage("**STOP spamming, " + event.getAuthor().getAsMention() + "! You have been warned!**").queue(); + log.info("User " + event.getAuthor().getName() + " has been warned for spam!"); + } + } + }catch(PermissionException e){ + log.info("Bot does not have permission to change the nick name of " + event.getAuthor().getName() + "!"); + } + } + } + + if(event.getGuild().getSelfMember().hasPermission(Permission.MESSAGE_MANAGE)){ + MessageQueue.fastremovemessages.put(event.getMessage().getId(), event.getTextChannel()); + } + } + } + + + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/timer/BiscuitTimer.java b/src/main/java/com/fpghoti/biscuit/timer/BiscuitTimer.java new file mode 100644 index 0000000..3599f21 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/timer/BiscuitTimer.java @@ -0,0 +1,26 @@ +package com.fpghoti.biscuit.timer; + +import java.util.TimerTask; + +public abstract class BiscuitTimer extends TimerTask{ + + protected Long delay; + protected Long period; + + public long getDelay() { + if(delay != null) { + return delay; + }else { + return 0; + } + } + + public long getPeriod() { + if(period != null) { + return period; + }else { + return 0; + } + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/timer/task/BotMsgRemoveTimer.java b/src/main/java/com/fpghoti/biscuit/timer/task/BotMsgRemoveTimer.java new file mode 100644 index 0000000..ac6cb91 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/timer/task/BotMsgRemoveTimer.java @@ -0,0 +1,28 @@ +package com.fpghoti.biscuit.timer.task; + +import com.fpghoti.biscuit.global.MessageQueue; +import com.fpghoti.biscuit.timer.BiscuitTimer; + +import net.dv8tion.jda.api.exceptions.ErrorResponseException; + +public class BotMsgRemoveTimer extends BiscuitTimer{ + + public BotMsgRemoveTimer(){ + delay = (long) 0; + period = (long) 5*1000; + } + + public void run() { + for(String m : MessageQueue.removemessages.keySet()){ + try{ + MessageQueue.removemessages.get(m).deleteMessageById(m).complete(); + }catch(ErrorResponseException ex){ + } + } + + MessageQueue.removemessages.clear(); + + } + + +} diff --git a/src/main/java/com/fpghoti/biscuit/timer/task/ChatCountTimer.java b/src/main/java/com/fpghoti/biscuit/timer/task/ChatCountTimer.java new file mode 100644 index 0000000..50cfaf8 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/timer/task/ChatCountTimer.java @@ -0,0 +1,19 @@ +package com.fpghoti.biscuit.timer.task; + +import com.fpghoti.biscuit.global.MessageQueue; +import com.fpghoti.biscuit.timer.BiscuitTimer; + +public class ChatCountTimer extends BiscuitTimer { + + public ChatCountTimer(){ + delay = (long) 0; + period = (long) 10*1000; + } + + public void run() { + MessageQueue.chatssent.clear(); + MessageQueue.spammsgs.clear(); + MessageQueue.chatssent10s.clear(); + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/timer/task/FastMsgRemoveTimer.java b/src/main/java/com/fpghoti/biscuit/timer/task/FastMsgRemoveTimer.java new file mode 100644 index 0000000..68c87f0 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/timer/task/FastMsgRemoveTimer.java @@ -0,0 +1,25 @@ +package com.fpghoti.biscuit.timer.task; + +import com.fpghoti.biscuit.global.MessageQueue; +import com.fpghoti.biscuit.timer.BiscuitTimer; + +import net.dv8tion.jda.api.exceptions.ErrorResponseException; + +public class FastMsgRemoveTimer extends BiscuitTimer{ + + public FastMsgRemoveTimer(){ + delay = (long) 0; + period = (long) 1*1000; + } + + public void run() { + for(String m : MessageQueue.fastremovemessages.keySet()){ + try{ + MessageQueue.fastremovemessages.get(m).deleteMessageById(m).complete(); + }catch(ErrorResponseException ex){ + } + } + MessageQueue.fastremovemessages.clear(); + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/timer/task/SlowMsgRemoveTimer.java b/src/main/java/com/fpghoti/biscuit/timer/task/SlowMsgRemoveTimer.java new file mode 100644 index 0000000..4b8f54f --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/timer/task/SlowMsgRemoveTimer.java @@ -0,0 +1,26 @@ +package com.fpghoti.biscuit.timer.task; + +import com.fpghoti.biscuit.global.MessageQueue; +import com.fpghoti.biscuit.timer.BiscuitTimer; + +import net.dv8tion.jda.api.exceptions.ErrorResponseException; + +public class SlowMsgRemoveTimer extends BiscuitTimer{ + + public SlowMsgRemoveTimer(){ + delay = (long) 0; + period = (long) 5*1000; + } + + public void run() { + for(String m : MessageQueue.slowremovemessages.keySet()){ + try{ + MessageQueue.slowremovemessages.get(m).deleteMessageById(m).complete(); + }catch(ErrorResponseException ex){ + } + } + MessageQueue.slowremovemessages.clear(); + } + + +} diff --git a/src/main/java/com/fpghoti/biscuit/timer/task/SoftMuteTimer.java b/src/main/java/com/fpghoti/biscuit/timer/task/SoftMuteTimer.java new file mode 100644 index 0000000..0347f47 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/timer/task/SoftMuteTimer.java @@ -0,0 +1,17 @@ +package com.fpghoti.biscuit.timer.task; + +import com.fpghoti.biscuit.global.MessageQueue; +import com.fpghoti.biscuit.timer.BiscuitTimer; + +public class SoftMuteTimer extends BiscuitTimer{ + + public SoftMuteTimer(){ + delay = (long) 0; + period = (long) 120*1000; + } + + public void run() { + MessageQueue.chatssent2m.clear(); + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/util/ChatFilter.java b/src/main/java/com/fpghoti/biscuit/util/ChatFilter.java new file mode 100644 index 0000000..ec41a1f --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/util/ChatFilter.java @@ -0,0 +1,86 @@ +package com.fpghoti.biscuit.util; + +import com.fpghoti.biscuit.global.Properties; + +public class ChatFilter { + + //CHAT FILTER + + public static Boolean isNaughty(String sentence){ + for(String s : sentence.split(" ")){ + if(isNaughtyWord(s)){ + return true; + } + } + return false; + } + + public static Boolean isNaughtyWord(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.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(","); + for(String item : list){ + if(word.equalsIgnoreCase(item) || word.equalsIgnoreCase(item + "s")){ + return true; + } + } + word2 = null; + return false; + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/util/PermUtil.java b/src/main/java/com/fpghoti/biscuit/util/PermUtil.java new file mode 100644 index 0000000..133a70e --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/util/PermUtil.java @@ -0,0 +1,43 @@ +package com.fpghoti.biscuit.util; + +import net.dv8tion.jda.api.Permission; +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; + } + return false; + } + + public static boolean isMod(Member member){ + if(isAdmin(member)){ + return true; + }else{ + for(Role role : member.getRoles()){ + if(role.getName().equalsIgnoreCase("bouncerkey")){ + return true; + } + } + } + + return false; + } + + public static boolean canMute(Member member){ + if(member.hasPermission(Permission.MESSAGE_MANAGE)){ + return true; + }else{ + for(Role role : member.getRoles()){ + if(role.getName().equalsIgnoreCase("bouncerkey")){ + return true; + } + } + } + return false; + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/util/Util.java b/src/main/java/com/fpghoti/biscuit/util/Util.java new file mode 100644 index 0000000..b1937d4 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/util/Util.java @@ -0,0 +1,31 @@ +package com.fpghoti.biscuit.util; + +import java.util.Random; + +import com.fpghoti.biscuit.config.ConfigRetrieval; + +import net.dv8tion.jda.api.entities.TextChannel; + +public class Util { + public static int randInt(int min, int max) { + Random rand = new Random(); + + int randomNum = rand.nextInt((max - min) + 1) + min; + + return randomNum; + } + + public static Boolean isLoggable(TextChannel c) { + if(c == null) { + return true; + } + Boolean a = true; + for(String s: ConfigRetrieval.getFromConfig("Channels-To-Not-Chatlog").split(",")) { + if(c.getName().equalsIgnoreCase(s)) { + a = false; + } + } + return a; + } + +} diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..a7a350e --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,31 @@ + + + + [%date] %level - %msg%n + + + + + + + ${DEV_HOME}/chatlog.log + + + [%date] %level - %msg%n + + + + + ${DEV_HOME}/archived/chatlog.%d{yyyy-MM-dd}.%i.log + 450kb + + + + + + + + + + \ No newline at end of file