import { Message } from 'discord.js';
import { EventHandler } from '../utils/types';
import { context } from '../config/context';
import { settingsStore } from '../config/state';

const event: EventHandler = {
  name: 'messageCreate',
  async execute(message: Message) {
    const cfg = message.guildId ? settingsStore.get(message.guildId) : undefined;
    if (message.guildId) context.admin.trackEvent('message', message.guildId);
    if (cfg?.automodEnabled === true) context.automod.checkMessage(message, cfg);
    if (cfg?.levelingEnabled === true) context.leveling.handleMessage(message);
    // Ticket SLA + KB
    await context.tickets.trackFirstResponse(message);
    await context.tickets.suggestKnowledgeBase(message);
  }
};

export default event;
