...
 
Commits (3)
......@@ -52,11 +52,11 @@ val jar by tasks.getting(Jar::class) {
tasks {
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn" // for custom GuildClient.getAuditLog
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn" // for custom GuildClient.getAuditLog
}
val createDependenciesFile by creating {
......
......@@ -38,7 +38,7 @@ class About: Command {
field("Diskord", Globals.getDependencyVersion("com.jessecorbett", "diskord-jvm"), true)
field("Bot version", Globals.getDependencyVersion("pw.modder", "Answernator"), true)
field("Commands", CommandList.commands.size.toString(), true)
field("Modules", CommandList.modules.joinToString("\n") { "${it.name}@${it.version}" }, true)
field("Modules", CommandList.modules.joinToString("\n") { "${it.name}@${it.version}".trim('\n') }, true)
field("Commands prefix", Globals.config.prefix.toString(), true)
field("Owner", "<@${Globals.config.author}>", true)
field("Creator", "<@135017849604276224>", true)
......
......@@ -3,8 +3,8 @@ package pw.modder.answernator.utils
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import kotlinx.serialization.UnstableDefault
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
import java.io.File
import java.util.*
......@@ -24,9 +24,8 @@ open class Config(
companion object {
val DEFAULT = Config()
@OptIn(UnstableDefault::class)
fun loadFrom(file: File): Config {
return Json.parse(serializer(), file.readText(Charsets.UTF_8))
return Json(JsonConfiguration.Stable).parse(serializer(), file.readText(Charsets.UTF_8))
}
}
}
package pw.modder.answernator.utils
import io.ktor.client.HttpClient
import kotlinx.serialization.UnstableDefault
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
import java.io.File
import kotlin.random.Random
@OptIn(UnstableDefault::class)
object Globals {
private const val configFileName = "config.json"
......@@ -16,7 +13,7 @@ object Globals {
init {
val configFile = File(configFileName)
if (!configFile.exists()) {
configFile.writeText(Json(JsonConfiguration(prettyPrint = true)).stringify(Config.serializer(), Config.DEFAULT))
configFile.writeText(Json(JsonConfiguration.Stable.copy(prettyPrint = true)).stringify(Config.serializer(), Config.DEFAULT))
throw Exception("Missing config")
}
config = Config.loadFrom(configFile)
......
......@@ -8,10 +8,10 @@ import io.ktor.http.userAgent
import pw.modder.answernator.utils.Globals
private val userAgent = "DiscordBot: (https://gitlab.com/jesselcorbett/diskord, ${Globals.getDependencyVersion("com.jessecorbett", "diskord-jvm")})"
suspend fun Attachment.downloadAsString(): String {
suspend fun Attachment.downloadAsString(proxied: Boolean = false): String {
return Globals.httpClient.get<String> {
userAgent(userAgent)
url(this@downloadAsString.proxiedUrl)
url(if (proxied) this@downloadAsString.proxiedUrl else this@downloadAsString.url)
cookies()
}
}
\ No newline at end of file
}
......@@ -4,6 +4,7 @@ import com.jessecorbett.diskord.api.rest.client.GuildClient
import com.jessecorbett.diskord.util.DiskordInternals
import pw.modder.answernator.utils.auditLog.AuditLog
@Suppress("UNUSED_PARAMETER")
@OptIn(DiskordInternals::class)
suspend fun GuildClient.getAuditLog(useCustom: Boolean = true) = getRequest("/guilds/$guildId/audit-logs", AuditLog.serializer())
\ No newline at end of file
@Suppress("UNUSED_PARAMETER")
suspend fun GuildClient.getAuditLog(useCustom: Boolean = true) = this.getRequest("/guilds/$guildId/audit-logs", AuditLog.serializer())
\ No newline at end of file
......@@ -40,11 +40,9 @@ dependencies {
tasks {
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
val createModuleVersionFile by creating {
......
......@@ -11,7 +11,6 @@ import com.jessecorbett.diskord.util.words
import io.ktor.client.request.get
import io.ktor.client.request.parameter
import kotlinx.serialization.MissingFieldException
import kotlinx.serialization.UnstableDefault
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
import pw.modder.answernator.db.Db
......@@ -22,8 +21,7 @@ import java.util.*
import com.jessecorbett.diskord.dsl.message as dslmessage
import pw.modder.answernator.`fun`.utils.Quote as QuoteData
@OptIn(UnstableDefault::class)
private val json = Json(JsonConfiguration(ignoreUnknownKeys = true))
private val json = Json(JsonConfiguration.Stable.copy(ignoreUnknownKeys = true))
class Quote: Command {
override val name = "quote"
......
......@@ -4,7 +4,6 @@ import com.jessecorbett.diskord.api.model.Message
import com.jessecorbett.diskord.dsl.Bot
import com.jessecorbett.diskord.dsl.CombinedMessageEmbed
import com.jessecorbett.diskord.util.mention
import kotlinx.serialization.UnstableDefault
import kotlinx.serialization.builtins.list
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
......@@ -16,8 +15,7 @@ import java.util.*
class Ubuntu: LocalizedCommand {
override val name: String = "ubuntu"
override val cmdType = Command.CommandGroup.FUN
@OptIn(UnstableDefault::class)
private val data = Json(JsonConfiguration.Default)
private val data = Json(JsonConfiguration.Stable)
.parse(UbuntuWord.serializer().list, javaClass.classLoader.getResourceAsStream("ubuntu.json").reader().readText())
override suspend fun action(bot: Bot, message: Message, texts: ResourceBundle): CombinedMessageEmbed {
......
kotlin.code.style=official
diskordVersion=1.6.2
kotlinxCoroutinesVersion=1.3.3
kotlinSerializationVersion=0.14.0
ktorVersion=1.2.6
kotlinxCoroutinesVersion=1.3.4
kotlinSerializationVersion=0.20.0
ktorVersion=1.3.2
exposedVersion=0.22.1
slf4jVersion=1.7.26
commonsIoVersion=2.6
......
......@@ -42,11 +42,9 @@ dependencies {
tasks {
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
val createModuleVersionFile by creating {
......