From bcf1509ad7bdc2497f4e00e8cdc3b8a6a1f2c13b Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 26 Jun 2023 14:15:32 -0700 Subject: [PATCH 1/8] pushing base code --- config/triggerList.cfg | 0 index.js | 78 ++++++++++++++++++++++++++++++++++++++++++ metadata.json | 7 ++++ models/fileModel.js | 42 +++++++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 config/triggerList.cfg create mode 100644 index.js create mode 100644 metadata.json create mode 100644 models/fileModel.js diff --git a/config/triggerList.cfg b/config/triggerList.cfg new file mode 100644 index 0000000..e69de29 diff --git a/index.js b/index.js new file mode 100644 index 0000000..e505e94 --- /dev/null +++ b/index.js @@ -0,0 +1,78 @@ +const fileModel = require("../models/fileModel"); + +const display = new Display(); +const Ykey = Client.getKeyBindFromKey(Keyboard.KEY_Y, "Y"); +const Nkey = Client.getKeyBindFromKey(Keyboard.KEY_N, "N"); +const Xkey = Client.getKeyBindFromKey(Keyboard.KEY_X, "X"); +let dataFile = fileModel.checkforFile(); + +display.setAlign("center"); + +register("worldLoad", () => { + ChatLib.chat("[CP]: ChatPing is ENABLED! do /cp or /chatping for more info."); +}); + +register("chat", (message, event) => { + if(message in fileModel.fileToArray(dataFile)){ + display.addLine( + new DisplayLine("PING").setTextColor(Renderer.RED) + ); + display.addLine( + new DisplayLine("press the X key to remove this text.").setTextColor(Renderer.ORANGE) + ); + + if(Xkey.isPressed()){ + display.setline(0, ""); + display.setline(1, ""); + } + // play a sound or sth + } +}); + +register("command", (user) => { // goal is to return a message, format shown below + let args[] = [] // placeholder + + if(args[0].toLowerCase() == "add"){ + if(args[1]){ + args.pop(0); + // convert args into a string called "words" + words = null; + fileModel.addText(words, dataFile); // create function that puts it into the function and reloads it here + ChatLib.chat("[CP]: Successfully added trigger. Do /cp display to show all active triggers."); + } + } + else if(args[0].toLowerCase() == "remove"){ + if(args[1] && !args[2]){ + fileModel.remove(args[1], dataFile); + ChatLib.chat("[CP]: Successfully removed trigger. Do /cp display to show all active triggers."); + } + } + else if(args[0].toLowerCase() == "wipe"){ + ChatLib.chat("[CP]: Are you sure you want to do this? Press Y/N"); + if(Ykey.isPressed()){ + fileModel.wipeFile(dataFile); + ChatLib.chat("[CP]: Wipe successful."); + } + if(Nkey.isPressed()){ + ChatLib.chat("[CP]: Aborted wipe."); + } + } + else if(args[0].toLowerCase() == "display"){ + fileModel.display(dataFile); + } + else{ + ChatLib.chat("---- ChatPing ----"); + ChatLib.chat("bla bla bla yeah we get it"); + } + }).setName("chatping").setAliases("cp"); + + + /* + ---- ChatPing ---- + /chatping or /cp + a lightweight system to notify you when a chat message is sent! + /cp add : adds as a trigger to ping you + /cp remove : removes trigger at index + /cp wipe: resets all triggers + /cp display: displays triggers + */ \ No newline at end of file diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..cc4e499 --- /dev/null +++ b/metadata.json @@ -0,0 +1,7 @@ +{ + "name":"ChatPing", + "creator":"FuzzyPcklz", + "description":"Pings you whenever a specific chat message is sent!", + "version":"1.0.0", + "entry":"index.js" +} \ No newline at end of file diff --git a/models/fileModel.js b/models/fileModel.js new file mode 100644 index 0000000..b1fe96b --- /dev/null +++ b/models/fileModel.js @@ -0,0 +1,42 @@ +// This is where all the file IO stuff will happen. + + + +function checkForFile(dataFile){ + // see if the file exists or not + try { + // try to open the file + } catch (error) { // see if it's a file not found error + // make a new file + } +} + +function addText(text, dataFile){ + // append text to the file +} + +function remove(index, dataFile){ + // convert the file to an array, then remove index "index" from ti +} + +function wipe(dataFile){ + // delete all data on the file +} + +function display(dataFile){ + // take all the data from the file, put it into an array, then map that array into the chat +} + +function fileToArray(dataFile){ + //converts it to an array, then returns it. simple. +} + + +module.exports = { + checkForFile, + addText, + remove, + wipe, + display, + fileToArray +} \ No newline at end of file From ef1df76abe69871ff9b318981b76a5edd5740649 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 27 Jun 2023 21:13:45 -0700 Subject: [PATCH 2/8] various bug fixes (untested changes) --- .gitignore | 1 + index.js | 22 ++++++++++------- models/fileModel.js | 43 ++++++++++++++++++++------------- node_modules/.package-lock.json | 12 +++++++++ node_modules/fs/README.md | 9 +++++++ node_modules/fs/package.json | 20 +++++++++++++++ package-lock.json | 24 ++++++++++++++++++ package.json | 5 ++++ 8 files changed, 110 insertions(+), 26 deletions(-) create mode 100644 .gitignore create mode 100644 node_modules/.package-lock.json create mode 100644 node_modules/fs/README.md create mode 100644 node_modules/fs/package.json create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ef1066e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/config \ No newline at end of file diff --git a/index.js b/index.js index e505e94..93b2f34 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ register("worldLoad", () => { }); register("chat", (message, event) => { - if(message in fileModel.fileToArray(dataFile)){ + if(message in fileModel.fileToArray()){ display.addLine( new DisplayLine("PING").setTextColor(Renderer.RED) ); @@ -29,28 +29,27 @@ register("chat", (message, event) => { } }); -register("command", (user) => { // goal is to return a message, format shown below - let args[] = [] // placeholder +register("command", (...args) => { // goal is to return a message, format shown below if(args[0].toLowerCase() == "add"){ if(args[1]){ - args.pop(0); + args.pop(); // convert args into a string called "words" - words = null; - fileModel.addText(words, dataFile); // create function that puts it into the function and reloads it here + let words = args.join(' ')+"^&$"; // ^&$ is just a marker so that fileModel functions know where to split the array + fileModel.addText(words); // create function that puts it into the function and reloads it here ChatLib.chat("[CP]: Successfully added trigger. Do /cp display to show all active triggers."); } } else if(args[0].toLowerCase() == "remove"){ if(args[1] && !args[2]){ - fileModel.remove(args[1], dataFile); + fileModel.remove(args[1]); ChatLib.chat("[CP]: Successfully removed trigger. Do /cp display to show all active triggers."); } } else if(args[0].toLowerCase() == "wipe"){ ChatLib.chat("[CP]: Are you sure you want to do this? Press Y/N"); if(Ykey.isPressed()){ - fileModel.wipeFile(dataFile); + fileModel.wipeFile(); ChatLib.chat("[CP]: Wipe successful."); } if(Nkey.isPressed()){ @@ -58,7 +57,12 @@ register("command", (user) => { // goal is to return a message, format shown bel } } else if(args[0].toLowerCase() == "display"){ - fileModel.display(dataFile); + let triggers = fileModel.fileToArray(); + + for(var i = 0; i<=triggers.length-1; i++){ + Chatlib.chat(i+": "+triggers[i]); + } + } else{ ChatLib.chat("---- ChatPing ----"); diff --git a/models/fileModel.js b/models/fileModel.js index b1fe96b..830e93d 100644 --- a/models/fileModel.js +++ b/models/fileModel.js @@ -1,34 +1,44 @@ // This is where all the file IO stuff will happen. +const fs = require('fs'); - -function checkForFile(dataFile){ +function checkForFile(){ // see if the file exists or not - try { - // try to open the file - } catch (error) { // see if it's a file not found error - // make a new file - } + fs.open('./config/triggerList.cfg').toString(); } -function addText(text, dataFile){ +function addText(text){ // append text to the file -} + let triggersArray = fs.readFile('./config/triggerList.cfg').toString().split("^&$"); -function remove(index, dataFile){ - // convert the file to an array, then remove index "index" from ti + triggersArray.append(text); + let weirdCSV = triggersArray.join("^&$"); + fs.unlink('./config/triggerList.cfg'); + fs.writeFile('./config/triggerList.cfg', weirdCSV); } -function wipe(dataFile){ - // delete all data on the file +function remove(index){ + // convert the file to an array, then remove index "index" from it + let triggersArray = fs.readFile('./config/triggerList.cfg').toString().split("^&$"); + + triggersArray.splice(index, 1) + let weirdCSV = triggersArray.join("^&$"); + fs.unlink('./config/triggerList.cfg'); + fs.writeFile('./config/triggerList.cfg', weirdCSV); + } -function display(dataFile){ - // take all the data from the file, put it into an array, then map that array into the chat +function wipe(){ + // delete all data on the file + fs.unlink('./config/triggerList.cfg'); + fs.writeFile('./config/triggerList.cfg', ""); } -function fileToArray(dataFile){ +function fileToArray(){ //converts it to an array, then returns it. simple. + let triggersArray = fs.readFile('./config/triggerList.cfg').toString().split("^&$"); + + return triggersArray; } @@ -37,6 +47,5 @@ module.exports = { addText, remove, wipe, - display, fileToArray } \ No newline at end of file diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json new file mode 100644 index 0000000..736c8f1 --- /dev/null +++ b/node_modules/.package-lock.json @@ -0,0 +1,12 @@ +{ + "name": "ChatPing", + "lockfileVersion": 2, + "requires": true, + "packages": { + "node_modules/fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + } + } +} diff --git a/node_modules/fs/README.md b/node_modules/fs/README.md new file mode 100644 index 0000000..5e9a74c --- /dev/null +++ b/node_modules/fs/README.md @@ -0,0 +1,9 @@ +# Security holding package + +This package name is not currently in use, but was formerly occupied +by another package. To avoid malicious use, npm is hanging on to the +package name, but loosely, and we'll probably give it to you if you +want it. + +You may adopt this package by contacting support@npmjs.com and +requesting the name. diff --git a/node_modules/fs/package.json b/node_modules/fs/package.json new file mode 100644 index 0000000..11661b0 --- /dev/null +++ b/node_modules/fs/package.json @@ -0,0 +1,20 @@ +{ + "name": "fs", + "version": "0.0.1-security", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/npm/security-holder.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/npm/security-holder/issues" + }, + "homepage": "https://github.com/npm/security-holder#readme" +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..47333b5 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,24 @@ +{ + "name": "ChatPing", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "dependencies": { + "fs": "^0.0.1-security" + } + }, + "node_modules/fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + } + }, + "dependencies": { + "fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..7ea3a90 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "fs": "^0.0.1-security" + } +} From 713aa709e31a6099e431f49ef7f176950de39e22 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 1 Jul 2023 17:23:57 -0700 Subject: [PATCH 3/8] migrated away from node modules since they are incompatible with CT --- config/triggerList.cfg | 0 index.js | 8 +++++--- metadata.json | 7 ------- models/fileModel.js | 28 +++++++++++++++------------- node_modules/.package-lock.json | 12 ------------ node_modules/fs/README.md | 9 --------- node_modules/fs/package.json | 20 -------------------- package-lock.json | 24 ------------------------ package.json | 5 ----- 9 files changed, 20 insertions(+), 93 deletions(-) delete mode 100644 config/triggerList.cfg delete mode 100644 metadata.json delete mode 100644 node_modules/.package-lock.json delete mode 100644 node_modules/fs/README.md delete mode 100644 node_modules/fs/package.json delete mode 100644 package-lock.json delete mode 100644 package.json diff --git a/config/triggerList.cfg b/config/triggerList.cfg deleted file mode 100644 index e69de29..0000000 diff --git a/index.js b/index.js index 93b2f34..48ae841 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,12 @@ -const fileModel = require("../models/fileModel"); +/// +/// +const fileModel = require("models/fileModel"); const display = new Display(); const Ykey = Client.getKeyBindFromKey(Keyboard.KEY_Y, "Y"); const Nkey = Client.getKeyBindFromKey(Keyboard.KEY_N, "N"); const Xkey = Client.getKeyBindFromKey(Keyboard.KEY_X, "X"); let dataFile = fileModel.checkforFile(); - display.setAlign("center"); register("worldLoad", () => { @@ -20,11 +21,12 @@ register("chat", (message, event) => { display.addLine( new DisplayLine("press the X key to remove this text.").setTextColor(Renderer.ORANGE) ); - + World.playSound("mob.cat.purreow", 10, 5) if(Xkey.isPressed()){ display.setline(0, ""); display.setline(1, ""); } + // play a sound or sth } }); diff --git a/metadata.json b/metadata.json deleted file mode 100644 index cc4e499..0000000 --- a/metadata.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name":"ChatPing", - "creator":"FuzzyPcklz", - "description":"Pings you whenever a specific chat message is sent!", - "version":"1.0.0", - "entry":"index.js" -} \ No newline at end of file diff --git a/models/fileModel.js b/models/fileModel.js index 830e93d..d476095 100644 --- a/models/fileModel.js +++ b/models/fileModel.js @@ -1,42 +1,44 @@ // This is where all the file IO stuff will happen. -const fs = require('fs'); function checkForFile(){ // see if the file exists or not - fs.open('./config/triggerList.cfg').toString(); + if(FileLib.exists('./config/triggerList.cfg')){ + return true + } + else{ + FileLib.write('./config/triggerList.cfg'); + } + } function addText(text){ // append text to the file - let triggersArray = fs.readFile('./config/triggerList.cfg').toString().split("^&$"); + let triggersArray = FileLib.read('./config/triggerList.cfg').toString().split("^&$"); - triggersArray.append(text); - let weirdCSV = triggersArray.join("^&$"); - fs.unlink('./config/triggerList.cfg'); - fs.writeFile('./config/triggerList.cfg', weirdCSV); + FileLib.append('./config/triggerList.cfg', text + "^&$"); } function remove(index){ // convert the file to an array, then remove index "index" from it - let triggersArray = fs.readFile('./config/triggerList.cfg').toString().split("^&$"); + let triggersArray = FileLib.read('./config/triggerList.cfg').toString().split("^&$"); triggersArray.splice(index, 1) let weirdCSV = triggersArray.join("^&$"); - fs.unlink('./config/triggerList.cfg'); - fs.writeFile('./config/triggerList.cfg', weirdCSV); + FileLib.delete('./config/triggerList.cfg'); + FileLib.write('./config/triggerList.cfg', weirdCSV); } function wipe(){ // delete all data on the file - fs.unlink('./config/triggerList.cfg'); - fs.writeFile('./config/triggerList.cfg', ""); + FileLib.delete('./config/triggerList.cfg'); + FileLib.write('./config/triggerList.cfg'); } function fileToArray(){ //converts it to an array, then returns it. simple. - let triggersArray = fs.readFile('./config/triggerList.cfg').toString().split("^&$"); + let triggersArray = FileLib.read('./config/triggerList.cfg').toString().split("^&$"); return triggersArray; } diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json deleted file mode 100644 index 736c8f1..0000000 --- a/node_modules/.package-lock.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "ChatPing", - "lockfileVersion": 2, - "requires": true, - "packages": { - "node_modules/fs": { - "version": "0.0.1-security", - "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", - "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" - } - } -} diff --git a/node_modules/fs/README.md b/node_modules/fs/README.md deleted file mode 100644 index 5e9a74c..0000000 --- a/node_modules/fs/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Security holding package - -This package name is not currently in use, but was formerly occupied -by another package. To avoid malicious use, npm is hanging on to the -package name, but loosely, and we'll probably give it to you if you -want it. - -You may adopt this package by contacting support@npmjs.com and -requesting the name. diff --git a/node_modules/fs/package.json b/node_modules/fs/package.json deleted file mode 100644 index 11661b0..0000000 --- a/node_modules/fs/package.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "fs", - "version": "0.0.1-security", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/npm/security-holder.git" - }, - "keywords": [], - "author": "", - "license": "ISC", - "bugs": { - "url": "https://github.com/npm/security-holder/issues" - }, - "homepage": "https://github.com/npm/security-holder#readme" -} diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 47333b5..0000000 --- a/package-lock.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "ChatPing", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "dependencies": { - "fs": "^0.0.1-security" - } - }, - "node_modules/fs": { - "version": "0.0.1-security", - "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", - "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" - } - }, - "dependencies": { - "fs": { - "version": "0.0.1-security", - "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", - "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" - } - } -} diff --git a/package.json b/package.json deleted file mode 100644 index 7ea3a90..0000000 --- a/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "dependencies": { - "fs": "^0.0.1-security" - } -} From e06b99fc7aed5fdf1a225f3a2caa7d0709620543 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 1 Jul 2023 18:02:04 -0700 Subject: [PATCH 4/8] it works lmao --- index.js | 57 +++++++++++++++++++++++++++++++++++++++------ metadata.json | 7 ++++++ models/fileModel.js | 11 --------- 3 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 metadata.json diff --git a/index.js b/index.js index 48ae841..10eb004 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,55 @@ /// /// -const fileModel = require("models/fileModel"); const display = new Display(); const Ykey = Client.getKeyBindFromKey(Keyboard.KEY_Y, "Y"); const Nkey = Client.getKeyBindFromKey(Keyboard.KEY_N, "N"); const Xkey = Client.getKeyBindFromKey(Keyboard.KEY_X, "X"); -let dataFile = fileModel.checkforFile(); + +// This is where all the file IO stuff will happen. +function checkForFile(){ + // see if the file exists or not + if(FileLib.exists('./config/triggerList.cfg')){ + return true + } + else{ + FileLib.write('./config/triggerList.cfg', ""); + } + +} + +function addText(text){ + // append text to the file + let triggersArray = FileLib.read('./config/triggerList.cfg').toString().split("^&$"); + + FileLib.append('./config/triggerList.cfg', text + "^&$"); +} + +function remove(index){ + // convert the file to an array, then remove index "index" from it + let triggersArray = FileLib.read('./config/triggerList.cfg').toString().split("^&$"); + + triggersArray.splice(index, 1) + let weirdCSV = triggersArray.join("^&$"); + FileLib.delete('./config/triggerList.cfg'); + FileLib.write('./config/triggerList.cfg', weirdCSV); + +} + +function wipe(){ + // delete all data on the file + FileLib.delete('./config/triggerList.cfg'); + FileLib.write('./config/triggerList.cfg', ""); +} + +function fileToArray(){ + //converts it to an array, then returns it. simple. + let triggersArray = FileLib.read('./config/triggerList.cfg').toString().split("^&$"); + + return triggersArray; +} + +let dataFile = checkForFile(); display.setAlign("center"); register("worldLoad", () => { @@ -14,7 +57,7 @@ register("worldLoad", () => { }); register("chat", (message, event) => { - if(message in fileModel.fileToArray()){ + if(message in fileToArray()){ display.addLine( new DisplayLine("PING").setTextColor(Renderer.RED) ); @@ -38,20 +81,20 @@ register("command", (...args) => { // goal is to return a message, format shown args.pop(); // convert args into a string called "words" let words = args.join(' ')+"^&$"; // ^&$ is just a marker so that fileModel functions know where to split the array - fileModel.addText(words); // create function that puts it into the function and reloads it here + addText(words); // create function that puts it into the function and reloads it here ChatLib.chat("[CP]: Successfully added trigger. Do /cp display to show all active triggers."); } } else if(args[0].toLowerCase() == "remove"){ if(args[1] && !args[2]){ - fileModel.remove(args[1]); + remove(args[1]); ChatLib.chat("[CP]: Successfully removed trigger. Do /cp display to show all active triggers."); } } else if(args[0].toLowerCase() == "wipe"){ ChatLib.chat("[CP]: Are you sure you want to do this? Press Y/N"); if(Ykey.isPressed()){ - fileModel.wipeFile(); + wipeFile(); ChatLib.chat("[CP]: Wipe successful."); } if(Nkey.isPressed()){ @@ -59,7 +102,7 @@ register("command", (...args) => { // goal is to return a message, format shown } } else if(args[0].toLowerCase() == "display"){ - let triggers = fileModel.fileToArray(); + let triggers = fileToArray(); for(var i = 0; i<=triggers.length-1; i++){ Chatlib.chat(i+": "+triggers[i]); diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..cc4e499 --- /dev/null +++ b/metadata.json @@ -0,0 +1,7 @@ +{ + "name":"ChatPing", + "creator":"FuzzyPcklz", + "description":"Pings you whenever a specific chat message is sent!", + "version":"1.0.0", + "entry":"index.js" +} \ No newline at end of file diff --git a/models/fileModel.js b/models/fileModel.js index d476095..9f0ab56 100644 --- a/models/fileModel.js +++ b/models/fileModel.js @@ -1,6 +1,4 @@ // This is where all the file IO stuff will happen. - - function checkForFile(){ // see if the file exists or not if(FileLib.exists('./config/triggerList.cfg')){ @@ -41,13 +39,4 @@ function fileToArray(){ let triggersArray = FileLib.read('./config/triggerList.cfg').toString().split("^&$"); return triggersArray; -} - - -module.exports = { - checkForFile, - addText, - remove, - wipe, - fileToArray } \ No newline at end of file From 844c573e658780c3175a574c810a07036967d505 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 3 Jul 2023 06:49:59 -0700 Subject: [PATCH 5/8] committing late night changes --- .gitignore | 1 - index.js | 131 +++++++++++++++++++++++++------------------- models/fileModel.js | 42 -------------- 3 files changed, 76 insertions(+), 98 deletions(-) delete mode 100644 .gitignore delete mode 100644 models/fileModel.js diff --git a/.gitignore b/.gitignore deleted file mode 100644 index ef1066e..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/config \ No newline at end of file diff --git a/index.js b/index.js index 10eb004..d177acd 100644 --- a/index.js +++ b/index.js @@ -28,11 +28,17 @@ function addText(text){ function remove(index){ // convert the file to an array, then remove index "index" from it let triggersArray = FileLib.read('./config/triggerList.cfg').toString().split("^&$"); - - triggersArray.splice(index, 1) - let weirdCSV = triggersArray.join("^&$"); - FileLib.delete('./config/triggerList.cfg'); - FileLib.write('./config/triggerList.cfg', weirdCSV); + if(index>triggersArray.length-1){ + return false; + } + else{ + triggersArray.splice(index, 1) + let weirdCSV = triggersArray.join("^&$"); + FileLib.delete('./config/triggerList.cfg'); + FileLib.write('./config/triggerList.cfg', weirdCSV); + return true; + } + } @@ -45,7 +51,7 @@ function wipe(){ function fileToArray(){ //converts it to an array, then returns it. simple. let triggersArray = FileLib.read('./config/triggerList.cfg').toString().split("^&$"); - + triggersArray.pop(); return triggersArray; } @@ -56,63 +62,78 @@ register("worldLoad", () => { ChatLib.chat("[CP]: ChatPing is ENABLED! do /cp or /chatping for more info."); }); -register("chat", (message, event) => { - if(message in fileToArray()){ - display.addLine( - new DisplayLine("PING").setTextColor(Renderer.RED) - ); - display.addLine( - new DisplayLine("press the X key to remove this text.").setTextColor(Renderer.ORANGE) - ); - World.playSound("mob.cat.purreow", 10, 5) - if(Xkey.isPressed()){ - display.setline(0, ""); - display.setline(1, ""); - } - +register("chat", (event) => { + console.log("do you hear the flibberty jibber jabber oh my god I gotta get out or I'm gonna have another work to sell another story to tell another time piece ringing the bell do you hear the clock stop when you reach the end no you don't so it must be neverending comprehend if you can but if you try to prentend you understand you resemble a fool and you're only a man so give it up and smile") + let msg = ChatLib.getChatMessage(event); + if(fileToArray().includes(msg.toString())){ + + ChatLib.chat("[CP]: \""+msg+"\" has triggered a ping!"); + World.playSound("mob.ghast.affectionate_scream", 100, 0.3); // play a sound or sth } }); register("command", (...args) => { // goal is to return a message, format shown below - - if(args[0].toLowerCase() == "add"){ - if(args[1]){ - args.pop(); - // convert args into a string called "words" - let words = args.join(' ')+"^&$"; // ^&$ is just a marker so that fileModel functions know where to split the array - addText(words); // create function that puts it into the function and reloads it here - ChatLib.chat("[CP]: Successfully added trigger. Do /cp display to show all active triggers."); - } - } - else if(args[0].toLowerCase() == "remove"){ - if(args[1] && !args[2]){ - remove(args[1]); - ChatLib.chat("[CP]: Successfully removed trigger. Do /cp display to show all active triggers."); - } - } - else if(args[0].toLowerCase() == "wipe"){ - ChatLib.chat("[CP]: Are you sure you want to do this? Press Y/N"); - if(Ykey.isPressed()){ - wipeFile(); - ChatLib.chat("[CP]: Wipe successful."); - } - if(Nkey.isPressed()){ - ChatLib.chat("[CP]: Aborted wipe."); - } - } - else if(args[0].toLowerCase() == "display"){ - let triggers = fileToArray(); - - for(var i = 0; i<=triggers.length-1; i++){ - Chatlib.chat(i+": "+triggers[i]); - } - - } - else{ + if(!args[0]){ + //explain that they're missing args + World.playSound("mob.cat.purreow", 100, 1); + ChatLib.chat("---- ChatPing ----"); ChatLib.chat("bla bla bla yeah we get it"); } + else{ + switch(args[0].toLowerCase()){ + default: + ChatLib.chat("---- ChatPing ----"); + ChatLib.chat("bla bla bla yeah we get it"); + case "add": + if(args[1]){ + args.shift(); + // convert args into a string called "words" + let words = args.join(' '); // ^&$ is just a marker so that fileModel functions know where to split the array + addText(words); // create function that puts it into the function and reloads it here + ChatLib.chat("[CP]: Successfully added trigger. Do /cp display to show all active triggers."); + World.playSound("mob.cat.meow", 100, 1); + break; + } + else{ + //explain that they're missing args + ChatLib.chat("[CP]: Addition failed. Missing arguments!"); + break; + } + case "remove": + if(args[1]){ + if(remove(args[1]) === true){ + ChatLib.chat("[CP]: Successfully removed trigger. Do /cp display to show all active triggers."); + } + else{ + ChatLib.chat("[CP]: Removal failed. Bad index number. Try a number listed in /cp display!"); + } + break; + } + else{ + //explain that they're missing args + ChatLib.chat("[CP]: Removal failed. Missing index number. Try a number listed in /cp display!"); + break; + } + case "wipe": + ChatLib.chat("[CP]: Are you sure you want to do this? Press Y/N"); + if(Ykey.isPressed()){ + wipeFile(); + ChatLib.chat("[CP]: Wipe successful."); + } + if(Nkey.isPressed()){ + ChatLib.chat("[CP]: Aborted wipe."); + } + case "display": + let triggers = fileToArray(); + ChatLib.chat("[CP] Currently active keywords:") + + for(var i = 0; i<=triggers.length-1; i++){ + ChatLib.chat(i+": "+triggers[i]); + } + } + } }).setName("chatping").setAliases("cp"); diff --git a/models/fileModel.js b/models/fileModel.js deleted file mode 100644 index 9f0ab56..0000000 --- a/models/fileModel.js +++ /dev/null @@ -1,42 +0,0 @@ -// This is where all the file IO stuff will happen. -function checkForFile(){ - // see if the file exists or not - if(FileLib.exists('./config/triggerList.cfg')){ - return true - } - else{ - FileLib.write('./config/triggerList.cfg'); - } - -} - -function addText(text){ - // append text to the file - let triggersArray = FileLib.read('./config/triggerList.cfg').toString().split("^&$"); - - FileLib.append('./config/triggerList.cfg', text + "^&$"); -} - -function remove(index){ - // convert the file to an array, then remove index "index" from it - let triggersArray = FileLib.read('./config/triggerList.cfg').toString().split("^&$"); - - triggersArray.splice(index, 1) - let weirdCSV = triggersArray.join("^&$"); - FileLib.delete('./config/triggerList.cfg'); - FileLib.write('./config/triggerList.cfg', weirdCSV); - -} - -function wipe(){ - // delete all data on the file - FileLib.delete('./config/triggerList.cfg'); - FileLib.write('./config/triggerList.cfg'); -} - -function fileToArray(){ - //converts it to an array, then returns it. simple. - let triggersArray = FileLib.read('./config/triggerList.cfg').toString().split("^&$"); - - return triggersArray; -} \ No newline at end of file From 4dcc6fd55f90578c6180d6ba7908951f36660852 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 4 Jul 2023 20:41:04 -0700 Subject: [PATCH 6/8] pushing not working changes --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index d177acd..f961725 100644 --- a/index.js +++ b/index.js @@ -64,7 +64,8 @@ register("worldLoad", () => { register("chat", (event) => { console.log("do you hear the flibberty jibber jabber oh my god I gotta get out or I'm gonna have another work to sell another story to tell another time piece ringing the bell do you hear the clock stop when you reach the end no you don't so it must be neverending comprehend if you can but if you try to prentend you understand you resemble a fool and you're only a man so give it up and smile") - let msg = ChatLib.getChatMessage(event); + let msg = ChatLib.getChatMessage(event,false); + console.log(msg); if(fileToArray().includes(msg.toString())){ ChatLib.chat("[CP]: \""+msg+"\" has triggered a ping!"); From d37b828213fd77b9725445b168d34fe6c09edd82 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 5 Jul 2023 19:50:39 -0700 Subject: [PATCH 7/8] code is fully functional! --- index.js | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index f961725..ffa58f3 100644 --- a/index.js +++ b/index.js @@ -51,7 +51,6 @@ function wipe(){ function fileToArray(){ //converts it to an array, then returns it. simple. let triggersArray = FileLib.read('./config/triggerList.cfg').toString().split("^&$"); - triggersArray.pop(); return triggersArray; } @@ -60,18 +59,43 @@ display.setAlign("center"); register("worldLoad", () => { ChatLib.chat("[CP]: ChatPing is ENABLED! do /cp or /chatping for more info."); + ChatLib.chat("[CP]: "); }); register("chat", (event) => { - console.log("do you hear the flibberty jibber jabber oh my god I gotta get out or I'm gonna have another work to sell another story to tell another time piece ringing the bell do you hear the clock stop when you reach the end no you don't so it must be neverending comprehend if you can but if you try to prentend you understand you resemble a fool and you're only a man so give it up and smile") - let msg = ChatLib.getChatMessage(event,false); + //console.log("do you hear the flibberty jibber jabber oh my god I gotta get out or I'm gonna have another work to sell another story to tell another time piece ringing the bell do you hear the clock stop when you reach the end no you don't so it must be neverending comprehend if you can but if you try to prentend you understand you resemble a fool and you're only a man so give it up and smile") + let msg = ChatLib.getChatMessage(event,false).toString(); console.log(msg); - if(fileToArray().includes(msg.toString())){ - + let wordCounter = 0; + const triggers = fileToArray(); + console.log(triggers) + for(var i = 0; i { // goal is to return a message, format shown below @@ -130,7 +154,7 @@ register("command", (...args) => { // goal is to return a message, format shown let triggers = fileToArray(); ChatLib.chat("[CP] Currently active keywords:") - for(var i = 0; i<=triggers.length-1; i++){ + for(var i = 0; i Date: Wed, 5 Jul 2023 19:51:16 -0700 Subject: [PATCH 8/8] deleting unnecessary comments --- index.js | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/index.js b/index.js index ffa58f3..01ceb84 100644 --- a/index.js +++ b/index.js @@ -79,23 +79,6 @@ register("chat", (event) => { } else console.log("skull") } - - - - - - - - /* - if(fileToArray().includes(msg.split(" "))){ - console.log("HAHAHA IT TRIGGELED") - ChatLib.chat("[CP]: \""+msg+"\" has triggered a ping!"); - //World.playSound("mob.ghast.affectionate_scream", 100, 0.1); - World.playSound("mob.guardian.death", 100, 1); - World.playSound("random.explode", 100, .5); - // play a sound or sth - } - */ }); register("command", (...args) => { // goal is to return a message, format shown below