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.

44 lines
1.1 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. "maunium.net/go/mautrix"
  7. mevt "maunium.net/go/mautrix/event"
  8. "maunium.net/go/mautrix/id"
  9. )
  10. // ServiceType of the Echo service
  11. const ServiceType = "echo"
  12. // Service represents the Echo service. It has no Config fields.
  13. type Service struct {
  14. types.DefaultService
  15. }
  16. // Commands supported:
  17. // !echo some message
  18. // Responds with a notice of "some message".
  19. func (e *Service) Commands(cli *mautrix.Client) []types.Command {
  20. return []types.Command{
  21. types.Command{
  22. Path: []string{"echo"},
  23. Command: func(roomID id.RoomID, userID id.UserID, args []string) (interface{}, error) {
  24. return &mevt.MessageEventContent{
  25. MsgType: mevt.MsgNotice,
  26. Body: strings.Join(args, " "),
  27. }, nil
  28. },
  29. },
  30. }
  31. }
  32. func init() {
  33. types.RegisterService(func(serviceID string, serviceUserID id.UserID, webhookEndpointURL string) types.Service {
  34. return &Service{
  35. DefaultService: types.NewDefaultService(serviceID, serviceUserID, ServiceType),
  36. }
  37. })
  38. }