refactor: Completely changed the API and a working argument
This commit is contained in:
parent
690812b628
commit
411e183e04
19 changed files with 244 additions and 199 deletions
|
@ -2,9 +2,8 @@ package io.github.null2264.tsukumogami.bot
|
|||
|
||||
import co.touchlab.kermit.Logger
|
||||
import io.github.null2264.tsukumogami.bot.core.di.appModule
|
||||
import io.github.null2264.tsukumogami.bot.core.module.DeveloperModule
|
||||
import io.github.null2264.tsukumogami.bot.core.module.GeneralModule
|
||||
import io.github.null2264.tsukumogami.bot.core.Bot
|
||||
import io.github.null2264.tsukumogami.bot.core.module.generalModule
|
||||
import io.github.null2264.tsukumogami.core.bot
|
||||
import org.koin.core.context.GlobalContext.startKoin
|
||||
|
||||
suspend fun main() {
|
||||
|
@ -13,13 +12,13 @@ suspend fun main() {
|
|||
modules(appModule)
|
||||
}
|
||||
|
||||
Bot {
|
||||
bot {
|
||||
Logger.setTag("Tsukumogami")
|
||||
|
||||
token = System.getenv("DISCORD_TOKEN")
|
||||
|
||||
prefixes("src!", "mm!") // mm! for backwards compatibility
|
||||
|
||||
extensions(::DeveloperModule, ::GeneralModule)
|
||||
modules(generalModule)
|
||||
}.start()
|
||||
}
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
package io.github.null2264.tsukumogami.bot.core
|
||||
|
||||
import io.github.null2264.tsukumogami.core.AbstractBot
|
||||
import io.github.null2264.tsukumogami.core.BotConfigurator
|
||||
|
||||
class Bot(block: BotConfigurator.() -> Unit = {}) : AbstractBot(block)
|
|
@ -1,17 +1,13 @@
|
|||
package io.github.null2264.tsukumogami.bot.core.module
|
||||
|
||||
import io.github.null2264.tsukumogami.core.commands.annotation.Command
|
||||
import io.github.null2264.tsukumogami.core.Context
|
||||
import io.github.null2264.tsukumogami.core.module.BotModule
|
||||
|
||||
class DeveloperModule : BotModule("Developer", "Only for developers") {
|
||||
|
||||
@Command(
|
||||
name="poweroff",
|
||||
description="Turn the bot off",
|
||||
)
|
||||
private suspend fun shutdown(ctx: Context) {
|
||||
ctx.reply("Shutting Down...", mentionsAuthor = true)
|
||||
bot?.stop()
|
||||
}
|
||||
}
|
||||
//class DeveloperModule : BotModule("Developer", "Only for developers") {
|
||||
//
|
||||
// @Command(
|
||||
// name="poweroff",
|
||||
// description="Turn the bot off",
|
||||
// )
|
||||
// private suspend fun shutdown(ctx: Context) {
|
||||
// ctx.reply("Shutting Down...", mentionsAuthor = true)
|
||||
// bot?.stop()
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,23 +1,20 @@
|
|||
package io.github.null2264.tsukumogami.bot.core.module
|
||||
|
||||
import dev.kord.core.entity.effectiveName
|
||||
import io.github.null2264.tsukumogami.core.commands.annotation.Command
|
||||
import io.github.null2264.tsukumogami.core.Context
|
||||
import io.github.null2264.tsukumogami.core.module.BotModule
|
||||
import io.github.null2264.tsukumogami.bot.core.module.arguments.TestArguments
|
||||
import io.github.null2264.tsukumogami.core.module.api.botModules
|
||||
import kotlinx.datetime.Clock
|
||||
|
||||
class GeneralModule : BotModule("General", "idk") {
|
||||
|
||||
@Command(description = "Ping the bot!")
|
||||
private suspend fun ping(ctx: Context) {
|
||||
val generalModule = botModules("General") {
|
||||
commands("ping", description = "Ping the bot!") { ctx ->
|
||||
val startTime = Clock.System.now()
|
||||
ctx.typing()
|
||||
val endTime = Clock.System.now()
|
||||
ctx.send("Pong! ${endTime.toEpochMilliseconds() - startTime.toEpochMilliseconds()}ms")
|
||||
}
|
||||
|
||||
@Command("test")
|
||||
private suspend fun differentName(ctx: Context) {
|
||||
ctx.send("Hello World! ${ctx.author?.effectiveName}")
|
||||
groups("group") {
|
||||
commands("test", arguments = ::TestArguments) { ctx, args -> ctx.send("Hello world ${args.test}") }
|
||||
}
|
||||
|
||||
commands("test", arguments = ::TestArguments) { ctx, args -> ctx.send("Hello world ${args.test}") }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue