Add files via upload

This commit is contained in:
2024-07-07 18:48:34 +02:00
committed by GitHub
parent 4ea7a9bf86
commit 5220bf4af4
18 changed files with 3101 additions and 0 deletions
+86
View File
@@ -0,0 +1,86 @@
const { joinVoiceChannel, createAudioPlayer, createAudioResource } = require("@discordjs/voice");
import { ERR, startParameters } from "../managers/UtilityManager";
import { join } from "node:path";
export function start({
imvci,
igi,
igv,
type,
Resource,
}: startParameters) {
try {
const AudioPlayer = createAudioPlayer();
function streamFile(FILE: string) {
let Audio = createAudioResource(join(__dirname, FILE), { inlineVolume: true });
AudioPlayer.play(Audio);
joinVoiceChannel({
channelId: imvci,
guildId: igi,
adapterCreator: igv
}).subscribe(AudioPlayer);
}
function streamLink(URL: string) {
let Audio = createAudioResource(URL);
AudioPlayer.play(Audio);
joinVoiceChannel({
channelId: imvci,
guildId: igi,
adapterCreator: igv
}).subscribe(AudioPlayer)
}
function LinkValidation(URL: string) {
var URLPattern = new RegExp('^(https?:\\/\\/)?'+
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|'+
'((\\d{1,3}\\.){3}\\d{1,3}))'+
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+
'(\\?[;&a-z\\d%_.~+=-]*)?'+
'(\\#[-a-z\\d_]*)?$','i');
return URLPattern.test(URL);
}
function FileValidation(FILE: string) {
var FILEPattern = new RegExp("^(.+)\/([^\/]+)$");
return FILEPattern.test(FILE);
}
switch (type) {
case "Link":
if(LinkValidation(Resource) === true && FileValidation(Resource) === false) {
streamLink(Resource);
} else {
ERR();
}
break;
case "File":
if(LinkValidation(Resource) === false && FileValidation(Resource) === true) {
streamFile(Resource);
} else {
ERR();
}
break;
case "Analyze":
if(LinkValidation(Resource) === true && FileValidation(Resource) === false) {
streamLink(Resource);
} else if(LinkValidation(Resource) === false && FileValidation(Resource) === true) {
streamFile(Resource)
} else {
ERR();
}
break;
default:
ERR();
break;
}
} catch (err) {
ERR(err);
}
};
+14
View File
@@ -0,0 +1,14 @@
const { getVoiceConnection } = require("@discordjs/voice");
import { ERR, stopParameter } from "../managers/UtilityManager";
export function stop({
igi,
}: stopParameter) {
try {
const connection = getVoiceConnection(igi);
connection.destroy();
} catch (err) {
ERR();
}
};
+1
View File
@@ -0,0 +1 @@
export * from "./managers/FuncManager";
+2
View File
@@ -0,0 +1,2 @@
export * from "../functions/startFunc";
export * from "../functions/stopFunc";
+3
View File
@@ -0,0 +1,3 @@
export * from "../utility/errorFunc";
export * from "../utility/startParameters";
export * from "../utility/stopParameter";
+13
View File
@@ -0,0 +1,13 @@
export function ERR(err?: unknown) {
console.error(" ")
console.error(" ______ _____ _____ ____ _____ \r\n | ____| __ \\| __ \\ \/ __ \\| __ \\ \r\n | |__ | |__) | |__) | | | | |__) |\r\n | __| | _ \/| _ \/| | | | _ \/ \r\n | |____| | \\ \\| | \\ \\| |__| | | \\ \\ \r\n |______|_| \\_\\_| \\_\\\\____\/|_| \\_\\")
console.error(" ")
console.error("This error comes from the discord-audio-stream package!")
console.error("This error occurs if you are not using the package correctly, sometimes it can also be bugs in the package.")
console.error(" ")
console.error("See the docs or open a issue post on github.")
console.error(" ")
if (err) {
console.error(err)
}
}
+7
View File
@@ -0,0 +1,7 @@
export type startParameters = {
imvci: number;
igi: number;
igv: number;
type: string;
Resource: string;
};
+3
View File
@@ -0,0 +1,3 @@
export type stopParameter = {
igi: number;
};