make sure it also works for no text following the mention

This commit is contained in:
NikkyAI
2018-09-29 13:18:04 +02:00
parent 0b4826751e
commit d4084d29a1

View File

@@ -407,12 +407,11 @@ func (b *Bdiscord) replaceUserMentions(text string) string {
mention := strings.TrimSpace(m[1:])
var member *discordgo.Member
var err error
var lastSpace int
for {
b.Log.Debugf("Testing mention: '%s'", mention)
member, err = b.getGuildMemberByNick(mention)
if err != nil {
lastSpace = strings.LastIndex(mention, " ")
lastSpace := strings.LastIndex(mention, " ")
if lastSpace == -1 {
break
}
@@ -424,7 +423,7 @@ func (b *Bdiscord) replaceUserMentions(text string) string {
if err != nil {
return m
}
return member.User.Mention() + " " + m[lastSpace+2:]
return strings.Replace(m, "@"+mention, member.User.Mention(), -1)
})
b.Log.Debugf("Message with mention replaced: %s", text)
return text