koishi-plugin-wjq-6657-meme 0.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,11 @@
1
+ import { Context, Schema } from 'koishi';
2
+ export declare const name = "wjq-6657-meme";
3
+ export declare const inject: string[];
4
+ export interface Config {
5
+ version: string;
6
+ baseUrl: string;
7
+ command: string;
8
+ showDebug: boolean;
9
+ }
10
+ export declare const Config: Schema<Config>;
11
+ export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js ADDED
@@ -0,0 +1,123 @@
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
+ inject: () => inject,
26
+ name: () => name
27
+ });
28
+ module.exports = __toCommonJS(src_exports);
29
+ var import_koishi = require("koishi");
30
+ var name = "wjq-6657-meme";
31
+ var inject = ["http"];
32
+ var logger = new import_koishi.Logger("6657cjdb");
33
+ var Config = import_koishi.Schema.object({
34
+ // 只读字段显示版本号
35
+ version: import_koishi.Schema.string().default("0.0.1").disabled().description("当前插件版本"),
36
+ baseUrl: import_koishi.Schema.string().default("https://hguofichp.cn:10086/machine").description("API 基础路径"),
37
+ command: import_koishi.Schema.string().default("6657").description("插件触发指令 (例如:6657)"),
38
+ showDebug: import_koishi.Schema.boolean().default(false).description("开启调试后缀 (在回复中显示 ID 和页数)")
39
+ });
40
+ function apply(ctx, config) {
41
+ ctx.command(`${config.command} [action] [keyword:text]`, "访问 s6657 抽象语录").action(async ({ session }, action, keyword) => {
42
+ try {
43
+ if (action === "搜索") {
44
+ if (!keyword) return `请输入搜索关键词,例如:${config.command} 搜索 丰川祥子`;
45
+ const url2 = `${config.baseUrl}/pageSearch`;
46
+ const pageSize = 20;
47
+ const payloadStep1 = {
48
+ barrage: keyword,
49
+ pageNum: 1,
50
+ pageSize,
51
+ sort: 0,
52
+ tags: ""
53
+ };
54
+ const res1 = await ctx.http.post(url2, payloadStep1);
55
+ const data1 = res1?.data;
56
+ const total = data1?.total || 0;
57
+ if (!data1?.list || data1.list.length === 0) {
58
+ return `没有搜到关于 "${keyword}" 的语录捏。`;
59
+ }
60
+ let targetList = data1.list;
61
+ let currentPage = 1;
62
+ const totalPages = Math.ceil(total / pageSize);
63
+ if (totalPages > 1) {
64
+ const randomPage = Math.floor(Math.random() * totalPages) + 1;
65
+ if (randomPage !== 1) {
66
+ const payloadStep2 = { ...payloadStep1, pageNum: randomPage };
67
+ const res2 = await ctx.http.post(url2, payloadStep2);
68
+ if (res2?.data?.list && res2.data.list.length > 0) {
69
+ targetList = res2.data.list;
70
+ currentPage = randomPage;
71
+ }
72
+ } else {
73
+ currentPage = 1;
74
+ }
75
+ }
76
+ const randomItem = targetList[Math.floor(Math.random() * targetList.length)];
77
+ const content = randomItem.barrage || "解析内容失败";
78
+ if (config.showDebug) {
79
+ return `${content}
80
+ (Debug: 第${currentPage}页 ID:${randomItem.id})`;
81
+ }
82
+ return content;
83
+ }
84
+ if (action === "热门") {
85
+ const url2 = `${config.baseUrl}/hotBarrageOf24H`;
86
+ const res2 = await ctx.http.get(url2);
87
+ const list = res2?.data;
88
+ if (!list || !Array.isArray(list) || list.length === 0) {
89
+ return "获取热门列表失败。";
90
+ }
91
+ const randomItem = list[Math.floor(Math.random() * list.length)];
92
+ const content = randomItem.barrage || "解析内容失败";
93
+ if (config.showDebug) {
94
+ return `${content}
95
+ (Debug: ID:${randomItem.id})`;
96
+ }
97
+ return content;
98
+ }
99
+ const url = `${config.baseUrl}/getRandOne`;
100
+ const res = await ctx.http.get(url);
101
+ const data = res?.data;
102
+ if (!data || !data.barrage) {
103
+ return "获取失败,服务器返回数据异常。";
104
+ }
105
+ if (config.showDebug) {
106
+ return `${data.barrage}
107
+ (Debug: ID:${data.id})`;
108
+ }
109
+ return data.barrage;
110
+ } catch (err) {
111
+ logger.error("请求 s6657 失败:", err);
112
+ return "连接 s6657 服务器失败 (API 可能挂了)";
113
+ }
114
+ });
115
+ }
116
+ __name(apply, "apply");
117
+ // Annotate the CommonJS export names for ESM import in node:
118
+ 0 && (module.exports = {
119
+ Config,
120
+ apply,
121
+ inject,
122
+ name
123
+ });
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "koishi-plugin-wjq-6657-meme",
3
+ "version": "0.0.1",
4
+ "description": "访问 s6657 抽象语录",
5
+ "main": "lib/index.js",
6
+ "typings": "lib/index.d.ts",
7
+ "files": [
8
+ "lib",
9
+ "dist"
10
+ ],
11
+ "license": "MIT",
12
+ "keywords": [
13
+ "koishi",
14
+ "plugin",
15
+ "6657",
16
+ "meme",
17
+ "abstract"
18
+ ],
19
+ "peerDependencies": {
20
+ "koishi": "^4.17.0"
21
+ }
22
+ }
package/readme.md ADDED
@@ -0,0 +1,5 @@
1
+ # koishi-plugin-6657cjdb
2
+
3
+ [![npm](https://img.shields.io/npm/v/koishi-plugin-6657cjdb?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-6657cjdb)
4
+
5
+ 6657