9
10 function testfunction(category, list) {
11
12 var statuses = {} 13
14 list.forEach((key, keyIndex) => {
15
57 method: 'get'
58 })
59 .then(function (response) { return __awaiter(_this, void 0, void 0, function () {
60 var body;61 return __generator(this, function (_a) {
62 body = JSON.parse(response.data);
63 if (body.items) {
46 });
47 list.forEach(function (key, keyIndex) { return __awaiter(_this, void 0, void 0, function () {
48 var pathForYtRequest;
49 var _this = this;50 return __generator(this, function (_a) {
51 switch (_a.label) {
52 case 0:
45 statuses["daemon" + keyIndex] = "Loading...";
46 });
47 list.forEach(function (key, keyIndex) { return __awaiter(_this, void 0, void 0, function () {
48 var pathForYtRequest;49 var _this = this;
50 return __generator(this, function (_a) {
51 switch (_a.label) {
40var config = require('./config.json').config;
41function testfunction(category, list) {
42 var _this = this;
43 var statuses = {};44 list.forEach(function (key, keyIndex) {
45 statuses["daemon" + keyIndex] = "Loading...";
46 });
39var axios_1 = require("axios");
40var config = require('./config.json').config;
41function testfunction(category, list) {
42 var _this = this;43 var statuses = {};
44 list.forEach(function (key, keyIndex) {
45 statuses["daemon" + keyIndex] = "Loading...";
37};
38exports.__esModule = true;
39var axios_1 = require("axios");
40var config = require('./config.json').config;41function testfunction(category, list) {
42 var _this = this;
43 var statuses = {};
36 }
37};
38exports.__esModule = true;
39var axios_1 = require("axios");40var config = require('./config.json').config;
41function testfunction(category, list) {
42 var _this = this;
9 });
10};
11var __generator = (this && this.__generator) || function (thisArg, body) {
12 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;13 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14 function verb(n) { return function (v) { return step([n, v]); }; }
15 function step(op) {
8 step((generator = generator.apply(thisArg, _arguments || [])).next());
9 });
10};
11var __generator = (this && this.__generator) || function (thisArg, body) {12 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;13 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;14 function verb(n) { return function (v) { return step([n, v]); }; }15 function step(op) {16 if (f) throw new TypeError("Generator is already executing.");17 while (_) try {18 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;19 if (y = 0, t) op = [op[0] & 2, t.value];20 switch (op[0]) {21 case 0: case 1: t = op; break;22 case 4: _.label++; return { value: op[1], done: false };23 case 5: _.label++; y = op[1]; op = [0]; continue;24 case 7: op = _.ops.pop(); _.trys.pop(); continue;25 default:26 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }27 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }28 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }29 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }30 if (t[2]) _.ops.pop();31 _.trys.pop(); continue;32 }33 op = body.call(thisArg, _);34 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }35 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };36 }37};38exports.__esModule = true;
39var axios_1 = require("axios");
40var config = require('./config.json').config;
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 return new (P || (P = Promise))(function (resolve, reject) { 5 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 });10};11var __generator = (this && this.__generator) || function (thisArg, body) {
12 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
7 if (ytquery.includes("youtu.be/")) {
8 var precurser = ytquery.replace("youtu.be/", "www.youtube.com/watch?v=")
9 } else {
10 var precurser = ytquery 11 }
12 }
13
5 } else {
6 // Valid url
7 if (ytquery.includes("youtu.be/")) {
8 var precurser = ytquery.replace("youtu.be/", "www.youtube.com/watch?v=") 9 } else {
10 var precurser = ytquery
11 }
1function convertUrlToVideoId(ytquery) {
2 if (ytquery.match(/youtube.com\/shorts\//g)) {
3 console.log('match')
4 var precurser = ytquery.replace("?feature=share","").replace(/youtube.com\/shorts\//g, "youtube.com/watch?v=") 5 } else {
6 // Valid url
7 if (ytquery.includes("youtu.be/")) {
1const { config } = require('./config.json');
2
3const Discord = require('discord.js');
4var client = new Discord.Client({ intents: Discord.Intents.NON_PRIVILEGED, retryLimit: Infinity}); 5
6client.on('ready', () => {
7 console.log(`Logged in as ${client.user.tag}!`);
274
275 var apikeysdaemonarray = loadedAuthData.config.youtubeApiKeysDaemon
276
277 var theRandomApiKey = apikeysdaemonarray[Math.floor(Math.random()*apikeysdaemonarray.length)];278
279 const firstPartOfPath = "https://youtube.googleapis.com/youtube/v3/videos?part=statistics&id="
280
272
273 if (loadedAuthData.config.youtubeApiKeysDaemon) {
274
275 var apikeysdaemonarray = loadedAuthData.config.youtubeApiKeysDaemon276
277 var theRandomApiKey = apikeysdaemonarray[Math.floor(Math.random()*apikeysdaemonarray.length)];
278
254
255 if (shouldRun === false) {
256 if (row.added) {
257 var currentTime = row.added.getDate().getTime();258
259 if (currentTime) {
260 if (currentTime > (Date.now() - (86400 * 1000 * 3))) {
232 if (shouldRun === false) {
233 var thisVideoSectionNumber;
234
235 var firstCharacterHash = simpleHash(row.videoid).substring(0, 1)236
237 console.log('firstCharacterHash', firstCharacterHash)
238
230 var shouldRun = inputObj.runAll;
231
232 if (shouldRun === false) {
233 var thisVideoSectionNumber;234
235 var firstCharacterHash = simpleHash(row.videoid).substring(0, 1)
236
227 // logger.discordInfoLogger.info(row.videoid + ' in the database')
228 // console.log('get video try')
229
230 var shouldRun = inputObj.runAll;231
232 if (shouldRun === false) {
233 var thisVideoSectionNumber;
209
210export async function fetchStatsForAll(inputObj:fetchAllInterface) {
211
212 var queryFetchAllTrackedIds = "SELECT * FROM adorastats.trackedytvideosids"213
214 cassandraclient.execute(queryFetchAllTrackedIds)
215 .then((result) => {
176 timeUuid = TimeUuid.now()
177 }
178
179 var params = [statParams.videoid, 180 timeUuid,181 longOrEmpty(statParams.views),182 longOrEmpty(statParams.likes),183 longOrEmpty(statParams.dislikes),184 commentsLong]185
186 await cassandraclient.execute(query, params, {prepare: true})
187 .then(async result => {
168
169 var commentsLong = longOrEmpty(statParams.comments)
170
171 var timeUuid;172
173 if (statParams.time) {
174 timeUuid = TimeUuid.fromDate(statParams.time)
166export async function addStatsToYtVideo(statParams: statInterface) {
167 var query = "INSERT INTO adorastats.ytvideostats (videoid, time, views, likes, dislikes, comments) VALUES (?,?,?,?,?,?)"
168
169 var commentsLong = longOrEmpty(statParams.comments)170
171 var timeUuid;
172
It is recommended to use let
or const
over var
.
This will help prevent re-declaration of variables that are in the global scope when using var
.
ES6 allows programmers to create variables with block scope instead of function scope using the let
and const
keywords.
Block scope is common in many other programming languages and helps programmers avoid mistakes such as this one:
var count = people.length;
var enoughFood = count > sandwiches.length;
if (enoughFood) {
var count = sandwiches.length; // accidentally overriding the count variable
console.log("We have " + count + " sandwiches for everyone. Plenty for all!");
}
// our count variable is no longer accurate
console.log("We have " + count + " people and " + sandwiches.length + " sandwiches!");
Block scoped variables shadow outer declarations instead of writing to them.
NOTE: There are certain edge cases where users might want to consider var. Consider this example:
var lib = lib || { run: () => {} }
Here, lib
might be a library that is exposed to an HTML file using a <script>
tag.
The var
keyword helps avoid re-writing lib
if it has already been declared via an injected script that was executed before this one.
Ideally, you should let bundlers worry about cases like this.
But if you want to use var
anyway, consider using a skipcq comment, or disabling the issue altogether.
Bad Practice
var x = "y";
var CONFIG = {};
Recommended
let x = "y";
const CONFIG = {};