Add files via upload
This commit is contained in:
+38
-18
@@ -1,34 +1,26 @@
|
||||
import { StartProps } from "../stuff/types";
|
||||
import { ERROR } from "../stuff/error";
|
||||
import fs from "fs";
|
||||
import { join } from "node:path";
|
||||
import { AudioPlayer } from "@discordjs/voice";
|
||||
|
||||
const { joinVoiceChannel, createAudioPlayer, createAudioResource } = require("@discordjs/voice");
|
||||
const { join } = require('node:path');
|
||||
|
||||
export function StreamStart({
|
||||
imvci,
|
||||
igi,
|
||||
igv,
|
||||
type,
|
||||
StreamFile,
|
||||
StreamLink
|
||||
Resource,
|
||||
}: StartProps) {
|
||||
try {
|
||||
//Create AudioPlayer variable.
|
||||
const AudioPlayer = createAudioPlayer();
|
||||
|
||||
if (type === "File") {
|
||||
|
||||
let Audio = createAudioResource(StreamLink);
|
||||
AudioPlayer.play(Audio);
|
||||
|
||||
joinVoiceChannel({
|
||||
channelId: imvci,
|
||||
guildId: igi,
|
||||
adapterCreator: igv
|
||||
}).subscribe(AudioPlayer)
|
||||
|
||||
} else if (type === "Link") {
|
||||
|
||||
const Audio = createAudioResource(join(__dirname, StreamFile));
|
||||
//File Resource
|
||||
function FileResource() {
|
||||
|
||||
let Audio = createAudioResource(join(__dirname, Resource), { inlineVolume: true });
|
||||
AudioPlayer.play(Audio);
|
||||
|
||||
joinVoiceChannel({
|
||||
@@ -36,11 +28,39 @@ export function StreamStart({
|
||||
guildId: igi,
|
||||
adapterCreator: igv
|
||||
}).subscribe(AudioPlayer);
|
||||
|
||||
}
|
||||
|
||||
//Link Resource
|
||||
function LinkResource() {
|
||||
let Audio = createAudioResource(Resource);
|
||||
AudioPlayer.play(Audio);
|
||||
|
||||
joinVoiceChannel({
|
||||
channelId: imvci,
|
||||
guildId: igi,
|
||||
adapterCreator: igv
|
||||
}).subscribe(AudioPlayer)
|
||||
}
|
||||
|
||||
//If the type is "Link".
|
||||
if (type === "Link") {
|
||||
LinkResource();
|
||||
//If the type is "File".
|
||||
} else if (type === "File") {
|
||||
FileResource();
|
||||
//If the type is "Analyze".
|
||||
} else if (type === "Analyze") {
|
||||
if (fs.existsSync(Resource)) { //Check if Resource is a file and exist.
|
||||
FileResource();
|
||||
} else { //If Resoure is not a file or doesn't exist.
|
||||
LinkResource();
|
||||
}
|
||||
} else {
|
||||
//If no valid value is specified.
|
||||
ERROR();
|
||||
}
|
||||
} catch (error) {
|
||||
//If syntax is wrong.
|
||||
ERROR();
|
||||
console.log("ERR:\n" + error);
|
||||
console.log(" ");
|
||||
|
||||
@@ -7,9 +7,11 @@ export function StreamStop({
|
||||
igi,
|
||||
}: StopProps) {
|
||||
try {
|
||||
|
||||
//Get connection from interaction guild.
|
||||
const connection = getVoiceConnection(igi);
|
||||
connection.disconnect();
|
||||
|
||||
//Destroy connection from interaction guild.
|
||||
connection.destroy();
|
||||
|
||||
} catch (error) {
|
||||
ERROR();
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
//Export Start and Stop Function
|
||||
export * from "./functions/start";
|
||||
export * from "./functions/stop";
|
||||
@@ -1,3 +1,4 @@
|
||||
//ERROR Message
|
||||
export function ERROR() {
|
||||
console.log(" ");
|
||||
console.log(" ______ _____ _____ ____ _____ \r\n | ____| __ \\| __ \\ \/ __ \\| __ \\ \r\n | |__ | |__) | |__) | | | | |__) |\r\n | __| | _ \/| _ \/| | | | _ \/ \r\n | |____| | \\ \\| | \\ \\| |__| | | \\ \\ \r\n |______|_| \\_\\_| \\_\\\\____\/|_| \\_\\");
|
||||
|
||||
+3
-2
@@ -1,12 +1,13 @@
|
||||
//Variables to use start function.
|
||||
export type StartProps = {
|
||||
imvci: number;
|
||||
igi: number;
|
||||
igv: number;
|
||||
type: string;
|
||||
StreamFile?: string;
|
||||
StreamLink?: string;
|
||||
Resource: string;
|
||||
};
|
||||
|
||||
//Variables to use stop function.
|
||||
export type StopProps = {
|
||||
igi: number;
|
||||
};
|
||||
Reference in New Issue
Block a user