2020-04-14 19:03:10 -04:00
|
|
|
import { Member, Message, Guild } from 'eris';
|
2020-04-14 13:15:33 -04:00
|
|
|
import { Client, Command } from '.';
|
2020-04-14 21:18:44 -04:00
|
|
|
import { statusMessages as emotes } from '../configs/emotes.json';
|
2020-04-14 13:15:33 -04:00
|
|
|
|
|
|
|
export default class Util {
|
|
|
|
public client: Client;
|
|
|
|
|
|
|
|
constructor(client: Client) {
|
|
|
|
this.client = client;
|
|
|
|
}
|
|
|
|
|
|
|
|
get emojis() {
|
|
|
|
return {
|
2020-04-14 21:18:44 -04:00
|
|
|
SUCCESS: emotes.success,
|
|
|
|
LOADING: emotes.loading,
|
|
|
|
ERROR: emotes.error,
|
2020-04-14 13:15:33 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolves a command
|
|
|
|
* @param query Command input
|
|
|
|
* @param message Only used to check for errors
|
|
|
|
*/
|
|
|
|
public resolveCommand(query: string | string[]): Promise<{cmd: Command, args: string[] }> {
|
|
|
|
try {
|
|
|
|
// let resolvedCommand: Command;
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
if (typeof query === 'string') query = query.split(' ');
|
|
|
|
const commands = this.client.commands.toArray();
|
|
|
|
const resolvedCommand = commands.find((c) => c.name === query[0].toLowerCase() || c.aliases.includes(query[0].toLowerCase()));
|
|
|
|
|
|
|
|
if (!resolvedCommand) return Promise.resolve(null);
|
|
|
|
query.shift();
|
|
|
|
return Promise.resolve({ cmd: resolvedCommand, args: query });
|
|
|
|
} catch (error) {
|
|
|
|
return Promise.reject(error);
|
|
|
|
}
|
|
|
|
}
|
2020-04-14 19:03:10 -04:00
|
|
|
|
|
|
|
public resolveMember(message: Message, search: string, guild: Guild): Member | undefined {
|
|
|
|
try {
|
|
|
|
let mem = guild.members.find((member) => `${member.user.username}#${member.user.discriminator}` === search || member.user.username === search || member.id === search || (message.mentions[0] && member.id === message.mentions[0].id) || (member.nick !== undefined && member.nick === search));
|
|
|
|
// eslint-disable-next-line no-mixed-operators
|
|
|
|
if (!mem) mem = guild.members.find((member) => `${member.user.username.toLowerCase()}#${member.user.discriminator}` === search.toLowerCase() || member.user.username.toLowerCase() === search.toLowerCase() || member.nick !== undefined && member.nick.toLowerCase() === search.toLowerCase());
|
|
|
|
// eslint-disable-next-line no-mixed-operators
|
|
|
|
if (!mem) mem = guild.members.find((member) => member.user.username.toLowerCase().includes(search.toLowerCase()) || member.nick !== undefined && member.nick.toLowerCase().includes(search.toLowerCase()));
|
|
|
|
if (mem) return mem;
|
|
|
|
return undefined;
|
|
|
|
} catch {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
}
|
2020-04-14 13:15:33 -04:00
|
|
|
}
|