1
0
forked from noxious/server

Major refractor, cleaning and improvements.

This commit is contained in:
2024-08-24 03:08:43 +02:00
parent e0b376cb83
commit 39f4e79a88
30 changed files with 123 additions and 69 deletions

View File

@ -0,0 +1,28 @@
import { Server } from 'socket.io'
import { TSocket } from '../../../utilities/types'
import { getArgs, isCommand } from '../../../utilities/chat'
import CharacterRepository from '../../../repositories/characterRepository'
type TypePayload = {
message: string
}
export default function (socket: TSocket, io: Server) {
socket.on('chat:send_message', async (data: TypePayload, callback: (response: boolean) => void) => {
try {
if (!isCommand(data.message, 'alert')) return
const args = getArgs('alert', data.message)
if (!args) return
const character = await CharacterRepository.getByUserAndId(socket.user?.id as number, socket.character?.id as number)
if (!character) return
io.emit('notification', { title: 'Message from GM', message: args.join(' ') })
callback(true)
} catch (error: any) {
console.log(`---Error sending message: ${error.message}`)
}
})
}