perf: 封装那些需要低级调用的方法到 Telegram 类中

This commit is contained in:
凌莞 2022-02-23 11:49:16 +08:00
parent f75fa06f25
commit 2682e65008
No known key found for this signature in database
GPG Key ID: 05F8479BA63A8E92
2 changed files with 16 additions and 10 deletions

View File

@ -112,8 +112,12 @@ export class Telegram {
return this.callbackQueryHelper.registerCallback(cb);
}
public invoke<R extends Api.AnyRequest>(req: R) {
return this.client.invoke(req);
public async getDialogFilters() {
return await this.client.invoke(new Api.messages.GetDialogFilters());
}
public async updateDialogFilter(params: Partial<Partial<{ id: number; filter?: Api.DialogFilter; }>>) {
return await this.client.invoke(new Api.messages.UpdateDialogFilter(params));
}
}

View File

@ -38,6 +38,8 @@ export default class ConfigService {
);
}
// region 打开添加关联的菜单
// 开始添加转发群组流程
public async addGroup() {
const qGroups = Array.from(this.oicq.gl).map(e => e[1]);
@ -106,6 +108,8 @@ export default class ConfigService {
});
}
// endregion
private async createGroupAndLink(roomId: number) {
this.log.info(`创建群组并关联:${roomId}`);
}
@ -115,7 +119,7 @@ export default class ConfigService {
try {
const qGroup = this.oicq.gl.get(-qqRoomId);
const tgChat = (await this.tgBot.getChat(tgChatId)).entity as Api.Chat;
message = `QQ群${qGroup.group_name} (<code>${qGroup.group_id}</code>)已与 Telegram 群 ${tgChat.title} (<code>${tgChatId})关联</code>`;
message = `QQ群${qGroup.group_name} (<code>${qGroup.group_id}</code>)已与 Telegram 群 ${tgChat.title} (<code>${tgChatId}</code>)关联`;
await db.forwardPair.create({
data: { qqRoomId, tgChatId },
});
@ -128,7 +132,7 @@ export default class ConfigService {
// 创建 QQ 群组的文件夹
public async setupFilter() {
const result = await this.tgUser.invoke(new Api.messages.GetDialogFilters());
const result = await this.tgUser.getDialogFilters();
this.filter = result.find(e => e.id === DEFAULT_FILTER_ID);
this.log.debug(this.filter);
if (!this.filter) {
@ -148,12 +152,10 @@ export default class ConfigService {
});
let errorText = '设置文件夹失败';
try {
const isSuccess = await this.tgUser.invoke(
new Api.messages.UpdateDialogFilter({
id: DEFAULT_FILTER_ID,
filter: this.filter,
}),
);
const isSuccess = await this.tgUser.updateDialogFilter({
id: DEFAULT_FILTER_ID,
filter: this.filter,
});
if (!isSuccess) {
this.filter = null;
this.log.error(errorText);