How to use writeResult method in wpt

Best JavaScript code snippet using wpt

server.js

Source:server.js Github

copy

Full Screen

...40function startHandler() {41 console.log('Server listening on port ' + process.env.PORT);42}43//sends results to client44function writeResult(res, obj) {45 res.writeHead(200, { 'Content-Type': 'application/json' });46 res.write(JSON.stringify(obj));47 res.end('');48}49// Registers a new user and stores their info in database, then logs the user in50function register(req, res) {51 validateEmail(req.query.email, function (regError) {52 if (!regError) {53 writeResult(res, { 'regError': "Email invalid or already used." });54 }55 else {56 validatePassword(req.query.password, function (regError) {57 if (!regError) {58 writeResult(res, { 'regError': "Password must have a minimum of eight characters, at least one letter and one number" });59 }60 else if (req.query.Q1 == req.query.Q2) {61 writeResult(res, { 'regError': "Please choose different questions for your security questions." });62 }63 else {64 var con = mysql.createConnection(conInfo);65 con.connect(function (err) {66 if (err)67 writeResult(res, { 'error': err });68 else {69 if (req.query.A1 == null || req.query.A1 == "" || req.query.A2 == null || req.query.A2 == "") {70 writeResult(res, { 'regError': "Answer field cannot be empty" })71 }72 //Storing the info in the database73 else {74 let hashPass = bcrypt.hashSync(req.query.password, 12);75 let hashA1 = bcrypt.hashSync(req.query.A1, 12);76 let hashA2 = bcrypt.hashSync(req.query.A2, 12);77 con.query("INSERT INTO ACCOUNT (ACC_EMAIL, ACC_PASSWORD, ACC_QUESTION_ONE, ACC_ANSWER_ONE, ACC_QUESTION_TWO, ACC_ANSWER_TWO) VALUES (?, ?, ?, ?, ?, ?)", [req.query.email, hashPass, req.query.Q1, hashA1, req.query.Q2, hashA2], function (err, result, fields) {78 if (err) {79 writeResult(res, { 'error': err });80 console.log(err);81 }82 // the user in83 else {84 con.query("SELECT * FROM ACCOUNT WHERE ACC_EMAIL = ?", [req.query.email], function (err, result, fields) {85 if (err)86 writeResult(res, { 'error': err });87 else {88 req.session.user = { 'id': result[0].ACC_ID, 'email': result[0].ACC_EMAIL };89 writeResult(res, { 'email': req.session.user, 'regError': "" });90 }91 });92 }93 });94 }95 }96 });97 }98 });99 }100 });101}102//Gets all snippets from DB to populate table with103//Can take queries for "order" and "filter"104//req.query.category, req.query.order, req.query.filter105function getSnippets(req, res) {106 let result = {};107 var con = mysql.createConnection(conInfo);108 con.connect(function (err) {109 if (err)110 writeResult(res, { 'error': err });111 else {112 console.log([req.query.filter, req.query.category, req.query.order]);113 //create filter114 let filter = "%" + req.query.filter + "%";115 //select snippets with filter, ordering, etc116 con.query('SELECT * FROM SNIPPET WHERE SNIP_LANG LIKE ? OR SNIP_CREATOR LIKE ? OR SNIP_DESC LIKE ? ORDER BY ' + req.query.category + " " + req.query.order, [filter, filter, filter], function (err, result, fields) {117 if (err)118 writeResult(res, { 'error': err });119 else {120 writeResult(res, { 'result': result });121 }122 });123 }124 });125}126//Returns all security questions from DB to populate dropdown menu in register modal127function getQuestions(req, res) {128 var con = mysql.createConnection(conInfo);129 con.connect(function (err) {130 if (err)131 writeResult(res, { 'error': err });132 else {133 con.query('SELECT * FROM QUESTION', function (err, result, fields) {134 if (err)135 writeResult(res, { 'error': err });136 else {137 writeResult(res, { 'questions': result })138 }139 });140 }141 });142}143//Returns all languages from DB to populate dropdown menu in create snippet modal144function getLanguages(req, res) {145 var con = mysql.createConnection(conInfo);146 con.connect(function (err) {147 if (err)148 writeResult(res, { 'error': err });149 else {150 con.query('SELECT * FROM LANGUAGES', function (err, result, fields) {151 if (err)152 writeResult(res, { 'error': err });153 else {154 writeResult(res, { 'languages': result })155 }156 });157 }158 });159}160//Gets user's security questions for change password modal161//Requires user Email162//req.query.email 163function getUserQuestions(req, res) {164 if (req.session.id != null) {165 if (req.query.email == undefined || req.query.email == "") {166 writeResult(res, { 'changePassError': "Email undefined" });167 console.log("Email empty");168 }169 else {170 var con = mysql.createConnection(conInfo);171 con.connect(function (err) {172 if (err)173 writeResult(res, { 'error': err });174 else {175 //get account id, used later to find user's questions176 con.query('SELECT ACCOUNT.ACC_ID FROM ACCOUNT WHERE ACCOUNT.ACC_EMAIL = ?', [req.query.email], function (err, id, fields) {177 if (err)178 writeResult(res, { 'error': err });179 else {180 if (id.length == 0) {181 console.log("No emails found");182 writeResult(res, { 'changePassError': "Email does not exist" });183 }184 else {185 //use account id to get user's questions186 con.query('SELECT QUESTION.QUEST_TEXT FROM ACCOUNT INNER JOIN QUESTION ON ACCOUNT.ACC_QUESTION_TWO = QUEST_ID WHERE ACCOUNT.ACC_ID = ' + id[0].ACC_ID + ' UNION SELECT QUESTION.QUEST_TEXT FROM ACCOUNT INNER JOIN QUESTION ON ACCOUNT.ACC_QUESTION_ONE = QUEST_ID WHERE ACCOUNT.ACC_ID = ' + id[0].ACC_ID, function (err, result, fields) {187 if (err)188 writeResult(res, { 'error': err });189 else {190 writeResult(res, { 'userQuestions': result, 'changePassError': "" });191 }192 });193 }194 }195 });196 }197 });198 }199 }200 else {201 writeResult(res, { 'error': "user is already logged in" });202 }203}204//Checks if security answers are correct, if new password is valid. Changes User's password if both conditions are met205//Takes Email, new Password, Security Answer 1, Security Answer 2206//req.query.email, req.query.password, req.query.Answer1, req.query.Answer2207function changePass(req, res) {208 if (req.query.Answer1 == undefined || req.query.Answer2 == undefined) {209 writeResult(res, { 'changePassError': "Answer fields cannot be blank" });210 }211 else {212 validatePassword(req.query.password, function (err) {213 if (!err) {214 console.log("password fault");215 writeResult(res, { 'changePassError': "Password must have a minimum of eight characters, at least one letter and one number" });216 }217 else {218 var con = mysql.createConnection(conInfo);219 //Get account id by their email220 con.query('SELECT ACCOUNT.ACC_ID FROM ACCOUNT WHERE ACCOUNT.ACC_EMAIL = ?', [req.query.email], function (err, id, fields) {221 if (err)222 writeResult(res, { 'error': err });223 else {224 if (id == null || id[0] == undefined) {225 console.log("invalid email");226 writeResult(res, { 'changePassError': "Invalid Email" })227 }228 else {229 //Get user's account info from their account ID230 con.query('SELECT * FROM ACCOUNT WHERE ACCOUNT.ACC_ID = ' + id[0].ACC_ID, function (err, result, fields) {231 //check that security question answers are correct, changes password if they are232 if (bcrypt.compareSync(req.query.Answer1, result[0].ACC_ANSWER_ONE) && bcrypt.compareSync(req.query.Answer2, result[0].ACC_ANSWER_TWO)) {233 let hashPass = bcrypt.hashSync(req.query.password, 12);234 con.query('UPDATE ACCOUNT SET ACCOUNT.ACC_PASSWORD = ? WHERE ACCOUNT.ACC_ID = ' + id[0].ACC_ID, [hashPass], function (err, result, fields) {235 if (err) {236 console.log("password not changed");237 writeResult(res, { 'error': err });238 }239 else {240 console.log("password changed");241 writeResult(res, { 'changePassError': "", 'loginError': "" });242 }243 });244 }245 else {246 console.log("invalid answers");247 writeResult(res, { 'changePassError': "Invalid Answers" })248 }249 });250 }251 }252 });253 }254 });255 }256}257//Returns the information stored in session for logged in user258function whoIsLoggedIn(req, res) {259 if (req.session.user == undefined)260 writeResult(res, { 'error': 'Nobody is logged in.' });261 else262 writeResult(res, { 'email': req.session.user });263}264//Logs the user in if email and password are correct265//Requires email, password266//req.query.email, req.query.password267function login(req, res) {268 if (req.query.email == undefined) {269 writeResult(res, { 'loginError': "Email is required" });270 return;271 }272 if (req.query.password == undefined) {273 writeResult(res, { 'loginError': "Password is required" });274 return;275 }276 var con = mysql.createConnection(conInfo);277 con.connect(function (err) {278 if (err)279 writeResult(res, { 'error': err });280 else {281 //Get account info282 con.query("SELECT * FROM ACCOUNT WHERE ACC_EMAIL = ?", [req.query.email], function (err, result, fields) {283 if (err)284 writeResult(res, { 'error': err });285 else {286 //Log in the user if the entered password is the same as the stored password287 if (result.length == 1 && bcrypt.compareSync(req.query.password, result[0].ACC_PASSWORD)) {288 req.session.user = { 'id': result[0].ACC_ID, 'email': result[0].ACC_EMAIL };289 writeResult(res, { 'email': req.session.user });290 }291 else {292 writeResult(res, { 'loginError': "Invalid email/password" });293 }294 }295 });296 }297 });298}299//Clears Sesssion storage300function logout(req, res) {301 req.session.user = undefined;302 writeResult(res, { 'error': 'Nobody is logged in.', 'email': '' });303}304//Checks if an email is useable305//Requires email306//req.query.email307function validateEmail(email, callback) {308 if (email == undefined) {309 callback(false);310 }311 else {312 var con = mysql.createConnection(conInfo);313 con.connect(function (err) {314 if (err)315 writeResult(res, { 'error': err });316 else {317 //check if email is already present in the database before other functions try to store the email318 con.query('SELECT COUNT(*) AS total FROM ACCOUNT WHERE ACC_EMAIL=?', [email], function (err, result, fields) {319 if (err)320 writeResult(res, { 'error': err });321 else {322 let eCount = parseInt(JSON.stringify(result[0].total));323 if (eCount > 0) {324 callback(false);325 }326 else {327 //Prevent bobby droptables328 var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;329 callback(re.test(String(email).toLowerCase()));330 }331 }332 });333 }334 });335 }336}337//Checks to make sure password does not break sql338//Requires password339//req.query.password340function validatePassword(pass, callback) {341 if (pass == undefined) {342 callback(false);343 }344 else {345 var re = /^([ -!]|[#-&]|[--.]|[0-:]|[a-z]|[<-Z]){8,59}$/;346 callback(re.test(pass));347 }348}349function insertSnippet(req, res) {350 //if req.query.email is not defined throw error351 if (req.session.user == undefined)352 writeResult(res, { 'insertError': "Email invalid" });353 else {354 //check if req.query.desc is valid for snip_desc355 if (req.query.desc == undefined || req.query.desc.length > 255 || req.query.desc.length < 1)356 writeResult(res, { 'insertError': "Description invalid" });357 else {358 //check if req.query.language is valid for snip_snippet359 if (req.query.lang == undefined || req.query.lang.length > 4294967295 || req.query.lang.length < 1)360 writeResult(res, { 'insertError': "Language invalid" });361 else {362 //check if req.query.snippet is valid for snip_snippet363 if (req.query.snippet == undefined || req.query.snippet.length > 4294967295 || req.query.snippet.length < 1)364 writeResult(res, { 'insertError': "Snippet invalid" });365 else {366 var con = mysql.createConnection(conInfo);367 con.connect(function (err) {368 if (err)369 writeResult(res, { 'error': err });370 else {371 con.query("INSERT INTO SNIPPET (SNIP_CREATOR, SNIP_LANG, SNIP_DESC, SNIP_SNIPPET) VALUES (?, ?, ?, ?)", [req.session.user.email, req.query.lang, req.query.desc, req.query.snippet], function (err, result, fields) {372 if (err)373 writeResult(res, { 'error': err });374 else375 writeResult(res, { 'insertError': "", 'error': "" });376 });377 }378 });379 }380 }381 }382 }383}384//delete a snippet created by the user, send error if user isn't logged in385function deleteSnippet(req, res){386 //if user isn't logged in throw error387 if (req.session.user == undefined)388 writeResult(res, {'deleteError': 'No user logged in'});389 else{390 //if no snippet selected391 if(req.query.id == undefined || req.query.id.length < 1)392 writeResult(res, {'deleteError' : 'No Snippet is Selected to delete'});393 else{394 var con = mysql.createConnection(conInfo);395 con.connect(function (err){396 if (err)397 writeResult(res, {'error': err});398 else {399 400 con.query("SELECT * FROM SNIPPET WHERE SNIP_ID = ?", [req.query.id], function(err, result, fields) {401 402 if(err)403 writeResult(res, {'error' : err});404 else{405 console.log(req.query.id);406 console.log("result: " + result[0].SNIP_CREATOR + "user: " + req.session.user.email);407 if(result[0].SNIP_CREATOR != req.session.user.email)408 writeResult(res, {'deleteError' : 'This is not your snipper to delete'});409 else{410 con.query("DELETE FROM SNIPPET WHERE SNIP_ID = ?", [req.query.id], function(err, result, fields){411 if(err)412 writeResult(res, {'error' : err});413 else{414 415 writeResult(res, {'deleteError' : "", 'error': ""});416 }417 });418 } 419 }420 });421 } 422 });423 424 }425 }426}427//edit snippet owned by user 428function updateSnippet(req, res){429 430 if(req.session.user == undefined)431 writeResult(res, {'updateError' : 'No user logged in'});432 else{433 console.log("user good");434 //check if req.query.desc is valid for snip_desc435 if (req.query.desc == undefined || req.query.desc.length > 255 || req.query.desc.length < 1)436 writeResult(res, { 'updateError': "Description invalid" });437 else {438 //check if req.query.language is valid for snip_snippet439 console.log("DESC GOOD");440 console.log("LANG: " + req.query.lang);441 if (req.query.lang == undefined || req.query.lang.length > 4294967295 || req.query.lang.length < 1)442 writeResult(res, { 'updateError': "Language invalid" });443 else {444 console.log("Lang good" + req.query.lang);445 //check if req.query.snippet is valid for snip_snippet446 if (req.query.snippet == undefined || req.query.snippet.length > 4294967295 || req.query.snippet.length < 1)447 writeResult(res, { 'updateError': "Snippet invalid" });448 else{449 console.log("Snippet goof");450 if(req.query.id == undefined || req.query.id.length < 1)451 writeResult(res, {'updateError' : "no Snippet selected"});452 else{453 console.log("ID IS GOOD");454 var con = mysql.createConnection(conInfo)455 con.connect(function(err) {456 if(err)457 writeResult(res, {'error' : err});458 else{459 con.query("SELECT * FROM SNIPPET WHERE SNIP_ID = ?", [req.query.id], function(err, result, fields){460 if(err)461 writeResult(res, {'error': err});462 else{463 console.log(result[0].SNIP_CREATOR + " " + req.session.user.email);464 console.log(req.query.id);465 if(result[0].SNIP_CREATOR != req.session.user.email)466 writeResult(res, {'updateError' : 'You do not own this snippet'});467 else{468 469 con.query("UPDATE SNIPPET SET SNIP_LANG = ?, SNIP_DESC = ?, SNIP_SNIPPET = ? WHERE SNIP_ID = ?", [req.query.lang, req.query.desc, req.query.snippet, req.query.id], function(err, result, fields){470 if(err)471 writeResult(res, {'error': err});472 else{473 writeResult(res, {'updateError': "", 'error' : ""});474 }475 });476 477 }478 }479 });480 }481 });482 } 483 }484 485 }486 }487 }488}489//using only for test.py to remove test user from database490function delUser(req, res)491{492 var con = mysql.createConnection(conInfo);493 con.connect(function (err) {494 if (err){495 console.log("Couldnt connect");496 writeResult(res, {'error' : err});497 }498 else {499 con.query("DELETE FROM ACCOUNT WHERE ACC_EMAIL = ?", [req.query.email], function(err, result, fields){500 if(err)501 writeResult(res, {'error' : err});502 else{503 writeResult(res, {'delSuccess' : "Deleted User"});504 console.log(req.query.email + " Deleted");505 }506 });507 }508 });509 510}511function delTestSnippets(req, res)512{513 var con = mysql.createConnection(conInfo);514 con.connect(function (err) {515 if(err) {516 console.log("couldnt connect");517 writeResult(res, {'error': err});518 }519 520 else{521 con.query("DELETE FROM SNIPPET WHERE SNIP_CREATOR = 'test@we.com'", function(err, result, fields){522 if(err)523 writeResult(res, {'error' : err});524 else{525 writeResult(res, {'delSuccess' : 'Deleted test snippets'});526 console.log("Test snippets deleted");527 }528 });529 }530 });531}532//"Start Program" by reading index.html533function serveIndex(req, res) {534 res.writeHead(200, { 'Content-Type': 'text/html' });535 var index = fs.readFileSync('index.html');536 res.end(index);...

Full Screen

Full Screen

discord.js

Source:discord.js Github

copy

Full Screen

...31 if ( command[2] && command[2].startsWith("/") ) command[2] = command[2].slice(1);32 checkPath(command.slice(2).join(" ").split("/"),function(valid) {33 if ( valid || ! command[2] ) {34 core.openPage("MusicAlbumPage","/" + command.slice(2).join(" "));35 writeResult("Moved to music/" + command.slice(2).join(" "));36 } else {37 writeResult("Couldn't find that album");38 }39 });40 } else if ( command[1] == "photos" ) {41 dataManager.retrieveList("/photos",function(list) {42 if ( list.indexOf(command.slice(2).join(" ")) > -1 || ! command[2] ) {43 if ( command[2] ) core.openPage("PhotoViewerPage",command.slice(2).join(" ") + ",0");44 else core.openPage("PhotoAlbumPage","");45 writeResult("Moved to photos/" + command.slice(2).join(" "));46 } else {47 writeResult("Couldn't find that album");48 }49 });50 } else {51 writeResult("Invalid subcommand");52 }53 } else if ( command[0] == "home" ) {54 core.openPage("MainPage","");55 writeResult("Moved to home");56 } else if ( command[0] == "list" ) {57 if ( activePage == "PhotoAlbumPage" ) {58 dataManager.retrieveList("/photos",function(list) {59 writeResult(`${list.length} entries\n${"```"}\n${list.join("\n")}${"```"}`);60 });61 } else if ( activePage == "PhotoViewerPage" ) {62 dataManager.retrieveList(`/photos/${page.albumName}`,function(list) {63 writeResult(`${list.length} entries\n${"```"}\n${list.map((item,index) => item + (index == page.index ? " √" : "")).join("\n")}${"```"}`);64 });65 } else if ( activePage == "MusicAlbumPage" || activePage == "MusicListPage" ) {66 dataManager.retrieveList(`/music/${params}`,function(list) {67 list = list.map(item => item.indexOf(".") > -1 ? readableSongName(item) : item);68 writeResult(`${list.length} entries\n${"```"}\n${list.map((item,index) => item + (index == page.index ? " √" : "")).join("\n")}${"```"}`);69 });70 } else {71 writeResult("Invalid command");72 }73 } else if ( command[0] == "listqueue" || command[0] == "lq" ) {74 writeResult(`${mcore.queue.length} entries\n${"```"}\n${[document.getElementById("musicname").innerText + " √"].concat(mcore.queue.map(item => readableSongName(item))).join("\n")}${"```"}`);75 } else if ( command[0] == "pause" || command[0] == "pp" ) {76 if ( mcore.hasSong ) {77 mcore.togglePlay();78 writeResult("Music is " + (mcore.playing ? "playing" : "paused"));79 } else {80 writeResult("No song is playing");81 }82 } else if ( command[0] == "playnext" || command[0] == "pn" ) {83 if ( mcore.hasSong ) {84 mcore.playNextSong();85 writeResult("Now playing next song");86 } else {87 writeResult("No song is playing");88 }89 } else if ( command[0] == "openqueue" || command[0] == "oq" ) {90 core.toggleQueue();91 writeResult((queue ? "Opened" : "Closed") + " the queue");92 } else if ( command[0] == "rewind" ) {93 if ( mcore.hasSong ) {94 mcore.setTime(0);95 writeResult("Rewinded song");96 } else {97 writeResult("No song is playing");98 }99 } else if ( command[0] == "volume" ) {100 var value = parseInt(command[1]);101 if ( command[1].toLowerCase() == "up" ) value = Math.min(mcore.volume + 25,100);102 else if ( command[1].toLowerCase() == "down" ) value = Math.max(mcore.volume - 25,0);103 else if ( command[1].toLowerCase() == "mute" ) value = 0;104 if ( isNaN(value) ) {105 writeResult("Invalid value");106 return;107 }108 mcore.volume = value;109 mcore.audio.volume = mcore.volume / 100;110 dcore.drawVolumeSlider();111 writeResult("Set volume to " + value);112 } else if ( command[0] == "remove" ) {113 if ( command[1] != "all" ) {114 var names = mcore.queue.map(item => readableSongName(item).toLowerCase());115 var indices = command.slice(1).join(" ").split(",").map(item => names.indexOf(item.toLowerCase().trim()));116 if ( indices.filter(item => item <= -1).length > 0 ) {117 writeResult("Couldn't find that song");118 return;119 }120 for ( var i = 0; i < indices.length; i++ ) {121 if ( indices[i] <= -1 ) continue;122 mcore.queue = mcore.queue.slice(0,indices[i]).concat(mcore.queue.slice(indices[i] + 1));123 indices = indices.map(item => item >= indices[i] ? item - 1 : item);124 }125 } else {126 mcore.queue = [];127 }128 if ( queue ) queue.render();129 writeResult("Removed" + (command[1] != "all" ? "" : " all") + " songs from the queue");130 } else if ( command[0] == "shuffle" ) {131 for ( var i = mcore.queue.length - 1; i > 0; i-- ) {132 var j = Math.floor(Math.random() * (i + 1));133 var temp = mcore.queue[i];134 mcore.queue[i] = mcore.queue[j];135 mcore.queue[j] = temp;136 }137 if ( queue ) queue.render();138 writeResult("Shuffled the queue");139 } else if ( command[0] == "move" ) {140 var names = mcore.queue.map(item => readableSongName(item).toLowerCase());141 var index = names.indexOf(command.slice(1,-1).join(" ").toLowerCase().trim());142 if ( index <= -1 ) {143 writeResult("Couldn't find that song");144 return;145 }146 if ( ["top","up","down"].indexOf(command[command.length - 1]) <= -1 ) {147 writeResult("Invalid subcommand");148 return;149 }150 var position = [0,index - 1,index + 1][["top","up","down"].indexOf(command[command.length - 1])];151 var item = mcore.queue[index];152 mcore.queue = mcore.queue.slice(0,index).concat(mcore.queue.slice(index + 1));153 mcore.queue.splice(position,0,item);154 if ( queue ) queue.render();155 writeResult("ok");156 }157 if ( activePage == "MusicListPage" ) {158 if ( command[0] == "select" || command[0] == "deselect" ) {159 if ( command[1] != "all" ) {160 var files = page.files.map(item => readableSongName(item).toLowerCase());161 var indices = command.slice(1).join(" ").split(",").map(item => files.indexOf(item.trim()));162 if ( indices.filter(item => item <= -1).length > 0 ) {163 writeResult("Couldn't find that song");164 return;165 }166 for ( var i = 0; i < indices.length; i++ ) {167 page.toggleItem(encodeURIComponent(page.files[indices[i]]),["","select","deselect"].indexOf(command[0]));168 }169 writeResult((command[0] == "select" ? "Selected" : "Deselected") + " songs");170 } else {171 if ( command[0] == "select" ) {172 page.selected = page.files.map(item => escape(item));173 page.selectionText = page.lang.deselect_all;174 } else {175 page.selected = [];176 page.selectionText = page.lang.select_all;177 }178 page.render();179 writeResult((command[0] == "select" ? "Selected" : "Deselected") + " all songs");180 }181 } else if ( command[0] == "add" ) {182 page.addToQueue();183 writeResult("Added songs to the queue");184 }185 } else if ( ["select","deselect","add"].indexOf(command[0]) > -1 ) {186 writeResult("Invalid command");187 } else if ( activePage == "PhotoViewerPage" ) {188 if ( command[0] == "forward" || command[0] == "backward" ) {189 var value = parseInt(command[1]) ? parseInt(command[1]) : 1;190 page.moveImage(command[0] == "forward" ? value : -value);191 writeResult("Moved " + command[0] + " " + value + " image(s)");192 } else if ( command[0] == "rotate" ) {193 page.rotate();194 writeResult("Rotated image 90 degrees");195 } else if ( command[0] == "count" ) {196 writeResult(`${page.files[page.index]} is photo #${page.index + 1}/${page.files.length}`);197 }198 } else if ( ["forward","backward","rotate","count"].indexOf(command[0]) > -1 ) {199 writeResult("Invalid command");200 }201 if ( command[0] == "help" ) {202 var table;203 if ( command[1] == "1" || ! command[1] ) {204 table = [205 ["Command ","Syntax ","Function ","Alias"],206 ["listqueue","!listqueue ","Lists the songs in the queue ","!lq "],207 ["pause ","!pause ","Plays or pauses the music ","!pp "],208 ["playnext ","!playnext ","Triggers the next song in the queue ","!pn "],209 ["openqueue","!openqueue ","Opens or closes the queue menu ","!oq "],210 ["goto ","!goto <music | photos> <album> ","Moves to a section of the app ","None "],211 ["home ","!home ","Moves the home page ","None "],212 ["list ","!list ","Lists items currently on screen ","None "],213 ["select ","!select <songs | all> ","Selects songs from the music page ","None "],214 ["deselect ","!deselect <songs | all> ","Deselects songs from the music page ","None "],215 ["add ","!add ","Adds selected songs to the queue ","None "],216 ["forward ","!forward ","Moves forward in photo albums ","None "],217 ["backward ","!backward ","Moves backward in photo albums ","None "],218 ["rotate ","!rotate ","Rotates the photo 90 degrees ","None "],219 ["count ","!count ","Returns the current photo's position ","None "],220 ["rewind ","!rewind ","Rewinds the current song to the start","None "],221 ["volume ","!volume <percent | up | down | mute>","Changes the volume ","None "]222 ];223 } else if ( command[1] == "2" ) {224 table = [225 ["Command ","Syntax ","Function ","Alias"],226 ["remove ","!remove <songs | all> ","Removes songs from the queue ","None "],227 ["shuffle ","!shuffle ","Shuffles the queue ","None "],228 ["move ","!move <song> <up | down | top> ","Moves a song in the queue ","None "],229 ["help ","!help <page> ","Displays this help text ","None "]230 ];231 } else {232 writeResult("Invalid page number, use `!help` for the first page");233 }234 table.splice(1,0,table[0].map(item => "-".repeat(item.length)));235 table = table.map(item => "|" + item.join("|") + "|");236 var length = table[0].length;237 table = table.join("\n");238 table = `\n${"-".repeat(length)}\n${table}\n${"-".repeat(length)}\n`;239 writeResult("```" + table + "```" + ((command[1] == "1" || ! command[1]) ? "Type `!help 2` for the next page" : ""));240 }241 if ( ["goto","home","list","select","deselect","add","forward","backward","rotate","count","listqueue","lq","pause","pp","playnext","pn","openqueue","oq","rewind","volume","remove","shuffle","move","help"].indexOf(command[0]) <= -1 ) writeResult("Invalid command");242}243function writeResult(message) {244 fs.writeFile(__dirname + "/../discord/response",message,function(err) {245 if ( err ) throw err;246 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 wpt.getTestResults(data.data.testId, function(err, data) {5 if (err) return console.error(err);6 wpt.writeResult(data, 'csv', function(err, data) {7 if (err) return console.error(err);8 console.log(data);9 });10 });11});12var wpt = require('webpagetest');13var wpt = new WebPageTest('www.webpagetest.org');14 if (err) return console.error(err);15 wpt.getTestResults(data.data.testId, function(err, data) {16 if (err) return console.error(err);17 wpt.writeResult(data, 'xml', function(err, data) {18 if (err) return console.error(err);19 console.log(data);20 });21 });22});23var wpt = require('webpagetest');24var wpt = new WebPageTest('www.webpagetest.org');25 if (err) return console.error(err);26 wpt.getTestResults(data.data.testId, function(err, data) {27 if (err) return console.error(err);28 wpt.writeResult(data, 'json', function(err, data) {29 if (err) return console.error(err);30 console.log(data);31 });32 });33});34var wpt = require('webpagetest');35var wpt = new WebPageTest('www.webpagetest.org');36 if (err) return console.error(err);37 wpt.getTestResults(data.data.testId, function(err, data) {38 if (err) return console.error(err);39 wpt.writeResult(data, 'html', function(err, data) {40 if (

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 console.log(data);4 wpt.writeResult(data.data.testId, 'json', function(err, data) {5 console.log(data);6 });7});8var wpt = require('webpagetest');9var wpt = new WebPageTest('www.webpagetest.org');10wpt.getLocations(function(err, data) {11 console.log(data);12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org');15wpt.getTesters(function(err, data) {16 console.log(data);17});18var wpt = require('webpagetest');19var wpt = new WebPageTest('www.webpagetest.org');20wpt.getTesters(function(err, data) {21 console.log(data);22});23var wpt = require('webpagetest');24var wpt = new WebPageTest('www.webpagetest.org');25wpt.getTesters(function(err, data) {26 console.log(data);27});28var wpt = require('webpagetest');29var wpt = new WebPageTest('www.webpagetest.org');30wpt.getTesters(function(err, data) {31 console.log(data);32});33var wpt = require('webpagetest');34var wpt = new WebPageTest('www.webpagetest.org');35wpt.getTesters(function(err, data) {36 console.log(data);37});38var wpt = require('webpagetest');39var wpt = new WebPageTest('www.webpagetest.org');40wpt.getTesters(function(err, data) {41 console.log(data

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 wpt.getTestResults(data.data.testId, function(err, data) {5 if (err) return console.error(err);6 console.log(data);7 });8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org');11 if (err) return console.error(err);12 wpt.getTestResults(data.data.testId, function(err, data) {13 if (err) return console.error(err);14 console.log(data);15 });16});17var wpt = require('webpagetest');18var wpt = new WebPageTest('www.webpagetest.org');19 if (err) return console.error(err);20 wpt.getTestResults(data.data.testId, function(err, data) {21 if (err) return console.error(err);22 console.log(data);23 });24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27 if (err) return console.error(err);28 wpt.getTestResults(data.data.testId, function(err, data) {29 if (err) return console.error(err);30 console.log(data);31 });32});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new wpt('API_KEY');3 console.log(data);4});5var wpt = require('wpt');6var wpt = new wpt('API_KEY');7 console.log(data);8});9var wpt = require('wpt');10var wpt = new wpt('API_KEY');11 console.log(data);12});13var wpt = require('wpt');14var wpt = new wpt('API_KEY');15 console.log(data);16});17var wpt = require('wpt');18var wpt = new wpt('API_KEY');19 console.log(data);20});21var wpt = require('wpt');22var wpt = new wpt('API_KEY');23 console.log(data);24});25var wpt = require('wpt');26var wpt = new wpt('API_KEY');27 console.log(data);28});29var wpt = require('wpt');30var wpt = new wpt('API_KEY');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful