Skip to content

Commit

Permalink
Merge branch 'v5' into v5-error-messages-in-http-request
Browse files Browse the repository at this point in the history
  • Loading branch information
zunderscore authored Dec 21, 2024
2 parents 8a212ea + 9b566f6 commit ef5a028
Show file tree
Hide file tree
Showing 83 changed files with 1,029 additions and 1,702 deletions.
4 changes: 2 additions & 2 deletions src/backend/app-management/electron/events/when-ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ exports.whenReady = async () => {
builtinGameLoader.loadGames();

windowManagement.updateSplashScreenStatus("Loading custom variables...");
const {settings} = require("../../../common/settings-access");
if (settings.getPersistCustomVariables()) {
const { SettingsManager } = require("../../../common/settings-manager");
if (SettingsManager.getSetting("PersistCustomVariables")) {
const customVariableManager = require("../../../common/custom-variable-manager");
customVariableManager.loadVariablesFromFile();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports.windowsAllClosed = async () => {
const logger = require("../../../logwrapper");
logger.debug("All windows closed triggered");

const { settings } = require("../../../common/settings-access");
const { SettingsManager } = require("../../../common/settings-manager");
const backupManager = require("../../../backup-manager");

// Stop all scheduled tasks
Expand All @@ -27,7 +27,7 @@ exports.windowsAllClosed = async () => {
chatModerationManager.stopService();

// Persist custom variables
if (settings.getPersistCustomVariables()) {
if (SettingsManager.getSetting("PersistCustomVariables")) {
const customVariableManager = require("../../../common/custom-variable-manager");
customVariableManager.persistVariablesToFile();
}
Expand All @@ -36,7 +36,7 @@ exports.windowsAllClosed = async () => {
const viewerOnlineStatusManager = require("../../../viewers/viewer-online-status-manager");
await viewerOnlineStatusManager.setAllViewersOffline();

if (settings.backupOnExit()) {
if (SettingsManager.getSetting("BackupOnExit")) {
// Make a backup
await backupManager.startBackup(false, app.quit);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/backend/app-management/electron/tray-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const electron = require("electron");
const { Menu, Tray, app, nativeImage } = electron;

const frontendCommunicator = require('../../common/frontend-communicator.js');
const { settings } = require("../../common/settings-access");
const { SettingsManager } = require("../../common/settings-manager");

let mainTray;
let minimizedToTray = false;
Expand Down Expand Up @@ -62,7 +62,7 @@ module.exports = function createTray(mainWindow) {
});

mainWindow.on('minimize', () => {
if (settings.getMinimizeToTray() && minimizedToTray !== true) {
if (SettingsManager.getSetting("MinimizeToTray") && minimizedToTray !== true) {
mainWindow.hide();
minimizedToTray = true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/backend/app-management/electron/window-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const logger = require("../../logwrapper");
const { setupTitlebar, attachTitlebarToWindow } = require("custom-electron-titlebar/main");
const screenHelpers = require("./screen-helpers");
const frontendCommunicator = require("../../common/frontend-communicator");
const { settings } = require("../../common/settings-access");
const { SettingsManager } = require("../../common/settings-manager");

const argv = require('../../common/argv-parser');

Expand Down Expand Up @@ -473,7 +473,7 @@ async function createMainWindow() {
username: "Firebot"
});

if (settings.getOpenStreamPreviewOnLaunch() === true) {
if (SettingsManager.getSetting("OpenStreamPreviewOnLaunch") === true) {
createStreamPreviewWindow();
}

Expand All @@ -483,7 +483,7 @@ async function createMainWindow() {

mainWindow.on("close", (event) => {
const connectionManager = require("../../common/connection-manager");
if (!settings.hasJustUpdated() && connectionManager.chatIsConnected() && connectionManager.streamerIsOnline()) {
if (!SettingsManager.getSetting("JustUpdated") && connectionManager.chatIsConnected() && connectionManager.streamerIsOnline()) {
event.preventDefault();
dialog.showMessageBox(mainWindow, {
message: "Are you sure you want to close Firebot while connected to Twitch?",
Expand Down
6 changes: 3 additions & 3 deletions src/backend/auth/auth-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import { EventEmitter } from "events";
import ClientOAuth2 from "client-oauth2";
import logger from "../logwrapper";
import { AuthProvider, AuthProviderDefinition } from "./auth";
import { settings } from "../common/settings-access";
import { SettingsManager } from "../common/settings-manager";
import frontendCommunicator from "../common/frontend-communicator";
import { Notification, app } from "electron";
import windowManagement from "../app-management/electron/window-management";

class AuthManager extends EventEmitter {
private readonly _httpPort: string;
private readonly _httpPort: number;
private _authProviders: AuthProvider[];

constructor() {
super();

this._authProviders = [];
this._httpPort = settings.getWebServerPort();
this._httpPort = SettingsManager.getSetting("WebServerPort");
}

registerAuthProvider(provider: AuthProviderDefinition): void {
Expand Down
12 changes: 6 additions & 6 deletions src/backend/backup-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { glob } from "glob";
import { DeflateOptions, Zip, ZipDeflate, unzipSync } from "fflate";
import logger from "./logwrapper";
import utils from "./utility";
import { settings } from "./common/settings-access";
import { SettingsManager } from "./common/settings-manager";
import dataAccess from "./common/data-access.js";
import frontendCommunicator from "./common/frontend-communicator";

Expand All @@ -31,7 +31,7 @@ class BackupManager {
}

private async cleanUpOldBackups(callback: () => void) {
const maxBackups = settings.maxBackupCount();
const maxBackups = SettingsManager.getSetting("MaxBackupCount");

if (maxBackups !== "All") {
const fileNames = (await fsp.readdir(this._backupFolderPath))
Expand Down Expand Up @@ -78,7 +78,7 @@ class BackupManager {

// listen for all archive data to be written
output.on("close", async () => {
settings.setLastBackupDate(new Date());
SettingsManager.saveSetting("LastBackupDate", new Date());
await this.cleanUpOldBackups(callback);
});

Expand Down Expand Up @@ -107,7 +107,7 @@ class BackupManager {
//archive.directory(folderPath, "profiles");

const varIgnoreInArchive = ['backups/**', 'clips/**', 'logs/**', 'overlay.html'];
const ignoreResources = settings.backupIgnoreResources();
const ignoreResources = SettingsManager.getSetting("BackupIgnoreResources");

if (ignoreResources && !manualActivation) {
logger.info("Ignoring overlay-resources folder");
Expand Down Expand Up @@ -147,8 +147,8 @@ class BackupManager {
}

async onceADayBackUpCheck() {
const shouldBackUp = settings.backupOnceADay(),
lastBackupDate = settings.lastBackupDate(),
const shouldBackUp = SettingsManager.getSetting("BackupOnceADay"),
lastBackupDate = SettingsManager.getSetting("LastBackupDate"),
todayDate = new Date();

if (shouldBackUp) {
Expand Down
4 changes: 2 additions & 2 deletions src/backend/chat/chat-listeners/active-user-handler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

const chatHelpers = require("../chat-helpers");
const { settings } = require("../../common/settings-access");
const { SettingsManager } = require("../../common/settings-manager");
const frontendCommunicator = require("../../common/frontend-communicator");
const utils = require("../../utility");
const chatRolesManager = require("../../roles/chat-roles-manager");
Expand Down Expand Up @@ -235,7 +235,7 @@ exports.addActiveUser = async (chatUser, includeInOnline = false, forceActive =

const viewerDatabase = require("../../viewers/viewer-database");

const ttl = settings.getActiveChatUserListTimeout() * 60;
const ttl = SettingsManager.getSetting("ActiveChatUserListTimeout") * 60;

let user = await viewerDatabase.getViewerById(chatUser.userId);

Expand Down
23 changes: 12 additions & 11 deletions src/backend/chat/commands/builtin/quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,23 +277,24 @@ export const QuotesManagementSystemCommand: SystemCommand<{

switch (triggeredArg) {
case "add": {
const shouldInsertStreamerUsername = (commandOptions.defaultStreamerAttribution && args.length === 1)
|| (commandOptions.defaultStreamerAttribution && !args[1].includes("@"));
const shouldInsertStreamerUsername =
(commandOptions.defaultStreamerAttribution && args.length === 1) ||
(commandOptions.defaultStreamerAttribution && !args[1].includes("@"));
const expectedArgs = shouldInsertStreamerUsername
? 2
: 3;
? 2
: 3;

if (args.length < expectedArgs) {
await twitchChat.sendChatMessage(`Please provide some quote text!`);
return resolve();
await twitchChat.sendChatMessage(`Please provide some quote text!`);
return resolve();
}
// Once we've evaluated that the syntax is correct we make our API calls
const channelData = await TwitchApi.channels.getChannelInformation();
const currentGameName = channelData && channelData.gameName ? channelData.gameName : "Unknown game";

// If shouldInsertStreamerUsername and no @ is included in the originator arg, set originator @streamerName and treat the rest as the quote
if (shouldInsertStreamerUsername) {
args.splice(1,0,`@${channelData.displayName}`)
args.splice(1, 0, `@${channelData.displayName}`);
}

const newQuote = {
Expand Down Expand Up @@ -404,8 +405,8 @@ export const QuotesManagementSystemCommand: SystemCommand<{
}
case "searchdate": {
const rawDay = parseInt(args[1]);
const rawMonth = parseInt(args[1]);
const rawYear = parseInt(args[1]);
const rawMonth = parseInt(args[2]);
const rawYear = parseInt(args[3]);

const day = !isNaN(rawDay) ? rawDay : null;
const month = !isNaN(rawMonth) ? rawMonth : null;
Expand Down
4 changes: 2 additions & 2 deletions src/backend/chat/commands/chat-command-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import commandManager from "./command-manager";
import commandCooldownManager from "./command-cooldown-manager";
import twitchApi from "../../twitch-api/api";
import commandRunner from "./command-runner";
import { settings } from "../../common/settings-access";
import { SettingsManager } from "../../common/settings-manager";

const DEFAULT_COOLDOWN_MESSAGE = "This command is still on cooldown for: {timeLeft}";
const DEFAULT_RESTRICTION_MESSAGE = "Sorry, you cannot use this command because: {reason}";
Expand Down Expand Up @@ -130,7 +130,7 @@ class CommandHandler {
}

// 'inherit' or undefined = inherit app settings
if (command.allowTriggerBySharedChat !== true && !settings.getAllowCommandsInSharedChat()) {
if (command.allowTriggerBySharedChat !== true && !SettingsManager.getSetting("AllowCommandsInSharedChat")) {
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/backend/cloud-sync/profile-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const logger = require("../logwrapper");
const commandList = require("./sync-handlers/command-list");
const quoteList = require("./sync-handlers/quotes-list");
const frontendCommunicator = require("../common/frontend-communicator");
const { settings } = require("../common/settings-access");
const { SettingsManager } = require("../common/settings-manager");
const rankManager = require("../ranks/rank-manager");

async function syncProfileData(profileSyncData) {
Expand All @@ -25,7 +25,7 @@ async function syncProfileData(profileSyncData) {
'variables': variableManager.getReplaceVariables().map(v => v.definition),
'ranks': rankManager.getAllItems(),
'quotes': quotes,
'allowQuoteCSVDownloads': settings.getAllowQuoteCSVDownloads()
'allowQuoteCSVDownloads': SettingsManager.getSetting("AllowQuoteCSVDownloads")
};

const binId = await cloudSync.sync(completeSyncJSON);
Expand Down
6 changes: 3 additions & 3 deletions src/backend/common/common-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports.setupCommonListeners = () => {
const frontendCommunicator = require("./frontend-communicator");
const dataAccess = require("./data-access");
const profileManager = require("./profile-manager");
const { settings } = require("./settings-access");
const { SettingsManager } = require("./settings-manager");
const backupManager = require("../backup-manager");
const webServer = require("../../server/http-server-manager");

Expand Down Expand Up @@ -198,7 +198,7 @@ exports.setupCommonListeners = () => {
const GhReleases = require("electron-gh-releases");

//back up first
if (settings.backupBeforeUpdates()) {
if (SettingsManager.getSetting("BackupBeforeUpdates")) {
await backupManager.startBackup();
}

Expand All @@ -221,7 +221,7 @@ exports.setupCommonListeners = () => {
renderWindow.webContents.send("updateDownloaded");

// Prepare for update install on next run
settings.setJustUpdated(true);
SettingsManager.saveSetting("JustUpdated", true);
});
});

Expand Down
6 changes: 3 additions & 3 deletions src/backend/common/connection-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { EventEmitter } = require("events");
const util = require("../utility");
const logger = require("../logwrapper");
const frontendCommunicator = require("./frontend-communicator");
const { settings } = require("./settings-access");
const { SettingsManager } = require("./settings-manager");
const twitchApi = require("../twitch-api/api");
const twitchChat = require("../chat/twitch-chat");
const twitchPubSubClient = require("../twitch-api/pubsub/pubsub-client");
Expand Down Expand Up @@ -224,7 +224,7 @@ manager.on("service-connection-update", (data) => {
});

frontendCommunicator.onAsync("connect-sidebar-controlled-services", async () => {
const serviceIds = settings.getSidebarControlledServices();
const serviceIds = SettingsManager.getSetting("SidebarControlledServices");

await manager.updateConnectionForServices(serviceIds.map(id => ({
id,
Expand All @@ -233,7 +233,7 @@ frontendCommunicator.onAsync("connect-sidebar-controlled-services", async () =>
});

frontendCommunicator.on("disconnect-sidebar-controlled-services", () => {
const serviceIds = settings.getSidebarControlledServices();
const serviceIds = SettingsManager.getSetting("SidebarControlledServices");
for (const id of serviceIds) {
manager.updateServiceConnection(id, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const twitchChat = require("../../../chat/twitch-chat");
const twitchApi = require("../../../twitch-api/api");
const profileManager = require("../../profile-manager");
const settings = require('../../settings-access').settings;
const settings = require('../../settings-manager').SettingsManager;
const path = require("path");
const logger = require("../../../logwrapper");
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
const { ipcMain, shell } = require("electron");
const { v4: uuid } = require("uuid");
const logger = require("../../../logwrapper");
const { settings } = require("../../settings-access");
const utils = require("../../../utility");
const profileManager = require("../../profile-manager");
const { getScriptPath, buildRunRequest, mapParameters, mapV4EffectToV5 } = require("./custom-script-helpers");
const effectRunner = require("../../effect-runner.js");
import { SettingsManager } from "../../settings-manager";

/**
* @typedef { import('./script-types').ScriptData } ScriptData
Expand Down Expand Up @@ -36,7 +36,7 @@ async function executeScript(scriptData, trigger, isStartupScript = false) {
let customScript;
try {
// Make sure we first remove the cached version, incase there was any changes
if (settings.getClearCustomScriptCache()) {
if (SettingsManager.getSetting("ClearCustomScriptCache")) {
delete require.cache[require.resolve(scriptFilePath)];
}
customScript = require(scriptFilePath);
Expand Down Expand Up @@ -168,7 +168,7 @@ async function runStartUpScript(startUpScriptConfig) {
const { scriptName } = startUpScriptConfig;
logger.debug(`running startup script: ${scriptName}`);

if (!settings.isCustomScriptsEnabled()) {
if (SettingsManager.getSetting("RunCustomScripts") !== true) {
logger.warn("Attempted to run startup script but custom scripts are disabled.");
return;
}
Expand Down Expand Up @@ -229,7 +229,7 @@ function runScript(effect, trigger) {

logger.debug(`running script: ${scriptName}`);

if (!settings.isCustomScriptsEnabled()) {
if (SettingsManager.getSetting("RunCustomScripts")) {
renderWindow.webContents.send(
"error",
"Something attempted to run a custom script but this feature is disabled!"
Expand Down
Loading

0 comments on commit ef5a028

Please sign in to comment.