added delete after option.

This commit is contained in:
5elenay 2021-08-25 20:53:10 +03:00
parent f2d47011cb
commit 1045db4f49
3 changed files with 21 additions and 0 deletions

View File

@ -74,6 +74,13 @@ func (c Channel) SendMessage(message *SendMessage) (*Message, error) {
return respMessage, err
}
if message.DeleteAfter != 0 {
go func() {
time.Sleep(time.Second * time.Duration(message.DeleteAfter))
respMessage.Delete()
}()
}
return respMessage, nil
}

View File

@ -144,5 +144,12 @@ func (m Message) Reply(mention bool, sm *SendMessage) (*Message, error) {
return respMessage, err
}
if sm.DeleteAfter != 0 {
go func() {
time.Sleep(time.Second * time.Duration(sm.DeleteAfter))
respMessage.Delete()
}()
}
return respMessage, nil
}

View File

@ -7,6 +7,7 @@ type SendMessage struct {
Content string `json:"content,omitempty"`
Attachments []string `json:"attachments,omitempty"`
Nonce string `json:"nonce,omitempty"`
DeleteAfter uint `json:"-"`
Replies []struct {
Id string `json:"id,omitempty"`
Mention bool `json:"mention,omitempty"`
@ -25,6 +26,12 @@ func (sms *SendMessage) SetContentf(format string, values ...interface{}) *SendM
return sms
}
// Set delete after option.
func (sms *SendMessage) SetDeleteAfter(second uint) *SendMessage {
sms.DeleteAfter = second
return sms
}
// Add a new attachment.
func (sms *SendMessage) AddAttachment(attachment string) *SendMessage {
sms.Attachments = append(sms.Attachments, attachment)