Skip to content

Commit

Permalink
refa(lark): FeishuBot -> LarkBot
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Oct 30, 2024
1 parent c5291b9 commit d97d320
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions adapters/lark/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@ import { ReadableStream } from 'node:stream/web'
import { Adapter, Context, Logger, Schema } from '@satorijs/core'
import {} from '@cordisjs/plugin-server'

import { FeishuBot } from './bot'
import { LarkBot } from './bot'
import { EventPayload } from './types'
import { adaptSession, Cipher } from './utils'

export class HttpServer<C extends Context = Context> extends Adapter<C, FeishuBot<C>> {
export class HttpServer<C extends Context = Context> extends Adapter<C, LarkBot<C>> {
static inject = ['server']

private logger: Logger
private ciphers: Record<string, Cipher> = {}

constructor(ctx: C, bot: FeishuBot<C>) {
constructor(ctx: C, bot: LarkBot<C>) {
super(ctx)
this.logger = ctx.logger('lark')
}

fork(ctx: C, bot: FeishuBot<C>) {
fork(ctx: C, bot: LarkBot<C>) {
super.fork(ctx, bot)

this._refreshCipher()
return bot.initialize()
}

async connect(bot: FeishuBot) {
async connect(bot: LarkBot) {
const { path } = bot.config
bot.ctx.server.post(path, (ctx) => {
this._refreshCipher()
Expand Down
6 changes: 3 additions & 3 deletions adapters/lark/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import crypto from 'crypto'
import { Context, h, Session, trimSlash, Universal } from '@satorijs/core'
import { FeishuBot, LarkBot } from './bot'
import { LarkBot } from './bot'
import { EventPayload, Events, GetImChatResponse, Lark, MessageContentType, MessageType } from './types'

export type Sender =
Expand All @@ -22,7 +22,7 @@ export function adaptSender(sender: Sender, session: Session): Session {
return session
}

export async function adaptMessage(bot: FeishuBot, data: Events['im.message.receive_v1'], session: Session, details = true): Promise<Session> {
export async function adaptMessage(bot: LarkBot, data: Events['im.message.receive_v1'], session: Session, details = true): Promise<Session> {
const json = JSON.parse(data.message.content) as MessageContentType<MessageType>
const assetEndpoint = trimSlash(bot.config.selfUrl ?? bot.ctx.server.config.selfUrl) + bot.config.path + '/assets'
const content: (string | h)[] = []
Expand Down Expand Up @@ -71,7 +71,7 @@ export async function adaptMessage(bot: FeishuBot, data: Events['im.message.rece
return session
}

export async function adaptSession<C extends Context>(bot: FeishuBot<C>, body: EventPayload) {
export async function adaptSession<C extends Context>(bot: LarkBot<C>, body: EventPayload) {
const session = bot.session()
session.setInternal('lark', body)

Expand Down

0 comments on commit d97d320

Please sign in to comment.