mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-15 08:30:36 +03:00
40 lines
842 B
Go
40 lines
842 B
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/shazow/ssh-chat/chat"
|
|
)
|
|
|
|
// InitCommands adds host-specific commands to a Commands container.
|
|
func InitCommands(h *Host, c *chat.Commands) {
|
|
c.Add(chat.Command{
|
|
Op: true,
|
|
Prefix: "/msg",
|
|
PrefixHelp: "USER MESSAGE",
|
|
Help: "Send MESSAGE to USER.",
|
|
Handler: func(channel *chat.Channel, msg chat.CommandMsg) error {
|
|
if !channel.IsOp(msg.From()) {
|
|
return errors.New("must be op")
|
|
}
|
|
|
|
args := msg.Args()
|
|
switch len(args) {
|
|
case 0:
|
|
return errors.New("must specify user")
|
|
case 1:
|
|
return errors.New("must specify message")
|
|
}
|
|
|
|
member, ok := channel.MemberById(chat.Id(args[0]))
|
|
if !ok {
|
|
return errors.New("user not found")
|
|
}
|
|
|
|
m := chat.NewPrivateMsg("hello", msg.From(), member.User)
|
|
channel.Send(m)
|
|
return nil
|
|
},
|
|
})
|
|
}
|