re-formatted, better structure
This commit is contained in:
@@ -1,71 +1 @@
|
||||
// handlers.go
|
||||
package ws
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
"time"
|
||||
)
|
||||
|
||||
type LoggingModHandler struct {
|
||||
logger *slog.Logger
|
||||
}
|
||||
|
||||
type LoggingBotHandler struct {
|
||||
logger *slog.Logger
|
||||
}
|
||||
|
||||
func NewLoggingModHandler(logger *slog.Logger) *LoggingModHandler {
|
||||
return &LoggingModHandler{logger: logger}
|
||||
}
|
||||
|
||||
func NewLoggingBotHandler(logger *slog.Logger) *LoggingBotHandler {
|
||||
return &LoggingBotHandler{logger: logger}
|
||||
}
|
||||
|
||||
func (h *LoggingModHandler) Handle(ctx context.Context, msg GatewayModMessageIn) error {
|
||||
// For now, just log and pretend it's being forwarded
|
||||
// TODO: Look up channel_id from database using server
|
||||
// TODO: Forward to bot connection(s)
|
||||
|
||||
fwd := ForwardedModMessage{
|
||||
Type: "mod",
|
||||
ServerID: msg.Server,
|
||||
ChannelID: "TODO", // will come from database lookup
|
||||
User: msg.User,
|
||||
Content: msg.Content,
|
||||
Meta: msg.Meta,
|
||||
Ts: msg.Ts,
|
||||
ReceivedAt: msg.ReceivedAt,
|
||||
ForwardedAt: time.Now().UTC(),
|
||||
}
|
||||
|
||||
b, _ := json.Marshal(fwd)
|
||||
h.logger.Debug("forwarding mod message", "msg_id", msg.MsgID, "server", msg.Server, "payload", string(b))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *LoggingBotHandler) Handle(ctx context.Context, msg GatewayBotMessageIn) error {
|
||||
// For now, just log and pretend it's being forwarded
|
||||
// TODO: Look up server_id from database using channel_id
|
||||
// TODO: Forward to mod connection(s)
|
||||
|
||||
fwd := ForwardedBotMessage{
|
||||
Type: "bot",
|
||||
ServerID: "TODO", // will come from database lookup
|
||||
ChannelID: msg.ChannelID,
|
||||
Author: msg.Author,
|
||||
Content: msg.Content,
|
||||
Meta: msg.Meta,
|
||||
Ts: msg.Ts,
|
||||
ReceivedAt: msg.ReceivedAt,
|
||||
ForwardedAt: time.Now().UTC(),
|
||||
}
|
||||
|
||||
b, _ := json.Marshal(fwd)
|
||||
h.logger.Debug("forwarding bot message", "msg_id", msg.MsgID, "channel", msg.ChannelID, "payload", string(b))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user