bugfix - stable

This commit is contained in:
djkato 2022-01-29 19:19:05 +01:00
parent f7ccc2ec05
commit a6cac307aa
2 changed files with 28 additions and 16 deletions

View file

@ -1,14 +1,9 @@
# Discord-Rich-Presence-For-Cinema-4D
How to use:
A hacky way of allowing all your discord friends to know what your'e working on in Cinema 4D!
-ideally create batch file that runs `node ./src/Rich Presence for C4D.js`
How it works:
>gets process info on c4D and takes windows name, extracts name from it
>hooks into discord api via npms `discord-rich-presence` and uses my custom app assets to show as cinema 4D, puts project name there
-put a shortcut to it in `shell:StartUp` folder to run on startup.
-change `DRCSettings.json` to have your website porfolio
-Enjoy <3
known issues:
-crash on cinema 4D close
enjoy~
Dj

View file

@ -6,11 +6,15 @@ const { stdout, mainModule } = require('process')
let currentProject = "lorem Ipsum"
let pastProject = "."
//Command used to scan for C4D process
let cmd = 'tasklist /fi "imagename eq Cinema 4D.exe" /fo list /v'
//Loads DRC settings
let DRCSettings = JSON.parse(fs.readFileSync("DRCSettings.json"))
let clientIsConnected = false
let currentClient
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
@ -46,6 +50,16 @@ function updateOpenProjectName(str) {
function setDRCProject() {
//update current presence settings
//reconnects the client if isnt connected
if (!clientIsConnected) {
currentClient = client("936296341250904065")
currentClient.on("error", (err) => {
console.log("err")
})
clientIsConnected = true
console.log("starting client")
currentProject = "0"
}
if (currentProject != pastProject) {
currentClient.updatePresence({
state: `Porfolio: ${DRCSettings.portfolio_website}`,
@ -54,28 +68,31 @@ function setDRCProject() {
largeImageKey: 'c4d',
instance: true,
})
console.log("updating client")
}
pastProject = currentProject
}
//catches the error
async function main() {
while (true) {
updateOpenProjectName(await getCinemaProcessInfo())
//stops DRC when broken
if (currentProject == false) {
if (currentClient) {
if (clientIsConnected) {
await currentClient.disconnect()
clientIsConnected = false
console.log("disconnecting client...")
}
await sleep(20000)
await sleep(DRCSettings.scan_refresh_rate * 10)
continue
} else {
if (!currentClient) {
currentClient = client("936296341250904065")
}
setDRCProject()
}
await sleep(DRCSettings.scan_refresh_rate)
}
}