-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
100 lines (89 loc) · 2.92 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
import got from 'got';
import puppeteer from 'puppeteer';
import cheerio from 'cheerio';
// Get the stream name from the event
var streamName = 'streamname';
var streamerId = '123456789';
var authToken = '123456789_longtoken_verylong';
console.log('whats happening');;;
// Request https://streamelements.com/${streamName}/commands with puppeteer then get the body html
const browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-setuid-sandbox'],
headless: true
});
const page = await browser.newPage();
await page.goto(`https://streamelements.com/${streamName}/commands`, {
waitUntil: "networkidle0",
});
const html = await page.content();
await browser.close();
// Load the html into cheerio
const $ = cheerio.load(html);
// Get the commands
var commands = [];
// Loop through each command
// Get .md-row within tbody
$("tbody")
.find(".md-row")
.each(function (i, elem) {
// Get the command name
var commandName = $(this).find(".md-cell").first().text();
// Get the command message in .command-message
var commandMessage = $(this).find(".command-message").text();
// Get command cost
var commandCost = $(this).find(".md-cell").last().text();
// Add the command to the commands array
commands.push({
name: commandName,
message: commandMessage,
cost: commandCost,
});
});
// For each command create a new command
for (var i = 0; i < commands.length; i++) {
// Get the command
var command = commands[i];
try {
// Create new command by posting to https://api.streamelements.com/kappa/v2/bot/commands/${streamerId}
// Add authorization: Bearer ${authToken} to header
let commandPost = await got.post(
`https://api.streamelements.com/kappa/v2/bot/commands/${streamerId}`,
{
headers: {
Authorization:
`Bearer ${authToken}`,
},
json: {
_id: "",
accessLevel: 100,
aliases: [],
channel: "",
command: `${command.name.replace("!", "")}`,
cooldown: {
global: 5,
user: 15,
},
cost: `${parseInt(command.cost)}`,
enabled: true,
enabledOffline: true,
enabledOnline: true,
hidden: false,
keywords: [],
regex: "",
reply: `${command.message}`,
type: "say",
updatedAt: "",
new: {
type: "new",
template: "",
},
},
responseType: "json",
}
);
console.log('success');
} catch (error) {
console.log(error);
}
}
console.log('done');