forked from Crenshaw1312/Jackson
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is set up to support and require certain args per flag, so I'll be makin an embed command with fields support to demonstrate this later
- Loading branch information
Crenshaw
committed
Mar 14, 2021
1 parent
42db699
commit e06e337
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |