Compare commits

...

2 Commits

Author SHA1 Message Date
Grand-cocoa
fc65e875e2 和数据库提醒服务优化
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`配置,支持新协议。

这些更改提高了数据库操作的便捷性,增强了网络请求的处理能力,并通过协议优化改善了整体性能。
2024-09-18 17:12:51 +08:00
Grand-cocoa
6b18dd55a7 新功能:实现定时喝水提醒服务
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s
添加了一个定时任务,用于每两小时提醒用户喝水。同时,引入了开启和关闭该提醒服务的功能,用户可以通过消息与机器人互动来管理提醒服务。此更新涉及数据库映射、服务类和定时任务的创建。
2024-09-18 14:41:19 +08:00
14 changed files with 314 additions and 5 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.

30
pom.xml
View File

@ -77,10 +77,6 @@
<groupId>org.jetbrains.kotlinx</groupId> <groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-reactor</artifactId> <artifactId>kotlinx-coroutines-reactor</artifactId>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId></groupId>-->
<!-- <artifactId></artifactId>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>com.mysql</groupId> <groupId>com.mysql</groupId>
@ -110,6 +106,29 @@
<artifactId>hutool-http</artifactId> <artifactId>hutool-http</artifactId>
<version>5.8.27</version> <version>5.8.27</version>
</dependency> </dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>3.5.7</version>
</dependency>
<dependency>
<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> </dependencies>
<build> <build>
@ -119,6 +138,9 @@
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.jetbrains.kotlin</groupId> <groupId>org.jetbrains.kotlin</groupId>

View File

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

View File

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

View File

@ -0,0 +1,68 @@
package info.alinadace.miraibot.service.drink_water
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
import info.alinadace.miraibot.service.drink_water.mapper.DrinkWaterMapper
import jakarta.annotation.Resource
import net.mamoe.mirai.event.events.FriendMessageEvent
import net.mamoe.mirai.message.data.MessageSource
import net.mamoe.mirai.message.data.PlainText
import org.slf4j.Logger
import org.slf4j.LoggerFactory
/**
* 定时喝水提醒关闭服务
* @author Kane
* @since 2024/9/18 13:27
*/
@BotFunction(FriendMessageEvent::class)
class DisableService : Service<FriendMessageEvent> {
companion object {
val log: Logger = LoggerFactory.getLogger(this::class.java)
}
@Resource
lateinit var drinkWaterMapper: DrinkWaterMapper
/**
* 服务入口
*/
override fun entrance(event: FriendMessageEvent): Boolean {
val chain = event.message
val filter = chain.filter { it !is MessageSource }
if (filter.size == 1 && filter[0] is PlainText) {
if (filter[0].contentToString() == "关闭喝水提醒") {
return true
}
}
return false
}
/**
* 服务行为
*/
override suspend fun active(event: FriendMessageEvent) {
log.info("服务关闭请求 - DrinkWater - target:{}", event.sender.id)
val one = drinkWaterMapper.selectOne(
KtQueryWrapper(DrinkWaterUser())
.eq(DrinkWaterUser::botId, event.sender.id)
)
if (one == null) {
event.subject.sendMessage("服务已关闭 - DrinkWater")
log.info("服务已关闭 - DrinkWater - target:{} - 无记录", event.sender.id)
return
}
if (one.enable == DrinkWaterUser.ENABLE) {
one.enable = DrinkWaterUser.DISABLE
val updateById = drinkWaterMapper.updateById(one)
event.subject.sendMessage("服务已关闭 - DrinkWater")
log.info("服务已关闭 - DrinkWater - target:{} - 记录更新 - {}", event.sender.id, updateById)
return
}
event.subject.sendMessage("服务已关闭 - DrinkWater")
}
}

View File

@ -0,0 +1,73 @@
package info.alinadace.miraibot.service.drink_water
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
import info.alinadace.miraibot.service.drink_water.mapper.DrinkWaterMapper
import jakarta.annotation.Resource
import net.mamoe.mirai.event.events.FriendMessageEvent
import net.mamoe.mirai.message.data.MessageSource
import net.mamoe.mirai.message.data.PlainText
import org.slf4j.Logger
import org.slf4j.LoggerFactory
/**
* 定时喝水提醒开启服务
* @author Kane
* @since 2024/9/18 13:27
*/
@BotFunction(FriendMessageEvent::class)
class EnableService : Service<FriendMessageEvent> {
companion object {
val log: Logger = LoggerFactory.getLogger(this::class.java)
}
@Resource
lateinit var drinkWaterMapper: DrinkWaterMapper
/**
* 服务入口
*/
override fun entrance(event: FriendMessageEvent): Boolean {
val chain = event.message
val filter = chain.filter { it !is MessageSource }
if (filter.size == 1 && filter[0] is PlainText) {
if (filter[0].contentToString() == "开启喝水提醒") {
return true
}
}
return false
}
/**
* 服务行为
*/
override suspend fun active(event: FriendMessageEvent) {
log.info("服务开启请求 - DrinkWater - target:{}", event.sender.id)
val one = drinkWaterMapper.selectOne(
KtQueryWrapper(DrinkWaterUser())
.eq(DrinkWaterUser::botId, event.sender.id)
)
if (one == null) {
val let = DrinkWaterUser().apply {
botId = event.sender.id
enable = DrinkWaterUser.ENABLE
}.let {
drinkWaterMapper.insert(it)
}
event.subject.sendMessage("服务已开启 - DrinkWater")
log.info("服务开启请求 - DrinkWater - target:{} - 记录创建 - {}", event.sender.id, let)
return
}
if (one.enable == DrinkWaterUser.DISABLE) {
one.enable = DrinkWaterUser.ENABLE
val updateById = drinkWaterMapper.updateById(one)
event.subject.sendMessage("服务已开启 - DrinkWater")
log.info("服务开启请求 - DrinkWater - target:{} - 记录更新 - {}", event.sender.id, updateById)
return
}
event.subject.sendMessage("服务已开启 - DrinkWater")
}
}

View File

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

View File

@ -0,0 +1,12 @@
package info.alinadace.miraibot.service.drink_water.mapper
import com.baomidou.mybatisplus.core.mapper.BaseMapper
import info.alinadace.miraibot.service.drink_water.domain.DrinkWaterUser
/**
* 喝水提醒用户Mapper
* @author Kane
* @since 2024/9/18 13:39
*/
interface DrinkWaterMapper : BaseMapper<DrinkWaterUser> {
}

View File

@ -0,0 +1,49 @@
package info.alinadace.miraibot.service.drink_water.task
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
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Service
/**
* 定时喝水提醒服务
* @author Kane
* @since 2024/9/18 13:59
*/
@Service
class ReminderService {
companion object {
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(
KtQueryWrapper(DrinkWaterUser())
.eq(DrinkWaterUser::enable, DrinkWaterUser.ENABLE)
)
log.info("定时喝水提醒服务 - 查询结果 - {}", list)
list.forEach {
if (it.botId == null || it.botId == 0L) {
return@forEach
}
bot.getFriend(it.botId!!)?.sendMessage("请喝水")
log.info("定时喝水提醒服务 - 发送消息 - {}", it.botId)
}
log.info("定时喝水提醒服务 - 结束")
}
}

View File

@ -1,2 +1,17 @@
bot: bot:
id: 3437522130 id: 3437522130
type: password
password: nobuts001
spring:
data:
redis:
host: 101.35.164.171
password: wTE32JjsieQ2JTOwsg9X
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
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

@ -0,0 +1,14 @@
bot:
id: 3437522130
type: password
password: nobuts001
spring:
data:
redis:
host: 10.0.4.16
password: wTE32JjsieQ2JTOwsg9X
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://10.0.4.16:3306/mirai?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username: root
password: FydsaZsFm5w26We6

View File

@ -8,3 +8,4 @@ bot:
admin: 1075576561 admin: 1075576561
server: server:
port: 25684 # 无用随机端口 port: 25684 # 无用随机端口