qq-official-bot
Version:
170 lines (169 loc) • 4.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChannelService = void 0;
class ChannelService {
constructor(bot) {
this.bot = bot;
}
/**
* 获取子频道列表
*/
async getList(guildId) {
try {
const { data: result = [] } = await this.bot.request.get(`/guilds/${guildId}/channels`);
const formattedResult = result.map(({ id: channel_id, name: channel_name, ...channel }) => ({
channel_id,
channel_name,
...channel
}));
return { success: true, data: formattedResult };
}
catch (error) {
return {
success: false,
error: {
code: error.status || 500,
message: error.message
}
};
}
}
/**
* 获取子频道信息
*/
async getInfo(channelId) {
try {
const { data: { id: _, name: channel_name, ...channel } } = await this.bot.request.get(`/channels/${channelId}`);
const result = {
channel_id: channelId,
channel_name,
...channel
};
return { success: true, data: result };
}
catch (error) {
return {
success: false,
error: {
code: error.status || 500,
message: error.message
}
};
}
}
/**
* 创建子频道
*/
async create(guildId, channelInfo) {
try {
const { data: result } = await this.bot.request.post(`/guilds/${guildId}/channels`, channelInfo);
return { success: true, data: result };
}
catch (error) {
return {
success: false,
error: {
code: error.status || 500,
message: error.message
}
};
}
}
/**
* 修改子频道
*/
async update(channelId, updateInfo) {
try {
const { data: result } = await this.bot.request.patch(`/channels/${channelId}`, updateInfo);
return { success: true, data: result };
}
catch (error) {
return {
success: false,
error: {
code: error.status || 500,
message: error.message
}
};
}
}
/**
* 删除子频道
*/
async delete(channelId) {
try {
const result = await this.bot.request.delete(`/channels/${channelId}`);
return {
success: true,
data: result.status === 200
};
}
catch (error) {
return {
success: false,
error: {
code: error.status || 500,
message: error.message
}
};
}
}
/**
* 获取频道置顶消息id列表
*/
async getPins(channelId) {
try {
const { data: { message_ids = [] } = {} } = await this.bot.request.get(`/channels/${channelId}/pins`);
return { success: true, data: message_ids };
}
catch (error) {
return {
success: false,
error: {
code: error.status || 500,
message: error.message
}
};
}
}
/**
* 置顶频道消息
*/
async pinMessage(channelId, messageId) {
try {
const { data: result } = await this.bot.request.post(`/channels/${channelId}/pins/${messageId}`);
return { success: true, data: result };
}
catch (error) {
return {
success: false,
error: {
code: error.status || 500,
message: error.message
}
};
}
}
/**
* 取消置顶频道消息
*/
async unpinMessage(channelId, messageId) {
try {
const result = await this.bot.request.delete(`/channels/${channelId}/pins/${messageId}`);
return {
success: true,
data: result.status === 204
};
}
catch (error) {
return {
success: false,
error: {
code: error.status || 500,
message: error.message
}
};
}
}
}
exports.ChannelService = ChannelService;