forked from ThatOneCalculator/DiscordRPCMaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpresence.js
executable file
·69 lines (60 loc) · 2.13 KB
/
presence.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env node
const RPC = require('discord-rpc')
const chalk = require('chalk')
const fs = require('fs')
const os = require('os')
let client = new RPC.Client({ transport: 'ipc' })
const dir = `${os.userInfo().homedir}/${process.platform === 'win32' ? '/AppData/Roaming' : '/.config'}`
const options = require(`${dir}/drpcm-options.json`)
// console.log(options);
const activity = {}
const assets = {}
if (options.largeimage !== '') {
assets.large_image = options.largeimage
// If you change this and some asks about this, please still give me credit :)
assets.large_text = `Made with ThatOneCalculator's Discord RPC Maker (v${require('./package.json').version})!`
}
if (options.smallimage !== '') {
assets.small_image = options.smallimage
// Same applies with assets.large_text
assets.small_text = 'https://drpcm.t1c.dev/'
}
if (assets !== {}) { activity.assets = assets }
if (options.description !== '') { activity.details = options.description }
if (options.state !== '') { activity.state = options.state }
if (options.buttons.length !== 0) { activity.buttons = options.buttons }
function assembleClient(timeout = 5000) {
client.destroy()
client = new RPC.Client({ transport: 'ipc' })
client.on('ready', () => {
running = true;
client.request('SET_ACTIVITY', {
pid: process.pid,
activity: activity
})
/*
notifier.notify({
title: 'Discord RPC Maker',
message: 'Your Rich Presence has started!',
sound: true
})
*/
console.log(chalk`{bold.green Your Rich Presence has started!} Generated by {blue.underline https://github.com/ThatOneCalculator/DiscordRPCMaker}`)
client.transport.socket.on("close", (c,s) => {
console.log(chalk`{bold.red Connection closed. }{green Attempting to reopen in 5 seconds.}`)
assembleClient()
})
})
setTimeout(() => client.login({ clientId: options.clientid }), timeout)
}
process.on("unhandledRejection", e => {
if (e.message === "Could not connect") {
console.log(chalk`{bold.red Failed to connect.}\n{bold.green Retrying in 5 seconds.}`)
assembleClient()
} else {
console.log(chalk`{bold.red Something went wrong.}`)
console.error(e)
process.exit()
}
})
assembleClient(0)