🌱 帖子回复请求&类型

This commit is contained in:
目棃
2024-08-31 11:00:50 +08:00
parent dbaed7da20
commit 01359b061d
5 changed files with 416 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
/**
* @file plugins/Mys/index.ts
* @description Mys plugin index
* @since Beta v0.5.1
* @since Beta v0.5.5
*/
import MysApi from "./api/index.js";
@@ -15,6 +15,7 @@ import getLotteryData from "./request/getLotteryData.js";
import getNewsList from "./request/getNewsList.js";
import { getPositionData } from "./request/getPositionData.js";
import getPostData from "./request/getPostData.js";
import { getPostReply, getPostSubRoot, getPostSubReply } from "./request/getPostReply.js";
import { getVoteInfo, getVoteResult } from "./request/getVoteData.js";
import searchPosts from "./request/searchPost.js";
import { getGachaCard } from "./utils/getGachaCard.js";
@@ -25,6 +26,9 @@ const Mys = {
Api: MysApi,
Post: {
get: getPostData,
reply: getPostReply,
replySubRoot: getPostSubRoot,
replySub: getPostSubReply,
},
Collection: {
info: getCollectionData,

View File

@@ -0,0 +1,114 @@
/**
* @file plugins/Mys/request/getPostReply.ts
* @description Mys 插件帖子回复请求
* @since Beta v0.5.5
*/
import TGHttp from "../../../utils/TGHttp.js";
import MysApi from "../api/index.js";
/**
* @description 获取帖子回复信息
* @since Beta v0.5.5
* @param {number} postId 帖子 ID
* @param {number} gid 社区 ID
* @param {boolean} isHot 是否热门
* @param {boolean} onlyMaster 是否只看楼主
* @param {number} orderType 排序类型
* @param {string} lastId 最后 ID
* @param {number} size 每页大小
* @return {Promise<TGApp.Plugins.Mys.Reply.ReplyData|TGApp.BBS.Response.Base>}
*/
export async function getPostReply(
postId: number,
gid: number,
isHot: boolean,
lastId: string,
onlyMaster: boolean = false,
orderType?: 1 | 2,
size: number = 20,
): Promise<TGApp.Plugins.Mys.Reply.ReplyData | TGApp.BBS.Response.Base> {
const params: Record<string, string | number | boolean> = {
post_id: postId,
gids: gid,
is_hot: isHot,
size: size,
};
if (lastId) {
params["last_id"] = lastId;
}
if (orderType) {
params["order_type"] = orderType;
}
if (onlyMaster) {
params["only_master"] = onlyMaster;
}
const link = "https://bbs-api.miyoushe.com/post/wapi/getPostReplies";
const resp = await TGHttp<TGApp.Plugins.Mys.Reply.Response>(link, {
method: "GET",
headers: { referer: MysApi.PostReferer },
query: params,
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data;
}
/**
* @description 获取帖子子回复根信息
* @since Beta v0.5.5
* @param {number} gid 社区 ID
* @param {string} postId 帖子 ID
* @param {string} replyId 回复 ID
* @return {Promise<TGApp.Plugins.Mys.Reply.SubRootData|TGApp.BBS.Response.Base>}
*/
export async function getPostSubRoot(
gid: number,
postId: string,
replyId: string,
): Promise<TGApp.Plugins.Mys.Reply.SubRootData | TGApp.BBS.Response.Base> {
const link = "https://bbs-api.miyoushe.com/post/wapi/getRootReplyInfo";
const params = { gids: gid, post_id: postId, reply_id: replyId };
const resp = await TGHttp<TGApp.Plugins.Mys.Reply.SubRootResponse>(link, {
method: "GET",
headers: { referer: MysApi.PostReferer },
query: params,
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data;
}
/**
* @description 获取帖子子回复信息
* @since Beta v0.5.5
* @param {number} floorId 楼层 ID
* @param {number} gid 社区 ID
* @param {string} postId 帖子 ID
* @param {string} lastId 最后 ID
* @param {number} size 每页大小
* @return {Promise<TGApp.Plugins.Mys.Reply.SubData|TGApp.BBS.Response.Base>}
*/
export async function getPostSubReply(
floorId: number,
gid: number,
postId: string,
lastId: string,
size: number = 20,
): Promise<TGApp.Plugins.Mys.Reply.SubData | TGApp.BBS.Response.Base> {
const params: Record<string, string | number> = {
floor_id: floorId,
gids: gid,
post_id: postId,
size: size,
};
if (lastId) {
params["last_id"] = lastId;
}
const link = "https://bbs-api.miyoushe.com/post/wapi/getSubReplies";
const resp = await TGHttp<TGApp.Plugins.Mys.Reply.SubResponse>(link, {
method: "GET",
headers: { referer: MysApi.PostReferer },
query: params,
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data;
}

View File

@@ -1,12 +1,12 @@
/**
* @file plugins/Mys/types/post.d.ts
* @description Mys 插件帖子类型定义文件
* @since Beta v0.5.0
* @since Beta v0.5.5
*/
/**
* @description Mys 插件帖子类型
* @since Beta v0.5.0
* @since Beta v0.5.5
* @namespace TGApp.Plugins.Mys.Post
* @memberof TGApp.Plugins.Mys
*/
@@ -249,7 +249,7 @@ declare namespace TGApp.Plugins.Mys.Post {
/**
* @description 图片数据
* @since Alpha v0.2.1
* @since Beta v0.5.5
* @interface Image
* @property {string} url 图片 URL
* @property {number} height 图片高度
@@ -282,7 +282,7 @@ declare namespace TGApp.Plugins.Mys.Post {
h: number;
url: string;
} | null;
is_user_set_cover: boolean;
is_user_set_cover?: boolean;
image_id: string;
entity_type: string;
entity_id: string;

252
src/plugins/Mys/types/Reply.d.ts vendored Normal file
View File

@@ -0,0 +1,252 @@
/**
* @file plugins/Mys/types/Reply.d.ts
* @description Mys 插件帖子回复数据类型定义文件
* @since Beta v0.5.5
*/
/**
* @description Mys 插件帖子回复数据类型定义
* @since Beta v0.5.5
* @namespace TGApp.Plugins.Mys.Reply
* @memberof TGApp.Plugins.Mys
*/
declare namespace TGApp.Plugins.Mys.Reply {
/**
* @description 帖子回复数据类型
* @since Beta v0.5.5
* @interface Response
* @extends TGApp.BBS.Response.BaseWithData
* @property {ReplyData} data - 回复数据
* @return Response
*/
interface Response extends TGApp.BBS.Response.BaseWithData {
data: ReplyData;
}
/**
* @description 子回复数据类型
* @since Beta v0.5.5
* @interface SubResponse
* @extends TGApp.BBS.Response.BaseWithData
* @property {SubData} data - 子回复数据
* @return SubResponse
*/
interface SubResponse extends TGApp.BBS.Response.BaseWithData {
data: SubData;
}
/**
* @description 子回复数据的根数据类型
* @since Beta v0.5.5
* @interface SubRootResponse
* @extends TGApp.BBS.Response.BaseWithData
* @property {SubRootData} data - 子回复数据
* @return SubRootResponse
*/
interface SubRootResponse extends TGApp.BBS.Response.BaseWithData {
data: SubRootData;
}
/**
* @description 子回复数据类型
* @since Beta v0.5.5
* @interface SubRootData
* @property {TGApp.Plugins.Mys.Post.FullData} post - 帖子数据
* @property {ReplyFull} reply - 回复数据
* @return SubRootData
*/
interface SubRootData {
post: TGApp.Plugins.Mys.Post.FullData;
reply: ReplyFull;
}
/**
* @description 回复数据类型
* @since Beta v0.5.5
* @interface ReplyData
* @property {Array<ReplyFull>} list - 回复列表
* @property {string} last_id - 最后 ID
* @property {boolean} is_last - 是否最后
* @property {string} post_owner_id - 帖子拥有者 ID
* @property {string} pin_reply_id - 置顶回复 ID
* @property {number} fold_reply_num - 折叠回复数
* @return ReplyData
*/
interface ReplyData {
list: Array<ReplyFull>;
last_id: string;
is_last: boolean;
post_owner_id: string;
pin_reply_id: string;
fold_reply_num: number;
}
/**
* @description 子回复数据类型
* @since Beta v0.5.5
* @interface SubData
* @property {Array<ReplyFull>} list - 回复列表
* @property {string} last_id - 最后 ID
* @property {boolean} is_last - 是否最后
* @property {boolean} has_previous - 是否有上一页
* @property {string} post_owner_id - 帖子拥有者 ID
* @return SubData
*/
interface SubData {
list: Array<ReplyFull>;
last_id: string;
is_last: boolean;
has_previous: boolean;
post_owner_id: string;
}
/**
* @description 回复数据类型
* @since Beta v0.5.5
* @interface ReplyFull
* @property {Reply} reply - 回复数据
* @property {User} user - 用户数据
* @property {Stat} stat - 点赞数据
* @property {SelfOperation} self_operation - 自身操作数据
* @property {MasterStatus} master_status - 主楼状态数据
* @property {Array<TGApp.Plugins.Mys.Post.Image>} images - 图片数据
* @property {Array<ReplyFull>} sub_replies - 子回复数据
* @property {boolean} is_lz - 是否楼主
* @property {number} sub_reply_count - 子回复数量
* @property {unknown} r_user - 未知数据
* @property {unknown} r_reply - 未知数据
* @property {unknown} r_post - 未知数据
* @property {unknown} user_game_info - 未知数据
* @return ReplyFull
*/
interface ReplyFull {
reply: Reply;
user: TGApp.Plugins.Mys.User.Reply;
stat: Stat;
self_operation: SelfOperation;
master_status: MasterStatus;
images: Array<TGApp.Plugins.Mys.Post.Image>;
sub_replies: Array<ReplyFull>;
is_lz: boolean;
sub_reply_count: number;
r_user: unknown;
r_reply: unknown;
r_post: unknown;
user_game_info: unknown;
}
/**
* @description 回复数据类型
* @since Beta v0.5.5
* @interface Reply
* @property {number} game_id - 游戏 ID
* @property {string} post_id - 帖子 ID
* @property {string} reply_id - 回复 ID
* @property {string} uid - 用户 ID
* @property {string} r_uid - 回复用户 ID
* @property {string} content - 回复内容
* @property {number} f_forum_id - 板块 ID
* @property {string} f_reply_id - 主楼 ID
* @property {number} floor_id - 楼层 ID
* @property {number} is_deleted - 是否删除 // 0 未删除 1 已删除
* @property {number} delete_src - 删除来源
* @property {number} created_at - 创建时间,秒级时间戳
* @property {number} updated_at - 更新时间,秒级时间戳
* @property {number} deleted_at - 删除时间,秒级时间戳
* @property {string} struct_content - 结构化内容
* @property {Array<unknown>} structured_content_rows - 结构化内容行
* @property {boolean} is_top - 是否置顶
* @property {boolean} has_block_word - 是否有屏蔽词
* @property {number} overt_status - 公开状态
* @property {boolean} is_showing_missing - 是否显示缺失
* @property {number} selected_comment_time - 选中评论时间
* @property {boolean} is_mentor - 是否导师
* @property {number} view_status - 查看状态
* @return Reply
*/
interface Reply {
game_id: number;
post_id: string;
reply_id: string;
uid: string;
r_uid: string;
content: string;
f_forum_id: number;
f_reply_id: string;
floor_id: number;
is_deleted: number;
delete_src: number;
created_at: number;
updated_at: number;
deleted_at: number;
struct_content: string;
structured_content_rows: Array<unknown>;
is_top: boolean;
has_block_word: boolean;
overt_status: number;
is_showing_missing: boolean;
selected_comment_time: number;
is_mentor: boolean;
view_status: number;
}
/**
* @description 回复气泡数据类型
* @since Beta v0.5.5
* @interface ReplyBubble
* @property {string} assets_id - 资源 ID
* @property {string} bg_color - 背景颜色
* @property {string} url - 链接
* @property {string} name - 名称
* @return ReplyBubble
*/
interface ReplyBubble {
assets_id: string;
bg_color: string;
url: string;
name: string;
}
/**
* @description 点赞数据类型
* @since Beta v0.5.5
* @interface Stat
* @property {number} reply_num - 回复数
* @property {number} like_num - 点赞数
* @property {number} sub_num - 子回复数
* @property {number} dislike_num - 踩数
* @return Stat
*/
interface Stat {
reply_num: number;
like_num: number;
sub_num: number;
dislike_num: number;
}
/**
* @description 自身操作数据类型
* @since Beta v0.5.5
* @interface SelfOperation
* @property {number} attitude - 操作态度
* @property {number} reply_vote_attitude - 回复投票态度
* @return SelfOperation
*/
interface SelfOperation {
attitude: number;
reply_vote_attitude: number;
}
/**
* @description 主楼状态数据类型
* @since Beta v0.5.5
* @interface MasterStatus
* @property {boolean} is_official_master - 是否官方
* @property {boolean} is_user_master - 是否用户
* @return MasterStatus
*/
interface MasterStatus {
is_official_master: boolean;
is_user_master: boolean;
}
}

View File

@@ -1,12 +1,12 @@
/**
* @file plugins/Mys/types/user.ts
* @description Mys 插件用户类型定义文件
* @since Beta v0.3.9
* @since Beta v0.5.5
*/
/**
* @description Mys 插件用户类型
* @since Beta v0.3.9
* @since Beta v0.5.5
* @namespace TGApp.Plugins.Mys.User
* @memberof TGApp.Plugins.Mys
*/
@@ -339,4 +339,43 @@ declare namespace TGApp.Plugins.Mys.User {
pendant: string;
uid: string;
}
/**
* @description 帖子回复中的用户信息
* @since Beta v0.5.5
* @interface Reply
* @property {string} uid 用户 ID
* @property {string} nickname 用户昵称
* @property {string} introduce 用户简介
* @property {string} avatar 用户头像
* @property {number} gender 用户性别
* @property {Certification} certification 用户认证信息
* @property {LevelExp} level_exp 用户等级经验
* @property {string} avatar_url 用户头像链接
* @property {string} pendant 用户挂件 URL可能为 ""
* @property {string} ip_region 用户 IP 地区
* @property {boolean} is_following 是否关注
* @property {boolean} is_followed 是否被关注
* @property {AvatarExt} avatar_ext 用户头像扩展信息
* @property {boolean} is_super_fan 是否是铁粉
* @property {TGApp.Plugins.Mys.Reply.ReplyBubble} reply_bubble 回复气泡,可能为 null
* @return Reply
*/
interface Reply {
uid: string;
nickname: string;
introduce: string;
avatar: string;
gender: number;
certification: Certification;
level_exp: LevelExp;
avatar_url: string;
pendant: string;
ip_region: string;
is_following: boolean;
is_followed: boolean;
avatar_ext: AvatarExt;
is_super_fan: boolean;
reply_bubble: TGApp.Plugins.Mys.Reply.ReplyBubble | null;
}
}