qq-official-bot
Version:
109 lines (108 loc) • 3.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PermissionService = void 0;
class PermissionService {
constructor(bot) {
this.bot = bot;
}
/**
* 获取频道角色权限信息
*/
async getChannelRolePermission(channelId, roleId) {
try {
const { data: result } = await this.bot.request.get(`/channels/${channelId}/roles/${roleId}/permissions`);
return { success: true, data: result };
}
catch (error) {
return {
success: false,
error: {
code: error.status || 500,
message: error.message
}
};
}
}
/**
* 更新频道角色权限
*/
async updateChannelRolePermission(channelId, roleId, permission) {
try {
const result = await this.bot.request.put(`/channels/${channelId}/roles/${roleId}/permissions`, permission);
return {
success: true,
data: result.status === 204
};
}
catch (error) {
return {
success: false,
error: {
code: error.status || 500,
message: error.message
}
};
}
}
/**
* 获取频道用户权限
*/
async getChannelMemberPermission(channelId, memberId) {
try {
const { data: result } = await this.bot.request.get(`/channels/${channelId}/members/${memberId}/permissions`);
return { success: true, data: result };
}
catch (error) {
return {
success: false,
error: {
code: error.status || 500,
message: error.message
}
};
}
}
/**
* 更新频道用户权限
*/
async updateChannelMemberPermission(channelId, memberId, permission) {
try {
const result = await this.bot.request.put(`/channels/${channelId}/members/${memberId}/permissions`, permission);
return {
success: true,
data: result.status === 204
};
}
catch (error) {
return {
success: false,
error: {
code: error.status || 500,
message: error.message
}
};
}
}
/**
* 设置频道公告
*/
async setChannelAnnounce(guildId, channelId, messageId) {
try {
const { data: result } = await this.bot.request.post(`/guilds/${guildId}/announces`, {
channel_id: channelId,
message_id: messageId
});
return { success: true, data: result };
}
catch (error) {
return {
success: false,
error: {
code: error.status || 500,
message: error.message
}
};
}
}
}
exports.PermissionService = PermissionService;