2024-03-10 16:38:18 +00:00
|
|
|
package chat
|
|
|
|
|
|
|
|
import (
|
2024-03-14 12:33:52 +00:00
|
|
|
"log/slog"
|
|
|
|
|
2024-03-10 16:38:18 +00:00
|
|
|
"git.sr.ht/~ashkeel/strimertul/database"
|
2024-03-16 00:20:15 +00:00
|
|
|
"git.sr.ht/~ashkeel/strimertul/log"
|
2024-03-10 16:38:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// WriteMessageRequest is an RPC to send a chat message with extra options
|
|
|
|
type WriteMessageRequest struct {
|
|
|
|
Message string `json:"message" desc:"Chat message to send"`
|
|
|
|
ReplyTo string `json:"reply_to,omitempty" desc:"If specified, send as reply to a message ID"`
|
|
|
|
WhisperTo string `json:"whisper_to,omitempty" desc:"If specified, send as whisper to user ID"`
|
|
|
|
Announce bool `json:"announce" desc:"If true, send as announcement"`
|
|
|
|
}
|
|
|
|
|
2024-03-14 12:33:52 +00:00
|
|
|
func WriteMessage(db database.Database, logger *slog.Logger, m WriteMessageRequest) {
|
2024-03-10 16:38:18 +00:00
|
|
|
err := db.PutJSON(WriteMessageRPC, m)
|
|
|
|
if err != nil {
|
2024-03-16 00:20:15 +00:00
|
|
|
logger.Error("Failed to write chat message", log.Error(err))
|
2024-03-10 16:38:18 +00:00
|
|
|
}
|
|
|
|
}
|