Commit a81e4724 authored by nanahira's avatar nanahira

bump

parent 8efedeec
...@@ -14,6 +14,19 @@ npm install koishi-plugin-autopic koishi-plugin-pics ...@@ -14,6 +14,19 @@ npm install koishi-plugin-autopic koishi-plugin-pics
## 配置 ## 配置
详见 `config.ts` 部分,或详见 Schema 描述配置。 ```yaml
# koishi.yaml
* `targets` 的用法详见 [koishi-target-def](https://code.mycard.moe/3rdeye/koishi-target-def/) 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 @@ ...@@ -9,9 +9,8 @@
"version": "2.0.3", "version": "2.0.3",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"koishi-target-def": "^1.0.5", "koishi-schedule-send": "^1.0.3",
"koishi-thirdeye": "^10.0.8", "koishi-thirdeye": "^10.0.20"
"node-schedule": "^2.1.0"
}, },
"devDependencies": { "devDependencies": {
"@koishijs/plugin-cache-lru": "^1.0.0-rc.0", "@koishijs/plugin-cache-lru": "^1.0.0-rc.0",
...@@ -27,7 +26,7 @@ ...@@ -27,7 +26,7 @@
"eslint-config-prettier": "^8.5.0", "eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^3.4.1", "eslint-plugin-prettier": "^3.4.1",
"jest": "^27.5.1", "jest": "^27.5.1",
"koishi-plugin-picsource-lolicon": "^9.0.0", "koishi-plugin-picsource-lolicon": "^9.0.3",
"prettier": "^2.6.0", "prettier": "^2.6.0",
"raw-loader": "^4.0.2", "raw-loader": "^4.0.2",
"ts-jest": "^27.1.3", "ts-jest": "^27.1.3",
...@@ -39,8 +38,8 @@ ...@@ -39,8 +38,8 @@
"ws": "^8.5.0" "ws": "^8.5.0"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.6.1", "koishi": "^4.6.2",
"koishi-plugin-pics": "^9.0.3" "koishi-plugin-pics": "^9.1.2"
} }
}, },
"node_modules/@ampproject/remapping": { "node_modules/@ampproject/remapping": {
...@@ -5297,9 +5296,9 @@ ...@@ -5297,9 +5296,9 @@
} }
}, },
"node_modules/koishi-decorators": { "node_modules/koishi-decorators": {
"version": "2.0.0", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.0.0.tgz", "resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.0.1.tgz",
"integrity": "sha512-YAbjOLdBxJU0DnBM7vqH+UNfSqMrejlcTEc+m++ZvuMbkUA4tHZ5iciwJFV2iPZUKSZy7GbmImNbXDmmjowF5w==", "integrity": "sha512-dDrBS4Su1NtmrkIeCdcCKsC6uaBYTRTspDdeeoPLOMuSJf6fqqXwxa2qEosvG5475MXs9SaNQDaKjh0gq/NY6A==",
"dependencies": { "dependencies": {
"@types/koa": "^2.13.4", "@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11", "@types/koa__router": "^8.0.11",
...@@ -5312,29 +5311,42 @@ ...@@ -5312,29 +5311,42 @@
} }
}, },
"node_modules/koishi-plugin-pics": { "node_modules/koishi-plugin-pics": {
"version": "9.0.3", "version": "9.1.2",
"resolved": "https://registry.npmjs.org/koishi-plugin-pics/-/koishi-plugin-pics-9.0.3.tgz", "resolved": "https://registry.npmjs.org/koishi-plugin-pics/-/koishi-plugin-pics-9.1.2.tgz",
"integrity": "sha512-ZXzRJnGwg1W7dNRdmcaRyYFiGDFuOPq8qLh/Qer0Bk/dHVTW9tYZcdViXfA5TSe7sxluoB2koTRB8JvwPTnhVA==", "integrity": "sha512-8Zuof7PTGl7efxWB7Y4W3h40+bhw3dFIvL0DIGTSJl8D2c5dgGbUT9ApHH5W4yWZcZEADwOgcg7oyH1lGSHzEg==",
"peer": true, "peer": true,
"dependencies": { "dependencies": {
"koishi-thirdeye": "^10.0.5", "koishi-thirdeye": "^10.0.20",
"lodash": "^4.17.21" "lodash": "^4.17.21"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.6.1" "koishi": "^4.6.2"
} }
}, },
"node_modules/koishi-plugin-picsource-lolicon": { "node_modules/koishi-plugin-picsource-lolicon": {
"version": "9.0.0", "version": "9.0.3",
"resolved": "https://registry.npmjs.org/koishi-plugin-picsource-lolicon/-/koishi-plugin-picsource-lolicon-9.0.0.tgz", "resolved": "https://registry.npmjs.org/koishi-plugin-picsource-lolicon/-/koishi-plugin-picsource-lolicon-9.0.3.tgz",
"integrity": "sha512-uz/SddPYw4S3CyAPnR9CFlfLljBsr8cXZwZdDaUs2IYt/35eQ7wzjqXLN2bs1ODp7QfD05WBc/yIHfsxT49Opg==", "integrity": "sha512-k/V1wnjY5N2oo/HHsuV1ViFJvcpj2k9OdY0NScxfllEF+hp+Zj61lqPaqPQSTkImWHWt8qwRtJ3flA/HhMxwYw==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"koishi-thirdeye": "^10.0.0" "koishi-thirdeye": "^10.0.20"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.6.0", "koishi": "^4.6.2",
"koishi-plugin-pics": "^9.0.0" "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": { "node_modules/koishi-target-def": {
...@@ -5350,21 +5362,21 @@ ...@@ -5350,21 +5362,21 @@
} }
}, },
"node_modules/koishi-thirdeye": { "node_modules/koishi-thirdeye": {
"version": "10.0.8", "version": "10.0.20",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-10.0.8.tgz", "resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-10.0.20.tgz",
"integrity": "sha512-osmkYVNzcv2T2ItKFVLvCYOPEyuVbyZ6jdG7uybA2lLt4Y8zCxWHZFhq0ck1UaahZs5oFIrCfpTSdjxDv83UcQ==", "integrity": "sha512-aYBiQ6R4A8VcZ7xw0qfECIJvWsuEoW3MWdBH+SuWi0dcrwhvfF3naEtkC0ZGEnWOkauyW1YyOzTK/Fieikmv4w==",
"dependencies": { "dependencies": {
"@types/koa": "^2.13.4", "@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11", "@types/koa__router": "^8.0.11",
"cosmotype-decorators": "^2.0.5", "cosmotype-decorators": "^2.0.5",
"koishi-decorators": "^2.0.0", "koishi-decorators": "^2.0.1",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"schemastery-gen": "^3.1.6", "schemastery-gen": "^3.1.10",
"typed-reflector": "^1.0.10" "typed-reflector": "^1.0.10"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.6.1", "koishi": "^4.6.2",
"schemastery": "^3.1.0" "schemastery": "^3.1.0"
} }
}, },
...@@ -6518,9 +6530,9 @@ ...@@ -6518,9 +6530,9 @@
} }
}, },
"node_modules/schemastery-gen": { "node_modules/schemastery-gen": {
"version": "3.1.6", "version": "3.1.10",
"resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.1.6.tgz", "resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.1.10.tgz",
"integrity": "sha512-UiYsiuvj830k2IzznWx/+Ed9+j1+XwMZ1zfctpy6+rHe6Se0IrulBsh2XDmI2uDslFtd6HfjIi5BJksbVvXQ/w==", "integrity": "sha512-hwCLOICGEodCcQt+eLoEEvNhm7iSEwJB37JQ+27cHbggTry/Rq07ivXVsPw63Et74EobEaOGDVOTzJ4kIQa01w==",
"dependencies": { "dependencies": {
"lodash": "^4.17.21", "lodash": "^4.17.21",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
...@@ -11901,9 +11913,9 @@ ...@@ -11901,9 +11913,9 @@
} }
}, },
"koishi-decorators": { "koishi-decorators": {
"version": "2.0.0", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.0.0.tgz", "resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.0.1.tgz",
"integrity": "sha512-YAbjOLdBxJU0DnBM7vqH+UNfSqMrejlcTEc+m++ZvuMbkUA4tHZ5iciwJFV2iPZUKSZy7GbmImNbXDmmjowF5w==", "integrity": "sha512-dDrBS4Su1NtmrkIeCdcCKsC6uaBYTRTspDdeeoPLOMuSJf6fqqXwxa2qEosvG5475MXs9SaNQDaKjh0gq/NY6A==",
"requires": { "requires": {
"@types/koa": "^2.13.4", "@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11", "@types/koa__router": "^8.0.11",
...@@ -11913,22 +11925,32 @@ ...@@ -11913,22 +11925,32 @@
} }
}, },
"koishi-plugin-pics": { "koishi-plugin-pics": {
"version": "9.0.3", "version": "9.1.2",
"resolved": "https://registry.npmjs.org/koishi-plugin-pics/-/koishi-plugin-pics-9.0.3.tgz", "resolved": "https://registry.npmjs.org/koishi-plugin-pics/-/koishi-plugin-pics-9.1.2.tgz",
"integrity": "sha512-ZXzRJnGwg1W7dNRdmcaRyYFiGDFuOPq8qLh/Qer0Bk/dHVTW9tYZcdViXfA5TSe7sxluoB2koTRB8JvwPTnhVA==", "integrity": "sha512-8Zuof7PTGl7efxWB7Y4W3h40+bhw3dFIvL0DIGTSJl8D2c5dgGbUT9ApHH5W4yWZcZEADwOgcg7oyH1lGSHzEg==",
"peer": true, "peer": true,
"requires": { "requires": {
"koishi-thirdeye": "^10.0.5", "koishi-thirdeye": "^10.0.20",
"lodash": "^4.17.21" "lodash": "^4.17.21"
} }
}, },
"koishi-plugin-picsource-lolicon": { "koishi-plugin-picsource-lolicon": {
"version": "9.0.0", "version": "9.0.3",
"resolved": "https://registry.npmjs.org/koishi-plugin-picsource-lolicon/-/koishi-plugin-picsource-lolicon-9.0.0.tgz", "resolved": "https://registry.npmjs.org/koishi-plugin-picsource-lolicon/-/koishi-plugin-picsource-lolicon-9.0.3.tgz",
"integrity": "sha512-uz/SddPYw4S3CyAPnR9CFlfLljBsr8cXZwZdDaUs2IYt/35eQ7wzjqXLN2bs1ODp7QfD05WBc/yIHfsxT49Opg==", "integrity": "sha512-k/V1wnjY5N2oo/HHsuV1ViFJvcpj2k9OdY0NScxfllEF+hp+Zj61lqPaqPQSTkImWHWt8qwRtJ3flA/HhMxwYw==",
"dev": true, "dev": true,
"requires": { "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": { "koishi-target-def": {
...@@ -11940,17 +11962,17 @@ ...@@ -11940,17 +11962,17 @@
} }
}, },
"koishi-thirdeye": { "koishi-thirdeye": {
"version": "10.0.8", "version": "10.0.20",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-10.0.8.tgz", "resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-10.0.20.tgz",
"integrity": "sha512-osmkYVNzcv2T2ItKFVLvCYOPEyuVbyZ6jdG7uybA2lLt4Y8zCxWHZFhq0ck1UaahZs5oFIrCfpTSdjxDv83UcQ==", "integrity": "sha512-aYBiQ6R4A8VcZ7xw0qfECIJvWsuEoW3MWdBH+SuWi0dcrwhvfF3naEtkC0ZGEnWOkauyW1YyOzTK/Fieikmv4w==",
"requires": { "requires": {
"@types/koa": "^2.13.4", "@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11", "@types/koa__router": "^8.0.11",
"cosmotype-decorators": "^2.0.5", "cosmotype-decorators": "^2.0.5",
"koishi-decorators": "^2.0.0", "koishi-decorators": "^2.0.1",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"schemastery-gen": "^3.1.6", "schemastery-gen": "^3.1.10",
"typed-reflector": "^1.0.10" "typed-reflector": "^1.0.10"
} }
}, },
...@@ -12794,9 +12816,9 @@ ...@@ -12794,9 +12816,9 @@
} }
}, },
"schemastery-gen": { "schemastery-gen": {
"version": "3.1.6", "version": "3.1.10",
"resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.1.6.tgz", "resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.1.10.tgz",
"integrity": "sha512-UiYsiuvj830k2IzznWx/+Ed9+j1+XwMZ1zfctpy6+rHe6Se0IrulBsh2XDmI2uDslFtd6HfjIi5BJksbVvXQ/w==", "integrity": "sha512-hwCLOICGEodCcQt+eLoEEvNhm7iSEwJB37JQ+27cHbggTry/Rq07ivXVsPw63Et74EobEaOGDVOTzJ4kIQa01w==",
"requires": { "requires": {
"lodash": "^4.17.21", "lodash": "^4.17.21",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
......
...@@ -44,13 +44,12 @@ ...@@ -44,13 +44,12 @@
"testEnvironment": "node" "testEnvironment": "node"
}, },
"dependencies": { "dependencies": {
"koishi-target-def": "^1.0.5", "koishi-schedule-send": "^1.0.3",
"koishi-thirdeye": "^10.0.8", "koishi-thirdeye": "^10.0.20"
"node-schedule": "^2.1.0"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.6.1", "koishi": "^4.6.2",
"koishi-plugin-pics": "^9.0.3" "koishi-plugin-pics": "^9.1.2"
}, },
"devDependencies": { "devDependencies": {
"@koishijs/plugin-cache-lru": "^1.0.0-rc.0", "@koishijs/plugin-cache-lru": "^1.0.0-rc.0",
...@@ -66,7 +65,7 @@ ...@@ -66,7 +65,7 @@
"eslint-config-prettier": "^8.5.0", "eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^3.4.1", "eslint-plugin-prettier": "^3.4.1",
"jest": "^27.5.1", "jest": "^27.5.1",
"koishi-plugin-picsource-lolicon": "^9.0.0", "koishi-plugin-picsource-lolicon": "^9.0.3",
"prettier": "^2.6.0", "prettier": "^2.6.0",
"raw-loader": "^4.0.2", "raw-loader": "^4.0.2",
"ts-jest": "^27.1.3", "ts-jest": "^27.1.3",
......
// import 'source-map-support/register'; // import 'source-map-support/register';
import { SendTarget } from 'koishi-target-def';
import { SchemaProperty, RegisterSchema } from 'koishi-thirdeye'; import { SchemaProperty, RegisterSchema } from 'koishi-thirdeye';
@RegisterSchema() @RegisterSchema()
export class AutoPicPluginConfig { export class AutoPicPluginConfig {
@SchemaProperty({ required: true })
cron: string;
@SchemaProperty({
default: false,
description: '插件启动时是否立即运行一遍。',
})
immediate: boolean;
@SchemaProperty({ @SchemaProperty({
type: String, type: String,
description: '图片标签。见 koishi-plugin-pics 文档。', description: '图片标签。见 koishi-plugin-pics 文档。',
...@@ -24,10 +14,4 @@ export class AutoPicPluginConfig { ...@@ -24,10 +14,4 @@ export class AutoPicPluginConfig {
description: '图源标签。见 koishi-plugin-pics 文档。', description: '图源标签。见 koishi-plugin-pics 文档。',
}) })
sourceTags: string[]; sourceTags: string[];
@SchemaProperty({
type: SendTarget,
description: '图片发送目标。',
})
targets: SendTarget[];
} }
// import 'source-map-support/register'; // import 'source-map-support/register';
import { AutoPicPluginConfig } from './config'; import { AutoPicPluginConfig } from './config';
import { import { DefinePlugin, Inject, MultiInstancePlugin } from 'koishi-thirdeye';
DefinePlugin,
BasePlugin,
Inject,
InjectLogger,
LifecycleEvents,
MultiInstancePlugin,
} from 'koishi-thirdeye';
import PicsContainer from 'koishi-plugin-pics'; import PicsContainer from 'koishi-plugin-pics';
import { Adapter, Logger } from 'koishi'; import { SchedulePlugin } from 'koishi-schedule-send';
import { Job, scheduleJob } from 'node-schedule';
export * from './config'; export * from './config';
@DefinePlugin({ name: 'autopic', schema: AutoPicPluginConfig }) @DefinePlugin()
export class AutoPicInstancePlugin export class AutoPicInstancePlugin extends SchedulePlugin(AutoPicPluginConfig) {
extends BasePlugin<AutoPicPluginConfig>
implements LifecycleEvents
{
@Inject(true) @Inject(true)
private pics: PicsContainer; private pics: PicsContainer;
@Inject(true) async send() {
private bots: Adapter.BotList;
@InjectLogger()
private logger: Logger;
async run() {
const pic = await this.pics.randomPic( const pic = await this.pics.randomPic(
this.config.tags, this.config.tags,
this.config.sourceTags, this.config.sourceTags,
...@@ -40,41 +23,7 @@ export class AutoPicInstancePlugin ...@@ -40,41 +23,7 @@ export class AutoPicInstancePlugin
); );
return; return;
} }
const message = await this.pics.getSegment(pic.url); return 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();
} }
} }
......
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