Commit d7574066 authored by nanahira's avatar nanahira

catchup

parent bdbf2ae7
......@@ -32,6 +32,7 @@ plugins:
patterns: # 语段,对于每一个语段,会带权随机选择一个。
- words:
- word: '早'
patterns: [] # 可以继续定义子语段。
- words:
- word: '上好'
- word: '安'
......
......@@ -9,7 +9,7 @@
"version": "2.3.0",
"license": "MIT",
"dependencies": {
"koishi-thirdeye": "^9.0.1",
"koishi-thirdeye": "^9.1.0",
"lodash": "^4.17.21",
"moment": "^2.29.1",
"node-schedule": "^2.1.0",
......@@ -41,7 +41,7 @@
"ws": "^8.4.2"
},
"peerDependencies": {
"koishi": "^4.3.2"
"koishi": "^4.4.0"
}
},
"node_modules/@ampproject/remapping": {
......@@ -1062,14 +1062,14 @@
}
},
"node_modules/@koishijs/core": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.3.2.tgz",
"integrity": "sha512-Z/xnla4oneEG0WzI05ZkfZRy9bAEVkzcvpEkXk3lGbuhoY6/CIHL7eboOlPLZnICFV7GNqiHobPQJxNI4cyC1Q==",
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.4.0.tgz",
"integrity": "sha512-MmKVlCx89M5icof92+U8U5QnywQ7dIjkGGUnzGlcBr59OrylHdRMKqZIIrtnqZo5EONehqh3k1Zbxr5V/6X5Eg==",
"peer": true,
"dependencies": {
"@koishijs/utils": "^5.1.2",
"@koishijs/utils": "^5.2.0",
"fastest-levenshtein": "^1.0.12",
"schemastery": "^3.0.0"
"schemastery": "^3.1.0"
},
"engines": {
"node": ">=12.0.0"
......@@ -1160,9 +1160,9 @@
"peer": true
},
"node_modules/@koishijs/utils": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/@koishijs/utils/-/utils-5.1.2.tgz",
"integrity": "sha512-KexHBO3dXR2d5oxPgbVGQ5sFnApjo7iiUfK1+cv5o2dztsKxaI2E//7e26tYQqPoBzImpJpxt5peBu43Mwa5fg==",
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/@koishijs/utils/-/utils-5.2.0.tgz",
"integrity": "sha512-KqZS/zK415XkFZn1EQ9BpT4ydaNS0ZFCAS64RT4pR8pzCUWz5eyN81Z8A7AmLKdJWgNDiT6mQ08EyUvMq0l/7Q==",
"peer": true,
"dependencies": {
"@koishijs/segment": "^1.1.1",
......@@ -5209,14 +5209,14 @@
}
},
"node_modules/koishi": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.3.2.tgz",
"integrity": "sha512-RC6wb6a+PS6Es3gEhbmyQ7Px9qXIwoGtIIuJYghaTOFKGcU301x/jYXjOGY0RTKgOoLPIRd9dgdk158TB33ZPg==",
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.4.0.tgz",
"integrity": "sha512-ar4V0oBJ2by9gT0Hey3w/japL80ddtF2A48jP+UrPZ17Z3ha505lB79sQyPVyFdM78BY7wRkFw/qMc8eKZG3+g==",
"peer": true,
"dependencies": {
"@koa/router": "^10.1.1",
"@koishijs/core": "^4.3.2",
"@koishijs/utils": "^5.1.2",
"@koishijs/core": "^4.4.0",
"@koishijs/utils": "^5.2.0",
"@types/koa": "*",
"@types/koa__router": "*",
"@types/ws": "^8.2.2",
......@@ -5249,21 +5249,21 @@
}
},
"node_modules/koishi-thirdeye": {
"version": "9.0.1",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-9.0.1.tgz",
"integrity": "sha512-iVSc+HNF1qXcKpWdn6hMhaTDXYEc7GYqkn51LOq9XQXRZ9ou1NVjAps488C+P8VaWlf3Tp25NLbnH8a0DO6bNw==",
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-9.1.0.tgz",
"integrity": "sha512-yDxve27tQomVuYH1dMPRLHM3tllE3Kcw2pnDBVkxjOolEVwzrOwjO/+H6780Gx0iSCG6fd0mE7U/DRg44RTgHw==",
"dependencies": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
"koishi-decorators": "^1.1.1",
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"schemastery-gen": "^3.0.0",
"schemastery-gen": "^3.1.0",
"typed-reflector": "^1.0.9"
},
"peerDependencies": {
"koishi": "^4.3.2",
"schemastery": "^3.0.0"
"koishi": "^4.4.0",
"schemastery": "^3.1.0"
}
},
"node_modules/leven": {
......@@ -6368,22 +6368,22 @@
}
},
"node_modules/schemastery": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.0.0.tgz",
"integrity": "sha512-0aWxVyVoa5XMxfsFqHdyj2QZCiUgImzcsCEdseALm57JlmBktu92EvTXm1AebD21q/fcSi+M7BGclDQyfMjQzg==",
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.1.0.tgz",
"integrity": "sha512-I1KaYmKfB+buINqBXydV8bC7N+BaC8y/V+609oSJNDO3mP3DY0zoNcDCIaY95KR0a5Cr9+CxgKl5BLEgFoikzw==",
"peer": true
},
"node_modules/schemastery-gen": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.0.0.tgz",
"integrity": "sha512-g6lxh/R1r3x9hqXKY6q/P6t6uvzpz2eUtm4GbwtIYclPS2Jfk6MT3b38x5dvR62RvnLzsinvmekAdVOD1iEUjQ==",
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.1.0.tgz",
"integrity": "sha512-rVvv/c47aKU40f49+MWiM/anoZoKgo6+54jn4XL3frren/KISwklsJ9EstkVwUGeGiwxekP4ZNlWGS/3k0n+Aw==",
"dependencies": {
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"typed-reflector": "^1.0.8"
},
"peerDependencies": {
"schemastery": "^3.0.0"
"schemastery": "^3.1.0"
}
},
"node_modules/semver": {
......@@ -8530,14 +8530,14 @@
}
},
"@koishijs/core": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.3.2.tgz",
"integrity": "sha512-Z/xnla4oneEG0WzI05ZkfZRy9bAEVkzcvpEkXk3lGbuhoY6/CIHL7eboOlPLZnICFV7GNqiHobPQJxNI4cyC1Q==",
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.4.0.tgz",
"integrity": "sha512-MmKVlCx89M5icof92+U8U5QnywQ7dIjkGGUnzGlcBr59OrylHdRMKqZIIrtnqZo5EONehqh3k1Zbxr5V/6X5Eg==",
"peer": true,
"requires": {
"@koishijs/utils": "^5.1.2",
"@koishijs/utils": "^5.2.0",
"fastest-levenshtein": "^1.0.12",
"schemastery": "^3.0.0"
"schemastery": "^3.1.0"
}
},
"@koishijs/orm-utils": {
......@@ -8607,9 +8607,9 @@
"peer": true
},
"@koishijs/utils": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/@koishijs/utils/-/utils-5.1.2.tgz",
"integrity": "sha512-KexHBO3dXR2d5oxPgbVGQ5sFnApjo7iiUfK1+cv5o2dztsKxaI2E//7e26tYQqPoBzImpJpxt5peBu43Mwa5fg==",
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/@koishijs/utils/-/utils-5.2.0.tgz",
"integrity": "sha512-KqZS/zK415XkFZn1EQ9BpT4ydaNS0ZFCAS64RT4pR8pzCUWz5eyN81Z8A7AmLKdJWgNDiT6mQ08EyUvMq0l/7Q==",
"peer": true,
"requires": {
"@koishijs/segment": "^1.1.1",
......@@ -11747,14 +11747,14 @@
}
},
"koishi": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.3.2.tgz",
"integrity": "sha512-RC6wb6a+PS6Es3gEhbmyQ7Px9qXIwoGtIIuJYghaTOFKGcU301x/jYXjOGY0RTKgOoLPIRd9dgdk158TB33ZPg==",
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.4.0.tgz",
"integrity": "sha512-ar4V0oBJ2by9gT0Hey3w/japL80ddtF2A48jP+UrPZ17Z3ha505lB79sQyPVyFdM78BY7wRkFw/qMc8eKZG3+g==",
"peer": true,
"requires": {
"@koa/router": "^10.1.1",
"@koishijs/core": "^4.3.2",
"@koishijs/utils": "^5.1.2",
"@koishijs/core": "^4.4.0",
"@koishijs/utils": "^5.2.0",
"@types/koa": "*",
"@types/koa__router": "*",
"@types/ws": "^8.2.2",
......@@ -11781,16 +11781,16 @@
}
},
"koishi-thirdeye": {
"version": "9.0.1",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-9.0.1.tgz",
"integrity": "sha512-iVSc+HNF1qXcKpWdn6hMhaTDXYEc7GYqkn51LOq9XQXRZ9ou1NVjAps488C+P8VaWlf3Tp25NLbnH8a0DO6bNw==",
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-9.1.0.tgz",
"integrity": "sha512-yDxve27tQomVuYH1dMPRLHM3tllE3Kcw2pnDBVkxjOolEVwzrOwjO/+H6780Gx0iSCG6fd0mE7U/DRg44RTgHw==",
"requires": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
"koishi-decorators": "^1.1.1",
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"schemastery-gen": "^3.0.0",
"schemastery-gen": "^3.1.0",
"typed-reflector": "^1.0.9"
}
},
......@@ -12593,15 +12593,15 @@
}
},
"schemastery": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.0.0.tgz",
"integrity": "sha512-0aWxVyVoa5XMxfsFqHdyj2QZCiUgImzcsCEdseALm57JlmBktu92EvTXm1AebD21q/fcSi+M7BGclDQyfMjQzg==",
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.1.0.tgz",
"integrity": "sha512-I1KaYmKfB+buINqBXydV8bC7N+BaC8y/V+609oSJNDO3mP3DY0zoNcDCIaY95KR0a5Cr9+CxgKl5BLEgFoikzw==",
"peer": true
},
"schemastery-gen": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.0.0.tgz",
"integrity": "sha512-g6lxh/R1r3x9hqXKY6q/P6t6uvzpz2eUtm4GbwtIYclPS2Jfk6MT3b38x5dvR62RvnLzsinvmekAdVOD1iEUjQ==",
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.1.0.tgz",
"integrity": "sha512-rVvv/c47aKU40f49+MWiM/anoZoKgo6+54jn4XL3frren/KISwklsJ9EstkVwUGeGiwxekP4ZNlWGS/3k0n+Aw==",
"requires": {
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
......
......@@ -28,7 +28,7 @@
},
"homepage": "https://code.mycard.moe/3rdeye/koishi-plugin-greeting",
"dependencies": {
"koishi-thirdeye": "^9.0.1",
"koishi-thirdeye": "^9.1.0",
"lodash": "^4.17.21",
"moment": "^2.29.1",
"node-schedule": "^2.1.0",
......@@ -60,7 +60,7 @@
"ws": "^8.4.2"
},
"peerDependencies": {
"koishi": "^4.3.2"
"koishi": "^4.4.0"
},
"jest": {
"moduleFileExtensions": [
......
import 'source-map-support/register';
import { DefineSchema, RegisterSchema } from 'koishi-thirdeye';
import { DefineSchema, RegisterSchema, SchemaRef } from 'koishi-thirdeye';
import _ from 'lodash';
import { Adapter, Bot, Logger, Random } from 'koishi';
import moment from 'moment';
......@@ -29,14 +29,27 @@ function hashRandom(saltObjects: Salt[]) {
export class Word {
constructor(config: Partial<Word>) {}
@DefineSchema({ description: '文本。', required: true })
word: string;
@DefineSchema({ description: '文本。', default: '' })
word?: string;
@DefineSchema({ description: '权重。', default: 1 })
weight?: number;
formWord() {
return `${this.word}${(this.patterns || [])
.map((p) => p.pickWord())
.join('')}`;
}
@DefineSchema({
description: '子语段。',
type: SchemaRef(() => Pattern),
default: [],
})
patterns?: Pattern[];
toEntry() {
return [this.word, this.weight || 1];
return [this.formWord(), this.weight || 1];
}
}
......@@ -46,7 +59,7 @@ export class Pattern {
@DefineSchema({
description: '词语。该语段中会随机悬着其中1种词语出现。',
type: Word,
type: SchemaRef(() => Word),
})
words: Word[];
......
import { App } from 'koishi';
import TargetPlugin from '../src';
import { Word, Pattern } from '../src';
describe('Test of plugin.', () => {
let app: App;
beforeEach(async () => {
app = new App();
// app.plugin(TargetPlugin);
await app.start();
});
it('should pass', () => {
expect(true).toBe(true);
describe('Test of pattern', () => {
it('should form pattern', () => {
const word = new Word({
word: 'test',
patterns: [
new Pattern({
words: [new Word({ word: 'foo' }), new Word({ word: 'bar' })],
}),
new Pattern({
words: [new Word({ word: 'baz' })],
}),
],
});
const text = word.formWord();
expect(text === 'testfoobaz' || text === 'testbarbaz').toBe(true);
});
});
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