37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { BaseEvent } from '@/application/base/baseEvent'
|
|
import { SocketEvent } from '@/application/enums'
|
|
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(SocketEvent.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(SocketEvent.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)
|
|
}
|
|
}
|
|
}
|