koishi-plugin-yutang-ksplus 1.0.1

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 ADDED
@@ -0,0 +1,9 @@
1
+ import { Context, Schema } from 'koishi';
2
+ export declare const name = "yutang-ksplus";
3
+ export declare const usage = "\n# \u5FEB\u624B\u89E3\u6790\n## \u8054\u7CFB\u6211\u4EEC QQ\u7FA4 738988912\n### \u4E4B\u524D\u7684\u90A3\u4E2A\u56E0\u4E3A\u662F\u522B\u4EBA\u7684\u540E\u7AEF\u670D\u52A1\uFF0C\u73B0\u5728\u6302\u4E86\uFF0C\u7136\u540E\u6211\u7535\u8111\u91CD\u88C5\u4E86\u7CFB\u7EDF\uFF0C\u4EE5\u524D\u7684\u7684\u5DE5\u7A0B\u6587\u4EF6\u4E5F\u6CA1\u6709\u4E86\uFF0C\u6240\u4EE5\u91CD\u65B0\u5199\u4E86\u4E00\u4E2A\u5FEB\u624B\u89E3\u6790\uFF0C\u6B22\u8FCE\u52A0\u7FA4\u53CD\u9988\u95EE\u9898";
4
+ export interface Config {
5
+ targetApi: string;
6
+ debugLog: boolean;
7
+ }
8
+ export declare const Config: Schema<Config>;
9
+ export declare function apply(ctx: Context): void;
package/lib/index.js ADDED
@@ -0,0 +1,125 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name2 in all)
8
+ __defProp(target, name2, { get: all[name2], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ Config: () => Config,
24
+ apply: () => apply,
25
+ name: () => name,
26
+ usage: () => usage
27
+ });
28
+ module.exports = __toCommonJS(src_exports);
29
+ var import_koishi = require("koishi");
30
+ var name = "yutang-ksplus";
31
+ var usage = `
32
+ # 快手解析
33
+ ## 联系我们 QQ群 738988912
34
+ ### 之前的那个因为是别人的后端服务,现在挂了,然后我电脑重装了系统,以前的的工程文件也没有了,所以重新写了一个快手解析,欢迎加群反馈问题`;
35
+ var Config = import_koishi.Schema.object({
36
+ targetApi: import_koishi.Schema.string().default("https://yutangxiaowu.cn:6033/api/kuaishou").description("快手视频解析API地址"),
37
+ debugLog: import_koishi.Schema.boolean().default(false).description("是否输出详细日志")
38
+ });
39
+ function apply(ctx) {
40
+ function extraKuaishouVideo(msg) {
41
+ if (!msg)
42
+ return null;
43
+ const match = msg.match(/https?:\/\/(?:[a-zA-Z0-9-]+\.)?(?:kuaishou\.com|chenzhongtech\.com)\/[A-Za-z0-9._?%&+\-=\/#]*/);
44
+ return match ? match[0] : null;
45
+ }
46
+ __name(extraKuaishouVideo, "extraKuaishouVideo");
47
+ ctx.on("message", async (msg) => {
48
+ try {
49
+ const debug = ctx.config.debugLog;
50
+ if (debug) ctx.logger("yutang-ksplus").info(`收到消息: ${msg.content}`);
51
+ const url = extraKuaishouVideo(msg.content);
52
+ const targetApi = ctx.config.targetApi;
53
+ if (debug) ctx.logger("yutang-ksplus").info(`提取的快手链接: ${url}`);
54
+ if (url) {
55
+ if (debug) ctx.logger("yutang-ksplus").info(`向API发送请求: ${targetApi}?url=${encodeURIComponent(url)}`);
56
+ const response = await ctx.http.get(targetApi, {
57
+ params: {
58
+ url
59
+ }
60
+ });
61
+ if (debug)
62
+ ctx.logger("yutang-ksplus").info(`API响应数据: ${JSON.stringify(response)}`);
63
+ if (response && response.code === 0) {
64
+ const videoData = response.data;
65
+ const cleanVideoUrl = videoData.video.url.replace(/[`\s]/g, "");
66
+ const videoInfo = [
67
+ `视频标题:${videoData.video.title}`,
68
+ `作者:${videoData.owner.name}`,
69
+ `时长:${videoData.video.duration}`,
70
+ `发布时间:${videoData.createTime}`,
71
+ `播放量:${videoData.stat.view}`,
72
+ `点赞数:${videoData.stat.like}`,
73
+ `评论数:${videoData.stat.comment}`,
74
+ `分享数:${videoData.stat.share}`,
75
+ `背景音乐:${videoData.songName}`
76
+ ].join("\n");
77
+ const result1 = (0, import_koishi.h)("message", {}, [
78
+ (0, import_koishi.h)("figure", {}, [
79
+ (0, import_koishi.h)("figcaption", {}, videoInfo)
80
+ ])
81
+ ]);
82
+ const result2 = (0, import_koishi.h)("message", {}, [
83
+ (0, import_koishi.h)("figure", {}, [
84
+ (0, import_koishi.h)("figcaption", {}, `视频链接:${cleanVideoUrl}`)
85
+ ])
86
+ ]);
87
+ const result = (0, import_koishi.h)("message", {}, [result1, result2]);
88
+ if (debug)
89
+ ctx.logger("yutang-ksplus").info(`准备发送回复: ${JSON.stringify(result)}`);
90
+ await msg.send(result);
91
+ if (debug)
92
+ ctx.logger("yutang-ksplus").info(`回复发送成功`);
93
+ try {
94
+ const videoElement = import_koishi.h.video(cleanVideoUrl, {
95
+ cache: 0
96
+ });
97
+ if (debug)
98
+ ctx.logger("yutang-ksplus").info(`准备发送视频: ${cleanVideoUrl}`);
99
+ await msg.send([videoElement]);
100
+ if (debug)
101
+ ctx.logger("yutang-ksplus").info(`视频发送成功: ${cleanVideoUrl}`);
102
+ } catch (videoError) {
103
+ if (debug)
104
+ ctx.logger("yutang-ksplus").error(`视频发送失败: ${videoError instanceof Error ? videoError.message : String(videoError)}`);
105
+ await msg.send(`视频发送失败,您可以尝试使用视频链接手动观看:${cleanVideoUrl}`);
106
+ }
107
+ } else {
108
+ if (debug) ctx.logger("yutang-ksplus").error(`API返回错误: ${response?.msg || "未知错误"}`);
109
+ }
110
+ } else {
111
+ if (debug) ctx.logger("yutang-ksplus").info(`未提取到快手链接`);
112
+ }
113
+ } catch (error) {
114
+ ctx.logger("yutang-ksplus").error(`处理消息时发生异常: ${error instanceof Error ? error.message : String(error)}`);
115
+ }
116
+ });
117
+ }
118
+ __name(apply, "apply");
119
+ // Annotate the CommonJS export names for ESM import in node:
120
+ 0 && (module.exports = {
121
+ Config,
122
+ apply,
123
+ name,
124
+ usage
125
+ });
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "koishi-plugin-yutang-ksplus",
3
+ "description": "快手视频解析",
4
+ "version": "1.0.1",
5
+ "main": "lib/index.js",
6
+ "typings": "lib/index.d.ts",
7
+ "files": [
8
+ "lib",
9
+ "dist"
10
+ ],
11
+ "license": "MIT",
12
+ "keywords": [
13
+ "chatbot",
14
+ "koishi",
15
+ "plugin",
16
+ "yutang",
17
+ "快手视频解析"
18
+ ],
19
+ "peerDependencies": {
20
+ "koishi": "^4.18.7"
21
+ }
22
+ }
package/readme.md ADDED
@@ -0,0 +1,5 @@
1
+ # koishi-plugin-yutang-ksplus
2
+
3
+ [![npm](https://img.shields.io/npm/v/koishi-plugin-yutang-ksplus?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-yutang-ksplus)
4
+
5
+ 快手视频解析