@mashroomwolf/koishi-plugin-daynew 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.
Files changed (3) hide show
  1. package/lib/index.js +124 -0
  2. package/package.json +36 -0
  3. package/readme.md +5 -0
package/lib/index.js ADDED
@@ -0,0 +1,124 @@
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 = "daily-news";
31
+ var inject = {
32
+ required: ["cron"],
33
+ optional: ["adapter-onebot"]
34
+ };
35
+ var Config = import_koishi.Schema.intersect([
36
+ import_koishi.Schema.object({
37
+ daynews: import_koishi.Schema.boolean().default(true).description("是否发送每日新闻"),
38
+ sendTime: import_koishi.Schema.object({
39
+ week: import_koishi.Schema.number().default(0).description("发送时间-星期几(0-7, 0 表示每天)").min(0).max(7).step(1),
40
+ month: import_koishi.Schema.number().default(0).description("发送时间-哪个月(0-12, 0 表示每个月)").min(0).max(12).step(1),
41
+ day: import_koishi.Schema.number().default(0).description("发送时间-哪一天(0-31, 0 表示每天)").min(0).max(31).step(1),
42
+ hour: import_koishi.Schema.number().default(9).description("发送时间-哪个小时(0-24, 24 表示每小时)(默认为早上9点)").min(0).max(24).step(1),
43
+ minute: import_koishi.Schema.number().default(0).description("发送时间-哪一分钟(0-60, 60 表示每分钟)").min(0).max(60).step(1)
44
+ }).description("发送时间"),
45
+ url: import_koishi.Schema.object({
46
+ list: import_koishi.Schema.array(import_koishi.Schema.string().default("").description("新闻源")).default(["https://60s.viki.moe/v2/60s"]).description("新闻源列表")
47
+ }).description("新闻源配置")
48
+ }).description("每日新闻配置"),
49
+ import_koishi.Schema.object({
50
+ Objective: import_koishi.Schema.array(
51
+ import_koishi.Schema.object({
52
+ platform: import_koishi.Schema.union(["onebot"]).default("onebot").description("目标平台(当前仅支持onebot)"),
53
+ group: import_koishi.Schema.array(
54
+ import_koishi.Schema.string().default("").description("目标群组")
55
+ ).default([])
56
+ })
57
+ ).default([]).description("信息目标列表")
58
+ }).description("信息目标配置")
59
+ ]);
60
+ function apply(ctx, config) {
61
+ const UrlList = config.url.list;
62
+ if (!config.daynews) return;
63
+ ctx.cron(
64
+ `${config.sendTime.minute == 60 ? "*" : config.sendTime.minute} ${config.sendTime.hour == 24 ? "*" : config.sendTime.hour} ${config.sendTime.day == 0 ? "*" : config.sendTime.day} ${config.sendTime.month == 0 ? "*" : config.sendTime.month} ${config.sendTime.week == 0 ? "*" : config.sendTime.week}`,
65
+ async () => {
66
+ const sendnewMessage = await sendNews(ctx, UrlList);
67
+ const groupList = config.Objective.flatMap(
68
+ (item) => item.group.map((groupId) => `${item.platform}:${groupId}`)
69
+ );
70
+ console.log(sendnewMessage, groupList);
71
+ ctx.broadcast(groupList, sendnewMessage);
72
+ }
73
+ );
74
+ ctx.command("daily").action(async ({ session }) => {
75
+ for (const url of UrlList) {
76
+ try {
77
+ await session.send(await sendNews(ctx, UrlList));
78
+ break;
79
+ } catch (err) {
80
+ console.error("请求失败:", err);
81
+ }
82
+ }
83
+ });
84
+ }
85
+ __name(apply, "apply");
86
+ function dateFormat(date) {
87
+ const year = date.getFullYear();
88
+ const month = date.getMonth() + 1;
89
+ const day = date.getDate();
90
+ return `${year}年${month}月${day}日`;
91
+ }
92
+ __name(dateFormat, "dateFormat");
93
+ async function sendNews(ctx, UrlList) {
94
+ for (const url of UrlList) {
95
+ try {
96
+ const res = await ctx.http.get(url);
97
+ const dailyNews = res.data;
98
+ return `${dateFormat(new Date(dailyNews.date))} ${dailyNews.day_of_week || ""} 农历 ${dailyNews.lunar_date || ""}
99
+ 1. ${dailyNews.news[0] || ""}
100
+ 2. ${dailyNews.news[1] || ""}
101
+ 3. ${dailyNews.news[2] || ""}
102
+ 4. ${dailyNews.news[3] || ""}
103
+ 5. ${dailyNews.news[4] || ""}
104
+ 6. ${dailyNews.news[5] || ""}
105
+ 7. ${dailyNews.news[6] || ""}
106
+ 8. ${dailyNews.news[7] || ""}
107
+ 9. ${dailyNews.news[8] || ""}
108
+ 10. ${dailyNews.news[9] || ""}
109
+
110
+ `;
111
+ } catch (err) {
112
+ console.error("请求失败:", err);
113
+ }
114
+ }
115
+ return "❌ 获取每日新闻失败,请稍后再试。";
116
+ }
117
+ __name(sendNews, "sendNews");
118
+ // Annotate the CommonJS export names for ESM import in node:
119
+ 0 && (module.exports = {
120
+ Config,
121
+ apply,
122
+ inject,
123
+ name
124
+ });
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@mashroomwolf/koishi-plugin-daynew",
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
+ "scripts": {},
13
+ "keywords": [
14
+ "chatbot",
15
+ "koishi",
16
+ "plugin"
17
+ ],
18
+ "peerDependencies": {
19
+ "koishi": "^4.18.7"
20
+ },
21
+ "dependencies": {
22
+ "koishi-plugin-adapter-onebot": "^6.8.0",
23
+ "koishi-plugin-cron": "^3.1.0"
24
+ },
25
+ "koishi": {
26
+ "service": {
27
+ "required": [
28
+ "cron"
29
+ ],
30
+ "optional": [
31
+ "adapter-onebot"
32
+ ]
33
+ },
34
+ "preview": true
35
+ }
36
+ }
package/readme.md ADDED
@@ -0,0 +1,5 @@
1
+ # @mashroomwolf/koishi-plugin-daily-news
2
+
3
+ [![npm](https://img.shields.io/npm/v/@mashroomwolf/koishi-plugin-daily-news?style=flat-square)](https://www.npmjs.com/package/@mashroomwolf/koishi-plugin-daily-news)
4
+
5
+