Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentWithMentionReplaced on roles and nicks (Fixes #208) #375

Merged
merged 11 commits into from
Jun 13, 2017
Prev Previous commit
Next Next commit
Compatibility
  • Loading branch information
LEGOlord208 authored and LEGOlord208 committed May 4, 2017
commit f0d4ea1ff10f4e3056658ac84916b94f4c5b1590
17 changes: 13 additions & 4 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,22 @@ type MessageReactions struct {

// ContentWithMentionsReplaced will replace all @<id> mentions with the
// username of the mention.
func (m *Message) ContentWithMentionsReplaced(s *Session) (content string, err error) {
func (m *Message) ContentWithMentionsReplaced() (content string) {
content = m.Content

for _, user := range m.Mentions {
content = regexp.MustCompile("<@!?"+regexp.QuoteMeta(user.ID)+">").ReplaceAllString(content, "@"+user.Username)
}
return
}

// ContentWithMoreMentionsReplaced will replace all @<id> mentions with the
// username of the mention, but also role IDs and more.
func (m *Message) ContentWithMoreMentionsReplaced(s *Session) (content string, err error) {
content = m.Content

if !s.StateEnabled {
for _, user := range m.Mentions {
content = regexp.MustCompile("<@!?"+regexp.QuoteMeta(user.ID)+">").ReplaceAllString(content, "@"+user.Username)
}
content = m.ContentWithMentionsReplaced()
return
}

Expand Down