Skip to content

Commit

Permalink
[FEAT] Dashboard + Fixes (#317)
Browse files Browse the repository at this point in the history
* Implement installer web interface, add privacy policy, terms and conditions

* Copy and update config file with payloads sent from the installer.
  • Loading branch information
earnestangel authored Jan 31, 2024
1 parent f03591e commit bbecbc0
Show file tree
Hide file tree
Showing 52 changed files with 10,380 additions and 108 deletions.
16 changes: 11 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#.env file will take over the config.js file. This file is useful for deployments

# Set the port and ip address for the web server and installer
PORT=3000
IP_ADDRESS="localhost" # Use 0.0.0.0 to listen on all interfaces, or localhost to listen on local interface only
DOMAIN_NAME="" # Leave blank if you don't have a domain name

# Language of the bot
LANGUAGE="en"

Expand All @@ -24,13 +29,14 @@ MONGODB_ACCESS_URI=
DEBUG_LEVEL=
LOG_DIR=

# Default 3000
PORT=

# Genius API token for lyrics. GENIUS_ENABLED option true = enable, false = disable
GENIUS_TOKEN=
GENIUS_ENABLED=true

# Only use this if you're having problems with Genius. LYRIST_ENABLED option true = enable, false = disable
# Only use this if you're having problems with Genius. LYRIST_URL: http://yourserver.com:3000/api (no ending slash)
# LYRIST_ENABLED option true = enable, false = disable
LYRIST_URL=
LYRIST_ENABLED=false
LYRIST_ENABLED=false

# Replicate.com API Token. Get it from https://replicate.com/account
REPLICATE_TOKEN=
10 changes: 5 additions & 5 deletions config.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ module.exports = {
Prefix: "!",

// Discord bot token. Under the Bot tab. Please prefer setting this in the .env file instead of here
Token: "",
DiscordToken: "",

// The discord bot client ID under the General Information tab. Please prefer setting this in the .env file instead of here
ID: "",
DiscordBotID: "",

// Discord user IDs for permissions and ownerships
Users: {
Expand Down Expand Up @@ -71,7 +71,7 @@ module.exports = {
Provider: "OpenAIProvider",

// Provider Token
Token: "",
AIToken: "",

// Must be one of: davinci or gpt35.
GPTModel: "gpt35",
Expand Down Expand Up @@ -126,10 +126,10 @@ module.exports = {
// -------------------------------------------- Twitch Announcer -----------------------------------------------------
TWITCH: {
// Your twitch client ID,get it here: https://dev.twitch.tv/console/apps/create
clientId: "",
TwitchClientId: "",

//
clientSecret: "",
TwitchClientSecret: "",
},

// ------------------------------------------------ welcomer --------------------------------------------------------
Expand Down
143 changes: 70 additions & 73 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,47 @@
require("dotenv").config({path: ".env"});
let fs = require("fs");
require("dotenv").config({ path: ".env" });
const fs = require("fs");
const colors = require("colors");
const {Worker} = require("worker_threads");
const { Worker } = require("worker_threads");

// will be "development" or "production" depending on your config, falls back to "development"
const NODE_ENV = process.env.NODE_ENV || "development";

// Set the build directory. If this directory is missing or empty, do `npm run build`
const buildDir = "./dist";
const logDirectory = "./logs";
const cli = require(`./${buildDir}/ririkoCli`);

const configFileExists = fs.existsSync("./config.js");

// Create the log directory if not exists
let logDirectory = "./logs";
if (!fs.existsSync(logDirectory)) {
fs.mkdirSync(logDirectory);
function createLogDirectory() {
if (!fs.existsSync(logDirectory)) {
fs.mkdirSync(logDirectory);
}
}

const {overrideLoggers} = require(`${buildDir}/helpers/logger`);
const { overrideLoggers } = require(`${buildDir}/helpers/logger`);
overrideLoggers();

// Handle errors
process.on("unhandledRejection", async (err, promise) => {
function handleUnhandledRejection(err, promise) {
console.error(`[ANTI-CRASH] Unhandled Rejection: ${err}`.red);
console.error(promise);
});
}

process.on("uncaughtException", (err) => {
function handleUncaughtException(err) {
console.error(`Uncaught Exception: ${err.message}`);
console.error(err);
});

// Start the bot and web server here
(async () => {
const cli = require(`./${buildDir}/ririkoCli`);

const {Worker} = require("worker_threads");

// Function 1
function function1() {
console.log("Function 1 is running");
// Add your function logic here
}

// Function 2
function function2() {
console.log("Function 2 is running");
// Add your function logic here
}

// Create a worker thread for Function 1
const worker_ririkoStreamChecker = new Worker(
`./${buildDir}/ririkoStreamChecker`
);

// Create a worker thread for Function 1
const worker_RirikoExpress = new Worker(`./${buildDir}/ririkoExpress`);
}

// Create a worker thread for Function 2
function startRirikoBotWorker() {
const worker_RirikoBot = new Worker(`./${buildDir}/ririkoBot`);

const worker_RirikoQueueManager = new Worker(
`./${buildDir}/ririkoQueueManager`
);

// Listen for messages from worker threads
worker_RirikoExpress.on("message", (message) => {
console.log(`Message from Ririko Express: ${message}`);
});

worker_RirikoQueueManager.on("message", (message) => {
console.log(`Message from Ririko Queue Manager: ${message}`);
});

worker_RirikoBot.on("message", (message) => {
if (message.ready) {
cli.log("NODE_ENV:".red, NODE_ENV);
cli.log(
"\n" +
`[READY] ${message.botUsername} is up and ready to go. ${
process.env.npm_package_version
? "\nRunning ririko@" + process.env.npm_package_version
: ""
}`.brightGreen
`[READY] ${message.botUsername} is up and ready to go. ${
process.env.npm_package_version
? "\nRunning ririko@" + process.env.npm_package_version
: ""
}`.brightGreen
);
cli.log(
"\n==============================================================\n"
Expand All @@ -90,33 +51,69 @@ process.on("uncaughtException", (err) => {
}
});

// Listen for errors from worker threads
worker_RirikoExpress.on("error", (error) => {
console.error(`[UNCAUGHT EXCEPTION] Ririko Express:`, error);
});

worker_RirikoBot.on("error", (error) => {
console.error(`[UNCAUGHT EXCEPTION] Ririko Bot:`, error);
});
}

function startRirikoStreamCheckerWorker() {
const worker_ririkoStreamChecker = new Worker(
`./${buildDir}/ririkoStreamChecker`
);

worker_ririkoStreamChecker.on("error", (error) => {
console.error(`[UNCAUGHT EXCEPTION] Ririko Stream Notifier:`, error);
});

worker_ririkoStreamChecker.on("message", (message) => {
if (message.exit) {
console.error('Terminating stream checker due to unrecoverable error');
worker_ririkoStreamChecker.terminate()
worker_ririkoStreamChecker.terminate().then(() => {
console.error("Terminating stream checker due to unrecoverable error");
});
}
});
}

function startRirikoQueueManagerWorker() {
const worker_RirikoQueueManager = new Worker(
`./${buildDir}/ririkoQueueManager`
);

worker_RirikoQueueManager.on("message", (message) => {
console.log(`Message from Ririko Queue Manager: ${message}`);
});

worker_RirikoQueueManager.on("error", (error) => {
console.error(`[UNCAUGHT EXCEPTION] Ririko Stream Notifier:`, error);
});
}

function startRirikoExpressWorker() {
const worker_RirikoExpress = new Worker(`./${buildDir}/ririkoExpress.js`);

// Start the worker threads
worker_RirikoExpress.postMessage("Start");
worker_ririkoStreamChecker.postMessage("Start");
worker_RirikoBot.postMessage("Start");
worker_RirikoQueueManager.postMessage("Start");
worker_RirikoExpress.on("message", (message) => {
if (message.ready) {
}
});

worker_RirikoExpress.on("error", (error) => {
console.error(`[UNCAUGHT EXCEPTION] Ririko Express:`, error);
});
}

(function () {
createLogDirectory();

process.on("unhandledRejection", handleUnhandledRejection);

process.on("uncaughtException", handleUncaughtException);

startRirikoExpressWorker();

// check if config.js file exists
if (configFileExists === true) {
startRirikoBotWorker();
startRirikoStreamCheckerWorker();
startRirikoQueueManagerWorker();
}
})();
2 changes: 2 additions & 0 deletions installer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.DS_Store
Loading

0 comments on commit bbecbc0

Please sign in to comment.