Skip to content

Commit

Permalink
add some features
Browse files Browse the repository at this point in the history
  • Loading branch information
kukume committed Apr 30, 2022
1 parent 4e6eb65 commit 7d1d7f0
Show file tree
Hide file tree
Showing 27 changed files with 472 additions and 246 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ out/
.vscode/

tmp/
db/
db/
application.yml
34 changes: 29 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

YuQ-Art + Spring-Data-Jpa

环境要求:`jdk11`以上,以后可能会`jdk17`以上
YuQ是路由框架、Web框架中最简单好用的

https://github.com/YuQWorks/YuQ

https://github.com/IceCream-QAQ/Rain

环境要求:Jar包`jdk11`以上,Dev`jdk8`以上,`Spring-Data-Jpa 3正式版`出来后会`jdk17`以上

## 功能

Expand All @@ -13,9 +19,9 @@ YuQ-Art + Spring-Data-Jpa
- [x] 网易云音乐自动签到
- [x] 微博超话自动签到+微博推送
- [x] 百度贴吧自动签到
- [x] 酷狗音乐自动领会员
- [x] 原神签到
- [ ] oppo商城(欢太)自动签到
- [x] 酷狗音乐自动签到
- [x] 原神自动签到
- [x] oppo商城(欢太)自动签到
- [x] 修改微信、支付宝步数


Expand All @@ -30,4 +36,22 @@ yuq:
password:
# 机器人主人
master: 734669014
```
```
## 机器人菜单
https://outline.kuku.me/share/2e461ea5-19fb-4326-be24-ba23367ff72d
## 部署教程
https://www.kuku.me/archives/6/
## 鸣谢
> [IntelliJ IDEA](https://zh.wikipedia.org/zh-hans/IntelliJ_IDEA) 是一个在各个方面都最大程度地提高开发人员的生产力的 IDE,适用于 JVM 平台语言。
特别感谢 [JetBrains](https://www.jetbrains.com/?from=kuku-bot) 为开源项目提供免费的 [IntelliJ IDEA](https://www.jetbrains.com/idea/?from=kuku-bot) 等 IDE 的授权
[<img src="https://img.kuku.me/images/2021/01/31/4I4aI.png" width="200"/>](https://www.jetbrains.com/?from=kuku-bot)
## 协议
AGPL
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ repositories {
dependencies {
kapt("org.springframework.boot:spring-boot-configuration-processor")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-cache")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("com.squareup.okhttp3:okhttp:4.9.3")
implementation("me.kuku:utils-fastjson:0.0.1")
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/me/kuku/yuq/KuKuBotApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package me.kuku.yuq

import com.IceCreamQAQ.Yu.loader.AppClassloader
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.cache.annotation.EnableCaching
import org.springframework.data.jpa.repository.config.EnableJpaAuditing

@SpringBootApplication
@EnableCaching
@EnableJpaAuditing
class KuKuBotApplication

Expand Down
12 changes: 0 additions & 12 deletions src/main/kotlin/me/kuku/yuq/config/JpaConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,14 @@ package me.kuku.yuq.config
import com.IceCreamQAQ.Yu.annotation.HookBy
import com.IceCreamQAQ.Yu.hook.HookMethod
import com.IceCreamQAQ.Yu.hook.HookRunnable
import kotlinx.coroutines.runBlocking
import me.kuku.yuq.utils.SpringUtils
import org.springframework.transaction.PlatformTransactionManager
import org.springframework.transaction.TransactionDefinition
import org.springframework.transaction.TransactionStatus
import org.springframework.transaction.support.TransactionTemplate

suspend fun <T> TransactionTemplate.executeBlock(block: suspend () -> T?): T? {
return this.execute {
runBlocking {
block.invoke()
}
}
}


@HookBy("me.kuku.yuq.config.JpaHook")
annotation class Transactional


class JpaHook: HookRunnable {

override fun preRun(method: HookMethod): Boolean {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/me/kuku/yuq/controller/BeforeController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ class BeforeController (
val source = context.source
source.sendMessage(mif.at(qq).plus("程序出现异常了,异常信息为:$url"))
val messageId = message.source?.id ?: 0
if (source is Friend) {
if (source is Friend || source is Member) {
val messageEntity = privateMessageService.findByMessageIdAndQq(messageId, qq) ?: return
val exceptionLogEntity = ExceptionLogEntity()
exceptionLogEntity.privateMessageEntity = messageEntity
exceptionLogEntity.stackTrace = exceptionStackTrace
exceptionLogEntity.url = url
exceptionLogService.save(exceptionLogEntity)
} else if (source is Group || source is Member) {
} else if (source is Group) {
val messageEntity = messageService.findByMessageIdAndGroup(messageId, group!!) ?: return
val exceptionLogEntity = ExceptionLogEntity()
exceptionLogEntity.messageEntity = messageEntity
Expand Down
113 changes: 90 additions & 23 deletions src/main/kotlin/me/kuku/yuq/controller/ManagerController.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
@file:Suppress("DuplicatedCode")

package me.kuku.yuq.controller

import com.IceCreamQAQ.Yu.annotation.Action
import com.IceCreamQAQ.Yu.annotation.Before
import com.icecreamqaq.yuq.annotation.GroupController
import com.icecreamqaq.yuq.annotation.QMsg
import com.icecreamqaq.yuq.annotation.PathVar
import com.icecreamqaq.yuq.controller.ContextSession
import com.icecreamqaq.yuq.entity.Group
import com.icecreamqaq.yuq.entity.Member
import com.icecreamqaq.yuq.message.At
import com.icecreamqaq.yuq.message.Message.Companion.firstString
import com.icecreamqaq.yuq.message.Message.Companion.toCodeString
import com.icecreamqaq.yuq.message.Text
import com.icecreamqaq.yuq.mif
import me.kuku.yuq.entity.*
import org.springframework.beans.factory.annotation.Value
Expand All @@ -17,16 +22,20 @@ import org.springframework.stereotype.Component
@Component
class ManagerController (
private val groupService: GroupService,
@Value("yuq.art.master") private val master: String
private val messageService: MessageService,
@Value("\${yuq.art.master}") private val master: String
) {

@Before(except = ["operateStatus", "add", "delete", "query"])
fun before(qq: Long) {
if (qq != master.toLong()) throw mif.at(qq).plus("权限不足,无法执行").toThrowable()
fun before(qq: Member, groupEntity: GroupEntity) {
val b = groupEntity.config.adminCanExecute == Status.ON && qq.isAdmin()
val bb = qq.id == master.toLong()
val bbb = groupEntity.config.adminList.firstOrNull { it == qq.id } != null
if (!(b || bb || bbb)) throw mif.at(qq).plus("权限不足,无法执行").toThrowable()
}

@Action("{operate} {statusStr}")
fun operateStatus(operate: String, statusStr: String, groupEntity: GroupEntity, qq: Long): String? {
fun operateStatus(operate: String, statusStr: String, groupEntity: GroupEntity, qq: Member): String? {
val status = statusStr.contains("")
val config = groupEntity.config
when (operate) {
Expand All @@ -36,84 +45,124 @@ class ManagerController (
"退群拉黑" -> config.leaveToBlack = status.toStatus()
"r18" -> config.loLiConR18 = status.toStatus()
"进群验证" -> config.entryVerification = status.toStatus()
"群管权限" -> config.adminCanExecute = status.toStatus()
else -> return null
}
before(qq)
before(qq, groupEntity)
groupService.save(groupEntity)
return "${operate}${if (status) "开启" else "关闭"}成功"
}

@Action("加{operate}")
fun add(operate: String, session: ContextSession, groupEntity: GroupEntity, qq: Long, group: Group): String? {
fun add(operate: String, session: ContextSession, groupEntity: GroupEntity, qq: Member, group: Group): String? {
val config = groupEntity.config
when (operate) {
"违禁词" -> {
group.sendMessage("请发送违禁词列表,多个使用空格分割")
group.sendMessage(mif.at(qq).plus("请发送违禁词列表,多个使用空格分割"))
val str = session.waitNextMessage().firstString()
val arr = str.split(" ")
config.prohibitedWords.addAll(arr)
}
"黑名单" -> {
group.sendMessage("请发送黑名单列表,多个使用空格分割")
group.sendMessage(mif.at(qq).plus("请发送黑名单列表,多个使用空格分割"))
val str = session.waitNextMessage().firstString()
val arr = str.split(" ").map { it.toLong() }
config.blackList.addAll(arr)
}
"问答" -> {
group.sendMessage("请发送问题")
group.sendMessage(mif.at(qq).plus("请发送问题"))
val q = session.waitNextMessage().toCodeString()
group.sendMessage("请发送机器人回复的答案")
group.sendMessage(mif.at(qq).plus("请发送机器人回复的答案"))
val a = session.waitNextMessage().toCodeString()
group.sendMessage("请发送数字,1表示精准匹配,2表示模糊匹配")
group.sendMessage(mif.at(qq).plus("请发送数字,1表示精准匹配,2表示模糊匹配"))
val ss = session.waitNextMessage().firstString()
val type = if (ss == "1") QaType.EXACT else QaType.FUZZY
val qa = Qa(q, a, type)
config.qaList.add(qa)
}
"" -> {
group.sendMessage(mif.at(qq).plus("请发送qq号或者直接at"))
val message = session.waitNextMessage()
val set = mutableSetOf<Long>()
message.body.forEach {
if (it is At) {
set.add(it.user)
} else if (it is Text) {
it.text.toLongOrNull()?.let { qq ->
set.add(qq)
}
}
}
config.adminList.addAll(set)
}
"拦截" -> {
group.sendMessage(mif.at(qq).plus("请发送需要拦截的指令"))
val ss = session.waitNextMessage().firstString()
groupEntity.config.interceptList.addAll(ss.split(" "))
}
else -> return null
}
before(qq)
before(qq, groupEntity)
groupService.save(groupEntity)
return "添加${operate}成功"
}

@Action("删{operate}")
@QMsg(reply = true)
fun delete(operate: String, session: ContextSession, groupEntity: GroupEntity, qq: Long, group: Group): String? {
fun delete(operate: String, session: ContextSession, groupEntity: GroupEntity, qq: Member, group: Group): String? {
val config = groupEntity.config
when (operate) {
"违禁词" -> {
group.sendMessage("请发送需要删除的违禁词列表,多个使用空格分割")
group.sendMessage(mif.at(qq).plus("请发送需要删除的违禁词列表,多个使用空格分割"))
val str = session.waitNextMessage().firstString()
val arr = str.split(" ")
val prohibitedWords = config.prohibitedWords
arr.forEach(prohibitedWords::remove)
}
"黑名单" -> {
group.sendMessage("请发送需要删除的黑名单列表,多个使用空格分割")
group.sendMessage(mif.at(qq).plus("请发送需要删除的黑名单列表,多个使用空格分割"))
val str = session.waitNextMessage().firstString()
val arr = str.split(" ").map { it.toLong() }
val blackList = config.blackList
arr.forEach(blackList::remove)
}
"问答" -> {
group.sendMessage("请发送需要删除的问答的问题")
group.sendMessage(mif.at(qq).plus("请发送需要删除的问答的问题"))
val str = session.waitNextMessage().firstString()
val arr = str.split(" ")
val qaList = config.qaList
for (s in arr) {
qaList.removeIf { it.q == s }
}
}
"" -> {
group.sendMessage(mif.at(qq).plus("请发送需要删除的机器人管理,qq号和at都可"))
val message = session.waitNextMessage()
val set = mutableSetOf<Long>()
message.body.forEach {
if (it is At) {
set.add(it.user)
} else if (it is Text) {
it.text.toLongOrNull()?.let { qq ->
set.add(qq)
}
}
}
config.adminList.removeAll(set)
}
"拦截" -> {
group.sendMessage(mif.at(qq).plus("请发送需要拦截的指令"))
val ss = session.waitNextMessage().firstString()
config.interceptList.removeAll(ss.split(" ").toSet())

}
else -> return null
}
before(qq)
before(qq, groupEntity)
groupService.save(groupEntity)
return "删除${operate}成功"
}

@Action("查{operate}")
@QMsg(reply = true)
fun query(operate: String, groupEntity: GroupEntity): String? {
val config = groupEntity.config
val sb = StringBuilder()
Expand All @@ -130,12 +179,19 @@ class ManagerController (
config.qaList.forEach { sb.append(it.q).append(" ") }
sb.toString()
}
"" -> {
config.adminList.forEach { sb.append(it).append(" ") }
sb.toString()
}
"拦截" -> {
config.interceptList.forEach { sb.append(it).append(" ") }
sb.toString()
}
else -> return null
}
}.ifEmpty { "木得" }
}

@Action("t {qqNo}")
@QMsg(reply = true)
fun kick(qqNo: Long, group: Group): String {
return kotlin.runCatching {
group[qqNo].kick()
Expand All @@ -144,7 +200,6 @@ class ManagerController (
}

@Action("{day}天未发言")
@QMsg(reply = true)
fun notSpeak(day: String, group: Group, session: ContextSession, qq: Long): String? {
val list = mutableListOf<Long>()
val members = group.members
Expand All @@ -170,6 +225,18 @@ class ManagerController (
} else null
} else null
}

@Action("撤回 {qqNo}")
fun recall(qqNo: Long, group: Long, @PathVar(value = 2, type = PathVar.Type.Integer) num: Int?): String {
val list = messageService.findByGroupAndQqOrderByIdDesc(group, qqNo)
val n = if ((num ?: 1) > list.size) list.size else num ?: 1
for (i in 0 until n) {
for (messageEntity in list) {
messageEntity.messageSource?.recall()
}
}
return "撤回成功"
}
}

fun Boolean.toStatus() = if (this) Status.ON else Status.OFF
Expand Down
Loading

0 comments on commit 7d1d7f0

Please sign in to comment.