Skip to content

Commit

Permalink
MiraiNative: update folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
PeratX committed Apr 17, 2020
1 parent f2a6220 commit 58367b9
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 28 deletions.
3 changes: 1 addition & 2 deletions src/main/kotlin/org/itxtech/mirainative/MiraiNative.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import kotlin.coroutines.ContinuationInterceptor
object MiraiNative : PluginBase() {
var botOnline = false
val bot: Bot by lazy { Bot.instances.first().get()!! }
private val lib: File by lazy { File(dataFolder.absolutePath + File.separatorChar + "libraries") }
private val lib: File by lazy { File(dataFolder.absolutePath + File.separatorChar + "libraries").also { it.mkdirs() } }
private val dll: File by lazy { File(dataFolder.absolutePath + File.separatorChar + "CQP.dll") }

private fun checkNativeLibs() {
Expand Down Expand Up @@ -84,7 +84,6 @@ object MiraiNative : PluginBase() {
}

private fun initDataDir() {
lib.mkdirs()
File("data" + File.separatorChar + "image").mkdirs()
File(
System.getProperty("java.library.path")
Expand Down
21 changes: 0 additions & 21 deletions src/main/kotlin/org/itxtech/mirainative/bridge/MiraiBridge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ object MiraiBridge {
return false
}

@JvmStatic
fun quoteMessage(pluginId: Int, msgId: Int, message: String): Int {
if (isLegalCall(pluginId)) {
val internalId = CacheManager.nextId()
Expand Down Expand Up @@ -96,7 +95,6 @@ object MiraiBridge {
return 0
}

@JvmStatic
fun sendPrivateMessage(pluginId: Int, id: Long, message: String): Int {
if (isLegalCall(pluginId)) {
val internalId = CacheManager.nextId()
Expand All @@ -111,7 +109,6 @@ object MiraiBridge {
return 0
}

@JvmStatic
fun sendGroupMessage(pluginId: Int, id: Long, message: String): Int {
if (isLegalCall(pluginId)) {
val internalId = CacheManager.nextId()
Expand All @@ -126,7 +123,6 @@ object MiraiBridge {
return 0
}

@JvmStatic
fun setGroupBan(pluginId: Int, groupId: Long, memberId: Long, duration: Int): Int {
if (isLegalCall(pluginId)) {
MiraiNative.launch {
Expand All @@ -140,15 +136,13 @@ object MiraiBridge {
return 0
}

@JvmStatic
fun setGroupCard(pluginId: Int, groupId: Long, memberId: Long, card: String): Int {
if (isLegalCall(pluginId)) {
MiraiNative.bot.getGroup(groupId)[memberId].nameCard = card
}
return 0
}

@JvmStatic
fun setGroupKick(pluginId: Int, groupId: Long, memberId: Long): Int {
if (isLegalCall(pluginId)) {
MiraiNative.launch {
Expand All @@ -158,7 +152,6 @@ object MiraiBridge {
return 0
}

@JvmStatic
fun setGroupLeave(pluginId: Int, groupId: Long): Int {
if (isLegalCall(pluginId)) {
MiraiNative.launch {
Expand All @@ -168,23 +161,20 @@ object MiraiBridge {
return 0
}

@JvmStatic
fun setGroupSpecialTitle(pluginId: Int, group: Long, member: Long, title: String, duration: Long): Int {
if (isLegalCall(pluginId)) {
MiraiNative.bot.getGroup(group)[member].specialTitle = title
}
return 0
}

@JvmStatic
fun setGroupWholeBan(pluginId: Int, group: Long, enable: Boolean): Int {
if (isLegalCall(pluginId)) {
MiraiNative.bot.getGroup(group).settings.isMuteAll = enable
}
return 0
}

@JvmStatic
fun getStrangerInfo(pluginId: Int, account: Long): String {
if (isLegalCall(pluginId)) {
val m = CacheManager.findMember(account) ?: return ""
Expand All @@ -198,7 +188,6 @@ object MiraiBridge {
return ""
}

@JvmStatic
fun getFriendList(pluginId: Int): String {
if (isLegalCall(pluginId)) {
val list = MiraiNative.bot.friends
Expand All @@ -217,7 +206,6 @@ object MiraiBridge {
return ""
}

@JvmStatic
fun getGroupInfo(pluginId: Int, id: Long): String {
if (isLegalCall(pluginId)) {
val info = MiraiNative.bot.getGroupOrNull(id)
Expand All @@ -234,7 +222,6 @@ object MiraiBridge {
return ""
}

@JvmStatic
fun getGroupList(pluginId: Int): String {
if (isLegalCall(pluginId)) {
val list = MiraiNative.bot.groups
Expand All @@ -251,7 +238,6 @@ object MiraiBridge {
return ""
}

@JvmStatic
fun getGroupMemberInfo(pluginId: Int, groupId: Long, memberId: Long): String {
if (isLegalCall(pluginId)) {
val member = MiraiNative.bot.getGroupOrNull(groupId)?.getOrNull(memberId) ?: return ""
Expand All @@ -262,7 +248,6 @@ object MiraiBridge {
return ""
}

@JvmStatic
fun getGroupMemberList(pluginId: Int, groupId: Long): String {
if (isLegalCall(pluginId)) {
val group = MiraiNative.bot.getGroupOrNull(groupId) ?: return ""
Expand All @@ -278,7 +263,6 @@ object MiraiBridge {
return ""
}

@JvmStatic
fun setGroupAddRequest(pluginId: Int, requestId: String, reqType: Int, type: Int, reason: String): Int {
if (isLegalCall(pluginId)) {
MiraiNative.nativeLaunch {
Expand All @@ -294,7 +278,6 @@ object MiraiBridge {
return 0
}

@JvmStatic
fun setFriendAddRequest(pluginId: Int, requestId: String, type: Int, remark: String): Int {
if (isLegalCall(pluginId)) {
MiraiNative.nativeLaunch {
Expand All @@ -309,22 +292,18 @@ object MiraiBridge {
return 0
}

@JvmStatic
fun addLog(pluginId: Int, priority: Int, type: String, content: String) {
NativeLoggerHelper.log(PluginManager.plugins[pluginId]!!, priority, type, content)
}

@JvmStatic
fun getPluginDataDir(pluginId: Int): String {
return PluginManager.plugins[pluginId]!!.appDir.absolutePath + File.separatorChar
}

@JvmStatic
fun getLoginQQ(pluginId: Int): Long {
return if (isLegalCall(pluginId)) MiraiNative.bot.id else 0
}

@JvmStatic
fun getLoginNick(pluginId: Int): String {
return if (isLegalCall(pluginId)) MiraiNative.bot.nick else ""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ import java.io.File
object PluginManager {
private var pluginId = atomic(0)
var plugins = hashMapOf<Int, NativePlugin>()
private val pl: File by lazy { File(MiraiNative.dataFolder.absolutePath + File.separatorChar + "plugins").also { it.mkdirs() } }

fun loadPlugins() {
if (!MiraiNative.dataFolder.isDirectory) {
MiraiNative.logger.error("数据文件夹不是一个文件夹!" + MiraiNative.dataFolder.absolutePath)
} else {
MiraiNative.nativeLaunch {
MiraiNative.dataFolder.listFiles()?.forEach { file ->
pl.listFiles()?.forEach { file ->
if (file.isFile && file.absolutePath.endsWith("dll") && !file.absolutePath.endsWith("CQP.dll")) {
loadPlugin(file)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ data class NativePlugin(val file: File, val id: Int) {
var api = -1
var identifier: String = file.name
val appDir: File by lazy {
File(file.parent + File.separatorChar + identifier).also { it.mkdir() }
File(file.parent + File.separatorChar + "data" + File.separatorChar + identifier).also { it.mkdir() }
}
var pluginInfo: PluginInfo? = null
set(v) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/org/itxtech/mirainative/util/NpmHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ package org.itxtech.mirainative.util
import org.itxtech.mirainative.plugin.NativePlugin

object NpmHelper {
fun state(p: NativePlugin): String {
return "状态:" + (if (p.enabled) "已启用 " else "已禁用 ") + (if (p.loaded) "已加载" else "已卸载")
fun state(p: NativePlugin, h: Boolean = true): String {
return (if (h) " 状态:" else "") + (if (p.enabled) "已启用 " else "已禁用 ") + (if (p.loaded) "已加载" else "已卸载")
}

fun name(p: NativePlugin): String {
Expand All @@ -39,7 +39,7 @@ object NpmHelper {
val d = StringBuilder()
val i = p.pluginInfo
d.appendln("标识符:" + p.identifier)
d.appendln("状态:" + state(p))
d.appendln("状态:" + state(p, false))
if (i == null) {
d.appendln("Id:" + p.id + " (JSON文件缺失)")
d.appendln("CQ API:" + p.api)
Expand Down

0 comments on commit 58367b9

Please sign in to comment.