mirror of
https://github.com/bbernhard/signal-cli-rest-api.git
synced 2026-05-21 13:54:18 +00:00
format code with gofmt
This commit is contained in:
parent
6522dcf8c8
commit
b274fd2e49
@ -1,24 +1,24 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"errors"
|
|
||||||
"os/exec"
|
|
||||||
"bytes"
|
|
||||||
"time"
|
|
||||||
"bufio"
|
"bufio"
|
||||||
log "github.com/sirupsen/logrus"
|
"bytes"
|
||||||
|
"errors"
|
||||||
utils "github.com/bbernhard/signal-cli-rest-api/utils"
|
utils "github.com/bbernhard/signal-cli-rest-api/utils"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CliClient struct {
|
type CliClient struct {
|
||||||
signalCliMode SignalCliMode
|
signalCliMode SignalCliMode
|
||||||
signalCliApiConfig *utils.SignalCliApiConfig
|
signalCliApiConfig *utils.SignalCliApiConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCliClient(signalCliMode SignalCliMode, signalCliApiConfig *utils.SignalCliApiConfig) *CliClient {
|
func NewCliClient(signalCliMode SignalCliMode, signalCliApiConfig *utils.SignalCliApiConfig) *CliClient {
|
||||||
return &CliClient {
|
return &CliClient{
|
||||||
signalCliMode: signalCliMode,
|
signalCliMode: signalCliMode,
|
||||||
signalCliApiConfig: signalCliApiConfig,
|
signalCliApiConfig: signalCliApiConfig,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ func (s *CliClient) Execute(wait bool, args []string, stdin string) (string, err
|
|||||||
//check if args contain number
|
//check if args contain number
|
||||||
trustModeStr := ""
|
trustModeStr := ""
|
||||||
for i, arg := range args {
|
for i, arg := range args {
|
||||||
if (arg == "-a" || arg == "--account") && (((i+1) < len(args)) && (utils.IsPhoneNumber(args[i+1]))) {
|
if (arg == "-a" || arg == "--account") && (((i + 1) < len(args)) && (utils.IsPhoneNumber(args[i+1]))) {
|
||||||
number := args[i+1]
|
number := args[i+1]
|
||||||
trustMode, err := s.signalCliApiConfig.GetTrustModeForNumber(number)
|
trustMode, err := s.signalCliApiConfig.GetTrustModeForNumber(number)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -167,4 +167,3 @@ func (s *CliClient) Execute(wait bool, args []string, stdin string) (string, err
|
|||||||
return string(line), nil
|
return string(line), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -161,7 +161,7 @@ type SignalCliIdentityEntry struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SendResponse struct {
|
type SendResponse struct {
|
||||||
Timestamp int64 `json:"timestamp"`
|
Timestamp int64 `json:"timestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type About struct {
|
type About struct {
|
||||||
@ -178,7 +178,7 @@ type SearchResultEntry struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SetUsernameResponse struct {
|
type SetUsernameResponse struct {
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
UsernameLink string `json:"username_link"`
|
UsernameLink string `json:"username_link"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,19 +191,19 @@ type ListInstalledStickerPacksResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SignalCliSendRequest struct {
|
type SignalCliSendRequest struct {
|
||||||
Number string
|
Number string
|
||||||
Message string
|
Message string
|
||||||
Recipients []string
|
Recipients []string
|
||||||
Base64Attachments []string
|
Base64Attachments []string
|
||||||
IsGroup bool
|
IsGroup bool
|
||||||
Sticker string
|
Sticker string
|
||||||
Mentions []MessageMention
|
Mentions []MessageMention
|
||||||
QuoteTimestamp *int64
|
QuoteTimestamp *int64
|
||||||
QuoteAuthor *string
|
QuoteAuthor *string
|
||||||
QuoteMessage *string
|
QuoteMessage *string
|
||||||
QuoteMentions []MessageMention
|
QuoteMentions []MessageMention
|
||||||
TextMode *string
|
TextMode *string
|
||||||
EditTimestamp *int64
|
EditTimestamp *int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanupTmpFiles(paths []string) {
|
func cleanupTmpFiles(paths []string) {
|
||||||
@ -365,7 +365,7 @@ func (s *MessageMention) toString() string {
|
|||||||
return fmt.Sprintf("%d:%d:%s", s.Start, s.Length, s.Author)
|
return fmt.Sprintf("%d:%d:%s", s.Start, s.Length, s.Author)
|
||||||
}
|
}
|
||||||
|
|
||||||
func(s *SignalClient) send(signalCliSendRequest SignalCliSendRequest) (*SendResponse, error) {
|
func (s *SignalClient) send(signalCliSendRequest SignalCliSendRequest) (*SendResponse, error) {
|
||||||
var resp SendResponse
|
var resp SendResponse
|
||||||
|
|
||||||
if len(signalCliSendRequest.Recipients) == 0 {
|
if len(signalCliSendRequest.Recipients) == 0 {
|
||||||
@ -569,9 +569,9 @@ func (s *SignalClient) About() About {
|
|||||||
func (s *SignalClient) RegisterNumber(number string, useVoice bool, captcha string) error {
|
func (s *SignalClient) RegisterNumber(number string, useVoice bool, captcha string) error {
|
||||||
if s.signalCliMode == JsonRpc {
|
if s.signalCliMode == JsonRpc {
|
||||||
type Request struct {
|
type Request struct {
|
||||||
UseVoice bool `json:"voice,omitempty"`
|
UseVoice bool `json:"voice,omitempty"`
|
||||||
Captcha string `json:"captcha,omitempty"`
|
Captcha string `json:"captcha,omitempty"`
|
||||||
Account string `json:"account,omitempty"`
|
Account string `json:"account,omitempty"`
|
||||||
}
|
}
|
||||||
request := Request{Account: number}
|
request := Request{Account: number}
|
||||||
|
|
||||||
@ -633,9 +633,9 @@ func (s *SignalClient) UnregisterNumber(number string, deleteAccount bool, delet
|
|||||||
func (s *SignalClient) VerifyRegisteredNumber(number string, token string, pin string) error {
|
func (s *SignalClient) VerifyRegisteredNumber(number string, token string, pin string) error {
|
||||||
if s.signalCliMode == JsonRpc {
|
if s.signalCliMode == JsonRpc {
|
||||||
type Request struct {
|
type Request struct {
|
||||||
VerificationCode string `json:"verificationCode,omitempty"`
|
VerificationCode string `json:"verificationCode,omitempty"`
|
||||||
Account string `json:"account,omitempty"`
|
Account string `json:"account,omitempty"`
|
||||||
Pin string `json:"pin,omitempty"`
|
Pin string `json:"pin,omitempty"`
|
||||||
}
|
}
|
||||||
request := Request{Account: number, VerificationCode: token}
|
request := Request{Account: number, VerificationCode: token}
|
||||||
|
|
||||||
@ -663,8 +663,8 @@ func (s *SignalClient) VerifyRegisteredNumber(number string, token string, pin s
|
|||||||
|
|
||||||
func (s *SignalClient) SendV1(number string, message string, recipients []string, base64Attachments []string, isGroup bool) (*SendResponse, error) {
|
func (s *SignalClient) SendV1(number string, message string, recipients []string, base64Attachments []string, isGroup bool) (*SendResponse, error) {
|
||||||
signalCliSendRequest := SignalCliSendRequest{Number: number, Message: message, Recipients: recipients, Base64Attachments: base64Attachments,
|
signalCliSendRequest := SignalCliSendRequest{Number: number, Message: message, Recipients: recipients, Base64Attachments: base64Attachments,
|
||||||
IsGroup: isGroup, Sticker: "", Mentions: nil, QuoteTimestamp: nil, QuoteAuthor: nil, QuoteMessage: nil,
|
IsGroup: isGroup, Sticker: "", Mentions: nil, QuoteTimestamp: nil, QuoteAuthor: nil, QuoteMessage: nil,
|
||||||
QuoteMentions: nil, TextMode: nil, EditTimestamp: nil}
|
QuoteMentions: nil, TextMode: nil, EditTimestamp: nil}
|
||||||
timestamp, err := s.send(signalCliSendRequest)
|
timestamp, err := s.send(signalCliSendRequest)
|
||||||
return timestamp, err
|
return timestamp, err
|
||||||
}
|
}
|
||||||
@ -716,9 +716,9 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas
|
|||||||
timestamps := []SendResponse{}
|
timestamps := []SendResponse{}
|
||||||
for _, group := range groups {
|
for _, group := range groups {
|
||||||
signalCliSendRequest := SignalCliSendRequest{Number: number, Message: message, Recipients: []string{group}, Base64Attachments: base64Attachments,
|
signalCliSendRequest := SignalCliSendRequest{Number: number, Message: message, Recipients: []string{group}, Base64Attachments: base64Attachments,
|
||||||
IsGroup: true, Sticker: sticker, Mentions: mentions, QuoteTimestamp: quoteTimestamp,
|
IsGroup: true, Sticker: sticker, Mentions: mentions, QuoteTimestamp: quoteTimestamp,
|
||||||
QuoteAuthor: quoteAuthor, QuoteMessage: quoteMessage, QuoteMentions: quoteMentions,
|
QuoteAuthor: quoteAuthor, QuoteMessage: quoteMessage, QuoteMentions: quoteMentions,
|
||||||
TextMode: textMode, EditTimestamp: editTimestamp}
|
TextMode: textMode, EditTimestamp: editTimestamp}
|
||||||
timestamp, err := s.send(signalCliSendRequest)
|
timestamp, err := s.send(signalCliSendRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -728,9 +728,9 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas
|
|||||||
|
|
||||||
if len(recipients) > 0 {
|
if len(recipients) > 0 {
|
||||||
signalCliSendRequest := SignalCliSendRequest{Number: number, Message: message, Recipients: recipients, Base64Attachments: base64Attachments,
|
signalCliSendRequest := SignalCliSendRequest{Number: number, Message: message, Recipients: recipients, Base64Attachments: base64Attachments,
|
||||||
IsGroup: false, Sticker: sticker, Mentions: mentions, QuoteTimestamp: quoteTimestamp,
|
IsGroup: false, Sticker: sticker, Mentions: mentions, QuoteTimestamp: quoteTimestamp,
|
||||||
QuoteAuthor: quoteAuthor, QuoteMessage: quoteMessage, QuoteMentions: quoteMentions,
|
QuoteAuthor: quoteAuthor, QuoteMessage: quoteMessage, QuoteMentions: quoteMentions,
|
||||||
TextMode: textMode, EditTimestamp: editTimestamp}
|
TextMode: textMode, EditTimestamp: editTimestamp}
|
||||||
timestamp, err := s.send(signalCliSendRequest)
|
timestamp, err := s.send(signalCliSendRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -805,12 +805,12 @@ func (s *SignalClient) CreateGroup(number string, name string, members []string,
|
|||||||
var internalGroupId string
|
var internalGroupId string
|
||||||
if s.signalCliMode == JsonRpc {
|
if s.signalCliMode == JsonRpc {
|
||||||
type Request struct {
|
type Request struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Members []string `json:"members"`
|
Members []string `json:"members"`
|
||||||
Link string `json:"link,omitempty"`
|
Link string `json:"link,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
EditGroupPermissions string `json:"setPermissionEditDetails,omitempty"`
|
EditGroupPermissions string `json:"setPermissionEditDetails,omitempty"`
|
||||||
AddMembersPermissions string `json:"setPermissionAddMember,omitempty"`
|
AddMembersPermissions string `json:"setPermissionAddMember,omitempty"`
|
||||||
}
|
}
|
||||||
request := Request{Name: name, Members: members}
|
request := Request{Name: name, Members: members}
|
||||||
|
|
||||||
@ -1096,7 +1096,7 @@ func (s *SignalClient) GetGroup(number string, groupId string) (*GroupEntry, err
|
|||||||
func (s *SignalClient) DeleteGroup(number string, groupId string) error {
|
func (s *SignalClient) DeleteGroup(number string, groupId string) error {
|
||||||
if s.signalCliMode == JsonRpc {
|
if s.signalCliMode == JsonRpc {
|
||||||
type Request struct {
|
type Request struct {
|
||||||
GroupId string `json:"groupId"`
|
GroupId string `json:"groupId"`
|
||||||
}
|
}
|
||||||
request := Request{GroupId: groupId}
|
request := Request{GroupId: groupId}
|
||||||
|
|
||||||
@ -1531,8 +1531,8 @@ func (s *SignalClient) UpdateGroup(number string, groupId string, base64Avatar *
|
|||||||
|
|
||||||
if s.signalCliMode == JsonRpc {
|
if s.signalCliMode == JsonRpc {
|
||||||
type Request struct {
|
type Request struct {
|
||||||
GroupId string `json:"groupId"`
|
GroupId string `json:"groupId"`
|
||||||
Avatar string `json:"avatar,omitempty"`
|
Avatar string `json:"avatar,omitempty"`
|
||||||
Description *string `json:"description,omitempty"`
|
Description *string `json:"description,omitempty"`
|
||||||
Name *string `json:"name,omitempty"`
|
Name *string `json:"name,omitempty"`
|
||||||
}
|
}
|
||||||
@ -1545,7 +1545,6 @@ func (s *SignalClient) UpdateGroup(number string, groupId string, base64Avatar *
|
|||||||
request.Description = groupDescription
|
request.Description = groupDescription
|
||||||
request.Name = groupName
|
request.Name = groupName
|
||||||
|
|
||||||
|
|
||||||
jsonRpc2Client, err := s.getJsonRpc2Client()
|
jsonRpc2Client, err := s.getJsonRpc2Client()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -1781,7 +1780,7 @@ func (s *SignalClient) SearchForNumbers(number string, numbers []string) ([]Sear
|
|||||||
return searchResultEntries, err
|
return searchResultEntries, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s* SignalClient) SendContacts(number string) error {
|
func (s *SignalClient) SendContacts(number string) error {
|
||||||
var err error
|
var err error
|
||||||
if s.signalCliMode == JsonRpc {
|
if s.signalCliMode == JsonRpc {
|
||||||
jsonRpc2Client, err := s.getJsonRpc2Client()
|
jsonRpc2Client, err := s.getJsonRpc2Client()
|
||||||
@ -1865,7 +1864,7 @@ func (s *SignalClient) SubmitRateLimitChallenge(number string, challengeToken st
|
|||||||
if s.signalCliMode == JsonRpc {
|
if s.signalCliMode == JsonRpc {
|
||||||
type Request struct {
|
type Request struct {
|
||||||
Challenge string `json:"challenge"`
|
Challenge string `json:"challenge"`
|
||||||
Captcha string `json:"captcha"`
|
Captcha string `json:"captcha"`
|
||||||
}
|
}
|
||||||
request := Request{Challenge: challengeToken, Captcha: captcha}
|
request := Request{Challenge: challengeToken, Captcha: captcha}
|
||||||
jsonRpc2Client, err := s.getJsonRpc2Client()
|
jsonRpc2Client, err := s.getJsonRpc2Client()
|
||||||
@ -1883,7 +1882,7 @@ func (s *SignalClient) SubmitRateLimitChallenge(number string, challengeToken st
|
|||||||
|
|
||||||
func (s *SignalClient) SetUsername(number string, username string) (SetUsernameResponse, error) {
|
func (s *SignalClient) SetUsername(number string, username string) (SetUsernameResponse, error) {
|
||||||
type SetUsernameSignalCliResponse struct {
|
type SetUsernameSignalCliResponse struct {
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
UsernameLink string `json:"usernameLink"`
|
UsernameLink string `json:"usernameLink"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1939,7 +1938,7 @@ func (s *SignalClient) RemoveUsername(number string) error {
|
|||||||
func (s *SignalClient) UpdateAccountSettings(number string, discoverableByNumber *bool, shareNumber *bool) error {
|
func (s *SignalClient) UpdateAccountSettings(number string, discoverableByNumber *bool, shareNumber *bool) error {
|
||||||
if s.signalCliMode == JsonRpc {
|
if s.signalCliMode == JsonRpc {
|
||||||
type Request struct {
|
type Request struct {
|
||||||
ShareNumber *bool `json:"number-sharing"`
|
ShareNumber *bool `json:"number-sharing"`
|
||||||
DiscoverableByNumber *bool `json:"discoverable-by-number"`
|
DiscoverableByNumber *bool `json:"discoverable-by-number"`
|
||||||
}
|
}
|
||||||
request := Request{}
|
request := Request{}
|
||||||
@ -2004,7 +2003,7 @@ func (s *SignalClient) ListInstalledStickerPacks(number string) ([]ListInstalled
|
|||||||
|
|
||||||
for _, value := range signalCliResp {
|
for _, value := range signalCliResp {
|
||||||
resp = append(resp, ListInstalledStickerPacksResponse{PackId: value.PackId, Url: value.Url,
|
resp = append(resp, ListInstalledStickerPacksResponse{PackId: value.PackId, Url: value.Url,
|
||||||
Installed: value.Installed, Title: value.Title, Author: value.Author})
|
Installed: value.Installed, Title: value.Title, Author: value.Author})
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
|||||||
@ -5,8 +5,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/bbernhard/signal-cli-rest-api/utils"
|
"github.com/bbernhard/signal-cli-rest-api/utils"
|
||||||
uuid "github.com/gofrs/uuid"
|
uuid "github.com/gofrs/uuid"
|
||||||
@ -160,9 +160,9 @@ func (r *JsonRpc2Client) getRaw(command string, account *string, args interface{
|
|||||||
}
|
}
|
||||||
|
|
||||||
return "", &RateLimitErrorType{
|
return "", &RateLimitErrorType{
|
||||||
ChallengeTokens: challengeTokens,
|
ChallengeTokens: challengeTokens,
|
||||||
Err : errors.New(resp.Err.Message),
|
Err: errors.New(resp.Err.Message),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", errors.New(resp.Err.Message)
|
return "", errors.New(resp.Err.Message)
|
||||||
}
|
}
|
||||||
@ -184,8 +184,6 @@ func (r *JsonRpc2Client) ReceiveData(number string) {
|
|||||||
}
|
}
|
||||||
log.Debug("json-rpc received data: ", str)
|
log.Debug("json-rpc received data: ", str)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var resp1 JsonRpc2ReceivedMessage
|
var resp1 JsonRpc2ReceivedMessage
|
||||||
json.Unmarshal([]byte(str), &resp1)
|
json.Unmarshal([]byte(str), &resp1)
|
||||||
if resp1.Method == "receive" {
|
if resp1.Method == "receive" {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user