MVP for nested commands
All checks were successful
NodBot Production Dockerization / build (pull_request) Successful in 53s
All checks were successful
NodBot Production Dockerization / build (pull_request) Successful in 53s
This commit is contained in:
parent
2cbfc7f354
commit
e4fbcca6c4
@ -8,6 +8,7 @@ module.exports = {
|
||||
this.args = message.content.slice(0,this.finalPeriod).toLowerCase(); // Grab everything leading up to the final period
|
||||
this.command = message.content.slice(this.finalPeriod + 1).toLowerCase(); // Grab everything after the final period
|
||||
this.author = message.author.username;
|
||||
this.message = message;
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -16,25 +17,110 @@ module.exports = {
|
||||
if (this.args.startsWith('http')) return false;
|
||||
if (this.args.startsWith('www')) return false;
|
||||
|
||||
const indices = {
|
||||
curlyBrace: {
|
||||
start: -1,
|
||||
end: -1
|
||||
},
|
||||
bracket: {
|
||||
start: -1,
|
||||
end: -1
|
||||
},
|
||||
parenthesis: {
|
||||
start: -1,
|
||||
end: -1
|
||||
}
|
||||
}
|
||||
|
||||
// Check for and extract the part of the message that's
|
||||
// wrapped in any type of brackets or quotes eg. ([{``''""}])
|
||||
const bracketStart = this.args.match(/[\[\(\{\`\'\"\`]/g);
|
||||
const bracketEnd = this.args.match(/[\]\)\}\`\'\"\`]/g);
|
||||
let bracketedText = new String();
|
||||
if ((bracketStart && bracketEnd) && (bracketStart.length !== bracketEnd.length)) {
|
||||
bracketedText = this.args.slice(this.args.indexOf(bracketStart[0]), this.args.lastIndexOf(bracketEnd[0]) + 1);
|
||||
this.args = this.args.replace(bracketedText, '');
|
||||
const curlyBraceStart = this.message.content.match(/[\{]/g);
|
||||
const curlyBraceEnd = this.message.content.match(/[\}]/g);
|
||||
if (curlyBraceStart && curlyBraceEnd) {
|
||||
indices.curlyBrace.start = this.message.content.indexOf(curlyBraceStart[0]) + 1;
|
||||
indices.curlyBrace.end = this.message.content.lastIndexOf(curlyBraceEnd[0]);
|
||||
}
|
||||
|
||||
const bracketStart = this.message.content.match(/[\[]/g);
|
||||
const bracketEnd = this.message.content.match(/[\]]/g);
|
||||
if (bracketStart && bracketEnd) {
|
||||
indices.bracket.start = this.message.content.indexOf(bracketStart[0]) + 1;
|
||||
indices.bracket.end = this.message.content.lastIndexOf(bracketEnd[0]);
|
||||
}
|
||||
|
||||
const parenthesisStart = this.message.content.match(/[\(]/g);
|
||||
const parenthesisEnd = this.message.content.match(/[\)]/g);
|
||||
if (parenthesisStart && parenthesisEnd) {
|
||||
indices.parenthesis.start = this.message.content.indexOf(parenthesisStart[0]) + 1;
|
||||
indices.parenthesis.end = this.message.content.lastIndexOf(parenthesisEnd[0]);
|
||||
}
|
||||
|
||||
let nestedText = new String();
|
||||
|
||||
if (indices.curlyBrace.start >= 0 && indices.curlyBrace.end > 0) {
|
||||
nestedText = this.message.content.slice(indices.curlyBrace.start, indices.curlyBrace.end);
|
||||
}
|
||||
|
||||
if (indices.bracket.start >= 0 && indices.bracket.end > 0) {
|
||||
nestedText = this.message.content.slice(indices.bracket.start, indices.bracket.end);
|
||||
}
|
||||
|
||||
if (indices.parenthesis.start >= 0 && indices.parenthesis.end > 0) {
|
||||
nestedText = this.message.content.slice(indices.parenthesis.start, indices.parenthesis.end);
|
||||
}
|
||||
|
||||
console.log(nestedText);
|
||||
|
||||
if (nestedText !== "") {
|
||||
this.nestedCommand = {
|
||||
finalPeriod: nestedText.lastIndexOf('.'),
|
||||
isCommand: nestedText.lastIndexOf('.') >= 0 ? true : false,
|
||||
args: nestedText.slice(0, nestedText.lastIndexOf('.')).toLowerCase(),
|
||||
command: nestedText.slice(nestedText.lastIndexOf('.') + 1).toLowerCase()
|
||||
}
|
||||
|
||||
for (const [key, value] of dotCommands) {
|
||||
if (key === this.nestedCommand.command) {
|
||||
this.isValid = true;
|
||||
this.args = this.nestedCommand.args;
|
||||
this.command = key;
|
||||
this.isCommand = this.nestedCommand.isCommand;
|
||||
this.finalPeriod = this.nestedCommand.finalPeriod;
|
||||
return this;
|
||||
} else if (value.alias) {
|
||||
if (typeof value.alias === 'string' && value.alias === this.nestedCommand.command) {
|
||||
this.command = key
|
||||
this.args = this.nestedCommand.args;
|
||||
this.isValid = true;
|
||||
this.isCommand = this.nestedCommand.isCommand;
|
||||
this.finalPeriod = this.nestedCommand.finalPeriod;
|
||||
return this;
|
||||
} else if (typeof value.alias === 'object' && value.alias.includes(this.nestedCommand.command)) {
|
||||
this.command = key
|
||||
this.args = this.nestedCommand.args;
|
||||
this.isValid = true;
|
||||
this.isCommand = this.nestedCommand.isCommand;
|
||||
this.finalPeriod = this.nestedCommand.finalPeriod;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(bracketedText);
|
||||
|
||||
for (const [key, value] of dotCommands) {
|
||||
if (key === this.command) {
|
||||
this.isValid = true;
|
||||
return this;
|
||||
} else if (value.alias && value.alias.includes(this.command)) {
|
||||
} else if (value.alias) {
|
||||
if (typeof value.alias === 'string' && value.alias === this.command) {
|
||||
this.command = key;
|
||||
this.isValid = true;
|
||||
return this;
|
||||
} else if (typeof value.alias === 'object' && value.alias.includes(this.command)) {
|
||||
this.command = key;
|
||||
this.isValid = true;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
|
Loading…
Reference in New Issue
Block a user