Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stage: add slash commands #6

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 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
6 changes: 6 additions & 0 deletions .idea/GradleUpdaterPlugin.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Our command system is based on [BankoBot](https://github.com/bankobotv14/BankoBot) and is used with permission
76 changes: 50 additions & 26 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
@file:Suppress("GradlePackageUpdate")

plugins {
application
id("com.google.cloud.tools.jib") version "2.8.0"
kotlin("jvm") version "1.5.0"
kotlin("kapt") version "1.5.0"
kotlin("plugin.serialization") version "1.5.0"
id("com.google.cloud.tools.jib") version "3.1.4"
kotlin("jvm") version "1.5.30"
kotlin("kapt") version "1.5.30"
kotlin("plugin.serialization") version "1.5.30"
}

group = "to.rxs"
version = "1.0-SNAPSHOT"

repositories {
maven("https://oss.sonatype.org/content/repositories/snapshots") // kord.x
maven("https://schlaubi.jfrog.io/artifactory/envconf/")
mavenCentral()
}

dependencies {
runtimeOnly(kotlin("scripting-jsr223"))

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

implementation("org.jetbrains.kotlinx", "kotlinx-serialization-core", "1.2.0")
implementation("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8", "1.5.1")
implementation("org.jetbrains.kotlinx", "kotlinx-serialization-json", "1.2.2")

implementation("io.github.pdvrieze.xmlutil", "core-jvm", "0.81.2")
implementation("io.github.pdvrieze.xmlutil", "serialization-jvm", "0.81.2")
Expand All @@ -28,51 +30,73 @@ dependencies {
implementation("org.apache.logging.log4j", "log4j-slf4j18-impl", "2.14.1")
implementation("org.apache.logging.log4j", "log4j-core", "2.14.1")

implementation("org.jetbrains.exposed", "exposed-core", "0.30.1")
implementation("org.jetbrains.exposed", "exposed-dao", "0.30.1")
implementation("org.jetbrains.exposed", "exposed-jdbc", "0.30.1")
implementation("org.postgresql", "postgresql", "42.2.19")
implementation("com.zaxxer", "HikariCP", "4.0.3")
implementation("org.jetbrains.exposed", "exposed-core", "0.33.1")
implementation("org.jetbrains.exposed", "exposed-dao", "0.33.1")
implementation("org.jetbrains.exposed", "exposed-jdbc", "0.33.1")
implementation("org.postgresql", "postgresql", "42.2.23")
implementation("com.zaxxer", "HikariCP", "5.0.0")

implementation("org.xerial", "sqlite-jdbc", "3.34.0")
implementation("org.xerial", "sqlite-jdbc", "3.36.0.1")

implementation("io.ktor", "ktor-server-netty", "1.5.3")
implementation("io.ktor", "ktor-serialization", "1.5.3")
implementation(platform("io.ktor:ktor-bom:1.6.3"))
implementation("io.ktor", "ktor-server-netty")
implementation("io.ktor", "ktor-serialization")

implementation("dev.kord", "kord-core", "kotlin-1.5-20210505.195343-2") {
version {
strictly("kotlin-1.5-20210505.195343-2")
}
}
implementation("dev.kord", "kord-core", "0.8.0-M5")

implementation("dev.kord.x", "emoji", "0.5.0-SNAPSHOT")

implementation("dev.kord.x", "commands-runtime-kord", "0.4.0-SNAPSHOT")
kapt("dev.kord.x", "commands-processor", "0.4.0-SNAPSHOT")

implementation("org.jetbrains.kotlinx", "kotlinx-datetime", "0.1.1")
implementation("org.jetbrains.kotlinx", "kotlinx-datetime", "0.2.1")
implementation("dev.schlaubi", "envconf", "1.1")

implementation(kotlin("reflect"))

testCompileOnly("junit", "junit", "4.13.2")
}

application {
mainClass.value("to.rxs.kommunity.LauncherKt")
}

kotlin {
kotlinDaemonJvmArgs = listOf(
"-Dfile.encoding=UTF-8",
"--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
)
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(16))
}
}

tasks {
compileKotlin {
kotlinOptions {
jvmTarget = "15"
jvmTarget = "16"
freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn"
}
}

}

kapt {
includeCompileClasspath = false
}

jib {
from {
image = "openjdk:15"
image = "adoptopenjdk/openjdk16-openj9:debian-jre"
}

to {
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
kotlin.code.style=official
# See Kapt issue: https://youtrack.jetbrains.com/issue/KT-45545
kapt.use.worker.api=false
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
42 changes: 27 additions & 15 deletions src/main/kotlin/to/rxs/kommunity/Config.kt
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
package to.rxs.kommunity

import dev.kord.common.entity.Snowflake
import org.apache.logging.log4j.Level
import to.rxs.kommunity.util.EnvironmentConfig
import dev.schlaubi.envconf.Config as EnvironmentConfig

object Config : EnvironmentConfig("") {

val GAMES by getEnv { it.split("|") }
val PREFIX by getEnv()
val DATABASE_ACTIVE by getEnv()
val POSTGRES_URL by getEnv()
val POSTGRES_USERNAME by getEnv()
val POSTGRES_PASSWORD by getEnv()
val PREFIX by environment
val DATABASE_ACTIVE by environment
val POSTGRES_URL by environment
val POSTGRES_USERNAME by environment
val POSTGRES_PASSWORD by environment
val ENVIRONMENT by getEnv { Environment.valueOf(it) }
val LOG_LEVEL by getEnv { Level.valueOf(it) }
val DISCORD_TOKEN by getEnv()
val DISCORD_TOKEN by environment
val NOTIFICATION_SERVER_PORT by getEnv(1337) { it.toInt() }
val GUILD_ID by getEnv()
val SERVER_NEWS_ROLE by getEnv()
val VIDEO_NEWS_ROLE by getEnv()
val STREAM_NEWS_ROLE by getEnv()
val GUILD_ID by getEnv { Snowflake(it) }
val ROLES by getEnv { createRolesMap(it) }
val SERVER_NEWS_ROLE by environment
val ADMIN_ROLE by getEnv { Snowflake(it) }
val VIDEO_NEWS_ROLE by environment
val STREAM_NEWS_ROLE by environment
val OPT_OUT_ROLES = listOf(SERVER_NEWS_ROLE, VIDEO_NEWS_ROLE, STREAM_NEWS_ROLE)
val NEWS_CHANNEL by getEnv()
val VIDEOS_CHANNEL by getEnv()
val STREAMS_CHANNEL by getEnv()
val WELCOME_CHANNEL by getEnv()
val NEWS_CHANNEL by environment
val VIDEOS_CHANNEL by environment
val STREAMS_CHANNEL by environment
val WELCOME_CHANNEL by environment

}

enum class Environment {
DEVELOPMENT,
PRODUCTION
}

@OptIn(ExperimentalStdlibApi::class)
fun createRolesMap(env: String): Map<String, Snowflake> {
return env.split(",")
.associateBy {
it.substringBefore(':')
}
.mapValues { Snowflake(it.value.substringBefore(':')) }
}
14 changes: 12 additions & 2 deletions src/main/kotlin/to/rxs/kommunity/Kommunity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ import dev.kord.core.event.gateway.ReadyEvent
import dev.kord.core.on
import dev.kord.gateway.Intents
import dev.kord.gateway.PrivilegedIntent
import dev.kord.x.commands.kord.bot
import dev.kord.x.commands.kord.model.prefix.kord
import dev.kord.x.commands.kord.model.prefix.mention
import dev.kord.x.commands.kord.model.processor.KordProcessorBuilder
import dev.kord.x.commands.model.prefix.literal
import dev.kord.x.commands.model.prefix.or
import kapt.kotlin.generated.configure
import kotlinx.coroutines.launch
import mu.KotlinLogging
import to.rxs.kommunity.command.slashcommands.InteractionEventSource
import to.rxs.kommunity.command.slashcommands.slashCommands
import to.rxs.kommunity.command.slashcommands.updateSlashCommands
import to.rxs.kommunity.core.GameAnimator
import to.rxs.kommunity.io.connect
import to.rxs.kommunity.listeners.joinListener
import to.rxs.kommunity.listeners.selfMentionListener
import to.rxs.kommunity.util.bot
import to.rxs.kommunity.youtube.CallbackServer
import to.rxs.kommunity.youtube.YoutubeEventListener

Expand Down Expand Up @@ -44,13 +48,15 @@ class Kommunity {
}

private suspend fun initialize() {
bot(kord) {
val configureBot: suspend KordProcessorBuilder.() -> Unit = {
configure()

prefix {
kord { literal(Config.PREFIX) or mention() }
}

slashCommands()

kord.apply {
selfMentionListener()
joinListener()
Expand All @@ -59,6 +65,10 @@ class Kommunity {
}
}
}

bot(kord, configureBot) {
updateSlashCommands(kord)
}
}

private suspend fun start() {
Expand Down
Loading