This repository has been archived by the owner on Jul 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
169 lines (165 loc) · 6 KB
/
index.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
const DiscordRPC = require("discord-rpc");
const fs = require('fs');
const rpc = new DiscordRPC.Client({transport: 'ipc'});
const inquirer = require("inquirer");
fs.access("config.json", async (err) => {
if (err) {
console.log("File doesnt exists. Let's create one.")
await createConfigFile("config.json")
console.log("config.json file successfully created. Restarting in 5 seconds...")
setTimeout(async () => {
await startRpc('./config.json')
}, 5000);
} else {
await startRpc('./config.json')
}
});
async function createConfigFile(fileName) {
await inquirer.prompt([{
name: "clientid",
type: "input",
message: "What is your client id?",
}, {
name: "details",
type: "input",
message: "What is your first text (detail) ?",
}, {
name: "state",
type: "input",
message: "What is your second text (state) ?",
}, {
name: "images",
type: "list",
message: "Do you want images ?",
choices: ["No Image","Large Image","Small Image","Large and Small Images"]
}, {
name: "buttons",
type: "list",
message: "Do you want buttons ?",
choices: ["No buttons","1 Button","2 Buttons"]
}]).then(async(answer) => {
switch (answer.images) {
case "Large Image":
await inquirer.prompt([{
name: "largeImageKey",
type: "input",
message: "What is your large image key?",
},{
name: "largeImageText",
type: "input",
message: "What is your large image text?",
}]).then((imageAnswers) => {
answer.images = imageAnswers
})
break;
case "Small Image":
await inquirer.prompt([{
name: "smallImageKey",
type: "input",
message: "What is your small image key?",
},{
name: "smallImageText",
type: "input",
message: "What is your small image text?",
}]).then((imageAnswers) => {
answer.images = imageAnswers
})
break;
case "Large and Small Images":
await inquirer.prompt([{
name: "largeImageKey",
type: "input",
message: "What is your large image key?",
},{
name: "largeImageText",
type: "input",
message: "What is your large image text?",
},{
name: "smallImagekey",
type: "input",
message: "What is your small image key?",
},{
name: "smallImageText",
type: "input",
message: "What is your small image text?",
}]).then((imageAnswers) => {
answer.images = imageAnswers
})
break;
}
switch (answer.buttons) {
case "1 Button":
await inquirer.prompt([{
name: "label",
type: "input",
message: "What is your button text?",
},{
name: "url",
type: "input",
message: "What is your button url?",
}]).then((buttonAnswers) => {
let buttons = [{
label: buttonAnswers.label,
url: buttonAnswers.url
}]
answer.buttons = buttons
})
break;
case "2 Buttons":
await inquirer.prompt([{
name: "label1",
type: "input",
message: "What is your button 1 text?",
},{
name: "url1",
type: "input",
message: "What is your button 1 url?",
},{
name: "label2",
type: "input",
message: "What is your button 2 text?",
},{
name: "url2",
type: "input",
message: "What is your button 2 url?",
}]).then((buttonAnswers) => {
let firstButton = {label: buttonAnswers.label1,url: buttonAnswers.url1}
let secondButton = {label: buttonAnswers.label2,url: buttonAnswers.url2}
let buttons = [firstButton,secondButton]
answer.buttons = buttons
})
break;
}
let configDatas = {
clientId: answer.clientid,
staticActivityOptions: {
details: answer.details,
state: answer.state
}
}
if(typeof(answer.images) == 'object'){
Object.keys(answer.images).forEach(key => {
configDatas.staticActivityOptions[key] = answer.images[key]
})
}
if(answer.buttons != "No buttons"){
configDatas.staticActivityOptions["buttons"] = []
let configbuttons = []
answer.buttons.forEach(button => {
configbuttons.push(button)
});
configDatas.staticActivityOptions["buttons"] = configbuttons
}
const content = JSON.stringify(configDatas);
fs.writeFileSync(fileName, content);
});
}
async function startRpc(configFile) {
const {clientId,staticActivityOptions} = require(configFile);
DiscordRPC.register(clientId);
rpc.on('ready', () => {
if (!rpc) return;
rpc.setActivity(staticActivityOptions).then(drpc => console.log(`Running ${drpc.name}`))
})
rpc.login({clientId}).catch(console.error);
}