mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-14 07:10:09 +08:00
plugin supporting
This commit is contained in:
parent
350fe5aaf4
commit
aa427c20de
@ -1,5 +1,6 @@
|
||||
package net.mamoe.mirai.plugin
|
||||
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.utils.DefaultLogger
|
||||
import net.mamoe.mirai.utils.io.encodeToString
|
||||
import java.io.File
|
||||
@ -25,6 +26,11 @@ abstract class PluginBase constructor() {
|
||||
|
||||
}
|
||||
|
||||
open fun onBotAdd(bot: Bot) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private lateinit var pluginDescription: PluginDescription
|
||||
|
||||
internal fun init(pluginDescription: PluginDescription) {
|
||||
@ -200,7 +206,7 @@ object PluginManager {
|
||||
val subClass = pluginClass.asSubclass(PluginBase::class.java)
|
||||
val plugin: PluginBase = subClass.getDeclaredConstructor().newInstance()
|
||||
description.loaded = true
|
||||
logger.info("successfully loaded plugin " + description.name)
|
||||
logger.info("successfully loaded plugin " + description.name + " version " + description.version + " by " + description.author)
|
||||
logger.info(description.info)
|
||||
|
||||
nameToPluginBaseMap[description.name] = plugin
|
||||
@ -220,6 +226,12 @@ object PluginManager {
|
||||
pluginsFound.values.forEach {
|
||||
loadPlugin(it)
|
||||
}
|
||||
|
||||
nameToPluginBaseMap.values.forEach {
|
||||
it.onEnable()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,6 +22,7 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version"
|
||||
|
||||
fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version"
|
||||
@ -36,6 +37,8 @@ dependencies {
|
||||
api(kotlinx("io", kotlinXIoVersion))
|
||||
api(kotlinx("coroutines-io", coroutinesIoVersion))
|
||||
api(kotlinx("coroutines-core", coroutinesVersion))
|
||||
implementation("org.jsoup:jsoup:1.12.1")
|
||||
implementation(group = "com.alibaba", name = "fastjson", version = "1.2.62")
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>() {
|
||||
|
@ -0,0 +1,42 @@
|
||||
import com.alibaba.fastjson.JSON
|
||||
import kotlinx.coroutines.*
|
||||
import net.mamoe.mirai.contact.Contact
|
||||
import net.mamoe.mirai.message.data.Image
|
||||
import net.mamoe.mirai.message.uploadAsImage
|
||||
import org.jsoup.Jsoup
|
||||
|
||||
class ImageProvider {
|
||||
lateinit var contact: Contact
|
||||
|
||||
// `Deferred<Image?>` causes a runtime ClassCastException
|
||||
|
||||
val image: Deferred<Image> by lazy {
|
||||
GlobalScope.async {
|
||||
//delay((Math.random() * 5000L).toLong())
|
||||
class Result {
|
||||
var id: String = ""
|
||||
}
|
||||
|
||||
withTimeoutOrNull(5 * 1000) {
|
||||
withContext(Dispatchers.IO) {
|
||||
val result = JSON.parseObject(
|
||||
Jsoup.connect("http://dev.itxtech.org:10322/v2/randomImg.uue").ignoreContentType(true).timeout(
|
||||
10_0000
|
||||
).get().body().text(),
|
||||
Result::class.java
|
||||
)
|
||||
|
||||
Jsoup.connect("http://dev.itxtech.org:10322/img.uue?size=large&id=${result.id}")
|
||||
.userAgent("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; ja-jp) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27")
|
||||
.timeout(10_0000)
|
||||
.ignoreContentType(true)
|
||||
.maxBodySize(Int.MAX_VALUE)
|
||||
.execute()
|
||||
.bodyStream()
|
||||
}
|
||||
}?.uploadAsImage(contact) ?: error("Unable to download image")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user