From b12151cec45ef9a24a771d20b3f7f3f64606fc78 Mon Sep 17 00:00:00 2001 From: RTAkland Date: Sun, 22 Sep 2024 14:14:24 +0800 Subject: [PATCH] feat: add short link command --- src/main/kotlin/cn/rtast/fancybot/FancyBot.kt | 5 +-- .../commands/record/ShortLinkCommand.kt | 34 +++++++++++++++++++ .../cn/rtast/fancybot/entity/ShortLink.kt | 12 +++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/cn/rtast/fancybot/commands/record/ShortLinkCommand.kt create mode 100644 src/main/kotlin/cn/rtast/fancybot/entity/ShortLink.kt diff --git a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt index afbfd82..d476e77 100644 --- a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt +++ b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt @@ -11,9 +11,9 @@ import cn.rtast.fancybot.commands.AboutCommand import cn.rtast.fancybot.commands.EchoCommand import cn.rtast.fancybot.commands.HelpCommand 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.DomainPriceCommand -import cn.rtast.fancybot.commands.lookup.AICommand import cn.rtast.fancybot.commands.lookup.GithubUserCommand import cn.rtast.fancybot.commands.lookup.MCPingCommand 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.NiuziSignCommand 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.entity.bili.CardShare import cn.rtast.fancybot.entity.enums.WSType @@ -223,7 +224,7 @@ val commands = listOf( SendMailCommand(), ZiBiCommand(), UnsetZiBiCommand(), WikipediaCommand(), AsciiArtCommand(), StatusCommand(), - JueCommand() + JueCommand(), ShortLinkCommand() ) val START_UP_TIME = Instant.now().epochSecond diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/record/ShortLinkCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/record/ShortLinkCommand.kt new file mode 100644 index 0000000..aac93d5 --- /dev/null +++ b/src/main/kotlin/cn/rtast/fancybot/commands/record/ShortLinkCommand.kt @@ -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) { + if (args.isEmpty()) { + message.reply("发送`/s `来生成短链接`不要放入一些奇怪的链接哦~") + return + } + val target = args.first().encodeToBase64() + val shortLink = Http.post( + "$shortLinkApi/short_link", + params = mapOf("target" to target) + ) + message.reply("$shortLinkApi/s?rnd_id=${shortLink.id}") + } +} \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/entity/ShortLink.kt b/src/main/kotlin/cn/rtast/fancybot/entity/ShortLink.kt new file mode 100644 index 0000000..36f3e64 --- /dev/null +++ b/src/main/kotlin/cn/rtast/fancybot/entity/ShortLink.kt @@ -0,0 +1,12 @@ +/* + * Copyright © 2024 RTAkland + * Author: RTAkland + * Date: 2024/9/22 + */ + + +package cn.rtast.fancybot.entity + +data class ShortLink( + val id: String +) \ No newline at end of file