koishi-plugin-weibo-post-monitor 0.0.4 → 0.0.5

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 (2) hide show
  1. package/lib/index.js +43 -37
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -46,7 +46,7 @@ var Config = import_koishi.Schema.object({
46
46
  sendINFO: import_koishi.Schema.array(import_koishi.Schema.object({
47
47
  weiboUID: import_koishi.Schema.string().description("微博用户UID"),
48
48
  forward: import_koishi.Schema.boolean().default(false).description("是否监听转发"),
49
- blockwords: import_koishi.Schema.string().description("屏蔽词(多个关键词用分号分隔)"),
49
+ blockwords: import_koishi.Schema.string().description("屏蔽词(多个屏蔽词用分号分隔)"),
50
50
  keywords: import_koishi.Schema.string().description("关键词(多个关键词用分号分隔)"),
51
51
  groupID: import_koishi.Schema.string().description("需要发送的群组"),
52
52
  sendAll: import_koishi.Schema.boolean().default(false).description("@全体成员")
@@ -90,10 +90,22 @@ var getWeiboAndSendMessageToGroup = /* @__PURE__ */ __name(async (ctx, params) =
90
90
  }
91
91
  let message = result;
92
92
  if (params.sendAll) {
93
- message = '<at id="all"/> ' + message;
93
+ message = import_koishi.h.at("all") + " " + message;
94
94
  }
95
95
  ctx.bots[`${params.plantform}:${params.account}`].sendMessage(params.groupID, message);
96
96
  }, "getWeiboAndSendMessageToGroup");
97
+ var getLastPost = /* @__PURE__ */ __name((params, weiboList) => {
98
+ for (const wb_element of weiboList) {
99
+ const result = getMessage(params, wb_element);
100
+ if (!result) {
101
+ continue;
102
+ }
103
+ if (result.islast) {
104
+ return result.post;
105
+ }
106
+ }
107
+ return null;
108
+ }, "getLastPost");
97
109
  var getMessage = /* @__PURE__ */ __name((params, wbPost) => {
98
110
  if (!wbPost) {
99
111
  return null;
@@ -116,8 +128,6 @@ var getMessage = /* @__PURE__ */ __name((params, wbPost) => {
116
128
  weiboType = 1;
117
129
  }
118
130
  let message = "";
119
- let keywordsList = params.keywords?.split(";") || [];
120
- let blockwordsList = params.blockwords?.split(";") || [];
121
131
  if (weiboType == 0) {
122
132
  const pageInfo = wbPost?.page_info;
123
133
  if (!pageInfo) {
@@ -140,35 +150,14 @@ var getMessage = /* @__PURE__ */ __name((params, wbPost) => {
140
150
  const picIds = wbPost?.pic_ids || [];
141
151
  const picInfos = wbPost?.pic_infos || {};
142
152
  const firstPicUrl = picInfos?.[picIds[0]]?.large?.url || "";
143
- const picture = `<img src="${firstPicUrl}"/>`;
153
+ const picture = import_koishi.h.image(firstPicUrl);
144
154
  message += screenName + " 发布了微博:\n" + text + "\n" + picture || "";
145
155
  }
146
156
  const mid = wbPost?.mid || "";
147
157
  const url = `
148
158
  链接:https://m.weibo.cn/status/${mid}`;
149
- if (keywordsList.length > 0) {
150
- let hasKeywords = false;
151
- for (const keyword of keywordsList) {
152
- if (message.includes(keyword)) {
153
- hasKeywords = true;
154
- break;
155
- }
156
- }
157
- if (!hasKeywords) {
158
- return null;
159
- }
160
- }
161
- if (blockwordsList.length > 0) {
162
- let hasBlockwords = false;
163
- for (const blockword of blockwordsList) {
164
- if (message.includes(blockword)) {
165
- hasBlockwords = true;
166
- break;
167
- }
168
- }
169
- if (hasBlockwords) {
170
- return null;
171
- }
159
+ if (!checkWords(params, message)) {
160
+ return null;
172
161
  }
173
162
  const wbpost = message ? message + url : screenName + " 发布了微博:\n" + wbPost?.text_raw + url || "";
174
163
  return { post: wbpost, islast: true };
@@ -242,18 +231,35 @@ var parseDateString = /* @__PURE__ */ __name((dateString) => {
242
231
  date.setUTCMinutes(date.getUTCMinutes() - timezoneOffset);
243
232
  return date;
244
233
  }, "parseDateString");
245
- var getLastPost = /* @__PURE__ */ __name((params, weiboList) => {
246
- for (const wb_element of weiboList) {
247
- const result = getMessage(params, wb_element);
248
- if (!result) {
249
- continue;
234
+ var checkWords = /* @__PURE__ */ __name((params, message) => {
235
+ let keywordsList = params.keywords?.split(";") || [];
236
+ let blockwordsList = params.blockwords?.split(";") || [];
237
+ if (keywordsList.length > 0) {
238
+ let hasKeywords = false;
239
+ for (const keyword of keywordsList) {
240
+ if (message.includes(keyword)) {
241
+ hasKeywords = true;
242
+ break;
243
+ }
250
244
  }
251
- if (result.islast) {
252
- return result.post;
245
+ if (!hasKeywords) {
246
+ return false;
253
247
  }
254
248
  }
255
- return null;
256
- }, "getLastPost");
249
+ if (blockwordsList.length > 0) {
250
+ let hasBlockwords = false;
251
+ for (const blockword of blockwordsList) {
252
+ if (message.includes(blockword)) {
253
+ hasBlockwords = true;
254
+ break;
255
+ }
256
+ }
257
+ if (hasBlockwords) {
258
+ return false;
259
+ }
260
+ }
261
+ return true;
262
+ }, "checkWords");
257
263
  // Annotate the CommonJS export names for ESM import in node:
258
264
  0 && (module.exports = {
259
265
  Config,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-weibo-post-monitor",
3
3
  "description": "微博帖子更新推送插件,用于获取指定微博用户的最新帖子推送到指定群聊,参考代码https://github.com/moehuhu/weibo-monitor",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [