Functioning audio bot
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import { readFileSync } from 'fs';
|
||||
// Debug
|
||||
import debugBuilder from "./debugBuilder.js";
|
||||
const log = new debugBuilder("bot", "configHandler");
|
||||
|
||||
export function getConfig() {
|
||||
return JSON.parse(readFileSync("./config/botConfig.json"));
|
||||
@@ -6,31 +9,40 @@ export function getConfig() {
|
||||
|
||||
export function getTOKEN() {
|
||||
const parsedJSON = getConfig();
|
||||
return parsedJSON.TOKEN;
|
||||
const token = parsedJSON.TOKEN;
|
||||
|
||||
log.DEBUG("Discord API Token: ", token)
|
||||
return token;
|
||||
}
|
||||
|
||||
export function getGuildID() {
|
||||
const parsedJSON = getConfig();
|
||||
parsedJSON.GuildID = BigInt(parsedJSON.GuildID);
|
||||
//console.log("Guild ID: ", parsedJSON.GuildID);
|
||||
return parsedJSON.GuildID;
|
||||
const guildID = BigInt(parsedJSON.GuildID);
|
||||
|
||||
log.DEBUG("Guild ID: ", guildID);
|
||||
return guildID;
|
||||
}
|
||||
|
||||
export function getApplicationID() {
|
||||
const parsedJSON = getConfig();
|
||||
parsedJSON.ApplicationID = BigInt(parsedJSON.ApplicationID);
|
||||
//console.log("Application ID: ", parsedJSON.ApplicationID);
|
||||
return parsedJSON.ApplicationID;
|
||||
const appID = BigInt(parsedJSON.ApplicationID);
|
||||
|
||||
log.DEBUG("Application ID: ", appID);
|
||||
return appID;
|
||||
}
|
||||
|
||||
export function getDeviceID(){
|
||||
const parsedJSON = getConfig();
|
||||
//console.log("Device ID: ", parseInt(parsedJSON.DeviceID));
|
||||
return parseInt(parsedJSON.DeviceID);
|
||||
const deviceID = parseInt(parsedJSON.DeviceID);
|
||||
|
||||
log.DEBUG("Device ID: ", deviceID);
|
||||
return deviceID;
|
||||
}
|
||||
|
||||
export function getDeviceName(){
|
||||
const parsedJSON = getConfig();
|
||||
//console.log("Device Name: ", parseInt(parsedJSON.DeviceName));
|
||||
return parsedJSON.DeviceName;
|
||||
const deviceName = parsedJSON.DeviceName;
|
||||
|
||||
log.DEBUG("Device Name: ", deviceName);
|
||||
return deviceName;
|
||||
}
|
||||
17
Client/discord-bot/utilities/debugBuilder.js
Normal file
17
Client/discord-bot/utilities/debugBuilder.js
Normal file
@@ -0,0 +1,17 @@
|
||||
// Debug
|
||||
import Debug from 'debug';
|
||||
|
||||
export default class debugBuilder {
|
||||
/**
|
||||
* Create the different logging methods for a function
|
||||
* Namespace template = ("[app]:[fileName]:['INFO', 'WARNING', 'DEBUG', 'ERROR']")
|
||||
* @param {string} appName The name of the app to be used in the 'app' portion of the namespace
|
||||
* @param {string} fileName The name of the file calling the builder to be used in the 'fileName' portion of the namespace
|
||||
*/
|
||||
constructor(appName, fileName) {
|
||||
this.INFO = Debug(`${appName}:${fileName}:INFO`);
|
||||
this.DEBUG = Debug(`${appName}:${fileName}:DEBUG`);
|
||||
this.WARN = Debug(`${appName}:${fileName}:WARNING`);
|
||||
this.ERROR = Debug(`${appName}:${fileName}::ERROR`);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
// Debug
|
||||
import debugBuilder from "./debugBuilder.js";
|
||||
const log = new debugBuilder("bot", "messageHandler");
|
||||
|
||||
export function replyToInteraction(interaction, message){
|
||||
interaction.reply({ content: message, fetchReply: true })
|
||||
.then((message) => console.log(`Reply sent with content ${message.content}`))
|
||||
.catch(console.error);
|
||||
.then((message) => log.DEBUG(`Reply sent with content ${message.content}`))
|
||||
.catch((err) => log.ERROR(err));
|
||||
}
|
||||
@@ -2,6 +2,9 @@ import {SlashCommandBuilder} from "@discordjs/builders";
|
||||
import {REST} from "@discordjs/rest";
|
||||
import {getApplicationID, getGuildID, getTOKEN} from "./configHandler.js";
|
||||
import { Routes, ChannelType } from "discord.js";
|
||||
// Debug
|
||||
import debugBuilder from "./debugBuilder.js";
|
||||
const log = new debugBuilder("bot", "registerCommands");
|
||||
|
||||
const pingCommand = new SlashCommandBuilder()
|
||||
.setName("ping")
|
||||
@@ -38,8 +41,9 @@ export default async function registerCommands(callback){
|
||||
await rest.put(Routes.applicationGuildCommands(clientID, guildID), {
|
||||
body: commands,
|
||||
});
|
||||
log.DEBUG("Successfully registered the following commands: ", commands)
|
||||
callback();
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
log.ERROR(err);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user