Skip to content

Commit

Permalink
Merge pull request #158 from HoshinoTented/master
Browse files Browse the repository at this point in the history
Fix: buggy config
  • Loading branch information
ryoii authored Sep 10, 2020
2 parents bb1c5eb + b35d18c commit 74ce843
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ host: '0.0.0.0'
# 可选,默认值为8080
port: 8080

# 可选,默认由插件随机生成,建议手动指定
# 可选,默认由插件第一次启动时随机生成,建议手动指定
authKey: 1234567890

# 可选,缓存大小,默认4096.缓存过小会导致引用回复与撤回消息失败
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ object HttpApiPluginBase : KotlinPlugin(HttpApiPluginDescription) {
var services: MiraiApiHttpServices = MiraiApiHttpServices(this);

override fun onLoad() {
logger.info("Loading Mirai HTTP API plugin")
}

override fun onEnable() {
Setting.reload()

with(Setting) {
logger.info("Loading Mirai HTTP API plugin")
logger.info("Trying to Start Mirai HTTP Server in 0.0.0.0:$port")

if (authKey.startsWith("INITKEY")) {
logger.warning("USING INITIAL KEY, please edit the key")
}

services.onLoad()
}
}

override fun onEnable() {
Setting.reload()

with(Setting) {
logger.info("Starting Mirai HTTP Server in $host:$port")
MiraiHttpAPIServer.start(host, port, authKey)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package net.mamoe.mirai.api.http.config

import kotlinx.serialization.Serializable
import net.mamoe.mirai.api.http.generateSessionKey
import net.mamoe.mirai.api.http.HttpApiPluginBase
import net.mamoe.mirai.api.http.generateSessionKey
import net.mamoe.mirai.console.data.*
import net.mamoe.mirai.console.util.ConsoleInternalAPI

typealias Destination = String
typealias Destinations = List<Destination>

/**
* Mirai Api Http 的配置文件类,它应该是单例,并且在 [HttpApiPluginBase.onEnable] 时被初始化
*/
object Setting : AutoSavePluginConfig() {
object Setting : AbstractPluginData(), PluginConfig {

/**
* 上报子消息配置
*
Expand Down Expand Up @@ -75,7 +77,7 @@ object Setting : AutoSavePluginConfig() {
val port: Int by value(8080)

/**
* 认证密钥,默认为随机生成
* 认证密钥,默认为随机
*/
val authKey: String by value("INITKEY" + generateSessionKey())

Expand All @@ -99,4 +101,14 @@ object Setting : AutoSavePluginConfig() {
* 心跳服务配置
*/
val heartbeat: HeartBeat by value(HeartBeat())

@ConsoleInternalAPI
override fun onStored(owner: PluginDataHolder, storage: PluginDataStorage) {
// do nothing
}

@ConsoleInternalAPI
override fun onValueChanged(value: Value<*>) {
// do nothing
}
}

0 comments on commit 74ce843

Please sign in to comment.