Skip to content

Commit

Permalink
4.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
idranme committed Nov 16, 2024
1 parent 38e2912 commit 40dbfca
Show file tree
Hide file tree
Showing 4 changed files with 252 additions and 241 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@myrtus/koishi-plugin-forward",
"description": "Forward messages",
"version": "4.1.0",
"version": "4.2.0",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand Down
129 changes: 66 additions & 63 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,100 @@
import { Schema, Dict, Time } from 'koishi'

interface Source {
channelId: string
name?: string
platform: string
blockingWords: string[]
selfId: string
channelId: string
name?: string
platform: string
blockingWords: string[]
selfId: string
onlyQuote: boolean
}
interface Target {
selfId: string
channelId: string
platform: string
disabled: boolean
simulateOriginal: boolean
selfId: string
channelId: string
platform: string
disabled: boolean
simulateOriginal: boolean
}

interface SourceConst extends Source {
type: 'source'
type: 'source'
}
interface TargetConst extends Target {
type: 'target'
type: 'target'
}
interface FullConst extends Target, Source {
type: 'full'
type: 'full'
}

export type RuleTarget = TargetConst | FullConst
export type RuleSource = SourceConst | FullConst

export interface Config {
constants: Dict<SourceConst | TargetConst | FullConst, string>
rules: {
source: string
targets: string[]
}[]
delay: Record<string, number>
constants: Dict<SourceConst | TargetConst | FullConst, string>
rules: {
source: string
targets: string[]
}[]
delay: Record<string, number>
}

const share = {
platform: Schema.string().required(),
channelId: Schema.string().required()
platform: Schema.string().required(),
channelId: Schema.string().required()
}

const sourceConst: Schema<SourceConst> = Schema.object({
type: Schema.const('source').required(),
name: Schema.string(),
...share,
selfId: Schema.string().default('*'),
blockingWords: Schema.array(String).role('table').default([])
type: Schema.const('source').required(),
name: Schema.string(),
...share,
selfId: Schema.string().default('*'),
blockingWords: Schema.array(String).role('table').default([]),
onlyQuote: Schema.boolean().default(false)
})

const targetConst: Schema<TargetConst> = Schema.object({
type: Schema.const('target').required(),
...share,
selfId: Schema.string().required(),
simulateOriginal: Schema.boolean().default(false),
disabled: Schema.boolean().default(false)
type: Schema.const('target').required(),
...share,
selfId: Schema.string().required(),
simulateOriginal: Schema.boolean().default(false),
disabled: Schema.boolean().default(false)
})

const fullConst: Schema<FullConst> = Schema.object({
type: Schema.const('full').required(),
name: Schema.string(),
...share,
selfId: Schema.string().required(),
blockingWords: Schema.array(String).role('table').default([]),
simulateOriginal: Schema.boolean().default(false),
disabled: Schema.boolean().default(false)
type: Schema.const('full').required(),
name: Schema.string(),
...share,
selfId: Schema.string().required(),
blockingWords: Schema.array(String).role('table').default([]),
simulateOriginal: Schema.boolean().default(false),
onlyQuote: Schema.boolean().default(false),
disabled: Schema.boolean().default(false),
})

export const Config: Schema<Config> = Schema.intersect([
Schema.object({
constants: Schema.dict(Schema.intersect([
Schema.object({
type: Schema.union([
Schema.const('source'),
Schema.const('target'),
Schema.const('full')
]).role('radio').required()
}),
Schema.union([
sourceConst,
targetConst,
fullConst
])
])).collapse(true)
}),
Schema.object({
rules: Schema.array(Schema.object({
source: Schema.string().required(),
targets: Schema.array(String).role('table')
})),
delay: Schema.dict(Schema.natural().role('ms').default(0.2 * Time.second))
})
Schema.object({
constants: Schema.dict(Schema.intersect([
Schema.object({
type: Schema.union([
Schema.const('source'),
Schema.const('target'),
Schema.const('full')
]).role('radio').required()
}),
Schema.union([
sourceConst,
targetConst,
fullConst
])
])).collapse(true)
}),
Schema.object({
rules: Schema.array(Schema.object({
source: Schema.string().required(),
targets: Schema.array(String).role('table')
})),
delay: Schema.dict(Schema.natural().role('ms').default(0.2 * Time.second))
})
]).i18n({
'zh-CN': require('./locales/zh-CN')
})
'zh-CN': require('./locales/zh-CN')
})
Loading

0 comments on commit 40dbfca

Please sign in to comment.