forked from mamoe/mirai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAtAll.kt
60 lines (51 loc) · 1.86 KB
/
AtAll.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
@file:JvmMultifileClass
@file:JvmName("MessageUtils")
@file:Suppress("MemberVisibilityCanBePrivate")
package net.mamoe.mirai.message.data
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import net.mamoe.mirai.message.code.CodableMessage
import net.mamoe.mirai.utils.MiraiExperimentalApi
/**
* "@全体成员".
*
* 非会员每天只能发送 10 次 [AtAll]. 超出部分会被以普通文字看待.
*
* ## mirai 码支持
* 格式: [mirai:atall]
*
* @see At at 单个群成员
*/
@SerialName(AtAll.SERIAL_NAME)
@Serializable
public object AtAll :
MessageContent, CodableMessage {
public const val display: String = "@全体成员"
public const val SERIAL_NAME: String = "AtAll"
@Suppress("SpellCheckingInspection")
override fun contentToString(): String = display
override fun toString(): String = "[mirai:atall]"
override fun serializeToMiraiCode(): String = toString()
override fun hashCode(): Int = display.hashCode()
override fun equals(other: Any?): Boolean = other === this
@MiraiExperimentalApi
override fun appendMiraiCodeTo(builder: StringBuilder) {
builder.append(toString())
}
// 自动为消息补充 " "
@JvmSynthetic
public override fun followedBy(tail: Message): MessageChain {
if (tail is PlainText && tail.content.startsWith(' ')) {
return super<MessageContent>.followedBy(tail)
}
return super<MessageContent>.followedBy(PlainText(" ")) + tail
}
}