diff --git a/commands/Owner/flagparse.js b/commands/Owner/flagparse.js new file mode 100644 index 0000000..11e8fa4 --- /dev/null +++ b/commands/Owner/flagparse.js @@ -0,0 +1,25 @@ +const { MessageEmbed } = require("discord.js"); +const { flagParse } = require("../../config/flagParser.js"); + +module.exports = { + name: "flagparse", + description: "Evaluate entered code", + usage: "invite", + groups: ["utilites"], + DM: true, + cooldown: {type: "map", time: 0}, + aliases: ["fparse"], + run: async (client, message, args) => { + + let parse = await flagParse([ + {name: "good", args: [String]}, + {name: "bad", args: [String]} + ], args.join(" ")); + + const embed = new MessageEmbed() + .setTitle('Flag Parse') + .setDescription(`noFlags: ${parse.get("noFlag")}\nGood: ${parse.get("good")}\nbad: ${parse.get("bad")}\n`) + .setColor(0x4B0082); + message.reply(embed); + } +} \ No newline at end of file diff --git a/config/flagParser.js b/config/flagParser.js new file mode 100644 index 0000000..d62e1bb --- /dev/null +++ b/config/flagParser.js @@ -0,0 +1,34 @@ +exports.flagParse = async (flags, string) => { + // find all groups + let located = string.match(/("[^"]*")|([^"\s]*)/ig).filter(str => str !== ''); + const map = new Map(); + let currentFlag = ""; + console.log(located); + // combine two that are next to eachother + for (let current of located) { + // make and set currentFlag + if (current.match(/^-/ig)) { + for (let flag of flags) { + if (flag.name == current.slice(1)) { + map.set(flag.name, []); + currentFlag = current.slice(1); + } + }; + // add to an exsisting flag + } else if (currentFlag) { + map.get(currentFlag).push(current) + // There was no flag defiend to add to + } else { + if (!map.get("noFlag")) { + map.set("noFlag", [current]); + currentFlag = "noFlag" + continue + } + map.get("noFlag").push(current); + } + } + + + console.log(map); + return map; +} \ No newline at end of file