-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpodcastType.go
55 lines (43 loc) · 1.55 KB
/
podcastType.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package radiobot
import (
"crypto/md5"
"time"
telebot "gopkg.in/tucnak/telebot.v2"
"github.com/google/uuid"
)
// Podcast represent podcast of the channel
type Podcast struct {
ID [md5.Size]byte `json:"id" bson:"_id"`
FileURL string `json:"file_url" bson:"file_url"`
ChannelID uuid.UUID `json:"channel_id" bson:"channel_id"`
Comment string `json:"comment" bson:"comment"`
CreatedOn time.Time `json:"created_on" bson:"created_on"`
ParsedOn time.Time `json:"parsed_on" bson:"parsed_on"`
// telegram messages data to forward messages from channel to another chat
Recipient Recipient `json:"recipient" bson:"recipient"`
CommentMsgID int `json:"comment_msg_id" bson:"comment_msg_id"`
FileMsgID int `json:"file_msg_id" bson:"file_msg_id"`
FIleTgID string `json:"file_tg_id" bson:"file_tg_id"`
}
// CalcID calc and set ID of podcast based on the FileURL
func (p *Podcast) CalcID() {
p.ID = md5.Sum([]byte(p.FileURL))
}
// SetParsedOnNow set field ParsedOn now
func (p *Podcast) SetParsedOnNow() {
p.ParsedOn = time.Now()
}
// IsSended check if podcas is sended to channel
func (p *Podcast) IsSended() bool {
return p.Recipient.Recipient() != "" && (p.CommentMsgID != 0 || p.FileMsgID != 0)
}
// SetRecipient set Recipient from telebot.Recipient interface
func (p *Podcast) SetRecipient(r telebot.Recipient) {
p.Recipient = Recipient(r.Recipient())
}
// Recipient implement telebot.Recipient interface
type Recipient string
// Recipient return string of recipient
func (r *Recipient) Recipient() string {
return string(*r)
}