Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
replace MessageSender interfaces with Session
Browse files Browse the repository at this point in the history
  • Loading branch information
andersfylling committed Oct 24, 2020
1 parent 5a180c2 commit 304919b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
8 changes: 4 additions & 4 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (c *Channel) CopyOverTo(other interface{}) (err error) {
}

// SendMsgString same as SendMsg, however this only takes the message content (string) as a argument for the message
func (c *Channel) SendMsgString(ctx context.Context, client MessageSender, content string) (msg *Message, err error) {
func (c *Channel) SendMsgString(ctx context.Context, s Session, content string) (msg *Message, err error) {
if c.ID.IsZero() {
err = newErrorMissingSnowflake("snowflake ID not set for channel")
return
Expand All @@ -260,12 +260,12 @@ func (c *Channel) SendMsgString(ctx context.Context, client MessageSender, conte
Content: content,
}

msg, err = client.CreateMessage(ctx, c.ID, params)
msg, err = s.Channel(c.ID).WithContext(ctx).CreateMessage(params)
return
}

// SendMsg sends a message to a channel
func (c *Channel) SendMsg(ctx context.Context, client MessageSender, message *Message) (msg *Message, err error) {
func (c *Channel) SendMsg(ctx context.Context, s Session, message *Message) (msg *Message, err error) {
if c.ID.IsZero() {
err = newErrorMissingSnowflake("snowflake ID not set for channel")
return
Expand All @@ -286,7 +286,7 @@ func (c *Channel) SendMsg(ctx context.Context, client MessageSender, message *Me
params.Embed = message.Embeds[0]
}

msg, err = client.CreateMessage(ctx, c.ID, params)
msg, err = s.Channel(c.ID).WithContext(ctx).CreateMessage(params)
return
}

Expand Down
9 changes: 2 additions & 7 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,8 @@ func (m *Message) CopyOverTo(other interface{}) (err error) {
return
}

// MessageSender is an interface which only holds the method needed for creating a channel message
type MessageSender interface {
CreateMessage(ctx context.Context, channelID Snowflake, params *CreateMessageParams, flags ...Flag) (ret *Message, err error)
}

// Send sends this message to discord.
func (m *Message) Send(ctx context.Context, client MessageSender, flags ...Flag) (msg *Message, err error) {
func (m *Message) Send(ctx context.Context, s Session, flags ...Flag) (msg *Message, err error) {
nonce := fmt.Sprint(m.Nonce)
if len(nonce) > 25 {
return nil, errors.New("nonce can not be more than 25 characters")
Expand All @@ -280,7 +275,7 @@ func (m *Message) Send(ctx context.Context, client MessageSender, flags ...Flag)
}
channelID := m.ChannelID

msg, err = client.CreateMessage(ctx, channelID, params, flags...)
msg, err = s.Channel(channelID).WithContext(ctx).CreateMessage(params, flags...)
return
}

Expand Down

0 comments on commit 304919b

Please sign in to comment.