Compare commits

..

27 Commits

Author SHA1 Message Date
Grand-cocoa
e7ad348544 修改打包方式Action
Some checks failed
Mirai-build / Explore-Gitea-Actions (push) Failing after 9s
2024-12-26 14:37:13 +08:00
Grand-cocoa
7cedd4e152 修改依赖库
All checks were successful
Mirai-build / Explore-Gitea-Actions (push) Successful in 2s
2024-12-26 14:33:54 +08:00
Grand-cocoa
7d36b6d9dc 修改依赖库
All checks were successful
Mirai-build / Explore-Gitea-Actions (push) Successful in 2s
2024-12-26 14:30:47 +08:00
Grand-cocoa
84c2a7d82d 修改依赖库
Some checks failed
Mirai-build / Explore-Gitea-Actions (push) Failing after 11s
2024-12-26 14:20:25 +08:00
Grand-cocoa
787520c98b 修改 打包方式
Some checks failed
Mirai-build / Explore-Gitea-Actions (push) Failing after 12s
2024-12-26 14:16:22 +08:00
Grand-cocoa
f818241731 修改 实现改为workflow
Some checks failed
Mirai-build / Explore-Gitea-Actions (push) Failing after 26s
2024-12-25 19:08:33 +08:00
Grand-cocoa
10ed0dc703 ```更改数据库用户名以符合专用配置
Some checks failed
Mirai-build / Explore-Gitea-Actions (push) Failing after 10s
将应用的数据库用户名从root更改为mirai,以符合专用的数据库配置设置。此次更改对于与特定环境要求保持一致是必要的。
```
2024-09-18 19:04:27 +08:00
Grand-cocoa
f4475cd09d ```在Dockerfile中添加WORKDIR指令
Some checks failed
Mirai-build / Explore-Gitea-Actions (push) Failing after 10s
在Dockerfile中包含WORKDIR指令,确保容器内的默认工作目录设置为/opt。此更改对于在容器启动时正确执行后续命令至关重要。
```
2024-09-18 18:56:15 +08:00
Grand-cocoa
3aadf53e0e 明确指定配置文件添加路径
Some checks failed
Mirai-build / Explore-Gitea-Actions (push) Failing after 10s
更新了Dockerfile以指定配置文件的确切路径。这确保了`android_pad.json`、`device.json`和`KFCFactory.json`文件将被正确地添加到容器的`/opt`目录下,而不是基于当前工作目录的相对路径。此更改对于避免在构建Docker镜像期间的路径解析问题至关重要。
2024-09-18 18:52:25 +08:00
Grand-cocoa
a7fcb58f98 ```更新Docker镜像中的启动配置和文件
Some checks failed
Mirai-build / Explore-Gitea-Actions (push) Failing after 10s
将Dockerfile中的主要启动文件从'spring-boot-docker.jar'更新为'Mirai-bot.jar',并相应地调整了ENTRYPOINT命令。不再使用的旧文件已从镜像构建脚本中移除,确保Docker镜像配置与新的项目文件对齐。
```
2024-09-18 18:51:04 +08:00
Grand-cocoa
80a782f41d ```优化Dockerfile中的命令执行
Some checks failed
Mirai-build / Explore-Gitea-Actions (push) Failing after 11s
将'CMD'指令更改为'ENTRYPOINT',以允许更好地控制Spring Boot应用程序的启动方式。此更改使得在容器启动时能够更灵活地传递参数给Java命令。
```
2024-09-18 18:48:36 +08:00
Grand-cocoa
2fed165aba 添加华为云插件仓库以支持maven构建
Some checks failed
Mirai-build / Explore-Gitea-Actions (push) Failing after 13s
2024-09-18 18:44:48 +08:00
Grand-cocoa
67ac79e17f 添加华为云仓库以支持新插件的集成
Some checks failed
Mirai-build / Explore-Gitea-Actions (push) Failing after 10s
2024-09-18 18:20:23 +08:00
Grand-cocoa
791fee74d4 工作流优化:简化仓库克隆路径配置
Some checks failed
Mirai-build / Explore-Gitea-Actions (push) Failing after 10s
在Gitea Actions工作流中,已更新仓库克隆目录的路径设置,以简化为当前目录下的相对路径。这样做旨在避免潜在的权限问题,并使工作流的配置更加清晰。
2024-09-18 17:57:25 +08:00
Grand-cocoa
3b3d5b6fa6 工作流优化:简化仓库克隆路径配置
Some checks failed
Mirai-build / Explore-Gitea-Actions (push) Failing after 2s
在Gitea Actions工作流中,已更新仓库克隆目录的路径设置,以简化为当前目录下的相对路径。这样做旨在避免潜在的权限问题,并使工作流的配置更加清晰。
2024-09-18 17:56:47 +08:00
Grand-cocoa
4b3deaa520 修正构建和测试工作流中的目录变更错误
Some checks failed
Mirai-build / Explore-Gitea-Actions (push) Failing after 10s
之前的工作流配置错误地从根目录运行命令,而不是从预期的子目录运行。此更改确保命令在正确的项目目录中执行,以避免任何构建或测试过程中的潜在错误。
2024-09-18 17:54:06 +08:00
Grand-cocoa
45f79398fd ```在构建测试工作流中添加初始化步骤
Some checks failed
Mirai-build / Explore-Gitea-Actions (push) Failing after 10s
添加了两个新步骤来打印当前工作目录和列出克隆存储库目录的内容。这将帮助诊断克隆和构建过程中遇到的任何问题。

更改前:```
rm -rf $CLONED_REPO_DIR
git clone $BARE_REPO_DIR $CLONED_REPO_DIR
run: cd $CLONED_REPO_DIR
run: chmod +x ./mvnw
run: sh ./mvnw -DskipTests=true clean package -P prod
run: docker build -t mirai-bot:latest
```

更改后:
```
rm -rf $CLONED_REPO_DIR
git clone $BARE
2024-09-18 17:52:51 +08:00
Grand-cocoa
24179727ed ```将BARE_REPO_DIR更新为远程URL
Some checks failed
Mirai-build / Explore-Gitea-Actions (push) Failing after 10s
将BARE_REPO_DIR环境变量的值从本地路径更改为完整的远程Git仓库URL,以便正确配置仓库位置。
```
2024-09-18 17:51:50 +08:00
Grand-cocoa
27755a6d7b ```设置Mirai-bot项目构建测试工作流
Some checks failed
Mirai-build / Explore-Gitea-Actions (push) Failing after 2s
更新了Gitea Actions的配置,使其能够适配Mirai-bot项目的构建和测试。工作流被重命名为“Mirai-build”,并且新的环境变量指定了裸仓库和克隆仓库的目录。此外,流程中包含了一个新的步骤,用于克隆仓库,并且运行的命令现在会导航到克隆的目录并使`mvnw`可执行。
```
2024-09-18 17:49:53 +08:00
Grand-cocoa
47fbae8703 修正构建流程中的工作目录错误在Gitea的CI/CD流程中,更新了build-test.yaml文件,以明确构建脚本的执行路径。此更改确保构建脚本在正确的目录下执行,避免因路径问题导致的构建错误。
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 2s
2024-09-18 17:42:16 +08:00
Grand-cocoa
a941c05a75 修正构建流程中的工作目录错误在Gitea的CI/CD流程中,更新了build-test.yaml文件,以明确构建脚本的执行路径。此更改确保构建脚本在正确的目录下执行,避免因路径问题导致的构建错误。
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 3s
2024-09-18 17:41:30 +08:00
Grand-cocoa
8f532c5686 修正构建流程中的工作目录错误在Gitea的CI/CD流程中,更新了build-test.yaml文件,以明确构建脚本的执行路径。此更改确保构建脚本在正确的目录下执行,避免因路径问题导致的构建错误。
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 2s
2024-09-18 17:40:39 +08:00
Grand-cocoa
f81ddde881 ```使用华为云Maven镜像更新Maven依赖项
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 2s
此提交通过修改Maven配置文件和包装脚本,将Maven依赖项来源更新为华为云镜像。此更改旨在优化Maven包的下载速度和稳定性。
```
2024-09-18 17:36:11 +08:00
Grand-cocoa
ee6403eb7d ```工作流更新与设备信息添加
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 2s
- 重构`.gitea/workflows/build-test.yaml`,优化Maven构建流程,省略非必要步骤。
- 实现`device.json`文件,模拟设备信息,适用于mirai设备。
- 更新`Dockerfile`,自动化构建流程,包括必要的配置文件。
```
2024-09-18 17:25:48 +08:00
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
Grand-cocoa
90307e1ee9 refactor(miraibot): 更新注解和服务配置
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 23s
- 修正BotFunction注解中的Service属性值。
- 直接使用KClass<out Event>初始化functionMap。- 在Initialization类中添加全局事件订阅。
- 重构BotConfig类,增加类型和管理员QQ配置。
2024-09-18 14:30:47 +08:00
21 changed files with 395 additions and 43 deletions

View File

@ -1,19 +1,18 @@
name: Gitea Actions Demo name: Mirai-build
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [ push ] on: [ push ]
env:
BARE_REPO_DIR: https://git.alina-dace.info/Dace/Mirai-bot.git
CLONED_REPO_DIR: ./
jobs: jobs:
Explore-Gitea-Actions: Explore-Gitea-Actions:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event." - run: |
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!" rm -rf ./*
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." git clone $BARE_REPO_DIR $CLONED_REPO_DIR
- name: Check out repository code - run: pwd
uses: actions/checkout@v4 # - run: ls -sl
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner." # - run: chmod +x ./mvnw
- run: echo "🖥️ The workflow is now ready to test your code on the runner." - run: docker run -it --rm --name my-maven-project -v "$(pwd)":/usr/src/mymaven -v maven-repo:/root/.m2 -w /usr/src/mymaven maven mvn -DskipTests=true clean package -P prod-remote
- name: List files in the repository - run: docker build -t mirai-bot:latest
run: |
ls ${{ gitea.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."

View File

@ -6,7 +6,7 @@
# "License"); you may not use this file except in compliance # "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at # with the License. You may obtain a copy of the License at
# #
# https://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, # Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an # software distributed under the License is distributed on an
@ -16,4 +16,4 @@
# under the License. # under the License.
wrapperVersion=3.3.2 wrapperVersion=3.3.2
distributionType=only-script distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.7/apache-maven-3.9.7-bin.zip distributionUrl=https://mirrors.huaweicloud.com/repository/maven//org/apache/maven/apache-maven/3.9.7/apache-maven-3.9.7-bin.zip

13
Dockerfile Normal file
View File

@ -0,0 +1,13 @@
#FROM maven as builder
#WORKDIR /app
#COPY . .
#RUN mvn clean package
FROM bellsoft/liberica-openjdk-debian:17.0.11-cds
LABEL authors="Kane"
WORKDIR /opt
#COPY --from=builder /app/target/Mirai-bot-0.0.1-SNAPSHOT.jar /opt/Mirai-bot.jar
COPY target/Mirai-bot-0.0.1-SNAPSHOT.jar /opt/Mirai-bot.jar
ENTRYPOINT java -jar /opt/Mirai-bot.jar

Binary file not shown.

2
mvnw vendored
View File

@ -8,7 +8,7 @@
# "License"); you may not use this file except in compliance # "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at # with the License. You may obtain a copy of the License at
# #
# https://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, # Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an # software distributed under the License is distributed on an

2
mvnw.cmd vendored
View File

@ -8,7 +8,7 @@
@REM "License"); you may not use this file except in compliance @REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at @REM with the License. You may obtain a copy of the License at
@REM @REM
@REM https://www.apache.org/licenses/LICENSE-2.0 @REM http://www.apache.org/licenses/LICENSE-2.0
@REM @REM
@REM Unless required by applicable law or agreed to in writing, @REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an @REM software distributed under the License is distributed on an

58
pom.xml
View File

@ -42,11 +42,37 @@
<profiles.active>prod</profiles.active> <profiles.active>prod</profiles.active>
</properties> </properties>
</profile> </profile>
<profile>
<id>prod-remote</id>
<properties>
<profiles.active>prod-remote</profiles.active>
</properties>
</profile>
</profiles> </profiles>
<properties> <properties>
<java.version>17</java.version> <java.version>17</java.version>
<kotlin.version>1.9.25</kotlin.version> <kotlin.version>1.9.25</kotlin.version>
</properties> </properties>
<repositories>
<repository>
<id>HuaweiCloud</id>
<name>HuaweiCloud</name>
<url>https://mirrors.huaweicloud.com/repository/maven</url>
</repository>
<!-- Maven 官方仓库 -->
<repository>
<id>MavenOfficial</id>
<name>MavenOfficial</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>HuaweiCloud</id>
<name>HuaweiCloud</name>
<url>https://mirrors.huaweicloud.com/repository/maven</url>
</pluginRepository>
</pluginRepositories>
<dependencies> <dependencies>
<!-- 运行依赖 --> <!-- 运行依赖 -->
<dependency> <dependency>
@ -77,10 +103,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>
@ -99,9 +121,16 @@
</dependency> </dependency>
<!-- 核心 机器人 --> <!-- 核心 机器人 -->
<!-- https://mvnrepository.com/artifact/top.mrxiaom.mirai/overflow-core -->
<dependency>
<groupId>top.mrxiaom.mirai</groupId>
<artifactId>overflow-core</artifactId>
<version>1.0.1</version>
</dependency>
<dependency> <dependency>
<groupId>net.mamoe</groupId> <groupId>net.mamoe</groupId>
<artifactId>mirai-core-jvm</artifactId> <artifactId>mirai-core-api-jvm</artifactId>
<version>2.16.0</version> <version>2.16.0</version>
</dependency> </dependency>
@ -110,6 +139,22 @@
<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>
</dependencies> </dependencies>
<build> <build>
@ -119,6 +164,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,9 +1,13 @@
package info.alinadace.miraibot package info.alinadace.miraibot
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
@SpringBootApplication @SpringBootApplication
@EnableScheduling
@MapperScan("info.alinadace.miraibot.service")
class MiraiBotApplication class MiraiBotApplication
fun main(args: Array<String>) { fun main(args: Array<String>) {

View File

@ -13,5 +13,5 @@ import kotlin.reflect.KClass
*/ */
@Target(AnnotationTarget.CLASS) @Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME) @Retention(AnnotationRetention.RUNTIME)
@org.springframework.stereotype.Service("BotFunction") @org.springframework.stereotype.Service
annotation class BotFunction(vararg val value: KClass<out Event>) annotation class BotFunction(vararg val value: KClass<out Event>)

View File

@ -2,15 +2,14 @@ package info.alinadace.miraibot.bean
import info.alinadace.miraibot.annotation.BotFunction import info.alinadace.miraibot.annotation.BotFunction
import info.alinadace.miraibot.configuration.BotConfig import info.alinadace.miraibot.configuration.BotConfig
import info.alinadace.miraibot.enums.LoginType
import info.alinadace.miraibot.service.Service import info.alinadace.miraibot.service.Service
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import net.mamoe.mirai.Bot import net.mamoe.mirai.Bot
import net.mamoe.mirai.BotFactory
import net.mamoe.mirai.auth.BotAuthorization
import net.mamoe.mirai.event.Event import net.mamoe.mirai.event.Event
import net.mamoe.mirai.utils.BotConfiguration
import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.Configuration
import top.mrxiaom.overflow.BotBuilder
import kotlin.reflect.KClass import kotlin.reflect.KClass
/** /**
@ -23,15 +22,13 @@ class BotConfiguration {
@Bean @Bean
fun bot(config: BotConfig): Bot { fun bot(config: BotConfig): Bot {
return when (config.type) { val connect = runBlocking {
LoginType.PASSWORD -> BotFactory.newBot(config.id, config.password) { val bot = async {
extracted() BotBuilder.positive(config.ws).token(config.token).connect() ?: throw Exception("Bot connect failed")
}
LoginType.QRCODE -> BotFactory.newBot(config.id, BotAuthorization.byQRCode()) {
extracted()
} }
bot.await()
} }
return connect
} }
@Bean("functionMap") @Bean("functionMap")
@ -57,10 +54,4 @@ class BotConfiguration {
} }
return eventMap return eventMap
} }
private fun BotConfiguration.extracted() {
fileBasedDeviceInfo()
protocol = BotConfiguration.MiraiProtocol.MACOS
enableContactCache()
}
} }

View File

@ -6,25 +6,54 @@ import org.springframework.context.annotation.Configuration
/** /**
* 机器人配置 * 机器人配置
* @param id 机器人QQ号
* @param password 机器人密码
* @author Kane * @author Kane
* @since 2024/8/29 下午2:39 * @since 2024/8/29 下午2:39
*/ */
@Configuration @Configuration
@ConfigurationProperties("bot") @ConfigurationProperties("bot")
class BotConfig { class BotConfig {
/**
* 机器人QQ号
*/
@Deprecated(message = "内部认证已失效")
final var id: Long = 0L final var id: Long = 0L
/**
* 机器人密码
*/
@Deprecated(message = "内部认证已失效")
final var password: String = "" final var password: String = ""
/**
* 机器人登录方式
*/
@Deprecated(message = "内部认证已失效")
final var type: LoginType = LoginType.PASSWORD final var type: LoginType = LoginType.PASSWORD
/**
* 机器人ws地址
*/
final var ws: String = ""
/**
* 机器人token
*/
final var token: String = ""
/**
* 管理员QQ
*/
final var admin: Long = 0L final var admin: Long = 0L
constructor() constructor()
constructor(id: Long, password: String, type: LoginType, admin: Long) { constructor(id: Long, password: String, type: LoginType, ws: String, token: String, admin: Long) {
this.id = id this.id = id
this.password = password this.password = password
this.type = type this.type = type
this.ws = ws
this.token = token
this.admin = admin this.admin = admin
} }
} }

View File

@ -18,6 +18,7 @@ import kotlin.reflect.KClass
*/ */
@org.springframework.stereotype.Service @org.springframework.stereotype.Service
class Initialization { class Initialization {
@Suppress("SpringJavaInjectionPointsAutowiringInspection")
@Resource(name = "functionMap") @Resource(name = "functionMap")
lateinit var functionMap: HashMap<KClass<out Event>, MutableList<Service<Event>>> lateinit var functionMap: HashMap<KClass<out Event>, MutableList<Service<Event>>>
@ -36,6 +37,10 @@ class Initialization {
} }
} }
GlobalEventChannel.subscribeAlways(Event::class) {
log.info("GlobalEvent: {}", this)
}
log.info("Channel complete") log.info("Channel complete")
log.info("Login: id:{}", bot.id) log.info("Login: id:{}", bot.id)
bot.login() bot.login()

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,11 @@
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: 101.35.164.171
password: wTE32JjsieQ2JTOwsg9X
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://101.35.164.171:3306/mirai?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username: mirai
password: FydsaZsFm5w26We6

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: mirai
password: FydsaZsFm5w26We6

View File

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