github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/chat/commands/msg.go (about) 1 package commands 2 3 import ( 4 "context" 5 "strings" 6 7 "github.com/keybase/client/go/chat/globals" 8 "github.com/keybase/client/go/protocol/chat1" 9 "github.com/keybase/client/go/protocol/gregor1" 10 ) 11 12 type Msg struct { 13 *baseCommand 14 } 15 16 func NewMsg(g *globals.Context) *Msg { 17 return &Msg{ 18 baseCommand: newBaseCommand(g, "msg", "<conversation> <message>", 19 "Send a message to a conversation", false, "dm"), 20 } 21 } 22 23 func (d *Msg) Execute(ctx context.Context, uid gregor1.UID, convID chat1.ConversationID, 24 tlfName, text string, replyTo *chat1.MessageID) (err error) { 25 defer d.Trace(ctx, &err, "Execute")() 26 if !d.Match(ctx, text) { 27 return ErrInvalidCommand 28 } 29 defer func() { 30 if err != nil { 31 err := d.getChatUI().ChatCommandStatus(ctx, convID, "Failed to send message", 32 chat1.UICommandStatusDisplayTyp_ERROR, nil) 33 if err != nil { 34 d.Debug(ctx, "Execute: error with command status: %+v", err) 35 } 36 } 37 }() 38 toks, err := d.tokenize(text, 3) 39 if err != nil { 40 return err 41 } 42 conv, err := getConvByName(ctx, d.G(), uid, toks[1]) 43 if err != nil { 44 return err 45 } 46 text = strings.Join(toks[2:], " ") 47 _, err = d.G().ChatHelper.SendTextByIDNonblock(ctx, conv.GetConvID(), conv.Info.TlfName, text, nil, 48 replyTo) 49 return err 50 }