1
0
Fork 0
cloudservices/src/events/messageCreate.ts

47 lines
1.9 KiB
TypeScript
Raw Normal View History

2019-10-14 23:37:04 -04:00
import { Message, TextChannel } from 'eris';
2019-10-28 16:21:04 -04:00
import { Client } from '..';
2019-10-14 23:37:04 -04:00
import Command from '../class/Command';
2019-10-14 19:04:07 -04:00
export default class {
public 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
public async run(message: Message) {
2019-10-15 19:10:37 -04:00
try {
2019-10-28 16:21:04 -04:00
if (message.author.bot) return;
if (message.content.indexOf(this.client.config.prefix) !== 0) return;
const noPrefix: string[] = message.content.slice(this.client.config.prefix.length).trim().split(/ +/g);
2019-10-15 19:10:37 -04:00
const command: string = noPrefix[0].toLowerCase();
2019-10-29 17:44:12 -04:00
const Args = noPrefix.slice(1);
const resolved: { command: Command, args: string[] } = this.client.util.resolveCommand(command, Args);
2019-10-15 19:10:37 -04:00
if (!resolved) return;
2019-10-29 17:44:12 -04:00
if (resolved.command.guildOnly && !(message.channel instanceof TextChannel)) return;
2019-10-28 16:21:04 -04:00
let hasUserPerms: boolean;
2019-10-29 17:44:12 -04:00
if (resolved.command.permissions.users) {
hasUserPerms = resolved.command.permissions.users.includes(message.author.id);
2019-10-28 16:21:04 -04:00
}
2019-10-15 19:10:37 -04:00
let hasRolePerms: boolean = false;
2019-10-29 17:44:12 -04:00
if (resolved.command.permissions.roles) {
for (const role of resolved.command.permissions.roles) {
2019-10-28 16:21:04 -04:00
if (message.member && message.member.roles.includes(role)) {
// this.client.signale.debug(message.member.roles.includes(role));
hasRolePerms = true; break;
}
2019-10-15 19:10:37 -04:00
}
2019-10-14 19:04:07 -04:00
}
2019-10-29 17:44:12 -04:00
if (!resolved.command.permissions.users && !resolved.command.permissions.roles) {
2019-10-28 16:21:04 -04:00
hasUserPerms = true;
hasRolePerms = true;
}
2019-10-15 19:10:37 -04:00
if (!hasRolePerms && !hasUserPerms) return;
2019-10-29 17:44:12 -04:00
if (!resolved.command.enabled) { message.channel.createMessage(`***${this.client.stores.emojis.error} This command has been disabled***`); return; }
resolved.command.run(message, resolved.args);
2019-10-15 19:10:37 -04:00
} catch (error) {
this.client.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
}