2017-11-30 06:40:56 +00:00
|
|
|
// Work in progress
|
2017-12-03 13:54:10 +00:00
|
|
|
const {Client} = require('discord-rpc')
|
2017-12-03 05:38:22 +00:00
|
|
|
const ConfigManager = require('./configmanager.js')
|
2017-11-30 06:40:56 +00:00
|
|
|
|
|
|
|
let rpc
|
|
|
|
|
2017-12-03 07:13:42 +00:00
|
|
|
exports.initRPC = function(genSettings, servSettings){
|
2017-11-30 06:40:56 +00:00
|
|
|
rpc = new Client({ transport: 'ipc' });
|
|
|
|
|
2017-12-03 07:13:42 +00:00
|
|
|
rpc.on('ready', () => {
|
|
|
|
const activity = {
|
|
|
|
// state = top text
|
|
|
|
// details = bottom text
|
2017-12-03 13:54:10 +00:00
|
|
|
state: 'Server: ' + servSettings.shortId,
|
|
|
|
details: 'Exploring the wall',
|
2017-12-03 07:13:42 +00:00
|
|
|
largeImageKey: servSettings.largeImageKey,
|
2017-12-03 13:54:10 +00:00
|
|
|
largeImageText: servSettings.largeImageText,
|
2017-12-03 07:13:42 +00:00
|
|
|
smallImageKey: genSettings.smallImageKey,
|
|
|
|
smallImageText: genSettings.smallImageText,
|
|
|
|
startTimestamp: new Date().getTime() / 1000,
|
|
|
|
instance: false
|
|
|
|
}
|
|
|
|
|
|
|
|
rpc.setActivity(activity)
|
|
|
|
})
|
|
|
|
|
2017-12-03 13:54:10 +00:00
|
|
|
rpc.login(genSettings.clientID).catch(error => {
|
2017-11-30 06:40:56 +00:00
|
|
|
if(error.message.includes('ENOENT')) {
|
|
|
|
console.log('Unable to initialize Discord Rich Presence, no client detected.')
|
|
|
|
} else {
|
2017-12-03 13:54:10 +00:00
|
|
|
console.log('Unable to initialize Discord Rich Presence: ' + error.message, error)
|
2017-11-30 06:40:56 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-12-03 07:13:42 +00:00
|
|
|
exports.shutdownRPC = function(){
|
|
|
|
rpc.setActivity({})
|
2017-11-30 06:40:56 +00:00
|
|
|
rpc.destroy()
|
|
|
|
rpc = null
|
|
|
|
}
|