Skip to content

Commit

Permalink
fix: 官方适配器发消息功能丢失
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-cn committed Jul 11, 2024
1 parent 9687c5b commit ee4f6a3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# 镜像继承
FROM node:18
RUN mkdir /app
COPY ./test/package.json /app
WORKDIR /app
RUN npm init -y
RUN npm install
RUN npm install zhin
RUN npx zhin init
RUN npx zhin
EXPOSE 8086
CMD npm start
2 changes: 1 addition & 1 deletion packages/adapters/qq/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"directory": "packages/adapters/qq"
},
"dependencies": {
"qq-group-bot": "latest"
"qq-official-bot": "latest"
},
"peerDependencies": {
"zhin": "workspace:^"
Expand Down
30 changes: 26 additions & 4 deletions packages/adapters/qq/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Adapter, App, Message, Schema } from 'zhin';
import { sendableToString, formatSendable } from './utils';
import { formatSendable, sendableToString } from './utils';
import {
Bot,
PrivateMessageEvent,
GroupMessageEvent,
GuildMessageEvent,
Sendable,
Quotable,
GuildMessageEvent,
Intent,
} from 'qq-group-bot';
Quotable,
} from 'qq-official-bot';
type QQMessageEvent = PrivateMessageEvent | GroupMessageEvent | GuildMessageEvent;
export type QQAdapter = typeof qq;
const qq = new Adapter<Adapter.Bot<Bot>, QQMessageEvent>('qq');
Expand Down Expand Up @@ -123,6 +123,28 @@ const messageHandler = (bot: Adapter.Bot<Bot>, event: QQMessageEvent) => {
}
qq.app!.emit('message', qq, bot, message);
};
qq.define('sendMsg', async (bot_id, target_id, target_type, message, source) => {
const bot = qq.pick(bot_id);
let msg: Sendable = await qq.app!.renderMessage(message as string, source);
msg = formatSendable(msg);
const quote: Quotable | undefined = source ? source.original : undefined;
switch (target_type) {
case 'group':
return bot.sendGroupMessage(target_id, msg, quote);
case 'private':
const [sub_type, user_id] = target_id.split(':');
if (sub_type === 'friend') {
return bot.sendPrivateMessage(user_id, msg, quote);
}
return bot.sendDirectMessage(user_id, msg, quote);
case 'direct':
return bot.sendDirectMessage(target_id, msg, quote);
case 'guild':
return bot.sendGuildMessage(target_id, msg, quote);
default:
throw new Error(`QQ适配器暂不支持发送${target_type}类型的消息`);
}
});
const stopBots = () => {
for (const bot of qq.bots) {
bot.stop();
Expand Down

0 comments on commit ee4f6a3

Please sign in to comment.