You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.0 KiB

  1. // Package echo implements a Service which echoes back !commands.
  2. package echo
  3. import (
  4. "strings"
  5. "github.com/matrix-org/go-neb/types"
  6. mevt "maunium.net/go/mautrix/event"
  7. "maunium.net/go/mautrix/id"
  8. )
  9. // ServiceType of the Echo service
  10. const ServiceType = "echo"
  11. // Service represents the Echo service. It has no Config fields.
  12. type Service struct {
  13. types.DefaultService
  14. }
  15. // Commands supported:
  16. // !echo some message
  17. // Responds with a notice of "some message".
  18. func (e *Service) Commands(cli types.MatrixClient) []types.Command {
  19. return []types.Command{
  20. {
  21. Path: []string{"echo"},
  22. Command: func(roomID id.RoomID, userID id.UserID, args []string) (interface{}, error) {
  23. return &mevt.MessageEventContent{
  24. MsgType: mevt.MsgNotice,
  25. Body: strings.Join(args, " "),
  26. }, nil
  27. },
  28. },
  29. }
  30. }
  31. func init() {
  32. types.RegisterService(func(serviceID string, serviceUserID id.UserID, webhookEndpointURL string) types.Service {
  33. return &Service{
  34. DefaultService: types.NewDefaultService(serviceID, serviceUserID, ServiceType),
  35. }
  36. })
  37. }