diff --git a/.github/dependabot.yml b/.github/dependabot.yml
deleted file mode 100644
index c26c285..0000000
--- a/.github/dependabot.yml
+++ /dev/null
@@ -1,17 +0,0 @@
-# To get started with Dependabot version updates, you'll need to specify which
-# package ecosystems to update and where the package manifests are located.
-# Please see the documentation for all configuration options:
-# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
-
-version: 2
-updates:
- - package-ecosystem: gradle # See documentation for possible values
- directory: / # Location of package manifests
- schedule:
- interval: weekly
- open-pull-requests-limit: 5
- - package-ecosystem: github-actions
- directory: /
- schedule:
- interval: weekly
- open-pull-requests-limit: 5
diff --git a/Module.md b/Module.md
index dc14af2..958adb8 100644
--- a/Module.md
+++ b/Module.md
@@ -1,16 +1,15 @@
# Module mirai-console-lolicon
+
受 [ACGPro](https://github.com/ShrBox/ACGPro) 启发而写
-
+
Social preview的图片来自 [AliceSoft](https://www.alicesoft.com) 制作的游戏 [ドーナドーナ いっしょにわるいことをしよう](https://www.alicesoft.com/dohnadohna)
-
-在群内随机发送图片(默认30s自动撤回+60s冷却),支持关键词检索
-
-适配 [mirai-console](https://github.com/mamoe/mirai-console) [![Version](https://img.shields.io/badge/version-2.6.5-blue)](https://github.com/mamoe/mirai/releases/tag/v2.6.5)
-
-可以在 [Lolicon API](https://api.lolicon.app/#/setu) 申请apikey来增加调用额度
-
-帮助文档已经移到了 [Wiki](https://github.com/Samarium150/mirai-console-lolicon/wiki) 页面
-
+
+在群内随机发送来自 [Lolicon API v2](https://api.lolicon.app/#/setu) 的图片(默认30s自动撤回+60s冷却),支持标签检索和JSON高级检索
+
+适配 [mirai-console](https://github.com/mamoe/mirai-console) v2.7.0
+
+使用文档已经移到了 [Wiki](https://github.com/Samarium150/mirai-console-lolicon/wiki) 页面
+
本页面为Kotlin源文件的注释文档
# Package com.github.samarium150.mirai.plugin
diff --git a/build.gradle.kts b/build.gradle.kts
index 978e87f..5bf1bcf 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -5,13 +5,13 @@ plugins {
kotlin("jvm") version kotlinVersion
kotlin("plugin.serialization") version kotlinVersion
- id("net.mamoe.mirai-console") version "2.7.0"
+ id("net.mamoe.mirai-console") version "2.7.1-dev-1"
id("org.jetbrains.dokka") version "1.5.0"
id("com.geoffgranum.gradle-conventional-changelog") version "0.3.1"
}
group = "com.github.samarium150"
-version = "4.0.0"
+version = "4.1.0"
repositories {
mavenLocal()
@@ -31,7 +31,6 @@ tasks.withType().all {
tasks.withType().configureEach {
dokkaSourceSets {
configureEach {
- outputDirectory.set(file("docs"))
includeNonPublic.set(true)
includes.from("Module.md")
sourceLink {
diff --git a/src/main/kotlin/Lolicon.kt b/src/main/kotlin/Lolicon.kt
index 381a0cd..bb18cc7 100644
--- a/src/main/kotlin/Lolicon.kt
+++ b/src/main/kotlin/Lolicon.kt
@@ -85,8 +85,13 @@ object Lolicon: CompositeCommand(
*/
@OptIn(DelicateCoroutinesApi::class)
@SubCommand("get", "来一张")
- @Description("(默认冷却时间60s)根据关键字发送涩图, 不提供关键字则随机发送一张")
+ @Description("根据标签发送涩图, 不提供则随机发送一张")
suspend fun CommandSender.get(tags: String = "") {
+ if (!Utils.isPermitted(subject)) {
+ val where = if (subject is Group) "@${(subject as Group).id}" else ""
+ Main.logger.info("当前模式为'${PluginConfig.mode}',${user?.id}${where}的命令已被无视")
+ return
+ }
if (!Timer.getCooldown(subject)) {
sendMessage(ReplyConfig.inCooldown)
return
@@ -117,8 +122,9 @@ object Lolicon: CompositeCommand(
try {
val imageData = response.data[0]
val url = imageData.urls[PluginConfig.size] ?: return
- Main.logger.info("url: $url")
- val imgInfoReceipt = sendMessage(imageData.toReadable()) ?: return
+ val imgInfoReceipt =
+ if (PluginConfig.verbose || subject == null) sendMessage(imageData.toReadable())
+ else null
var stream: InputStream? = null
try {
stream = if (PluginConfig.save && PluginConfig.cache) {
@@ -159,7 +165,7 @@ object Lolicon: CompositeCommand(
} finally {
@Suppress("BlockingMethodInNonBlockingContext")
stream?.close()
- if (recall > 0 && PluginConfig.recallImgInfo)
+ if (PluginConfig.verbose && imgInfoReceipt != null && recall > 0 && PluginConfig.recallImgInfo)
GlobalScope.launch {
val result = imgInfoReceipt.recallIn((recall * 1000).toLong()).awaitIsSuccess()
withContext(Dispatchers.Default) {
@@ -173,12 +179,23 @@ object Lolicon: CompositeCommand(
}
}
+ /**
+ * Advanced get
+ *
+ * 子命令adv,根据[json]获取图片
+ *
+ * @param json JSON字符串
+ */
@Suppress("unused")
@OptIn(DelicateCoroutinesApi::class, kotlinx.serialization.ExperimentalSerializationApi::class)
@SubCommand("adv", "高级")
- @Description("")
+ @Description("根据JSON字符串发送涩图")
suspend fun CommandSender.advanced(json: String) {
- Main.logger.info(json)
+ if (!Utils.isPermitted(subject)) {
+ val where = if (subject is Group) "@${(subject as Group).id}" else ""
+ Main.logger.info("当前模式为'${PluginConfig.mode}',${user?.id}${where}的命令已被无视")
+ return
+ }
val (r18, recall, cooldown) = ExecutionConfig.create(subject)
val body: RequestBody?
try {
@@ -248,7 +265,9 @@ object Lolicon: CompositeCommand(
stream?.close()
}
}
- val imgInfoReceipt = sendMessage(imageInfoMsgBuilder.asMessageChain()) ?: return
+ val imgInfoReceipt =
+ if (PluginConfig.verbose || subject == null) sendMessage(imageInfoMsgBuilder.asMessageChain())
+ else null
val imgReceipt = sendMessage(imageMsgBuilder.asMessageChain())
if (imgReceipt != null) {
if (recall > 0 && PluginConfig.recallImg)
@@ -269,7 +288,7 @@ object Lolicon: CompositeCommand(
}
}
}
- if (recall > 0 && PluginConfig.recallImgInfo)
+ if (PluginConfig.verbose && imgInfoReceipt != null && recall > 0 && PluginConfig.recallImgInfo)
GlobalScope.launch {
val result = imgInfoReceipt.recallIn((recall * 1000).toLong()).awaitIsSuccess()
withContext(Dispatchers.Default) {
@@ -363,6 +382,39 @@ object Lolicon: CompositeCommand(
}
}
+ /**
+ * Add user id or group id to corresponding set
+ *
+ * 添加用户id或群组id到对应的集合,用于黑白名单
+ *
+ * @param type
+ * @param id
+ */
+ @Suppress("unused")
+ @SubCommand("add", "添加")
+ suspend fun CommandSender.add(type: String, id: Long) {
+ if (!Utils.checkMaster(user)) {
+ sendMessage(ReplyConfig.nonMasterPermissionDenied)
+ if (PluginConfig.master == 0L) sendMessage(ReplyConfig.noMasterID)
+ return
+ }
+ val success: Boolean = when (type) {
+ "user" -> {
+ PluginData.userSet.add(id)
+ true
+ }
+ "group" -> {
+ PluginData.groupSet.add(id)
+ true
+ }
+ else -> {
+ sendMessage("类型错误")
+ false
+ }
+ }
+ if (success) sendMessage("添加成功")
+ }
+
/**
* Subcommand trust, add user to trusted set
*
diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt
index e5f8589..4dbe6ec 100644
--- a/src/main/kotlin/Main.kt
+++ b/src/main/kotlin/Main.kt
@@ -41,7 +41,7 @@ import java.net.Proxy
object Main: KotlinPlugin(
JvmPluginDescription(
id = "com.github.samarium150.mirai-console-lolicon",
- version = "4.0.0",
+ version = "4.1.0",
name = "mirai-console-lolicon"
)
) {
@@ -66,6 +66,12 @@ object Main: KotlinPlugin(
ProxyConfig.reload()
PluginData.reload()
+ if (PluginConfig.master != 0L) {
+ PluginData.trustedUsers.add(PluginConfig.master)
+ PluginData.userSet.add(PluginConfig.master)
+ PluginData.reload()
+ } else logger.warning("请先在配置文件设置Bot所有者id")
+
client = HttpClient {
engine {
proxy = if (ProxyConfig.type != "DIRECT") Proxy(
diff --git a/src/main/kotlin/PluginConfig.kt b/src/main/kotlin/PluginConfig.kt
index 820a92e..cc12e62 100644
--- a/src/main/kotlin/PluginConfig.kt
+++ b/src/main/kotlin/PluginConfig.kt
@@ -38,6 +38,14 @@ object PluginConfig : AutoSavePluginConfig("Config") {
@ValueDescription("Bot所有者账号")
val master: Long by value()
+ /**
+ * mode for Get and adv command
+ *
+ * Get命令和Adv命令的模式
+ */
+ @ValueDescription("Get命令和Adv命令的模式:none/whitelist/blacklist")
+ val mode: String by value("none")
+
/**
* Enable image saving
*
@@ -54,6 +62,14 @@ object PluginConfig : AutoSavePluginConfig("Config") {
@ValueDescription("是否使用已保存的图片作为缓存")
val cache: Boolean by value(false)
+ /**
+ * Sending image info
+ *
+ * 是否发送图片信息
+ */
+ @ValueDescription("是否发送图片信息")
+ val verbose: Boolean by value(true)
+
/**
* Enable flash image
*
diff --git a/src/main/kotlin/PluginData.kt b/src/main/kotlin/PluginData.kt
index f3edc3a..5980865 100644
--- a/src/main/kotlin/PluginData.kt
+++ b/src/main/kotlin/PluginData.kt
@@ -31,28 +31,28 @@ import net.mamoe.mirai.console.data.value
object PluginData: AutoSavePluginData("Data") {
/**
- * Trusted Users
+ * User set
*
- * 受信任的用户
+ * 用户列表
*/
- @ValueDescription("受信任的用户")
- val trustedUsers: MutableSet by value()
+ @ValueDescription("用户列表")
+ val userSet: MutableSet by value()
/**
- * Users' id and their apikey mappings
+ * Group set
*
- * 自定义了 apikey 的用户和对应的 apikey
+ * 群组列表
*/
- @ValueDescription("自定义了apikey的用户和对应的apikey")
- val customAPIKeyUsers: MutableMap by value()
+ @ValueDescription("群组列表")
+ val groupSet: MutableSet by value()
/**
- * Groups' id and their apikey mappings
+ * Trusted Users
*
- * 自定义了 apikey 的群和对应的 apikey
+ * 受信任的用户
*/
- @ValueDescription("自定义了apikey的群和对应的apikey")
- val customAPIKeyGroups: MutableMap by value()
+ @ValueDescription("受信任的用户")
+ val trustedUsers: MutableSet by value()
/**
* Users that enabled R18 option
diff --git a/src/main/kotlin/Utils.kt b/src/main/kotlin/Utils.kt
index f818dbf..f203de1 100644
--- a/src/main/kotlin/Utils.kt
+++ b/src/main/kotlin/Utils.kt
@@ -17,9 +17,7 @@
package com.github.samarium150.mirai.plugin
import com.github.samarium150.mirai.plugin.Lolicon.set
-import net.mamoe.mirai.contact.Member
-import net.mamoe.mirai.contact.MemberPermission
-import net.mamoe.mirai.contact.User
+import net.mamoe.mirai.contact.*
import org.jetbrains.annotations.Nullable
import java.net.Proxy
@@ -135,4 +133,34 @@ object Utils {
fun getUrl(urls: Map): String? {
return urls[urls.keys.sortedBy { sizeMap[it] } [0]]
}
+
+ /**
+ * Is the subject permitted to use the bot
+ *
+ * 是否能执行命令
+ *
+ * @param subject
+ * @return
+ */
+ fun isPermitted(subject: Contact?): Boolean {
+ return when (PluginConfig.mode) {
+ "whitelist" -> {
+ when {
+ subject == null -> true
+ subject is User && PluginData.userSet.contains(subject.id) -> true
+ subject is Group && PluginData.groupSet.contains(subject.id) -> true
+ else -> false
+ }
+ }
+ "blacklist" -> {
+ when {
+ subject == null -> true
+ subject is User && !PluginData.userSet.contains(subject.id) -> true
+ subject is Group && !PluginData.groupSet.contains(subject.id) -> true
+ else -> true
+ }
+ }
+ else -> true
+ }
+ }
}
diff --git a/src/main/resources/help.txt b/src/main/resources/help.txt
index 03fa665..718438b 100644
--- a/src/main/resources/help.txt
+++ b/src/main/resources/help.txt
@@ -2,16 +2,15 @@
简介:
在私聊/群内随机发送图片, 支持关键词检索
-apikey可以在申请
可用指令:
/lolicon help # 获取帮助信息
-/lolicon get [keyword] # (冷却时间60s)根据关键字发送涩图, 不提供关键字则随机发送一张
+/lolicon get [tag] # 根据标签发送涩图, 不提供关键字则随机发送一张
+/lolicon adv # 根据JSON获取涩图
+/lolicon add # 将群或用户添加到列表(黑白名单用)
/lolicon set
# 设置属性, 群聊模式仅能由群主和管理员设置
# 可选属性:
- # apikey, 对应值: default/正确的apikey, 效果: 重置apikey或设置apikey的值,私聊模式也可以更改
- # apikey设置后, 调用get时将使用设置的值, 而不是bot的默认值
# r18, 对应值: 0/1/2, 效果: 将模式设置为non-R18/R18/mixed
# 私聊模式仅限受信任清单中的用户设置
# recall, 对应值: 以秒为单位的小于120的非负整数, 效果: 设置自动撤回的时间, 默认为30s, 0则不撤回