feat: add compiler and format class dir
This commit is contained in:
23 files changed
+128
-68
No files matched your search
@@ -8,10 +8,25 @@
|
||||
package cn.rtast.fancybot
|
||||
|
||||
import cn.rtast.fancybot.commands.*
|
||||
import cn.rtast.fancybot.commands.misc.BVParseCommand
|
||||
import cn.rtast.fancybot.commands.misc.GitHubParseCommand
|
||||
import cn.rtast.fancybot.commands.misc.ImageURLCommand
|
||||
import cn.rtast.fancybot.commands.misc.ReverseGIFCommand
|
||||
import cn.rtast.fancybot.commands.CompilerCommand
|
||||
import cn.rtast.fancybot.commands.lookup.CigaretteCommand
|
||||
import cn.rtast.fancybot.commands.lookup.MCPingCommand
|
||||
import cn.rtast.fancybot.commands.lookup.MusicCommand
|
||||
import cn.rtast.fancybot.commands.lookup.NslookupCommand
|
||||
import cn.rtast.fancybot.commands.lookup.PixivCommand
|
||||
import cn.rtast.fancybot.commands.lookup.QRCodeCommand
|
||||
import cn.rtast.fancybot.commands.lookup.WeatherCommand
|
||||
import cn.rtast.fancybot.commands.parse.BVParseCommand
|
||||
import cn.rtast.fancybot.commands.parse.GitHubParseCommand
|
||||
import cn.rtast.fancybot.commands.parse.ImageURLCommand
|
||||
import cn.rtast.fancybot.commands.parse.ReverseGIFCommand
|
||||
import cn.rtast.fancybot.commands.record.JiJianCommand
|
||||
import cn.rtast.fancybot.commands.record.JrrpCommand
|
||||
import cn.rtast.fancybot.commands.record.MyNiuziCommand
|
||||
import cn.rtast.fancybot.commands.record.MyPointCommand
|
||||
import cn.rtast.fancybot.commands.record.NiuziSignCommand
|
||||
import cn.rtast.fancybot.commands.record.RedeemCommand
|
||||
import cn.rtast.fancybot.commands.record.SignCommand
|
||||
import cn.rtast.fancybot.entity.bili.CardShare
|
||||
import cn.rtast.fancybot.entity.enums.WSType
|
||||
import cn.rtast.fancybot.items.BaisiItem
|
||||
@@ -129,7 +144,7 @@ val commands = listOf(
|
||||
RUACommand(), NslookupCommand(),
|
||||
NiuziSignCommand(), MyNiuziCommand(),
|
||||
JiJianCommand(), LikeMeCommand(),
|
||||
KotlinCCommand()
|
||||
CompilerCommand()
|
||||
)
|
||||
|
||||
suspend fun main() {
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright © 2024 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2024/9/12
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands
|
||||
|
||||
import cn.rtast.fancybot.entity.compiler.GLOTPayload
|
||||
import cn.rtast.fancybot.entity.compiler.GLOTResponse
|
||||
import cn.rtast.fancybot.entity.compiler.KCSPayload
|
||||
import cn.rtast.fancybot.entity.compiler.KCSResponse
|
||||
import cn.rtast.fancybot.util.Http
|
||||
import cn.rtast.fancybot.util.str.toJson
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.util.BaseCommand
|
||||
import cn.rtast.rob.util.ob.MessageChain
|
||||
import cn.rtast.rob.util.ob.OBMessage
|
||||
|
||||
class CompilerCommand : BaseCommand() {
|
||||
override val commandNames = listOf("/compiler", "/exec")
|
||||
|
||||
private val kotlinCompilerServer = "https://api.kotlinlang.org/api/2.0.20/compiler/run"
|
||||
private val glotCompilerServer = "https://glot.io/run"
|
||||
|
||||
override suspend fun executeGroup(listener: OBMessage, message: GroupMessage, args: List<String>) {
|
||||
if (args.isEmpty()) {
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addText("使用`/exec` <语言> <代码> 即可执行~")
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
return
|
||||
}
|
||||
val language = args.first()
|
||||
val code = args.drop(1).joinToString(" ")
|
||||
val response = when (language) {
|
||||
"kotlin", "Kotlin", "kt", "Kt", "KT" -> {
|
||||
Http.post<KCSResponse>(
|
||||
kotlinCompilerServer, jsonBody = KCSPayload(listOf(KCSPayload.File(code))).toJson()
|
||||
).text
|
||||
}
|
||||
|
||||
else -> {
|
||||
Http.post<GLOTResponse>(
|
||||
"$glotCompilerServer/$language",
|
||||
params = mapOf("version" to "latest"),
|
||||
jsonBody = GLOTPayload(listOf(GLOTPayload.File(code))).toJson()
|
||||
).stdout
|
||||
}
|
||||
}
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addText("执行结果如下:")
|
||||
.addNewLine()
|
||||
.addText(response.replace("<outStream>", "").replace("</outStream>", ""))
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2024 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2024/9/12
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands
|
||||
|
||||
import cn.rtast.fancybot.entity.kcs.KCSPayload
|
||||
import cn.rtast.fancybot.entity.kcs.KCSResponse
|
||||
import cn.rtast.fancybot.util.Http
|
||||
import cn.rtast.fancybot.util.str.toJson
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.util.BaseCommand
|
||||
import cn.rtast.rob.util.ob.MessageChain
|
||||
import cn.rtast.rob.util.ob.OBMessage
|
||||
|
||||
class KotlinCCommand : BaseCommand() {
|
||||
override val commandNames = listOf("/kotlinc", "/ktc")
|
||||
|
||||
private val kotlinCompilerServer = "https://api.kotlinlang.org/api/2.0.20/compiler/run"
|
||||
|
||||
override suspend fun executeGroup(listener: OBMessage, message: GroupMessage, args: List<String>) {
|
||||
if (args.isEmpty()) {
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addText("使用`/ktc` <code>传入Kotlin代码即可执行~")
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
return
|
||||
}
|
||||
val code = args.joinToString(" ")
|
||||
val response = Http.post<KCSResponse>(
|
||||
kotlinCompilerServer, jsonBody = KCSPayload(listOf(KCSPayload.File(code))).toJson()
|
||||
)
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addText("执行结果如下:")
|
||||
.addNewLine()
|
||||
.addText(response.text.replace("</outStream>", "").replace("<outStream>", ""))
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands
|
||||
package cn.rtast.fancybot.commands.lookup
|
||||
|
||||
import cn.rtast.fancybot.entity.cigarette.Cigarette
|
||||
import cn.rtast.fancybot.util.Http
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands
|
||||
package cn.rtast.fancybot.commands.lookup
|
||||
|
||||
import cn.rtast.fancybot.entity.MCPing
|
||||
import cn.rtast.fancybot.util.str.fromJson
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands
|
||||
package cn.rtast.fancybot.commands.lookup
|
||||
|
||||
import cn.rtast.fancybot.configManager
|
||||
import cn.rtast.fancybot.entity.music.Search
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands
|
||||
package cn.rtast.fancybot.commands.lookup
|
||||
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.util.BaseCommand
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands
|
||||
package cn.rtast.fancybot.commands.lookup
|
||||
|
||||
import cn.rtast.fancybot.entity.pixiv.Ranking
|
||||
import cn.rtast.fancybot.util.Http
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands
|
||||
package cn.rtast.fancybot.commands.lookup
|
||||
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.util.BaseCommand
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands
|
||||
package cn.rtast.fancybot.commands.lookup
|
||||
|
||||
import cn.rtast.fancybot.configManager
|
||||
import cn.rtast.fancybot.entity.weather.Geo
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands.misc
|
||||
package cn.rtast.fancybot.commands.parse
|
||||
|
||||
import cn.rtast.fancybot.entity.bili.BVID
|
||||
import cn.rtast.fancybot.util.Http
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands.misc
|
||||
package cn.rtast.fancybot.commands.parse
|
||||
|
||||
import cn.rtast.fancybot.configManager
|
||||
import cn.rtast.fancybot.entity.github.RepoInfo
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands.misc
|
||||
package cn.rtast.fancybot.commands.parse
|
||||
|
||||
import cn.rtast.rob.entity.GetMessage
|
||||
import cn.rtast.rob.enums.ArrayMessageType
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands.misc
|
||||
package cn.rtast.fancybot.commands.parse
|
||||
|
||||
import cn.rtast.fancybot.util.str.encodeToBase64
|
||||
import cn.rtast.rob.entity.GetMessage
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands
|
||||
package cn.rtast.fancybot.commands.record
|
||||
|
||||
import cn.rtast.fancybot.util.file.JrrpManager
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands
|
||||
package cn.rtast.fancybot.commands.record
|
||||
|
||||
import cn.rtast.fancybot.ADMINS
|
||||
import cn.rtast.fancybot.signManager
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands
|
||||
package cn.rtast.fancybot.commands.record
|
||||
|
||||
import cn.rtast.fancybot.niuziManager
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands
|
||||
package cn.rtast.fancybot.commands.record
|
||||
|
||||
import cn.rtast.fancybot.itemManager
|
||||
import cn.rtast.fancybot.signManager
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands
|
||||
package cn.rtast.fancybot.commands.record
|
||||
|
||||
import cn.rtast.fancybot.signManager
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright © 2024 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2024/9/13
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.entity.compiler
|
||||
|
||||
data class GLOTPayload(
|
||||
val files: List<File>
|
||||
) {
|
||||
data class File(
|
||||
val content: String,
|
||||
val name: String = "main"
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright © 2024 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2024/9/13
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.entity.compiler
|
||||
|
||||
data class GLOTResponse(
|
||||
val stdout: String,
|
||||
)
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.entity.kcs
|
||||
package cn.rtast.fancybot.entity.compiler
|
||||
|
||||
data class KCSPayload(
|
||||
val files: List<File>,
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.entity.kcs
|
||||
package cn.rtast.fancybot.entity.compiler
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
Reference in New Issue
Block a user