From a2f4785a153986c32239c3e1d10ef4754430e9aa Mon Sep 17 00:00:00 2001 From: MODcraft Date: Sun, 2 Apr 2023 17:43:31 +0800 Subject: [PATCH 01/19] feat(kook): Kook internal api (Channel) --- adapters/kook/src/index.ts | 4 +++ adapters/kook/src/types.ts | 53 ++++++++++++++++++++++++++++++++++---- adapters/kook/src/utils.ts | 4 ++- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/adapters/kook/src/index.ts b/adapters/kook/src/index.ts index 74343e19..0c07d7f7 100644 --- a/adapters/kook/src/index.ts +++ b/adapters/kook/src/index.ts @@ -13,6 +13,10 @@ export default KookBot declare global { namespace Satori { + interface Session { + kook?: Kook.Internal + } + interface Events { 'kook/message-btn-click': {} } diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index 267f9173..e67eefc1 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -253,8 +253,8 @@ export interface Channel { name: string user_id: string guild_id: string - isCategory: number - parentId: string + is_category: number + parent_id: string topic: string type: number level: number @@ -387,20 +387,63 @@ export interface Internal { createGuildMute(param: { guild_id: string; user_id: string; type: GuildMute.Type }): Promise deleteGuildMute(param: { guild_id: string; user_id: string; type: GuildMute.Type }): Promise getGuildBoostHistory(param: { guild_id: string; start_time: number; end_time: number }): Promise> + + getChannelList(param: { guild_id: string }): Promise> + getChannelView(param: { target_id: string }): Promise + createChannel(param: { + guild_id: string + parent_id?: string + name: string + type?: number + limit_amount?: number + voice_quality?: string + is_category?: 0|1 + }): Promise + updateChannel(param: { + channel_id: string + name?: string + topic?: string + slow_mode?: 0|5000|10000|15000|30000|60000|120000|300000|600000|900000|1800000|3600000|7200000|21600000 + }): Promise + deleteChannel(param: { channel_id: string }): Promise + getChannelUserList(param: { channel_id: string }): Promise> + moveChannelUser(param: { target_id: string; user_ids: [] }): Promise + getChannelRoleIndex(param: { channel_id: string }): Promise<{ permission_overwrites: Overwrite; permission_users: List; permission_sync: 0 | 1 }> + createChannelRole(param: { channel_id: string; type?: 'user_id'; value?: string }): Promise<{ + user_id: string + allow: number + deny: number + }> + createChannelRole(param: { channel_id: string; type: 'role_id'; value?: string }): Promise<{ + role_id: string + allow: number + deny: number + }> + updateChannelRole(param: { channel_id: string; type?: 'user_id'; value?: string; allow?: number; deny?: number }): Promise<{ + user_id: string + allow: number + deny: number + }> + updateChannelRole(param: { channel_id: string; type: 'role_id'; value?: string; allow?: number; deny?: number }): Promise<{ + role_id: string + allow: number + deny: number + }> + deleteChannelRole(param: { channel_id: string; type?: 'role_id' | 'user_id'; value?: string }): Promise } export class Internal { constructor(private http: Quester) {} static define(name: string, method: Quester.Method, path: string) { - Internal.prototype[name] = function (this: Internal, ...args: any[]) { + Internal.prototype[name] = async function (this: Internal, ...args: any[]) { const config: Quester.AxiosRequestConfig = {} if (method === 'GET' || method === 'DELETE') { config.params = args[0] } else { config.data = args[0] } - return this.http(method, path, config) + return (await this.http(method, path, config))?.data } } } @@ -437,7 +480,7 @@ Internal.define('getMessageReactionList', 'GET', '/message/reaction-list') Internal.define('addMessageReaction', 'POST', '/message/add-reaction') Internal.define('deleteMessageReaction', 'POST', '/message/delete-reaction') -Internal.define('getChannelUserList', 'GET', '/channel-user/get-joined-channel') +Internal.define('getChannelJoinedUserList', 'GET', '/channel-user/get-joined-channel') Internal.define('getPrivateChatList', 'GET', '/user-chat/list') Internal.define('getPrivateChatView', 'GET', '/user-chat/view') diff --git a/adapters/kook/src/utils.ts b/adapters/kook/src/utils.ts index 226df553..4714cf9d 100644 --- a/adapters/kook/src/utils.ts +++ b/adapters/kook/src/utils.ts @@ -1,4 +1,4 @@ -import { Bot, h, hyphenate, Session, Universal } from '@satorijs/satori' +import { Bot, defineProperty, h, hyphenate, Session, Universal } from '@satorijs/satori' import * as Kook from './types' export const adaptGroup = (data: Kook.Guild): Universal.Guild => ({ @@ -117,6 +117,8 @@ function adaptReaction(body: Kook.NoticeBody, session: Partial) { export function adaptSession(bot: Bot, input: any) { const session = bot.session() + defineProperty(session, 'kook', Object.create(bot.internal)) + Object.assign(session.kook, input) if (input.type === Kook.Type.system) { const { type, body } = input.extra as Kook.Notice switch (type) { From f55b1c58c86cf070523c5d0f063c2c0a8d3321ca Mon Sep 17 00:00:00 2001 From: MODcraft Date: Sun, 2 Apr 2023 18:00:50 +0800 Subject: [PATCH 02/19] Add Payload --- adapters/kook/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapters/kook/src/index.ts b/adapters/kook/src/index.ts index 0c07d7f7..43b7507a 100644 --- a/adapters/kook/src/index.ts +++ b/adapters/kook/src/index.ts @@ -14,7 +14,7 @@ export default KookBot declare global { namespace Satori { interface Session { - kook?: Kook.Internal + kook?: Kook.Payload & Kook.Internal } interface Events { From b367f5f0dcce9045caf9dc9fba31238f27ac8fbe Mon Sep 17 00:00:00 2001 From: MODcraft Date: Sun, 2 Apr 2023 18:37:12 +0800 Subject: [PATCH 03/19] Message & getChannelJoinedUserList --- adapters/kook/src/types.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index e67eefc1..7651a8d0 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -388,7 +388,7 @@ export interface Internal { deleteGuildMute(param: { guild_id: string; user_id: string; type: GuildMute.Type }): Promise getGuildBoostHistory(param: { guild_id: string; start_time: number; end_time: number }): Promise> - getChannelList(param: { guild_id: string }): Promise> + getChannelList(param: { guild_id: string } & Pagination): Promise> getChannelView(param: { target_id: string }): Promise createChannel(param: { guild_id: string @@ -430,6 +430,21 @@ export interface Internal { deny: number }> deleteChannelRole(param: { channel_id: string; type?: 'role_id' | 'user_id'; value?: string }): Promise + + getMessageList(param: { target_id: string; msg_id?: string; pin?: 0 | 1; flag?: 'before' | 'around' | 'after' } & Pagination): Promise> + getMessageView(param: { msg_id: string }): Promise + createMessage(param: { type?: Type; target_id: string; content: string; quote?: string; nonce?: string; temp_target_id: string }): Promise<{ + msg_id: string + msg_timestamp: number + nonce: string + }> + updateMessage(param: { msg_id: string; content: string; quote?: string; temp_target_id: string }): Promise + deleteMessage(param: { msg_id: string }): Promise + getMessageReactionList(param: { msg_id: string; emoji: string }): Promise + addMessageReaction(param: { msg_id: string; emoji: string }): Promise + deleteMessageReaction(param: { msg_id: string; emoji: string; user_id?: string}): Promise + + getChannelJoinedUserList(param: { guild_id: string; user_id: string } & Pagination): Promise> } export class Internal { From f048cba2c8fbece245abb77a6045e45c653417ef Mon Sep 17 00:00:00 2001 From: MODcraft Date: Sun, 2 Apr 2023 19:13:17 +0800 Subject: [PATCH 04/19] PrivateChat --- adapters/kook/src/types.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index 7651a8d0..c7960d32 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -88,6 +88,24 @@ export interface MessageMeta { } } +export interface PrivateChat { + code: string + last_read_time: number + latest_msg_time: number + unread_count: number + is_friend: boolean + is_blocked: boolean + is_target_blocked: boolean + target_info: PrivateChatUserMeta +} + +export interface PrivateChatUserMeta { + id: string + username: string + online: boolean + avatar: string +} + export interface KmarkdownUserMeta { id: string username: string @@ -445,6 +463,11 @@ export interface Internal { deleteMessageReaction(param: { msg_id: string; emoji: string; user_id?: string}): Promise getChannelJoinedUserList(param: { guild_id: string; user_id: string } & Pagination): Promise> + + getPrivateChatList(param?: Pagination): Promise>> + getPrivateChatView(param: { chat_code: string }): Promise + createPrivateChat(param: { target_id: string }): Promise + deletePrivateChat(param: { chat_code: string }): Promise } export class Internal { From ae951a6d3703e9a6d46d1bfb95e1a62e661cfe7a Mon Sep 17 00:00:00 2001 From: MODcraft Date: Sun, 2 Apr 2023 20:03:10 +0800 Subject: [PATCH 05/19] DirectMessage --- adapters/kook/src/types.ts | 117 ++++++++++++++++++++++++++----------- 1 file changed, 82 insertions(+), 35 deletions(-) diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index c7960d32..0c2ca982 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -96,14 +96,7 @@ export interface PrivateChat { is_friend: boolean is_blocked: boolean is_target_blocked: boolean - target_info: PrivateChatUserMeta -} - -export interface PrivateChatUserMeta { - id: string - username: string - online: boolean - avatar: string + target_info: User } export interface KmarkdownUserMeta { @@ -427,35 +420,40 @@ export interface Internal { getChannelUserList(param: { channel_id: string }): Promise> moveChannelUser(param: { target_id: string; user_ids: [] }): Promise getChannelRoleIndex(param: { channel_id: string }): Promise<{ permission_overwrites: Overwrite; permission_users: List; permission_sync: 0 | 1 }> - createChannelRole(param: { channel_id: string; type?: 'user_id'; value?: string }): Promise<{ - user_id: string - allow: number - deny: number - }> - createChannelRole(param: { channel_id: string; type: 'role_id'; value?: string }): Promise<{ - role_id: string - allow: number - deny: number - }> - updateChannelRole(param: { channel_id: string; type?: 'user_id'; value?: string; allow?: number; deny?: number }): Promise<{ - user_id: string - allow: number - deny: number - }> - updateChannelRole(param: { channel_id: string; type: 'role_id'; value?: string; allow?: number; deny?: number }): Promise<{ - role_id: string - allow: number - deny: number - }> + createChannelRole(param: { channel_id: string; type?: 'user_id'; value?: string }): + Promise<{ + user_id: string + allow: number + deny: number + }> + createChannelRole(param: { channel_id: string; type: 'role_id'; value?: string }): + Promise<{ + role_id: string + allow: number + deny: number + }> + updateChannelRole(param: { channel_id: string; type?: 'user_id'; value?: string; allow?: number; deny?: number }): + Promise<{ + user_id: string + allow: number + deny: number + }> + updateChannelRole(param: { channel_id: string; type: 'role_id'; value?: string; allow?: number; deny?: number }): + Promise<{ + role_id: string + allow: number + deny: number + }> deleteChannelRole(param: { channel_id: string; type?: 'role_id' | 'user_id'; value?: string }): Promise getMessageList(param: { target_id: string; msg_id?: string; pin?: 0 | 1; flag?: 'before' | 'around' | 'after' } & Pagination): Promise> getMessageView(param: { msg_id: string }): Promise - createMessage(param: { type?: Type; target_id: string; content: string; quote?: string; nonce?: string; temp_target_id: string }): Promise<{ - msg_id: string - msg_timestamp: number - nonce: string - }> + createMessage(param: { type?: Type; target_id: string; content: string; quote?: string; nonce?: string; temp_target_id: string }): + Promise<{ + msg_id: string + msg_timestamp: number + nonce: string + }> updateMessage(param: { msg_id: string; content: string; quote?: string; temp_target_id: string }): Promise deleteMessage(param: { msg_id: string }): Promise getMessageReactionList(param: { msg_id: string; emoji: string }): Promise @@ -468,7 +466,57 @@ export interface Internal { getPrivateChatView(param: { chat_code: string }): Promise createPrivateChat(param: { target_id: string }): Promise deletePrivateChat(param: { chat_code: string }): Promise -} + + getDirectMessageList(param: EitherOr<{ target_id: string; chat_code: string }, 'target_id', 'chat_code'> & + { msg_id?: string; flag?: 'before' | 'around' | 'after' } & Pagination): + Promise<{ items: Message[] }> + createDirectMessage(param: { type?: Type; content: string; quote?: string; nonce?: string} & + EitherOr<{ target_id: string; chat_code: string }, 'target_id', 'chat_code'>): + Promise<{ + msg_id: string + msg_timestamp: number + nonce: string + }> + updateDirectMessage(param: { msg_id: string; content: string; quote?: string}): Promise + deleteDirectMessage(param: { msg_id: string }): Promise + getDirectMessageReactionList(param: { msg_id: string; emoji?: string}): Promise + addDirectMessageReaction(param: { msg_id: string; emoji: string }): Promise + deleteDirectMessageReaction(param: { msg_id: string; emoji: string; user_id?: string }): Promise +} + +type FilterOptional = Pick< + T, + Exclude< + { + [K in keyof T]: T extends Record ? K : never; + }[keyof T], + undefined + > +> + +type FilterNotOptional = Pick< + T, + Exclude< + { + [K in keyof T]: T extends Record ? never : K; + }[keyof T], + undefined + > +> + +type PartialEither = { [P in Exclude, K>]-?: T[P] } & + { [P in Exclude, K>]?: T[P] } & + { [P in Extract]?: undefined } + +type Object = { + [name: string]: any +} + +type EitherOr = + ( + PartialEither, L> | + PartialEither, R> + ) & Omit export class Internal { constructor(private http: Quester) {} @@ -526,7 +574,6 @@ Internal.define('createPrivateChat', 'POST', '/user-chat/create') Internal.define('deletePrivateChat', 'POST', '/user-chat/delete') Internal.define('getDirectMessageList', 'GET', '/direct-message/list') -Internal.define('getDirectMessageView', 'GET', '/direct-message/view') Internal.define('createDirectMessage', 'POST', '/direct-message/create') Internal.define('updateDirectMessage', 'POST', '/direct-message/update') Internal.define('deleteDirectMessage', 'POST', '/direct-message/delete') From 6e57fb58291c9e457615881e0d6f9631a1511460 Mon Sep 17 00:00:00 2001 From: MODcraft Date: Sun, 2 Apr 2023 20:37:08 +0800 Subject: [PATCH 06/19] update --- adapters/kook/src/types.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index 0c2ca982..8aae75c4 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -482,6 +482,20 @@ export interface Internal { getDirectMessageReactionList(param: { msg_id: string; emoji?: string}): Promise addDirectMessageReaction(param: { msg_id: string; emoji: string }): Promise deleteDirectMessageReaction(param: { msg_id: string; emoji: string; user_id?: string }): Promise + + getGateway(param: { compress?: 0|1 }): Promise<{ url: string }> + getToken(param: { grant_type: 'authorization_code'; client_id: string; client_secret: string; code: string; redirect_uri: string}): + Promise<{ + access_token: string + expires_in?: number + token_type: 'Bearer' + scope: string + }> + createAsset(param: { file: FormData }): Promise<{ url: string }> + + getUserMe(): Promise + getUserView(param: { user_id: string; guild_id?: string }): Promise + offline(): Promise } type FilterOptional = Pick< @@ -529,7 +543,9 @@ export class Internal { } else { config.data = args[0] } - return (await this.http(method, path, config))?.data + const req = await this.http(method, path, config) + if (req?.code !== 0) throw new Error(req?.message || 'Unexpected Error') + return req?.data } } } From 9fcb6a761513239ce03f4afff1ca7bb780ed1109 Mon Sep 17 00:00:00 2001 From: MODcraft Date: Sun, 2 Apr 2023 21:37:02 +0800 Subject: [PATCH 07/19] GuildRole --- adapters/kook/src/types.ts | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index 8aae75c4..4d7ae31c 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -367,6 +367,51 @@ interface GuildMute { user_ids: string[] } +interface GuildRole { + role_id: number + name: string + color: number + position: number + hoist: 0 | 1 + mentionable: 0 | 1 + permissions: number +} + +export enum Permissions { + GUILD_ADMIN = 0, + GUILD_MANAGE = 1, + GUILD_LOG = 2, + GUILD_INVITE_CREATE = 3, + GUILD_INVITE_MANAGE = 4, + CHANNEL_MANAGE = 5, + GUILD_USER_KICK = 6, + GUILD_USER_BAN = 7, + GUILD_EMOJI_MANAGE = 8, + GUILD_USER_NAME_CHANGE = 9, + GUILD_ROLE_MANAGE = 10, + CHANNEL_VIEW = 11, + CHANNEL_MESSAGE = 12, + CHANNEL_MANAGE_MESSAGE = 13, + CHANNEL_UPLOAD = 14, + CHANNEL_VOICE_CONNECT = 15, + CHANNEL_VOICE_MANAGE = 16, + CHANNEL_MESSAGE_AT_ALL = 17, + CHANNEL_MESSAGE_REACTION_CREATE = 18, + CHANNEL_MESSAGE_REACTION_FOLLOW = 19, + CHANNEL_VOICE_CONNECT_PASSIVE = 20, + CHANNEL_VOICE_SPEAK_KEY_ONLY = 21, + CHANNEL_VOICR_SPEAK_FREE = 22, + CHANNEL_VOICE_SPEAK = 23, + GUILD_USER_DEAFEN = 24, + GUILD_USER_NAME_CHANGE_OTHER = 25, + GUILD_USER_MUTE = 26, + CHANNEL_VOICE_BGM = 27 +} + +export function hasPermission(permissions: number, permission: Permissions) { + return (permissions & (1 << permission)) === (1 << permission) +} + namespace GuildMute { export enum Type { mic = 1, @@ -496,6 +541,23 @@ export interface Internal { getUserMe(): Promise getUserView(param: { user_id: string; guild_id?: string }): Promise offline(): Promise + + getGuildRoleList(param: { guild_id: string } & Pagination): Promise> + createGuildRole(param: { name?: string; guild_id: string }): Promise + updateGuildRole(param: { guild_id: string; role_id: number } & Partial>): Promise + deleteGuildRole(param: { guild_id: string; role_id: number }): Promise + grantGuildRole(param: { guild_id: string; user_id?: string; role_id: number }): + Promise<{ + user_id: string + guild_id: string + roles: [] + }> + revokeGuildRole(param: { guild_id: string; user_id?: string; role_id: number }): + Promise<{ + user_id: string + guild_id: string + roles: [] + }> } type FilterOptional = Pick< @@ -605,6 +667,7 @@ Internal.define('getUserMe', 'GET', '/user/me') Internal.define('getUserView', 'GET', '/user/view') Internal.define('offline', 'POST', '/user/offline') +Internal.define('getGuildRoleList', 'GET', '/guild-role/list') Internal.define('createGuildRole', 'POST', '/guild-role/create') Internal.define('updateGuildRole', 'POST', '/guild-role/update') Internal.define('deleteGuildRole', 'POST', '/guild-role/delete') From 8ffd493b88c325b42fac436f47019a006d7cb119 Mon Sep 17 00:00:00 2001 From: MODcraft Date: Sun, 2 Apr 2023 21:44:16 +0800 Subject: [PATCH 08/19] Intimacy --- adapters/kook/src/types.ts | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index 4d7ae31c..57e449a4 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -550,14 +550,28 @@ export interface Internal { Promise<{ user_id: string guild_id: string - roles: [] + roles: number[] }> revokeGuildRole(param: { guild_id: string; user_id?: string; role_id: number }): - Promise<{ - user_id: string - guild_id: string - roles: [] - }> + Promise<{ + user_id: string + guild_id: string + roles: number[] + }> + + getIntimacy(param: { user_id: string }): + Promise<{ + img_url: string + social_info: string + last_read: number + score: number + img_list: { + id: string + url: string + }[] + }> + updateIntimacy(param: { user_id: string; score?: number; social_info?: string; img_id?: string }): Promise + } type FilterOptional = Pick< From f6aed5efe7e4d997c9eb15f7b5c43253e4141731 Mon Sep 17 00:00:00 2001 From: MODcraft Date: Sun, 2 Apr 2023 23:01:55 +0800 Subject: [PATCH 09/19] finish kook api --- adapters/kook/src/types.ts | 51 +++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index 57e449a4..a002f360 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -432,6 +432,17 @@ interface GuildBoost { user: User } +interface Game { + id: number + name: string + type: 0|1|2 + options: string + kmhook_admin: boolean + process_name: string[] + product_name: string[] + icon: string +} + export interface Internal { getGuildList(param?: Pagination): Promise> getGuildView(param: { guild_id: string }): Promise @@ -572,6 +583,42 @@ export interface Internal { }> updateIntimacy(param: { user_id: string; score?: number; social_info?: string; img_id?: string }): Promise + getGuildEmojiList(param?: Pagination): Promise> + createGuildEmoji(param: { name?: string; guild_id: string; emoji: FormData }): Promise + updateGuildEmoji(param: { name: string; id: string }): Promise + deleteGuildEmoji(param: { id: string }): Promise + + getInviteList(param: EitherOr<{ guild_id: string; channel_id: string }, 'guild_id', 'channel_id'> & Pagination): + Promise> + createInvite(param: EitherOr<{ guild_id: string; channel_id: string }, 'guild_id', 'channel_id'> & { duration?: number; setting_times?: number }): + Promise<{ url: string }> + deleteInvite(param: { url_code: string; guild_id?: string; channel_id?: string }): Promise + + getBlacklist(param: { guild_id: string } & Pagination): + Promise> + createBlacklist(param: { guild_id: string; target_id: string; remark?: string; del_msg_days?: 0|1|2|3|4|5|6|7 }): Promise + deleteBlacklist(param: { guild_id: string; target_id: string }): Promise + + // getGuildBadge(param: { guild_id: string; style?: 0|1|2 }): Promise // 未实现 + getGameList(param?: { type?: '0'|'1'|'2' }): Promise> + createGame(param: { name: string; icon?: string }): Promise> + updateGame(param: { id: number; name?: string; icon?: string }): Promise> + deleteGame(param: { id: number }): Promise + createGameActivity(param: { id: number; data_type: 1|2; software?: 'cloudmusic'|'qqmusic'|'kugou'; singer?: string; music_name?: string}): Promise + deleteGameActivity(param: { data_type: 1|2 }): Promise + + hasPermission(permissions: number, permission: Permissions): boolean } type FilterOptional = Pick< @@ -609,7 +656,9 @@ type EitherOr = ) & Omit export class Internal { - constructor(private http: Quester) {} + constructor(private http: Quester) { + Internal.prototype['hasPermission'] = hasPermission + } static define(name: string, method: Quester.Method, path: string) { Internal.prototype[name] = async function (this: Internal, ...args: any[]) { From c5b30b2d654a1991a792a8864876e535f25194c3 Mon Sep 17 00:00:00 2001 From: MODcraft Date: Sun, 2 Apr 2023 23:11:24 +0800 Subject: [PATCH 10/19] mark --- adapters/kook/src/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index a002f360..84e72f3f 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -547,7 +547,7 @@ export interface Internal { token_type: 'Bearer' scope: string }> - createAsset(param: { file: FormData }): Promise<{ url: string }> + // createAsset(param: { file: FormData }): Promise<{ url: string }> getUserMe(): Promise getUserView(param: { user_id: string; guild_id?: string }): Promise @@ -584,7 +584,7 @@ export interface Internal { updateIntimacy(param: { user_id: string; score?: number; social_info?: string; img_id?: string }): Promise getGuildEmojiList(param?: Pagination): Promise> - createGuildEmoji(param: { name?: string; guild_id: string; emoji: FormData }): Promise + // createGuildEmoji(param: { name?: string; guild_id: string; emoji: FormData }): Promise updateGuildEmoji(param: { name: string; id: string }): Promise deleteGuildEmoji(param: { id: string }): Promise From ab594f7c9fef10707520b0590a7c36d52892da30 Mon Sep 17 00:00:00 2001 From: MODcraft Date: Mon, 3 Apr 2023 21:01:58 +0800 Subject: [PATCH 11/19] add kickChannelUser --- adapters/kook/src/types.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index 84e72f3f..13b4a297 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -474,6 +474,7 @@ export interface Internal { }): Promise deleteChannel(param: { channel_id: string }): Promise getChannelUserList(param: { channel_id: string }): Promise> + kickChannelUser(param: { channel_id: string; user_id: string}): Promise moveChannelUser(param: { target_id: string; user_ids: [] }): Promise getChannelRoleIndex(param: { channel_id: string }): Promise<{ permission_overwrites: Overwrite; permission_users: List; permission_sync: 0 | 1 }> createChannelRole(param: { channel_id: string; type?: 'user_id'; value?: string }): @@ -692,6 +693,7 @@ Internal.define('createChannel', 'POST', '/channel/create') Internal.define('updateChannel', 'POST', '/channel/update') Internal.define('deleteChannel', 'POST', '/channel/delete') Internal.define('getChannelUserList', 'GET', '/channel/user-list') +Internal.define('kickChannelUser', 'POST', '/channel/kickout') Internal.define('moveChannelUser', 'POST', '/channel/move-user') Internal.define('getChannelRoleIndex', 'GET', '/channel-role/index') Internal.define('createChannelRole', 'POST', '/channel-role/create') From 7d20476e0ac329cfa785c46d0a93ae3baaa632c5 Mon Sep 17 00:00:00 2001 From: MODcraft Date: Tue, 4 Apr 2023 01:01:20 +0800 Subject: [PATCH 12/19] fix --- adapters/kook/src/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index 13b4a297..b852fc27 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -505,13 +505,13 @@ export interface Internal { getMessageList(param: { target_id: string; msg_id?: string; pin?: 0 | 1; flag?: 'before' | 'around' | 'after' } & Pagination): Promise> getMessageView(param: { msg_id: string }): Promise - createMessage(param: { type?: Type; target_id: string; content: string; quote?: string; nonce?: string; temp_target_id: string }): + createMessage(param: { type?: Type; target_id: string; content: string; quote?: string; nonce?: string; temp_target_id?: string }): Promise<{ msg_id: string msg_timestamp: number nonce: string }> - updateMessage(param: { msg_id: string; content: string; quote?: string; temp_target_id: string }): Promise + updateMessage(param: { msg_id: string; content: string; quote?: string; temp_target_id?: string }): Promise deleteMessage(param: { msg_id: string }): Promise getMessageReactionList(param: { msg_id: string; emoji: string }): Promise addMessageReaction(param: { msg_id: string; emoji: string }): Promise From 94c203091cb786d4da2cd061daefd735da4f7d67 Mon Sep 17 00:00:00 2001 From: MODcraft Date: Sun, 23 Apr 2023 00:25:14 +0800 Subject: [PATCH 13/19] export GuildRole --- adapters/kook/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index b852fc27..48bbce32 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -367,7 +367,7 @@ interface GuildMute { user_ids: string[] } -interface GuildRole { +export interface GuildRole { role_id: number name: string color: number From 8eee87aed89139a2756770ba79825f31f7d113ab Mon Sep 17 00:00:00 2001 From: MODcraft Date: Tue, 25 Apr 2023 20:19:26 +0800 Subject: [PATCH 14/19] fix --- adapters/kook/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index 48bbce32..18554e60 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -435,7 +435,7 @@ interface GuildBoost { interface Game { id: number name: string - type: 0|1|2 + type: 0 | 1 | 2 options: string kmhook_admin: boolean process_name: string[] From 30058ff790236e38852d9e6e588a874978811f98 Mon Sep 17 00:00:00 2001 From: MODcraft Date: Tue, 25 Apr 2023 21:58:15 +0800 Subject: [PATCH 15/19] fix --- adapters/kook/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index 18554e60..d6d523c0 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -405,7 +405,7 @@ export enum Permissions { GUILD_USER_DEAFEN = 24, GUILD_USER_NAME_CHANGE_OTHER = 25, GUILD_USER_MUTE = 26, - CHANNEL_VOICE_BGM = 27 + CHANNEL_VOICE_BGM = 27, } export function hasPermission(permissions: number, permission: Permissions) { From 082f8ae6c1166017442541da0f15dc2a553feeb1 Mon Sep 17 00:00:00 2001 From: MODcraft Date: Tue, 25 Apr 2023 21:59:57 +0800 Subject: [PATCH 16/19] fix --- adapters/kook/src/types.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index d6d523c0..1ccd852a 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -657,9 +657,7 @@ type EitherOr = ) & Omit export class Internal { - constructor(private http: Quester) { - Internal.prototype['hasPermission'] = hasPermission - } + constructor(private http: Quester) {} static define(name: string, method: Quester.Method, path: string) { Internal.prototype[name] = async function (this: Internal, ...args: any[]) { From 3afd1167d37e15555d55090419795b23470ee60a Mon Sep 17 00:00:00 2001 From: MODcraft Date: Tue, 25 Apr 2023 23:22:33 +0800 Subject: [PATCH 17/19] update --- adapters/kook/src/types.ts | 222 +++++++++++++------------------------ 1 file changed, 80 insertions(+), 142 deletions(-) diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index 1ccd852a..7d25c320 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -128,6 +128,12 @@ export interface Message extends MessageBase, MessageMeta { extra: MessageExtra | Notice } +export interface MessageReturn { + msg_id: string + msg_timestamp: number + nonce: string +} + export interface Card { type: 'card' theme?: Card.Theme @@ -300,6 +306,19 @@ export interface NoticeBody extends Channel, MessageMeta { guilds: string[] } +export interface ChannelRoleIndex { + permission_overwrites: Overwrite + permission_users: List + permission_sync: 0 | 1 +} + +export interface ChannelRole { + user_id?: string + role_id?: string + allow: number + deny: number +} + export interface Emoji { id: string name: string @@ -377,6 +396,12 @@ export interface GuildRole { permissions: number } +export interface GuildRoleReturn { + user_id: string + guild_id: string + roles: number[] +} + export enum Permissions { GUILD_ADMIN = 0, GUILD_MANAGE = 1, @@ -412,19 +437,19 @@ export function hasPermission(permissions: number, permission: Permissions) { return (permissions & (1 << permission)) === (1 << permission) } -namespace GuildMute { +export namespace GuildMute { export enum Type { mic = 1, headset = 2, } } -interface GuildMuteList { +export interface GuildMuteList { mic: GuildMute headset: GuildMute } -interface GuildBoost { +export interface GuildBoost { user_id: string guild_id: string start_time: number @@ -432,7 +457,7 @@ interface GuildBoost { user: User } -interface Game { +export interface Game { id: number name: string type: 0 | 1 | 2 @@ -443,6 +468,39 @@ interface Game { icon: string } +export interface AccessToken { + access_token: string + expires_in?: number + token_type: 'Bearer' + scope: string +} + +export interface Intimacy { + img_url: string + social_info: string + last_read: number + score: number + img_list: { + id: string + url: string + }[] +} + +export interface Invite { + guild_id: string + channel_id: string + url_code: string + url: string + user: User +} + +export interface BlackList { + user_id: string + created_time: number + remark: string + user: User +} + export interface Internal { getGuildList(param?: Pagination): Promise> getGuildView(param: { guild_id: string }): Promise @@ -457,60 +515,22 @@ export interface Internal { getChannelList(param: { guild_id: string } & Pagination): Promise> getChannelView(param: { target_id: string }): Promise - createChannel(param: { - guild_id: string - parent_id?: string - name: string - type?: number - limit_amount?: number - voice_quality?: string - is_category?: 0|1 - }): Promise - updateChannel(param: { - channel_id: string - name?: string - topic?: string - slow_mode?: 0|5000|10000|15000|30000|60000|120000|300000|600000|900000|1800000|3600000|7200000|21600000 - }): Promise + createChannel(param: { guild_id: string; parent_id?: string; name: string; type?: number; limit_amount?: number; voice_quality?: string; is_category?: 0|1 }): Promise + updateChannel(param: { channel_id: string; name?: string; topic?: string; slow_mode?: 0|5000|10000|15000|30000|60000|120000|300000|600000|900000|1800000|3600000|7200000|21600000 }): Promise deleteChannel(param: { channel_id: string }): Promise getChannelUserList(param: { channel_id: string }): Promise> kickChannelUser(param: { channel_id: string; user_id: string}): Promise moveChannelUser(param: { target_id: string; user_ids: [] }): Promise - getChannelRoleIndex(param: { channel_id: string }): Promise<{ permission_overwrites: Overwrite; permission_users: List; permission_sync: 0 | 1 }> - createChannelRole(param: { channel_id: string; type?: 'user_id'; value?: string }): - Promise<{ - user_id: string - allow: number - deny: number - }> - createChannelRole(param: { channel_id: string; type: 'role_id'; value?: string }): - Promise<{ - role_id: string - allow: number - deny: number - }> - updateChannelRole(param: { channel_id: string; type?: 'user_id'; value?: string; allow?: number; deny?: number }): - Promise<{ - user_id: string - allow: number - deny: number - }> - updateChannelRole(param: { channel_id: string; type: 'role_id'; value?: string; allow?: number; deny?: number }): - Promise<{ - role_id: string - allow: number - deny: number - }> + getChannelRoleIndex(param: { channel_id: string }): Promise + createChannelRole(param: { channel_id: string; type?: 'user_id'; value?: string }): Promise> + createChannelRole(param: { channel_id: string; type: 'role_id'; value?: string }): Promise> + updateChannelRole(param: { channel_id: string; type?: 'user_id'; value?: string; allow?: number; deny?: number }): Promise> + updateChannelRole(param: { channel_id: string; type: 'role_id'; value?: string; allow?: number; deny?: number }): Promise> deleteChannelRole(param: { channel_id: string; type?: 'role_id' | 'user_id'; value?: string }): Promise getMessageList(param: { target_id: string; msg_id?: string; pin?: 0 | 1; flag?: 'before' | 'around' | 'after' } & Pagination): Promise> getMessageView(param: { msg_id: string }): Promise - createMessage(param: { type?: Type; target_id: string; content: string; quote?: string; nonce?: string; temp_target_id?: string }): - Promise<{ - msg_id: string - msg_timestamp: number - nonce: string - }> + createMessage(param: { type?: Type; target_id: string; content: string; quote?: string; nonce?: string; temp_target_id?: string }): Promise updateMessage(param: { msg_id: string; content: string; quote?: string; temp_target_id?: string }): Promise deleteMessage(param: { msg_id: string }): Promise getMessageReactionList(param: { msg_id: string; emoji: string }): Promise @@ -524,16 +544,8 @@ export interface Internal { createPrivateChat(param: { target_id: string }): Promise deletePrivateChat(param: { chat_code: string }): Promise - getDirectMessageList(param: EitherOr<{ target_id: string; chat_code: string }, 'target_id', 'chat_code'> & - { msg_id?: string; flag?: 'before' | 'around' | 'after' } & Pagination): - Promise<{ items: Message[] }> - createDirectMessage(param: { type?: Type; content: string; quote?: string; nonce?: string} & - EitherOr<{ target_id: string; chat_code: string }, 'target_id', 'chat_code'>): - Promise<{ - msg_id: string - msg_timestamp: number - nonce: string - }> + getDirectMessageList(param: { target_id?: string; chat_code?: string; msg_id?: string; flag?: 'before' | 'around' | 'after' } & Pagination): Promise<{ items: Message[] }> + createDirectMessage(param: { target_id?: string; chat_code?: string; type?: Type; content: string; quote?: string; nonce?: string}): Promise updateDirectMessage(param: { msg_id: string; content: string; quote?: string}): Promise deleteDirectMessage(param: { msg_id: string }): Promise getDirectMessageReactionList(param: { msg_id: string; emoji?: string}): Promise @@ -541,13 +553,7 @@ export interface Internal { deleteDirectMessageReaction(param: { msg_id: string; emoji: string; user_id?: string }): Promise getGateway(param: { compress?: 0|1 }): Promise<{ url: string }> - getToken(param: { grant_type: 'authorization_code'; client_id: string; client_secret: string; code: string; redirect_uri: string}): - Promise<{ - access_token: string - expires_in?: number - token_type: 'Bearer' - scope: string - }> + getToken(param: { grant_type: 'authorization_code'; client_id: string; client_secret: string; code: string; redirect_uri: string}): Promise // createAsset(param: { file: FormData }): Promise<{ url: string }> getUserMe(): Promise @@ -558,30 +564,10 @@ export interface Internal { createGuildRole(param: { name?: string; guild_id: string }): Promise updateGuildRole(param: { guild_id: string; role_id: number } & Partial>): Promise deleteGuildRole(param: { guild_id: string; role_id: number }): Promise - grantGuildRole(param: { guild_id: string; user_id?: string; role_id: number }): - Promise<{ - user_id: string - guild_id: string - roles: number[] - }> - revokeGuildRole(param: { guild_id: string; user_id?: string; role_id: number }): - Promise<{ - user_id: string - guild_id: string - roles: number[] - }> - - getIntimacy(param: { user_id: string }): - Promise<{ - img_url: string - social_info: string - last_read: number - score: number - img_list: { - id: string - url: string - }[] - }> + grantGuildRole(param: { guild_id: string; user_id?: string; role_id: number }): Promise + revokeGuildRole(param: { guild_id: string; user_id?: string; role_id: number }): Promise + + getIntimacy(param: { user_id: string }): Promise updateIntimacy(param: { user_id: string; score?: number; social_info?: string; img_id?: string }): Promise getGuildEmojiList(param?: Pagination): Promise> @@ -589,25 +575,11 @@ export interface Internal { updateGuildEmoji(param: { name: string; id: string }): Promise deleteGuildEmoji(param: { id: string }): Promise - getInviteList(param: EitherOr<{ guild_id: string; channel_id: string }, 'guild_id', 'channel_id'> & Pagination): - Promise> - createInvite(param: EitherOr<{ guild_id: string; channel_id: string }, 'guild_id', 'channel_id'> & { duration?: number; setting_times?: number }): - Promise<{ url: string }> + getInviteList(param: { guild_id?: string; channel_id?: string } & Pagination): Promise> + createInvite(param: { guild_id?: string; channel_id?: string; duration?: number; setting_times?: number }): Promise<{ url: string }> deleteInvite(param: { url_code: string; guild_id?: string; channel_id?: string }): Promise - getBlacklist(param: { guild_id: string } & Pagination): - Promise> + getBlacklist(param: { guild_id: string } & Pagination): Promise> createBlacklist(param: { guild_id: string; target_id: string; remark?: string; del_msg_days?: 0|1|2|3|4|5|6|7 }): Promise deleteBlacklist(param: { guild_id: string; target_id: string }): Promise @@ -622,40 +594,6 @@ export interface Internal { hasPermission(permissions: number, permission: Permissions): boolean } -type FilterOptional = Pick< - T, - Exclude< - { - [K in keyof T]: T extends Record ? K : never; - }[keyof T], - undefined - > -> - -type FilterNotOptional = Pick< - T, - Exclude< - { - [K in keyof T]: T extends Record ? never : K; - }[keyof T], - undefined - > -> - -type PartialEither = { [P in Exclude, K>]-?: T[P] } & - { [P in Exclude, K>]?: T[P] } & - { [P in Extract]?: undefined } - -type Object = { - [name: string]: any -} - -type EitherOr = - ( - PartialEither, L> | - PartialEither, R> - ) & Omit - export class Internal { constructor(private http: Quester) {} From 515b4d66ef34acb3bd0f403bf65d217ff952d95c Mon Sep 17 00:00:00 2001 From: MODcraft Date: Tue, 25 Apr 2023 23:24:01 +0800 Subject: [PATCH 18/19] disable eslint max-len --- adapters/kook/src/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index 7d25c320..e030bf74 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -1,3 +1,4 @@ +/* eslint-disable max-len */ import { Quester } from '@satorijs/satori' export enum Signal { From e7be3056404e0cc751b7b397ed28a3cde88d2d1c Mon Sep 17 00:00:00 2001 From: MODcraft Date: Tue, 25 Apr 2023 23:28:38 +0800 Subject: [PATCH 19/19] update --- adapters/kook/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index e030bf74..c3ca7ff6 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -585,7 +585,7 @@ export interface Internal { deleteBlacklist(param: { guild_id: string; target_id: string }): Promise // getGuildBadge(param: { guild_id: string; style?: 0|1|2 }): Promise // 未实现 - getGameList(param?: { type?: '0'|'1'|'2' }): Promise> + getGameList(param?: { type?: 0 | 1 | 2 }): Promise> createGame(param: { name: string; icon?: string }): Promise> updateGame(param: { id: number; name?: string; icon?: string }): Promise> deleteGame(param: { id: number }): Promise