1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-discord.git synced 2024-11-01 12:24:15 +00:00

Added attachment support

This commit is contained in:
diamondburned 2020-07-09 16:32:49 -07:00
parent 5b88b577fb
commit 5c8031b8a2
3 changed files with 33 additions and 9 deletions

View file

@ -71,14 +71,15 @@ type Channel struct {
}
var (
_ cchat.Server = (*Channel)(nil)
_ cchat.ServerMessage = (*Channel)(nil)
_ cchat.ServerMessageSender = (*Channel)(nil)
_ cchat.ServerMessageSendCompleter = (*Channel)(nil)
_ cchat.ServerNickname = (*Channel)(nil)
_ cchat.ServerMessageEditor = (*Channel)(nil)
_ cchat.ServerMessageActioner = (*Channel)(nil)
_ cchat.ServerMessageTypingIndicator = (*Channel)(nil)
_ cchat.Server = (*Channel)(nil)
_ cchat.ServerMessage = (*Channel)(nil)
_ cchat.ServerMessageSender = (*Channel)(nil)
_ cchat.ServerMessageAttachmentSender = (*Channel)(nil)
_ cchat.ServerMessageSendCompleter = (*Channel)(nil)
_ cchat.ServerNickname = (*Channel)(nil)
_ cchat.ServerMessageEditor = (*Channel)(nil)
_ cchat.ServerMessageActioner = (*Channel)(nil)
_ cchat.ServerMessageTypingIndicator = (*Channel)(nil)
)
func NewChannel(s *Session, ch discord.Channel) *Channel {
@ -272,11 +273,32 @@ func (ch *Channel) SendMessage(msg cchat.SendableMessage) error {
if noncer, ok := msg.(cchat.MessageNonce); ok {
send.Nonce = noncer.Nonce()
}
if attcher, ok := msg.(cchat.SendableMessageAttachments); ok {
send.Files = addAttachments(attcher.Attachments())
}
_, err := ch.session.SendMessageComplex(ch.id, send)
return err
}
func (ch *Channel) SendAttachments(atts []cchat.MessageAttachment) error {
_, err := ch.session.SendMessageComplex(ch.id, api.SendMessageData{
Files: addAttachments(atts),
})
return err
}
func addAttachments(atts []cchat.MessageAttachment) []api.SendMessageFile {
var files = make([]api.SendMessageFile, len(atts))
for i, a := range atts {
files[i] = api.SendMessageFile{
Name: a.Name,
Reader: a,
}
}
return files
}
// MessageEditable returns true if the given message ID belongs to the current
// user.
func (ch *Channel) MessageEditable(id string) bool {

2
go.mod
View file

@ -4,7 +4,7 @@ go 1.14
require (
github.com/diamondburned/arikawa v0.9.6
github.com/diamondburned/cchat v0.0.42
github.com/diamondburned/cchat v0.0.43
github.com/diamondburned/ningen v0.1.1-0.20200708211706-57c712372ede
github.com/dustin/go-humanize v1.0.0
github.com/go-test/deep v1.0.6

2
go.sum
View file

@ -43,6 +43,8 @@ github.com/diamondburned/cchat v0.0.41 h1:6y32s2wWTiDw4hWN/Gna6ay3uUrRAW5V8Cj0/x
github.com/diamondburned/cchat v0.0.41/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
github.com/diamondburned/cchat v0.0.42 h1:FVMLy9hOTxKju8OWDBIStrekbgTHCaH8+GVnV4LOByg=
github.com/diamondburned/cchat v0.0.42/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
github.com/diamondburned/cchat v0.0.43 h1:HetAujSaUSdnQgAUZgprNLARjf/MSWXpCfWdvX2wOCU=
github.com/diamondburned/cchat v0.0.43/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
github.com/diamondburned/ningen v0.1.1-0.20200621014632-6babb812b249 h1:yP7kJ+xCGpDz6XbcfACJcju4SH1XDPwlrvbofz3lP8I=
github.com/diamondburned/ningen v0.1.1-0.20200621014632-6babb812b249/go.mod h1:xW9hpBZsGi8KpAh10TyP+YQlYBo+Xc+2w4TR6N0951A=
github.com/diamondburned/ningen v0.1.1-0.20200708085949-b64e350f3b8c h1:3h/kyk6HplYZF3zLi106itjYJWjbuMK/twijeGLEy2M=