koishi-plugin-weibo-post-monitor 0.0.3 → 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 -23
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -46,6 +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
50
  keywords: import_koishi.Schema.string().description("关键词(多个关键词用分号分隔)"),
50
51
  groupID: import_koishi.Schema.string().description("需要发送的群组"),
51
52
  sendAll: import_koishi.Schema.boolean().default(false).description("@全体成员")
@@ -89,10 +90,22 @@ var getWeiboAndSendMessageToGroup = /* @__PURE__ */ __name(async (ctx, params) =
89
90
  }
90
91
  let message = result;
91
92
  if (params.sendAll) {
92
- message = '<at id="all"/> ' + message;
93
+ message = import_koishi.h.at("all") + " " + message;
93
94
  }
94
95
  ctx.bots[`${params.plantform}:${params.account}`].sendMessage(params.groupID, message);
95
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");
96
109
  var getMessage = /* @__PURE__ */ __name((params, wbPost) => {
97
110
  if (!wbPost) {
98
111
  return null;
@@ -115,7 +128,6 @@ var getMessage = /* @__PURE__ */ __name((params, wbPost) => {
115
128
  weiboType = 1;
116
129
  }
117
130
  let message = "";
118
- let keywordsList = params.keywords?.split(";") || [];
119
131
  if (weiboType == 0) {
120
132
  const pageInfo = wbPost?.page_info;
121
133
  if (!pageInfo) {
@@ -138,23 +150,14 @@ var getMessage = /* @__PURE__ */ __name((params, wbPost) => {
138
150
  const picIds = wbPost?.pic_ids || [];
139
151
  const picInfos = wbPost?.pic_infos || {};
140
152
  const firstPicUrl = picInfos?.[picIds[0]]?.large?.url || "";
141
- const picture = `<img src="${firstPicUrl}"/>`;
153
+ const picture = import_koishi.h.image(firstPicUrl);
142
154
  message += screenName + " 发布了微博:\n" + text + "\n" + picture || "";
143
155
  }
144
156
  const mid = wbPost?.mid || "";
145
157
  const url = `
146
158
  链接:https://m.weibo.cn/status/${mid}`;
147
- if (keywordsList.length > 0) {
148
- let hasKeywords = false;
149
- for (const keyword of keywordsList) {
150
- if (message.includes(keyword)) {
151
- hasKeywords = true;
152
- break;
153
- }
154
- }
155
- if (!hasKeywords) {
156
- return null;
157
- }
159
+ if (!checkWords(params, message)) {
160
+ return null;
158
161
  }
159
162
  const wbpost = message ? message + url : screenName + " 发布了微博:\n" + wbPost?.text_raw + url || "";
160
163
  return { post: wbpost, islast: true };
@@ -228,18 +231,35 @@ var parseDateString = /* @__PURE__ */ __name((dateString) => {
228
231
  date.setUTCMinutes(date.getUTCMinutes() - timezoneOffset);
229
232
  return date;
230
233
  }, "parseDateString");
231
- var getLastPost = /* @__PURE__ */ __name((params, weiboList) => {
232
- for (const wb_element of weiboList) {
233
- const result = getMessage(params, wb_element);
234
- if (!result) {
235
- 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
+ }
236
244
  }
237
- if (result.islast) {
238
- return result.post;
245
+ if (!hasKeywords) {
246
+ return false;
239
247
  }
240
248
  }
241
- return null;
242
- }, "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");
243
263
  // Annotate the CommonJS export names for ESM import in node:
244
264
  0 && (module.exports = {
245
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.3",
4
+ "version": "0.0.5",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [