-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
460 lines (391 loc) · 13 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
const { Client, Intents } = require("discord.js");
const { token, config_domain, config_port, defaultPower } = require("./config.json");
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const fetch = (...args) =>
import("node-fetch").then(({ default: fetch }) => fetch(...args));
const returnMessages = [
"Spank me!",
"I love when you play with me",
"Oh baby, that feels good",
"Keep going harder.",
"This feels amazing.",
"Right there!!",
"Harder, baby.",
"Mmmmmmm!",
"You make me so wet!",
"I wish you were fucking me",
"Send me over the edge",
"Give me more",
"Fuck my tight ass",
"Make me cum!",
"I want more",
"It feels so good",
"Make me squirt!",
];
var availableToys = [];
var domain, port, platform;
// replace with fetch.
fetch("https://api.lovense.com/api/lan/getToys")
.then(async (response) => {
var lovenseConfig = await response.json();
var keys = Object.keys(lovenseConfig);
if (keys.length === 0) {
if (config_domain !== "" && config_port !== "") {
directConfig();
}
else {
console.error("No information found in Lovense Config");
console.error(
"Please check you are running the Lovense CONNECT (not remote) App on your Phone or Desktop PC."
);
console.error(
"Please also check that you can see information returned from: https://api.lovense.com/api/lan/getToys website."
);
console.warn(
"If this continues to fail again and again... You can go to the URL Above and use the \"domain\" and \"httpsPort\" (not httpPort) and place them into the config_domain and config_port in the config.json file."
)
console.error("");
process.exit(1);
}
}
else if (keys.length > 1) {
console.error(
"Multiple connected users on same network, currently not setup to support this."
);
process.exit(1);
}
else {
domain = keys[0];
var lovenseDetails = lovenseConfig[domain];
port = lovenseDetails.httpsPort;
platform = lovenseDetails.platform;
console.log("Lovense Details: ");
console.log("Domain: " + domain);
console.log("Port (Secure): " + port);
console.log("Device: " + platform);
console.log("Toys:");
for (const [toyId, toyDetails] of Object.entries(lovenseDetails.toys)) {
var nickname =
toyDetails.nickName !== ""
? `${toyDetails.nickName} - (${toyDetails.name})`
: toyDetails.name;
console.log(
`${nickname}: (${toyDetails.id}) `+
`[Version: ${toyDetails.version}] `+
`[Battery: ${toyDetails.battery.toString().padStart(3, ' ')}] `+
`${toyDetails.status === 1 ? "Connected" : "Disconnected"}`
);
availableToys.push({
toy: nickname,
nickName: toyDetails.nickName,
id: toyDetails.id,
});
}
startBot();
}
})
.catch((error) => {
console.error(
"Failed to load the Lovense API for Toy Information. This can be due to many reasons."
);
console.error("Please provide the following if you have any issues:");
console.error(error);
process.exit(1);
});
function directConfig() {
fetch(`https://${config_domain}:${config_port}/GetToys`)
.then(async (data) => {
var response = await data.json();
if (response.code === "200") {
domain = config_domain;
port = config_port;
platform = config_domain.indexOf('127-0-0-1') !== -1 ? "pc" : "mobile (unknown)"
console.log("Lovense Details: ");
console.log("Domain: " + domain);
console.log("Port (Secure): " + port);
console.log("Device: " + platform);
console.log("Toys:");
for (const [toyId, toyDetails] of Object.entries(response.data)) {
var nickname =
toyDetails.nickName !== ""
? `${toyDetails.nickName} - (${toyDetails.name})`
: toyDetails.name;
console.log(
` ${nickname}: (${toyDetails.id}) `+
`[Version: ${toyDetails.version}] `+
`[Battery: ${toyDetails.battery.toString().padStart(3, ' ')}] `+
`${toyDetails.status === 1 ? "Connected" : "Disconnected"}`
);
availableToys.push({
toy: nickname,
nickName: toyDetails.nickName,
id: toyDetails.id,
});
}
startBot();
}
else {
console.error(
`Lovense API returned a Unexpected code of ${response.code}`
);
console.error(
`Please provide the following details in the error report:`
)
console.error(response)
process.exit(1);
}
})
}
function startBot() {
client.once("ready", () => {
console.log("LolaBot 4.0.0 - Ready to Play!");
});
client.on("interactionCreate", async (interaction) => {
if (!interaction.isCommand()) return;
const { commandName, options } = interaction;
switch (commandName) {
case "ping":
await interaction.reply("Pong!"); // Test command
break;
case "server":
await interaction.reply(
`Server name: ${interaction.guild.name}\nTotal members: ${interaction.guild.memberCount}`
);
break;
case "user":
await interaction.reply(
`Your tag: ${interaction.user.tag}\nYour id: ${interaction.user.id}`
);
break;
case "battery":
// "Bot" is thinking...
// We need to "edit" the reply afterwards
await interaction.deferReply();
var selectedToy = options.getString("toy", false);
var params = {};
await fetch(lovenseUrl("GetToys", params))
.then(async (request) => {
var toyInfo = await request.json();
var outputMessage =
"Toy Battery" +
(Object.entries(toyInfo.data).length > 1 && selectedToy === null ? "s" : "") +
":";
for (const [toyId, toyDetails] of Object.entries(toyInfo.data)) {
// Only get the user selected Toys.
if (selectedToy !== null && selectedToy !== toyId) {
continue;
}
var nickname =
toyDetails.nickName !== ""
? `${toyDetails.nickName} - (${toyDetails.name})`
: toyDetails.name;
outputMessage +=
`\n> ${nickname}: \`${toyDetails.battery.toString().padStart(3, ' ')}\` | `+
`${toyDetails.status === 1 ? "Connected" : "Disconnected"}`;
}
interaction.editReply( outputMessage );
})
.catch((e) => {
interaction.editReply("Failed to get Battery ;-;");
console.log("Error has been encountered while trying to get Battery:", e);
});
break;
case "vibrate":
var toy = options.getString("toy");
var power = options.getInteger("power", false);
if (!power) { power = defaultPower; }
var params = {
sec: 0,
v: power
}
if (toy !== 'ALL') {
params.t = toy;
}
await fetch(lovenseUrl("AVibrate", params));
interaction.reply(getRandomMessage());
break;
case "stopvibrate":
var toy = options.getString("toy");
var params = {
sec: 0,
v: 0
}
if (toy !== 'ALL') {
params.t = toy;
}
await fetch(lovenseUrl("AVibrate", params));
interaction.reply(
`Stopping ${getToyName(toy)}`
);
break;
// ==============================
// PRESET SPECIFIC COMMANDS
case "pulse":
case "circle":
case "grind":
var toy = options.getString("toy");
var params = {
sec: 0,
v:
commandName === "pulse"
? 1
: commandName === "circle"
? 2
: commandName === "grind"
? 3
: 0, // Something?
};
if (toy !== "ALL") {
params.t = toy;
}
await fetch(lovenseUrl("Preset", params)).then((response) =>
response.json()
);
interaction.reply(getRandomMessage());
break;
// ==============================
// EDGE SPECIFIC COMMANDS
case "vibrateedge":
var location = options.getString("location");
var toy = options.getString("toy");
var power = options.getInteger("power", false)
if (!power) { power = defaultPower; }
var params = {
sec: 0,
v: power
}
if (toy !== "ALL") {
params.t = toy;
}
if (location === "top") {
await fetch(lovenseUrl("AVibrate1", params)).then((response) => {
response.json()
});
}
else if (location === "bottom") {
await fetch(lovenseUrl("AVibrate2", params)).then((response) => {
response.json()
});
}
interaction.reply(getRandomMessage());
break;
// ==============================
// NORA SPECIFIC COMMANDS
case "rotateleft":
var toy = options.getString("toy");
var power = options.getInteger("power", false)
if (!power) { power = defaultPower; }
var params = {
v: power
}
if (toy !== "ALL") {
params.t = toy;
}
await fetch(lovenseUrl("ARotateAntiClockwise", params)).then((response) =>
response.json()
);
interaction.reply(getRandomMessage());
break;
case "rotateright":
var toy = options.getString("toy");
var power = options.getInteger("power", false)
if (!power) { power = defaultPower; }
var params = {
v: power
}
if (toy !== "ALL") {
params.t = toy;
}
await fetch(lovenseUrl("ARotateClockwise", params)).then((response) =>
response.json()
);
interaction.reply(getRandomMessage());
break;
case "stoprotate":
var toy = options.getString("toy");
var params = {
v: 0
}
if (toy !== "ALL") {
params.t = toy;
}
await fetch(lovenseUrl("ARotateAntiClockwise", params)).then((response) =>
response.json()
);
interaction.reply(
`Stopping rotating on ${getToyName(options.getString("toy"))}`
);
break;
// ==============================
// LEGACY COMMANDS based upon the original re-make
case "low":
case "medium":
case "high":
case "stop":
var toy = options.getString("toy");
var params = {
sec: 0,
v:
commandName === "high"
? 20
: commandName === "medium"
? 10
: commandName === "low"
? 1
: 0, // Stop
};
if (toy !== "ALL") {
params.t = toy;
}
await fetch(lovenseUrl("AVibrate", params));
if (commandName === "stop") {
interaction.reply(
`Stopping ${getToyName(toy)}`
);
} else {
interaction.reply(getRandomMessage());
}
break;
}
});
client.login(token);
}
// ============================================================================
// Helper Functions
function lovenseUrl(endpoint, values) {
if (endpoint.indexOf("A") === 0 && platform == "pc") {
endpoint = endpoint.substring(1); // Removes the A for PC specific.
}
return (
`https://${domain}:${port}/${endpoint}` +
(Object.keys(values).length > 0 ? `?${getProp(values)}` : "")
);
function getProp(myData) {
var out = [];
for (var key in myData) {
if (myData.hasOwnProperty(key)) {
out.push(key + "=" + encodeURIComponent(myData[key]));
}
}
return out.join("&");
}
}
/**
* Get a Toy's Name from it's ID. Helpful when getting stuff from Discord's response. (Returns "All Toys" on "ALL" ID)
* @param {String} id ID of a Toy
* @returns Toy's Name
*/
function getToyName(id) {
if (id === "ALL") {
return "All Toys";
}
var toy = availableToys.filter((toy) => toy.id === id);
return toy.length === 1
? toy[0].nickName !== "" && toy[0].nickName !== undefined
? toy[0].nickName
: toy[0].toy
: null;
}
function getRandomMessage() {
return returnMessages[Math.floor(Math.random() * returnMessages.length)];
}