Commit a4d78b3d authored by jiahua.liu's avatar jiahua.liu

plugin supporting

parent 3ddbdbf6
...@@ -2,6 +2,7 @@ package net.mamoe.mirai.plugin ...@@ -2,6 +2,7 @@ package net.mamoe.mirai.plugin
import kotlinx.coroutines.* import kotlinx.coroutines.*
import net.mamoe.mirai.utils.DefaultLogger import net.mamoe.mirai.utils.DefaultLogger
import net.mamoe.mirai.utils.MiraiLogger
import net.mamoe.mirai.utils.io.encodeToString import net.mamoe.mirai.utils.io.encodeToString
import java.io.File import java.io.File
import java.net.URL import java.net.URL
...@@ -58,6 +59,12 @@ abstract class PluginBase(coroutineContext: CoroutineContext) : CoroutineScope { ...@@ -58,6 +59,12 @@ abstract class PluginBase(coroutineContext: CoroutineContext) : CoroutineScope {
this.pluginDescription = pluginDescription this.pluginDescription = pluginDescription
this.onLoad() this.onLoad()
} }
fun getPluginManager() = PluginManager
val logger: MiraiLogger by lazy {
DefaultLogger(pluginDescription.name)
}
} }
class PluginDescription( class PluginDescription(
...@@ -125,7 +132,7 @@ object PluginManager { ...@@ -125,7 +132,7 @@ object PluginManager {
File(it).mkdirs() File(it).mkdirs()
} }
private val logger = DefaultLogger("Mirai Plugin Manager") val logger = DefaultLogger("Mirai Plugin Manager")
//已完成加载的 //已完成加载的
private val nameToPluginBaseMap: MutableMap<String, PluginBase> = mutableMapOf() private val nameToPluginBaseMap: MutableMap<String, PluginBase> = mutableMapOf()
......
package net.mamoe.mirai.imageplugin;
import net.mamoe.mirai.plugin.PluginBase;
public class ImagePluginMain extends PluginBase {
static {
System.out.println("Static Loaded");
}
@Override
public void onLoad() {
System.out.println("Loaded");
}
@Override
public void onEnable() {
System.out.println("Enabled");
}
}
import kotlinx.coroutines.GlobalScope
import net.mamoe.mirai.event.events.BotLoginSucceedEvent
import net.mamoe.mirai.event.subscribeAlways
import net.mamoe.mirai.event.subscribeMessages
import net.mamoe.mirai.message.data.At
import net.mamoe.mirai.plugin.PluginBase
import net.mamoe.mirai.utils.MiraiExperimentalAPI
class ImageSenderMain : PluginBase() {
@MiraiExperimentalAPI
override fun onEnable() {
logger.info("Image Sender plugin enabled")
GlobalScope.subscribeAlways<BotLoginSucceedEvent> {
logger.info("${this.bot.uin} login succeed, it will be controlled by Image Sender Plugin")
this.bot.subscribeMessages {
case("at me") {
(At(sender) + " ? ").reply()
}
(contains("image") || contains("图")) {
(At(sender) + " ? ").reply()
}
}
}
}
override fun onLoad() {
logger.info("loading...")
}
override fun onDisable() {
}
}
\ No newline at end of file
name: ImageSender name: ImageSender
main: net.mamoe.mirai.imageplugin.ImagePluginMain.kt.kt main: net.mamoe.mirai.imageplugin.ImagePluginMain
version: 1.0.0 version: 1.0.0
author: mamoe author: mamoe
info: a demo plugin of mirai info: a demo plugin of mirai
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment