Update ConfigService.ts

This commit is contained in:
Nofated 2023-01-18 23:57:32 +08:00 committed by GitHub
parent 6693d2c421
commit 37022d8f33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 80 deletions

View File

@ -158,36 +158,6 @@ export default class ConfigService {
await status.edit({ text: '正在创建 Telegram 群…', buttons: Button.clear() });
}
if (!chat) {
// 创建群聊,拿到的是 user 的 chat
chat = await this.tgUser.createChat(title, await getAboutText(room, false));
// 添加机器人
status && await status.edit({ text: '正在添加机器人…' });
await chat.inviteMember(this.tgBot.me.id);
}
// 设置管理员
status && await status.edit({ text: '正在设置管理员…' });
await chat.setAdmin(this.tgBot.me.username);
// 添加到 Filter
try {
status && await status.edit({ text: '正在将群添加到文件夹…' });
const dialogFilters = await this.tgUser.getDialogFilters() as Api.DialogFilter[];
const filter = dialogFilters.find(e => e.id === DEFAULT_FILTER_ID);
if (filter) {
filter.includePeers.push(utils.getInputPeer(chat));
await this.tgUser.updateDialogFilter({
id: DEFAULT_FILTER_ID,
filter,
});
}
}
catch (e) {
errorMessage += `\n添加到文件夹失败${e.message}`;
}
// 关闭【添加成员】快捷条
try {
status && await status.edit({ text: '正在关闭【添加成员】快捷条…' });
@ -270,56 +240,7 @@ export default class ConfigService {
}
}
else {
const chat = await this.tgUser.getChat(tgChatId);
await this.createGroupAndLink(qqRoomId, undefined, true, chat);
}
}
// 创建 QQ 群组的文件夹
public async setupFilter() {
const result = await this.tgUser.getDialogFilters() as Api.DialogFilter[];
let filter = result.find(e => e.id === DEFAULT_FILTER_ID);
if (!filter) {
this.log.info('创建 TG 文件夹');
// 要自己计算新的 id随意 id 也是可以的
// https://github.com/morethanwords/tweb/blob/7d646bc9a87d943426d831f30b69d61b743f51e0/src/lib/storages/filters.ts#L251
// 创建
filter = new Api.DialogFilter({
id: DEFAULT_FILTER_ID,
title: 'QQ',
pinnedPeers: [
(await this.tgUser.getChat(this.tgBot.me.username)).inputPeer,
],
includePeers: [],
excludePeers: [],
emoticon: '🐧',
});
let errorText = '设置文件夹失败';
try {
const isSuccess = await this.tgUser.updateDialogFilter({
id: DEFAULT_FILTER_ID,
filter,
});
if (!isSuccess) {
this.log.error(errorText);
await (await this.owner).sendMessage(errorText);
}
}
catch (e) {
this.log.error(errorText, e);
await (await this.owner).sendMessage(errorText + `\n<code>${e}</code>`);
}
}
}
public async migrateAllChats() {
const dbPairs = await db.forwardPair.findMany();
for (const forwardPair of dbPairs) {
const chatForUser = await this.tgUser.getChat(Number(forwardPair.tgChatId));
if (chatForUser.entity instanceof Api.Chat) {
this.log.info('升级群组 ', chatForUser.id);
await chatForUser.migrate();
}
const chat = await tgChat = await this.tgBot.getChat(tgChatId);
}
}
}