forked from lug/matterbridge
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35736bbbfe | ||
|
|
85fa4df39d | ||
|
|
859b084814 | ||
|
|
315a038e00 | ||
|
|
b3999b6e71 | ||
|
|
6bef998bb3 | ||
|
|
919a0309ad | ||
|
|
95bcca7335 | ||
|
|
c78bd24c61 | ||
|
|
d2cfd235ef | ||
|
|
f8bf7f8d76 | ||
|
|
8432330cb2 | ||
|
|
02577a2b5c | ||
|
|
73501739d5 | ||
|
|
ba674af5d4 | ||
|
|
3c85d937c6 | ||
|
|
c6fd65d1d7 | ||
|
|
0795906533 | ||
|
|
a2b45bc799 | ||
|
|
757657f29c |
@@ -76,9 +76,10 @@ func (b *Bdiscord) Connect() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
serverName := strings.Replace(b.GetString("Server"), "ID:", "", -1)
|
||||||
b.Nick = userinfo.Username
|
b.Nick = userinfo.Username
|
||||||
for _, guild := range guilds {
|
for _, guild := range guilds {
|
||||||
if guild.Name == b.GetString("Server") {
|
if guild.Name == serverName || guild.ID == serverName {
|
||||||
b.Channels, err = b.c.GuildChannels(guild.ID)
|
b.Channels, err = b.c.GuildChannels(guild.ID)
|
||||||
b.guildID = guild.ID
|
b.guildID = guild.ID
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -164,6 +165,10 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) {
|
|||||||
|
|
||||||
msg.Text = helper.ClipMessage(msg.Text, MessageLength)
|
msg.Text = helper.ClipMessage(msg.Text, MessageLength)
|
||||||
msg.Text = b.replaceUserMentions(msg.Text)
|
msg.Text = b.replaceUserMentions(msg.Text)
|
||||||
|
// discord username must be [0..32] max
|
||||||
|
if len(msg.Username) > 32 {
|
||||||
|
msg.Username = msg.Username[0:32]
|
||||||
|
}
|
||||||
err := b.c.WebhookExecute(
|
err := b.c.WebhookExecute(
|
||||||
wID,
|
wID,
|
||||||
wToken,
|
wToken,
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ type Birc struct {
|
|||||||
i *girc.Client
|
i *girc.Client
|
||||||
Nick string
|
Nick string
|
||||||
names map[string][]string
|
names map[string][]string
|
||||||
connected chan struct{}
|
connected chan error
|
||||||
Local chan config.Message // local queue for flood control
|
Local chan config.Message // local queue for flood control
|
||||||
FirstConnection bool
|
FirstConnection, authDone bool
|
||||||
MessageDelay, MessageQueue, MessageLength int
|
MessageDelay, MessageQueue, MessageLength int
|
||||||
|
|
||||||
*bridge.Config
|
*bridge.Config
|
||||||
@@ -44,7 +44,7 @@ func New(cfg *bridge.Config) bridge.Bridger {
|
|||||||
b.Config = cfg
|
b.Config = cfg
|
||||||
b.Nick = b.GetString("Nick")
|
b.Nick = b.GetString("Nick")
|
||||||
b.names = make(map[string][]string)
|
b.names = make(map[string][]string)
|
||||||
b.connected = make(chan struct{})
|
b.connected = make(chan error)
|
||||||
if b.GetInt("MessageDelay") == 0 {
|
if b.GetInt("MessageDelay") == 0 {
|
||||||
b.MessageDelay = 1300
|
b.MessageDelay = 1300
|
||||||
} else {
|
} else {
|
||||||
@@ -116,14 +116,18 @@ func (b *Birc) Connect() error {
|
|||||||
i.Handlers.Add(girc.RPL_WELCOME, b.handleNewConnection)
|
i.Handlers.Add(girc.RPL_WELCOME, b.handleNewConnection)
|
||||||
i.Handlers.Add(girc.RPL_ENDOFMOTD, b.handleOtherAuth)
|
i.Handlers.Add(girc.RPL_ENDOFMOTD, b.handleOtherAuth)
|
||||||
i.Handlers.Add(girc.ALL_EVENTS, b.handleOther)
|
i.Handlers.Add(girc.ALL_EVENTS, b.handleOther)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
if err := i.Connect(); err != nil {
|
if err := i.Connect(); err != nil {
|
||||||
b.Log.Errorf("disconnect: error: %s", err)
|
b.Log.Errorf("disconnect: error: %s", err)
|
||||||
|
if b.FirstConnection {
|
||||||
|
b.connected <- err
|
||||||
|
return
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
b.Log.Info("disconnect: client requested quit")
|
b.Log.Info("disconnect: client requested quit")
|
||||||
}
|
}
|
||||||
|
|
||||||
b.Log.Info("reconnecting in 30 seconds...")
|
b.Log.Info("reconnecting in 30 seconds...")
|
||||||
time.Sleep(30 * time.Second)
|
time.Sleep(30 * time.Second)
|
||||||
i.Handlers.Clear(girc.RPL_WELCOME)
|
i.Handlers.Clear(girc.RPL_WELCOME)
|
||||||
@@ -135,13 +139,12 @@ func (b *Birc) Connect() error {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
b.i = i
|
b.i = i
|
||||||
select {
|
err = <-b.connected
|
||||||
case <-b.connected:
|
if err != nil {
|
||||||
b.Log.Info("Connection succeeded")
|
return fmt.Errorf("connection failed %s", err)
|
||||||
case <-time.After(time.Second * 30):
|
|
||||||
return fmt.Errorf("connection timed out")
|
|
||||||
}
|
}
|
||||||
//i.Debug = false
|
b.Log.Info("Connection succeeded")
|
||||||
|
b.FirstConnection = false
|
||||||
if b.GetInt("DebugLevel") == 0 {
|
if b.GetInt("DebugLevel") == 0 {
|
||||||
i.Handlers.Clear(girc.ALL_EVENTS)
|
i.Handlers.Clear(girc.ALL_EVENTS)
|
||||||
}
|
}
|
||||||
@@ -156,6 +159,13 @@ func (b *Birc) Disconnect() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Birc) JoinChannel(channel config.ChannelInfo) error {
|
func (b *Birc) JoinChannel(channel config.ChannelInfo) error {
|
||||||
|
// need to check if we have nickserv auth done before joining channels
|
||||||
|
for {
|
||||||
|
if b.authDone {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
}
|
||||||
if channel.Options.Key != "" {
|
if channel.Options.Key != "" {
|
||||||
b.Log.Debugf("using key %s for channel %s", channel.Options.Key, channel.Name)
|
b.Log.Debugf("using key %s for channel %s", channel.Options.Key, channel.Name)
|
||||||
b.i.Cmd.JoinKey(channel.Name, channel.Options.Key)
|
b.i.Cmd.JoinKey(channel.Name, channel.Options.Key)
|
||||||
@@ -287,7 +297,6 @@ func (b *Birc) handleNewConnection(client *girc.Client, event girc.Event) {
|
|||||||
i := b.i
|
i := b.i
|
||||||
b.Nick = event.Params[0]
|
b.Nick = event.Params[0]
|
||||||
|
|
||||||
i.Handlers.Add(girc.RPL_ENDOFMOTD, b.handleOtherAuth)
|
|
||||||
i.Handlers.Add("PRIVMSG", b.handlePrivMsg)
|
i.Handlers.Add("PRIVMSG", b.handlePrivMsg)
|
||||||
i.Handlers.Add("CTCP_ACTION", b.handlePrivMsg)
|
i.Handlers.Add("CTCP_ACTION", b.handlePrivMsg)
|
||||||
i.Handlers.Add(girc.RPL_TOPICWHOTIME, b.handleTopicWhoTime)
|
i.Handlers.Add(girc.RPL_TOPICWHOTIME, b.handleTopicWhoTime)
|
||||||
@@ -296,8 +305,6 @@ func (b *Birc) handleNewConnection(client *girc.Client, event girc.Event) {
|
|||||||
i.Handlers.Add("PART", b.handleJoinPart)
|
i.Handlers.Add("PART", b.handleJoinPart)
|
||||||
i.Handlers.Add("QUIT", b.handleJoinPart)
|
i.Handlers.Add("QUIT", b.handleJoinPart)
|
||||||
i.Handlers.Add("KICK", b.handleJoinPart)
|
i.Handlers.Add("KICK", b.handleJoinPart)
|
||||||
// we are now fully connected
|
|
||||||
b.connected <- struct{}{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Birc) handleJoinPart(client *girc.Client, event girc.Event) {
|
func (b *Birc) handleJoinPart(client *girc.Client, event girc.Event) {
|
||||||
@@ -334,8 +341,7 @@ func (b *Birc) handleJoinPart(client *girc.Client, event girc.Event) {
|
|||||||
|
|
||||||
func (b *Birc) handleNotice(client *girc.Client, event girc.Event) {
|
func (b *Birc) handleNotice(client *girc.Client, event girc.Event) {
|
||||||
if strings.Contains(event.String(), "This nickname is registered") && event.Source.Name == b.GetString("NickServNick") {
|
if strings.Contains(event.String(), "This nickname is registered") && event.Source.Name == b.GetString("NickServNick") {
|
||||||
b.Log.Debugf("Sending identify to nickserv %s", b.GetString("NickServNick"))
|
b.handleNickServ()
|
||||||
b.i.Cmd.Message(b.GetString("NickServNick"), "IDENTIFY "+b.GetString("NickServPassword"))
|
|
||||||
} else {
|
} else {
|
||||||
b.handlePrivMsg(client, event)
|
b.handlePrivMsg(client, event)
|
||||||
}
|
}
|
||||||
@@ -357,10 +363,9 @@ func (b *Birc) handleOther(client *girc.Client, event girc.Event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Birc) handleOtherAuth(client *girc.Client, event girc.Event) {
|
func (b *Birc) handleOtherAuth(client *girc.Client, event girc.Event) {
|
||||||
if strings.EqualFold(b.GetString("NickServNick"), "Q@CServe.quakenet.org") {
|
b.handleNickServ()
|
||||||
b.Log.Debugf("Authenticating %s against %s", b.GetString("NickServUsername"), b.GetString("NickServNick"))
|
// we are now fully connected
|
||||||
b.i.Cmd.Message(b.GetString("NickServNick"), "AUTH "+b.GetString("NickServUsername")+" "+b.GetString("NickServPassword"))
|
b.connected <- nil
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Birc) skipPrivMsg(event girc.Event) bool {
|
func (b *Birc) skipPrivMsg(event girc.Event) bool {
|
||||||
@@ -464,3 +469,17 @@ func (b *Birc) storeNames(client *girc.Client, event girc.Event) {
|
|||||||
func (b *Birc) formatnicks(nicks []string) string {
|
func (b *Birc) formatnicks(nicks []string) string {
|
||||||
return strings.Join(nicks, ", ") + " currently on IRC"
|
return strings.Join(nicks, ", ") + " currently on IRC"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Birc) handleNickServ() {
|
||||||
|
if !b.GetBool("UseSASL") && b.GetString("NickServNick") != "" && b.GetString("NickServPassword") != "" {
|
||||||
|
b.Log.Debugf("Sending identify to nickserv %s", b.GetString("NickServNick"))
|
||||||
|
b.i.Cmd.Message(b.GetString("NickServNick"), "IDENTIFY "+b.GetString("NickServPassword"))
|
||||||
|
}
|
||||||
|
if strings.EqualFold(b.GetString("NickServNick"), "Q@CServe.quakenet.org") {
|
||||||
|
b.Log.Debugf("Authenticating %s against %s", b.GetString("NickServUsername"), b.GetString("NickServNick"))
|
||||||
|
b.i.Cmd.Message(b.GetString("NickServNick"), "AUTH "+b.GetString("NickServUsername")+" "+b.GetString("NickServPassword"))
|
||||||
|
}
|
||||||
|
// give nickserv some slack
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
|
b.authDone = true
|
||||||
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ func (b *Bslack) handleSlackClient(messages chan *config.Message) {
|
|||||||
// When we join a channel we update the full list of users as
|
// When we join a channel we update the full list of users as
|
||||||
// well as the information for the channel that we joined as this
|
// well as the information for the channel that we joined as this
|
||||||
// should now tell that we are a member of it.
|
// should now tell that we are a member of it.
|
||||||
b.populateUsers()
|
b.populateUsers(false)
|
||||||
|
|
||||||
b.channelsMutex.Lock()
|
b.channelsMutex.Lock()
|
||||||
b.channelsByID[ev.Channel.ID] = &ev.Channel
|
b.channelsByID[ev.Channel.ID] = &ev.Channel
|
||||||
@@ -83,13 +83,16 @@ func (b *Bslack) handleSlackClient(messages chan *config.Message) {
|
|||||||
b.channelsMutex.Unlock()
|
b.channelsMutex.Unlock()
|
||||||
case *slack.ConnectedEvent:
|
case *slack.ConnectedEvent:
|
||||||
b.si = ev.Info
|
b.si = ev.Info
|
||||||
b.populateChannels()
|
b.populateChannels(true)
|
||||||
b.populateUsers()
|
b.populateUsers(true)
|
||||||
case *slack.InvalidAuthEvent:
|
case *slack.InvalidAuthEvent:
|
||||||
b.Log.Fatalf("Invalid Token %#v", ev)
|
b.Log.Fatalf("Invalid Token %#v", ev)
|
||||||
case *slack.ConnectionErrorEvent:
|
case *slack.ConnectionErrorEvent:
|
||||||
b.Log.Errorf("Connection failed %#v %#v", ev.Error(), ev.ErrorObj)
|
b.Log.Errorf("Connection failed %#v %#v", ev.Error(), ev.ErrorObj)
|
||||||
|
case *slack.MemberJoinedChannelEvent:
|
||||||
|
b.populateUser(ev.User)
|
||||||
default:
|
default:
|
||||||
|
b.Log.Debugf("Unhandled incoming event: %T", ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,7 +196,7 @@ func (b *Bslack) handleMessageEvent(ev *slack.MessageEvent) (*config.Message, er
|
|||||||
func (b *Bslack) handleStatusEvent(ev *slack.MessageEvent, rmsg *config.Message) bool {
|
func (b *Bslack) handleStatusEvent(ev *slack.MessageEvent, rmsg *config.Message) bool {
|
||||||
switch ev.SubType {
|
switch ev.SubType {
|
||||||
case sChannelJoined, sMemberJoined:
|
case sChannelJoined, sMemberJoined:
|
||||||
b.populateUsers()
|
b.populateUsers(false)
|
||||||
// There's no further processing needed on channel events
|
// There's no further processing needed on channel events
|
||||||
// so we return 'true'.
|
// so we return 'true'.
|
||||||
return true
|
return true
|
||||||
@@ -202,6 +205,13 @@ func (b *Bslack) handleStatusEvent(ev *slack.MessageEvent, rmsg *config.Message)
|
|||||||
rmsg.Event = config.EventJoinLeave
|
rmsg.Event = config.EventJoinLeave
|
||||||
case sChannelTopic, sChannelPurpose:
|
case sChannelTopic, sChannelPurpose:
|
||||||
rmsg.Event = config.EventTopicChange
|
rmsg.Event = config.EventTopicChange
|
||||||
|
case sMessageChanged:
|
||||||
|
rmsg.Text = ev.SubMessage.Text
|
||||||
|
// handle deleted thread starting messages
|
||||||
|
if ev.SubMessage.Text == "This message was deleted." {
|
||||||
|
rmsg.Event = config.EventMsgDelete
|
||||||
|
return true
|
||||||
|
}
|
||||||
case sMessageDeleted:
|
case sMessageDeleted:
|
||||||
rmsg.Text = config.EventMsgDelete
|
rmsg.Text = config.EventMsgDelete
|
||||||
rmsg.Event = config.EventMsgDelete
|
rmsg.Event = config.EventMsgDelete
|
||||||
|
|||||||
@@ -65,15 +65,38 @@ func (b *Bslack) getChannelByID(ID string) (*slack.Channel, error) {
|
|||||||
|
|
||||||
const minimumRefreshInterval = 10 * time.Second
|
const minimumRefreshInterval = 10 * time.Second
|
||||||
|
|
||||||
func (b *Bslack) populateUsers() {
|
func (b *Bslack) populateUser(userID string) {
|
||||||
|
b.usersMutex.RLock()
|
||||||
|
_, exists := b.users[userID]
|
||||||
|
b.usersMutex.RUnlock()
|
||||||
|
if exists {
|
||||||
|
// already in cache
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user, err := b.sc.GetUserInfo(userID)
|
||||||
|
if err != nil {
|
||||||
|
b.Log.Debugf("GetUserInfo failed for %v: %v", userID, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
b.usersMutex.Lock()
|
||||||
|
b.users[userID] = user
|
||||||
|
b.usersMutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bslack) populateUsers(wait bool) {
|
||||||
b.refreshMutex.Lock()
|
b.refreshMutex.Lock()
|
||||||
if time.Now().Before(b.earliestUserRefresh) || b.refreshInProgress {
|
if !wait && (time.Now().Before(b.earliestUserRefresh) || b.refreshInProgress) {
|
||||||
b.Log.Debugf("Not refreshing user list as it was done less than %v ago.",
|
b.Log.Debugf("Not refreshing user list as it was done less than %v ago.",
|
||||||
minimumRefreshInterval)
|
minimumRefreshInterval)
|
||||||
b.refreshMutex.Unlock()
|
b.refreshMutex.Unlock()
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
for b.refreshInProgress {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
}
|
||||||
b.refreshInProgress = true
|
b.refreshInProgress = true
|
||||||
b.refreshMutex.Unlock()
|
b.refreshMutex.Unlock()
|
||||||
|
|
||||||
@@ -109,14 +132,17 @@ func (b *Bslack) populateUsers() {
|
|||||||
b.refreshInProgress = false
|
b.refreshInProgress = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bslack) populateChannels() {
|
func (b *Bslack) populateChannels(wait bool) {
|
||||||
b.refreshMutex.Lock()
|
b.refreshMutex.Lock()
|
||||||
if time.Now().Before(b.earliestChannelRefresh) || b.refreshInProgress {
|
if !wait && (time.Now().Before(b.earliestChannelRefresh) || b.refreshInProgress) {
|
||||||
b.Log.Debugf("Not refreshing channel list as it was done less than %v seconds ago.",
|
b.Log.Debugf("Not refreshing channel list as it was done less than %v seconds ago.",
|
||||||
minimumRefreshInterval)
|
minimumRefreshInterval)
|
||||||
b.refreshMutex.Unlock()
|
b.refreshMutex.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
for b.refreshInProgress {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
}
|
||||||
b.refreshInProgress = true
|
b.refreshInProgress = true
|
||||||
b.refreshMutex.Unlock()
|
b.refreshMutex.Unlock()
|
||||||
|
|
||||||
@@ -251,7 +277,7 @@ func (b *Bslack) populateMessageWithBotInfo(ev *slack.MessageEvent, rmsg *config
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if bot.Name != "" && bot.Name != "Slack API Tester" {
|
if bot.Name != "" {
|
||||||
rmsg.Username = bot.Name
|
rmsg.Username = bot.Name
|
||||||
if ev.Username != "" {
|
if ev.Username != "" {
|
||||||
rmsg.Username = ev.Username
|
rmsg.Username = ev.Username
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ const (
|
|||||||
sChannelLeave = "channel_leave"
|
sChannelLeave = "channel_leave"
|
||||||
sChannelJoined = "channel_joined"
|
sChannelJoined = "channel_joined"
|
||||||
sMemberJoined = "member_joined_channel"
|
sMemberJoined = "member_joined_channel"
|
||||||
|
sMessageChanged = "message_changed"
|
||||||
sMessageDeleted = "message_deleted"
|
sMessageDeleted = "message_deleted"
|
||||||
sSlackAttachment = "slack_attachment"
|
sSlackAttachment = "slack_attachment"
|
||||||
sPinnedItem = "pinned_item"
|
sPinnedItem = "pinned_item"
|
||||||
@@ -76,14 +77,9 @@ func New(cfg *bridge.Config) bridge.Bridger {
|
|||||||
// Print a deprecation warning for legacy non-bot tokens (#527).
|
// Print a deprecation warning for legacy non-bot tokens (#527).
|
||||||
token := cfg.GetString(tokenConfig)
|
token := cfg.GetString(tokenConfig)
|
||||||
if token != "" && !strings.HasPrefix(token, "xoxb") {
|
if token != "" && !strings.HasPrefix(token, "xoxb") {
|
||||||
cfg.Log.Error("Non-bot token detected. It is STRONGLY recommended to use a proper bot-token instead.")
|
cfg.Log.Warn("Non-bot token detected. It is STRONGLY recommended to use a proper bot-token instead.")
|
||||||
cfg.Log.Error("Legacy tokens may be deprecated by Slack at short notice. See the Matterbridge GitHub wiki for a migration guide.")
|
cfg.Log.Warn("Legacy tokens may be deprecated by Slack at short notice. See the Matterbridge GitHub wiki for a migration guide.")
|
||||||
cfg.Log.Error("See https://github.com/42wim/matterbridge/wiki/Slack-bot-setup")
|
cfg.Log.Warn("See https://github.com/42wim/matterbridge/wiki/Slack-bot-setup")
|
||||||
cfg.Log.Error("")
|
|
||||||
cfg.Log.Error("To continue using a legacy token please move your configuration to a \"slack-legacy\" bridge instead.")
|
|
||||||
cfg.Log.Error("See https://github.com/42wim/matterbridge/wiki/Section-Slack-(basic)#legacy-configuration)")
|
|
||||||
cfg.Log.Error("Delaying start of bridge by 30 seconds. Future Matterbridge release will fail here unless you use a \"slack-legacy\" bridge.")
|
|
||||||
time.Sleep(30 * time.Second)
|
|
||||||
return NewLegacy(cfg)
|
return NewLegacy(cfg)
|
||||||
}
|
}
|
||||||
return newBridge(cfg)
|
return newBridge(cfg)
|
||||||
@@ -164,7 +160,7 @@ func (b *Bslack) JoinChannel(channel config.ChannelInfo) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
b.populateChannels()
|
b.populateChannels(false)
|
||||||
|
|
||||||
channelInfo, err := b.getChannel(channel.Name)
|
channelInfo, err := b.getChannel(channel.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -356,6 +352,10 @@ func (b *Bslack) editMessage(msg *config.Message, channelInfo *slack.Channel) (b
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bslack) postMessage(msg *config.Message, messageParameters *slack.PostMessageParameters, channelInfo *slack.Channel) (string, error) {
|
func (b *Bslack) postMessage(msg *config.Message, messageParameters *slack.PostMessageParameters, channelInfo *slack.Channel) (string, error) {
|
||||||
|
// don't post empty messages
|
||||||
|
if msg.Text == "" {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
_, id, err := b.rtm.PostMessage(channelInfo.ID, msg.Text, *messageParameters)
|
_, id, err := b.rtm.PostMessage(channelInfo.ID, msg.Text, *messageParameters)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -385,11 +385,16 @@ func (b *Bslack) uploadFile(msg *config.Message, channelID string) {
|
|||||||
ts := time.Now()
|
ts := time.Now()
|
||||||
b.Log.Debugf("Adding file %s to cache at %s with timestamp", fi.Name, ts.String())
|
b.Log.Debugf("Adding file %s to cache at %s with timestamp", fi.Name, ts.String())
|
||||||
b.cache.Add("filename"+fi.Name, ts)
|
b.cache.Add("filename"+fi.Name, ts)
|
||||||
|
initialComment := fmt.Sprintf("File from %s", msg.Username)
|
||||||
|
if fi.Comment != "" {
|
||||||
|
initialComment += fmt.Sprintf("with comment: %s", fi.Comment)
|
||||||
|
}
|
||||||
res, err := b.sc.UploadFile(slack.FileUploadParameters{
|
res, err := b.sc.UploadFile(slack.FileUploadParameters{
|
||||||
Reader: bytes.NewReader(*fi.Data),
|
Reader: bytes.NewReader(*fi.Data),
|
||||||
Filename: fi.Name,
|
Filename: fi.Name,
|
||||||
Channels: []string{channelID},
|
Channels: []string{channelID},
|
||||||
InitialComment: fi.Comment,
|
InitialComment: initialComment,
|
||||||
|
ThreadTimestamp: msg.ParentID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Log.Errorf("uploadfile %#v", err)
|
b.Log.Errorf("uploadfile %#v", err)
|
||||||
|
|||||||
23
changelog.md
23
changelog.md
@@ -1,3 +1,26 @@
|
|||||||
|
# v1.12.3
|
||||||
|
## Bugfix
|
||||||
|
* slack: Fix bot (legacy token) messages not being send. Closes #571
|
||||||
|
* slack: Populate user on channel join (slack) (#644)
|
||||||
|
* slack: Add wait option for populateUsers/Channels (slack) Fixes #579 (#653)
|
||||||
|
|
||||||
|
# v1.12.2
|
||||||
|
|
||||||
|
## Bugfix
|
||||||
|
* irc: Fix multiple channel join regression. Closes #639
|
||||||
|
* slack: Make slack-legacy change less restrictive (#626)
|
||||||
|
|
||||||
|
# v1.12.1
|
||||||
|
|
||||||
|
## Bugfix
|
||||||
|
* discord: fix regression on server ID connection #619 #617
|
||||||
|
* discord: Limit discord username via webhook to 32 chars
|
||||||
|
* slack: Make sure threaded files stay in thread (slack). Fixes #590
|
||||||
|
* slack: Do not post empty messages (slack). Fixes #574
|
||||||
|
* slack: Handle deleted/edited thread starting messages (slack). Fixes #600 (#605)
|
||||||
|
* irc: Rework connection logic (irc)
|
||||||
|
* irc: Fix Nickserv logic (irc) #602
|
||||||
|
|
||||||
# v1.12.0
|
# v1.12.0
|
||||||
|
|
||||||
## Breaking changes
|
## Breaking changes
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
version = "1.12.0"
|
version = "1.12.3"
|
||||||
githash string
|
githash string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1389,7 +1389,7 @@ enable=true
|
|||||||
|
|
||||||
#OPTIONAL - webhookurl only works for discord (it needs a different URL for each cahnnel)
|
#OPTIONAL - webhookurl only works for discord (it needs a different URL for each cahnnel)
|
||||||
[gateway.inout.options]
|
[gateway.inout.options]
|
||||||
webhookurl=""https://discordapp.com/api/webhooks/123456789123456789/C9WPqExYWONPDZabcdef-def1434FGFjstasJX9pYht73y"
|
webhookurl="https://discordapp.com/api/webhooks/123456789123456789/C9WPqExYWONPDZabcdef-def1434FGFjstasJX9pYht73y"
|
||||||
|
|
||||||
#API example
|
#API example
|
||||||
#[[gateway.inout]]
|
#[[gateway.inout]]
|
||||||
|
|||||||
Reference in New Issue
Block a user