Commit a81e4724 authored by nanahira's avatar nanahira

bump

parent 8efedeec
......@@ -14,6 +14,19 @@ npm install koishi-plugin-autopic koishi-plugin-pics
## 配置
详见 `config.ts` 部分,或详见 Schema 描述配置。
* `targets` 的用法详见 [koishi-target-def](https://code.mycard.moe/3rdeye/koishi-target-def/)
```yaml
# koishi.yaml
plugins:
autopic:
instances:
- cron: '18 13 * * * *'
interval: 30000 # cron 和 interval 选一个即可
immediate: false # 是否立即发送
sourceTags: # 图源标签
- anime
picTags: [] # 图片标签
targets: # 见 koishi-target-def 的定义
- bot: 'onebot:1111111111'
channels:
- channelId: '222222222'
```
......@@ -9,9 +9,8 @@
"version": "2.0.3",
"license": "MIT",
"dependencies": {
"koishi-target-def": "^1.0.5",
"koishi-thirdeye": "^10.0.8",
"node-schedule": "^2.1.0"
"koishi-schedule-send": "^1.0.3",
"koishi-thirdeye": "^10.0.20"
},
"devDependencies": {
"@koishijs/plugin-cache-lru": "^1.0.0-rc.0",
......@@ -27,7 +26,7 @@
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^3.4.1",
"jest": "^27.5.1",
"koishi-plugin-picsource-lolicon": "^9.0.0",
"koishi-plugin-picsource-lolicon": "^9.0.3",
"prettier": "^2.6.0",
"raw-loader": "^4.0.2",
"ts-jest": "^27.1.3",
......@@ -39,8 +38,8 @@
"ws": "^8.5.0"
},
"peerDependencies": {
"koishi": "^4.6.1",
"koishi-plugin-pics": "^9.0.3"
"koishi": "^4.6.2",
"koishi-plugin-pics": "^9.1.2"
}
},
"node_modules/@ampproject/remapping": {
......@@ -5297,9 +5296,9 @@
}
},
"node_modules/koishi-decorators": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.0.0.tgz",
"integrity": "sha512-YAbjOLdBxJU0DnBM7vqH+UNfSqMrejlcTEc+m++ZvuMbkUA4tHZ5iciwJFV2iPZUKSZy7GbmImNbXDmmjowF5w==",
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.0.1.tgz",
"integrity": "sha512-dDrBS4Su1NtmrkIeCdcCKsC6uaBYTRTspDdeeoPLOMuSJf6fqqXwxa2qEosvG5475MXs9SaNQDaKjh0gq/NY6A==",
"dependencies": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
......@@ -5312,29 +5311,42 @@
}
},
"node_modules/koishi-plugin-pics": {
"version": "9.0.3",
"resolved": "https://registry.npmjs.org/koishi-plugin-pics/-/koishi-plugin-pics-9.0.3.tgz",
"integrity": "sha512-ZXzRJnGwg1W7dNRdmcaRyYFiGDFuOPq8qLh/Qer0Bk/dHVTW9tYZcdViXfA5TSe7sxluoB2koTRB8JvwPTnhVA==",
"version": "9.1.2",
"resolved": "https://registry.npmjs.org/koishi-plugin-pics/-/koishi-plugin-pics-9.1.2.tgz",
"integrity": "sha512-8Zuof7PTGl7efxWB7Y4W3h40+bhw3dFIvL0DIGTSJl8D2c5dgGbUT9ApHH5W4yWZcZEADwOgcg7oyH1lGSHzEg==",
"peer": true,
"dependencies": {
"koishi-thirdeye": "^10.0.5",
"koishi-thirdeye": "^10.0.20",
"lodash": "^4.17.21"
},
"peerDependencies": {
"koishi": "^4.6.1"
"koishi": "^4.6.2"
}
},
"node_modules/koishi-plugin-picsource-lolicon": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/koishi-plugin-picsource-lolicon/-/koishi-plugin-picsource-lolicon-9.0.0.tgz",
"integrity": "sha512-uz/SddPYw4S3CyAPnR9CFlfLljBsr8cXZwZdDaUs2IYt/35eQ7wzjqXLN2bs1ODp7QfD05WBc/yIHfsxT49Opg==",
"version": "9.0.3",
"resolved": "https://registry.npmjs.org/koishi-plugin-picsource-lolicon/-/koishi-plugin-picsource-lolicon-9.0.3.tgz",
"integrity": "sha512-k/V1wnjY5N2oo/HHsuV1ViFJvcpj2k9OdY0NScxfllEF+hp+Zj61lqPaqPQSTkImWHWt8qwRtJ3flA/HhMxwYw==",
"dev": true,
"dependencies": {
"koishi-thirdeye": "^10.0.0"
"koishi-thirdeye": "^10.0.20"
},
"peerDependencies": {
"koishi": "^4.6.0",
"koishi-plugin-pics": "^9.0.0"
"koishi": "^4.6.2",
"koishi-plugin-pics": "^9.1.2"
}
},
"node_modules/koishi-schedule-send": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/koishi-schedule-send/-/koishi-schedule-send-1.0.3.tgz",
"integrity": "sha512-Qsy4YcLGSXm7srNEQ7OU6HkYm24LwyNPamnydbrXH9gDJW0svqSJ7uvK8Q944QR/V8xbiu6tN63eDEsf4b5/qA==",
"dependencies": {
"koishi-target-def": "^1.0.5",
"koishi-thirdeye": "^10.0.20",
"node-schedule": "^2.1.0"
},
"peerDependencies": {
"koishi": "^4.6.2"
}
},
"node_modules/koishi-target-def": {
......@@ -5350,21 +5362,21 @@
}
},
"node_modules/koishi-thirdeye": {
"version": "10.0.8",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-10.0.8.tgz",
"integrity": "sha512-osmkYVNzcv2T2ItKFVLvCYOPEyuVbyZ6jdG7uybA2lLt4Y8zCxWHZFhq0ck1UaahZs5oFIrCfpTSdjxDv83UcQ==",
"version": "10.0.20",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-10.0.20.tgz",
"integrity": "sha512-aYBiQ6R4A8VcZ7xw0qfECIJvWsuEoW3MWdBH+SuWi0dcrwhvfF3naEtkC0ZGEnWOkauyW1YyOzTK/Fieikmv4w==",
"dependencies": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
"cosmotype-decorators": "^2.0.5",
"koishi-decorators": "^2.0.0",
"koishi-decorators": "^2.0.1",
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"schemastery-gen": "^3.1.6",
"schemastery-gen": "^3.1.10",
"typed-reflector": "^1.0.10"
},
"peerDependencies": {
"koishi": "^4.6.1",
"koishi": "^4.6.2",
"schemastery": "^3.1.0"
}
},
......@@ -6518,9 +6530,9 @@
}
},
"node_modules/schemastery-gen": {
"version": "3.1.6",
"resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.1.6.tgz",
"integrity": "sha512-UiYsiuvj830k2IzznWx/+Ed9+j1+XwMZ1zfctpy6+rHe6Se0IrulBsh2XDmI2uDslFtd6HfjIi5BJksbVvXQ/w==",
"version": "3.1.10",
"resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.1.10.tgz",
"integrity": "sha512-hwCLOICGEodCcQt+eLoEEvNhm7iSEwJB37JQ+27cHbggTry/Rq07ivXVsPw63Et74EobEaOGDVOTzJ4kIQa01w==",
"dependencies": {
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
......@@ -11901,9 +11913,9 @@
}
},
"koishi-decorators": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.0.0.tgz",
"integrity": "sha512-YAbjOLdBxJU0DnBM7vqH+UNfSqMrejlcTEc+m++ZvuMbkUA4tHZ5iciwJFV2iPZUKSZy7GbmImNbXDmmjowF5w==",
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.0.1.tgz",
"integrity": "sha512-dDrBS4Su1NtmrkIeCdcCKsC6uaBYTRTspDdeeoPLOMuSJf6fqqXwxa2qEosvG5475MXs9SaNQDaKjh0gq/NY6A==",
"requires": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
......@@ -11913,22 +11925,32 @@
}
},
"koishi-plugin-pics": {
"version": "9.0.3",
"resolved": "https://registry.npmjs.org/koishi-plugin-pics/-/koishi-plugin-pics-9.0.3.tgz",
"integrity": "sha512-ZXzRJnGwg1W7dNRdmcaRyYFiGDFuOPq8qLh/Qer0Bk/dHVTW9tYZcdViXfA5TSe7sxluoB2koTRB8JvwPTnhVA==",
"version": "9.1.2",
"resolved": "https://registry.npmjs.org/koishi-plugin-pics/-/koishi-plugin-pics-9.1.2.tgz",
"integrity": "sha512-8Zuof7PTGl7efxWB7Y4W3h40+bhw3dFIvL0DIGTSJl8D2c5dgGbUT9ApHH5W4yWZcZEADwOgcg7oyH1lGSHzEg==",
"peer": true,
"requires": {
"koishi-thirdeye": "^10.0.5",
"koishi-thirdeye": "^10.0.20",
"lodash": "^4.17.21"
}
},
"koishi-plugin-picsource-lolicon": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/koishi-plugin-picsource-lolicon/-/koishi-plugin-picsource-lolicon-9.0.0.tgz",
"integrity": "sha512-uz/SddPYw4S3CyAPnR9CFlfLljBsr8cXZwZdDaUs2IYt/35eQ7wzjqXLN2bs1ODp7QfD05WBc/yIHfsxT49Opg==",
"version": "9.0.3",
"resolved": "https://registry.npmjs.org/koishi-plugin-picsource-lolicon/-/koishi-plugin-picsource-lolicon-9.0.3.tgz",
"integrity": "sha512-k/V1wnjY5N2oo/HHsuV1ViFJvcpj2k9OdY0NScxfllEF+hp+Zj61lqPaqPQSTkImWHWt8qwRtJ3flA/HhMxwYw==",
"dev": true,
"requires": {
"koishi-thirdeye": "^10.0.0"
"koishi-thirdeye": "^10.0.20"
}
},
"koishi-schedule-send": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/koishi-schedule-send/-/koishi-schedule-send-1.0.3.tgz",
"integrity": "sha512-Qsy4YcLGSXm7srNEQ7OU6HkYm24LwyNPamnydbrXH9gDJW0svqSJ7uvK8Q944QR/V8xbiu6tN63eDEsf4b5/qA==",
"requires": {
"koishi-target-def": "^1.0.5",
"koishi-thirdeye": "^10.0.20",
"node-schedule": "^2.1.0"
}
},
"koishi-target-def": {
......@@ -11940,17 +11962,17 @@
}
},
"koishi-thirdeye": {
"version": "10.0.8",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-10.0.8.tgz",
"integrity": "sha512-osmkYVNzcv2T2ItKFVLvCYOPEyuVbyZ6jdG7uybA2lLt4Y8zCxWHZFhq0ck1UaahZs5oFIrCfpTSdjxDv83UcQ==",
"version": "10.0.20",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-10.0.20.tgz",
"integrity": "sha512-aYBiQ6R4A8VcZ7xw0qfECIJvWsuEoW3MWdBH+SuWi0dcrwhvfF3naEtkC0ZGEnWOkauyW1YyOzTK/Fieikmv4w==",
"requires": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
"cosmotype-decorators": "^2.0.5",
"koishi-decorators": "^2.0.0",
"koishi-decorators": "^2.0.1",
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"schemastery-gen": "^3.1.6",
"schemastery-gen": "^3.1.10",
"typed-reflector": "^1.0.10"
}
},
......@@ -12794,9 +12816,9 @@
}
},
"schemastery-gen": {
"version": "3.1.6",
"resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.1.6.tgz",
"integrity": "sha512-UiYsiuvj830k2IzznWx/+Ed9+j1+XwMZ1zfctpy6+rHe6Se0IrulBsh2XDmI2uDslFtd6HfjIi5BJksbVvXQ/w==",
"version": "3.1.10",
"resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.1.10.tgz",
"integrity": "sha512-hwCLOICGEodCcQt+eLoEEvNhm7iSEwJB37JQ+27cHbggTry/Rq07ivXVsPw63Et74EobEaOGDVOTzJ4kIQa01w==",
"requires": {
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
......
......@@ -44,13 +44,12 @@
"testEnvironment": "node"
},
"dependencies": {
"koishi-target-def": "^1.0.5",
"koishi-thirdeye": "^10.0.8",
"node-schedule": "^2.1.0"
"koishi-schedule-send": "^1.0.3",
"koishi-thirdeye": "^10.0.20"
},
"peerDependencies": {
"koishi": "^4.6.1",
"koishi-plugin-pics": "^9.0.3"
"koishi": "^4.6.2",
"koishi-plugin-pics": "^9.1.2"
},
"devDependencies": {
"@koishijs/plugin-cache-lru": "^1.0.0-rc.0",
......@@ -66,7 +65,7 @@
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^3.4.1",
"jest": "^27.5.1",
"koishi-plugin-picsource-lolicon": "^9.0.0",
"koishi-plugin-picsource-lolicon": "^9.0.3",
"prettier": "^2.6.0",
"raw-loader": "^4.0.2",
"ts-jest": "^27.1.3",
......
// import 'source-map-support/register';
import { SendTarget } from 'koishi-target-def';
import { SchemaProperty, RegisterSchema } from 'koishi-thirdeye';
@RegisterSchema()
export class AutoPicPluginConfig {
@SchemaProperty({ required: true })
cron: string;
@SchemaProperty({
default: false,
description: '插件启动时是否立即运行一遍。',
})
immediate: boolean;
@SchemaProperty({
type: String,
description: '图片标签。见 koishi-plugin-pics 文档。',
......@@ -24,10 +14,4 @@ export class AutoPicPluginConfig {
description: '图源标签。见 koishi-plugin-pics 文档。',
})
sourceTags: string[];
@SchemaProperty({
type: SendTarget,
description: '图片发送目标。',
})
targets: SendTarget[];
}
// import 'source-map-support/register';
import { AutoPicPluginConfig } from './config';
import {
DefinePlugin,
BasePlugin,
Inject,
InjectLogger,
LifecycleEvents,
MultiInstancePlugin,
} from 'koishi-thirdeye';
import { DefinePlugin, Inject, MultiInstancePlugin } from 'koishi-thirdeye';
import PicsContainer from 'koishi-plugin-pics';
import { Adapter, Logger } from 'koishi';
import { Job, scheduleJob } from 'node-schedule';
import { SchedulePlugin } from 'koishi-schedule-send';
export * from './config';
@DefinePlugin({ name: 'autopic', schema: AutoPicPluginConfig })
export class AutoPicInstancePlugin
extends BasePlugin<AutoPicPluginConfig>
implements LifecycleEvents
{
@DefinePlugin()
export class AutoPicInstancePlugin extends SchedulePlugin(AutoPicPluginConfig) {
@Inject(true)
private pics: PicsContainer;
@Inject(true)
private bots: Adapter.BotList;
@InjectLogger()
private logger: Logger;
async run() {
async send() {
const pic = await this.pics.randomPic(
this.config.tags,
this.config.sourceTags,
......@@ -40,41 +23,7 @@ export class AutoPicInstancePlugin
);
return;
}
const message = await this.pics.getSegment(pic.url);
await Promise.all(
this.config.targets.map(async (target) => {
try {
this.logger.debug(`Sending image ${pic.url} from ${target.bot}.`);
let targetMessage = message;
if (this.pics.isOneBotBot(this.bots.get(target.bot))) {
targetMessage = message.replace(/,url=base64/, ',file=base64');
}
const ids = await target.send(this.bots, targetMessage);
this.logger.debug(
`Image ${pic.url} sent from ${target.bot}: ${ids?.join(',')}`,
);
} catch (e) {
this.logger.error(
`Failed to send image ${pic.url} from bot ${
target.bot
}: ${e.toString()}`,
);
}
}),
);
}
private job: Job;
onConnect() {
if (this.config.immediate) {
this.run().then();
}
this.job = scheduleJob(this.config.cron, () => this.run());
}
onDisconnect() {
this.job.cancel();
return await this.pics.getSegment(pic.url);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment