Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { | ||
GuildPermissionRes, | ||
GuildPermissionDemand, | ||
GuildPermissionsAPI, | ||
Config, | ||
OpenAPIRequest, | ||
PermissionDemandToCreate, | ||
} from '@src/types'; | ||
import { RestyResponse } from 'resty-client'; | ||
import { getURL } from './resource'; | ||
|
||
export default class GuildPermissions implements GuildPermissionsAPI { | ||
public request: OpenAPIRequest; | ||
public config: Config; | ||
constructor(request: OpenAPIRequest, config: Config) { | ||
this.request = request; | ||
this.config = config; | ||
} | ||
|
||
// 获取频道可用权限列表 | ||
public permissions(guildID: string): Promise<RestyResponse<GuildPermissionRes>> { | ||
const options = { | ||
method: 'GET' as const, | ||
url: getURL('guildPermissionURI'), | ||
rest: { | ||
guildID, | ||
}, | ||
}; | ||
return this.request<GuildPermissionRes>(options); | ||
} | ||
|
||
// 创建频道 API 接口权限授权链接 | ||
public postPermissionDemand( | ||
guildID: string, | ||
permissionDemandObj: PermissionDemandToCreate, | ||
): Promise<RestyResponse<GuildPermissionDemand>> { | ||
const options = { | ||
method: 'POST' as const, | ||
url: getURL('guildPermissionDemandURI'), | ||
rest: { | ||
guildID, | ||
}, | ||
data: permissionDemandObj, | ||
}; | ||
return this.request<GuildPermissionDemand>(options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { RestyResponse } from 'resty-client'; | ||
|
||
/** | ||
* ============= GuildPermission API权限接口 ============= | ||
*/ | ||
export interface GuildPermissionsAPI { | ||
permissions: (guildID: string) => Promise<RestyResponse<GuildPermissionRes>>; | ||
postPermissionDemand: ( | ||
guildID: string, | ||
permissionDemandObj: PermissionDemandToCreate, | ||
) => Promise<RestyResponse<GuildPermissionDemand>>; | ||
} | ||
|
||
export interface GuildPermission { | ||
path: string; // API 接口名,例如 /guilds/{guild_id}/members/{user_id} | ||
method: string; // 请求方法,例如 GET | ||
desc: string; // API 接口名称,例如 获取频道信 | ||
auth_status: number; // 授权状态,auth_stats 为 1 时已授权 | ||
} | ||
|
||
export interface GuildPermissionRes { | ||
apis: GuildPermission[]; | ||
} | ||
|
||
export interface GuildPermissionDemand { | ||
guild_id: string; // 申请接口权限的频道 id | ||
channel_id: string; // 接口权限需求授权链接发送的子频道 id | ||
api_identify: GuildPermissionDemandIdentify; // 权限接口唯一标识 | ||
title: string; // 接口权限链接中的接口权限描述信息 | ||
desc: string; // 接口权限链接中的机器人可使用功能的描述信息 | ||
} | ||
|
||
export interface PermissionDemandToCreate { | ||
channel_id: string; // 授权链接发送的子频道 ID | ||
api_identify: GuildPermissionDemandIdentify; // api 权限需求标识对象 | ||
desc?: string; // 机器人申请对应的 API 接口权限后可以使用功能的描述 | ||
} | ||
|
||
export interface GuildPermissionDemandIdentify { | ||
path: string; // API 接口名,例如 /guilds/{guild_id}/members/{user_id} | ||
method: string; // 请求方法,例如 GET | ||
} |