Add files via upload

This commit is contained in:
2024-05-04 16:29:27 +02:00
committed by GitHub
parent dec33f4e2a
commit 5a341a3281
12 changed files with 150 additions and 72 deletions
+3 -4
View File
@@ -35,9 +35,8 @@ Audio.StreamStart({
imvci: 0, //Voice Channel ID e.g. interaction.member.voice.channel.id
igi: 0, //Guild ID e.g. interaction.guild.id
igv: 0, //Bot Voice Adapter e.g. interaction.guild.voiceAdapterCreator
type: "Link", //Choose the Stream resource - File or Link
StreamFile: "", //Link to File e.g. ../assets/Stream.mp3
StreamLink: "" //Link to Audio Stream e.g. YouTube Video or LautFM Stream Link
type: "", //Choose the Stream resource - File or Link or Analyze
Resource: "", //Link to File e.g. ../assets/Stream.mp3 or Link to Audio Stream e.g. YouTube Video or LautFM Stream Link
})
```
@@ -52,4 +51,4 @@ Audio.StreamStart({
## 🤝 Enjoy the package?
Give it a star ⭐ on github!
Give it a star ⭐ on github or [donate](https://buymeacoffee.com/fraujuliannn) a hot chocolate!
+2 -3
View File
@@ -3,14 +3,13 @@ type StartProps = {
igi: number;
igv: number;
type: string;
StreamFile?: string;
StreamLink?: string;
Resource: string;
};
type StopProps = {
igi: number;
};
declare function StreamStart({ imvci, igi, igv, type, StreamFile, StreamLink }: StartProps): void;
declare function StreamStart({ imvci, igi, igv, type, Resource, }: StartProps): void;
declare function StreamStop({ igi, }: StopProps): void;
+2 -3
View File
@@ -3,14 +3,13 @@ type StartProps = {
igi: number;
igv: number;
type: string;
StreamFile?: string;
StreamLink?: string;
Resource: string;
};
type StopProps = {
igi: number;
};
declare function StreamStart({ imvci, igi, igv, type, StreamFile, StreamLink }: StartProps): void;
declare function StreamStart({ imvci, igi, igv, type, Resource, }: StartProps): void;
declare function StreamStop({ igi, }: StopProps): void;
+41 -19
View File
@@ -1,7 +1,9 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
@@ -38,34 +48,46 @@ function ERROR() {
}
// src/functions/start.ts
var import_fs = __toESM(require("fs"));
var import_node_path = require("path");
var { joinVoiceChannel, createAudioPlayer, createAudioResource } = require("@discordjs/voice");
var { join } = require("path");
function StreamStart({
imvci,
igi,
igv,
type,
StreamFile,
StreamLink
Resource
}) {
try {
let FileResource2 = function() {
let Audio = createAudioResource((0, import_node_path.join)(__dirname, Resource), { inlineVolume: true });
AudioPlayer.play(Audio);
joinVoiceChannel({
channelId: imvci,
guildId: igi,
adapterCreator: igv
}).subscribe(AudioPlayer);
}, LinkResource2 = function() {
let Audio = createAudioResource(Resource);
AudioPlayer.play(Audio);
joinVoiceChannel({
channelId: imvci,
guildId: igi,
adapterCreator: igv
}).subscribe(AudioPlayer);
};
var FileResource = FileResource2, LinkResource = LinkResource2;
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));
AudioPlayer.play(Audio);
joinVoiceChannel({
channelId: imvci,
guildId: igi,
adapterCreator: igv
}).subscribe(AudioPlayer);
if (type === "Link") {
LinkResource2();
} else if (type === "File") {
FileResource2();
} else if (type === "Analyze") {
if (import_fs.default.existsSync(Resource)) {
FileResource2();
} else {
LinkResource2();
}
} else {
ERROR();
}
+31 -19
View File
@@ -26,34 +26,46 @@ function ERROR() {
}
// src/functions/start.ts
import fs from "fs";
import { join } from "node:path";
var { joinVoiceChannel, createAudioPlayer, createAudioResource } = __require("@discordjs/voice");
var { join } = __require("node:path");
function StreamStart({
imvci,
igi,
igv,
type,
StreamFile,
StreamLink
Resource
}) {
try {
let FileResource2 = function() {
let Audio = createAudioResource(join(__dirname, Resource), { inlineVolume: true });
AudioPlayer.play(Audio);
joinVoiceChannel({
channelId: imvci,
guildId: igi,
adapterCreator: igv
}).subscribe(AudioPlayer);
}, LinkResource2 = function() {
let Audio = createAudioResource(Resource);
AudioPlayer.play(Audio);
joinVoiceChannel({
channelId: imvci,
guildId: igi,
adapterCreator: igv
}).subscribe(AudioPlayer);
};
var FileResource = FileResource2, LinkResource = LinkResource2;
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));
AudioPlayer.play(Audio);
joinVoiceChannel({
channelId: imvci,
guildId: igi,
adapterCreator: igv
}).subscribe(AudioPlayer);
if (type === "Link") {
LinkResource2();
} else if (type === "File") {
FileResource2();
} else if (type === "Analyze") {
if (fs.existsSync(Resource)) {
FileResource2();
} else {
LinkResource2();
}
} else {
ERROR();
}
+22 -2
View File
@@ -1,17 +1,19 @@
{
"name": "discord-audio-stream",
"version": "0.0.2",
"version": "0.0.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "discord-audio-stream",
"version": "0.0.2",
"version": "0.0.3",
"license": "BSD-3-Clause",
"dependencies": {
"@discordjs/voice": "^0.16.1",
"discord.js": "^14.14.1",
"ffmpeg": "^0.0.4",
"ffmpeg-static": "^5.2.0",
"fs": "^0.0.1-security",
"libsodium-wrappers": "^0.7.13",
"opusscript": "^0.0.8"
},
@@ -1313,6 +1315,14 @@
"reusify": "^1.0.4"
}
},
"node_modules/ffmpeg": {
"version": "0.0.4",
"resolved": "https://registry.npmjs.org/ffmpeg/-/ffmpeg-0.0.4.tgz",
"integrity": "sha512-3TgWUJJlZGQn+crJFyhsO/oNeRRnGTy6GhgS98oUCIfZrOW5haPPV7DUfOm3xJcHr5q3TJpjk2GudPutrNisRA==",
"dependencies": {
"when": ">= 0.0.1"
}
},
"node_modules/ffmpeg-static": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/ffmpeg-static/-/ffmpeg-static-5.2.0.tgz",
@@ -1368,6 +1378,11 @@
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/fs": {
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
},
"node_modules/fsevents": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
@@ -2422,6 +2437,11 @@
"webidl-conversions": "^4.0.2"
}
},
"node_modules/when": {
"version": "3.7.8",
"resolved": "https://registry.npmjs.org/when/-/when-3.7.8.tgz",
"integrity": "sha512-5cZ7mecD3eYcMiCH4wtRPA5iFJZ50BJYDfckI5RRpQiktMiYTcn0ccLTZOvcbBume+1304fQztxeNzNS9Gvrnw=="
},
"node_modules/which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
+2
View File
@@ -30,7 +30,9 @@
"dependencies": {
"@discordjs/voice": "^0.16.1",
"discord.js": "^14.14.1",
"ffmpeg": "^0.0.4",
"ffmpeg-static": "^5.2.0",
"fs": "^0.0.1-security",
"libsodium-wrappers": "^0.7.13",
"opusscript": "^0.0.8"
}
+38 -18
View File
@@ -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(" ");
+4 -2
View File
@@ -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
View File
@@ -1,2 +1,3 @@
//Export Start and Stop Function
export * from "./functions/start";
export * from "./functions/stop";
+1
View File
@@ -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
View File
@@ -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;
};