Skip to content

Commit

Permalink
v5.51.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SReject committed Mar 28, 2022
1 parent d88863c commit 0410456
Show file tree
Hide file tree
Showing 81 changed files with 2,195 additions and 801 deletions.
9 changes: 9 additions & 0 deletions .github/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Branches
The `master` branch is reserved for the current latest release. We will not accept Pull Requests made to it.

For developement, work from the `v5` branch and then Pull Request against it.

# Formatting
We use Unix-style end of line character: Line-Feed(`\n` aka `\x0A`)

We use 4 spaces for indents
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"files.eol": "\n"
},
"editor.formatOnSave": true
}
7 changes: 6 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Registered Tasks:
scss - Deletes compiled CSS, then recompiles SCSS
inline-source - Generates a new index.html containing AngularJS modules
lint - Runs eslint
secrets:encrypt - Encrypts an updated secrets.json to secrets.gpg
Expand All @@ -24,7 +26,9 @@ Registered Tasks:
compile - Creates an installer/tarball from the platform's pack
build - Runs cleanup, scss, pack, and compile
fullpack - Runs cleanup, scss, inline-source, pack
build - Runs cleanup, scss, inline-source, pack, and compile
*/

module.exports = function(grunt) {
Expand Down Expand Up @@ -58,5 +62,6 @@ module.exports = function(grunt) {
require('./grunt/secrets.js')(grunt);
require('./grunt/include-source')(grunt);

grunt.registerTask('fullpack', ['scss', 'include-source', 'pack']);
grunt.registerTask('build', ['scss', 'include-source', 'pack', 'compile']);
};
3 changes: 3 additions & 0 deletions backend/app-management/electron/events/second-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ exports.secondInstance = (_, argv) => {
try {
const { mainWindow } = require("../window-management");
if (mainWindow) {
if (!mainWindow.isVisible()) {
mainWindow.show();
}
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
Expand Down
3 changes: 3 additions & 0 deletions backend/app-management/electron/events/when-ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ exports.whenReady = async () => {
const setupImporter = require("../../../import/setups/setup-importer");
setupImporter.setupListeners();

const slcbImporter = require("../../../import/third-party/streamlabs-chatbot");
slcbImporter.setupListeners();

const { setupCommonListeners } = require("../../../common/common-listeners");
setupCommonListeners();

Expand Down
102 changes: 102 additions & 0 deletions backend/app-management/electron/tray-creation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
'use strict';

const path = require("path");

const electron = require("electron");
const { Menu, Tray, app } = electron;

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

let mainTray;
let minimizedToTray = false;

module.exports = function createTray(mainWindow) {
if (mainTray != null) {
return;
}

const trayMenu = Menu.buildFromTemplate([
{
label: 'Show',
type: 'normal',
click: () => {
if (minimizedToTray) {
mainWindow.show();
minimizedToTray = false;
} else {
mainWindow.focus();
}
}
},
{
type: 'separator'
},
{
label: 'Exit',
type: 'normal',
click: () => {
app.quit();
}
}
]);
mainTray = new Tray(path.join(__dirname, "../../../gui/images/logo_transparent_2.png"));
mainTray.setToolTip('Firebot');
mainTray.setContextMenu(trayMenu);

mainTray.on('double-click', () => {
if (minimizedToTray) {
mainWindow.show();
minimizedToTray = false;
} else {
mainWindow.focus();
}
});

mainWindow.on('minimize', () => {
if (settings.getMinimizeToTray() && minimizedToTray !== true) {
mainWindow.hide();
minimizedToTray = true;
}
});

mainWindow.on('restore', () => {
if (minimizedToTray) {
if (!mainWindow.isVisible()) {
mainWindow.show();
}
minimizedToTray = false;
}

});
mainWindow.on('show', () => {
if (minimizedToTray) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
minimizedToTray = false;
}
});
mainWindow.on('focus', () => {
if (minimizedToTray) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
if (!mainWindow.isVisible()) {
mainWindow.show();
}
minimizedToTray = false;
}
});

frontendCommunicator.on('settings-updated-renderer', (evt) => {
if (
evt.path === '/settings/minimizeToTray' &&
evt.data !== true &&
minimizedToTray === true
) {
mainWindow.show();
minimizedToTray = false;
}
});
};
4 changes: 4 additions & 0 deletions backend/app-management/electron/window-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const path = require("path");
const url = require("url");
const windowStateKeeper = require("electron-window-state");
const fileOpenHelpers = require("../file-open-helpers");
const createTray = require('./tray-creation.js');
const logger = require("../../logwrapper");

/**
Expand Down Expand Up @@ -208,6 +209,9 @@ function createMainWindow() {

// wait for the main window's content to load, then show it
mainWindow.webContents.on("did-finish-load", () => {

createTray(mainWindow);

mainWindow.show();
if (splashscreenWindow) {
splashscreenWindow.destroy();
Expand Down
2 changes: 1 addition & 1 deletion backend/chat/chat-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function parseMessageParts(firebotChatMessage, parts) {
if (!firebotChatMessage.whisper &&
!firebotChatMessage.tagged &&
streamer.loggedIn &&
p.text.includes(streamer.username)) {
(p.text.includes(streamer.username) || p.text.includes(streamer.displayName))) {
firebotChatMessage.tagged = true;
}
}
Expand Down
8 changes: 8 additions & 0 deletions backend/common/settings-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,12 @@ settings.getSidebarControlledServices = function() {
: ["chat"];
};

settings.getMinimizeToTray = function () {
let minimizeToTray = getDataFromFile('/settings/minimizeToTray');
return minimizeToTray === true;
};
settings.setMinimizeToTray = function (minimizeToTray) {
pushDataToFile('/settings/minimizeToTray', minimizeToTray === true);
};

exports.settings = settings;
6 changes: 3 additions & 3 deletions backend/database/currencyDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ frontendCommunicator.on("give-currency", async (/** @type {CurrencyInfo} */ {
break;
case "individual":
await adjustCurrencyForUser(username, currencyId, amount);
messageTarget = `@${username}}`;
messageTarget = `@${username}`;
break;
}

Expand All @@ -503,7 +503,7 @@ frontendCommunicator.on("give-currency", async (/** @type {CurrencyInfo} */ {
return;
}

twitchChat.sendChatMessage(`${amount < 0 ? "Removed" : "Gave"} ${util.commafy(amount)} ${currency.name} to ${messageTarget}!`);
twitchChat.sendChatMessage(`${amount < 0 ? "Removed" : "Gave"} ${util.commafy(amount)} ${currency.name} ${amount < 0 ? "from" : "to"} ${messageTarget}!`);
}
});

Expand Down Expand Up @@ -563,4 +563,4 @@ exports.addCurrencyToUserGroupOnlineUsers = addCurrencyToUserGroupOnlineUsers;
exports.isViewerDBOn = isViewerDBOn;
exports.getTopCurrencyHolders = getTopCurrencyHolders;
exports.getTopCurrencyPosition = getTopCurrencyPosition;
exports.adjustCurrencyForAllUsers = adjustCurrencyForAllUsers;
exports.adjustCurrencyForAllUsers = adjustCurrencyForAllUsers;
22 changes: 22 additions & 0 deletions backend/database/userDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,26 @@ function getAllUsernames() {
});
}

function getAllUsernamesWithIds() {
return new Promise(resolve => {
if (!isViewerDBOn()) {
return resolve([]);
}

const projectionObj = {
displayName: 1
};

db.find({ twitch: true }).projection(projectionObj).exec(function (err, docs) {
if (err) {
logger.error("Error getting all users: ", err);
return resolve([]);
}
return resolve(docs != null ? docs.map(u => ({ id: u._id, username: u.displayName })) : []);
});
});
}

function getTopViewTimeUsers(count) {
return new Promise(resolve => {
if (!isViewerDBOn()) {
Expand Down Expand Up @@ -895,6 +915,7 @@ exports.getTwitchUserByUsername = getTwitchUserByUsername;
exports.incrementDbField = incrementDbField;
exports.getUserDb = getUserDb;
exports.removeUser = removeUser;
exports.createNewUser = createNewUser;
exports.updateUser = updateUser;
exports.setChatUsersOnline = setChatUsersOnline;
exports.getTopViewTimeUsers = getTopViewTimeUsers;
Expand All @@ -903,5 +924,6 @@ exports.getOnlineUsers = getOnlineUsers;
exports.updateUserMetadata = updateUserMetadata;
exports.getUserMetadata = getUserMetadata;
exports.getAllUsernames = getAllUsernames;
exports.getAllUsernamesWithIds = getAllUsernamesWithIds;
exports.getTopMetadata = getTopMetadata;
exports.getTopMetadataPosition = getTopMetadataPosition;
1 change: 1 addition & 0 deletions backend/effects/builtin-effect-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports.loadEffects = () => {
[
'active-user-lists',
'ad-break',
'add-quote',
'api',
'celebration',
'chat-feed-alert',
Expand Down
71 changes: 71 additions & 0 deletions backend/effects/builtin/add-quote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"use strict";

const twitchChannels = require("../../twitch-api/resource/channels");
const quotesManager = require("../../quotes/quotes-manager");
const { EffectCategory } = require('../../../shared/effect-constants');
const moment = require("moment");

const addQuoteEffect = {
definition: {
id: "firebot:add-quote",
name: "Add Quote",
description: "Adds a quote to the quote database.",
icon: "fad fa-quote-right",
categories: [EffectCategory.FUN],
dependencies: []
},
globalSettings: {},
optionsTemplate: `
<eos-container header="Quote Creator">
<p class="muted">This is the name of the person who is creating the quote entry.</p>
<input ng-model="effect.creator" type="text" class="form-control" id="chat-text-setting" placeholder="Enter quote creator" replace-variables/>
</eos-container>
<eos-container header="Quote Originator" pad-top="true">
<p class="muted">This is the name of the person who actually said the quote.</p>
<input ng-model="effect.originator" type="text" class="form-control" id="chat-text-setting" placeholder="Enter quote originator" replace-variables/>
</eos-container>
<eos-container header="Quote Text" pad-top="true">
<p class="muted">This is the actual quote text.</p>
<input ng-model="effect.text" type="text" class="form-control" id="chat-text-setting" placeholder="Enter quote text" replace-variables/>
</eos-container>
`,
optionsController: () => {},
optionsValidator: effect => {
let errors = [];
if (effect.creator == null || effect.creator === "") {
errors.push("Please provide a quote creator.");
}

if (effect.originator == null || effect.originator === "") {
errors.push("Please provide a quote originator.");
}

if (effect.text == null || effect.text === "") {
errors.push("Please provide a value for quote text.");
}
return errors;
},
onTriggerEvent: async event => {
const { effect } = event;

const channelData = await twitchChannels.getChannelInformation();

const currentGameName = channelData && channelData.gameName ? channelData.gameName : "Unknown game";

const newQuote = {
text: effect.text,
originator: effect.originator.replace(/@/g, ""),
creator: effect.creator.replace(/@/g, ""),
game: currentGameName,
createdAt: moment().toISOString()
}

quotesManager.addQuote(newQuote);

return true;
}
}

module.exports = addQuoteEffect;
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
"use strict";

const firebotRolesManager = require("../../../../../roles/firebot-roles-manager");
const customRolesManager = require("../../../../../roles/custom-roles-manager");
const teamRolesManager = require("../../../../../roles/team-roles-manager");
const twitchRolesManager = require("../../../../../../shared/twitch-roles");
const chatRolesManager = require("../../../../../roles/chat-roles-manager");
const { viewerHasRoles } = require("../../../../../roles/role-helpers");

module.exports = {
id: "firebot:viewerroles",
Expand Down Expand Up @@ -46,20 +42,7 @@ module.exports = {
username = trigger.metadata.username;
}

const userTwitchRoles = (await chatRolesManager.getUsersChatRoles(username))
.map(twitchRolesManager.mapTwitchRole);
const userFirebotRoles = firebotRolesManager.getAllFirebotRolesForViewer(username);
const userCustomRoles = customRolesManager.getAllCustomRolesForViewer(username);
const userTeamRoles = await teamRolesManager.getAllTeamRolesForViewer(username);

const allRoles = [
...userTwitchRoles,
...userFirebotRoles,
...userCustomRoles,
...userTeamRoles
];

const hasRole = allRoles.some(r => r.id === rightSideValue);
const hasRole = await viewerHasRoles(username, [rightSideValue]);

switch (comparisonType) {
case "include":
Expand Down
Loading

0 comments on commit 0410456

Please sign in to comment.