Skip to content

Commit 5a10de8

Browse files
author
dompling
committed
update
1 parent dbece78 commit 5a10de8

File tree

9 files changed

+669
-0
lines changed

9 files changed

+669
-0
lines changed

.github/workflows/build-store.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Build Store
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
permissions:
14+
contents: write
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: '20'
24+
25+
- name: Install dependencies
26+
run: npm install
27+
28+
- name: Build store.json and README files
29+
run: npm run build
30+
31+
- name: Check for changes
32+
id: git-check
33+
run: |
34+
git add -A
35+
git diff --staged --exit-code || echo "changed=true" >> $GITHUB_OUTPUT
36+
37+
- name: Commit and push changes
38+
if: steps.git-check.outputs.changed == 'true'
39+
run: |
40+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
41+
git config --local user.name "github-actions[bot]"
42+
git commit -m "🤖 Auto-update store.json and README files"
43+
git push

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea
2+
node_modules
3+
.vscode
4+
.claude

README.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# TrollScript Store
2+
3+
巨魔脚本商店 - 自动化脚本仓库
4+
5+
[![Build Store](https://github.com/dompling/TrollScript-Store/actions/workflows/build-store.yml/badge.svg)](https://github.com/dompling/TrollScript-Store/actions/workflows/build-store.yml)
6+
7+
## 🔗 相关链接
8+
9+
- **发布仓库**: [TrollScript-Release](https://github.com/dompling/TrollScript-Release)
10+
- **API 文档**: [API.md](https://github.com/dompling/TrollScript-Release/blob/main/API.md)
11+
12+
## 📜 脚本列表
13+
14+
<!-- SCRIPTS_START -->
15+
| 脚本 | 描述 | 版本 | 文档 |
16+
|------|------|------|------|
17+
| **ExpressSMS** | 提取快递短信取件码 | `1.0.0` | [📖](./message/README.md) |
18+
<!-- SCRIPTS_END -->
19+
20+
## 📦 项目结构
21+
22+
```
23+
TrollScript-Store/
24+
├── .github/
25+
│ └── workflows/
26+
│ └── build-store.yml # GitHub Actions 自动构建
27+
├── message/ # 消息类脚本
28+
│ └── *.js
29+
│ └── README.md # 自动生成的脚本文档
30+
├── scripts/
31+
│ └── build-store.js # 构建脚本
32+
├── store.json # 生成的商店数据
33+
├── package.json
34+
└── README.md
35+
```
36+
37+
## 🚀 快速开始
38+
39+
### 添加新脚本
40+
41+
1.`message/` 或其他目录下创建 `.js` 文件
42+
2. 在文件顶部添加元数据注释:
43+
44+
```javascript
45+
/*
46+
id: YourScriptId
47+
name: 脚本名称
48+
description: 脚本描述
49+
icon: terminal
50+
category: 工具
51+
version: 1.0.0
52+
*/
53+
54+
// 你的脚本代码...
55+
```
56+
57+
3. 提交并推送到 `main` 分支
58+
4. GitHub Actions 会自动构建并更新 `store.json` 和脚本文档
59+
60+
### 元数据字段说明
61+
62+
| 字段 | 必填 | 说明 |
63+
|------|------|------|
64+
| `id` || 脚本唯一标识符 |
65+
| `name` || 脚本显示名称 |
66+
| `description` || 脚本描述 |
67+
| `icon` || 图标名称 (SF Symbols) |
68+
| `category` || 分类名称 |
69+
| `version` || 版本号 (语义化版本) |
70+
71+
### 可用图标
72+
73+
使用 [SF Symbols](https://developer.apple.com/sf-symbols/) 图标名称,例如:
74+
- `terminal` - 终端
75+
- `play.circle` - 播放
76+
- `message` - 消息
77+
- `gear` - 设置
78+
- `doc.text` - 文档
79+
80+
## 🛠 本地开发
81+
82+
### 安装依赖
83+
84+
```bash
85+
npm install
86+
```
87+
88+
### 手动构建
89+
90+
```bash
91+
npm run build
92+
```
93+
94+
这将扫描所有脚本文件并生成 `store.json` 和脚本文档。
95+
96+
## 🔄 自动化工作流
97+
98+
当你推送脚本文件到 `main` 分支时,GitHub Actions 会自动:
99+
100+
1. 检出代码
101+
2. 安装依赖
102+
3. 运行构建脚本
103+
4. 生成 `store.json` 和各目录的脚本 README
104+
5. 更新主 README.md 的脚本列表
105+
6. 如果有变化,自动提交更新
106+
107+
你也可以在 GitHub Actions 页面手动触发构建(workflow_dispatch)。
108+
109+
## 📄 store.json 结构
110+
111+
```json
112+
{
113+
"version": "1.0",
114+
"lastUpdated": "2024-03-20T12:00:00Z",
115+
"categories": ["工具", "媒体"],
116+
"authors": [
117+
{
118+
"name": "dompling",
119+
"avatar": "https://avatars.githubusercontent.com/u/23498579?v=4",
120+
"scripts": [
121+
{
122+
"id": "ScriptId",
123+
"name": "脚本名称",
124+
"description": "脚本描述",
125+
"icon": "terminal",
126+
"category": "工具",
127+
"version": "1.0.0",
128+
"downloadUrl": "https://raw.githubusercontent.com/.../script.js",
129+
"size": 1024,
130+
"downloads": 100,
131+
"createdAt": "2024-03-20T12:00:00Z",
132+
"updatedAt": "2024-03-20T12:00:00Z"
133+
}
134+
]
135+
}
136+
]
137+
}
138+
```
139+
140+
## 📝 License
141+
142+
ISC © [dompling](https://github.com/dompling)

message/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# message 脚本
2+
3+
此目录包含 1 个脚本。
4+
5+
## 脚本列表
6+
7+
| 脚本 | 描述 | 版本 | 分类 |
8+
|------|------|------|------|
9+
| [ExpressSMS](./sms.js) | 提取快递短信取件码 | `1.0.0` | 工具 |
10+
11+
---
12+
13+
> 此文件由构建脚本自动生成,请勿手动编辑。

message/sms.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
id: ExpressSMS
3+
name: ExpressSMS
4+
description: 提取快递短信取件码
5+
icon: terminal
6+
category: 工具
7+
version: 1.0.0
8+
*/
9+
10+
function main() {
11+
if (!sms.checkAccess()) {
12+
console.error("没有短信访问权限");
13+
return;
14+
}
15+
16+
const messages = sms.read(20);
17+
if (!messages || messages.length === 0) {
18+
console.log("未读取到短信");
19+
return;
20+
}
21+
22+
const patterns = [
23+
{
24+
regex: /(?:|\[\]).*?\s*(\d+).*?\s*(.+?)(?:|$)/,
25+
codeIndex: 1,
26+
locationIndex: 2
27+
},
28+
{
29+
regex: /(?:(.*?)|\[(.*?)\]).*?(?:|)\s*(.+?)(?:|||).*?\s*([A-Za-z0-9-]+?)/,
30+
codeIndex: 4,
31+
locationIndex: 3
32+
}
33+
];
34+
35+
const upcomingReminders = reminder.getUpcoming(7) || [];
36+
37+
const STORAGE_KEY = 'sms_processed_codes';
38+
let processedCodes = storage.get(STORAGE_KEY) || [];
39+
40+
let processedCount = 0;
41+
let hasNew = false;
42+
43+
for (let i = 0; i < messages.length; i++) {
44+
const msg = messages[i];
45+
let match = null;
46+
let code = null;
47+
let location = null;
48+
49+
for (const pattern of patterns) {
50+
match = msg.text.match(pattern.regex);
51+
if (match) {
52+
code = match[pattern.codeIndex];
53+
location = match[pattern.locationIndex];
54+
break;
55+
}
56+
}
57+
58+
if (match && code && location) {
59+
// 唯一标识 (仅使用取件码,防止位置描述不同导致重复)
60+
const uniqueKey = code;
61+
62+
// 查重逻辑 1: 检查持久化缓存 (以及本次运行已处理的)
63+
// 兼容旧的缓存格式 "code|location"
64+
if (processedCodes.some(item => item === uniqueKey || item.startsWith(`${code}|`))) {
65+
console.log(`跳过已缓存的取件码: ${code}`);
66+
continue;
67+
}
68+
69+
const isDuplicateReminder = upcomingReminders.some(r => r.title.includes(code));
70+
if (isDuplicateReminder) {
71+
console.log(`跳过现有提醒事项: ${code}`);
72+
// 即使缓存没有,如果有提醒了,也加入缓存
73+
if (!processedCodes.includes(uniqueKey)) {
74+
processedCodes.push(uniqueKey);
75+
hasNew = true;
76+
}
77+
continue;
78+
}
79+
80+
reminder.createSystemReminder(`取件码: ${code}`, {
81+
notes: `位置: ${location}\n原文: ${msg.text || msg.body}`,
82+
priority: 5,
83+
listTitle: "取件码"
84+
});
85+
86+
notification.send("快递取件提醒", `凭取件码 ${code}${location} 取件`, {});
87+
88+
console.log(`已提取取件码: ${code} (${location})`);
89+
90+
// 更新缓存
91+
processedCodes.push(uniqueKey);
92+
hasNew = true;
93+
processedCount++;
94+
}
95+
}
96+
97+
if (processedCount === 0) {
98+
console.log("未找到新的取件码短信");
99+
}
100+
}
101+
102+
main();

package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "trollscript-store",
3+
"version": "1.0.0",
4+
"main": "",
5+
"author": "dompling",
6+
"license": "ISC",
7+
"description": "巨魔脚本",
8+
"scripts": {
9+
"build": "node scripts/build-store.js",
10+
"prebuild": "echo '🔮 开始构建 store.json...'"
11+
},
12+
"dependencies": {
13+
"@dompling/trollscript-types": "^1.0.24"
14+
}
15+
}

0 commit comments

Comments
 (0)