koishi-plugin-booknews 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 +22 -0
- package/lib/index.js +99 -0
- package/package.json +38 -0
- package/readme.md +5 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Context, Schema } from 'koishi';
|
|
2
|
+
export declare const name = "booknews";
|
|
3
|
+
export declare const inject: string[];
|
|
4
|
+
export interface Config {
|
|
5
|
+
sourceGroupId: string;
|
|
6
|
+
adminIds: string[];
|
|
7
|
+
dstGroupIds: string;
|
|
8
|
+
sendTime: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const Config: Schema<Config>;
|
|
11
|
+
declare module 'koishi' {
|
|
12
|
+
interface Tables {
|
|
13
|
+
daily_book_news: BookNewsItem;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export interface BookNewsItem {
|
|
17
|
+
id: number;
|
|
18
|
+
content: string;
|
|
19
|
+
authorName: string;
|
|
20
|
+
timestamp: Date;
|
|
21
|
+
}
|
|
22
|
+
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
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 = "booknews";
|
|
31
|
+
var inject = ["database", "cron"];
|
|
32
|
+
var Config = import_koishi.Schema.object({
|
|
33
|
+
sourceGroupId: import_koishi.Schema.string().description("监听的群聊号").required(),
|
|
34
|
+
adminIds: import_koishi.Schema.array(String).description("发布者的QQ号【白名单形式】").required(),
|
|
35
|
+
dstGroupIds: import_koishi.Schema.string().description("接受日报的群聊号").required(),
|
|
36
|
+
sendTime: import_koishi.Schema.string().default("0 21 * * *").description("发送时间 (Cron表达式,默认每天21点)")
|
|
37
|
+
});
|
|
38
|
+
function apply(ctx, config) {
|
|
39
|
+
ctx.model.extend("daily_book_news", {
|
|
40
|
+
id: "unsigned",
|
|
41
|
+
content: "text",
|
|
42
|
+
authorName: "string",
|
|
43
|
+
timestamp: "timestamp"
|
|
44
|
+
}, { autoInc: true });
|
|
45
|
+
ctx.on("message", async (session) => {
|
|
46
|
+
if (session.guildId !== config.sourceGroupId) return;
|
|
47
|
+
if (!config.adminIds.includes(session.userId)) return;
|
|
48
|
+
await ctx.database.create("daily_book_news", {
|
|
49
|
+
content: session.content,
|
|
50
|
+
authorName: session.username || session.userId,
|
|
51
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
52
|
+
});
|
|
53
|
+
ctx.logger("booknews").info(`收录一条来自 ${session.username} 的书讯`);
|
|
54
|
+
});
|
|
55
|
+
ctx.cron(config.sendTime, async () => {
|
|
56
|
+
const newsList = await ctx.database.get("daily_book_news", {});
|
|
57
|
+
if (newsList.length == 0) {
|
|
58
|
+
ctx.logger("book").info("书讯数量为0");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const bot = ctx.bots[0];
|
|
62
|
+
if (!bot) return;
|
|
63
|
+
const nodes = newsList.map((item) => {
|
|
64
|
+
return (0, import_koishi.h)("message", {
|
|
65
|
+
forward: true,
|
|
66
|
+
// 标记这是一个转发节点
|
|
67
|
+
userId: bot.selfId,
|
|
68
|
+
// 节点的发送者 ID
|
|
69
|
+
nickname: item.authorName
|
|
70
|
+
// 节点的发送者昵称
|
|
71
|
+
}, item.content);
|
|
72
|
+
});
|
|
73
|
+
nodes.unshift((0, import_koishi.h)("message", {
|
|
74
|
+
forward: true,
|
|
75
|
+
userId: bot.selfId,
|
|
76
|
+
nickname: "书讯助手"
|
|
77
|
+
}, `${(/* @__PURE__ */ new Date()).toLocaleDateString()} 书讯汇总
|
|
78
|
+
共收录 ${newsList.length} 条资讯`));
|
|
79
|
+
try {
|
|
80
|
+
await bot.sendMessage(config.dstGroupIds, nodes);
|
|
81
|
+
ctx.logger("book").info(`日报发送成功,共 ${newsList.length} 条书讯`);
|
|
82
|
+
await ctx.database.remove("daily_book_news", {});
|
|
83
|
+
} catch (e) {
|
|
84
|
+
ctx.logger("book").error("日报发送失败", e);
|
|
85
|
+
}
|
|
86
|
+
ctx.command("sendNews", "手动触发发送今日书讯 (不清空数据库)").action(async () => {
|
|
87
|
+
await bot.sendMessage(config.dstGroupIds, nodes);
|
|
88
|
+
ctx.logger("book").info(`日报发送成功,共 ${newsList.length} 条书讯`);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
__name(apply, "apply");
|
|
93
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
94
|
+
0 && (module.exports = {
|
|
95
|
+
Config,
|
|
96
|
+
apply,
|
|
97
|
+
inject,
|
|
98
|
+
name
|
|
99
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-booknews",
|
|
3
|
+
"description": "It's a plugin for booknews collection",
|
|
4
|
+
"version": "0.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
|
+
"booknews"
|
|
17
|
+
],
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"koishi": "^4.18.7"
|
|
20
|
+
},
|
|
21
|
+
"koishi": {
|
|
22
|
+
"description": {
|
|
23
|
+
"zh": "中文描述"
|
|
24
|
+
},
|
|
25
|
+
"service": {
|
|
26
|
+
"required": [
|
|
27
|
+
"database",
|
|
28
|
+
"cron"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@koishijs/plugin-database-sqlite": "^4.6.0",
|
|
33
|
+
"koishi-plugin-cron": "^3.1.0"
|
|
34
|
+
},
|
|
35
|
+
"preview": true,
|
|
36
|
+
"hidden": false
|
|
37
|
+
}
|
|
38
|
+
}
|