mirai-console-jcc-plugin/src/main/kotlin/JccCommand.kt
筱傑 8c3c316d5d 移除 第三方Json解析库,使用Mirai自带库
增加 获取代码模板功能
2021-08-02 22:51:22 +08:00

36 lines
1.2 KiB
Kotlin

import JCC.CMD_PREFIX
import net.mamoe.mirai.console.command.CommandSender
import net.mamoe.mirai.console.command.CompositeCommand
object JccCommand : CompositeCommand(
JCC, "jcc",
description = "在线编译器集合"
) {
@SubCommand
@Description("列出所有支持的编程语言")
suspend fun CommandSender.list() {
try {
sendMessage(GlotAPI.listLanguages().joinToString { it.name })
} catch (e: Exception) {
sendMessage("执行失败\n${e.message}")
JCC.logger.warning(e)
}
}
@SubCommand
@Description("帮助")
suspend fun CommandSender.help() {
sendMessage("直接调用${CMD_PREFIX}即可运行代码\n例如:${CMD_PREFIX} python print(\"Hello world\")\n其它指令:\n$usage")
}
@SubCommand
@Description("获取指定语言的模板")
suspend fun CommandSender.template(language: String) {
if (!GlotAPI.checkSupport(language)) {
sendMessage("不支持该语言,请使用/jcc list列出所有支持的编程语言")
return
}
val file = GlotAPI.getTemplateFile(language)
sendMessage("$CMD_PREFIX $language\n" + file.content)
}
}