76 lines
2.2 KiB
Go
76 lines
2.2 KiB
Go
// Copyright © 2018 Finn Herzfeld <finn@janky.solutions>
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"git.callpipe.com/finn/signald-go/signald"
|
|
)
|
|
|
|
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 := signald.Request{
|
|
Type: "send",
|
|
Username: username,
|
|
}
|
|
|
|
if toUser != "" {
|
|
request.RecipientNumber = toUser
|
|
} else if toGroup != "" {
|
|
request.RecipientGroupID = toGroup
|
|
} else {
|
|
log.Fatal("--to or --group must be specified!")
|
|
}
|
|
|
|
if messageBody != "" {
|
|
request.MessageBody = messageBody
|
|
}
|
|
|
|
if attachment != "" {
|
|
request.AttachmentFilenames = []string{attachment}
|
|
}
|
|
s.Send(request)
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
RootCmd.AddCommand(sendCmd)
|
|
|
|
sendCmd.Flags().StringVarP(&username, "username", "u", "", "The username to send from (required)")
|
|
sendCmd.MarkFlagRequired("username") // Misleading: cobra doesn't actually do anything to enforce "required" flags
|
|
|
|
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")
|
|
}
|