From 3704d275b02e8c53320edf470cc1f705e7c625a1 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sun, 12 Mar 2023 13:21:09 +0300 Subject: [PATCH 1/1] cmd/ch-leave --- cmd/ch-leave/.gitignore | 1 + cmd/ch-leave/main.go | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 cmd/ch-leave/.gitignore create mode 100644 cmd/ch-leave/main.go diff --git a/cmd/ch-leave/.gitignore b/cmd/ch-leave/.gitignore new file mode 100644 index 0000000..cc25015 --- /dev/null +++ b/cmd/ch-leave/.gitignore @@ -0,0 +1 @@ +/ch-leave diff --git a/cmd/ch-leave/main.go b/cmd/ch-leave/main.go new file mode 100644 index 0000000..00e6311 --- /dev/null +++ b/cmd/ch-leave/main.go @@ -0,0 +1,47 @@ +// 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" + + "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() +} -- 2.44.0