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
5aba7196
Commit
5aba7196
authored
Jan 18, 2020
by
jiahua.liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plugin supporting
parent
bda3e6dc
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
68 deletions
+26
-68
mirai-console/build.gradle
mirai-console/build.gradle
+2
-1
mirai-console/src/main/kotlin/MiraiConsole.kt
mirai-console/src/main/kotlin/MiraiConsole.kt
+19
-26
mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/PluginBase.kt
...sole/src/main/kotlin/net/mamoe/mirai/plugin/PluginBase.kt
+5
-14
mirai-plugins/image-sender/image-sender.iml
mirai-plugins/image-sender/image-sender.iml
+0
-15
mirai-plugins/mirai-plugins.iml
mirai-plugins/mirai-plugins.iml
+0
-12
No files found.
mirai-console/build.gradle
View file @
5aba7196
...
@@ -3,7 +3,8 @@ apply plugin: "java"
...
@@ -3,7 +3,8 @@ apply plugin: "java"
dependencies
{
dependencies
{
api
project
(
':mirai-core'
)
api
project
(
':mirai-core'
)
runtimeOnly
files
(
':mirai-core-timpc'
)
api
project
(
':mirai-core-timpc'
)
runtimeOnly
files
(
'../mirai-core-timpc/build/classes/kotlin/jvm/main'
)
runtimeOnly
files
(
'../mirai-core/build/classes/kotlin/jvm/main'
)
runtimeOnly
files
(
'../mirai-core/build/classes/kotlin/jvm/main'
)
// classpath is not set correctly by IDE
// classpath is not set correctly by IDE
}
}
mirai-console/src/main/kotlin/MiraiConsole.kt
View file @
5aba7196
...
@@ -18,34 +18,27 @@ fun main() {
...
@@ -18,34 +18,27 @@ fun main() {
println
(
"\"login qqnumber qqpassword \" to login a bot"
)
println
(
"\"login qqnumber qqpassword \" to login a bot"
)
println
(
"\"login qq号 qq密码 \" 来登陆一个BOT"
)
println
(
"\"login qq号 qq密码 \" 来登陆一个BOT"
)
thread
{
processNextCommandLine
()
}
thread
{
PluginManager
.
loadPlugins
()
loop
@
while
(
true
)
{
}
var
command
=
readLine
()
if
(
command
!=
null
)
{
tailrec
fun
processNextCommandLine
()
{
var
commandArgs
=
command
.
split
(
" "
)
val
commandArgs
=
readLine
()
?.
split
(
" "
)
?:
return
when
(
commandArgs
[
0
])
{
when
(
commandArgs
[
0
])
{
"login"
->
{
"login"
->
{
if
(
commandArgs
.
size
<
3
)
{
if
(
commandArgs
.
size
<
3
)
{
println
(
"\"login qqnumber qqpassword \" to login a bot"
)
println
(
"\"login qqnumber qqpassword \" to login a bot"
)
println
(
"\"login qq号 qq密码 \" 来登陆一个BOT"
)
println
(
"\"login qq号 qq密码 \" 来登录一个BOT"
)
continue
@
loop
return
processNextCommandLine
()
}
}
val
qqNumber
=
commandArgs
[
1
].
toLong
()
val
qqNumber
=
commandArgs
[
1
].
toLong
()
val
qqPassword
=
commandArgs
[
2
]
val
qqPassword
=
commandArgs
[
2
]
println
(
"login..."
)
println
(
"login..."
)
GlobalScope
.
launch
{
GlobalScope
.
launch
{
Bot
(
qqNumber
,
qqPassword
)
Bot
(
qqNumber
,
qqPassword
)
}
}
}
}
}
}
}
}
}
return
processNextCommandLine
()
PluginManager
.
loadPlugins
()
}
}
mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/PluginBase.kt
View file @
5aba7196
...
@@ -7,7 +7,6 @@ import java.io.InputStream
...
@@ -7,7 +7,6 @@ import java.io.InputStream
import
java.io.InputStreamReader
import
java.io.InputStreamReader
import
java.net.JarURLConnection
import
java.net.JarURLConnection
import
java.net.URL
import
java.net.URL
import
java.net.URLClassLoader
import
java.util.jar.JarFile
import
java.util.jar.JarFile
...
@@ -103,13 +102,6 @@ class PluginDescription(
...
@@ -103,13 +102,6 @@ class PluginDescription(
}
}
class
PluginClassLoader
(
file
:
File
,
parent
:
ClassLoader
)
:
URLClassLoader
(
arrayOf
(
file
.
toURI
().
toURL
()),
parent
)
{
override
fun
findClass
(
moduleName
:
String
?,
name
:
String
?):
Class
<
*
>
{
return
super
.
findClass
(
name
)
}
}
object
PluginManager
{
object
PluginManager
{
internal
val
pluginsPath
=
System
.
getProperty
(
"user.dir"
)
+
"/plugins/"
.
replace
(
"//"
,
"/"
).
also
{
internal
val
pluginsPath
=
System
.
getProperty
(
"user.dir"
)
+
"/plugins/"
.
replace
(
"//"
,
"/"
).
also
{
File
(
it
).
mkdirs
()
File
(
it
).
mkdirs
()
...
@@ -127,7 +119,7 @@ object PluginManager {
...
@@ -127,7 +119,7 @@ object PluginManager {
*/
*/
fun
loadPlugins
(){
fun
loadPlugins
(){
val
pluginsFound
:
MutableMap
<
String
,
PluginDescription
>
=
mutableMapOf
()
val
pluginsFound
:
MutableMap
<
String
,
PluginDescription
>
=
mutableMapOf
()
val
pluginsLocation
:
MutableMap
<
String
,
File
>
=
mutableMapOf
()
val
pluginsLocation
:
MutableMap
<
String
,
Jar
File
>
=
mutableMapOf
()
File
(
pluginsPath
).
listFiles
()
?.
forEach
{
file
->
File
(
pluginsPath
).
listFiles
()
?.
forEach
{
file
->
if
(
file
!=
null
)
{
if
(
file
!=
null
)
{
...
@@ -151,7 +143,7 @@ object PluginManager {
...
@@ -151,7 +143,7 @@ object PluginManager {
val
description
=
PluginDescription
.
readFromContent
(
sb
.
toString
())
val
description
=
PluginDescription
.
readFromContent
(
sb
.
toString
())
println
(
description
)
println
(
description
)
pluginsFound
[
description
.
pluginName
]
=
description
pluginsFound
[
description
.
pluginName
]
=
description
pluginsLocation
[
description
.
pluginName
]
=
file
pluginsLocation
[
description
.
pluginName
]
=
jar
}
}
}
}
}
}
...
@@ -217,11 +209,9 @@ object PluginManager {
...
@@ -217,11 +209,9 @@ object PluginManager {
logger
.
info
(
"loading plugin "
+
description
.
pluginName
)
logger
.
info
(
"loading plugin "
+
description
.
pluginName
)
try
{
try
{
val
pluginClass
=
this
.
javaClass
.
classLoader
.
loadClass
(
description
.
pluginBasePath
)
PluginClassLoader
((
pluginsLocation
[
description
.
pluginName
]
!!
),
this
.
javaClass
.
classLoader
)
.
loadClass
(
description
.
pluginBasePath
)
return
try
{
return
try
{
val
subClass
=
plugin
Class
.
asSubclass
(
PluginBase
::
class
.
java
)
val
subClass
=
java
Class
.
asSubclass
(
PluginBase
::
class
.
java
)
val
plugin
:
PluginBase
=
subClass
.
getDeclaredConstructor
().
newInstance
()
val
plugin
:
PluginBase
=
subClass
.
getDeclaredConstructor
().
newInstance
()
description
.
loaded
=
true
description
.
loaded
=
true
logger
.
info
(
"successfully loaded plugin "
+
description
.
pluginName
)
logger
.
info
(
"successfully loaded plugin "
+
description
.
pluginName
)
...
@@ -229,6 +219,7 @@ object PluginManager {
...
@@ -229,6 +219,7 @@ object PluginManager {
nameToPluginBaseMap
[
description
.
pluginName
]
=
plugin
nameToPluginBaseMap
[
description
.
pluginName
]
=
plugin
plugin
.
init
(
description
)
plugin
.
init
(
description
)
true
true
}
catch
(
e
:
ClassCastException
)
{
}
catch
(
e
:
ClassCastException
)
{
false
.
also
{
false
.
also
{
...
...
mirai-plugins/image-sender/image-sender.iml
deleted
100644 → 0
View file @
bda3e6dc
<?xml version="1.0" encoding="UTF-8"?>
<module
type=
"JAVA_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
inherit-compiler-output=
"true"
>
<exclude-output
/>
<content
url=
"file://$MODULE_DIR$"
>
<sourceFolder
url=
"file://$MODULE_DIR$/resources"
type=
"java-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/main/java"
isTestSource=
"false"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/main/resources"
type=
"java-resource"
/>
</content>
<orderEntry
type=
"inheritedJdk"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
<orderEntry
type=
"library"
name=
"KotlinJavaRuntime (3)"
level=
"project"
/>
<orderEntry
type=
"module"
module-name=
"mirai-console_main"
/>
</component>
</module>
\ No newline at end of file
mirai-plugins/mirai-plugins.iml
deleted
100644 → 0
View file @
bda3e6dc
<?xml version="1.0" encoding="UTF-8"?>
<module
type=
"JAVA_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
inherit-compiler-output=
"true"
>
<exclude-output
/>
<content
url=
"file://$MODULE_DIR$"
>
<sourceFolder
url=
"file://$MODULE_DIR$/src"
isTestSource=
"false"
/>
</content>
<orderEntry
type=
"inheritedJdk"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
<orderEntry
type=
"library"
name=
"KotlinJavaRuntime"
level=
"project"
/>
</component>
</module>
\ No newline at end of file
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