Commit ef73b952 authored by nanahira's avatar nanahira

rework with factory

parent e92712c3
......@@ -42,20 +42,5 @@ export class SchedulePluginConfig {
description: '图片发送目标。',
})
targets: SendTarget[];
initializeTasks(ctx: Context, callback: () => void) {
if (this.immediate) {
callback();
}
if (this.cron) {
const job = scheduleJob(this.cron, callback);
ctx.on('dispose', () => {
job.cancel()
});
}
if (this.interval) {
ctx.setInterval(callback, this.interval);
}
}
}
```
import { Context } from 'koishi';
import { DefinePlugin, SchemaProperty } from 'koishi-thirdeye';
import {
DefinePlugin,
MultiInstancePlugin,
SchemaProperty,
} from 'koishi-thirdeye';
import { SchedulePlugin } from '../src';
class Config {
......@@ -14,17 +18,24 @@ class TestSendPlugin extends SchedulePlugin(Config) {
}
}
@DefinePlugin()
class MultiTestSendPlugin extends MultiInstancePlugin(TestSendPlugin) {}
export default class ExtrasInDev {
constructor(ctx: Context) {
ctx.plugin(TestSendPlugin, {
message: 'dress',
interval: 5000,
immediate: true,
targets: [
ctx.plugin(MultiTestSendPlugin, {
instances: [
{
bot: 'sandbox:koishi',
users: ['Alice', 'Bob'],
channels: [{ channelId: '#' }],
message: 'dress',
interval: 5000,
immediate: true,
targets: [
{
bot: 'sandbox:koishi',
users: ['Alice', 'Bob'],
channels: [{ channelId: '#' }],
},
],
},
],
});
......
{
"name": "koishi-plugin-SchedulePlugin",
"name": "koishi-schedule-send",
"version": "1.0.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "koishi-plugin-SchedulePlugin",
"name": "koishi-schedule-send",
"version": "1.0.2",
"license": "MIT",
"dependencies": {
"koishi-target-def": "^1.0.5",
"koishi-thirdeye": "^10.0.12",
"koishi-thirdeye": "^10.0.20",
"node-schedule": "^2.1.0"
},
"devDependencies": {
......@@ -5338,9 +5338,9 @@
}
},
"node_modules/koishi-thirdeye": {
"version": "10.0.12",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-10.0.12.tgz",
"integrity": "sha512-ErvIbWU+tsLIroKAs6ErldrfCQSqyVhewZXVV3j1cOrZCWlsp+HElYXWqFiFqSs7xm5IcfoNa4cN6RFCOHk8PA==",
"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",
......@@ -5348,7 +5348,7 @@
"koishi-decorators": "^2.0.1",
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"schemastery-gen": "^3.1.7",
"schemastery-gen": "^3.1.10",
"typed-reflector": "^1.0.10"
},
"peerDependencies": {
......@@ -6512,9 +6512,9 @@
}
},
"node_modules/schemastery-gen": {
"version": "3.1.7",
"resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.1.7.tgz",
"integrity": "sha512-0M/9QLRQ2yuDxMVkwkcW0g3Lf+2De+dPlll8CEgzKJ4ow1zDd/H/k+gDPLawpAccAooHoGgV2++8RGWecXf7MQ==",
"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",
......@@ -11951,9 +11951,9 @@
}
},
"koishi-thirdeye": {
"version": "10.0.12",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-10.0.12.tgz",
"integrity": "sha512-ErvIbWU+tsLIroKAs6ErldrfCQSqyVhewZXVV3j1cOrZCWlsp+HElYXWqFiFqSs7xm5IcfoNa4cN6RFCOHk8PA==",
"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",
......@@ -11961,7 +11961,7 @@
"koishi-decorators": "^2.0.1",
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"schemastery-gen": "^3.1.7",
"schemastery-gen": "^3.1.10",
"typed-reflector": "^1.0.10"
}
},
......@@ -12811,9 +12811,9 @@
}
},
"schemastery-gen": {
"version": "3.1.7",
"resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.1.7.tgz",
"integrity": "sha512-0M/9QLRQ2yuDxMVkwkcW0g3Lf+2De+dPlll8CEgzKJ4ow1zDd/H/k+gDPLawpAccAooHoGgV2++8RGWecXf7MQ==",
"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",
......
......@@ -45,7 +45,7 @@
},
"dependencies": {
"koishi-target-def": "^1.0.5",
"koishi-thirdeye": "^10.0.12",
"koishi-thirdeye": "^10.0.20",
"node-schedule": "^2.1.0"
},
"peerDependencies": {
......
......@@ -2,20 +2,16 @@
import { SchedulePluginConfig } from './config';
import {
BasePlugin,
ClassType,
CreatePluginFactory,
Inject,
InjectLogger,
Mixin,
PluginSchema,
} from 'koishi-thirdeye';
import { Logger } from 'koishi';
import { Adapter } from 'koishi';
import { Bot } from 'koishi';
export * from './config';
export class BaseSchedulePlugin<C> extends BasePlugin<
SchedulePluginConfig & C
> {
export class BaseSchedulePlugin extends BasePlugin<SchedulePluginConfig> {
@InjectLogger()
logger: Logger;
......@@ -73,8 +69,7 @@ export class BaseSchedulePlugin<C> extends BasePlugin<
}
}
export function SchedulePlugin<C>(config?: ClassType<C>) {
const plugin = class SpecificSchedulePlugin extends BaseSchedulePlugin<C> {};
PluginSchema(Mixin(config, SchedulePluginConfig))(plugin);
return plugin;
}
export const SchedulePlugin = CreatePluginFactory(
BaseSchedulePlugin,
SchedulePluginConfig,
);
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