2017-11-30 06:40:56 +00:00
|
|
|
// Work in progress
|
2018-08-22 18:21:49 +00:00
|
|
|
const logger = require('./loggerutil')('%c[DiscordWrapper]', 'color: #7289da; font-weight: bold')
|
|
|
|
|
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,
|
2018-10-31 05:25:38 +00:00
|
|
|
startTimestamp: new Date().getTime(),
|
2018-07-22 15:40:15 +00:00
|
|
|
instance: false
|
|
|
|
}
|
2017-12-03 07:13:42 +00:00
|
|
|
|
2018-07-22 15:40:15 +00:00
|
|
|
client.on('ready', () => {
|
2018-08-22 18:21:49 +00:00
|
|
|
logger.log('Discord RPC Connected')
|
2018-07-22 15:40:15 +00:00
|
|
|
client.setActivity(activity)
|
|
|
|
})
|
|
|
|
|
|
|
|
client.login({clientId: genSettings.clientId}).catch(error => {
|
2017-11-30 06:40:56 +00:00
|
|
|
if(error.message.includes('ENOENT')) {
|
2018-08-22 18:21:49 +00:00
|
|
|
logger.log('Unable to initialize Discord Rich Presence, no client detected.')
|
2017-11-30 06:40:56 +00:00
|
|
|
} else {
|
2018-08-22 18:21:49 +00:00
|
|
|
logger.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){
|
|
|
|
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
|
|
|
}
|