Adds group configuration
This commit is contained in:
parent
0d9cf6a370
commit
154002f6f3
16 changed files with 633 additions and 20 deletions
61
source/Groups/GroupConfigurationTransformers.ts
Normal file
61
source/Groups/GroupConfigurationTransformers.ts
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import {ChannelId} from "../types/DiscordTypes";
|
||||
import {GroupConfigurationModel} from "../Models/GroupConfigurationModel";
|
||||
import {config} from "dotenv";
|
||||
import {transform} from "esbuild";
|
||||
import {Nullable} from "../types/Nullable";
|
||||
import {ArrayUtils} from "../Utilities/ArrayUtils";
|
||||
|
||||
export enum TransformerType {
|
||||
Locale,
|
||||
Channel,
|
||||
}
|
||||
|
||||
type GroupConfigurationTransformer = {
|
||||
path: string[];
|
||||
type: TransformerType,
|
||||
}
|
||||
|
||||
export type GroupConfigurationResult =
|
||||
ChannelId | Intl.Locale
|
||||
|
||||
export class GroupConfigurationTransformers {
|
||||
static TRANSFORMERS: GroupConfigurationTransformer[] = [
|
||||
{
|
||||
path: ['channels', 'newPlaydates'],
|
||||
type: TransformerType.Channel,
|
||||
},
|
||||
{
|
||||
path: ['channels', 'playdateReminders'],
|
||||
type: TransformerType.Channel,
|
||||
},
|
||||
{
|
||||
path: ['locale'],
|
||||
type: TransformerType.Locale,
|
||||
}
|
||||
];
|
||||
|
||||
public getValue(configValue: GroupConfigurationModel): GroupConfigurationResult {
|
||||
const transformerType = this.getTransformerType(configValue.key);
|
||||
if (transformerType === undefined || transformerType === null) {
|
||||
throw new Error(`Can't find transformer for ${configValue.key}`);
|
||||
}
|
||||
|
||||
switch (transformerType) {
|
||||
case TransformerType.Locale:
|
||||
return new Intl.Locale(configValue.value)
|
||||
case TransformerType.Channel:
|
||||
return <ChannelId>configValue.value;
|
||||
}
|
||||
}
|
||||
|
||||
public getTransformerType(configKey: string): Nullable<TransformerType> {
|
||||
const path = configKey.split('.');
|
||||
return GroupConfigurationTransformers.TRANSFORMERS.find(
|
||||
transformer => {
|
||||
return ArrayUtils.arraysEqual(transformer.path, path);
|
||||
}
|
||||
)?.type;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue