Updated Structure

This commit is contained in:
2024-11-13 18:25:29 +01:00
parent 41a411687b
commit b4ccaf837d
25 changed files with 695 additions and 1035 deletions
+2 -1
View File
@@ -1 +1,2 @@
/node_modules
node_modules
dist
+5
View File
@@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
+14
View File
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/node_modules" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<content url="file://$MODULE_DIR$/node_modules" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="ASK" />
<option name="description" value="" />
</component>
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/DiscordAudioStreamNPM.iml" filepath="$PROJECT_DIR$/.idea/DiscordAudioStreamNPM.iml" />
</modules>
</component>
</project>
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
+3 -4
View File
@@ -1,5 +1,4 @@
/src
/node_modules
src
node_modules
tsconfig.json
tsup.config.ts
tsup.config.ts
+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)!
+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"
}
}
+15
View File
@@ -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);
}
}
+51
View File
@@ -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);
}
}
+14
View File
@@ -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;
};
+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;
};