]> Sergey Matveev's repositories - mmc.git/commitdiff
Ability to send multiple /FILEs at once
authorSergey Matveev <stargrave@stargrave.org>
Thu, 16 Mar 2023 08:05:36 +0000 (11:05 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 16 Mar 2023 08:05:36 +0000 (11:05 +0300)
cmd/mmc/main.go
cmd/mmc/post.go

index 9283745d0563ab514b0c78a8d67545f1220848b7..f27ec75504f6ec9ed05cce84bf38a2b49920b48e 100644 (file)
@@ -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
index 0adcd2227f24fbcea718b859bf9379e74cabedce..72830655959c275e47068079ba8392c00f9b9ed9 100644 (file)
@@ -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
 }