koishi-plugin-echo-cave 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 ADDED
@@ -0,0 +1,5 @@
1
+ # koishi-plugin-cave
2
+
3
+ [![npm](https://img.shields.io/npm/v/koishi-plugin-cave?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-cave)
4
+
5
+ Group echo cave
package/lib/index.cjs ADDED
@@ -0,0 +1,118 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name2 in all)
7
+ __defProp(target, name2, { get: all[name2], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.ts
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ Config: () => Config,
23
+ apply: () => apply,
24
+ inject: () => inject,
25
+ name: () => name
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+ var import_koishi = require("koishi");
29
+ var import_koishi_plugin_adapter_onebot = require("koishi-plugin-adapter-onebot");
30
+ var name = "echo-cave";
31
+ var inject = ["database"];
32
+ var Config = import_koishi.Schema.object({});
33
+ function apply(ctx) {
34
+ ctx.model.extend(
35
+ "echo_cave",
36
+ {
37
+ id: "unsigned",
38
+ channelId: "string",
39
+ createTime: "timestamp",
40
+ userId: "string",
41
+ originUserId: "string",
42
+ content: "text"
43
+ },
44
+ {
45
+ primary: "id",
46
+ autoInc: true,
47
+ unique: ["content"]
48
+ }
49
+ );
50
+ ctx.command("cave", "\u968F\u673A\u83B7\u53D6\u56DE\u58F0\u6D1E\u6D88\u606F").action(
51
+ async ({ session }) => await getCave(ctx, session)
52
+ );
53
+ ctx.command("cave.echo", "\u5C06\u6D88\u606F\u5B58\u5165\u56DE\u58F0\u6D1E\u7A74").action(
54
+ async ({ session }) => await addCave(ctx, session)
55
+ );
56
+ }
57
+ async function getCave(ctx, session) {
58
+ if (!session.guildId) {
59
+ return "\u274C \u8BF7\u5728\u7FA4\u804A\u4E2D\u4F7F\u7528\u8BE5\u547D\u4EE4\uFF01";
60
+ }
61
+ const { channelId } = session;
62
+ const caves = await ctx.database.get("echo_cave", {
63
+ channelId
64
+ });
65
+ if (caves.length === 0) {
66
+ return '\u{1F680} \u56DE\u58F0\u6D1E\u4E2D\u6682\u65E0\u6D88\u606F\uFF0C\u5FEB\u4F7F\u7528 "cave.echo" \u547D\u4EE4\u6DFB\u52A0\u7B2C\u4E00\u6761\u6D88\u606F\u5427\uFF01';
67
+ }
68
+ return caves[Math.floor(Math.random() * caves.length)].content;
69
+ }
70
+ async function addCave(ctx, session) {
71
+ if (!session.guildId) {
72
+ return "\u274C \u8BF7\u5728\u7FA4\u804A\u4E2D\u4F7F\u7528\u8BE5\u547D\u4EE4\uFF01";
73
+ }
74
+ if (!session.quote) {
75
+ return "\u{1F4A1} \u8BF7\u5F15\u7528\u4E00\u6761\u6D88\u606F\u540E\u518D\u4F7F\u7528\u6B64\u547D\u4EE4\uFF01";
76
+ }
77
+ const { userId, channelId } = session;
78
+ const content = session.quote.content;
79
+ ctx.logger("echo-cave").info(
80
+ `User ${userId} is adding a message to the echo cave: ${content}`
81
+ );
82
+ await ctx.database.get("echo_cave", { content }).then((existing) => {
83
+ if (existing) {
84
+ return "\u267B\uFE0F \u8BE5\u6D88\u606F\u5DF2\u5B58\u5728\u4E8E\u56DE\u58F0\u6D1E\u7A74\u4E2D\uFF01";
85
+ }
86
+ });
87
+ try {
88
+ const result = await ctx.database.create("echo_cave", {
89
+ channelId,
90
+ createTime: /* @__PURE__ */ new Date(),
91
+ userId,
92
+ originUserId: userId,
93
+ content
94
+ });
95
+ if (session.onebot) {
96
+ const messageId = await session.onebot.sendGroupMsg(
97
+ session.channelId,
98
+ `\u2705 \u56DE\u58F0\u6D1E\u6D88\u606F\u5DF2\u6210\u529F\u5B58\u5165\uFF0C\u6D88\u606F ID\uFF1A${result.id}`
99
+ );
100
+ ctx.setInterval(
101
+ async () => await session.onebot.deleteMsg(messageId),
102
+ 5e3
103
+ );
104
+ } else {
105
+ return `\u2705 \u56DE\u58F0\u6D1E\u6D88\u606F\u5DF2\u6210\u529F\u5B58\u5165\uFF0C\u6D88\u606F ID\uFF1A${result.id}`;
106
+ }
107
+ } catch (error) {
108
+ this.ctx.logger.warn("\u4E0A\u67B6\u5546\u54C1\u5931\u8D25:", error);
109
+ return "\u274C \u4E0A\u67B6\u5546\u54C1\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\uFF01";
110
+ }
111
+ }
112
+ // Annotate the CommonJS export names for ESM import in node:
113
+ 0 && (module.exports = {
114
+ Config,
115
+ apply,
116
+ inject,
117
+ name
118
+ });
package/lib/index.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { Context, Schema } from 'koishi';
2
+ import 'koishi-plugin-adapter-onebot';
3
+ export declare const name = "echo-cave";
4
+ export declare const inject: string[];
5
+ export interface Config {
6
+ }
7
+ export declare const Config: Schema<Config>;
8
+ export interface EchoCave {
9
+ id: number;
10
+ channelId: string;
11
+ createTime: Date;
12
+ userId: string;
13
+ originUserId: string;
14
+ content: string;
15
+ }
16
+ declare module 'koishi' {
17
+ interface Tables {
18
+ echo_cave: EchoCave;
19
+ }
20
+ }
21
+ export declare function apply(ctx: Context): void;
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "koishi-plugin-echo-cave",
3
+ "description": "Group echo cave",
4
+ "version": "1.0.0",
5
+ "main": "lib/index.cjs",
6
+ "typings": "lib/index.d.ts",
7
+ "type": "module",
8
+ "files": [
9
+ "lib",
10
+ "dist"
11
+ ],
12
+ "license": "MIT",
13
+ "scripts": {
14
+ "lint": "eslint ./src --ext .ts",
15
+ "lint:fix": "eslint ./src --ext .ts --fix",
16
+ "build": "node esbuild.config.js && tsc --emitDeclarationOnly",
17
+ "release": "semantic-release"
18
+ },
19
+ "keywords": [
20
+ "group",
21
+ "koishi",
22
+ "plugin",
23
+ "cave"
24
+ ],
25
+ "peerDependencies": {
26
+ "koishi": "^4.18.9",
27
+ "koishi-plugin-adapter-onebot": "^6.8.0"
28
+ },
29
+ "devDependencies": {
30
+ "@semantic-release/changelog": "^6.0.3",
31
+ "@semantic-release/commit-analyzer": "^13.0.1",
32
+ "@semantic-release/git": "^10.0.1",
33
+ "@semantic-release/npm": "^13.1.1",
34
+ "@semantic-release/release-notes-generator": "^14.1.0",
35
+ "@trivago/prettier-plugin-sort-imports": "^5.2.2",
36
+ "conventional-changelog-conventionalcommits": "^9.1.0",
37
+ "esbuild": "^0.25.11",
38
+ "esbuild-plugin-yaml": "^0.0.1",
39
+ "eslint": "^9.38.0",
40
+ "eslint-config-prettier": "^10.1.8",
41
+ "eslint-plugin-prettier": "^5.5.4",
42
+ "prettier": "^3.6.2",
43
+ "semantic-release": "^25.0.1",
44
+ "typescript": "^5.9.3",
45
+ "typescript-eslint": "^8.46.2"
46
+ }
47
+ }