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:
parent
5b88b577fb
commit
5c8031b8a2
38
channel.go
38
channel.go
|
@ -71,14 +71,15 @@ type Channel struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ cchat.Server = (*Channel)(nil)
|
_ cchat.Server = (*Channel)(nil)
|
||||||
_ cchat.ServerMessage = (*Channel)(nil)
|
_ cchat.ServerMessage = (*Channel)(nil)
|
||||||
_ cchat.ServerMessageSender = (*Channel)(nil)
|
_ cchat.ServerMessageSender = (*Channel)(nil)
|
||||||
_ cchat.ServerMessageSendCompleter = (*Channel)(nil)
|
_ cchat.ServerMessageAttachmentSender = (*Channel)(nil)
|
||||||
_ cchat.ServerNickname = (*Channel)(nil)
|
_ cchat.ServerMessageSendCompleter = (*Channel)(nil)
|
||||||
_ cchat.ServerMessageEditor = (*Channel)(nil)
|
_ cchat.ServerNickname = (*Channel)(nil)
|
||||||
_ cchat.ServerMessageActioner = (*Channel)(nil)
|
_ cchat.ServerMessageEditor = (*Channel)(nil)
|
||||||
_ cchat.ServerMessageTypingIndicator = (*Channel)(nil)
|
_ cchat.ServerMessageActioner = (*Channel)(nil)
|
||||||
|
_ cchat.ServerMessageTypingIndicator = (*Channel)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewChannel(s *Session, ch discord.Channel) *Channel {
|
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 {
|
if noncer, ok := msg.(cchat.MessageNonce); ok {
|
||||||
send.Nonce = noncer.Nonce()
|
send.Nonce = noncer.Nonce()
|
||||||
}
|
}
|
||||||
|
if attcher, ok := msg.(cchat.SendableMessageAttachments); ok {
|
||||||
|
send.Files = addAttachments(attcher.Attachments())
|
||||||
|
}
|
||||||
|
|
||||||
_, err := ch.session.SendMessageComplex(ch.id, send)
|
_, err := ch.session.SendMessageComplex(ch.id, send)
|
||||||
return err
|
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
|
// MessageEditable returns true if the given message ID belongs to the current
|
||||||
// user.
|
// user.
|
||||||
func (ch *Channel) MessageEditable(id string) bool {
|
func (ch *Channel) MessageEditable(id string) bool {
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/diamondburned/arikawa v0.9.6
|
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/diamondburned/ningen v0.1.1-0.20200708211706-57c712372ede
|
||||||
github.com/dustin/go-humanize v1.0.0
|
github.com/dustin/go-humanize v1.0.0
|
||||||
github.com/go-test/deep v1.0.6
|
github.com/go-test/deep v1.0.6
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -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.41/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
|
||||||
github.com/diamondburned/cchat v0.0.42 h1:FVMLy9hOTxKju8OWDBIStrekbgTHCaH8+GVnV4LOByg=
|
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.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 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.20200621014632-6babb812b249/go.mod h1:xW9hpBZsGi8KpAh10TyP+YQlYBo+Xc+2w4TR6N0951A=
|
||||||
github.com/diamondburned/ningen v0.1.1-0.20200708085949-b64e350f3b8c h1:3h/kyk6HplYZF3zLi106itjYJWjbuMK/twijeGLEy2M=
|
github.com/diamondburned/ningen v0.1.1-0.20200708085949-b64e350f3b8c h1:3h/kyk6HplYZF3zLi106itjYJWjbuMK/twijeGLEy2M=
|
||||||
|
|
Loading…
Reference in a new issue