koishi-plugin-stock 1.0.0
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 +23 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +74 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# koishi-plugin-stock
|
|
2
|
+
|
|
3
|
+
一个Koishi插件,当用户发送"活跃市值"时自动获取股票市值数据并回复。
|
|
4
|
+
|
|
5
|
+
## 功能
|
|
6
|
+
|
|
7
|
+
- 用户发送"活跃市值"命令时,自动从 http://stock.svip886.com/api/indexes 获取数据并格式化显示
|
|
8
|
+
- 用户发送"异动 [股票代码]"命令时,自动从 http://stock.svip886.com/api/analyze?code=[股票代码] 获取指定股票的异动分析数据
|
|
9
|
+
- 自动格式化数据显示给用户
|
|
10
|
+
|
|
11
|
+
## 安装
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install koishi-plugin-market-value
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 配置
|
|
18
|
+
|
|
19
|
+
此插件无需配置。
|
|
20
|
+
|
|
21
|
+
## 使用
|
|
22
|
+
|
|
23
|
+
在聊天中输入"活跃市值"即可获取最新的市值数据。
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Config = void 0;
|
|
4
|
+
exports.apply = apply;
|
|
5
|
+
const koishi_1 = require("koishi");
|
|
6
|
+
exports.Config = koishi_1.Schema.object({});
|
|
7
|
+
function apply(ctx) {
|
|
8
|
+
// 监听活跃市值命令
|
|
9
|
+
ctx.command('活跃市值', '获取活跃市值数据')
|
|
10
|
+
.action(async ({ session }) => {
|
|
11
|
+
try {
|
|
12
|
+
// 使用Koishi的HTTP服务发起请求获取数据
|
|
13
|
+
// 根据测试,API返回的是文本格式而非JSON
|
|
14
|
+
const responseText = await ctx.http.get('http://stock.svip886.com/api/indexes', { responseType: 'text' });
|
|
15
|
+
// 直接返回API返回的数据
|
|
16
|
+
return `📊 活跃市值数据:\n\n${responseText}`;
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
console.error('获取活跃市值数据失败:', error);
|
|
20
|
+
return '获取活跃市值数据失败,请稍后重试。';
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
// 监听异动命令,接受股票代码参数
|
|
24
|
+
ctx.command('异动 <stockCode:text>', '获取指定股票的异动分析数据')
|
|
25
|
+
.action(async ({ session }, stockCode) => {
|
|
26
|
+
if (!stockCode) {
|
|
27
|
+
return '请输入股票代码,格式:异动 [股票代码]';
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
// 使用Koishi的HTTP服务发起请求获取数据
|
|
31
|
+
const responseText = await ctx.http.get(`http://stock.svip886.com/api/analyze?code=${stockCode}`, { responseType: 'text' });
|
|
32
|
+
// 直接返回API返回的数据
|
|
33
|
+
return `📈 股票 ${stockCode} 异动分析:\n\n${responseText}`;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error('获取股票异动数据失败:', error);
|
|
37
|
+
return `获取股票 ${stockCode} 异动数据失败,请稍后重试。`;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
// 使用中间件方式监听特定关键词(作为备用方案)
|
|
41
|
+
ctx.middleware(async (session, next) => {
|
|
42
|
+
const content = session.content?.trim();
|
|
43
|
+
if (content === '活跃市值') {
|
|
44
|
+
try {
|
|
45
|
+
// 使用Koishi的HTTP服务发起请求获取数据
|
|
46
|
+
const responseText = await ctx.http.get('http://stock.svip886.com/api/indexes', { responseType: 'text' });
|
|
47
|
+
// 直接返回API返回的数据
|
|
48
|
+
return `📊 活跃市值数据:\n\n${responseText}`;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.error('获取活跃市值数据失败:', error);
|
|
52
|
+
return '获取活跃市值数据失败,请稍后重试。';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else if (content?.startsWith('异动 ')) {
|
|
56
|
+
// 解析股票代码
|
|
57
|
+
const match = content.match(/^异动\s+(.+)$/);
|
|
58
|
+
if (match) {
|
|
59
|
+
const stockCode = match[1].trim();
|
|
60
|
+
try {
|
|
61
|
+
// 使用Koishi的HTTP服务发起请求获取数据
|
|
62
|
+
const responseText = await ctx.http.get(`http://stock.svip886.com/api/analyze?code=${stockCode}`, { responseType: 'text' });
|
|
63
|
+
// 直接返回API返回的数据
|
|
64
|
+
return `📈 股票 ${stockCode} 异动分析:\n\n${responseText}`;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.error('获取股票异动数据失败:', error);
|
|
68
|
+
return `获取股票 ${stockCode} 异动数据失败,请稍后重试。`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return next();
|
|
73
|
+
});
|
|
74
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-stock",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A Koishi plugin that fetches stock data when user sends '活跃市值' or '异动 [stock code]'",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "lib/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"dev": "tsc --watch",
|
|
10
|
+
"prepublishOnly": "npm run build"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"require": "./lib/index.js",
|
|
15
|
+
"import": "./lib/index.js",
|
|
16
|
+
"types": "./lib/index.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"koishi",
|
|
24
|
+
"plugin",
|
|
25
|
+
"stock",
|
|
26
|
+
"finance",
|
|
27
|
+
"market",
|
|
28
|
+
"data",
|
|
29
|
+
"api"
|
|
30
|
+
],
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"koishi": "^4.18.10"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@koishijs/scripts": "^4.0.0",
|
|
36
|
+
"@types/node": "^18.19.130",
|
|
37
|
+
"typescript": "^5.9.3"
|
|
38
|
+
},
|
|
39
|
+
"author": "Paranoid <administrator@vip886.cn>",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/svip886/koishi-plugin-stock.git"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/svip886/koishi-plugin-stock",
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/svip886/koishi-plugin-stock/issues"
|
|
48
|
+
}
|
|
49
|
+
}
|