]> Sergey Matveev's repositories - mmc.git/commitdiff
cmd/ch-leave
authorSergey Matveev <stargrave@stargrave.org>
Sun, 12 Mar 2023 10:21:09 +0000 (13:21 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 12 Mar 2023 12:42:11 +0000 (15:42 +0300)
cmd/ch-leave/.gitignore [new file with mode: 0644]
cmd/ch-leave/main.go [new file with mode: 0644]

diff --git a/cmd/ch-leave/.gitignore b/cmd/ch-leave/.gitignore
new file mode 100644 (file)
index 0000000..cc25015
--- /dev/null
@@ -0,0 +1 @@
+/ch-leave
diff --git a/cmd/ch-leave/main.go b/cmd/ch-leave/main.go
new file mode 100644 (file)
index 0000000..00e6311
--- /dev/null
@@ -0,0 +1,47 @@
+// mmc -- Mattermost client
+// Copyright (C) 2023 Sergey Matveev <stargrave@stargrave.org>
+//
+// 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 <http://www.gnu.org/licenses/>.
+
+package main
+
+import (
+       "flag"
+       "log"
+
+       "github.com/mattermost/mattermost-server/v6/model"
+       "go.stargrave.org/mmc"
+)
+
+func main() {
+       entrypoint := flag.String("entrypoint", "mm.rnd.stcnet.ru", "Entrypoint")
+       flag.Parse()
+       log.SetFlags(log.Lshortfile)
+
+       chId := flag.Arg(0)
+       login, password := mmc.FindInNetrc(*entrypoint)
+       if login == "" || password == "" {
+               log.Fatalln("no credentials found for:", *entrypoint)
+       }
+       c := model.NewAPIv4Client("https://" + *entrypoint)
+       c.Login(login, password)
+       me, _, err := c.GetMe("")
+       if err != nil {
+               log.Fatalln(err)
+       }
+       if _, err = c.RemoveUserFromChannel(chId, me.Id); err != nil {
+               log.Println("RemoveUserFromChannel:", err)
+       }
+       c.Logout()
+}