import express from 'express';
import { ChatColor, ChatColors } from '../../../../const/chat-colors';
import { ChatSystem } from '../../../../features/chat';
import { motdSystem } from '../../../../features/motd';

export async function MotdPublish(req: express.Request, res: express.Response): Promise<express.Response<any, Record<string, any>>> {
    if (!req.body.by) {
        res.status(400).send('Missing parameter');
    }

    ChatSystem.AdminWarn(`${req.body.by} published a new MOTD.`);

    await motdSystem.init();
    mp.players.toArray().forEach((player) => {
        ChatSystem.Message(
            player,
            `${ChatColor('a7cdff')}A new Message of the Day has been posted. Use /${ChatColor('529cfd')}motd${ChatColor('a7cdff')} to view it.`,
        );
    });

    return res.sendStatus(200);
}
