mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-05 17:59:14 +08:00
Java Friendly Manager API
This commit is contained in:
parent
de3cbdafd1
commit
b08546b5aa
@ -0,0 +1,31 @@
|
||||
package net.mamoe.mirai.console.utils;
|
||||
|
||||
import net.mamoe.mirai.Bot;
|
||||
import net.mamoe.mirai.console.MiraiConsole;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 获取Bot Manager
|
||||
* Java友好API
|
||||
*/
|
||||
public class BotManager {
|
||||
|
||||
static List<Long> getManagers(long botAccount) {
|
||||
Bot bot = MiraiConsole.INSTANCE.getBotOrThrow(botAccount);
|
||||
return getManagers(bot);
|
||||
}
|
||||
|
||||
static List<Long> getManagers(Bot bot){
|
||||
return BotHelperKt.getBotManagers(bot);
|
||||
}
|
||||
|
||||
static boolean isManager(Bot bot, long target){
|
||||
return getManagers(bot).contains(target);
|
||||
}
|
||||
|
||||
static boolean isManager(long botAccount, long target){
|
||||
return getManagers(botAccount).contains(target);
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,11 @@ object MiraiConsole {
|
||||
return bots.asSequence().mapNotNull { it.get() }.firstOrNull { it.id == uin }
|
||||
}
|
||||
|
||||
class BotNotFoundException(uin: Long):Exception("Bot $uin Not Found")
|
||||
fun getBotOrThrow(uin: Long):Bot{
|
||||
return bots.asSequence().mapNotNull { it.get() }.firstOrNull { it.id == uin }?:throw BotNotFoundException(uin)
|
||||
}
|
||||
|
||||
/**
|
||||
* 与前端交互所使用的Logger
|
||||
*/
|
||||
|
@ -108,7 +108,7 @@ object PluginManager {
|
||||
val pluginsFound: MutableMap<String, PluginDescription>
|
||||
)
|
||||
|
||||
private fun findPlugins():FindPluginsResult{
|
||||
internal fun findPlugins():FindPluginsResult{
|
||||
val pluginsLocation: MutableMap<String, File> = mutableMapOf()
|
||||
val pluginsFound: MutableMap<String, PluginDescription> = mutableMapOf()
|
||||
|
||||
@ -202,7 +202,7 @@ object PluginManager {
|
||||
}
|
||||
val depend = pluginsFound[dependent]!!
|
||||
|
||||
if (!loadPlugin(depend)) {
|
||||
if (!loadPlugin(depend)) {//先加载depend
|
||||
logger.error("Failed to load plugin " + description.name + " because " + dependent + " as dependency failed to load")
|
||||
return false
|
||||
}
|
||||
|
@ -48,3 +48,6 @@ fun Bot.checkManager(long: Long): Boolean {
|
||||
}
|
||||
|
||||
|
||||
fun getBotManagers(bot:Bot):List<Long>{
|
||||
return bot.managers
|
||||
}
|
Loading…
Reference in New Issue
Block a user