|
@@ -173,24 +173,15 @@ export class TaskExecutor {
|
|
|
|
|
|
|
|
accountUsageInRound = 0
|
|
accountUsageInRound = 0
|
|
|
inviteGroupEntity = null
|
|
inviteGroupEntity = null
|
|
|
-
|
|
|
|
|
- // 延迟
|
|
|
|
|
- const delaySeconds = this.getRandomDelaySeconds()
|
|
|
|
|
- this.app.log.info(`延迟 ${delaySeconds}s 后开始处理任务`)
|
|
|
|
|
- await this.sleep(delaySeconds * 1000)
|
|
|
|
|
-
|
|
|
|
|
- // 群拉人任务:每次换号后,确保已加入目标群并拿到群实体
|
|
|
|
|
- if (task.type === TaskType.INVITE_TO_GROUP) {
|
|
|
|
|
- const inviteLink = String(task.payload?.inviteLink ?? '').trim()
|
|
|
|
|
- if (!inviteLink) {
|
|
|
|
|
- throw new Error('邀请链接为空,请检查 task.payload.inviteLink')
|
|
|
|
|
- }
|
|
|
|
|
- inviteGroupEntity = await workerTgClient.resolveGroupEntityByInviteLink(inviteLink)
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 延迟
|
|
|
|
|
+ const delaySeconds = this.getRandomDelaySeconds()
|
|
|
|
|
+ this.app.log.info(`延迟 ${delaySeconds}s 后开始处理任务`)
|
|
|
|
|
+ await this.sleep(delaySeconds * 1000)
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
- await this.processTaskItem(task, taskItem, tgUser, workerTgClient, inviteGroupEntity)
|
|
|
|
|
|
|
+ await this.processTaskItem(task, taskItem, tgUser, workerTgClient)
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
const msg = error instanceof Error ? error.message : '未知错误'
|
|
const msg = error instanceof Error ? error.message : '未知错误'
|
|
|
if (tgUser && this.isSessionRevokedMessage(msg)) {
|
|
if (tgUser && this.isSessionRevokedMessage(msg)) {
|
|
@@ -263,11 +254,10 @@ export class TaskExecutor {
|
|
|
task: Task,
|
|
task: Task,
|
|
|
item: TaskItem,
|
|
item: TaskItem,
|
|
|
sender: TgUser,
|
|
sender: TgUser,
|
|
|
- workerTgClient: TgClientManager,
|
|
|
|
|
- inviteGroupEntity: any | null
|
|
|
|
|
|
|
+ workerTgClient: TgClientManager
|
|
|
): Promise<void> {
|
|
): Promise<void> {
|
|
|
if (task.type === TaskType.INVITE_TO_GROUP) {
|
|
if (task.type === TaskType.INVITE_TO_GROUP) {
|
|
|
- return await this.processInviteToGroup(task, item, sender, workerTgClient, inviteGroupEntity)
|
|
|
|
|
|
|
+ return await this.processInviteToGroup(task, item, sender, workerTgClient)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return await this.processSendMessage(task, item, sender, workerTgClient)
|
|
return await this.processSendMessage(task, item, sender, workerTgClient)
|
|
@@ -344,12 +334,12 @@ export class TaskExecutor {
|
|
|
task: Task,
|
|
task: Task,
|
|
|
item: TaskItem,
|
|
item: TaskItem,
|
|
|
sender: TgUser,
|
|
sender: TgUser,
|
|
|
- workerTgClient: TgClientManager,
|
|
|
|
|
- inviteGroupEntity: any | null
|
|
|
|
|
|
|
+ workerTgClient: TgClientManager
|
|
|
): Promise<void> {
|
|
): Promise<void> {
|
|
|
try {
|
|
try {
|
|
|
- if (!inviteGroupEntity) {
|
|
|
|
|
- throw new Error('未获取到群组实体(inviteGroupEntity 为空)')
|
|
|
|
|
|
|
+ const inviteLink = String(task.payload?.inviteLink ?? '').trim()
|
|
|
|
|
+ if (!inviteLink) {
|
|
|
|
|
+ throw new Error('群拉人任务:邀请链接为空,请检查任务配置信息')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const parsedTarget = this.parseTarget(item.target)
|
|
const parsedTarget = this.parseTarget(item.target)
|
|
@@ -367,40 +357,14 @@ export class TaskExecutor {
|
|
|
throw new Error('TelegramClient 未连接')
|
|
throw new Error('TelegramClient 未连接')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const isChannel = inviteGroupEntity?.className === 'Channel'
|
|
|
|
|
- const isChat = inviteGroupEntity?.className === 'Chat'
|
|
|
|
|
- if (!isChannel && !isChat) {
|
|
|
|
|
- throw new Error('目标并非群组或频道,无法邀请成员')
|
|
|
|
|
|
|
+ // tgUser 加入群组,获取群组实体
|
|
|
|
|
+ const inviteGroupEntity = await workerTgClient.resolveGroupEntityByInviteLink(inviteLink)
|
|
|
|
|
+ if (!inviteGroupEntity) {
|
|
|
|
|
+ throw new Error('群拉人任务:未获取到群组实体(inviteGroupEntity 为空)')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const inputUser = new Api.InputUser({
|
|
|
|
|
- userId: targetUser.id,
|
|
|
|
|
- accessHash: targetUser.accessHash || BigInt(0)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- if (isChannel) {
|
|
|
|
|
- if (!inviteGroupEntity?.accessHash) {
|
|
|
|
|
- throw new Error('缺少 accessHash,无法邀请到频道/超级群组')
|
|
|
|
|
- }
|
|
|
|
|
- const inputChannel = new Api.InputChannel({
|
|
|
|
|
- channelId: inviteGroupEntity.id,
|
|
|
|
|
- accessHash: inviteGroupEntity.accessHash
|
|
|
|
|
- })
|
|
|
|
|
- await client.invoke(
|
|
|
|
|
- new Api.channels.InviteToChannel({
|
|
|
|
|
- channel: inputChannel,
|
|
|
|
|
- users: [inputUser]
|
|
|
|
|
- })
|
|
|
|
|
- )
|
|
|
|
|
- } else {
|
|
|
|
|
- await client.invoke(
|
|
|
|
|
- new Api.messages.AddChatUser({
|
|
|
|
|
- chatId: inviteGroupEntity.id,
|
|
|
|
|
- userId: inputUser,
|
|
|
|
|
- fwdLimit: 0
|
|
|
|
|
- })
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const inputChannel = await workerTgClient.getInputChannel(inviteGroupEntity.chatId, inviteGroupEntity.accessHash)
|
|
|
|
|
+ await workerTgClient.inviteMembersToChannelGroup(inputChannel, [targetUser])
|
|
|
|
|
|
|
|
await this.taskItemRepo.update(item.id, {
|
|
await this.taskItemRepo.update(item.id, {
|
|
|
status: TaskItemStatus.SUCCESS,
|
|
status: TaskItemStatus.SUCCESS,
|
|
@@ -647,7 +611,7 @@ export class TaskExecutor {
|
|
|
/**
|
|
/**
|
|
|
* 获取随机延迟秒数
|
|
* 获取随机延迟秒数
|
|
|
*/
|
|
*/
|
|
|
- private getRandomDelaySeconds(min: number = 10, max: number = 20): number {
|
|
|
|
|
|
|
+ private getRandomDelaySeconds(min: number = 5, max: number = 10): number {
|
|
|
return Math.floor(Math.random() * (max - min + 1)) + min
|
|
return Math.floor(Math.random() * (max - min + 1)) + min
|
|
|
}
|
|
}
|
|
|
|
|
|