mirror of
https://github.com/mamoe/mirai.git
synced 2024-12-27 00:50:11 +08:00
Fix all compiler warnings throughout the project
This commit is contained in:
parent
c1f7149aa7
commit
1f8524fb04
@ -9,7 +9,7 @@
|
||||
|
||||
package net.mamoe.mirai.console.fontend
|
||||
|
||||
import net.mamoe.mirai.console.MiraiConsole
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
|
||||
/**
|
||||
* [ProcessProgress] 的简单实现, 前端应该自行实现 [ProcessProgress]
|
||||
@ -23,7 +23,12 @@ internal class DefaultLoggingProcessProgress : ProcessProgress {
|
||||
private var failed: Boolean = false
|
||||
|
||||
private companion object {
|
||||
private val logger by lazy { MiraiConsole.createLogger("ProcessProgress") }
|
||||
private val logger by lazy {
|
||||
MiraiLogger.Factory.create(
|
||||
DefaultLoggingProcessProgress::class,
|
||||
"ProcessProgress"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateText(txt: String) {
|
||||
|
@ -48,9 +48,9 @@ internal open class LoginCommandImpl : SimpleCommand(
|
||||
val config = DataScope.get<AutoLoginConfig>()
|
||||
val account = config.accounts.firstOrNull { it.account == id.toString() }
|
||||
if (account != null) {
|
||||
account.configuration[AutoLoginConfig.Account.ConfigurationKey.protocol]?.let { protocol ->
|
||||
account.configuration[AutoLoginConfig.Account.ConfigurationKey.protocol]?.let { proto ->
|
||||
try {
|
||||
this.protocol = BotConfiguration.MiraiProtocol.valueOf(protocol.toString())
|
||||
this.protocol = BotConfiguration.MiraiProtocol.valueOf(proto.toString())
|
||||
} catch (_: Throwable) {
|
||||
//
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import org.junit.jupiter.api.DynamicTest
|
||||
import org.junit.jupiter.api.TestFactory
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Suppress("UNUSED_PARAMETER", "unused")
|
||||
internal class CommandValueArgumentContextTest : AbstractCommandTest() {
|
||||
|
||||
inner class CustomBooleanParser : CommandValueArgumentParser<Boolean> {
|
||||
|
@ -9,9 +9,7 @@
|
||||
|
||||
package net.mamoe.mirai.console.terminal
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import net.mamoe.mirai.utils.TestOnly
|
||||
import java.io.File
|
||||
|
||||
// Used by https://github.com/iTXTech/soyuz, change with care.
|
||||
internal sealed class LoggingService {
|
||||
@ -31,14 +29,3 @@ internal class LoggingServiceNoop : LoggingService() {
|
||||
}
|
||||
}
|
||||
|
||||
internal class LoggingServiceI(
|
||||
scope: CoroutineScope,
|
||||
) : LoggingService() {
|
||||
fun startup(logDir: File) {
|
||||
}
|
||||
|
||||
|
||||
override fun pushLine(line: String) {
|
||||
}
|
||||
|
||||
}
|
@ -11,36 +11,32 @@ package net.mamoe.mirai.console.gradle
|
||||
|
||||
import com.google.gson.Gson
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.publish.maven.MavenPublication
|
||||
import org.gradle.api.tasks.TaskContainer
|
||||
import org.gradle.api.tasks.bundling.Jar
|
||||
import org.gradle.kotlin.dsl.get
|
||||
import org.gradle.kotlin.dsl.getValue
|
||||
import org.gradle.kotlin.dsl.provideDelegate
|
||||
import org.gradle.kotlin.dsl.registering
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
|
||||
private val Project.selfAndParentProjects: Sequence<Project>
|
||||
get() = generateSequence(this) { it.parent }
|
||||
|
||||
private fun Project.findPropertySmart(propName: String): String? {
|
||||
return findProperty(propName)?.toString()
|
||||
?: System.getProperty(propName)
|
||||
?: selfAndParentProjects.map { it.projectDir.resolve(propName) }.find { it.exists() }?.readText()
|
||||
?: System.getenv(propName)
|
||||
}
|
||||
|
||||
private class PropertyNotFoundException(message: String) : RuntimeException(message)
|
||||
|
||||
private fun Project.findPropertySmartOrFail(propName: String): String {
|
||||
return findPropertySmart(propName)
|
||||
?: throw PropertyNotFoundException("[Mirai Console] Cannot find property for publication: '$propName'. Please check your 'mirai' configuration.")
|
||||
}
|
||||
//private val Project.selfAndParentProjects: Sequence<Project>
|
||||
// get() = generateSequence(this) { it.parent }
|
||||
//
|
||||
//private fun Project.findPropertySmart(propName: String): String? {
|
||||
// return findProperty(propName)?.toString()
|
||||
// ?: System.getProperty(propName)
|
||||
// ?: selfAndParentProjects.map { it.projectDir.resolve(propName) }.find { it.exists() }?.readText()
|
||||
// ?: System.getenv(propName)
|
||||
//}
|
||||
//
|
||||
//private class PropertyNotFoundException(message: String) : RuntimeException(message)
|
||||
//
|
||||
//private fun Project.findPropertySmartOrFail(propName: String): String {
|
||||
// return findPropertySmart(propName)
|
||||
// ?: throw PropertyNotFoundException("[Mirai Console] Cannot find property for publication: '$propName'. Please check your 'mirai' configuration.")
|
||||
//}
|
||||
|
||||
internal fun Project.configurePublishing() {
|
||||
if (!miraiExtension.publishingEnabled) return
|
||||
@ -50,23 +46,6 @@ internal fun Project.configurePublishing() {
|
||||
registerPublishPluginTasks(it, isSingleTarget)
|
||||
registerMavenPublications(it, isSingleTarget)
|
||||
}
|
||||
|
||||
try {
|
||||
registerBintrayPublish()
|
||||
} catch (e: PropertyNotFoundException) {
|
||||
logger.warn(e.message)
|
||||
tasks.filter { it.group == "mirai" }
|
||||
.filter { it.name.startsWith("publishPlugin") }
|
||||
.forEach { it.enabled = false }
|
||||
logger.warn("Publishing tasks disabled.")
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun <reified T : Task> TaskContainer.getSingleTask(): T = filterIsInstance<T>().single()
|
||||
|
||||
private fun Project.registerPublishPluginTasks() {
|
||||
val isSingleTarget = kotlinJvmOrAndroidTargets.size == 1
|
||||
kotlinJvmOrAndroidTargets.forEach { registerPublishPluginTasks(it, isSingleTarget) }
|
||||
}
|
||||
|
||||
// effectively public
|
||||
@ -90,51 +69,50 @@ internal fun String.wrapNameWithPlatform(target: KotlinTarget, isSingleTarget: B
|
||||
}
|
||||
|
||||
private fun Project.registerPublishPluginTasks(target: KotlinTarget, isSingleTarget: Boolean) {
|
||||
val generateMetadataTask =
|
||||
tasks.register("generatePluginMetadata".wrapNameWithPlatform(target, isSingleTarget)).get().apply {
|
||||
group = "mirai"
|
||||
tasks.register("generatePluginMetadata".wrapNameWithPlatform(target, isSingleTarget)).get().apply {
|
||||
group = "mirai"
|
||||
|
||||
val metadataFile =
|
||||
project.buildDir.resolve("mirai")
|
||||
.resolve(if (isSingleTarget) "mirai-plugin.metadata" else "mirai-plugin-${target.name}.metadata")
|
||||
outputs.file(metadataFile)
|
||||
val metadataFile =
|
||||
project.buildDir.resolve("mirai")
|
||||
.resolve(if (isSingleTarget) "mirai-plugin.metadata" else "mirai-plugin-${target.name}.metadata")
|
||||
outputs.file(metadataFile)
|
||||
|
||||
|
||||
|
||||
doLast {
|
||||
val mirai = miraiExtension
|
||||
doLast {
|
||||
val mirai = miraiExtension
|
||||
|
||||
val output = outputs.files.singleFile
|
||||
output.parentFile.mkdir()
|
||||
val output = outputs.files.singleFile
|
||||
output.parentFile.mkdir()
|
||||
|
||||
fun getConfigurationsToInclude(): List<Configuration> {
|
||||
val compilation = target.compilations["main"]
|
||||
return compilation.relatedConfigurationNames.map { configurations[it] }
|
||||
}
|
||||
|
||||
val dependencies = getConfigurationsToInclude().flatMap { it.allDependencies }.map {
|
||||
"${it.group}:${it.name}:${it.version}"
|
||||
}.distinct()
|
||||
|
||||
val json = Gson().toJson(
|
||||
PluginMetadata(
|
||||
metadataVersion = 1,
|
||||
groupId = mirai.publishing.groupId ?: project.group.toString(),
|
||||
artifactId = mirai.publishing.artifactId ?: project.name,
|
||||
version = mirai.publishing.version ?: project.version.toString(),
|
||||
description = mirai.publishing.description ?: project.description,
|
||||
dependencies = dependencies
|
||||
)
|
||||
)
|
||||
|
||||
logger.info("Generated mirai plugin metadata json: $json")
|
||||
|
||||
output.writeText(json)
|
||||
fun getConfigurationsToInclude(): List<Configuration> {
|
||||
val compilation = target.compilations["main"]
|
||||
return compilation.relatedConfigurationNames.map { configurations[it] }
|
||||
}
|
||||
|
||||
Unit
|
||||
val dependencies = getConfigurationsToInclude().flatMap { it.allDependencies }.map {
|
||||
"${it.group}:${it.name}:${it.version}"
|
||||
}.distinct()
|
||||
|
||||
val json = Gson().toJson(
|
||||
PluginMetadata(
|
||||
metadataVersion = 1,
|
||||
groupId = mirai.publishing.groupId ?: project.group.toString(),
|
||||
artifactId = mirai.publishing.artifactId ?: project.name,
|
||||
version = mirai.publishing.version ?: project.version.toString(),
|
||||
description = mirai.publishing.description ?: project.description,
|
||||
dependencies = dependencies
|
||||
)
|
||||
)
|
||||
|
||||
logger.info("Generated mirai plugin metadata json: $json")
|
||||
|
||||
output.writeText(json)
|
||||
}
|
||||
|
||||
Unit
|
||||
}
|
||||
|
||||
// val bintrayUpload = tasks.getByName(BintrayUploadTask.getTASK_NAME()).dependsOn(
|
||||
// "buildPlugin".wrapNameWithPlatform(target, isSingleTarget),
|
||||
// generateMetadataTask,
|
||||
@ -147,41 +125,6 @@ private fun Project.registerPublishPluginTasks(target: KotlinTarget, isSingleTar
|
||||
// }
|
||||
}
|
||||
|
||||
internal inline fun File.renamed(block: File.(nameWithoutExtension: String) -> String): File =
|
||||
this.resolveSibling(block(this, nameWithoutExtension))
|
||||
|
||||
private fun Project.registerBintrayPublish() {
|
||||
val mirai = miraiExtension
|
||||
|
||||
// bintray {
|
||||
// user = mirai.publishing.user ?: findPropertySmartOrFail("bintray.user")
|
||||
// key = mirai.publishing.key ?: findPropertySmartOrFail("bintray.key")
|
||||
//
|
||||
// val targets = kotlinJvmOrAndroidTargets
|
||||
// if (targets.size == 1) {
|
||||
// setPublications("mavenJava")
|
||||
// } else {
|
||||
// setPublications(*targets.map { "mavenJava".wrapNameWithPlatform(it, false) }.toTypedArray())
|
||||
// }
|
||||
//
|
||||
// setConfigurations("archives")
|
||||
//
|
||||
// publish = mirai.publishing.publish
|
||||
// override = mirai.publishing.override
|
||||
//
|
||||
// pkg.apply {
|
||||
// repo = mirai.publishing.repo ?: findPropertySmartOrFail("bintray.repo")
|
||||
// name = mirai.publishing.packageName ?: findPropertySmartOrFail("bintray.package")
|
||||
// userOrg = mirai.publishing.org ?: findPropertySmart("bintray.org")
|
||||
// desc = mirai.publishing.description ?: project.description
|
||||
//
|
||||
// mirai.publishing.bintrayPackageConfigConfigs.forEach { it.invoke(this) }
|
||||
// }
|
||||
//
|
||||
// mirai.publishing.bintrayConfigs.forEach { it.invoke(this) }
|
||||
// }
|
||||
}
|
||||
|
||||
private fun Project.registerMavenPublications(target: KotlinTarget, isSingleTarget: Boolean) {
|
||||
val mirai = miraiExtension
|
||||
|
||||
@ -241,7 +184,6 @@ private fun Project.registerMavenPublications(target: KotlinTarget, isSingleTarg
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PublishedApi
|
||||
internal val Project.sourceSets: org.gradle.api.tasks.SourceSetContainer
|
||||
get() = (this as org.gradle.api.plugins.ExtensionAware).extensions.getByName("sourceSets") as org.gradle.api.tasks.SourceSetContainer
|
||||
|
@ -18,7 +18,6 @@ import net.mamoe.mirai.contact.announcement.Announcement
|
||||
import net.mamoe.mirai.contact.announcement.AnnouncementImage
|
||||
import net.mamoe.mirai.contact.announcement.OnlineAnnouncement
|
||||
import net.mamoe.mirai.contact.isOperator
|
||||
import net.mamoe.mirai.event.events.GroupEntranceAnnouncementChangeEvent
|
||||
import net.mamoe.mirai.mock.contact.announcement.MockAnnouncements
|
||||
import net.mamoe.mirai.mock.contact.announcement.MockOnlineAnnouncement
|
||||
import net.mamoe.mirai.mock.contact.announcement.copy
|
||||
@ -45,21 +44,21 @@ internal class MockAnnouncementsImpl(
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
internal fun putDirect(announcement: MockOnlineAnnouncement) {
|
||||
val annoc = if (announcement.fid.isEmpty()) {
|
||||
val ann = if (announcement.fid.isEmpty()) {
|
||||
announcement.copy(fid = UUID.randomUUID().toString())
|
||||
} else announcement
|
||||
if (annoc.parameters.sendToNewMember) {
|
||||
if (ann.parameters.sendToNewMember) {
|
||||
announcements.entries.removeIf { (_, v) -> v.parameters.sendToNewMember }
|
||||
}
|
||||
announcements[annoc.fid] = annoc
|
||||
annoc.group = group
|
||||
announcements[ann.fid] = ann
|
||||
ann.group = group
|
||||
}
|
||||
|
||||
override fun mockPublish(announcement: Announcement, actor: NormalMember, events: Boolean): OnlineAnnouncement {
|
||||
val old = if (announcement.parameters.sendToNewMember)
|
||||
announcements.elements().toList().firstOrNull { oa -> oa.parameters.sendToNewMember }
|
||||
else null
|
||||
val onac = MockOnlineAnnouncement(
|
||||
val ann = MockOnlineAnnouncement(
|
||||
content = announcement.content,
|
||||
parameters = announcement.parameters,
|
||||
senderId = actor.id,
|
||||
@ -68,19 +67,19 @@ internal class MockAnnouncementsImpl(
|
||||
confirmedMembersCount = 0,
|
||||
publicationTime = currentTimeSeconds()
|
||||
)
|
||||
putDirect(onac)
|
||||
if (!events) return onac
|
||||
putDirect(ann)
|
||||
if (!events) return ann
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
GroupEntranceAnnouncementChangeEvent(
|
||||
net.mamoe.mirai.event.events.GroupEntranceAnnouncementChangeEvent(
|
||||
origin = old?.content.orEmpty(),
|
||||
new = onac.content,
|
||||
new = ann.content,
|
||||
group = group,
|
||||
operator = actor.takeUnless { it.id == group.bot.id }
|
||||
).broadcastBlocking()
|
||||
|
||||
// TODO: mirai-core no other events about announcements
|
||||
return onac
|
||||
return ann
|
||||
}
|
||||
|
||||
override suspend fun publish(announcement: Announcement): OnlineAnnouncement {
|
||||
|
@ -62,6 +62,7 @@ internal class MockAnonymousMemberImpl(
|
||||
override suspend fun uploadImage(resource: ExternalResource): Image =
|
||||
super<AbstractMockContact>.uploadImage(resource)
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
override var permission: MemberPermission
|
||||
get() = MemberPermission.MEMBER
|
||||
set(value) {
|
||||
|
@ -64,7 +64,7 @@ internal suspend fun ExternalResource.mockUploadAudio(bot: MockBot) = inResource
|
||||
internal suspend fun ExternalResource.mockUploadVoice(bot: MockBot) = kotlin.run {
|
||||
val md5 = this.md5
|
||||
val size = this.size
|
||||
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
net.mamoe.mirai.message.data.Voice(
|
||||
fileName = md5.toUHexString() + ".amr",
|
||||
md5 = md5,
|
||||
|
@ -101,7 +101,8 @@ internal class MockGroupTest : MockBotTestBase() {
|
||||
)
|
||||
}.let { events ->
|
||||
assertEquals(2, events.size)
|
||||
assertIsInstance<GroupEntranceAnnouncementChangeEvent>(events[0])
|
||||
@Suppress("RemoveRedundantQualifierName", "DEPRECATION")
|
||||
assertIsInstance<net.mamoe.mirai.event.events.GroupEntranceAnnouncementChangeEvent>(events[0])
|
||||
}
|
||||
val anc = group.announcements.asFlow().toList()
|
||||
assertEquals(1, anc.size)
|
||||
|
@ -19,12 +19,13 @@ import platform.posix.*
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
@OptIn(UnsafeNumber::class)
|
||||
public actual fun currentTimeMillis(): Long {
|
||||
// Do not use getTimeMillis from stdlib, it doesn't support iosSimulatorArm64
|
||||
memScoped {
|
||||
val spec = alloc<timespec>()
|
||||
clock_gettime(CLOCK_REALTIME.convert(), spec.ptr)
|
||||
return (spec.tv_sec * 1000 + spec.tv_nsec / 1e6).toLong()
|
||||
return (spec.tv_sec * 1000 + spec.tv_nsec.convert<Long>() / 1e6).toLong()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
internal inline fun FriendGroup.impl(): FriendGroupImpl {
|
||||
internal fun FriendGroup.impl(): FriendGroupImpl {
|
||||
contract {
|
||||
returns() implies (this@impl is FriendGroupImpl)
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ package net.mamoe.mirai.internal.message.protocol.impl
|
||||
|
||||
import net.mamoe.mirai.contact.AnonymousMember
|
||||
import net.mamoe.mirai.contact.Group
|
||||
import net.mamoe.mirai.internal.message.MessageSourceSerializerImpl
|
||||
import net.mamoe.mirai.internal.message.protocol.MessageProtocol
|
||||
import net.mamoe.mirai.internal.message.protocol.ProcessorCollector
|
||||
import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder
|
||||
@ -39,7 +38,6 @@ internal class QuoteReplyProtocol : MessageProtocol(PRIORITY_METADATA) {
|
||||
currentMessageChain[QuoteReply]?.source?.ensureSequenceIdAvailable()
|
||||
})
|
||||
|
||||
val baseSourceSerializer = MessageSourceSerializerImpl(MessageSource.SERIAL_NAME)
|
||||
MessageSerializer.superclassesScope(MessageSource::class, MessageMetadata::class, SingleMessage::class) {
|
||||
add(
|
||||
MessageSerializer(
|
||||
|
@ -20,8 +20,8 @@ import net.mamoe.mirai.internal.test.AbstractTest
|
||||
import net.mamoe.mirai.message.MessageSerializers
|
||||
import net.mamoe.mirai.message.data.*
|
||||
import net.mamoe.mirai.utils.cast
|
||||
import net.mamoe.mirai.utils.structureToString
|
||||
import net.mamoe.mirai.utils.mapToByteArray
|
||||
import net.mamoe.mirai.utils.structureToString
|
||||
import kotlin.test.*
|
||||
|
||||
internal class MessageSerializationTest : AbstractTest() {
|
||||
@ -143,7 +143,6 @@ internal class MessageSerializationTest : AbstractTest() {
|
||||
assertEquals(element2["width"]?.jsonPrimitive?.int, image2.width)
|
||||
assertEquals(element2["height"]?.jsonPrimitive?.int, image2.height)
|
||||
val decoded: Image = string2.deserialize()
|
||||
decoded as Image
|
||||
assertEquals(decoded.imageId, image2.imageId)
|
||||
assertEquals(decoded.imageType, image2.imageType)
|
||||
assertEquals(decoded.width, image2.width)
|
||||
@ -252,11 +251,6 @@ internal class MessageSerializationTest : AbstractTest() {
|
||||
)
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class V(
|
||||
val msg: Audio
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class AudioTestStandard(
|
||||
val online: OnlineAudio,
|
||||
|
Loading…
Reference in New Issue
Block a user