koishi-plugin-booth-get 6.0.0-beta.2 → 6.0.0-beta.3
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/command-handler-discord.js +158 -0
- package/lib/index.js +9 -2
- package/package.json +1 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
const import_koishi = require("koishi");
|
|
2
|
+
|
|
3
|
+
class DiscordCommandHandler {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.ctx = null;
|
|
6
|
+
this.config = null;
|
|
7
|
+
this.modules = null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
init(ctx, config, modules) {
|
|
11
|
+
this.ctx = ctx;
|
|
12
|
+
this.config = config;
|
|
13
|
+
this.modules = modules;
|
|
14
|
+
|
|
15
|
+
if (this.config.enableDiscordCommands) {
|
|
16
|
+
this.registerDiscordCommands();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
registerDiscordCommands() {
|
|
21
|
+
const logger = this.ctx.logger("booth-get");
|
|
22
|
+
|
|
23
|
+
this.ctx.command("booth.item <id>", "获取 BOOTH 商品详情")
|
|
24
|
+
.action(async ({ session }, id) => {
|
|
25
|
+
if (session.platform !== 'discord') return;
|
|
26
|
+
if (!id) return "请输入商品ID";
|
|
27
|
+
try {
|
|
28
|
+
const item = await this.getBoothItem(id);
|
|
29
|
+
if (!item) return "商品获取失败";
|
|
30
|
+
|
|
31
|
+
if (this.checkR18(item)) {
|
|
32
|
+
return "该商品可能包含R18内容,已跳过";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const relatedItems = await this.fetchRelatedItems(item.author);
|
|
36
|
+
const html = this.modules.cardGenerator.generateCardHTML(item, relatedItems);
|
|
37
|
+
const buffer = await this.modules.cardGenerator.captureCardHTML(html, this.config);
|
|
38
|
+
|
|
39
|
+
return buffer ? import_koishi.h.image(buffer, "image/png") : "卡片生成失败";
|
|
40
|
+
} catch (error) {
|
|
41
|
+
logger.warn(error);
|
|
42
|
+
return "卡片生成失败";
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
this.ctx.command("booth.search <query:text>", "搜索 BOOTH 商品")
|
|
47
|
+
.option('author', '-a <author> 指定作者名称')
|
|
48
|
+
.action(async ({ session, options }, query) => {
|
|
49
|
+
if (session.platform !== 'discord') return;
|
|
50
|
+
if (!query) return "请输入搜索关键词";
|
|
51
|
+
return await this.handleSearchCommand(session, query, options.author);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
this.ctx.command("booth.author <authorName:text>", "查看作者店铺信息")
|
|
55
|
+
.action(async ({ session }, authorName) => {
|
|
56
|
+
if (session.platform !== 'discord') return;
|
|
57
|
+
if (!authorName) return "请输入作者名称";
|
|
58
|
+
return await this.handleAuthorCommand(session, authorName);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
this.ctx.command("booth.subscribe <target>", "订阅作者新作品通知")
|
|
62
|
+
.action(async ({ session }, target) => {
|
|
63
|
+
if (session.platform !== 'discord') return;
|
|
64
|
+
if (!target) return "请输入作者名或 Booth 链接";
|
|
65
|
+
const success = await this.modules.subscriptionManager.addUserSubscription(
|
|
66
|
+
session.platform, session.userId, target
|
|
67
|
+
);
|
|
68
|
+
return success ? `✅ 已订阅:${target}` : `⚠️ 你已经订阅过 ${target} 了`;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
this.ctx.command("booth.unsubscribe <target>", "取消订阅作者")
|
|
72
|
+
.action(async ({ session }, target) => {
|
|
73
|
+
if (session.platform !== 'discord') return;
|
|
74
|
+
if (!target) return "请输入作者名或 Booth 链接";
|
|
75
|
+
const success = await this.modules.subscriptionManager.removeUserSubscription(
|
|
76
|
+
session.platform, session.userId, target
|
|
77
|
+
);
|
|
78
|
+
return success ? `❌ 已取消订阅:${target}` : "⚠️ 你还没有订阅此作者";
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
this.ctx.command("booth.subscriptions", "查看我的订阅列表")
|
|
82
|
+
.action(async ({ session }) => {
|
|
83
|
+
if (session.platform !== 'discord') return;
|
|
84
|
+
const subs = await this.modules.subscriptionManager.getUserSubscriptions(
|
|
85
|
+
session.platform, session.userId
|
|
86
|
+
);
|
|
87
|
+
return subs.length > 0 ? `📌 你订阅的作者有:\n${subs.join("\n")}` : "📭 你还没有订阅任何作者";
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
this.ctx.command("booth.groupSubscribe <target>", "群组订阅作者")
|
|
91
|
+
.channelFields(['id'])
|
|
92
|
+
.action(async ({ session }, target) => {
|
|
93
|
+
if (session.platform !== 'discord') return;
|
|
94
|
+
if (!target) return "请输入作者名或 Booth 链接";
|
|
95
|
+
if (!session.channelId) return "此命令只能在群组内使用";
|
|
96
|
+
|
|
97
|
+
const success = await this.modules.subscriptionManager.addGroupSubscription(
|
|
98
|
+
session.platform, session.channelId, target
|
|
99
|
+
);
|
|
100
|
+
return success ? `✅ 群组已订阅:${target}` : `⚠️ 群组已经订阅过 ${target} 了`;
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
this.ctx.command("booth.groupUnsubscribe <target>", "群组取消订阅作者")
|
|
104
|
+
.channelFields(['id'])
|
|
105
|
+
.action(async ({ session }, target) => {
|
|
106
|
+
if (session.platform !== 'discord') return;
|
|
107
|
+
if (!target) return "请输入作者名或 Booth 链接";
|
|
108
|
+
if (!session.channelId) return "此命令只能在群组内使用";
|
|
109
|
+
|
|
110
|
+
const success = await this.modules.subscriptionManager.removeGroupSubscription(
|
|
111
|
+
session.platform, session.channelId, target
|
|
112
|
+
);
|
|
113
|
+
return success ? `❌ 群组已取消订阅:${target}` : "⚠️ 群组还没有订阅此作者";
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
this.ctx.command("booth.groupSubscriptions", "查看群组订阅列表")
|
|
117
|
+
.channelFields(['id'])
|
|
118
|
+
.action(async ({ session }) => {
|
|
119
|
+
if (session.platform !== 'discord') return;
|
|
120
|
+
if (!session.channelId) return "此命令只能在群组内使用";
|
|
121
|
+
|
|
122
|
+
const subs = await this.modules.subscriptionManager.getGroupSubscriptions(
|
|
123
|
+
session.platform, session.channelId
|
|
124
|
+
);
|
|
125
|
+
return subs.length > 0 ? `📌 群组订阅的作者有:\n${subs.join("\n")}` : "📭 群组还没有订阅任何作者";
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async getBoothItem(id) {
|
|
130
|
+
return this.modules.commandHandler.getBoothItem(id);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
checkR18(item) {
|
|
134
|
+
return this.modules.commandHandler.checkR18(item);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async fetchRelatedItems(author) {
|
|
138
|
+
return this.modules.commandHandler.fetchRelatedItems(author);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async handleSearchCommand(session, query, authorFilter) {
|
|
142
|
+
return this.modules.commandHandler.handleSearchCommand(session, query, authorFilter);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async handleAuthorCommand(session, authorName) {
|
|
146
|
+
return this.modules.commandHandler.handleAuthorCommand(session, authorName);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
generateAuthorShopCardHTML(authorName, items = []) {
|
|
150
|
+
return this.modules.commandHandler.generateAuthorShopCardHTML(authorName, items);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async fetchAuthorItems(authorName, limit = 6) {
|
|
154
|
+
return this.modules.commandHandler.fetchAuthorItems(authorName, limit);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
module.exports = new DiscordCommandHandler();
|
package/lib/index.js
CHANGED
|
@@ -32,6 +32,7 @@ const cardGenerator = require('./card-generator');
|
|
|
32
32
|
const subscriptionManager = require('./subscription-manager');
|
|
33
33
|
const discountTracker = require('./discount-tracker');
|
|
34
34
|
const commandHandler = require('./command-handler');
|
|
35
|
+
const commandHandlerDiscord = require('./command-handler-discord');
|
|
35
36
|
|
|
36
37
|
var name = "koishi-plugin-booth-get";
|
|
37
38
|
var inject = ["puppeteer"];
|
|
@@ -46,8 +47,9 @@ var Config = import_koishi.Schema.object({
|
|
|
46
47
|
enableDiscountTracking: import_koishi.Schema.boolean().description("启用折扣商品自动追踪").default(true),
|
|
47
48
|
discountCheckInterval: import_koishi.Schema.natural().description("折扣检测间隔(分钟)").default(60),
|
|
48
49
|
maxDiscountPushCount: import_koishi.Schema.number().min(1).max(50).description("每次最大推送商品数量").default(5),
|
|
49
|
-
targetTags: import_koishi.Schema.array(import_koishi.Schema.string()).description("目标标签").default(["VRChat", "3Dモデル", "Avatar", "VRM"]),
|
|
50
|
-
targetGroups: import_koishi.Schema.array(import_koishi.Schema.string()).description("折扣商品推送目标群组“ID”").default([])
|
|
50
|
+
targetTags: import_koishi.Schema.array(import_koishi.Schema.string()).description("目标标签").default(["VRChat", "3Dモデル", "Avatar", "VRM"]).hidden(),
|
|
51
|
+
targetGroups: import_koishi.Schema.array(import_koishi.Schema.string()).description("折扣商品推送目标群组“ID”").default([]),
|
|
52
|
+
enableDiscordCommands: import_koishi.Schema.boolean().description("是否启用 Discord 专用指令(启用后仅在 Discord 平台生效)").default(false)
|
|
51
53
|
}).description("booth-get");
|
|
52
54
|
|
|
53
55
|
function apply(ctx, config) {
|
|
@@ -61,6 +63,11 @@ function apply(ctx, config) {
|
|
|
61
63
|
subscriptionManager,
|
|
62
64
|
discountTracker
|
|
63
65
|
});
|
|
66
|
+
commandHandlerDiscord.init(ctx, config, {
|
|
67
|
+
cardGenerator,
|
|
68
|
+
subscriptionManager,
|
|
69
|
+
discountTracker
|
|
70
|
+
});
|
|
64
71
|
|
|
65
72
|
logger.info('BOOTH插件已启动');
|
|
66
73
|
}
|