"go.stargrave.org/mmc"
)
-const CmdFile = "/FILE "
-
var (
Newwin = flag.String("newwin", "cmd/newwin", "Path to newwin command")
DebugFd *os.File
"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
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
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
}