server/src/events/chat/gameMaster/alertCommand.ts
2025-01-04 19:05:54 +01:00

36 lines
1.0 KiB
TypeScript

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<void> {
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)
}
}
}