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-11-30 06:40:56 +00:00
|
|
|
|
2018-07-22 15:40:15 +00:00
|
|
|
let client
|
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..'){
|
2018-07-22 15:40:15 +00:00
|
|
|
client = new Client({ transport: 'ipc' })
|
2017-11-30 06:40:56 +00:00
|
|
|
|
2018-07-22 15:40:15 +00: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-03 07:13:42 +00:00
|
|
|
|
2018-07-22 15:40:15 +00: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-30 06:40:56 +00:00
|
|
|
if(error.message.includes('ENOENT')) {
|
2018-07-22 15:40:15 +00:00
|
|
|
console.log('%c[Discord Wrapper]', 'color: #a02d2a; font-weight: bold', 'Unable to initialize Discord Rich Presence, no client detected.')
|
2017-11-30 06:40:56 +00:00
|
|
|
} else {
|
2018-07-22 15:40:15 +00:00
|
|
|
console.log('%c[Discord Wrapper]', 'color: #a02d2a; font-weight: bold', '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){
|
|
|
|
activity.details = details
|
2018-07-22 15:40:15 +00:00
|
|
|
client.setActivity(activity)
|
2018-01-19 04:45:50 +00:00
|
|
|
}
|
|
|
|
|
2017-12-03 07:13:42 +00:00
|
|
|
exports.shutdownRPC = function(){
|
2018-07-22 15:40:15 +00:00
|
|
|
if(!client) return
|
|
|
|
client.clearActivity()
|
|
|
|
client.destroy()
|
|
|
|
client = null
|
2018-01-19 04:45:50 +00:00
|
|
|
activity = null
|
2017-11-30 06:40:56 +00:00
|
|
|
}
|