Adds ICS
This commit is contained in:
parent
441715675c
commit
a79898b2e9
48 changed files with 2062 additions and 1503 deletions
|
|
@ -1,29 +1,28 @@
|
|||
import {Class} from "../types/Class";
|
||||
|
||||
export class Container {
|
||||
static instance: Container;
|
||||
|
||||
private instances: Map<string, object> = new Map();
|
||||
|
||||
public set<T extends Class>(instance: T, name: string|null = null): void
|
||||
{
|
||||
const settingName = name ?? instance.constructor.name;
|
||||
this.instances.set(settingName.toLowerCase(), instance);
|
||||
}
|
||||
|
||||
public get<T extends Class>(name: string): T
|
||||
{
|
||||
return <T>this.instances.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
static getInstance(): Container {
|
||||
if (!Container.instance) {
|
||||
Container.instance = new Container();
|
||||
}
|
||||
|
||||
return Container.instance;
|
||||
}
|
||||
public static get<T>(name: string): T {
|
||||
return Container.instance.get<T>(name);
|
||||
static instance: Container;
|
||||
|
||||
private instances: Map<string, object> = new Map();
|
||||
|
||||
public set<T extends Class>(instance: T, name: string | null = null): void {
|
||||
const settingName = name ?? instance.constructor.name;
|
||||
this.instances.set(settingName.toLowerCase(), instance);
|
||||
}
|
||||
|
||||
public get<T extends Class>(name: string): T {
|
||||
return <T>this.instances.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
static getInstance(): Container {
|
||||
if (!Container.instance) {
|
||||
Container.instance = new Container();
|
||||
}
|
||||
|
||||
return Container.instance;
|
||||
}
|
||||
|
||||
public static get<T>(name: string): T {
|
||||
return Container.instance.get<T>(name);
|
||||
}
|
||||
}
|
||||
|
|
@ -11,69 +11,77 @@ import {IconCache} from "../Icons/IconCache";
|
|||
import {EventHandler} from "../Events/EventHandler";
|
||||
import {InteractionRouter} from "../Discord/InteractionRouter";
|
||||
import Commands from "../Discord/Commands/Commands";
|
||||
import {CommandDeployer} from "../Discord/CommandDeployer";
|
||||
import {REST} from "discord.js";
|
||||
import {log} from "node:util";
|
||||
|
||||
export enum ServiceHint {
|
||||
App,
|
||||
Deploy
|
||||
App,
|
||||
Deploy
|
||||
}
|
||||
|
||||
export class Services {
|
||||
public static setup(container: Container, hint: ServiceHint) {
|
||||
const env = new Environment();
|
||||
env.setup();
|
||||
container.set<Environment>(env);
|
||||
|
||||
const logger = this.setupLogger(hint);
|
||||
container.set<Logger>(logger, 'logger');
|
||||
public static setup(container: Container, hint: ServiceHint) {
|
||||
const env = new Environment();
|
||||
env.setup();
|
||||
container.set<Environment>(env);
|
||||
|
||||
const logger = this.setupLogger(hint);
|
||||
container.set<Logger>(logger, 'logger');
|
||||
|
||||
const database = new DatabaseConnection(env.database);
|
||||
container.set<DatabaseConnection>(database);
|
||||
|
||||
const restClient = new REST();
|
||||
const commands = new Commands();
|
||||
const discordClient = new DiscordClient(
|
||||
env.discord.clientId,
|
||||
new InteractionRouter(commands, logger),
|
||||
new CommandDeployer(env.discord.clientId, restClient, commands, logger),
|
||||
logger,
|
||||
restClient
|
||||
);
|
||||
container.set<DiscordClient>(discordClient);
|
||||
|
||||
const iconCache = new IconCache(discordClient);
|
||||
container.set<IconCache>(iconCache);
|
||||
|
||||
container.set<EventHandler>(new EventHandler());
|
||||
this.setupRepositories(container);
|
||||
}
|
||||
|
||||
private static setupRepositories(container: Container) {
|
||||
const db = container.get<DatabaseConnection>(DatabaseConnection.name);
|
||||
container.set<GroupRepository>(new GroupRepository(db));
|
||||
container.set<PlaydateRepository>(new PlaydateRepository(db, container.get<GroupRepository>(GroupRepository.name)))
|
||||
container.set<GroupConfigurationRepository>(new GroupConfigurationRepository(db, container.get<GroupRepository>(GroupRepository.name)))
|
||||
}
|
||||
|
||||
private static setupLogger(hint: ServiceHint): Logger {
|
||||
|
||||
configure({
|
||||
appenders: {
|
||||
out: {type: "stdout"},
|
||||
appLogFile: {type: "file", filename: path.resolve("logs/run.log")},
|
||||
deployLogFile: {type: "file", filename: path.resolve("logs/deploy.log")},
|
||||
},
|
||||
categories: {
|
||||
default: {appenders: ['out'], level: 'debug'},
|
||||
app: {appenders: ["out", "appLogFile"], level: "debug"},
|
||||
deploy: {appenders: ["out", "deployLogFile"], level: "debug"},
|
||||
}
|
||||
})
|
||||
|
||||
let loggername = '';
|
||||
switch (hint) {
|
||||
case ServiceHint.App:
|
||||
loggername = "app";
|
||||
break;
|
||||
case ServiceHint.Deploy:
|
||||
loggername = "deploy";
|
||||
break;
|
||||
|
||||
const database = new DatabaseConnection(env.database);
|
||||
container.set<DatabaseConnection>(database);
|
||||
|
||||
const discordClient = new DiscordClient(
|
||||
env.discord.clientId,
|
||||
new InteractionRouter(new Commands(), logger)
|
||||
);
|
||||
container.set<DiscordClient>(discordClient);
|
||||
|
||||
const iconCache = new IconCache(discordClient);
|
||||
container.set<IconCache>(iconCache);
|
||||
|
||||
container.set<EventHandler>(new EventHandler());
|
||||
this.setupRepositories(container);
|
||||
}
|
||||
|
||||
private static setupRepositories(container: Container) {
|
||||
const db = container.get<DatabaseConnection>(DatabaseConnection.name);
|
||||
container.set<GroupRepository>(new GroupRepository(db));
|
||||
container.set<PlaydateRepository>(new PlaydateRepository(db, container.get<GroupRepository>(GroupRepository.name)))
|
||||
container.set<GroupConfigurationRepository>(new GroupConfigurationRepository(db, container.get<GroupRepository>(GroupRepository.name)))
|
||||
}
|
||||
|
||||
private static setupLogger(hint: ServiceHint): Logger {
|
||||
|
||||
configure({
|
||||
appenders: {
|
||||
out: { type: "stdout" },
|
||||
appLogFile: { type: "file", filename: path.resolve("logs/run.log")},
|
||||
deployLogFile: { type: "file", filename: path.resolve("logs/deploy.log")},
|
||||
},
|
||||
categories: {
|
||||
default: { appenders: ['out'], level: 'debug' },
|
||||
app: { appenders: ["out", "appLogFile"], level: "debug" },
|
||||
deploy: { appenders: ["out", "deployLogFile"], level: "debug" },
|
||||
}
|
||||
})
|
||||
|
||||
let loggername = '';
|
||||
switch (hint) {
|
||||
case ServiceHint.App:
|
||||
loggername = "app";
|
||||
break;
|
||||
case ServiceHint.Deploy:
|
||||
loggername = "deploy";
|
||||
break;
|
||||
|
||||
}
|
||||
return getLogger(loggername);
|
||||
}
|
||||
return getLogger(loggername);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue