-
Notifications
You must be signed in to change notification settings - Fork 11
/
keygen.js
65 lines (55 loc) · 1.85 KB
/
keygen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module.exports = async ({
github,
context,
core,
KEYGEN_JS_CODE
}) => {
async function endWithComment(words, isok) {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: words || '指令匹配错误\n\ncommand match error'
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
state: 'closed',
labels: [isok ? '☑️keygen/注册机🎉' : '🤔invalid/无效的😒']
});
return;
}
if (context.payload.issue.title === 'keygen') {
let showerror = true;
try {
const info = context.payload.issue.body;
const commMatch = info.replace(/\r/g, '').match(/<!--.+-->/s);
if (commMatch) {
const conf = commMatch[0].split('\n').filter(i => !i.match(/:|<!--|-->/));
if (conf.length === 3) {
const key = KEYGEN_JS_CODE(...conf);
showerror = false;
await endWithComment(`您的离线激活码为/Your offline activation code is:
\`+${key}\`
---
最好在\`host\`中添加如下拦截,以防联网检测(懒,未删除该部分内容)
It is best to add the following interception to the \`host\` to prevent network detection (cause of lazy, this part of the content did not deleted)
\`\`\`
0.0.0.0 store.typora.io
0.0.0.0 dian.typora.com.cn
0.0.0.0 typora.com.cn
\`\`\``, true);
return;
}
}
if (showerror) await endWithComment('无法正确匹配到配置信息\n\nCan not match the configuration information correctly.');
return;
} catch (error) {
await endWithComment('激活码计算过程中发生错误\n\nAn error occurred during activation code calculation');
return;
}
} else {
await endWithComment();
}
};