-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
121 lines (102 loc) · 2.9 KB
/
index.ts
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import RPC from "discord-rpc";
import Enquirer from "enquirer";
const clientId = "1203759686776528977";
const client = new RPC.Client({ transport: "ipc" });
const possibleStates = [
"Designing",
"Prototyping",
"Collaborating",
"Presenting",
"Developing"
];
interface IliveSettings {
details: string
state: string
largeImageKey: string
largeImageText: string
smallImageKey: string
smallImageText: string
label: string
url: string
}
const goLive = (liveSettings: IliveSettings) => {
client.on("ready", () => {
client.setActivity({
startTimestamp: Date.now(),
details: liveSettings.details,
state: liveSettings.state,
largeImageKey: liveSettings.largeImageKey,
largeImageText: liveSettings.largeImageText,
smallImageKey : liveSettings.smallImageKey,
smallImageText : liveSettings.smallImageText,
buttons: [
{
label: liveSettings.label,
url: liveSettings.url
},
]
});
});
client.login({ clientId }).catch(console.error);
};
console.log("Welcome to Figma Discord RPC !!");
let onBoarding : Partial<IliveSettings> = {};
let isIdle : Partial<{ idle: boolean }> = {};
let hasConnectedOnce = false;
let isAskOpen = false;
const ask = async () => {
console.log("Asking for status");
if(isAskOpen) return;
isAskOpen = true;
isIdle = await Enquirer.prompt({
type: "confirm",
name: "idle",
message: "Are you Idle?",
});
if(hasConnectedOnce) {
await client.clearActivity();
}
if (isIdle.idle) {
statusRunner({
details: "Probably taking a break or doing something else.",
state: "AFK",
largeImageKey: "figma_main_logo",
largeImageText: "Zzz....",
smallImageKey: "figma_frame_sec",
smallImageText: "Figma RPC by @bravo68web",
label: "Github Repo",
url: "https://gtihub.com/thenestdevs/figma-discord-rpc"
});
console.log("RPC is now live !!");
}
else {
onBoarding = await Enquirer.prompt([
{
type: "input",
name: "details",
message: "Enter the details of your activity"
},
]);
statusRunner({
details: onBoarding.details!,
state: isIdle.idle ? "AFK" : possibleStates[Math.floor(Math.random() * possibleStates.length)],
largeImageKey: "figma_main_logo",
largeImageText: possibleStates[Math.floor(Math.random() * possibleStates.length)] + " with Figma",
smallImageKey: "figma_frame_primary",
smallImageText: "Figma RPC by @bravo68web",
label: "Github Repo",
url: "https://gtihub.com/thenestdevs/figma-discord-rpc"
});
console.log("RPC is now live !!");
}
console.log("Asking for status is now closed");
hasConnectedOnce = true;
isAskOpen = false;
};
console.log("Starting Figma Discord RPC !!");
const statusRunner = async (stuff: IliveSettings) => {
goLive(stuff);
};
setInterval(() => {
if(!isAskOpen) ask();
}, 2000);