changed Project Stucture - Part1
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
import {JsonDatabaseServices} from "../InternalServices/DatabaseServices/JsonDatabaseServices";
|
||||
import {MySqlDatabaseServices} from "../InternalServices/DatabaseServices/MySqlDatabaseServices";
|
||||
|
||||
export class Constants {
|
||||
public static DatabaseServices: JsonDatabaseServices | MySqlDatabaseServices | null = null;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import {JsonDatabaseServices} from "../../InternalServices/DatabaseServices/JsonDatabaseServices";
|
||||
import {MySqlDatabaseServices} from "../../InternalServices/DatabaseServices/MySqlDatabaseServices";
|
||||
import {Constants} from "../../Core/Contants";
|
||||
|
||||
export class AudioStreamManager {
|
||||
constructor(
|
||||
databaseType: "Json" | "MySql",
|
||||
databaseOptions: {
|
||||
Host: string;
|
||||
Port: number;
|
||||
Username: string;
|
||||
Password: string;
|
||||
Database: string;
|
||||
} | string) {
|
||||
|
||||
if (databaseType === "MySql" &&
|
||||
databaseOptions &&
|
||||
typeof databaseOptions === "object") {
|
||||
console.log("mysql passed")
|
||||
Constants.DatabaseServices = new MySqlDatabaseServices(databaseOptions);
|
||||
} else if (databaseType === "Json" &&
|
||||
databaseOptions &&
|
||||
typeof databaseOptions === "string") {
|
||||
console.log("json passed")
|
||||
Constants.DatabaseServices = new JsonDatabaseServices(databaseOptions);
|
||||
} else {
|
||||
console.log("err passed")
|
||||
throw new Error("Failed validating database.")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import {DiscordGatewayAdapterCreator, getVoiceConnection, joinVoiceChannel, VoiceConnection} from "@discordjs/voice";
|
||||
import {IConnectionManager} from "./IConnectionManager";
|
||||
import {Constants} from "../../Core/Contants";
|
||||
|
||||
class ConnectionManager implements IConnectionManager {
|
||||
constructor() {
|
||||
if (Constants.DatabaseServices === null) throw Error("Database services were not initialized.");
|
||||
}
|
||||
|
||||
CreateConnection(connectionData: {
|
||||
VoiceChannelId: number;
|
||||
GuildId: number;
|
||||
VoiceAdapter: DiscordGatewayAdapterCreator;
|
||||
}): VoiceConnection {
|
||||
return joinVoiceChannel({
|
||||
channelId: connectionData.VoiceChannelId.toString(),
|
||||
guildId: connectionData.GuildId.toString(),
|
||||
adapterCreator: connectionData.VoiceAdapter
|
||||
})
|
||||
}
|
||||
|
||||
PlayAudioOnConnection(audioData: {
|
||||
ResourceType: "Link" | "File";
|
||||
Resource: string;
|
||||
}, guildId: bigint): VoiceConnection {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
ConnectAndPlayAudio(connectionData: { VoiceChannelId: number; GuildId: number; VoiceAdapter: DiscordGatewayAdapterCreator; }, audioData: {
|
||||
ResourceType: "Link" | "File";
|
||||
Resource: string;
|
||||
}): VoiceConnection {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
StopAudioOnConnection(guildId: bigint): VoiceConnection {
|
||||
let voiceConnection = getVoiceConnection(guildId.toString());
|
||||
if (!voiceConnection) throw new Error("Voice connection were not found.");
|
||||
|
||||
//TODO: MAKE STOP AUDIO WITHOUT DESTROYING CONNECTION
|
||||
|
||||
return voiceConnection;
|
||||
}
|
||||
|
||||
DestroyConnection(guildId: bigint): void {
|
||||
let voiceConnection = getVoiceConnection(guildId.toString());
|
||||
if (!voiceConnection) throw new Error("Voice connection were not found.");
|
||||
|
||||
voiceConnection.destroy();
|
||||
}
|
||||
|
||||
SetMaxListeners(maxListeners: number, guildId: bigint): VoiceConnection {
|
||||
let voiceConnection = getVoiceConnection(guildId.toString());
|
||||
if (!voiceConnection) throw new Error("Voice connection were not found.");
|
||||
|
||||
voiceConnection.setMaxListeners(maxListeners);
|
||||
|
||||
return voiceConnection;
|
||||
}
|
||||
|
||||
SetVolume(volume: number, guildId: bigint): VoiceConnection {
|
||||
if (volume < 0 || volume > 100) throw new Error("Volume must be between 0 and 100.");
|
||||
|
||||
let voiceConnection = getVoiceConnection(guildId.toString());
|
||||
if (!voiceConnection) throw new Error("Voice connection were not found.");
|
||||
|
||||
//TODO: MAKE VOLUME WORK
|
||||
|
||||
return voiceConnection;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import {DiscordGatewayAdapterCreator, getVoiceConnection, joinVoiceChannel, VoiceConnection} from "@discordjs/voice";
|
||||
|
||||
export interface IConnectionManager {
|
||||
CreateConnection(connectionData: {
|
||||
VoiceChannelId: number;
|
||||
GuildId: number;
|
||||
VoiceAdapter: DiscordGatewayAdapterCreator;
|
||||
}): VoiceConnection;
|
||||
|
||||
SetVolume(volume: number, guildId: bigint): VoiceConnection;
|
||||
|
||||
SetMaxListeners(maxListeners: number, guildId: bigint): VoiceConnection;
|
||||
|
||||
DestroyConnection(guildId: bigint): void;
|
||||
|
||||
StopAudioOnConnection(guildId: bigint): VoiceConnection;
|
||||
|
||||
ConnectAndPlayAudio(connectionData: {
|
||||
VoiceChannelId: number;
|
||||
GuildId: number;
|
||||
VoiceAdapter: DiscordGatewayAdapterCreator;
|
||||
}, audioData: {
|
||||
ResourceType: "Link" | "File";
|
||||
Resource: string;
|
||||
}): VoiceConnection;
|
||||
|
||||
PlayAudioOnConnection(audioData: {
|
||||
ResourceType: "Link" | "File";
|
||||
Resource: string;
|
||||
}, guildId: bigint): VoiceConnection;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface IDatabaseServices {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import {IDatabaseServices} from "./IDatabaseServices";
|
||||
|
||||
export class JsonDatabaseServices implements IDatabaseServices {
|
||||
constructor(databaseOptions : string) {
|
||||
// IMPLEMENT DATABASE
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import {IDatabaseServices} from "./IDatabaseServices";
|
||||
|
||||
export class MySqlDatabaseServices implements IDatabaseServices {
|
||||
|
||||
constructor(databaseOptions: {
|
||||
Host: string;
|
||||
Port: number;
|
||||
Username: string;
|
||||
Password: string;
|
||||
Database: string;
|
||||
}) {
|
||||
//IMPLEMENT DATABASE
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
const {joinVoiceChannel, createAudioPlayer, createAudioResource} = require("@discordjs/voice");
|
||||
const {
|
||||
joinVoiceChannel, createAudioPlayer, createAudioResource} = require("@discordjs/voice");
|
||||
const {join} = require("node:path");
|
||||
|
||||
import {startMethodOptions} from "../Utils/Options/StartMethodOptions";
|
||||
|
||||
+1
-3
@@ -1,3 +1 @@
|
||||
export * from "./Methods/StartMethod";
|
||||
export * from "./Methods/StopMethod";
|
||||
export * from "./Methods/MaxListenerMethod";
|
||||
export { AudioStreamManager } from "./ExternalServices/AudioStreamManager/AudioStreamManager";
|
||||
Reference in New Issue
Block a user