From b25d398e9f91dbbf5411b6804f6edef7761322bb Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Thu, 16 Mar 2023 11:05:36 +0300 Subject: [PATCH 1/1] Ability to send multiple /FILEs at once --- cmd/mmc/main.go | 2 -- cmd/mmc/post.go | 18 +++++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cmd/mmc/main.go b/cmd/mmc/main.go index 9283745..f27ec75 100644 --- a/cmd/mmc/main.go +++ b/cmd/mmc/main.go @@ -41,8 +41,6 @@ import ( "go.stargrave.org/mmc" ) -const CmdFile = "/FILE " - var ( Newwin = flag.String("newwin", "cmd/newwin", "Path to newwin command") DebugFd *os.File diff --git a/cmd/mmc/post.go b/cmd/mmc/post.go index 0adcd22..7283065 100644 --- a/cmd/mmc/post.go +++ b/cmd/mmc/post.go @@ -30,6 +30,8 @@ import ( "go.stargrave.org/mmc" ) +const CmdFile = "/FILE " + func writePosts(where string, users map[string]*model.User, posts []mmc.Post) error { if len(posts) == 0 { return nil @@ -130,12 +132,14 @@ func makePost(c *model.Client4, chId, text string) (*model.Post, error) { if text == "" { return nil, nil } - post := &model.Post{ - Message: text, - ChannelId: chId, - } - if strings.HasPrefix(text, CmdFile) { - fn := strings.TrimPrefix(text, CmdFile) + post := &model.Post{ChannelId: chId} + var lines []string + for _, line := range strings.Split(text, "\n") { + if !strings.HasPrefix(line, CmdFile) { + lines = append(lines, line) + continue + } + fn := strings.TrimPrefix(line, CmdFile) data, err := os.ReadFile(fn) if err != nil { return nil, err @@ -144,9 +148,9 @@ func makePost(c *model.Client4, chId, text string) (*model.Post, error) { if err != nil { return nil, err } - post.Message = "" post.FileIds = append(post.FileIds, resp.FileInfos[0].Id) } + post.Message = strings.Join(lines, "\n") post, _, err := c.CreatePost(post) return post, err } -- 2.44.0