mirror of
https://github.com/jie65535/JChatGPT.git
synced 2025-12-08 18:31:36 +08:00
Add meme prompt
This commit is contained in:
@@ -33,6 +33,7 @@ import net.mamoe.mirai.utils.info
|
|||||||
import top.jie65535.mirai.tools.*
|
import top.jie65535.mirai.tools.*
|
||||||
import xyz.cssxsh.mirai.hibernate.MiraiHibernateRecorder
|
import xyz.cssxsh.mirai.hibernate.MiraiHibernateRecorder
|
||||||
import xyz.cssxsh.mirai.hibernate.entry.MessageRecord
|
import xyz.cssxsh.mirai.hibernate.entry.MessageRecord
|
||||||
|
import java.io.File
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.OffsetDateTime
|
import java.time.OffsetDateTime
|
||||||
import java.time.ZoneOffset
|
import java.time.ZoneOffset
|
||||||
@@ -165,6 +166,8 @@ object JChatGPT : KotlinPlugin(
|
|||||||
startChat(event)
|
startChat(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var memePrompt: String? = null
|
||||||
|
|
||||||
private fun getSystemPrompt(event: MessageEvent): String {
|
private fun getSystemPrompt(event: MessageEvent): String {
|
||||||
val now = OffsetDateTime.now()
|
val now = OffsetDateTime.now()
|
||||||
val prompt = StringBuilder(LargeLanguageModels.systemPrompt)
|
val prompt = StringBuilder(LargeLanguageModels.systemPrompt)
|
||||||
@@ -194,6 +197,46 @@ object JChatGPT : KotlinPlugin(
|
|||||||
} else memoryText
|
} else memoryText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
replace("{meme}") {
|
||||||
|
memePrompt?.let { return@replace it }
|
||||||
|
|
||||||
|
if (PluginConfig.memeDir.isEmpty()) {
|
||||||
|
""
|
||||||
|
} else {
|
||||||
|
buildString {
|
||||||
|
val dir = File(PluginConfig.memeDir)
|
||||||
|
if (dir.exists() && dir.isDirectory) {
|
||||||
|
append("memes文件夹地址为:")
|
||||||
|
append(PluginConfig.memeDir)
|
||||||
|
appendLine()
|
||||||
|
|
||||||
|
val memes = dir.list()
|
||||||
|
|
||||||
|
if (memes.isEmpty()) {
|
||||||
|
append("暂无表情包~")
|
||||||
|
} else {
|
||||||
|
for (name in memes) {
|
||||||
|
append("- ")
|
||||||
|
append(name)
|
||||||
|
appendLine()
|
||||||
|
}
|
||||||
|
appendLine()
|
||||||
|
append("表情包示例:![")
|
||||||
|
append(memes[0])
|
||||||
|
append("](")
|
||||||
|
append(File(dir, memes[0]).absoluteFile)
|
||||||
|
append(")")
|
||||||
|
appendLine()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
append("配置的meme路径不存在!")
|
||||||
|
}
|
||||||
|
}.also {
|
||||||
|
memePrompt = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return prompt.toString()
|
return prompt.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -583,7 +626,7 @@ object JChatGPT : KotlinPlugin(
|
|||||||
* @param content 文本内容
|
* @param content 文本内容
|
||||||
* @return 构造的消息
|
* @return 构造的消息
|
||||||
*/
|
*/
|
||||||
suspend fun toMessage(contact: Contact, content: String): Message {
|
fun toMessage(contact: Contact, content: String): Message {
|
||||||
return if (content.isEmpty()) {
|
return if (content.isEmpty()) {
|
||||||
PlainText("...")
|
PlainText("...")
|
||||||
} else if (content.length < 3) {
|
} else if (content.length < 3) {
|
||||||
|
|||||||
@@ -104,4 +104,7 @@ object PluginConfig : AutoSavePluginConfig("Config") {
|
|||||||
|
|
||||||
@ValueDescription("好感度每日基础偏移速度(点/天)")
|
@ValueDescription("好感度每日基础偏移速度(点/天)")
|
||||||
val favorabilityBaseShiftSpeed by value(2.0)
|
val favorabilityBaseShiftSpeed by value(2.0)
|
||||||
|
|
||||||
|
@ValueDescription("表情包路径,配置后会加载目录下的文件名,提示词中需要用{meme}来插入上下文")
|
||||||
|
val memeDir: String by value("")
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user