From d9474d9acbe102cbb13d9d3e5a57e49f5c48f257 Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Thu, 14 Dec 2023 16:17:11 -0300 Subject: [PATCH] Update dependencies --- build.gradle.kts | 53 ++----- buildSrc/build.gradle.kts | 7 - buildSrc/src/main/kotlin/RunnableJarTask.kt | 93 ------------ .../perfectdreams/floppapower/FloppaPower.kt | 47 +++--- .../floppapower/MigrationTool.kt | 136 ------------------ .../commands/AbstractSlashCommand.kt | 4 +- .../commands/impl/CheckGuildCommand.kt | 4 +- .../commands/impl/CheckGuildsCommand.kt | 4 +- .../impl/CheckSimilarAvatarsCommand.kt | 10 +- .../commands/impl/GuildsCommand.kt | 7 +- .../commands/impl/LeaveGuildCommand.kt | 4 +- .../floppapower/commands/impl/PingCommand.kt | 14 ++ .../commands/impl/SameAvatarHashCommand.kt | 6 +- .../commands/impl/SameAvatarUserCommand.kt | 6 +- .../commands/impl/SearchUsersCommand.kt | 7 +- .../commands/impl/SharedGuildsCommand.kt | 4 +- .../commands/impl/SusJoinsCommand.kt | 8 +- .../commands/impl/TopMutualUsersCommand.kt | 19 +-- .../listeners/FloppaGangButtonListener.kt | 4 +- .../floppapower/listeners/MessageListener.kt | 76 +++++----- .../listeners/SlashCommandListener.kt | 36 ++--- .../floppapower/rest/FloppaPowerWebAPI.kt | 7 +- .../tables/BlockedAvatarHashesBanEntries.kt | 2 +- .../tables/BlockedUserBanEntries.kt | 2 +- .../floppapower/tables/MessagesMetadata.kt | 1 - .../tables/MultiEntriesMetadata.kt | 2 +- .../OldBlockedAvatarHashesBanEntries.kt | 1 - .../tables/OldBlockedUserBanEntries.kt | 1 - .../tables/OldMultiEntriesMetadata.kt | 1 - .../floppapower/utils/Constants.kt | 2 +- .../floppapower/utils/FloppaButton.kt | 6 +- .../utils/FloppaButtonClickEvent.kt | 4 +- 32 files changed, 162 insertions(+), 416 deletions(-) delete mode 100644 buildSrc/build.gradle.kts delete mode 100644 buildSrc/src/main/kotlin/RunnableJarTask.kt delete mode 100644 src/main/kotlin/net/perfectdreams/floppapower/MigrationTool.kt create mode 100644 src/main/kotlin/net/perfectdreams/floppapower/commands/impl/PingCommand.kt diff --git a/build.gradle.kts b/build.gradle.kts index 1c1ae6c..d6c98d1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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" } @@ -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 { @@ -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) - } } \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts deleted file mode 100644 index c39a297..0000000 --- a/buildSrc/build.gradle.kts +++ /dev/null @@ -1,7 +0,0 @@ -plugins { - `kotlin-dsl` -} - -repositories { - jcenter() -} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/RunnableJarTask.kt b/buildSrc/src/main/kotlin/RunnableJarTask.kt deleted file mode 100644 index 2045fe0..0000000 --- a/buildSrc/src/main/kotlin/RunnableJarTask.kt +++ /dev/null @@ -1,93 +0,0 @@ -import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.api.artifacts.Configuration -import org.gradle.api.file.CopySpec -import org.gradle.api.tasks.bundling.Jar -import org.gradle.kotlin.dsl.task -import java.io.File - -val DEFAULT_SHADED_WITHIN_JAR_LIBRARIES = arrayOf( - "common-", - "loritta-serializable-commons-", - "parallax-code-api-", - "db-tables-" -) - -/** - * Creates a Runnable JAR with a few dependencies inside (`loritta-api`, `loritta-serializable-commons` and `parallax-code-api`) - * - * A manifest file is created with the application class path and sets the main class attribute to [mainClass]. - * - * Custom manifest attributes can be set, or overriden, with the [customAttributes] map - * - * So this is just like a "poor mans" Gradle Shadow Plugin :P, however there are a few advantages of doing this! - * - * https://product.hubspot.com/blog/the-fault-in-our-jars-why-we-stopped-building-fat-jars - * - * @param mainClass the main class of the application - * @param customAttributes custom attributes to be set in the manifest - */ -fun Project.runnableJarTask( - addToFinalJarSourceProjectsPrefixes: Array = DEFAULT_SHADED_WITHIN_JAR_LIBRARIES, - runtimeClasspath: Configuration, - taskProvider: Jar, - mainClass: String, - customAttributes: Map -): Task { - return task("runnableJar", type = Jar::class) { - doFirst { - archiveBaseName.set("${project.name}-runnable") - - manifest { - fun addIfAvailable(name: String, attrName: String) { - attributes[attrName] = System.getProperty(name) ?: "Unknown" - } - - addIfAvailable("build.number", "Build-Number") - addIfAvailable("commit.hash", "Commit-Hash") - addIfAvailable("git.branch", "Git-Branch") - addIfAvailable("compiled.at", "Compiled-At") - addIfAvailable("github.build.id", "Github-Build-Id") - attributes["Main-Class"] = mainClass - attributes["Class-Path"] = runtimeClasspath - .filterNot { addToFinalJarSourceProjectsPrefixes.any { sourceName -> it.name.startsWith(sourceName) } } - .filter { it.extension == "jar" } - .distinctBy { it.name } - .joinToString(" ", transform = { "libs/" + it.name }) - attributes.putAll(customAttributes) - } - - // Add any required dependencies inside the JAR - // This NEEDS to be within the "doFirst", not in "doLast"! - // In the "doLast", the JARs were never added to the JAR (I wonder why?) - from(runtimeClasspath.mapNotNull { - if (addToFinalJarSourceProjectsPrefixes.any { sourceName -> it.name.startsWith(sourceName) }) { - zipTree(it) - } else null - }) - } - - // Only copy the libs in a "doLast" - // doLast means that this won't be executed when loading the build.gradle.kts - // (Yes, by default Gradle will run everything in this task block, even if you are compiling a unrelated project) - // Very strange... - doLast { - println("Copying dependencies JARs for ${project.name}...") - - val libs = File(project.projectDir, "build/libs/libs") - libs.mkdirs() - // And the rest we will store outside of the JAR - from(runtimeClasspath.mapNotNull { - if (!addToFinalJarSourceProjectsPrefixes.any { sourceName -> it.name.startsWith(sourceName) }) { - val output = File(libs, it.name) - - if (it.exists() && !output.exists() && it.extension == "jar") - it.copyTo(output, true) - } - null - }) - } - - with(taskProvider as CopySpec) - } -} \ No newline at end of file diff --git a/src/main/kotlin/net/perfectdreams/floppapower/FloppaPower.kt b/src/main/kotlin/net/perfectdreams/floppapower/FloppaPower.kt index 331864a..8ce148c 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/FloppaPower.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/FloppaPower.kt @@ -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 @@ -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 @@ -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 @@ -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 @@ -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"), @@ -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! @@ -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() } @@ -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, @@ -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, @@ -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, @@ -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, @@ -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 } - } + ) } \ No newline at end of file diff --git a/src/main/kotlin/net/perfectdreams/floppapower/MigrationTool.kt b/src/main/kotlin/net/perfectdreams/floppapower/MigrationTool.kt deleted file mode 100644 index 2030077..0000000 --- a/src/main/kotlin/net/perfectdreams/floppapower/MigrationTool.kt +++ /dev/null @@ -1,136 +0,0 @@ -package net.perfectdreams.floppapower - -import net.perfectdreams.floppapower.tables.BlockedAvatarHashes -import net.perfectdreams.floppapower.tables.BlockedAvatarHashesBanEntries -import net.perfectdreams.floppapower.tables.BlockedUserBanEntries -import net.perfectdreams.floppapower.tables.BlockedUsers -import net.perfectdreams.floppapower.tables.MessagesMetadata -import net.perfectdreams.floppapower.tables.MultiEntriesMetadata -import net.perfectdreams.floppapower.tables.OldBlockedAvatarHashesBanEntries -import net.perfectdreams.floppapower.tables.OldBlockedUserBanEntries -import net.perfectdreams.floppapower.tables.OldMultiEntriesMetadata -import net.perfectdreams.floppapower.tables.UsersApprovals -import org.jetbrains.exposed.sql.Database -import org.jetbrains.exposed.sql.insert -import org.jetbrains.exposed.sql.selectAll -import org.jetbrains.exposed.sql.transactions.transaction -import java.time.Instant - -object MigrationTool { - fun migrate(database: Database, sqliteDatabase: Database) { - val multiEntriesMetadata = transaction(sqliteDatabase) { - OldMultiEntriesMetadata.selectAll() - .toList() - } - - transaction(database) { - for (entry in multiEntriesMetadata) { - MultiEntriesMetadata.insert { - it[MultiEntriesMetadata.id] = entry[OldMultiEntriesMetadata.id] - it[MultiEntriesMetadata.comment] = entry[OldMultiEntriesMetadata.comment] - it[MultiEntriesMetadata.submittedBy] = entry[OldMultiEntriesMetadata.submittedBy] - it[MultiEntriesMetadata.approvedAt] = Instant.ofEpochMilli(entry[OldMultiEntriesMetadata.approvedAt]) - } - } - } - - val usersApprovals = transaction(sqliteDatabase) { - UsersApprovals.selectAll() - .toList() - } - - transaction(database) { - for (entry in usersApprovals) { - UsersApprovals.insert { - it[UsersApprovals.id] = entry[UsersApprovals.id] - it[UsersApprovals.user] = entry[UsersApprovals.user] - it[UsersApprovals.approvedEntries] = entry[UsersApprovals.approvedEntries] - } - } - } - - val messagesMetadata = transaction(sqliteDatabase) { - MessagesMetadata.selectAll() - .toList() - } - - transaction(database) { - for (entry in messagesMetadata) { - MessagesMetadata.insert { - it[MessagesMetadata.id] = entry[MessagesMetadata.id] - it[MessagesMetadata.type] = entry[MessagesMetadata.type] - it[MessagesMetadata.comment] = entry[MessagesMetadata.comment] - it[MessagesMetadata.size] = entry[MessagesMetadata.size] - it[MessagesMetadata.submittedBy] = entry[MessagesMetadata.submittedBy] - it[MessagesMetadata.approvedBy] = entry[MessagesMetadata.approvedBy] - } - } - } - - val blockedUsers = transaction(sqliteDatabase) { - BlockedUsers.selectAll() - .toList() - } - - transaction(database) { - for (entry in blockedUsers) { - BlockedUsers.insert { - it[BlockedUsers.id] = entry[BlockedUsers.id] - it[BlockedUsers.entry] = entry[BlockedUsers.entry] - it[BlockedUsers.valid] = entry[BlockedUsers.valid] - } - } - } - - val blockedAvatarHashes = transaction(sqliteDatabase) { - BlockedAvatarHashes.selectAll() - .toList() - } - - transaction(database) { - for (entry in blockedAvatarHashes) { - BlockedAvatarHashes.insert { - it[BlockedAvatarHashes.id] = entry[BlockedAvatarHashes.id] - it[BlockedAvatarHashes.entry] = entry[BlockedAvatarHashes.entry] - it[BlockedAvatarHashes.valid] = entry[BlockedAvatarHashes.valid] - } - } - } - - val blockedUserBanEntries = transaction(sqliteDatabase) { - OldBlockedUserBanEntries.selectAll() - .toList() - } - - transaction(database) { - for (entry in blockedUserBanEntries) { - BlockedUserBanEntries.insert { - it[BlockedUserBanEntries.id] = entry[OldBlockedUserBanEntries.id] - it[BlockedUserBanEntries.user] = entry[OldBlockedUserBanEntries.user] - it[BlockedUserBanEntries.guild] = entry[OldBlockedUserBanEntries.guild] - it[BlockedUserBanEntries.bannedAt] = Instant.ofEpochMilli(entry[OldBlockedUserBanEntries.bannedAt]) - it[BlockedUserBanEntries.blockEntry] = entry[OldBlockedUserBanEntries.blockEntry] - } - } - } - - val blockedAvatarHashesBanEntries = transaction(sqliteDatabase) { - OldBlockedAvatarHashesBanEntries.selectAll() - .toList() - } - - transaction(database) { - for (entry in blockedAvatarHashesBanEntries) { - BlockedAvatarHashesBanEntries.insert { - it[BlockedAvatarHashesBanEntries.id] = entry[OldBlockedAvatarHashesBanEntries.id] - it[BlockedAvatarHashesBanEntries.user] = entry[OldBlockedAvatarHashesBanEntries.user] - it[BlockedAvatarHashesBanEntries.guild] = entry[OldBlockedAvatarHashesBanEntries.guild] - it[BlockedAvatarHashesBanEntries.bannedAt] = Instant.ofEpochMilli(entry[OldBlockedAvatarHashesBanEntries.bannedAt]) - it[BlockedAvatarHashesBanEntries.blockEntry] = entry[OldBlockedAvatarHashesBanEntries.blockEntry] - } - } - } - - println("Done!") - } -} \ No newline at end of file diff --git a/src/main/kotlin/net/perfectdreams/floppapower/commands/AbstractSlashCommand.kt b/src/main/kotlin/net/perfectdreams/floppapower/commands/AbstractSlashCommand.kt index 256d4e2..fc28751 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/commands/AbstractSlashCommand.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/commands/AbstractSlashCommand.kt @@ -1,7 +1,7 @@ package net.perfectdreams.floppapower.commands -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent abstract class AbstractSlashCommand(val commandPath: String) { - abstract fun execute(event: SlashCommandEvent) + abstract fun execute(event: SlashCommandInteractionEvent) } \ No newline at end of file diff --git a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/CheckGuildCommand.kt b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/CheckGuildCommand.kt index 7483f14..af950b4 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/CheckGuildCommand.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/CheckGuildCommand.kt @@ -3,7 +3,7 @@ package net.perfectdreams.floppapower.commands.impl import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import kotlinx.coroutines.sync.withLock -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent import net.dv8tion.jda.api.sharding.ShardManager import net.perfectdreams.floppapower.FloppaPower import net.perfectdreams.floppapower.commands.AbstractSlashCommand @@ -11,7 +11,7 @@ import net.perfectdreams.floppapower.listeners.SlashCommandListener import net.perfectdreams.floppapower.utils.CheckedDueToType class CheckGuildCommand(private val m: FloppaPower, private val shardManager: ShardManager) : AbstractSlashCommand("checkguild") { - override fun execute(event: SlashCommandEvent) { + override fun execute(event: SlashCommandInteractionEvent) { val guildId = event.getOption("guild_id")?.asString?.toLongOrNull() if (guildId == null) { diff --git a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/CheckGuildsCommand.kt b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/CheckGuildsCommand.kt index 9e38816..e8508d2 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/CheckGuildsCommand.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/CheckGuildsCommand.kt @@ -3,7 +3,7 @@ package net.perfectdreams.floppapower.commands.impl import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import kotlinx.coroutines.sync.withLock -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent import net.dv8tion.jda.api.sharding.ShardManager import net.perfectdreams.floppapower.FloppaPower import net.perfectdreams.floppapower.commands.AbstractSlashCommand @@ -11,7 +11,7 @@ import net.perfectdreams.floppapower.listeners.SlashCommandListener import net.perfectdreams.floppapower.utils.CheckedDueToType class CheckGuildsCommand(private val m: FloppaPower, private val shardManager: ShardManager) : AbstractSlashCommand("checkguilds") { - override fun execute(event: SlashCommandEvent) { + override fun execute(event: SlashCommandInteractionEvent) { if (SlashCommandListener.verificationMutex.isLocked) { event.deferReply(true) .setContent("Já tem uma verificação em andamento, espere ela acabar! ") diff --git a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/CheckSimilarAvatarsCommand.kt b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/CheckSimilarAvatarsCommand.kt index 8d52eaa..e5d693e 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/CheckSimilarAvatarsCommand.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/CheckSimilarAvatarsCommand.kt @@ -3,9 +3,9 @@ package net.perfectdreams.floppapower.commands.impl import net.dv8tion.jda.api.EmbedBuilder import net.dv8tion.jda.api.entities.Guild import net.dv8tion.jda.api.entities.MessageEmbed -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent -import net.dv8tion.jda.api.interactions.components.Button -import net.dv8tion.jda.api.interactions.components.ButtonStyle +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent +import net.dv8tion.jda.api.interactions.components.buttons.Button +import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle import net.dv8tion.jda.api.sharding.ShardManager import net.perfectdreams.floppapower.FloppaPower import net.perfectdreams.floppapower.commands.AbstractSlashCommand @@ -13,7 +13,7 @@ import net.perfectdreams.floppapower.utils.Constants import net.perfectdreams.floppapower.utils.FloppaButton class CheckSimilarAvatarsCommand(private val m: FloppaPower, private val shardManager: ShardManager) : AbstractSlashCommand("checksimilaravatars") { - override fun execute(event: SlashCommandEvent) { + override fun execute(event: SlashCommandInteractionEvent) { val pageId = (event.getOption("page")?.asString?.toInt() ?: 1).coerceAtLeast(1) val reply = event.deferReply() @@ -112,7 +112,7 @@ class CheckSimilarAvatarsCommand(private val m: FloppaPower, private val shardMa embeds.add( EmbedBuilder() .setTitle("Usado por ${it.value.size} usuários") - .addField("Avatar Hash", firstUser.avatarId, true) + .addField("Avatar Hash", firstUser.avatarId.toString(), true) .addField( "Visto em Servidores (${guildsFound.size})", serverListText.take(1000), diff --git a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/GuildsCommand.kt b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/GuildsCommand.kt index 809e8fc..e7f74d8 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/GuildsCommand.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/GuildsCommand.kt @@ -1,11 +1,12 @@ package net.perfectdreams.floppapower.commands.impl -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent import net.dv8tion.jda.api.sharding.ShardManager +import net.dv8tion.jda.api.utils.FileUpload import net.perfectdreams.floppapower.commands.AbstractSlashCommand class GuildsCommand(private val shardManager: ShardManager) : AbstractSlashCommand("guilds") { - override fun execute(event: SlashCommandEvent) { + override fun execute(event: SlashCommandInteractionEvent) { val builder = StringBuilder("Guilds (${shardManager.guildCache.size()}):") builder.append("\n") shardManager.guildCache.sortedByDescending { it.memberCache.size() }.forEach { @@ -14,7 +15,7 @@ class GuildsCommand(private val shardManager: ShardManager) : AbstractSlashComma } event.deferReply() - .addFile(builder.toString().toByteArray(Charsets.UTF_8), "guilds.txt") + .setFiles(FileUpload.fromData(builder.toString().toByteArray(Charsets.UTF_8), "guilds.txt")) .queue() } } \ No newline at end of file diff --git a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/LeaveGuildCommand.kt b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/LeaveGuildCommand.kt index 8d41176..17decd2 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/LeaveGuildCommand.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/LeaveGuildCommand.kt @@ -1,12 +1,12 @@ package net.perfectdreams.floppapower.commands.impl -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent import net.dv8tion.jda.api.sharding.ShardManager import net.perfectdreams.floppapower.FloppaPower import net.perfectdreams.floppapower.commands.AbstractSlashCommand class LeaveGuildCommand(private val m: FloppaPower, private val shardManager: ShardManager) : AbstractSlashCommand("leaveguild") { - override fun execute(event: SlashCommandEvent) { + override fun execute(event: SlashCommandInteractionEvent) { val guildId = event.getOption("guild_id")?.asString?.toLongOrNull() val peguinGuardID = 819692196378443800L diff --git a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/PingCommand.kt b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/PingCommand.kt new file mode 100644 index 0000000..f769294 --- /dev/null +++ b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/PingCommand.kt @@ -0,0 +1,14 @@ +package net.perfectdreams.floppapower.commands.impl + +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent +import net.dv8tion.jda.api.sharding.ShardManager +import net.perfectdreams.floppapower.FloppaPower +import net.perfectdreams.floppapower.commands.AbstractSlashCommand + +class PingCommand(private val m: FloppaPower, private val shardManager: ShardManager) : AbstractSlashCommand("ping") { + override fun execute(event: SlashCommandInteractionEvent) { + event.deferReply(false) + .setContent("floppa flopper flop ") + .queue() + } +} \ No newline at end of file diff --git a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SameAvatarHashCommand.kt b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SameAvatarHashCommand.kt index f28d205..e6fb9c4 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SameAvatarHashCommand.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SameAvatarHashCommand.kt @@ -1,14 +1,14 @@ package net.perfectdreams.floppapower.commands.impl import net.dv8tion.jda.api.EmbedBuilder -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent import net.dv8tion.jda.api.sharding.ShardManager import net.perfectdreams.floppapower.FloppaPower import net.perfectdreams.floppapower.commands.AbstractSlashCommand import net.perfectdreams.floppapower.utils.Constants class SameAvatarHashCommand(private val m: FloppaPower, private val shardManager: ShardManager) : AbstractSlashCommand("sameavatar/hash") { - override fun execute(event: SlashCommandEvent) { + override fun execute(event: SlashCommandInteractionEvent) { val avatarId = event.getOption("hash")?.asString if (avatarId == null || avatarId.length !in Constants.AVATAR_HASH_LENGTH) { @@ -32,7 +32,7 @@ class SameAvatarHashCommand(private val m: FloppaPower, private val shardManager .addEmbeds( EmbedBuilder() .setThumbnail(first.effectiveAvatarUrl) - .addField("Avatar Hash", first.avatarId, true) + .addField("Avatar Hash", first.avatarId.toString(), true) .setDescription( buildString { matchedUsers.sortedByDescending { it.timeCreated }.forEach { diff --git a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SameAvatarUserCommand.kt b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SameAvatarUserCommand.kt index 4a0c035..e83fdc0 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SameAvatarUserCommand.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SameAvatarUserCommand.kt @@ -4,7 +4,7 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import kotlinx.coroutines.sync.withLock import net.dv8tion.jda.api.EmbedBuilder -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent import net.dv8tion.jda.api.sharding.ShardManager import net.perfectdreams.floppapower.FloppaPower import net.perfectdreams.floppapower.commands.AbstractSlashCommand @@ -13,7 +13,7 @@ import net.perfectdreams.floppapower.utils.CheckedDueToType import net.perfectdreams.floppapower.utils.Constants class SameAvatarUserCommand(private val m: FloppaPower, private val shardManager: ShardManager) : AbstractSlashCommand("sameavatar/user") { - override fun execute(event: SlashCommandEvent) { + override fun execute(event: SlashCommandInteractionEvent) { val avatarId = event.getOption("user")?.asUser?.avatarId if (avatarId == null || avatarId.length !in Constants.AVATAR_HASH_LENGTH) { @@ -37,7 +37,7 @@ class SameAvatarUserCommand(private val m: FloppaPower, private val shardManager .addEmbeds( EmbedBuilder() .setThumbnail(first.effectiveAvatarUrl) - .addField("Avatar Hash", first.avatarId, true) + .addField("Avatar Hash", first.avatarId.toString(), true) .setDescription( buildString { matchedUsers.sortedByDescending { it.timeCreated }.forEach { diff --git a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SearchUsersCommand.kt b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SearchUsersCommand.kt index e707131..801eb72 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SearchUsersCommand.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SearchUsersCommand.kt @@ -1,8 +1,9 @@ package net.perfectdreams.floppapower.commands.impl import net.dv8tion.jda.api.entities.User -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent import net.dv8tion.jda.api.sharding.ShardManager +import net.dv8tion.jda.api.utils.FileUpload import net.perfectdreams.floppapower.commands.AbstractSlashCommand import net.perfectdreams.floppapower.utils.Constants import net.perfectdreams.floppapower.utils.InfoGenerationUtils @@ -17,7 +18,7 @@ class SearchUsersCommand(private val shardManager: ShardManager) : AbstractSlash const val MAX_USERS_PER_LIST = 15_000 } - override fun execute(event: SlashCommandEvent) { + override fun execute(event: SlashCommandInteractionEvent) { event.deferReply().queue() val hook = event.hook // This is a special webhook that allows you to send messages without having permissions in the channel and also allows ephemeral messages @@ -83,7 +84,7 @@ class SearchUsersCommand(private val shardManager: ShardManager) : AbstractSlash hook .editOriginal(if (tooManyUsers) "Tem tantos usuários que eu limitei a $MAX_USERS_PER_LIST usuários! " else "") - .addFile(builder.toString().take(8_000_000).toByteArray(Charsets.UTF_8), "users.txt") + .setFiles(FileUpload.fromData(builder.toString().take(8_000_000).toByteArray(Charsets.UTF_8), "users.txt")) .queue() } } \ No newline at end of file diff --git a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SharedGuildsCommand.kt b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SharedGuildsCommand.kt index e7606ff..a8c2f6e 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SharedGuildsCommand.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SharedGuildsCommand.kt @@ -1,13 +1,13 @@ package net.perfectdreams.floppapower.commands.impl import net.dv8tion.jda.api.EmbedBuilder -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent import net.dv8tion.jda.api.sharding.ShardManager import net.perfectdreams.floppapower.FloppaPower import net.perfectdreams.floppapower.commands.AbstractSlashCommand class SharedGuildsCommand(private val m: FloppaPower, private val shardManager: ShardManager) : AbstractSlashCommand("sharedguilds") { - override fun execute(event: SlashCommandEvent) { + override fun execute(event: SlashCommandInteractionEvent) { val user = event.getOption("user")!!.asUser val mutualGuilds = shardManager.getMutualGuilds(user) diff --git a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SusJoinsCommand.kt b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SusJoinsCommand.kt index f89578c..2a588e3 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SusJoinsCommand.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/SusJoinsCommand.kt @@ -4,9 +4,9 @@ import net.dv8tion.jda.api.EmbedBuilder import net.dv8tion.jda.api.entities.Guild import net.dv8tion.jda.api.entities.MessageEmbed import net.dv8tion.jda.api.entities.User -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent -import net.dv8tion.jda.api.interactions.components.Button -import net.dv8tion.jda.api.interactions.components.ButtonStyle +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent +import net.dv8tion.jda.api.interactions.components.buttons.Button +import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle import net.dv8tion.jda.api.sharding.ShardManager import net.perfectdreams.floppapower.FloppaPower import net.perfectdreams.floppapower.commands.AbstractSlashCommand @@ -16,7 +16,7 @@ import java.time.OffsetDateTime import java.time.ZoneId class SusJoinsCommand(private val m: FloppaPower, private val shardManager: ShardManager) : AbstractSlashCommand("susjoins") { - override fun execute(event: SlashCommandEvent) { + override fun execute(event: SlashCommandInteractionEvent) { val diffBetweenJoinTimes = event.getOption("time")?.asString?.toLong() ?: error("Missing time!") val creationTimeDayFilter = event.getOption("creation_time_filter")?.asString?.toLong() ?: error("Missing time!") // val pageId = (event.getOption("page")?.asString?.toInt() ?: 1).coerceAtLeast(1) diff --git a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/TopMutualUsersCommand.kt b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/TopMutualUsersCommand.kt index 7030362..8162705 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/TopMutualUsersCommand.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/commands/impl/TopMutualUsersCommand.kt @@ -2,15 +2,16 @@ package net.perfectdreams.floppapower.commands.impl import net.dv8tion.jda.api.entities.Guild import net.dv8tion.jda.api.entities.User -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent import net.dv8tion.jda.api.sharding.ShardManager +import net.dv8tion.jda.api.utils.FileUpload import net.perfectdreams.floppapower.commands.AbstractSlashCommand import net.perfectdreams.floppapower.commands.impl.SearchUsersCommand.Companion.MAX_USERS_PER_LIST import net.perfectdreams.floppapower.utils.Constants import net.perfectdreams.floppapower.utils.InfoGenerationUtils class TopMutualUsersCommand(private val shardManager: ShardManager) : AbstractSlashCommand("topmutualusers") { - override fun execute(event: SlashCommandEvent) { + override fun execute(event: SlashCommandInteractionEvent) { event.deferReply().queue() val hook = event.hook // This is a special webhook that allows you to send messages without having permissions in the channel and also allows ephemeral messages @@ -88,12 +89,14 @@ class TopMutualUsersCommand(private val shardManager: ShardManager) : AbstractSl val (successfullyAddedUsers, lines) = generateTopUsersMutualGuildsLines() hook.editOriginal("**Todos os $userCacheSize usuários foram verificados! (${userWithMutualGuilds.size} válidos baseado no filtro)** \nResultado apenas possui os top $successfullyAddedUsers usuários, ignorando bots e usuários que estão na EPF!") - .retainFiles(listOf()) // Remove all files from the message - .addFile( - lines - .joinToString("\n") - .toByteArray(Charsets.UTF_8), - "users.txt" + .setReplace(false) + .setFiles( + FileUpload.fromData( + lines + .joinToString("\n") + .toByteArray(Charsets.UTF_8), + "users.txt" + ) ) .queue() } diff --git a/src/main/kotlin/net/perfectdreams/floppapower/listeners/FloppaGangButtonListener.kt b/src/main/kotlin/net/perfectdreams/floppapower/listeners/FloppaGangButtonListener.kt index ba9a1e1..b776d8e 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/listeners/FloppaGangButtonListener.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/listeners/FloppaGangButtonListener.kt @@ -1,13 +1,13 @@ package net.perfectdreams.floppapower.listeners -import net.dv8tion.jda.api.events.interaction.ButtonClickEvent +import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent import net.dv8tion.jda.api.hooks.ListenerAdapter import net.dv8tion.jda.api.sharding.ShardManager import net.perfectdreams.floppapower.FloppaPower import net.perfectdreams.floppapower.utils.Constants class FloppaGangButtonListener(private val m: FloppaPower, private val shardManager: ShardManager) : ListenerAdapter() { - override fun onButtonClick(event: ButtonClickEvent) { + override fun onButtonInteraction(event: ButtonInteractionEvent) { if (event.componentId != "get_floppa_role") return diff --git a/src/main/kotlin/net/perfectdreams/floppapower/listeners/MessageListener.kt b/src/main/kotlin/net/perfectdreams/floppapower/listeners/MessageListener.kt index 494ebbe..c5b4566 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/listeners/MessageListener.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/listeners/MessageListener.kt @@ -9,19 +9,20 @@ import kotlinx.coroutines.withContext import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import mu.KotlinLogging -import net.dv8tion.jda.api.MessageBuilder -import net.dv8tion.jda.api.entities.Emoji import net.dv8tion.jda.api.entities.Member import net.dv8tion.jda.api.entities.Message import net.dv8tion.jda.api.entities.User -import net.dv8tion.jda.api.events.interaction.ButtonClickEvent +import net.dv8tion.jda.api.entities.emoji.Emoji +import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent import net.dv8tion.jda.api.events.message.MessageReceivedEvent import net.dv8tion.jda.api.exceptions.ErrorResponseException import net.dv8tion.jda.api.hooks.ListenerAdapter import net.dv8tion.jda.api.interactions.components.ActionRow -import net.dv8tion.jda.api.interactions.components.Button -import net.dv8tion.jda.api.interactions.components.ButtonStyle +import net.dv8tion.jda.api.interactions.components.buttons.Button +import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle import net.dv8tion.jda.api.sharding.ShardManager +import net.dv8tion.jda.api.utils.FileUpload +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder import net.perfectdreams.floppapower.FloppaPower import net.perfectdreams.floppapower.dao.MessageMetadata import net.perfectdreams.floppapower.dao.MultiEntryMetadata @@ -86,21 +87,23 @@ class MessageListener(private val m: FloppaPower, private val shardManager: Shar } event.channel.sendMessage( - MessageBuilder() + MessageCreateBuilder() .setContent(generateContentFromMetadata(metadata)) - .setActionRows(generateActionRowFromMetadata(metadata)) + .setComponents(generateActionRowFromMetadata(metadata)) .setAllowedMentions(listOf(Message.MentionType.ROLE)) // none. thank you, next .build() - ).addFile( - checkUserIdsInLines(shardManager, data) - .toMutableList() - .apply { - this.add(0, "") - this.add(0, "# Message Metadata ID: ${metadata.id.value}") - } - .joinToString("\n") - .toByteArray(Charsets.UTF_8), - "report.txt" + ).setFiles( + FileUpload.fromData( + checkUserIdsInLines(shardManager, data) + .toMutableList() + .apply { + this.add(0, "") + this.add(0, "# Message Metadata ID: ${metadata.id.value}") + } + .joinToString("\n") + .toByteArray(Charsets.UTF_8), + "report.txt" + ) ).queue() } catch (e: Throwable) { logger.warn(e) { "Something went wrong while trying to create a selfbot_id report!" } @@ -129,22 +132,23 @@ class MessageListener(private val m: FloppaPower, private val shardManager: Shar } event.channel.sendMessage( - MessageBuilder() + MessageCreateBuilder() .setContent(generateContentFromMetadata(metadata)) - .setActionRows(generateActionRowFromMetadata(metadata)) + .setComponents(generateActionRowFromMetadata(metadata)) .setAllowedMentions(listOf(Message.MentionType.ROLE)) // only role mentions .build() - ).addFile( - checkAvatarHashesInLines(shardManager, validatedData) - .toMutableList() - .apply { - this.add(0, "") - this.add(0, "# Message Metadata ID: ${metadata.id.value}") - } - .joinToString("\n") - .toByteArray(Charsets.UTF_8), - - "report.txt" + ).setFiles( + FileUpload.fromData( + checkAvatarHashesInLines(shardManager, validatedData) + .toMutableList() + .apply { + this.add(0, "") + this.add(0, "# Message Metadata ID: ${metadata.id.value}") + } + .joinToString("\n") + .toByteArray(Charsets.UTF_8), + "report.txt" + ) ).queue() } catch (e: Throwable) { logger.warn(e) { "Something went wrong while trying to create a selfbot_id report!" } @@ -317,7 +321,7 @@ class MessageListener(private val m: FloppaPower, private val shardManager: Shar return veryImportantStuff } - override fun onButtonClick(event: ButtonClickEvent) { + override fun onButtonInteraction(event: ButtonInteractionEvent) { if (!event.componentId.startsWith("approve_ban_entry-") && !event.componentId.startsWith("delete_ban_entry-")) return @@ -348,7 +352,7 @@ class MessageListener(private val m: FloppaPower, private val shardManager: Shar // Update the message if it was processed but the buttons are somehow active event.deferEdit() .setContent(generateContentFromMetadata(metadata)) - .setActionRows(generateActionRowFromMetadata(metadata)) + .setComponents(generateActionRowFromMetadata(metadata)) .queue { // And tell the user that it was already processed it.setEphemeral(true) @@ -397,7 +401,7 @@ class MessageListener(private val m: FloppaPower, private val shardManager: Shar event.deferEdit() .setContent(generateContentFromMetadata(metadata)) - .setActionRows(generateActionRowFromMetadata(metadata)) + .setComponents(generateActionRowFromMetadata(metadata)) .queue() if (metadata.approvedByAsList.size >= metadata.type.requiredApprovals) { @@ -626,7 +630,7 @@ class MessageListener(private val m: FloppaPower, private val shardManager: Shar true -> "Yay, os não-meliantes foram removidos do xilindró!" false -> "Yay, os meliantes foram adicionados ao xilindró!" }, - Emoji.fromEmote("lori_coffee", 727631176432484473, false) + Emoji.fromCustom("lori_coffee", 727631176432484473, false) ).asDisabled() ) } else { @@ -635,13 +639,13 @@ class MessageListener(private val m: FloppaPower, private val shardManager: Shar ButtonStyle.DANGER, "approve_ban_entry-${metadata.id.value}", "Aprovar", - Emoji.fromEmote("lori_ban_hammer", 741058240455901254, false) + Emoji.fromCustom("lori_ban_hammer", 741058240455901254, false) ), Button.of( ButtonStyle.SECONDARY, "delete_ban_entry-${metadata.id.value}", "Deletar", - Emoji.fromEmote("lori_sob", 556524143281963008, false) + Emoji.fromCustom("lori_sob", 556524143281963008, false) ) ) } diff --git a/src/main/kotlin/net/perfectdreams/floppapower/listeners/SlashCommandListener.kt b/src/main/kotlin/net/perfectdreams/floppapower/listeners/SlashCommandListener.kt index 1dcb548..0c87d66 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/listeners/SlashCommandListener.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/listeners/SlashCommandListener.kt @@ -3,11 +3,11 @@ package net.perfectdreams.floppapower.listeners import kotlinx.coroutines.sync.Mutex import mu.KotlinLogging import net.dv8tion.jda.api.events.guild.GuildReadyEvent -import net.dv8tion.jda.api.events.interaction.ButtonClickEvent -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent +import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent import net.dv8tion.jda.api.hooks.ListenerAdapter 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.Commands import net.dv8tion.jda.api.interactions.commands.build.OptionData import net.dv8tion.jda.api.interactions.commands.build.SubcommandData import net.dv8tion.jda.api.sharding.ShardManager @@ -16,7 +16,6 @@ import net.perfectdreams.floppapower.commands.impl.* import net.perfectdreams.floppapower.utils.Constants import net.perfectdreams.floppapower.utils.FloppaButtonClickEvent import java.util.* -import kotlin.concurrent.thread class SlashCommandListener(private val m: FloppaPower, private val shardManager: ShardManager) : ListenerAdapter() { companion object { @@ -36,7 +35,8 @@ class SlashCommandListener(private val m: FloppaPower, private val shardManager: SameAvatarUserCommand(m, shardManager), SusJoinsCommand(m, shardManager), SearchUsersCommand(shardManager), - TopMutualUsersCommand(shardManager) + TopMutualUsersCommand(shardManager), + PingCommand(m, shardManager) ) override fun onGuildReady(event: GuildReadyEvent) { @@ -46,30 +46,30 @@ class SlashCommandListener(private val m: FloppaPower, private val shardManager: val guild = event.guild guild.upsertCommand( - CommandData("guilds", "Mostra quais servidores o Floppa está") + Commands.slash("guilds", "Mostra quais servidores o Floppa está") ).queue() guild.upsertCommand( - CommandData("leaveguild", "Faça o Floppa sair de um servidor em que ele está") + Commands.slash("leaveguild", "Faça o Floppa sair de um servidor em que ele está") .addOption(OptionType.STRING, "guild_id", "ID do Servidor", true) ).queue() guild.upsertCommand( - CommandData("checkguild", "Verifique meliantes em um servidor") + Commands.slash("checkguild", "Verifique meliantes em um servidor") .addOption(OptionType.STRING, "guild_id", "ID do Servidor", true) ).queue() guild.upsertCommand( - CommandData("checkguilds", "Verifique meliantes em todos os servidores que eu estou") + Commands.slash("checkguilds", "Verifique meliantes em todos os servidores que eu estou") ).queue() guild.upsertCommand( - CommandData("checksimilaravatars", "Verifique meliantes com avatares similares") + Commands.slash("checksimilaravatars", "Verifique meliantes com avatares similares") .addOption(OptionType.INTEGER, "page", "Página", false) ).queue() guild.upsertCommand( - CommandData("sameavatar", "Verifique meliantes que possuem o mesmo avatar") + Commands.slash("sameavatar", "Verifique meliantes que possuem o mesmo avatar") .addSubcommands( SubcommandData("hash", "Verifique meliantes que possuem o mesmo avatar pelo hash") .addOption(OptionType.STRING, "hash", "O hash do avatar", true), @@ -79,12 +79,12 @@ class SlashCommandListener(private val m: FloppaPower, private val shardManager: ).queue() guild.upsertCommand( - CommandData("sharedguilds", "Verifique aonde os meliantes estão na fuga") + Commands.slash("sharedguilds", "Verifique aonde os meliantes estão na fuga") .addOption(OptionType.USER, "user", "O meliante", true) ).queue() guild.upsertCommand( - CommandData("searchusers", "Busca usuários usando um RegEx") + Commands.slash("searchusers", "Busca usuários usando um RegEx") .addOption(OptionType.STRING, "pattern", "RegEx pattern do nome de usuário que você deseja procurar", true) .addOption(OptionType.BOOLEAN, "list", "Gera uma lista sem os detalhes", false) .addOptions( @@ -108,11 +108,11 @@ class SlashCommandListener(private val m: FloppaPower, private val shardManager: ).queue() guild.upsertCommand( - CommandData("topmutualusers", "Mostra os top usuários que compartilham mais servidores com o Floppa") + Commands.slash("topmutualusers", "Mostra os top usuários que compartilham mais servidores com o Floppa") ).queue() guild.upsertCommand( - CommandData("susjoins", "Verifique meliantes que entraram em vários servidores em seguida") + Commands.slash("susjoins", "Verifique meliantes que entraram em vários servidores em seguida") .addOptions( OptionData(OptionType.STRING, "time", "A diferença + e - de tempo que o meliante entrou, baseado no tempo de entrada no \"meio\" dos joins", true) .addChoice("10 segundos", "5") @@ -138,11 +138,11 @@ class SlashCommandListener(private val m: FloppaPower, private val shardManager: ).queue() } - override fun onSlashCommand(event: SlashCommandEvent) { + override fun onSlashCommandInteraction(event: SlashCommandInteractionEvent) { m.executor.execute { logger.info { "Received Slash Command ${event.name} from ${event.user}" } - val command = commands.firstOrNull { it.commandPath == event.commandPath } + val command = commands.firstOrNull { it.commandPath == event.fullCommandName } if (command != null) { command.execute(event) @@ -151,7 +151,7 @@ class SlashCommandListener(private val m: FloppaPower, private val shardManager: } } - override fun onButtonClick(event: ButtonClickEvent) { + override fun onButtonInteraction(event: ButtonInteractionEvent) { try { val uniqueId = UUID.fromString(event.componentId) m.slashCommandButtonInteractionCache[uniqueId]?.invoke( diff --git a/src/main/kotlin/net/perfectdreams/floppapower/rest/FloppaPowerWebAPI.kt b/src/main/kotlin/net/perfectdreams/floppapower/rest/FloppaPowerWebAPI.kt index e87c6bd..0a6049c 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/rest/FloppaPowerWebAPI.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/rest/FloppaPowerWebAPI.kt @@ -1,11 +1,12 @@ package net.perfectdreams.floppapower.rest -import io.ktor.application.* import io.ktor.http.* -import io.ktor.response.* -import io.ktor.routing.* +import io.ktor.server.application.* import io.ktor.server.engine.* import io.ktor.server.netty.* +import io.ktor.server.response.* +import io.ktor.server.routing.* +import io.ktor.server.util.* import io.ktor.util.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext diff --git a/src/main/kotlin/net/perfectdreams/floppapower/tables/BlockedAvatarHashesBanEntries.kt b/src/main/kotlin/net/perfectdreams/floppapower/tables/BlockedAvatarHashesBanEntries.kt index 8bd0df0..5973377 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/tables/BlockedAvatarHashesBanEntries.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/tables/BlockedAvatarHashesBanEntries.kt @@ -1,7 +1,7 @@ package net.perfectdreams.floppapower.tables import org.jetbrains.exposed.dao.id.LongIdTable -import org.jetbrains.exposed.sql.`java-time`.timestamp +import org.jetbrains.exposed.sql.javatime.timestamp object BlockedAvatarHashesBanEntries : LongIdTable() { val user = long("user").index() diff --git a/src/main/kotlin/net/perfectdreams/floppapower/tables/BlockedUserBanEntries.kt b/src/main/kotlin/net/perfectdreams/floppapower/tables/BlockedUserBanEntries.kt index 15eca65..cb21ebe 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/tables/BlockedUserBanEntries.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/tables/BlockedUserBanEntries.kt @@ -1,7 +1,7 @@ package net.perfectdreams.floppapower.tables import org.jetbrains.exposed.dao.id.LongIdTable -import org.jetbrains.exposed.sql.`java-time`.timestamp +import org.jetbrains.exposed.sql.javatime.timestamp object BlockedUserBanEntries : LongIdTable() { val user = long("user").index() diff --git a/src/main/kotlin/net/perfectdreams/floppapower/tables/MessagesMetadata.kt b/src/main/kotlin/net/perfectdreams/floppapower/tables/MessagesMetadata.kt index 6fc6f98..80294bf 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/tables/MessagesMetadata.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/tables/MessagesMetadata.kt @@ -3,7 +3,6 @@ package net.perfectdreams.floppapower.tables import net.perfectdreams.floppapower.utils.MetadataEntryType import net.perfectdreams.floppapower.utils.exposed.jsonb import org.jetbrains.exposed.dao.id.LongIdTable -import org.jetbrains.exposed.sql.`java-time`.timestamp object MessagesMetadata : LongIdTable() { val type = enumeration("type", MetadataEntryType::class) diff --git a/src/main/kotlin/net/perfectdreams/floppapower/tables/MultiEntriesMetadata.kt b/src/main/kotlin/net/perfectdreams/floppapower/tables/MultiEntriesMetadata.kt index fce8523..ce4f3fb 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/tables/MultiEntriesMetadata.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/tables/MultiEntriesMetadata.kt @@ -1,7 +1,7 @@ package net.perfectdreams.floppapower.tables import org.jetbrains.exposed.dao.id.LongIdTable -import org.jetbrains.exposed.sql.`java-time`.timestamp +import org.jetbrains.exposed.sql.javatime.timestamp object MultiEntriesMetadata : LongIdTable() { val submittedBy = long("submitted_by").index() diff --git a/src/main/kotlin/net/perfectdreams/floppapower/tables/OldBlockedAvatarHashesBanEntries.kt b/src/main/kotlin/net/perfectdreams/floppapower/tables/OldBlockedAvatarHashesBanEntries.kt index 464fc22..26146a0 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/tables/OldBlockedAvatarHashesBanEntries.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/tables/OldBlockedAvatarHashesBanEntries.kt @@ -1,7 +1,6 @@ package net.perfectdreams.floppapower.tables import org.jetbrains.exposed.dao.id.LongIdTable -import org.jetbrains.exposed.sql.`java-time`.timestamp object OldBlockedAvatarHashesBanEntries : LongIdTable() { override val tableName = "BlockedAvatarHashesBanEntries" diff --git a/src/main/kotlin/net/perfectdreams/floppapower/tables/OldBlockedUserBanEntries.kt b/src/main/kotlin/net/perfectdreams/floppapower/tables/OldBlockedUserBanEntries.kt index c9f2b38..267288c 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/tables/OldBlockedUserBanEntries.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/tables/OldBlockedUserBanEntries.kt @@ -1,7 +1,6 @@ package net.perfectdreams.floppapower.tables import org.jetbrains.exposed.dao.id.LongIdTable -import org.jetbrains.exposed.sql.`java-time`.timestamp object OldBlockedUserBanEntries : LongIdTable() { override val tableName = "BlockedUserBanEntries" diff --git a/src/main/kotlin/net/perfectdreams/floppapower/tables/OldMultiEntriesMetadata.kt b/src/main/kotlin/net/perfectdreams/floppapower/tables/OldMultiEntriesMetadata.kt index 84cc6a0..1b34330 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/tables/OldMultiEntriesMetadata.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/tables/OldMultiEntriesMetadata.kt @@ -1,7 +1,6 @@ package net.perfectdreams.floppapower.tables import org.jetbrains.exposed.dao.id.LongIdTable -import org.jetbrains.exposed.sql.`java-time`.timestamp object OldMultiEntriesMetadata : LongIdTable() { override val tableName = "MultiEntriesMetadata" diff --git a/src/main/kotlin/net/perfectdreams/floppapower/utils/Constants.kt b/src/main/kotlin/net/perfectdreams/floppapower/utils/Constants.kt index 02cac6c..3c7af50 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/utils/Constants.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/utils/Constants.kt @@ -17,7 +17,7 @@ object Constants { Permission.BAN_MEMBERS, Permission.KICK_MEMBERS, Permission.MANAGE_CHANNEL, - Permission.MANAGE_EMOTES_AND_STICKERS, + Permission.MANAGE_GUILD_EXPRESSIONS, Permission.MANAGE_PERMISSIONS, Permission.MANAGE_ROLES, Permission.MANAGE_SERVER diff --git a/src/main/kotlin/net/perfectdreams/floppapower/utils/FloppaButton.kt b/src/main/kotlin/net/perfectdreams/floppapower/utils/FloppaButton.kt index 3c6c8ff..424e9d5 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/utils/FloppaButton.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/utils/FloppaButton.kt @@ -1,13 +1,11 @@ package net.perfectdreams.floppapower.utils -import net.dv8tion.jda.api.interactions.components.Button -import net.dv8tion.jda.api.interactions.components.ButtonStyle +import net.dv8tion.jda.api.interactions.components.buttons.Button +import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle import net.perfectdreams.floppapower.FloppaPower import java.util.* -import javax.annotation.Nonnull object FloppaButton { - @Nonnull fun of(m: FloppaPower, style: ButtonStyle, label: String, callback: (FloppaButtonClickEvent) -> (Unit)): Button { val uniqueId = UUID.randomUUID() m.slashCommandButtonInteractionCache[uniqueId] = callback diff --git a/src/main/kotlin/net/perfectdreams/floppapower/utils/FloppaButtonClickEvent.kt b/src/main/kotlin/net/perfectdreams/floppapower/utils/FloppaButtonClickEvent.kt index fe3b593..a169432 100644 --- a/src/main/kotlin/net/perfectdreams/floppapower/utils/FloppaButtonClickEvent.kt +++ b/src/main/kotlin/net/perfectdreams/floppapower/utils/FloppaButtonClickEvent.kt @@ -1,10 +1,10 @@ package net.perfectdreams.floppapower.utils -import net.dv8tion.jda.api.events.interaction.ButtonClickEvent +import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent import net.perfectdreams.floppapower.FloppaPower import java.util.* -class FloppaButtonClickEvent(val m: FloppaPower, val uniqueId: UUID, val event: ButtonClickEvent) { +class FloppaButtonClickEvent(val m: FloppaPower, val uniqueId: UUID, val event: ButtonInteractionEvent) { fun invalidate() { m.slashCommandButtonInteractionCache.remove(uniqueId) }