Skip to content

Commit

Permalink
fix(slack): check channel name with #
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc committed Aug 18, 2021
1 parent cd3e371 commit c2f53be
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
10 changes: 6 additions & 4 deletions example.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
"forwards": {
"subchannel": {
"token": "",
"forwardChannels": {
"source": "#general_child",
"target": "#general"
}
"forwardChannels": [
{
"source": "#general_child",
"target": "#general"
}
]
}
}
},
Expand Down
20 changes: 14 additions & 6 deletions slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func NewClient(cfg *Config, store storage.Backend, cache storage.CacheBackend) (
botGravatarMail: cfg.BotGravatarMail,
humanGravatarMail: cfg.HumanGravatarMail,
joinChannels: cfg.JoinChannels,
forwards: make(map[string]*ForwardClient),
}
if cfg.Proxy == "" {
c.api = slack.New(cfg.Token)
Expand All @@ -86,10 +87,17 @@ func NewClient(cfg *Config, store storage.Backend, cache storage.CacheBackend) (
},
},
))

for forwardName, forwardConfig := range cfg.Forwards {
fclient := slack.New(forwardConfig.Token, slack.OptionHTTPClient(
&http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(proxyUrl),
},
},
))
c.forwards[forwardName] = &ForwardClient{
api: c.api,
api: fclient,
forwardChannels: make(map[string]string),
}
for _, forwardChannel := range forwardConfig.ForwardChannels {
c.forwards[forwardName].forwardChannels[forwardChannel.Source] = forwardChannel.Target
Expand All @@ -113,7 +121,7 @@ func (c *Client) Run() {
logrus.Errorf("get conversations failed: %s", err)
}
for _, ch := range chs {
if !contains(c.joinChannels, ch.Name) {
if !contains(c.joinChannels, "#"+ch.Name) {
continue
}
_, warnings, _, err := c.api.JoinConversation(ch.ID)
Expand All @@ -138,12 +146,12 @@ func (c *Client) Run() {
logrus.Errorf("get conversations for %s failed: %s", name, err)
}
for _, ch := range chs {
if !containsValue(fc.forwardChannels, ch.Name) {
if !containsValue(fc.forwardChannels, "#"+ch.Name) {
continue
}
_, warnings, _, err := c.api.JoinConversation(ch.ID)
_, warnings, _, err := fc.api.JoinConversation(ch.ID)
if err != nil {
logrus.Warnf("join channel %s failed: %v, warning: %v", ch, err, warnings)
logrus.Warnf("join channel %s in %s failed: %v, warning: %v", ch.Name, name, err, warnings)
continue
}
}
Expand Down

0 comments on commit c2f53be

Please sign in to comment.