mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-23 19:22:03 -08:00
go lint is a bloody picky little bastard
This commit is contained in:
parent
9663721680
commit
14a83e08cb
@ -2,10 +2,10 @@ package bsignald
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"net"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/42wim/matterbridge/bridge"
|
"github.com/42wim/matterbridge/bridge"
|
||||||
"github.com/42wim/matterbridge/bridge/config"
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
type JSONCMD map[string]interface{}
|
type JSONCMD map[string]interface{}
|
||||||
@ -13,7 +13,6 @@ type JSONCMD map[string]interface{}
|
|||||||
const (
|
const (
|
||||||
cfgNumber = "Number"
|
cfgNumber = "Number"
|
||||||
cfgSocket = "UnixSocket"
|
cfgSocket = "UnixSocket"
|
||||||
cfgGroupID = "GroupID"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type signaldMessage struct {
|
type signaldMessage struct {
|
||||||
@ -180,13 +179,17 @@ func (b *Bsignald) HandleUnexpectedErrorMessage(msg signaldMessage) {
|
|||||||
func (b *Bsignald) HandleSubscribeMessage() {
|
func (b *Bsignald) HandleSubscribeMessage() {
|
||||||
b.Log.Debugln("subscribe successful", b.GetString(cfgNumber))
|
b.Log.Debugln("subscribe successful", b.GetString(cfgNumber))
|
||||||
b.subscribed = true
|
b.subscribed = true
|
||||||
go b.GetContacts()
|
if err := b.GetContacts(); err != nil {
|
||||||
|
b.Log.Errorln("Error getting contacts: ", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bsignald) HandleListenStoppedMessage() {
|
func (b *Bsignald) HandleListenStoppedMessage() {
|
||||||
b.Log.Errorln("got listen stopped, trying to re-subscribe")
|
b.Log.Errorln("got listen stopped, trying to re-subscribe")
|
||||||
b.subscribed = false
|
b.subscribed = false
|
||||||
go b.Login()
|
if err := b.Login(); err != nil {
|
||||||
|
b.Log.Errorln("Error logging in: ", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bsignald) HandleContactList(msg signaldMessage) {
|
func (b *Bsignald) HandleContactList(msg signaldMessage) {
|
||||||
@ -203,12 +206,13 @@ func (b *Bsignald) HandleContactList(msg signaldMessage) {
|
|||||||
func (b *Bsignald) GetUsername(uuid string) string {
|
func (b *Bsignald) GetUsername(uuid string) string {
|
||||||
username := ""
|
username := ""
|
||||||
if v, found := b.contacts[uuid]; found {
|
if v, found := b.contacts[uuid]; found {
|
||||||
if "" != v.ProfileName {
|
if v.ProfileName != "" {
|
||||||
username = v.ProfileName
|
username = v.ProfileName
|
||||||
} else if "" != v.Name {
|
} else if v.Name != "" {
|
||||||
username = v.Name
|
username = v.Name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return username
|
return username
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,7 +223,7 @@ func (b *Bsignald) HandleMessage(msg signaldMessage) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil == response.Data.DataMessage {
|
if response.Data.DataMessage == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,13 +238,13 @@ func (b *Bsignald) HandleMessage(msg signaldMessage) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if false == groupMatched {
|
if !groupMatched {
|
||||||
b.Log.Debugln("skipping non-group message")
|
b.Log.Debugln("skipping non-group message")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
username := b.GetUsername(response.Data.Source.UUID)
|
username := b.GetUsername(response.Data.Source.UUID)
|
||||||
if "" == username {
|
if username == "" {
|
||||||
username = response.Data.Source.Number
|
username = response.Data.Source.Number
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +260,6 @@ func (b *Bsignald) HandleMessage(msg signaldMessage) {
|
|||||||
b.Log.Debugf("<= Sending message from %s on %s to gateway", rmsg.Username, b.Account)
|
b.Log.Debugf("<= Sending message from %s on %s to gateway", rmsg.Username, b.Account)
|
||||||
b.Log.Debugf("<= Message is %#v", rmsg)
|
b.Log.Debugf("<= Message is %#v", rmsg)
|
||||||
b.Remote <- rmsg
|
b.Remote <- rmsg
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bsignald) Listen() {
|
func (b *Bsignald) Listen() {
|
||||||
@ -288,7 +291,7 @@ func (b *Bsignald) Listen() {
|
|||||||
case "message":
|
case "message":
|
||||||
b.HandleMessage(msg)
|
b.HandleMessage(msg)
|
||||||
default:
|
default:
|
||||||
b.Log.Debugln("unsupported signald data received, skipping it");
|
b.Log.Debugln("unsupported signald data received, skipping it")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -304,7 +307,7 @@ func (b *Bsignald) GetContacts() error {
|
|||||||
|
|
||||||
func (b *Bsignald) Login() error {
|
func (b *Bsignald) Login() error {
|
||||||
var err error
|
var err error
|
||||||
if ! b.subscribed {
|
if !b.subscribed {
|
||||||
cmd := JSONCMD{
|
cmd := JSONCMD{
|
||||||
"type": "subscribe",
|
"type": "subscribe",
|
||||||
"username": b.GetString(cfgNumber),
|
"username": b.GetString(cfgNumber),
|
||||||
@ -314,7 +317,7 @@ func (b *Bsignald) Login() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bsignald) SendRawJSON(cmd JSONCMD) (error) {
|
func (b *Bsignald) SendRawJSON(cmd JSONCMD) error {
|
||||||
err := json.NewEncoder(b.socket).Encode(cmd)
|
err := json.NewEncoder(b.socket).Encode(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Log.Errorln(err.Error())
|
b.Log.Errorln(err.Error())
|
||||||
@ -331,7 +334,7 @@ func (b *Bsignald) Disconnect() error {
|
|||||||
func (b *Bsignald) Send(msg config.Message) (string, error) {
|
func (b *Bsignald) Send(msg config.Message) (string, error) {
|
||||||
b.Log.Debugf("message to forward into signal: %#v", msg)
|
b.Log.Debugf("message to forward into signal: %#v", msg)
|
||||||
|
|
||||||
msgJSON := signaldSendMessage {
|
msgJSON := signaldSendMessage{
|
||||||
Type: "send",
|
Type: "send",
|
||||||
Username: b.GetString(cfgNumber),
|
Username: b.GetString(cfgNumber),
|
||||||
RecipientGroupId: b.groupid,
|
RecipientGroupId: b.groupid,
|
||||||
|
Loading…
Reference in New Issue
Block a user