forked from noxious/server
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import { BaseEvent } from '#application/base/baseEvent'
|
|
import WeatherManager from '#managers/weatherManager'
|
|
import CharacterRepository from '#repositories/characterRepository'
|
|
import ChatService from '#services/chatService'
|
|
|
|
type TypePayload = {
|
|
message: string
|
|
}
|
|
|
|
export default class ToggleRainCommand 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 rain
|
|
if (!ChatService.isCommand(data.message, 'rain')) return
|
|
|
|
// Check if character exists and is GM
|
|
if (!(await this.isCharacterGM())) return
|
|
|
|
let args = ChatService.getArgs('rain', data.message)
|
|
|
|
//if no arguments are given, should default to random
|
|
await WeatherManager.setRainValue(Number(args![0]))
|
|
|
|
} catch (error: any) {
|
|
this.logger.error('command error', error.message)
|
|
callback(false)
|
|
}
|
|
}
|
|
}
|