Skip to content

Commit

Permalink
Merge branch 'master' into slash-fix-2
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 20, 2023
2 parents c9e6496 + 76eaa4c commit 448b849
Show file tree
Hide file tree
Showing 94 changed files with 6,167 additions and 102 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
- [ ] @satorijs/database
- [ ] @satorijs/server
- Ecosystem
- [x] DingTalk
- [x] Discord
- [x] Telegram
- [x] OneBot (v11)
- [x] QQ Guild
- [x] KOOK (开黑啦)
- [x] Lark (飞书)
- [x] Line
- [ ] Whatsapp
- [ ] Slack
- [ ] Dingding
- [ ] Wecom
- [x] Mail
- [x] Matrix
- [x] OneBot (v11,可用于 QQ)
- [x] QQ Guild
- [x] Slack
- [x] Telegram
- [x] WhatsApp
- [ ] WeCom (企业微信)
- [ ] Wechat Official (微信公众号)

## Examples

Expand Down
4 changes: 2 additions & 2 deletions adapters/dingtalk/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@satorijs/adapter-dingtalk",
"description": "Dingtalk Adapter for Satorijs",
"version": "1.0.0",
"version": "1.0.1",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand All @@ -26,6 +26,6 @@
"satori"
],
"peerDependencies": {
"@satorijs/satori": "^2.5.3"
"@satorijs/satori": "^2.6.1"
}
}
5 changes: 5 additions & 0 deletions adapters/dingtalk/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [@satorijs/adapter-dingtalk](https://koishi.chat/plugins/adapter/dingtalk.html)

DingTalk (钉钉) adapter for [Satori](https://github.com/satorijs/satori).

- [Documentation](https://koishi.chat/plugins/adapter/dingtalk.html)
2 changes: 2 additions & 0 deletions adapters/dingtalk/src/api/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rules:
max-len: off
2 changes: 1 addition & 1 deletion adapters/dingtalk/src/api/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface GetOrgAuthInfoResponse {
}

export interface BatchApproveUnionApplyParams {
/** 申请的合作伙伴组织CorpId,参考[基础概念-CorpId](https://open.dingtalk.com/document/org/basic-concepts)。 */
/** 申请的合作伙伴组织 CorpId,参考[基础概念-CorpId](https://open.dingtalk.com/document/org/basic-concepts)。 */
branchCorpId?: string
/** 合作伙伴组织在上下游组织内的名称。 */
unionRootName?: string
Expand Down
6 changes: 3 additions & 3 deletions adapters/dingtalk/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ export class DingtalkBot extends Bot<DingtalkBot.Config> {
static MessageEncoder = DingtalkMessageEncoder
public oldHttp: Quester
public http: Quester
refreshTokenTimer: NodeJS.Timeout
public internal: Internal
refreshTokenTimer: NodeJS.Timeout

constructor(ctx: Context, config: DingtalkBot.Config) {
super(ctx, config)
this.platform = 'dingtalk'
this.http = ctx.http.extend(config.api)
this.oldHttp = ctx.http.extend(config.oldApi)
this.internal = new Internal(this)
Expand Down Expand Up @@ -106,5 +108,3 @@ export namespace DingtalkBot {
WsClient.Config,
])
}

DingtalkBot.prototype.platform = 'dingtalk'
4 changes: 2 additions & 2 deletions adapters/discord/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@satorijs/adapter-discord",
"description": "Discord Adapter for Satorijs",
"version": "3.8.4",
"version": "3.8.5",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand Down Expand Up @@ -29,7 +29,7 @@
"satori"
],
"peerDependencies": {
"@satorijs/satori": "^2.6.0"
"@satorijs/satori": "^2.6.1"
},
"dependencies": {
"form-data": "^4.0.0"
Expand Down
5 changes: 5 additions & 0 deletions adapters/discord/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [@satorijs/adapter-discord](https://koishi.chat/plugins/adapter/discord.html)

Discord adapter for [Satori](https://github.com/satorijs/satori).

- [Documentation](https://koishi.chat/plugins/adapter/discord.html)
3 changes: 1 addition & 2 deletions adapters/discord/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class DiscordBot extends Bot<DiscordBot.Config> {

constructor(ctx: Context, config: DiscordBot.Config) {
super(ctx, config)
this.platform = 'discord'
this.http = ctx.http.extend({
...config,
headers: {
Expand Down Expand Up @@ -264,5 +265,3 @@ export namespace DiscordBot {
Quester.createConfig('https://discord.com/api/v10'),
])
}

DiscordBot.prototype.platform = 'discord'
4 changes: 2 additions & 2 deletions adapters/kook/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@satorijs/adapter-kook",
"description": "Kook (Kaiheila) Adapter for Satorijs",
"version": "3.10.1",
"version": "3.10.2",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand All @@ -26,7 +26,7 @@
"satori"
],
"peerDependencies": {
"@satorijs/satori": "^2.6.0"
"@satorijs/satori": "^2.6.1"
},
"dependencies": {
"form-data": "^4.0.0"
Expand Down
5 changes: 5 additions & 0 deletions adapters/kook/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [@satorijs/adapter-kook](https://koishi.chat/plugins/adapter/kook.html)

KOOK (开黑啦) adapter for [Satori](https://github.com/satorijs/satori).

- [Documentation](https://koishi.chat/plugins/adapter/kook.html)
4 changes: 1 addition & 3 deletions adapters/kook/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class KookBot<T extends KookBot.Config = KookBot.Config> extends Bot<T> {

constructor(ctx: Context, config: T) {
super(ctx, config)
this.platform = 'kook'
this.http = ctx.http.extend({
headers: {
'Authorization': `Bot ${config.token}`,
Expand Down Expand Up @@ -192,6 +193,3 @@ export namespace KookBot {
Quester.createConfig('https://www.kookapp.cn/api/v3'),
] as const)
}

// for backward compatibility
KookBot.prototype.platform = 'kook'
4 changes: 2 additions & 2 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 / Feishu Adapter for Satorijs",
"version": "2.1.2",
"version": "2.1.3",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand Down Expand Up @@ -30,7 +30,7 @@
"satori"
],
"peerDependencies": {
"@satorijs/satori": "^2.6.0"
"@satorijs/satori": "^2.6.1"
},
"dependencies": {
"form-data": "^4.0.0"
Expand Down
5 changes: 5 additions & 0 deletions adapters/lark/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [@satorijs/adapter-lark](https://koishi.chat/plugins/adapter/lark.html)

Lark (飞书) adapter for [Satori](https://github.com/satorijs/satori).

- [Documentation](https://koishi.chat/plugins/adapter/lark.html)
1 change: 1 addition & 0 deletions adapters/lark/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class LarkBot extends Bot<LarkBot.Config> {
logger.warn('selfUrl is not set, some features may not work')
}

this.platform = 'lark'
this.selfId = config.appId

this.http = ctx.http.extend({
Expand Down
4 changes: 2 additions & 2 deletions adapters/line/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@satorijs/adapter-line",
"description": "Line Adapter for Satorijs",
"version": "1.1.0",
"version": "1.1.1",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand All @@ -26,6 +26,6 @@
"satori"
],
"peerDependencies": {
"@satorijs/satori": "^2.6.0"
"@satorijs/satori": "^2.6.1"
}
}
5 changes: 5 additions & 0 deletions adapters/line/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [@satorijs/adapter-line](https://koishi.chat/plugins/adapter/line.html)

LINE adapter for [Satori](https://github.com/satorijs/satori).

- [Documentation](https://koishi.chat/plugins/adapter/line.html)
7 changes: 4 additions & 3 deletions adapters/line/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ export class LineBot extends Bot<LineBot.Config> {
public http: Quester
public contentHttp: Quester
public internal: Internal

constructor(ctx: Context, config: LineBot.Config) {
super(ctx, config)
if (!ctx.root.config.selfUrl) {
logger.warn('selfUrl is not set, some features may not work')
}

ctx.plugin(HttpServer, this)
this.platform = 'line'
this.http = ctx.http.extend({
...config.api,
headers: {
Expand All @@ -30,6 +31,8 @@ export class LineBot extends Bot<LineBot.Config> {
},
})
this.internal = new Internal(this.http)

ctx.plugin(HttpServer, this)
}

async initialize(callback: (bot: this) => Promise<void>) {
Expand Down Expand Up @@ -115,5 +118,3 @@ export namespace LineBot {
}),
])
}

LineBot.prototype.platform = 'line'
17 changes: 9 additions & 8 deletions adapters/line/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import internal from 'stream'

export class HttpServer extends Adapter.Server<LineBot> {
logger = new Logger('line')

constructor(ctx: Context, bot: LineBot) {
super()
}
Expand All @@ -16,16 +17,16 @@ export class HttpServer extends Adapter.Server<LineBot> {
const sign = ctx.headers['x-line-signature']?.toString()
const parsed = ctx.request.body as WebhookRequestBody
const { destination } = parsed
const localBot = this.bots.find(bot => bot.selfId === destination)
if (!localBot) return ctx.status = 403
const hash = crypto.createHmac('SHA256', localBot?.config?.secret).update(ctx.request.rawBody || '').digest('base64')
const bot = this.bots.find(bot => bot.selfId === destination)
if (!bot) return ctx.status = 403
const hash = crypto.createHmac('SHA256', bot?.config?.secret).update(ctx.request.rawBody || '').digest('base64')
if (hash !== sign) {
return ctx.status = 403
}
this.logger.debug(require('util').inspect(parsed, false, null, true))
for (const event of parsed.events) {
const sessions = await adaptSessions(localBot, event)
if (sessions.length) sessions.forEach(localBot.dispatch.bind(localBot))
const sessions = await adaptSessions(bot, event)
if (sessions.length) sessions.forEach(bot.dispatch.bind(bot))
this.logger.debug(require('util').inspect(sessions, false, null, true))
}
ctx.status = 200
Expand All @@ -34,9 +35,9 @@ export class HttpServer extends Adapter.Server<LineBot> {
bot.ctx.router.get('/line/assets/:self_id/:message_id', async (ctx) => {
const messageId = ctx.params.message_id
const selfId = ctx.params.self_id
const localBot = this.bots.find((bot) => bot.selfId === selfId)
if (!localBot) return ctx.status = 404
const resp = await localBot.contentHttp.axios<internal.Readable>(`/v2/bot/message/${messageId}/content`, {
const bot = this.bots.find((bot) => bot.selfId === selfId)
if (!bot) return ctx.status = 404
const resp = await bot.contentHttp.axios<internal.Readable>(`/v2/bot/message/${messageId}/content`, {
method: 'GET',
responseType: 'stream',
})
Expand Down
4 changes: 2 additions & 2 deletions adapters/mail/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@satorijs/adapter-mail",
"description": "Mail Adapter for Satorijs",
"version": "1.1.1",
"version": "1.1.2",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand All @@ -25,7 +25,7 @@
"satori"
],
"peerDependencies": {
"@satorijs/satori": "^2.6.0"
"@satorijs/satori": "^2.6.1"
},
"dependencies": {
"@types/mailparser": "^3.4.0",
Expand Down
5 changes: 5 additions & 0 deletions adapters/mail/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [@satorijs/adapter-mail](https://koishi.chat/plugins/adapter/mail.html)

Mail adapter for [Satori](https://github.com/satorijs/satori).

- [Documentation](https://koishi.chat/plugins/adapter/mail.html)
9 changes: 6 additions & 3 deletions adapters/mail/src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bot, Logger, Schema } from '@satorijs/satori'
import { Bot, Context, Logger, Schema } from '@satorijs/satori'
import { ParsedMail } from 'mailparser'
import { IMAP, SMTP } from './mail'
import { MailMessageEncoder } from './message'
Expand All @@ -12,6 +12,11 @@ export class MailBot extends Bot<MailBot.Config> {
imap: IMAP
smtp: SMTP

constructor(ctx: Context, config: MailBot.Config) {
super(ctx, config)
this.platform = 'mail'
}

async start() {
this.username = this.config.username
await super.start()
Expand Down Expand Up @@ -113,5 +118,3 @@ export namespace MailBot {
]),
})
}

MailBot.prototype.platform = 'mail'
4 changes: 2 additions & 2 deletions adapters/matrix/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@satorijs/adapter-matrix",
"description": "Matrix Adapter for Satorijs",
"version": "3.1.2",
"version": "3.2.1",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand All @@ -24,7 +24,7 @@
"satori"
],
"peerDependencies": {
"@satorijs/satori": "^2.6.0"
"@satorijs/satori": "^2.6.1"
},
"dependencies": {
"image-size": "^1.0.2",
Expand Down
5 changes: 5 additions & 0 deletions adapters/matrix/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [@satorijs/adapter-matrix](https://koishi.chat/plugins/adapter/matrix.html)

Matrix adapter for [Satori](https://github.com/satorijs/satori).

- [Documentation](https://koishi.chat/plugins/adapter/matrix.html)
Loading

0 comments on commit 448b849

Please sign in to comment.