chore: merge dev to main #172

Merged
Anri merged 11 commits from dev into main 2024-09-18 18:25:04 +02:00
2 changed files with 16 additions and 11 deletions
Showing only changes of commit b316734511 - Show all commits

View file

@ -1,6 +1,7 @@
import { Player, PlayerEvents, useMainPlayer } from "discord-player";
import { Client } from "discord.js";
import { readdir } from "fs/promises";
import { splitFilenameExtensions } from "../utils/misc";
/** Load all the events */
export default async (client: Client) => {
@ -20,13 +21,10 @@ export default async (client: Client) => {
);
// Remove extension
// TODO: use utils functions
const event_type_ext = event_file.split(".");
const ext = event_type_ext.pop();
const { file: event_type, ext } = splitFilenameExtensions(event_file);
if (!(ext === "js" || ext === "ts")) {
throw `Unknown file in ${event_category}: ${event_file}`;
}
const event_type = event_type_ext.join(".");
if (event_category == "player") {
const player = useMainPlayer() as Player;

View file

@ -28,16 +28,25 @@ export const getFilename = (path: string) => {
return removeExtension(filename_with_ext);
};
/**
* Split a filename and his extension
* @param filename string of the filename
* @returns Object with filename and extension splitted
*/
export const splitFilenameExtensions = (filename: string) => {
const array = filename.split(".");
const ext = array.pop();
return { file: array.join("."), ext };
};
/**
* Remove extension from a filename
* @param filename string of the filename with an extension
* @returns string of the filename without an extension
*/
export const removeExtension = (filename: string) => {
const array = filename.split(".");
array.pop();
return array.join(".");
return splitFilenameExtensions(filename).file;
};
/**
@ -46,9 +55,7 @@ export const removeExtension = (filename: string) => {
* @returns string of the extension if it exists
*/
export const getExtension = (filename: string) => {
const array = filename.split(".");
return array.pop();
return splitFilenameExtensions(filename).ext;
};
/**