Merge remote-tracking branch 'origin/master'

This commit is contained in:
Him188 2020-02-16 01:21:19 +08:00
commit 909614192d
7 changed files with 109 additions and 48 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -7,7 +7,7 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE * 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.JSON
import com.alibaba.fastjson.JSONObject import com.alibaba.fastjson.JSONObject
@ -55,7 +55,14 @@ interface Config {
companion object { companion object {
fun load(fileName: String): Config { fun load(fileName: String): Config {
return load(File(fileName.replace("//", "/"))) return load(
File(
fileName.replace(
"//",
"/"
)
)
)
} }
fun load(file: File): Config { fun load(file: File): Config {
@ -115,7 +122,12 @@ inline fun <reified T : Any> Config.withDefault(
inline fun <reified T : Any> Config.withDefaultWrite( inline fun <reified T : Any> Config.withDefaultWrite(
noinline defaultValue: () -> T noinline defaultValue: () -> T
): WithDefaultWriteLoader<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 @Serializable
open class ConfigSectionImpl() : ConcurrentHashMap<String, Any>(), ConfigSection { open class ConfigSectionImpl() : ConcurrentHashMap<String, Any>(),
ConfigSection {
override fun set(key: String, value: Any) { override fun set(key: String, value: Any) {
super.put(key, value) super.put(key, value)
} }
@ -310,7 +323,8 @@ interface FileConfig : Config {
abstract class FileConfigImpl internal constructor( abstract class FileConfigImpl internal constructor(
private val file: File private val file: File
) : FileConfig, ConfigSection { ) : FileConfig,
ConfigSection {
private val content by lazy { private val content by lazy {
deserialize(file.readText()) deserialize(file.readText())

View File

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

View File

@ -14,7 +14,7 @@ import kotlinx.coroutines.GlobalScope
import net.mamoe.mirai.event.events.BotOnlineEvent import net.mamoe.mirai.event.events.BotOnlineEvent
import net.mamoe.mirai.event.subscribeAlways import net.mamoe.mirai.event.subscribeAlways
import net.mamoe.mirai.event.subscribeMessages 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 import net.mamoe.mirai.utils.MiraiExperimentalAPI
class ImageSenderMain : PluginBase() { class ImageSenderMain : PluginBase() {