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-11-29 22:40:56 -08:00
|
|
|
|
2018-07-22 08:40:15 -07:00
|
|
|
let client
|
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..'){
|
2018-07-22 08:40:15 -07:00
|
|
|
client = new Client({ transport: 'ipc' })
|
2017-11-29 22:40:56 -08:00
|
|
|
|
2018-07-22 08:40:15 -07:00
|
|
|
activity = {
|
|
|
|
details: initialDetails,
|
|
|
|
state: 'Server: ' + servSettings.shortId,
|
|
|
|
largeImageKey: servSettings.largeImageKey,
|
|
|
|
largeImageText: servSettings.largeImageText,
|
|
|
|
smallImageKey: genSettings.smallImageKey,
|
|
|
|
smallImageText: genSettings.smallImageText,
|
|
|
|
startTimestamp: new Date().getTime() / 1000,
|
|
|
|
instance: false
|
|
|
|
}
|
2017-12-02 23:13:42 -08:00
|
|
|
|
2018-07-22 08:40:15 -07:00
|
|
|
client.on('ready', () => {
|
|
|
|
console.log('%c[Discord Wrapper]', 'color: #a02d2a; font-weight: bold', 'Discord RPC Connected')
|
|
|
|
client.setActivity(activity)
|
|
|
|
})
|
|
|
|
|
|
|
|
client.login({clientId: genSettings.clientId}).catch(error => {
|
2017-11-29 22:40:56 -08:00
|
|
|
if(error.message.includes('ENOENT')) {
|
2018-07-22 08:40:15 -07:00
|
|
|
console.log('%c[Discord Wrapper]', 'color: #a02d2a; font-weight: bold', 'Unable to initialize Discord Rich Presence, no client detected.')
|
2017-11-29 22:40:56 -08:00
|
|
|
} else {
|
2018-07-22 08:40:15 -07:00
|
|
|
console.log('%c[Discord Wrapper]', 'color: #a02d2a; font-weight: bold', '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){
|
|
|
|
activity.details = details
|
2018-07-22 08:40:15 -07:00
|
|
|
client.setActivity(activity)
|
2018-01-18 20:45:50 -08:00
|
|
|
}
|
|
|
|
|
2017-12-02 23:13:42 -08:00
|
|
|
exports.shutdownRPC = function(){
|
2018-07-22 08:40:15 -07:00
|
|
|
if(!client) return
|
|
|
|
client.clearActivity()
|
|
|
|
client.destroy()
|
|
|
|
client = null
|
2018-01-18 20:45:50 -08:00
|
|
|
activity = null
|
2017-11-29 22:40:56 -08:00
|
|
|
}
|