Skip to content

Commit

Permalink
add music/playlist/album/dj/djmusic send comment and like/floors/repl…
Browse files Browse the repository at this point in the history
…y/unlike/delete comment
  • Loading branch information
FengLiuFeseliud committed Jul 3, 2024
1 parent 089d915 commit 172a1a1
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 64 deletions.
210 changes: 176 additions & 34 deletions src/main/java/fengliu/cloudmusic/command/MusicCommand.java

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions src/main/java/fengliu/cloudmusic/music163/ICanComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,34 @@
import java.util.Map;

public interface ICanComment {
ApiPage getComments(boolean hot);
String getThreadId();

default ApiPage comments(HttpClient api, long id, String threadId, boolean hot) {
HttpClient getApi();

default void send(String content) {
Map<String, Object> data = new HashMap<String, Object>();
data.put("threadId", this.getThreadId());
data.put("content", content);

this.getApi().POST_API("/api/resource/comments/add", data);
}

default ApiPage comments(boolean hot) {
Map<String, Object> data = new HashMap<String, Object>();
data.put("rid", id);
data.put("rid", this.getThreadId().split("_")[3]);
data.put("limit", 24);

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

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

String arrayKey = hot ? "hotComments" : "comments";
return new ApiPage(json.getAsJsonArray(arrayKey), json.get("total").getAsInt(), path, api, data) {
return new ApiPage(json.getAsJsonArray(arrayKey), json.get("total").getAsInt(), path, this.getApi(), data) {
@Override
protected JsonArray getNewPageDataJsonArray(JsonObject result) {
return result.getAsJsonArray(arrayKey);
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/fengliu/cloudmusic/music163/data/Album.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import fengliu.cloudmusic.util.HttpClient;
import fengliu.cloudmusic.util.IdUtil;
import fengliu.cloudmusic.util.TextClickItem;
import fengliu.cloudmusic.util.page.ApiPage;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
Expand Down Expand Up @@ -52,8 +51,13 @@ public Album(HttpClient api, JsonObject album) {
}

@Override
public ApiPage getComments(boolean hot) {
return this.comments(this.api, this.id, this.threadId, hot);
public String getThreadId() {
return this.threadId;
}

@Override
public HttpClient getApi() {
return this.api;
}

@Override
Expand Down Expand Up @@ -102,6 +106,7 @@ public void printToChatHud(FabricClientCommandSource source) {

source.sendFeedback(TextClickItem.combine(
new TextClickItem("play", "/cloudmusic album play " + this.id),
new TextClickItem("send.comment", "/cloudmusic album send comment " + this.id),
new TextClickItem("hot.comment", "/cloudmusic album hotComment " + this.id),
new TextClickItem("comment", "/cloudmusic album comment " + this.id),
new TextClickItem("subscribe", "/cloudmusic album subscribe " + this.id),
Expand Down
67 changes: 59 additions & 8 deletions src/main/java/fengliu/cloudmusic/music163/data/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import fengliu.cloudmusic.util.page.ApiPage;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -34,7 +35,7 @@ public class Comment extends Music163Obj implements IPrint {
*/
public Comment(HttpClient api, JsonObject data, String threadId) {
super(api, data);
this.id = data.get("commentId").getAsLong();
this.id = data.has("commentId") ? data.get("commentId").getAsLong() : data.get("beRepliedCommentId").getAsLong();
this.threadId = threadId;
this.content = data.get("content").getAsString();
this.time = data.get("time").getAsLong();
Expand All @@ -47,22 +48,22 @@ public Comment(HttpClient api, JsonObject data, String threadId) {

public ApiPage floors() {
String threadId = this.threadId;
Map<String, Object> data = new HashMap<String, Object>();
Map<String, Object> data = new HashMap<>();
data.put("parentCommentId", this.id);
data.put("threadId", threadId);
data.put("limit", 24);

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

int total = json.get("total").getAsInt();
int total = json.getAsJsonObject("data").get("totalCount").getAsInt();
if (total == 0) {
throw new ActionException(Text.translatable("cloudmusic.exception.not.hot.comments"));
throw new ActionException(Text.translatable("cloudmusic.exception.not.comment.floors"));
}

return new ApiPage(json.getAsJsonArray("comments"), json.get("total").getAsInt(), "/api/resource/comment/floor/get", api, data) {
return new ApiPage(json.getAsJsonObject("data").getAsJsonArray("comments"), total, "/api/resource/comment/floor/get", api, data) {
@Override
protected JsonArray getNewPageDataJsonArray(JsonObject result) {
return result.getAsJsonArray("comments");
return result.getAsJsonObject("data").getAsJsonArray("comments");
}

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

public void reply(String content) {
Map<String, Object> data = new HashMap<>();
data.put("threadId", this.threadId);
data.put("commentId", this.id);
data.put("content", content);

this.api.POST_API("/api/resource/comments/reply", data);
}

protected void like(boolean _in) {
Map<String, Object> data = new HashMap<>();
data.put("threadId", this.threadId);
data.put("commentId", this.id);

this.api.POST_API("/api/v1/comment/" + (_in ? "like" : "unlike"), data);
}

public void like() {
this.like(true);
}

public void unlike() {
this.like(false);
}

public void delete() {
Map<String, Object> data = new HashMap<>();
data.put("threadId", this.threadId);
data.put("commentId", this.id);

this.api.POST_API("/api/resource/comments/delete", data);
}

@Override
public void printToChatHud(FabricClientCommandSource source) {
if (!this.beReplied.isEmpty()) {
// source.sendFeedback(new TextClickItem(
// (MutableText) this.getBeContent(),
// Text.translatable(IdUtil.getShowInfo("page.comment")),
// "/cloudmusic comment %s %s".formatted(this.beReplied.get(0).getAsJsonObject().get("beRepliedCommentId").getAsLong(), this.threadId)
// ).build());
source.sendFeedback(this.getBeContent());
source.sendFeedback(Text.literal(""));
source.sendFeedback(Text.literal("========================").formatted(Formatting.GRAY));
}

source.sendFeedback(Text.literal("%s - %s: %s".formatted(this.user.get("nickname").getAsString(), this.ipLocation.get("location").getAsString(), this.content)));
source.sendFeedback(new TextClickItem(
Text.literal("%s - %s: %s".formatted(this.user.get("nickname").getAsString(), this.ipLocation.get("location").getAsString(), this.content)),
Text.translatable(IdUtil.getShowInfo("comment.user")),
"/cloudmusic user " + this.user.get("userId").getAsLong()
).build());
source.sendFeedback(Text.translatable("cloudmusic.info.comment.time", this.timeStr));
source.sendFeedback(Text.translatable("cloudmusic.page.item.comments.like", this.likedCount));

source.sendFeedback(TextClickItem.combine(
new TextClickItem("comment.floors", "/cloudmusic comment floors %s %s".formatted(id, this.threadId)),
new TextClickItem("comment.reply", "/cloudmusic comment reply %s %s".formatted(id, this.threadId)),
new TextClickItem("comment.like", "/cloudmusic comment like %s %s".formatted(id, this.threadId)),
new TextClickItem("comment.unlike", "/cloudmusic comment unlike %s %s".formatted(id, this.threadId)),
new TextClickItem("comment.delete", "/cloudmusic comment delete %s %s".formatted(id, this.threadId))
));
}
}
11 changes: 8 additions & 3 deletions src/main/java/fengliu/cloudmusic/music163/data/DjMusic.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import fengliu.cloudmusic.music163.*;
import fengliu.cloudmusic.util.HttpClient;
import fengliu.cloudmusic.util.TextClickItem;
import fengliu.cloudmusic.util.page.ApiPage;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.text.Text;

Expand Down Expand Up @@ -90,8 +89,13 @@ public long getDuration() {
}

@Override
public ApiPage getComments(boolean hot) {
return this.comments(this.api, this.id, this.threadId, hot);
public String getThreadId() {
return this.threadId;
}

@Override
public HttpClient getApi() {
return this.api;
}

@Override
Expand Down Expand Up @@ -126,6 +130,7 @@ public void printToChatHud(FabricClientCommandSource source) {

source.sendFeedback(TextClickItem.combine(
new TextClickItem("play", "/cloudmusic dj music play " + this.id),
new TextClickItem("send.comment", "/cloudmusic dj music send comment " + this.id),
new TextClickItem("hot.comment", "/cloudmusic dj music hotComment " + this.id),
new TextClickItem("comment", "/cloudmusic dj music comment " + this.id),
new TextClickItem("shar", Shares.DJ_MUSIC.getShar(this.id))
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/fengliu/cloudmusic/music163/data/DjRadio.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import fengliu.cloudmusic.util.IdUtil;
import fengliu.cloudmusic.util.MusicPlayer;
import fengliu.cloudmusic.util.TextClickItem;
import fengliu.cloudmusic.util.page.ApiPage;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
Expand Down Expand Up @@ -89,8 +88,13 @@ public void run() {
}

@Override
public ApiPage getComments(boolean hot) {
return this.comments(this.api, this.id, this.threadId, hot);
public String getThreadId() {
return this.threadId;
}

@Override
public HttpClient getApi() {
return this.api;
}

@Override
Expand Down Expand Up @@ -149,6 +153,7 @@ public void printToChatHud(FabricClientCommandSource source) {

source.sendFeedback(TextClickItem.combine(
new TextClickItem("play", "/cloudmusic dj play " + this.id),
new TextClickItem("send.comment", "/cloudmusic dj send comment " + this.id),
new TextClickItem("hot.comment", "/cloudmusic dj hotComment " + this.id),
new TextClickItem("comment", "/cloudmusic dj comment " + this.id),
new TextClickItem("subscribe", "/cloudmusic dj subscribe " + this.id),
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/fengliu/cloudmusic/music163/data/Music.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import fengliu.cloudmusic.util.HttpClient;
import fengliu.cloudmusic.util.IdUtil;
import fengliu.cloudmusic.util.TextClickItem;
import fengliu.cloudmusic.util.page.ApiPage;
import fengliu.cloudmusic.util.page.Page;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -237,8 +236,13 @@ public long getDuration() {
}

@Override
public ApiPage getComments(boolean hot) {
return this.comments(this.api, this.id, this.threadId, hot);
public String getThreadId() {
return this.threadId;
}

@Override
public HttpClient getApi() {
return this.api;
}

@Override
Expand Down Expand Up @@ -287,6 +291,7 @@ public void printToChatHud(FabricClientCommandSource source) {
));

source.sendFeedback(TextClickItem.combine(
new TextClickItem("send.comment", "/cloudmusic music send comment " + this.id),
new TextClickItem("hot.comment", "/cloudmusic music hotComment " + this.id),
new TextClickItem("comment", "/cloudmusic music comment " + this.id),
new TextClickItem("playlist.add", "/cloudmusic my playlist add " + this.id),
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/fengliu/cloudmusic/music163/data/PlayList.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import fengliu.cloudmusic.util.HttpClient;
import fengliu.cloudmusic.util.IdUtil;
import fengliu.cloudmusic.util.TextClickItem;
import fengliu.cloudmusic.util.page.ApiPage;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
Expand Down Expand Up @@ -99,8 +98,13 @@ public List<IMusic> getMusics(){
}

@Override
public ApiPage getComments(boolean hot) {
return this.comments(this.api, this.id, this.threadId, hot);
public String getThreadId() {
return this.threadId;
}

@Override
public HttpClient getApi() {
return this.api;
}

@Override
Expand Down Expand Up @@ -145,6 +149,7 @@ public void printToChatHud(FabricClientCommandSource source) {

source.sendFeedback(TextClickItem.combine(
new TextClickItem("play", "/cloudmusic playlist play " + this.id),
new TextClickItem("send.comment", "/cloudmusic playlist send comment " + this.id),
new TextClickItem("hot.comment", "/cloudmusic playlist hotComment " + this.id),
new TextClickItem("comment", "/cloudmusic playlist comment " + this.id),
new TextClickItem("subscribe", "/cloudmusic playlist subscribe " + this.id),
Expand Down
22 changes: 20 additions & 2 deletions src/main/resources/assets/cloudmusic/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"cloudmusic.help.music.similar.playlist": "获取歌曲相似歌单 /cloudmusic music similar playlist [id]",
"cloudmusic.help.music.comment": "获取歌曲评论 /cloudmusic music comment [id]",
"cloudmusic.help.music.hot.comment": "获取歌曲热评 /cloudmusic music hotComment [id]",
"cloudmusic.help.music.send.comment": "向歌曲发送评论 /cloudmusic music send comment [threadId] [content]",
"cloudmusic.help.playlist": "获取歌单 /cloudmusic playlist [id]",
"cloudmusic.help.playlist.play": "播放歌单 /cloudmusic music playlist [id]",
"cloudmusic.help.playlist.subscribe": "收藏歌单 /cloudmusic playlist subscribe [id]",
Expand All @@ -15,6 +16,7 @@
"cloudmusic.help.playlist.del": "歌单删除歌曲 /cloudmusic playlist del [id] [歌曲 id]",
"cloudmusic.help.playlist.comment": "获取歌单评论 /cloudmusic playlist comment [id]",
"cloudmusic.help.playlist.hot.comment": "获取歌单热评 /cloudmusic playlist hotComment [id]",
"cloudmusic.help.playlist.send.comment": "向歌单发送评论 /cloudmusic playlist send comment [threadId] [content]",
"cloudmusic.help.artist": "获取歌手 /cloudmusic artist [id]",
"cloudmusic.help.artist.top": "播放歌手热门 50 首 /cloudmusic artist top [id]",
"cloudmusic.help.artist.album": "查看歌手所有专辑 /cloudmusic artist album [id]",
Expand All @@ -27,12 +29,15 @@
"cloudmusic.help.album.unsubscribe": "取消收藏专辑 /cloudmusic album unsubscribe [id]",
"cloudmusic.help.album.comment": "获取专辑评论 /cloudmusic album comment [id]",
"cloudmusic.help.album.hot.comment": "获取专辑热评 /cloudmusic album hotComment [id]",
"cloudmusic.help.album.send.comment": "向专辑发送评论 /cloudmusic album send comment [threadId] [content]",
"cloudmusic.help.dj": "获取电台 /cloudmusic dj [id]",
"cloudmusic.help.dj.play": "播放电台 /cloudmusic dj play [id]",
"cloudmusic.help.dj.send.comment": "向电台发送评论 /cloudmusic dj send comment [threadId] [content]",
"cloudmusic.help.dj.music": "获取电台节目 /cloudmusic dj music [id]",
"cloudmusic.help.dj.music.play": "播放电台节目 /cloudmusic dj music play [id]",
"cloudmusic.help.dj.music.comment": "获取电台节目评论 /cloudmusic dj music comment [id]",
"cloudmusic.help.dj.music.hot.comment": "获取电台节目热评 /cloudmusic dj hotComment [id]",
"cloudmusic.help.dj.send.comment": "向电台节目发送评论 /cloudmusic dj music send comment [threadId] [content]",
"cloudmusic.help.dj.subscribe": "收藏电台 /cloudmusic dj subscribe [id]",
"cloudmusic.help.dj.unsubscribe": "取消收藏电台 /cloudmusic dj unsubscribe [id]",
"cloudmusic.help.dj.comment": "获取电台评论 /cloudmusic dj comment [id]",
Expand Down Expand Up @@ -195,9 +200,12 @@
"cloudmusic.info.page.dj.radio.comments": "电台 %s 的评论",
"cloudmusic.info.page.dj.radio.hot.comments": "电台 %s 的热论",
"cloudmusic.info.page.dj.music.comments": "电台节目 %s 的评论",
"cloudmusic.info.page.dj.music.hot.comments": "电台节目 %s 的热论",
"cloudmusic.info.page.dj.music.hot.comments": "评论的子评论",
"cloudmusic.info.page.comment.floors": "电台节目 %s 的热论",
"cloudmusic.page.item.comments.like": "点赞数: %s",
"cloudmusic.info.comment.be.replied": "§b回复 %s - %s§r§7: %s",
"cloudmusic.info.comment.be.replied": "§b回复 §b%s - %s§r§7: %s",
"cloudmusic.info.comment.user.show": "点击查看发送评论用户",
"cloudmusic.info.comment.time": "发送时间: %s",
"cloudmusic.info.page.comment.null": "该评论已删除",
"cloudmusic.info.page.comment.err.null": "该评论涉及违规内容,经举报已被屏蔽",
"cloudmusic.info.page.help": "CloudMusic 帮助",
Expand Down Expand Up @@ -230,6 +238,11 @@
"cloudmusic.info.command.music.play": "播放 %s",
"cloudmusic.info.command.trash": "将 %s 扔进垃圾桶",
"cloudmusic.info.command.style.not.children": "曲风 %s - %s 没有子曲风",
"cloudmusic.info.command.send.comment": "向资源 %s 发送了一条评论",
"cloudmusic.info.command.comment.like": "点赞了评论 %s",
"cloudmusic.info.command.comment.unlike": "取消点赞了评论 %s",
"cloudmusic.info.command.comment.delete": "删除了评论 %s",
"cloudmusic.info.command.comment.reply": "回复了评论 %s",
"cloudmusic.info.command.login": "成功登录至 %s",
"cloudmusic.info.command.login.send.captcha": "成功向手机号发送验证码...",
"cloudmusic.info.command.country.code": "设置手机号国家码为 %s...",
Expand Down Expand Up @@ -282,6 +295,8 @@
"cloudmusic.options.style.album.show": "点击查看该曲风的专辑",
"cloudmusic.options.children.style": "[子曲风]",
"cloudmusic.options.children.style.show": "点击查看曲风所有子类型",
"cloudmusic.options.send.comment": "[发送回复]",
"cloudmusic.options.send.comment.show": "点击并补充回复內容进行发送评论",
"cloudmusic.options.hot.comment": "[热评]",
"cloudmusic.options.hot.comment.show": "点击查看该资源热评",
"cloudmusic.options.comment": "[评论]",
Expand All @@ -292,6 +307,8 @@
"cloudmusic.options.comment.reply.show": "点击并补充回复內容进行回复评论",
"cloudmusic.options.comment.like": "[点赞]",
"cloudmusic.options.comment.like.show": "点击点赞评论",
"cloudmusic.options.comment.unlike": "[取消点赞]",
"cloudmusic.options.comment.unlike.show": "点击取消点赞评论",
"cloudmusic.options.comment.delete": "[删除]",
"cloudmusic.options.comment.delete.show": "点击删除评论",
"cloudmusic.options.page.prev": "[上一页]",
Expand All @@ -317,6 +334,7 @@
"cloudmusic.exception.http.download": "下载文件重试超出最大次数 %s 次, 错误: %s",
"cloudmusic.exception.not.comments": "该资源目前没有评论...",
"cloudmusic.exception.not.hot.comments": "该资源目前没有热评...",
"cloudmusic.exception.not.comment.floors": "该评论目前没有子评论...",
"cloudmusic.play.quality.standard": "标准",
"cloudmusic.play.quality.higher": "较高",
"cloudmusic.play.quality.exhigh": "极高",
Expand Down

0 comments on commit 172a1a1

Please sign in to comment.