mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-12-01 01:05:30 +08:00
feat: 拓展中心
This commit is contained in:
1 parent
9ffa1efc26
commit
4eaddc2d75
74 files changed
+11738
-379
No files matched your search
@@ -149,6 +149,8 @@ function describeError(error) {
|
||||
async function onMessage(event) {
|
||||
try {
|
||||
const config = await loadConfig()
|
||||
// 交给自动化规则处理时,订阅路径必须彻底闭嘴,否则同一条消息回复两次。
|
||||
if (config.executionMode === 'automation') return
|
||||
const now = Date.now()
|
||||
const verdict = shouldReply(event, config, cooldownUntil, now)
|
||||
if (!verdict.reply || !verdict.rule) return
|
||||
@@ -198,6 +200,10 @@ module.exports = function activate(api) {
|
||||
if (!config.enabled) {
|
||||
return { success: false, error: '机器人未启用' }
|
||||
}
|
||||
// 订阅模式下这条路径同样会发送:直接跳过,避免与事件路径重复回复。
|
||||
if (config.executionMode === 'subscribe') {
|
||||
return { success: true, output: { matched: false, skipped: 'subscribe-mode' } }
|
||||
}
|
||||
const rule = pickRule(input.text, config)
|
||||
if (!rule) {
|
||||
return { success: true, output: { matched: false } }
|
||||
|
||||
@@ -20,6 +20,15 @@ const MAX_GROUPS = 200
|
||||
|
||||
const MODES = new Set(['contains', 'exact', 'prefix'])
|
||||
|
||||
/**
|
||||
* 两条回复入口的执行模式。
|
||||
*
|
||||
* 同一条消息若同时被「事件订阅」和「自动化动作」处理,会回复两次。
|
||||
* 这里用互斥模式从根上避免:默认保留订阅(兼容旧用户),
|
||||
* 切到 `automation` 后订阅路径完全不再发送。
|
||||
*/
|
||||
const EXECUTION_MODES = new Set(['subscribe', 'automation'])
|
||||
|
||||
/**
|
||||
* 把任意来源的配置规范化为 `configVersion: 2`。
|
||||
*
|
||||
@@ -49,6 +58,7 @@ function normalizeConfig(raw) {
|
||||
return {
|
||||
configVersion: CONFIG_VERSION,
|
||||
enabled: input.enabled === true,
|
||||
executionMode: EXECUTION_MODES.has(input.executionMode) ? input.executionMode : 'subscribe',
|
||||
rules,
|
||||
scope: {
|
||||
groups: Array.isArray(scope.groups)
|
||||
@@ -204,6 +214,7 @@ function clampNumber(value, min, max) {
|
||||
|
||||
module.exports = {
|
||||
CONFIG_VERSION,
|
||||
EXECUTION_MODES,
|
||||
normalizeConfig,
|
||||
matchRule,
|
||||
pickRule,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"manifestVersion": 1,
|
||||
"id": "com.example.keyword-bot",
|
||||
"name": "关键词回复机器人",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"apiVersion": "1",
|
||||
"minAppVersion": "2.6.0",
|
||||
"description": "监听微信文本消息,命中关键词后经 TraceMemo Gateway 回复。",
|
||||
@@ -19,7 +19,9 @@
|
||||
"background": "background/index.js"
|
||||
},
|
||||
"subscriptions": {
|
||||
"messageTypes": ["text"],
|
||||
"messageTypes": [
|
||||
"text"
|
||||
],
|
||||
"conversationIds": [],
|
||||
"requireMentionMe": false,
|
||||
"includeSelf": false
|
||||
|
||||
Reference in new issue
Block a user