Skip to content

Commit 172a1a1

Browse files
add music/playlist/album/dj/djmusic send comment and like/floors/reply/unlike/delete comment
1 parent 089d915 commit 172a1a1

File tree

9 files changed

+311
-64
lines changed

9 files changed

+311
-64
lines changed

src/main/java/fengliu/cloudmusic/command/MusicCommand.java

+176-34
Large diffs are not rendered by default.

src/main/java/fengliu/cloudmusic/music163/ICanComment.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,34 @@
1313
import java.util.Map;
1414

1515
public interface ICanComment {
16-
ApiPage getComments(boolean hot);
16+
String getThreadId();
1717

18-
default ApiPage comments(HttpClient api, long id, String threadId, boolean hot) {
18+
HttpClient getApi();
19+
20+
default void send(String content) {
21+
Map<String, Object> data = new HashMap<String, Object>();
22+
data.put("threadId", this.getThreadId());
23+
data.put("content", content);
24+
25+
this.getApi().POST_API("/api/resource/comments/add", data);
26+
}
27+
28+
default ApiPage comments(boolean hot) {
1929
Map<String, Object> data = new HashMap<String, Object>();
20-
data.put("rid", id);
30+
data.put("rid", this.getThreadId().split("_")[3]);
2131
data.put("limit", 24);
2232

33+
String threadId = this.getThreadId();
2334
String path = "/api/v1/resource/%s/%s".formatted(hot ? "hotcomments" : "comments", threadId);
24-
JsonObject json = api.POST_API(path, data);
35+
JsonObject json = this.getApi().POST_API(path, data);
2536

2637
int total = json.get("total").getAsInt();
2738
if (total == 0) {
2839
throw new ActionException(Text.translatable("cloudmusic.exception.not%scomments".formatted(hot ? ".hot." : ".")));
2940
}
3041

3142
String arrayKey = hot ? "hotComments" : "comments";
32-
return new ApiPage(json.getAsJsonArray(arrayKey), json.get("total").getAsInt(), path, api, data) {
43+
return new ApiPage(json.getAsJsonArray(arrayKey), json.get("total").getAsInt(), path, this.getApi(), data) {
3344
@Override
3445
protected JsonArray getNewPageDataJsonArray(JsonObject result) {
3546
return result.getAsJsonArray(arrayKey);

src/main/java/fengliu/cloudmusic/music163/data/Album.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import fengliu.cloudmusic.util.HttpClient;
88
import fengliu.cloudmusic.util.IdUtil;
99
import fengliu.cloudmusic.util.TextClickItem;
10-
import fengliu.cloudmusic.util.page.ApiPage;
1110
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
1211
import net.minecraft.text.Text;
1312
import net.minecraft.util.Formatting;
@@ -52,8 +51,13 @@ public Album(HttpClient api, JsonObject album) {
5251
}
5352

5453
@Override
55-
public ApiPage getComments(boolean hot) {
56-
return this.comments(this.api, this.id, this.threadId, hot);
54+
public String getThreadId() {
55+
return this.threadId;
56+
}
57+
58+
@Override
59+
public HttpClient getApi() {
60+
return this.api;
5761
}
5862

5963
@Override
@@ -102,6 +106,7 @@ public void printToChatHud(FabricClientCommandSource source) {
102106

103107
source.sendFeedback(TextClickItem.combine(
104108
new TextClickItem("play", "/cloudmusic album play " + this.id),
109+
new TextClickItem("send.comment", "/cloudmusic album send comment " + this.id),
105110
new TextClickItem("hot.comment", "/cloudmusic album hotComment " + this.id),
106111
new TextClickItem("comment", "/cloudmusic album comment " + this.id),
107112
new TextClickItem("subscribe", "/cloudmusic album subscribe " + this.id),

src/main/java/fengliu/cloudmusic/music163/data/Comment.java

+59-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import fengliu.cloudmusic.util.page.ApiPage;
1212
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
1313
import net.minecraft.text.Text;
14+
import net.minecraft.util.Formatting;
1415

1516
import java.util.HashMap;
1617
import java.util.Map;
@@ -34,7 +35,7 @@ public class Comment extends Music163Obj implements IPrint {
3435
*/
3536
public Comment(HttpClient api, JsonObject data, String threadId) {
3637
super(api, data);
37-
this.id = data.get("commentId").getAsLong();
38+
this.id = data.has("commentId") ? data.get("commentId").getAsLong() : data.get("beRepliedCommentId").getAsLong();
3839
this.threadId = threadId;
3940
this.content = data.get("content").getAsString();
4041
this.time = data.get("time").getAsLong();
@@ -47,22 +48,22 @@ public Comment(HttpClient api, JsonObject data, String threadId) {
4748

4849
public ApiPage floors() {
4950
String threadId = this.threadId;
50-
Map<String, Object> data = new HashMap<String, Object>();
51+
Map<String, Object> data = new HashMap<>();
5152
data.put("parentCommentId", this.id);
5253
data.put("threadId", threadId);
5354
data.put("limit", 24);
5455

5556
JsonObject json = api.POST_API("/api/resource/comment/floor/get", data);
5657

57-
int total = json.get("total").getAsInt();
58+
int total = json.getAsJsonObject("data").get("totalCount").getAsInt();
5859
if (total == 0) {
59-
throw new ActionException(Text.translatable("cloudmusic.exception.not.hot.comments"));
60+
throw new ActionException(Text.translatable("cloudmusic.exception.not.comment.floors"));
6061
}
6162

62-
return new ApiPage(json.getAsJsonArray("comments"), json.get("total").getAsInt(), "/api/resource/comment/floor/get", api, data) {
63+
return new ApiPage(json.getAsJsonObject("data").getAsJsonArray("comments"), total, "/api/resource/comment/floor/get", api, data) {
6364
@Override
6465
protected JsonArray getNewPageDataJsonArray(JsonObject result) {
65-
return result.getAsJsonArray("comments");
66+
return result.getAsJsonObject("data").getAsJsonArray("comments");
6667
}
6768

6869
@Override
@@ -98,15 +99,65 @@ public String getPageItem() {
9899
this.content, Text.translatable("cloudmusic.page.item.comments.like", this.likedCount).getString(), this.id);
99100
}
100101

102+
public void reply(String content) {
103+
Map<String, Object> data = new HashMap<>();
104+
data.put("threadId", this.threadId);
105+
data.put("commentId", this.id);
106+
data.put("content", content);
107+
108+
this.api.POST_API("/api/resource/comments/reply", data);
109+
}
110+
111+
protected void like(boolean _in) {
112+
Map<String, Object> data = new HashMap<>();
113+
data.put("threadId", this.threadId);
114+
data.put("commentId", this.id);
115+
116+
this.api.POST_API("/api/v1/comment/" + (_in ? "like" : "unlike"), data);
117+
}
118+
119+
public void like() {
120+
this.like(true);
121+
}
122+
123+
public void unlike() {
124+
this.like(false);
125+
}
126+
127+
public void delete() {
128+
Map<String, Object> data = new HashMap<>();
129+
data.put("threadId", this.threadId);
130+
data.put("commentId", this.id);
131+
132+
this.api.POST_API("/api/resource/comments/delete", data);
133+
}
134+
101135
@Override
102136
public void printToChatHud(FabricClientCommandSource source) {
103137
if (!this.beReplied.isEmpty()) {
138+
// source.sendFeedback(new TextClickItem(
139+
// (MutableText) this.getBeContent(),
140+
// Text.translatable(IdUtil.getShowInfo("page.comment")),
141+
// "/cloudmusic comment %s %s".formatted(this.beReplied.get(0).getAsJsonObject().get("beRepliedCommentId").getAsLong(), this.threadId)
142+
// ).build());
104143
source.sendFeedback(this.getBeContent());
105-
source.sendFeedback(Text.literal(""));
144+
source.sendFeedback(Text.literal("========================").formatted(Formatting.GRAY));
106145
}
107146

108-
source.sendFeedback(Text.literal("%s - %s: %s".formatted(this.user.get("nickname").getAsString(), this.ipLocation.get("location").getAsString(), this.content)));
147+
source.sendFeedback(new TextClickItem(
148+
Text.literal("%s - %s: %s".formatted(this.user.get("nickname").getAsString(), this.ipLocation.get("location").getAsString(), this.content)),
149+
Text.translatable(IdUtil.getShowInfo("comment.user")),
150+
"/cloudmusic user " + this.user.get("userId").getAsLong()
151+
).build());
109152
source.sendFeedback(Text.translatable("cloudmusic.info.comment.time", this.timeStr));
110153
source.sendFeedback(Text.translatable("cloudmusic.page.item.comments.like", this.likedCount));
154+
155+
source.sendFeedback(TextClickItem.combine(
156+
new TextClickItem("comment.floors", "/cloudmusic comment floors %s %s".formatted(id, this.threadId)),
157+
new TextClickItem("comment.reply", "/cloudmusic comment reply %s %s".formatted(id, this.threadId)),
158+
new TextClickItem("comment.like", "/cloudmusic comment like %s %s".formatted(id, this.threadId)),
159+
new TextClickItem("comment.unlike", "/cloudmusic comment unlike %s %s".formatted(id, this.threadId)),
160+
new TextClickItem("comment.delete", "/cloudmusic comment delete %s %s".formatted(id, this.threadId))
161+
));
111162
}
112163
}

src/main/java/fengliu/cloudmusic/music163/data/DjMusic.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import fengliu.cloudmusic.music163.*;
66
import fengliu.cloudmusic.util.HttpClient;
77
import fengliu.cloudmusic.util.TextClickItem;
8-
import fengliu.cloudmusic.util.page.ApiPage;
98
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
109
import net.minecraft.text.Text;
1110

@@ -90,8 +89,13 @@ public long getDuration() {
9089
}
9190

9291
@Override
93-
public ApiPage getComments(boolean hot) {
94-
return this.comments(this.api, this.id, this.threadId, hot);
92+
public String getThreadId() {
93+
return this.threadId;
94+
}
95+
96+
@Override
97+
public HttpClient getApi() {
98+
return this.api;
9599
}
96100

97101
@Override
@@ -126,6 +130,7 @@ public void printToChatHud(FabricClientCommandSource source) {
126130

127131
source.sendFeedback(TextClickItem.combine(
128132
new TextClickItem("play", "/cloudmusic dj music play " + this.id),
133+
new TextClickItem("send.comment", "/cloudmusic dj music send comment " + this.id),
129134
new TextClickItem("hot.comment", "/cloudmusic dj music hotComment " + this.id),
130135
new TextClickItem("comment", "/cloudmusic dj music comment " + this.id),
131136
new TextClickItem("shar", Shares.DJ_MUSIC.getShar(this.id))

src/main/java/fengliu/cloudmusic/music163/data/DjRadio.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import fengliu.cloudmusic.util.IdUtil;
1212
import fengliu.cloudmusic.util.MusicPlayer;
1313
import fengliu.cloudmusic.util.TextClickItem;
14-
import fengliu.cloudmusic.util.page.ApiPage;
1514
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
1615
import net.minecraft.text.Text;
1716
import net.minecraft.util.Formatting;
@@ -89,8 +88,13 @@ public void run() {
8988
}
9089

9190
@Override
92-
public ApiPage getComments(boolean hot) {
93-
return this.comments(this.api, this.id, this.threadId, hot);
91+
public String getThreadId() {
92+
return this.threadId;
93+
}
94+
95+
@Override
96+
public HttpClient getApi() {
97+
return this.api;
9498
}
9599

96100
@Override
@@ -149,6 +153,7 @@ public void printToChatHud(FabricClientCommandSource source) {
149153

150154
source.sendFeedback(TextClickItem.combine(
151155
new TextClickItem("play", "/cloudmusic dj play " + this.id),
156+
new TextClickItem("send.comment", "/cloudmusic dj send comment " + this.id),
152157
new TextClickItem("hot.comment", "/cloudmusic dj hotComment " + this.id),
153158
new TextClickItem("comment", "/cloudmusic dj comment " + this.id),
154159
new TextClickItem("subscribe", "/cloudmusic dj subscribe " + this.id),

src/main/java/fengliu/cloudmusic/music163/data/Music.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import fengliu.cloudmusic.util.HttpClient;
99
import fengliu.cloudmusic.util.IdUtil;
1010
import fengliu.cloudmusic.util.TextClickItem;
11-
import fengliu.cloudmusic.util.page.ApiPage;
1211
import fengliu.cloudmusic.util.page.Page;
1312
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
1413
import net.minecraft.text.Text;
@@ -237,8 +236,13 @@ public long getDuration() {
237236
}
238237

239238
@Override
240-
public ApiPage getComments(boolean hot) {
241-
return this.comments(this.api, this.id, this.threadId, hot);
239+
public String getThreadId() {
240+
return this.threadId;
241+
}
242+
243+
@Override
244+
public HttpClient getApi() {
245+
return this.api;
242246
}
243247

244248
@Override
@@ -287,6 +291,7 @@ public void printToChatHud(FabricClientCommandSource source) {
287291
));
288292

289293
source.sendFeedback(TextClickItem.combine(
294+
new TextClickItem("send.comment", "/cloudmusic music send comment " + this.id),
290295
new TextClickItem("hot.comment", "/cloudmusic music hotComment " + this.id),
291296
new TextClickItem("comment", "/cloudmusic music comment " + this.id),
292297
new TextClickItem("playlist.add", "/cloudmusic my playlist add " + this.id),

src/main/java/fengliu/cloudmusic/music163/data/PlayList.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import fengliu.cloudmusic.util.HttpClient;
88
import fengliu.cloudmusic.util.IdUtil;
99
import fengliu.cloudmusic.util.TextClickItem;
10-
import fengliu.cloudmusic.util.page.ApiPage;
1110
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
1211
import net.minecraft.text.Text;
1312
import net.minecraft.util.Formatting;
@@ -99,8 +98,13 @@ public List<IMusic> getMusics(){
9998
}
10099

101100
@Override
102-
public ApiPage getComments(boolean hot) {
103-
return this.comments(this.api, this.id, this.threadId, hot);
101+
public String getThreadId() {
102+
return this.threadId;
103+
}
104+
105+
@Override
106+
public HttpClient getApi() {
107+
return this.api;
104108
}
105109

106110
@Override
@@ -145,6 +149,7 @@ public void printToChatHud(FabricClientCommandSource source) {
145149

146150
source.sendFeedback(TextClickItem.combine(
147151
new TextClickItem("play", "/cloudmusic playlist play " + this.id),
152+
new TextClickItem("send.comment", "/cloudmusic playlist send comment " + this.id),
148153
new TextClickItem("hot.comment", "/cloudmusic playlist hotComment " + this.id),
149154
new TextClickItem("comment", "/cloudmusic playlist comment " + this.id),
150155
new TextClickItem("subscribe", "/cloudmusic playlist subscribe " + this.id),

src/main/resources/assets/cloudmusic/lang/zh_cn.json

+20-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"cloudmusic.help.music.similar.playlist": "获取歌曲相似歌单 /cloudmusic music similar playlist [id]",
88
"cloudmusic.help.music.comment": "获取歌曲评论 /cloudmusic music comment [id]",
99
"cloudmusic.help.music.hot.comment": "获取歌曲热评 /cloudmusic music hotComment [id]",
10+
"cloudmusic.help.music.send.comment": "向歌曲发送评论 /cloudmusic music send comment [threadId] [content]",
1011
"cloudmusic.help.playlist": "获取歌单 /cloudmusic playlist [id]",
1112
"cloudmusic.help.playlist.play": "播放歌单 /cloudmusic music playlist [id]",
1213
"cloudmusic.help.playlist.subscribe": "收藏歌单 /cloudmusic playlist subscribe [id]",
@@ -15,6 +16,7 @@
1516
"cloudmusic.help.playlist.del": "歌单删除歌曲 /cloudmusic playlist del [id] [歌曲 id]",
1617
"cloudmusic.help.playlist.comment": "获取歌单评论 /cloudmusic playlist comment [id]",
1718
"cloudmusic.help.playlist.hot.comment": "获取歌单热评 /cloudmusic playlist hotComment [id]",
19+
"cloudmusic.help.playlist.send.comment": "向歌单发送评论 /cloudmusic playlist send comment [threadId] [content]",
1820
"cloudmusic.help.artist": "获取歌手 /cloudmusic artist [id]",
1921
"cloudmusic.help.artist.top": "播放歌手热门 50 首 /cloudmusic artist top [id]",
2022
"cloudmusic.help.artist.album": "查看歌手所有专辑 /cloudmusic artist album [id]",
@@ -27,12 +29,15 @@
2729
"cloudmusic.help.album.unsubscribe": "取消收藏专辑 /cloudmusic album unsubscribe [id]",
2830
"cloudmusic.help.album.comment": "获取专辑评论 /cloudmusic album comment [id]",
2931
"cloudmusic.help.album.hot.comment": "获取专辑热评 /cloudmusic album hotComment [id]",
32+
"cloudmusic.help.album.send.comment": "向专辑发送评论 /cloudmusic album send comment [threadId] [content]",
3033
"cloudmusic.help.dj": "获取电台 /cloudmusic dj [id]",
3134
"cloudmusic.help.dj.play": "播放电台 /cloudmusic dj play [id]",
35+
"cloudmusic.help.dj.send.comment": "向电台发送评论 /cloudmusic dj send comment [threadId] [content]",
3236
"cloudmusic.help.dj.music": "获取电台节目 /cloudmusic dj music [id]",
3337
"cloudmusic.help.dj.music.play": "播放电台节目 /cloudmusic dj music play [id]",
3438
"cloudmusic.help.dj.music.comment": "获取电台节目评论 /cloudmusic dj music comment [id]",
3539
"cloudmusic.help.dj.music.hot.comment": "获取电台节目热评 /cloudmusic dj hotComment [id]",
40+
"cloudmusic.help.dj.send.comment": "向电台节目发送评论 /cloudmusic dj music send comment [threadId] [content]",
3641
"cloudmusic.help.dj.subscribe": "收藏电台 /cloudmusic dj subscribe [id]",
3742
"cloudmusic.help.dj.unsubscribe": "取消收藏电台 /cloudmusic dj unsubscribe [id]",
3843
"cloudmusic.help.dj.comment": "获取电台评论 /cloudmusic dj comment [id]",
@@ -195,9 +200,12 @@
195200
"cloudmusic.info.page.dj.radio.comments": "电台 %s 的评论",
196201
"cloudmusic.info.page.dj.radio.hot.comments": "电台 %s 的热论",
197202
"cloudmusic.info.page.dj.music.comments": "电台节目 %s 的评论",
198-
"cloudmusic.info.page.dj.music.hot.comments": "电台节目 %s 的热论",
203+
"cloudmusic.info.page.dj.music.hot.comments": "评论的子评论",
204+
"cloudmusic.info.page.comment.floors": "电台节目 %s 的热论",
199205
"cloudmusic.page.item.comments.like": "点赞数: %s",
200-
"cloudmusic.info.comment.be.replied": "§b回复 %s - %s§r§7: %s",
206+
"cloudmusic.info.comment.be.replied": "§b回复 §b%s - %s§r§7: %s",
207+
"cloudmusic.info.comment.user.show": "点击查看发送评论用户",
208+
"cloudmusic.info.comment.time": "发送时间: %s",
201209
"cloudmusic.info.page.comment.null": "该评论已删除",
202210
"cloudmusic.info.page.comment.err.null": "该评论涉及违规内容,经举报已被屏蔽",
203211
"cloudmusic.info.page.help": "CloudMusic 帮助",
@@ -230,6 +238,11 @@
230238
"cloudmusic.info.command.music.play": "播放 %s",
231239
"cloudmusic.info.command.trash": "将 %s 扔进垃圾桶",
232240
"cloudmusic.info.command.style.not.children": "曲风 %s - %s 没有子曲风",
241+
"cloudmusic.info.command.send.comment": "向资源 %s 发送了一条评论",
242+
"cloudmusic.info.command.comment.like": "点赞了评论 %s",
243+
"cloudmusic.info.command.comment.unlike": "取消点赞了评论 %s",
244+
"cloudmusic.info.command.comment.delete": "删除了评论 %s",
245+
"cloudmusic.info.command.comment.reply": "回复了评论 %s",
233246
"cloudmusic.info.command.login": "成功登录至 %s",
234247
"cloudmusic.info.command.login.send.captcha": "成功向手机号发送验证码...",
235248
"cloudmusic.info.command.country.code": "设置手机号国家码为 %s...",
@@ -282,6 +295,8 @@
282295
"cloudmusic.options.style.album.show": "点击查看该曲风的专辑",
283296
"cloudmusic.options.children.style": "[子曲风]",
284297
"cloudmusic.options.children.style.show": "点击查看曲风所有子类型",
298+
"cloudmusic.options.send.comment": "[发送回复]",
299+
"cloudmusic.options.send.comment.show": "点击并补充回复內容进行发送评论",
285300
"cloudmusic.options.hot.comment": "[热评]",
286301
"cloudmusic.options.hot.comment.show": "点击查看该资源热评",
287302
"cloudmusic.options.comment": "[评论]",
@@ -292,6 +307,8 @@
292307
"cloudmusic.options.comment.reply.show": "点击并补充回复內容进行回复评论",
293308
"cloudmusic.options.comment.like": "[点赞]",
294309
"cloudmusic.options.comment.like.show": "点击点赞评论",
310+
"cloudmusic.options.comment.unlike": "[取消点赞]",
311+
"cloudmusic.options.comment.unlike.show": "点击取消点赞评论",
295312
"cloudmusic.options.comment.delete": "[删除]",
296313
"cloudmusic.options.comment.delete.show": "点击删除评论",
297314
"cloudmusic.options.page.prev": "[上一页]",
@@ -317,6 +334,7 @@
317334
"cloudmusic.exception.http.download": "下载文件重试超出最大次数 %s 次, 错误: %s",
318335
"cloudmusic.exception.not.comments": "该资源目前没有评论...",
319336
"cloudmusic.exception.not.hot.comments": "该资源目前没有热评...",
337+
"cloudmusic.exception.not.comment.floors": "该评论目前没有子评论...",
320338
"cloudmusic.play.quality.standard": "标准",
321339
"cloudmusic.play.quality.higher": "较高",
322340
"cloudmusic.play.quality.exhigh": "极高",

0 commit comments

Comments
 (0)