koishi-plugin-stock 1.0.2 → 1.0.4

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
@@ -7,6 +7,7 @@
7
7
  - 用户发送"活跃市值"命令时,自动从 http://stock.svip886.com/api/indexes 获取数据并格式化显示
8
8
  - 用户发送"异动 [股票代码]"命令时,自动从 http://stock.svip886.com/api/analyze?code=[股票代码] 获取指定股票的异动分析数据
9
9
  - 用户发送"涨停看板"命令时,自动下载 http://stock.svip886.com/api/limit_up.png 图片并显示
10
+ - 用户发送"选股 [策略名称]"命令时,自动从 http://stock.svip886.com/api/dyq_select/[策略API名] 获取选股结果
10
11
  - 自动格式化数据显示给用户
11
12
 
12
13
  ## 安装
package/lib/index.js CHANGED
@@ -55,6 +55,49 @@ function apply(ctx) {
55
55
  return '获取涨停看板图片失败,请稍后重试。';
56
56
  }
57
57
  });
58
+ // 监听选股命令
59
+ ctx.command('选股 <strategy:text>', '根据指定策略选股(支持策略:N型、填坑、少妇、突破、补票、少妇pro)')
60
+ .action(async ({ session }, strategy) => {
61
+ if (!strategy) {
62
+ return '请输入选股策略,格式:选股 [策略名称或编号]\n支持的策略:N型(1)、填坑(2)、少妇(3)、突破(4)、补票(5)、少妇pro(6)';
63
+ }
64
+ // 映射策略名称到API端点
65
+ const strategyMap = {
66
+ 'N型': 'n_shape',
67
+ 'n_shape': 'n_shape',
68
+ '1': 'n_shape',
69
+ '填坑': 'fill_pit',
70
+ 'fill_pit': 'fill_pit',
71
+ '2': 'fill_pit',
72
+ '少妇': 'young_woman',
73
+ 'young_woman': 'young_woman',
74
+ '3': 'young_woman',
75
+ '突破': 'breakthrough',
76
+ 'breakthrough': 'breakthrough',
77
+ '4': 'breakthrough',
78
+ '补票': 'ticket',
79
+ 'ticket': 'ticket',
80
+ '5': 'ticket',
81
+ '少妇pro': 'young_woman_pro',
82
+ 'young_woman_pro': 'young_woman_pro',
83
+ '6': 'young_woman_pro',
84
+ };
85
+ const apiStrategy = strategyMap[strategy.trim()];
86
+ if (!apiStrategy) {
87
+ return `不支持的选股策略:${strategy}\n支持的策略:N型(1)、填坑(2)、少妇(3)、突破(4)、补票(5)、少妇pro(6)`;
88
+ }
89
+ try {
90
+ // 使用Koishi的HTTP服务发起请求获取数据
91
+ const apiUrl = `http://stock.svip886.com/api/dyq_select/${apiStrategy}`;
92
+ const responseText = await ctx.http.get(apiUrl, { responseType: 'text' });
93
+ // 直接返回API返回的数据
94
+ return `选股策略【${strategy}】结果:\n\n${responseText}`;
95
+ }
96
+ catch (error) {
97
+ console.error('获取选股数据失败:', error);
98
+ return `获取【${strategy}】选股数据失败,请稍后重试。`;
99
+ }
100
+ });
58
101
  // 使用中间件方式监听特定关键词(作为备用方案)
59
102
  ctx.middleware(async (session, next) => {
60
103
  const content = session.content?.trim();
@@ -63,7 +106,7 @@ function apply(ctx) {
63
106
  // 使用Koishi的HTTP服务发起请求获取数据
64
107
  const responseText = await ctx.http.get('http://stock.svip886.com/api/indexes', { responseType: 'text' });
65
108
  // 直接返回API返回的数据
66
- return `📊 活跃市值数据:\n\n${responseText}`;
109
+ return `📊 指数看板:\n\n${responseText}`;
67
110
  }
68
111
  catch (error) {
69
112
  console.error('获取活跃市值数据失败:', error);
@@ -79,7 +122,7 @@ function apply(ctx) {
79
122
  // 使用Koishi的HTTP服务发起请求获取数据
80
123
  const responseText = await ctx.http.get(`http://stock.svip886.com/api/analyze?code=${stockCode}`, { responseType: 'text' });
81
124
  // 直接返回API返回的数据
82
- return `📈 股票 ${stockCode} 异动分析:\n\n${responseText}`;
125
+ return `📈 异动分析:\n\n${responseText}`;
83
126
  }
84
127
  catch (error) {
85
128
  console.error('获取股票异动数据失败:', error);
@@ -103,6 +146,49 @@ function apply(ctx) {
103
146
  return '获取涨停看板图片失败,请稍后重试。';
104
147
  }
105
148
  }
149
+ else if (content?.startsWith('选股 ')) {
150
+ // 解析选股策略
151
+ const match = content.match(/^选股\s+(.+)$/);
152
+ if (match) {
153
+ const strategy = match[1].trim();
154
+ // 映射策略名称到API端点
155
+ const strategyMap = {
156
+ 'N型': 'n_shape',
157
+ 'n_shape': 'n_shape',
158
+ '1': 'n_shape',
159
+ '填坑': 'fill_pit',
160
+ 'fill_pit': 'fill_pit',
161
+ '2': 'fill_pit',
162
+ '少妇': 'young_woman',
163
+ 'young_woman': 'young_woman',
164
+ '3': 'young_woman',
165
+ '突破': 'breakthrough',
166
+ 'breakthrough': 'breakthrough',
167
+ '4': 'breakthrough',
168
+ '补票': 'ticket',
169
+ 'ticket': 'ticket',
170
+ '5': 'ticket',
171
+ '少妇pro': 'young_woman_pro',
172
+ 'young_woman_pro': 'young_woman_pro',
173
+ '6': 'young_woman_pro',
174
+ };
175
+ const apiStrategy = strategyMap[strategy];
176
+ if (!apiStrategy) {
177
+ return `不支持的选股策略:${strategy}\n支持的策略:N型(1)、填坑(2)、少妇(3)、突破(4)、补票(5)、少妇pro(6)`;
178
+ }
179
+ try {
180
+ // 使用Koishi的HTTP服务发起请求获取数据
181
+ const apiUrl = `http://stock.svip886.com/api/dyq_select/${apiStrategy}`;
182
+ const responseText = await ctx.http.get(apiUrl, { responseType: 'text' });
183
+ // 直接返回API返回的数据
184
+ return `选股策略【${strategy}】结果:\n\n${responseText}`;
185
+ }
186
+ catch (error) {
187
+ console.error('获取选股数据失败:', error);
188
+ return `获取【${strategy}】选股数据失败,请稍后重试。`;
189
+ }
190
+ }
191
+ }
106
192
  return next();
107
193
  });
108
194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-stock",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A Koishi plugin that fetches stock data when user sends '活跃市值' or '异动 [stock code]'",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",