Update Biscuit to work on multiple guilds simultaneously

This commit is contained in:
Ghoti 2020-07-15 01:48:50 -05:00
parent ac5f3672fd
commit 4b443a1a6c
67 changed files with 2173 additions and 1236 deletions

View File

@ -25,6 +25,7 @@
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>

View File

@ -1,2 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8

View File

@ -9,4 +9,5 @@ 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.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.fpghoti</groupId>
<artifactId>Biscuit</artifactId>
<version>1.5</version>
<version>1.6</version>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
@ -36,7 +36,7 @@
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
@ -46,6 +46,14 @@
<configuration>
<encoding>UTF-8</encoding>
<minimizeJar>true</minimizeJar>
<filters>
<filter>
<artifact>org.tuxdude.logback.extensions:logback-colorizer</artifact>
<includes>
<include>**</include>
</includes>
</filter>
</filters>
</configuration>
</execution>
</executions>
@ -88,88 +96,18 @@
<artifactId>spigot-api</artifactId>
<version>1.15.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>commons-lang</artifactId>
<groupId>commons-lang</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
</exclusion>
<exclusion>
<artifactId>bungeecord-chat</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>snakeyaml</artifactId>
<groupId>org.yaml</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.15.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>commons-lang</artifactId>
<groupId>commons-lang</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
</exclusion>
<exclusion>
<artifactId>snakeyaml</artifactId>
<groupId>org.yaml</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.15-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bungeecord-config</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>bungeecord-event</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>bungeecord-protocol</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>netty-transport-native-unix-common</artifactId>
<groupId>io.netty</groupId>
</exclusion>
<exclusion>
<artifactId>bungeecord-chat</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>snakeyaml</artifactId>
<groupId>org.yaml</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
@ -226,4 +164,3 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

25
pom.xml
View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.fpghoti</groupId>
<artifactId>Biscuit</artifactId>
<version>1.5</version>
<version>1.6</version>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
@ -40,7 +40,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
@ -50,6 +50,14 @@
<configuration>
<encoding>UTF-8</encoding>
<minimizeJar>true</minimizeJar>
<filters>
<filter>
<artifact>org.tuxdude.logback.extensions:logback-colorizer</artifact>
<includes>
<include>**</include>
</includes>
</filter>
</filters>
</configuration>
</execution>
</executions>
@ -91,6 +99,17 @@
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>1.18</version>
</dependency>
<dependency>
<groupId>org.tuxdude.logback.extensions</groupId>
<artifactId>logback-colorizer</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.github.CrabMustard</groupId>
<artifactId>emoji-java</artifactId>
@ -148,7 +167,7 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.1.1_155</version>
<version>4.2.0_177</version>
</dependency>
<dependency>
<groupId>com.github.cage</groupId>

View File

@ -1,192 +0,0 @@
package com.fpghoti.biscuit;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Timer;
import org.slf4j.Logger;
import com.fpghoti.biscuit.captcha.BCage;
import com.fpghoti.biscuit.commands.CommandManager;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.timer.BiscuitTimer;
import com.fpghoti.biscuit.user.PreUser;
import com.github.cage.Cage;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Invite;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.User;
public class Biscuit {
private JDA jda;
private Logger logger;
private CommandManager commandManager;
private Timer timer;
private List<BiscuitTimer> timers;
private File captchaDir;
private Cage cage;
private HashMap<String, Integer> inviteUses;
public Biscuit(JDA jda, Logger log) {
this.jda = jda;
this.logger = log;
commandManager = new CommandManager();
timer = new Timer();
timers = new ArrayList<BiscuitTimer>();
if(!Main.isPlugin) {
captchaDir = new File("captcha");
}else {
captchaDir = new File(PluginCore.plugin.getDataFolder(), "captcha");
}
captchaDir.mkdir();
cage = new BCage();
wipeCaptchaDir();
loadPreUsers();
inviteUses = new HashMap<String, Integer>();
if(canManageServer() && PropertiesRetrieval.checkJoinInvite()) {
for(Guild g : jda.getGuilds()) {
g.retrieveInvites().queue((invs) -> {
indexInvites(invs);
});
}
}
}
public boolean canManageServer() {
for(Guild g : jda.getGuilds()) {
if(g.getSelfMember().hasPermission(Permission.MANAGE_SERVER)) {
return true;
}
}
return false;
}
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);
}
public void wipeCaptchaDir() {
Main.log.info("Wiping captcha files...");
boolean good = true;
File[] files = captchaDir.listFiles();
for (File file : files){
if (!file.delete()){
good = false;
Main.log.error("Could not remove captcha file: " + file);
}
}
if(good) {
Main.log.info("All captcha files successfully removed!");
}else {
Main.log.error("Some captcha file(s) could not be removed!");
}
}
public Cage getCage() {
return this.cage;
}
public ArrayList<TextChannel> getCaptchaLogChannels() {
ArrayList<TextChannel> ch = new ArrayList<TextChannel>();
for(Guild g : jda.getGuilds()) {
for(TextChannel t : g.getTextChannels()) {
if(t.getName().equalsIgnoreCase(PropertiesRetrieval.getCaptchaLogChannel())) {
ch.add(t);
}
}
}
return ch;
}
public void captchaLog(String msg) {
if(PropertiesRetrieval.logCaptcha()) {
for(TextChannel t : getCaptchaLogChannels()) {
t.sendMessage(msg).queue();
}
}
}
private void loadPreUsers() {
for(Guild g : jda.getGuilds()) {
for(Member m : g.getMembers()) {
User u = m.getUser();
if(!PreUser.preUserExists(u)) {
if(m.getRoles().size() == 1) {
for(Role role : m.getRoles()){
if(role.getName().equalsIgnoreCase(PropertiesRetrieval.getDefaultRole())){
PreUser.users.add(new PreUser(u));
}
}
}
}
}
}
}
private void indexInvites(List<Invite> invs) {
for(Invite i : invs) {
String code = i.getCode();
int uses = i.getUses();
inviteUses.put(code, uses);
}
}
public HashMap<String, Integer> getInviteUses(){
return inviteUses;
}
public void setInviteUses(HashMap<String, Integer> c) {
inviteUses = c;
}
public void clearInviteUses() {
inviteUses.clear();
}
}

View File

@ -1,16 +1,22 @@
package com.fpghoti.biscuit;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Scanner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.fusesource.jansi.AnsiConsole;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.BaseCommand;
import com.fpghoti.biscuit.commands.CommandListener;
import com.fpghoti.biscuit.commands.CommandManager;
import com.fpghoti.biscuit.commands.client.AddCommand;
import com.fpghoti.biscuit.commands.client.ChanIDCommand;
import com.fpghoti.biscuit.commands.client.DivideCommand;
import com.fpghoti.biscuit.commands.client.GetConfigCommand;
import com.fpghoti.biscuit.commands.client.GuildIDCommand;
import com.fpghoti.biscuit.commands.client.ToggleRoleCommand;
import com.fpghoti.biscuit.commands.client.HelpCommand;
import com.fpghoti.biscuit.commands.client.MultiplyCommand;
@ -19,34 +25,38 @@ import com.fpghoti.biscuit.commands.client.MakeInviteCommand;
import com.fpghoti.biscuit.commands.client.PingCommand;
import com.fpghoti.biscuit.commands.client.PowerCommand;
import com.fpghoti.biscuit.commands.client.RecentSpammersCommand;
import com.fpghoti.biscuit.commands.client.SaveConfigCommand;
import com.fpghoti.biscuit.commands.client.SoftMuteCommand;
import com.fpghoti.biscuit.commands.client.SquareRootCommand;
import com.fpghoti.biscuit.commands.client.SubtractCommand;
import com.fpghoti.biscuit.commands.client.UIDCommand;
import com.fpghoti.biscuit.commands.client.UnSoftMuteCommand;
import com.fpghoti.biscuit.commands.client.WikiCommand;
import com.fpghoti.biscuit.commands.console.GuildSayCommand;
import com.fpghoti.biscuit.commands.console.SayCommand;
import com.fpghoti.biscuit.commands.console.ShutdownConsoleCommand;
import com.fpghoti.biscuit.config.ConfigRetrieval;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.listener.DMListener;
import com.fpghoti.biscuit.listener.GuildListener;
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.listener.ReactionListener;
import com.fpghoti.biscuit.listener.RoleListener;
import com.fpghoti.biscuit.timer.task.BotMsgRemoveTimer;
import com.fpghoti.biscuit.logging.BColor;
import com.fpghoti.biscuit.logging.BiscuitLog;
import com.fpghoti.biscuit.timer.task.ChatCountTimer;
import com.fpghoti.biscuit.timer.task.DecrementTimer;
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;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.ChunkingFilter;
import net.dv8tion.jda.api.utils.MemberCachePolicy;
public class Main {
@ -55,21 +65,30 @@ public class Main {
public RollingFileAppender<String> we;
public SizeAndTimeBasedRollingPolicy<String> wes;
public static final Logger log = LoggerFactory.getLogger("ch.qos.logback.core.ConsoleAppender");
private static final BiscuitLog log = new BiscuitLog();
private static ArrayList<Biscuit> biscuits;
private static Biscuit mainBiscuit;
public static Scanner sc;
public static Biscuit biscuit;
public static boolean ready = false;
public static boolean isPlugin = false;
public static boolean shutdownStarted = false;
public static void main(String[] args){
ConfigRetrieval.generateConfig();
log.info("========================= Welcome to Biscuit =========================");
startJDA();
biscuit = new Biscuit(jda, log);
startCommandListener();
final Properties properties = new Properties();
try {
properties.load(Main.class.getClassLoader().getResourceAsStream("info.properties"));
} catch (IOException e) {
log.error("Could not determine Biscuit version.");
}
String version = properties.getProperty("version");
AnsiConsole.systemInstall();
log.info(BColor.CYAN_BOLD + "========================= WELCOME TO BISCUIT =========================");
log.info("Running version: " + BColor.MAGENTA_BOLD + version);
mainBiscuit = new Biscuit(null, null, log);
startJDA();
jda.addEventListener(new GuildListener());
jda.addEventListener(new MessageReceiveListener());
jda.addEventListener(new MessageEditListener());
jda.addEventListener(new MessageDeleteListener());
@ -77,19 +96,21 @@ public class Main {
jda.addEventListener(new DMListener());
jda.addEventListener(new ReactionListener());
jda.addEventListener(new RoleListener());
biscuits = new ArrayList<Biscuit>();
for(Guild g : jda.getGuilds()) {
Biscuit biscuit = new Biscuit(jda, g, log);
biscuit.addTimer(new ChatCountTimer(biscuit));
biscuit.addTimer(new SoftMuteTimer(biscuit));
biscuit.addTimer(new DecrementTimer(biscuit));
biscuit.loadTimers();
biscuits.add(biscuit);
}
startCommandListener();
String link = "NULL";
biscuit.addTimer(new ChatCountTimer());
biscuit.addTimer(new BotMsgRemoveTimer());
biscuit.addTimer(new FastMsgRemoveTimer());
biscuit.addTimer(new SlowMsgRemoveTimer());
biscuit.addTimer(new SoftMuteTimer());
biscuit.addTimer(new DecrementTimer());
biscuit.loadTimers();
List<BaseCommand> commands = biscuit.getCommandManager().getCommands();
List<BaseCommand> commands = CommandManager.getCommands();
//Client
@ -109,28 +130,37 @@ public class Main {
commands.add(new DivideCommand());
commands.add(new PowerCommand());
commands.add(new MakeInviteCommand());
commands.add(new GetConfigCommand());
commands.add(new SaveConfigCommand());
commands.add(new GuildIDCommand());
commands.add(new WikiCommand());
//Console
commands.add(new SayCommand());
commands.add(new GuildSayCommand());
commands.add(new ShutdownConsoleCommand());
link = "https://discordapp.com/oauth2/authorize?&client_id=" + jda.getSelfUser().getId() + "&scope=bot";
link = "https://discord.com/oauth2/authorize?&client_id=" + jda.getSelfUser().getId() + "&permissions=8&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(BColor.CYAN_BOLD + "======================================================================");
log.info("CHAT LOGS BEGIN HERE:");
ready = true;
}
@SuppressWarnings("deprecation")
private static void startJDA() {
String token = PropertiesRetrieval.getToken();
String token = mainBiscuit.getProperties().getToken();
log.info("Connecting bot to Discord.");
try{
jda = new JDABuilder(AccountType.BOT).setToken(token).build();
jda = JDABuilder.createDefault(token)
.setChunkingFilter(ChunkingFilter.ALL)
.setMemberCachePolicy(MemberCachePolicy.ALL)
.enableIntents(GatewayIntent.getIntents(GatewayIntent.DEFAULT))
.enableIntents(GatewayIntent.GUILD_MEMBERS)
.build();
try {
jda.awaitReady();
} catch (InterruptedException e) {
@ -144,31 +174,35 @@ public class Main {
}
}
public static Biscuit getMainBiscuit() {
return mainBiscuit;
}
private static void startCommandListener() {
if(!isPlugin) {
sc = new Scanner(System.in);
CommandListener cl = new CommandListener();
cl.sc = sc;
cl.jda = jda;
CommandListener cl = new CommandListener(sc, log);
jda.addEventListener(cl);
new Thread(cl).start();
}else {
CommandListener cl = new CommandListener();
cl.jda = jda;
CommandListener cl = new CommandListener(null, log);
jda.addEventListener(cl);
}
}
public static Biscuit getBiscuit() {
return biscuit;
public static ArrayList<Biscuit> getBiscuits() {
return biscuits;
}
public static void shutdown() {
if(!shutdownStarted) {
shutdownStarted = true;
log.info("Shutting down...");
biscuit.wipeCaptchaDir();
mainBiscuit.log("Shutting down...");
ArrayList<Biscuit> list = new ArrayList<Biscuit>(biscuits);
for(Biscuit b : list) {
b.remove();
}
mainBiscuit.wipeCaptchaDir();
if(jda != null) {
jda.shutdown();
}
@ -179,6 +213,20 @@ public class Main {
}
}
public static JDA getJDA() {
return jda;
}
public static BiscuitLog getLogger() {
return log;
}
public static void registerBiscuit(Biscuit b) {
biscuits.add(b);
}
public static void unregisterBiscuit(Biscuit b) {
biscuits.remove(b);
}
}

View File

@ -24,17 +24,13 @@ public class PluginCore extends JavaPlugin{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
CommandManager m = Main.getBiscuit().getCommandManager();
if(m != null) {
if(sender instanceof Player) {
Player p = (Player)sender;
if(!p.hasPermission("biscuit.admin")) {
return false;
}
}
return m.dispatch(label,args);
}
return false;
return CommandManager.dispatch(label,args);
}
}

View File

@ -0,0 +1,328 @@
package com.fpghoti.biscuit.biscuit;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Timer;
import java.util.concurrent.CopyOnWriteArrayList;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.PluginCore;
import com.fpghoti.biscuit.captcha.BCage;
import com.fpghoti.biscuit.config.BiscuitConfig;
import com.fpghoti.biscuit.config.BiscuitProperties;
import com.fpghoti.biscuit.logging.BColor;
import com.fpghoti.biscuit.logging.BiscuitLog;
import com.fpghoti.biscuit.timer.BiscuitTimer;
import com.fpghoti.biscuit.timer.task.ChatCountTimer;
import com.fpghoti.biscuit.timer.task.DecrementTimer;
import com.fpghoti.biscuit.timer.task.SoftMuteTimer;
import com.fpghoti.biscuit.user.PreUser;
import com.github.cage.Cage;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Invite;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.User;
public class Biscuit {
public static Biscuit getBiscuit(Guild g) {
for(Biscuit b : Main.getBiscuits()) {
if(b.getGuild().getId().equals(g.getId())) {
return b;
}
}
return null;
}
public static Biscuit getBiscuit(String guildcode) {
for(Biscuit b : Main.getBiscuits()) {
if(b.getProperties().getGuildCode().equalsIgnoreCase(guildcode)) {
return b;
}
}
return null;
}
public static ArrayList<PreUser> getPreUsers(User u) {
ArrayList<PreUser> pres = new ArrayList<PreUser>();
for(Guild g : Main.getJDA().getGuilds()) {
if(g.isMember(u)){
Biscuit b = getBiscuit(g);
if(b.preUserExists(u)) {
pres.add(b.getPreUser(u));
}
}
}
return pres;
}
public static Biscuit loadGuild(Guild g) {
Biscuit biscuit = new Biscuit(Main.getJDA(), g, Main.getLogger());
biscuit.addTimer(new ChatCountTimer(biscuit));
biscuit.addTimer(new SoftMuteTimer(biscuit));
biscuit.addTimer(new DecrementTimer(biscuit));
biscuit.loadTimers();
Main.registerBiscuit(biscuit);
return biscuit;
}
private boolean isMain;
private JDA jda;
private BiscuitLog logger;
private Timer timer;
private List<BiscuitTimer> timers;
private File captchaDir;
private Cage cage;
private Guild guild;
private HashMap<String, Integer> inviteUses;
private BiscuitConfig config;
private BiscuitProperties properties;
private BiscuitMessageStore messageStore;
private CopyOnWriteArrayList<PreUser> users = new CopyOnWriteArrayList<PreUser>();
public Biscuit(JDA jda, Guild guild, BiscuitLog log) {
this.jda = jda;
this.guild = guild;
this.logger = log;
this.isMain = guild == null;
this.messageStore = new BiscuitMessageStore(this);
this.config = new BiscuitConfig(this);
config.generateConfig();
this.properties = new BiscuitProperties(this);
timer = new Timer();
timers = new ArrayList<BiscuitTimer>();
if(!Main.isPlugin) {
captchaDir = new File("captcha");
captchaDir.mkdir();
}else {
captchaDir = new File(PluginCore.plugin.getDataFolder(), "captcha");
}
cage = new BCage();
if(isMain) {
wipeCaptchaDir();
}
if(!isMain) {
loadPreUsers();
inviteUses = new HashMap<String, Integer>();
if(canManageServer() && properties.checkJoinInvite()) {
guild.retrieveInvites().queue((invs) -> {
indexInvites(invs);
});
}
}
}
public BiscuitConfig getConfig() {
return config;
}
public BiscuitProperties getProperties() {
return properties;
}
public BiscuitMessageStore getMessageStore() {
return messageStore;
}
public Guild getGuild() {
return guild;
}
public boolean canManageServer() {
return guild.getSelfMember().hasPermission(Permission.MANAGE_SERVER);
}
public void log(String message) {
if(properties == null) {
logger.info(message);
return;
}
logger.info("[" + BColor.CYAN + properties.getGuildCode().toUpperCase() + BColor.RESET + "]: " + message);
}
public void warn(String message) {
if(properties == null) {
logger.warn(message);
return;
}
logger.warn("[" + properties.getGuildCode().toUpperCase() + "]: " + message);
}
public void error(String message) {
if(properties == null) {
logger.error(message);
return;
}
logger.error("[" + properties.getGuildCode().toUpperCase() + "]: " + message);
}
public JDA getJDA() {
return jda;
}
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);
}
public void wipeCaptchaDir() {
log("Wiping captcha files...");
boolean good = true;
File[] files = captchaDir.listFiles();
for (File file : files){
if (!file.delete()){
good = false;
error("Could not remove captcha file: " + file);
}
}
if(good) {
log("All captcha files successfully removed!");
}else {
error("Some captcha file(s) could not be removed!");
}
}
public Cage getCage() {
return this.cage;
}
public ArrayList<TextChannel> getCaptchaLogChannels() {
ArrayList<TextChannel> ch = new ArrayList<TextChannel>();
for(TextChannel t : guild.getTextChannels()) {
if(t.getName().equalsIgnoreCase(properties.getCaptchaLogChannel())) {
ch.add(t);
}
}
return ch;
}
public void captchaLog(String msg) {
if(properties.logCaptcha()) {
for(TextChannel t : getCaptchaLogChannels()) {
t.sendMessage(msg).queue();
}
}
}
private void loadPreUsers() {
if(!properties.captchaEnabled()) {
return;
}
for(Member m : guild.getMembers()) {
User u = m.getUser();
if(!preUserExists(u)) {
if(m.getRoles().size() == 1) {
for(Role role : m.getRoles()){
if(role.getName().equalsIgnoreCase(properties.getDefaultRole())){
log(BColor.MAGENTA_BOLD + "Adding pre-join check for user " + u.getName() + " (" + u.getAsMention() + ")...");
users.add(new PreUser(u,this));
}
}
}
}
}
}
private void indexInvites(List<Invite> invs) {
for(Invite i : invs) {
String code = i.getCode();
int uses = i.getUses();
inviteUses.put(code, uses);
}
}
public HashMap<String, Integer> getInviteUses(){
return inviteUses;
}
public void setInviteUses(HashMap<String, Integer> c) {
inviteUses = c;
}
public void clearInviteUses() {
inviteUses.clear();
}
public void addPreUser(PreUser user) {
users.add(user);
}
public void removePreUser(PreUser user) {
users.remove(user);
}
public CopyOnWriteArrayList<PreUser> getPreUsers(){
return users;
}
public PreUser getPreUser(User user) {
for(PreUser u : users) {
if(u.getUser().getId().equals(user.getId())) {
return u;
}
}
return null;
}
public boolean preUserExists(User user) {
return getPreUser(user) != null;
}
public File getConfigDir() {
boolean isMain = guild == null;
if(isMain) {
if(Main.isPlugin) {
return PluginCore.plugin.getDataFolder();
}else {
return new File("").getAbsoluteFile();
}
}else {
File dir;
if(!Main.isPlugin) {
dir = new File("guilds");
}else {
dir = new File(PluginCore.plugin.getDataFolder(), "guilds");
}
dir.mkdir();
return dir;
}
}
public void remove() {
log("Removing guild biscuit...");
for(BiscuitTimer t : timers) {
t.cancel();
}
for(PreUser p : users) {
p.remove();
}
Main.unregisterBiscuit(this);
}
}

View File

@ -0,0 +1,148 @@
package com.fpghoti.biscuit.biscuit;
import java.util.ArrayList;
import java.util.HashMap;
import net.dv8tion.jda.api.entities.User;
public class BiscuitMessageStore {
Biscuit biscuit;
private HashMap<User, Integer> messageCounts = new HashMap<>();
private HashMap<User, Integer> messagesTenSeconds = new HashMap<>();
private HashMap<User, Integer> messagesTwoMin = new HashMap<>();
private ArrayList<User> spammers = new ArrayList<User>();
private ArrayList<User> spamWarned = new ArrayList<User>();
private ArrayList<User> softmuted = new ArrayList<User>();
public BiscuitMessageStore(Biscuit b) {
this.biscuit = b;
}
public String getSpammerList() {
String msg = "Recent spammers:";
for( User u: spammers){
msg = msg + " " + u.getAsMention();
}
return msg;
}
public void forgetChats() {
messageCounts.clear();
messagesTenSeconds.clear();
}
public void allowSoftMutedMessage() {
messagesTwoMin.clear();
}
public boolean isTwoMinCountEmpty() {
return messagesTwoMin.isEmpty();
}
public boolean hasTwoMinCount(User user) {
return messagesTwoMin.containsKey(user);
}
public void setTwoMinCount(User user, Integer i) {
messagesTwoMin.put(user,i);
}
public int getTwoMinCount(User user) {
return messagesTwoMin.get(user);
}
public void removeTwoMinCount(User user) {
messagesTwoMin.remove(user);
}
public boolean isTenSecondCountEmpty() {
return messagesTenSeconds.isEmpty();
}
public boolean hasTenSecondCount(User user) {
return messagesTenSeconds.containsKey(user);
}
public void setTenSecondCount(User user, Integer i) {
messagesTenSeconds.put(user,i);
}
public int getTenSecondsCount(User user) {
return messagesTenSeconds.get(user);
}
public void removeTenSecondsCount(User user) {
messagesTenSeconds.remove(user);
}
public boolean isMessageCountEmpty() {
return messageCounts.isEmpty();
}
public boolean hasMessageCount(User user) {
return messageCounts.containsKey(user);
}
public void setMessageCount(User user, Integer i) {
messageCounts.put(user,i);
}
public int getMessageCount(User user) {
return messageCounts.get(user);
}
public void removeMessageCount(User user) {
messageCounts.remove(user);
}
public void addSpammer(User u) {
spammers.add(u);
}
public void removeSpammer(User u) {
spammers.remove(u);
}
public boolean isSpammer(User u) {
return spammers.contains(u);
}
public boolean hasNoSpammers() {
return spammers.isEmpty();
}
public void addSpamWarned(User u) {
spamWarned.add(u);
}
public void removeSpamWarned(User u) {
spamWarned.remove(u);
}
public boolean isSpamWarned(User u) {
return spamWarned.contains(u);
}
public boolean hasNoSpamWarned() {
return spamWarned.isEmpty();
}
public void addSoftmuted(User u) {
softmuted.add(u);
}
public void removeSoftmuted(User u) {
softmuted.remove(u);
}
public boolean isSoftmuted(User u) {
return softmuted.contains(u);
}
public boolean hasNoSoftmuted() {
return softmuted.isEmpty();
}
}

View File

@ -2,13 +2,10 @@ package com.fpghoti.biscuit.commands;
import java.util.Scanner;
import org.slf4j.Logger;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.logging.BiscuitLog;
import com.fpghoti.biscuit.util.PermUtil;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -16,23 +13,29 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter;
public class CommandListener extends ListenerAdapter implements Runnable {
public Scanner sc;
public JDA jda;
Logger log = Main.log;
private Scanner sc;
private BiscuitLog log;
public CommandListener(Scanner sc, BiscuitLog log) {
this.sc = sc;
this.log = log;
}
@Override
public void onMessageReceived(MessageReceivedEvent event){
if (event.isFromType(ChannelType.TEXT)) {
if(PermUtil.isAdmin(event.getMember()) || !PropertiesRetrieval.restrictCmdChannels() || (PropertiesRetrieval.restrictCmdChannels() && isBotChannel(event.getTextChannel()))) {
if(!event.getAuthor().isBot() && event.getMessage().getContentDisplay().startsWith(PropertiesRetrieval.getCommandSignifier()) && event.getMessage().getAuthor().getId() != event.getJDA().getSelfUser().getId()){
Main.getBiscuit().getCommandManager().parse(event.getMessage().getContentRaw().toLowerCase(), event);
Biscuit b = Biscuit.getBiscuit(event.getGuild());
if(PermUtil.isAdmin(event.getMember()) || !b.getProperties().restrictCmdChannels() || (b.getProperties().restrictCmdChannels() && isBotChannel(event.getTextChannel()))) {
if(!event.getAuthor().isBot() && event.getMessage().getContentDisplay().startsWith(b.getProperties().getCommandSignifier()) && event.getMessage().getAuthor().getId() != event.getJDA().getSelfUser().getId()){
CommandManager.parse(event.getMessage().getContentRaw().toLowerCase(), event);
}
}
}
}
private boolean isBotChannel(TextChannel c) {
for(String s : PropertiesRetrieval.getCmdChannels()) {
Biscuit b = Biscuit.getBiscuit(c.getGuild());
for(String s : b.getProperties().getCmdChannels()) {
if(s.equals(c.getName())) {
return true;
}
@ -55,7 +58,7 @@ public class CommandListener extends ListenerAdapter implements Runnable {
private void runCommand(String label, String[] args) {
log.info(label);
Main.getBiscuit().getCommandManager().dispatch(label, args);
CommandManager.dispatch(label, args);
}
}

View File

@ -3,9 +3,8 @@ package com.fpghoti.biscuit.commands;
import java.util.ArrayList;
import java.util.List;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.util.PermUtil;
import com.fpghoti.biscuit.util.Util;
@ -13,11 +12,12 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
public class CommandManager {
private List<BaseCommand> commands = new ArrayList<BaseCommand>();
private static List<BaseCommand> commands = new ArrayList<BaseCommand>();
public void parse(String message, MessageReceivedEvent e){
public static void parse(String message, MessageReceivedEvent e){
Biscuit b = Biscuit.getBiscuit(e.getGuild());
ArrayList<String> split = new ArrayList<String>();
String fixed = message.replaceFirst(PropertiesRetrieval.getCommandSignifier(), "");
String fixed = message.replaceFirst(b.getProperties().getCommandSignifier(), "");
String[] splitMsg = fixed.split(" ");
for(String s: splitMsg){
split.add(s);
@ -30,18 +30,20 @@ public class CommandManager {
}
public boolean dispatch(String label, String[] args) {
public static boolean dispatch(String label, String[] args) {
return dispatch(null,label,args);
}
public boolean dispatch(MessageReceivedEvent e, String label, String[] args) {
public static boolean dispatch(MessageReceivedEvent e, String label, String[] args) {
Biscuit b = Main.getMainBiscuit();
boolean isMain = true;
if(e != null) {
if(Util.contains(PropertiesRetrieval.disabledCommands(), label)) {
b = Biscuit.getBiscuit(e.getGuild());
isMain = false;
if(Util.contains(b.getProperties().disabledCommands(), label)) {
return false;
}
if(!PermUtil.isAdmin(e.getMember()) && Util.contains(PropertiesRetrieval.disabledUserCommands(), label)) {
if(!PermUtil.isAdmin(e.getMember()) && Util.contains(b.getProperties().disabledUserCommands(), label)) {
return false;
}
@ -83,8 +85,17 @@ public class CommandManager {
}
}
}else {
if(Util.contains(PropertiesRetrieval.getCustomCmds(), label)) {
CustomCommand cc = new CustomCommand(label);
if(Util.contains(Main.getMainBiscuit().getProperties().getCustomCmds(), label)) {
CustomCommand cc = new CustomCommand(label, Main.getMainBiscuit());
if(args.length >= 1) {
commandReply(e, "``Command:" + " " + cc.getName() + "``");
commandReply(e, "``Description:" + " " + cc.getDescription() + "``");
commandReply(e, "``Usage:" + " " + cc.getUsage() + "``");
}else {
commandReply(e, CustomCommand.fixPlaceholders(e, cc.getMessage()));
}
}else if(!isMain && Util.contains(b.getProperties().getCustomCmds(), label)) {
CustomCommand cc = new CustomCommand(label, b);
if(args.length >= 1) {
commandReply(e, "``Command:" + " " + cc.getName() + "``");
commandReply(e, "``Description:" + " " + cc.getDescription() + "``");
@ -97,25 +108,24 @@ public class CommandManager {
return true;
}
public void commandReply(MessageReceivedEvent e, String msg) {
Biscuit b = Main.getBiscuit();
public static void commandReply(MessageReceivedEvent e, String msg) {
if(e != null) {
b.say(e.getTextChannel(), msg);
e.getTextChannel().sendMessage(msg).queue();
}else {
b.log(msg);
Main.getLogger().info(msg);
}
}
public void addCommand(BaseCommand command) {
public static void addCommand(BaseCommand command) {
commands.add(command);
}
public void removeCommand(BaseCommand command) {
public static void removeCommand(BaseCommand command) {
commands.remove(command);
}
public List<BaseCommand> getCommands() {
public static List<BaseCommand> getCommands() {
return commands;
}

View File

@ -1,7 +1,6 @@
package com.fpghoti.biscuit.commands;
import com.fpghoti.biscuit.config.ConfigRetrieval;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.biscuit.Biscuit;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -13,9 +12,11 @@ public class CustomCommand extends BaseCommand {
}
private String name;
private Biscuit biscuit;
public CustomCommand(String name) {
public CustomCommand(String name, Biscuit biscuit) {
this.name = name;
this.biscuit = biscuit;
}
@Override
@ -25,12 +26,12 @@ public class CustomCommand extends BaseCommand {
@Override
public String getUsage() {
return PropertiesRetrieval.getCommandSignifier() + name;
return biscuit.getProperties().getCommandSignifier() + name;
}
@Override
public String getDescription() {
String desc = ConfigRetrieval.getFromConfig("cc-" + name + "-description");
String desc = biscuit.getConfig().getFromConfig("cc-" + name + "-description", biscuit);
if(desc == null) {
return "null";
}
@ -43,7 +44,7 @@ public class CustomCommand extends BaseCommand {
}
public String getMessage() {
String msg = ConfigRetrieval.getFromConfig("cc-" + name + "-message");
String msg = biscuit.getConfig().getFromConfig("cc-" + name + "-message", biscuit);
if(msg == null) {
return "null";
}

View File

@ -1,9 +1,8 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.util.Util;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -13,7 +12,7 @@ public class AddCommand extends ClientCommand{
public AddCommand() {
name = "Add";
description = "Finds sum of two numbers.";
usage = PropertiesRetrieval.getCommandSignifier() + "add <Num1> <Num2>";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "add <Num1> <Num2>";
minArgs = 2;
maxArgs = 2;
identifiers.add("add");
@ -21,7 +20,7 @@ public class AddCommand extends ClientCommand{
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Main.getBiscuit();
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -add");
if(args[0] != null && Util.isDeciDigit(args[0]) && args[1] != null && Util.isDeciDigit(args[1])) {
double num = Double.parseDouble(args[0]);

View File

@ -1,9 +1,8 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -12,7 +11,7 @@ public class ChanIDCommand extends ClientCommand{
public ChanIDCommand() {
name = "Channel ID";
description = "Retrieves the channel ID.";
usage = PropertiesRetrieval.getCommandSignifier() + "chanid";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "chanid";
minArgs = 0;
maxArgs = 0;
identifiers.add("chanid");
@ -20,7 +19,7 @@ public class ChanIDCommand extends ClientCommand{
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Main.getBiscuit();
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -chanid");
String id = event.getTextChannel().getId();
event.getTextChannel().sendMessage(id).queue();

View File

@ -1,9 +1,8 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.util.Util;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -13,7 +12,7 @@ public class DivideCommand extends ClientCommand{
public DivideCommand() {
name = "Divide";
description = "Divides two numbers.";
usage = PropertiesRetrieval.getCommandSignifier() + "divide <Num 1> <Num 2>";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "divide <Num 1> <Num 2>";
minArgs = 2;
maxArgs = 2;
identifiers.add("divide");
@ -22,7 +21,7 @@ public class DivideCommand extends ClientCommand{
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Main.getBiscuit();
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -divide");
if(args[0] != null && Util.isDeciDigit(args[0]) && args[1] != null && Util.isDeciDigit(args[1])) {
double num = Double.parseDouble(args[0]);

View File

@ -0,0 +1,45 @@
package com.fpghoti.biscuit.commands.client;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.logging.BColor;
import com.fpghoti.biscuit.util.PermUtil;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
public class GetConfigCommand extends ClientCommand{
public GetConfigCommand() {
name = "Get Config";
description = "Gets the config of the current guild.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "getconfig";
minArgs = 0;
maxArgs = 0;
identifiers.add("getconfig");
}
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -getconfig");
if(PermUtil.isAdmin(event.getMember())) {
event.getTextChannel().sendFile(b.getConfig().getFile(), "config-" + b.getProperties().getGuildCode() + ".properties").queue();
}else {
b.log(BColor.MAGENTA_BOLD + event.getAuthor().getName() + " lacks permission to view the config!");
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + " You do not have "
+ "permission to view the config.").queue(new Consumer<Message>()
{
@Override
public void accept(Message msg){
msg.delete().submitAfter(5, TimeUnit.SECONDS);
}
});
}
}
}

View File

@ -0,0 +1,31 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.util.PermUtil;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
public class GuildIDCommand extends ClientCommand{
public GuildIDCommand() {
name = "Guild ID";
description = "Retrieves a guild's ID.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "guildid";
minArgs = 0;
maxArgs = 0;
identifiers.add("guildid");
identifiers.add("gid");
}
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -guildid");
if(PermUtil.isMod(event.getMember())) {
event.getTextChannel().sendMessage(event.getGuild().getId()).queue();
}
}
}

View File

@ -3,12 +3,12 @@ package com.fpghoti.biscuit.commands.client;
import java.util.ArrayList;
import java.util.List;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.BaseCommand;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.commands.CommandManager;
import com.fpghoti.biscuit.commands.CustomCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.util.Util;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -18,7 +18,7 @@ public class HelpCommand extends ClientCommand {
public HelpCommand() {
name = "Help";
description = "Pulls up help menu";
usage = PropertiesRetrieval.getCommandSignifier() + "help [Page #]";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "help [Page #]";
minArgs = 0;
maxArgs = 1;
identifiers.add("help");
@ -27,7 +27,7 @@ public class HelpCommand extends ClientCommand {
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit biscuit = Main.getBiscuit();
Biscuit biscuit = Biscuit.getBiscuit(event.getGuild());
int pg = 1;
if (args.length > 0) {
@ -37,28 +37,35 @@ public class HelpCommand extends ClientCommand {
event.getTextChannel().sendMessage("Usage: ``" + usage + "``").queue();
}
}
List<BaseCommand> commands = new ArrayList<BaseCommand>();
String[] ccs = PropertiesRetrieval.getCustomCmds();
String[] ccs = biscuit.getProperties().getCustomCmds();
for(String s : ccs) {
if(!Util.contains(PropertiesRetrieval.disabledCommands(), s)) {
CustomCommand cc = new CustomCommand(s);
if(!Util.contains(biscuit.getProperties().disabledCommands(), s)) {
CustomCommand cc = new CustomCommand(s, biscuit);
commands.add(cc);
}
}
for(BaseCommand bc : biscuit.getCommandManager().getCommands()) {
String bclabel = bc.getUsage().split(" ")[0];
if(!Util.contains(PropertiesRetrieval.disabledCommands(), bclabel.replace(PropertiesRetrieval.getCommandSignifier(), ""))) {
commands.add(bc);
ccs = Main.getMainBiscuit().getProperties().getCustomCmds();
for(String s : ccs) {
if(!Util.contains(biscuit.getProperties().disabledCommands(), s)) {
CustomCommand cc = new CustomCommand(s, Main.getMainBiscuit());
commands.add(cc);
}
}
for(BaseCommand bc : CommandManager.getCommands()) {
String bclabel = bc.getUsage().split(" ")[0];
if(!Util.contains(biscuit.getProperties().disabledCommands(), bclabel.replace(Main.getMainBiscuit().getProperties().getCommandSignifier(), ""))) {
commands.add(bc);
}
}
int pageCount = (int) Math.ceil((double) commands.size() / 8);
if (pg > pageCount) {
pg = pageCount;
}
event.getTextChannel().sendMessage("**Use " + PropertiesRetrieval.getCommandSignifier() + "help [Page #] to navigate the different pages.**").queue();
event.getTextChannel().sendMessage("**Use " + Main.getMainBiscuit().getProperties().getCommandSignifier() + "help [Page #] to navigate the different pages.**").queue();
event.getTextChannel().sendMessage("[" + Integer.toString(pg) + "/" + Integer.toString(pageCount) + "] **Bot Commands:**").queue();
String msg = "";
for (int i = 0; i < 8; i++) {

View File

@ -1,9 +1,8 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.util.PermUtil;
import com.fpghoti.biscuit.util.Util;
@ -16,7 +15,7 @@ public class MakeInviteCommand extends ClientCommand{
public MakeInviteCommand() {
name = "Make Invite";
description = "Creates an invite in the specified channel";
usage = PropertiesRetrieval.getCommandSignifier() + "makeinvite <channel-name> [max-age-hours]";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "makeinvite <channel-name> [max-age-hours]";
minArgs = 1;
maxArgs = 2;
identifiers.add("makeinvite");
@ -29,10 +28,10 @@ public class MakeInviteCommand extends ClientCommand{
doubAge = Double.parseDouble(args[1]) * 3600;
}
int maxAge = (int)Math.round(doubAge);
Biscuit b = Main.getBiscuit();
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -makeinvite " + args[0]);
if((PermUtil.isAdmin(event.getMember()))) {
for(Guild g : b.getJDA().getGuilds()) {
Guild g = event.getGuild();
TextChannel c = null;
for(TextChannel t : g.getTextChannels()) {
if(t.getName().equalsIgnoreCase(args[0])) {
@ -55,6 +54,5 @@ public class MakeInviteCommand extends ClientCommand{
}
}
}
}
}

View File

@ -1,9 +1,8 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.util.Util;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -13,7 +12,7 @@ public class MultiplyCommand extends ClientCommand{
public MultiplyCommand() {
name = "Multiply";
description = "Multiplies two numbers.";
usage = PropertiesRetrieval.getCommandSignifier() + "multiply <Num1> <Num2>";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "multiply <Num1> <Num2>";
minArgs = 2;
maxArgs = 2;
identifiers.add("multiply");
@ -22,7 +21,7 @@ public class MultiplyCommand extends ClientCommand{
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Main.getBiscuit();
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -multiply");
if(args[0] != null && Util.isDeciDigit(args[0]) && args[1] != null && Util.isDeciDigit(args[1])) {
double num = Double.parseDouble(args[0]);

View File

@ -1,10 +1,8 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.global.SpamRecords;
import com.fpghoti.biscuit.util.PermUtil;
import net.dv8tion.jda.api.entities.Member;
@ -16,7 +14,7 @@ public class NotSpammerCommand extends ClientCommand{
public NotSpammerCommand() {
name = "Not Spammer";
description = "Delists user as spammer.";
usage = PropertiesRetrieval.getCommandSignifier() + "notspammer @<mention-user>";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "notspammer @<mention-user>";
minArgs = 1;
maxArgs = 1;
identifiers.add("notspammer");
@ -24,13 +22,13 @@ public class NotSpammerCommand extends ClientCommand{
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Main.getBiscuit();
Biscuit b = Biscuit.getBiscuit(event.getGuild());
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()))) {
SpamRecords.spammers.remove(u);
b.getMessageStore().removeSpammer(u);
event.getTextChannel().sendMessage(s+ " is no longer flagged as spam.").queue();
}
}

View File

@ -1,9 +1,8 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -12,7 +11,7 @@ public class PingCommand extends ClientCommand{
public PingCommand() {
name = "Ping";
description = "Pings the bot.";
usage = PropertiesRetrieval.getCommandSignifier() + "ping";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "ping";
minArgs = 0;
maxArgs = 0;
identifiers.add("ping");
@ -20,7 +19,7 @@ public class PingCommand extends ClientCommand{
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Main.getBiscuit();
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -ping");
event.getTextChannel().sendMessage("Pong!").queue();
}

View File

@ -1,9 +1,8 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.util.Util;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -13,7 +12,7 @@ public class PowerCommand extends ClientCommand{
public PowerCommand() {
name = "Power";
description = "Finds Num1 ^ Num2";
usage = PropertiesRetrieval.getCommandSignifier() + "power <Num1> <Num2>";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "power <Num1> <Num2>";
minArgs = 2;
maxArgs = 2;
identifiers.add("power");
@ -22,7 +21,7 @@ public class PowerCommand extends ClientCommand{
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Main.getBiscuit();
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -power");
if(args[0] != null && Util.isDeciDigit(args[0]) && args[1] != null && Util.isDeciDigit(args[1])) {
double num = Double.parseDouble(args[0]);

View File

@ -1,12 +1,9 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
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{
@ -14,7 +11,7 @@ public class RecentSpammersCommand extends ClientCommand{
public RecentSpammersCommand() {
name = "Recent Spammers";
description = "Retrieves a list of recent spammers.";
usage = PropertiesRetrieval.getCommandSignifier() + "recentspammers";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "recentspammers";
minArgs = 0;
maxArgs = 0;
identifiers.add("recentspammers");
@ -22,12 +19,9 @@ public class RecentSpammersCommand extends ClientCommand{
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Main.getBiscuit();
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -recentspammers");
String msg = "Recent spammers:";
for( User u: SpamRecords.spammers){
msg = msg + " " + u.getAsMention();
}
String msg = b.getMessageStore().getSpammerList();
event.getTextChannel().sendMessage(msg).queue();
}

View File

@ -0,0 +1,74 @@
package com.fpghoti.biscuit.commands.client;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.logging.BColor;
import com.fpghoti.biscuit.util.PermUtil;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.Message.Attachment;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
public class SaveConfigCommand extends ClientCommand{
public SaveConfigCommand() {
name = "Save Config";
description = "Saves the config of the current guild.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "getconfig (with file upload)";
minArgs = 0;
maxArgs = 0;
identifiers.add("saveconfig");
}
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -saveconfig");
List<Attachment> attch = event.getMessage().getAttachments();
if(PermUtil.isAdmin(event.getMember())) {
if(!attch.isEmpty()) {
if(attch.size() == 1) {
for(Attachment a : attch) {
b.getConfig().replaceConfig(a, event.getTextChannel());
b.remove();
b = Biscuit.loadGuild(event.getGuild());
}
}else {
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + " Too many attachments added! "
+ "Please only include the config file you want to save.").queue(new Consumer<Message>()
{
@Override
public void accept(Message msg){
msg.delete().submitAfter(5, TimeUnit.SECONDS);
}
});
}
}else {
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + " You need to send "
+ "a file in order to save the config.").queue(new Consumer<Message>()
{
@Override
public void accept(Message msg){
msg.delete().submitAfter(5, TimeUnit.SECONDS);
}
});
}
}else {
b.log(BColor.MAGENTA_BOLD + event.getAuthor().getName() + " lacks permission to save the config!");
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + " You do not have "
+ "permission to save the config.").queue(new Consumer<Message>()
{
@Override
public void accept(Message msg){
msg.delete().submitAfter(5, TimeUnit.SECONDS);
}
});
}
}
}

View File

@ -1,13 +1,15 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Biscuit;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
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.Message;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -16,7 +18,7 @@ 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 = PropertiesRetrieval.getCommandSignifier() + "softmute @<mention-user>";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "softmute @<mention-user>";
minArgs = 1;
maxArgs = 1;
identifiers.add("softmute");
@ -24,13 +26,23 @@ public class SoftMuteCommand extends ClientCommand{
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Main.getBiscuit();
Biscuit b = Biscuit.getBiscuit(event.getGuild());
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(b.getMessageStore().isSoftmuted(u)) {
event.getTextChannel().sendMessage(s+ " is already softmuted.").queue(new Consumer<Message>()
{
@Override
public void accept(Message msg){
msg.delete().reason("Automatic bot message removal").submitAfter(3, TimeUnit.SECONDS);
}
});
return;
}
if(event.getChannel().getName().equals("public-softmute-test") || (PermUtil.isMod(event.getMember()))) {
SpamRecords.softmute.add(u);
b.getMessageStore().addSoftmuted(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();
}

View File

@ -1,9 +1,8 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.util.Util;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -13,7 +12,7 @@ public class SquareRootCommand extends ClientCommand{
public SquareRootCommand() {
name = "Square Root";
description = "Finds square root.";
usage = PropertiesRetrieval.getCommandSignifier() + "squareroot <Num>";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "squareroot <Num>";
minArgs = 1;
maxArgs = 1;
identifiers.add("squareroot");
@ -22,7 +21,7 @@ public class SquareRootCommand extends ClientCommand{
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Main.getBiscuit();
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -squareroot");
if(args[0] != null && Util.isDeciDigit(args[0])) {
double num = Double.parseDouble(args[0]);

View File

@ -1,9 +1,8 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.util.Util;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -13,7 +12,7 @@ public class SubtractCommand extends ClientCommand{
public SubtractCommand() {
name = "Subtract";
description = "Subtracts two numbers.";
usage = PropertiesRetrieval.getCommandSignifier() + "subtract <Num1> <Num2>";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "subtract <Num1> <Num2>";
minArgs = 2;
maxArgs = 2;
identifiers.add("subtract");
@ -22,7 +21,7 @@ public class SubtractCommand extends ClientCommand{
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Main.getBiscuit();
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -subtract");
if(args[0] != null && Util.isDeciDigit(args[0]) && args[1] != null && Util.isDeciDigit(args[1])) {
double num = Double.parseDouble(args[0]);

View File

@ -1,9 +1,8 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.util.PermUtil;
import net.dv8tion.jda.api.entities.Emote;
@ -15,7 +14,7 @@ public class ToggleRoleCommand extends ClientCommand{
public ToggleRoleCommand() {
name = "ToggleRole";
description = "Toggles specified role on/off";
usage = PropertiesRetrieval.getCommandSignifier() + "togglerole <role>";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "togglerole <role>";
minArgs = 1;
maxArgs = 1;
identifiers.add("togglerole");
@ -24,13 +23,14 @@ public class ToggleRoleCommand extends ClientCommand{
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Main.getBiscuit();
Biscuit b = Biscuit.getBiscuit(event.getGuild());
if(!event.getAuthor().isBot()) {
b.log(event.getAuthor().getName() + " issued a command: -togglerole " + args[0]);
boolean foundEmote = false;
String rolename = "";
for(String s : PropertiesRetrieval.getToggleRoles()) {
for(String s : b.getProperties().getToggleRoles()) {
if(s.equalsIgnoreCase(args[0])) {
rolename = s;
}
@ -54,13 +54,14 @@ public class ToggleRoleCommand extends ClientCommand{
Emote done = null;
for(Emote e : event.getGuild().getEmotes()) {
if(e.getName().contains(PropertiesRetrieval.getDoneEmote())) {
if(e.getName().contains(b.getProperties().getDoneEmote())) {
done = e;
}
}
if(done == null) {
if(done != null) {
foundEmote = true;
}else {
b.error("Cannot find emote!");
return;
}
if(PermUtil.hasRole(event.getMember(), role)){
event.getGuild().removeRoleFromMember(event.getMember(),role).queue();
@ -75,9 +76,13 @@ public class ToggleRoleCommand extends ClientCommand{
}
if(canAdd) {
event.getGuild().addRoleToMember(event.getMember(), role).queue();
}
}
if(foundEmote) {
event.getMessage().addReaction(done).queue();
}else {
event.getMessage().addReaction("").queue();
}
}
}
}
}

View File

@ -1,9 +1,8 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.util.PermUtil;
import net.dv8tion.jda.api.entities.Member;
@ -15,7 +14,7 @@ public class UIDCommand extends ClientCommand{
public UIDCommand() {
name = "User ID";
description = "Retrieves a user's ID.";
usage = PropertiesRetrieval.getCommandSignifier() + "uid @<mention-user>";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "uid @<mention-user>";
minArgs = 1;
maxArgs = 1;
identifiers.add("uid");
@ -23,7 +22,7 @@ public class UIDCommand extends ClientCommand{
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Main.getBiscuit();
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -uid " + args[0]);
for(Member m : event.getMessage().getMentionedMembers()){
User u = m.getUser();

View File

@ -1,10 +1,8 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.global.SpamRecords;
import com.fpghoti.biscuit.util.PermUtil;
import net.dv8tion.jda.api.entities.Member;
@ -16,7 +14,7 @@ public class UnSoftMuteCommand extends ClientCommand{
public UnSoftMuteCommand() {
name = "Un Soft Mute";
description = "Removes a soft mute from a user.";
usage = PropertiesRetrieval.getCommandSignifier() + "unsoftmute @<mention-user>";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "unsoftmute @<mention-user>";
minArgs = 1;
maxArgs = 1;
identifiers.add("unsoftmute");
@ -24,13 +22,13 @@ public class UnSoftMuteCommand extends ClientCommand{
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Main.getBiscuit();
Biscuit b = Biscuit.getBiscuit(event.getGuild());
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()))) {
SpamRecords.softmute.remove(u);
b.getMessageStore().removeSoftmuted(u);
event.getTextChannel().sendMessage(s+ " is no longer soft-muted.").queue();
}
}

View File

@ -0,0 +1,30 @@
package com.fpghoti.biscuit.commands.client;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ClientCommand;
import com.fpghoti.biscuit.util.PermUtil;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
public class WikiCommand extends ClientCommand{
public WikiCommand() {
name = "Wiki";
description = "Sends a link to the Biscuit wiki. Look there for config help.";
usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "wiki";
minArgs = 0;
maxArgs = 0;
identifiers.add("wiki");
}
@Override
public void execute(String[] args, MessageReceivedEvent event) {
Biscuit b = Biscuit.getBiscuit(event.getGuild());
b.log(event.getAuthor().getName() + " issued a command: -wiki");
if(PermUtil.isMod(event.getMember())) {
event.getTextChannel().sendMessage("https://git.fpghoti.com/thmsdy/Biscuit/wiki").queue();
}
}
}

View File

@ -0,0 +1,60 @@
package com.fpghoti.biscuit.commands.console;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ConsoleCommand;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.TextChannel;
public class GuildSayCommand extends ConsoleCommand{
public GuildSayCommand() {
name = "Guild Say (Console)";
description = "Makes bot send message to a channel in the specified guild.";
usage = "[CONSOLE] guildsay <guild-code> <channel-name> <message>";
minArgs = 3;
maxArgs = 2000;
identifiers.add("guildsay");
identifiers.add("gsay");
}
public void execute(String[] args) {
if(args.length > 0) {
String guildcode = args[0];
Biscuit b = Biscuit.getBiscuit(guildcode);
if(b == null) {
Main.getMainBiscuit().log("INVALID GUILD! TRY: guildsay <guild-code> <channel-name> <message>");
return;
}
Guild guild = b.getGuild();
if(args.length > 1) {
String channel = args[1];
String message = "";
if(args.length > 2) {
message = args[2];
if(args.length > 3) {
for(int i = 3; i < args.length; i++) {
message = message + " " + args[i];
}
}
for(TextChannel c : guild.getTextChannels()) {
if(c.getName().equalsIgnoreCase(channel) || c.getName().equalsIgnoreCase("#" + channel)) {
c.sendMessage(message).queue();
}
}
}else{
b.log("INCORRECT USAGE! TRY: guildsay " + guildcode + " " + channel + " <message>");
}
}else{
b.log("INCORRECT USAGE! TRY: guildsay " + guildcode + " <channel-name> <message>");
}
}else{
Main.getMainBiscuit().log("INCORRECT USAGE! TRY: guildsay <guild-code> <channel-name> <message>");
}
}
}

View File

@ -1,7 +1,7 @@
package com.fpghoti.biscuit.commands.console;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.commands.ConsoleCommand;
import net.dv8tion.jda.api.entities.Guild;
@ -11,7 +11,7 @@ public class SayCommand extends ConsoleCommand{
public SayCommand() {
name = "Say (Console)";
description = "Makes bot send message on specified channel.";
description = "Makes bot send message to a channel in all guilds.";
usage = "[CONSOLE] say <channel-name> <message>";
minArgs = 2;
maxArgs = 2000;
@ -22,7 +22,7 @@ public class SayCommand extends ConsoleCommand{
}
public void execute(String[] args) {
Biscuit b = Main.getBiscuit();
Biscuit b = Main.getMainBiscuit();
if(args.length > 0) {
String target = args[0];
String message = "";
@ -33,7 +33,7 @@ public class SayCommand extends ConsoleCommand{
message = message + " " + args[i];
}
}
for(Guild guild : b.getJDA().getGuilds()) {
for(Guild guild : Main.getJDA().getGuilds()) {
for(TextChannel c : guild.getTextChannels()) {
if(c.getName().equalsIgnoreCase(target) || c.getName().equalsIgnoreCase("#" + target)) {

View File

@ -1,6 +1,5 @@
package com.fpghoti.biscuit.commands.console;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.commands.ConsoleCommand;
@ -16,11 +15,10 @@ public class ShutdownConsoleCommand extends ConsoleCommand{
}
public void execute(String[] args) {
Biscuit b = Main.getBiscuit();
if(args.length == 0) {
Main.shutdown();
}else{
b.log("INCORRECT USAGE! TRY: say <channel-name> <message>");
Main.getLogger().info("INCORRECT USAGE! TRY: say <channel-name> <message>");
}
}

View File

@ -0,0 +1,266 @@
package com.fpghoti.biscuit.config;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.PropertiesConfigurationLayout;
import org.apache.commons.configuration2.ex.ConfigurationException;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.jcabi.aspects.Async;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message.Attachment;
import net.dv8tion.jda.api.entities.TextChannel;
public class BiscuitConfig {
private Biscuit biscuit;
public BiscuitConfig(Biscuit b) {
this.biscuit = b;
}
public void generateConfig() {
Guild guild = biscuit.getGuild();
boolean isMain = guild == null;
String name = "config.properties";
if(!isMain) {
name = guild.getId() + ".properties";
}
File config = new File(biscuit.getConfigDir(), name);
if (!config.exists()) {
try {
if(isMain) {
Path path = config.toPath();
InputStream is = BiscuitConfig.class.getClassLoader().getResourceAsStream(name);
Files.copy( is, path);
is.close();
}else {
config.createNewFile();
updateConfig(config);
}
} catch (Exception e) {
e.printStackTrace();
}
}else {
updateConfig(config);
}
}
@Async
public void replaceConfig(Attachment a, TextChannel c) {
Guild guild = biscuit.getGuild();
String code = getFromConfig("Guild-Code", biscuit);
if(guild == null) {
biscuit.error("Main config replacement is currently not allowed.");
return;
}
String name = guild.getId() + ".properties";
if(a.getSize() > 51200) {
c.sendMessage("**The file is too big!**").queue();
return;
}
File config = new File(biscuit.getConfigDir(), name);
a.downloadToFile(config).thenAccept(file -> {
updateConfig(file, true, code);
c.sendMessage("**The config was successfully updated.**").queue();
}).exceptionally(t -> {
biscuit.error("Could not accept config file.");
c.sendMessage("**An Exception occurred while trying to read the file.**").queue();
return null;
});
return;
}
public void updateConfig(File config) {
updateConfig(config, false);
}
public void updateConfig(File config, boolean silent) {
updateConfig(config, false, null);
}
public void updateConfig(File config, boolean silent, String code) {
boolean added = false;
PropertiesConfiguration prop = new PropertiesConfiguration();
PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout();
prop.setLayout(layout);
try {
layout.load(prop, new FileReader(config));
FileWriter fw = new FileWriter(config);
added = addNewOptions(prop, silent, code);
layout.save(prop, fw);
if(biscuit.getGuild() == null && added && !silent) {
biscuit.log("Options have been added to config.properties! For information on what each "
+ "option does, check out the Biscuit wiki.");
}
} catch (ConfigurationException e) {
e.printStackTrace();
biscuit.error("There was an issue preparing the config for updates.");
return;
} catch (IOException e) {
e.printStackTrace();
biscuit.error("There was an issue preparing the config for updates.");
return;
}
}
private boolean addNewOptions(PropertiesConfiguration prop, boolean silent, String code) {
Guild guild = biscuit.getGuild();
boolean isMain = guild == null;
boolean added = false;
String name = "Main Config";
if(!isMain) {
name = guild.getName();
}
//Add properties to only be used in main config here
if(isMain) {
added = addProperty("Command-Signifier", "-", prop, added, silent);
added = addProperty("Bot-Token", "", prop, added, silent);
}
added = addProperty("Guild-Identifier", name, prop, added, silent);
if(prop.getProperty("Guild-Identifier") != null) {
prop.setProperty("Guild-Identifier", name);
}
//Add properties to only be used in guild configs here
if(!isMain) {
//Each key value will be set to [global] by default
added = addProperty("Guild-Code", "", prop, added, silent);
}
//Add properties to appear in both types of configs here
added = addProperty("ChatLog", "true", prop, added, silent);
added = addProperty("AllowSpamPunish", "true", prop, added, silent);
added = addProperty("Channels-To-Not-Chatlog", "ignore_me,ignore_me2,ignore_me3", prop, added, silent);
added = addProperty("NaughtyList", "piff,word123,another1", prop, added, silent);
added = addProperty("Restrict-Cmd-Channels", "false", prop, added, silent);
added = addProperty("CmdChannels", "bot,bot2,bot3", prop, added, silent);
added = addProperty("ToggleRoles", "role1,role2,role3", prop, added, silent);
added = addProperty("UseCustomDefaultRole", "true", prop, added, silent);
added = addProperty("DefaultRoleName", "Standard", prop, added, silent);
added = addProperty("Done-Emote", "ActionComplete", prop, added, silent);
added = addProperty("Captcha", "false", prop, added, silent);
added = addProperty("Captcha-Reward-Role", "cleared", prop, added, silent);
added = addProperty("No-Captcha-Kick", "false", prop, added, silent);
added = addProperty("No-Captcha-Kick-Time", "10", prop, added, silent);
added = addProperty("Block-Unicode-Emotes", "baby,snake,squid", prop, added, silent);
added = addProperty("Block-Custom-Emotes", "badfish,fix,bigleaf", prop, added, silent);
added = addProperty("DisabledCommands", "cmd1,cmd2,cmd3", prop, added, silent);
added = addProperty("DisabledUserCommands", "cmd4,cmd5,cmd6", prop, added, silent);
added = addProperty("ModRole", "biscuit-key", prop, added, silent);
added = addProperty("AdminRole", "biscuit-admin", prop, added, silent);
added = addProperty("Toggle-Role-React-Channels", "toggleroles1,toggleroles2,toggleroles3", prop, added, silent);
added = addProperty("Boost-Exclusive-Roles", "role2,role3", prop, added, silent);
added = addProperty("Treat-Like-Booster", "Nitro Booster,silver,gold", prop, added, silent);
added = addProperty("LogCaptcha", "false", prop, added, silent);
added = addProperty("Captcha-Log-Channel", "verify-log", prop, added, silent);
added = addProperty("Check-Join-Invite", "false", prop, added, silent);
added = addProperty("Custom-Command-Names", "", prop, added, silent);
if(!isMain) {
if(code != null) {
prop.setProperty("Guild-Code", code);
}
}
return added;
}
private boolean addProperty(String key, String value, PropertiesConfiguration prop, boolean added, boolean silent) {
Guild guild = biscuit.getGuild();
if(guild != null) {
value = "[global]";
}
if(prop.getProperty(key) == null) {
if(silent) {
biscuit.log("IMPORTANT: A new option has been added to the configuration file: " + key);
}
prop.addProperty(key, value);
return true;
}
return added;
}
public String getFromConfig(String property, Biscuit biscuit){
boolean isMain = biscuit.getGuild() == null;
String setting = "";
Properties prop = new Properties();
InputStream input = null;
String name = "config.properties";
if(!isMain) {
name = biscuit.getGuild().getId() + ".properties";
}
File config = new File(biscuit.getConfigDir(), name);
if(!config.exists()) {
return "";
}
try {
input = new FileInputStream(config);
prop.load(input);
setting = prop.getProperty(property);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return setting;
}
public File getFile() {
if(biscuit.getGuild() == null) {
return null;
}
String name = biscuit.getGuild().getId() + ".properties";
//Most likely will not happen
//but here to prevent bot token leakage
if(name.equalsIgnoreCase("config")) {
return null;
}
File config = new File(biscuit.getConfigDir(), name);
return config;
}
public String makeCode(String name) {
String code = "";
name = name.replace(" ", "");
if(name.length() > 6) {
code = name.substring(0, 6);
}else{
code = name;
}
return code.toUpperCase();
}
}

View File

@ -0,0 +1,331 @@
package com.fpghoti.biscuit.config;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.util.Util;
public class BiscuitProperties {
Biscuit biscuit;
public BiscuitProperties(Biscuit b) {
this.biscuit = b;
}
public String getToken(){
String key = "Bot-Token";
return Main.getMainBiscuit().getConfig().getFromConfig(key, Main.getMainBiscuit());
}
public String getCommandSignifier(){
String key = "Command-Signifier";
return Main.getMainBiscuit().getConfig().getFromConfig(key, Main.getMainBiscuit());
}
public String getGuildCode(){
String key = "Guild-Code";
if(biscuit.getGuild() == null) {
return "MAIN";
}
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return biscuit.getConfig().makeCode(biscuit.getGuild().getName());
}
return biscuit.getConfig().getFromConfig(key, biscuit);
}
public String getDoneEmote(){
String key = "Done-Emote";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().getDoneEmote();
}
return biscuit.getConfig().getFromConfig(key, biscuit);
}
public String getDontNotify(){
String key = "Dont-Notify-Role";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().getDontNotify();
}
return biscuit.getConfig().getFromConfig(key, biscuit);
}
public boolean captchaEnabled(){
String key = "Captcha";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().captchaEnabled();
}
String value = biscuit.getConfig().getFromConfig(key, biscuit);
return value.equalsIgnoreCase("true");
}
public boolean customDefaultRole(){
String key = "UseCustomDefaultRole";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().customDefaultRole();
}
String value = biscuit.getConfig().getFromConfig(key, biscuit);
return value.equalsIgnoreCase("true");
}
public String getCaptchaReward(){
String key = "Captcha-Reward-Role";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().getCaptchaReward();
}
return biscuit.getConfig().getFromConfig(key, biscuit);
}
public String getDefaultRole(){
String key = "DefaultRoleName";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().getDefaultRole();
}
return biscuit.getConfig().getFromConfig(key, biscuit);
}
public String getModRole(){
String key = "ModRole";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().getModRole();
}
return biscuit.getConfig().getFromConfig(key, biscuit);
}
public String getAdminRole(){
String key = "AdminRole";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().getAdminRole();
}
return biscuit.getConfig().getFromConfig(key, biscuit);
}
public String getCaptchaLogChannel(){
String key = "Captcha-Log-Channel";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().getCaptchaLogChannel();
}
return biscuit.getConfig().getFromConfig(key, biscuit);
}
public boolean logCaptcha(){
String key = "LogCaptcha";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().logCaptcha();
}
String value = biscuit.getConfig().getFromConfig(key, biscuit);
return value.equalsIgnoreCase("true");
}
public boolean spamPunishAllow(){
String key = "AllowSpamPunish";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().spamPunishAllow();
}
String value = biscuit.getConfig().getFromConfig(key, biscuit);
return value.equalsIgnoreCase("true");
}
public boolean checkJoinInvite(){
String key = "Check-Join-Invite";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().checkJoinInvite();
}
String value = biscuit.getConfig().getFromConfig(key, biscuit);
return value.equalsIgnoreCase("true");
}
public boolean noCaptchaKick(){
String key = "No-Captcha-Kick";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().noCaptchaKick();
}
String value = biscuit.getConfig().getFromConfig(key, biscuit);
return value.equalsIgnoreCase("true");
}
public Integer noCaptchaKickTime(){
String key = "No-Captcha-Kick-Time";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().noCaptchaKickTime();
}
String value = biscuit.getConfig().getFromConfig(key, biscuit);
if(!Util.isDigit(value)) {
return 0;
}
return Integer.parseInt(value);
}
public boolean logChat(){
String key = "ChatLog";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().logChat();
}
String value = biscuit.getConfig().getFromConfig(key, biscuit);
return value.equalsIgnoreCase("true");
}
public String[] getNaughtyWords(){
String key = "NaughtyList";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().getNaughtyWords();
}
String [] list = biscuit.getConfig().getFromConfig(key, biscuit).replace(" ", "").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public boolean restrictCmdChannels(){
String key = "Restrict-Cmd-Channels";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().restrictCmdChannels();
}
String value = biscuit.getConfig().getFromConfig(key, biscuit);
return value.equalsIgnoreCase("true");
}
public String[] getCmdChannels(){
String key = "CmdChannels";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().getCmdChannels();
}
String [] list = biscuit.getConfig().getFromConfig(key, biscuit).replace(" ", "").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public String[] getDontLogChannels(){
String key = "Channels-To-Not-Chatlog";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().getCmdChannels();
}
String [] list = biscuit.getConfig().getFromConfig(key, biscuit).replace(" ", "").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public String[] getToggleRoles(){
String key = "ToggleRoles";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().getToggleRoles();
}
String [] list = biscuit.getConfig().getFromConfig(key, biscuit).replace(" , ", ",").replace(", ", ",").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public String[] getBoostExclusiveRoles(){
String key = "Boost-Exclusive-Roles";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().getBoostExclusiveRoles();
}
String [] list = biscuit.getConfig().getFromConfig(key, biscuit).replace(" , ", ",").replace(", ", ",").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public String[] getBoosterRoles(){
String key = "Treat-Like-Booster";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().getBoosterRoles();
}
String [] list = biscuit.getConfig().getFromConfig(key, biscuit).replace(" , ", ",").replace(", ", ",").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public String[] blockedUnicodeEmotes(){
String key = "Block-Unicode-Emotes";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().blockedUnicodeEmotes();
}
String [] list = biscuit.getConfig().getFromConfig(key, biscuit).replace(" ", "").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public String[] blockedCustomEmotes(){
String key = "Block-Custom-Emotes";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().blockedCustomEmotes();
}
String [] list = biscuit.getConfig().getFromConfig(key, biscuit).replace(" ", "").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public String[] getCustomCmds(){
String key = "Custom-Command-Names";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().getCustomCmds();
}
String [] list = biscuit.getConfig().getFromConfig(key, biscuit).replace(" ", "").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public String[] disabledCommands(){
String key = "DisabledCommands";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().disabledCommands();
}
String [] list = biscuit.getConfig().getFromConfig(key, biscuit).replace(" ", "").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public String[] disabledUserCommands(){
String key = "DisabledUserCommands";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().disabledUserCommands();
}
String [] list = biscuit.getConfig().getFromConfig(key, biscuit).replace(" ", "").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public String[] getToggleChannels(){
String key = "Toggle-Role-React-Channels";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().getToggleChannels();
}
String [] list = biscuit.getConfig().getFromConfig(key, biscuit).replace(" ", "").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
}

View File

@ -1,147 +0,0 @@
package com.fpghoti.biscuit.config;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.PropertiesConfigurationLayout;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.slf4j.Logger;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.PluginCore;
public class ConfigRetrieval {
static Logger log = Main.log;
public static void generateConfig() {
File config;
if(Main.isPlugin) {
config = new File(PluginCore.plugin.getDataFolder(), "config.properties");
if(!config.exists()) {
config.getParentFile().mkdir();
}
}else {
config = new File("config.properties");
}
if (!config.exists()) {
try {
Path path = config.toPath();
InputStream is = ConfigRetrieval.class.getClassLoader().getResourceAsStream("config.properties");
Files.copy( is, path);
is.close();
} catch (Exception e) {
e.printStackTrace();
}
}else {
boolean added = false;
PropertiesConfiguration prop = new PropertiesConfiguration();
PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout();
prop.setLayout(layout);
try {
layout.load(prop, new FileReader(config));
FileWriter fw = new FileWriter(config);
added = updateConfig(prop);
layout.save(prop, fw);
if(added) {
Main.log.info("The above options have been added to config.properties! For information on what each "
+ "option does, check out the Biscuit wiki.");
}
} catch (ConfigurationException e) {
e.printStackTrace();
Main.log.error("There was an issue preparing the config for updates.");
return;
} catch (IOException e) {
e.printStackTrace();
Main.log.error("There was an issue preparing the config for updates.");
return;
}
}
}
private static boolean updateConfig(PropertiesConfiguration prop) {
boolean added = false;
added = addProperty("Command-Signifier", "-", prop, added);
added = addProperty("ChatLog", "true", prop, added);
added = addProperty("AllowSpamPunish", "true", prop, added);
added = addProperty("Channels-To-Not-Chatlog", "ignore_me,ignore_me2,ignore_me3", prop, added);
added = addProperty("Bot-Token", "", prop, added);
added = addProperty("NaughtyList", "piff,word123,another1", prop, added);
added = addProperty("Restrict-Cmd-Channels", "false", prop, added);
added = addProperty("CmdChannels", "bot,bot2,bot3", prop, added);
added = addProperty("ToggleRoles", "role1,role2,role3", prop, added);
added = addProperty("UseCustomDefaultRole", "true", prop, added);
added = addProperty("DefaultRoleName", "Standard", prop, added);
added = addProperty("Done-Emote", "ActionComplete", prop, added);
added = addProperty("Captcha", "false", prop, added);
added = addProperty("Captcha-Reward-Role", "cleared", prop, added);
added = addProperty("No-Captcha-Kick", "false", prop, added);
added = addProperty("No-Captcha-Kick-Time", "10", prop, added);
added = addProperty("Block-Unicode-Emotes", "baby,snake,squid", prop, added);
added = addProperty("Block-Custom-Emotes", "badfish,fix,bigleaf", prop, added);
added = addProperty("Custom-Command-Names", "", prop, added);
added = addProperty("DisabledCommands", "cmd1,cmd2,cmd3", prop, added);
added = addProperty("DisabledUserCommands", "cmd4,cmd5,cmd6", prop, added);
added = addProperty("ModRole", "biscuit-key", prop, added);
added = addProperty("AdminRole", "biscuit-admin", prop, added);
added = addProperty("Toggle-Role-React-Channels", "toggleroles1,toggleroles2,toggleroles3", prop, added);
added = addProperty("Boost-Exclusive-Roles", "role2,role3", prop, added);
added = addProperty("Treat-Like-Booster", "Nitro Booster,silver,gold", prop, added);
added = addProperty("LogCaptcha", "false", prop, added);
added = addProperty("Captcha-Log-Channel", "verify-log", prop, added);
added = addProperty("Check-Join-Invite", "false", prop, added);
return added;
}
private static boolean addProperty(String key, String value, PropertiesConfiguration prop, boolean added) {
if(prop.getProperty(key) == null) {
Main.log.info("IMPORTANT: A new option has been added to the configuration file: " + key);
prop.addProperty(key, value);
return true;
}
return added;
}
public static String getFromConfig(String property){
String setting = "";
Properties prop = new Properties();
InputStream input = null;
File config;
if(Main.isPlugin) {
config = new File(PluginCore.plugin.getDataFolder(), "config.properties");
}else {
config = new File("config.properties");
}
try {
input = new FileInputStream(config);
prop.load(input);
setting = prop.getProperty(property);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return setting;
}
}

View File

@ -1,184 +0,0 @@
package com.fpghoti.biscuit.config;
import com.fpghoti.biscuit.util.Util;
public class PropertiesRetrieval {
public static String getToken(){
return ConfigRetrieval.getFromConfig("Bot-Token");
}
public static String getCommandSignifier(){
return ConfigRetrieval.getFromConfig("Command-Signifier");
}
public static String getDoneEmote(){
return ConfigRetrieval.getFromConfig("Done-Emote");
}
public static String getDontNotify(){
return ConfigRetrieval.getFromConfig("Dont-Notify-Role");
}
public static boolean captchaEnabled(){
String value = ConfigRetrieval.getFromConfig("Captcha");
return value.equalsIgnoreCase("true");
}
public static boolean customDefaultRole(){
String value = ConfigRetrieval.getFromConfig("UseCustomDefaultRole");
return value.equalsIgnoreCase("true");
}
public static String getCaptchaReward(){
return ConfigRetrieval.getFromConfig("Captcha-Reward-Role");
}
public static String getDefaultRole(){
return ConfigRetrieval.getFromConfig("DefaultRoleName");
}
public static String getModRole(){
return ConfigRetrieval.getFromConfig("ModRole");
}
public static String getAdminRole(){
return ConfigRetrieval.getFromConfig("AdminRole");
}
public static String getCaptchaLogChannel(){
return ConfigRetrieval.getFromConfig("Captcha-Log-Channel");
}
public static boolean logCaptcha(){
String value = ConfigRetrieval.getFromConfig("LogCaptcha");
return value.equalsIgnoreCase("true");
}
public static boolean checkJoinInvite(){
String value = ConfigRetrieval.getFromConfig("Check-Join-Invite");
return value.equalsIgnoreCase("true");
}
public static boolean noCaptchaKick(){
String value = ConfigRetrieval.getFromConfig("No-Captcha-Kick");
return value.equalsIgnoreCase("true");
}
public static Integer noCaptchaKickTime(){
String value = ConfigRetrieval.getFromConfig("No-Captcha-Kick-Time");
if(!Util.isDigit(value)) {
return 0;
}
return Integer.parseInt(value);
}
public static boolean logChat(){
String value = ConfigRetrieval.getFromConfig("ChatLog");
return value.equalsIgnoreCase("true");
}
public static String[] getNaughtyWords(){
String [] list = ConfigRetrieval.getFromConfig("NaughtyList").replace(" ", "").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public static boolean restrictCmdChannels(){
String value = ConfigRetrieval.getFromConfig("Restrict-Cmd-Channels");
return value.equalsIgnoreCase("true");
}
public static String[] getCmdChannels(){
String [] list = ConfigRetrieval.getFromConfig("CmdChannels").replace(" ", "").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public static String[] getToggleRoles(){
String [] list = ConfigRetrieval.getFromConfig("ToggleRoles").replace(" , ", ",").replace(", ", ",").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public static String[] getBoostExclusiveRoles(){
String [] list = ConfigRetrieval.getFromConfig("Boost-Exclusive-Roles").replace(" , ", ",").replace(", ", ",").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public static String[] getBoosterRoles(){
String [] list = ConfigRetrieval.getFromConfig("Treat-Like-Booster").replace(" , ", ",").replace(", ", ",").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public static String[] blockedUnicodeEmotes(){
String [] list = ConfigRetrieval.getFromConfig("Block-Unicode-Emotes").replace(" ", "").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public static String[] blockedCustomEmotes(){
String [] list = ConfigRetrieval.getFromConfig("Block-Custom-Emotes").replace(" ", "").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public static String[] getCustomCmds(){
String [] list = ConfigRetrieval.getFromConfig("Custom-Command-Names").replace(" ", "").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public static String[] disabledCommands(){
String [] list = ConfigRetrieval.getFromConfig("DisabledCommands").replace(" ", "").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public static String[] disabledUserCommands(){
String [] list = ConfigRetrieval.getFromConfig("DisabledUserCommands").replace(" ", "").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
public static String[] getToggleChannels(){
String [] list = ConfigRetrieval.getFromConfig("Toggle-Role-React-Channels").replace(" ", "").split(",");
if(list.length == 1 && list[0].equals("")) {
String[] blank = {};
return blank;
}
return list;
}
}

View File

@ -1,19 +0,0 @@
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<>();
}

View File

@ -1,13 +0,0 @@
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<>();
}

View File

@ -7,11 +7,10 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import org.slf4j.Logger;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.PluginCore;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.logging.BColor;
import com.fpghoti.biscuit.user.PreUser;
import com.fpghoti.biscuit.util.PermUtil;
import com.github.cage.Cage;
@ -28,12 +27,11 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter;
public class DMListener extends ListenerAdapter{
Logger log = Main.log;
private static ArrayList<User> testers = new ArrayList<User>();
@Override
public void onMessageReceived(MessageReceivedEvent event){
//Biscuit biscuit = Biscuit.getBiscuit(event.getGuild());
if (event.isFromType(ChannelType.PRIVATE) && !event.getAuthor().isBot()) {
String content = event.getMessage().getContentDisplay();
User user = event.getAuthor();
@ -48,22 +46,24 @@ public class DMListener extends ListenerAdapter{
}
}
if(content.equalsIgnoreCase("captcha pls") || content.equalsIgnoreCase("cpls")) {
JDA jda = Main.getBiscuit().getJDA();
JDA jda = Main.getJDA();
for(Guild g : jda.getGuilds()) {
if(g.isMember(user)) {
Member m = g.getMember(user);
if(PermUtil.isAdmin(m)) {
isTest = true;
if(!found) {
PreUser.testusers.add(new PreUser(user,true));
if(!found && !PreUser.hasTestUser(event.getAuthor())) {
PreUser.testusers.add(new PreUser(user, Main.getMainBiscuit(), true));
testers.add(user);
}
}
}
}
}
if(PropertiesRetrieval.logChat()) {
log.info( "NEW PRIVATE MESSAGE - MSGID: " + event.getMessageId() + "- @" + user.getName() + " " + event.getAuthor().getAsMention() + " - " + content);
if(Main.getMainBiscuit().getProperties().logChat()) {
Main.getMainBiscuit().log("[" + BColor.CYAN_BOLD + "DM" + BColor.RESET + "] " + BColor.YELLOW + "ID: " + BColor.RESET +
event.getMessageId() + BColor.YELLOW + " Sender: " + BColor.RESET + event.getAuthor().getAsMention());
Main.getMainBiscuit().log(BColor.YELLOW + event.getAuthor().getName() + ": " + BColor.WHITE_BOLD + event.getMessage().getContentDisplay());
}
handleCaptcha(event, isTest);
}
@ -73,11 +73,12 @@ public class DMListener extends ListenerAdapter{
PreUser preu;
PrivateChannel channel = event.getPrivateChannel();
User author = event.getAuthor();
if(PreUser.getPreUser(author) != null || isTest) {
ArrayList<PreUser> preus = Biscuit.getPreUsers(event.getAuthor());
if(!preus.isEmpty() || isTest) {
if(isTest) {
preu = PreUser.getTestUser(author);
}else {
preu = PreUser.getPreUser(author);
preu = preus.get(0);
}
@ -91,9 +92,9 @@ public class DMListener extends ListenerAdapter{
if(preu.getToken() != null) {
channel.sendMessage(tlabel + "Sorry! That's not quite right! Please try again.").queue();
}
Main.log.info(tlabel + "Generating captcha challenge for user " + author.getName() + " " + author.getAsMention() + "...");
Main.getMainBiscuit().log(tlabel + "Generating captcha challenge for user " + author.getName() + " " + author.getAsMention() + "...");
Cage cage = Main.getBiscuit().getCage();
Cage cage = Main.getMainBiscuit().getCage();
preu.genToken();
@ -137,43 +138,50 @@ public class DMListener extends ListenerAdapter{
if(isTest) {
tlabel = "[TEST] ";
}
preu.setDone();
Main.log.info(tlabel + author.getName() + " successfully completed a captcha challenge. Granting role.");
Main.getBiscuit().captchaLog("" + tlabel + " ``" + author.getName() +"`` " + author.getAsMention() + " successfully completed a captcha challenge. Granting role.");
Role newrole = null;
Role defaultrole = null;
Main.getMainBiscuit().log(BColor.YELLOW_BOLD + tlabel + author.getName() + " successfully completed a captcha challenge. Granting role.");
if(isTest) {
preu.setDone();
Main.getMainBiscuit().captchaLog("" + tlabel + " ``" + author.getName() +"`` " + author.getAsMention() + " successfully completed a captcha challenge. Test complete.");
testers.remove(author);
preu.remove();
}else {
for(Guild g : preu.getGuilds()) {
for(PreUser p : preus) {
p.setDone();
Role newrole = null;
Role defaultrole = null;
Biscuit biscuit = p.getBiscuit();
biscuit.captchaLog("" + tlabel + " ``" + author.getName() +"`` " + author.getAsMention() + " successfully completed a captcha challenge. Granting role.");
Guild g = biscuit.getGuild();
for(Role r : g.getRoles()) {
if(r.getName().toLowerCase().contains(PropertiesRetrieval.getCaptchaReward().toLowerCase())) {
if(r.getName().toLowerCase().contains(biscuit.getProperties().getCaptchaReward().toLowerCase())) {
newrole = r;
}else if(r.getName().toLowerCase().contains(PropertiesRetrieval.getDefaultRole().toLowerCase())) {
}else if(r.getName().toLowerCase().contains(biscuit.getProperties().getDefaultRole().toLowerCase())) {
defaultrole = r;
}
}
if(newrole == null) {
Main.log.error("Cannot find captcha reward role!");
biscuit.error("Cannot find captcha reward role!");
return;
}
if(defaultrole == null) {
Main.log.error("Cannot find captcha default role!");
biscuit.error("Cannot find captcha default role!");
return;
}
Member member = g.getMemberById(author.getId());
g.addRoleToMember(member, newrole).queue();
g.removeRoleFromMember(member, defaultrole).queue();
preu.remove();
g.removeRoleFromMember(member, defaultrole).complete();
p.remove();
}
}
channel.sendMessage(tlabel + "Well done, " + author.getAsMention() + "!").queue();
channel.sendMessage(tlabel + "Well done, " + author.getAsMention() + "!").complete();
}
}

View File

@ -0,0 +1,51 @@
package com.fpghoti.biscuit.listener;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.logging.BColor;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.events.guild.GenericGuildEvent;
import net.dv8tion.jda.api.events.guild.GuildAvailableEvent;
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
import net.dv8tion.jda.api.events.guild.GuildLeaveEvent;
import net.dv8tion.jda.api.events.guild.GuildUnavailableEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
public class GuildListener extends ListenerAdapter {
@Override
public void onGuildJoin(GuildJoinEvent event) {
loadGuild(event);
}
@Override
public void onGuildAvailable(GuildAvailableEvent event) {
loadGuild(event);
}
@Override
public void onGuildLeave(GuildLeaveEvent event) {
unloadGuild(event);
}
@Override
public void onGuildUnavailable(GuildUnavailableEvent event) {
unloadGuild(event);
}
private void loadGuild(GenericGuildEvent event) {
Guild g = event.getGuild();
Biscuit biscuit = Biscuit.loadGuild(g);
biscuit.log(BColor.CYAN_BOLD + "---- Joined new Guild! ----");
biscuit.log(BColor.CYAN_BOLD + "Name: " + BColor.WHITE + g.getName());
biscuit.log(BColor.CYAN_BOLD + "Id: " + BColor.WHITE + g.getId());
biscuit.log(BColor.CYAN_BOLD + "---------------------------");
}
private void unloadGuild(GenericGuildEvent event) {
Guild g = event.getGuild();
Biscuit biscuit = Biscuit.getBiscuit(g);
biscuit.remove();
}
}

View File

@ -2,11 +2,8 @@ package com.fpghoti.biscuit.listener;
import java.util.HashMap;
import org.slf4j.Logger;
import com.fpghoti.biscuit.Biscuit;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.logging.BColor;
import com.fpghoti.biscuit.user.PreUser;
import com.jcabi.aspects.Async;
@ -19,35 +16,34 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter;
public class JoinListener extends ListenerAdapter {
Logger log = Main.log;
@Override
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
Biscuit b = Main.getBiscuit();
Biscuit biscuit = Biscuit.getBiscuit(event.getGuild());
User user = event.getMember().getUser();
log.info("USER JOINED: " + user.getName() + " " + user.getAsMention());
b.captchaLog("**User Joined:** ``" + user.getName() + "`` " + user.getAsMention());
if(b.canManageServer() && PropertiesRetrieval.checkJoinInvite()) {
logUserInvite(user);
biscuit.log(BColor.YELLOW_BOLD + "USER JOINED: " + user.getName() + " " + user.getAsMention());
biscuit.captchaLog("**User Joined:** ``" + user.getName() + "`` " + user.getAsMention());
if(biscuit.canManageServer() && biscuit.getProperties().checkJoinInvite()) {
logUserInvite(user, biscuit);
}else {
b.clearInviteUses();
biscuit.clearInviteUses();
}
if(PropertiesRetrieval.customDefaultRole()) {
if(biscuit.getProperties().customDefaultRole()) {
if(!event.getMember().getUser().isBot()) {
log.info("Issuing a role..");
biscuit.log("Issuing a role..");
Role role = null;
for(Role r : event.getGuild().getRoles()) {
if(r.getName().equals(PropertiesRetrieval.getDefaultRole())) {
if(r.getName().equals(biscuit.getProperties().getDefaultRole())) {
role = r;
}
}
if(role == null) {
log.error("Cannot find role!");
biscuit.error("Cannot find role!");
return;
}
if(PropertiesRetrieval.captchaEnabled()) {
new PreUser(event.getMember().getUser());
if(biscuit.getProperties().captchaEnabled()) {
biscuit.log(BColor.MAGENTA_BOLD + "Adding pre-join check for user " + user.getName() + " (" + user.getAsMention() + ")...");
new PreUser(event.getMember().getUser(), biscuit);
}
event.getGuild().addRoleToMember(event.getMember(), role).queue();
@ -57,9 +53,8 @@ public class JoinListener extends ListenerAdapter {
}
@Async
private void logUserInvite(final User user){
final Biscuit b = Main.getBiscuit();
for(Guild g : b.getJDA().getGuilds()) {
private void logUserInvite(final User user, final Biscuit b){
Guild g = b.getGuild();
g.retrieveInvites().queue((invs) -> {
String usedInv = "Other";
HashMap<String, Integer> newinv = new HashMap<String, Integer>();
@ -73,15 +68,14 @@ public class JoinListener extends ListenerAdapter {
}
}
if(empty) {
log.info("The ability for the bot to check the invites has only recently been enabled, so there is not enough data to determine the invite used. This should be fixed by the next time a user joins the server.");
b.log("The ability for the bot to check the invites has only recently been enabled, so there is not enough data to determine the invite used. This should be fixed by the next time a user joins the server.");
usedInv = "Unknown";
}
b.setInviteUses(newinv);
log.info("INVITE INFO: " + user.getName() + " used invite: " + usedInv);
b.log(BColor.YELLOW_BOLD + "INVITE INFO: " + BColor.WHITE + user.getName() + " used invite: " + BColor.GREEN_BOLD + usedInv);
b.captchaLog("**Invite Info:** ``" + user.getName() + "`` used invite: ``" + usedInv + "``");
});
}
}
}

View File

@ -1,8 +1,7 @@
package com.fpghoti.biscuit.listener;
import org.slf4j.Logger;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.logging.BColor;
import com.fpghoti.biscuit.util.Util;
import net.dv8tion.jda.api.events.message.MessageDeleteEvent;
@ -10,12 +9,11 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter;
public class MessageDeleteListener extends ListenerAdapter {
Logger log = Main.log;
@Override
public void onMessageDelete(MessageDeleteEvent event) {
Biscuit biscuit = Biscuit.getBiscuit(event.getGuild());
if(Util.isLoggable(event.getTextChannel())) {
log.info("MESSAGE DELETED - MSGID: " + event.getMessageId());
biscuit.log(BColor.MAGENTA_BOLD + "Message " + event.getMessageId() + " was deleted.");
}
}

View File

@ -1,8 +1,7 @@
package com.fpghoti.biscuit.listener;
import org.slf4j.Logger;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.logging.BColor;
import com.fpghoti.biscuit.util.Util;
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
@ -10,12 +9,14 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter;
public class MessageEditListener extends ListenerAdapter {
Logger log = Main.log;
@Override
public void onMessageUpdate(MessageUpdateEvent event) {
Biscuit biscuit = Biscuit.getBiscuit(event.getGuild());
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());
biscuit.log("[" + BColor.CYAN_BOLD + "MSG EDIT" + BColor.RESET + "] " + BColor.CYAN + "ID: " + BColor.RESET +
event.getMessageId() + BColor.CYAN + " User: " + BColor.RESET + event.getAuthor().getAsMention() +
BColor.GREEN + " Channel: " + BColor.RESET + event.getChannel().getName());
biscuit.log(BColor.CYAN + event.getAuthor().getName() + ": " + BColor.WHITE_BOLD + event.getMessage().getContentDisplay());
}
}

View File

@ -1,123 +1,167 @@
package com.fpghoti.biscuit.listener;
import org.slf4j.Logger;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.config.ConfigRetrieval;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.global.MessageQueue;
import com.fpghoti.biscuit.global.SpamRecords;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.biscuit.BiscuitMessageStore;
import com.fpghoti.biscuit.logging.BColor;
import com.fpghoti.biscuit.util.ChatFilter;
import com.fpghoti.biscuit.util.PermUtil;
import com.fpghoti.biscuit.util.Util;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.entities.Message;
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;
/*TODO Cleanup*/
@Override
public void onMessageReceived(MessageReceivedEvent event){
if (event.isFromType(ChannelType.TEXT)) {
Biscuit biscuit = Biscuit.getBiscuit(event.getGuild());
if(event.getAuthor().isBot()) {
logBot(event, biscuit);
return;
}
PermUtil.clearUndeservedRoles(event.getMember());
logUser(event, biscuit);
if(isNaughty(event)) {
return;
}
if(handleSoftmuted(event, biscuit)) {
return;
}
if(!handleSpammer(event, biscuit) && biscuit.getProperties().spamPunishAllow()){
checkNewSpammer(event, biscuit);
}
}
}
private void logBot(MessageReceivedEvent event, Biscuit biscuit) {
if(Util.isLoggable(event.getTextChannel())) {
if(PropertiesRetrieval.logChat()) {
log.info( "NEW MSG - MSGID: " + event.getMessageId() + "- @" + event.getAuthor().getName() + " " + event.getAuthor().getAsMention() + " - CHANNEL: #" + event.getChannel().getName() + " - " + event.getMessage().getContentDisplay());
if(biscuit.getProperties().logChat()) {
biscuit.log("[" + BColor.BLACK_BOLD + "BOT" + BColor.RESET + "] [" + BColor.RED + "#" + event.getChannel().getName() + BColor.RESET + "] "
+ BColor.RED_BOLD + event.getAuthor().getName() + ": " + BColor.RESET + event.getMessage().getContentDisplay());
}
}
}
if(event.getAuthor().isBot() && event.getMessage().getContentRaw().contains("This message contains words not appropriate for this channel.") || (ChatFilter.filter(event))){
MessageQueue.removemessages.put(event.getMessage().getId(), event.getTextChannel());
private void logUser(MessageReceivedEvent event, Biscuit biscuit) {
if(Util.isLoggable(event.getTextChannel())) {
if(biscuit.getProperties().logChat()) {
biscuit.log("[" + BColor.CYAN_BOLD + "MSG" + BColor.RESET + "] " + BColor.GREEN + "ID: " + BColor.RESET +
event.getMessageId() + BColor.GREEN + " Sender: " + BColor.RESET + event.getAuthor().getAsMention() +
BColor.GREEN + " Channel: " + BColor.RESET + event.getChannel().getName());
biscuit.log(BColor.GREEN_BOLD + event.getAuthor().getName() + ": " + BColor.WHITE_BOLD + event.getMessage().getContentDisplay());
}
}
}
//staff channels do not need filtering, as the filter could actually be a hinderance
private boolean isNaughty(MessageReceivedEvent event) {
// TODO make staff filter configurable
if(!event.getChannel().getName().toLowerCase().contains("staff") && ChatFilter.filter(event, false)){
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + " This message contains words not appropriate for this channel.").complete();
MessageQueue.fastremovemessages.put(event.getMessage().getId(), event.getTextChannel());
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + " This message contains words not appropriate for this channel.").queue(new Consumer<Message>()
{
@Override
public void accept(Message msg){
msg.delete().submitAfter(3, TimeUnit.SECONDS);
}
});
event.getMessage().delete().submit();
return true;
}
return false;
}
if(!event.getAuthor().isBot() && !MessageQueue.chatssent.containsKey(event.getAuthor())){
MessageQueue.chatssent.put(event.getAuthor(), 0);
private boolean handleSpammer(MessageReceivedEvent event, Biscuit biscuit) {
//TODO make numbers configurable
BiscuitMessageStore store = biscuit.getMessageStore();
String mention = event.getAuthor().getAsMention();
if(store.isSpammer(event.getAuthor())){
//User is a spammer but has not sent a message during
//the current interval. Count message and take no action
if(!store.hasTenSecondCount(event.getAuthor())) {
store.setTenSecondCount(event.getAuthor(), 1);
return false;
}
//User is a spammer and has sent another message during
//the current interval. Remove message.
if(store.getTenSecondsCount(event.getAuthor()) >= 1) {
biscuit.log(BColor.MAGENTA_BOLD + "Removed spam message from " + event.getAuthor().getName());
event.getMessage().delete().reason("Spam removal activated for " + mention).submit();
return true;
}
}
return false;
}
if(!event.getAuthor().isBot() && !MessageQueue.spammsgs.containsKey(event.getAuthor())){
MessageQueue.spammsgs.put(event.getAuthor(), 0);
private boolean handleSoftmuted(MessageReceivedEvent event, Biscuit biscuit) {
//TODO make numbers configurable
BiscuitMessageStore store = biscuit.getMessageStore();
String mention = event.getAuthor().getAsMention();
if(store.isSoftmuted(event.getAuthor())){
//User is softmuted but has not sent a message during
//the current interval. Count message and take no action
if(!store.hasTwoMinCount(event.getAuthor())) {
store.setTwoMinCount(event.getAuthor(), 1);
return false;
}
//User is softmuted and has sent another message during
//the current interval. Remove message.
if(store.getTwoMinCount(event.getAuthor()) >= 1) {
biscuit.log(BColor.MAGENTA_BOLD + event.getAuthor().getName() + " is softmuted. Removing message...");
event.getMessage().delete().reason("User is softmuted: " + mention).submit();
return true;
}
}
return false;
}
if(!MessageQueue.chatssent10s.containsKey(event.getAuthor()) && SpamRecords.spammers.contains(event.getAuthor())){
MessageQueue.chatssent10s.put(event.getAuthor(), 0);
private void checkNewSpammer(MessageReceivedEvent event, Biscuit biscuit) {
BiscuitMessageStore store = biscuit.getMessageStore();
String mention = event.getAuthor().getAsMention();
if(!store.hasMessageCount(event.getAuthor())) {
store.setMessageCount(event.getAuthor(), 1);
return;
}else {
store.setMessageCount(event.getAuthor(), store.getMessageCount(event.getAuthor()) + 1);
}
if(!MessageQueue.chatssent2m.containsKey(event.getAuthor()) && SpamRecords.softmute.contains(event.getAuthor())){
MessageQueue.chatssent2m.put(event.getAuthor(), 0);
if(store.getMessageCount(event.getAuthor()) > 7){
//User has already been warned. Remove warning and apply restrictions.
if(!store.isSpammer(event.getAuthor()) && store.isSpamWarned(event.getAuthor())){
store.addSpammer(event.getAuthor());
store.removeSpamWarned(event.getAuthor());
event.getMessage().delete().submit();
event.getTextChannel().sendMessage("*Flagging " + mention + " as spam!*").queue(new Consumer<Message>()
{
@Override
public void accept(Message msg){
msg.delete().reason("Automatic bot message removal").submitAfter(3, TimeUnit.SECONDS);
}
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);
});
biscuit.log(BColor.MAGENTA_BOLD + "User " + event.getAuthor().getName() + " has been flagged as spam!");
event.getMessage().delete().reason("Spam removal activated for " + mention).submit();
//User is spamming and has not been warned. Apply warning.
}else if(!store.isSpammer(event.getAuthor()) && !store.isSpamWarned(event.getAuthor())){
store.removeMessageCount(event.getAuthor());
store.addSpamWarned(event.getAuthor());
event.getTextChannel().sendMessage("**STOP spamming, " + mention + "! You have been warned!**").queue(new Consumer<Message>()
{
@Override
public void accept(Message msg){
msg.delete().reason("Automatic bot message removal").submitAfter(3, TimeUnit.SECONDS);
}
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());
}
}
////// Listen for spammers
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() + "!");
});
biscuit.log(BColor.MAGENTA_BOLD + "User " + event.getAuthor().getName() + " has been warned for spam!");
}
}
}
if(event.getGuild().getSelfMember().hasPermission(Permission.MESSAGE_MANAGE)){
MessageQueue.fastremovemessages.put(event.getMessage().getId(), event.getTextChannel());
}
}
}
/////
}
}
}

View File

@ -1,9 +1,7 @@
package com.fpghoti.biscuit.listener;
import org.slf4j.Logger;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.logging.BColor;
import com.fpghoti.biscuit.util.PermUtil;
import com.fpghoti.biscuit.util.Util;
@ -17,32 +15,33 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter;
public class ReactionListener extends ListenerAdapter{
Logger log = Main.log;
@Override
public void onMessageReactionAdd(MessageReactionAddEvent event){
Biscuit biscuit = Biscuit.getBiscuit(event.getGuild());
if(event.getGuild() == null) {
return;
}
if(Util.contains(PropertiesRetrieval.getToggleChannels(),event.getTextChannel().getName())) {
if(Util.contains(biscuit.getProperties().getToggleChannels(),event.getTextChannel().getName())) {
handleMessageRole(event, false);
}
}
@Override
public void onMessageReactionRemove(MessageReactionRemoveEvent event){
Biscuit biscuit = Biscuit.getBiscuit(event.getGuild());
if(event.getGuild() == null) {
return;
}
if(Util.contains(PropertiesRetrieval.getToggleChannels(),event.getTextChannel().getName())) {
if(Util.contains(biscuit.getProperties().getToggleChannels(),event.getTextChannel().getName())) {
handleMessageRole(event, true);
}
}
private void handleMessageRole(GenericMessageReactionEvent event, boolean remove) {
Biscuit biscuit = Biscuit.getBiscuit(event.getGuild());
event.getTextChannel().retrieveMessageById(event.getMessageId()).queue((message) -> {
String msg = message.getContentDisplay();
for(String rolename : PropertiesRetrieval.getToggleRoles()) {
for(String rolename : biscuit.getProperties().getToggleRoles()) {
for(Role r : event.getGuild().getRoles()) {
if(r.getName().toLowerCase().equalsIgnoreCase(rolename)) {
if(msg.toLowerCase().contains("[toggle " + rolename.toLowerCase() + "]")) {
@ -58,6 +57,7 @@ public class ReactionListener extends ListenerAdapter{
}
private void toggleRole(Role role, GenericMessageReactionEvent event, boolean remove) {
Biscuit biscuit = Biscuit.getBiscuit(event.getGuild());
Guild guild = event.getGuild();
if(role == null) {
return;
@ -65,7 +65,7 @@ public class ReactionListener extends ListenerAdapter{
Member m = event.getMember();
if(remove) {
if(PermUtil.hasRole(m, role)) {
log.info("REACTION TOGGLE (#" + event.getTextChannel().getName() + ") - Removing role " + role.getName() + " from " + m.getUser().getName() + "(" + m.getId() + ")");
biscuit.log(BColor.MAGENTA_BOLD + "REACTION TOGGLE (#" + event.getTextChannel().getName() + ") - " + BColor.RESET + "Removing role " + role.getName() + " from " + m.getUser().getName() + "(" + m.getId() + ")");
guild.removeRoleFromMember(m, role).queue();
}
}else {
@ -80,7 +80,7 @@ public class ReactionListener extends ListenerAdapter{
canAdd = true;
}
if(canAdd) {
log.info("REACTION TOGGLE (#" + event.getTextChannel().getName() + ") - Adding role " + role.getName() + " too " + m.getUser().getName() + "(" + m.getId() + ")");
biscuit.log(BColor.MAGENTA_BOLD + "REACTION TOGGLE (#" + event.getTextChannel().getName() + ") - " + BColor.RESET + " Adding role " + role.getName() + " too " + m.getUser().getName() + "(" + m.getId() + ")");
guild.addRoleToMember(m, role).queue();
}
}

View File

@ -1,8 +1,5 @@
package com.fpghoti.biscuit.listener;
import org.slf4j.Logger;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.util.PermUtil;
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent;
@ -10,8 +7,6 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter;
public class RoleListener extends ListenerAdapter{
Logger log = Main.log;
@Override
public void onGuildMemberRoleRemove(GuildMemberRoleRemoveEvent event){
PermUtil.clearUndeservedRoles(event.getMember());

View File

@ -0,0 +1,43 @@
package com.fpghoti.biscuit.logging;
public enum BColor {
RESET("\033[0m"),
BLACK("\033[0;30m"),
RED("\033[0;31m"),
GREEN("\033[0;32m"),
YELLOW("\033[0;33m"),
BLUE("\033[0;34m"),
MAGENTA("\033[0;35m"), //Doesn't display on powershell
CYAN("\033[0;36m"),
WHITE("\033[0;37m"),
BLACK_BOLD("\033[1;30m"),
RED_BOLD("\033[1;31m"),
GREEN_BOLD("\033[1;32m"),
YELLOW_BOLD("\033[1;33m"),
BLUE_BOLD("\033[1;34m"),
MAGENTA_BOLD("\033[1;35m"),
CYAN_BOLD("\033[1;36m"),
WHITE_BOLD("\033[1;37m");
private final String code;
BColor(String code) {
this.code = code;
}
@Override
public String toString() {
return code;
}
public static String clear(String s) {
for(BColor b : BColor.values()) {
s = s.replace(b.toString(), "");
}
return s;
}
}

View File

@ -0,0 +1,36 @@
package com.fpghoti.biscuit.logging;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BiscuitLog {
private final Logger console = LoggerFactory.getLogger("Biscuit");
private final Logger file = LoggerFactory.getLogger("B-File");
public void debug(String msg) {
console.debug(BColor.MAGENTA_BOLD + msg + BColor.RESET);
file.debug(BColor.clear(msg));
}
public void error(String msg) {
console.error(BColor.RED + msg + BColor.RESET);
file.error(BColor.clear(msg));
}
public void info(String msg) {
console.info(msg + BColor.RESET);
file.info(BColor.clear(msg));
}
public void trace(String msg) {
console.trace(BColor.WHITE_BOLD + msg + BColor.RESET);
file.trace(BColor.clear(msg));
}
public void warn(String msg) {
console.warn(BColor.YELLOW + msg + BColor.RESET);
file.warn(BColor.clear(msg));
}
}

View File

@ -2,11 +2,15 @@ package com.fpghoti.biscuit.timer;
import java.util.TimerTask;
import com.fpghoti.biscuit.biscuit.Biscuit;
public abstract class BiscuitTimer extends TimerTask{
protected Long delay;
protected Long period;
protected Biscuit biscuit;
public long getDelay() {
if(delay != null) {
return delay;

View File

@ -1,28 +0,0 @@
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();
}
}

View File

@ -1,19 +1,18 @@
package com.fpghoti.biscuit.timer.task;
import com.fpghoti.biscuit.global.MessageQueue;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.timer.BiscuitTimer;
public class ChatCountTimer extends BiscuitTimer {
public ChatCountTimer(){
public ChatCountTimer(Biscuit b){
biscuit = b;
delay = (long) 0;
period = (long) 10*1000;
}
public void run() {
MessageQueue.chatssent.clear();
MessageQueue.spammsgs.clear();
MessageQueue.chatssent10s.clear();
biscuit.getMessageStore().forgetChats();
}
}

View File

@ -1,19 +1,21 @@
package com.fpghoti.biscuit.timer.task;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.timer.BiscuitTimer;
import com.fpghoti.biscuit.user.PreUser;
public class DecrementTimer extends BiscuitTimer{
public DecrementTimer(){
public DecrementTimer(Biscuit b){
biscuit = b;
delay = (long) 0;
period = (long) 60*1000;
}
public void run() {
if(Main.ready) {
for(PreUser p : PreUser.users) {
for(PreUser p : biscuit.getPreUsers()) {
p.decrementTime();
}
}

View File

@ -1,26 +0,0 @@
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;
period = (long) 250;
}
public void run() {
for(String m : MessageQueue.fastremovemessages.keySet()){
try{
MessageQueue.fastremovemessages.get(m).deleteMessageById(m).complete();
}catch(ErrorResponseException ex){
}
}
MessageQueue.fastremovemessages.clear();
}
}

View File

@ -1,26 +0,0 @@
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();
}
}

View File

@ -1,17 +1,18 @@
package com.fpghoti.biscuit.timer.task;
import com.fpghoti.biscuit.global.MessageQueue;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.timer.BiscuitTimer;
public class SoftMuteTimer extends BiscuitTimer{
public SoftMuteTimer(){
public SoftMuteTimer(Biscuit b){
biscuit = b;
delay = (long) 0;
period = (long) 120*1000;
}
public void run() {
MessageQueue.chatssent2m.clear();
biscuit.getMessageStore().allowSoftMutedMessage();
}
}

View File

@ -0,0 +1,24 @@
package com.fpghoti.biscuit.timer.task;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.timer.BiscuitTimer;
import com.fpghoti.biscuit.user.PreUser;
public class StatusTimer extends BiscuitTimer{
public StatusTimer(Biscuit b){
biscuit = b;
delay = (long) 0;
period = (long) 60*1000;
}
public void run() {
if(Main.ready) {
for(PreUser p : biscuit.getPreUsers()) {
p.decrementTime();
}
}
}
}

View File

@ -6,38 +6,30 @@ import java.util.concurrent.CopyOnWriteArrayList;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.PluginCore;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.util.PermUtil;
import com.github.cage.Cage;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
public class PreUser {
public static CopyOnWriteArrayList<PreUser> testusers = new CopyOnWriteArrayList<PreUser>();
public static CopyOnWriteArrayList<PreUser> users = new CopyOnWriteArrayList<PreUser>();
public static PreUser getTestUser(User user) {
for(PreUser u : testusers) {
if(u.getUser().getId().equals(user.getId())) {
return u;
public static PreUser getTestUser(User u) {
for(PreUser pu : testusers) {
if(pu.getUser().getId().equals(u.getId())) {
return pu;
}
}
return null;
}
public static PreUser getPreUser(User user) {
for(PreUser u : users) {
if(u.getUser().getId().equals(user.getId())) {
return u;
}
}
return null;
}
public static boolean preUserExists(User user) {
return getPreUser(user) != null;
public static boolean hasTestUser(User u) {
return getTestUser(u) != null;
}
private User user;
@ -45,22 +37,28 @@ public class PreUser {
private int timeLeft;
private boolean done;
private boolean test;
private Biscuit biscuit;
public PreUser(User user) {
this(user, false);
public PreUser(User user, Biscuit biscuit) {
this(user, biscuit, false);
}
public PreUser(User user, boolean test) {
public PreUser(User user, Biscuit biscuit, boolean test) {
this.test = test;
this.user = user;
this.token = null;
this.biscuit = biscuit;
this.done = false;
this.timeLeft = PropertiesRetrieval.noCaptchaKickTime() + 1;
this.timeLeft = biscuit.getProperties().noCaptchaKickTime() + 1;
if(!test) {
users.add(this);
biscuit.addPreUser(this);
}
}
public Biscuit getBiscuit() {
return biscuit;
}
public User getUser() {
return this.user;
}
@ -70,7 +68,7 @@ public class PreUser {
}
public void genToken() {
Cage cage = Main.getBiscuit().getCage();
Cage cage = biscuit.getCage();
token = cage.getTokenGenerator().next();
}
@ -89,15 +87,18 @@ public class PreUser {
}
if(!done) {
if(PropertiesRetrieval.noCaptchaKick()) {
if(biscuit.getProperties().noCaptchaKick()) {
timeLeft = timeLeft - 1;
if(timeLeft <= 0) {
for(Guild g : getGuilds()) {
Main.log.info(user.getName() + " " + user.getAsMention() + " waited too long to complete the captcha. Kicking...");
Main.getBiscuit().captchaLog("``" + user.getName() +"`` " + user.getAsMention() + " waited too long to complete the captcha! Kicking...");
g.kick(user.getId()).queue();
remove();
Member m = biscuit.getGuild().getMember(user);
biscuit.log(user.getName() + " " + user.getAsMention() + " waited too long to complete the captcha. Kicking...");
biscuit.captchaLog("``" + user.getName() +"`` " + user.getAsMention() + " waited too long to complete the captcha! Kicking...");
if(biscuit.getGuild().getMember(user).getRoles().size() == 1 && PermUtil.hasDefaultRole(m) && !PermUtil.hasRewardRole(m)) {
biscuit.getGuild().kick(user.getId()).queue();
}
remove();
}
}
}
@ -105,7 +106,7 @@ public class PreUser {
}
public boolean shareGuild() {
JDA jda = Main.getBiscuit().getJDA();
JDA jda = biscuit.getJDA();
for(Guild g : jda.getGuilds()) {
if(g.isMember(user)){
return true;
@ -116,7 +117,7 @@ public class PreUser {
public ArrayList<Guild> getGuilds(){
ArrayList<Guild> guilds = new ArrayList<Guild>();
JDA jda = Main.getBiscuit().getJDA();
JDA jda = biscuit.getJDA();
for(Guild g : jda.getGuilds()) {
if(g.isMember(user)){
guilds.add(g);
@ -127,7 +128,7 @@ public class PreUser {
public void remove() {
setDone();
Main.log.info("Removing captcha data for user " + user.getName() + " " + user.getAsMention());
biscuit.log("Removing captcha data for user " + user.getName() + " " + user.getAsMention());
File captcha;
if(!Main.isPlugin) {
captcha = new File("captcha/" + user.getId() + ".jpg");
@ -136,7 +137,7 @@ public class PreUser {
}
token = null;
captcha.delete();
users.remove(this);
biscuit.removePreUser(this);
testusers.remove(this);
}

View File

@ -1,7 +1,7 @@
package com.fpghoti.biscuit.util;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.fpghoti.biscuit.logging.BColor;
import com.vdurmont.emoji.EmojiParser;
import net.dv8tion.jda.api.entities.Emote;
@ -16,6 +16,7 @@ public class ChatFilter {
}
public static boolean filter(MessageReceivedEvent event, boolean silent) {
Biscuit biscuit = Biscuit.getBiscuit(event.getGuild());
String msg = event.getMessage().getContentDisplay();
//Message removal priority occurs in this order
@ -23,10 +24,10 @@ public class ChatFilter {
boolean found = false;
//Naughty word check
boolean filter = (filter(msg));
boolean filter = (filter(biscuit, msg));
if(filter) {
if(!silent) {
Main.log.info("Removed Msg - REASON NAUGHTY WORD(S) - by " + event.getAuthor().getName() + ": " + msg);
biscuit.log(BColor.MAGENTA_BOLD + "Removed message from " + event.getAuthor().getName() + " for use of disallowed word(s).");
}
return true;
}
@ -35,7 +36,7 @@ public class ChatFilter {
for(Emote e : event.getMessage().getEmotes()) {
String name = e.getName();
for(String s : PropertiesRetrieval.blockedCustomEmotes()) {
for(String s : biscuit.getProperties().blockedCustomEmotes()) {
if(s.equals(name)) {
found = true;
}
@ -44,7 +45,7 @@ public class ChatFilter {
if(found) {
if(!silent) {
Main.log.info("Removed Msg - REASON BLOCKED CUSTOM EMOTE(S) - by " + event.getAuthor().getName() + ": " + msg);
biscuit.log(BColor.MAGENTA_BOLD + "Removed message from " + event.getAuthor().getName() + " for use of disallowed custom emote(s).");
}
return true;
}
@ -52,7 +53,7 @@ public class ChatFilter {
//Unicode emote check
for(String u : EmojiParser.extractEmojis(msg)) {
u = EmojiParser.parseToAliases(u).replace(":","");
for(String s : PropertiesRetrieval.blockedUnicodeEmotes()) {
for(String s : biscuit.getProperties().blockedUnicodeEmotes()) {
if(s.equalsIgnoreCase(u)) {
found = true;
}
@ -61,7 +62,7 @@ public class ChatFilter {
if(found) {
if(!silent) {
Main.log.info("Removed Msg - REASON BLOCKED UNICODE EMOTE(S) - by " + event.getAuthor().getName() + ": " + msg);
biscuit.log(BColor.MAGENTA_BOLD + "Removed message from " + event.getAuthor().getName() + " for use of disallowed unicode emote(s).");
}
return true;
}
@ -69,32 +70,32 @@ public class ChatFilter {
return false;
}
public static boolean filter(String sentence){
public static boolean filter(Biscuit biscuit, String sentence){
for(String s : sentence.split(" ")){
if(filterWord(s)){
if(filterWord(biscuit, s)){
return true;
}
}
return false;
}
public static boolean filterWord(String word) {
String[] match = findMatchPair(word);
public static boolean filterWord(Biscuit biscuit, String word) {
String[] match = findMatchPair(biscuit, word);
if(match != null) {
return true;
}
return false;
}
public static String findMatch(String word) {
String[] match = findMatchPair(word);
public static String findMatch(Biscuit biscuit, String word) {
String[] match = findMatchPair(biscuit, word);
if(match == null || match[0] == null) {
return null;
}
return match[0];
}
public static String[] findMatchPair(String word) {
public static String[] findMatchPair(Biscuit biscuit, String word) {
String cleaned = "";
word = word.toLowerCase();
if(word.length() >= 2 && word.charAt(word.length() -1) == '!'){
@ -117,7 +118,7 @@ public class ChatFilter {
return null;
}
String[] wordSuf = {null,null};
for(String item : PropertiesRetrieval.getNaughtyWords()) {
for(String item : biscuit.getProperties().getNaughtyWords()) {
if(cleaned.equalsIgnoreCase(item)){
wordSuf[0] = item;
return wordSuf;

View File

@ -1,7 +1,6 @@
package com.fpghoti.biscuit.util;
import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.biscuit.Biscuit;
import com.jcabi.aspects.Async;
import net.dv8tion.jda.api.Permission;
@ -11,11 +10,12 @@ import net.dv8tion.jda.api.entities.Role;
public class PermUtil {
public static boolean isAdmin(Member member){
Biscuit biscuit = Biscuit.getBiscuit(member.getGuild());
if(member.hasPermission(Permission.ADMINISTRATOR)){
return true;
}else{
for(Role role : member.getRoles()){
if(role.getName().equalsIgnoreCase(PropertiesRetrieval.getAdminRole())){
if(role.getName().equalsIgnoreCase(biscuit.getProperties().getAdminRole())){
return true;
}
}
@ -24,11 +24,12 @@ public class PermUtil {
}
public static boolean isMod(Member member){
Biscuit biscuit = Biscuit.getBiscuit(member.getGuild());
if(isAdmin(member)){
return true;
}else{
for(Role role : member.getRoles()){
if(role.getName().equalsIgnoreCase(PropertiesRetrieval.getModRole())){
if(role.getName().equalsIgnoreCase(biscuit.getProperties().getModRole())){
return true;
}
}
@ -58,10 +59,11 @@ public class PermUtil {
}
public static boolean isBooster(Member member) {
Biscuit biscuit = Biscuit.getBiscuit(member.getGuild());
if(isAdmin(member)) {
return true;
}
for(String r : PropertiesRetrieval.getBoosterRoles()) {
for(String r : biscuit.getProperties().getBoosterRoles()) {
if(hasRole(member,r)) {
return true;
}
@ -70,16 +72,38 @@ public class PermUtil {
}
public static boolean isBoosterExclusive(Role r) {
return Util.containsIgnoreCase(PropertiesRetrieval.getBoostExclusiveRoles(),r.getName());
Biscuit biscuit = Biscuit.getBiscuit(r.getGuild());
return Util.containsIgnoreCase(biscuit.getProperties().getBoostExclusiveRoles(),r.getName());
}
public static boolean hasDefaultRole(Member m) {
Biscuit biscuit = Biscuit.getBiscuit(m.getGuild());
for(Role r : biscuit.getGuild().getRoles()) {
if(r.getName().equalsIgnoreCase(biscuit.getProperties().getDefaultRole())){
return hasRole(m,r);
}
}
return false;
}
public static boolean hasRewardRole(Member m) {
Biscuit biscuit = Biscuit.getBiscuit(m.getGuild());
for(Role r : biscuit.getGuild().getRoles()) {
if(r.getName().equalsIgnoreCase(biscuit.getProperties().getCaptchaReward())){
return hasRole(m,r);
}
}
return false;
}
@Async
public static void clearUndeservedRoles(Member m) {
boolean booster = isBooster(m);
Biscuit b = Biscuit.getBiscuit(m.getGuild());
for(Role r : m.getRoles()) {
if(!booster && isBoosterExclusive(r)) {
m.getGuild().removeRoleFromMember(m,r).queue();
Main.log.info("BOOST ROLE REMOVED - Member: " + m.getUser().getName() + " (" + m.getId() + ") Role: " + r.getName());
b.log("Booster role removed from " + m.getUser().getName() + " (" + m.getId() + ") Role: " + r.getName());
}
}
}

View File

@ -2,7 +2,7 @@ package com.fpghoti.biscuit.util;
import java.util.Random;
import com.fpghoti.biscuit.config.ConfigRetrieval;
import com.fpghoti.biscuit.biscuit.Biscuit;
import net.dv8tion.jda.api.entities.TextChannel;
@ -16,11 +16,9 @@ public class Util {
}
public static Boolean isLoggable(TextChannel c) {
if(c == null) {
return true;
}
Biscuit biscuit = Biscuit.getBiscuit(c.getGuild());
Boolean a = true;
for(String s: ConfigRetrieval.getFromConfig("Channels-To-Not-Chatlog").split(",")) {
for(String s: biscuit.getProperties().getDontLogChannels()) {
if(c.getName().equalsIgnoreCase(s)) {
a = false;
}

View File

@ -1,3 +1,6 @@
#This doesn't do anything, but is set by the program to help users identify the guild associated with the file
Guild-Identifier = Main Config
#Change this to redefine the main command signifier character/String
Command-Signifier = -

View File

@ -0,0 +1 @@
version=${project.version}

View File

@ -1,7 +1,13 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<property scope="context" name="COLORIZER_COLORS"
value="boldred@,boldyellow@,boldcyan@,boldmagenta@,boldwhite@" />
<conversionRule conversionWord="colorize"
converterClass="org.tuxdude.logback.extensions.LogColorizer" />
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%date] %level - %msg%n</pattern>
<pattern>%colorize([%date{MM/dd/yyyy HH:mm:ss}] %level) - %msg%n</pattern>
</encoder>
</appender>
@ -10,22 +16,28 @@
<appender name="FILE-AUDIT"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${DEV_HOME}/chatlog.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
<pattern>[%date] %level - %msg%n</pattern>
<pattern>[%date{MM/dd/yyyy HH:mm:ss}] %level - %msg%n</pattern>
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${DEV_HOME}/archived/chatlog.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<rollingPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${DEV_HOME}/archived/chatlog.%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<maxFileSize>450kb</maxFileSize>
</rollingPolicy>
</appender>
<root level="INFO">
<logger level="INFO" name="Biscuit">
<appender-ref ref="STDOUT" />
</logger>
<logger level="INFO" name="B-File">
<appender-ref ref="FILE-AUDIT" />
</root>
</logger>
</configuration>