-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
99 lines (84 loc) · 2.49 KB
/
main.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const DiscordRPC = require('discord-rpc')
const clientId = '642126871177199617'
const rpc = new DiscordRPC.Client({ transport: 'ipc' })
var startTimestamp = new Date();
(function() {
let setting
let intervalID
let installed = true
let curProject = ''
Plugin.register('discord-rpc', {
title: 'Discord RPC',
author: 'strajabot, Kastle, & simplyme',
icon: 'announcement',
version: '1.1.1',
description: 'Show a rich presence status in Discord',
variant: 'desktop',
onload() {
setting = new Setting('obfuscaterpc', {
value: true,
name: 'Discord Rich Prescense',
description: 'Obfuscate Project Name',
})
async function setActivity() {
if (!rpc) {
return
}
if (curProject !== Project.name) {
curProject = Project.name
startTimestamp = new Date()
}
var discordrpcfilename = (Settings.get('obfuscaterpc')) ? 'Unknown Model' : `${curProject}.bbmodel`;
const actionString = {
'edit': 'Editing',
'paint': 'Painting',
'animate': 'Animating',
'start': 'Starting'
}[Modes.selected.id] || 'Making'
const formatString = {
'java_block': 'a Java Block/Item',
'bedrock': 'a Bedrock Model',
'bedrock_old': 'a Bedrock Legacy Model',
'modded_entity': 'a Modded Entity',
'optifine_entity': 'an OptiFine Entity',
'optifine_part': 'an OptiFine Part',
'skin': 'a Skin',
'free': 'a Generic Model'
}[Format.id] || `a ${Format.name}`
rpc.setActivity({
largeImageKey: 'icon',
largeImageText: `Blockbench ${Blockbench.version}`,
smallImageKey: `${Format.id}`,
details: `${actionString} ${formatString}`,
state: `${discordrpcfilename}`,
startTimestamp,
instance: false,
})
}
// add a small hook onto the clicks to detect when they change, hehe
const ops = Modes.options
Object.keys(ops).forEach(e => {
const mode = Modes.options[e]
if (mode.onSelect && typeof mode.onSelect === 'function') {
let appSelect = mode.onSelect
mode.onSelect = () => {
appSelect.apply(this, arguments)
if (installed) setActivity()
}
}
})
rpc.on('ready', () => {
setActivity()
intervalID = setInterval(() => {
setActivity()
}, 15e3)
})
rpc.login({ clientId }).catch(console.error)
},
onunload() {
installed = false
setting.delete()
clearInterval(intervalID)
}
});
})();