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
e42d7ff7
Commit
e42d7ff7
authored
Feb 25, 2020
by
jiahua.liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add usage
parent
6cf563c8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
13 deletions
+40
-13
mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/Command.kt
...rc/main/kotlin/net/mamoe/mirai/console/command/Command.kt
+7
-1
mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugins/PluginBase.kt
...main/kotlin/net/mamoe/mirai/console/plugins/PluginBase.kt
+32
-11
mirai-plugins/image-sender/src/main/java/net/mamoe/mirai/imageplugin/ImageSenderMain.kt
.../main/java/net/mamoe/mirai/imageplugin/ImageSenderMain.kt
+1
-1
No files found.
mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/Command.kt
View file @
e42d7ff7
...
...
@@ -156,6 +156,8 @@ interface Command {
val
name
:
String
val
alias
:
List
<
String
>
val
description
:
String
val
usage
:
String
suspend
fun
onCommand
(
sender
:
CommandSender
,
args
:
List
<
String
>):
Boolean
fun
register
()
}
...
...
@@ -163,7 +165,8 @@ interface Command {
abstract
class
BlockingCommand
(
override
val
name
:
String
,
override
val
alias
:
List
<
String
>
=
listOf
(),
override
val
description
:
String
=
""
override
val
description
:
String
=
""
,
override
val
usage
:
String
=
""
)
:
Command
{
/**
* 最高优先级监听器
...
...
@@ -186,6 +189,7 @@ class AnonymousCommand internal constructor(
override
val
name
:
String
,
override
val
alias
:
List
<
String
>,
override
val
description
:
String
,
override
val
usage
:
String
=
""
,
val
onCommand
:
suspend
CommandSender
.(
args
:
List
<
String
>)
->
Boolean
)
:
Command
{
override
suspend
fun
onCommand
(
sender
:
CommandSender
,
args
:
List
<
String
>):
Boolean
{
...
...
@@ -201,6 +205,7 @@ class CommandBuilder internal constructor() {
var
name
:
String
?
=
null
var
alias
:
List
<
String
>?
=
null
var
description
:
String
=
""
var
usage
:
String
=
"use /help for help"
var
onCommand
:
(
suspend
CommandSender
.(
args
:
List
<
String
>)
->
Boolean
)?
=
null
fun
onCommand
(
commandProcess
:
suspend
CommandSender
.(
args
:
List
<
String
>)
->
Boolean
)
{
...
...
@@ -218,6 +223,7 @@ class CommandBuilder internal constructor() {
name
!!
,
alias
!!
,
description
,
usage
,
onCommand
!!
).
also
{
it
.
register
()
}
}
...
...
mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugins/PluginBase.kt
View file @
e42d7ff7
...
...
@@ -31,6 +31,9 @@ abstract class PluginBase(coroutineContext: CoroutineContext) : CoroutineScope {
private
val
supervisorJob
=
SupervisorJob
()
final
override
val
coroutineContext
:
CoroutineContext
=
coroutineContext
+
supervisorJob
/**
* 插件被分配的data folder, 如果插件改名了 data folder 也会变 请注意
*/
val
dataFolder
:
File
by
lazy
{
File
(
PluginManager
.
pluginsPath
+
pluginDescription
.
name
).
also
{
it
.
mkdir
()
}
}
...
...
@@ -68,12 +71,14 @@ abstract class PluginBase(coroutineContext: CoroutineContext) : CoroutineScope {
this
.
onEnable
()
}
/**
* 加载一个data folder中的Config
* 这个config是read-write的
*/
fun
loadConfig
(
fileName
:
String
):
Config
{
return
Config
.
load
(
File
(
fileName
)
)
return
Config
.
load
(
dataFolder
.
absolutePath
+
fileName
)
}
@JvmOverloads
internal
fun
disable
(
throwable
:
CancellationException
?
=
null
)
{
this
.
coroutineContext
[
Job
]
!!
.
cancelChildren
(
throwable
)
...
...
@@ -87,7 +92,7 @@ abstract class PluginBase(coroutineContext: CoroutineContext) : CoroutineScope {
this
.
onLoad
()
}
fun
getPluginManager
()
=
PluginManager
val
pluginManager
=
PluginManager
val
logger
:
MiraiLogger
by
lazy
{
SimpleLogger
(
"Plugin ${pluginDescription.name}"
)
{
_
,
message
,
e
->
...
...
@@ -99,15 +104,31 @@ abstract class PluginBase(coroutineContext: CoroutineContext) : CoroutineScope {
}
}
/**
* 加载一个插件jar, resources中的东西
*/
fun
getResources
(
fileName
:
String
):
InputStream
?
{
return
PluginManager
.
getFileInJarByName
(
this
.
pluginDescription
.
name
,
fileName
)
return
try
{
this
.
javaClass
.
classLoader
.
getResourceAsStream
(
fileName
)
}
catch
(
e
:
Exception
)
{
PluginManager
.
getFileInJarByName
(
this
.
pluginDescription
.
name
,
fileName
)
}
}
/**
* 加载一个插件jar, resources中的Config
* 这个Config是read-only的
*/
fun
getResourcesConfig
(
fileName
:
String
):
Config
{
if
(
fileName
.
contains
(
"."
))
{
error
(
"Unknown Config Type"
)
}
return
Config
.
load
(
getResources
(
fileName
)
?:
error
(
"Config Not Found"
),
fileName
.
split
(
"."
)[
1
])
}
//fun getResourcesConfig()
}
class
PluginDescription
(
...
...
@@ -370,7 +391,7 @@ object PluginManager {
/**
* 根据插件名字找Jar
resources
中的文件
* 根据插件名字找Jar中的文件
* null => 没找到
*/
fun
getFileInJarByName
(
pluginName
:
String
,
toFind
:
String
):
InputStream
?
{
...
...
mirai-plugins/image-sender/src/main/java/net/mamoe/mirai/imageplugin/ImageSenderMain.kt
View file @
e42d7ff7
...
...
@@ -134,7 +134,7 @@ class ImageSenderMain : PluginBase() {
logger
.
info
(
"loading local image data"
)
try
{
images
=
Config
.
load
(
getResources
(
fileName
=
"data.yml"
)
!!
,
"
yml"
)
images
=
getResourcesConfig
(
"data.
yml"
)
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
logger
.
info
(
"无法加载本地图片"
)
...
...
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