// mmc -- Mattermost client // Copyright (C) 2023 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the // License. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . package main import ( "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", "mm.rnd.stcnet.ru", "Entrypoint") flag.Parse() log.SetFlags(log.Lshortfile) log.SetOutput(os.Stdout) chId := flag.Arg(0) postId := flag.Arg(1) login, password := mmc.FindInNetrc(*entrypoint) if login == "" || password == "" { log.Fatalln("no credentials found for:", *entrypoint) } c := model.NewAPIv4Client("https://" + *entrypoint) c.Login(login, password) users := make(map[string]*model.User) for pageNum := 0; ; pageNum++ { time.Sleep(mmc.SleepTime) page, _, err := c.GetUsers(pageNum, PerPage, "") if err != nil { log.Fatalln(err) } for _, u := range page { users[u.Id] = u } if len(page) < PerPage { break } } list, _, err := c.GetPostsBefore(chId, postId, 0, 200, "", false) if err != nil { log.Fatalln(err) } w := recfile.NewWriter(os.Stdout) for _, post := range list.ToSlice() { if err = mmc.PostToRec( w, users, mmc.Post{P: post, E: model.WebsocketEventPosted}, ); err != nil { log.Fatalln(err) } } c.Logout() }