koishi-plugin-bns-rate 1.0.6 → 1.0.8

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/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ # Ignore everything except plugin files
2
+ /*
3
+ !.gitignore
4
+ !/.github
5
+ !/index.js
6
+ !/package.json
package/index.js CHANGED
@@ -3,7 +3,7 @@ const { Schema } = require('koishi')
3
3
  const DEFAULT_URL = 'https://www.dd373.com/s-d5gqt8-0-0-0-0-0-0-0-0-0-0-0-1-0-5-0.html'
4
4
 
5
5
  const FORWARD_RE = /1元\s*=\s*(\d+\.?\d*)神石/g
6
- const REVERSE_RE = /1神石\s*=\s*(\d+\.?\d*)元/g
6
+
7
7
 
8
8
  const Config = Schema.object({
9
9
  url: Schema.string()
@@ -45,23 +45,11 @@ async function fetchRate(ctx, url) {
45
45
  throw new Error('无法解析页面汇率数据,页面结构可能已变更')
46
46
  }
47
47
 
48
- // 取对应的反向汇率
49
- const reverseMatches = [...html.matchAll(REVERSE_RE)]
50
- let bestReverse = null
51
- for (const m of reverseMatches) {
52
- const ctx = html.substring(Math.max(0, m.index - 50), m.index + 100)
53
- if (!ctx.includes('/神石')) {
54
- bestReverse = parseFloat(m[1])
55
- break
56
- }
57
- }
58
-
59
- if (bestReverse === null) {
60
- throw new Error('无法解析页面反向汇率数据')
61
- }
48
+ // 反向汇率直接用正向算,更准: 1神石 = 1/forward 元
49
+ const bestReverse = Math.round((1 / bestSeller) * 10000) / 10000
62
50
 
63
- if (bestSeller < 100 || bestSeller > 200 || bestReverse < 0.001 || bestReverse > 0.02) {
64
- throw new Error(`解析的汇率超出合理范围: forward=${bestSeller}, reverse=${bestReverse}`)
51
+ if (bestSeller < 100 || bestSeller > 200) {
52
+ throw new Error(`解析的汇率超出合理范围: forward=${bestSeller}`)
65
53
  }
66
54
 
67
55
  return { forward: bestSeller, reverse: bestReverse }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-bns-rate",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Fetch BNS Classic Divine Stone exchange rate from dd373.com",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
@@ -1,10 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(npm install *)",
5
- "Read(//c/Program Files/**)",
6
- "Bash(cmd //c \"where npm\")",
7
- "WebFetch(domain:registry.npmjs.org)"
8
- ]
9
- }
10
- }