From 7fc9331e04fcc317e1dbc4747bdd96bc50c8edb8 Mon Sep 17 00:00:00 2001 From: Bruce Marriner Date: Fri, 8 Jan 2016 10:29:01 -0600 Subject: [PATCH] Created message.go to store code related to the Message struct. --- message.go | 26 ++++++++++++++++++++++++++ structs.go | 10 ---------- 2 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 message.go diff --git a/message.go b/message.go new file mode 100644 index 0000000..86e6701 --- /dev/null +++ b/message.go @@ -0,0 +1,26 @@ +// Discordgo - Discord bindings for Go +// Available at https://github.com/bwmarrin/discordgo + +// Copyright 2015-2016 Bruce Marriner . All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file contains code related to the Message struct + +package discordgo + +import ( + "fmt" + "strings" +) + +// ContentWithMentionsReplaced will replace all @ mentions with the +// username of the mention. +func (m *Message) ContentWithMentionsReplaced() string { + content := m.Content + for _, user := range m.Mentions { + content = strings.Replace(content, fmt.Sprintf("<@%s>", user.ID), + fmt.Sprintf("@%s", user.Username), -1) + } + return content +} diff --git a/structs.go b/structs.go index ca6ed5b..7763c6a 100644 --- a/structs.go +++ b/structs.go @@ -116,16 +116,6 @@ type Message struct { ChannelID string `json:"channel_id"` } -// ContentWithMentionsReplaced will replace all @ mentions with the -// username of the mention. -func (m *Message) ContentWithMentionsReplaced() string { - content := m.Content - for _, user := range m.Mentions { - content = strings.Replace(content, fmt.Sprintf("<@%s>", user.ID), fmt.Sprintf("@%s", user.Username), -1) - } - return content -} - // An Attachment stores data for message attachments. type Attachment struct { //TODO figure this out }