mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-24 11:42:03 -08:00
Fix golint linter issues and enable it in CI (#593)
This commit is contained in:
parent
c89085bf44
commit
ce21ba1545
@ -40,7 +40,7 @@ script:
|
|||||||
#- test -z "$(go fmt ./...)" # Fail if a .go file hasn't been formatted with gofmt
|
#- test -z "$(go fmt ./...)" # Fail if a .go file hasn't been formatted with gofmt
|
||||||
- go test -v -race $PKGS # Run all the tests with the race detector enabled
|
- go test -v -race $PKGS # Run all the tests with the race detector enabled
|
||||||
#- go vet $PKGS # go vet is the official Go static analyzer
|
#- go vet $PKGS # go vet is the official Go static analyzer
|
||||||
- golangci-lint run --enable-all -D golint -D lll -D errcheck -D gosec -D maligned -D prealloc -D gocyclo -D gochecknoglobals
|
- golangci-lint run --enable-all -D lll -D errcheck -D gosec -D maligned -D prealloc -D gocyclo -D gochecknoglobals
|
||||||
#- megacheck $PKGS # "go vet on steroids" + linter
|
#- megacheck $PKGS # "go vet on steroids" + linter
|
||||||
- /bin/bash ci/bintray.sh
|
- /bin/bash ci/bintray.sh
|
||||||
#- golint -set_exit_status $PKGS # one last linter
|
#- golint -set_exit_status $PKGS # one last linter
|
||||||
|
@ -13,13 +13,13 @@ import (
|
|||||||
"github.com/zfjagann/golang-ring"
|
"github.com/zfjagann/golang-ring"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Api struct {
|
type API struct {
|
||||||
Messages ring.Ring
|
Messages ring.Ring
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
*bridge.Config
|
*bridge.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApiMessage struct {
|
type Message struct {
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
UserID string `json:"userid"`
|
UserID string `json:"userid"`
|
||||||
@ -28,7 +28,7 @@ type ApiMessage struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg *bridge.Config) bridge.Bridger {
|
func New(cfg *bridge.Config) bridge.Bridger {
|
||||||
b := &Api{Config: cfg}
|
b := &API{Config: cfg}
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
e.HideBanner = true
|
e.HideBanner = true
|
||||||
e.HidePort = true
|
e.HidePort = true
|
||||||
@ -55,34 +55,34 @@ func New(cfg *bridge.Config) bridge.Bridger {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Api) Connect() error {
|
func (b *API) Connect() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (b *Api) Disconnect() error {
|
func (b *API) Disconnect() error {
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
func (b *Api) JoinChannel(channel config.ChannelInfo) error {
|
func (b *API) JoinChannel(channel config.ChannelInfo) error {
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Api) Send(msg config.Message) (string, error) {
|
func (b *API) Send(msg config.Message) (string, error) {
|
||||||
b.Lock()
|
b.Lock()
|
||||||
defer b.Unlock()
|
defer b.Unlock()
|
||||||
// ignore delete messages
|
// ignore delete messages
|
||||||
if msg.Event == config.EVENT_MSG_DELETE {
|
if msg.Event == config.EventMsgDelete {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
b.Messages.Enqueue(&msg)
|
b.Messages.Enqueue(&msg)
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Api) handleHealthcheck(c echo.Context) error {
|
func (b *API) handleHealthcheck(c echo.Context) error {
|
||||||
return c.String(http.StatusOK, "OK")
|
return c.String(http.StatusOK, "OK")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Api) handlePostMessage(c echo.Context) error {
|
func (b *API) handlePostMessage(c echo.Context) error {
|
||||||
message := config.Message{}
|
message := config.Message{}
|
||||||
if err := c.Bind(&message); err != nil {
|
if err := c.Bind(&message); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -98,7 +98,7 @@ func (b *Api) handlePostMessage(c echo.Context) error {
|
|||||||
return c.JSON(http.StatusOK, message)
|
return c.JSON(http.StatusOK, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Api) handleMessages(c echo.Context) error {
|
func (b *API) handleMessages(c echo.Context) error {
|
||||||
b.Lock()
|
b.Lock()
|
||||||
defer b.Unlock()
|
defer b.Unlock()
|
||||||
c.JSONPretty(http.StatusOK, b.Messages.Values(), " ")
|
c.JSONPretty(http.StatusOK, b.Messages.Values(), " ")
|
||||||
@ -106,11 +106,11 @@ func (b *Api) handleMessages(c echo.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Api) handleStream(c echo.Context) error {
|
func (b *API) handleStream(c echo.Context) error {
|
||||||
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
|
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
|
||||||
c.Response().WriteHeader(http.StatusOK)
|
c.Response().WriteHeader(http.StatusOK)
|
||||||
greet := config.Message{
|
greet := config.Message{
|
||||||
Event: config.EVENT_API_CONNECTED,
|
Event: config.EventAPIConnected,
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
}
|
}
|
||||||
if err := json.NewEncoder(c.Response()).Encode(greet); err != nil {
|
if err := json.NewEncoder(c.Response()).Encode(greet); err != nil {
|
||||||
|
@ -14,16 +14,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
EVENT_JOIN_LEAVE = "join_leave"
|
EventJoinLeave = "join_leave"
|
||||||
EVENT_TOPIC_CHANGE = "topic_change"
|
EventTopicChange = "topic_change"
|
||||||
EVENT_FAILURE = "failure"
|
EventFailure = "failure"
|
||||||
EVENT_FILE_FAILURE_SIZE = "file_failure_size"
|
EventFileFailureSize = "file_failure_size"
|
||||||
EVENT_AVATAR_DOWNLOAD = "avatar_download"
|
EventAvatarDownload = "avatar_download"
|
||||||
EVENT_REJOIN_CHANNELS = "rejoin_channels"
|
EventRejoinChannels = "rejoin_channels"
|
||||||
EVENT_USER_ACTION = "user_action"
|
EventUserAction = "user_action"
|
||||||
EVENT_MSG_DELETE = "msg_delete"
|
EventMsgDelete = "msg_delete"
|
||||||
EVENT_API_CONNECTED = "api_connected"
|
EventAPIConnected = "api_connected"
|
||||||
EVENT_USER_TYPING = "user_typing"
|
EventUserTyping = "user_typing"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
@ -157,20 +157,20 @@ type SameChannelGateway struct {
|
|||||||
Accounts []string
|
Accounts []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfigValues struct {
|
type BridgeValues struct {
|
||||||
Api map[string]Protocol
|
API map[string]Protocol
|
||||||
Irc map[string]Protocol
|
IRC map[string]Protocol
|
||||||
Mattermost map[string]Protocol
|
Mattermost map[string]Protocol
|
||||||
Matrix map[string]Protocol
|
Matrix map[string]Protocol
|
||||||
Slack map[string]Protocol
|
Slack map[string]Protocol
|
||||||
SlackLegacy map[string]Protocol
|
SlackLegacy map[string]Protocol
|
||||||
Steam map[string]Protocol
|
Steam map[string]Protocol
|
||||||
Gitter map[string]Protocol
|
Gitter map[string]Protocol
|
||||||
Xmpp map[string]Protocol
|
XMPP map[string]Protocol
|
||||||
Discord map[string]Protocol
|
Discord map[string]Protocol
|
||||||
Telegram map[string]Protocol
|
Telegram map[string]Protocol
|
||||||
Rocketchat map[string]Protocol
|
Rocketchat map[string]Protocol
|
||||||
Sshchat map[string]Protocol
|
SSHChat map[string]Protocol
|
||||||
Zulip map[string]Protocol
|
Zulip map[string]Protocol
|
||||||
General Protocol
|
General Protocol
|
||||||
Gateway []Gateway
|
Gateway []Gateway
|
||||||
@ -178,7 +178,7 @@ type ConfigValues struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Config interface {
|
type Config interface {
|
||||||
ConfigValues() *ConfigValues
|
BridgeValues() *BridgeValues
|
||||||
GetBool(key string) (bool, bool)
|
GetBool(key string) (bool, bool)
|
||||||
GetInt(key string) (int, bool)
|
GetInt(key string) (int, bool)
|
||||||
GetString(key string) (string, bool)
|
GetString(key string) (string, bool)
|
||||||
@ -190,7 +190,7 @@ type config struct {
|
|||||||
v *viper.Viper
|
v *viper.Viper
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
|
||||||
cv *ConfigValues
|
cv *BridgeValues
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig(cfgfile string) Config {
|
func NewConfig(cfgfile string) Config {
|
||||||
@ -236,7 +236,7 @@ func newConfigFromString(input []byte) *config {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := &ConfigValues{}
|
cfg := &BridgeValues{}
|
||||||
err = viper.Unmarshal(cfg)
|
err = viper.Unmarshal(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -247,7 +247,7 @@ func newConfigFromString(input []byte) *config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *config) ConfigValues() *ConfigValues {
|
func (c *config) BridgeValues() *BridgeValues {
|
||||||
return c.cv
|
return c.cv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make a action /me of the message
|
// Make a action /me of the message
|
||||||
if msg.Event == config.EVENT_USER_ACTION {
|
if msg.Event == config.EventUserAction {
|
||||||
msg.Text = "_" + msg.Text + "_"
|
msg.Text = "_" + msg.Text + "_"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) {
|
|||||||
// Use webhook to send the message
|
// Use webhook to send the message
|
||||||
if wID != "" {
|
if wID != "" {
|
||||||
// skip events
|
// skip events
|
||||||
if msg.Event != "" && msg.Event != config.EVENT_JOIN_LEAVE && msg.Event != config.EVENT_TOPIC_CHANGE {
|
if msg.Event != "" && msg.Event != config.EventJoinLeave && msg.Event != config.EventTopicChange {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
b.Log.Debugf("Broadcasting using Webhook")
|
b.Log.Debugf("Broadcasting using Webhook")
|
||||||
@ -179,7 +179,7 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) {
|
|||||||
b.Log.Debugf("Broadcasting using token (API)")
|
b.Log.Debugf("Broadcasting using token (API)")
|
||||||
|
|
||||||
// Delete message
|
// Delete message
|
||||||
if msg.Event == config.EVENT_MSG_DELETE {
|
if msg.Event == config.EventMsgDelete {
|
||||||
if msg.ID == "" {
|
if msg.ID == "" {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
@ -217,7 +217,7 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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.EventMsgDelete, Text: config.EventMsgDelete}
|
||||||
rmsg.Channel = b.getChannelName(m.ChannelID)
|
rmsg.Channel = b.getChannelName(m.ChannelID)
|
||||||
if b.UseChannelID {
|
if b.UseChannelID {
|
||||||
rmsg.Channel = "ID:" + m.ChannelID
|
rmsg.Channel = "ID:" + m.ChannelID
|
||||||
@ -300,7 +300,7 @@ func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
|
|||||||
var ok bool
|
var ok bool
|
||||||
rmsg.Text, ok = b.replaceAction(rmsg.Text)
|
rmsg.Text, ok = b.replaceAction(rmsg.Text)
|
||||||
if ok {
|
if ok {
|
||||||
rmsg.Event = config.EVENT_USER_ACTION
|
rmsg.Event = config.EventUserAction
|
||||||
}
|
}
|
||||||
|
|
||||||
b.Log.Debugf("<= Sending message from %s on %s to gateway", m.Author.Username, b.Account)
|
b.Log.Debugf("<= Sending message from %s on %s to gateway", m.Author.Username, b.Account)
|
||||||
|
@ -77,7 +77,7 @@ func (b *Bgitter) JoinChannel(channel config.ChannelInfo) error {
|
|||||||
Account: b.Account, Avatar: b.getAvatar(ev.Message.From.Username), UserID: ev.Message.From.ID,
|
Account: b.Account, Avatar: b.getAvatar(ev.Message.From.Username), UserID: ev.Message.From.ID,
|
||||||
ID: ev.Message.ID}
|
ID: ev.Message.ID}
|
||||||
if strings.HasPrefix(ev.Message.Text, "@"+ev.Message.From.Username) {
|
if strings.HasPrefix(ev.Message.Text, "@"+ev.Message.From.Username) {
|
||||||
rmsg.Event = config.EVENT_USER_ACTION
|
rmsg.Event = config.EventUserAction
|
||||||
rmsg.Text = strings.Replace(rmsg.Text, "@"+ev.Message.From.Username+" ", "", -1)
|
rmsg.Text = strings.Replace(rmsg.Text, "@"+ev.Message.From.Username+" ", "", -1)
|
||||||
}
|
}
|
||||||
b.Log.Debugf("<= Message is %#v", rmsg)
|
b.Log.Debugf("<= Message is %#v", rmsg)
|
||||||
@ -100,7 +100,7 @@ func (b *Bgitter) Send(msg config.Message) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete message
|
// Delete message
|
||||||
if msg.Event == config.EVENT_MSG_DELETE {
|
if msg.Event == config.EventMsgDelete {
|
||||||
if msg.ID == "" {
|
if msg.ID == "" {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ func GetSubLines(message string, maxLineLength int) []string {
|
|||||||
func HandleExtra(msg *config.Message, general *config.Protocol) []config.Message {
|
func HandleExtra(msg *config.Message, general *config.Protocol) []config.Message {
|
||||||
extra := msg.Extra
|
extra := msg.Extra
|
||||||
rmsg := []config.Message{}
|
rmsg := []config.Message{}
|
||||||
for _, f := range extra[config.EVENT_FILE_FAILURE_SIZE] {
|
for _, f := range extra[config.EventFileFailureSize] {
|
||||||
fi := f.(config.FileInfo)
|
fi := f.(config.FileInfo)
|
||||||
text := fmt.Sprintf("file %s too big to download (%#v > allowed size: %#v)", fi.Name, fi.Size, general.MediaDownloadSize)
|
text := fmt.Sprintf("file %s too big to download (%#v > allowed size: %#v)", fi.Name, fi.Size, general.MediaDownloadSize)
|
||||||
rmsg = append(rmsg, config.Message{Text: text, Username: "<system> ", Channel: msg.Channel, Account: msg.Account})
|
rmsg = append(rmsg, config.Message{Text: text, Username: "<system> ", Channel: msg.Channel, Account: msg.Account})
|
||||||
@ -113,7 +113,7 @@ func HandleDownloadSize(flog *log.Entry, msg *config.Message, name string, size
|
|||||||
}
|
}
|
||||||
flog.Debugf("Trying to download %#v with size %#v", name, size)
|
flog.Debugf("Trying to download %#v with size %#v", name, size)
|
||||||
if int(size) > general.MediaDownloadSize {
|
if int(size) > general.MediaDownloadSize {
|
||||||
msg.Event = config.EVENT_FILE_FAILURE_SIZE
|
msg.Event = config.EventFileFailureSize
|
||||||
msg.Extra[msg.Event] = append(msg.Extra[msg.Event], config.FileInfo{Name: name, Comment: msg.Text, Size: size})
|
msg.Extra[msg.Event] = append(msg.Extra[msg.Event], config.FileInfo{Name: name, Comment: msg.Text, Size: size})
|
||||||
return fmt.Errorf("File %#v to large to download (%#v). MediaDownloadSize is %#v", name, size, general.MediaDownloadSize)
|
return fmt.Errorf("File %#v to large to download (%#v). MediaDownloadSize is %#v", name, size, general.MediaDownloadSize)
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ func HandleDownloadSize(flog *log.Entry, msg *config.Message, name string, size
|
|||||||
func HandleDownloadData(flog *log.Entry, msg *config.Message, name, comment, url string, data *[]byte, general *config.Protocol) {
|
func HandleDownloadData(flog *log.Entry, msg *config.Message, name, comment, url string, data *[]byte, general *config.Protocol) {
|
||||||
var avatar bool
|
var avatar bool
|
||||||
flog.Debugf("Download OK %#v %#v", name, len(*data))
|
flog.Debugf("Download OK %#v %#v", name, len(*data))
|
||||||
if msg.Event == config.EVENT_AVATAR_DOWNLOAD {
|
if msg.Event == config.EventAvatarDownload {
|
||||||
avatar = true
|
avatar = true
|
||||||
}
|
}
|
||||||
msg.Extra["file"] = append(msg.Extra["file"], config.FileInfo{Name: name, Data: data, URL: url, Comment: comment, Avatar: avatar})
|
msg.Extra["file"] = append(msg.Extra["file"], config.FileInfo{Name: name, Data: data, URL: url, Comment: comment, Avatar: avatar})
|
||||||
|
@ -128,7 +128,7 @@ func (b *Birc) Connect() error {
|
|||||||
time.Sleep(30 * time.Second)
|
time.Sleep(30 * time.Second)
|
||||||
i.Handlers.Clear(girc.RPL_WELCOME)
|
i.Handlers.Clear(girc.RPL_WELCOME)
|
||||||
i.Handlers.Add(girc.RPL_WELCOME, func(client *girc.Client, event girc.Event) {
|
i.Handlers.Add(girc.RPL_WELCOME, func(client *girc.Client, event girc.Event) {
|
||||||
b.Remote <- config.Message{Username: "system", Text: "rejoin", Channel: "", Account: b.Account, Event: config.EVENT_REJOIN_CHANNELS}
|
b.Remote <- config.Message{Username: "system", Text: "rejoin", Channel: "", Account: b.Account, Event: config.EventRejoinChannels}
|
||||||
// set our correct nick on reconnect if necessary
|
// set our correct nick on reconnect if necessary
|
||||||
b.Nick = event.Source.Name
|
b.Nick = event.Source.Name
|
||||||
})
|
})
|
||||||
@ -167,7 +167,7 @@ func (b *Birc) JoinChannel(channel config.ChannelInfo) error {
|
|||||||
|
|
||||||
func (b *Birc) Send(msg config.Message) (string, error) {
|
func (b *Birc) Send(msg config.Message) (string, error) {
|
||||||
// ignore delete messages
|
// ignore delete messages
|
||||||
if msg.Event == config.EVENT_MSG_DELETE {
|
if msg.Event == config.EventMsgDelete {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,7 +257,7 @@ func (b *Birc) doSend() {
|
|||||||
colorCode := checksum%14 + 2 // quick fix - prevent white or black color codes
|
colorCode := checksum%14 + 2 // quick fix - prevent white or black color codes
|
||||||
username = fmt.Sprintf("\x03%02d%s\x0F", colorCode, msg.Username)
|
username = fmt.Sprintf("\x03%02d%s\x0F", colorCode, msg.Username)
|
||||||
}
|
}
|
||||||
if msg.Event == config.EVENT_USER_ACTION {
|
if msg.Event == config.EventUserAction {
|
||||||
b.i.Cmd.Action(msg.Channel, username+msg.Text)
|
b.i.Cmd.Action(msg.Channel, username+msg.Text)
|
||||||
} else {
|
} else {
|
||||||
b.Log.Debugf("Sending to channel %s", msg.Channel)
|
b.Log.Debugf("Sending to channel %s", msg.Channel)
|
||||||
@ -309,13 +309,13 @@ func (b *Birc) handleJoinPart(client *girc.Client, event girc.Event) {
|
|||||||
if event.Command == "KICK" && event.Params[1] == b.Nick {
|
if event.Command == "KICK" && event.Params[1] == b.Nick {
|
||||||
b.Log.Infof("Got kicked from %s by %s", channel, event.Source.Name)
|
b.Log.Infof("Got kicked from %s by %s", channel, event.Source.Name)
|
||||||
time.Sleep(time.Duration(b.GetInt("RejoinDelay")) * time.Second)
|
time.Sleep(time.Duration(b.GetInt("RejoinDelay")) * time.Second)
|
||||||
b.Remote <- config.Message{Username: "system", Text: "rejoin", Channel: channel, Account: b.Account, Event: config.EVENT_REJOIN_CHANNELS}
|
b.Remote <- config.Message{Username: "system", Text: "rejoin", Channel: channel, Account: b.Account, Event: config.EventRejoinChannels}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if event.Command == "QUIT" {
|
if event.Command == "QUIT" {
|
||||||
if event.Source.Name == b.Nick && strings.Contains(event.Trailing, "Ping timeout") {
|
if event.Source.Name == b.Nick && strings.Contains(event.Trailing, "Ping timeout") {
|
||||||
b.Log.Infof("%s reconnecting ..", b.Account)
|
b.Log.Infof("%s reconnecting ..", b.Account)
|
||||||
b.Remote <- config.Message{Username: "system", Text: "reconnect", Channel: channel, Account: b.Account, Event: config.EVENT_FAILURE}
|
b.Remote <- config.Message{Username: "system", Text: "reconnect", Channel: channel, Account: b.Account, Event: config.EventFailure}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -324,7 +324,7 @@ func (b *Birc) handleJoinPart(client *girc.Client, event girc.Event) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
b.Log.Debugf("<= Sending JOIN_LEAVE event from %s to gateway", b.Account)
|
b.Log.Debugf("<= Sending JOIN_LEAVE event from %s to gateway", b.Account)
|
||||||
msg := config.Message{Username: "system", Text: event.Source.Name + " " + strings.ToLower(event.Command) + "s", Channel: channel, Account: b.Account, Event: config.EVENT_JOIN_LEAVE}
|
msg := config.Message{Username: "system", Text: event.Source.Name + " " + strings.ToLower(event.Command) + "s", Channel: channel, Account: b.Account, Event: config.EventJoinLeave}
|
||||||
b.Log.Debugf("<= Message is %#v", msg)
|
b.Log.Debugf("<= Message is %#v", msg)
|
||||||
b.Remote <- msg
|
b.Remote <- msg
|
||||||
return
|
return
|
||||||
@ -391,7 +391,7 @@ func (b *Birc) handlePrivMsg(client *girc.Client, event girc.Event) {
|
|||||||
|
|
||||||
// set action event
|
// set action event
|
||||||
if event.IsAction() {
|
if event.IsAction() {
|
||||||
rmsg.Event = config.EVENT_USER_ACTION
|
rmsg.Event = config.EventUserAction
|
||||||
}
|
}
|
||||||
|
|
||||||
// strip action, we made an event if it was an action
|
// strip action, we made an event if it was an action
|
||||||
|
@ -72,7 +72,7 @@ func (b *Bmatrix) Send(msg config.Message) (string, error) {
|
|||||||
b.Log.Debugf("Channel %s maps to channel id %s", msg.Channel, channel)
|
b.Log.Debugf("Channel %s maps to channel id %s", msg.Channel, channel)
|
||||||
|
|
||||||
// Make a action /me of the message
|
// Make a action /me of the message
|
||||||
if msg.Event == config.EVENT_USER_ACTION {
|
if msg.Event == config.EventUserAction {
|
||||||
m := matrix.TextMessage{
|
m := matrix.TextMessage{
|
||||||
MsgType: "m.emote",
|
MsgType: "m.emote",
|
||||||
Body: msg.Username + msg.Text,
|
Body: msg.Username + msg.Text,
|
||||||
@ -85,7 +85,7 @@ func (b *Bmatrix) Send(msg config.Message) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete message
|
// Delete message
|
||||||
if msg.Event == config.EVENT_MSG_DELETE {
|
if msg.Event == config.EventMsgDelete {
|
||||||
if msg.ID == "" {
|
if msg.ID == "" {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
@ -173,16 +173,16 @@ func (b *Bmatrix) handleEvent(ev *matrix.Event) {
|
|||||||
|
|
||||||
// Delete event
|
// Delete event
|
||||||
if ev.Type == "m.room.redaction" {
|
if ev.Type == "m.room.redaction" {
|
||||||
rmsg.Event = config.EVENT_MSG_DELETE
|
rmsg.Event = config.EventMsgDelete
|
||||||
rmsg.ID = ev.Redacts
|
rmsg.ID = ev.Redacts
|
||||||
rmsg.Text = config.EVENT_MSG_DELETE
|
rmsg.Text = config.EventMsgDelete
|
||||||
b.Remote <- rmsg
|
b.Remote <- rmsg
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do we have a /me action
|
// Do we have a /me action
|
||||||
if ev.Content["msgtype"].(string) == "m.emote" {
|
if ev.Content["msgtype"].(string) == "m.emote" {
|
||||||
rmsg.Event = config.EVENT_USER_ACTION
|
rmsg.Event = config.EventUserAction
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do we have attachments
|
// Do we have attachments
|
||||||
|
@ -136,12 +136,12 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) {
|
|||||||
b.Log.Debugf("=> Receiving %#v", msg)
|
b.Log.Debugf("=> Receiving %#v", msg)
|
||||||
|
|
||||||
// Make a action /me of the message
|
// Make a action /me of the message
|
||||||
if msg.Event == config.EVENT_USER_ACTION {
|
if msg.Event == config.EventUserAction {
|
||||||
msg.Text = "*" + msg.Text + "*"
|
msg.Text = "*" + msg.Text + "*"
|
||||||
}
|
}
|
||||||
|
|
||||||
// map the file SHA to our user (caches the avatar)
|
// map the file SHA to our user (caches the avatar)
|
||||||
if msg.Event == config.EVENT_AVATAR_DOWNLOAD {
|
if msg.Event == config.EventAvatarDownload {
|
||||||
return b.cacheAvatar(&msg)
|
return b.cacheAvatar(&msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete message
|
// Delete message
|
||||||
if msg.Event == config.EVENT_MSG_DELETE {
|
if msg.Event == config.EventMsgDelete {
|
||||||
if msg.ID == "" {
|
if msg.ID == "" {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
@ -201,7 +201,7 @@ func (b *Bmattermost) handleMatter() {
|
|||||||
message.Account = b.Account
|
message.Account = b.Account
|
||||||
message.Text, ok = b.replaceAction(message.Text)
|
message.Text, ok = b.replaceAction(message.Text)
|
||||||
if ok {
|
if ok {
|
||||||
message.Event = config.EVENT_USER_ACTION
|
message.Event = config.EventUserAction
|
||||||
}
|
}
|
||||||
b.Log.Debugf("<= Sending message from %s on %s to gateway", message.Username, b.Account)
|
b.Log.Debugf("<= Sending message from %s on %s to gateway", message.Username, b.Account)
|
||||||
b.Log.Debugf("<= Message is %#v", message)
|
b.Log.Debugf("<= Message is %#v", message)
|
||||||
@ -256,7 +256,7 @@ func (b *Bmattermost) handleMatterClient(messages chan *config.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if message.Raw.Event == model.WEBSOCKET_EVENT_POST_DELETED {
|
if message.Raw.Event == model.WEBSOCKET_EVENT_POST_DELETED {
|
||||||
rmsg.Event = config.EVENT_MSG_DELETE
|
rmsg.Event = config.EventMsgDelete
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(message.Post.FileIds) > 0 {
|
if len(message.Post.FileIds) > 0 {
|
||||||
@ -331,7 +331,7 @@ func (b *Bmattermost) cacheAvatar(msg *config.Message) (string, error) {
|
|||||||
// sends a EVENT_AVATAR_DOWNLOAD message to the gateway if successful.
|
// sends a EVENT_AVATAR_DOWNLOAD message to the gateway if successful.
|
||||||
// logs an error message if it fails
|
// logs an error message if it fails
|
||||||
func (b *Bmattermost) handleDownloadAvatar(userid string, channel string) {
|
func (b *Bmattermost) handleDownloadAvatar(userid string, channel string) {
|
||||||
rmsg := config.Message{Username: "system", Text: "avatar", Channel: channel, Account: b.Account, UserID: userid, Event: config.EVENT_AVATAR_DOWNLOAD, Extra: make(map[string][]interface{})}
|
rmsg := config.Message{Username: "system", Text: "avatar", Channel: channel, Account: b.Account, UserID: userid, Event: config.EventAvatarDownload, Extra: make(map[string][]interface{})}
|
||||||
if _, ok := b.avatarMap[userid]; !ok {
|
if _, ok := b.avatarMap[userid]; !ok {
|
||||||
data, resp := b.mc.Client.GetProfileImage(userid, "")
|
data, resp := b.mc.Client.GetProfileImage(userid, "")
|
||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
@ -442,7 +442,7 @@ func (b *Bmattermost) skipMessage(message *matterclient.Message) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
b.Log.Debugf("Sending JOIN_LEAVE event from %s to gateway", b.Account)
|
b.Log.Debugf("Sending JOIN_LEAVE event from %s to gateway", b.Account)
|
||||||
b.Remote <- config.Message{Username: "system", Text: message.Text, Channel: message.Channel, Account: b.Account, Event: config.EVENT_JOIN_LEAVE}
|
b.Remote <- config.Message{Username: "system", Text: message.Text, Channel: message.Channel, Account: b.Account, Event: config.EventJoinLeave}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ func (b *Brocketchat) JoinChannel(channel config.ChannelInfo) error {
|
|||||||
|
|
||||||
func (b *Brocketchat) Send(msg config.Message) (string, error) {
|
func (b *Brocketchat) Send(msg config.Message) (string, error) {
|
||||||
// ignore delete messages
|
// ignore delete messages
|
||||||
if msg.Event == config.EVENT_MSG_DELETE {
|
if msg.Event == config.EventMsgDelete {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
b.Log.Debugf("=> Receiving %#v", msg)
|
b.Log.Debugf("=> Receiving %#v", msg)
|
||||||
|
@ -22,7 +22,7 @@ func (b *Bslack) handleSlack() {
|
|||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
b.Log.Debug("Start listening for Slack messages")
|
b.Log.Debug("Start listening for Slack messages")
|
||||||
for message := range messages {
|
for message := range messages {
|
||||||
if message.Event != config.EVENT_USER_TYPING {
|
if message.Event != config.EventUserTyping {
|
||||||
b.Log.Debugf("<= Sending message from %s on %s to gateway", message.Username, b.Account)
|
b.Log.Debugf("<= Sending message from %s on %s to gateway", message.Username, b.Account)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,18 +199,18 @@ func (b *Bslack) handleStatusEvent(ev *slack.MessageEvent, rmsg *config.Message)
|
|||||||
return true
|
return true
|
||||||
case sChannelJoin, sChannelLeave:
|
case sChannelJoin, sChannelLeave:
|
||||||
rmsg.Username = sSystemUser
|
rmsg.Username = sSystemUser
|
||||||
rmsg.Event = config.EVENT_JOIN_LEAVE
|
rmsg.Event = config.EventJoinLeave
|
||||||
case sChannelTopic, sChannelPurpose:
|
case sChannelTopic, sChannelPurpose:
|
||||||
rmsg.Event = config.EVENT_TOPIC_CHANGE
|
rmsg.Event = config.EventTopicChange
|
||||||
case sMessageDeleted:
|
case sMessageDeleted:
|
||||||
rmsg.Text = config.EVENT_MSG_DELETE
|
rmsg.Text = config.EventMsgDelete
|
||||||
rmsg.Event = config.EVENT_MSG_DELETE
|
rmsg.Event = config.EventMsgDelete
|
||||||
rmsg.ID = "slack " + ev.DeletedTimestamp
|
rmsg.ID = "slack " + ev.DeletedTimestamp
|
||||||
// If a message is being deleted we do not need to process
|
// If a message is being deleted we do not need to process
|
||||||
// the event any further so we return 'true'.
|
// the event any further so we return 'true'.
|
||||||
return true
|
return true
|
||||||
case sMeMessage:
|
case sMeMessage:
|
||||||
rmsg.Event = config.EVENT_USER_ACTION
|
rmsg.Event = config.EventUserAction
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -256,7 +256,7 @@ func (b *Bslack) handleTypingEvent(ev *slack.UserTypingEvent) (*config.Message,
|
|||||||
return &config.Message{
|
return &config.Message{
|
||||||
Channel: channelInfo.Name,
|
Channel: channelInfo.Name,
|
||||||
Account: b.Account,
|
Account: b.Account,
|
||||||
Event: config.EVENT_USER_TYPING,
|
Event: config.EventUserTyping,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,15 +8,15 @@ import (
|
|||||||
"github.com/nlopes/slack"
|
"github.com/nlopes/slack"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BslackLegacy struct {
|
type BLegacy struct {
|
||||||
*Bslack
|
*Bslack
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLegacy(cfg *bridge.Config) bridge.Bridger {
|
func NewLegacy(cfg *bridge.Config) bridge.Bridger {
|
||||||
return &BslackLegacy{Bslack: newBridge(cfg)}
|
return &BLegacy{Bslack: newBridge(cfg)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BslackLegacy) Connect() error {
|
func (b *BLegacy) Connect() error {
|
||||||
b.RLock()
|
b.RLock()
|
||||||
defer b.RUnlock()
|
defer b.RUnlock()
|
||||||
if b.GetString(incomingWebhookConfig) != "" {
|
if b.GetString(incomingWebhookConfig) != "" {
|
||||||
|
@ -185,12 +185,12 @@ func (b *Bslack) Reload(cfg *bridge.Config) (string, error) {
|
|||||||
|
|
||||||
func (b *Bslack) Send(msg config.Message) (string, error) {
|
func (b *Bslack) Send(msg config.Message) (string, error) {
|
||||||
// Too noisy to log like other events
|
// Too noisy to log like other events
|
||||||
if msg.Event != config.EVENT_USER_TYPING {
|
if msg.Event != config.EventUserTyping {
|
||||||
b.Log.Debugf("=> Receiving %#v", msg)
|
b.Log.Debugf("=> Receiving %#v", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a action /me of the message
|
// Make a action /me of the message
|
||||||
if msg.Event == config.EVENT_USER_ACTION {
|
if msg.Event == config.EventUserAction {
|
||||||
msg.Text = "_" + msg.Text + "_"
|
msg.Text = "_" + msg.Text + "_"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,7 +270,7 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("could not send message: %v", err)
|
return "", fmt.Errorf("could not send message: %v", err)
|
||||||
}
|
}
|
||||||
if msg.Event == config.EVENT_USER_TYPING {
|
if msg.Event == config.EventUserTyping {
|
||||||
if b.GetBool("ShowUserTyping") {
|
if b.GetBool("ShowUserTyping") {
|
||||||
b.rtm.SendMessage(b.rtm.NewTypingMessage(channelInfo.ID))
|
b.rtm.SendMessage(b.rtm.NewTypingMessage(channelInfo.ID))
|
||||||
}
|
}
|
||||||
@ -312,7 +312,7 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bslack) deleteMessage(msg *config.Message, channelInfo *slack.Channel) (bool, error) {
|
func (b *Bslack) deleteMessage(msg *config.Message, channelInfo *slack.Channel) (bool, error) {
|
||||||
if msg.Event != config.EVENT_MSG_DELETE {
|
if msg.Event != config.EventMsgDelete {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ func (b *Bsshchat) Connect() error {
|
|||||||
b.w = w
|
b.w = w
|
||||||
b.r.Scan()
|
b.r.Scan()
|
||||||
w.Write([]byte("/theme mono\r\n"))
|
w.Write([]byte("/theme mono\r\n"))
|
||||||
b.handleSshChat()
|
b.handleSSHChat()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}()
|
}()
|
||||||
@ -53,7 +53,7 @@ func (b *Bsshchat) JoinChannel(channel config.ChannelInfo) error {
|
|||||||
|
|
||||||
func (b *Bsshchat) Send(msg config.Message) (string, error) {
|
func (b *Bsshchat) Send(msg config.Message) (string, error) {
|
||||||
// ignore delete messages
|
// ignore delete messages
|
||||||
if msg.Event == config.EVENT_MSG_DELETE {
|
if msg.Event == config.EventMsgDelete {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
b.Log.Debugf("=> Receiving %#v", msg)
|
b.Log.Debugf("=> Receiving %#v", msg)
|
||||||
@ -113,7 +113,7 @@ func stripPrompt(s string) string {
|
|||||||
return s[pos+3:]
|
return s[pos+3:]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bsshchat) handleSshChat() error {
|
func (b *Bsshchat) handleSSHChat() error {
|
||||||
/*
|
/*
|
||||||
done := b.sshchatKeepAlive()
|
done := b.sshchatKeepAlive()
|
||||||
defer close(done)
|
defer close(done)
|
||||||
|
@ -60,7 +60,7 @@ func (b *Bsteam) JoinChannel(channel config.ChannelInfo) error {
|
|||||||
|
|
||||||
func (b *Bsteam) Send(msg config.Message) (string, error) {
|
func (b *Bsteam) Send(msg config.Message) (string, error) {
|
||||||
// ignore delete messages
|
// ignore delete messages
|
||||||
if msg.Event == config.EVENT_MSG_DELETE {
|
if msg.Event == config.EventMsgDelete {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
id, err := steamid.NewId(msg.Channel)
|
id, err := steamid.NewId(msg.Channel)
|
||||||
|
@ -66,7 +66,7 @@ func (b *Btelegram) Send(msg config.Message) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// map the file SHA to our user (caches the avatar)
|
// map the file SHA to our user (caches the avatar)
|
||||||
if msg.Event == config.EVENT_AVATAR_DOWNLOAD {
|
if msg.Event == config.EventAvatarDownload {
|
||||||
return b.cacheAvatar(&msg)
|
return b.cacheAvatar(&msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ func (b *Btelegram) Send(msg config.Message) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete message
|
// Delete message
|
||||||
if msg.Event == config.EVENT_MSG_DELETE {
|
if msg.Event == config.EventMsgDelete {
|
||||||
if msg.ID == "" {
|
if msg.ID == "" {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
@ -268,7 +268,7 @@ func (b *Btelegram) getFileDirectURL(id string) string {
|
|||||||
// sends a EVENT_AVATAR_DOWNLOAD message to the gateway if successful.
|
// sends a EVENT_AVATAR_DOWNLOAD message to the gateway if successful.
|
||||||
// logs an error message if it fails
|
// logs an error message if it fails
|
||||||
func (b *Btelegram) handleDownloadAvatar(userid int, channel string) {
|
func (b *Btelegram) handleDownloadAvatar(userid int, channel string) {
|
||||||
rmsg := config.Message{Username: "system", Text: "avatar", Channel: channel, Account: b.Account, UserID: strconv.Itoa(userid), Event: config.EVENT_AVATAR_DOWNLOAD, Extra: make(map[string][]interface{})}
|
rmsg := config.Message{Username: "system", Text: "avatar", Channel: channel, Account: b.Account, UserID: strconv.Itoa(userid), Event: config.EventAvatarDownload, Extra: make(map[string][]interface{})}
|
||||||
if _, ok := b.avatarMap[strconv.Itoa(userid)]; !ok {
|
if _, ok := b.avatarMap[strconv.Itoa(userid)]; !ok {
|
||||||
photos, err := b.c.GetUserProfilePhotos(tgbotapi.UserProfilePhotosConfig{UserID: userid, Limit: 1})
|
photos, err := b.c.GetUserProfilePhotos(tgbotapi.UserProfilePhotosConfig{UserID: userid, Limit: 1})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -51,7 +51,7 @@ func (b *Bxmpp) Connect() error {
|
|||||||
time.Sleep(d)
|
time.Sleep(d)
|
||||||
b.xc, err = b.createXMPP()
|
b.xc, err = b.createXMPP()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
b.Remote <- config.Message{Username: "system", Text: "rejoin", Channel: "", Account: b.Account, Event: config.EVENT_REJOIN_CHANNELS}
|
b.Remote <- config.Message{Username: "system", Text: "rejoin", Channel: "", Account: b.Account, Event: config.EventRejoinChannels}
|
||||||
b.handleXMPP()
|
b.handleXMPP()
|
||||||
bf.Reset()
|
bf.Reset()
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ func (b *Bxmpp) JoinChannel(channel config.ChannelInfo) error {
|
|||||||
|
|
||||||
func (b *Bxmpp) Send(msg config.Message) (string, error) {
|
func (b *Bxmpp) Send(msg config.Message) (string, error) {
|
||||||
// ignore delete messages
|
// ignore delete messages
|
||||||
if msg.Event == config.EVENT_MSG_DELETE {
|
if msg.Event == config.EventMsgDelete {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
b.Log.Debugf("=> Receiving %#v", msg)
|
b.Log.Debugf("=> Receiving %#v", msg)
|
||||||
@ -177,7 +177,7 @@ func (b *Bxmpp) handleXMPP() error {
|
|||||||
// check if we have an action event
|
// check if we have an action event
|
||||||
rmsg.Text, ok = b.replaceAction(rmsg.Text)
|
rmsg.Text, ok = b.replaceAction(rmsg.Text)
|
||||||
if ok {
|
if ok {
|
||||||
rmsg.Event = config.EVENT_USER_ACTION
|
rmsg.Event = config.EventUserAction
|
||||||
}
|
}
|
||||||
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)
|
||||||
|
@ -52,7 +52,7 @@ func (b *Bzulip) Send(msg config.Message) (string, error) {
|
|||||||
b.Log.Debugf("=> Receiving %#v", msg)
|
b.Log.Debugf("=> Receiving %#v", msg)
|
||||||
|
|
||||||
// Delete message
|
// Delete message
|
||||||
if msg.Event == config.EVENT_MSG_DELETE {
|
if msg.Event == config.EventMsgDelete {
|
||||||
if msg.ID == "" {
|
if msg.ID == "" {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ func (gw *Gateway) AddBridge(cfg *config.Bridge) error {
|
|||||||
if br == nil {
|
if br == nil {
|
||||||
br = bridge.New(cfg)
|
br = bridge.New(cfg)
|
||||||
br.Config = gw.Router.Config
|
br.Config = gw.Router.Config
|
||||||
br.General = &gw.ConfigValues().General
|
br.General = &gw.BridgeValues().General
|
||||||
// set logging
|
// set logging
|
||||||
br.Log = log.WithFields(log.Fields{"prefix": "bridge"})
|
br.Log = log.WithFields(log.Fields{"prefix": "bridge"})
|
||||||
brconfig := &bridge.Config{Remote: gw.Message, Log: log.WithFields(log.Fields{"prefix": br.Protocol}), Bridge: br}
|
brconfig := &bridge.Config{Remote: gw.Message, Log: log.WithFields(log.Fields{"prefix": br.Protocol}), Bridge: br}
|
||||||
@ -159,7 +159,7 @@ RECONNECT:
|
|||||||
|
|
||||||
func (gw *Gateway) mapChannelConfig(cfg []config.Bridge, direction string) {
|
func (gw *Gateway) mapChannelConfig(cfg []config.Bridge, direction string) {
|
||||||
for _, br := range cfg {
|
for _, br := range cfg {
|
||||||
if isApi(br.Account) {
|
if isAPI(br.Account) {
|
||||||
br.Channel = apiProtocol
|
br.Channel = apiProtocol
|
||||||
}
|
}
|
||||||
// make sure to lowercase irc channels in config #348
|
// make sure to lowercase irc channels in config #348
|
||||||
@ -246,7 +246,7 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
|
|
||||||
// if we have an attached file, or other info
|
// if we have an attached file, or other info
|
||||||
if msg.Extra != nil {
|
if msg.Extra != nil {
|
||||||
if len(msg.Extra[config.EVENT_FILE_FAILURE_SIZE]) != 0 {
|
if len(msg.Extra[config.EventFileFailureSize]) != 0 {
|
||||||
if msg.Text == "" {
|
if msg.Text == "" {
|
||||||
return brMsgIDs
|
return brMsgIDs
|
||||||
}
|
}
|
||||||
@ -254,7 +254,7 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Avatar downloads are only relevant for telegram and mattermost for now
|
// Avatar downloads are only relevant for telegram and mattermost for now
|
||||||
if msg.Event == config.EVENT_AVATAR_DOWNLOAD {
|
if msg.Event == config.EventAvatarDownload {
|
||||||
if dest.Protocol != "mattermost" &&
|
if dest.Protocol != "mattermost" &&
|
||||||
dest.Protocol != "telegram" {
|
dest.Protocol != "telegram" {
|
||||||
return brMsgIDs
|
return brMsgIDs
|
||||||
@ -262,24 +262,24 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
}
|
}
|
||||||
|
|
||||||
// only relay join/part when configured
|
// only relay join/part when configured
|
||||||
if msg.Event == config.EVENT_JOIN_LEAVE && !gw.Bridges[dest.Account].GetBool("ShowJoinPart") {
|
if msg.Event == config.EventJoinLeave && !gw.Bridges[dest.Account].GetBool("ShowJoinPart") {
|
||||||
return brMsgIDs
|
return brMsgIDs
|
||||||
}
|
}
|
||||||
|
|
||||||
// only relay topic change when configured
|
// only relay topic change when configured
|
||||||
if msg.Event == config.EVENT_TOPIC_CHANGE && !gw.Bridges[dest.Account].GetBool("ShowTopicChange") {
|
if msg.Event == config.EventTopicChange && !gw.Bridges[dest.Account].GetBool("ShowTopicChange") {
|
||||||
return brMsgIDs
|
return brMsgIDs
|
||||||
}
|
}
|
||||||
|
|
||||||
// broadcast to every out channel (irc QUIT)
|
// broadcast to every out channel (irc QUIT)
|
||||||
if msg.Channel == "" && msg.Event != config.EVENT_JOIN_LEAVE {
|
if msg.Channel == "" && msg.Event != config.EventJoinLeave {
|
||||||
flog.Debug("empty channel")
|
flog.Debug("empty channel")
|
||||||
return brMsgIDs
|
return brMsgIDs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the ID of the parent message in thread
|
// Get the ID of the parent message in thread
|
||||||
var canonicalParentMsgID string
|
var canonicalParentMsgID string
|
||||||
if msg.ParentID != "" && (gw.ConfigValues().General.PreserveThreading || dest.GetBool("PreserveThreading")) {
|
if msg.ParentID != "" && (gw.BridgeValues().General.PreserveThreading || dest.GetBool("PreserveThreading")) {
|
||||||
thisParentMsgID := dest.Protocol + " " + msg.ParentID
|
thisParentMsgID := dest.Protocol + " " + msg.ParentID
|
||||||
canonicalParentMsgID = gw.FindCanonicalMsgID(thisParentMsgID)
|
canonicalParentMsgID = gw.FindCanonicalMsgID(thisParentMsgID)
|
||||||
}
|
}
|
||||||
@ -289,7 +289,7 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
channels := gw.getDestChannel(&msg, *dest)
|
channels := gw.getDestChannel(&msg, *dest)
|
||||||
for _, channel := range channels {
|
for _, channel := range channels {
|
||||||
// Only send the avatar download event to ourselves.
|
// Only send the avatar download event to ourselves.
|
||||||
if msg.Event == config.EVENT_AVATAR_DOWNLOAD {
|
if msg.Event == config.EventAvatarDownload {
|
||||||
if channel.ID != getChannelID(origmsg) {
|
if channel.ID != getChannelID(origmsg) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -301,7 +301,7 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Too noisy to log like other events
|
// Too noisy to log like other events
|
||||||
if msg.Event != config.EVENT_USER_TYPING {
|
if msg.Event != config.EventUserTyping {
|
||||||
flog.Debugf("=> Sending %#v from %s (%s) to %s (%s)", msg, msg.Account, originchannel, dest.Account, channel.Name)
|
flog.Debugf("=> Sending %#v from %s (%s) to %s (%s)", msg, msg.Account, originchannel, dest.Account, channel.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,14 +349,14 @@ func (gw *Gateway) ignoreMessage(msg *config.Message) bool {
|
|||||||
|
|
||||||
// check if we need to ignore a empty message
|
// check if we need to ignore a empty message
|
||||||
if msg.Text == "" {
|
if msg.Text == "" {
|
||||||
if msg.Event == config.EVENT_USER_TYPING {
|
if msg.Event == config.EventUserTyping {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// we have an attachment or actual bytes, do not ignore
|
// we have an attachment or actual bytes, do not ignore
|
||||||
if msg.Extra != nil &&
|
if msg.Extra != nil &&
|
||||||
(msg.Extra["attachments"] != nil ||
|
(msg.Extra["attachments"] != nil ||
|
||||||
len(msg.Extra["file"]) > 0 ||
|
len(msg.Extra["file"]) > 0 ||
|
||||||
len(msg.Extra[config.EVENT_FILE_FAILURE_SIZE]) > 0) {
|
len(msg.Extra[config.EventFileFailureSize]) > 0) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
flog.Debugf("ignoring empty message %#v from %s", msg, msg.Account)
|
flog.Debugf("ignoring empty message %#v from %s", msg, msg.Account)
|
||||||
@ -392,13 +392,13 @@ func (gw *Gateway) ignoreMessage(msg *config.Message) bool {
|
|||||||
func (gw *Gateway) modifyUsername(msg config.Message, dest *bridge.Bridge) string {
|
func (gw *Gateway) modifyUsername(msg config.Message, dest *bridge.Bridge) string {
|
||||||
br := gw.Bridges[msg.Account]
|
br := gw.Bridges[msg.Account]
|
||||||
msg.Protocol = br.Protocol
|
msg.Protocol = br.Protocol
|
||||||
if gw.ConfigValues().General.StripNick || dest.GetBool("StripNick") {
|
if gw.BridgeValues().General.StripNick || dest.GetBool("StripNick") {
|
||||||
re := regexp.MustCompile("[^a-zA-Z0-9]+")
|
re := regexp.MustCompile("[^a-zA-Z0-9]+")
|
||||||
msg.Username = re.ReplaceAllString(msg.Username, "")
|
msg.Username = re.ReplaceAllString(msg.Username, "")
|
||||||
}
|
}
|
||||||
nick := dest.GetString("RemoteNickFormat")
|
nick := dest.GetString("RemoteNickFormat")
|
||||||
if nick == "" {
|
if nick == "" {
|
||||||
nick = gw.ConfigValues().General.RemoteNickFormat
|
nick = gw.BridgeValues().General.RemoteNickFormat
|
||||||
}
|
}
|
||||||
|
|
||||||
// loop to replace nicks
|
// loop to replace nicks
|
||||||
@ -437,7 +437,7 @@ func (gw *Gateway) modifyUsername(msg config.Message, dest *bridge.Bridge) strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gw *Gateway) modifyAvatar(msg config.Message, dest *bridge.Bridge) string {
|
func (gw *Gateway) modifyAvatar(msg config.Message, dest *bridge.Bridge) string {
|
||||||
iconurl := gw.ConfigValues().General.IconURL
|
iconurl := gw.BridgeValues().General.IconURL
|
||||||
if iconurl == "" {
|
if iconurl == "" {
|
||||||
iconurl = dest.GetString("IconURL")
|
iconurl = dest.GetString("IconURL")
|
||||||
}
|
}
|
||||||
@ -479,8 +479,8 @@ func (gw *Gateway) handleFiles(msg *config.Message) {
|
|||||||
|
|
||||||
// If we don't have a attachfield or we don't have a mediaserver configured return
|
// If we don't have a attachfield or we don't have a mediaserver configured return
|
||||||
if msg.Extra == nil ||
|
if msg.Extra == nil ||
|
||||||
(gw.ConfigValues().General.MediaServerUpload == "" &&
|
(gw.BridgeValues().General.MediaServerUpload == "" &&
|
||||||
gw.ConfigValues().General.MediaDownloadPath == "") {
|
gw.BridgeValues().General.MediaDownloadPath == "") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -502,10 +502,10 @@ func (gw *Gateway) handleFiles(msg *config.Message) {
|
|||||||
|
|
||||||
sha1sum := fmt.Sprintf("%x", sha1.Sum(*fi.Data))[:8]
|
sha1sum := fmt.Sprintf("%x", sha1.Sum(*fi.Data))[:8]
|
||||||
|
|
||||||
if gw.ConfigValues().General.MediaServerUpload != "" {
|
if gw.BridgeValues().General.MediaServerUpload != "" {
|
||||||
// Use MediaServerUpload. Upload using a PUT HTTP request and basicauth.
|
// Use MediaServerUpload. Upload using a PUT HTTP request and basicauth.
|
||||||
|
|
||||||
url := gw.ConfigValues().General.MediaServerUpload + "/" + sha1sum + "/" + fi.Name
|
url := gw.BridgeValues().General.MediaServerUpload + "/" + sha1sum + "/" + fi.Name
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT", url, bytes.NewReader(*fi.Data))
|
req, err := http.NewRequest("PUT", url, bytes.NewReader(*fi.Data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -524,7 +524,7 @@ func (gw *Gateway) handleFiles(msg *config.Message) {
|
|||||||
} else {
|
} else {
|
||||||
// Use MediaServerPath. Place the file on the current filesystem.
|
// Use MediaServerPath. Place the file on the current filesystem.
|
||||||
|
|
||||||
dir := gw.ConfigValues().General.MediaDownloadPath + "/" + sha1sum
|
dir := gw.BridgeValues().General.MediaDownloadPath + "/" + sha1sum
|
||||||
err := os.Mkdir(dir, os.ModePerm)
|
err := os.Mkdir(dir, os.ModePerm)
|
||||||
if err != nil && !os.IsExist(err) {
|
if err != nil && !os.IsExist(err) {
|
||||||
flog.Errorf("mediaserver path failed, could not mkdir: %s %#v", err, err)
|
flog.Errorf("mediaserver path failed, could not mkdir: %s %#v", err, err)
|
||||||
@ -542,7 +542,7 @@ func (gw *Gateway) handleFiles(msg *config.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Download URL.
|
// Download URL.
|
||||||
durl := gw.ConfigValues().General.MediaServerDownload + "/" + sha1sum + "/" + fi.Name
|
durl := gw.BridgeValues().General.MediaServerDownload + "/" + sha1sum + "/" + fi.Name
|
||||||
|
|
||||||
flog.Debugf("mediaserver download URL = %s", durl)
|
flog.Debugf("mediaserver download URL = %s", durl)
|
||||||
|
|
||||||
@ -562,6 +562,6 @@ func getChannelID(msg config.Message) string {
|
|||||||
return msg.Channel + msg.Account
|
return msg.Channel + msg.Account
|
||||||
}
|
}
|
||||||
|
|
||||||
func isApi(account string) bool {
|
func isAPI(account string) bool {
|
||||||
return strings.HasPrefix(account, "api.")
|
return strings.HasPrefix(account, "api.")
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ func NewRouter(cfg config.Config) (*Router, error) {
|
|||||||
sgw := samechannelgateway.New(cfg)
|
sgw := samechannelgateway.New(cfg)
|
||||||
gwconfigs := sgw.GetConfig()
|
gwconfigs := sgw.GetConfig()
|
||||||
|
|
||||||
for _, entry := range append(gwconfigs, cfg.ConfigValues().Gateway...) {
|
for _, entry := range append(gwconfigs, cfg.BridgeValues().Gateway...) {
|
||||||
if !entry.Enable {
|
if !entry.Enable {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ func (r *Router) getBridge(account string) *bridge.Bridge {
|
|||||||
func (r *Router) handleReceive() {
|
func (r *Router) handleReceive() {
|
||||||
for msg := range r.Message {
|
for msg := range r.Message {
|
||||||
msg := msg // scopelint
|
msg := msg // scopelint
|
||||||
if msg.Event == config.EVENT_FAILURE {
|
if msg.Event == config.EventFailure {
|
||||||
Loop:
|
Loop:
|
||||||
for _, gw := range r.Gateways {
|
for _, gw := range r.Gateways {
|
||||||
for _, br := range gw.Bridges {
|
for _, br := range gw.Bridges {
|
||||||
@ -88,7 +88,7 @@ func (r *Router) handleReceive() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if msg.Event == config.EVENT_REJOIN_CHANNELS {
|
if msg.Event == config.EventRejoinChannels {
|
||||||
for _, gw := range r.Gateways {
|
for _, gw := range r.Gateways {
|
||||||
for _, br := range gw.Bridges {
|
for _, br := range gw.Bridges {
|
||||||
if msg.Account == br.Account {
|
if msg.Account == br.Account {
|
||||||
|
@ -15,7 +15,7 @@ func New(cfg config.Config) *SameChannelGateway {
|
|||||||
func (sgw *SameChannelGateway) GetConfig() []config.Gateway {
|
func (sgw *SameChannelGateway) GetConfig() []config.Gateway {
|
||||||
var gwconfigs []config.Gateway
|
var gwconfigs []config.Gateway
|
||||||
cfg := sgw.Config
|
cfg := sgw.Config
|
||||||
for _, gw := range cfg.ConfigValues().SameChannelGateway {
|
for _, gw := range cfg.BridgeValues().SameChannelGateway {
|
||||||
gwconfig := config.Gateway{Name: gw.Name, Enable: gw.Enable}
|
gwconfig := config.Gateway{Name: gw.Name, Enable: gw.Enable}
|
||||||
for _, account := range gw.Accounts {
|
for _, account := range gw.Accounts {
|
||||||
for _, channel := range gw.Channels {
|
for _, channel := range gw.Channels {
|
||||||
|
@ -44,7 +44,7 @@ func main() {
|
|||||||
flog.Println("WARNING: THIS IS A DEVELOPMENT VERSION. Things may break.")
|
flog.Println("WARNING: THIS IS A DEVELOPMENT VERSION. Things may break.")
|
||||||
}
|
}
|
||||||
cfg := config.NewConfig(*flagConfig)
|
cfg := config.NewConfig(*flagConfig)
|
||||||
cfg.ConfigValues().General.Debug = *flagDebug
|
cfg.BridgeValues().General.Debug = *flagDebug
|
||||||
r, err := gateway.NewRouter(cfg)
|
r, err := gateway.NewRouter(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
flog.Fatalf("Starting gateway failed: %s", err)
|
flog.Fatalf("Starting gateway failed: %s", err)
|
||||||
|
@ -43,6 +43,7 @@ type Message struct {
|
|||||||
UserID string
|
UserID string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint:golint
|
||||||
type Team struct {
|
type Team struct {
|
||||||
Team *model.Team
|
Team *model.Team
|
||||||
Id string
|
Id string
|
||||||
@ -423,7 +424,7 @@ func (m *MMClient) UpdateChannels() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) GetChannelName(channelId string) string {
|
func (m *MMClient) GetChannelName(channelId string) string { //nolint:golint
|
||||||
m.RLock()
|
m.RLock()
|
||||||
defer m.RUnlock()
|
defer m.RUnlock()
|
||||||
for _, t := range m.OtherTeams {
|
for _, t := range m.OtherTeams {
|
||||||
@ -458,7 +459,7 @@ func (m *MMClient) GetChannelName(channelId string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) GetChannelId(name string, teamId string) string {
|
func (m *MMClient) GetChannelId(name string, teamId string) string { //nolint:golint
|
||||||
m.RLock()
|
m.RLock()
|
||||||
defer m.RUnlock()
|
defer m.RUnlock()
|
||||||
if teamId == "" {
|
if teamId == "" {
|
||||||
@ -488,7 +489,7 @@ func (m *MMClient) GetChannelId(name string, teamId string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) GetChannelTeamId(id string) string {
|
func (m *MMClient) GetChannelTeamId(id string) string { //nolint:golint
|
||||||
m.RLock()
|
m.RLock()
|
||||||
defer m.RUnlock()
|
defer m.RUnlock()
|
||||||
for _, t := range append(m.OtherTeams, m.Team) {
|
for _, t := range append(m.OtherTeams, m.Team) {
|
||||||
@ -501,7 +502,7 @@ func (m *MMClient) GetChannelTeamId(id string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) GetChannelHeader(channelId string) string {
|
func (m *MMClient) GetChannelHeader(channelId string) string { //nolint:golint
|
||||||
m.RLock()
|
m.RLock()
|
||||||
defer m.RUnlock()
|
defer m.RUnlock()
|
||||||
for _, t := range m.OtherTeams {
|
for _, t := range m.OtherTeams {
|
||||||
@ -515,7 +516,7 @@ func (m *MMClient) GetChannelHeader(channelId string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) PostMessage(channelId string, text string) (string, error) {
|
func (m *MMClient) PostMessage(channelId string, text string) (string, error) { //nolint:golint
|
||||||
post := &model.Post{ChannelId: channelId, Message: text}
|
post := &model.Post{ChannelId: channelId, Message: text}
|
||||||
res, resp := m.Client.CreatePost(post)
|
res, resp := m.Client.CreatePost(post)
|
||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
@ -524,7 +525,7 @@ func (m *MMClient) PostMessage(channelId string, text string) (string, error) {
|
|||||||
return res.Id, nil
|
return res.Id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) PostMessageWithFiles(channelId string, text string, fileIds []string) (string, error) {
|
func (m *MMClient) PostMessageWithFiles(channelId string, text string, fileIds []string) (string, error) { //nolint:golint
|
||||||
post := &model.Post{ChannelId: channelId, Message: text, FileIds: fileIds}
|
post := &model.Post{ChannelId: channelId, Message: text, FileIds: fileIds}
|
||||||
res, resp := m.Client.CreatePost(post)
|
res, resp := m.Client.CreatePost(post)
|
||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
@ -533,7 +534,7 @@ func (m *MMClient) PostMessageWithFiles(channelId string, text string, fileIds [
|
|||||||
return res.Id, nil
|
return res.Id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) EditMessage(postId string, text string) (string, error) {
|
func (m *MMClient) EditMessage(postId string, text string) (string, error) { //nolint:golint
|
||||||
post := &model.Post{Message: text}
|
post := &model.Post{Message: text}
|
||||||
res, resp := m.Client.UpdatePost(postId, post)
|
res, resp := m.Client.UpdatePost(postId, post)
|
||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
@ -542,7 +543,7 @@ func (m *MMClient) EditMessage(postId string, text string) (string, error) {
|
|||||||
return res.Id, nil
|
return res.Id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) DeleteMessage(postId string) error {
|
func (m *MMClient) DeleteMessage(postId string) error { //nolint:golint
|
||||||
_, resp := m.Client.DeletePost(postId)
|
_, resp := m.Client.DeletePost(postId)
|
||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
return resp.Error
|
return resp.Error
|
||||||
@ -550,7 +551,7 @@ func (m *MMClient) DeleteMessage(postId string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) JoinChannel(channelId string) error {
|
func (m *MMClient) JoinChannel(channelId string) error { //nolint:golint
|
||||||
m.RLock()
|
m.RLock()
|
||||||
defer m.RUnlock()
|
defer m.RUnlock()
|
||||||
for _, c := range m.Team.Channels {
|
for _, c := range m.Team.Channels {
|
||||||
@ -567,7 +568,7 @@ func (m *MMClient) JoinChannel(channelId string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) GetPostsSince(channelId string, time int64) *model.PostList {
|
func (m *MMClient) GetPostsSince(channelId string, time int64) *model.PostList { //nolint:golint
|
||||||
res, resp := m.Client.GetPostsSince(channelId, time)
|
res, resp := m.Client.GetPostsSince(channelId, time)
|
||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
return nil
|
return nil
|
||||||
@ -583,7 +584,7 @@ func (m *MMClient) SearchPosts(query string) *model.PostList {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) GetPosts(channelId string, limit int) *model.PostList {
|
func (m *MMClient) GetPosts(channelId string, limit int) *model.PostList { //nolint:golint
|
||||||
res, resp := m.Client.GetPostsForChannel(channelId, 0, limit, "")
|
res, resp := m.Client.GetPostsForChannel(channelId, 0, limit, "")
|
||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
return nil
|
return nil
|
||||||
@ -630,7 +631,7 @@ func (m *MMClient) GetFileLinks(filenames []string) []string {
|
|||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) UpdateChannelHeader(channelId string, header string) {
|
func (m *MMClient) UpdateChannelHeader(channelId string, header string) { //nolint:golint
|
||||||
channel := &model.Channel{Id: channelId, Header: header}
|
channel := &model.Channel{Id: channelId, Header: header}
|
||||||
m.log.Debugf("updating channelheader %#v, %#v", channelId, header)
|
m.log.Debugf("updating channelheader %#v, %#v", channelId, header)
|
||||||
_, resp := m.Client.UpdateChannel(channel)
|
_, resp := m.Client.UpdateChannel(channel)
|
||||||
@ -639,7 +640,7 @@ func (m *MMClient) UpdateChannelHeader(channelId string, header string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) UpdateLastViewed(channelId string) error {
|
func (m *MMClient) UpdateLastViewed(channelId string) error { //nolint:golint
|
||||||
m.log.Debugf("posting lastview %#v", channelId)
|
m.log.Debugf("posting lastview %#v", channelId)
|
||||||
view := &model.ChannelView{ChannelId: channelId}
|
view := &model.ChannelView{ChannelId: channelId}
|
||||||
_, resp := m.Client.ViewChannel(m.User.Id, view)
|
_, resp := m.Client.ViewChannel(m.User.Id, view)
|
||||||
@ -660,7 +661,7 @@ func (m *MMClient) UpdateUserNick(nick string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) UsernamesInChannel(channelId string) []string {
|
func (m *MMClient) UsernamesInChannel(channelId string) []string { //nolint:golint
|
||||||
res, resp := m.Client.GetChannelMembers(channelId, 0, 50000, "")
|
res, resp := m.Client.GetChannelMembers(channelId, 0, 50000, "")
|
||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
m.log.Errorf("UsernamesInChannel(%s) failed: %s", channelId, resp.Error)
|
m.log.Errorf("UsernamesInChannel(%s) failed: %s", channelId, resp.Error)
|
||||||
@ -690,11 +691,11 @@ func (m *MMClient) createCookieJar(token string) *cookiejar.Jar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SendDirectMessage sends a direct message to specified user
|
// SendDirectMessage sends a direct message to specified user
|
||||||
func (m *MMClient) SendDirectMessage(toUserId string, msg string) {
|
func (m *MMClient) SendDirectMessage(toUserId string, msg string) { //nolint:golint
|
||||||
m.SendDirectMessageProps(toUserId, msg, nil)
|
m.SendDirectMessageProps(toUserId, msg, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) SendDirectMessageProps(toUserId string, msg string, props map[string]interface{}) {
|
func (m *MMClient) SendDirectMessageProps(toUserId string, msg string, props map[string]interface{}) { //nolint:golint
|
||||||
m.log.Debugf("SendDirectMessage to %s, msg %s", toUserId, msg)
|
m.log.Debugf("SendDirectMessage to %s, msg %s", toUserId, msg)
|
||||||
// create DM channel (only happens on first message)
|
// create DM channel (only happens on first message)
|
||||||
_, resp := m.Client.CreateDirectChannel(m.User.Id, toUserId)
|
_, resp := m.Client.CreateDirectChannel(m.User.Id, toUserId)
|
||||||
@ -714,7 +715,7 @@ func (m *MMClient) SendDirectMessageProps(toUserId string, msg string, props map
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetTeamName returns the name of the specified teamId
|
// GetTeamName returns the name of the specified teamId
|
||||||
func (m *MMClient) GetTeamName(teamId string) string {
|
func (m *MMClient) GetTeamName(teamId string) string { //nolint:golint
|
||||||
m.RLock()
|
m.RLock()
|
||||||
defer m.RUnlock()
|
defer m.RUnlock()
|
||||||
for _, t := range m.OtherTeams {
|
for _, t := range m.OtherTeams {
|
||||||
@ -752,7 +753,7 @@ func (m *MMClient) GetMoreChannels() []*model.Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetTeamFromChannel returns teamId belonging to channel (DM channels have no teamId).
|
// GetTeamFromChannel returns teamId belonging to channel (DM channels have no teamId).
|
||||||
func (m *MMClient) GetTeamFromChannel(channelId string) string {
|
func (m *MMClient) GetTeamFromChannel(channelId string) string { //nolint:golint
|
||||||
m.RLock()
|
m.RLock()
|
||||||
defer m.RUnlock()
|
defer m.RUnlock()
|
||||||
var channels []*model.Channel
|
var channels []*model.Channel
|
||||||
@ -774,7 +775,7 @@ func (m *MMClient) GetTeamFromChannel(channelId string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) GetLastViewedAt(channelId string) int64 {
|
func (m *MMClient) GetLastViewedAt(channelId string) int64 { //nolint:golint
|
||||||
m.RLock()
|
m.RLock()
|
||||||
defer m.RUnlock()
|
defer m.RUnlock()
|
||||||
res, resp := m.Client.GetChannelMember(channelId, m.User.Id, "")
|
res, resp := m.Client.GetChannelMember(channelId, m.User.Id, "")
|
||||||
@ -794,7 +795,7 @@ func (m *MMClient) GetUsers() map[string]*model.User {
|
|||||||
return users
|
return users
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) GetUser(userId string) *model.User {
|
func (m *MMClient) GetUser(userId string) *model.User { //nolint:golint
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
_, ok := m.Users[userId]
|
_, ok := m.Users[userId]
|
||||||
@ -808,7 +809,7 @@ func (m *MMClient) GetUser(userId string) *model.User {
|
|||||||
return m.Users[userId]
|
return m.Users[userId]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) UpdateUser(userId string) {
|
func (m *MMClient) UpdateUser(userId string) { //nolint:golint
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
res, resp := m.Client.GetUser(userId, "")
|
res, resp := m.Client.GetUser(userId, "")
|
||||||
@ -818,7 +819,7 @@ func (m *MMClient) UpdateUser(userId string) {
|
|||||||
m.Users[userId] = res
|
m.Users[userId] = res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) GetUserName(userId string) string {
|
func (m *MMClient) GetUserName(userId string) string { //nolint:golint
|
||||||
user := m.GetUser(userId)
|
user := m.GetUser(userId)
|
||||||
if user != nil {
|
if user != nil {
|
||||||
return user.Username
|
return user.Username
|
||||||
@ -826,7 +827,7 @@ func (m *MMClient) GetUserName(userId string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) GetNickName(userId string) string {
|
func (m *MMClient) GetNickName(userId string) string { //nolint:golint
|
||||||
user := m.GetUser(userId)
|
user := m.GetUser(userId)
|
||||||
if user != nil {
|
if user != nil {
|
||||||
return user.Nickname
|
return user.Nickname
|
||||||
@ -834,7 +835,7 @@ func (m *MMClient) GetNickName(userId string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) GetStatus(userId string) string {
|
func (m *MMClient) GetStatus(userId string) string { //nolint:golint
|
||||||
res, resp := m.Client.GetUserStatus(userId, "")
|
res, resp := m.Client.GetUserStatus(userId, "")
|
||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
return ""
|
return ""
|
||||||
@ -848,7 +849,7 @@ func (m *MMClient) GetStatus(userId string) string {
|
|||||||
return "offline"
|
return "offline"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) UpdateStatus(userId string, status string) error {
|
func (m *MMClient) UpdateStatus(userId string, status string) error { //nolint:golint
|
||||||
_, resp := m.Client.UpdateUserStatus(userId, &model.Status{Status: status})
|
_, resp := m.Client.UpdateUserStatus(userId, &model.Status{Status: status})
|
||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
return resp.Error
|
return resp.Error
|
||||||
@ -878,11 +879,11 @@ func (m *MMClient) GetStatuses() map[string]string {
|
|||||||
return statuses
|
return statuses
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) GetTeamId() string {
|
func (m *MMClient) GetTeamId() string { //nolint:golint
|
||||||
return m.Team.Id
|
return m.Team.Id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) UploadFile(data []byte, channelId string, filename string) (string, error) {
|
func (m *MMClient) UploadFile(data []byte, channelId string, filename string) (string, error) { //nolint:golint
|
||||||
f, resp := m.Client.UploadFile(data, channelId, filename)
|
f, resp := m.Client.UploadFile(data, channelId, filename)
|
||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
return "", resp.Error
|
return "", resp.Error
|
||||||
|
@ -41,9 +41,9 @@ type IMessage struct {
|
|||||||
Timestamp string `schema:"timestamp"`
|
Timestamp string `schema:"timestamp"`
|
||||||
UserID string `schema:"user_id"`
|
UserID string `schema:"user_id"`
|
||||||
UserName string `schema:"user_name"`
|
UserName string `schema:"user_name"`
|
||||||
PostId string `schema:"post_id"`
|
PostId string `schema:"post_id"` //nolint:golint
|
||||||
RawText string `schema:"raw_text"`
|
RawText string `schema:"raw_text"`
|
||||||
ServiceId string `schema:"service_id"`
|
ServiceId string `schema:"service_id"` //nolint:golint
|
||||||
Text string `schema:"text"`
|
Text string `schema:"text"`
|
||||||
TriggerWord string `schema:"trigger_word"`
|
TriggerWord string `schema:"trigger_word"`
|
||||||
FileIDs string `schema:"file_ids"`
|
FileIDs string `schema:"file_ids"`
|
||||||
@ -51,7 +51,8 @@ type IMessage struct {
|
|||||||
|
|
||||||
// Client for Mattermost.
|
// Client for Mattermost.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
Url string // URL for incoming webhooks on mattermost.
|
// URL for incoming webhooks on mattermost.
|
||||||
|
Url string // nolint:golint
|
||||||
In chan IMessage
|
In chan IMessage
|
||||||
Out chan OMessage
|
Out chan OMessage
|
||||||
httpclient *http.Client
|
httpclient *http.Client
|
||||||
|
Loading…
Reference in New Issue
Block a user