🚧 Added command !mark.
- missing functionality!
This commit is contained in:
parent
31531dabff
commit
ef8f20c762
71
bot.js
71
bot.js
|
@ -46,10 +46,13 @@ function onMessageHandler(target, context, msg, self) {
|
||||||
|
|
||||||
// If the command is known, let's execute it
|
// If the command is known, let's execute it
|
||||||
if (commandName === '!dice') {
|
if (commandName === '!dice') {
|
||||||
|
console.log(`* Executed ${commandName} command`);
|
||||||
|
|
||||||
const num = rollDice();
|
const num = rollDice();
|
||||||
client.say(target, `You rolled a ${num}`);
|
client.say(target, `You rolled a ${num}`);
|
||||||
console.log(`* Executed ${commandName} command`);
|
|
||||||
} else if (commandName === '!uptime') {
|
} else if (commandName === '!uptime') {
|
||||||
|
console.log(`* Executed ${commandName} command`);
|
||||||
|
|
||||||
let stream;
|
let stream;
|
||||||
let stream_time;
|
let stream_time;
|
||||||
const req = https.request(options, res => {
|
const req = https.request(options, res => {
|
||||||
|
@ -74,11 +77,77 @@ function onMessageHandler(target, context, msg, self) {
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
req.end();
|
req.end();
|
||||||
|
} else if (commandName.startsWith('!mark')) {
|
||||||
|
console.log(`* Executed ${commandName} command`);
|
||||||
|
|
||||||
|
let streamer;
|
||||||
|
let stream;
|
||||||
|
let stream_id;
|
||||||
|
let stream_game;
|
||||||
|
let description;
|
||||||
|
let username;
|
||||||
|
let timestamp;
|
||||||
|
|
||||||
|
|
||||||
|
const req = https.request(options, res => {
|
||||||
|
let data = [];
|
||||||
|
|
||||||
|
res.on('data', chunk => {
|
||||||
|
data.push(chunk);
|
||||||
|
});
|
||||||
|
|
||||||
|
res.on('end', () => {
|
||||||
|
stream = JSON.parse(Buffer.concat(data).toString());
|
||||||
|
if (!stream || !stream['stream'] || !stream['stream']['created_at']) {
|
||||||
|
client.say(target, `You can't do that now!`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const stream_time = stream['stream']['created_at'];
|
||||||
|
const dateStart = new Date(stream_time);
|
||||||
|
const dateEnd = new Date();
|
||||||
|
const timeDifference = Math.abs(dateEnd - dateStart);
|
||||||
|
|
||||||
|
|
||||||
|
// streamer | stream_id | game | description | timestamp | username
|
||||||
|
|
||||||
|
streamer = "yiggalow";
|
||||||
|
stream_id = stream['stream']['_id'];
|
||||||
|
stream_game = stream['stream']['game'];
|
||||||
|
timestamp = getTimeInHHMMSS(timeDifference);
|
||||||
|
description = commandName.substr(6,commandName.length-1);
|
||||||
|
username = context["username"];
|
||||||
|
|
||||||
|
const json_for_sql = {
|
||||||
|
access_key: process.env.ACCESS_KEY,
|
||||||
|
streamer: streamer,
|
||||||
|
stream_id: stream_id,
|
||||||
|
stream_game: stream_game,
|
||||||
|
timestamp: timestamp,
|
||||||
|
description: description,
|
||||||
|
username: username
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
client.say(target, `Mark has been tracked for the next highlight video! Thank you for your submission ${username}. `);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
req.end();
|
||||||
} else {
|
} else {
|
||||||
console.log(`* Unknown command ${commandName}`);
|
console.log(`* Unknown command ${commandName}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTimeInHHMMSS(timeInMillis) {
|
||||||
|
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+":"+minutes+":"+seconds;
|
||||||
|
}
|
||||||
|
|
||||||
function getTimeInFormat(timeInMillis) {
|
function getTimeInFormat(timeInMillis) {
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user