Improve Captcha readability

This commit is contained in:
2020-05-31 22:33:34 -05:00
parent d686d70bd4
commit 13a1480d36
8 changed files with 168 additions and 69 deletions

View File

@@ -8,6 +8,7 @@ import com.fpghoti.biscuit.Main;
import com.fpghoti.biscuit.PluginCore;
import com.fpghoti.biscuit.config.PropertiesRetrieval;
import com.fpghoti.biscuit.util.Util;
import com.github.cage.Cage;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
@@ -15,8 +16,18 @@ 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;
}
}
return null;
}
public static PreUser getPreUser(User user) {
for(PreUser u : users) {
if(u.getUser().getId().equals(user.getId())) {
@@ -34,13 +45,21 @@ public class PreUser {
private String token;
private int timeLeft;
private boolean done;
private boolean test;
public PreUser(User user) {
this(user, false);
}
public PreUser(User user, boolean test) {
this.test = test;
this.user = user;
this.token = null;
this.done = false;
this.timeLeft = PropertiesRetrieval.noCaptchaKickTime() + 1;
users.add(this);
if(!test) {
users.add(this);
}
}
public User getUser() {
@@ -51,10 +70,9 @@ public class PreUser {
return this.token;
}
//Going to use custom string gen for more char types in captcha
public void genToken() {
//token = Main.getBiscuit().getCage().getTokenGenerator().next();
token = Util.randomString(6);
Cage cage = Main.getBiscuit().getCage();
token = cage.getTokenGenerator().next();
}
public void setDone() {
@@ -66,6 +84,10 @@ public class PreUser {
remove();
return;
}
if(test) {
return;
}
if(!done) {
if(PropertiesRetrieval.noCaptchaKick()) {
@@ -115,6 +137,7 @@ public class PreUser {
token = null;
captcha.delete();
users.remove(this);
testusers.remove(this);
}
}