refactor: unify all C2S commands through POST /messages

All client-to-server commands now go through POST /api/v1/messages
with a 'command' field. The server dispatches by command type:

- PRIVMSG/NOTICE: send message to channel or user
- JOIN: join channel (creates if needed)
- PART: leave channel
- NICK: change nickname
- TOPIC: set channel topic
- PING: keepalive (returns PONG)

Removed separate routes:
- POST /channels/join
- DELETE /channels/{channel}
- POST /register (renamed to POST /session)
- GET /channels/all (moved to GET /channels)

Added DB methods: ChangeNick, SetTopic
This commit is contained in:
clawbot
2026-02-10 17:53:08 -08:00
parent f7776f8d3f
commit 0ee3fd78d2
3 changed files with 172 additions and 99 deletions

View File

@@ -372,7 +372,21 @@ func (s *Database) GetDMsBefore(ctx context.Context, userA, userB int64, beforeI
return msgs, nil
}
// GetMOTD returns the server MOTD from config.
// ChangeNick updates a user's nickname.
func (s *Database) ChangeNick(ctx context.Context, userID int64, newNick string) error {
_, err := s.db.ExecContext(ctx,
"UPDATE users SET nick = ? WHERE id = ?", newNick, userID)
return err
}
// SetTopic sets the topic for a channel.
func (s *Database) SetTopic(ctx context.Context, channelName string, _ int64, topic string) error {
_, err := s.db.ExecContext(ctx,
"UPDATE channels SET topic = ? WHERE name = ?", topic, channelName)
return err
}
// GetServerName returns the server name (unused, config provides this).
func (s *Database) GetServerName() string {
return ""
}