mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-06-27 08:49:24 +00:00
Fix golint linter issues and enable it in CI (#593)
This commit is contained in:
@ -13,13 +13,13 @@ import (
|
||||
"github.com/zfjagann/golang-ring"
|
||||
)
|
||||
|
||||
type Api struct {
|
||||
type API struct {
|
||||
Messages ring.Ring
|
||||
sync.RWMutex
|
||||
*bridge.Config
|
||||
}
|
||||
|
||||
type ApiMessage struct {
|
||||
type Message struct {
|
||||
Text string `json:"text"`
|
||||
Username string `json:"username"`
|
||||
UserID string `json:"userid"`
|
||||
@ -28,7 +28,7 @@ type ApiMessage struct {
|
||||
}
|
||||
|
||||
func New(cfg *bridge.Config) bridge.Bridger {
|
||||
b := &Api{Config: cfg}
|
||||
b := &API{Config: cfg}
|
||||
e := echo.New()
|
||||
e.HideBanner = true
|
||||
e.HidePort = true
|
||||
@ -55,34 +55,34 @@ func New(cfg *bridge.Config) bridge.Bridger {
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *Api) Connect() error {
|
||||
func (b *API) Connect() error {
|
||||
return nil
|
||||
}
|
||||
func (b *Api) Disconnect() error {
|
||||
func (b *API) Disconnect() error {
|
||||
return nil
|
||||
|
||||
}
|
||||
func (b *Api) JoinChannel(channel config.ChannelInfo) error {
|
||||
func (b *API) JoinChannel(channel config.ChannelInfo) error {
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (b *Api) Send(msg config.Message) (string, error) {
|
||||
func (b *API) Send(msg config.Message) (string, error) {
|
||||
b.Lock()
|
||||
defer b.Unlock()
|
||||
// ignore delete messages
|
||||
if msg.Event == config.EVENT_MSG_DELETE {
|
||||
if msg.Event == config.EventMsgDelete {
|
||||
return "", nil
|
||||
}
|
||||
b.Messages.Enqueue(&msg)
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (b *Api) handleHealthcheck(c echo.Context) error {
|
||||
func (b *API) handleHealthcheck(c echo.Context) error {
|
||||
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{}
|
||||
if err := c.Bind(&message); err != nil {
|
||||
return err
|
||||
@ -98,7 +98,7 @@ func (b *Api) handlePostMessage(c echo.Context) error {
|
||||
return c.JSON(http.StatusOK, message)
|
||||
}
|
||||
|
||||
func (b *Api) handleMessages(c echo.Context) error {
|
||||
func (b *API) handleMessages(c echo.Context) error {
|
||||
b.Lock()
|
||||
defer b.Unlock()
|
||||
c.JSONPretty(http.StatusOK, b.Messages.Values(), " ")
|
||||
@ -106,11 +106,11 @@ func (b *Api) handleMessages(c echo.Context) error {
|
||||
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().WriteHeader(http.StatusOK)
|
||||
greet := config.Message{
|
||||
Event: config.EVENT_API_CONNECTED,
|
||||
Event: config.EventAPIConnected,
|
||||
Timestamp: time.Now(),
|
||||
}
|
||||
if err := json.NewEncoder(c.Response()).Encode(greet); err != nil {
|
||||
|
@ -14,16 +14,16 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
EVENT_JOIN_LEAVE = "join_leave"
|
||||
EVENT_TOPIC_CHANGE = "topic_change"
|
||||
EVENT_FAILURE = "failure"
|
||||
EVENT_FILE_FAILURE_SIZE = "file_failure_size"
|
||||
EVENT_AVATAR_DOWNLOAD = "avatar_download"
|
||||
EVENT_REJOIN_CHANNELS = "rejoin_channels"
|
||||
EVENT_USER_ACTION = "user_action"
|
||||
EVENT_MSG_DELETE = "msg_delete"
|
||||
EVENT_API_CONNECTED = "api_connected"
|
||||
EVENT_USER_TYPING = "user_typing"
|
||||
EventJoinLeave = "join_leave"
|
||||
EventTopicChange = "topic_change"
|
||||
EventFailure = "failure"
|
||||
EventFileFailureSize = "file_failure_size"
|
||||
EventAvatarDownload = "avatar_download"
|
||||
EventRejoinChannels = "rejoin_channels"
|
||||
EventUserAction = "user_action"
|
||||
EventMsgDelete = "msg_delete"
|
||||
EventAPIConnected = "api_connected"
|
||||
EventUserTyping = "user_typing"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
@ -157,20 +157,20 @@ type SameChannelGateway struct {
|
||||
Accounts []string
|
||||
}
|
||||
|
||||
type ConfigValues struct {
|
||||
Api map[string]Protocol
|
||||
Irc map[string]Protocol
|
||||
type BridgeValues struct {
|
||||
API map[string]Protocol
|
||||
IRC map[string]Protocol
|
||||
Mattermost map[string]Protocol
|
||||
Matrix map[string]Protocol
|
||||
Slack map[string]Protocol
|
||||
SlackLegacy map[string]Protocol
|
||||
Steam map[string]Protocol
|
||||
Gitter map[string]Protocol
|
||||
Xmpp map[string]Protocol
|
||||
XMPP map[string]Protocol
|
||||
Discord map[string]Protocol
|
||||
Telegram map[string]Protocol
|
||||
Rocketchat map[string]Protocol
|
||||
Sshchat map[string]Protocol
|
||||
SSHChat map[string]Protocol
|
||||
Zulip map[string]Protocol
|
||||
General Protocol
|
||||
Gateway []Gateway
|
||||
@ -178,7 +178,7 @@ type ConfigValues struct {
|
||||
}
|
||||
|
||||
type Config interface {
|
||||
ConfigValues() *ConfigValues
|
||||
BridgeValues() *BridgeValues
|
||||
GetBool(key string) (bool, bool)
|
||||
GetInt(key string) (int, bool)
|
||||
GetString(key string) (string, bool)
|
||||
@ -190,7 +190,7 @@ type config struct {
|
||||
v *viper.Viper
|
||||
sync.RWMutex
|
||||
|
||||
cv *ConfigValues
|
||||
cv *BridgeValues
|
||||
}
|
||||
|
||||
func NewConfig(cfgfile string) Config {
|
||||
@ -236,7 +236,7 @@ func newConfigFromString(input []byte) *config {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
cfg := &ConfigValues{}
|
||||
cfg := &BridgeValues{}
|
||||
err = viper.Unmarshal(cfg)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) {
|
||||
}
|
||||
|
||||
// Make a action /me of the message
|
||||
if msg.Event == config.EVENT_USER_ACTION {
|
||||
if msg.Event == config.EventUserAction {
|
||||
msg.Text = "_" + msg.Text + "_"
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) {
|
||||
// Use webhook to send the message
|
||||
if wID != "" {
|
||||
// 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
|
||||
}
|
||||
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)")
|
||||
|
||||
// Delete message
|
||||
if msg.Event == config.EVENT_MSG_DELETE {
|
||||
if msg.Event == config.EventMsgDelete {
|
||||
if msg.ID == "" {
|
||||
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) {
|
||||
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)
|
||||
if b.UseChannelID {
|
||||
rmsg.Channel = "ID:" + m.ChannelID
|
||||
@ -300,7 +300,7 @@ func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
|
||||
var ok bool
|
||||
rmsg.Text, ok = b.replaceAction(rmsg.Text)
|
||||
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)
|
||||
|
@ -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,
|
||||
ID: ev.Message.ID}
|
||||
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)
|
||||
}
|
||||
b.Log.Debugf("<= Message is %#v", rmsg)
|
||||
@ -100,7 +100,7 @@ func (b *Bgitter) Send(msg config.Message) (string, error) {
|
||||
}
|
||||
|
||||
// Delete message
|
||||
if msg.Event == config.EVENT_MSG_DELETE {
|
||||
if msg.Event == config.EventMsgDelete {
|
||||
if msg.ID == "" {
|
||||
return "", nil
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ func GetSubLines(message string, maxLineLength int) []string {
|
||||
func HandleExtra(msg *config.Message, general *config.Protocol) []config.Message {
|
||||
extra := msg.Extra
|
||||
rmsg := []config.Message{}
|
||||
for _, f := range extra[config.EVENT_FILE_FAILURE_SIZE] {
|
||||
for _, f := range extra[config.EventFileFailureSize] {
|
||||
fi := f.(config.FileInfo)
|
||||
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})
|
||||
@ -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)
|
||||
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})
|
||||
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) {
|
||||
var avatar bool
|
||||
flog.Debugf("Download OK %#v %#v", name, len(*data))
|
||||
if msg.Event == config.EVENT_AVATAR_DOWNLOAD {
|
||||
if msg.Event == config.EventAvatarDownload {
|
||||
avatar = true
|
||||
}
|
||||
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)
|
||||
i.Handlers.Clear(girc.RPL_WELCOME)
|
||||
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
|
||||
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) {
|
||||
// ignore delete messages
|
||||
if msg.Event == config.EVENT_MSG_DELETE {
|
||||
if msg.Event == config.EventMsgDelete {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
@ -257,7 +257,7 @@ func (b *Birc) doSend() {
|
||||
colorCode := checksum%14 + 2 // quick fix - prevent white or black color codes
|
||||
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)
|
||||
} else {
|
||||
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 {
|
||||
b.Log.Infof("Got kicked from %s by %s", channel, event.Source.Name)
|
||||
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
|
||||
}
|
||||
if event.Command == "QUIT" {
|
||||
if event.Source.Name == b.Nick && strings.Contains(event.Trailing, "Ping timeout") {
|
||||
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
|
||||
}
|
||||
}
|
||||
@ -324,7 +324,7 @@ func (b *Birc) handleJoinPart(client *girc.Client, event girc.Event) {
|
||||
return
|
||||
}
|
||||
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.Remote <- msg
|
||||
return
|
||||
@ -391,7 +391,7 @@ func (b *Birc) handlePrivMsg(client *girc.Client, event girc.Event) {
|
||||
|
||||
// set action event
|
||||
if event.IsAction() {
|
||||
rmsg.Event = config.EVENT_USER_ACTION
|
||||
rmsg.Event = config.EventUserAction
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
// Make a action /me of the message
|
||||
if msg.Event == config.EVENT_USER_ACTION {
|
||||
if msg.Event == config.EventUserAction {
|
||||
m := matrix.TextMessage{
|
||||
MsgType: "m.emote",
|
||||
Body: msg.Username + msg.Text,
|
||||
@ -85,7 +85,7 @@ func (b *Bmatrix) Send(msg config.Message) (string, error) {
|
||||
}
|
||||
|
||||
// Delete message
|
||||
if msg.Event == config.EVENT_MSG_DELETE {
|
||||
if msg.Event == config.EventMsgDelete {
|
||||
if msg.ID == "" {
|
||||
return "", nil
|
||||
}
|
||||
@ -173,16 +173,16 @@ func (b *Bmatrix) handleEvent(ev *matrix.Event) {
|
||||
|
||||
// Delete event
|
||||
if ev.Type == "m.room.redaction" {
|
||||
rmsg.Event = config.EVENT_MSG_DELETE
|
||||
rmsg.Event = config.EventMsgDelete
|
||||
rmsg.ID = ev.Redacts
|
||||
rmsg.Text = config.EVENT_MSG_DELETE
|
||||
rmsg.Text = config.EventMsgDelete
|
||||
b.Remote <- rmsg
|
||||
return
|
||||
}
|
||||
|
||||
// Do we have a /me action
|
||||
if ev.Content["msgtype"].(string) == "m.emote" {
|
||||
rmsg.Event = config.EVENT_USER_ACTION
|
||||
rmsg.Event = config.EventUserAction
|
||||
}
|
||||
|
||||
// Do we have attachments
|
||||
|
@ -136,12 +136,12 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) {
|
||||
b.Log.Debugf("=> Receiving %#v", msg)
|
||||
|
||||
// Make a action /me of the message
|
||||
if msg.Event == config.EVENT_USER_ACTION {
|
||||
if msg.Event == config.EventUserAction {
|
||||
msg.Text = "*" + msg.Text + "*"
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) {
|
||||
}
|
||||
|
||||
// Delete message
|
||||
if msg.Event == config.EVENT_MSG_DELETE {
|
||||
if msg.Event == config.EventMsgDelete {
|
||||
if msg.ID == "" {
|
||||
return "", nil
|
||||
}
|
||||
@ -201,7 +201,7 @@ func (b *Bmattermost) handleMatter() {
|
||||
message.Account = b.Account
|
||||
message.Text, ok = b.replaceAction(message.Text)
|
||||
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("<= 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 {
|
||||
rmsg.Event = config.EVENT_MSG_DELETE
|
||||
rmsg.Event = config.EventMsgDelete
|
||||
}
|
||||
|
||||
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.
|
||||
// logs an error message if it fails
|
||||
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 {
|
||||
data, resp := b.mc.Client.GetProfileImage(userid, "")
|
||||
if resp.Error != nil {
|
||||
@ -442,7 +442,7 @@ func (b *Bmattermost) skipMessage(message *matterclient.Message) bool {
|
||||
return true
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ func (b *Brocketchat) JoinChannel(channel config.ChannelInfo) error {
|
||||
|
||||
func (b *Brocketchat) Send(msg config.Message) (string, error) {
|
||||
// ignore delete messages
|
||||
if msg.Event == config.EVENT_MSG_DELETE {
|
||||
if msg.Event == config.EventMsgDelete {
|
||||
return "", nil
|
||||
}
|
||||
b.Log.Debugf("=> Receiving %#v", msg)
|
||||
|
@ -22,7 +22,7 @@ func (b *Bslack) handleSlack() {
|
||||
time.Sleep(time.Second)
|
||||
b.Log.Debug("Start listening for Slack 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)
|
||||
}
|
||||
|
||||
@ -199,18 +199,18 @@ func (b *Bslack) handleStatusEvent(ev *slack.MessageEvent, rmsg *config.Message)
|
||||
return true
|
||||
case sChannelJoin, sChannelLeave:
|
||||
rmsg.Username = sSystemUser
|
||||
rmsg.Event = config.EVENT_JOIN_LEAVE
|
||||
rmsg.Event = config.EventJoinLeave
|
||||
case sChannelTopic, sChannelPurpose:
|
||||
rmsg.Event = config.EVENT_TOPIC_CHANGE
|
||||
rmsg.Event = config.EventTopicChange
|
||||
case sMessageDeleted:
|
||||
rmsg.Text = config.EVENT_MSG_DELETE
|
||||
rmsg.Event = config.EVENT_MSG_DELETE
|
||||
rmsg.Text = config.EventMsgDelete
|
||||
rmsg.Event = config.EventMsgDelete
|
||||
rmsg.ID = "slack " + ev.DeletedTimestamp
|
||||
// If a message is being deleted we do not need to process
|
||||
// the event any further so we return 'true'.
|
||||
return true
|
||||
case sMeMessage:
|
||||
rmsg.Event = config.EVENT_USER_ACTION
|
||||
rmsg.Event = config.EventUserAction
|
||||
}
|
||||
return false
|
||||
}
|
||||
@ -256,7 +256,7 @@ func (b *Bslack) handleTypingEvent(ev *slack.UserTypingEvent) (*config.Message,
|
||||
return &config.Message{
|
||||
Channel: channelInfo.Name,
|
||||
Account: b.Account,
|
||||
Event: config.EVENT_USER_TYPING,
|
||||
Event: config.EventUserTyping,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -8,15 +8,15 @@ import (
|
||||
"github.com/nlopes/slack"
|
||||
)
|
||||
|
||||
type BslackLegacy struct {
|
||||
type BLegacy struct {
|
||||
*Bslack
|
||||
}
|
||||
|
||||
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()
|
||||
defer b.RUnlock()
|
||||
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) {
|
||||
// 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)
|
||||
}
|
||||
|
||||
// Make a action /me of the message
|
||||
if msg.Event == config.EVENT_USER_ACTION {
|
||||
if msg.Event == config.EventUserAction {
|
||||
msg.Text = "_" + msg.Text + "_"
|
||||
}
|
||||
|
||||
@ -270,7 +270,7 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) {
|
||||
if err != nil {
|
||||
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") {
|
||||
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) {
|
||||
if msg.Event != config.EVENT_MSG_DELETE {
|
||||
if msg.Event != config.EventMsgDelete {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ func (b *Bsshchat) Connect() error {
|
||||
b.w = w
|
||||
b.r.Scan()
|
||||
w.Write([]byte("/theme mono\r\n"))
|
||||
b.handleSshChat()
|
||||
b.handleSSHChat()
|
||||
return nil
|
||||
})
|
||||
}()
|
||||
@ -53,7 +53,7 @@ func (b *Bsshchat) JoinChannel(channel config.ChannelInfo) error {
|
||||
|
||||
func (b *Bsshchat) Send(msg config.Message) (string, error) {
|
||||
// ignore delete messages
|
||||
if msg.Event == config.EVENT_MSG_DELETE {
|
||||
if msg.Event == config.EventMsgDelete {
|
||||
return "", nil
|
||||
}
|
||||
b.Log.Debugf("=> Receiving %#v", msg)
|
||||
@ -113,7 +113,7 @@ func stripPrompt(s string) string {
|
||||
return s[pos+3:]
|
||||
}
|
||||
|
||||
func (b *Bsshchat) handleSshChat() error {
|
||||
func (b *Bsshchat) handleSSHChat() error {
|
||||
/*
|
||||
done := b.sshchatKeepAlive()
|
||||
defer close(done)
|
||||
|
@ -60,7 +60,7 @@ func (b *Bsteam) JoinChannel(channel config.ChannelInfo) error {
|
||||
|
||||
func (b *Bsteam) Send(msg config.Message) (string, error) {
|
||||
// ignore delete messages
|
||||
if msg.Event == config.EVENT_MSG_DELETE {
|
||||
if msg.Event == config.EventMsgDelete {
|
||||
return "", nil
|
||||
}
|
||||
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)
|
||||
if msg.Event == config.EVENT_AVATAR_DOWNLOAD {
|
||||
if msg.Event == config.EventAvatarDownload {
|
||||
return b.cacheAvatar(&msg)
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ func (b *Btelegram) Send(msg config.Message) (string, error) {
|
||||
}
|
||||
|
||||
// Delete message
|
||||
if msg.Event == config.EVENT_MSG_DELETE {
|
||||
if msg.Event == config.EventMsgDelete {
|
||||
if msg.ID == "" {
|
||||
return "", nil
|
||||
}
|
||||
@ -268,7 +268,7 @@ func (b *Btelegram) getFileDirectURL(id string) string {
|
||||
// sends a EVENT_AVATAR_DOWNLOAD message to the gateway if successful.
|
||||
// logs an error message if it fails
|
||||
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 {
|
||||
photos, err := b.c.GetUserProfilePhotos(tgbotapi.UserProfilePhotosConfig{UserID: userid, Limit: 1})
|
||||
if err != nil {
|
||||
|
@ -51,7 +51,7 @@ func (b *Bxmpp) Connect() error {
|
||||
time.Sleep(d)
|
||||
b.xc, err = b.createXMPP()
|
||||
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()
|
||||
bf.Reset()
|
||||
}
|
||||
@ -76,7 +76,7 @@ func (b *Bxmpp) JoinChannel(channel config.ChannelInfo) error {
|
||||
|
||||
func (b *Bxmpp) Send(msg config.Message) (string, error) {
|
||||
// ignore delete messages
|
||||
if msg.Event == config.EVENT_MSG_DELETE {
|
||||
if msg.Event == config.EventMsgDelete {
|
||||
return "", nil
|
||||
}
|
||||
b.Log.Debugf("=> Receiving %#v", msg)
|
||||
@ -177,7 +177,7 @@ func (b *Bxmpp) handleXMPP() error {
|
||||
// check if we have an action event
|
||||
rmsg.Text, ok = b.replaceAction(rmsg.Text)
|
||||
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("<= Message is %#v", rmsg)
|
||||
|
@ -52,7 +52,7 @@ func (b *Bzulip) Send(msg config.Message) (string, error) {
|
||||
b.Log.Debugf("=> Receiving %#v", msg)
|
||||
|
||||
// Delete message
|
||||
if msg.Event == config.EVENT_MSG_DELETE {
|
||||
if msg.Event == config.EventMsgDelete {
|
||||
if msg.ID == "" {
|
||||
return "", nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user