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
baa3e56d
Commit
baa3e56d
authored
Feb 15, 2020
by
Him188
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
25b3b2b2
1437ad70
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
251 additions
and
230 deletions
+251
-230
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/MiraiHttpAPIServer.kt
...ain/kotlin/net/mamoe/mirai/api/http/MiraiHttpAPIServer.kt
+13
-1
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/BaseRoute.kt
...c/main/kotlin/net/mamoe/mirai/api/http/route/BaseRoute.kt
+8
-1
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt
...i-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt
+6
-5
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsoleUI.kt
...console/src/main/kotlin/net/mamoe/mirai/MiraiConsoleUI.kt
+224
-223
No files found.
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/MiraiHttpAPIServer.kt
View file @
baa3e56d
...
...
@@ -11,10 +11,15 @@ package net.mamoe.mirai.api.http
import
io.ktor.application.Application
import
io.ktor.server.cio.CIO
import
io.ktor.server.engine.applicationEngineEnvironment
import
io.ktor.server.engine.connector
import
io.ktor.server.engine.embeddedServer
import
io.ktor.util.KtorExperimentalAPI
import
net.mamoe.mirai.api.http.route.mirai
import
net.mamoe.mirai.utils.DefaultLogger
import
org.slf4j.LoggerFactory
import
org.slf4j.helpers.NOPLogger
import
org.slf4j.helpers.NOPLoggerFactory
object
MiraiHttpAPIServer
{
...
...
@@ -39,7 +44,14 @@ object MiraiHttpAPIServer {
// TODO: start是无阻塞的,理应获取启动状态后再执行后续代码
try
{
embeddedServer
(
CIO
,
port
,
module
=
Application
::
mirai
).
start
()
embeddedServer
(
CIO
,
environment
=
applicationEngineEnvironment
{
this
.
log
=
NOPLoggerFactory
().
getLogger
(
"NMYSL"
)
this
.
module
(
Application
::
mirai
)
connector
{
this
.
port
=
port
}
}).
start
()
logger
.
info
(
"Http api server is running with authKey: ${SessionManager.authKey}"
)
callback
?.
invoke
()
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/BaseRoute.kt
View file @
baa3e56d
...
...
@@ -35,11 +35,18 @@ import net.mamoe.mirai.api.http.data.common.DTO
import
net.mamoe.mirai.api.http.data.common.VerifyDTO
import
net.mamoe.mirai.api.http.util.jsonParseOrNull
import
net.mamoe.mirai.api.http.util.toJson
import
org.slf4j.Logger
import
org.slf4j.helpers.NOPLogger
import
org.slf4j.helpers.NOPLoggerFactory
import
org.slf4j.impl.SimpleLogger
import
org.slf4j.impl.SimpleLoggerFactory
fun
Application
.
mirai
()
{
install
(
DefaultHeaders
)
install
(
CallLogging
)
install
(
CallLogging
)
{
logger
=
NOPLoggerFactory
().
getLogger
(
"NMSL"
)
}
authModule
()
messageModule
()
infoModule
()
...
...
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt
View file @
baa3e56d
...
...
@@ -19,6 +19,7 @@ import net.mamoe.mirai.api.http.generateSessionKey
import
net.mamoe.mirai.contact.sendMessage
import
net.mamoe.mirai.utils.MiraiLogger
import
java.io.File
import
java.io.PrintStream
import
kotlin.concurrent.thread
object
MiraiConsole
{
...
...
@@ -37,8 +38,7 @@ object MiraiConsole {
val
pluginManager
:
PluginManager
get
()
=
PluginManager
var
logger
:
MiraiConsoleLogger
=
UIPushLogger
()
var
logger
=
UIPushLogger
(
0
)
var
path
:
String
=
System
.
getProperty
(
"user.dir"
)
...
...
@@ -255,11 +255,11 @@ object MiraiConsole {
}
}
class
UIPushLogger
(
override
val
identity
:
String
?,
override
var
follower
:
MiraiLogger
?)
:
MiraiLogger
{
o
verride
fun
invoke
(
any
:
Any
?
)
{
class
UIPushLogger
(
val
identity
:
Long
)
{
o
perator
fun
invoke
(
any
:
Any
?
=
null
)
{
MiraiConsoleUI
.
start
()
if
(
any
!=
null
)
{
MiraiConsoleUI
.
pushLog
(
0
,
"[Mirai$version $build]: $any"
)
MiraiConsoleUI
.
pushLog
(
identity
,
"[Mirai$version $build]: $any"
)
}
}
}
...
...
@@ -281,6 +281,7 @@ class MiraiConsoleLoader {
companion
object
{
@JvmStatic
fun
main
(
args
:
Array
<
String
>)
{
MiraiConsole
.
start
()
Runtime
.
getRuntime
().
addShutdownHook
(
thread
(
start
=
false
)
{
MiraiConsole
.
stop
()
...
...
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsoleUI.kt
View file @
baa3e56d
...
...
@@ -11,6 +11,8 @@ import com.googlecode.lanterna.terminal.Terminal
import
com.googlecode.lanterna.terminal.TerminalResizeListener
import
com.googlecode.lanterna.terminal.swing.SwingTerminal
import
com.googlecode.lanterna.terminal.swing.SwingTerminalFrame
import
java.io.OutputStream
import
java.io.PrintStream
import
java.lang.StringBuilder
import
java.util.*
import
kotlin.concurrent.thread
...
...
@@ -29,9 +31,9 @@ object MiraiConsoleUI {
log
[
uin
]
=
LimitLinkedQueue
()
}
fun
pushLog
(
uin
:
Long
,
str
:
String
)
{
log
[
uin
]
!!
.
push
(
str
)
}
lateinit
var
terminal
:
Terminal
lateinit
var
textGraphics
:
TextGraphics
var
hasStart
=
false
fun
start
()
{
...
...
@@ -40,25 +42,64 @@ object MiraiConsoleUI {
}
hasStart
=
true
val
defaultTerminalFactory
=
DefaultTerminalFactory
()
var
terminal
:
Terminal
?
=
null
try
{
terminal
=
defaultTerminalFactory
.
createTerminal
()
terminal
.
enterPrivateMode
()
terminal
.
clearScreen
()
terminal
.
setCursorVisible
(
false
)
}
catch
(
e
:
Exception
)
{
try
{
terminal
=
SwingTerminalFrame
(
"Mirai Console"
)
terminal
.
enterPrivateMode
()
terminal
.
clearScreen
()
terminal
.
setCursorVisible
(
false
)
}
if
(
terminal
==
null
)
{
}
catch
(
e
:
Exception
)
{
error
(
"can not create terminal"
)
}
}
textGraphics
=
terminal
.
newTextGraphics
()
val
textGraphics
:
TextGraphics
=
terminal
.
newTextGraphics
()
terminal
.
addResizeListener
(
TerminalResizeListener
{
terminal1
:
Terminal
,
newSize
:
TerminalSize
->
terminal
.
clearScreen
()
inited
=
false
update
()
redrawCommand
()
})
update
()
val
charList
=
listOf
(
','
,
'.'
,
'/'
,
'@'
,
'#'
,
'$'
,
'%'
,
'^'
,
'&'
,
'*'
,
'('
,
')'
,
'_'
,
'='
,
'+'
,
'!'
,
' '
)
thread
{
while
(
true
)
{
var
keyStroke
:
KeyStroke
=
terminal
.
readInput
()
when
(
keyStroke
.
keyType
)
{
KeyType
.
ArrowLeft
->
{
currentScreenId
=
getLeftScreenId
()
update
()
}
KeyType
.
ArrowRight
->
{
currentScreenId
=
getRightScreenId
()
update
()
}
KeyType
.
Enter
->
{
emptyCommand
()
}
else
->
{
if
(
keyStroke
.
character
!=
null
)
{
if
(
keyStroke
.
character
.
toInt
()
==
8
)
{
deleteCommandChar
()
}
if
(
keyStroke
.
character
.
isLetterOrDigit
()
||
charList
.
contains
(
keyStroke
.
character
))
{
addCommandChar
(
keyStroke
.
character
)
}
}
}
}
}
}
}
try
{
fun
getLeftScreenId
():
Int
{
var
newId
=
currentScreenId
-
1
if
(
newId
<
0
)
{
...
...
@@ -99,7 +140,7 @@ object MiraiConsoleUI {
val
height
=
terminal
.
terminalSize
.
rows
terminal
.
setBackgroundColor
(
TextColor
.
ANSI
.
DEFAULT
)
if
(!
inited
)
{
val
mainTitle
=
"Mirai Console v0.01 Core v0.14
"
val
mainTitle
=
"Mirai Console v0.01 Core v0.15
"
textGraphics
.
foregroundColor
=
TextColor
.
ANSI
.
WHITE
textGraphics
.
backgroundColor
=
TextColor
.
ANSI
.
GREEN
textGraphics
.
putString
((
width
-
mainTitle
.
length
)
/
2
,
1
,
mainTitle
,
SGR
.
BOLD
)
...
...
@@ -188,9 +229,15 @@ object MiraiConsoleUI {
}
}
if
(
terminal
is
SwingTerminalFrame
)
{
textGraphics
.
putString
(
3
,
9
,
"AAAAAAAAAAAAAAAAAAAAAAa"
,
SGR
.
ITALIC
)
terminal
.
flush
()
}
fun
pushLog
(
uin
:
Long
,
str
:
String
)
{
log
[
uin
]
!!
.
push
(
str
)
if
(
uin
==
screens
[
currentScreenId
])
{
drawLogs
(
log
[
screens
[
currentScreenId
]]
!!
)
}
}
...
...
@@ -257,58 +304,12 @@ object MiraiConsoleUI {
}
}
terminal
.
flush
()
}
terminal
.
addResizeListener
(
TerminalResizeListener
{
terminal1
:
Terminal
,
newSize
:
TerminalSize
->
terminal
.
clearScreen
()
inited
=
false
update
()
redrawCommand
()
})
update
()
val
charList
=
listOf
(
','
,
'.'
,
'/'
,
'@'
,
'#'
,
'$'
,
'%'
,
'^'
,
'&'
,
'*'
,
'('
,
')'
,
'_'
,
'='
,
'+'
,
'!'
,
' '
)
thread
{
while
(
true
)
{
var
keyStroke
:
KeyStroke
=
terminal
.
readInput
()
when
(
keyStroke
.
keyType
)
{
KeyType
.
ArrowLeft
->
{
currentScreenId
=
getLeftScreenId
()
update
()
}
KeyType
.
ArrowRight
->
{
currentScreenId
=
getRightScreenId
()
update
()
}
KeyType
.
Enter
->
{
emptyCommand
()
}
else
->
{
if
(
keyStroke
.
character
!=
null
)
{
if
(
keyStroke
.
character
.
toInt
()
==
8
)
{
deleteCommandChar
()
}
if
(
keyStroke
.
character
.
isLetterOrDigit
()
||
charList
.
contains
(
keyStroke
.
character
))
{
addCommandChar
(
keyStroke
.
character
)
}
}
}
}
}
}
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
}
}
class
LimitLinkedQueue
<
T
>(
val
limit
:
Int
=
50
)
:
LinkedList
<
T
>()
{
)
:
LinkedList
<
T
>()
,
List
<
T
>
{
override
fun
push
(
e
:
T
)
{
if
(
size
>=
limit
)
{
pollLast
()
...
...
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