Fixed database query and changed to only unban bans that were with the same reason as the auto ban

This commit is contained in:
Teriuihi 2022-02-03 01:15:30 +01:00
parent 16996e95e2
commit 2d05ec61af
4 changed files with 50 additions and 40 deletions

View File

@ -38,34 +38,36 @@ dependencies {
annotationProcessor("com.velocitypowered:velocity-api:1.1.5")
// JDA
implementation("net.dv8tion:JDA:5.0.0-alpha.3") {
exclude("opus-java") // exclude audio
}
compileOnly("com.gitlab.ruany:LitebansAPI:0.3.5")
// LuckPerms
compileOnly("net.luckperms:api:5.3")
// MySQL
runtimeOnly("mysql:mysql-connector-java:8.0.23")
// ShutdownInfo
compileOnly("com.alttd:ShutdownInfo:1.0")
}
tasks {
shadowJar {
archiveFileName.set("${project.name}-${project.version}.jar")
exclude("net.kyori.adventure")
exclude("net.kyori.examination")
minimize {
//exclude(dependency("net.kyori:.*:.*"))
shadow("net.dv8tion:JDA:5.0.0-alpha.3") {
exclude("opus-java") // exclude audio
}
listOf(
compileOnly("com.gitlab.ruany:LitebansAPI:0.3.5")
// LuckPerms
compileOnly("net.luckperms:api:5.3")
// MySQL
runtimeOnly("mysql:mysql-connector-java:8.0.23")
// ShutdownInfo
compileOnly("com.alttd:ShutdownInfo:1.0")
}
tasks {
shadowJar {
archiveFileName.set("${project.name}-${project.version}.jar")
exclude("net.kyori.adventure")
exclude("net.kyori.examination")
minimize {
//exclude(dependency("net.kyori:.*:.*"))
}
listOf(
// "net.kyori",
"net.dv8tion.jda"
).forEach { relocate(it, "${rootProject.group}.lib.$it") }
}
"net.dv8tion.jda"
).forEach { relocate(it, "${rootProject.group}.lib.$it") }
}
build {
dependsOn(shadowJar)
}
build {
dependsOn(shadowJar)
}
}
}
}

View File

@ -4,21 +4,19 @@ dependencyResolutionManagement {
repositories {
mavenCentral()
// Altitude
// maven {
// name = "maven"
// url = uri("http://leo:8081/")
// isAllowInsecureProtocol = true
// //credentials(PasswordCredentials::class)
// }
maven("https://jitpack.io")
maven {
name = "maven"
url = uri("https://repo.destro.xyz/snapshots")
credentials(PasswordCredentials::class)
}
// Velocity
maven("https://nexus.velocitypowered.com/repository/maven-public/")
// JDA
maven("https://m2.dv8tion.net/releases/")
// MiniMessage
maven("https://oss.sonatype.org/content/repositories/snapshots/")
// Local maven repo .m2
mavenLocal()
// LiteBans
maven("https://jitpack.io")
}
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
}

View File

@ -19,6 +19,7 @@ import net.dv8tion.jda.api.utils.MemberCachePolicy;
import org.jetbrains.annotations.Nullable;
import javax.security.auth.login.LoginException;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
public class Bot {
@ -193,10 +194,16 @@ public class Bot {
ALogger.warn("I can't unban members in " + guild.getName() + ".");
return;
}
guild.retrieveBanList().queue(bans -> bans.stream()
.filter(ban -> ban.getUser().getIdLong() == userId)
.findFirst()
.ifPresent(bans::remove));
guild.retrieveBanList().queue(bans -> {
Optional<Guild.Ban> first = bans.stream()
.filter(ban -> ban.getUser().getIdLong() == userId)
.findFirst();
if (first.isEmpty())
return;
Guild.Ban ban = first.get();
if (ban.getReason() != null && ban.getReason().equals("Auto ban due to Minecraft ban"))
bans.remove(ban);
});
}
public void discordBan(long guildId, long userId, @Nullable String optionalReason) {

View File

@ -262,6 +262,9 @@ public class Database {
try {
PreparedStatement statement = DatabaseConnection.getConnection().prepareStatement(sql);
statement.setInt(1, active ? 1 : 0);
statement.setString(2, uuid.toString());
statement.executeUpdate();
} catch (SQLException exception) {
exception.printStackTrace();
}