Skip to content

Commit

Permalink
Merge pull request #7 from pipipear/patch-1
Browse files Browse the repository at this point in the history
Formats notifications more similarly to Discord
  • Loading branch information
efskap authored Dec 17, 2021
2 parents ded2c61 + b496930 commit dcf0668
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,12 @@ func onMessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {

func formatNotification(s *discordgo.Session, m *discordgo.Message) (title, body string) {
authorName := m.Author.String()
if guildMember, err := s.GuildMember(m.GuildID, m.Author.ID); err == nil && guildMember.Nick != "" {
authorName = guildMember.Nick
if guildMember, err := s.GuildMember(m.GuildID, m.Author.ID); err == nil {
if guildMember.Nick != "" {
authorName = guildMember.Nick
} else {
authorName = guildMember.User.Username
}
}
locationText := "you"
if channel, err := s.Channel(m.ChannelID); err == nil {
Expand All @@ -348,7 +352,7 @@ func formatNotification(s *discordgo.Session, m *discordgo.Message) (title, body
locationText = channel.Name
}
}
title = fmt.Sprintf("%s | %s", authorName, locationText)
title = fmt.Sprintf("%s (%s)", authorName, locationText)

var err error
body, err = m.ContentWithMoreMentionsReplaced(s)
Expand Down

0 comments on commit dcf0668

Please sign in to comment.