Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Add epehemerals #203

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 56 additions & 58 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

plugins {
application
kotlin("jvm") version "1.5.0"
kotlin("plugin.serialization") version "1.5.0"
kotlin("jvm") version "1.5.10"
kotlin("plugin.serialization") version "1.5.10"
id("org.jlleitschuh.gradle.ktlint") version "10.0.0"
}

Expand All @@ -39,80 +39,78 @@ dependencies {
runtimeOnly(kotlin("scripting-jsr223"))

// Coroutines
implementation("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8", "1.5.0-RC")
implementation("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8", "1.5.0")

// Logging
implementation("io.github.microutils", "kotlin-logging", "1.12.5")
implementation("org.slf4j", "slf4j-api", "2.0.0alpha1")
implementation("io.github.microutils", "kotlin-logging", "2.0.6")
implementation("org.slf4j", "slf4j-api", "2.0.0-alpha1")
implementation("ch.qos.logback", "logback-classic", "1.3.0-alpha5")
implementation("io.sentry", "sentry", "4.3.0")
implementation("io.sentry", "sentry-logback", "4.3.0")

// Database
implementation("org.jetbrains.exposed", "exposed-core", "0.30.2")
implementation("org.jetbrains.exposed", "exposed-dao", "0.30.2")
implementation("org.jetbrains.exposed", "exposed-jdbc", "0.30.2")
implementation("org.jetbrains.exposed", "exposed-java-time", "0.30.2")
implementation("org.postgresql", "postgresql", "42.2.19")
implementation("org.jetbrains.exposed", "exposed-core", "0.31.1")
implementation("org.jetbrains.exposed", "exposed-dao", "0.31.1")
implementation("org.jetbrains.exposed", "exposed-jdbc", "0.31.1")
implementation("org.jetbrains.exposed", "exposed-java-time", "0.31.1")
implementation("org.postgresql", "postgresql", "42.2.20")
implementation("com.zaxxer", "HikariCP", "4.0.3")

// Discord
implementation("dev.kord", "kord-core", "kotlin-1.5-SNAPSHOT") {
implementation("dev.kord", "kord-core", "kotlin-1.5-20210514.081043-5") {
version {
strictly("kotlin-1.5-SNAPSHOT")
}
version {
strictly("kotlin-1.5-SNAPSHOT")
}

// Util
implementation("io.github.cdimascio", "java-dotenv", "5.2.2")
implementation("org.jetbrains.kotlinx", "kotlinx-cli", "0.2.1")
implementation("com.google.apis", "google-api-services-customsearch", "v1-rev20200917-1.31.0")
implementation("net.sf.trove4j", "trove4j", "3.0.3")

// Http
implementation(platform("io.ktor:ktor-bom:1.5.3"))
implementation("io.ktor", "ktor-client")
implementation("io.ktor", "ktor-client-okhttp")
implementation("io.ktor", "ktor-client-serialization-jvm")
implementation("org.jetbrains.kotlinx", "kotlinx-serialization-json", "1.2.1")

// Config
implementation("com.github.uchuhimo.konf", "konf", "master-SNAPSHOT")
implementation("com.fasterxml.jackson.module", "jackson-module-kotlin", "2.12.+")

// Autohelp
implementation("me.schlaubi.autohelp", "kord", "1.2.0-hotifx.1")
implementation("dev.schlaubi.forp", "forp-analyze-client", "1.0-SNAPSHOT")
implementation("com.vladsch.flexmark", "flexmark-html2md-converter", "0.60.2")

// Testing
testImplementation("org.mockito", "mockito-core", "3.8.0")
testImplementation("com.nhaarman.mockitokotlin2", "mockito-kotlin", "2.2.0")
testImplementation("org.junit.jupiter", "junit-jupiter-api", "5.7.1")
testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", "5.7.1")
}

application {
mainClass.set("com.github.devcordde.devcordbot.LauncherKt")
}
// Util
implementation("io.github.cdimascio", "dotenv-kotlin", "6.2.2")
implementation("org.jetbrains.kotlinx", "kotlinx-cli", "0.3.2")
implementation("com.google.apis", "google-api-services-customsearch", "v1-rev20200917-1.31.0")
implementation("net.sf.trove4j", "trove4j", "3.0.3")

// Http
implementation(platform("io.ktor:ktor-bom:1.5.4"))
implementation("io.ktor", "ktor-client")
implementation("io.ktor", "ktor-client-okhttp")
implementation("io.ktor", "ktor-client-serialization-jvm")
implementation("org.jetbrains.kotlinx", "kotlinx-serialization-json", "1.2.1")

// Config
implementation("com.github.uchuhimo.konf", "konf", "master-SNAPSHOT")
implementation("com.fasterxml.jackson.module", "jackson-module-kotlin", "2.12.3")

// Autohelp
implementation("me.schlaubi.autohelp", "kord", "1.2.0-hotifx.1")
implementation("dev.schlaubi.forp", "forp-analyze-client", "1.0-SNAPSHOT")
implementation("com.vladsch.flexmark", "flexmark-html2md-converter", "0.62.2")

// Testing
testImplementation("org.mockito", "mockito-core", "3.8.0")
testImplementation("com.nhaarman.mockitokotlin2", "mockito-kotlin", "2.2.0")
testImplementation("org.junit.jupiter", "junit-jupiter-api", "5.7.1")
testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", "5.7.1")
}

tasks {
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "16"
freeCompilerArgs =
freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn" + "-Xopt-in=dev.kord.common.annotation.KordPreview" + "-Xopt-in=dev.kord.common.annotation.KordExperimental"
}
}
application {
mainClass.set("com.github.devcordde.devcordbot.LauncherKt")
}

test {
useJUnitPlatform()
tasks {
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "16"
freeCompilerArgs =
freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn" + "-Xopt-in=dev.kord.common.annotation.KordPreview" + "-Xopt-in=dev.kord.common.annotation.KordExperimental"
}
}

installDist {
destinationDir = buildDir.resolve("libs/install")
}
test {
useJUnitPlatform()
}

installDist {
destinationDir = buildDir.resolve("libs/install")
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
#
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
8 changes: 4 additions & 4 deletions src/main/kotlin/com/github/devcordde/devcordbot/Launcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ suspend fun main(args: Array<String>) {
fullName = "debug",
description = "Disables HastebinErrorHandler and Sentry"
).default(false)
val logLevelRaw by cliParser.option(
ArgType.Choice(SLF4JLevel.values().map { it.toString() }),
val logLevel by cliParser.option(
ArgType.Choice(SLF4JLevel.values().toList(), SLF4JLevel::valueOf),
shortName = "ll",
fullName = "log-level",
description = "Sets the Logging level of the bot"
).default("INFO")
).default(SLF4JLevel.INFO)
cliParser.parse(args)

val config = Config()
Expand All @@ -69,7 +69,7 @@ suspend fun main(args: Array<String>) {
}

val rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) as Logger
rootLogger.level = Level.valueOf(logLevelRaw)
rootLogger.level = Level.toLevel(logLevel.toInt())

Constants.hastebinUrl = config.hasteHost

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.github.devcordde.devcordbot.command

import com.github.devcordde.devcordbot.command.permission.Permission
import com.github.devcordde.devcordbot.command.root.AbstractRootCommand
import com.github.devcordde.devcordbot.command.root.AbstractSingleCommand
import dev.kord.common.entity.DiscordGuildApplicationCommandPermission
import dev.kord.common.entity.Snowflake

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.github.devcordde.devcordbot.command

import com.github.devcordde.devcordbot.command.context.Context
import com.github.devcordde.devcordbot.command.permission.Permission
import dev.kord.core.behavior.interaction.InteractionResponseBehavior
import dev.kord.rest.builder.interaction.ApplicationCommandCreateBuilder
import dev.kord.rest.builder.interaction.ApplicationCommandsCreateBuilder
import dev.kord.rest.builder.interaction.SubCommandBuilder
Expand Down Expand Up @@ -46,7 +47,9 @@ sealed class AbstractSubCommand(val parent: AbstractCommand) : AbstractCommand()
/**
* Abstract implementation of a slash sub-command.
*/
abstract class Command(parent: AbstractCommand) : AbstractSubCommand(parent) {
abstract class Command<T : InteractionResponseBehavior>(parent: AbstractCommand) :
AbstractSubCommand(parent),
ExecutableCommand<T> {

/**
* Function that is called when building command to add options.
Expand All @@ -58,7 +61,7 @@ sealed class AbstractSubCommand(val parent: AbstractCommand) : AbstractCommand()
* Invokes the command.
* @param context the [Context] in which the command is invoked
*/
abstract suspend fun execute(context: Context)
abstract override suspend fun execute(context: Context<T>)

final override fun ApplicationCommandCreateBuilder.applyCommand() {
subCommand(this@Command.name, this@Command.description) {
Expand All @@ -72,7 +75,7 @@ sealed class AbstractSubCommand(val parent: AbstractCommand) : AbstractCommand()
*/
abstract class Group(parent: AbstractCommand) :
AbstractSubCommand(parent),
CommandRegistry<Command> {
CommandRegistry<Command<*>> {
override fun ApplicationCommandCreateBuilder.applyCommand() {
group(name, description) {
commandAssociations.values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface ErrorHandler {
*/
fun handleException(
exception: Throwable,
context: Context,
context: Context<*>,
thread: Thread,
coroutineContext: CoroutineContext? = null
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2021 Daniel Scherf & Michael Rittmeister & Julian König
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.github.devcordde.devcordbot.command

import com.github.devcordde.devcordbot.command.context.Context
import dev.kord.core.behavior.interaction.InteractionResponseBehavior
import dev.kord.core.entity.interaction.Interaction
import dev.kord.core.event.interaction.InteractionCreateEvent

/**
* Command that can be executed (non groups, sub commands, single commands)
*
* @param T the [InteractionResponseBehavior] produced by this commands acknowledgement (See [acknowledge])
*/
interface ExecutableCommand<T : InteractionResponseBehavior> {
/**
* Function acknowledging the [InteractionCreateEvent].
*
* @see Interaction.ackowledgePublic
* @see Interaction.acknowledgeEphemeral
*/
suspend fun InteractionCreateEvent.acknowledge(): T

/**
* Executes the command logic.
*
* @see Context
*/
suspend fun execute(context: Context<T>)
}
Loading