diff --git a/index.js b/index.js new file mode 100644 index 0000000..01ceb84 --- /dev/null +++ b/index.js @@ -0,0 +1,156 @@ +/// +/// + +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"); + +// 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("^&$"); + 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; + } + + +} + +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", () => { + 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).toString(); + console.log(msg); + let wordCounter = 0; + const triggers = fileToArray(); + console.log(triggers) + for(var i = 0; i { // goal is to return a message, format shown below + 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: 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