mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-22 12:50:27 +00:00
Fix megacheck / go vet issues
This commit is contained in:
parent
5af40db396
commit
6dee988b76
@ -88,10 +88,7 @@ func New(cfg *config.Config, bridge *config.Bridge, c chan config.Message) *Brid
|
|||||||
|
|
||||||
func (b *Bridge) JoinChannels() error {
|
func (b *Bridge) JoinChannels() error {
|
||||||
err := b.joinChannels(b.Channels, b.Joined)
|
err := b.joinChannels(b.Channels, b.Joined)
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bridge) joinChannels(channels map[string]config.ChannelInfo, exists map[string]bool) error {
|
func (b *Bridge) joinChannels(channels map[string]config.ChannelInfo, exists map[string]bool) error {
|
||||||
|
@ -209,7 +209,7 @@ func Deprecated(cfg Protocol, account string) bool {
|
|||||||
log.Printf("ERROR: %s BindAddress is deprecated, you need to change it to WebhookBindAddress.", account)
|
log.Printf("ERROR: %s BindAddress is deprecated, you need to change it to WebhookBindAddress.", account)
|
||||||
} else if cfg.URL != "" {
|
} else if cfg.URL != "" {
|
||||||
log.Printf("ERROR: %s URL is deprecated, you need to change it to WebhookURL.", account)
|
log.Printf("ERROR: %s URL is deprecated, you need to change it to WebhookURL.", account)
|
||||||
} else if cfg.UseAPI == true {
|
} else if cfg.UseAPI {
|
||||||
log.Printf("ERROR: %s UseAPI is deprecated, it's enabled by default, please remove it from your config file.", account)
|
log.Printf("ERROR: %s UseAPI is deprecated, it's enabled by default, please remove it from your config file.", account)
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
func tableformatter(nicks []string, nicksPerRow int, continued bool) string {
|
func tableformatter(nicks []string, nicksPerRow int, continued bool) string {
|
||||||
result := "|IRC users"
|
result := "|IRC users"
|
||||||
if continued {
|
if continued {
|
||||||
@ -29,6 +30,7 @@ func tableformatter(nicks []string, nicksPerRow int, continued bool) string {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
func plainformatter(nicks []string, nicksPerRow int) string {
|
func plainformatter(nicks []string, nicksPerRow int) string {
|
||||||
return strings.Join(nicks, ", ") + " currently on IRC"
|
return strings.Join(nicks, ", ") + " currently on IRC"
|
||||||
|
@ -148,9 +148,9 @@ func (b *Birc) Send(msg config.Message) error {
|
|||||||
|
|
||||||
func (b *Birc) doSend() {
|
func (b *Birc) doSend() {
|
||||||
rate := time.Millisecond * time.Duration(b.Config.MessageDelay)
|
rate := time.Millisecond * time.Duration(b.Config.MessageDelay)
|
||||||
throttle := time.Tick(rate)
|
throttle := time.NewTicker(rate)
|
||||||
for msg := range b.Local {
|
for msg := range b.Local {
|
||||||
<-throttle
|
<-throttle.C
|
||||||
b.i.Privmsg(msg.Channel, msg.Username+msg.Text)
|
b.i.Privmsg(msg.Channel, msg.Username+msg.Text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,8 @@ type MMhook struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MMapi struct {
|
type MMapi struct {
|
||||||
mc *matterclient.MMClient
|
mc *matterclient.MMClient
|
||||||
mmMap map[string]string
|
mmMap map[string]string
|
||||||
mmIgnoreNicks []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type MMMessage struct {
|
type MMMessage struct {
|
||||||
@ -29,7 +28,6 @@ type Bmattermost struct {
|
|||||||
MMapi
|
MMapi
|
||||||
Config *config.Protocol
|
Config *config.Protocol
|
||||||
Remote chan config.Message
|
Remote chan config.Message
|
||||||
name string
|
|
||||||
TeamId string
|
TeamId string
|
||||||
Account string
|
Account string
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ type Brocketchat struct {
|
|||||||
MMhook
|
MMhook
|
||||||
Config *config.Protocol
|
Config *config.Protocol
|
||||||
Remote chan config.Message
|
Remote chan config.Message
|
||||||
name string
|
|
||||||
Account string
|
Account string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ func (b *Bslack) Send(msg config.Message) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
np := slack.NewPostMessageParameters()
|
np := slack.NewPostMessageParameters()
|
||||||
if b.Config.PrefixMessagesWithNick == true {
|
if b.Config.PrefixMessagesWithNick {
|
||||||
np.AsUser = true
|
np.AsUser = true
|
||||||
}
|
}
|
||||||
np.Username = nick
|
np.Username = nick
|
||||||
|
@ -136,7 +136,7 @@ func (b *Bsteam) handleEvents() {
|
|||||||
myLoginInfo.AuthCode = code
|
myLoginInfo.AuthCode = code
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
log.Errorf("LogOnFailedEvent: ", e.Result)
|
log.Errorf("LogOnFailedEvent: %#v ", e.Result)
|
||||||
// TODO: Handle EResult_InvalidLoginAuthCode
|
// TODO: Handle EResult_InvalidLoginAuthCode
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -96,31 +96,28 @@ func (gw *Gateway) Start() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gw *Gateway) handleReceive() {
|
func (gw *Gateway) handleReceive() {
|
||||||
for {
|
for msg := range gw.Message {
|
||||||
select {
|
if msg.Event == config.EVENT_FAILURE {
|
||||||
case msg := <-gw.Message:
|
for _, br := range gw.Bridges {
|
||||||
if msg.Event == config.EVENT_FAILURE {
|
if msg.Account == br.Account {
|
||||||
for _, br := range gw.Bridges {
|
go gw.reconnectBridge(br)
|
||||||
if msg.Account == br.Account {
|
|
||||||
go gw.reconnectBridge(br)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if msg.Event == config.EVENT_REJOIN_CHANNELS {
|
}
|
||||||
for _, br := range gw.Bridges {
|
if msg.Event == config.EVENT_REJOIN_CHANNELS {
|
||||||
if msg.Account == br.Account {
|
for _, br := range gw.Bridges {
|
||||||
br.Joined = make(map[string]bool)
|
if msg.Account == br.Account {
|
||||||
br.JoinChannels()
|
br.Joined = make(map[string]bool)
|
||||||
}
|
br.JoinChannels()
|
||||||
}
|
}
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
if !gw.ignoreMessage(&msg) {
|
continue
|
||||||
msg.Timestamp = time.Now()
|
}
|
||||||
gw.modifyMessage(&msg)
|
if !gw.ignoreMessage(&msg) {
|
||||||
for _, br := range gw.Bridges {
|
msg.Timestamp = time.Now()
|
||||||
gw.handleMessage(msg, br)
|
gw.modifyMessage(&msg)
|
||||||
}
|
for _, br := range gw.Bridges {
|
||||||
|
gw.handleMessage(msg, br)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -317,8 +314,8 @@ func (gw *Gateway) validGatewayDest(msg *config.Message, channel *config.Channel
|
|||||||
|
|
||||||
// check if we are running a samechannelgateway.
|
// check if we are running a samechannelgateway.
|
||||||
// if it is and the channel name matches it's ok, otherwise we shouldn't use this channel.
|
// if it is and the channel name matches it's ok, otherwise we shouldn't use this channel.
|
||||||
for k, _ := range GIDmap {
|
for k := range GIDmap {
|
||||||
if channel.SameChannel[k] == true {
|
if channel.SameChannel[k] {
|
||||||
if msg.Channel == channel.Name {
|
if msg.Channel == channel.Name {
|
||||||
// add the gateway to our message
|
// add the gateway to our message
|
||||||
msg.Gateway = k
|
msg.Gateway = k
|
||||||
@ -329,8 +326,8 @@ func (gw *Gateway) validGatewayDest(msg *config.Message, channel *config.Channel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check if we are in the correct gateway
|
// check if we are in the correct gateway
|
||||||
for k, _ := range GIDmap {
|
for k := range GIDmap {
|
||||||
if channel.GID[k] == true {
|
if channel.GID[k] {
|
||||||
// add the gateway to our message
|
// add the gateway to our message
|
||||||
msg.Gateway = k
|
msg.Gateway = k
|
||||||
return true
|
return true
|
||||||
@ -340,8 +337,5 @@ func (gw *Gateway) validGatewayDest(msg *config.Message, channel *config.Channel
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isApi(account string) bool {
|
func isApi(account string) bool {
|
||||||
if strings.HasPrefix(account, "api.") {
|
return strings.HasPrefix(account, "api.")
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
@ -99,10 +99,9 @@ func (c *Client) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// Receive returns an incoming message from mattermost outgoing webhooks URL.
|
// Receive returns an incoming message from mattermost outgoing webhooks URL.
|
||||||
func (c *Client) Receive() Message {
|
func (c *Client) Receive() Message {
|
||||||
for {
|
var msg Message
|
||||||
select {
|
for msg = range c.In {
|
||||||
case msg := <-c.In:
|
return msg
|
||||||
return msg
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return msg
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ func (m *MMClient) SetLogLevel(level string) {
|
|||||||
func (m *MMClient) Login() error {
|
func (m *MMClient) Login() error {
|
||||||
// check if this is a first connect or a reconnection
|
// check if this is a first connect or a reconnection
|
||||||
firstConnection := true
|
firstConnection := true
|
||||||
if m.WsConnected == true {
|
if m.WsConnected {
|
||||||
firstConnection = false
|
firstConnection = false
|
||||||
}
|
}
|
||||||
m.WsConnected = false
|
m.WsConnected = false
|
||||||
@ -149,7 +149,7 @@ func (m *MMClient) Login() error {
|
|||||||
return errors.New("invalid " + model.SESSION_COOKIE_TOKEN)
|
return errors.New("invalid " + model.SESSION_COOKIE_TOKEN)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
myinfo, appErr = m.Client.Login(m.Credentials.Login, m.Credentials.Pass)
|
_, appErr = m.Client.Login(m.Credentials.Login, m.Credentials.Pass)
|
||||||
}
|
}
|
||||||
if appErr != nil {
|
if appErr != nil {
|
||||||
d := b.Duration()
|
d := b.Duration()
|
||||||
@ -329,7 +329,6 @@ func (m *MMClient) parseActionPost(rmsg *Message) {
|
|||||||
}
|
}
|
||||||
rmsg.Text = data.Message
|
rmsg.Text = data.Message
|
||||||
rmsg.Post = data
|
rmsg.Post = data
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) UpdateUsers() error {
|
func (m *MMClient) UpdateUsers() error {
|
||||||
@ -535,7 +534,7 @@ func (m *MMClient) UpdateLastViewed(channelId string) {
|
|||||||
if m.mmVersion() >= 3.08 {
|
if m.mmVersion() >= 3.08 {
|
||||||
view := model.ChannelView{ChannelId: channelId}
|
view := model.ChannelView{ChannelId: channelId}
|
||||||
res, _ := m.Client.ViewChannel(view)
|
res, _ := m.Client.ViewChannel(view)
|
||||||
if res == false {
|
if !res {
|
||||||
m.log.Errorf("ChannelView update for %s failed", channelId)
|
m.log.Errorf("ChannelView update for %s failed", channelId)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -683,13 +682,13 @@ func (m *MMClient) GetUsers() map[string]*model.User {
|
|||||||
func (m *MMClient) GetUser(userId string) *model.User {
|
func (m *MMClient) GetUser(userId string) *model.User {
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
u, ok := m.Users[userId]
|
_, ok := m.Users[userId]
|
||||||
if !ok {
|
if !ok {
|
||||||
res, err := m.Client.GetProfilesByIds([]string{userId})
|
res, err := m.Client.GetProfilesByIds([]string{userId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
u = res.Data.(map[string]*model.User)[userId]
|
u := res.Data.(map[string]*model.User)[userId]
|
||||||
m.Users[userId] = u
|
m.Users[userId] = u
|
||||||
}
|
}
|
||||||
return m.Users[userId]
|
return m.Users[userId]
|
||||||
|
@ -134,12 +134,11 @@ func (c *Client) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// Receive returns an incoming message from mattermost outgoing webhooks URL.
|
// Receive returns an incoming message from mattermost outgoing webhooks URL.
|
||||||
func (c *Client) Receive() IMessage {
|
func (c *Client) Receive() IMessage {
|
||||||
for {
|
var msg IMessage
|
||||||
select {
|
for msg := range c.In {
|
||||||
case msg := <-c.In:
|
return msg
|
||||||
return msg
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send sends a msg to mattermost incoming webhooks URL.
|
// Send sends a msg to mattermost incoming webhooks URL.
|
||||||
|
Loading…
Reference in New Issue
Block a user