cloudservices/src/events/messageCreate.ts

39 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-10-14 23:37:04 -04:00
import { Message, TextChannel } from 'eris';
2019-10-15 20:34:13 -04:00
import { Client, config, Util } from '..';
2019-10-14 23:37:04 -04:00
import Command from '../class/Command';
2019-10-14 19:04:07 -04:00
2019-10-15 20:34:13 -04:00
const { prefix } = config;
2019-10-14 19:04:07 -04:00
export default class {
client: Client
2019-10-14 23:37:04 -04:00
constructor(client: Client) {
this.client = client;
2019-10-14 19:04:07 -04:00
}
2019-10-15 14:03:40 -04:00
2019-10-15 10:42:42 -04:00
util: Util = new Util(this.client)
2019-10-14 19:04:07 -04:00
async run(message: Message) {
2019-10-15 19:10:37 -04:00
try {
const noPrefix: string[] = message.content.slice(prefix.length).trim().split(/ +/g);
const command: string = noPrefix[0].toLowerCase();
const resolved: Command = this.util.resolveCommand(command);
if (!resolved) return;
if (resolved.guildOnly && !(message.channel instanceof TextChannel)) return;
const hasUserPerms: boolean = resolved.permissions.users.includes(message.author.id);
let hasRolePerms: boolean = false;
for (const role of resolved.permissions.roles) {
if (message.member && message.member.roles.includes(role)) {
hasRolePerms = true; break;
}
2019-10-14 19:04:07 -04:00
}
2019-10-15 19:10:37 -04:00
if (!hasRolePerms && !hasUserPerms) return;
if (!resolved.enabled) { message.channel.createMessage(`***${this.client.stores.emojis.error} This command has been disabled***`); return; }
const args: string[] = noPrefix.slice(1);
resolved.run(message, args);
} catch (error) {
this.util.handleError(error, message);
2019-10-14 23:37:04 -04:00
}
2019-10-14 19:04:07 -04:00
}
2019-10-14 23:37:04 -04:00
}