Skip to content

Commit

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

async getGuildMemberList(guildId: string, after?: string) {
const { data: users } = await this.internal.getGuildMembers(guildId, { page_token: after })
const data = users.items.map(v => ({ user: { id: v.member_id, name: v.name }, name: v.name }))
Expand Down
1 change: 1 addition & 0 deletions adapters/lark/src/types/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ declare module '.' {
edit_permission: string
owner_id_type: string
owner_id: string
chat_id: string
chat_mode: string
chat_type: string
chat_tag: string
Expand Down
9 changes: 9 additions & 0 deletions adapters/lark/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { 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'

Check failure on line 6 in adapters/lark/src/utils.ts

View workflow job for this annotation

GitHub Actions / lint

'@satorijs/protocol' imported multiple times

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

export function decodeGuild(guild: Lark.Guild): Guild {
return {
id: guild.chat_id,
name: guild.name,
avatar: guild.avatar,
}
}

export function decodeUser(user: Lark.User): User {
return {
id: user.open_id,
Expand Down

0 comments on commit 88cf4c5

Please sign in to comment.