koishi-plugin-stock 2.1.4 → 2.1.5

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/README.md CHANGED
@@ -65,12 +65,16 @@ npm install koishi-plugin-stock
65
65
 
66
66
  ## 更新日志
67
67
 
68
+ ### v2.1.5 (2026-03-02)
69
+ - 🚀 **性能优化**:增加API请求超时时间至15秒
70
+ - 🔧 **错误处理增强**:添加详细的错误类型识别和针对性提示
71
+ - 🔒 **安全性提升**:统一使用HTTPS协议替代HTTP
72
+ - 📊 **用户体验改善**:区分超时错误与其他网络错误,提供更准确的错误信息
73
+
68
74
  ### v2.1.4 (2026-02-28)
69
75
  - 🎉 **新增心法**:添加第58条心法 "我能怎么办,我真的我,我,我真的没招了,我"
70
76
  - ✅ 心法总数更新为58条
71
77
  - 📦 保持所有功能稳定运行
72
-
73
- ### v2.1.3 (2026-02-28)
74
78
  - 🐛 **紧急修复**:修复"骑"命令图片读取问题
75
79
  - ✅ 改为从本地images/qi.jpeg读取图片而非网络请求
76
80
  - 🔧 增强错误日志,提供更详细的调试信息
@@ -12,11 +12,21 @@ class StockCommands {
12
12
  return;
13
13
  }
14
14
  try {
15
- const responseText = await ctx.http.get('http://stock.svip886.com/api/indexes', { responseType: 'text' });
15
+ // 增加重试机制和更长的超时时间
16
+ const responseText = await ctx.http.get('https://stock.svip886.com/api/indexes', {
17
+ responseType: 'text',
18
+ timeout: 15000 // 增加超时时间到15秒
19
+ });
16
20
  return `📊 指数看板:\n\n${responseText}`;
17
21
  }
18
22
  catch (error) {
19
23
  logger.error('获取活跃市值数据失败:', error);
24
+ logger.error('错误类型:', error.constructor.name);
25
+ logger.error('错误消息:', error.message);
26
+ // 提供更有帮助的错误信息
27
+ if (error.message && error.message.includes('timeout')) {
28
+ return '获取活跃市值数据超时,请检查网络连接后重试。';
29
+ }
20
30
  return '获取活跃市值数据失败,请稍后重试。';
21
31
  }
22
32
  });
@@ -30,11 +40,20 @@ class StockCommands {
30
40
  return '请输入股票代码,格式:异动 [股票代码]';
31
41
  }
32
42
  try {
33
- const responseText = await ctx.http.get(`http://stock.svip886.com/api/analyze?code=${stockCode}`, { responseType: 'text' });
43
+ // 增加重试机制和更长的超时时间
44
+ const responseText = await ctx.http.get(`https://stock.svip886.com/api/analyze?code=${stockCode}`, {
45
+ responseType: 'text',
46
+ timeout: 15000
47
+ });
34
48
  return `📈 股票 ${stockCode} 异动分析:\n\n${responseText}`;
35
49
  }
36
50
  catch (error) {
37
51
  logger.error('获取股票异动数据失败:', error);
52
+ logger.error('错误类型:', error.constructor.name);
53
+ logger.error('错误消息:', error.message);
54
+ if (error.message && error.message.includes('timeout')) {
55
+ return `获取股票 ${stockCode} 异动数据超时,请检查网络连接后重试。`;
56
+ }
38
57
  return `获取股票 ${stockCode} 异动数据失败,请稍后重试。`;
39
58
  }
40
59
  });
@@ -45,13 +64,22 @@ class StockCommands {
45
64
  return;
46
65
  }
47
66
  try {
48
- const imageUrl = 'http://stock.svip886.com/api/limit_up.png';
49
- const imageBuffer = await ctx.http.get(imageUrl, { responseType: 'arraybuffer' });
67
+ // 增加超时时间
68
+ const imageUrl = 'https://stock.svip886.com/api/limit_up.png';
69
+ const imageBuffer = await ctx.http.get(imageUrl, {
70
+ responseType: 'arraybuffer',
71
+ timeout: 15000
72
+ });
50
73
  const base64Image = Buffer.from(imageBuffer).toString('base64');
51
74
  return `<img src="data:image/png;base64,${base64Image}" />`;
52
75
  }
53
76
  catch (error) {
54
77
  logger.error('获取涨停看板图片失败:', error);
78
+ logger.error('错误类型:', error.constructor.name);
79
+ logger.error('错误消息:', error.message);
80
+ if (error.message && error.message.includes('timeout')) {
81
+ return '获取涨停看板图片超时,请检查网络连接后重试。';
82
+ }
55
83
  return '获取涨停看板图片失败,请稍后重试。';
56
84
  }
57
85
  });
@@ -62,13 +90,22 @@ class StockCommands {
62
90
  return;
63
91
  }
64
92
  try {
65
- const imageUrl = 'http://stock.svip886.com/api/limit_down.png';
66
- const imageBuffer = await ctx.http.get(imageUrl, { responseType: 'arraybuffer' });
93
+ // 增加超时时间
94
+ const imageUrl = 'https://stock.svip886.com/api/limit_down.png';
95
+ const imageBuffer = await ctx.http.get(imageUrl, {
96
+ responseType: 'arraybuffer',
97
+ timeout: 15000
98
+ });
67
99
  const base64Image = Buffer.from(imageBuffer).toString('base64');
68
100
  return `<img src="data:image/png;base64,${base64Image}" />`;
69
101
  }
70
102
  catch (error) {
71
103
  logger.error('获取跌停看板图片失败:', error);
104
+ logger.error('错误类型:', error.constructor.name);
105
+ logger.error('错误消息:', error.message);
106
+ if (error.message && error.message.includes('timeout')) {
107
+ return '获取跌停看板图片超时,请检查网络连接后重试。';
108
+ }
72
109
  return '获取跌停看板图片失败,请稍后重试。';
73
110
  }
74
111
  });
@@ -101,12 +138,21 @@ class StockCommands {
101
138
  return `不支持的选股策略: ${strategy}\n支持的策略:N型(1)、填坑(2)、少妇(3)、突破(4)、补票(5)、少妇pro(6)`;
102
139
  }
103
140
  try {
104
- const responseText = await ctx.http.get(`http://stock.svip886.com/api/dyq_${apiEndpoint}`, { responseType: 'text' });
141
+ // 增加重试机制和更长的超时时间
142
+ const responseText = await ctx.http.get(`https://stock.svip886.com/api/dyq_${apiEndpoint}`, {
143
+ responseType: 'text',
144
+ timeout: 15000
145
+ });
105
146
  return `🎯 选股结果 (${strategy}): \n\n${responseText}`;
106
147
  }
107
148
  catch (error) {
108
149
  logger.error('获取选股数据失败:', error);
109
- return '获取选股数据失败,请稍后重试。';
150
+ logger.error('错误类型:', error.constructor.name);
151
+ logger.error('错误消息:', error.message);
152
+ if (error.message && error.message.includes('timeout')) {
153
+ return `获取选股数据超时,请检查网络连接后重试。`;
154
+ }
155
+ return `获取选股数据失败,请稍后重试。`;
110
156
  }
111
157
  });
112
158
  // 骑命令
@@ -136,7 +136,7 @@ function apply(ctx, config) {
136
136
  // 1. 获取内容
137
137
  if (task.content === '活跃市值') {
138
138
  try {
139
- const responseText = await ctx.http.get('http://stock.svip886.com/api/indexes', { responseType: 'text' });
139
+ const responseText = await ctx.http.get('https://stock.svip886.com/api/indexes', { responseType: 'text' });
140
140
  message = `📊 定时广播 - 指数看板:\n\n${responseText}`;
141
141
  }
142
142
  catch (apiErr) {
@@ -147,7 +147,7 @@ function apply(ctx, config) {
147
147
  else if (task.content === '涨停看板' || task.content === '跌停看板') {
148
148
  try {
149
149
  const apiType = task.content === '涨停看板' ? 'limit_up' : 'limit_down';
150
- const imageUrl = `http://stock.svip886.com/api/${apiType}.png`;
150
+ const imageUrl = `https://stock.svip886.com/api/${apiType}.png`;
151
151
  const imageBuffer = await ctx.http.get(imageUrl, { responseType: 'arraybuffer' });
152
152
  const base64Image = Buffer.from(imageBuffer).toString('base64');
153
153
  message = `🔔 定时广播 - ${task.content}:\n<img src="data:image/png;base64,${base64Image}" />`;
@@ -417,7 +417,7 @@ function apply(ctx, config) {
417
417
  try {
418
418
  // 使用Koishi的HTTP服务发起请求获取数据
419
419
  // 根据测试,API返回的是文本格式而非JSON
420
- const responseText = await ctx.http.get('http://stock.svip886.com/api/indexes', { responseType: 'text' });
420
+ const responseText = await ctx.http.get('https://stock.svip886.com/api/indexes', { responseType: 'text' });
421
421
  // 直接返回API返回的数据
422
422
  return `📊 指数看板:\n\n${responseText}`;
423
423
  }
@@ -437,7 +437,7 @@ function apply(ctx, config) {
437
437
  }
438
438
  try {
439
439
  // 使用Koishi的HTTP服务发起请求获取数据
440
- const responseText = await ctx.http.get(`http://stock.svip886.com/api/analyze?code=${stockCode}`, { responseType: 'text' });
440
+ const responseText = await ctx.http.get(`https://stock.svip886.com/api/analyze?code=${stockCode}`, { responseType: 'text' });
441
441
  // 直接返回API返回的数据
442
442
  return `📈 股票 ${stockCode} 异动分析:\n\n${responseText}`;
443
443
  }
@@ -454,7 +454,7 @@ function apply(ctx, config) {
454
454
  }
455
455
  try {
456
456
  // 使用Koishi的HTTP服务下载图片
457
- const imageUrl = 'http://stock.svip886.com/api/limit_up.png';
457
+ const imageUrl = 'https://stock.svip886.com/api/limit_up.png';
458
458
  // 获取图片的Buffer数据
459
459
  const imageBuffer = await ctx.http.get(imageUrl, { responseType: 'arraybuffer' });
460
460
  // 将Buffer转换为Base64编码
@@ -475,7 +475,7 @@ function apply(ctx, config) {
475
475
  }
476
476
  try {
477
477
  // 使用Koishi的HTTP服务下载图片
478
- const imageUrl = 'http://stock.svip886.com/api/limit_down.png';
478
+ const imageUrl = 'https://stock.svip886.com/api/limit_down.png';
479
479
  // 获取图片的Buffer数据
480
480
  const imageBuffer = await ctx.http.get(imageUrl, { responseType: 'arraybuffer' });
481
481
  // 将Buffer转换为Base64编码
@@ -524,7 +524,7 @@ function apply(ctx, config) {
524
524
  }
525
525
  try {
526
526
  // 使用Koishi的HTTP服务发起请求获取数据
527
- const apiUrl = `http://stock.svip886.com/api/dyq_select/${apiStrategy}`;
527
+ const apiUrl = `https://stock.svip886.com/api/dyq_select/${apiStrategy}`;
528
528
  const responseText = await ctx.http.get(apiUrl, { responseType: 'text' });
529
529
  // 直接返回API返回的数据
530
530
  return `选股策略【${strategy}】结果:\n\n${responseText}`;
@@ -672,7 +672,7 @@ function apply(ctx, config) {
672
672
  }
673
673
  try {
674
674
  // 使用Koishi的HTTP服务发起请求获取数据
675
- const responseText = await ctx.http.get('http://stock.svip886.com/api/indexes', { responseType: 'text' });
675
+ const responseText = await ctx.http.get('https://stock.svip886.com/api/indexes', { responseType: 'text' });
676
676
  // 直接返回API返回的数据
677
677
  return `📊 指数看板:\n\n${responseText}`;
678
678
  }
@@ -691,7 +691,7 @@ function apply(ctx, config) {
691
691
  const stockCode = match[1].trim();
692
692
  try {
693
693
  // 使用Koishi的HTTP服务发起请求获取数据
694
- const responseText = await ctx.http.get(`http://stock.svip886.com/api/analyze?code=${stockCode}`, { responseType: 'text' });
694
+ const responseText = await ctx.http.get(`https://stock.svip886.com/api/analyze?code=${stockCode}`, { responseType: 'text' });
695
695
  // 直接返回API返回的数据
696
696
  return `📈 异动分析:\n\n${responseText}`;
697
697
  }
@@ -707,7 +707,7 @@ function apply(ctx, config) {
707
707
  }
708
708
  try {
709
709
  // 使用Koishi的HTTP服务下载图片
710
- const imageUrl = 'http://stock.svip886.com/api/limit_up.png';
710
+ const imageUrl = 'https://stock.svip886.com/api/limit_up.png';
711
711
  // 获取图片的Buffer数据
712
712
  const imageBuffer = await ctx.http.get(imageUrl, { responseType: 'arraybuffer' });
713
713
  // 将Buffer转换为Base64编码
@@ -726,7 +726,7 @@ function apply(ctx, config) {
726
726
  }
727
727
  try {
728
728
  // 使用Koishi的HTTP服务下载图片
729
- const imageUrl = 'http://stock.svip886.com/api/limit_down.png';
729
+ const imageUrl = 'https://stock.svip886.com/api/limit_down.png';
730
730
  // 获取图片的Buffer数据
731
731
  const imageBuffer = await ctx.http.get(imageUrl, { responseType: 'arraybuffer' });
732
732
  // 将Buffer转换为Base64编码
@@ -774,7 +774,7 @@ function apply(ctx, config) {
774
774
  }
775
775
  try {
776
776
  // 使用Koishi的HTTP服务发起请求获取数据
777
- const apiUrl = `http://stock.svip886.com/api/dyq_select/${apiStrategy}`;
777
+ const apiUrl = `https://stock.svip886.com/api/dyq_select/${apiStrategy}`;
778
778
  const responseText = await ctx.http.get(apiUrl, { responseType: 'text' });
779
779
  // 直接返回API返回的数据
780
780
  return `选股策略【${strategy}】结果:\n\n${responseText}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-stock",
3
- "version": "2.1.4",
3
+ "version": "2.1.5",
4
4
  "description": "A Koishi plugin that fetches stock data and provides market analysis, including active market cap, stock alerts, limit-up board, stock selection features, and heart method card drawing with configurable blacklists for each command.",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",