✨ Added request for database.
This commit is contained in:
parent
bb7c356b39
commit
f5a43c897c
33
bot.js
33
bot.js
|
@ -1,6 +1,8 @@
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const tmi = require('tmi.js');
|
const tmi = require('tmi.js');
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
|
const request = require('request');
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
hostname: 'api.twitch.tv',
|
hostname: 'api.twitch.tv',
|
||||||
port: 443,
|
port: 443,
|
||||||
|
@ -13,7 +15,6 @@ const options = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Define configuration options
|
// Define configuration options
|
||||||
const opts = {
|
const opts = {
|
||||||
identity: {
|
identity: {
|
||||||
|
@ -132,7 +133,11 @@ function onMessageHandler(target, context, msg, self) {
|
||||||
|
|
||||||
username = context["username"];
|
username = context["username"];
|
||||||
|
|
||||||
const json_for_sql = {
|
// Post request to database
|
||||||
|
request.post(
|
||||||
|
'https://api.plutodev.de/twitch-highlight-marker/addHighlight',
|
||||||
|
{
|
||||||
|
json: {
|
||||||
access_key: process.env.ACCESS_KEY,
|
access_key: process.env.ACCESS_KEY,
|
||||||
streamer: streamer,
|
streamer: streamer,
|
||||||
stream_id: stream_id,
|
stream_id: stream_id,
|
||||||
|
@ -140,13 +145,21 @@ function onMessageHandler(target, context, msg, self) {
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
description: description,
|
description: description,
|
||||||
username: username
|
username: username
|
||||||
};
|
}
|
||||||
|
},
|
||||||
// TODO send API request to database
|
function (error, response, body) {
|
||||||
|
if (!error && response.statusCode === 200) {
|
||||||
// ENGLISH: client.say(target, `Mark has been tracked for the next highlight video. Thank you for your submission ${username}! `);
|
// ENGLISH: client.say(target, `Mark has been tracked for the next highlight video. Thank you for your submission ${username}! `);
|
||||||
client.say(target, `Die Markierung wurde für das nächste Highlight Video gespeichert. Danke für deine Hilfe ${username}!`);
|
client.say(target, `Die Markierung wurde für das nächste Highlight Video gespeichert. Danke für deine Hilfe ${username}!`);
|
||||||
});
|
console.log(body);
|
||||||
|
} else {
|
||||||
|
client.say(target, `Leider ist etwas schief gelaufen. Versuch es bitte später erneut.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
})
|
})
|
||||||
req.end();
|
req.end();
|
||||||
} else {
|
} else {
|
||||||
|
@ -158,13 +171,13 @@ function onMessageHandler(target, context, msg, self) {
|
||||||
// readable decides if the words "hours", "minutes" and "seconds" should be added
|
// readable decides if the words "hours", "minutes" and "seconds" should be added
|
||||||
function getTimeInFormat(timeInMillis, readable) {
|
function getTimeInFormat(timeInMillis, readable) {
|
||||||
let hours = Math.floor(timeInMillis / 1000 / 60 / 60);
|
let hours = Math.floor(timeInMillis / 1000 / 60 / 60);
|
||||||
timeInMillis -= hours * 1000 * 60 * 60
|
timeInMillis -= hours * 1000 * 60 * 60;
|
||||||
let minutes = Math.floor((timeInMillis) / 1000 / 60);
|
let minutes = Math.floor((timeInMillis) / 1000 / 60);
|
||||||
timeInMillis -= minutes * 1000 * 60
|
timeInMillis -= minutes * 1000 * 60;
|
||||||
let seconds = Math.floor((timeInMillis) / 1000);
|
let seconds = Math.floor((timeInMillis) / 1000);
|
||||||
|
|
||||||
if (readable) {
|
if (readable) {
|
||||||
return hours + " Stunde/n " + minutes + " Minute/n " + seconds + " Sekunde/n"
|
return hours + " Stunde/n " + minutes + " Minute/n " + seconds + " Sekunde/n";
|
||||||
} else {
|
} else {
|
||||||
return hours + ":" + minutes + ":" + seconds;
|
return hours + ":" + minutes + ":" + seconds;
|
||||||
}
|
}
|
||||||
|
|
746
package-lock.json
generated
746
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -16,5 +16,8 @@
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"tmi.js": "^1.8.2",
|
"tmi.js": "^1.8.2",
|
||||||
"twitch-js": "*"
|
"twitch-js": "*"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"request": "^2.88.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user