mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-25 04:02:03 -08:00
parent
1fb91c6316
commit
5551f9d56f
@ -95,12 +95,14 @@ func (b *Bdiscord) Connect() error {
|
|||||||
b.channelsMutex.Lock()
|
b.channelsMutex.Lock()
|
||||||
for _, guild := range guilds {
|
for _, guild := range guilds {
|
||||||
if guild.Name == serverName || guild.ID == serverName {
|
if guild.Name == serverName || guild.ID == serverName {
|
||||||
b.channels, err = b.c.GuildChannels(guild.ID)
|
var chans []*discordgo.Channel
|
||||||
b.guildID = guild.ID
|
chans, err = b.c.GuildChannels(guild.ID)
|
||||||
guildFound = true
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
b.channels = filterChannelsByType(chans, discordgo.ChannelTypeGuildText, false)
|
||||||
|
b.guildID = guild.ID
|
||||||
|
guildFound = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.channelsMutex.Unlock()
|
b.channelsMutex.Unlock()
|
||||||
|
@ -88,13 +88,13 @@ var (
|
|||||||
|
|
||||||
func (b *Bdiscord) replaceChannelMentions(text string) string {
|
func (b *Bdiscord) replaceChannelMentions(text string) string {
|
||||||
replaceChannelMentionFunc := func(match string) string {
|
replaceChannelMentionFunc := func(match string) string {
|
||||||
var err error
|
|
||||||
channelID := match[2 : len(match)-1]
|
channelID := match[2 : len(match)-1]
|
||||||
|
|
||||||
channelName := b.getChannelName(channelID)
|
channelName := b.getChannelName(channelID)
|
||||||
|
|
||||||
// If we don't have the channel refresh our list.
|
// If we don't have the channel refresh our list.
|
||||||
if channelName == "" {
|
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 {
|
if err != nil {
|
||||||
return "#unknownchannel"
|
return "#unknownchannel"
|
||||||
}
|
}
|
||||||
@ -211,3 +211,19 @@ func (b *Bdiscord) webhookExecute(webhookID, token string, wait bool, data *disc
|
|||||||
|
|
||||||
return st, nil
|
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
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user