Updated Structure
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
const { getVoiceConnection } = require("@discordjs/voice");
|
||||
|
||||
import {maxListenerMethodOptions} from "../Utils/Options/MaxListenerMethodOptions";
|
||||
|
||||
export function setMaxAudioListeners({
|
||||
GuildID,
|
||||
MaxListeners
|
||||
}: maxListenerMethodOptions) {
|
||||
try {
|
||||
let audioConnection = getVoiceConnection(GuildID);
|
||||
audioConnection.setMaxListeners(MaxListeners);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
const { joinVoiceChannel, createAudioPlayer, createAudioResource } = require("@discordjs/voice");
|
||||
const { join } = require("node:path");
|
||||
|
||||
import {startMethodOptions} from "../Utils/Options/StartMethodOptions";
|
||||
|
||||
export function startAudio({
|
||||
VoiceChannelID,
|
||||
GuildID,
|
||||
VoiceAdapter,
|
||||
ResourceType,
|
||||
Resource
|
||||
}: startMethodOptions) {
|
||||
try {
|
||||
const AudioPlayer = createAudioPlayer();
|
||||
|
||||
function streamFile(file: string) {
|
||||
let audioResource = createAudioResource(join(__dirname, file), { inlineVolume: true });
|
||||
AudioPlayer.play(audioResource);
|
||||
|
||||
joinVoiceChannel({
|
||||
channelId: VoiceChannelID,
|
||||
guildId: GuildID,
|
||||
adapterCreator: VoiceAdapter
|
||||
}).subscribe(AudioPlayer);
|
||||
}
|
||||
|
||||
function streamLink(link: string) {
|
||||
let audioResource = createAudioResource(link);
|
||||
AudioPlayer.play(audioResource);
|
||||
|
||||
joinVoiceChannel({
|
||||
channelId: VoiceChannelID,
|
||||
guildId: GuildID,
|
||||
adapterCreator: VoiceAdapter
|
||||
}).subscribe(AudioPlayer)
|
||||
}
|
||||
|
||||
switch (ResourceType) {
|
||||
case "Link":
|
||||
streamLink(Resource);
|
||||
break;
|
||||
case "File":
|
||||
streamFile(Resource);
|
||||
break;
|
||||
default:
|
||||
throw new TypeError("Audio type isn't valid.");
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
const { getVoiceConnection } = require("@discordjs/voice");
|
||||
|
||||
import {stopMethodOptions} from "../Utils/Options/StopMethodOptions";
|
||||
|
||||
export function stopAudio({
|
||||
GuildID
|
||||
}: stopMethodOptions) {
|
||||
try {
|
||||
let audioConnection = getVoiceConnection(GuildID);
|
||||
audioConnection.destroy();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
export type maxListenerParameter = {
|
||||
GuildID: number;
|
||||
MaxListeners: number;
|
||||
export type maxListenerMethodOptions = {
|
||||
GuildID: number;
|
||||
MaxListeners: number;
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
export type startParameters = {
|
||||
export type startMethodOptions = {
|
||||
VoiceChannelID: number;
|
||||
GuildID: number;
|
||||
VoiceAdapter: number;
|
||||
Type: string;
|
||||
ResourceType: "Link" | "File";
|
||||
Resource: string;
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
export type stopMethodOptions = {
|
||||
GuildID: number;
|
||||
};
|
||||
@@ -1,14 +0,0 @@
|
||||
const { getVoiceConnection } = require("@discordjs/voice");
|
||||
import { ERR, maxListenerParameter } from "../managers/UtilityManager";
|
||||
|
||||
export function setMaxListeners({
|
||||
GuildID,
|
||||
MaxListeners,
|
||||
}: maxListenerParameter) {
|
||||
try {
|
||||
const connection = getVoiceConnection(GuildID);
|
||||
connection.setMaxListeners(MaxListeners);
|
||||
} catch (err) {
|
||||
ERR(err);
|
||||
}
|
||||
};
|
||||
@@ -1,78 +0,0 @@
|
||||
const { joinVoiceChannel, createAudioPlayer, createAudioResource } = require("@discordjs/voice");
|
||||
import { ERR, startParameters } from "../managers/UtilityManager";
|
||||
|
||||
import { join } from "node:path";
|
||||
|
||||
export function start({
|
||||
VoiceChannelID,
|
||||
GuildID,
|
||||
VoiceAdapter,
|
||||
Type,
|
||||
Resource,
|
||||
}: startParameters) {
|
||||
try {
|
||||
const AudioPlayer = createAudioPlayer();
|
||||
|
||||
function streamFile(FILE: string) {
|
||||
let Audio = createAudioResource(join(__dirname, FILE), { inlineVolume: true });
|
||||
AudioPlayer.play(Audio);
|
||||
|
||||
joinVoiceChannel({
|
||||
channelId: VoiceChannelID,
|
||||
guildId: GuildID,
|
||||
adapterCreator: VoiceAdapter
|
||||
}).subscribe(AudioPlayer);
|
||||
}
|
||||
|
||||
function streamLink(URL: string) {
|
||||
let Audio = createAudioResource(URL);
|
||||
AudioPlayer.play(Audio);
|
||||
|
||||
joinVoiceChannel({
|
||||
channelId: VoiceChannelID,
|
||||
guildId: GuildID,
|
||||
adapterCreator: VoiceAdapter
|
||||
}).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":
|
||||
streamLink(Resource);
|
||||
break;
|
||||
case "File":
|
||||
streamFile(Resource);
|
||||
break;
|
||||
case "Analyze":
|
||||
if (LinkValidation(Resource)) {
|
||||
streamLink(Resource);
|
||||
} else if (FileValidation(Resource)) {
|
||||
streamFile(Resource)
|
||||
} else {
|
||||
ERR();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ERR();
|
||||
break;
|
||||
}
|
||||
} catch (err) {
|
||||
ERR(err);
|
||||
}
|
||||
};
|
||||
@@ -1,13 +0,0 @@
|
||||
const { getVoiceConnection } = require("@discordjs/voice");
|
||||
import { ERR, stopParameter } from "../managers/UtilityManager";
|
||||
|
||||
export function stop({
|
||||
GuildID,
|
||||
}: stopParameter) {
|
||||
try {
|
||||
const connection = getVoiceConnection(GuildID);
|
||||
connection.destroy();
|
||||
} catch (err) {
|
||||
ERR(err);
|
||||
}
|
||||
};
|
||||
+3
-1
@@ -1 +1,3 @@
|
||||
export * from "./managers/FuncManager";
|
||||
export * from "./Methods/StartMethod";
|
||||
export * from "./Methods/StopMethod";
|
||||
export * from "./Methods/MaxListenerMethod";
|
||||
@@ -1,3 +0,0 @@
|
||||
export * from "../functions/startFunc";
|
||||
export * from "../functions/stopFunc";
|
||||
export * from "../functions/maxListenersFunc";
|
||||
@@ -1,4 +0,0 @@
|
||||
export * from "../utility/errorFunc";
|
||||
export * from "../utility/startParameters";
|
||||
export * from "../utility/stopParameter";
|
||||
export * from "../utility/maxListenerParameter";
|
||||
@@ -1,13 +0,0 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export type stopParameter = {
|
||||
GuildID: number;
|
||||
};
|
||||
Reference in New Issue
Block a user