📝 Writing docs...
This commit is contained in:
parent
ef8f20c762
commit
bb7c356b39
66
bot.js
66
bot.js
|
@ -55,29 +55,36 @@ function onMessageHandler(target, context, msg, self) {
|
||||||
|
|
||||||
let stream;
|
let stream;
|
||||||
let stream_time;
|
let stream_time;
|
||||||
|
|
||||||
|
// Send request to Twitch API with client-id and oauth token
|
||||||
const req = https.request(options, res => {
|
const req = https.request(options, res => {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
|
||||||
res.on('data', chunk => {
|
res.on('data', chunk => {
|
||||||
|
// Saving data of response to variable data
|
||||||
data.push(chunk);
|
data.push(chunk);
|
||||||
});
|
});
|
||||||
|
|
||||||
res.on('end', () => {
|
res.on('end', () => {
|
||||||
|
// Parse data as JSON to variable stream
|
||||||
stream = JSON.parse(Buffer.concat(data).toString());
|
stream = JSON.parse(Buffer.concat(data).toString());
|
||||||
|
|
||||||
|
// Check if stream is online or not
|
||||||
if (!stream || !stream['stream'] || !stream['stream']['created_at']) {
|
if (!stream || !stream['stream'] || !stream['stream']['created_at']) {
|
||||||
client.say(target, `Uptime: not available`);
|
client.say(target, `Uptime: not available`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream_time = stream['stream']['created_at'];
|
stream_time = stream['stream']['created_at'];
|
||||||
const dateStart = new Date(stream_time);
|
const dateStart = new Date(stream_time);
|
||||||
const dateEnd = new Date();
|
const dateEnd = new Date();
|
||||||
const timeDifference = Math.abs(dateEnd - dateStart);
|
const timeDifference = Math.abs(dateEnd - dateStart);
|
||||||
client.say(target, `Uptime: ${getTimeInFormat(timeDifference)}`);
|
|
||||||
console.log(`* Executed ${commandName} command`);
|
client.say(target, `Uptime: ${getTimeInFormat(timeDifference, true)}`);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
req.end();
|
req.end();
|
||||||
} else if (commandName.startsWith('!mark')) {
|
} else if (commandName.startsWith('!mark')) { // Description comes after a whitespace e.g.: "!mark DESCRIPTION"
|
||||||
console.log(`* Executed ${commandName} command`);
|
console.log(`* Executed ${commandName} command`);
|
||||||
|
|
||||||
let streamer;
|
let streamer;
|
||||||
|
@ -89,32 +96,40 @@ function onMessageHandler(target, context, msg, self) {
|
||||||
let timestamp;
|
let timestamp;
|
||||||
|
|
||||||
|
|
||||||
|
// Send request to Twitch API with client-id and oauth token
|
||||||
const req = https.request(options, res => {
|
const req = https.request(options, res => {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
|
||||||
res.on('data', chunk => {
|
res.on('data', chunk => {
|
||||||
|
// Saving data of response to variable data
|
||||||
data.push(chunk);
|
data.push(chunk);
|
||||||
});
|
});
|
||||||
|
|
||||||
res.on('end', () => {
|
res.on('end', () => {
|
||||||
|
// Parse data as JSON to variable stream
|
||||||
stream = JSON.parse(Buffer.concat(data).toString());
|
stream = JSON.parse(Buffer.concat(data).toString());
|
||||||
|
|
||||||
|
// Check if stream is online or not
|
||||||
if (!stream || !stream['stream'] || !stream['stream']['created_at']) {
|
if (!stream || !stream['stream'] || !stream['stream']['created_at']) {
|
||||||
client.say(target, `You can't do that now!`);
|
client.say(target, `You can't do that now!`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stream_time = stream['stream']['created_at'];
|
const stream_time = stream['stream']['created_at'];
|
||||||
const dateStart = new Date(stream_time);
|
const dateStart = new Date(stream_time);
|
||||||
const dateEnd = new Date();
|
const dateEnd = new Date();
|
||||||
const timeDifference = Math.abs(dateEnd - dateStart);
|
const timeDifference = Math.abs(dateEnd - dateStart);
|
||||||
|
|
||||||
|
|
||||||
// streamer | stream_id | game | description | timestamp | username
|
|
||||||
|
|
||||||
streamer = "yiggalow";
|
streamer = "yiggalow";
|
||||||
stream_id = stream['stream']['_id'];
|
stream_id = stream['stream']['_id'];
|
||||||
stream_game = stream['stream']['game'];
|
stream_game = stream['stream']['game'];
|
||||||
timestamp = getTimeInHHMMSS(timeDifference);
|
timestamp = getTimeInFormat(timeDifference, false);
|
||||||
description = commandName.substr(6,commandName.length-1);
|
description = commandName.substr(6, commandName.length - 1);
|
||||||
|
|
||||||
|
if (description.trim().length < 3) {
|
||||||
|
description = "No Description";
|
||||||
|
}
|
||||||
|
|
||||||
username = context["username"];
|
username = context["username"];
|
||||||
|
|
||||||
const json_for_sql = {
|
const json_for_sql = {
|
||||||
|
@ -127,9 +142,10 @@ function onMessageHandler(target, context, msg, self) {
|
||||||
username: username
|
username: username
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO send API request to database
|
||||||
|
|
||||||
|
// ENGLISH: client.say(target, `Mark has been tracked for the next highlight video. Thank you for your submission ${username}! `);
|
||||||
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}! `);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
req.end();
|
req.end();
|
||||||
|
@ -138,24 +154,20 @@ function onMessageHandler(target, context, msg, self) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTimeInHHMMSS(timeInMillis) {
|
// Function for formatting time from millis to normal
|
||||||
let hours = Math.floor(timeInMillis/1000/60/60);
|
// readable decides if the words "hours", "minutes" and "seconds" should be added
|
||||||
timeInMillis -= hours*1000*60*60
|
function getTimeInFormat(timeInMillis, readable) {
|
||||||
let minutes = Math.floor((timeInMillis)/1000/60);
|
let hours = Math.floor(timeInMillis / 1000 / 60 / 60);
|
||||||
timeInMillis -= minutes*1000*60
|
timeInMillis -= hours * 1000 * 60 * 60
|
||||||
let seconds = Math.floor((timeInMillis)/1000);
|
let minutes = Math.floor((timeInMillis) / 1000 / 60);
|
||||||
|
timeInMillis -= minutes * 1000 * 60
|
||||||
|
let seconds = Math.floor((timeInMillis) / 1000);
|
||||||
|
|
||||||
return hours+":"+minutes+":"+seconds;
|
if (readable) {
|
||||||
}
|
return hours + " Stunde/n " + minutes + " Minute/n " + seconds + " Sekunde/n"
|
||||||
|
} else {
|
||||||
function getTimeInFormat(timeInMillis) {
|
return hours + ":" + minutes + ":" + seconds;
|
||||||
let hours = Math.floor(timeInMillis/1000/60/60);
|
}
|
||||||
timeInMillis -= hours*1000*60*60
|
|
||||||
let minutes = Math.floor((timeInMillis)/1000/60);
|
|
||||||
timeInMillis -= minutes*1000*60
|
|
||||||
let seconds = Math.floor((timeInMillis)/1000);
|
|
||||||
|
|
||||||
return hours + " Stunde/n " + minutes + " Minute/n " + seconds + " Sekunde/n"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function called when the "dice" command is issued
|
// Function called when the "dice" command is issued
|
||||||
|
|
Loading…
Reference in New Issue
Block a user