Fixed Spigot double logging and Kick message

This commit is contained in:
Ghoti 2020-07-16 19:36:49 -05:00
parent 5dc66effca
commit 7fbe35b83b
13 changed files with 80 additions and 31 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.fpghoti</groupId> <groupId>com.fpghoti</groupId>
<artifactId>Biscuit</artifactId> <artifactId>Biscuit</artifactId>
<version>1.6.1</version> <version>1.6.2</version>
<build> <build>
<sourceDirectory>src/main/java</sourceDirectory> <sourceDirectory>src/main/java</sourceDirectory>
<resources> <resources>

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.fpghoti</groupId> <groupId>com.fpghoti</groupId>
<artifactId>Biscuit</artifactId> <artifactId>Biscuit</artifactId>
<version>1.6.1</version> <version>1.6.2</version>
<build> <build>
<sourceDirectory>src/main/java</sourceDirectory> <sourceDirectory>src/main/java</sourceDirectory>
<resources> <resources>

View File

@ -46,9 +46,6 @@ import com.fpghoti.biscuit.listener.ReactionListener;
import com.fpghoti.biscuit.listener.RoleListener; import com.fpghoti.biscuit.listener.RoleListener;
import com.fpghoti.biscuit.logging.BColor; import com.fpghoti.biscuit.logging.BColor;
import com.fpghoti.biscuit.logging.BiscuitLog; 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.SoftMuteTimer;
import ch.qos.logback.core.rolling.RollingFileAppender; import ch.qos.logback.core.rolling.RollingFileAppender;
import ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy; import ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy;
@ -100,13 +97,7 @@ public class Main {
jda.addEventListener(new RoleListener()); jda.addEventListener(new RoleListener());
biscuits = new ArrayList<Biscuit>(); biscuits = new ArrayList<Biscuit>();
for(Guild g : jda.getGuilds()) { for(Guild g : jda.getGuilds()) {
Biscuit biscuit = new Biscuit(jda, g, log); Biscuit.loadGuild(g);
biscuit.addTimer(new ChatCountTimer(biscuit));
biscuit.addTimer(new SoftMuteTimer(biscuit));
biscuit.addTimer(new DecrementTimer(biscuit));
biscuit.loadTimers();
biscuits.add(biscuit);
} }
startCommandListener(); startCommandListener();

View File

@ -68,7 +68,6 @@ public class Biscuit {
biscuit.addTimer(new ChatCountTimer(biscuit)); biscuit.addTimer(new ChatCountTimer(biscuit));
biscuit.addTimer(new SoftMuteTimer(biscuit)); biscuit.addTimer(new SoftMuteTimer(biscuit));
biscuit.addTimer(new DecrementTimer(biscuit)); biscuit.addTimer(new DecrementTimer(biscuit));
biscuit.loadTimers(); biscuit.loadTimers();
Main.registerBiscuit(biscuit); Main.registerBiscuit(biscuit);
return biscuit; return biscuit;
@ -88,6 +87,7 @@ public class Biscuit {
private BiscuitMessageStore messageStore; private BiscuitMessageStore messageStore;
private CopyOnWriteArrayList<PreUser> users = new CopyOnWriteArrayList<PreUser>(); private CopyOnWriteArrayList<PreUser> users = new CopyOnWriteArrayList<PreUser>();
private HashMap<Member, Role> rolequeue;
public Biscuit(JDA jda, Guild guild, BiscuitLog log) { public Biscuit(JDA jda, Guild guild, BiscuitLog log) {
this.jda = jda; this.jda = jda;
@ -98,7 +98,7 @@ public class Biscuit {
this.config = new BiscuitConfig(this); this.config = new BiscuitConfig(this);
config.generateConfig(); config.generateConfig();
this.properties = new BiscuitProperties(this); this.properties = new BiscuitProperties(this);
this.rolequeue = new HashMap<Member, Role>();
timer = new Timer(); timer = new Timer();
timers = new ArrayList<BiscuitTimer>(); timers = new ArrayList<BiscuitTimer>();
if(!Main.isPlugin) { if(!Main.isPlugin) {
@ -314,6 +314,10 @@ public class Biscuit {
} }
} }
public HashMap<Member, Role> getRoleQueue() {
return rolequeue;
}
public void remove() { public void remove() {
log("Removing guild biscuit..."); log("Removing guild biscuit...");
for(BiscuitTimer t : timers) { for(BiscuitTimer t : timers) {

View File

@ -173,6 +173,8 @@ public class BiscuitConfig {
added = addProperty("Captcha-Log-Channel", "verify-log", prop, added, silent); added = addProperty("Captcha-Log-Channel", "verify-log", prop, added, silent);
added = addProperty("Check-Join-Invite", "false", prop, added, silent); added = addProperty("Check-Join-Invite", "false", prop, added, silent);
added = addProperty("Custom-Command-Names", "", prop, added, silent); added = addProperty("Custom-Command-Names", "", prop, added, silent);
added = addProperty("DM-Before-Kick", "true", prop, added, silent);
added = addProperty("Kick-DM-Invite", "", prop, added, silent);
if(!isMain) { if(!isMain) {
if(code != null) { if(code != null) {

View File

@ -49,6 +49,14 @@ public class BiscuitProperties {
return biscuit.getConfig().getFromConfig(key, biscuit); return biscuit.getConfig().getFromConfig(key, biscuit);
} }
public String getKickDMInvite(){
String key = "Kick-DM-Invite";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().getKickDMInvite();
}
return biscuit.getConfig().getFromConfig(key, biscuit);
}
public boolean captchaEnabled(){ public boolean captchaEnabled(){
String key = "Captcha"; String key = "Captcha";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) { if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
@ -67,6 +75,15 @@ public class BiscuitProperties {
return value.equalsIgnoreCase("true"); return value.equalsIgnoreCase("true");
} }
public boolean dmBeforeKick(){
String key = "DM-Before-Kick";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
return Main.getMainBiscuit().getProperties().dmBeforeKick();
}
String value = biscuit.getConfig().getFromConfig(key, biscuit);
return value.equalsIgnoreCase("true");
}
public String getCaptchaReward(){ public String getCaptchaReward(){
String key = "Captcha-Reward-Role"; String key = "Captcha-Reward-Role";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) { if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {

View File

@ -176,7 +176,7 @@ public class DMListener extends ListenerAdapter{
Member member = g.getMemberById(author.getId()); Member member = g.getMemberById(author.getId());
g.addRoleToMember(member, newrole).queue(); g.addRoleToMember(member, newrole).complete();
g.removeRoleFromMember(member, defaultrole).complete(); g.removeRoleFromMember(member, defaultrole).complete();
p.remove(); p.remove();
} }

View File

@ -55,7 +55,7 @@ public class JoinListener extends ListenerAdapter {
@Async @Async
private void logUserInvite(final User user, final Biscuit b){ private void logUserInvite(final User user, final Biscuit b){
Guild g = b.getGuild(); Guild g = b.getGuild();
g.retrieveInvites().queue((invs) -> { g.retrieveInvites().queue(invs -> {
String usedInv = "Other"; String usedInv = "Other";
HashMap<String, Integer> newinv = new HashMap<String, Integer>(); HashMap<String, Integer> newinv = new HashMap<String, Integer>();
boolean empty = b.getInviteUses().isEmpty(); boolean empty = b.getInviteUses().isEmpty();

View File

@ -15,12 +15,16 @@ public class LeaveListener extends ListenerAdapter {
Biscuit biscuit = Biscuit.getBiscuit(event.getGuild()); Biscuit biscuit = Biscuit.getBiscuit(event.getGuild());
User user = event.getMember().getUser(); User user = event.getMember().getUser();
PreUser u = biscuit.getPreUser(user); PreUser u = biscuit.getPreUser(user);
int time = u.getTimeLeft(); int time = 1;
if(u != null) {
time = u.getTimeLeft();
u.remove(); u.remove();
}
if(time > 0) { if(time > 0) {
biscuit.log(BColor.YELLOW + "USER LEFT: " + user.getName() + " " + user.getAsMention()); biscuit.log(BColor.YELLOW + "USER LEFT: " + user.getName() + " " + user.getAsMention());
biscuit.captchaLog("**User Left: ** ``" + user.getName() + "`` " + user.getAsMention() + "``"); biscuit.captchaLog("**User Left: ** ``" + user.getName() + "`` " + user.getAsMention() + "``");
} }
} }
} }

View File

@ -65,7 +65,7 @@ public class MessageReceiveListener extends ListenerAdapter{
msg = msg + " "; msg = msg + " ";
} }
for(Attachment a : event.getMessage().getAttachments()) { for(Attachment a : event.getMessage().getAttachments()) {
tail = tail + msg + " " + a.getUrl(); tail = tail + " " + a.getUrl();
} }
msg = msg + tail; msg = msg + tail;
} }

View File

@ -3,6 +3,8 @@ package com.fpghoti.biscuit.logging;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.fpghoti.biscuit.Main;
public class BiscuitLog { public class BiscuitLog {
private final Logger console = LoggerFactory.getLogger("Biscuit"); private final Logger console = LoggerFactory.getLogger("Biscuit");
@ -10,27 +12,37 @@ public class BiscuitLog {
public void debug(String msg) { public void debug(String msg) {
console.debug(BColor.MAGENTA_BOLD + msg + BColor.RESET); console.debug(BColor.MAGENTA_BOLD + msg + BColor.RESET);
if(!Main.isPlugin) {
file.debug(BColor.clear(msg)); file.debug(BColor.clear(msg));
} }
}
public void error(String msg) { public void error(String msg) {
console.error(BColor.RED + msg + BColor.RESET); console.error(BColor.RED + msg + BColor.RESET);
if(!Main.isPlugin) {
file.error(BColor.clear(msg)); file.error(BColor.clear(msg));
} }
}
public void info(String msg) { public void info(String msg) {
console.info(msg + BColor.RESET); console.info(msg + BColor.RESET);
if(!Main.isPlugin) {
file.info(BColor.clear(msg)); file.info(BColor.clear(msg));
} }
}
public void trace(String msg) { public void trace(String msg) {
console.trace(BColor.WHITE_BOLD + msg + BColor.RESET); console.trace(BColor.WHITE_BOLD + msg + BColor.RESET);
if(!Main.isPlugin) {
file.trace(BColor.clear(msg)); file.trace(BColor.clear(msg));
} }
}
public void warn(String msg) { public void warn(String msg) {
console.warn(BColor.YELLOW + msg + BColor.RESET); console.warn(BColor.YELLOW + msg + BColor.RESET);
if(!Main.isPlugin) {
file.warn(BColor.clear(msg)); file.warn(BColor.clear(msg));
} }
}
} }

View File

@ -99,7 +99,18 @@ public class PreUser {
biscuit.captchaLog("``" + 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(m != null && m.getRoles().size() == 1 && PermUtil.hasDefaultRole(m) && !PermUtil.hasRewardRole(m)) { if(m != null && m.getRoles().size() == 1 && PermUtil.hasDefaultRole(m) && !PermUtil.hasRewardRole(m)) {
biscuit.getGuild().kick(user.getId()).queue(); if(biscuit.getProperties().dmBeforeKick()) {
String msg = "You did not complete the captcha in **"
+ " " + biscuit.getGuild().getName() + "**! If you believe this is a mistake, rejoin the server"
+ ", complete the captcha, and inform an administrator.";
String invite = biscuit.getProperties().getKickDMInvite().replace(" ", "");
if(!invite.equals("")) {
msg = msg + " " + invite;
}
final String fmsg = msg;
user.openPrivateChannel().flatMap(channel -> channel.sendMessage(fmsg)).complete();
}
biscuit.getGuild().kick(user.getId()).submit();
} }
remove(); remove();

View File

@ -91,6 +91,14 @@ LogCaptcha = false
#Put the name of the text channel you want to log captcha information to. #Put the name of the text channel you want to log captcha information to.
Captcha-Log-Channel = verify-log Captcha-Log-Channel = verify-log
#DM the user before kicking for captcha.
DM-Before-Kick = true
#Send an invite to the server when dm-ing kicked users
#Does nothing when blank
#Use full link
Kick-DM-Invite =
#List your custom commands here. This line will always generate blank. #List your custom commands here. This line will always generate blank.
#Example - Custom-Command-Names = hello,botcheck,apple #Example - Custom-Command-Names = hello,botcheck,apple
Custom-Command-Names = Custom-Command-Names =