feat: add short link command

This commit is contained in:
2024-09-22 14:14:24 +08:00
parent c3dd7a3e0b
commit b12151cec4
3 files changed
+49 -2

No files matched your search

@@ -11,9 +11,9 @@ import cn.rtast.fancybot.commands.AboutCommand
import cn.rtast.fancybot.commands.EchoCommand import cn.rtast.fancybot.commands.EchoCommand
import cn.rtast.fancybot.commands.HelpCommand import cn.rtast.fancybot.commands.HelpCommand
import cn.rtast.fancybot.commands.StatusCommand import cn.rtast.fancybot.commands.StatusCommand
import cn.rtast.fancybot.commands.lookup.AICommand
import cn.rtast.fancybot.commands.lookup.CigaretteCommand import cn.rtast.fancybot.commands.lookup.CigaretteCommand
import cn.rtast.fancybot.commands.lookup.DomainPriceCommand import cn.rtast.fancybot.commands.lookup.DomainPriceCommand
import cn.rtast.fancybot.commands.lookup.AICommand
import cn.rtast.fancybot.commands.lookup.GithubUserCommand import cn.rtast.fancybot.commands.lookup.GithubUserCommand
import cn.rtast.fancybot.commands.lookup.MCPingCommand import cn.rtast.fancybot.commands.lookup.MCPingCommand
import cn.rtast.fancybot.commands.lookup.MusicCommand import cn.rtast.fancybot.commands.lookup.MusicCommand
@@ -46,6 +46,7 @@ import cn.rtast.fancybot.commands.record.MyNiuziCommand
import cn.rtast.fancybot.commands.record.MyPointCommand import cn.rtast.fancybot.commands.record.MyPointCommand
import cn.rtast.fancybot.commands.record.NiuziSignCommand import cn.rtast.fancybot.commands.record.NiuziSignCommand
import cn.rtast.fancybot.commands.record.RedeemCommand import cn.rtast.fancybot.commands.record.RedeemCommand
import cn.rtast.fancybot.commands.record.ShortLinkCommand
import cn.rtast.fancybot.commands.record.SignCommand import cn.rtast.fancybot.commands.record.SignCommand
import cn.rtast.fancybot.entity.bili.CardShare import cn.rtast.fancybot.entity.bili.CardShare
import cn.rtast.fancybot.entity.enums.WSType import cn.rtast.fancybot.entity.enums.WSType
@@ -223,7 +224,7 @@ val commands = listOf(
SendMailCommand(), ZiBiCommand(), SendMailCommand(), ZiBiCommand(),
UnsetZiBiCommand(), WikipediaCommand(), UnsetZiBiCommand(), WikipediaCommand(),
AsciiArtCommand(), StatusCommand(), AsciiArtCommand(), StatusCommand(),
JueCommand() JueCommand(), ShortLinkCommand()
) )
val START_UP_TIME = Instant.now().epochSecond val START_UP_TIME = Instant.now().epochSecond
@@ -0,0 +1,34 @@
/*
* Copyright © 2024 RTAkland
* Author: RTAkland
* Date: 2024/9/22
*/
package cn.rtast.fancybot.commands.record
import cn.rtast.fancybot.entity.ShortLink
import cn.rtast.fancybot.util.Http
import cn.rtast.fancybot.util.str.encodeToBase64
import cn.rtast.rob.entity.GroupMessage
import cn.rtast.rob.util.BaseCommand
import cn.rtast.rob.util.ob.OneBotListener
class ShortLinkCommand : BaseCommand() {
override val commandNames = listOf("/s", "/sl", "/shortlink", "/short")
private val shortLinkApi = "https://api.rtast.cn"
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
if (args.isEmpty()) {
message.reply("发送`/s <url>`来生成短链接`不要放入一些奇怪的链接哦~")
return
}
val target = args.first().encodeToBase64()
val shortLink = Http.post<ShortLink>(
"$shortLinkApi/short_link",
params = mapOf("target" to target)
)
message.reply("$shortLinkApi/s?rnd_id=${shortLink.id}")
}
}
@@ -0,0 +1,12 @@
/*
* Copyright © 2024 RTAkland
* Author: RTAkland
* Date: 2024/9/22
*/
package cn.rtast.fancybot.entity
data class ShortLink(
val id: String
)