koishi-plugin-rss-cat
Advanced tools
Comparing version 0.0.13 to 0.0.14
import { Context, Logger, Schema, Dict } from 'koishi'; | ||
import Puppeteer from 'koishi-plugin-puppeteer'; | ||
export declare const name = "rss-cat"; | ||
export declare const inject: { | ||
optional: any[]; | ||
optional: string[]; | ||
required: string[]; | ||
@@ -16,2 +17,3 @@ }; | ||
}; | ||
toImg: boolean; | ||
} | ||
@@ -44,2 +46,5 @@ export declare const Config: Schema<Schemastery.ObjectS<{ | ||
} | ||
interface Context { | ||
puppeteer: Puppeteer; | ||
} | ||
} | ||
@@ -46,0 +51,0 @@ export interface RssSource { |
@@ -33,3 +33,3 @@ "use strict"; | ||
exports.inject = { | ||
optional: [], | ||
optional: ['puppeteer'], | ||
required: ['database'] | ||
@@ -50,3 +50,3 @@ }; | ||
koishi_1.Schema.object({ | ||
toImg: koishi_1.Schema.boolean().description("转换成图片发送(正在制作 启用无效)").default(false).experimental(), | ||
toImg: koishi_1.Schema.boolean().description("使用 puppeteer 插件转换成图片发送。请确保 puppeteer 服务已加载。在 puppeteer 插件设置页面中调节转换成图片的详细设置(如图片宽度)。 ").default(false).experimental(), | ||
}).description('<description> 的特殊处理') | ||
@@ -76,13 +76,17 @@ ]); | ||
// | ||
//TODO: 使用rxjs确保只有一个UpdateSubOperator在运行 | ||
if (config.toImg && !(ctx.puppeteer)) { | ||
exports.logger.warn("警告:toImg 选项已打开,但未检测到 puppeteer 服务,可能无法正常推送消息。"); | ||
} | ||
//定时拉取新消息,有新消息就推送 | ||
ctx.setInterval(async () => { | ||
const DBreturn = await ctx.database.get('rsscat.source', {}); | ||
(0, rxjs_1.from)(DBreturn).pipe(updater.UpdateSubOperator(ctx, config)). | ||
subscribe({ | ||
error: (err) => { | ||
exports.logger.warn(err); | ||
} | ||
}); | ||
}, config.refresh * koishi_1.Time.second); | ||
}); | ||
//定时拉取新消息,有新消息就推送 | ||
ctx.setInterval(async () => { | ||
const DBreturn = await ctx.database.get('rsscat.source', {}); | ||
(0, rxjs_1.from)(DBreturn).pipe(updater.UpdateSubOperator(ctx, config)). | ||
subscribe({ | ||
error: (err) => { | ||
exports.logger.warn(err); | ||
} | ||
}); | ||
}, config.refresh * koishi_1.Time.second); | ||
ctx.command('rsscat', '订阅推送,设计为与rsshub搭配使用'); | ||
@@ -136,4 +140,9 @@ ctx.command('rsscat.add <rssLink:string>', '增加一个订阅').example('rsscat add https://www.solidot.org/index.rss') | ||
}); | ||
/* | ||
ctx.command('rsscat.testImg', '测试 puppeteer 可用性') | ||
.action(async function ({ session }, rssLink) { | ||
return await ctx.puppeteer.render('<h1>test</h1>') | ||
});*/ | ||
//ctx.command('rss-cat.set', '设定 rss-cat 在当前频道的行为') | ||
} | ||
exports.apply = apply; |
@@ -8,3 +8,3 @@ import { Context } from 'koishi'; | ||
[x: string]: any; | ||
}, config: Config): string; | ||
}, config: Config, ctx: Context): string; | ||
export { UpdateSubOperator, getRSSbody, getRSSItems, RSScomposer }; |
@@ -27,3 +27,3 @@ "use strict"; | ||
for (const item of newItems) { | ||
const message = RSScomposer(item, config); | ||
const message = RSScomposer(item, config, ctx); | ||
await ctx.broadcast(RssSource.subscriber, message); | ||
@@ -62,8 +62,19 @@ } | ||
; | ||
function RSScomposer(item, config) { | ||
function RSScomposer(item, config, ctx) { | ||
let message = ''; | ||
Object.entries(config.RSSitem).forEach(([key, enabled]) => { | ||
Object.entries(config.RSSitem).forEach(async ([key, enabled]) => { | ||
if (!enabled) | ||
return; | ||
message += `${item[key]}\n`; | ||
if (key === 'description') { | ||
//<description> 的特殊处理 | ||
if (config.toImg) { | ||
message += `${(await ctx.puppeteer.render(item[key]))}\n`; | ||
} | ||
else { | ||
message += `${item[key]}\n`; | ||
} | ||
} | ||
else { | ||
message += `${item[key]}\n`; | ||
} | ||
}); | ||
@@ -70,0 +81,0 @@ return message; |
{ | ||
"name": "koishi-plugin-rss-cat", | ||
"description": "又一款rss订阅推送器(开发中)", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"main": "lib/index.js", | ||
@@ -18,3 +18,4 @@ "typings": "lib/index.d.ts", | ||
"peerDependencies": { | ||
"koishi": "^4.17.6" | ||
"koishi": "^4.17.6", | ||
"koishi-plugin-puppeteer": "*" | ||
}, | ||
@@ -21,0 +22,0 @@ "dependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
130015
2409
4