|
@@ -1,11 +1,14 @@
|
|
|
import { App, Bot, segment, Session, sleep } from 'koishi';
|
|
|
import 'koishi-adapter-onebot';
|
|
|
+import { Message as CQMessage, SenderInfo } from 'koishi-adapter-onebot';
|
|
|
|
|
|
import { parseCmd, query, view } from './command';
|
|
|
import { getLogger } from './loggers';
|
|
|
|
|
|
const logger = getLogger('qqbot');
|
|
|
|
|
|
+type CQSession = Session & CQMessage & {sender: SenderInfo & {groupId?: number}};
|
|
|
+
|
|
|
interface IQQProps {
|
|
|
access_token: string;
|
|
|
host: string;
|
|
@@ -62,16 +65,16 @@ export default class {
|
|
|
if (wasEmpty) this.next(type, id);
|
|
|
};
|
|
|
|
|
|
- private getChat = async (session: Session): Promise<IChat> => {
|
|
|
+ private getChat = async (session: CQSession): Promise<IChat> => {
|
|
|
switch (session.subtype) {
|
|
|
case 'private':
|
|
|
- if (session.groupId) { // temp message
|
|
|
+ if (session.sender.groupId) { // temp message
|
|
|
const friendList = await session.bot.getFriendList();
|
|
|
if (!friendList.some(friendItem => friendItem.userId === session.userId)) {
|
|
|
return {
|
|
|
chatID: {
|
|
|
qq: Number(session.userId),
|
|
|
- group: Number(session.groupId),
|
|
|
+ group: Number(session.sender.groupId),
|
|
|
},
|
|
|
chatType: ChatType.Temp,
|
|
|
};
|
|
@@ -89,12 +92,12 @@ export default class {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- private sendToGroup = (groupID: string, message: string) => new Promise<string>(resolve => {
|
|
|
- this.enqueue('group', groupID, () => this.bot.sendMessage(groupID, message).then(resolve));
|
|
|
+ private sendToGroup = (groupID: string, message: string) => new Promise<string>((resolve, reject) => {
|
|
|
+ this.enqueue('group', groupID, () => this.bot.sendMessage(groupID, message).then(resolve).catch(reject));
|
|
|
});
|
|
|
|
|
|
- private sendToUser = (userID: string, message: string) => new Promise<string>(resolve => {
|
|
|
- this.enqueue('private', userID, () => this.bot.sendPrivateMessage(userID, message).then(resolve));
|
|
|
+ private sendToUser = (userID: string, message: string) => new Promise<string>((resolve, reject) => {
|
|
|
+ this.enqueue('private', userID, () => this.bot.sendPrivateMessage(userID, message).then(resolve).catch(reject));
|
|
|
});
|
|
|
|
|
|
public sendTo = (subscriber: IChat, messageChain: string) => Promise.all(
|
|
@@ -160,7 +163,7 @@ export default class {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- this.app.middleware(async session => {
|
|
|
+ this.app.middleware(async (session: CQSession) => {
|
|
|
const chat = await this.getChat(session);
|
|
|
const cmdObj = parseCmd(session.content);
|
|
|
const reply = async msg => session.sendQueued(msg);
|