Initial Commit
This commit is contained in:
75
src/main/java/com/fpghoti/biscuit/Biscuit.java
Normal file
75
src/main/java/com/fpghoti/biscuit/Biscuit.java
Normal file
@@ -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<BiscuitTimer> timers;
|
||||
|
||||
public Biscuit(JDA jda, Logger log) {
|
||||
this.jda = jda;
|
||||
this.logger = log;
|
||||
|
||||
commandManager = new CommandManager();
|
||||
timer = new Timer();
|
||||
timers = new ArrayList<BiscuitTimer>();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
144
src/main/java/com/fpghoti/biscuit/Main.java
Normal file
144
src/main/java/com/fpghoti/biscuit/Main.java
Normal file
@@ -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<String> we;
|
||||
public SizeAndTimeBasedRollingPolicy<String> 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<BaseCommand> 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
12
src/main/java/com/fpghoti/biscuit/api/API.java
Normal file
12
src/main/java/com/fpghoti/biscuit/api/API.java
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
86
src/main/java/com/fpghoti/biscuit/commands/BaseCommand.java
Normal file
86
src/main/java/com/fpghoti/biscuit/commands/BaseCommand.java
Normal file
@@ -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<String> identifiers;
|
||||
protected List<String> notes;
|
||||
|
||||
public BaseCommand() {
|
||||
this.identifiers = new ArrayList<String>();
|
||||
this.notes = new ArrayList<String>();
|
||||
}
|
||||
|
||||
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<String> getIdentifiers() {
|
||||
return identifiers;
|
||||
}
|
||||
|
||||
public void setIdentifiers(List<String> identifiers) {
|
||||
this.identifiers = identifiers;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getUsage() {
|
||||
return usage;
|
||||
}
|
||||
|
||||
public List<String> getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<BaseCommand> commands = new ArrayList<BaseCommand>();
|
||||
|
||||
public void parse(String message, MessageReceivedEvent e){
|
||||
ArrayList<String> split = new ArrayList<String>();
|
||||
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<String> 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<BaseCommand> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.fpghoti.biscuit.commands;
|
||||
|
||||
public enum CommandType {
|
||||
CLIENT,
|
||||
CONSOLE
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 @<mention-user>";
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 @<mention-user>";
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 @<mention-user>";
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 @<mention-user>";
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <channel-name> <message>";
|
||||
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 + " <message>");
|
||||
}
|
||||
}else{
|
||||
b.log("INCORRECT USAGE! TRY: say <channel-name> <message>");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
19
src/main/java/com/fpghoti/biscuit/global/MessageQueue.java
Normal file
19
src/main/java/com/fpghoti/biscuit/global/MessageQueue.java
Normal file
@@ -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<User, Integer> chatssent = new HashMap<>();
|
||||
public static HashMap<User, Integer> spammsgs = new HashMap<>();
|
||||
public static HashMap<User, Integer> chatssent10s = new HashMap<>();
|
||||
public static HashMap<User, Integer> chatssent2m = new HashMap<>();
|
||||
public static ConcurrentHashMap<String, TextChannel> removemessages = new ConcurrentHashMap<>();
|
||||
public static ConcurrentHashMap<String, TextChannel> fastremovemessages = new ConcurrentHashMap<>();
|
||||
public static ConcurrentHashMap<String, TextChannel> slowremovemessages = new ConcurrentHashMap<>();
|
||||
|
||||
}
|
||||
10
src/main/java/com/fpghoti/biscuit/global/Properties.java
Normal file
10
src/main/java/com/fpghoti/biscuit/global/Properties.java
Normal file
@@ -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 = "";
|
||||
|
||||
}
|
||||
13
src/main/java/com/fpghoti/biscuit/global/SpamRecords.java
Normal file
13
src/main/java/com/fpghoti/biscuit/global/SpamRecords.java
Normal file
@@ -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<User> spammers = new ArrayList<>();
|
||||
public static List<User> elist = new ArrayList<>();
|
||||
public static List<User> warnedspm = new ArrayList<>();
|
||||
public static List<User> softmute = new ArrayList<>();
|
||||
}
|
||||
40
src/main/java/com/fpghoti/biscuit/listener/JoinListener.java
Normal file
40
src/main/java/com/fpghoti/biscuit/listener/JoinListener.java
Normal file
@@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
26
src/main/java/com/fpghoti/biscuit/timer/BiscuitTimer.java
Normal file
26
src/main/java/com/fpghoti/biscuit/timer/BiscuitTimer.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
86
src/main/java/com/fpghoti/biscuit/util/ChatFilter.java
Normal file
86
src/main/java/com/fpghoti/biscuit/util/ChatFilter.java
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
43
src/main/java/com/fpghoti/biscuit/util/PermUtil.java
Normal file
43
src/main/java/com/fpghoti/biscuit/util/PermUtil.java
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
31
src/main/java/com/fpghoti/biscuit/util/Util.java
Normal file
31
src/main/java/com/fpghoti/biscuit/util/Util.java
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user