Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
version 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CapOliveiraBr committed Apr 19, 2020
2 parents 6e626de + dd20b94 commit e8acbd8
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 48 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

📖 A Rich Presence of Discord that shows your DBM information.

> **Note:** This is just a first version, soon it will be super cool!
![](https://i.imgur.com/4IPNq8U.png)
![](https://i.imgur.com/KSAR1JE.png)

![](https://img.shields.io/github/v/release/CapOliveiraBr/DBM-Rich-Presence?style=for-the-badge) ![](https://img.shields.io/github/license/CapOliveiraBr/DBM-Rich-Presence?logo=https%3A%2F%2Fimg.shields.io%2Fgithub%2Flicense%2FCapOliveiraBr%2FDBM-Rich-Presence%3Fstyle%3Dsocial&style=for-the-badge)

Expand Down Expand Up @@ -46,7 +44,7 @@ Download the latest release of the RPC [here](https://github.com/CapOliveiraBr/D
When you install the RPC, a new menu tab is added to DBM, called "**Integrations**", inside it you can go to **DBM Rich Presence** where you can see some settings.

![](https://i.imgur.com/Mz1xPcz.png)
![](https://i.imgur.com/jVgGIJ0.png)
![](https://i.imgur.com/926LZKv.png)

---

Expand Down
210 changes: 167 additions & 43 deletions src/dbm-rich-presence.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,84 @@
/*======================================================*
* *
* # DBM Rich Presence - v1.0.0 *
* Created by Cap *
* https://github.com/CapOliveiraBr/DBM-Rich-Presence *
* *
*======================================================*/
const rpcVersion = '1.1.0';

/*======================================================*
* *
* # DBM Rich Presence - v1.1.0 *
* Created by Cap & General Wrex *
* https://github.com/CapOliveiraBr/DBM-Rich-Presence *
* *
*======================================================*/

const { Window, Menu, MenuItem } = nw;
const { writeFileSync } = require('fs');
const { resolve } = require('path');

let modal;
let Menu;
let rpc;
let menu;

const settings = require(resolve('rpcSettings.json'));
let rpc;
let rpcOptions = {
details: 'Idling',
state: 'No Project Opened',
largeImageKey: 'dbm',
largeImageText: `DBM Rich Presence v${rpcVersion}`,
startTimestamp: Date.now()
};

const rpcSettings = require(resolve('rpcSettings.json'));
let enableRPC;
let enableCmdNames;

function setMenu() {
Menu = nw.Window.get().menu;
menu = Window.get().menu;

const dbmRichPresenceMenu = new nw.Menu();
dbmRichPresenceMenu.append(new nw.MenuItem({
const dbmRichPresenceMenu = new Menu();
dbmRichPresenceMenu.append(new MenuItem({
label: 'DBM Rich Presence',
click: () => jQuery('#discordRichPresence').modal('show')
click: () => jQuery('#dbmRichPresence').modal('show')
}))

Menu.append(new nw.MenuItem({
menu.append(new MenuItem({
label: 'Integrations',
submenu: dbmRichPresenceMenu
}));
}

function setModal() {
modal = document.createElement('div');
modal.id = 'discordRichPresence';
modal.id = 'dbmRichPresence';
modal.classList.add('ui');
modal.classList.add('modal');
modal.setAttribute('style', 'padding: 20px; height: 220px; border-radius: 10px; background-color: #36393e; border: 2px solid #000;');
modal.setAttribute('style', 'padding: 20px; height: 320px; border-radius: 10px; background-color: #36393e; border: 2px solid #000;');
modal.innerHTML = `
<h2>DBM Rich Presence - v1.0.0</h2>
Created by <b>Cap</b> - <a href="#" onclick="nw.Shell.openExternal('https://github.com/CapOliveiraBr/DBM-Rich-Presence')">Repository</a>
<h3>Settings</h3>
Enable RPC:<br><br>
<select id="enableRPC" class="round">
<option value="true">True</option>
<option value="false">False</option>
</select>
`;
<h2>DBM Rich Presence - v${rpcVersion}</h2>
Created by <b>Cap & General Wrex</b> - <a href="#" onclick="nw.Shell.openExternal('https://github.com/CapOliveiraBr/DBM-Rich-Presence')">Repository</a>
<h3>Settings</h3>
Enable RPC:<br><br>
<select id="enableRPC" class="round">
<option value="true">True</option>
<option value="false">False</option>
</select><br><br>
Show Command/Event Names:<br><br>
<select id="enableCmdNames" class="round">
<option value="true">True</option>
<option value="false">False</option>
</select>
`;

document.body.appendChild(modal);
document.getElementById('enableRPC').value = settings.enableRPC;

document.getElementById('enableRPC').value = rpcSettings.enableRPC;
document.getElementById('enableCmdNames').value = rpcSettings.enableCmdNames;

setInterval(() => {
enableRPC = document.getElementById('enableRPC').value === 'true' ? true : false;
enableCmdNames = document.getElementById('enableCmdNames').value === 'true' ? true : false;

writeFileSync(resolve('rpcSettings.json'), JSON.stringify({
enableRPC,
enableCmdNames
}));

writeFileSync(resolve('rpcSettings.json'), JSON.stringify({ enableRPC }));

if (enableRPC) {
if (!rpc) setRichPresence();
} else stopRichPresence();
Expand All @@ -67,24 +90,19 @@ function setRichPresence() {

const { Client } = require('discord-rpc');
rpc = new Client({ transport: 'ipc' });

const stateVal = `Project: ${require(resolve('settings.json'))['current-project'].replace(/\\/g, '/').split('/').slice(-1).toString()}`;

function setActivity() {
rpc.setActivity({
state: stateVal,
largeImageKey: 'dbm',
largeImageText: 'DBM Rich Presence v1.0.0',
startTimestamp: Date.now()
});
}

rpcOptions.state = `Project: ${DBM._currentProject.replace(/\\/g, '/').split('/').slice(-1).toString()}`;

rpc.on('ready', () => {
setActivity();
setTimeout(() => setActivity(), 1000);
try {
overrideFunctions();
rpc.setActivity(rpcOptions);
} catch (err) {
alert(err);
}
});

rpc.login({ clientId: '675588061140353025' }).catch(() => alert('Some error ocurred on set your RPC.'));
rpc.login({ clientId: '675588061140353025' }).catch(alert);
}

function stopRichPresence() {
Expand All @@ -96,6 +114,112 @@ function stopRichPresence() {
});
}

function getName(type, index) {
switch (type) {
case 'Commands':
return DBM.$cmds[index] && DBM.$cmds[index].name ? DBM.$cmds[index].name : false;
case 'Events':
return DBM.$evts[index] && DBM.$evts[index].name ? DBM.$evts[index].name : false;
}
}

function overrideFunctions() {
const cache = {
Commands: enableCmdNames ? `Command: ${getName('Commands', 1) || `None`}` : `Editing Commands`,
Events: enableCmdNames ? `Event: ${getName('Events', 1) || `None`}` : `Editing Events`,
Settings: 'Editing Bot Settings'
};

let section = 'Commands';

const shiftTabs = DBM.shiftTabs;
DBM.shiftTabs = function(event, sect, index) {
try {
section = sect;
rpcOptions.details = cache[sect];
rpc.setActivity(rpcOptions);
} catch (err) {
alert(err);
}

shiftTabs.apply(this, arguments);
}

const onCommandClick = DBM.onCommandClick;
DBM.onCommandClick = function(index) {
try {
const type = section.slice(0, -1);
const details = enableCmdNames ? `${index ? `${type}: ` : ' '}${index ? (getName(section, index) || `New ${type}`) : 'None Selected'}` : `Editing ${section}`;

cache['Commands'] = details;
rpcOptions.details = details;
rpcOptions.state = `Project: ${DBM._currentProject.replace(/\\/g, '/').split('/').slice(-1).toString()}`;
rpc.setActivity(rpcOptions);
} catch (err) {
alert(err);
}

onCommandClick.apply(this, arguments);
}

const eonCommandClick = DBM.eonCommandClick;
DBM.eonCommandClick = function(index) {
try {
const type = section.slice(0, -1);
const details = enableCmdNames ? `${index ? `${type}: ` : ' '}${index ? (getName(section, index) || `New ${type}`) : 'None Selected'}` : `Editing ${section}`;

cache['Events'] = details;
rpcOptions.details = details;
rpcOptions.state = `Project: ${DBM._currentProject.replace(/\\/g, '/').split('/').slice(-1).toString()}`;

rpc.setActivity(rpcOptions);
} catch (err) {
alert(err);
}

eonCommandClick.apply(this, arguments);
}

const createNewProject = DBM.createNewProject;
DBM.createNewProject = function() {
try {
rpcOptions.state = `Creating Project...`;
rpcOptions.startTimestamp = Date.now()
rpc.setActivity(rpcOptions);
} catch (err) {
alert(err);
}

createNewProject.apply(this, arguments);
}

const openProject = DBM.openProject;
DBM.openProject = function() {
try {
rpcOptions.state = 'Opening Project...';
rpcOptions.startTimestamp = Date.now()
rpc.setActivity(rpcOptions);
} catch (err) {
alert(err);
}

openProject.apply(this, arguments);
}

const saveAndClose = DBM.saveAndClose;
DBM.saveAndClose = function() {
try {
rpcOptions.state = `No Project Opened`;
rpc.setActivity(rpcOptions);
} catch (err) {
alert(err);
}

saveAndClose.apply(this, arguments);
}
}

setMenu();
setModal();

setRichPresence();
2 changes: 1 addition & 1 deletion src/rpcSettings.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"enableRPC":true}
{"enableRPC":true,"enableCmdNames":true}

0 comments on commit e8acbd8

Please sign in to comment.