summaryrefslogtreecommitdiffstats
path: root/bridge/discord/helpers.go
diff options
context:
space:
mode:
authorQais Patankar <qaisjp@gmail.com>2019-07-15 02:53:09 +0900
committerWim <wim@42.be>2019-07-14 19:53:09 +0200
commit5551f9d56f2270c58738d3d43b3f4ef82507a3b9 (patch)
tree1c39c430d7be90831c101f9039fe347bfad42552 /bridge/discord/helpers.go
parent1fb91c6316f86426d62d38562f957963a522cdd1 (diff)
downloadmatterbridge-msglm-5551f9d56f2270c58738d3d43b3f4ef82507a3b9.tar.gz
matterbridge-msglm-5551f9d56f2270c58738d3d43b3f4ef82507a3b9.tar.bz2
matterbridge-msglm-5551f9d56f2270c58738d3d43b3f4ef82507a3b9.zip
Fix discord channel & category name clash. #860 (#861)
Diffstat (limited to 'bridge/discord/helpers.go')
-rw-r--r--bridge/discord/helpers.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/bridge/discord/helpers.go b/bridge/discord/helpers.go
index e150d192..5bf6931d 100644
--- a/bridge/discord/helpers.go
+++ b/bridge/discord/helpers.go
@@ -88,13 +88,13 @@ var (
func (b *Bdiscord) replaceChannelMentions(text string) string {
replaceChannelMentionFunc := func(match string) string {
- var err error
channelID := match[2 : len(match)-1]
-
channelName := b.getChannelName(channelID)
+
// If we don't have the channel refresh our list.
if channelName == "" {
- b.channels, err = b.c.GuildChannels(b.guildID)
+ chans, err := b.c.GuildChannels(b.guildID)
+ b.channels = filterChannelsByType(chans, discordgo.ChannelTypeGuildCategory, true)
if err != nil {
return "#unknownchannel"
}
@@ -211,3 +211,19 @@ func (b *Bdiscord) webhookExecute(webhookID, token string, wait bool, data *disc
return st, nil
}
+
+func filterChannelsByType(chans []*discordgo.Channel, t discordgo.ChannelType, filterOut bool) []*discordgo.Channel {
+ cs := []*discordgo.Channel{}
+ for _, c := range chans {
+ keep := c.Type == t
+ if filterOut {
+ keep = c.Type != t
+ }
+
+ if keep {
+ cs = append(cs, c)
+ }
+ }
+ return cs
+
+}