feat: 加入新群时询问用户是否关联

This commit is contained in:
Clansty 2022-03-02 14:07:21 +08:00
parent 58b623f688
commit 3c03ce63d3
No known key found for this signature in database
GPG Key ID: 05F8479BA63A8E92
2 changed files with 35 additions and 3 deletions

View File

@ -5,7 +5,7 @@ import ConfigService from '../services/ConfigService';
import { config } from '../providers/userConfig';
import regExps from '../constants/regExps';
import forwardPairs from '../providers/forwardPairs';
import { GroupMessageEvent, PrivateMessageEvent } from 'oicq';
import { GroupMessageEvent, MemberIncreaseEvent, PrivateMessageEvent } from 'oicq';
export default class ConfigController {
private readonly configService: ConfigService;
@ -18,6 +18,7 @@ export default class ConfigController {
tgBot.addNewMessageEventHandler(this.handleMessage);
tgBot.addNewServiceMessageEventHandler(this.handleServiceMessage);
oicq.addNewMessageEventHandler(this.handleQqMessage);
config.workMode === 'personal' && oicq.on('notice.group.increase', this.handleMemberIncrease);
this.configService.configCommands();
config.workMode === 'personal' && this.configService.setupFilter();
}
@ -66,6 +67,7 @@ export default class ConfigController {
};
private handleServiceMessage = async (message: Api.MessageService) => {
// 用于检测群升级为超级群的情况
if (message.action instanceof Api.MessageActionChatMigrateTo) {
const pair = forwardPairs.find((message.peerId as Api.PeerChat).chatId);
if (!pair) return;
@ -89,4 +91,10 @@ export default class ConfigController {
await promise;
return false;
};
private handleMemberIncrease = async (event: MemberIncreaseEvent) => {
if(event.user_id!==this.oicq.uin||await forwardPairs.find(event.group)) return;
// 是新群并且是自己加入了
await this.configService.promptNewGroup(event.group)
};
}

View File

@ -109,7 +109,13 @@ export default class ConfigService {
// endregion
public async createGroupAndLink(roomId: number, title?: string, silent = false) {
/**
*
* @param roomId
* @param title
* @param status false
*/
public async createGroupAndLink(roomId: number, title?: string, status: boolean | Api.Message = true) {
this.log.info(`创建群组并关联:${roomId}`);
const qEntity = this.oicq.getChat(roomId);
if (!title) {
@ -124,7 +130,12 @@ export default class ConfigService {
let isFinish = false;
try {
// 状态信息
const status = !silent && await (await this.owner).sendMessage('正在创建 Telegram 群…');
if (status === true) {
status = await (await this.owner).sendMessage('正在创建 Telegram 群…');
}
else if (status instanceof Api.Message) {
await status.edit({ text: '正在创建 Telegram 群…', buttons: Button.clear() });
}
// 创建群聊,拿到的是 user 的 chat
const chat = await this.tgUser.createChat({
@ -189,6 +200,19 @@ export default class ConfigService {
}
}
public async promptNewGroup(group: Group) {
const message = await (await this.owner).sendMessage({
message: '你加入了一个新的群:\n' +
`${group.name}\n` +
`${group.info.member_count} 名成员\n` +
`群号:${group.group_id}\n` +
'要创建关联群吗',
buttons: Button.inline('创建', this.tgBot.registerCallback(
() => this.createGroupAndLink(-group.group_id, group.name, message))),
});
return message;
}
public async createLinkGroup(qqRoomId: number, tgChatId: number) {
let message: string;
try {