github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/chat/commands/me.go (about)

     1  package commands
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     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 Me struct {
    13  	*baseCommand
    14  }
    15  
    16  func NewMe(g *globals.Context) *Me {
    17  	return &Me{
    18  		baseCommand: newBaseCommand(g, "me", "<message>", "Displays action text", false),
    19  	}
    20  }
    21  
    22  func (s *Me) Execute(ctx context.Context, uid gregor1.UID, convID chat1.ConversationID,
    23  	tlfName, text string, replyTo *chat1.MessageID) (err error) {
    24  	defer s.Trace(ctx, &err, "Execute")()
    25  	if !s.Match(ctx, text) {
    26  		return ErrInvalidCommand
    27  	}
    28  	_, msg, err := s.commandAndMessage(text)
    29  	if err != nil {
    30  		return err
    31  	}
    32  	if len(msg) == 0 {
    33  		return nil
    34  	}
    35  	_, err = s.G().ChatHelper.SendTextByIDNonblock(ctx, convID, tlfName, fmt.Sprintf("_%s_", msg), nil,
    36  		replyTo)
    37  	return err
    38  }