2020-01-21 05:22:24 +13:00
|
|
|
package websocket
|
|
|
|
|
|
|
|
import (
|
2020-01-25 04:47:37 +13:00
|
|
|
"n.eko.moe/neko/internal/types"
|
|
|
|
"n.eko.moe/neko/internal/types/event"
|
|
|
|
"n.eko.moe/neko/internal/types/message"
|
2020-01-21 05:22:24 +13:00
|
|
|
)
|
|
|
|
|
2020-02-27 01:46:10 +13:00
|
|
|
func (h *MessageHandler) chat(id string, session types.Session, payload *message.ChatReceive) error {
|
2020-01-25 04:47:37 +13:00
|
|
|
if session.Muted() {
|
2020-01-23 06:16:40 +13:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-27 01:46:10 +13:00
|
|
|
if err := h.sessions.Broadcast(
|
2020-01-21 05:22:24 +13:00
|
|
|
message.ChatSend{
|
|
|
|
Event: event.CHAT_MESSAGE,
|
|
|
|
Content: payload.Content,
|
|
|
|
ID: id,
|
|
|
|
}, nil); err != nil {
|
2020-02-27 01:46:10 +13:00
|
|
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_RELEASE)
|
2020-01-21 05:22:24 +13:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-27 01:46:10 +13:00
|
|
|
func (h *MessageHandler) chatEmote(id string, session types.Session, payload *message.EmoteReceive) error {
|
2020-01-25 04:47:37 +13:00
|
|
|
if session.Muted() {
|
2020-01-23 06:16:40 +13:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-27 01:46:10 +13:00
|
|
|
if err := h.sessions.Broadcast(
|
2020-01-24 04:23:26 +13:00
|
|
|
message.EmoteSend{
|
|
|
|
Event: event.CHAT_EMOTE,
|
|
|
|
Emote: payload.Emote,
|
2020-01-21 05:22:24 +13:00
|
|
|
ID: id,
|
|
|
|
}, nil); err != nil {
|
2020-02-27 01:46:10 +13:00
|
|
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_RELEASE)
|
2020-01-21 05:22:24 +13:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|