diff --git a/plugins/adapter/qqguild/package.json b/plugins/adapter/qqguild/package.json index 5c23d28a22..7809175ffd 100644 --- a/plugins/adapter/qqguild/package.json +++ b/plugins/adapter/qqguild/package.json @@ -1,7 +1,7 @@ { "name": "@koishijs/plugin-adapter-qqguild", "description": "QQ Guild Adapter for Koishi", - "version": "1.1.2", + "version": "2.0.0", "main": "lib/index.js", "typings": "lib/index.d.ts", "files": [ @@ -33,7 +33,7 @@ "koishi": "^4.6.2" }, "dependencies": { - "@qq-guild-sdk/core": "^1.1.4", + "@qq-guild-sdk/core": "^2.0.1", "qface": "^1.2.0" } } \ No newline at end of file diff --git a/plugins/adapter/qqguild/src/utils.ts b/plugins/adapter/qqguild/src/utils.ts index ad0e96b4fc..3f21f49140 100644 --- a/plugins/adapter/qqguild/src/utils.ts +++ b/plugins/adapter/qqguild/src/utils.ts @@ -1,6 +1,6 @@ -import { Guild as GGuild, User as GUser } from '@qq-guild-sdk/core/dist/common' -import { Adapter, Bot, Schema } from 'koishi' +import { Guild as GGuild, User as GUser } from '@qq-guild-sdk/core' import * as QQGuild from '@qq-guild-sdk/core' +import { Adapter, Bot, Schema } from 'koishi' export interface AdapterConfig extends Adapter.WebSocketClient.Config, Omit {} @@ -13,8 +13,11 @@ export const AdapterConfig: Schema = Schema.intersect([ Adapter.WebSocketClient.Config, ]) +const Intents = QQGuild.Bot.Intents +type Intents = keyof typeof Intents + export interface BotConfig extends Bot.BaseConfig, QQGuild.Bot.AppConfig { - indents: number + intents: number } export const BotConfig = Schema.intersect([ @@ -22,6 +25,7 @@ export const BotConfig = Schema.intersect([ id: Schema.string().description('机器人 id。').required(), key: Schema.string().description('机器人 key。').role('secret').required(), token: Schema.string().description('机器人令牌。').role('secret').required(), + intents: Schema.number().description('需要订阅的机器人事件。').default(Intents.PUBLIC_GUILD_MESSAGES), }), ]) diff --git a/plugins/adapter/qqguild/src/ws.ts b/plugins/adapter/qqguild/src/ws.ts index ca4e912921..3f9a71f3c9 100644 --- a/plugins/adapter/qqguild/src/ws.ts +++ b/plugins/adapter/qqguild/src/ws.ts @@ -1,4 +1,5 @@ import { Message } from '@qq-guild-sdk/core' +import * as QQGuild from '@qq-guild-sdk/core' import { Logger, segment } from '@koishijs/utils' import { Adapter, Session } from 'koishi' import { QQGuildBot } from './bot' @@ -22,9 +23,12 @@ const createSession = (bot: QQGuildBot, msg: Message) => { session.guildId = msg.guildId session.channelId = msg.channelId session.subtype = 'group' - session.content = msg.content + session.content = (msg.content ?? '') .replace(/<@!(.+)>/, (_, $1) => segment.at($1)) .replace(/<#(.+)>/, (_, $1) => segment.sharp($1)) + session.content = (msg as any as { attachments: any[] }).attachments + .filter(({ contentType }) => contentType.startsWith('image')) + .reduce((content, attachment) => content + segment.image(attachment.url), session.content) return new Session(bot, session) } @@ -34,7 +38,7 @@ export class WebSocketClient extends Adapter { async connect(bot: QQGuildBot) { Object.assign(bot, await bot.getSelf()) bot.resolve() - await bot.$innerBot.startClient(bot.config.indents) + await bot.$innerBot.startClient(bot.config.intents) bot.$innerBot.on('ready', bot.resolve) bot.$innerBot.on('message', msg => { const session = createSession(bot, msg)