Skip to content

Instantly share code, notes, and snippets.

@TheBlackParrot
Created February 3, 2018 06:01
Show Gist options
  • Save TheBlackParrot/cace5bc0b1c6bf54c9789290b6c804e2 to your computer and use it in GitHub Desktop.
Save TheBlackParrot/cace5bc0b1c6bf54c9789290b6c804e2 to your computer and use it in GitHub Desktop.
Discord rich presence for Foobar2000
/* 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);
@Thein1
Copy link

Thein1 commented Feb 9, 2018

Total noob question, but how exactly do I use this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment