mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-28 21:52:08 -08:00
Replace long ids in channel metions (discord). Fixes #174
This commit is contained in:
parent
dd3c572256
commit
3812693111
@ -140,6 +140,7 @@ func (b *bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
|
|||||||
m.Message.Content = b.replaceRoleMentions(m.Message.Content)
|
m.Message.Content = b.replaceRoleMentions(m.Message.Content)
|
||||||
}
|
}
|
||||||
m.Message.Content = b.stripCustomoji(m.Message.Content)
|
m.Message.Content = b.stripCustomoji(m.Message.Content)
|
||||||
|
m.Message.Content = b.replaceChannelMentions(m.Message.Content)
|
||||||
b.Remote <- config.Message{Username: username, Text: m.ContentWithMentionsReplaced(), Channel: channelName,
|
b.Remote <- config.Message{Username: username, Text: m.ContentWithMentionsReplaced(), Channel: channelName,
|
||||||
Account: b.Account, Avatar: "https://cdn.discordapp.com/avatars/" + m.Author.ID + "/" + m.Author.Avatar + ".jpg"}
|
Account: b.Account, Avatar: "https://cdn.discordapp.com/avatars/" + m.Author.ID + "/" + m.Author.Avatar + ".jpg"}
|
||||||
}
|
}
|
||||||
@ -213,6 +214,25 @@ func (b *bdiscord) replaceRoleMentions(text string) string {
|
|||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *bdiscord) replaceChannelMentions(text string) string {
|
||||||
|
var err error
|
||||||
|
re := regexp.MustCompile("<#[0-9]+>")
|
||||||
|
text = re.ReplaceAllStringFunc(text, func(m string) string {
|
||||||
|
channel := b.getChannelName(m[2 : len(m)-1])
|
||||||
|
// if at first don't succeed, try again
|
||||||
|
if channel == "" {
|
||||||
|
b.Channels, err = b.c.GuildChannels(b.guildID)
|
||||||
|
if err != nil {
|
||||||
|
return "#unknownchannel"
|
||||||
|
}
|
||||||
|
channel = b.getChannelName(m[2 : len(m)-1])
|
||||||
|
return channel
|
||||||
|
}
|
||||||
|
return channel
|
||||||
|
})
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|
||||||
func (b *bdiscord) stripCustomoji(text string) string {
|
func (b *bdiscord) stripCustomoji(text string) string {
|
||||||
// <:doge:302803592035958784>
|
// <:doge:302803592035958784>
|
||||||
re := regexp.MustCompile("<(:.*?:)[0-9]+>")
|
re := regexp.MustCompile("<(:.*?:)[0-9]+>")
|
||||||
|
Loading…
Reference in New Issue
Block a user