5 Commits

Author SHA1 Message Date
Logan Cusano
cf04e37f89 Implement example .env files 2023-05-07 04:48:19 -04:00
Logan Cusano
d04cc8d5b1 Update gitignore for .env files 2023-05-07 04:43:46 -04:00
Logan Cusano
4662f37a72 Removing real .env files 2023-05-07 04:43:00 -04:00
Logan Cusano
be34c5381b Removing real .envs 2023-05-07 04:42:05 -04:00
Logan Cusano
ed79403a9b Remove config file for client, moved to .env 2023-05-07 04:40:46 -04:00
11 changed files with 144 additions and 55 deletions

2
.gitignore vendored
View File

@@ -5,4 +5,4 @@ node_modules/
# Development files
*.log
*.txt
*.env

View File

@@ -1,8 +0,0 @@
DEBUG="client:*"
TOKEN=""
# Bot Config
APPLICATION_ID=""
GUILD_ID=""
# Audio Config
AUDIO_DEVICE_ID="1"
AUDIO_DEVICE_NAME="VoiceMeeter VAIO3 Output (VB-Au"

31
Client/.env.example Normal file
View File

@@ -0,0 +1,31 @@
DEBUG="client:*"
# Bot Config
# Discord Bot Token
TOKEN=""
# Discord Bot Application ID
APPLICATION_ID=""
# Default Guild ID
GUILD_ID=""
# Audio Config
AUDIO_DEVICE_ID=""
AUDIO_DEVICE_NAME=""
# The level to open the noisegate and play audio to Discord, recommended to set to 10
AUDIO_NOISE_GATE_OPEN="10"
# Client Config
CLIENT_ID=
CLIENT_NAME=""
CLIENT_IP=""
CLIENT_PORT=3010
CLIENT_LOCATION=""
CLIENT_NEARBY_SYSTEMS=""
CLIENT_ONLINE=true
# Configuration for the connection to the server
SERVER_IP=""
SERVER_HOSTNAME=""
SERVER_PORT=3000
# Configuration of the local OP25 application
OP25_BIN_PATH=""

View File

@@ -1,23 +0,0 @@
// Core config settings for the node, these are the settings that are checked with the server
const path = require("path");
exports.clientConfig = {
"id": 13,
"name": "boilin balls in the hall",
"ip": "172.16.100.150",
"port": 3010,
"location": "the house",
"nearbySystems": ["Westchester Cty. Simulcast"],
"online": true
}
// Configuration for the connection to the server
exports.serverConfig = {
"ip": "172.16.100.108",
"hostname": "localhost",
"port": 3000
}
// Configuration of the local OP25 application
exports.radioAppConfig = {
"bin": "H:/Logan/Projects/Discord-Radio-Bot-CnC/Client/.idea/testOP25Dir/multi_rx.py"
}

View File

@@ -2,7 +2,7 @@
const { DebugBuilder } = require("../utilities/debugBuilder.js");
const log = new DebugBuilder("client", "clientController");
// Configs
const config = require("../config/clientConfig");
require('dotenv').config();
const modes = require("../config/modes");
// Modules
const { executeAsyncConsoleCommand } = require("../utilities/executeConsoleCommands.js");
@@ -10,6 +10,9 @@ const { executeAsyncConsoleCommand } = require("../utilities/executeConsoleComma
const { updateId, updateConfig } = require("../utilities/updateConfig");
const updatePreset = require("../utilities/updatePresets");
const requests = require("../utilities/httpRequests");
const { nodeObject } = require("../utilities/recordHelper.js");
var runningClientConfig = new nodeObject({_id: process.env.CLIENT_ID, _ip: process.env.CLIENT_IP, _name: process.env.CLIENT_NAME, _port: process.env.CLIENT_PORT, _location: process.env.CLIENT_LOCATION, _nearbySystems: process.env.CLIENT_NEARBY_SYSTEMS, _online: process.env.CLIENT_ONLINE});
/**
* Check the body for the required fields to update or add a preset
@@ -66,23 +69,23 @@ async function checkLocalIP() {
* Checks the config file for all required fields or gets and updates the required fields
*/
exports.checkConfig = async function checkConfig() {
if (!config.clientConfig.ip) {
if (!runningClientConfig.ip) {
const ipAddr = await checkLocalIP();
updateConfig('ip', ipAddr);
config.clientConfig.ip = ipAddr;
runningClientConfig.ip = ipAddr;
}
if(!config.clientConfig.name) {
if(!runningClientConfig.name) {
const lastOctet = await String(checkLocalIP()).spit('.')[-1];
const clientName = `Radio-Node-${lastOctet}`;
updateConfig('name', clientName);
config.clientConfig.name = clientName;
const name = `Radio-Node-${lastOctet}`;
updateConfig('name', name);
runningClientConfig.name = name;
}
if(!config.clientConfig.port) {
if(!runningClientConfig.port) {
const port = 3010;
updateConfig('port', port);
config.clientConfig.port = port;
runningClientConfig.port = port;
}
}
@@ -95,13 +98,13 @@ exports.checkIn = async () => {
let reqOptions;
await this.checkConfig();
// Check if there is an ID found, if not add the node to the server. If there was an ID, check in with the server to make sure it has the correct information
if (config.clientConfig.id === 0) {
if (clientId === 0) {
// ID was not found in the config, creating a new node
reqOptions = new requests.requestOptions("/nodes/newNode", "POST");
requests.sendHttpRequest(reqOptions, JSON.stringify(config.clientConfig), (responseObject) => {
requests.sendHttpRequest(reqOptions, JSON.stringify(), (responseObject) => {
// Update the client's ID if the server accepted it
if (responseObject.statusCode === 202) {
config.clientConfig.id = responseObject.body.nodeId;
runningClientConfig.id = responseObject.body.nodeId;
updateId(responseObject.body.nodeId);
}
});
@@ -109,7 +112,7 @@ exports.checkIn = async () => {
else {
// ID is in the config, checking in with the server
reqOptions = new requests.requestOptions("/nodes/nodeCheckIn", "POST");
requests.sendHttpRequest(reqOptions, JSON.stringify(config.clientConfig), (responseObject) => {
requests.sendHttpRequest(reqOptions, JSON.stringify(runningClientConfig), (responseObject) => {
if (responseObject.statusCode === 202) {
// Server accepted an update
}

View File

@@ -3,13 +3,14 @@ const { DebugBuilder } = require("../utilities/debugBuilder.js");
const log = new DebugBuilder("client", "radioController");
// Modules
const { resolve, dirname } = require('path');
require('dotenv').config();
const fs = require('fs');
const radioConfig = require('../config/clientConfig').radioAppConfig;
const radioConfigHelper = require("../utilities/radioConfigHelper");
const presetWrappers = require("../utilities/updatePresets");
const spawn = require('child_process').spawn;
const converter = require("convert-units");
const radioBinPath = process.env.OP25_BIN_PATH;
let radioChildProcess, tempRes, radioConfigPath;
/**
@@ -60,7 +61,7 @@ exports.openRadioSession = () => {
* Get the location of the 'multi_rx.py' binary from the config
*/
function getRadioBinPath(){
return resolve(radioConfig.bin);
return resolve(radioBinPath);
}
/**

View File

@@ -2,16 +2,18 @@
const { DebugBuilder } = require("../utilities/debugBuilder.js");
const log = new DebugBuilder("client", "httpRequests");
// Config
const config = require("../config/clientConfig");
require('dotenv').config();
// Modules
const http = require("http");
var runningClientConfig = new nodeObject({_id: process.env.CLIENT_ID, _ip: process.env.CLIENT_IP, _name: process.env.CLIENT_NAME, _port: process.env.CLIENT_PORT, _location: process.env.CLIENT_LOCATION, _nearbySystems: process.env.CLIENT_NEARBY_SYSTEMS, _online: process.env.CLIENT_ONLINE});
exports.requestOptions = class requestOptions {
constructor(path, method, hostname = undefined, headers = undefined, port = undefined) {
if (method === "POST"){
this.hostname = hostname ?? config.serverConfig.hostname
this.hostname = hostname ?? runningClientConfig.hostname
this.path = path
this.port = port ?? config.serverConfig.port
this.port = port ?? runningClientConfig.port
this.method = method
this.headers = headers ?? {
'Content-Type': 'application/json',

View File

@@ -0,0 +1,26 @@
/**
*
*/
class nodeObject {
/**
*
* @param {*} param0._id The ID of the node
* @param {*} param0._name The name of the node
* @param {*} param0._ip The IP that the master can contact the node at
* @param {*} param0._port The port that the client is listening on
* @param {*} param0._location The physical location of the node
* @param {*} param0._online An integer representation of the online status of the bot, ie 0=off, 1=on
* @param {*} param0._nearbySystems An object array of nearby systems
*/
constructor({ _id = null, _name = null, _ip = null, _port = null, _location = null, _nearbySystems = null, _online = null }) {
this.id = _id;
this.name = _name;
this.ip = _ip;
this.port = _port;
this.location = _location;
this.nearbySystems = _nearbySystems;
this.online = _online;
}
}
exports.nodeObject = nodeObject;

View File

@@ -6,12 +6,12 @@ const replace = require('replace-in-file');
class Options {
constructor(key, updatedValue) {
this.files = "./config/clientConfig.js";
this.files = "./.env";
// A regex of the line containing the key in the config file
this.from = new RegExp(`"${key}": (.+),`, "g");
this.from = new RegExp(`${key}="(.+)",`, "g");
// Check to see if the value is a string and needs to be wrapped in double quotes
if (typeof updatedValue === "string") this.to = `"${key}": "${updatedValue}",`;
else this.to = `"${key}": ${updatedValue},`;
if (Array(["string", "number"]).includes(typeof updatedValue)) this.to = `${key}="${updatedValue}",`;
else this.to = `${key}=${updatedValue},`;
}
}

View File

@@ -1 +0,0 @@
DEBUG="server:*";

58
Server/.env.example Normal file
View File

@@ -0,0 +1,58 @@
# Discord Bot Configs
# Bot Token
TOKEN=""
# Client ID
clientId=""
# Prefix (deprecated)
PREFIX="^"
# ID of the Group than Can Admin The Bot
BOT_ADMINS=""
# Default Voice Channel to Join if None are Specified
DEFAULT_VOICE_CHANNEL_ID=""
# HTTP Server Config (DRB_CNC)
# HTTP Port to listen on
HTTP_PORT=3000
# MySQL Config for Emmelia
# Core DB Info and Login
EM_DB_HOST=""
EM_DB_USER=""
EM_DB_PASS=""
EM_DB_NAME=""
# Names of DB Tables
DB_RSS_FEEDS_TABLE="RSSFeeds"
DB_RSS_POSTS_TABLE="RSSPosts"
DB_ACCOUNTS_TABLE="accounts"
DB_TRANSACTIONS_TABLE="transactions"
DB_PRICING_TABLE="pricing"
# MySQL Config for Node Control
NODE_DB_HOST=''
NODE_DB_USER=''
NODE_DB_PASS=''
NODE_DB_NAME=''
# Node Config
# Time betwen check ins with the nodes
NODE_MONITOR_REFRESH_INTERVAL=100000
# RSS Config
# Interval between refreshes
RSS_REFRESH_INTERVAL=3000000
# OpenAI Config
# OpenAI Organization ID
OPENAI_ORG=""
# OpenAI API Key
OPENAI_KEY=""
# Stable Diffusion (Stability AI) Config
# API KEY
STABILITY_API_KEY=""
# General Config
# Exit when the program encounters and error (this may be ignored in some instances, and the error will exit the program either way)
EXIT_ON_ERROR=false
# Delay the exit of the program for X miliseconds, this can be used if you want to see what happens just after the error occurs or see if something else errors
EXIT_ON_ERROR_DELAY=0