forked from mamoe/mirai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMusicShare.kt
156 lines (142 loc) · 4.38 KB
/
MusicShare.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* Copyright 2020 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:Suppress("unused")
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.message.code.internal.appendStringAsMiraiCode
import net.mamoe.mirai.utils.MiraiExperimentalApi
import net.mamoe.mirai.utils.MiraiInternalApi
import net.mamoe.mirai.utils.safeCast
/**
* QQ 互联通道音乐分享
*
* @since 2.1
*/
@Serializable
@SerialName(MusicShare.SERIAL_NAME)
public data class MusicShare(
/**
* 音乐应用类型
*/
public val kind: MusicKind, // 'type' is reserved by serialization
/**
* 消息卡片标题
*/
public val title: String,
/**
* 消息卡片内容
*/
public val summary: String,
/**
* 点击卡片跳转网页 URL
*/
public val jumpUrl: String,
/**
* 消息卡片图片 URL
*/
public val pictureUrl: String,
/**
* 音乐文件 URL
*/
public val musicUrl: String,
/**
* 在消息列表显示
*/
public val brief: String,
) : MessageContent, ConstrainSingle, CodableMessage {
public constructor(
/**
* 音乐应用类型
*/
kind: MusicKind,
/**
* 消息卡片标题
*/
title: String,
/**
* 消息卡片内容
*/
summary: String,
/**
* 点击卡片跳转网页 URL
*/
jumpUrl: String,
/**
* 消息卡片图片 URL
*/
pictureUrl: String,
/**
* 音乐文件 URL
*/
musicUrl: String,
) : this(kind, title, summary, jumpUrl, pictureUrl, musicUrl, "[分享]$title")
// kotlinx serialization doesn't support default arguments.
override val key: MessageKey<*> get() = Key
override fun contentToString(): String =
brief.takeIf { it.isNotBlank() } ?: "[分享]$title" // empty content is not accepted by `sendMessage`
override fun appendMiraiCodeTo(builder: StringBuilder) {
builder.append("[mirai:musicshare:")
.append(kind.name)
.append(',').appendStringAsMiraiCode(title)
.append(',').appendStringAsMiraiCode(summary)
.append(',').appendStringAsMiraiCode(jumpUrl)
.append(',').appendStringAsMiraiCode(pictureUrl)
.append(',').appendStringAsMiraiCode(musicUrl)
.append(',').appendStringAsMiraiCode(brief)
.append(']')
}
// MusicShare(type=NeteaseCloudMusic, title='ファッション', summary='rinahamu/Yunomi', brief='', url='http://music.163.com/song/1338728297/?userid=324076307', pictureUrl='http://p2.music.126.net/y19E5SadGUmSR8SZxkrNtw==/109951163785855539.jpg', musicUrl='http://music.163.com/song/media/outer/url?id=1338728297&userid=324076307')
/**
* 注意, baseKey [MessageContent] 不稳定. 未来可能会有变更.
*/
public companion object Key :
AbstractPolymorphicMessageKey<@MiraiExperimentalApi MessageContent, MusicShare>
(MessageContent, { it.safeCast() }) {
/**
* @since 2.3
*/
public const val SERIAL_NAME: String = "MusicShare"
}
}
/**
* @see MusicShare.kind
* @since 2.1
*/
public enum class MusicKind constructor(
@MiraiInternalApi public val appId: Long,
@MiraiInternalApi public val platform: Int,
@MiraiInternalApi public val sdkVersion: String,
@MiraiInternalApi public val packageName: String,
@MiraiInternalApi public val signature: String
) {
NeteaseCloudMusic(
100495085,
1,
"0.0.0",
"com.netease.cloudmusic",
"da6b069da1e2982db3e386233f68d76d"
),
QQMusic(
100497308,
1,
"0.0.0",
"com.tencent.qqmusic",
"cbd27cd7c861227d013a25b2d10f0799"
),
MiguMusic(
1101053067,
1,
"0.0.0",
"cmccwm.mobilemusic",
"6cdc72a439cef99a3418d2a78aa28c73"
)
// add more? https://github.com/mamoe/mirai/issues/new/choose
}