Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
idranme authored Nov 29, 2024
2 parents bb72b1d + 8b20e2a commit dac6868
Show file tree
Hide file tree
Showing 30 changed files with 3,165 additions and 4,234 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ jobs:
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
- name: Enable Corepack
run: corepack enable
- name: Install
run: yarn
run: yarn --no-immutable
- name: Lint
run: yarn lint

Expand All @@ -26,8 +28,10 @@ jobs:
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
- name: Enable Corepack
run: corepack enable
- name: Install
run: yarn
run: yarn --no-immutable
- name: Build
run: yarn build

Expand All @@ -46,8 +50,10 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Enable Corepack
run: corepack enable
- name: Install
run: yarn
run: yarn --no-immutable
- name: Unit Test
run: yarn test:json
- name: Report Coverage
Expand Down
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
4 changes: 2 additions & 2 deletions adapters/dingtalk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
"devDependencies": {
"@cordisjs/plugin-server": "^0.2.4",
"@cordisjs/plugin-server-temp": "^0.5.0",
"@satorijs/core": "^4.2.11",
"@satorijs/core": "^4.2.12",
"cordis": "^3.18.1"
},
"peerDependencies": {
"@satorijs/core": "^4.2.11"
"@satorijs/core": "^4.2.12"
}
}
4 changes: 2 additions & 2 deletions adapters/discord/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
"chat"
],
"devDependencies": {
"@satorijs/core": "^4.2.11",
"@satorijs/core": "^4.2.12",
"cordis": "^3.18.1"
},
"peerDependencies": {
"@satorijs/core": "^4.2.11"
"@satorijs/core": "^4.2.12"
}
}
4 changes: 2 additions & 2 deletions adapters/kook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
],
"devDependencies": {
"@cordisjs/plugin-server": "^0.2.4",
"@satorijs/core": "^4.2.11",
"@satorijs/core": "^4.2.12",
"cordis": "^3.18.1"
},
"peerDependencies": {
"@satorijs/core": "^4.2.11"
"@satorijs/core": "^4.2.12"
}
}
6 changes: 3 additions & 3 deletions adapters/lark/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@satorijs/adapter-lark",
"description": "Lark (飞书) Adapter for Satorijs",
"version": "3.6.2",
"version": "3.7.4",
"type": "module",
"main": "lib/index.cjs",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -35,10 +35,10 @@
],
"devDependencies": {
"@cordisjs/plugin-server": "^0.2.4",
"@satorijs/core": "^4.2.11",
"@satorijs/core": "^4.2.12",
"cordis": "^3.18.1"
},
"peerDependencies": {
"@satorijs/core": "^4.2.11"
"@satorijs/core": "^4.2.12"
}
}
26 changes: 13 additions & 13 deletions adapters/lark/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,46 +89,46 @@ export class LarkBot<C extends Context = Context> extends Bot<C, LarkBot.Config>

async getMessage(channelId: string, messageId: string, recursive = true) {
const data = await this.internal.getImMessage(messageId)
const message = await Utils.decodeMessage(this, data.data.items[0], recursive)
const message = await Utils.decodeMessage(this, data.items[0], recursive)
const im = await this.internal.getImChat(channelId)
message.channel.type = im.data.chat_mode === 'p2p' ? Universal.Channel.Type.DIRECT : Universal.Channel.Type.TEXT
message.channel.type = im.chat_mode === 'p2p' ? Universal.Channel.Type.DIRECT : Universal.Channel.Type.TEXT
return message
}

async getMessageList(channelId: string, before?: string) {
const { data: messages } = await this.internal.listImMessage({ container_id_type: 'chat', container_id: channelId, page_token: before })
const messages = await this.internal.listImMessage({ container_id_type: 'chat', container_id: channelId, page_token: before })
const data = await Promise.all(messages.items.reverse().map(data => Utils.decodeMessage(this, data)))
return { data, next: data[0]?.id }
}

async getUser(userId: string, guildId?: string) {
const data = await this.internal.getContactUser(userId)
return Utils.decodeUser(data.data.user)
return Utils.decodeUser(data.user)
}

async getChannel(channelId: string) {
const { data } = await this.internal.getImChat(channelId)
return Utils.decodeChannel(channelId, data)
const chat = await this.internal.getImChat(channelId)
return Utils.decodeChannel(channelId, chat)
}

async getChannelList(guildId: string) {
return { data: [await this.getChannel(guildId)] }
}

async getGuild(guildId: string) {
const { data } = await this.internal.getImChat(guildId)
return Utils.decodeGuild(data)
const chat = await this.internal.getImChat(guildId)
return Utils.decodeGuild(chat)
}

async getGuildList(after?: string) {
const { data: guilds } = await this.internal.listImChat({ page_token: after })
return { data: guilds.items.map(Utils.decodeGuild), next: guilds.page_token }
const chats = await this.internal.listImChat({ page_token: after })
return { data: chats.items.map(Utils.decodeGuild), next: chats.page_token }
}

async getGuildMemberList(guildId: string, after?: string) {
const { data: users } = await this.internal.getImChatMembers(guildId, { page_token: after })
const data = users.items.map(v => ({ user: { id: v.member_id, name: v.name }, name: v.name }))
return { data, next: users.page_token }
const members = await this.internal.getImChatMembers(guildId, { page_token: after })
const data = members.items.map(v => ({ user: { id: v.member_id, name: v.name }, name: v.name }))
return { data, next: members.page_token }
}
}

Expand Down
60 changes: 39 additions & 21 deletions adapters/lark/src/message.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Context, Dict, h, MessageEncoder } from '@satorijs/core'
import { LarkBot } from './bot'
import { BaseResponse, Lark, MessageContent } from './types'
import { CreateImFileForm, Lark, MessageContent } from './types'
import { extractIdType } from './utils'

export class LarkMessageEncoder<C extends Context = Context> extends MessageEncoder<C, LarkBot<C>> {
Expand All @@ -13,7 +13,7 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco

async post(data?: any) {
try {
let resp: BaseResponse & { data?: Lark.Message }
let resp: Lark.Message
if (this.quote?.id) {
resp = await this.bot.internal.replyImMessage(this.quote.id, {
...data,
Expand All @@ -26,9 +26,9 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
})
}
const session = this.bot.session()
session.messageId = resp.data.message_id
session.timestamp = Number(resp.data.create_time) * 1000
session.userId = resp.data.sender.id
session.messageId = resp.message_id
session.timestamp = Number(resp.create_time) * 1000
session.userId = resp.sender.id
session.channelId = this.channelId
session.guildId = this.guildId
session.app.emit(session, 'send', session)
Expand Down Expand Up @@ -93,40 +93,43 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco

async createImage(url: string) {
const { filename, type, data } = await this.bot.assetsQuester.file(url)
const payload = new FormData()
payload.append('image', new Blob([data], { type }), filename)
payload.append('image_type', 'message')
const { data: { image_key } } = await this.bot.internal.createImImage(payload)
const { image_key } = await this.bot.internal.createImImage({
image_type: 'message',
image: new File([data], filename, { type }),
})
return image_key
}

async sendFile(_type: 'video' | 'audio' | 'file', attrs: any) {
const url = attrs.src || attrs.url
const payload = new FormData()
const { filename, type, data } = await this.bot.assetsQuester.file(url)
payload.append('file', new Blob([data], { type }), filename)
payload.append('file_name', filename)

if (attrs.duration) {
payload.append('duration', attrs.duration)
}

let file_type: CreateImFileForm['file_type']
if (_type === 'audio') {
// FIXME: only support opus
payload.append('file_type', 'opus')
file_type = 'opus'
} else if (_type === 'video') {
// FIXME: only support mp4
payload.append('file_type', 'mp4')
file_type = 'mp4'
} else {
const ext = filename.split('.').pop()
if (['doc', 'xls', 'ppt', 'pdf'].includes(ext)) {
payload.append('file_type', ext)
file_type = ext
} else {
payload.append('file_type', 'stream')
file_type = 'stream'
}
}

const { data: { file_key } } = await this.bot.internal.createImFile(payload)
const form: CreateImFileForm = {
file_type,
file: new File([data], filename, { type }),
file_name: filename,
}
if (attrs.duration) {
form.duration = attrs.duration
}

const { file_key } = await this.bot.internal.createImFile(form)
await this.post({
msg_type: _type === 'video' ? 'media' : _type,
content: JSON.stringify({ file_key }),
Expand Down Expand Up @@ -236,6 +239,21 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
},
disabled: attrs.disabled,
behaviors: this.createBehavior(attrs),
type: attrs['lark:type'],
size: attrs['lark:size'],
width: attrs['lark:width'],
icon: attrs['lark:icon'] && {
tag: 'standard_icon',
token: attrs['lark:icon'],
},
hover_tips: attrs['lark:hover-tips'] && {
tag: 'plain_text',
content: attrs['lark:hover-tips'],
},
disabled_tips: attrs['lark:disabled-tips'] && {
tag: 'plain_text',
content: attrs['lark:disabled-tips'],
},
})
this.textContent = ''
} else if (type === 'button-group') {
Expand Down
Loading

0 comments on commit dac6868

Please sign in to comment.