Remove legacy subcommands send and subscribe
This commit is contained in:
parent
3cf02aebb0
commit
7dfca9f0e1
2 changed files with 0 additions and 158 deletions
|
@ -1,86 +0,0 @@
|
||||||
// Copyright © 2018 Finn Herzfeld <finn@janky.solutions>
|
|
||||||
//
|
|
||||||
// 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 <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
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")
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
// Copyright © 2020 Finn Herzfeld <finn@janky.solutions>
|
|
||||||
//
|
|
||||||
// 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 <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
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"))
|
|
||||||
}
|
|
Loading…
Reference in a new issue