diff --git a/adapters/dingtalk/src/internal.ts b/adapters/dingtalk/src/internal.ts index 00d73bd2..ba72a3e1 100644 --- a/adapters/dingtalk/src/internal.ts +++ b/adapters/dingtalk/src/internal.ts @@ -16,7 +16,7 @@ export class Internal { if (!args.length) throw new Error(`too few arguments for ${path}, received ${raw}`) return args.shift() }) - const config: Quester.AxiosRequestConfig = {} + const config: Quester.RequestConfig = {} if (args.length === 1) { if (method === 'GET' || method === 'DELETE') { config.params = args[0] diff --git a/adapters/dingtalk/src/message.ts b/adapters/dingtalk/src/message.ts index 84bbc079..6d940b09 100644 --- a/adapters/dingtalk/src/message.ts +++ b/adapters/dingtalk/src/message.ts @@ -95,7 +95,7 @@ export class DingtalkMessageEncoder extends Message // await this.sendMessage('sampleImageMsg', { // photoURL: src, // }) - if (await this.bot.http.isPrivate(src)) { + if (await this.bot.http.isLocal(src)) { const temp = this.bot.ctx.get('server.temp') if (!temp) { return this.bot.logger.warn('missing temporary file service, cannot send assets with private url') diff --git a/adapters/discord/src/message.ts b/adapters/discord/src/message.ts index b1e60d73..bf751812 100644 --- a/adapters/discord/src/message.ts +++ b/adapters/discord/src/message.ts @@ -112,7 +112,7 @@ export class DiscordMessageEncoder extends MessageE return this.post({ ...addition, content: attrs.src || attrs.url }) } - if (await this.bot.http.isPrivate(attrs.src || attrs.url)) { + if (await this.bot.http.isLocal(attrs.src || attrs.url)) { return await this.sendEmbed(attrs, addition) } diff --git a/adapters/discord/src/types/internal.ts b/adapters/discord/src/types/internal.ts index 04be3ef1..cb627fbb 100644 --- a/adapters/discord/src/types/internal.ts +++ b/adapters/discord/src/types/internal.ts @@ -15,7 +15,7 @@ export class Internal { if (!args.length) throw new Error(`too few arguments for ${path}, received ${raw}`) return args.shift() }) - const config: Quester.AxiosRequestConfig = {} + const config: Quester.RequestConfig = {} if (args.length === 1) { if (method === 'GET' || method === 'DELETE') { config.params = args[0] diff --git a/adapters/kook/src/message.ts b/adapters/kook/src/message.ts index 2dbd063f..dbef84fe 100644 --- a/adapters/kook/src/message.ts +++ b/adapters/kook/src/message.ts @@ -51,7 +51,7 @@ export class KookMessageEncoder extends MessageEnco private async transformUrl({ type, attrs }: h) { const src = attrs.src || attrs.url - if (await this.bot.http.isPrivate(src)) { + if (await this.bot.http.isLocal(src)) { const payload = new FormData() const result = await this.bot.ctx.http.file(src, attrs) payload.append('file', Buffer.from(result.data), { diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index 2dfd1444..a24a3189 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -665,15 +665,15 @@ export class Internal { static define(name: string, method: Quester.Method, path: string) { Internal.prototype[name] = async function (this: Internal, ...args: any[]) { - const config: Quester.AxiosRequestConfig = {} + const config: Quester.RequestConfig = {} if (method === 'GET' || method === 'DELETE') { config.params = args[0] } else { config.data = args[0] } - const req = await this.http(method, path, config) - if (req?.code !== 0) throw new Error(req?.message || 'Unexpected Error') - return req?.data + const { data } = await this.http(method, path, config) + if (data?.code !== 0) throw new Error(data?.message || 'Unexpected Error') + return data?.data } } } diff --git a/adapters/lark/src/http.ts b/adapters/lark/src/http.ts index d7083c4e..855788c7 100644 --- a/adapters/lark/src/http.ts +++ b/adapters/lark/src/http.ts @@ -85,7 +85,7 @@ export class HttpServer extends Adapter bot.selfId === selfId) if (!bot) return ctx.status = 404 - const resp = await bot.http.axios(`/im/v1/messages/${messageId}/resources/${key}`, { + const resp = await bot.http(`/im/v1/messages/${messageId}/resources/${key}`, { method: 'GET', params: { type }, responseType: 'stream', diff --git a/adapters/lark/src/types/internal.ts b/adapters/lark/src/types/internal.ts index 22625f78..ee9af685 100644 --- a/adapters/lark/src/types/internal.ts +++ b/adapters/lark/src/types/internal.ts @@ -37,7 +37,7 @@ export class Internal { if (!args.length) throw new Error(`too few arguments for ${path}, received ${raw}`) return args.shift() }) - const config: Quester.AxiosRequestConfig = {} + const config: Quester.RequestConfig = {} if (args.length === 1) { if (method === 'GET' || method === 'DELETE') { config.params = args[0] diff --git a/adapters/lark/src/utils.ts b/adapters/lark/src/utils.ts index e98a9062..8d46361d 100644 --- a/adapters/lark/src/utils.ts +++ b/adapters/lark/src/utils.ts @@ -1,6 +1,5 @@ import crypto from 'crypto' -import { Channel, Guild, Message, User } from '@satorijs/protocol' -import { Context, h, Session, trimSlash } from '@satorijs/satori' +import { Context, h, Session, trimSlash, Universal } from '@satorijs/satori' import { FeishuBot, LarkBot } from './bot' import { AllEvents, Events, Lark, Message as LarkMessage, MessageContentType, MessageType } from './types' @@ -86,7 +85,7 @@ export function adaptSession(bot: FeishuBot, body: AllEven } // TODO: This function has many duplicated code with `adaptMessage`, should refactor them -export async function decodeMessage(bot: LarkBot, body: LarkMessage): Promise { +export async function decodeMessage(bot: LarkBot, body: LarkMessage): Promise { const json = JSON.parse(body.body.content) as MessageContentType const assetEndpoint = trimSlash(bot.config.selfUrl ?? bot.ctx.server.config.selfUrl) + bot.config.path + '/assets' const content: h[] = [] @@ -146,16 +145,16 @@ export function extractIdType(id: string): Lark.ReceiveIdType { return 'user_id' } -export function decodeChannel(guild: Lark.Guild): Channel { +export function decodeChannel(guild: Lark.Guild): Universal.Channel { return { id: guild.chat_id, - type: Channel.Type.TEXT, + type: Universal.Channel.Type.TEXT, name: guild.name, parentId: guild.chat_id, } } -export function decodeGuild(guild: Lark.Guild): Guild { +export function decodeGuild(guild: Lark.Guild): Universal.Guild { return { id: guild.chat_id, name: guild.name, @@ -163,7 +162,7 @@ export function decodeGuild(guild: Lark.Guild): Guild { } } -export function decodeUser(user: Lark.User): User { +export function decodeUser(user: Lark.User): Universal.User { return { id: user.open_id, avatar: user.avatar?.avatar_origin, diff --git a/adapters/line/src/types/internal.ts b/adapters/line/src/types/internal.ts index 976ab4d3..98f9d5d4 100644 --- a/adapters/line/src/types/internal.ts +++ b/adapters/line/src/types/internal.ts @@ -14,7 +14,7 @@ export class Internal { if (!args.length) throw new Error(`too few arguments for ${path}, received ${raw}`) return args.shift() }) - const config: Quester.AxiosRequestConfig = {} + const config: Quester.RequestConfig = {} if (args.length === 1) { if (method === 'GET' || method === 'DELETE') { config.params = args[0] diff --git a/adapters/qq/src/bot/index.ts b/adapters/qq/src/bot/index.ts index c2617214..844ad6a1 100644 --- a/adapters/qq/src/bot/index.ts +++ b/adapters/qq/src/bot/index.ts @@ -62,9 +62,8 @@ export class QQBot extends Bot { async _ensureAccessToken() { try { - const result = await this.ctx.http.axios({ - url: 'https://bots.qq.com/app/getAppAccessToken', - method: 'post', + const result = await this.ctx.http('https://bots.qq.com/app/getAppAccessToken', { + method: 'POST', data: { appId: this.config.id, clientSecret: this.config.secret, diff --git a/adapters/qq/src/internal/internal.ts b/adapters/qq/src/internal/internal.ts index 888c0a6f..be68f9b5 100644 --- a/adapters/qq/src/internal/internal.ts +++ b/adapters/qq/src/internal/internal.ts @@ -14,7 +14,7 @@ export class Internal { if (!args.length) throw new Error(`too few arguments for ${path}, received ${raw}`) return args.shift() }) - const config: Quester.AxiosRequestConfig = {} + const config: Quester.RequestConfig = {} if (args.length === 1) { if (method === 'GET' || method === 'DELETE') { config.params = args[0] diff --git a/adapters/qq/src/message.ts b/adapters/qq/src/message.ts index ecaf94a4..fb573797 100644 --- a/adapters/qq/src/message.ts +++ b/adapters/qq/src/message.ts @@ -144,7 +144,7 @@ export class QQGuildMessageEncoder extends MessageE } async resolveFile(attrs: Dict, download = false) { - if (!download && !await this.bot.ctx.http.isPrivate(attrs.src || attrs.url)) { + if (!download && !await this.bot.ctx.http.isLocal(attrs.src || attrs.url)) { return this.fileUrl = attrs.src || attrs.url } const { data, filename } = await this.bot.ctx.http.file(this.fileUrl || attrs.src || attrs.url, attrs) @@ -305,7 +305,7 @@ export class QQMessageEncoder extends MessageEncode async sendFile(type: string, attrs: Dict) { let url = attrs.src || attrs.url, entry: Entry | undefined - if (await this.bot.ctx.http.isPrivate(url)) { + if (await this.bot.ctx.http.isLocal(url)) { const temp = this.bot.ctx.get('server.temp') if (!temp) { return this.bot.logger.warn('missing temporary file service, cannot send assets with private url') diff --git a/adapters/qq/src/utils.ts b/adapters/qq/src/utils.ts index b9fbbc87..ca240b4c 100644 --- a/adapters/qq/src/utils.ts +++ b/adapters/qq/src/utils.ts @@ -1,7 +1,6 @@ import { Bot, Context, h, Session, Universal } from '@satorijs/satori' import * as QQ from './types' import { QQBot } from './bot' -import { unescape } from '@satorijs/element' export const decodeGuild = (guild: QQ.Guild): Universal.Guild => ({ id: guild.id, @@ -75,7 +74,7 @@ export async function decodeMessage( .reduce((content, attachment) => content + h.image('https://' + attachment.url), message.content) message.elements = h.parse(message.content) message.elements = h.transform(message.elements, { - text: (attrs) => unescape(attrs.content), + text: (attrs) => h.unescape(attrs.content), }) if (data.message_reference) { diff --git a/adapters/slack/src/bot.ts b/adapters/slack/src/bot.ts index 5bdf29d1..32117d76 100644 --- a/adapters/slack/src/bot.ts +++ b/adapters/slack/src/bot.ts @@ -29,14 +29,14 @@ export class SlackBot(method: Quester.Method, path: string, data = {}, headers: any = {}, zap: boolean = false): Promise { headers['Authorization'] = `Bearer ${zap ? this.config.token : this.config.botToken}` if (method === 'GET') { - return (await this.http.get(path, { params: data, headers })).data + return await this.http.get(path, { params: data, headers }) } else { if (!headers['content-type']) { data = data instanceof FormData ? data : JSON.stringify(data) const type = data instanceof FormData ? 'multipart/form-data' : 'application/json; charset=utf-8' headers['content-type'] = type } - return (await this.http(method, path, { data, headers })) + return (await this.http(method, path, { data, headers })).data } } diff --git a/adapters/slack/src/types/internal.ts b/adapters/slack/src/types/internal.ts index 132735fd..80afc1f8 100644 --- a/adapters/slack/src/types/internal.ts +++ b/adapters/slack/src/types/internal.ts @@ -23,7 +23,7 @@ export class Internal { const method = key as Quester.Method for (const name of Object.keys(routes[path][method])) { Internal.prototype[name] = async function (this: Internal, ...args: any[]) { - const config: Quester.AxiosRequestConfig = { + const config: Quester.RequestConfig = { headers: {}, } let token = '' diff --git a/adapters/wechat-official/src/http.ts b/adapters/wechat-official/src/http.ts index d4ac5457..b64462ef 100644 --- a/adapters/wechat-official/src/http.ts +++ b/adapters/wechat-official/src/http.ts @@ -108,7 +108,7 @@ export class HttpServer extends Adapter bot.selfId === selfId) if (!localBot) return ctx.status = 404 - const resp = await localBot.http.axios(`/cgi-bin/media/get`, { + const resp = await localBot.http(`/cgi-bin/media/get`, { method: 'GET', responseType: 'stream', params: { diff --git a/adapters/wecom/src/http.ts b/adapters/wecom/src/http.ts index 2ae627a0..1b566292 100644 --- a/adapters/wecom/src/http.ts +++ b/adapters/wecom/src/http.ts @@ -69,7 +69,7 @@ export class HttpServer extends Adapter bot.selfId === selfId) if (!localBot) return ctx.status = 404 - const resp = await localBot.http.axios(`/cgi-bin/media/get`, { + const resp = await localBot.http(`/cgi-bin/media/get`, { method: 'GET', responseType: 'stream', params: { diff --git a/adapters/whatsapp/src/adapter.ts b/adapters/whatsapp/src/adapter.ts index e1ec732e..23988617 100644 --- a/adapters/whatsapp/src/adapter.ts +++ b/adapters/whatsapp/src/adapter.ts @@ -68,8 +68,7 @@ class HttpServer { const fetched = await bot.internal.getMedia(mediaId) this.logger.debug(fetched.url) - const resp = await bot.ctx.http.axios({ - url: fetched.url, + const resp = await bot.ctx.http(fetched.url, { method: 'GET', responseType: 'stream', }) diff --git a/adapters/zulip/src/bot.ts b/adapters/zulip/src/bot.ts index 719e8e93..4a01e02c 100644 --- a/adapters/zulip/src/bot.ts +++ b/adapters/zulip/src/bot.ts @@ -103,7 +103,7 @@ export class ZulipBot extends Bot extends Adapter = Schema.object({ + export const Options: Schema = Schema.object({ protocol: Schema.const('polling').required(process.env.KOISHI_ENV !== 'browser'), // pollingTimeout: Schema.natural().role('ms').default(Time.second * 25).description('通过长轮询获取更新时请求的超时 (单位为毫秒)。'), retryTimes: Schema.natural().description('连接时的最大重试次数。').default(6), diff --git a/adapters/zulip/src/types/internal.ts b/adapters/zulip/src/types/internal.ts index a6085796..f16220f4 100644 --- a/adapters/zulip/src/types/internal.ts +++ b/adapters/zulip/src/types/internal.ts @@ -14,7 +14,7 @@ export class Internal { if (!args.length) throw new Error(`too few arguments for ${path}, received ${raw}`) return args.shift() }) - const config: Quester.AxiosRequestConfig = {} + const config: Quester.RequestConfig = {} if (args.length === 1) { if (method === 'GET' || method === 'DELETE') { config.params = args[0]