Skip to content

Commit

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

* WIP: Copy and update config file with payloads sent from the installer.

* [WIP] Dashboard

* [WIP] Dashboard + Latest Changes

* [FEAT] Dashboard + Fixes

* 0.14.0

* [FEAT] Dashboard + Fixes
  • Loading branch information
earnestangel authored Jan 31, 2024
1 parent bbecbc0 commit d37d242
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 64 deletions.
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function createLogDirectory() {
}

const { overrideLoggers } = require(`${buildDir}/helpers/logger`);
const { twitchClientId } = require("./src/helpers/getconfig");
overrideLoggers();

function handleUnhandledRejection(err, promise) {
Expand Down Expand Up @@ -57,6 +58,17 @@ function startRirikoBotWorker() {
}

function startRirikoStreamCheckerWorker() {
if (twitchClientId()) {
console.log(
"Twitch Client ID found in environment variables. Starting stream checker."
);
} else {
console.log(
"Twitch Client ID not found in environment variables. Not starting stream checker."
);
return;
}

const worker_ririkoStreamChecker = new Worker(
`./${buildDir}/ririkoStreamChecker`
);
Expand Down
47 changes: 28 additions & 19 deletions installer/assets/js/bd-wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,34 @@ form.children("#wizard").steps({
return form.valid();
},
onFinished: function (event, currentIndex) {
var formData = JSON.stringify($("#wizardForm").serializeArray()); // Serialize form data

console.log("formData, ", formData);

// Ajax request
$.ajax({
type: "POST",
url: "submit_install", // Replace with your server-side script URL
data: formData,
contentType: "application/json",
success: function (response) {
// Handle success response
console.log(response);
},
error: function (xhr, status, error) {
// Handle error response
console.log(error);
},
});
try {
var formData = JSON.stringify($("#wizardForm").serializeArray()); // Serialize form data

console.log("formData, ", formData);

// Ajax request
$.ajax({
type: "POST",
url: "submit_install", // Replace with your server-side script URL
data: formData,
contentType: "application/json",
success: function (response) {
// Handle success response
console.log(response);
},
error: function (xhr, status, error) {
// Handle error response
console.log(error);
},
});
alert(
"Installation complete! Please restart the bot and refresh the page."
);
} catch (e) {
alert(
"An error occurred while submitting the form. Please try again, or contact the developer."
);
}
},
});

Expand Down
2 changes: 2 additions & 0 deletions installer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ <h4 class="section-heading">Configure AI Chatbot and Stable Diffusion</h4>
<select class="select form-control" name="ai_provider" id="ai_provider">
<option value="OpenAI" selected>OpenAI</option>
<option value="NLPCloud">NLPCloud</option>
<option value="RirikoLLaMAProvider">RirikoLLaMAProvider</option>
<option value="RirikoHuggingChatProvider">RirikoHuggingChatProvider</option>
</select>
</div>
<div class="form-group col-12">
Expand Down
6 changes: 4 additions & 2 deletions nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"watch": [
"index.js",
"config.js",
"src/"
"src/",
"./config.js"
],
"ignore": [
"*.test.js",
"**/*.test.js"
],
"ext": "js, css"
"ext": "js, css",
"delay": 3500
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "ririko",
"version": "0.13.0",
"version": "0.14.0",

"description": "Ririko - A powerful AI-powered general Discord bot that you can call your companion",
"author": "Earnest Angel",
"email": "[email protected]",
Expand Down Expand Up @@ -96,7 +97,8 @@
"save-dev": "^0.0.1-security",
"semver": "^7.5.3",
"source-map-support": "^0.5.21",
"sourcebin_js": "^0.0.3-ignore"
"sourcebin_js": "^0.0.3-ignore",
"body-parser": "^1.20.2"
},
"devDependencies": {
"@babel/cli": "^7.22.5",
Expand Down
11 changes: 11 additions & 0 deletions src/commands/prefix/Announcer/twitch-stream-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {
deleteSubscription,
} = require("app/Schemas/StreamSubscribers");
const { addStreamersAndSubscribers } = require("app/RirikoTwitchManager");
const { twitchClientId } = require("../../../helpers/getconfig");

module.exports = {
config: {
Expand Down Expand Up @@ -45,6 +46,16 @@ module.exports = {
* @returns {Promise<*>}
*/
run: async (client, message, args, prefix, config, db) => {
if (!twitchClientId()) {
return message.reply({
embeds: [
new EmbedBuilder()
.setTitle("Missing Twitch Client ID")
.setDescription(`You need to add Twitch Client ID to the config`),
],
});
}

await updateGuildOwner(message.guild);
let settings = await getSettings(message.guild.id);
// console.log("settings", settings);
Expand Down
6 changes: 5 additions & 1 deletion src/helpers/getconfig.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const config = require("config");
let config;

try {
config = require("../../config");
} catch (e) {}

/**
* This section of code is proudly written by Ririko herself (up until a point)
Expand Down
11 changes: 2 additions & 9 deletions src/ririkoExpress.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ async function writeConfigFile(payloads) {
const twitchClientSecretRegex = stringRegex("TwitchClientSecret");

// Define the new values you want to set
const discordToken = getValueFromKey("application_id", payloads);
const discordBotID = getValueFromKey("bot_token", payloads);
const discordToken = getValueFromKey("bot_token", payloads);
const discordBotID = getValueFromKey("application_id", payloads);
const replicateToken = getValueFromKey("replicate_token", payloads);
const aiToken = getValueFromKey("ai_token", payloads);
const accessURI = getValueFromKey("mongodb_uri", payloads);
Expand All @@ -186,15 +186,8 @@ async function writeConfigFile(payloads) {

console.log("discordTokenRegex", discordTokenRegex);

const portRegex = integerRegex("PORT");
const languageRegex = stringRegex("LANGUAGE");
const newPort = 8080;
const newLanguage = "fr";

// Replace the values while preserving the data type and comments
const modifiedContent = content
.replace(portRegex, `$1${newPort}`)
.replace(languageRegex, `$1${newLanguage}"`)
.replace(discordTokenRegex, `$1${discordToken}"`)
.replace(discordBotIDRegex, `$1${discordBotID}"`)
.replace(replicateTokenRegex, `$1${replicateToken}"`)
Expand Down
64 changes: 35 additions & 29 deletions src/ririkoStreamChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
* @type {axios.AxiosStatic | axios | AxiosStatic | {all<T>(values: Array<Promise<T> | T>): Promise<T[]>, AxiosInterceptorOptions: AxiosInterceptorOptions, AxiosResponse: AxiosResponse, Axios: Axios, ParamsSerializerOptions: ParamsSerializerOptions, ParamEncoder: ParamEncoder, AxiosDefaults: AxiosDefaults, AxiosInterceptorManager: AxiosInterceptorManager, ResponseType: "arraybuffer" | "blob" | "document" | "json" | "text" | "stream", AxiosBasicCredentials: AxiosBasicCredentials, AxiosProxyConfig: AxiosProxyConfig, RawAxiosRequestHeaders: RawAxiosRequestHeaders, Method: "get" | "GET" | "delete" | "DELETE" | "head" | "HEAD" | "options" | "OPTIONS" | "post" | "POST" | "put" | "PUT" | "patch" | "PATCH" | "purge" | "PURGE" | "link" | "LINK" | "unlink" | "UNLINK", FormDataVisitorHelpers: FormDataVisitorHelpers, AxiosRequestConfig: AxiosRequestConfig, SerializerVisitor: SerializerVisitor, AxiosAdapter: AxiosAdapter, CancelStatic: CancelStatic, AxiosStatic: AxiosStatic, AxiosRequestHeaders: RawAxiosRequestHeaders & AxiosHeaders, AxiosPromise: Promise<AxiosResponse<T>>, InternalAxiosRequestConfig: InternalAxiosRequestConfig, GenericHTMLFormElement: GenericHTMLFormElement, CanceledError: CanceledError, RawAxiosRequestConfig: AxiosRequestConfig<D>, HeadersDefaults: HeadersDefaults, GenericFormData: GenericFormData, AxiosHeaderValue: AxiosHeaders | string | string[] | number | boolean, CancelTokenStatic: CancelTokenStatic, Canceler: Canceler, FormSerializerOptions: FormSerializerOptions, spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R, Cancel: Cancel, CancelTokenSource: CancelTokenSource, CancelToken: CancelToken, AxiosError: AxiosError, toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData, AxiosProgressEvent: AxiosProgressEvent, responseEncoding: "ascii" | "ASCII" | "ansi" | "ANSI" | "binary" | "BINARY" | "base64" | "BASE64" | "base64url" | "BASE64URL" | "hex" | "HEX" | "latin1" | "LATIN1" | "ucs-2" | "UCS-2" | "ucs2" | "UCS2" | "utf-8" | "UTF-8" | "utf8" | "UTF8" | "utf16le" | "UTF16LE", isAxiosError<T=any, D=any>(payload: any): payload is AxiosError<T, D>, TransitionalOptions: TransitionalOptions, HttpStatusCode: HttpStatusCode, CustomParamsSerializer: CustomParamsSerializer, GenericAbortSignal: GenericAbortSignal, AxiosResponseHeaders: RawAxiosResponseHeaders & AxiosHeaders, CreateAxiosDefaults: CreateAxiosDefaults, formToJSON(form: (GenericFormData | GenericHTMLFormElement)): object, AxiosInstance: AxiosInstance, AxiosRequestTransformer: AxiosRequestTransformer, SerializerOptions: SerializerOptions, AxiosHeaders: AxiosHeaders, isCancel(value: any): value is Cancel, AxiosResponseTransformer: AxiosResponseTransformer, RawAxiosResponseHeaders: RawAxiosResponseHeaders, readonly default: AxiosStatic}}
*/
const axios = require("axios");
const {getStreamers} = require("app/Schemas/Streamer");
const { getStreamers } = require("app/Schemas/Streamer");
const {
Subscriber,
getSubscribersByUserId,
getSubscribersByUserIdArray,
} = require("app/Schemas/StreamSubscribers");
const {overrideLoggers} = require("helpers/logger");
const { overrideLoggers } = require("helpers/logger");
overrideLoggers();
const {twitchClientId, twitchClientSecret} = require("helpers/getconfig");
const {det} = require("mathjs");
const {addQueueItems, deleteQueueItems} = require("./app/Schemas/QueueItem");
const {getNotification} = require("./app/Schemas/StreamNotification");
const {addStreamersAndSubscribers} = require("./app/RirikoTwitchManager");
const {getAllSettings} = require("./app/Schemas/Guild");
const {parentPort} = require("worker_threads");
const { twitchClientId, twitchClientSecret } = require("helpers/getconfig");
const { det } = require("mathjs");
const { addQueueItems, deleteQueueItems } = require("./app/Schemas/QueueItem");
const { getNotification } = require("./app/Schemas/StreamNotification");
const { addStreamersAndSubscribers } = require("./app/RirikoTwitchManager");
const { getAllSettings } = require("./app/Schemas/Guild");
const { parentPort } = require("worker_threads");

const clientId = twitchClientId();
const clientSecret = twitchClientSecret();
Expand Down Expand Up @@ -61,27 +61,33 @@ async function run() {
}

async function twitchLogin() {
if (retries <= max_retries) {
// Get OAuth token
tokenResponse = await axios.post(
"https://id.twitch.tv/oauth2/token",
null,
{
params: {
client_id: clientId,
client_secret: clientSecret,
grant_type: "client_credentials",
},
try {
if (retries <= max_retries) {
// Get OAuth token
tokenResponse = await axios.post(
"https://id.twitch.tv/oauth2/token",
null,
{
params: {
client_id: clientId,
client_secret: clientSecret,
grant_type: "client_credentials",
},
}
);
accessToken = tokenResponse.data.access_token;
retries++;
} else {
if (typeof parentPort !== "undefined") {
parentPort.postMessage({
exit: true,
});
}
);
accessToken = tokenResponse.data.access_token;
retries++;
} else {
if (typeof parentPort !== "undefined") {
parentPort.postMessage({
exit: true
});
}
} catch (e) {
console.error(
"Something went wrong trying to login to Twitch: " + e.message
);
}
}

Expand Down Expand Up @@ -273,7 +279,7 @@ async function fetchStreamersInfo(streams) {
const matchingItem = onlineStreamers.find((otherItem) => {
return otherItem.user_id === item.user_id;
});
return {...item, ...matchingItem};
return { ...item, ...matchingItem };
});

return onlineStreamers;
Expand Down

0 comments on commit d37d242

Please sign in to comment.