Skip to content

Commit

Permalink
mirai-starter
Browse files Browse the repository at this point in the history
  • Loading branch information
ForteScarlet committed Nov 6, 2020
1 parent 77dc6c8 commit 6ed3bd2
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2020. ForteScarlet All rights reserved.
* Project parent
* File AsMiraiConfig.java
*
* You can contact the author through the following channels:
* github https://github.com/ForteScarlet
* gitee https://gitee.com/ForteScarlet
* email [email protected]
* QQ 1149159218
*/

package love.forte.simbot.component.mirai.configuration;

import love.forte.common.configuration.annotation.AsConfig;
import love.forte.common.utils.annotation.AnnotateMapping;

import java.lang.annotation.*;

/**
* @author <a href="https://github.com/ForteScarlet"> ForteScarlet </a>
*/
@Retention(RetentionPolicy.RUNTIME) //注解会在class字节码文件中存在,在运行时可以通过反射获取到
@Target({ElementType.TYPE}) //接口、类、枚举、注解、方法
@Documented
@AsConfig
@AnnotateMapping(AsConfig.class)
public @interface AsMiraiConfig {


/** 前缀,默认为空 */
String prefix() default "simbot.component.mirai";

/** 后缀,默认为空 */
String suffix() default "";

/**
* 如果在配置类上标注此注解且此参数为 {@code true},
* 则没有标记 {@link love.forte.common.configuration.annotation.ConfigInject} 的字段也会被默认作为配置字段而添加。
*/
boolean allField() default false;

/**
* 进行深层注入,即会扫描父类的字段。
* @return
*/
boolean deep() default true;

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package love.forte.simbot.component.mirai.configuration
import cn.hutool.crypto.SecureUtil
import love.forte.common.configuration.annotation.ConfigInject
import love.forte.common.ioc.annotation.Beans
import love.forte.simbot.annotation.AsSimbotConfig
import love.forte.simbot.component.mirai.SimbotMiraiLogger
import net.mamoe.mirai.utils.*
import java.io.File
Expand All @@ -33,69 +32,69 @@ import kotlin.random.nextInt
*
*/
@Beans
@AsSimbotConfig
@AsMiraiConfig
public class MiraiConfiguration {

/**
* mirai心跳周期. 过长会导致被服务器断开连接. 单位毫秒
* @see BotConfiguration.heartbeatPeriodMillis
*/
@field:ConfigInject("mirai.heartbeatPeriodMillis", orIgnore = true)
@field:ConfigInject
var heartbeatPeriodMillis: Long = BotConfiguration.Default.heartbeatPeriodMillis

/**
* 每次心跳时等待结果的时间.
* 一旦心跳超时, 整个网络服务将会重启 (将消耗约 1s). 除正在进行的任务 (如图片上传) 会被中断外, 事件和插件均不受影响.
* @see BotConfiguration.heartbeatTimeoutMillis
*/
@field:ConfigInject("mirai.heartbeatTimeoutMillis", orIgnore = true)
@field:ConfigInject
var heartbeatTimeoutMillis: Long = BotConfiguration.Default.heartbeatTimeoutMillis

/** 心跳失败后的第一次重连前的等待时间. */
@field:ConfigInject("mirai.firstReconnectDelayMillis", orIgnore = true)
@field:ConfigInject
var firstReconnectDelayMillis: Long = BotConfiguration.Default.firstReconnectDelayMillis

/** 重连失败后, 继续尝试的每次等待时间 */
@field:ConfigInject("mirai.reconnectPeriodMillis", orIgnore = true)
@field:ConfigInject
var reconnectPeriodMillis: Long = BotConfiguration.Default.reconnectPeriodMillis

/** 最多尝试多少次重连 */
@field:ConfigInject("mirai.reconnectionRetryTimes", orIgnore = true)
@field:ConfigInject
var reconnectionRetryTimes: Int = BotConfiguration.Default.reconnectionRetryTimes


/** 使用协议类型 */
@field:ConfigInject("mirai.protocol", orIgnore = true)
@field:ConfigInject
var protocol: BotConfiguration.MiraiProtocol = BotConfiguration.Default.protocol

/** 关闭mirai的bot logger */
@field:ConfigInject("mirai.noBotLog", orIgnore = true)
@field:ConfigInject
var noBotLog: Boolean = false

/** 关闭mirai网络日志 */
@field:ConfigInject("mirai.noNetworkLog", orIgnore = true)
@field:ConfigInject
var noNetworkLog: Boolean = false

/** mirai bot log切换使用simbot的log */
@field:ConfigInject("mirai.useSimbotBotLog", orIgnore = true)
@field:ConfigInject
var useSimbotBotLog: Boolean = true

/** mirai 网络log 切换使用simbot的log */
@field:ConfigInject("mirai.useSimbotNetworkLog", orIgnore = true)
@field:ConfigInject
var useSimbotNetworkLog: Boolean = true

/** mirai配置自定义deviceInfoSeed的时候使用的随机种子。默认为1. */
@field:ConfigInject("mirai.deviceInfoSeed", orIgnore = true)
@field:ConfigInject
var deviceInfoSeed: Long = 1L


// @field:ConfigInject("mirai.autoRelogin")
// var autoRelogin: Boolean = false

@field:ConfigInject("mirai.cacheType", orIgnore = true)
@field:ConfigInject
var cacheType: MiraiCacheType = MiraiCacheType.FILE

@field:ConfigInject("mirai.cacheDirectory", orIgnore = true)
@field:ConfigInject
var cacheDirectory: String? = null


Expand Down

This file was deleted.

6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@
<artifactId>core-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>love.forte.simple-robot</groupId>
<artifactId>component-mirai-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<!--</editor-fold>-->

<!--</editor-fold>-->
Expand Down
61 changes: 61 additions & 0 deletions spring-boot-starter/component-mirai-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-boot-starter</artifactId>
<groupId>love.forte.simple-robot</groupId>
<version>2.0.0-ALPHA.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>component-mirai-spring-boot-starter</artifactId>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>

<dependency>
<groupId>love.forte.simple-robot</groupId>
<artifactId>core-spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>love.forte.simple-robot</groupId>
<artifactId>component-mirai</artifactId>
<exclusions>
<!-- exclusion log. -->
<exclusion>
<groupId>love.forte.common</groupId>
<artifactId>log</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>love.forte.common</groupId>
<artifactId>configuration</artifactId>
</dependency>

<dependency>
<groupId>love.forte.common</groupId>
<artifactId>ioc</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>

</dependencies>

</project>
Loading

0 comments on commit 6ed3bd2

Please sign in to comment.