forked from CCDirectLink/CCdiscord
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin.js
More file actions
105 lines (88 loc) · 2.58 KB
/
plugin.js
File metadata and controls
105 lines (88 loc) · 2.58 KB
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
100
101
102
103
104
105
const DiscordRPC = ccmod.require('discord-rpc');
const CLIENT_ID = '376560840012201984';
export default class DiscordMod {
prestart() {
this.rpc = new DiscordRPC.Client({ transport: 'ipc' });
}
poststart() {
this.rpc.on('ready', () => {
this.setActivity();
// activity can only be set every 15 seconds
setInterval(() => this.setActivity(), 15e3);
});
this.rpc.login({ clientId: CLIENT_ID }).catch(console.error);
}
setActivity() {
if (this.rpc == null) return;
if (sc.model.isTitle() || !ig.ready) {
this.rpc.setActivity({
state: 'Menu',
details: 'In the menu',
largeImageKey: 'ducklea',
largeImageText: 'Menu',
instance: false,
});
return;
}
let area = getArea();
let areaName = sc.map.getCurrentAreaName().value;
let element = getCurrentElementName();
let timeStamp =
new Date().getTime() / 1000 - sc.stats.getMap('player', 'playtime');
let partySize = sc.party.getPartySize() + 1;
let partyMax = sc.PARTY_MAX_MEMBERS + 1;
this.rpc.setActivity({
details: getChapterText(),
state: getState(areaName),
startTimestamp: timeStamp,
partySize: partySize,
partyMax: partyMax,
smallImageKey: 'e-' + element.toLowerCase(),
smallImageText: element,
largeImageKey: getArtKey(area),
largeImageText: areaName,
instance: false,
});
}
}
function getState(areaName) {
let state;
if (sc.model.isPaused()) {
state = '(Paused)';
} else {
if (sc.pvp.isActive()) state = 'In a PvP';
else if (sc.combat.isInCombat(ig.game.playerEntity)) state = 'In combat';
else state = 'Exploring';
}
state += ' ' + areaName;
return state;
}
function getArea() {
// can be replaced with `sc.map.currentPlayerArea.path`, but that will require
// changing names of rich presence assets, and alas I don't have access to the
// application registered in Discord
return (ig.game.mapName || '???').split('.')[0];
}
function getChapterText() {
let chapter = sc.model.player.chapter;
let loreKey = `chapter-${chapter.toString().padStart(2, '0')}`;
return ig.LangLabel.bakeVars(sc.lore.getLoreTitle(loreKey));
}
const ART_LIST = [
'autumn',
'jungle-city',
'bergen',
'heat-dng',
'jungle',
'heat',
'rhombus-sqr',
'heat-village',
'rookie-harbor',
];
function getArtKey(area) {
return ART_LIST.includes(area) ? area : 'ducklea';
}
const ELEMENT_NAMES = ['Neutral', 'Heat', 'Cold', 'Shock', 'Wave'];
function getCurrentElementName() {
return ELEMENT_NAMES[sc.model.player.currentElementMode];
}