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