This commit is contained in:
Michel Fedde 2025-06-18 22:53:54 +02:00
parent 441715675c
commit a79898b2e9
48 changed files with 2062 additions and 1503 deletions

View file

@ -1,67 +1,77 @@
import {
Client,
GatewayIntentBits,
Events,
ActivityType, REST
Client,
GatewayIntentBits,
Events,
ActivityType, REST
} from "discord.js";
import Commands from "./Commands/Commands";
import {Container} from "../Container/Container";
import {Logger} from "log4js";
import {InteractionRouter} from "./InteractionRouter";
import {CommandDeployer} from "./CommandDeployer";
export class DiscordClient {
private readonly client: Client;
private readonly client: Client;
public get Client(): Client {
return this.client;
}
public get Client(): Client {
return this.client;
}
public get Commands(): Commands {
return this.router.commands
}
public get Commands(): Commands {
return this.router.commands
}
public get RESTClient(): REST {
return this.restClient;
}
public get RESTClient(): REST {
return this.restClient;
}
public get ApplicationId(): string {
return this.applicationId;
}
public get ApplicationId(): string {
return this.applicationId;
}
constructor(
private readonly applicationId: string,
private readonly router: InteractionRouter,
private readonly restClient: REST = new REST()
) {
this.client = new Client({
intents: [GatewayIntentBits.Guilds]
})
}
constructor(
private readonly applicationId: string,
private readonly router: InteractionRouter,
private readonly deployer: CommandDeployer,
private readonly logger: Logger,
private readonly restClient: REST = new REST()
) {
this.client = new Client({
intents: [GatewayIntentBits.Guilds]
})
}
applyEvents() {
this.client.once(Events.ClientReady, () => {
if (!this.client.user) {
return;
}
applyEvents() {
this.client.once(Events.ClientReady, () => {
if (!this.client.user) {
return;
}
Container.get<Logger>("logger").info(`Ready! Logged in as ${this.client.user.tag}`);
this.client.user.setActivity('your PnP playdates', {
type: ActivityType.Watching,
});
})
this.logger.info(`Ready! Logged in as ${this.client.user.tag}`);
this.client.user.setActivity('your PnP playdates', {
type: ActivityType.Watching,
});
})
this.client.on(Events.GuildAvailable, () => {
Container.get<Logger>("logger").info("Joined Guild?")
})
this.client.on(Events.GuildCreate, (guild) => {
this.logger.info(`Joined ${guild.name}`);
this.deployer.deployServer(guild.id);
})
this.client.on(Events.GuildDelete, (guild) => {
this.logger.info(`Left ${guild.name}`);
})
this.client.on(Events.GuildAvailable, (guild) => {
this.deployer.deployServer(guild.id);
})
this.client.on(Events.InteractionCreate, this.router.route.bind(this.router));
}
this.client.on(Events.InteractionCreate, this.router.route.bind(this.router));
}
connect(token: string) {
this.client.login(token);
}
connect(token: string) {
this.client.login(token);
}
connectRESTClient(token: string) {
this.restClient.setToken(token);
}
connectRESTClient(token: string) {
this.restClient.setToken(token);
}
}