Skip to content

Commit 934e00f

Browse files
committed
Added live stream detection
1 parent ce1b2a5 commit 934e00f

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ vigne:welcomer:main | | ID of the channel where welcome messages should go
2121
vigne:welcomer:secret | | ID of the channel where messages of leaves and joins should go
2222
vigne:welcomer:text:before | | Message, that should be displayed when a user joins. Example: `Welcome %s! Have fun!`
2323
vigne:welcomer:text:after | | After a short period of time, the original message gets replaced by this one. Example: `Welcome %s!`
24+
vigne:canPlayLive | | 1 or 0. Whether the music bot can play live streams or not.
2425

2526
## Default commands
2627

database/Music.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,19 @@ func (d MusicDatabase) CanPlay(duration time.Duration) bool {
5959
}
6060
return true
6161

62+
}
63+
64+
func (d MusicDatabase) CanPlayLive() bool {
65+
if d.d.Redis.Exists(d.d.Decorate("canPlayLive")).Val() == 0{
66+
return true
67+
}
68+
val, err := d.d.Redis.Get(d.d.Decorate("canPlayLive")).Int()
69+
if err != nil {
70+
return true
71+
}
72+
if val != 0 {
73+
return true
74+
}
75+
76+
return false
6277
}

errors/errors.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ var NoCommand = New("", "Couldn't find this command")
1515
var NoMusic = New("couldn't find musicChannel and musicVoiceChannel in the config. Music bot functionality will be unavailable", "The Music Bot is unavailable")
1616
var NotPlaying = New("", "There is nothing playing currently...")
1717
var NotRequester = New("", "You can't skip this music")
18-
var MusicTooLong = New("", "The selected song is too long")
18+
var MusicTooLong = New("", "The selected song is too long")
19+
var MusicIsLive = New("", "Sorry, but I can't play live streams")

modules/music/music.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ func (p *MusicPlayer) AddMusic(url string, user *discordgo.User) (*Music, error)
177177
if !d.CanPlay(time.Duration(m.Duration) * time.Second) {
178178
return m, errors.MusicTooLong
179179
}
180+
//Make sure that it isn't live
181+
if m.IsLive && !d.CanPlayLive() {
182+
return m, errors.MusicIsLive
183+
}
180184
//Convert music data to JSON
181185
jsonData, err := json.Marshal(m)
182186
if err != nil {

modules/music/playCommand.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,22 @@ func (p PlayCommand) Action(m *discordgo.MessageCreate, args []string, creator *
3434
message := creator.NewMessage()
3535
message.SetContent("Loading...")
3636
go func() {
37-
//new message builder
38-
newMessage := &messages.MessageBuilder{}
3937
//Replace Loading... with new message after loading is done
40-
defer message.ReplaceMessage(newMessage)
38+
newMessage := message.GetAfter()
39+
defer message.Delete()
4140
//Actually add music to queue
4241
info, err := p.module.Player.AddMusic(strings.Join(args, " "), m.Author)
4342
if err == errors.InvalidExtractor {
4443
newMessage.SetContent("Sorry, I can't play music from this site")
4544
return
4645
}
4746
if err != nil {
47+
e, ok := err.(*errors.PublicError)
4848
newMessage.SetContent("Couldn't play music")
49+
if ok {
50+
newMessage.SetContent(e.PublicPart)
51+
}
52+
newMessage.SetExpiry(time.Second*10)
4953
return
5054
}
5155
embed := newMessage.GetEmbedBuilder()

modules/music/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type Music struct {
99
Entries []Music `json:"entries"`
1010
URL string `json:"webpage_url"`
1111
Duration int `json:"duration"`
12+
IsLive bool `json:"is_live"`
1213
RequesterID string
1314
RequesterName string
1415
}

0 commit comments

Comments
 (0)