From 5551f9d56f2270c58738d3d43b3f4ef82507a3b9 Mon Sep 17 00:00:00 2001 From: Qais Patankar Date: Mon, 15 Jul 2019 02:53:09 +0900 Subject: Fix discord channel & category name clash. #860 (#861) --- bridge/discord/discord.go | 8 +++++--- bridge/discord/helpers.go | 22 +++++++++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) (limited to 'bridge/discord') diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index 4c1c0f46..66c8134c 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -95,12 +95,14 @@ func (b *Bdiscord) Connect() error { b.channelsMutex.Lock() for _, guild := range guilds { if guild.Name == serverName || guild.ID == serverName { - b.channels, err = b.c.GuildChannels(guild.ID) - b.guildID = guild.ID - guildFound = true + var chans []*discordgo.Channel + chans, err = b.c.GuildChannels(guild.ID) if err != nil { break } + b.channels = filterChannelsByType(chans, discordgo.ChannelTypeGuildText, false) + b.guildID = guild.ID + guildFound = true } } b.channelsMutex.Unlock() 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 + +} -- cgit v1.2.3