mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-05 17:37:03 +08:00
plugin supporting
This commit is contained in:
parent
c0a9db0e07
commit
4f82703703
@ -1,6 +1,7 @@
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.alsoLogin
|
||||
import net.mamoe.mirai.plugin.PluginManager
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
@ -22,7 +23,7 @@ fun main() {
|
||||
|
||||
PluginManager.loadPlugins()
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(thread {
|
||||
Runtime.getRuntime().addShutdownHook(Thread {
|
||||
PluginManager.disableAllPlugins()
|
||||
})
|
||||
}
|
||||
@ -40,7 +41,7 @@ tailrec fun processNextCommandLine() {
|
||||
val qqPassword = commandArgs[2]
|
||||
println("login...")
|
||||
GlobalScope.launch {
|
||||
Bot(qqNumber, qqPassword)
|
||||
Bot(qqNumber, qqPassword).alsoLogin()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -223,9 +223,14 @@ object PluginManager {
|
||||
logger.info("loading plugin " + description.name)
|
||||
|
||||
try {
|
||||
val pluginClass =
|
||||
val pluginClass = try {
|
||||
PluginClassLoader((pluginsLocation[description.name]!!), this.javaClass.classLoader)
|
||||
.loadClass(description.basePath)
|
||||
} catch (e: ClassNotFoundException) {
|
||||
logger.info("failed to find Main: " + description.basePath + " checking if it's kotlin's path")
|
||||
PluginClassLoader((pluginsLocation[description.name]!!), this.javaClass.classLoader)
|
||||
.loadClass("${description.basePath}Kt")
|
||||
}
|
||||
return try {
|
||||
val subClass = pluginClass.asSubclass(PluginBase::class.java)
|
||||
val plugin: PluginBase = subClass.getDeclaredConstructor().newInstance()
|
||||
|
Binary file not shown.
@ -1,3 +1,5 @@
|
||||
package net.mamoe.mirai.imageplugin
|
||||
|
||||
import com.alibaba.fastjson.JSON
|
||||
import kotlinx.coroutines.*
|
||||
import net.mamoe.mirai.contact.Contact
|
@ -1,3 +1,6 @@
|
||||
package net.mamoe.mirai.imageplugin
|
||||
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import net.mamoe.mirai.event.events.BotLoginSucceedEvent
|
||||
import net.mamoe.mirai.event.subscribeAlways
|
||||
@ -7,7 +10,7 @@ import net.mamoe.mirai.plugin.PluginBase
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
|
||||
class ImageSenderMain : PluginBase() {
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
@MiraiExperimentalAPI
|
||||
override fun onEnable() {
|
||||
logger.info("Image Sender plugin enabled")
|
||||
@ -19,9 +22,13 @@ class ImageSenderMain : PluginBase() {
|
||||
(At(sender) + " ? ").reply()
|
||||
}
|
||||
|
||||
(contains("image") || contains("图")) {
|
||||
(At(sender) + " ? ").reply()
|
||||
(contains("image") or contains("图")) {
|
||||
"图片发送中".reply()
|
||||
ImageProvider().apply {
|
||||
this.contact = sender
|
||||
}.image.await().reply()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
name: ImageSender
|
||||
main: net.mamoe.mirai.imageplugin.ImagePluginMain
|
||||
main: net.mamoe.mirai.imageplugin.ImageSenderMain
|
||||
version: 1.0.0
|
||||
author: mamoe
|
||||
info: a demo plugin of mirai
|
||||
|
Loading…
Reference in New Issue
Block a user