mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-23 22:00:10 +08:00
plugin supporting
This commit is contained in:
parent
3ddbdbf649
commit
a4d78b3d21
@ -2,6 +2,7 @@ package net.mamoe.mirai.plugin
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
import net.mamoe.mirai.utils.DefaultLogger
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
import net.mamoe.mirai.utils.io.encodeToString
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
@ -58,6 +59,12 @@ abstract class PluginBase(coroutineContext: CoroutineContext) : CoroutineScope {
|
||||
this.pluginDescription = pluginDescription
|
||||
this.onLoad()
|
||||
}
|
||||
|
||||
fun getPluginManager() = PluginManager
|
||||
|
||||
val logger: MiraiLogger by lazy {
|
||||
DefaultLogger(pluginDescription.name)
|
||||
}
|
||||
}
|
||||
|
||||
class PluginDescription(
|
||||
@ -125,7 +132,7 @@ object PluginManager {
|
||||
File(it).mkdirs()
|
||||
}
|
||||
|
||||
private val logger = DefaultLogger("Mirai Plugin Manager")
|
||||
val logger = DefaultLogger("Mirai Plugin Manager")
|
||||
|
||||
//已完成加载的
|
||||
private val nameToPluginBaseMap: MutableMap<String, PluginBase> = mutableMapOf()
|
||||
|
@ -1,20 +0,0 @@
|
||||
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");
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
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() {
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
name: ImageSender
|
||||
main: net.mamoe.mirai.imageplugin.ImagePluginMain.kt.kt
|
||||
main: net.mamoe.mirai.imageplugin.ImagePluginMain
|
||||
version: 1.0.0
|
||||
author: mamoe
|
||||
info: a demo plugin of mirai
|
||||
|
Loading…
Reference in New Issue
Block a user