Make gometalinter happier

This commit is contained in:
Wim 2018-02-24 23:22:15 +01:00
parent d62f49d1fc
commit 73525a4bbc
2 changed files with 26 additions and 26 deletions

View File

@ -12,7 +12,7 @@ import (
"sync" "sync"
) )
type bdiscord struct { type Bdiscord struct {
c *discordgo.Session c *discordgo.Session
Channels []*discordgo.Channel Channels []*discordgo.Channel
Nick string Nick string
@ -33,8 +33,8 @@ func init() {
flog = log.WithFields(log.Fields{"prefix": protocol}) flog = log.WithFields(log.Fields{"prefix": protocol})
} }
func New(cfg *config.BridgeConfig) *bdiscord { func New(cfg *config.BridgeConfig) *Bdiscord {
b := &bdiscord{BridgeConfig: cfg} b := &Bdiscord{BridgeConfig: cfg}
b.userMemberMap = make(map[string]*discordgo.Member) b.userMemberMap = make(map[string]*discordgo.Member)
b.channelInfoMap = make(map[string]*config.ChannelInfo) b.channelInfoMap = make(map[string]*config.ChannelInfo)
if b.Config.WebhookURL != "" { if b.Config.WebhookURL != "" {
@ -44,7 +44,7 @@ func New(cfg *config.BridgeConfig) *bdiscord {
return b return b
} }
func (b *bdiscord) Connect() error { func (b *Bdiscord) Connect() error {
var err error var err error
flog.Info("Connecting") flog.Info("Connecting")
if b.Config.WebhookURL == "" { if b.Config.WebhookURL == "" {
@ -89,11 +89,11 @@ func (b *bdiscord) Connect() error {
return nil return nil
} }
func (b *bdiscord) Disconnect() error { func (b *Bdiscord) Disconnect() error {
return nil return nil
} }
func (b *bdiscord) JoinChannel(channel config.ChannelInfo) error { func (b *Bdiscord) JoinChannel(channel config.ChannelInfo) error {
b.channelInfoMap[channel.ID] = &channel b.channelInfoMap[channel.ID] = &channel
idcheck := strings.Split(channel.Name, "ID:") idcheck := strings.Split(channel.Name, "ID:")
if len(idcheck) > 1 { if len(idcheck) > 1 {
@ -102,7 +102,7 @@ func (b *bdiscord) JoinChannel(channel config.ChannelInfo) error {
return nil return nil
} }
func (b *bdiscord) Send(msg config.Message) (string, error) { func (b *Bdiscord) Send(msg config.Message) (string, error) {
flog.Debugf("Receiving %#v", msg) flog.Debugf("Receiving %#v", msg)
channelID := b.getChannelID(msg.Channel) channelID := b.getChannelID(msg.Channel)
@ -181,7 +181,7 @@ func (b *bdiscord) Send(msg config.Message) (string, error) {
return res.ID, err return res.ID, err
} }
func (b *bdiscord) messageDelete(s *discordgo.Session, m *discordgo.MessageDelete) { func (b *Bdiscord) messageDelete(s *discordgo.Session, m *discordgo.MessageDelete) {
rmsg := config.Message{Account: b.Account, ID: m.ID, Event: config.EVENT_MSG_DELETE, Text: config.EVENT_MSG_DELETE} rmsg := config.Message{Account: b.Account, ID: m.ID, Event: config.EVENT_MSG_DELETE, Text: config.EVENT_MSG_DELETE}
rmsg.Channel = b.getChannelName(m.ChannelID) rmsg.Channel = b.getChannelName(m.ChannelID)
if b.UseChannelID { if b.UseChannelID {
@ -192,7 +192,7 @@ func (b *bdiscord) messageDelete(s *discordgo.Session, m *discordgo.MessageDelet
b.Remote <- rmsg b.Remote <- rmsg
} }
func (b *bdiscord) messageUpdate(s *discordgo.Session, m *discordgo.MessageUpdate) { func (b *Bdiscord) messageUpdate(s *discordgo.Session, m *discordgo.MessageUpdate) {
if b.Config.EditDisable { if b.Config.EditDisable {
return return
} }
@ -204,7 +204,7 @@ func (b *bdiscord) messageUpdate(s *discordgo.Session, m *discordgo.MessageUpdat
} }
} }
func (b *bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
var err error var err error
// not relay our own messages // not relay our own messages
@ -273,7 +273,7 @@ func (b *bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
b.Remote <- rmsg b.Remote <- rmsg
} }
func (b *bdiscord) memberUpdate(s *discordgo.Session, m *discordgo.GuildMemberUpdate) { func (b *Bdiscord) memberUpdate(s *discordgo.Session, m *discordgo.GuildMemberUpdate) {
b.Lock() b.Lock()
if _, ok := b.userMemberMap[m.Member.User.ID]; ok { if _, ok := b.userMemberMap[m.Member.User.ID]; ok {
flog.Debugf("%s: memberupdate: user %s (nick %s) changes nick to %s", b.Account, m.Member.User.Username, b.userMemberMap[m.Member.User.ID].Nick, m.Member.Nick) flog.Debugf("%s: memberupdate: user %s (nick %s) changes nick to %s", b.Account, m.Member.User.Username, b.userMemberMap[m.Member.User.ID].Nick, m.Member.Nick)
@ -282,7 +282,7 @@ func (b *bdiscord) memberUpdate(s *discordgo.Session, m *discordgo.GuildMemberUp
b.Unlock() b.Unlock()
} }
func (b *bdiscord) getNick(user *discordgo.User) string { func (b *Bdiscord) getNick(user *discordgo.User) string {
var err error var err error
b.Lock() b.Lock()
defer b.Unlock() defer b.Unlock()
@ -309,7 +309,7 @@ func (b *bdiscord) getNick(user *discordgo.User) string {
return user.Username return user.Username
} }
func (b *bdiscord) getChannelID(name string) string { func (b *Bdiscord) getChannelID(name string) string {
idcheck := strings.Split(name, "ID:") idcheck := strings.Split(name, "ID:")
if len(idcheck) > 1 { if len(idcheck) > 1 {
return idcheck[1] return idcheck[1]
@ -322,7 +322,7 @@ func (b *bdiscord) getChannelID(name string) string {
return "" return ""
} }
func (b *bdiscord) getChannelName(id string) string { func (b *Bdiscord) getChannelName(id string) string {
for _, channel := range b.Channels { for _, channel := range b.Channels {
if channel.ID == id { if channel.ID == id {
return channel.Name return channel.Name
@ -331,7 +331,7 @@ func (b *bdiscord) getChannelName(id string) string {
return "" return ""
} }
func (b *bdiscord) replaceChannelMentions(text string) string { func (b *Bdiscord) replaceChannelMentions(text string) string {
var err error var err error
re := regexp.MustCompile("<#[0-9]+>") re := regexp.MustCompile("<#[0-9]+>")
text = re.ReplaceAllStringFunc(text, func(m string) string { text = re.ReplaceAllStringFunc(text, func(m string) string {
@ -350,21 +350,21 @@ func (b *bdiscord) replaceChannelMentions(text string) string {
return text return text
} }
func (b *bdiscord) replaceAction(text string) (string, bool) { func (b *Bdiscord) replaceAction(text string) (string, bool) {
if strings.HasPrefix(text, "_") && strings.HasSuffix(text, "_") { if strings.HasPrefix(text, "_") && strings.HasSuffix(text, "_") {
return strings.Replace(text, "_", "", -1), true return strings.Replace(text, "_", "", -1), true
} }
return text, false return text, false
} }
func (b *bdiscord) stripCustomoji(text string) string { func (b *Bdiscord) stripCustomoji(text string) string {
// <:doge:302803592035958784> // <:doge:302803592035958784>
re := regexp.MustCompile("<(:.*?:)[0-9]+>") re := regexp.MustCompile("<(:.*?:)[0-9]+>")
return re.ReplaceAllString(text, `$1`) return re.ReplaceAllString(text, `$1`)
} }
// splitURL splits a webhookURL and returns the id and token // splitURL splits a webhookURL and returns the id and token
func (b *bdiscord) splitURL(url string) (string, string) { func (b *Bdiscord) splitURL(url string) (string, string) {
webhookURLSplit := strings.Split(url, "/") webhookURLSplit := strings.Split(url, "/")
if len(webhookURLSplit) != 7 { if len(webhookURLSplit) != 7 {
log.Fatalf("%s is no correct discord WebhookURL", url) log.Fatalf("%s is no correct discord WebhookURL", url)
@ -373,7 +373,7 @@ func (b *bdiscord) splitURL(url string) (string, string) {
} }
// useWebhook returns true if we have a webhook defined somewhere // useWebhook returns true if we have a webhook defined somewhere
func (b *bdiscord) useWebhook() bool { func (b *Bdiscord) useWebhook() bool {
if b.Config.WebhookURL != "" { if b.Config.WebhookURL != "" {
return true return true
} }
@ -386,7 +386,7 @@ func (b *bdiscord) useWebhook() bool {
} }
// isWebhookID returns true if the specified id is used in a defined webhook // isWebhookID returns true if the specified id is used in a defined webhook
func (b *bdiscord) isWebhookID(id string) bool { func (b *Bdiscord) isWebhookID(id string) bool {
if b.Config.WebhookURL != "" { if b.Config.WebhookURL != "" {
wID, _ := b.splitURL(b.Config.WebhookURL) wID, _ := b.splitURL(b.Config.WebhookURL)
if wID == id { if wID == id {
@ -405,7 +405,7 @@ func (b *bdiscord) isWebhookID(id string) bool {
} }
// handleUploadFile handles native upload of files // handleUploadFile handles native upload of files
func (b *bdiscord) handleUploadFile(msg *config.Message, channelID string) (string, error) { func (b *Bdiscord) handleUploadFile(msg *config.Message, channelID string) (string, error) {
var err error var err error
for _, f := range msg.Extra["file"] { for _, f := range msg.Extra["file"] {
fi := f.(config.FileInfo) fi := f.(config.FileInfo)

View File

@ -14,7 +14,7 @@ import (
type Bmattermost struct { type Bmattermost struct {
mh *matterhook.Client mh *matterhook.Client
mc *matterclient.MMClient mc *matterclient.MMClient
TeamId string TeamID string
*config.BridgeConfig *config.BridgeConfig
avatarMap map[string]string avatarMap map[string]string
} }
@ -100,7 +100,7 @@ func (b *Bmattermost) Connect() error {
go b.handleMatter() go b.handleMatter()
} }
if b.Config.WebhookBindAddress == "" && b.Config.WebhookURL == "" && b.Config.Login == "" && b.Config.Token == "" { if b.Config.WebhookBindAddress == "" && b.Config.WebhookURL == "" && b.Config.Login == "" && b.Config.Token == "" {
return errors.New("No connection method found. See that you have WebhookBindAddress, WebhookURL or Token/Login/Password/Server/Team configured.") return errors.New("no connection method found. See that you have WebhookBindAddress, WebhookURL or Token/Login/Password/Server/Team configured")
} }
return nil return nil
} }
@ -274,7 +274,7 @@ func (b *Bmattermost) apiLogin() error {
return err return err
} }
flog.Info("Connection succeeded") flog.Info("Connection succeeded")
b.TeamId = b.mc.GetTeamId() b.TeamID = b.mc.GetTeamId()
go b.mc.WsReceiver() go b.mc.WsReceiver()
go b.mc.StatusLoop() go b.mc.StatusLoop()
return nil return nil
@ -327,7 +327,7 @@ func (b *Bmattermost) handleDownloadFile(rmsg *config.Message, id string) error
if resp.Error != nil { if resp.Error != nil {
return resp.Error return resp.Error
} }
err := helper.HandleDownloadSize(flog, rmsg, finfo.Name, int64(finfo.Size), b.General) err := helper.HandleDownloadSize(flog, rmsg, finfo.Name, finfo.Size, b.General)
if err != nil { if err != nil {
return err return err
} }
@ -436,7 +436,7 @@ func (b *Bmattermost) skipMessage(message *matterclient.Message) bool {
} }
// ignore messages from other teams than ours // ignore messages from other teams than ours
if message.Raw.Data["team_id"].(string) != b.TeamId { if message.Raw.Data["team_id"].(string) != b.TeamID {
return true return true
} }