Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPowerGamerBR committed Dec 14, 2023
1 parent 09ac234 commit d9474d9
Show file tree
Hide file tree
Showing 32 changed files with 162 additions and 416 deletions.
53 changes: 14 additions & 39 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
kotlin("jvm") version "1.5.31"
kotlin("plugin.serialization") version "1.5.31"
kotlin("jvm") version "1.9.10"
kotlin("plugin.serialization") version "1.9.10"
id("com.google.cloud.tools.jib") version "3.1.4"
}

Expand All @@ -17,31 +17,21 @@ repositories {

dependencies {
implementation(kotlin("stdlib"))
implementation("net.dv8tion:JDA:5.0.0-alpha.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.3.0")
implementation("org.jetbrains.exposed:exposed-core:0.31.1")
implementation("org.jetbrains.exposed:exposed-jdbc:0.31.1")
implementation("org.jetbrains.exposed:exposed-dao:0.31.1")
implementation("org.jetbrains.exposed:exposed-java-time:0.31.1")
implementation("org.xerial:sqlite-jdbc:3.34.0")
implementation("net.dv8tion:JDA:5.0.0-beta.18")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.6.2")
implementation("org.jetbrains.exposed:exposed-core:0.45.0")
implementation("org.jetbrains.exposed:exposed-jdbc:0.45.0")
implementation("org.jetbrains.exposed:exposed-dao:0.45.0")
implementation("org.jetbrains.exposed:exposed-java-time:0.45.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.5.2")
implementation("org.postgresql:postgresql:42.2.24")
implementation("com.zaxxer:HikariCP:5.0.0")
implementation("io.ktor:ktor-server-netty:1.6.5")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.1")

// Kord
// implementation("dev.kord:kord-gateway:0.8.x-SNAPSHOT")
// implementation("dev.kord:kord-rest:0.8.x-SNAPSHOT")

// Discord InteraKTions
// implementation("net.perfectdreams.discordinteraktions:gateway-kord:0.0.10-SNAPSHOT")
implementation("org.postgresql:postgresql:42.7.1")
implementation("com.zaxxer:HikariCP:5.1.0")
implementation("io.ktor:ktor-server-netty:2.3.7")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.5.0")

api("io.github.microutils:kotlin-logging:2.0.6")
// Async Appender is broken in alpha5
// https://stackoverflow.com/questions/58742485/logback-error-no-attached-appenders-found
api("ch.qos.logback:logback-classic:1.3.0-alpha4")
api("ch.qos.logback:logback-classic:1.4.14")
}

jib {
Expand All @@ -57,19 +47,4 @@ jib {
from {
image = "eclipse-temurin:17-jdk-alpine"
}
}

tasks {
val runnableJar = runnableJarTask(
DEFAULT_SHADED_WITHIN_JAR_LIBRARIES,
configurations.runtimeClasspath.get(),
jar.get(),
"net.perfectdreams.floppapower.FloppaPowerLauncher",
mapOf()
)

"build" {
// This should be ran BEFORE the JAR is compiled!
dependsOn(runnableJar)
}
}
7 changes: 0 additions & 7 deletions buildSrc/build.gradle.kts

This file was deleted.

93 changes: 0 additions & 93 deletions buildSrc/src/main/kotlin/RunnableJarTask.kt

This file was deleted.

47 changes: 18 additions & 29 deletions src/main/kotlin/net/perfectdreams/floppapower/FloppaPower.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.sync.withPermit
import mu.KotlinLogging
import net.dv8tion.jda.api.JDA
import net.dv8tion.jda.api.MessageBuilder
import net.dv8tion.jda.api.OnlineStatus
import net.dv8tion.jda.api.Permission
import net.dv8tion.jda.api.entities.Guild
import net.dv8tion.jda.api.entities.Member
import net.dv8tion.jda.api.entities.UserSnowflake
import net.dv8tion.jda.api.interactions.commands.OptionType
import net.dv8tion.jda.api.interactions.commands.build.CommandData
import net.dv8tion.jda.api.interactions.commands.build.OptionData
Expand All @@ -21,6 +21,7 @@ import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder
import net.dv8tion.jda.api.sharding.ShardManager
import net.dv8tion.jda.api.utils.ChunkingFilter
import net.dv8tion.jda.api.utils.MemberCachePolicy
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder
import net.perfectdreams.floppapower.dao.BlockedAvatarHash
import net.perfectdreams.floppapower.dao.BlockedAvatarHashBanEntry
import net.perfectdreams.floppapower.dao.BlockedUser
Expand All @@ -41,12 +42,8 @@ import net.perfectdreams.floppapower.tables.UsersApprovals
import net.perfectdreams.floppapower.utils.CheckedDueToType
import net.perfectdreams.floppapower.utils.Constants
import net.perfectdreams.floppapower.utils.FloppaButtonClickEvent
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.DEFAULT_REPETITION_ATTEMPTS
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.inList
import org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManager
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
import org.jetbrains.exposed.sql.transactions.transaction
Expand All @@ -56,6 +53,7 @@ import java.util.*
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentLinkedQueue
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import kotlin.concurrent.thread
import kotlin.system.exitProcess

Expand All @@ -68,9 +66,6 @@ class FloppaPower {
IsolationLevel.TRANSACTION_REPEATABLE_READ // We use repeatable read to avoid dirty and non-repeatable reads! Very useful and safe!!
}

val sqLiteDatabaseFile = File("floppa.db")
val sqliteDatabase = Database.connect("jdbc:sqlite:${sqLiteDatabaseFile.toPath()}", driver = "org.sqlite.JDBC")

val database = initPostgreSQL(
System.getenv("FLOPPA_DATABASE_ADDRESS"),
System.getenv("FLOPPA_DATABASE_NAME"),
Expand Down Expand Up @@ -98,16 +93,11 @@ class FloppaPower {
)
}

if (System.getenv("FLOPPA_MIGRATE_DATABASE") == "true") {
MigrationTool.migrate(database, sqliteDatabase)
exitProcess(0)
}

val shardManager = DefaultShardManagerBuilder.createDefault(
System.getenv("FLOPPA_DISCORD_TOKEN"),
GatewayIntent.GUILD_MEMBERS,
GatewayIntent.GUILD_MESSAGES,
GatewayIntent.GUILD_BANS
GatewayIntent.GUILD_MODERATION
).setMemberCachePolicy(MemberCachePolicy.ALL) // we, want, EVERYTHING
.setChunkingFilter(ChunkingFilter.ALL) // EVERYTHING
.setStatus(OnlineStatus.INVISIBLE) // no one will ever know!
Expand Down Expand Up @@ -147,7 +137,7 @@ class FloppaPower {
try {
// Send the message if the content is not empty
val reportChannelId = shardManager.getTextChannelById(Constants.LOG_CHANNEL_ID) ?: continue
reportChannelId.sendMessage(MessageBuilder(builder.toString()).setAllowedMentions(listOf()).build()).queue()
reportChannelId.sendMessage(MessageCreateBuilder().setContent(builder.toString()).setAllowedMentions(listOf()).build()).queue()
} catch (e: Exception) {
e.printStackTrace()
}
Expand Down Expand Up @@ -182,8 +172,8 @@ class FloppaPower {
guild.ban(
member,
0,
"FloppaPower! Self Bot (ID) Report #${blockedUser.entry.id.value}"
).queue()
TimeUnit.SECONDS
).reason("FloppaPower! Self Bot (ID) Report #${blockedUser.entry.id.value}").queue()

log(
shardManager,
Expand Down Expand Up @@ -224,9 +214,8 @@ class FloppaPower {
guild.ban(
member,
0,
"FloppaPower! Self Bot (Avatar Hash) Report #${blockedAvatarHash.entry.id.value}"
)
.queue()
TimeUnit.SECONDS
).reason("FloppaPower! Self Bot (Avatar Hash) Report #${blockedAvatarHash.entry.id.value}").queue()

log(
shardManager,
Expand Down Expand Up @@ -286,7 +275,7 @@ class FloppaPower {
val userId = it[BlockedUserBanEntries.user]
if (guild.selfMember.hasPermission(Permission.BAN_MEMBERS)) {
// hmm where is the unban(Long)?
guild.unban(it[BlockedUserBanEntries.user].toString()).queue()
guild.unban(UserSnowflake.fromId(it[BlockedUserBanEntries.user])).queue()

log(
shardManager,
Expand Down Expand Up @@ -319,7 +308,7 @@ class FloppaPower {
val userId = it[BlockedAvatarHashesBanEntries.user]
if (guild.selfMember.hasPermission(Permission.BAN_MEMBERS)) {
// hmm where is the unban(Long)?
guild.unban(it[BlockedAvatarHashesBanEntries.user].toString()).queue()
guild.unban(UserSnowflake.fromId(it[BlockedAvatarHashesBanEntries.user])).queue()

log(
shardManager,
Expand Down Expand Up @@ -414,11 +403,11 @@ class FloppaPower {

private fun connectToDatabase(dataSource: HikariDataSource): Database =
Database.connect(
HikariDataSource(dataSource)
) {
HikariDataSource(dataSource),
// This code is the same callback used in the "Database.connect(...)" call, but with the default isolation level change
ThreadLocalTransactionManager(it, DEFAULT_REPETITION_ATTEMPTS).also {
it.defaultIsolationLevel = ISOLATION_LEVEL.levelId // Change our default isolation level
databaseConfig = DatabaseConfig {
this.defaultRepetitionAttempts = 5
this.defaultIsolationLevel = ISOLATION_LEVEL.levelId // Change our default isolation level
}
}
)
}
Loading

0 comments on commit d9474d9

Please sign in to comment.