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
1735eab9
Commit
1735eab9
authored
Feb 14, 2020
by
jiahua.liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Console Buildup
parent
155ad75c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
86 additions
and
41 deletions
+86
-41
mirai-console/build.gradle.kts
mirai-console/build.gradle.kts
+10
-1
mirai-console/src/main/kotlin/net/mamoe/mirai/Command.kt
mirai-console/src/main/kotlin/net/mamoe/mirai/Command.kt
+5
-3
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt
...i-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt
+56
-24
mirai-console/src/main/kotlin/net/mamoe/mirai/plugins/ConfigSection.kt
.../src/main/kotlin/net/mamoe/mirai/plugins/ConfigSection.kt
+1
-2
mirai-console/src/main/kotlin/net/mamoe/mirai/plugins/PluginBase.kt
...ole/src/main/kotlin/net/mamoe/mirai/plugins/PluginBase.kt
+13
-10
mirai-plugins/image-sender/src/main/java/net/mamoe/mirai/imageplugin/ImageSenderMain.kt
.../main/java/net/mamoe/mirai/imageplugin/ImageSenderMain.kt
+1
-1
plugins/image-sender-1.0.0-all.jar
plugins/image-sender-1.0.0-all.jar
+0
-0
No files found.
mirai-console/build.gradle.kts
View file @
1735eab9
...
@@ -4,7 +4,16 @@ plugins {
...
@@ -4,7 +4,16 @@ plugins {
id
(
"java"
)
id
(
"java"
)
}
}
apply
(
plugin
=
"com.github.johnrengelman.shadow"
)
apply
(
plugin
=
"com.github.johnrengelman.shadow"
)
apply
(
plugin
=
"java-library"
)
tasks
.
withType
<
com
.
github
.
jengelman
.
gradle
.
plugins
.
shadow
.
tasks
.
ShadowJar
>()
{
manifest
{
attributes
[
"Main-Class"
]
=
"net.mamoe.mirai.MiraiConsoleLoader"
}
}
val
kotlinVersion
:
String
by
rootProject
.
ext
val
kotlinVersion
:
String
by
rootProject
.
ext
val
atomicFuVersion
:
String
by
rootProject
.
ext
val
atomicFuVersion
:
String
by
rootProject
.
ext
...
...
mirai-console/src/main/kotlin/Command.kt
→
mirai-console/src/main/kotlin/
net/mamoe/mirai/
Command.kt
View file @
1735eab9
package
net.mamoe.mirai
/*
/*
* Copyright 2020 Mamoe Technologies and contributors.
* Copyright 2020 Mamoe Technologies and contributors.
*
*
...
@@ -7,7 +9,7 @@
...
@@ -7,7 +9,7 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
*/
import
net.mamoe.mirai.plugin.PluginManager
import
net.mamoe.mirai.plugin
s
.PluginManager
object
CommandManager
{
object
CommandManager
{
private
val
registeredCommand
:
MutableMap
<
String
,
ICommand
>
=
mutableMapOf
()
private
val
registeredCommand
:
MutableMap
<
String
,
ICommand
>
=
mutableMapOf
()
...
@@ -21,7 +23,7 @@ object CommandManager {
...
@@ -21,7 +23,7 @@ object CommandManager {
val
allNames
=
mutableListOf
(
command
.
name
).
also
{
it
.
addAll
(
command
.
alias
)
}
val
allNames
=
mutableListOf
(
command
.
name
).
also
{
it
.
addAll
(
command
.
alias
)
}
allNames
.
forEach
{
allNames
.
forEach
{
if
(
registeredCommand
.
containsKey
(
it
))
{
if
(
registeredCommand
.
containsKey
(
it
))
{
error
(
"Command Name(or Alias) $it is already registered, consider if same function plugin was installed"
)
error
(
"
net.mamoe.mirai.
Command Name(or Alias) $it is already registered, consider if same function plugin was installed"
)
}
}
}
}
allNames
.
forEach
{
allNames
.
forEach
{
...
@@ -113,7 +115,7 @@ class CommandBuilder internal constructor() {
...
@@ -113,7 +115,7 @@ class CommandBuilder internal constructor() {
fun
register
():
ICommand
{
fun
register
():
ICommand
{
if
(
name
==
null
||
onCommand
==
null
)
{
if
(
name
==
null
||
onCommand
==
null
)
{
error
(
"CommandBuilder not complete"
)
error
(
"
net.mamoe.mirai.
CommandBuilder not complete"
)
}
}
if
(
alias
==
null
)
{
if
(
alias
==
null
)
{
alias
=
listOf
()
alias
=
listOf
()
...
...
mirai-console/src/main/kotlin/MiraiConsole.kt
→
mirai-console/src/main/kotlin/
net/mamoe/mirai/
MiraiConsole.kt
View file @
1735eab9
package
net.mamoe.mirai
/*
/*
* Copyright 2020 Mamoe Technologies and contributors.
* Copyright 2020 Mamoe Technologies and contributors.
*
*
...
@@ -8,15 +10,15 @@
...
@@ -8,15 +10,15 @@
*/
*/
import
kotlinx.coroutines.runBlocking
import
kotlinx.coroutines.runBlocking
import
kotlinx.serialization.UnstableDefault
import
net.mamoe.mirai.plugins.PluginManager
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.plugins.loadAsConfig
import
net.mamoe.mirai.alsoLogin
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.api.http.generateSessionKey
import
net.mamoe.mirai.contact.sendMessage
import
net.mamoe.mirai.contact.sendMessage
import
net.mamoe.mirai.plugin.*
import
java.io.File
import
java.io.File
import
kotlin.concurrent.thread
import
kotlin.concurrent.thread
import
kotlin.math.log
object
MiraiConsole
{
object
MiraiConsole
{
val
bots
val
bots
...
@@ -34,16 +36,18 @@ object MiraiConsole {
...
@@ -34,16 +36,18 @@ object MiraiConsole {
val
pluginManager
:
PluginManager
val
pluginManager
:
PluginManager
get
()
=
PluginManager
get
()
=
PluginManager
var
logger
:
MiraiConsoleLogger
=
DefaultLogger
var
logger
:
MiraiConsoleLogger
=
DefaultLogger
var
path
:
String
=
System
.
getProperty
(
"user.dir"
)
var
path
:
String
=
System
.
getProperty
(
"user.dir"
)
val
version
=
"0.13"
val
version
=
"0.01"
var
coreVersion
=
"0.13"
val
build
=
"Beta"
val
build
=
"Beta"
fun
start
()
{
fun
start
()
{
logger
(
"Mirai-console v$
{version} $build
is still in testing stage, majority feature is available"
)
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
还处于测试阶段, 大部分功能可用"
)
logger
(
"Mirai-console v$
version $build | 核心版本 v${coreVersion}
还处于测试阶段, 大部分功能可用"
)
logger
()
logger
()
logger
(
"Mirai-console now running under "
+
System
.
getProperty
(
"user.dir"
))
logger
(
"Mirai-console now running under "
+
System
.
getProperty
(
"user.dir"
))
logger
(
"Mirai-console 正在 "
+
System
.
getProperty
(
"user.dir"
)
+
"下运行"
)
logger
(
"Mirai-console 正在 "
+
System
.
getProperty
(
"user.dir"
)
+
"下运行"
)
...
@@ -51,12 +55,17 @@ object MiraiConsole {
...
@@ -51,12 +55,17 @@ object MiraiConsole {
logger
(
"Get news in github: https://github.com/mamoe/mirai"
)
logger
(
"Get news in github: https://github.com/mamoe/mirai"
)
logger
(
"在Github中获取项目最新进展: https://github.com/mamoe/mirai"
)
logger
(
"在Github中获取项目最新进展: https://github.com/mamoe/mirai"
)
logger
(
"Mirai为开源项目,请自觉遵守开源项目协议"
)
logger
(
"Mirai为开源项目,请自觉遵守开源项目协议"
)
logger
(
"Powered by Mamoe Technolog
y
"
)
logger
(
"Powered by Mamoe Technolog
ies and contributors
"
)
logger
()
logger
()
DefaultCommands
()
runBlocking
{
pluginManager
.
loadPlugins
()
DefaultCommands
()
CommandListener
.
start
()
HTTPAPIAdaptar
()
pluginManager
.
loadPlugins
()
CommandListener
.
start
()
}
logger
(
"Mirai-console 启动完成"
)
logger
(
"\"/login qqnumber qqpassword \" to login a bot"
)
logger
(
"\"/login qqnumber qqpassword \" to login a bot"
)
logger
(
"\"/login qq号 qq密码 \" 来登陆一个BOT"
)
logger
(
"\"/login qq号 qq密码 \" 来登陆一个BOT"
)
...
@@ -66,6 +75,23 @@ object MiraiConsole {
...
@@ -66,6 +75,23 @@ object MiraiConsole {
PluginManager
.
disableAllPlugins
()
PluginManager
.
disableAllPlugins
()
}
}
object
HTTPAPIAdaptar
{
operator
fun
invoke
()
{
if
(
MiraiProperties
.
HTTP_API_ENABLE
)
{
if
(
MiraiProperties
.
HTTP_API_AUTH_KEY
.
startsWith
(
"InitKey"
))
{
logger
(
"请尽快更改初始生成的HTTP API AUTHKEY"
)
}
logger
(
"正在启动HTTPAPI; 端口="
+
MiraiProperties
.
HTTP_API_PORT
)
MiraiHttpAPIServer
.
start
(
MiraiProperties
.
HTTP_API_PORT
,
MiraiProperties
.
HTTP_API_AUTH_KEY
)
logger
(
"HTTPAPI启动完成; 端口="
+
MiraiProperties
.
HTTP_API_PORT
)
}
}
}
/**
/**
* Defaults Commands are recommend to be replaced by plugin provided commands
* Defaults Commands are recommend to be replaced by plugin provided commands
*/
*/
...
@@ -195,11 +221,11 @@ object MiraiConsole {
...
@@ -195,11 +221,11 @@ object MiraiConsole {
name
=
"about"
name
=
"about"
description
=
"About Mirai-Console"
description
=
"About Mirai-Console"
onCommand
{
onCommand
{
logger
(
"v$
{version}
$build is still in testing stage, majority feature is available"
)
logger
(
"v$
version
$build is still in testing stage, majority feature is available"
)
logger
(
"now running under "
+
System
.
getProperty
(
"user.dir"
))
logger
(
"now running under "
+
System
.
getProperty
(
"user.dir"
))
logger
(
"在Github中获取项目最新进展: https://github.com/mamoe/mirai"
)
logger
(
"在Github中获取项目最新进展: https://github.com/mamoe/mirai"
)
logger
(
"Mirai为开源项目,请自觉遵守开源项目协议"
)
logger
(
"Mirai为开源项目,请自觉遵守开源项目协议"
)
logger
(
"Powered by Mamoe Technolog
y
"
)
logger
(
"Powered by Mamoe Technolog
ies and contributors
"
)
true
true
}
}
}
}
...
@@ -235,7 +261,7 @@ object MiraiConsole {
...
@@ -235,7 +261,7 @@ object MiraiConsole {
object
DefaultLogger
:
MiraiConsoleLogger
{
object
DefaultLogger
:
MiraiConsoleLogger
{
override
fun
invoke
(
any
:
Any
?)
{
override
fun
invoke
(
any
:
Any
?)
{
if
(
any
!=
null
)
{
if
(
any
!=
null
)
{
println
(
"[Mirai$
{version}
$build]: "
+
any
.
toString
())
println
(
"[Mirai$
version
$build]: "
+
any
.
toString
())
}
}
}
}
}
}
...
@@ -246,18 +272,24 @@ object MiraiConsole {
...
@@ -246,18 +272,24 @@ object MiraiConsole {
var
HTTP_API_ENABLE
:
Boolean
by
config
.
withDefaultWrite
{
true
}
var
HTTP_API_ENABLE
:
Boolean
by
config
.
withDefaultWrite
{
true
}
var
HTTP_API_PORT
:
Int
by
config
.
withDefaultWrite
{
8080
}
var
HTTP_API_PORT
:
Int
by
config
.
withDefaultWrite
{
8080
}
var
HTTP_API_AUTH_KEY
:
String
by
config
.
withDefaultWriteSave
{
var
HTTP_API_AUTH_KEY
:
String
by
config
.
withDefaultWriteSave
{
"InitKey"
.
also
{
"InitKey"
+
generateSessionKey
()
logger
(
"Mirai HTTPAPI auth key 已随机生成 请注意修改"
)
}
+
generateSessionKey
()
}
}
}
}
}
}
fun
main
()
{
class
MiraiConsoleLoader
{
MiraiConsole
.
start
()
companion
object
{
Runtime
.
getRuntime
().
addShutdownHook
(
thread
(
start
=
false
)
{
@JvmStatic
MiraiConsole
.
stop
()
fun
main
(
args
:
Array
<
String
>)
{
})
MiraiConsole
.
start
()
Runtime
.
getRuntime
().
addShutdownHook
(
thread
(
start
=
false
)
{
MiraiConsole
.
stop
()
})
}
}
}
}
mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/ConfigSection.kt
→
mirai-console/src/main/kotlin/net/mamoe/mirai/plugin
s
/ConfigSection.kt
View file @
1735eab9
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
*/
package
net.mamoe.mirai.plugin
package
net.mamoe.mirai.plugin
s
import
com.alibaba.fastjson.JSON
import
com.alibaba.fastjson.JSON
import
com.alibaba.fastjson.JSONObject
import
com.alibaba.fastjson.JSONObject
...
@@ -16,7 +16,6 @@ import com.alibaba.fastjson.parser.Feature
...
@@ -16,7 +16,6 @@ import com.alibaba.fastjson.parser.Feature
import
kotlinx.serialization.*
import
kotlinx.serialization.*
import
java.io.File
import
java.io.File
import
java.util.concurrent.ConcurrentHashMap
import
java.util.concurrent.ConcurrentHashMap
import
java.util.concurrent.ConcurrentSkipListMap
import
kotlin.properties.ReadWriteProperty
import
kotlin.properties.ReadWriteProperty
import
kotlin.reflect.KClass
import
kotlin.reflect.KClass
import
kotlin.reflect.KProperty
import
kotlin.reflect.KProperty
...
...
mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/PluginBase.kt
→
mirai-console/src/main/kotlin/net/mamoe/mirai/plugin
s
/PluginBase.kt
View file @
1735eab9
...
@@ -7,13 +7,10 @@
...
@@ -7,13 +7,10 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
*/
package
net.mamoe.mirai.plugin
package
net.mamoe.mirai.plugin
s
import
Command
import
net.mamoe.mirai.ICommand
import
ICommand
import
kotlinx.coroutines.*
import
kotlinx.coroutines.*
import
kotlinx.serialization.UnstableDefault
import
kotlinx.serialization.json.Json
import
net.mamoe.mirai.utils.DefaultLogger
import
net.mamoe.mirai.utils.DefaultLogger
import
net.mamoe.mirai.utils.MiraiLogger
import
net.mamoe.mirai.utils.MiraiLogger
import
net.mamoe.mirai.utils.io.encodeToString
import
net.mamoe.mirai.utils.io.encodeToString
...
@@ -166,7 +163,7 @@ object PluginManager {
...
@@ -166,7 +163,7 @@ object PluginManager {
private
val
pluginDescriptions
:
MutableMap
<
String
,
PluginDescription
>
=
mutableMapOf
()
private
val
pluginDescriptions
:
MutableMap
<
String
,
PluginDescription
>
=
mutableMapOf
()
fun
onCommand
(
command
:
ICommand
,
args
:
List
<
String
>)
{
fun
onCommand
(
command
:
ICommand
,
args
:
List
<
String
>)
{
this
.
nameToPluginBaseMap
.
values
.
forEach
{
nameToPluginBaseMap
.
values
.
forEach
{
it
.
onCommand
(
command
,
args
)
it
.
onCommand
(
command
,
args
)
}
}
}
}
...
@@ -182,7 +179,7 @@ object PluginManager {
...
@@ -182,7 +179,7 @@ object PluginManager {
val
pluginsFound
:
MutableMap
<
String
,
PluginDescription
>
=
mutableMapOf
()
val
pluginsFound
:
MutableMap
<
String
,
PluginDescription
>
=
mutableMapOf
()
val
pluginsLocation
:
MutableMap
<
String
,
File
>
=
mutableMapOf
()
val
pluginsLocation
:
MutableMap
<
String
,
File
>
=
mutableMapOf
()
logger
.
info
(
"""开始加载${
this.
pluginsPath}下的插件"""
)
logger
.
info
(
"""开始加载${pluginsPath}下的插件"""
)
File
(
pluginsPath
).
listFiles
()
?.
forEach
{
file
->
File
(
pluginsPath
).
listFiles
()
?.
forEach
{
file
->
if
(
file
!=
null
&&
file
.
extension
==
"jar"
)
{
if
(
file
!=
null
&&
file
.
extension
==
"jar"
)
{
...
@@ -262,11 +259,17 @@ object PluginManager {
...
@@ -262,11 +259,17 @@ object PluginManager {
try
{
try
{
val
pluginClass
=
try
{
val
pluginClass
=
try
{
PluginClassLoader
((
pluginsLocation
[
description
.
name
]
!!
),
this
.
javaClass
.
classLoader
)
PluginClassLoader
(
(
pluginsLocation
[
description
.
name
]
!!
),
this
.
javaClass
.
classLoader
)
.
loadClass
(
description
.
basePath
)
.
loadClass
(
description
.
basePath
)
}
catch
(
e
:
ClassNotFoundException
)
{
}
catch
(
e
:
ClassNotFoundException
)
{
logger
.
info
(
"failed to find Main: "
+
description
.
basePath
+
" checking if it's kotlin's path"
)
logger
.
info
(
"failed to find Main: "
+
description
.
basePath
+
" checking if it's kotlin's path"
)
PluginClassLoader
((
pluginsLocation
[
description
.
name
]
!!
),
this
.
javaClass
.
classLoader
)
PluginClassLoader
(
(
pluginsLocation
[
description
.
name
]
!!
),
this
.
javaClass
.
classLoader
)
.
loadClass
(
"${description.basePath}Kt"
)
.
loadClass
(
"${description.basePath}Kt"
)
}
}
return
try
{
return
try
{
...
@@ -299,7 +302,7 @@ object PluginManager {
...
@@ -299,7 +302,7 @@ object PluginManager {
it
.
enable
()
it
.
enable
()
}
}
logger
.
info
(
"""加载了${
this.
nameToPluginBaseMap.size}个插件"""
)
logger
.
info
(
"""加载了${nameToPluginBaseMap.size}个插件"""
)
}
}
...
...
mirai-plugins/image-sender/src/main/java/net/mamoe/mirai/imageplugin/ImageSenderMain.kt
View file @
1735eab9
...
@@ -14,7 +14,7 @@ import kotlinx.coroutines.GlobalScope
...
@@ -14,7 +14,7 @@ import kotlinx.coroutines.GlobalScope
import
net.mamoe.mirai.event.events.BotOnlineEvent
import
net.mamoe.mirai.event.events.BotOnlineEvent
import
net.mamoe.mirai.event.subscribeAlways
import
net.mamoe.mirai.event.subscribeAlways
import
net.mamoe.mirai.event.subscribeMessages
import
net.mamoe.mirai.event.subscribeMessages
import
net.mamoe.mirai.plugin.PluginBase
import
net.mamoe.mirai.plugin
s
.PluginBase
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
class
ImageSenderMain
:
PluginBase
()
{
class
ImageSenderMain
:
PluginBase
()
{
...
...
plugins/image-sender-1.0.0-all.jar
deleted
100644 → 0
View file @
155ad75c
File deleted
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