-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store | ||
|
||
**/.test-env |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
plugins { | ||
alias(libs.plugins.ksp) | ||
alias(libs.plugins.kotlin.jvm) | ||
alias(libs.plugins.mikbot) | ||
} | ||
|
||
dependencies { | ||
implementation(projects.common) | ||
plugin(libs.mikbot.ktor) | ||
} | ||
|
||
mikbotPlugin { | ||
provider = "Schlaubi" | ||
pluginId = "tonbrett" | ||
license = "MIT" | ||
} | ||
|
||
tasks { | ||
installBot { | ||
botVersion = "3.17.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package dev.schlaubi.tonbrett.bot | ||
|
||
import com.kotlindiscord.kord.extensions.builders.ExtensibleBotBuilder | ||
import dev.schlaubi.mikbot.plugin.api.Plugin | ||
import dev.schlaubi.mikbot.plugin.api.PluginContext | ||
import dev.schlaubi.mikbot.plugin.api.PluginMain | ||
import dev.schlaubi.mikbot.plugin.api.module.MikBotModule | ||
import dev.schlaubi.tonbrett.bot.commands.addSoundCommand | ||
|
||
@PluginMain | ||
class Plugin(context: PluginContext) : Plugin(context) { | ||
override fun ExtensibleBotBuilder.ExtensionsBuilder.addExtensions() { | ||
add(::Module) | ||
} | ||
} | ||
|
||
private class Module(context: PluginContext) : MikBotModule(context) { | ||
override val name: String = "tonbrett" | ||
override val bundle: String = "soundboard" | ||
|
||
override suspend fun setup() { | ||
addSoundCommand() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package dev.schlaubi.tonbrett.bot.commands | ||
|
||
import com.kotlindiscord.kord.extensions.commands.Arguments | ||
import com.kotlindiscord.kord.extensions.commands.converters.impl.attachment | ||
import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalEmoji | ||
import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalString | ||
import com.kotlindiscord.kord.extensions.commands.converters.impl.string | ||
import com.kotlindiscord.kord.extensions.extensions.Extension | ||
import com.kotlindiscord.kord.extensions.extensions.ephemeralSlashCommand | ||
import com.kotlindiscord.kord.extensions.types.respond | ||
import dev.schlaubi.mikbot.plugin.api.util.kord | ||
import dev.schlaubi.tonbrett.bot.config.Config | ||
import dev.schlaubi.tonbrett.bot.io.SoundBoardDatabase | ||
import dev.schlaubi.tonbrett.common.Sound | ||
import io.ktor.client.call.* | ||
import io.ktor.client.request.* | ||
import io.ktor.http.* | ||
import org.litote.kmongo.newId | ||
import java.nio.file.StandardOpenOption | ||
import kotlin.io.path.absolutePathString | ||
import kotlin.io.path.div | ||
import kotlin.io.path.writeBytes | ||
|
||
class AddSoundCommandArgs : Arguments() { | ||
val sound by attachment { | ||
name = "attachment" | ||
description = "commands.add_sound.arguments.attachment.description" | ||
} | ||
|
||
val name by string { | ||
name = "name" | ||
description = "commands.add_sound.arguments.name.description" | ||
} | ||
|
||
val description by optionalString { | ||
name = "description" | ||
description = "commands.add_sound.arguments.description.description" | ||
} | ||
|
||
val emoji by optionalEmoji { | ||
name = "emoji" | ||
description = "commands.add_sound.arguments.emoji.description" | ||
} | ||
} | ||
|
||
suspend fun Extension.addSoundCommand() = ephemeralSlashCommand(::AddSoundCommandArgs) { | ||
name = "add-sound" | ||
description = "commands.add_sound.description" | ||
|
||
action { | ||
val id = newId<Sound>() | ||
val cdnResponse = kord.resources.httpClient.get(arguments.sound.proxyUrl) | ||
if (!cdnResponse.status.isSuccess()) { | ||
respond { | ||
content = translate("commands.add_sound.invalid_cdn_response", arrayOf(cdnResponse.status)) | ||
} | ||
return@action | ||
} | ||
val sound = Sound(id, arguments.name, user.id, arguments.description, null) | ||
val file = Config.SOUNDS_FOLDER / sound.fileName | ||
file.writeBytes(cdnResponse.body(), StandardOpenOption.CREATE) | ||
SoundBoardDatabase.sounds.save(sound) | ||
|
||
respond { | ||
content = translate("commands.add_sound.success") | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package dev.schlaubi.tonbrett.bot.config | ||
|
||
import dev.schlaubi.mikbot.plugin.api.EnvironmentConfig | ||
import kotlin.io.path.Path | ||
|
||
object Config : EnvironmentConfig() { | ||
val SOUNDS_FOLDER by getEnv(Path("sounds"), transform = ::Path) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package dev.schlaubi.tonbrett.bot.io | ||
|
||
import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent | ||
import dev.schlaubi.mikbot.plugin.api.io.getCollection | ||
import dev.schlaubi.mikbot.plugin.api.util.database | ||
import dev.schlaubi.tonbrett.common.Sound | ||
|
||
object SoundBoardDatabase : KordExKoinComponent { | ||
val sounds = database.getCollection<Sound>("sounds") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.schlaubi.tonbrett.bot.server | ||
|
||
import io.ktor.server.routing.* | ||
|
||
fun Route.files() { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package dev.schlaubi.tonbrett.bot.util | ||
|
||
import dev.kord.core.entity.GuildEmoji | ||
import dev.schlaubi.tonbrett.common.Sound | ||
|
||
fun GuildEmoji.toEmoji(): Sound.Emoji = Sound.GuildEmoji(mention) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
commands.add_sound.description=Adds a new sound | ||
commands.add_sound.arguments.attachment.description=The audio file you want to add | ||
commands.add_sound.arguments.name.description=The name of the sound | ||
commands.add_sound.arguments.emoji.description=An emoji to identify the sound | ||
commands.add_sound.arguments.description.description=An optional description | ||
commands.add_sound.success=Successfully added sound. | ||
commands.add_sound.invalid_cdn_response=CDN responded with unexpected error code: `{0}`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
allprojects { | ||
group = "dev.schlaubi" | ||
version = "1.0-SNAPSHOT" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
plugins { | ||
alias(libs.plugins.kotlin.multiplatform) | ||
alias(libs.plugins.kotlin.serialization) | ||
} | ||
|
||
kotlin { | ||
explicitApi() | ||
|
||
jvm() | ||
js(IR) { | ||
browser() | ||
} | ||
|
||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
api(libs.kotlinx.serialization) | ||
api(libs.ktor.resources) | ||
} | ||
} | ||
|
||
named("jvmMain") { | ||
dependencies { | ||
implementation(libs.kmongo.id.serialization) | ||
implementation(libs.kord.common) | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package dev.schlaubi.tonbrett.common | ||
|
||
/** | ||
* Multiplatform MongoDB Id. | ||
*/ | ||
public expect interface Id<T> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dev.schlaubi.tonbrett.common | ||
|
||
import io.ktor.resources.* | ||
|
||
@Resource("/soundboard") | ||
public class Route { | ||
@Resource("audio/{audioId}") | ||
public data class Audio(val audioId: String, val parent: Route = Route()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dev.schlaubi.tonbrett.common | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* Multiplatform snowflake. | ||
* | ||
* @property value the Snowflake as a [ULong] | ||
*/ | ||
public expect class Snowflake(value: ULong) { | ||
public val value: ULong | ||
} |