Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
bd568a7c
Commit
bd568a7c
authored
Feb 18, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Suspend console
parent
4108e58e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
34 deletions
+37
-34
mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt
...onsole/graphical/controller/MiraiGraphicalUIController.kt
+2
-2
mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/LoginFragment.kt
...n/net/mamoe/mirai/console/graphical/view/LoginFragment.kt
+4
-2
mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalUI.kt
.../kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalUI.kt
+5
-5
mirai-console/src/main/kotlin/net/mamoe/mirai/console/Command.kt
...onsole/src/main/kotlin/net/mamoe/mirai/console/Command.kt
+8
-8
mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt
...e/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt
+12
-14
mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleUIPure.kt
...main/kotlin/net/mamoe/mirai/console/MiraiConsoleUIPure.kt
+6
-3
No files found.
mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt
View file @
bd568a7c
...
@@ -24,8 +24,8 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI {
...
@@ -24,8 +24,8 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI {
val
botList
=
observableListOf
<
BotModel
>()
val
botList
=
observableListOf
<
BotModel
>()
val
consoleInfo
=
ConsoleInfo
()
val
consoleInfo
=
ConsoleInfo
()
fun
login
(
qq
:
String
,
psd
:
String
)
{
suspend
fun
login
(
qq
:
String
,
psd
:
String
)
{
MiraiConsole
.
CommandListener
.
commandChannel
.
offer
(
"/login $qq $psd"
)
MiraiConsole
.
CommandListener
.
commandChannel
.
send
(
"/login $qq $psd"
)
}
}
override
fun
pushLog
(
identity
:
Long
,
message
:
String
)
=
Platform
.
runLater
{
override
fun
pushLog
(
identity
:
Long
,
message
:
String
)
=
Platform
.
runLater
{
...
...
mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/LoginFragment.kt
View file @
bd568a7c
package
net.mamoe.mirai.console.graphical.view
package
net.mamoe.mirai.console.graphical.view
import
com.jfoenix.controls.JFXTextField
import
javafx.beans.property.SimpleStringProperty
import
javafx.beans.property.SimpleStringProperty
import
kotlinx.coroutines.runBlocking
import
net.mamoe.mirai.console.graphical.controller.MiraiGraphicalUIController
import
net.mamoe.mirai.console.graphical.controller.MiraiGraphicalUIController
import
net.mamoe.mirai.console.graphical.util.jfxButton
import
net.mamoe.mirai.console.graphical.util.jfxButton
import
net.mamoe.mirai.console.graphical.util.jfxPasswordfield
import
net.mamoe.mirai.console.graphical.util.jfxPasswordfield
...
@@ -24,7 +24,9 @@ class LoginFragment : Fragment() {
...
@@ -24,7 +24,9 @@ class LoginFragment : Fragment() {
}
}
}
}
jfxButton
(
"登录"
).
action
{
jfxButton
(
"登录"
).
action
{
controller
.
login
(
qq
.
value
,
psd
.
value
)
runBlocking
{
controller
.
login
(
qq
.
value
,
psd
.
value
)
}
close
()
close
()
}
}
}
}
...
...
mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalUI.kt
View file @
bd568a7c
...
@@ -10,7 +10,6 @@ import com.googlecode.lanterna.terminal.DefaultTerminalFactory
...
@@ -10,7 +10,6 @@ import com.googlecode.lanterna.terminal.DefaultTerminalFactory
import
com.googlecode.lanterna.terminal.Terminal
import
com.googlecode.lanterna.terminal.Terminal
import
com.googlecode.lanterna.terminal.TerminalResizeListener
import
com.googlecode.lanterna.terminal.TerminalResizeListener
import
com.googlecode.lanterna.terminal.swing.SwingTerminal
import
com.googlecode.lanterna.terminal.swing.SwingTerminal
import
com.googlecode.lanterna.terminal.swing.SwingTerminalFontConfiguration
import
com.googlecode.lanterna.terminal.swing.SwingTerminalFrame
import
com.googlecode.lanterna.terminal.swing.SwingTerminalFrame
import
kotlinx.coroutines.*
import
kotlinx.coroutines.*
import
kotlinx.coroutines.io.close
import
kotlinx.coroutines.io.close
...
@@ -23,7 +22,6 @@ import net.mamoe.mirai.console.MiraiConsoleTerminalUI.LoggerDrawer.redrawLogs
...
@@ -23,7 +22,6 @@ import net.mamoe.mirai.console.MiraiConsoleTerminalUI.LoggerDrawer.redrawLogs
import
net.mamoe.mirai.utils.LoginSolver
import
net.mamoe.mirai.utils.LoginSolver
import
net.mamoe.mirai.utils.createCharImg
import
net.mamoe.mirai.utils.createCharImg
import
net.mamoe.mirai.utils.writeChannel
import
net.mamoe.mirai.utils.writeChannel
import
java.awt.Font
import
java.io.File
import
java.io.File
import
java.io.OutputStream
import
java.io.OutputStream
import
java.io.PrintStream
import
java.io.PrintStream
...
@@ -126,12 +124,12 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI {
...
@@ -126,12 +124,12 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI {
}
}
fun
provideInput
(
input
:
String
)
{
suspend
fun
provideInput
(
input
:
String
)
{
if
(
requesting
)
{
if
(
requesting
)
{
requestResult
=
input
requestResult
=
input
requesting
=
false
requesting
=
false
}
else
{
}
else
{
MiraiConsole
.
CommandListener
.
commandChannel
.
offer
(
MiraiConsole
.
CommandListener
.
commandChannel
.
send
(
commandBuilder
.
toString
()
commandBuilder
.
toString
()
)
)
}
}
...
@@ -336,7 +334,9 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI {
...
@@ -336,7 +334,9 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI {
update
()
update
()
}
}
KeyType
.
Enter
->
{
KeyType
.
Enter
->
{
provideInput
(
commandBuilder
.
toString
())
runBlocking
{
provideInput
(
commandBuilder
.
toString
())
}
emptyCommand
()
emptyCommand
()
}
}
KeyType
.
Escape
->
{
KeyType
.
Escape
->
{
...
...
mirai-console/src/main/kotlin/net/mamoe/mirai/console/Command.kt
View file @
bd568a7c
...
@@ -42,7 +42,7 @@ object CommandManager {
...
@@ -42,7 +42,7 @@ object CommandManager {
registeredCommand
.
remove
(
commandName
)
registeredCommand
.
remove
(
commandName
)
}
}
fun
runCommand
(
fullCommand
:
String
):
Boolean
{
suspend
fun
runCommand
(
fullCommand
:
String
):
Boolean
{
val
blocks
=
fullCommand
.
split
(
" "
)
val
blocks
=
fullCommand
.
split
(
" "
)
val
commandHead
=
blocks
[
0
].
replace
(
"/"
,
""
)
val
commandHead
=
blocks
[
0
].
replace
(
"/"
,
""
)
if
(!
registeredCommand
.
containsKey
(
commandHead
))
{
if
(!
registeredCommand
.
containsKey
(
commandHead
))
{
...
@@ -66,7 +66,7 @@ interface ICommand {
...
@@ -66,7 +66,7 @@ interface ICommand {
val
name
:
String
val
name
:
String
val
alias
:
List
<
String
>
val
alias
:
List
<
String
>
val
description
:
String
val
description
:
String
fun
onCommand
(
args
:
List
<
String
>):
Boolean
suspend
fun
onCommand
(
args
:
List
<
String
>):
Boolean
fun
register
()
fun
register
()
}
}
...
@@ -77,9 +77,9 @@ abstract class Command(
...
@@ -77,9 +77,9 @@ abstract class Command(
)
:
ICommand
{
)
:
ICommand
{
/**
/**
* 最高优先级监听器
* 最高优先级监听器
* 如果
return [false] 这次指令不会被[PluginBase]的全局onCommand
监听器监听
* 如果
return `false` 这次指令不会被 [PluginBase] 的全局 onCommand
监听器监听
* */
* */
open
override
fun
onCommand
(
args
:
List
<
String
>):
Boolean
{
open
override
suspend
fun
onCommand
(
args
:
List
<
String
>):
Boolean
{
return
true
return
true
}
}
...
@@ -92,9 +92,9 @@ class AnonymousCommand internal constructor(
...
@@ -92,9 +92,9 @@ class AnonymousCommand internal constructor(
override
val
name
:
String
,
override
val
name
:
String
,
override
val
alias
:
List
<
String
>,
override
val
alias
:
List
<
String
>,
override
val
description
:
String
,
override
val
description
:
String
,
val
onCommand
:
ICommand
.(
args
:
List
<
String
>)
->
Boolean
val
onCommand
:
suspend
ICommand
.(
args
:
List
<
String
>)
->
Boolean
)
:
ICommand
{
)
:
ICommand
{
override
fun
onCommand
(
args
:
List
<
String
>):
Boolean
{
override
suspend
fun
onCommand
(
args
:
List
<
String
>):
Boolean
{
return
onCommand
.
invoke
(
this
,
args
)
return
onCommand
.
invoke
(
this
,
args
)
}
}
...
@@ -107,9 +107,9 @@ class CommandBuilder internal constructor() {
...
@@ -107,9 +107,9 @@ class CommandBuilder internal constructor() {
var
name
:
String
?
=
null
var
name
:
String
?
=
null
var
alias
:
List
<
String
>?
=
null
var
alias
:
List
<
String
>?
=
null
var
description
:
String
=
""
var
description
:
String
=
""
var
onCommand
:
(
ICommand
.(
args
:
List
<
String
>)
->
Boolean
)?
=
null
var
onCommand
:
(
suspend
ICommand
.(
args
:
List
<
String
>)
->
Boolean
)?
=
null
fun
onCommand
(
commandProcess
:
ICommand
.(
args
:
List
<
String
>)
->
Boolean
)
{
fun
onCommand
(
commandProcess
:
suspend
ICommand
.(
args
:
List
<
String
>)
->
Boolean
)
{
onCommand
=
commandProcess
onCommand
=
commandProcess
}
}
...
...
mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt
View file @
bd568a7c
...
@@ -9,20 +9,20 @@ package net.mamoe.mirai.console
...
@@ -9,20 +9,20 @@ package net.mamoe.mirai.console
* https://github.com/mamoe/mirai/blob/master/LICENSE
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
*/
import
kotlinx.coroutines.runBlocking
import
kotlinx.coroutines.*
import
kotlinx.coroutines.channels.Channel
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.api.http.MiraiHttpAPIServer
import
net.mamoe.mirai.api.http.MiraiHttpAPIServer
import
net.mamoe.mirai.api.http.generateSessionKey
import
net.mamoe.mirai.api.http.generateSessionKey
import
net.mamoe.mirai.console.MiraiConsole.CommandListener.processNextCommandLine
import
net.mamoe.mirai.console.plugins.PluginManager
import
net.mamoe.mirai.console.plugins.PluginManager
import
net.mamoe.mirai.console.plugins.loadAsConfig
import
net.mamoe.mirai.console.plugins.loadAsConfig
import
net.mamoe.mirai.console.plugins.withDefaultWrite
import
net.mamoe.mirai.console.plugins.withDefaultWrite
import
net.mamoe.mirai.console.plugins.withDefaultWriteSave
import
net.mamoe.mirai.console.plugins.withDefaultWriteSave
import
net.mamoe.mirai.contact.sendMessage
import
net.mamoe.mirai.contact.sendMessage
import
net.mamoe.mirai.utils.
*
import
net.mamoe.mirai.utils.
SimpleLogger
import
java.io.File
import
java.io.File
import
java.util.*
import
java.util.*
import
java.util.concurrent.LinkedBlockingQueue
import
kotlin.concurrent.thread
object
MiraiConsole
{
object
MiraiConsole
{
...
@@ -288,20 +288,19 @@ object MiraiConsole {
...
@@ -288,20 +288,19 @@ object MiraiConsole {
}
}
}
}
object
CommandListener
{
object
CommandListener
:
Job
by
{
val
commandChannel
:
Queue
<
String
>
=
LinkedBlockingQueue
<
String
>()
GlobalScope
.
launch
(
start
=
CoroutineStart
.
LAZY
)
{
fun
start
()
{
processNextCommandLine
()
thread
{
processNextCommandLine
()
}
}
}
}()
{
val
commandChannel
:
Channel
<
String
>
=
Channel
()
tailrec
fun
processNextCommandLine
()
{
suspend
fun
processNextCommandLine
()
{
if
(
allDown
)
{
if
(
allDown
)
{
return
return
}
}
var
fullCommand
=
commandChannel
.
poll
()
for
(
command
in
commandChannel
)
{
if
(
fullCommand
!=
null
)
{
var
fullCommand
=
command
if
(!
fullCommand
.
startsWith
(
"/"
))
{
if
(!
fullCommand
.
startsWith
(
"/"
))
{
fullCommand
=
"/$fullCommand"
fullCommand
=
"/$fullCommand"
}
}
...
@@ -309,7 +308,6 @@ object MiraiConsole {
...
@@ -309,7 +308,6 @@ object MiraiConsole {
logger
(
"未知指令 $fullCommand"
)
logger
(
"未知指令 $fullCommand"
)
}
}
}
}
processNextCommandLine
();
}
}
}
}
...
...
mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleUIPure.kt
View file @
bd568a7c
package
net.mamoe.mirai.console
package
net.mamoe.mirai.console
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.runBlocking
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.utils.DefaultLoginSolver
import
net.mamoe.mirai.utils.DefaultLoginSolver
import
net.mamoe.mirai.utils.LoginSolver
import
net.mamoe.mirai.utils.LoginSolver
import
net.mamoe.mirai.utils.LoginSolverInputReader
import
net.mamoe.mirai.utils.LoginSolverInputReader
import
kotlin.concurrent.thread
import
kotlin.concurrent.thread
class
MiraiConsoleUIPure
()
:
MiraiConsoleUI
{
class
MiraiConsoleUIPure
:
MiraiConsoleUI
{
var
requesting
=
false
var
requesting
=
false
var
requestStr
=
""
var
requestStr
=
""
init
{
init
{
thread
{
thread
{
while
(
true
)
{
while
(
true
)
{
val
input
=
readLine
()
?:
""
val
input
=
readLine
()
?:
return
@
thread
if
(
requesting
)
{
if
(
requesting
)
{
requestStr
=
input
requestStr
=
input
requesting
=
false
requesting
=
false
}
else
{
}
else
{
MiraiConsole
.
CommandListener
.
commandChannel
.
offer
(
input
)
runBlocking
{
MiraiConsole
.
CommandListener
.
commandChannel
.
send
(
input
)
}
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment