import { BaseEvent } from '#application/base/baseEvent' import CharacterRepository from '#repositories/characterRepository' import ChatService from '#services/chatService' type TypePayload = { message: string } export default class AlertCommandEvent extends BaseEvent { public listen(): void { this.socket.on('chat:message', this.handleEvent.bind(this)) } private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise { try { // Check if command is alert if (!ChatService.isCommand(data.message, 'alert')) return // Check if character exists if (!(await this.isCharacterGM())) return const args = ChatService.getArgs('alert', data.message) if (!args) { return callback(false) } this.io.emit('notification', { title: 'Message from GM', message: args.join(' ') }) return callback(true) } catch (error: any) { this.logger.error('chat:alert_command error', error.message) callback(false) } } }