Skip to content

Commit

Permalink
Refactoring all projet
Browse files Browse the repository at this point in the history
Objectifs de la PR :
- Retirer toute les classes du projet pour plus être orienté vers de la programmation fonctionnelle
- Créer un système d'auto-loading beaucoup plus propre avec des fichiers séparer les uns des autres
- Utilisation d'arrows functions a la place de regulars functions
- Nouvelle convention de nommage des fichiers *(kebab-case, fonctionnalité du fichier défini en `file.functionnalité.ts`, export barrel pour les choses pas auto load)*

Pour l'instant les exports sont un peu défini de manière magique, mais dans le futur cette PR viendra fix ça :  microsoft/TypeScript#38511
  • Loading branch information
Unarray committed Feb 25, 2023
1 parent ba87524 commit 90f79c3
Show file tree
Hide file tree
Showing 45 changed files with 270 additions and 1,919 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"name": "royaume-discord-bot",
"displayName": "Royaume-Discord-Bot",
"version": "2.6.0",
"main": "build/src/Client.js",
"scripts": {
"dev": "node --watch -r @swc-node/register -r tsconfig-paths/register ./src/Client.ts dev",
"dev": "npx nodemon --exec node -r @swc-node/register -r tsconfig-paths/register ./src/client.ts dev",
"start": "node -r @swc-node/register -r tsconfig-paths/register ./src/Client.ts",
"lint": "eslint ./src",
"lint:fix": "eslint ./src --fix",
Expand All @@ -28,7 +30,8 @@
"eslint": "^8.32.0",
"graphql": "^16.6.0",
"tsconfig-paths": "^4.1.2",
"typescript": "^4.9.4"
"typescript": "^4.9.4",
"nodemon": "^2.0.20"
},
"eslintConfig": {
"extends": "@bluzzi",
Expand Down
92 changes: 36 additions & 56 deletions src/Client.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,42 @@
import { Client as DiscordClient, GatewayIntentBits, Guild, Partials, Team, User } from "discord.js";
import EventManager from "$core/events/EventManager";
import CommandManager from "$core/commands/CommandManager";
import TaskManager from "$core/tasks/TaskManager";
import Logger, { logCrown } from "$core/utils/Logger";
import { guildId } from "$resources/config/information.json";
import { version } from "../package.json";
import { version, displayName } from "../package.json";
import { getStringEnv } from "./utils/EnvVariable";

export default class Client extends DiscordClient {

public static instance: Client;

// Events and commands managers :
public readonly eventManager: EventManager;

public readonly commandManager: CommandManager;

public readonly taskManager: TaskManager;

constructor() {
super({
intents: [
GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildIntegrations, GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildBans
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction]
});

// Create bot instance and login it :
Client.instance = this;
this.login(getStringEnv("BOT_TOKEN"));

// Load events, commands and tasks managers :
this.eventManager = new EventManager();
this.commandManager = new CommandManager();
this.taskManager = new TaskManager();
}

public async getGuild() : Promise<Guild> {
return await this.guilds.fetch(guildId);
}

public getDevTeam() : User[] | null {
const owner = this.application?.owner;

if (owner instanceof User) {
return [owner];
} else if (owner instanceof Team) {
return owner.members.map(teamMember => teamMember.user);
} else {
return null;
}
import { guildId } from "$resources/config/information.json";
import { listener, load, register } from "$core/utils/command";

export const client = new DiscordClient({
intents: [
GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildIntegrations, GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildModeration, GatewayIntentBits.GuildMessages
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction]
});

export const getGuild = async(): Promise<Guild> => {
return await client.guilds.fetch(guildId);
};

export const getDevTeam = (): User[] | null => {
const owner = client.application?.owner;

if (owner instanceof User) {
return [owner];
} else if (owner instanceof Team) {
return owner.members.map(teamMember => teamMember.user);
} else {
return null;
}
};

}
(async() => {
logCrown();
Logger.info(`Sarting ${displayName} v${version}...`);
await client.login(getStringEnv("BOT_TOKEN"));

logCrown();
Logger.info(`Sarting Royaume-Discord-Bot V${version}...`);
new Client();
await load(`${__dirname}\\commands`);
listener(client);
await register(client);
})();
19 changes: 0 additions & 19 deletions src/commands/Command.ts

This file was deleted.

53 changes: 0 additions & 53 deletions src/commands/CommandManager.ts

This file was deleted.

177 changes: 0 additions & 177 deletions src/commands/list/Birthday.ts

This file was deleted.

Loading

0 comments on commit 90f79c3

Please sign in to comment.