koishi-plugin-dwrgbwiki 2.1.2 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/codex.js +44 -56
- package/index.js +13 -1
- package/notice.js +16 -16
- package/package.json +1 -1
package/codex.js
CHANGED
|
@@ -36,26 +36,26 @@ async function fetchText(url, timeout) {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
async function fetchUrl(url, timeout) {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
let res = await doFetch()
|
|
50
|
-
if (res.status === 567 || res.status === 429 || res.status === 503) {
|
|
51
|
-
await new Promise(r => setTimeout(r, 3000))
|
|
52
|
-
res = await doFetch()
|
|
53
|
-
}
|
|
54
|
-
if (!res.ok) throw new Error('HTTP ' + res.status)
|
|
55
|
-
return await res.text()
|
|
56
|
-
} finally {
|
|
57
|
-
clearTimeout(timer)
|
|
39
|
+
const headers = {
|
|
40
|
+
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36',
|
|
41
|
+
'Accept-Language': 'zh-CN,zh;q=0.9',
|
|
42
|
+
}
|
|
43
|
+
const doFetch = () => {
|
|
44
|
+
const ctrl = new AbortController()
|
|
45
|
+
const timer = setTimeout(() => ctrl.abort(), timeout)
|
|
46
|
+
const p = fetch(url, { signal: ctrl.signal, headers })
|
|
47
|
+
p.finally(() => clearTimeout(timer))
|
|
48
|
+
return p
|
|
58
49
|
}
|
|
50
|
+
let res = await doFetch()
|
|
51
|
+
const RETRY_WAIT = [3000, 8000]
|
|
52
|
+
for (const wait of RETRY_WAIT) {
|
|
53
|
+
if (res.status !== 567 && res.status !== 429 && res.status !== 503) break
|
|
54
|
+
await new Promise(r => setTimeout(r, wait))
|
|
55
|
+
res = await doFetch()
|
|
56
|
+
}
|
|
57
|
+
if (!res.ok) throw new Error('HTTP ' + res.status)
|
|
58
|
+
return await res.text()
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
async function fetchCategoryMembers(category, config) {
|
|
@@ -74,6 +74,14 @@ async function fetchCategoryMembers(category, config) {
|
|
|
74
74
|
return titles
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
async function searchPages(query, config) {
|
|
78
|
+
const q = String(query || '').trim().replace(/[“”"]/g, '')
|
|
79
|
+
if (!q) return []
|
|
80
|
+
const url = API_BASE + '/api.php?action=query&list=search&srsearch=' + encodeURIComponent(q) + '&srlimit=5&format=json&formatversion=2'
|
|
81
|
+
const data = await fetchRaw(url, config.timeout || 15000)
|
|
82
|
+
return (data.query && data.query.search) || []
|
|
83
|
+
}
|
|
84
|
+
|
|
77
85
|
function buildRoleHtml(category, titles, config) {
|
|
78
86
|
const width = config.width || 1300
|
|
79
87
|
const total = titles.length
|
|
@@ -116,49 +124,28 @@ body { background:#0d1117; color:#c9d1d9; font-family:-apple-system,BlinkMacSyst
|
|
|
116
124
|
async function resolveTitle(title, config) {
|
|
117
125
|
const q = String(title || '').trim()
|
|
118
126
|
if (!q) throw new Error('请输入页面名')
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (!triedQuotes && !/[“”"]/.test(q)) {
|
|
127
|
-
triedQuotes = true
|
|
128
|
-
current = '“' + q + '”'
|
|
129
|
-
continue
|
|
130
|
-
}
|
|
131
|
-
throw new Error('页面不存在:' + current)
|
|
132
|
-
}
|
|
127
|
+
const hasQuote = /[“”"]/.test(q)
|
|
128
|
+
const candidates = hasQuote ? [q] : [q, '“' + q + '”']
|
|
129
|
+
const url = API_BASE + '/api.php?action=query&redirects=1&prop=info&titles=' + encodeURIComponent(candidates.join('|')) + '&format=json&formatversion=2'
|
|
130
|
+
const data = await fetchRaw(url, config.timeout || 15000)
|
|
131
|
+
const pages = (data.query && data.query.pages) || []
|
|
132
|
+
const page = pages.find(p => !p.missing && p.title)
|
|
133
|
+
if (page) return page.title
|
|
133
134
|
throw new Error('页面不存在:' + q)
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
async function fetchWikitext(title, config) {
|
|
137
138
|
const q = String(title || '').trim()
|
|
138
139
|
if (!q) throw new Error('请输入要查询的名称')
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
triedQuotes = true
|
|
149
|
-
current = '“' + q + '”'
|
|
150
|
-
continue
|
|
151
|
-
}
|
|
152
|
-
throw new Error('页面不存在:' + current)
|
|
153
|
-
}
|
|
154
|
-
if (!page.revisions || !page.revisions.length) throw new Error('页面「' + current + '」无内容')
|
|
155
|
-
const content = page.revisions[0].content
|
|
156
|
-
const rd = content.match(/^\s*#(?:重定向|REDIRECT)\s*\[\[([^\]]+)\]\]/)
|
|
157
|
-
if (rd && rd[1] && rd[1] !== current) {
|
|
158
|
-
current = rd[1].split('|')[0].trim()
|
|
159
|
-
continue
|
|
160
|
-
}
|
|
161
|
-
return { title: page.title, content }
|
|
140
|
+
const hasQuote = /[“”"]/.test(q)
|
|
141
|
+
const candidates = hasQuote ? [q] : [q, '“' + q + '”']
|
|
142
|
+
const url = API_BASE + '/api.php?action=query&prop=revisions&rvprop=content&redirects=1&format=json&formatversion=2&titles=' + encodeURIComponent(candidates.join('|'))
|
|
143
|
+
const data = await fetchRaw(url, config.timeout || 15000)
|
|
144
|
+
const pages = (data.query && data.query.pages) || []
|
|
145
|
+
const found = pages.find(p => !p.missing)
|
|
146
|
+
if (found) {
|
|
147
|
+
if (found.revisions && found.revisions.length) return { title: found.title, content: found.revisions[0].content }
|
|
148
|
+
throw new Error('页面「' + found.title + '」无内容')
|
|
162
149
|
}
|
|
163
150
|
throw new Error('页面不存在:' + q)
|
|
164
151
|
}
|
|
@@ -510,6 +497,7 @@ module.exports = {
|
|
|
510
497
|
fetchWikitext,
|
|
511
498
|
resolveTitle,
|
|
512
499
|
fetchCategoryMembers,
|
|
500
|
+
searchPages,
|
|
513
501
|
buildRoleHtml,
|
|
514
502
|
parseTemplates,
|
|
515
503
|
mergeParams,
|
package/index.js
CHANGED
|
@@ -879,7 +879,19 @@ async function codexImage(ctx, config, rest) {
|
|
|
879
879
|
return [h.image(image, 'image/png')]
|
|
880
880
|
} catch (e) {
|
|
881
881
|
ctx.logger('dwrgbwiki').warn(e)
|
|
882
|
-
|
|
882
|
+
const msg = e && e.message ? e.message : String(e)
|
|
883
|
+
if (String(msg).includes('页面不存在')) {
|
|
884
|
+
try {
|
|
885
|
+
const results = await codex.searchPages(q, config)
|
|
886
|
+
if (results.length) {
|
|
887
|
+
const list = results.slice(0, 5).map(r => ' ' + r.title).join('\n')
|
|
888
|
+
return '未找到「' + q + '」相关页面,为你找到:\n' + list + '\n可尝试:图鉴 ' + sub.name + ' <上面的名称>'
|
|
889
|
+
}
|
|
890
|
+
} catch (e2) {
|
|
891
|
+
ctx.logger('dwrgbwiki').warn(e2)
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
return errorImage(ctx, config, '图鉴查询失败:' + msg, '图鉴', codexWidth(sub, config))
|
|
883
895
|
}
|
|
884
896
|
}
|
|
885
897
|
|
package/notice.js
CHANGED
|
@@ -240,38 +240,38 @@ body { font-family:-apple-system,BlinkMacSystemFont,'Segoe UI','Microsoft YaHei'
|
|
|
240
240
|
.hero { text-align:center; padding:26px 24px 22px; border-radius:18px; margin-bottom:18px;
|
|
241
241
|
background:linear-gradient(135deg, #667eea 0%, #764ba2 55%, #a4508b 100%); box-shadow:0 8px 28px rgba(0,0,0,.4); position:relative; overflow:hidden; }
|
|
242
242
|
.hero::after { content:''; position:absolute; inset:0; background:radial-gradient(600px 200px at 80% -20%, rgba(255,255,255,.18), transparent 60%); }
|
|
243
|
-
.badge { display:inline-flex; align-items:center; gap:6px; font-size:
|
|
243
|
+
.badge { display:inline-flex; align-items:center; gap:6px; font-size:25px; font-weight:700; color:#ffd76d;
|
|
244
244
|
background:rgba(0,0,0,.28); border:1px solid rgba(255,215,109,.4); border-radius:999px; padding:4px 14px; margin-bottom:12px; letter-spacing:1px; }
|
|
245
|
-
.title { font-size:
|
|
246
|
-
.sub { font-size:
|
|
245
|
+
.title { font-size:35px; font-weight:800; color:#fff; letter-spacing:2px; text-shadow:0 2px 10px rgba(0,0,0,.35); }
|
|
246
|
+
.sub { font-size:25px; color:rgba(255,255,255,.8); margin-top:8px; letter-spacing:.5px; }
|
|
247
247
|
.intro { background:rgba(22,27,34,.82); border:1px solid rgba(255,255,255,.1); border-left:4px solid #ffd76d;
|
|
248
|
-
border-radius:14px; padding:16px 20px; margin-bottom:16px; line-height:1.9; font-size:
|
|
248
|
+
border-radius:14px; padding:16px 20px; margin-bottom:16px; line-height:1.9; font-size:25px; color:#c9d1d9; }
|
|
249
249
|
.section { background:rgba(22,27,34,.78); border:1px solid rgba(255,255,255,.09); border-radius:16px; padding:18px 20px; margin-bottom:16px; }
|
|
250
|
-
.s-head { display:flex; align-items:center; gap:12px; font-size:
|
|
250
|
+
.s-head { display:flex; align-items:center; gap:12px; font-size:25px; font-weight:800; color:#ffd76d; letter-spacing:1px;
|
|
251
251
|
padding-bottom:12px; margin-bottom:12px; border-bottom:1px solid rgba(255,255,255,.08); }
|
|
252
252
|
.s-num { flex-shrink:0; width:34px; height:34px; border-radius:10px; display:flex; align-items:center; justify-content:center;
|
|
253
|
-
font-size:
|
|
254
|
-
.s-sub { font-size:
|
|
255
|
-
.s-h3 { font-size:
|
|
256
|
-
.row { display:flex; gap:10px; margin-bottom:10px; line-height:1.85; font-size:
|
|
253
|
+
font-size:25px; font-weight:800; color:#fff; background:linear-gradient(135deg,#667eea,#764ba2); box-shadow:0 3px 10px rgba(102,126,234,.35); }
|
|
254
|
+
.s-sub { font-size:25px; font-weight:700; color:#79c0ff; margin:2px 0 10px; padding-left:10px; border-left:3px solid #58a6ff; line-height:1.6; }
|
|
255
|
+
.s-h3 { font-size:25px; font-weight:700; color:#56d4dd; margin:12px 0 8px; padding-left:10px; border-left:3px solid #56d4dd; line-height:1.6; }
|
|
256
|
+
.row { display:flex; gap:10px; margin-bottom:10px; line-height:1.85; font-size:25px; color:#c9d1d9; }
|
|
257
257
|
.row:last-child { margin-bottom:0; }
|
|
258
258
|
.dot { flex-shrink:0; width:7px; height:7px; border-radius:50%; margin-top:10px; background:linear-gradient(135deg,#ffd76d,#ff8c00); box-shadow:0 0 6px rgba(255,180,60,.6); }
|
|
259
259
|
.row-text { flex:1; }
|
|
260
260
|
.row.changed { background:rgba(255,215,109,.08); border:1px solid rgba(255,215,109,.28); border-radius:8px; padding:6px 10px; margin-left:-6px; margin-right:-6px; }
|
|
261
261
|
.row.changed .dot { background:#3fb950; box-shadow:0 0 6px rgba(63,185,80,.6); }
|
|
262
262
|
.kw { color:#ffd76d; font-weight:700; }
|
|
263
|
-
.tag-new { flex-shrink:0; font-size:
|
|
263
|
+
.tag-new { flex-shrink:0; font-size:25px; font-weight:700; color:#0d1117; background:linear-gradient(135deg,#3fb950,#2ea043); border-radius:999px; padding:2px 10px; letter-spacing:.5px; }
|
|
264
264
|
.tbl { margin:10px 0 14px; }
|
|
265
265
|
.tbl.changed { border:1px solid rgba(255,215,109,.35); border-radius:12px; padding:10px 12px; background:rgba(255,215,109,.05); }
|
|
266
266
|
.intro.update { border-left-color:#3fb950; }
|
|
267
|
-
.tbl-title { font-size:
|
|
267
|
+
.tbl-title { font-size:25px; font-weight:800; color:#fff; margin-bottom:8px; letter-spacing:.5px; }
|
|
268
268
|
.tbl table { width:100%; border-collapse:collapse; border-radius:10px; overflow:hidden; }
|
|
269
|
-
.tbl th { background:linear-gradient(135deg,#667eea,#764ba2); color:#fff; font-size:
|
|
270
|
-
.tbl td { padding:8px 14px; font-size:
|
|
269
|
+
.tbl th { background:linear-gradient(135deg,#667eea,#764ba2); color:#fff; font-size:25px; font-weight:700; padding:8px 14px; text-align:center; }
|
|
270
|
+
.tbl td { padding:8px 14px; font-size:25px; text-align:center; color:#e6edf3; border-top:1px solid rgba(255,255,255,.07); background:rgba(255,255,255,.02); }
|
|
271
271
|
.end-card { background:rgba(248,81,73,.08); border:1px solid rgba(248,81,73,.35); border-radius:16px; padding:18px 20px; margin-top:4px; }
|
|
272
|
-
.end-title { font-size:
|
|
273
|
-
.end-body { line-height:1.9; font-size:
|
|
274
|
-
.foot { text-align:center; color:#8b949e; font-size:
|
|
272
|
+
.end-title { font-size:25px; font-weight:800; color:#ff7b72; margin-bottom:10px; letter-spacing:.5px; }
|
|
273
|
+
.end-body { line-height:1.9; font-size:25px; color:#c9d1d9; }
|
|
274
|
+
.foot { text-align:center; color:#8b949e; font-size:25px; margin-top:16px; opacity:.75; letter-spacing:.5px; }
|
|
275
275
|
</style>
|
|
276
276
|
</head>
|
|
277
277
|
<body>
|
package/package.json
CHANGED