This commit is contained in:
djkato 2022-01-29 01:15:50 +01:00
commit 846f8c6850
6 changed files with 145 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
node_modules
null
temp.txt

1
README.md Normal file
View file

@ -0,0 +1 @@
# Discord-Rich-Presence-For-Cinema-4D

32
package.json Normal file
View file

@ -0,0 +1,32 @@
{
"name": "discord-rich-presence-for-cinema-4d",
"version": "1.0.0",
"description": "A simple node project to show your friends on discord what you're working on in Cinema 4D! Bit hacky but it works x)",
"main": "Rich Presence for C4D.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/djkato/Discord-Rich-Presence-For-Cinema-4D.git"
},
"keywords": [
"Cinema",
"4D",
"Maxon",
"Discord",
"Discord",
"RPC",
"Rich",
"presence"
],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/djkato/Discord-Rich-Presence-For-Cinema-4D/issues"
},
"homepage": "https://github.com/djkato/Discord-Rich-Presence-For-Cinema-4D#readme",
"dependencies": {
"discord-rich-presence": "0.0.8"
}
}

25
src/C4DRichPresence.bat Normal file
View file

@ -0,0 +1,25 @@
@echo off
set Active=0
:Search
timeout /t 60 /nobreak > null
wmic process list brief | find /i "Cinema 4D.exe"
set result=%ERRORLEVEL%
if "%result%"=="0" goto ProcessFound
goto ProcessNotFound
:ProcessFound
IF %Active%==1 goto Search
start node "Rich Presence For C4D.js"
set Active=1
goto Search
:ProcessNotFound
set Active=0
goto Search

4
src/DRCSettings.json Normal file
View file

@ -0,0 +1,4 @@
{
"portfolio_website": "djkato.net",
"scan_refresh_rate": 1000
}

View file

@ -0,0 +1,80 @@
const fs = require('fs')
const client = require('discord-rich-presence')('936296341250904065')
const { spawnSync, spawn, execSync, exec } = require('child_process')
var StringDecoder = require('string_decoder').StringDecoder
const { stdout, mainModule } = require('process')
let currentProject
let pastProject = ""
let cmd = 'tasklist /fi "imagename eq Cinema 4D.exe" /fo list /v'
//Loads DRC settings
let DRCSettings = JSON.parse(fs.readFileSync("DRCSettings.json"))
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
function isCinemaOpen() {
return new Promise((resolve) => {
exec(cmd, (err, stdout, stderr) => {
if (err || stderr) {
resolve("true")
return
}
if (stdout.includes("No tasks")) {
resolve("false")
return
}
if (stdout.includes("Cinema 4D")) {
//if window title is the actual project title(hover tooltips change window title to tooltip),
//resolves to Project file name from Process dump from.bat file
resolve(stdout)
return
}
else {
resolve("true")
return
}
})
})
}
function setDRCProject() {
//update current presence settings
if (currentProject !== pastProject) {
client.updatePresence({
state: `Porfolio: ${DRCSettings.portfolio_website}`,
details: `Working on ${currentProject}`,
startTimestamp: Date.now(),
largeImageKey: 'c4d',
instance: true,
})
}
pastProject = currentProject
}
async function main() {
let str
while (true) {
str = await isCinemaOpen()
console.log(str)
if (str == "false") {
break
}
else if (str == "true") {
setDRCProject()
await sleep(DRCSettings.scan_refresh_rate)
}
else {
//gets project file name
str = str.split("\n")
str = str[9].split("[")
str = str[1].split("]")
currentProject = str[0].toString()
setDRCProject()
await sleep(DRCSettings.scan_refresh_rate)
}
}
}
main()