Files
dumpsterChat/internal/gateway/events.go
T
hobokenchicken 7c70082f37 feat(bots): bot framework polish + store
- /ws/bot endpoint: bot token auth via query param, SHA-256 lookup
- Bot WS actions: SEND_MESSAGE + DELETE_MESSAGE handled in gateway
- Bot messages: bot_id on messages table, bot badge in chat (green + BOT tag)
- Bot store: /bots lists all bots with server count + add-to-server
- Bot manager moved to /bots/manage
- Fix: command routes were double-nested under /bots/{botID}/commands
- Fix: fetchServerCommands route corrected to /bots/servers/...
2026-07-15 12:45:44 -04:00

64 lines
1.7 KiB
Go

package gateway
import "encoding/json"
// Event type constants.
const (
EventMessageCreate = "MESSAGE_CREATE"
EventMessageUpdate = "MESSAGE_UPDATE"
EventMessageDelete = "MESSAGE_DELETE"
EventChannelCreate = "CHANNEL_CREATE"
EventChannelUpdate = "CHANNEL_UPDATE"
EventChannelDelete = "CHANNEL_DELETE"
EventMemberAdd = "SERVER_MEMBER_ADD"
EventMemberRemove = "SERVER_MEMBER_REMOVE"
EventPresenceUpdate = "PRESENCE_UPDATE"
EventTypingStart = "TYPING_START"
EventReactionAdd = "REACTION_ADD"
EventReactionRemove = "REACTION_REMOVE"
EventBotJoin = "BOT_JOIN"
EventBotLeave = "BOT_LEAVE"
EventVoiceJoin = "VOICE_JOIN"
EventVoiceLeave = "VOICE_LEAVE"
EventVoiceMute = "VOICE_MUTE"
EventVoiceDeafen = "VOICE_DEAFEN"
EventVoiceWhisper = "VOICE_WHISPER"
// Bot action events (sent by bot clients)
BotSendMessage = "SEND_MESSAGE"
BotDeleteMessage = "DELETE_MESSAGE"
)
// Event represents a WebSocket event sent to clients.
type Event struct {
Type string `json:"type"`
Data interface{} `json:"data,omitempty"`
}
// MarshalJSON implements custom JSON marshaling for Event.
func (e Event) MarshalJSON() ([]byte, error) {
type eventAlias struct {
Type string `json:"type"`
Data interface{} `json:"data,omitempty"`
}
return json.Marshal(eventAlias{
Type: e.Type,
Data: e.Data,
})
}
// UnmarshalJSON implements custom JSON unmarshaling for Event.
func (e *Event) UnmarshalJSON(data []byte) error {
type eventAlias struct {
Type string `json:"type"`
Data json.RawMessage `json:"data,omitempty"`
}
var raw eventAlias
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
e.Type = raw.Type
e.Data = raw.Data
return nil
}