mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-23 12:10:30 +03:00
Implement private messages
This commit is contained in:
parent
46d3d7575a
commit
ee23c1617a
15
client.go
15
client.go
@ -18,6 +18,7 @@ const HELP_TEXT string = `-> Available commands:
|
||||
/list
|
||||
/nick $NAME
|
||||
/whois $NAME
|
||||
/msg $NAME $MESSAGE
|
||||
`
|
||||
|
||||
const ABOUT_TEXT string = `-> ssh-chat is made by @shazow.
|
||||
@ -226,6 +227,20 @@ func (c *Client) handleShell(channel ssh.Channel) {
|
||||
client.Write(fmt.Sprintf("-> Silenced for %s by %s.", duration, c.ColoredName()))
|
||||
}
|
||||
}
|
||||
case "/msg": /* Send a PM */
|
||||
/* Make sure we have a recipient and a message */
|
||||
if len(parts) < 2 {
|
||||
c.Msg <- fmt.Sprintf("-> Missing $NAME from: /msg $NAME $MESSAGE")
|
||||
break
|
||||
} else if len(parts) < 3 {
|
||||
c.Msg <- fmt.Sprintf("-> Missing $MESSAGE from: /msg $NAME $MESSAGE")
|
||||
break
|
||||
}
|
||||
/* Ask the server to send the message */
|
||||
if err := c.Server.Privmsg(parts[1], parts[2], c); nil != err {
|
||||
c.Msg <- fmt.Sprintf("Unable to send message to %v: %v", parts[1], err)
|
||||
}
|
||||
|
||||
default:
|
||||
c.Msg <- fmt.Sprintf("-> Invalid command: %s", line)
|
||||
}
|
||||
|
13
server.go
13
server.go
@ -93,6 +93,19 @@ func (s *Server) Broadcast(msg string, except *Client) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Send a message to a particular nick, if it exists */
|
||||
func (s *Server) Privmsg(nick, message string, sender *Client) error {
|
||||
/* Get the recipient */
|
||||
target, ok := s.clients[nick]
|
||||
if !ok {
|
||||
return fmt.Errorf("no client with that nick")
|
||||
}
|
||||
/* Send the message */
|
||||
target.Msg <- fmt.Sprintf("\007[PM from %v] %v", sender.Name, message)
|
||||
logger.Debugf("PM from %v to %v: %v", sender.Name, nick, message)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) Add(client *Client) {
|
||||
go func() {
|
||||
client.WriteLines(s.history.Get(10))
|
||||
|
Loading…
x
Reference in New Issue
Block a user