和数据库提醒服务优化
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s

-引入`async-http-client`和`fix-protocol`依赖项以提升网络请求处理和协议兼容性。
- 在`BotConfiguration`中切换到`ANDROID_PAD`协议以改善性能。
- 在`DrinkWaterUser`实体中使用`TableId`注解并允许`botId`为`null`,以更好地与数据库交互。
- 在`ReminderService`和其他服务中使用`KtQueryWrapper`替代`LambdaQueryWrapper`,简化查询构建。
- 通过在`MiraiBotApplication`中预加载协议版本,加速启动时间。
- 更新`application-dev.yml`和`application-prod.yml`配置文件,引入密码认证。- 新增`android_pad.json`和`KFCFactory.json`配置,支持新协议。

这些更改提高了数据库操作的便捷性,增强了网络请求的处理能力,并通过协议优化改善了整体性能。
This commit is contained in:
Grand-cocoa 2024-09-18 17:12:51 +08:00
parent 6b18dd55a7
commit fc65e875e2
12 changed files with 76 additions and 11 deletions

12
KFCFactory.json Normal file
View File

@ -0,0 +1,12 @@
{
"9.0.56": {
"base_url": "https://qsign.trpgbot.com",
"type": "fuqiuluo/unidbg-fetch-qsign",
"key": "114514"
},
"9.0.95": {
"base_url": "https://qsign.trpgbot.com",
"type": "fuqiuluo/unidbg-fetch-qsign",
"key": "114514"
}
}

17
android_pad.json Normal file
View File

@ -0,0 +1,17 @@
{
"apk_id": "com.tencent.mobileqq",
"app_id": 537220362,
"sub_app_id": 537220362,
"app_key": "0S200MNJT807V3GE",
"sort_version_name": "9.0.56.16830",
"build_time": 1713424357,
"apk_sign": "a6b745bf24a2c277527716f6f36eb68d",
"sdk_version": "6.0.0.2560",
"sso_version": 21,
"misc_bitmap": 150470524,
"main_sig_map": 34869472,
"sub_sig_map": 66560,
"dump_time": 1713424357,
"qua": "V1_AND_SQ_9.0.56_6372_YYB_D",
"protocol_type": 6
}

Binary file not shown.

16
pom.xml
View File

@ -116,6 +116,19 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.asynchttpclient/async-http-client -->
<dependency>
<groupId>org.asynchttpclient</groupId>
<artifactId>async-http-client</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>xyz.cssxsh.mirai</groupId>
<artifactId>fix-protocol</artifactId>
<version>3.3.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/fix-protocol-version-1.13.0.mirai2.jar</systemPath>
</dependency>
</dependencies>
<build>
@ -125,6 +138,9 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>

View File

@ -1,13 +1,19 @@
package info.alinadace.miraibot
import net.mamoe.mirai.utils.BotConfiguration
import org.mybatis.spring.annotation.MapperScan
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.scheduling.annotation.EnableScheduling
import xyz.cssxsh.mirai.tool.FixProtocolVersion
@SpringBootApplication
@EnableScheduling
@MapperScan("info.alinadace.miraibot.service")
class MiraiBotApplication
fun main(args: Array<String>) {
// FixProtocolVersion.fetch(BotConfiguration.MiraiProtocol.ANDROID_PHONE, "8.9.96")
FixProtocolVersion.load(BotConfiguration.MiraiProtocol.ANDROID_PAD)
runApplication<MiraiBotApplication>(*args)
}

View File

@ -60,7 +60,7 @@ class BotConfiguration {
private fun BotConfiguration.extracted() {
fileBasedDeviceInfo()
protocol = BotConfiguration.MiraiProtocol.MACOS
protocol = BotConfiguration.MiraiProtocol.ANDROID_PAD
enableContactCache()
}
}

View File

@ -1,6 +1,6 @@
package info.alinadace.miraibot.service.drink_water
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
import info.alinadace.miraibot.annotation.BotFunction
import info.alinadace.miraibot.service.Service
import info.alinadace.miraibot.service.drink_water.domain.DrinkWaterUser
@ -48,7 +48,7 @@ class DisableService : Service<FriendMessageEvent> {
override suspend fun active(event: FriendMessageEvent) {
log.info("服务关闭请求 - DrinkWater - target:{}", event.sender.id)
val one = drinkWaterMapper.selectOne(
LambdaQueryWrapper<DrinkWaterUser>()
KtQueryWrapper(DrinkWaterUser())
.eq(DrinkWaterUser::botId, event.sender.id)
)
if (one == null) {

View File

@ -1,6 +1,6 @@
package info.alinadace.miraibot.service.drink_water
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
import info.alinadace.miraibot.annotation.BotFunction
import info.alinadace.miraibot.service.Service
import info.alinadace.miraibot.service.drink_water.domain.DrinkWaterUser
@ -47,7 +47,7 @@ class EnableService : Service<FriendMessageEvent> {
override suspend fun active(event: FriendMessageEvent) {
log.info("服务开启请求 - DrinkWater - target:{}", event.sender.id)
val one = drinkWaterMapper.selectOne(
LambdaQueryWrapper<DrinkWaterUser>()
KtQueryWrapper(DrinkWaterUser())
.eq(DrinkWaterUser::botId, event.sender.id)
)
if (one == null) {

View File

@ -1,11 +1,14 @@
package info.alinadace.miraibot.service.drink_water.domain
import com.baomidou.mybatisplus.annotation.TableId
/**
* 喝水提醒用户
*/
class DrinkWaterUser {
var id: Long = 0
var botId: Long = 0
@TableId
var id: Long? = null
var botId: Long? = null
var enable: Byte? = null
companion object {

View File

@ -1,8 +1,9 @@
package info.alinadace.miraibot.service.drink_water.task
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
import info.alinadace.miraibot.service.drink_water.domain.DrinkWaterUser
import info.alinadace.miraibot.service.drink_water.mapper.DrinkWaterMapper
import jakarta.annotation.Resource
import net.mamoe.mirai.Bot
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@ -21,22 +22,25 @@ class ReminderService {
val log: Logger = LoggerFactory.getLogger(this::class.java)
}
@Resource
lateinit var bot: Bot
@Resource
lateinit var drinkWaterMapper: DrinkWaterMapper
@Scheduled(cron = "0 0 0,8-23/2 * * *")
suspend fun reminder() {
log.info("定时喝水提醒服务 - 开始")
val list = drinkWaterMapper.selectList(
LambdaQueryWrapper<DrinkWaterUser>()
KtQueryWrapper(DrinkWaterUser())
.eq(DrinkWaterUser::enable, DrinkWaterUser.ENABLE)
)
log.info("定时喝水提醒服务 - 查询结果 - {}", list)
list.forEach {
if (it.botId == 0L) {
if (it.botId == null || it.botId == 0L) {
return@forEach
}
bot.getFriend(it.botId)?.sendMessage("请喝水")
bot.getFriend(it.botId!!)?.sendMessage("请喝水")
log.info("定时喝水提醒服务 - 发送消息 - {}", it.botId)
}
log.info("定时喝水提醒服务 - 结束")

View File

@ -1,5 +1,7 @@
bot:
id: 3437522130
type: password
password: nobuts001
spring:
data:
redis:
@ -10,3 +12,6 @@ spring:
url: jdbc:mysql://localhost:3306/mirai?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username: root
password: nobuts001
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

View File

@ -1,5 +1,7 @@
bot:
id: 3437522130
type: password
password: nobuts001
spring:
data:
redis: