2017-11-29 22:40:56 -08:00
|
|
|
// Work in progress
|
2017-12-03 05:54:10 -08:00
|
|
|
const {Client} = require('discord-rpc')
|
2017-12-02 21:38:22 -08:00
|
|
|
const ConfigManager = require('./configmanager.js')
|
2017-11-29 22:40:56 -08:00
|
|
|
|
|
|
|
let rpc
|
2018-01-18 20:45:50 -08:00
|
|
|
let activity
|
2017-11-29 22:40:56 -08:00
|
|
|
|
2018-01-18 20:45:50 -08:00
|
|
|
exports.initRPC = function(genSettings, servSettings, initialDetails = 'Waiting for Client..'){
|
|
|
|
rpc = new Client({ transport: 'ipc' })
|
2017-11-29 22:40:56 -08:00
|
|
|
|
2017-12-02 23:13:42 -08:00
|
|
|
rpc.on('ready', () => {
|
2018-01-18 20:45:50 -08:00
|
|
|
activity = {
|
|
|
|
details: initialDetails,
|
2017-12-03 05:54:10 -08:00
|
|
|
state: 'Server: ' + servSettings.shortId,
|
2017-12-02 23:13:42 -08:00
|
|
|
largeImageKey: servSettings.largeImageKey,
|
2017-12-03 05:54:10 -08:00
|
|
|
largeImageText: servSettings.largeImageText,
|
2017-12-02 23:13:42 -08:00
|
|
|
smallImageKey: genSettings.smallImageKey,
|
|
|
|
smallImageText: genSettings.smallImageText,
|
|
|
|
startTimestamp: new Date().getTime() / 1000,
|
|
|
|
instance: false
|
|
|
|
}
|
|
|
|
|
|
|
|
rpc.setActivity(activity)
|
|
|
|
})
|
|
|
|
|
2017-12-03 05:54:10 -08:00
|
|
|
rpc.login(genSettings.clientID).catch(error => {
|
2017-11-29 22:40:56 -08:00
|
|
|
if(error.message.includes('ENOENT')) {
|
|
|
|
console.log('Unable to initialize Discord Rich Presence, no client detected.')
|
|
|
|
} else {
|
2017-12-03 05:54:10 -08:00
|
|
|
console.log('Unable to initialize Discord Rich Presence: ' + error.message, error)
|
2017-11-29 22:40:56 -08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-01-18 20:45:50 -08: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-02 23:13:42 -08:00
|
|
|
exports.shutdownRPC = function(){
|
2018-01-18 20:45:50 -08:00
|
|
|
if(!rpc) return
|
2018-06-03 12:35:39 -07:00
|
|
|
rpc.clearActivity()
|
2017-11-29 22:40:56 -08:00
|
|
|
rpc.destroy()
|
|
|
|
rpc = null
|
2018-01-18 20:45:50 -08:00
|
|
|
activity = null
|
2017-11-29 22:40:56 -08:00
|
|
|
}
|