forked from hczhcz/telegram-kuso-bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordle.cn.resource.js
75 lines (58 loc) · 1.68 KB
/
wordle.cn.resource.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
66
67
68
69
70
71
72
73
74
75
'use strict';
const fs = require('fs');
const readline = require('readline');
const config = require('./config');
const core = require('./wordle.cn.core');
const dicts = {};
const verify = (id, onValid, onNotValid) => {
let dictInfo = null;
for (const i in config.wordleCnDict) {
if (config.wordleCnDict[i].id === id) {
dictInfo = config.wordleCnDict[i];
break;
}
}
if (dictInfo) {
onValid();
} else {
onNotValid();
}
};
const load = (id, size, onDone, onNotValid) => {
let dictInfo = null;
for (const i in config.wordleCnDict) {
if (config.wordleCnDict[i].id === id) {
dictInfo = config.wordleCnDict[i];
break;
}
}
if (dictInfo && dictInfo.size.indexOf(size) >= 0) {
if (dicts[id + size]) {
onDone(dictInfo, dicts[id + size]);
} else {
const rl = readline.createInterface({
input: fs.createReadStream('wordle/' + id + '.dict'),
});
const dict = core.dictInit();
for (const i in config.wordleCnCustomWord) {
if (config.wordleCnCustomWord[i].length === size) {
core.dictAdd(dict, config.wordleCnCustomWord[i], true);
}
}
rl.on('line', (line) => {
if (line.length === size) {
core.dictAdd(dict, line, true);
}
}).on('close', () => {
dicts[id + size] = dict;
onDone(dictInfo, dict);
});
}
} else {
onNotValid();
}
};
module.exports = {
verify: verify,
load: load,
};