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>
<groupId>com.fpghoti</groupId>
<artifactId>Biscuit</artifactId>
<version>1.6.1</version>
<version>1.6.2</version>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>

View File

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

View File

@ -46,9 +46,6 @@ import com.fpghoti.biscuit.listener.ReactionListener;
import com.fpghoti.biscuit.listener.RoleListener;
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.SoftMuteTimer;
import ch.qos.logback.core.rolling.RollingFileAppender;
import ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy;
@ -100,13 +97,7 @@ public class Main {
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);
Biscuit.loadGuild(g);
}
startCommandListener();

View File

@ -40,7 +40,7 @@ public class Biscuit {
}
return null;
}
public static Biscuit getBiscuit(String guildcode) {
for(Biscuit b : Main.getBiscuits()) {
if(b.getProperties().getGuildCode().equalsIgnoreCase(guildcode)) {
@ -49,7 +49,7 @@ public class Biscuit {
}
return null;
}
public static ArrayList<PreUser> getPreUsers(User u) {
ArrayList<PreUser> pres = new ArrayList<PreUser>();
for(Guild g : Main.getJDA().getGuilds()) {
@ -62,13 +62,12 @@ public class Biscuit {
}
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;
@ -88,6 +87,7 @@ public class Biscuit {
private BiscuitMessageStore messageStore;
private CopyOnWriteArrayList<PreUser> users = new CopyOnWriteArrayList<PreUser>();
private HashMap<Member, Role> rolequeue;
public Biscuit(JDA jda, Guild guild, BiscuitLog log) {
this.jda = jda;
@ -98,7 +98,7 @@ public class Biscuit {
this.config = new BiscuitConfig(this);
config.generateConfig();
this.properties = new BiscuitProperties(this);
this.rolequeue = new HashMap<Member, Role>();
timer = new Timer();
timers = new ArrayList<BiscuitTimer>();
if(!Main.isPlugin) {
@ -137,7 +137,7 @@ public class Biscuit {
public Guild getGuild() {
return guild;
}
public boolean canManageServer() {
return guild.getSelfMember().hasPermission(Permission.MANAGE_SERVER);
}
@ -314,6 +314,10 @@ public class Biscuit {
}
}
public HashMap<Member, Role> getRoleQueue() {
return rolequeue;
}
public void remove() {
log("Removing guild biscuit...");
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("Check-Join-Invite", "false", 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(code != null) {

View File

@ -49,6 +49,14 @@ public class BiscuitProperties {
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(){
String key = "Captcha";
if(biscuit.getConfig().getFromConfig(key, biscuit).equalsIgnoreCase("[global]") && biscuit.getGuild() != null) {
@ -67,6 +75,15 @@ public class BiscuitProperties {
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(){
String key = "Captcha-Reward-Role";
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());
g.addRoleToMember(member, newrole).queue();
g.addRoleToMember(member, newrole).complete();
g.removeRoleFromMember(member, defaultrole).complete();
p.remove();
}

View File

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

View File

@ -15,12 +15,16 @@ public class LeaveListener extends ListenerAdapter {
Biscuit biscuit = Biscuit.getBiscuit(event.getGuild());
User user = event.getMember().getUser();
PreUser u = biscuit.getPreUser(user);
int time = u.getTimeLeft();
u.remove();
int time = 1;
if(u != null) {
time = u.getTimeLeft();
u.remove();
}
if(time > 0) {
biscuit.log(BColor.YELLOW + "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 + " ";
}
for(Attachment a : event.getMessage().getAttachments()) {
tail = tail + msg + " " + a.getUrl();
tail = tail + " " + a.getUrl();
}
msg = msg + tail;
}

View File

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

View File

@ -75,7 +75,7 @@ public class PreUser {
public void setDone() {
this.done = true;
}
public int getTimeLeft() {
return timeLeft;
}
@ -97,9 +97,20 @@ public class PreUser {
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(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();

View File

@ -91,6 +91,14 @@ LogCaptcha = false
#Put the name of the text channel you want to log captcha information to.
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.
#Example - Custom-Command-Names = hello,botcheck,apple
Custom-Command-Names =