Skip to content

Commit

Permalink
feat: add getChannel / getGuild
Browse files Browse the repository at this point in the history
  • Loading branch information
MaikoTan authored Oct 11, 2023
1 parent 88cf4c5 commit a704ae2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 10 additions & 0 deletions adapters/lark/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ export class LarkBot extends Bot<LarkBot.Config> {
return Utils.decodeUser(data.data)
}

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

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

async getGuildList(after?: string) {
const { data: guilds } = await this.internal.getCurrentUserGuilds({ page_token: after })
return { data: guilds.items.map(Utils.decodeGuild), next: guilds.page_token }
Expand Down
12 changes: 10 additions & 2 deletions adapters/lark/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import crypto from 'crypto'
import { Message, User } from '@satorijs/protocol'
import { Channel, Guild, Message, User } from '@satorijs/protocol'
import { h, Session, trimSlash } from '@satorijs/satori'
import { FeishuBot, LarkBot } from './bot'
import { AllEvents, Events, Lark, Message as LarkMessage, MessageContentType, MessageType } from './types'
import { Guild } from '@satorijs/protocol'

export type Sender =
| {
Expand Down Expand Up @@ -147,6 +146,15 @@ export function extractIdType(id: string): Lark.ReceiveIdType {
return 'user_id'
}

export function decodeChannel(guild: Lark.Guild): Channel {
return {
id: guild.chat_id,
type: Channel.Type.TEXT,
name: guild.name,
parentId: guild.chat_id,
}
}

export function decodeGuild(guild: Lark.Guild): Guild {
return {
id: guild.chat_id,
Expand Down

0 comments on commit a704ae2

Please sign in to comment.