1
1
/*
2
- * Copyright 2019-2021 Mamoe Technologies and contributors.
2
+ * Copyright 2019-2022 Mamoe Technologies and contributors.
3
3
*
4
- * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
5
- * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
4
+ * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
5
+ * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
6
6
*
7
- * https://github.com/mamoe/mirai/blob/master /LICENSE
7
+ * https://github.com/mamoe/mirai/blob/dev /LICENSE
8
8
*/
9
9
10
10
@file:Suppress(" INVISIBLE_MEMBER" , " INVISIBLE_REFERENCE" )
@@ -13,6 +13,7 @@ package net.mamoe.mirai.internal.contact
13
13
14
14
import net.mamoe.mirai.Bot
15
15
import net.mamoe.mirai.contact.*
16
+ import net.mamoe.mirai.internal.message.FileMessageImpl
16
17
import net.mamoe.mirai.internal.message.LongMessageInternal
17
18
import net.mamoe.mirai.internal.utils.estimateLength
18
19
import net.mamoe.mirai.message.data.*
@@ -33,13 +34,6 @@ internal fun MessageChain.countImages(): Int = this.count { it is Image }
33
34
34
35
private val logger by lazy { MiraiLogger .Factory .create(SendMessageHandler ::class ) }
35
36
36
- // Fixme: Remove in the future, see #1715
37
- private val fileMessageWarningShown = object : ExceptionCollector () {
38
- override fun addSuppressed (receiver : Throwable , e : Throwable ) {
39
- }
40
- }
41
-
42
- // Fixme: Remove in the future, see #1715
43
37
private val ALLOW_SENDING_FILE_MESSAGE = systemProp(" mirai.message.allow.sending.file.message" , false )
44
38
45
39
internal fun Message.verifySendingValid () {
@@ -49,26 +43,14 @@ internal fun Message.verifySendingValid() {
49
43
this .forEach { it.verifySendingValid() }
50
44
}
51
45
is FileMessage -> {
52
- // Fixme: https://github.com/mamoe/mirai/issues/1715
53
-
54
- if (! ALLOW_SENDING_FILE_MESSAGE ) {
55
- val e =
56
- Exception (" This stacktrace might help you find your code causing this problem. It is shown once for each distinct line." )
57
- val log =
58
- " Sending FileMessage manually is error-prone and is planned to be prohibited in the future. " +
59
- " Please use AbsoluteFolder.uploadNewFile (recommended) or RemoteFile.uploadAndSend instead (deprecated)." +
60
- " You can add JVM argument '-Dmirai.message.allow.sending.file.message=true' to ignore this warning, " +
61
- " however, your code might not work in the future."
62
-
63
- // Show stacktrace for each call only once.
64
- if (fileMessageWarningShown.collect(e)) {
65
- logger.warning(log, e)
66
- } else {
67
- logger.warning(log)
68
- }
46
+ if (! ALLOW_SENDING_FILE_MESSAGE ) { // #1715
47
+ if (this !is FileMessageImpl ) error(" Customized FileMessage cannot be send" )
48
+ if (! this .allowSend) error(
49
+ " Sending FileMessage is not allowed, as it may cause unexpected results. " +
50
+ " Add JVM argument `-Dmirai.message.allow.sending.file.message=true` to disable this check. " +
51
+ " Do this only for compatibility!"
52
+ )
69
53
}
70
-
71
- // fail("Sending FileMessage is not in support")
72
54
}
73
55
}
74
56
}
0 commit comments