diff --git a/mirai-console/build.gradle.kts b/mirai-console/build.gradle.kts index 931d5481e..765ffb88d 100644 --- a/mirai-console/build.gradle.kts +++ b/mirai-console/build.gradle.kts @@ -7,7 +7,6 @@ plugins { apply(plugin = "com.github.johnrengelman.shadow") -apply(plugin = "java-library") tasks.withType() { manifest { diff --git a/mirai-console/src/main/kotlin/net/mamoe/mirai/Command.kt b/mirai-console/src/main/kotlin/net/mamoe/mirai/console/Command.kt similarity index 97% rename from mirai-console/src/main/kotlin/net/mamoe/mirai/Command.kt rename to mirai-console/src/main/kotlin/net/mamoe/mirai/console/Command.kt index bebbd228d..41dc5232a 100644 --- a/mirai-console/src/main/kotlin/net/mamoe/mirai/Command.kt +++ b/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 = mutableMapOf() diff --git a/mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt b/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt similarity index 89% rename from mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt rename to mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt index ed9ceb855..98a968f77 100644 --- a/mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt +++ b/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,7 +54,11 @@ 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") @@ -113,10 +119,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 +238,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 +277,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) { diff --git a/mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsoleUI.kt b/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleUI.kt similarity index 92% rename from mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsoleUI.kt rename to mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleUI.kt index ab398e73a..e91362ea5 100644 --- a/mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsoleUI.kt +++ b/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>().also { - it[0L] = LimitLinkedQueue(cacheLogSize) - it[2821869985L] = LimitLinkedQueue(cacheLogSize) + it[0L] = + LimitLinkedQueue(cacheLogSize) + it[2821869985L] = + LimitLinkedQueue(cacheLogSize) } val botAdminCount = mutableMapOf() @@ -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]]!!) diff --git a/mirai-console/src/main/kotlin/net/mamoe/mirai/plugins/ConfigSection.kt b/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugins/ConfigSection.kt similarity index 96% rename from mirai-console/src/main/kotlin/net/mamoe/mirai/plugins/ConfigSection.kt rename to mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugins/ConfigSection.kt index 41991dfb2..15a6c1f73 100644 --- a/mirai-console/src/main/kotlin/net/mamoe/mirai/plugins/ConfigSection.kt +++ b/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 Config.withDefault( inline fun Config.withDefaultWrite( noinline defaultValue: () -> T ): WithDefaultWriteLoader { - return WithDefaultWriteLoader(T::class, this, defaultValue, false) + return WithDefaultWriteLoader( + T::class, + this, + defaultValue, + false + ) } /* 带有默认值且如果为空会写入保存的代理 */ @@ -258,7 +270,8 @@ interface ConfigSection : Config, MutableMap { } @Serializable -open class ConfigSectionImpl() : ConcurrentHashMap(), ConfigSection { +open class ConfigSectionImpl() : ConcurrentHashMap(), + 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()) diff --git a/mirai-console/src/main/kotlin/net/mamoe/mirai/plugins/PluginBase.kt b/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugins/PluginBase.kt similarity index 94% rename from mirai-console/src/main/kotlin/net/mamoe/mirai/plugins/PluginBase.kt rename to mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugins/PluginBase.kt index ceb797100..f99bdf8f8 100644 --- a/mirai-console/src/main/kotlin/net/mamoe/mirai/plugins/PluginBase.kt +++ b/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 } diff --git a/mirai-plugins/image-sender/src/main/java/net/mamoe/mirai/imageplugin/ImageSenderMain.kt b/mirai-plugins/image-sender/src/main/java/net/mamoe/mirai/imageplugin/ImageSenderMain.kt index 41c4343b8..60b0b16a5 100644 --- a/mirai-plugins/image-sender/src/main/java/net/mamoe/mirai/imageplugin/ImageSenderMain.kt +++ b/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() {