-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
252 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) |
Oops, something went wrong.