mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-03 06:52:43 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
9710e34d82
16
.github/workflows/main.yml
vendored
16
.github/workflows/main.yml
vendored
@ -9,9 +9,15 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- name: setup-android
|
- name: Setup Java JDK
|
||||||
uses: msfjarvis/setup-android@0.2
|
uses: actions/setup-java@v1.3.0
|
||||||
with:
|
with:
|
||||||
# Gradle tasks to run - If you want to run ./gradlew assemble, specify assemble here.
|
# The Java version to make available on the path. Takes a whole or semver Java version, or 1.x syntax (e.g. 1.8 => Java 8.x)
|
||||||
gradleTasks: build -x mirai-core:jvmTest
|
java-version: 11
|
||||||
|
# The package type (jre, jdk, jdk+fx)
|
||||||
|
java-package: jdk+fx
|
||||||
|
- name: Gradle Command
|
||||||
|
uses: eskatos/gradle-command-action@v1
|
||||||
|
with:
|
||||||
|
# Gradle command line arguments, see gradle --help
|
||||||
|
arguments: build -x mirai-core:jvmTest
|
||||||
|
@ -187,3 +187,4 @@ bot.subscribeAlways<MemberPermissionChangedEvent> {
|
|||||||
## Acknowledgement
|
## Acknowledgement
|
||||||
特别感谢 [JetBrains](https://www.jetbrains.com/?from=mirai) 为开源项目提供免费的 [IntelliJ IDEA](https://www.jetbrains.com/idea/?from=mirai) 等 IDE 的授权
|
特别感谢 [JetBrains](https://www.jetbrains.com/?from=mirai) 为开源项目提供免费的 [IntelliJ IDEA](https://www.jetbrains.com/idea/?from=mirai) 等 IDE 的授权
|
||||||
[<img src=".github/jetbrains-variant-3.png" width="200"/>](https://www.jetbrains.com/?from=mirai)
|
[<img src=".github/jetbrains-variant-3.png" width="200"/>](https://www.jetbrains.com/?from=mirai)
|
||||||
|
|
@ -29,6 +29,7 @@ dependencies {
|
|||||||
api(project(":mirai-console"))
|
api(project(":mirai-console"))
|
||||||
runtimeOnly(files("../mirai-core-qqandroid/build/classes/kotlin/jvm/main"))
|
runtimeOnly(files("../mirai-core-qqandroid/build/classes/kotlin/jvm/main"))
|
||||||
api(group = "no.tornado", name = "tornadofx", version = "1.7.19")
|
api(group = "no.tornado", name = "tornadofx", version = "1.7.19")
|
||||||
|
api(group = "com.jfoenix", name = "jfoenix", version = "9.0.8")
|
||||||
api("org.bouncycastle:bcprov-jdk15on:1.64")
|
api("org.bouncycastle:bcprov-jdk15on:1.64")
|
||||||
// classpath is not set correctly by IDE
|
// classpath is not set correctly by IDE
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package net.mamoe.mirai.console.graphical.view
|
|||||||
|
|
||||||
import javafx.scene.control.TabPane
|
import javafx.scene.control.TabPane
|
||||||
import javafx.stage.Modality
|
import javafx.stage.Modality
|
||||||
import net.mamoe.mirai.Bot
|
|
||||||
import net.mamoe.mirai.console.graphical.controller.MiraiGraphicalUIController
|
import net.mamoe.mirai.console.graphical.controller.MiraiGraphicalUIController
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
|
|
||||||
|
@ -6,14 +6,24 @@ class MiraiConsoleTerminalLoader {
|
|||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
MiraiConsoleTerminalUI.start()
|
if (args.contains("pure") || args.contains("-pure") || System.getProperty(
|
||||||
thread {
|
"os.name",
|
||||||
MiraiConsole.start(
|
""
|
||||||
MiraiConsoleTerminalUI
|
).toLowerCase().contains("windows")
|
||||||
)
|
) {
|
||||||
|
println("[MiraiConsoleTerminalLoader]: 将以Pure[兼容模式]启动Console")
|
||||||
|
MiraiConsole.start(MiraiConsoleUIPure())
|
||||||
|
} else {
|
||||||
|
MiraiConsoleTerminalUI.start()
|
||||||
|
thread {
|
||||||
|
MiraiConsole.start(
|
||||||
|
MiraiConsoleTerminalUI
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Runtime.getRuntime().addShutdownHook(thread(start = false) {
|
Runtime.getRuntime().addShutdownHook(thread(start = false) {
|
||||||
MiraiConsole.stop()
|
MiraiConsole.stop()
|
||||||
|
MiraiConsoleTerminalUI.exit()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -227,19 +227,6 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI {
|
|||||||
|
|
||||||
hasStart = true
|
hasStart = true
|
||||||
val defaultTerminalFactory = DefaultTerminalFactory(internalPrinter, System.`in`, Charset.defaultCharset())
|
val defaultTerminalFactory = DefaultTerminalFactory(internalPrinter, System.`in`, Charset.defaultCharset())
|
||||||
|
|
||||||
val fontSize = 12
|
|
||||||
defaultTerminalFactory
|
|
||||||
.setInitialTerminalSize(
|
|
||||||
TerminalSize(
|
|
||||||
101, 60
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setTerminalEmulatorFontConfiguration(
|
|
||||||
SwingTerminalFontConfiguration.newInstance(
|
|
||||||
Font("Monospaced", Font.PLAIN, fontSize)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
try {
|
try {
|
||||||
terminal = defaultTerminalFactory.createTerminal()
|
terminal = defaultTerminalFactory.createTerminal()
|
||||||
terminal.enterPrivateMode()
|
terminal.enterPrivateMode()
|
||||||
@ -353,7 +340,7 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI {
|
|||||||
emptyCommand()
|
emptyCommand()
|
||||||
}
|
}
|
||||||
KeyType.Escape -> {
|
KeyType.Escape -> {
|
||||||
exitProcess(0)
|
exit()
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
if (keyStroke.character != null) {
|
if (keyStroke.character != null) {
|
||||||
@ -649,6 +636,16 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI {
|
|||||||
}
|
}
|
||||||
redrawLogs(log[screens[currentScreenId]]!!)
|
redrawLogs(log[screens[currentScreenId]]!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun exit() {
|
||||||
|
try {
|
||||||
|
terminal.exitPrivateMode()
|
||||||
|
terminal.close()
|
||||||
|
exitProcess(0)
|
||||||
|
} catch (ignored: Exception) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,43 @@
|
|||||||
# Mirai Console
|
# Mirai Console
|
||||||
#### Mirai Console allows you to run Mirai in command lines/terminal.
|
你可以在全平台运行Mirai高效率机器人框架
|
||||||
#### 你可以终端中或命令行环境下运行在Mirai
|
### Mirai Console提供了6个版本以满足各种需要
|
||||||
<br>
|
#### 所有版本的Mirai Console API相同 插件系统相同
|
||||||
|
|
||||||
|
| 名字 | 介绍 |
|
||||||
|
| --- | --- |
|
||||||
|
| Mirai-Console-Pure | 最纯净版, CLI环境, 通过标准输入与标准输出 交互 |
|
||||||
|
| Mirai-Console-Terminal | (UNIX)Terminal环境 提供简介好用的富文本控制台 |
|
||||||
|
| Mirai-Console-Android | 安卓APP (TODO) |
|
||||||
|
| Mirai-Console-Graphical | JavaFX的图形化界面, 有Native版本(.jar/.exe/.dmg) |
|
||||||
|
| Mirai-Console-WebPanel | Web Panel操作(TODO) |
|
||||||
|
| Mirai-Console-Ios | IOS APP (TODO) |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### 如何选择版本
|
||||||
|
1: Mirai-Console-Pure 兼容性最高, 在其他都表现不佳的时候请使用</br>
|
||||||
|
2: 以系统区分
|
||||||
|
```kotlin
|
||||||
|
return when(operatingSystem){
|
||||||
|
WINDOWS -> listOf("Graphical","WebPanel","Pure")
|
||||||
|
MAC_OS -> listOf("Graphical","Terminal","WebPanel","Pure")
|
||||||
|
LINUX -> listOf("Terminal","Pure")
|
||||||
|
ANDROID -> listOf("Android","Pure","WebPanel")
|
||||||
|
IOS -> listOf("Ios")
|
||||||
|
else -> listOf("Pure")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
3: 以策略区分
|
||||||
|
```kotlin
|
||||||
|
return when(task){
|
||||||
|
体验 -> listOf("Graphical","Terminal","WebPanel","Android","Pure")
|
||||||
|
测试插件 -> listOf("Pure")
|
||||||
|
调试插件 -> byOperatingSystem()
|
||||||
|
稳定挂机 -> listOf("Terminal","Pure")
|
||||||
|
else -> listOf("Pure")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
#### More Importantly, Mirai Console support <b>Plugins</b>, tells the bot what to do
|
#### More Importantly, Mirai Console support <b>Plugins</b>, tells the bot what to do
|
||||||
#### Mirai Console 支持插件系统, 你可以自己开发或使用公开的插件来逻辑化机器人, 如群管
|
#### Mirai Console 支持插件系统, 你可以自己开发或使用公开的插件来逻辑化机器人, 如群管
|
||||||
|
@ -7,7 +7,6 @@ plugins {
|
|||||||
|
|
||||||
apply(plugin = "com.github.johnrengelman.shadow")
|
apply(plugin = "com.github.johnrengelman.shadow")
|
||||||
|
|
||||||
|
|
||||||
val kotlinVersion: String by rootProject.ext
|
val kotlinVersion: String by rootProject.ext
|
||||||
val atomicFuVersion: String by rootProject.ext
|
val atomicFuVersion: String by rootProject.ext
|
||||||
val coroutinesVersion: String by rootProject.ext
|
val coroutinesVersion: String by rootProject.ext
|
||||||
@ -23,6 +22,11 @@ fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$v
|
|||||||
|
|
||||||
fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version"
|
fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version"
|
||||||
|
|
||||||
|
tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>() {
|
||||||
|
manifest {
|
||||||
|
attributes["Main-Class"] = "net.mamoe.mirai.console.MiraiConsolePureLoader"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@ -35,7 +39,6 @@ dependencies {
|
|||||||
api(group = "com.alibaba", name = "fastjson", version = "1.2.62")
|
api(group = "com.alibaba", name = "fastjson", version = "1.2.62")
|
||||||
api(group = "org.yaml", name = "snakeyaml", version = "1.25")
|
api(group = "org.yaml", name = "snakeyaml", version = "1.25")
|
||||||
api(group = "com.moandjiezana.toml", name = "toml4j", version = "0.7.2")
|
api(group = "com.moandjiezana.toml", name = "toml4j", version = "0.7.2")
|
||||||
api(group = "com.googlecode.lanterna", name = "lanterna", version = "3.0.2")
|
|
||||||
api("org.bouncycastle:bcprov-jdk15on:1.64")
|
api("org.bouncycastle:bcprov-jdk15on:1.64")
|
||||||
|
|
||||||
implementation("no.tornado:tornadofx:1.7.17")
|
implementation("no.tornado:tornadofx:1.7.17")
|
||||||
|
@ -49,6 +49,8 @@ object MiraiConsole {
|
|||||||
var coreVersion = "v0.15.1"
|
var coreVersion = "v0.15.1"
|
||||||
val build = "Beta"
|
val build = "Beta"
|
||||||
|
|
||||||
|
var allDown = false
|
||||||
|
|
||||||
lateinit var frontEnd: MiraiConsoleUI
|
lateinit var frontEnd: MiraiConsoleUI
|
||||||
fun start(
|
fun start(
|
||||||
frontEnd: MiraiConsoleUI
|
frontEnd: MiraiConsoleUI
|
||||||
@ -80,6 +82,14 @@ object MiraiConsole {
|
|||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
PluginManager.disableAllPlugins()
|
PluginManager.disableAllPlugins()
|
||||||
|
allDown = true
|
||||||
|
try {
|
||||||
|
bots.forEach {
|
||||||
|
it.get()?.close()
|
||||||
|
}
|
||||||
|
} catch (ignored: Exception) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object HTTPAPIAdaptar {
|
object HTTPAPIAdaptar {
|
||||||
@ -287,6 +297,9 @@ object MiraiConsole {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tailrec fun processNextCommandLine() {
|
tailrec fun processNextCommandLine() {
|
||||||
|
if (allDown) {
|
||||||
|
return
|
||||||
|
}
|
||||||
var fullCommand = commandChannel.poll()
|
var fullCommand = commandChannel.poll()
|
||||||
if (fullCommand != null) {
|
if (fullCommand != null) {
|
||||||
if (!fullCommand.startsWith("/")) {
|
if (!fullCommand.startsWith("/")) {
|
||||||
|
@ -0,0 +1,74 @@
|
|||||||
|
package net.mamoe.mirai.console
|
||||||
|
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import net.mamoe.mirai.Bot
|
||||||
|
import net.mamoe.mirai.utils.DefaultLoginSolver
|
||||||
|
import net.mamoe.mirai.utils.LoginSolver
|
||||||
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
|
class MiraiConsoleUIPure() : MiraiConsoleUI {
|
||||||
|
var requesting = false
|
||||||
|
var requestStr = ""
|
||||||
|
|
||||||
|
init {
|
||||||
|
thread {
|
||||||
|
while (true) {
|
||||||
|
val input = readLine() ?: ""
|
||||||
|
if (requesting) {
|
||||||
|
requestStr = input
|
||||||
|
requesting = false
|
||||||
|
} else {
|
||||||
|
MiraiConsole.CommandListener.commandChannel.offer(input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pushLog(identity: Long, message: String) {
|
||||||
|
println(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun prePushBot(identity: Long) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pushBot(bot: Bot) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pushVersion(consoleVersion: String, consoleBuild: String, coreVersion: String) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun requestInput(question: String): String {
|
||||||
|
requesting = true
|
||||||
|
while (true) {
|
||||||
|
delay(50)
|
||||||
|
if (!requesting) {
|
||||||
|
return requestStr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pushBotAdminStatus(identity: Long, admins: List<Long>) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createLoginSolver(): LoginSolver {
|
||||||
|
return DefaultLoginSolver()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class MiraiConsolePureLoader {
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
MiraiConsole.start(MiraiConsoleUIPure())
|
||||||
|
Runtime.getRuntime().addShutdownHook(thread(start = false) {
|
||||||
|
MiraiConsole.stop()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user