Merge pull request #3 from FrauJulian/v0.4.0

V0.4.0
This commit is contained in:
2024-11-16 16:07:46 +01:00
committed by GitHub
25 changed files with 646 additions and 1371 deletions
+3 -1
View File
@@ -1 +1,3 @@
/node_modules
.idea
node_modules
dist
+5 -4
View File
@@ -1,5 +1,6 @@
/src
/node_modules
.idea
node_modules
dist
src
tsconfig.json
tsup.config.ts
tsup.config.ts
-31
View File
@@ -1,31 +0,0 @@
Copyright © 2024 Julian Lechner. All rights reserved.
1) License Grant
Permission is hereby granted to any person obtaining a copy of this software and associated documentation files (the "Software") to view and test the Software solely for personal, non-commercial purposes. No other rights are granted, and the following activities are expressly prohibited:
- Copying or reproducing the Software in any form, except for personal viewing.
- Modifying, merging, or creating derivative works based on the Software.
- Distributing, redistributing, sublicensing, or publishing the Software in any form.
- Selling, reselling, or otherwise profiting from the Software.
2) Termination
This license is automatically terminated if you violate any of the terms. Upon termination, you must immediately cease all use of the Software and destroy any copies in your possession.
3) Legal Compliance
Any use of the Software that violates the terms of this license may result in legal action, including but not limited to, civil and criminal penalties under applicable law.
4) No Warranty
The Software is provided "as is," without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the copyright holder(s) be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the Software or the use or other dealings in the Software.
For any inquiries regarding permissions, please contact:
Julian Lechner
Ulmenstraße 9
3380 Pöchlarn
E-Mail: fraujulian@lechner.top
Phone: +43 660 9254001
Please send any abuse to the following e-mail address:
abuse@fraujulian.xyz
By using or accessing this repository, you acknowledge that you have read, understood, and agree to be bound by the terms of this License Agreement.
+58
View File
@@ -0,0 +1,58 @@
# License Agreement
**Copyright © 2024 Julian Lechner. All rights reserved.**
## 1. Grant of License
Subject to the terms and conditions of this Agreement, the Licensor hereby grants the Licensee a limited, non-exclusive, non-transferable, revocable license to access, view, and test the Software solely for personal, non-commercial purposes. **No other rights are granted.** The following actions are **strictly prohibited**:
- **Copying, reproducing, or replicating** the Software, in whole or in part, except for personal viewing.
- **Modifying, merging, adapting, translating, or creating derivative works** based on the Software.
- **Distributing, redistributing, transmitting, sublicensing, leasing, renting, or publishing** the Software in any form.
- **Selling, reselling, or otherwise exploiting** the Software for any commercial purpose.
## 2. Termination
This License Agreement is effective until terminated. This license will **automatically terminate without notice** if you fail to comply with any provision of this Agreement. Upon termination, you must immediately cease all use of the Software and destroy all copies, full or partial, in your possession or control.
## 3. Legal Compliance and Enforcement
Unauthorized use of the Software constitutes a violation of intellectual property laws and may result in **severe civil and criminal penalties**. The Licensor reserves the right to seek all remedies available at law and in equity for violations of this Agreement.
## 4. Disclaimer of Warranties
The Software is provided **"AS IS"**, without warranty of any kind, express or implied, including but not limited to the warranties of **merchantability**, **fitness for a particular purpose**, and **non-infringement**. The Licensor does not warrant that the Software will meet your requirements or that its operation will be uninterrupted or error-free.
## 5. Limitation of Liability
In no event shall the Licensor be liable for any **direct, indirect, incidental, special, consequential, or punitive damages**, including but not limited to loss of profits, data, or use, incurred by you or any third party, whether in an action in contract or tort, arising from your access to, or use of, the Software.
## 6. Indemnification
You agree to **indemnify, defend, and hold harmless** the Licensor from and against any and all claims, liabilities, damages, losses, or expenses (including legal fees and costs) arising out of or in any way connected with your violation of this Agreement or use of the Software.
## 7. Governing Law and Jurisdiction
This Agreement shall be governed by and construed in accordance with the laws of **Austria**, without regard to its conflict of law principles. Any legal action or proceeding arising under this Agreement will be brought exclusively in the courts located in **Austria**, and you hereby irrevocably consent to personal jurisdiction and venue therein.
## 8. Entire Agreement
This Agreement constitutes the **entire understanding** between you and the Licensor regarding the Software and supersedes all prior agreements, whether written or oral.
---
For any inquiries regarding permissions, please contact:
**Julian Lechner**
Ulmenstraße 9
3380 Pöchlarn
Email: [fraujulian@lechner.top](mailto:fraujulian@lechner.top)
Phone: +43 660 9254001
Please report any abuse to the following email address:
[abuse@fraujulian.xyz](mailto:abuse@fraujulian.xyz)
---
**By accessing or using this Software, you acknowledge that you have read, understood, and agree to be bound by the terms and conditions of this License Agreement.**
+66 -64
View File
@@ -1,64 +1,66 @@
# Discord Audio Stream
[![npm](https://img.shields.io/npm/dw/discord-audio-stream)](http://npmjs.org/package/discord-audio-stream)
![GitHub package.json version](https://img.shields.io/github/package-json/v/FrauJulian/discord-audio-stream)
![GitHub Repo stars](https://img.shields.io/github/stars/FrauJulian/discord-audio-stream?style=social)
<p>This NPM package was created to make it easier to stream audio to Discord.</p>
<p>There is a security feature of discord that stops the stream of audio after some time. This problem can be solved by disconnecting the Discord channel every 1.5 hours for 2 seconds and then reconnecting the channel. (If you use this package!) I recommend using a database to store the data e.g. MySQL, SQLite, json file and other database types.</p>
<p>The package does not fix this error yet. However, it is currently being worked on!</p>
**This module is designed to work with [discord.js](https://discord.js.org/#/) v14. This package doesn't support older versions!**
## 👋 Support
Pease create a bug post on github or write [`fraujulian`](https://discord.com/users/860206216893693973) on discord!
## 📝 Usage
### Install package
```bash
npm i discord-audio-stream
```
or
```bash
yarn add discord-audio-stream
```
### Code Snippet - Start
```js
const AudioStream = require("discord-audio-stream");
AudioStream.start({
VoiceChannelID: 0, //Integer | Voice Channel ID | e.g interaction.member.voice.channel.id
GuildID: 0, //Integer | Guild ID | e.g interaction.guild.id
VoiceAdapter: 0, //Integer | Voice Adapter Creator | e.g interaction.guild.voiceAdapterCreator
Type: "", //String | choose the Audio Resource [File or Link or Analyze] | Analyze
Resource: "", //String | Audio Stream Link or File Location | e.g https://synradiode.stream.laut.fm/synradiode
})
```
### Code Snippet - Stop
```js
const AudioStream = require("discord-audio-stream");
AudioStream.stop({
GuildID: 0, //Integer | Guild ID | e.g interaction.guild.id
})
```
### Code Snippet - Set Max Listeners
```js
const AudioStream = require("discord-audio-stream");
AudioStream.setMaxListeners({
GuildID: 0, //Integer | Guild ID | e.g interaction.guild.id
MaxListeners: 0, //Integer | max Listeners | e.g 30
})
```
## 🤝 Enjoy the package?
Give it a star ⭐ on [github](https://github.com/FrauJulian/discord-audio-stream) or [buy](https://buymeacoffee.com/fraujuliannn) a hot chocolate!
# Discord Audio Stream
[![npm](https://img.shields.io/npm/dw/discord-audio-stream)](http://npmjs.org/package/discord-audio-stream)
![GitHub package.json version](https://img.shields.io/github/package-json/v/FrauJulian/discord-audio-stream)
![GitHub Repo stars](https://img.shields.io/github/stars/FrauJulian/discord-audio-stream?style=social)
<p>This NPM package was created to make it easier to stream audio to Discord.</p>
<p>There is a security feature of discord that stops the stream of audio after some time. This problem can be solved by disconnecting the Discord channel every 1.5 hours for 2 seconds and then reconnecting the channel. (If you use this package!) I recommend using a database to store the data e.g. MySQL, SQLite, json file and other database types.</p>
<p>The package does not fix this error yet. However, it is currently being worked on!</p>
**This module is designed to work with [discord.js](https://discord.js.org/) v14. This package doesn't support older
versions!**
## 👋 Support
Please create an [issue](https://github.com/FrauJulian/DiscordAudioStreamNPM/issues) on github or write [`fraujulian`](https://discord.com/users/860206216893693973) on discord!
## 📝 Usage
### Install package
```bash
npm i discord-audio-stream
```
### Code Snippet - Start
```js
const AudioStream = require("discord-audio-stream");
AudioStream.startAudio({
VoiceChannelID: 0, //Integer | voice channel id | e.g. interaction.member.voice.channel.id
GuildID: 0, //Integer | guild id | e.g. interaction.guild.id
VoiceAdapter: 0, //Integer | aoice adapter creator | e.g. interaction.guild.voiceAdapterCreator
Type: "", //String | choose the Audio Resource | File or Link
Resource: "", //String | audio stream link or file location | e.g. https://synradiode.stream.laut.fm/synradiode
})
```
### Code Snippet - Stop
```js
const AudioStream = require("discord-audio-stream");
AudioStream.stopAudio({
GuildID: 0, //Integer | guild id | e.g. interaction.guild.id
})
```
### Code Snippet - Set Max Listeners
```js
const AudioStream = require("discord-audio-stream");
AudioStream.setMaxAudioListeners({
GuildID: 0, //Integer | guild id | e.g. interaction.guild.id
MaxListeners: 0, //Integer | max Listeners | e.g. 30
})
```
## 📋 Credits:
~ [**FrauJulian**](https://fraujulian.xyz/).
## 🤝 Enjoy the package?
Give it a star ⭐ on [github](https://github.com/FrauJulian/discord-audio-stream)!
-24
View File
@@ -1,24 +0,0 @@
type startParameters = {
VoiceChannelID: number;
GuildID: number;
VoiceAdapter: number;
Type: string;
Resource: string;
};
type stopParameter = {
GuildID: number;
};
type maxListenerParameter = {
GuildID: number;
MaxListeners: number;
};
declare function start({ VoiceChannelID, GuildID, VoiceAdapter, Type, Resource, }: startParameters): void;
declare function stop({ GuildID, }: stopParameter): void;
declare function setMaxListeners({ GuildID, MaxListeners, }: maxListenerParameter): void;
export { setMaxListeners, start, stop };
-24
View File
@@ -1,24 +0,0 @@
type startParameters = {
VoiceChannelID: number;
GuildID: number;
VoiceAdapter: number;
Type: string;
Resource: string;
};
type stopParameter = {
GuildID: number;
};
type maxListenerParameter = {
GuildID: number;
MaxListeners: number;
};
declare function start({ VoiceChannelID, GuildID, VoiceAdapter, Type, Resource, }: startParameters): void;
declare function stop({ GuildID, }: stopParameter): void;
declare function setMaxListeners({ GuildID, MaxListeners, }: maxListenerParameter): void;
export { setMaxListeners, start, stop };
-136
View File
@@ -1,136 +0,0 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
setMaxListeners: () => setMaxListeners,
start: () => start,
stop: () => stop
});
module.exports = __toCommonJS(src_exports);
// src/utility/errorFunc.ts
function ERR(err) {
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);
}
}
// src/functions/startFunc.ts
var import_node_path = require("path");
var { joinVoiceChannel, createAudioPlayer, createAudioResource } = require("@discordjs/voice");
function start({
VoiceChannelID,
GuildID,
VoiceAdapter,
Type,
Resource
}) {
try {
let streamFile2 = function(FILE) {
let Audio = createAudioResource((0, import_node_path.join)(__dirname, FILE), { inlineVolume: true });
AudioPlayer.play(Audio);
joinVoiceChannel({
channelId: VoiceChannelID,
guildId: GuildID,
adapterCreator: VoiceAdapter
}).subscribe(AudioPlayer);
}, streamLink2 = function(URL) {
let Audio = createAudioResource(URL);
AudioPlayer.play(Audio);
joinVoiceChannel({
channelId: VoiceChannelID,
guildId: GuildID,
adapterCreator: VoiceAdapter
}).subscribe(AudioPlayer);
}, LinkValidation2 = function(URL) {
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);
}, FileValidation2 = function(FILE) {
var FILEPattern = new RegExp("^(.+)/([^/]+)$");
return FILEPattern.test(FILE);
};
var streamFile = streamFile2, streamLink = streamLink2, LinkValidation = LinkValidation2, FileValidation = FileValidation2;
const AudioPlayer = createAudioPlayer();
switch (Type) {
case "Link":
streamLink2(Resource);
break;
case "File":
streamFile2(Resource);
break;
case "Analyze":
if (LinkValidation2(Resource)) {
streamLink2(Resource);
} else if (FileValidation2(Resource)) {
streamFile2(Resource);
} else {
ERR();
}
break;
default:
ERR();
break;
}
} catch (err) {
ERR(err);
}
}
// src/functions/stopFunc.ts
var { getVoiceConnection } = require("@discordjs/voice");
function stop({
GuildID
}) {
try {
const connection = getVoiceConnection(GuildID);
connection.destroy();
} catch (err) {
ERR(err);
}
}
// src/functions/maxListenersFunc.ts
var { getVoiceConnection: getVoiceConnection2 } = require("@discordjs/voice");
function setMaxListeners({
GuildID,
MaxListeners
}) {
try {
const connection = getVoiceConnection2(GuildID);
connection.setMaxListeners(MaxListeners);
} catch (err) {
ERR(err);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
setMaxListeners,
start,
stop
});
-121
View File
@@ -1,121 +0,0 @@
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined") return require.apply(this, arguments);
throw Error('Dynamic require of "' + x + '" is not supported');
});
// node_modules/tsup/assets/esm_shims.js
import { fileURLToPath } from "url";
import path from "path";
var getFilename = () => fileURLToPath(import.meta.url);
var getDirname = () => path.dirname(getFilename());
var __dirname = /* @__PURE__ */ getDirname();
// src/utility/errorFunc.ts
function ERR(err) {
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);
}
}
// src/functions/startFunc.ts
import { join } from "node:path";
var { joinVoiceChannel, createAudioPlayer, createAudioResource } = __require("@discordjs/voice");
function start({
VoiceChannelID,
GuildID,
VoiceAdapter,
Type,
Resource
}) {
try {
let streamFile2 = function(FILE) {
let Audio = createAudioResource(join(__dirname, FILE), { inlineVolume: true });
AudioPlayer.play(Audio);
joinVoiceChannel({
channelId: VoiceChannelID,
guildId: GuildID,
adapterCreator: VoiceAdapter
}).subscribe(AudioPlayer);
}, streamLink2 = function(URL) {
let Audio = createAudioResource(URL);
AudioPlayer.play(Audio);
joinVoiceChannel({
channelId: VoiceChannelID,
guildId: GuildID,
adapterCreator: VoiceAdapter
}).subscribe(AudioPlayer);
}, LinkValidation2 = function(URL) {
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);
}, FileValidation2 = function(FILE) {
var FILEPattern = new RegExp("^(.+)/([^/]+)$");
return FILEPattern.test(FILE);
};
var streamFile = streamFile2, streamLink = streamLink2, LinkValidation = LinkValidation2, FileValidation = FileValidation2;
const AudioPlayer = createAudioPlayer();
switch (Type) {
case "Link":
streamLink2(Resource);
break;
case "File":
streamFile2(Resource);
break;
case "Analyze":
if (LinkValidation2(Resource)) {
streamLink2(Resource);
} else if (FileValidation2(Resource)) {
streamFile2(Resource);
} else {
ERR();
}
break;
default:
ERR();
break;
}
} catch (err) {
ERR(err);
}
}
// src/functions/stopFunc.ts
var { getVoiceConnection } = __require("@discordjs/voice");
function stop({
GuildID
}) {
try {
const connection = getVoiceConnection(GuildID);
connection.destroy();
} catch (err) {
ERR(err);
}
}
// src/functions/maxListenersFunc.ts
var { getVoiceConnection: getVoiceConnection2 } = __require("@discordjs/voice");
function setMaxListeners({
GuildID,
MaxListeners
}) {
try {
const connection = getVoiceConnection2(GuildID);
connection.setMaxListeners(MaxListeners);
} catch (err) {
ERR(err);
}
}
export {
setMaxListeners,
start,
stop
};
+395 -792
View File
File diff suppressed because it is too large Load Diff
+40 -40
View File
@@ -1,40 +1,40 @@
{
"name": "discord-audio-stream",
"version": "0.3.2",
"description": "🖼️ NPM Package to stream any audio link on discord.",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsup"
},
"repository": {
"type": "git",
"url": "git+https://github.com/FrauJulian/discord-audio-stream.git"
},
"keywords": [
"discordjs-v14",
"stream",
"audio",
"music"
],
"author": "FrauJulian | Julian Lechner",
"license": "BSD-3-Clause",
"bugs": {
"url": "https://github.com/FrauJulian/discord-audio-stream/issues"
},
"homepage": "https://github.com/FrauJulian/discord-audio-stream#readme",
"devDependencies": {
"@types/ejs": "^3.1.5",
"@types/node": "^20.12.8",
"tsup": "^8.0.2",
"typescript": "^5.4.5"
},
"dependencies": {
"@discordjs/voice": "^0.16.1",
"ffmpeg-static": "^5.2.0",
"fs": "^0.0.1-security",
"libsodium-wrappers": "^0.7.13",
"opusscript": "^0.0.8"
}
}
{
"name": "discord-audio-stream",
"version": "0.4.0",
"description": "Node libary to make discord audio streaming easier.",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsup"
},
"repository": {
"type": "git",
"url": "git+https://github.com/FrauJulian/DiscordAudioStreamNPM.git"
},
"keywords": [
"discordjs-v14",
"stream",
"audio",
"music"
],
"author": "FrauJulian | Julian Lechner",
"license": "CUSTOM-LICENSE",
"bugs": {
"url": "https://github.com/FrauJulian/DiscordAudioStreamNPM/issues"
},
"homepage": "https://github.com/FrauJulian/DiscordAudioStreamNPM#readme",
"devDependencies": {
"@types/ejs": "^3.1.5",
"@types/node": "^20.12.8",
"tsup": "^8.0.2",
"typescript": "^5.4.5"
},
"dependencies": {
"@discordjs/voice": "^0.16.1",
"ffmpeg-static": "^5.2.0",
"fs": "^0.0.1-security",
"libsodium-wrappers": "^0.7.13",
"opusscript": "^0.0.8"
}
}
+11
View File
@@ -0,0 +1,11 @@
const {getVoiceConnection} = require("@discordjs/voice");
import {maxListenerMethodOptions} from "../Utils/Options/MaxListenerMethodOptions";
export function setMaxAudioListeners({
GuildID,
MaxListeners
}: maxListenerMethodOptions) {
let audioConnection = getVoiceConnection(GuildID);
audioConnection.setMaxListeners(MaxListeners);
}
+47
View File
@@ -0,0 +1,47 @@
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) {
let 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("Invalid audio type");
}
}
+10
View File
@@ -0,0 +1,10 @@
const {getVoiceConnection} = require("@discordjs/voice");
import {stopMethodOptions} from "../Utils/Options/StopMethodOptions";
export function stopAudio({
GuildID
}: stopMethodOptions) {
let audioConnection = getVoiceConnection(GuildID);
audioConnection.destroy();
}
@@ -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;
};
+3
View File
@@ -0,0 +1,3 @@
export type stopMethodOptions = {
GuildID: number;
};
-14
View File
@@ -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);
}
};
-78
View File
@@ -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);
}
};
-13
View File
@@ -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
View File
@@ -1 +1,3 @@
export * from "./managers/FuncManager";
export * from "./Methods/StartMethod";
export * from "./Methods/StopMethod";
export * from "./Methods/MaxListenerMethod";
-3
View File
@@ -1,3 +0,0 @@
export * from "../functions/startFunc";
export * from "../functions/stopFunc";
export * from "../functions/maxListenersFunc";
-4
View File
@@ -1,4 +0,0 @@
export * from "../utility/errorFunc";
export * from "../utility/startParameters";
export * from "../utility/stopParameter";
export * from "../utility/maxListenerParameter";
-13
View File
@@ -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)
}
}
-3
View File
@@ -1,3 +0,0 @@
export type stopParameter = {
GuildID: number;
};