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
a9f9618f
Commit
a9f9618f
authored
Jan 25, 2020
by
jiahua.liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Console ConfigSection.kt
parent
dcb8b0ac
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
125 additions
and
13 deletions
+125
-13
mirai-console/build.gradle
mirai-console/build.gradle
+0
-13
mirai-console/build.gradle.kts
mirai-console/build.gradle.kts
+32
-0
mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/ConfigSection.kt
...e/src/main/kotlin/net/mamoe/mirai/plugin/ConfigSection.kt
+54
-0
mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/PluginBase.kt
...sole/src/main/kotlin/net/mamoe/mirai/plugin/PluginBase.kt
+39
-0
No files found.
mirai-console/build.gradle
deleted
100644 → 0
View file @
dcb8b0ac
plugins
{
id
(
"com.github.johnrengelman.shadow"
)
version
"5.2.0"
}
apply
plugin:
"kotlin"
apply
plugin:
"java"
dependencies
{
api
project
(
':mirai-core'
)
api
project
(
':mirai-core-timpc'
)
runtimeOnly
files
(
'../mirai-core-timpc/build/classes/kotlin/jvm/main'
)
runtimeOnly
files
(
'../mirai-core/build/classes/kotlin/jvm/main'
)
// classpath is not set correctly by IDE
}
mirai-console/build.gradle.kts
0 → 100644
View file @
a9f9618f
plugins
{
id
(
"com.github.johnrengelman.shadow"
)
version
"5.2.0"
id
(
"kotlinx-serialization"
)
id
(
"kotlin"
)
id
(
"java"
)
}
val
kotlinVersion
:
String
by
rootProject
.
ext
val
atomicFuVersion
:
String
by
rootProject
.
ext
val
coroutinesVersion
:
String
by
rootProject
.
ext
val
kotlinXIoVersion
:
String
by
rootProject
.
ext
val
coroutinesIoVersion
:
String
by
rootProject
.
ext
val
klockVersion
:
String
by
rootProject
.
ext
val
ktorVersion
:
String
by
rootProject
.
ext
val
serializationVersion
:
String
by
rootProject
.
ext
fun
kotlinx
(
id
:
String
,
version
:
String
)
=
"org.jetbrains.kotlinx:kotlinx-$id:$version"
fun
ktor
(
id
:
String
,
version
:
String
)
=
"io.ktor:ktor-$id:$version"
dependencies
{
api
(
project
(
":mirai-core"
))
api
(
project
(
":mirai-core-timpc"
))
runtimeOnly
(
files
(
"../mirai-core-timpc/build/classes/kotlin/jvm/main"
))
runtimeOnly
(
files
(
"../mirai-core/build/classes/kotlin/jvm/main"
))
api
(
kotlin
(
"serialization"
))
// classpath is not set correctly by IDE
}
\ No newline at end of file
mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/ConfigSection.kt
0 → 100644
View file @
a9f9618f
package
net.mamoe.mirai.plugin
import
kotlinx.serialization.Serializable
import
java.util.concurrent.ConcurrentHashMap
@Serializable
class
ConfigSection
()
:
ConcurrentHashMap
<
String
,
Any
>()
{
fun
getString
(
key
:
String
):
String
{
return
(
get
(
key
)
?:
error
(
"ConfigSection does not contain $key "
)).
toString
()
}
fun
getInt
(
key
:
String
):
Int
{
return
(
get
(
key
)
?:
error
(
"ConfigSection does not contain $key "
)).
toString
().
toInt
()
}
fun
getFloat
(
key
:
String
):
Float
{
return
(
get
(
key
)
?:
error
(
"ConfigSection does not contain $key "
)).
toString
().
toFloat
()
}
fun
getDouble
(
key
:
String
):
Double
{
return
(
get
(
key
)
?:
error
(
"ConfigSection does not contain $key "
)).
toString
().
toDouble
()
}
fun
getLong
(
key
:
String
):
Long
{
return
(
get
(
key
)
?:
error
(
"ConfigSection does not contain $key "
)).
toString
().
toLong
()
}
fun
getConfigSection
(
key
:
String
):
ConfigSection
{
return
(
get
(
key
)
?:
error
(
"ConfigSection does not contain $key "
))
as
ConfigSection
}
fun
getStringList
(
key
:
String
):
List
<
String
>
{
return
((
get
(
key
)
?:
error
(
"ConfigSection does not contain $key "
))
as
List
<
*
>).
map
{
it
.
toString
()
}
}
fun
getIntList
(
key
:
String
):
List
<
Int
>
{
return
((
get
(
key
)
?:
error
(
"ConfigSection does not contain $key "
))
as
List
<
*
>).
map
{
it
.
toString
().
toInt
()
}
}
fun
getFloatList
(
key
:
String
):
List
<
Float
>
{
return
((
get
(
key
)
?:
error
(
"ConfigSection does not contain $key "
))
as
List
<
*
>).
map
{
it
.
toString
().
toFloat
()
}
}
fun
getDoubleList
(
key
:
String
):
List
<
Double
>
{
return
((
get
(
key
)
?:
error
(
"ConfigSection does not contain $key "
))
as
List
<
*
>).
map
{
it
.
toString
().
toDouble
()
}
}
fun
getLongList
(
key
:
String
):
List
<
Long
>
{
return
((
get
(
key
)
?:
error
(
"ConfigSection does not contain $key "
))
as
List
<
*
>).
map
{
it
.
toString
().
toLong
()
}
}
}
\ No newline at end of file
mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/PluginBase.kt
View file @
a9f9618f
package
net.mamoe.mirai.plugin
import
kotlinx.coroutines.*
import
kotlinx.serialization.UnstableDefault
import
kotlinx.serialization.json.Json
import
net.mamoe.mirai.utils.DefaultLogger
import
net.mamoe.mirai.utils.MiraiLogger
import
net.mamoe.mirai.utils.io.encodeToString
...
...
@@ -43,10 +45,47 @@ abstract class PluginBase(coroutineContext: CoroutineContext) : CoroutineScope {
}
/**
* 当任意指令被使用
*/
open
fun
onCommand
(
command
:
Command
)
{
}
internal
fun
enable
()
{
this
.
onEnable
()
}
@UnstableDefault
fun
loadConfig
(
fileName
:
String
=
"config.json"
):
ConfigSection
{
var
content
=
File
(
dataFolder
.
name
+
"/"
+
fileName
)
.
also
{
if
(!
it
.
exists
())
it
.
createNewFile
()
}.
readText
()
if
(
content
==
""
)
{
content
=
"{}"
}
return
Json
.
parse
(
ConfigSection
.
serializer
(),
content
)
}
@UnstableDefault
fun
saveConfig
(
config
:
ConfigSection
,
fileName
:
String
=
"config.json"
)
{
val
content
=
Json
.
stringify
(
ConfigSection
.
serializer
(),
config
)
File
(
dataFolder
.
name
+
"/"
+
fileName
)
.
also
{
if
(!
it
.
exists
())
it
.
createNewFile
()
}.
writeText
(
content
)
}
@JvmOverloads
internal
fun
disable
(
throwable
:
CancellationException
?
=
null
)
{
this
.
coroutineContext
[
Job
]
!!
.
cancelChildren
(
throwable
)
...
...
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