(rule: CommandRule)
| 540 | this.config.customRules = []; |
| 541 | } |
| 542 | |
| 543 | // 检查所有规则之间的冲突 |
| 544 | const existingCustomRules = this.getCustomRules(); |
| 545 | |
| 546 | // 检查参数冲突(带参数的规则) |
| 547 | if (rule.parameters && rule.parameters.length > 0) { |
| 548 | for (const param of rule.parameters) { |
| 549 | // 查找是否有其他规则使用了相同的参数但条件不同 |
| 550 | const conflictingRule = existingCustomRules.find(r => |
| 551 | r.command === rule.command && |
| 552 | r.parameters && |
| 553 | r.parameters.includes(param) && |
| 554 | (r.delay !== rule.delay || !!r.deleteResponse !== !!rule.deleteResponse) |
| 555 | ); |
| 556 | |
| 557 | if (conflictingRule) { |
| 558 | const conflictResponse = conflictingRule.deleteResponse ? " (含响应)" : ""; |
| 559 | const newResponse = rule.deleteResponse ? " (含响应)" : ""; |
| 560 | const safeParam = htmlEscape(param); |
| 561 | const safeRuleCommand = htmlEscape(rule.command); |
| 562 | const safeConflictCommand = htmlEscape(conflictingRule.command); |
| 563 | return { |
| 564 | success: false, |
| 565 | error: `参数冲突: 参数 "${safeParam}" 已存在于规则 "${safeConflictCommand} → ${conflictingRule.delay}秒删除${conflictResponse}" 中,与新规则 "${safeRuleCommand} → ${rule.delay}秒删除${newResponse}" 冲突\n |
| 566 | 💡 提示: 使用 "<code>${mainPrefix}autodelcmd del ${conflictingRule.id}</code>" 删除冲突规则后重试` |
| 567 | }; |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | // 检查不带参数规则的冲突 |
| 573 | if (!rule.parameters || rule.parameters.length === 0) { |
| 574 | // 查找是否存在相同命令、相同exactMatch模式的不带参数规则但其他条件不同 |
| 575 | const conflictingRule = existingCustomRules.find(r => |
| 576 | r.command === rule.command && |
| 577 | (!r.parameters || r.parameters.length === 0) && |
| 578 | !!r.exactMatch === !!rule.exactMatch && // exactMatch模式必须相同才检查冲突 |
| 579 | (r.delay !== rule.delay || !!r.deleteResponse !== !!rule.deleteResponse) |
| 580 | ); |
| 581 | |
| 582 | if (conflictingRule) { |
| 583 | const conflictResponse = conflictingRule.deleteResponse ? " (含响应)" : ""; |
| 584 | const conflictExact = conflictingRule.exactMatch ? " (精确匹配)" : " (普通匹配)"; |
| 585 | const newResponse = rule.deleteResponse ? " (含响应)" : ""; |
| 586 | const newExact = rule.exactMatch ? " (精确匹配)" : " (普通匹配)"; |
| 587 | |
| 588 | const safeRuleCommand = htmlEscape(rule.command); |
| 589 | const safeConflictCommand = htmlEscape(conflictingRule.command); |
| 590 | return { |
| 591 | success: false, |
| 592 | error: `规则冲突: 命令 "${safeRuleCommand}" 已存在规则 "→ ${conflictingRule.delay}秒删除${conflictResponse}${conflictExact}",与新规则 "${safeConflictCommand} → ${rule.delay}秒删除${newResponse}${newExact}" 冲突\n |
| 593 | 💡 提示: 使用 "<code>${mainPrefix}autodelcmd del ${conflictingRule.id}</code>" 删除冲突规则后重试` |
| 594 | }; |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | // 查找是否存在相同命令、延迟、deleteResponse和exactMatch设置的规则 |
| 599 | const existingRuleIndex = this.config.customRules.findIndex(r => |
no test coverage detected