Created
February 3, 2018 06:01
-
-
Save TheBlackParrot/cace5bc0b1c6bf54c9789290b6c804e2 to your computer and use it in GitHub Desktop.
Discord rich presence for Foobar2000
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* you need discord-rpc and a discord application in your dev page for this to work */ | |
/* uses the Now Playing Simple plugin in foobar */ | |
/* settings.json: | |
{ | |
"client_id": "[bot client id]", | |
"nowplaying_file": "D:/foobar.nowplaying.txt" | |
} | |
*/ | |
const { Client } = require('discord-rpc'); | |
const fs = require('fs'); | |
const settings = require("./settings.json"); | |
const client = new Client({ transport: 'ipc' }); | |
const startTimestamp = new Date(); | |
var current = ""; | |
client.on('ready', function() { | |
console.log("ready"); | |
fs.watch(settings.nowplaying_file, function(eventType, filename) { | |
if(eventType == "change") { | |
fs.readFile(settings.nowplaying_file, {encoding: "utf-8"}, function(err, data) { | |
if(!err) { | |
var lines = data.split("\r\n"); | |
if(current != lines[0] && typeof lines[0] !== "undefined") { | |
var end_at = new Date(); | |
end_at.setSeconds(end_at.getSeconds() + parseInt(lines[4])); | |
client.setActivity({ | |
state: lines[2], | |
details: lines[1] + " [" + lines[3] + "]", | |
endTimestamp: end_at | |
}); | |
current = lines[0]; | |
} | |
} else { | |
console.log(err); | |
} | |
}); | |
} | |
}); | |
}); | |
client.login(settings.client_id).catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Total noob question, but how exactly do I use this?