From 7dfca9f0e117c34c79878bfd31a8631adeddcdd9 Mon Sep 17 00:00:00 2001 From: Finn Date: Mon, 1 Feb 2021 17:42:50 -0800 Subject: [PATCH] Remove legacy subcommands send and subscribe --- cmd/signaldctl/cmd/send.go | 86 --------------------------------- cmd/signaldctl/cmd/subscribe.go | 72 --------------------------- 2 files changed, 158 deletions(-) delete mode 100644 cmd/signaldctl/cmd/send.go delete mode 100644 cmd/signaldctl/cmd/subscribe.go diff --git a/cmd/signaldctl/cmd/send.go b/cmd/signaldctl/cmd/send.go deleted file mode 100644 index 23e4bcc..0000000 --- a/cmd/signaldctl/cmd/send.go +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright © 2018 Finn Herzfeld -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// 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 General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -package cmd - -import ( - "encoding/json" - "log" - "os" - - "github.com/spf13/cobra" - - "gitlab.com/signald/signald-go/cmd/signaldctl/common" - "gitlab.com/signald/signald-go/signald/client-protocol/v0" - "gitlab.com/signald/signald-go/signald/client-protocol/v1" -) - -var ( - username string - toUser string - toGroup string - messageBody string - attachment string -) - -// sendCmd represents the send command -var sendCmd = &cobra.Command{ - Use: "send", - Short: "send a message to another user or group", - Long: `send a message to another user or group on Signal`, - Run: func(cmd *cobra.Command, args []string) { - request := v1.SendRequest{Username: username} - - if toUser != "" { - request.RecipientAddress = &v1.JsonAddress{Number: toUser} - } else if toGroup != "" { - request.RecipientGroupID = toGroup - } else { - log.Fatal("--to or --group must be specified!") - } - - if messageBody != "" { - request.MessageBody = messageBody - } - - if attachment != "" { - request.Attachments = []*v0.JsonAttachment{{Filename: attachment}} - } - go common.Signald.Listen(nil) - response, err := request.Submit(common.Signald) - if err != nil { - log.Fatal("error submitting request to signald: ", err) - } - err = json.NewEncoder(os.Stdout).Encode(response) - if err != nil { - log.Fatal("error encoding output ", err) - } - }, -} - -func init() { - RootCmd.AddCommand(sendCmd) - - sendCmd.Flags().StringVarP(&username, "username", "u", "", "The username to send from (required)") - common.Must(sendCmd.MarkFlagRequired("username")) - - sendCmd.Flags().StringVarP(&toUser, "to", "t", "", "The user to send the message to (cannot be combined with --group)") - - sendCmd.Flags().StringVarP(&toGroup, "group", "g", "", "The group to send the message to (cannot be combined with --to)") - - sendCmd.Flags().StringVarP(&messageBody, "message", "m", "", "The text of the message to send") - - sendCmd.Flags().StringVarP(&attachment, "attachment", "a", "", "A file to attach to the message") -} diff --git a/cmd/signaldctl/cmd/subscribe.go b/cmd/signaldctl/cmd/subscribe.go deleted file mode 100644 index c534aac..0000000 --- a/cmd/signaldctl/cmd/subscribe.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright © 2020 Finn Herzfeld -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// 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 General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -package cmd - -import ( - "encoding/json" - "fmt" - "log" - "math/rand" - "os" - - "github.com/spf13/cobra" - - "gitlab.com/signald/signald-go/cmd/signaldctl/common" - "gitlab.com/signald/signald-go/signald/client-protocol/v0" -) - -// subscribeCmd represents the subscribe command -var subscribeCmd = &cobra.Command{ - Use: "subscribe", - Short: "subscribe to incoming messages", - Long: `receive incoming messages from Signal`, - Run: func(cmd *cobra.Command, args []string) { - requestID := fmt.Sprint("signaldctl-", rand.Intn(1000)) - err := common.Signald.RawRequest(v0.LegacyRequest{ - Type: "subscribe", - Username: username, - ID: requestID, - }) - if err != nil { - log.Fatal("error sending request: ", err) - } - - c := make(chan v0.LegacyResponse) - go common.Signald.Listen(c) - - go func() { - defer common.Signald.CloseResponseListener(requestID) - r := <-common.Signald.GetResponseListener(requestID) - if r.GetError() != nil { - log.Fatal("error subscribing: ", r.GetError()) - } - }() - - for { - msg := <-c - if err := json.NewEncoder(os.Stdout).Encode(msg); err != nil { - log.Fatal("error encoding response to JSON. this should never happen", err) - } - } - }, -} - -func init() { - RootCmd.AddCommand(subscribeCmd) - - subscribeCmd.Flags().StringVarP(&username, "username", "u", "", "The phone number to subscribe to") - common.Must(subscribeCmd.MarkFlagRequired("username")) -}