"flag"
"log"
"os"
+ "time"
"github.com/mattermost/mattermost-server/v6/model"
"go.cypherpunks.ru/recfile"
"go.stargrave.org/mmc"
)
-const PerPage = 100
-
func main() {
entrypoint := flag.String("entrypoint", mmc.GetEntrypoint(), "Entrypoint")
pageNum := flag.Int("page", 0, "Page number")
+ whole := flag.Bool("whole", false, "Whole history")
direct := flag.Bool("direct", false, "Direct channel")
flag.Parse()
log.SetFlags(log.Lshortfile)
- log.SetOutput(os.Stdout)
chId := flag.Arg(0)
postId := flag.Arg(1)
}
chId = dc.Id
}
- list, _, err := c.GetPostsBefore(chId, postId, *pageNum, PerPage, "", false)
- if err != nil {
- log.Fatalln(err)
+ var slice []*model.Post
+ if *whole {
+ for n := 0; ; n++ {
+ log.Println("page:", n)
+ time.Sleep(mmc.SleepTime)
+ list, _, err := c.GetPostsBefore(chId, postId, n, mmc.PerPage, "", false)
+ if err != nil {
+ log.Fatalln(err)
+ }
+ s := list.ToSlice()
+ slice = append(slice, s...)
+ if len(s) < mmc.PerPage {
+ break
+ }
+ }
+ } else {
+ list, _, err := c.GetPostsBefore(chId, postId, *pageNum, mmc.PerPage, "", false)
+ if err != nil {
+ log.Fatalln(err)
+ }
+ slice = list.ToSlice()
}
w := recfile.NewWriter(os.Stdout)
- slice := list.ToSlice()
for i := len(slice) - 1; i >= 0; i-- {
if err = mmc.PostToRec(
w, users,