diff --git a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt index a0a5b95..d3a98cc 100644 --- a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt +++ b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt @@ -17,6 +17,7 @@ import cn.rtast.fancybot.commands.JrrpCommand import cn.rtast.fancybot.commands.MCPingCommand import cn.rtast.fancybot.commands.MusicCommand import cn.rtast.fancybot.commands.MyPointCommand +import cn.rtast.fancybot.commands.PixivCommand import cn.rtast.fancybot.commands.QRCodeCommand import cn.rtast.fancybot.commands.RedeemCommand import cn.rtast.fancybot.commands.RemakeCommand @@ -87,7 +88,7 @@ val commands = listOf( QRCodeCommand(), AntiRevokeCommand(), MCPingCommand(), HelpCommand(), WeatherCommand(), CigaretteCommand(), - RemakeCommand() + RemakeCommand(), PixivCommand() ) suspend fun main() { diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/PixivCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/PixivCommand.kt new file mode 100644 index 0000000..b0707e9 --- /dev/null +++ b/src/main/kotlin/cn/rtast/fancybot/commands/PixivCommand.kt @@ -0,0 +1,69 @@ +/* + * Copyright © 2024 RTAkland + * Author: RTAkland + * Date: 2024/9/5 + */ + + +package cn.rtast.fancybot.commands + +import cn.rtast.fancybot.entity.pixiv.Ranking +import cn.rtast.fancybot.util.Http +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 PixivCommand : BaseCommand() { + override val commandNames = listOf("/pixiv", "/p") + + private val pixivRankingURL = "https://proxy.rtast.cn/https/www.pixiv.net/ranking.php?format=json&mode=daily&p=1" + private val imageProxyURL = "https://pixiv.nl" + + override suspend fun executeGroup(listener: OBMessage, message: GroupMessage, args: List) { + if (args.isEmpty()) { + val msg = MessageChain.Builder() + .addAt(message.sender.userId) + .addText("发送/pixiv | rank 来进行操作哦~") + .build() + listener.sendGroupMessage(message.groupId, msg) + return + } + val keyword = args.first() + when (keyword) { + "rank", "排名", "r" -> { + val msg = MessageChain.Builder() + .addAt(message.sender.userId) + .addText("今日Pixiv Ranking~") + .addNewLine() + + val result = Http.get(pixivRankingURL) + result.contents.asSequence().take(5).forEach { + msg.addText(it.title) + .addImage(it.getOriginUrl()) + .addNewLine() + } + listener.sendGroupMessage(message.groupId, msg.build()) + return + } + + else -> { + try { + val id = keyword.toLong() + val msg = MessageChain.Builder() + .addAt(message.sender.userId) + .addText("来咯~ 你要的图片~~~") + .addImage("$imageProxyURL/$id.png") + .build() + listener.sendGroupMessage(message.groupId, msg) + } catch (_: Exception) { + val msg = MessageChain.Builder() + .addAt(message.sender.userId) + .addText("输入错误~检查一下有没有输错吧~") + .build() + listener.sendGroupMessage(message.groupId, msg) + } + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/entity/pixiv/Ranking.kt b/src/main/kotlin/cn/rtast/fancybot/entity/pixiv/Ranking.kt new file mode 100644 index 0000000..bec75fe --- /dev/null +++ b/src/main/kotlin/cn/rtast/fancybot/entity/pixiv/Ranking.kt @@ -0,0 +1,24 @@ +/* + * Copyright © 2024 RTAkland + * Author: RTAkland + * Date: 2024/9/5 + */ + + +package cn.rtast.fancybot.entity.pixiv + +data class Ranking( + val contents: List +) { + data class Content( + val title: String, + val tags: List, + val url: String + ) { + fun getOriginUrl(): String { + return url.replace("https://i.pximg.net", "https://proxy.rtast.cn/https/pixiv.microyu.workers.dev") + .replace("/c/240x480/img-master/", "/img-original/") + .replace("_master1200", "") + } + } +} \ No newline at end of file