forked from Galactic/galactic-bot
Merge branch 'master' of https://github.com/Navy-gif/New-GBot
This commit is contained in:
commit
3423828dac
@ -12,4 +12,8 @@ Pong! {number}
|
||||
**Last global activity:** {globalActivity}
|
||||
**Roles:** {roles}
|
||||
|
||||
[C_SEARCH_USER]
|
||||
[C_SEARCH_USER_TITLE]
|
||||
Search result for keyword: `{key}`
|
||||
|
||||
[C_SEARCH_USER_FOOTER]
|
||||
Found {matches} matches, displaying {count}
|
@ -4,7 +4,6 @@
|
||||
"description": "New iteration of GalacticBot",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"repository": {
|
||||
|
@ -1,4 +1,4 @@
|
||||
const { Command } = require('../../../../interfaces/');
|
||||
const { Command, Argument } = require('../../../../interfaces/');
|
||||
const similarity = require('similarity');
|
||||
|
||||
class UserCommand extends Command {
|
||||
@ -8,7 +8,17 @@ class UserCommand extends Command {
|
||||
super(client, {
|
||||
name: 'user',
|
||||
module: 'utility',
|
||||
description: "Display information about user."
|
||||
description: "Display information about user.",
|
||||
guildOnly: true,
|
||||
arguments: [
|
||||
new Argument(client, {
|
||||
name: 'search',
|
||||
type: 'string',
|
||||
types: ['FLAG', 'VERBAL'],
|
||||
requiredValue: true
|
||||
}),
|
||||
|
||||
]
|
||||
});
|
||||
|
||||
this.client = client;
|
||||
@ -16,14 +26,13 @@ class UserCommand extends Command {
|
||||
|
||||
}
|
||||
|
||||
async execute(message, { params }) {
|
||||
async execute(message, { params, args }) {
|
||||
|
||||
let search = params[0] ? params[0].toLowerCase() === 'search' : false;
|
||||
let response = '';
|
||||
if(search && params.length > 1) {
|
||||
let response;
|
||||
if(args.search && args.search.value.length > 1) {
|
||||
|
||||
params.shift();
|
||||
let key = params.join(' '), count = 0;
|
||||
let key = args.search.value,
|
||||
count = 0;
|
||||
|
||||
let members = message.guild.members.cache.filter(m => {
|
||||
return (m.nickname && (m.nickname.toLowerCase().includes(key) || (similarity(m.nickname.toLowerCase(), key) > 0.75 && Math.abs(m.nickname.length - key.length) < 3) )) ||
|
||||
@ -38,17 +47,26 @@ class UserCommand extends Command {
|
||||
|
||||
response = {
|
||||
description: response,
|
||||
title: `Search result for keyword: \`${key}\``,
|
||||
title: message.format('C_SEARCH_USER_TITLE', {
|
||||
key: key
|
||||
}),
|
||||
color: 0x0088cc,
|
||||
footer: {
|
||||
text: `Found ${members.size} matches, displaying ${count}`
|
||||
text: message.format('C_SEARCH_USER_FOOTER', {
|
||||
matches: members.size,
|
||||
count
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
} else {
|
||||
|
||||
let user = await this.client.resolver.resolveUser(params.length > 0 ? params.join(' ') : message.author.id).catch(console.error);
|
||||
if(!user) return message.respond('No user found.');
|
||||
let user;
|
||||
if (params.length > 0) {
|
||||
user = await this.client.resolver.resolveUser(params.join(' ')).catch(console.error);
|
||||
if (!user) return message.respond('No user found.');
|
||||
} else user = message.author;
|
||||
|
||||
let member = await message.guild.members.fetch(user.id).catch(console.error);
|
||||
|
||||
response = message.format('C_USER', {
|
||||
|
@ -175,7 +175,6 @@ class CommandHandler extends Observer {
|
||||
}
|
||||
if(currentArgument.required && !args[i+1]) {
|
||||
return this._handleError({ type: 'argument', info: { argument: currentArgument, word, missing: true }, message });
|
||||
//console.error(`Argument ${currentArgument.name} is required and was not provided.`);
|
||||
}
|
||||
continue;
|
||||
} else if((one === '-' && two === '-') || one === '—') { //Handling for "long dash" on mobile phones x_x
|
||||
@ -192,7 +191,6 @@ class CommandHandler extends Observer {
|
||||
}
|
||||
if(currentArgument.required && !args[i+1]) {
|
||||
return this._handleError({ type: 'argument', info: { argument: currentArgument, word, missing: true }, message });
|
||||
//console.error(`Argument ${currentArgument.name} is required and was not provided.`);
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
@ -218,7 +216,6 @@ class CommandHandler extends Observer {
|
||||
if(error) {
|
||||
if(currentArgument.required) {
|
||||
return this._handleError({ type: 'argument', info: { argument: currentArgument, word, missing: false }, message });
|
||||
// console.error(`Argument ${currentArgument.name} is required and failed to meet requirements.`);
|
||||
} else {
|
||||
parsedArguments.push(currentArgument);
|
||||
currentArgument = null;
|
||||
@ -248,7 +245,6 @@ class CommandHandler extends Observer {
|
||||
if(currentArgument.infinite) {
|
||||
if(currentArgument.value.length === 0) {
|
||||
return this._handleError({ type: 'argument', info: { argument: currentArgument, word, missing: false }, message });
|
||||
// console.error(`Argument ${currentArgument.name} is required and failed to meet requirements.`);
|
||||
} else {
|
||||
parsedArguments.push(currentArgument);
|
||||
currentArgument = null;
|
||||
@ -257,7 +253,6 @@ class CommandHandler extends Observer {
|
||||
}
|
||||
} else {
|
||||
return this._handleError({ type: 'argument', info: { argument: currentArgument, word, missing: false }, message });
|
||||
// console.error(`Argument ${currentArgument.name} is required and failed to meet requirements.`);
|
||||
}
|
||||
} else {
|
||||
currentArgument = null;
|
||||
@ -283,6 +278,11 @@ class CommandHandler extends Observer {
|
||||
}
|
||||
}
|
||||
|
||||
const blah = parsedArguments.filter(a=>a.requiredArgument && !a.value);
|
||||
const missingArgument = blah[0];
|
||||
if(missingArgument) return this._handleError({ type: 'argument', info: { argument: missingArgument, missing: true }, message });
|
||||
|
||||
|
||||
//fucking kill me
|
||||
const fff = {};
|
||||
parsedArguments.map(a=>fff[a.name] = a);
|
||||
@ -456,6 +456,15 @@ class CommandHandler extends Observer {
|
||||
if(truthy.includes(str)) return { error: false, value: true };
|
||||
if(falsey.includes(str)) return { error: false, value: false };
|
||||
return { error: true };
|
||||
},
|
||||
USER: (str) => { //eslint-disable-line no-unused-vars
|
||||
|
||||
},
|
||||
MEMBER: (str) => { //eslint-disable-line no-unused-vars
|
||||
|
||||
},
|
||||
CHANNEL: (str) => { //eslint-disable-line no-unused-vars
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
const { Util } = require('../../util');
|
||||
|
||||
class Argument {
|
||||
|
||||
constructor(client, options = {}) {
|
||||
@ -20,6 +18,7 @@ class Argument {
|
||||
|
||||
//NOTE: Instead of telling the person the argument is missing and is required, ask them and continue the command execution afterwards. More work to do.
|
||||
|
||||
this.requiredValue = Boolean(options.requiredValue);
|
||||
this.required = options.type === 'BOOLEAN' ? false : Boolean(options.required); //If the argument must be required for the command to work. Booleans
|
||||
this.default = options.default === null ? Constants.Defaults[options.type] : options.default;
|
||||
this.infinite = Boolean(options.infinite); //Accepts infinite amount of arguments e.g. -u @nolan @navy. If false, will only detect one user.
|
||||
@ -42,9 +41,9 @@ module.exports = Argument;
|
||||
|
||||
const Constants = {
|
||||
Defaults: { //these dont really mean anything, just default values. Most important one is the boolean one.
|
||||
STRING: 'okay',
|
||||
INTEGER: 5,
|
||||
FLOAT: 2.5,
|
||||
STRING: '',
|
||||
INTEGER: 0,
|
||||
FLOAT: 0,
|
||||
BOOLEAN: true
|
||||
},
|
||||
Types: [
|
||||
|
Loading…
Reference in New Issue
Block a user