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
5ebee874
Commit
5ebee874
authored
Feb 15, 2020
by
Him188
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
b7e4dc07
119c07dd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
16 deletions
+41
-16
mirai-console/build.gradle.kts
mirai-console/build.gradle.kts
+1
-0
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt
...i-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt
+19
-13
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsoleUI.kt
...console/src/main/kotlin/net/mamoe/mirai/MiraiConsoleUI.kt
+21
-3
No files found.
mirai-console/build.gradle.kts
View file @
5ebee874
...
...
@@ -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
}
\ No newline at end of file
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt
View file @
5ebee874
...
...
@@ -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
()
})
}
}
}
...
...
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsoleUI.kt
View file @
5ebee874
...
...
@@ -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
]]
!!
)
}
}
}
}
...
...
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