Skip to content

Commit

Permalink
feat: support spaced tags
Browse files Browse the repository at this point in the history
Closes #60
  • Loading branch information
Samarium150 committed Dec 6, 2021
1 parent f3e39b7 commit 6b339d1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}

group = "com.github.samarium150"
version = "4.1.4"
version = "4.2.0"

repositories {
mavenLocal()
Expand Down
18 changes: 10 additions & 8 deletions src/main/kotlin/Lolicon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import kotlinx.coroutines.*
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import net.mamoe.mirai.console.command.CommandSender
import net.mamoe.mirai.console.command.CommandSenderOnMessage
import net.mamoe.mirai.console.command.CompositeCommand
import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors
import net.mamoe.mirai.console.plugin.jvm.reloadPluginConfig
Expand Down Expand Up @@ -77,17 +76,17 @@ object Lolicon: CompositeCommand(
}

/**
* Subcommand get, get the image according to [tags]
* Subcommand get, get the image according to [tagArgs]
* <br>
* 子命令get,根据 [tags] 从API获取图片
* 子命令get,根据 [tagArgs] 从API获取图片
*
* @receiver [CommandSender] Command sender <br> 指令发送者
* @param tags keyword for searching <br> 关键词
* @param tagArgs keyword for searching <br> 关键词
*/
@OptIn(DelicateCoroutinesApi::class)
@SubCommand("get", "来一张")
@Description("根据标签发送涩图, 不提供则随机发送一张")
suspend fun CommandSenderOnMessage<*>.get(tags: String = "") {
suspend fun CommandSender.get(vararg tagArgs: String) {
if (!Utils.isPermitted(subject, user)) {
val where = if (subject is Group) "@${(subject as Group).id}" else ""
Main.logger.info("当前模式为'${PluginConfig.mode}',${user?.id}${where}的命令已被无视")
Expand All @@ -98,6 +97,7 @@ object Lolicon: CompositeCommand(
return
}
val (r18, recall, cooldown) = ExecutionConfig.create(subject)
val tags = tagArgs.joinToString(" ")
val body = if (tags.isNotEmpty())
RequestBody(r18, 1, listOf(), "", Utils.processTags(tags),
listOf(PluginConfig.size), PluginConfig.proxy)
Expand Down Expand Up @@ -183,20 +183,21 @@ object Lolicon: CompositeCommand(
/**
* Advanced get
* <br>
* 子命令adv,根据 [json] 获取图片
* 子命令adv,根据 [jsonArgs] 获取图片
*
* @param json JSON字符串
* @param jsonArgs JSON字符串
*/
@Suppress("unused")
@OptIn(DelicateCoroutinesApi::class, kotlinx.serialization.ExperimentalSerializationApi::class)
@SubCommand("adv", "高级")
@Description("根据JSON字符串发送涩图")
suspend fun CommandSender.advanced(json: String) {
suspend fun CommandSender.advanced(vararg jsonArgs: String) {
if (!Utils.isPermitted(subject, user)) {
val where = if (subject is Group) "@${(subject as Group).id}" else ""
Main.logger.info("当前模式为'${PluginConfig.mode}',${user?.id}${where}的命令已被无视")
return
}
val json = jsonArgs.joinToString(" ")
val (r18, recall, cooldown) = ExecutionConfig.create(subject)
val body: RequestBody?
try {
Expand All @@ -206,6 +207,7 @@ object Lolicon: CompositeCommand(
Main.logger.warning(e)
return
}
Main.logger.info(body.toString())
if (body.r18 != r18) {
if (subject is Group && !Utils.checkMemberPerm(user)) {
sendMessage(ReplyConfig.nonAdminPermissionDenied)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import java.net.Proxy
object Main: KotlinPlugin(
JvmPluginDescription(
id = "com.github.samarium150.mirai-console-lolicon",
version = "4.1.4",
version = "4.2.0",
name = "mirai-console-lolicon"
)
) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/RequestBody.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ data class RequestBody(
val keyword: String? = "",
val tag: List<List<String>>? = null,
val size: List<String>? = null,
val proxy: String = "i.pixiv.cat",
val proxy: String = "i.pixiv.re",
val dataAfter: Long? = null,
val dataBefore: Long? = null,
val dsc: Boolean? = null
Expand Down

0 comments on commit 6b339d1

Please sign in to comment.