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
8735cd2e
Commit
8735cd2e
authored
Feb 15, 2020
by
Him188
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
508d988c
0e4c9916
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
120 additions
and
57 deletions
+120
-57
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/MiraiHttpAPIServer.kt
...ain/kotlin/net/mamoe/mirai/api/http/MiraiHttpAPIServer.kt
+3
-2
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt
...i-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt
+15
-13
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsoleUI.kt
...console/src/main/kotlin/net/mamoe/mirai/MiraiConsoleUI.kt
+97
-41
mirai-console/src/main/kotlin/net/mamoe/mirai/plugins/PluginBase.kt
...ole/src/main/kotlin/net/mamoe/mirai/plugins/PluginBase.kt
+5
-1
No files found.
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/MiraiHttpAPIServer.kt
View file @
8735cd2e
...
...
@@ -25,8 +25,9 @@ import kotlin.coroutines.CoroutineContext
object
MiraiHttpAPIServer
:
CoroutineScope
{
private
val
logger
=
DefaultLogger
(
"Mirai HTTP API"
)
override
val
coroutineContext
:
CoroutineContext
=
CoroutineExceptionHandler
{
_
,
throwable
->
logger
.
error
(
throwable
)
}
var
logger
=
DefaultLogger
(
"Mirai HTTP API"
)
override
val
coroutineContext
:
CoroutineContext
=
CoroutineExceptionHandler
{
_
,
throwable
->
logger
.
error
(
throwable
)
}
init
{
SessionManager
.
authKey
=
generateSessionKey
()
//用于验证的key, 使用和SessionKey相同的方法生成, 但意义不同
...
...
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt
View file @
8735cd2e
...
...
@@ -18,6 +18,7 @@ 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
java.io.File
import
java.io.PrintStream
import
kotlin.concurrent.thread
...
...
@@ -38,26 +39,21 @@ object MiraiConsole {
val
pluginManager
:
PluginManager
get
()
=
PluginManager
var
logger
=
UIPushLogger
(
0
)
var
logger
=
UIPushLogger
var
path
:
String
=
System
.
getProperty
(
"user.dir"
)
val
version
=
"0.01"
var
coreVersion
=
"0.1
3
"
var
coreVersion
=
"0.1
5
"
val
build
=
"Beta"
fun
start
()
{
logger
(
"Mirai-console v$version $build | core version v$coreVersion is still in testing stage, majority feature is available"
)
logger
(
"Mirai-console v$version $build | 核心版本 v${coreVersion}还处于测试阶段, 大部分功能可用"
)
logger
()
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
(
"Mirai-console 正在 "
+
System
.
getProperty
(
"user.dir"
)
+
"下运行"
)
logger
()
logger
(
"Get news in github: https://github.com/mamoe/mirai"
)
logger
(
"在Github中获取项目最新进展: https://github.com/mamoe/mirai"
)
logger
(
"Mirai为开源项目,请自觉遵守开源项目协议"
)
logger
(
"Powered by Mamoe Technologies and contributors"
)
logger
()
runBlocking
{
DefaultCommands
()
...
...
@@ -83,11 +79,14 @@ object MiraiConsole {
logger
(
"请尽快更改初始生成的HTTP API AUTHKEY"
)
}
logger
(
"正在启动HTTPAPI; 端口="
+
MiraiProperties
.
HTTP_API_PORT
)
MiraiHttpAPIServer
.
logger
=
SimpleLogger
(
"HTTP API"
)
{
_
,
message
,
e
->
logger
(
"[Mirai HTTP API]"
,
0
,
message
)
}
MiraiHttpAPIServer
.
start
(
MiraiProperties
.
HTTP_API_PORT
,
MiraiProperties
.
HTTP_API_AUTH_KEY
)
logger
(
"HTTPAPI启动完成; 端口="
+
MiraiProperties
.
HTTP_API_PORT
)
logger
(
"HTTPAPI启动完成; 端口=
"
+
MiraiProperties
.
HTTP_API_PORT
)
}
}
...
...
@@ -255,11 +254,14 @@ object MiraiConsole {
}
}
class
UIPushLogger
(
val
identity
:
Long
)
{
object
UIPushLogger
{
operator
fun
invoke
(
any
:
Any
?
=
null
)
{
MiraiConsoleUI
.
start
()
invoke
(
"[Mirai$version $build]"
,
0L
,
any
)
}
operator
fun
invoke
(
identityStr
:
String
,
identity
:
Long
,
any
:
Any
?
=
null
)
{
if
(
any
!=
null
)
{
MiraiConsoleUI
.
pushLog
(
identity
,
"
[Mirai$version $build]
: $any"
)
MiraiConsoleUI
.
pushLog
(
identity
,
"
$identityStr
: $any"
)
}
}
}
...
...
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsoleUI.kt
View file @
8735cd2e
...
...
@@ -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
kotlinx.coroutines.*
import
net.mamoe.mirai.MiraiConsoleUI.LoggerDrawer.cleanPage
import
net.mamoe.mirai.MiraiConsoleUI.LoggerDrawer.drawLog
import
net.mamoe.mirai.MiraiConsoleUI.LoggerDrawer.redrawLogs
import
net.mamoe.mirai.utils.currentTimeSeconds
...
...
@@ -21,18 +23,35 @@ import java.util.*
import
kotlin.concurrent.thread
import
kotlin.math.ceil
/**
* 此文件不推荐任何人看
* 可能导致
* 1:心肌梗死
* 2:呼吸困难
* 3:想要重写但是发现改任何一个看似不合理的地方都会崩
*
* @author NaturalHG
*
*/
@SuppressWarnings
(
"UNCHECKED"
)
object
MiraiConsoleUI
{
val
cacheLogSize
=
50
val
log
=
mutableMapOf
<
Long
,
LimitLinkedQueue
<
String
>>().
also
{
it
[
0L
]
=
LimitLinkedQueue
(
50
)
}
val
log
=
mutableMapOf
<
Long
,
LimitLinkedQueue
<
String
>>().
also
{
it
[
0L
]
=
LimitLinkedQueue
(
cacheLogSize
)
}
val
botAdminCount
=
mutableMapOf
<
Long
,
Long
>()
private
val
screens
=
mutableListOf
(
0L
)
private
val
screens
=
mutableListOf
(
0L
,
2821869985L
)
private
var
currentScreenId
=
0
fun
addBotScreen
(
uin
:
Long
)
{
screens
.
add
(
uin
)
log
[
uin
]
=
LimitLinkedQueue
()
log
[
uin
]
=
LimitLinkedQueue
(
cacheLogSize
)
botAdminCount
[
uin
]
=
0
}
...
...
@@ -68,12 +87,46 @@ object MiraiConsoleUI {
}
textGraphics
=
terminal
.
newTextGraphics
()
/*
var lastRedrawTime = 0L
var lastNewWidth = 0
var lastNewHeight = 0
terminal.addResizeListener(TerminalResizeListener { terminal1: Terminal, newSize: TerminalSize ->
terminal
.
clearScreen
()
inited
=
false
update
()
redrawCommand
()
redrawLogs
(
log
[
screens
[
currentScreenId
]]
!!
)
try {
if (lastNewHeight == newSize.rows
&&
lastNewWidth == newSize.columns
) {
return@TerminalResizeListener
}
lastNewHeight = newSize.rows
lastNewWidth = newSize.columns
terminal.clearScreen()
if(terminal !is SwingTerminalFrame) {
Thread.sleep(300)
}
update()
redrawCommand()
redrawLogs(log[screens[currentScreenId]]!!)
}catch (ignored:Exception){
}
})
*/
var
lastJob
:
Job
?
=
null
terminal
.
addResizeListener
(
TerminalResizeListener
{
terminal1
:
Terminal
,
newSize
:
TerminalSize
->
lastJob
=
GlobalScope
.
launch
{
delay
(
300
)
if
(
lastJob
==
coroutineContext
[
Job
])
{
terminal
.
clearScreen
()
//inited = false
update
()
redrawCommand
()
redrawLogs
(
log
[
screens
[
currentScreenId
]]
!!
)
}
}
})
if
(
terminal
!
is
SwingTerminalFrame
)
{
...
...
@@ -104,10 +157,14 @@ object MiraiConsoleUI {
when
(
keyStroke
.
keyType
)
{
KeyType
.
ArrowLeft
->
{
currentScreenId
=
getLeftScreenId
()
clearRows
(
2
)
cleanPage
()
update
()
}
KeyType
.
ArrowRight
->
{
currentScreenId
=
getRightScreenId
()
clearRows
(
2
)
cleanPage
()
update
()
}
KeyType
.
Enter
->
{
...
...
@@ -128,7 +185,7 @@ object MiraiConsoleUI {
}
}
fun
getLeftScreenId
():
Int
{
private
fun
getLeftScreenId
():
Int
{
var
newId
=
currentScreenId
-
1
if
(
newId
<
0
)
{
newId
=
screens
.
size
-
1
...
...
@@ -136,7 +193,7 @@ object MiraiConsoleUI {
return
newId
}
fun
getRightScreenId
():
Int
{
private
fun
getRightScreenId
():
Int
{
var
newId
=
1
+
currentScreenId
if
(
newId
>=
screens
.
size
)
{
newId
=
0
...
...
@@ -144,7 +201,7 @@ object MiraiConsoleUI {
return
newId
}
fun
getScreenName
(
id
:
Int
):
String
{
private
fun
getScreenName
(
id
:
Int
):
String
{
return
when
(
screens
[
id
])
{
0L
->
{
"Console Screen"
...
...
@@ -156,7 +213,6 @@ object MiraiConsoleUI {
}
var
inited
=
false
fun
clearRows
(
row
:
Int
)
{
textGraphics
.
putString
(
0
,
row
,
" "
.
repeat
(
terminal
.
terminalSize
.
columns
))
}
...
...
@@ -167,25 +223,24 @@ object MiraiConsoleUI {
val
width
=
terminal
.
terminalSize
.
columns
val
height
=
terminal
.
terminalSize
.
rows
terminal
.
setBackgroundColor
(
TextColor
.
ANSI
.
DEFAULT
)
if
(!
inited
)
{
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
)
textGraphics
.
foregroundColor
=
TextColor
.
ANSI
.
DEFAULT
textGraphics
.
backgroundColor
=
TextColor
.
ANSI
.
DEFAULT
textGraphics
.
putString
(
2
,
3
,
"-"
.
repeat
(
width
-
4
))
textGraphics
.
putString
(
2
,
5
,
"-"
.
repeat
(
width
-
4
))
textGraphics
.
putString
(
2
,
height
-
4
,
"-"
.
repeat
(
width
-
4
))
textGraphics
.
putString
(
2
,
height
-
3
,
"|>>>"
)
textGraphics
.
putString
(
width
-
3
,
height
-
3
,
"|"
)
textGraphics
.
putString
(
2
,
height
-
2
,
"-"
.
repeat
(
width
-
4
))
inited
=
true
}
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
)
textGraphics
.
foregroundColor
=
TextColor
.
ANSI
.
DEFAULT
textGraphics
.
backgroundColor
=
TextColor
.
ANSI
.
DEFAULT
textGraphics
.
putString
(
2
,
3
,
"-"
.
repeat
(
width
-
4
))
textGraphics
.
putString
(
2
,
5
,
"-"
.
repeat
(
width
-
4
))
textGraphics
.
putString
(
2
,
height
-
4
,
"-"
.
repeat
(
width
-
4
))
textGraphics
.
putString
(
2
,
height
-
3
,
"|>>>"
)
textGraphics
.
putString
(
width
-
3
,
height
-
3
,
"|"
)
textGraphics
.
putString
(
2
,
height
-
2
,
"-"
.
repeat
(
width
-
4
))
textGraphics
.
foregroundColor
=
TextColor
.
ANSI
.
DEFAULT
textGraphics
.
backgroundColor
=
TextColor
.
ANSI
.
DEFAULT
val
leftName
=
getScreenName
(
getLeftScreenId
())
clearRows
(
2
)
//
clearRows(2)
textGraphics
.
putString
((
width
-
title
.
length
)
/
2
-
"$leftName << "
.
length
,
2
,
"$leftName << "
)
textGraphics
.
foregroundColor
=
TextColor
.
ANSI
.
WHITE
textGraphics
.
backgroundColor
=
TextColor
.
ANSI
.
YELLOW
...
...
@@ -230,14 +285,14 @@ object MiraiConsoleUI {
var
currentHeight
=
6
fun
drawLog
(
string
:
String
,
flush
:
Boolean
=
true
)
{
val
maxHeight
=
terminal
.
terminalSize
.
rows
-
6
val
maxHeight
=
terminal
.
terminalSize
.
rows
-
4
val
heightNeed
=
(
string
.
length
/
(
terminal
.
terminalSize
.
columns
-
6
))
+
1
if
(
currentHeight
+
heightNeed
>
maxHeight
)
{
cleanPage
()
}
textGraphics
.
foregroundColor
=
TextColor
.
ANSI
.
GREEN
textGraphics
.
backgroundColor
=
TextColor
.
ANSI
.
DEFAULT
val
width
=
terminal
.
terminalSize
.
columns
-
6
val
width
=
terminal
.
terminalSize
.
columns
-
7
var
x
=
string
while
(
true
)
{
if
(
x
==
""
)
break
...
...
@@ -264,7 +319,7 @@ object MiraiConsoleUI {
fun
cleanPage
()
{
for
(
index
in
6
until
terminal
.
terminalSize
.
rows
-
6
)
{
for
(
index
in
6
until
terminal
.
terminalSize
.
rows
-
4
)
{
clearRows
(
index
)
}
currentHeight
=
6
...
...
@@ -272,20 +327,21 @@ object MiraiConsoleUI {
fun
redrawLogs
(
toDraw
:
List
<
String
>)
{
this
.
cleanPage
()
//this.cleanPage()
currentHeight
=
6
var
logsToDraw
=
0
var
vara
=
0
toDraw
.
reversed
().
forEach
{
toDraw
.
forEach
{
val
heightNeed
=
(
it
.
length
/
(
terminal
.
terminalSize
.
columns
-
6
))
+
1
vara
+=
heightNeed
if
(
currentHeight
+
vara
<
terminal
.
terminalSize
.
rows
-
6
)
{
if
(
currentHeight
+
vara
<
terminal
.
terminalSize
.
rows
-
4
)
{
logsToDraw
++
}
else
{
return
return
@
forEach
}
}
for
(
index
in
(
toDraw
.
size
-
logsToDraw
)
until
toDraw
.
size
-
1
)
{
drawLog
(
toDraw
[
index
],
false
)
for
(
index
in
0
until
logsToDraw
)
{
drawLog
(
toDraw
[
logsToDraw
-
index
-
1
],
false
)
}
if
(
terminal
is
SwingTerminalFrame
)
{
terminal
.
flush
()
...
...
@@ -316,7 +372,7 @@ object MiraiConsoleUI {
}
}
fun
addCommandChar
(
private
fun
addCommandChar
(
c
:
Char
)
{
if
(
commandBuilder
.
isEmpty
()
&&
c
!=
'/'
)
{
...
...
@@ -332,7 +388,7 @@ object MiraiConsoleUI {
}
}
fun
deleteCommandChar
()
{
private
fun
deleteCommandChar
()
{
if
(!
commandBuilder
.
isEmpty
())
{
commandBuilder
=
StringBuilder
(
commandBuilder
.
toString
().
substring
(
0
,
commandBuilder
.
length
-
1
))
}
...
...
@@ -345,7 +401,7 @@ object MiraiConsoleUI {
}
fun
emptyCommand
()
{
private
fun
emptyCommand
()
{
commandBuilder
=
StringBuilder
()
redrawCommand
()
if
(
terminal
is
SwingTerminal
)
{
...
...
mirai-console/src/main/kotlin/net/mamoe/mirai/plugins/PluginBase.kt
View file @
8735cd2e
...
...
@@ -11,8 +11,10 @@ package net.mamoe.mirai.plugins
import
net.mamoe.mirai.ICommand
import
kotlinx.coroutines.*
import
net.mamoe.mirai.MiraiConsole
import
net.mamoe.mirai.utils.DefaultLogger
import
net.mamoe.mirai.utils.MiraiLogger
import
net.mamoe.mirai.utils.SimpleLogger
import
net.mamoe.mirai.utils.io.encodeToString
import
java.io.File
import
java.net.URL
...
...
@@ -156,7 +158,9 @@ object PluginManager {
File
(
it
).
mkdirs
()
}
val
logger
=
DefaultLogger
(
"Mirai Plugin Manager"
)
val
logger
=
SimpleLogger
(
"Plugin Manager"
)
{
_
,
message
,
e
->
MiraiConsole
.
logger
(
"[Plugin Manager]"
,
0
,
message
)
}
//已完成加载的
private
val
nameToPluginBaseMap
:
MutableMap
<
String
,
PluginBase
>
=
mutableMapOf
()
...
...
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