mirror of
https://github.com/Myxelium/RandomMemerBot.git
synced 2026-04-17 04:15:52 +00:00
Larger refactoring and added avoidlist
This commit is contained in:
18
helpers/generate-file-name.ts
Normal file
18
helpers/generate-file-name.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Formats a name into a file name with random generated value at the end.
|
||||
* @param name - The name to generate a file name for.
|
||||
* @returns string - The generated file name.
|
||||
*/
|
||||
export function generateFileName(name: string): string {
|
||||
const randomHex = [...Array(3)].map(() => Math.floor(Math.random() * 16).toString(16)).join('');
|
||||
|
||||
const formattedName = name
|
||||
.replace(/\(.*?\)|\[.*?\]/g, '')
|
||||
.split(' ')
|
||||
.filter(word => /^[a-zA-Z0-9]/.test(word))
|
||||
.join(' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.replace('.mp3', '');
|
||||
|
||||
return `${formattedName}-${randomHex}.mp3`;
|
||||
}
|
||||
Reference in New Issue
Block a user