mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-04 16:42:37 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
5ebee874c8
@ -43,5 +43,6 @@ dependencies {
|
||||
api(group = "org.yaml", name = "snakeyaml", version = "1.25")
|
||||
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")
|
||||
// classpath is not set correctly by IDE
|
||||
}
|
@ -10,19 +10,22 @@ package net.mamoe.mirai
|
||||
*/
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import net.mamoe.mirai.api.http.MiraiHttpAPIServer
|
||||
import net.mamoe.mirai.api.http.generateSessionKey
|
||||
import net.mamoe.mirai.contact.sendMessage
|
||||
import net.mamoe.mirai.plugins.PluginManager
|
||||
import net.mamoe.mirai.plugins.loadAsConfig
|
||||
import net.mamoe.mirai.plugins.withDefaultWrite
|
||||
import net.mamoe.mirai.plugins.withDefaultWriteSave
|
||||
import net.mamoe.mirai.api.http.MiraiHttpAPIServer
|
||||
import net.mamoe.mirai.api.http.generateSessionKey
|
||||
import net.mamoe.mirai.contact.sendMessage
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
import net.mamoe.mirai.utils.SimpleLogger
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider
|
||||
import java.io.File
|
||||
import java.io.PrintStream
|
||||
import java.security.Security
|
||||
import java.util.*
|
||||
import java.util.concurrent.LinkedBlockingQueue
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
|
||||
object MiraiConsole {
|
||||
val bots
|
||||
get() = Bot.instances
|
||||
@ -48,7 +51,6 @@ object MiraiConsole {
|
||||
val build = "Beta"
|
||||
|
||||
fun start() {
|
||||
MiraiConsoleUI.start()
|
||||
logger("Mirai-console [v$version $build | core version v$coreVersion] is still in testing stage, majority feature is available")
|
||||
logger("Mirai-console now running under " + System.getProperty("user.dir"))
|
||||
logger("Get news in github: https://github.com/mamoe/mirai")
|
||||
@ -65,7 +67,6 @@ object MiraiConsole {
|
||||
logger("Mirai-console 启动完成")
|
||||
logger("\"/login qqnumber qqpassword \" to login a bot")
|
||||
logger("\"/login qq号 qq密码 \" 来登陆一个BOT")
|
||||
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
@ -108,14 +109,15 @@ object MiraiConsole {
|
||||
}
|
||||
val qqNumber = it[0].toLong()
|
||||
val qqPassword = it[1]
|
||||
logger("login...")
|
||||
logger("[Bot Login]", 0, "login...")
|
||||
try {
|
||||
runBlocking {
|
||||
Bot(qqNumber, qqPassword).alsoLogin()
|
||||
println("$qqNumber login successes")
|
||||
logger("[Bot Login]", 0, "$qqNumber login successes")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
println("$qqNumber login failed")
|
||||
logger("[Bot Login]", 0, "$qqNumber login failed -> " + e.message)
|
||||
e.printStackTrace()
|
||||
}
|
||||
true
|
||||
}
|
||||
@ -234,14 +236,15 @@ object MiraiConsole {
|
||||
}
|
||||
|
||||
object CommandListener {
|
||||
val commandChannel: Queue<String> = LinkedBlockingQueue<String>()
|
||||
fun start() {
|
||||
thread {
|
||||
//processNextCommandLine()
|
||||
processNextCommandLine()
|
||||
}
|
||||
}
|
||||
|
||||
tailrec fun processNextCommandLine() {
|
||||
var fullCommand = readLine()
|
||||
var fullCommand = commandChannel.poll()
|
||||
if (fullCommand != null) {
|
||||
if (!fullCommand.startsWith("/")) {
|
||||
fullCommand = "/$fullCommand"
|
||||
@ -283,11 +286,14 @@ class MiraiConsoleLoader {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
Security.removeProvider("BC")
|
||||
Security.addProvider(BouncyCastleProvider())
|
||||
//Security.addProvider(BouncyCastle)
|
||||
MiraiConsoleUI.start()
|
||||
MiraiConsole.start()
|
||||
Runtime.getRuntime().addShutdownHook(thread(start = false) {
|
||||
MiraiConsole.stop()
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +70,11 @@ object MiraiConsoleUI {
|
||||
|
||||
hasStart = true
|
||||
val defaultTerminalFactory = DefaultTerminalFactory(internalPrinter, System.`in`, Charset.defaultCharset())
|
||||
defaultTerminalFactory.setInitialTerminalSize(
|
||||
TerminalSize(
|
||||
90, 120
|
||||
)
|
||||
)
|
||||
try {
|
||||
terminal = defaultTerminalFactory.createTerminal()
|
||||
terminal.enterPrivateMode()
|
||||
@ -168,6 +173,7 @@ object MiraiConsoleUI {
|
||||
update()
|
||||
}
|
||||
KeyType.Enter -> {
|
||||
MiraiConsole.CommandListener.commandChannel.offer(commandBuilder.toString())
|
||||
emptyCommand()
|
||||
}
|
||||
else -> {
|
||||
@ -290,8 +296,6 @@ object MiraiConsoleUI {
|
||||
if (currentHeight + heightNeed > maxHeight) {
|
||||
cleanPage()
|
||||
}
|
||||
textGraphics.foregroundColor = TextColor.ANSI.GREEN
|
||||
textGraphics.backgroundColor = TextColor.ANSI.DEFAULT
|
||||
val width = terminal.terminalSize.columns - 7
|
||||
var x = string
|
||||
while (true) {
|
||||
@ -306,6 +310,8 @@ object MiraiConsoleUI {
|
||||
}
|
||||
}
|
||||
try {
|
||||
textGraphics.foregroundColor = TextColor.ANSI.GREEN
|
||||
textGraphics.backgroundColor = TextColor.ANSI.DEFAULT
|
||||
textGraphics.putString(3, currentHeight, toWrite, SGR.ITALIC)
|
||||
} catch (ignored: Exception) {
|
||||
//
|
||||
@ -401,11 +407,23 @@ object MiraiConsoleUI {
|
||||
}
|
||||
|
||||
|
||||
var lastEmpty: Job? = null
|
||||
private fun emptyCommand() {
|
||||
commandBuilder = StringBuilder()
|
||||
redrawCommand()
|
||||
if (terminal is SwingTerminal) {
|
||||
redrawCommand()
|
||||
terminal.flush()
|
||||
} else {
|
||||
lastEmpty = GlobalScope.launch {
|
||||
delay(100)
|
||||
if (lastEmpty == coroutineContext[Job]) {
|
||||
terminal.clearScreen()
|
||||
//inited = false
|
||||
update()
|
||||
redrawCommand()
|
||||
redrawLogs(log[screens[currentScreenId]]!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user