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
|
2018-01-19 04:45:50 +00:00
|
|
|
let activity
|
2017-11-30 06:40:56 +00:00
|
|
|
|
2018-01-19 04:45:50 +00:00
|
|
|
exports.initRPC = function(genSettings, servSettings, initialDetails = 'Waiting for Client..'){
|
|
|
|
rpc = new Client({ transport: 'ipc' })
|
2017-11-30 06:40:56 +00:00
|
|
|
|
2017-12-03 07:13:42 +00:00
|
|
|
rpc.on('ready', () => {
|
2018-01-19 04:45:50 +00:00
|
|
|
activity = {
|
|
|
|
details: initialDetails,
|
2017-12-03 13:54:10 +00:00
|
|
|
state: 'Server: ' + servSettings.shortId,
|
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
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-01-19 04:45:50 +00:00
|
|
|
exports.updateDetails = function(details){
|
|
|
|
if(activity == null){
|
|
|
|
console.error('Discord RPC is not initialized and therefore cannot be updated.')
|
|
|
|
}
|
|
|
|
activity.details = details
|
|
|
|
rpc.setActivity(activity)
|
|
|
|
}
|
|
|
|
|
2017-12-03 07:13:42 +00:00
|
|
|
exports.shutdownRPC = function(){
|
2018-01-19 04:45:50 +00:00
|
|
|
if(!rpc) return
|
2017-12-03 07:13:42 +00:00
|
|
|
rpc.setActivity({})
|
2017-11-30 06:40:56 +00:00
|
|
|
rpc.destroy()
|
|
|
|
rpc = null
|
2018-01-19 04:45:50 +00:00
|
|
|
activity = null
|
2017-11-30 06:40:56 +00:00
|
|
|
}
|