From a704ae26608e2f1b3af37efd8d5efdb648a5749a Mon Sep 17 00:00:00 2001 From: Maiko Sinkyaet Tan Date: Wed, 11 Oct 2023 20:12:06 +0800 Subject: [PATCH] feat: add getChannel / getGuild --- adapters/lark/src/bot.ts | 10 ++++++++++ adapters/lark/src/utils.ts | 12 ++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/adapters/lark/src/bot.ts b/adapters/lark/src/bot.ts index b17cf271..97a76442 100644 --- a/adapters/lark/src/bot.ts +++ b/adapters/lark/src/bot.ts @@ -95,6 +95,16 @@ export class LarkBot extends Bot { 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 } diff --git a/adapters/lark/src/utils.ts b/adapters/lark/src/utils.ts index 29cf6a66..dc47af59 100644 --- a/adapters/lark/src/utils.ts +++ b/adapters/lark/src/utils.ts @@ -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 = | { @@ -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,