Просмотр исходного кода

Merge remote-tracking branch 'origin/master'

Him188 6 лет назад
Родитель
Сommit
909614192d

+ 1 - 2
mirai-console/build.gradle.kts

@@ -7,11 +7,10 @@ plugins {
 
 apply(plugin = "com.github.johnrengelman.shadow")
 
-apply(plugin = "java-library")
 
 tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>() {
     manifest {
-        attributes["Main-Class"] = "net.mamoe.mirai.MiraiConsoleLoader"
+        attributes["Main-Class"] = "net.mamoe.mirai.console.MiraiConsoleLoader"
     }
 }
 

+ 2 - 2
mirai-console/src/main/kotlin/net/mamoe/mirai/Command.kt → mirai-console/src/main/kotlin/net/mamoe/mirai/console/Command.kt

@@ -1,4 +1,4 @@
-package net.mamoe.mirai
+package net.mamoe.mirai.console
 
 /*
  * Copyright 2020 Mamoe Technologies and contributors.
@@ -9,7 +9,7 @@ package net.mamoe.mirai
  * https://github.com/mamoe/mirai/blob/master/LICENSE
  */
 
-import net.mamoe.mirai.plugins.PluginManager
+import net.mamoe.mirai.console.plugins.PluginManager
 
 object CommandManager {
     private val registeredCommand: MutableMap<String, ICommand> = mutableMapOf()

+ 37 - 16
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt → mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt

@@ -1,4 +1,4 @@
-package net.mamoe.mirai
+package net.mamoe.mirai.console
 
 /*
  * Copyright 2020 Mamoe Technologies and contributors.
@@ -13,10 +13,12 @@ import kotlinx.coroutines.runBlocking
 import net.mamoe.mirai.api.http.MiraiHttpAPIServer
 import net.mamoe.mirai.api.http.generateSessionKey
 import net.mamoe.mirai.contact.sendMessage
-import net.mamoe.mirai.plugins.PluginManager
-import net.mamoe.mirai.plugins.loadAsConfig
-import net.mamoe.mirai.plugins.withDefaultWrite
-import net.mamoe.mirai.plugins.withDefaultWriteSave
+import net.mamoe.mirai.console.plugins.PluginManager
+import net.mamoe.mirai.console.plugins.loadAsConfig
+import net.mamoe.mirai.console.plugins.withDefaultWrite
+import net.mamoe.mirai.console.plugins.withDefaultWriteSave
+import net.mamoe.mirai.Bot
+import net.mamoe.mirai.alsoLogin
 import net.mamoe.mirai.utils.SimpleLogger
 import org.bouncycastle.jce.provider.BouncyCastleProvider
 import java.io.File
@@ -52,17 +54,20 @@ object MiraiConsole {
 
     fun start() {
         logger("Mirai-console [v$version $build | core version v$coreVersion] is still in testing stage, majority feature is available")
-        logger("Mirai-console now running under " + System.getProperty("user.dir"))
+        logger(
+            "Mirai-console now running under " + System.getProperty(
+                "user.dir"
+            )
+        )
         logger("Get news in github: https://github.com/mamoe/mirai")
         logger("Mirai为开源项目,请自觉遵守开源项目协议")
         logger("Powered by Mamoe Technologies and contributors")
 
-        runBlocking {
-            DefaultCommands()
-            HTTPAPIAdaptar()
-            pluginManager.loadPlugins()
-            CommandListener.start()
-        }
+
+        DefaultCommands()
+        HTTPAPIAdaptar()
+        pluginManager.loadPlugins()
+        CommandListener.start()
 
         logger("Mirai-console 启动完成")
         logger("\"/login qqnumber qqpassword \" to login a bot")
@@ -113,10 +118,18 @@ object MiraiConsole {
                     try {
                         runBlocking {
                             Bot(qqNumber, qqPassword).alsoLogin()
-                            logger("[Bot Login]", 0, "$qqNumber login successes")
+                            logger(
+                                "[Bot Login]",
+                                0,
+                                "$qqNumber login successes"
+                            )
                         }
                     } catch (e: Exception) {
-                        logger("[Bot Login]", 0, "$qqNumber login failed -> " + e.message)
+                        logger(
+                            "[Bot Login]",
+                            0,
+                            "$qqNumber login failed -> " + e.message
+                        )
                         e.printStackTrace()
                     }
                     true
@@ -224,7 +237,11 @@ object MiraiConsole {
                 description = "About Mirai-Console"
                 onCommand {
                     logger("v$version $build is still in testing stage, majority feature is available")
-                    logger("now running under " + System.getProperty("user.dir"))
+                    logger(
+                        "now running under " + System.getProperty(
+                            "user.dir"
+                        )
+                    )
                     logger("在Github中获取项目最新进展: https://github.com/mamoe/mirai")
                     logger("Mirai为开源项目,请自觉遵守开源项目协议")
                     logger("Powered by Mamoe Technologies and contributors")
@@ -259,7 +276,11 @@ object MiraiConsole {
 
     object UIPushLogger {
         operator fun invoke(any: Any? = null) {
-            invoke("[Mirai$version $build]", 0L, any)
+            invoke(
+                "[Mirai$version $build]",
+                0L,
+                any
+            )
         }
 
         operator fun invoke(identityStr: String, identity: Long, any: Any? = null) {

+ 34 - 15
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsoleUI.kt → mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleUI.kt

@@ -1,4 +1,4 @@
-package net.mamoe.mirai
+package net.mamoe.mirai.console
 
 import com.googlecode.lanterna.SGR
 import com.googlecode.lanterna.TerminalSize
@@ -16,9 +16,9 @@ import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.Job
 import kotlinx.coroutines.delay
 import kotlinx.coroutines.launch
-import net.mamoe.mirai.MiraiConsoleUI.LoggerDrawer.cleanPage
-import net.mamoe.mirai.MiraiConsoleUI.LoggerDrawer.drawLog
-import net.mamoe.mirai.MiraiConsoleUI.LoggerDrawer.redrawLogs
+import net.mamoe.mirai.console.MiraiConsoleUI.LoggerDrawer.cleanPage
+import net.mamoe.mirai.console.MiraiConsoleUI.LoggerDrawer.drawLog
+import net.mamoe.mirai.console.MiraiConsoleUI.LoggerDrawer.redrawLogs
 import java.awt.Font
 import java.io.OutputStream
 import java.io.PrintStream
@@ -42,8 +42,10 @@ object MiraiConsoleUI {
     val cacheLogSize = 50
 
     val log = mutableMapOf<Long, LimitLinkedQueue<String>>().also {
-        it[0L] = LimitLinkedQueue(cacheLogSize)
-        it[2821869985L] = LimitLinkedQueue(cacheLogSize)
+        it[0L] =
+            LimitLinkedQueue(cacheLogSize)
+        it[2821869985L] =
+            LimitLinkedQueue(cacheLogSize)
     }
     val botAdminCount = mutableMapOf<Long, Long>()
 
@@ -54,7 +56,8 @@ object MiraiConsoleUI {
 
     fun addBotScreen(uin: Long) {
         screens.add(uin)
-        log[uin] = LimitLinkedQueue(cacheLogSize)
+        log[uin] =
+            LimitLinkedQueue(cacheLogSize)
         botAdminCount[uin] = 0
     }
 
@@ -173,19 +176,23 @@ object MiraiConsoleUI {
 
                 when (keyStroke.keyType) {
                     KeyType.ArrowLeft -> {
-                        currentScreenId = getLeftScreenId()
+                        currentScreenId =
+                            getLeftScreenId()
                         clearRows(2)
                         cleanPage()
                         update()
                     }
                     KeyType.ArrowRight -> {
-                        currentScreenId = getRightScreenId()
+                        currentScreenId =
+                            getRightScreenId()
                         clearRows(2)
                         cleanPage()
                         update()
                     }
                     KeyType.Enter -> {
-                        MiraiConsole.CommandListener.commandChannel.offer(commandBuilder.toString())
+                        MiraiConsole.CommandListener.commandChannel.offer(
+                            commandBuilder.toString()
+                        )
                         emptyCommand()
                     }
                     else -> {
@@ -232,7 +239,11 @@ object MiraiConsoleUI {
 
 
     fun clearRows(row: Int) {
-        textGraphics.putString(0, row, " ".repeat(terminal.terminalSize.columns))
+        textGraphics.putString(
+            0, row, " ".repeat(
+                terminal.terminalSize.columns
+            )
+        )
     }
 
     fun drawFrame(
@@ -257,7 +268,8 @@ object MiraiConsoleUI {
 
         textGraphics.foregroundColor = TextColor.ANSI.DEFAULT
         textGraphics.backgroundColor = TextColor.ANSI.DEFAULT
-        val leftName = getScreenName(getLeftScreenId())
+        val leftName =
+            getScreenName(getLeftScreenId())
         // clearRows(2)
         textGraphics.putString((width - title.length) / 2 - "$leftName << ".length, 2, "$leftName << ")
         textGraphics.foregroundColor = TextColor.ANSI.WHITE
@@ -265,7 +277,8 @@ object MiraiConsoleUI {
         textGraphics.putString((width - title.length) / 2, 2, title, SGR.BOLD)
         textGraphics.foregroundColor = TextColor.ANSI.DEFAULT
         textGraphics.backgroundColor = TextColor.ANSI.DEFAULT
-        val rightName = getScreenName(getRightScreenId())
+        val rightName =
+            getScreenName(getRightScreenId())
         textGraphics.putString((width + title.length) / 2 + 1, 2, ">> $rightName")
     }
 
@@ -324,7 +337,10 @@ object MiraiConsoleUI {
                 try {
                     textGraphics.foregroundColor = TextColor.ANSI.GREEN
                     textGraphics.backgroundColor = TextColor.ANSI.DEFAULT
-                    textGraphics.putString(3, currentHeight, toWrite, SGR.ITALIC)
+                    textGraphics.putString(
+                        3,
+                        currentHeight, toWrite, SGR.ITALIC
+                    )
                 } catch (ignored: Exception) {
                     //
                 }
@@ -449,7 +465,10 @@ object MiraiConsoleUI {
                 drawMainFrame(screens.size - 1)
             }
             else -> {
-                drawBotFrame(screens[currentScreenId], 0)
+                drawBotFrame(
+                    screens[currentScreenId],
+                    0
+                )
             }
         }
         redrawLogs(log[screens[currentScreenId]]!!)

+ 19 - 5
mirai-console/src/main/kotlin/net/mamoe/mirai/plugins/ConfigSection.kt → mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugins/ConfigSection.kt

@@ -7,7 +7,7 @@
  * https://github.com/mamoe/mirai/blob/master/LICENSE
  */
 
-package net.mamoe.mirai.plugins
+package net.mamoe.mirai.console.plugins
 
 import com.alibaba.fastjson.JSON
 import com.alibaba.fastjson.JSONObject
@@ -55,7 +55,14 @@ interface Config {
 
     companion object {
         fun load(fileName: String): Config {
-            return load(File(fileName.replace("//", "/")))
+            return load(
+                File(
+                    fileName.replace(
+                        "//",
+                        "/"
+                    )
+                )
+            )
         }
 
         fun load(file: File): Config {
@@ -115,7 +122,12 @@ inline fun <reified T : Any> Config.withDefault(
 inline fun <reified T : Any> Config.withDefaultWrite(
     noinline defaultValue: () -> T
 ): WithDefaultWriteLoader<T> {
-    return WithDefaultWriteLoader(T::class, this, defaultValue, false)
+    return WithDefaultWriteLoader(
+        T::class,
+        this,
+        defaultValue,
+        false
+    )
 }
 
 /* 带有默认值且如果为空会写入保存的代理 */
@@ -258,7 +270,8 @@ interface ConfigSection : Config, MutableMap<String, Any> {
 }
 
 @Serializable
-open class ConfigSectionImpl() : ConcurrentHashMap<String, Any>(), ConfigSection {
+open class ConfigSectionImpl() : ConcurrentHashMap<String, Any>(),
+    ConfigSection {
     override fun set(key: String, value: Any) {
         super.put(key, value)
     }
@@ -310,7 +323,8 @@ interface FileConfig : Config {
 
 abstract class FileConfigImpl internal constructor(
     private val file: File
-) : FileConfig, ConfigSection {
+) : FileConfig,
+    ConfigSection {
 
     private val content by lazy {
         deserialize(file.readText())

+ 15 - 7
mirai-console/src/main/kotlin/net/mamoe/mirai/plugins/PluginBase.kt → mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugins/PluginBase.kt

@@ -7,11 +7,11 @@
  * https://github.com/mamoe/mirai/blob/master/LICENSE
  */
 
-package net.mamoe.mirai.plugins
+package net.mamoe.mirai.console.plugins
 
-import net.mamoe.mirai.ICommand
+import net.mamoe.mirai.console.ICommand
 import kotlinx.coroutines.*
-import net.mamoe.mirai.MiraiConsole
+import net.mamoe.mirai.console.MiraiConsole
 import net.mamoe.mirai.utils.DefaultLogger
 import net.mamoe.mirai.utils.MiraiLogger
 import net.mamoe.mirai.utils.SimpleLogger
@@ -146,7 +146,14 @@ class PluginDescription(
                     depends.add(line.substringAfter("-").trim())
                 }
             }
-            return PluginDescription(name, author, basePath, version, info, depends)
+            return PluginDescription(
+                name,
+                author,
+                basePath,
+                version,
+                info,
+                depends
+            )
         }
     }
 }
@@ -194,9 +201,10 @@ object PluginManager {
                     logger.info("plugin.yml not found in jar " + jar.name + ", it will not be consider as a Plugin")
                 } else {
                     val description =
-                        PluginDescription.readFromContent(URL("jar:file:" + file.absoluteFile + "!/" + pluginYml.name).openConnection().inputStream.use {
-                            it.readBytes().encodeToString()
-                        })
+                        PluginDescription.readFromContent(
+                            URL("jar:file:" + file.absoluteFile + "!/" + pluginYml.name).openConnection().inputStream.use {
+                                it.readBytes().encodeToString()
+                            })
                     pluginsFound[description.name] = description
                     pluginsLocation[description.name] = file
                 }

+ 1 - 1
mirai-plugins/image-sender/src/main/java/net/mamoe/mirai/imageplugin/ImageSenderMain.kt

@@ -14,7 +14,7 @@ import kotlinx.coroutines.GlobalScope
 import net.mamoe.mirai.event.events.BotOnlineEvent
 import net.mamoe.mirai.event.subscribeAlways
 import net.mamoe.mirai.event.subscribeMessages
-import net.mamoe.mirai.plugins.PluginBase
+import net.mamoe.mirai.console.plugins.PluginBase
 import net.mamoe.mirai.utils.MiraiExperimentalAPI
 
 class ImageSenderMain : PluginBase() {