Stacks on #16. Opens a public thread named "{author} asks: {title}" and puts the post body in the first thread message. Reviewed-on: #17 Co-authored-by: codegirl-007 <s.raide@gmail.com>
This commit was merged in pull request #17.
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
// API is the Discord REST surface used by the outbound subscriber.
|
||||
type API interface {
|
||||
SendToChannel(ctx context.Context, channelID string, msg Message) (messageID string, err error)
|
||||
StartThread(ctx context.Context, channelID, messageID, name string) (threadID string, err error)
|
||||
StartThread(ctx context.Context, channelID, name string) (threadID string, err error)
|
||||
SendToThread(ctx context.Context, threadID string, msg Message) (messageID string, err error)
|
||||
Edit(ctx context.Context, channelID, messageID string, msg Message) error
|
||||
Close() error
|
||||
@@ -27,9 +27,10 @@ func (s *sessionAPI) SendToChannel(_ context.Context, channelID string, msg Mess
|
||||
return sent.ID, nil
|
||||
}
|
||||
|
||||
func (s *sessionAPI) StartThread(_ context.Context, channelID, messageID, name string) (string, error) {
|
||||
thread, err := s.session.MessageThreadStartComplex(channelID, messageID, &discordgo.ThreadStart{
|
||||
func (s *sessionAPI) StartThread(_ context.Context, channelID, name string) (string, error) {
|
||||
thread, err := s.session.ThreadStartComplex(channelID, &discordgo.ThreadStart{
|
||||
Name: name,
|
||||
Type: discordgo.ChannelTypeGuildPublicThread,
|
||||
AutoArchiveDuration: 10080,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -43,10 +44,12 @@ func (s *sessionAPI) SendToThread(ctx context.Context, threadID string, msg Mess
|
||||
}
|
||||
|
||||
func (s *sessionAPI) Edit(_ context.Context, channelID, messageID string, msg Message) error {
|
||||
content := messageContent(msg)
|
||||
embeds := toEmbeds(msg)
|
||||
_, err := s.session.ChannelMessageEditComplex(&discordgo.MessageEdit{
|
||||
ID: messageID,
|
||||
Channel: channelID,
|
||||
Content: &content,
|
||||
Embeds: &embeds,
|
||||
})
|
||||
return err
|
||||
@@ -61,6 +64,7 @@ func (s *sessionAPI) Close() error {
|
||||
|
||||
func toMessageSend(msg Message) *discordgo.MessageSend {
|
||||
return &discordgo.MessageSend{
|
||||
Content: messageContent(msg),
|
||||
Embeds: toEmbeds(msg),
|
||||
AllowedMentions: &discordgo.MessageAllowedMentions{},
|
||||
}
|
||||
@@ -69,7 +73,7 @@ func toMessageSend(msg Message) *discordgo.MessageSend {
|
||||
func toEmbeds(msg Message) []*discordgo.MessageEmbed {
|
||||
main := &discordgo.MessageEmbed{
|
||||
Title: msg.Title,
|
||||
URL: msg.URL,
|
||||
URL: publicURL(msg.URL),
|
||||
Description: msg.Description,
|
||||
Color: embedColor,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user