2024-10-14 17:40:04 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2024 RTAkland
|
|
|
|
|
* Author: RTAkland
|
|
|
|
|
* Date: 2024/10/14
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package cn.rtast.fancybot.commands.misc
|
|
|
|
|
|
|
|
|
|
import cn.rtast.fancybot.API_RTAST_URL
|
2024-10-15 11:13:54 +08:00
|
|
|
import cn.rtast.fancybot.PBI_API_URL
|
2024-10-14 17:40:04 +08:00
|
|
|
import cn.rtast.fancybot.annotations.CommandDescription
|
|
|
|
|
import cn.rtast.fancybot.configManager
|
|
|
|
|
import cn.rtast.fancybot.entity.pastebin.PastebinPayload
|
|
|
|
|
import cn.rtast.fancybot.entity.pastebin.PastebinResponse
|
2024-10-14 17:43:26 +08:00
|
|
|
import cn.rtast.fancybot.enums.CommandAction
|
2024-10-14 17:40:04 +08:00
|
|
|
import cn.rtast.fancybot.util.Http
|
2024-10-14 17:43:26 +08:00
|
|
|
import cn.rtast.fancybot.util.file.insertActionRecord
|
2024-10-14 17:40:04 +08:00
|
|
|
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.OneBotListener
|
|
|
|
|
|
|
|
|
|
@CommandDescription("Pastebin!")
|
|
|
|
|
class PastebinCommand : BaseCommand() {
|
|
|
|
|
override val commandNames = listOf("/pastebin", "/pb")
|
|
|
|
|
|
2024-10-14 22:41:01 +08:00
|
|
|
companion object {
|
2024-10-15 11:13:54 +08:00
|
|
|
fun createPastebin(content: String): String {
|
2024-10-14 22:41:01 +08:00
|
|
|
val pastebinPayload = PastebinPayload(content)
|
|
|
|
|
val response = Http.post<PastebinResponse>(
|
|
|
|
|
"$API_RTAST_URL/api/pastebin", pastebinPayload.toJson(),
|
|
|
|
|
params = mapOf("key" to configManager.apiRtastKey)
|
|
|
|
|
)
|
2024-10-15 11:13:54 +08:00
|
|
|
return "$PBI_API_URL/-/${response.id}"
|
2024-10-14 22:41:01 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-14 17:40:04 +08:00
|
|
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
|
|
|
|
val content = args.joinToString(" ")
|
2024-10-15 11:13:54 +08:00
|
|
|
message.reply(createPastebin(content))
|
2024-10-14 17:43:26 +08:00
|
|
|
insertActionRecord(CommandAction.Pastebin, message.sender.userId, content)
|
2024-10-14 17:40:04 +08:00
|
|
|
}
|
|
|
|
|
}
|