koishi-plugin-stock 1.0.4 → 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/lib/index.d.ts +6 -1
- package/lib/index.js +65 -3
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { Context, Schema } from 'koishi';
|
|
2
2
|
export interface Config {
|
|
3
|
+
activeMarketCapBlacklist?: string[];
|
|
4
|
+
stockAlertBlacklist?: string[];
|
|
5
|
+
limitUpBoardBlacklist?: string[];
|
|
6
|
+
stockSelectionBlacklist?: string[];
|
|
7
|
+
allCommandsBlacklist?: string[];
|
|
3
8
|
}
|
|
4
9
|
export declare const Config: Schema<Config>;
|
|
5
|
-
export declare function apply(ctx: Context): void;
|
|
10
|
+
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -3,17 +3,58 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Config = void 0;
|
|
4
4
|
exports.apply = apply;
|
|
5
5
|
const koishi_1 = require("koishi");
|
|
6
|
-
exports.Config = koishi_1.Schema.object({
|
|
7
|
-
|
|
6
|
+
exports.Config = koishi_1.Schema.object({
|
|
7
|
+
allCommandsBlacklist: koishi_1.Schema.array(String).description('全部指令黑名单用户ID'),
|
|
8
|
+
activeMarketCapBlacklist: koishi_1.Schema.array(String).description('活跃市值指令黑名单用户ID'),
|
|
9
|
+
stockAlertBlacklist: koishi_1.Schema.array(String).description('异动指令黑名单用户ID'),
|
|
10
|
+
limitUpBoardBlacklist: koishi_1.Schema.array(String).description('涨停看板指令黑名单用户ID'),
|
|
11
|
+
stockSelectionBlacklist: koishi_1.Schema.array(String).description('选股指令黑名单用户ID'),
|
|
12
|
+
});
|
|
13
|
+
function apply(ctx, config) {
|
|
14
|
+
// 检查用户是否在特定指令的黑名单中
|
|
15
|
+
function isUserInSpecificBlacklist(session, commandName) {
|
|
16
|
+
const userId = session.userId;
|
|
17
|
+
// 检查特定指令黑名单
|
|
18
|
+
switch (commandName) {
|
|
19
|
+
case '活跃市值':
|
|
20
|
+
if (config.activeMarketCapBlacklist?.includes(userId)) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
break;
|
|
24
|
+
case '异动':
|
|
25
|
+
if (config.stockAlertBlacklist?.includes(userId)) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
break;
|
|
29
|
+
case '涨停看板':
|
|
30
|
+
if (config.limitUpBoardBlacklist?.includes(userId)) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
case '选股':
|
|
35
|
+
if (config.stockSelectionBlacklist?.includes(userId)) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
// 检查全局黑名单
|
|
41
|
+
if (config.allCommandsBlacklist?.includes(userId)) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
8
46
|
// 监听活跃市值命令
|
|
9
47
|
ctx.command('活跃市值', '获取活跃市值数据')
|
|
10
48
|
.action(async ({ session }) => {
|
|
49
|
+
if (isUserInSpecificBlacklist(session, '活跃市值')) {
|
|
50
|
+
return '您已被加入黑名单,无法使用此功能。';
|
|
51
|
+
}
|
|
11
52
|
try {
|
|
12
53
|
// 使用Koishi的HTTP服务发起请求获取数据
|
|
13
54
|
// 根据测试,API返回的是文本格式而非JSON
|
|
14
55
|
const responseText = await ctx.http.get('http://stock.svip886.com/api/indexes', { responseType: 'text' });
|
|
15
56
|
// 直接返回API返回的数据
|
|
16
|
-
return `📊
|
|
57
|
+
return `📊 指数看板:\n\n${responseText}`;
|
|
17
58
|
}
|
|
18
59
|
catch (error) {
|
|
19
60
|
console.error('获取活跃市值数据失败:', error);
|
|
@@ -23,6 +64,9 @@ function apply(ctx) {
|
|
|
23
64
|
// 监听异动命令,接受股票代码参数
|
|
24
65
|
ctx.command('异动 <stockCode:text>', '获取指定股票的异动分析数据')
|
|
25
66
|
.action(async ({ session }, stockCode) => {
|
|
67
|
+
if (isUserInSpecificBlacklist(session, '异动')) {
|
|
68
|
+
return '您已被加入黑名单,无法使用此功能。';
|
|
69
|
+
}
|
|
26
70
|
if (!stockCode) {
|
|
27
71
|
return '请输入股票代码,格式:异动 [股票代码]';
|
|
28
72
|
}
|
|
@@ -40,6 +84,9 @@ function apply(ctx) {
|
|
|
40
84
|
// 监听涨停看板命令
|
|
41
85
|
ctx.command('涨停看板', '获取涨停看板图片')
|
|
42
86
|
.action(async ({ session }) => {
|
|
87
|
+
if (isUserInSpecificBlacklist(session, '涨停看板')) {
|
|
88
|
+
return '您已被加入黑名单,无法使用此功能。';
|
|
89
|
+
}
|
|
43
90
|
try {
|
|
44
91
|
// 使用Koishi的HTTP服务下载图片
|
|
45
92
|
const imageUrl = 'http://stock.svip886.com/api/limit_up.png';
|
|
@@ -58,6 +105,9 @@ function apply(ctx) {
|
|
|
58
105
|
// 监听选股命令
|
|
59
106
|
ctx.command('选股 <strategy:text>', '根据指定策略选股(支持策略:N型、填坑、少妇、突破、补票、少妇pro)')
|
|
60
107
|
.action(async ({ session }, strategy) => {
|
|
108
|
+
if (isUserInSpecificBlacklist(session, '选股')) {
|
|
109
|
+
return '您已被加入黑名单,无法使用此功能。';
|
|
110
|
+
}
|
|
61
111
|
if (!strategy) {
|
|
62
112
|
return '请输入选股策略,格式:选股 [策略名称或编号]\n支持的策略:N型(1)、填坑(2)、少妇(3)、突破(4)、补票(5)、少妇pro(6)';
|
|
63
113
|
}
|
|
@@ -102,6 +152,9 @@ function apply(ctx) {
|
|
|
102
152
|
ctx.middleware(async (session, next) => {
|
|
103
153
|
const content = session.content?.trim();
|
|
104
154
|
if (content === '活跃市值') {
|
|
155
|
+
if (isUserInSpecificBlacklist(session, '活跃市值')) {
|
|
156
|
+
return '您已被加入黑名单,无法使用此功能。';
|
|
157
|
+
}
|
|
105
158
|
try {
|
|
106
159
|
// 使用Koishi的HTTP服务发起请求获取数据
|
|
107
160
|
const responseText = await ctx.http.get('http://stock.svip886.com/api/indexes', { responseType: 'text' });
|
|
@@ -114,6 +167,9 @@ function apply(ctx) {
|
|
|
114
167
|
}
|
|
115
168
|
}
|
|
116
169
|
else if (content?.startsWith('异动 ')) {
|
|
170
|
+
if (isUserInSpecificBlacklist(session, '异动')) {
|
|
171
|
+
return '您已被加入黑名单,无法使用此功能。';
|
|
172
|
+
}
|
|
117
173
|
// 解析股票代码
|
|
118
174
|
const match = content.match(/^异动\s+(.+)$/);
|
|
119
175
|
if (match) {
|
|
@@ -131,6 +187,9 @@ function apply(ctx) {
|
|
|
131
187
|
}
|
|
132
188
|
}
|
|
133
189
|
else if (content === '涨停看板') {
|
|
190
|
+
if (isUserInSpecificBlacklist(session, '涨停看板')) {
|
|
191
|
+
return '您已被加入黑名单,无法使用此功能。';
|
|
192
|
+
}
|
|
134
193
|
try {
|
|
135
194
|
// 使用Koishi的HTTP服务下载图片
|
|
136
195
|
const imageUrl = 'http://stock.svip886.com/api/limit_up.png';
|
|
@@ -147,6 +206,9 @@ function apply(ctx) {
|
|
|
147
206
|
}
|
|
148
207
|
}
|
|
149
208
|
else if (content?.startsWith('选股 ')) {
|
|
209
|
+
if (isUserInSpecificBlacklist(session, '选股')) {
|
|
210
|
+
return '您已被加入黑名单,无法使用此功能。';
|
|
211
|
+
}
|
|
150
212
|
// 解析选股策略
|
|
151
213
|
const match = content.match(/^选股\s+(.+)$/);
|
|
152
214
|
if (match) {
|
package/package.json
CHANGED