Skip to content

Commit

Permalink
fix queues and autodjing
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Pavoni committed Mar 24, 2022
1 parent 848feea commit 9472fce
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
34 changes: 24 additions & 10 deletions ttfm/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@ func (a *Actions) AutoSnag() {

func (a *Actions) AutoDj() {
if a.bot.Config.AutoDjEnabled && a.bot.Room.Djs.Size() <= int(a.bot.Config.AutoDjMinDjs) && !a.bot.Users.UserIsDj(a.bot.Identity.Id) {
a.bot.api.AddDj()
if err := a.bot.api.AddDj(); err == nil {
a.bot.RoomMessage("/me is going on stage")
}
}
}

func (a *Actions) ConsiderStopAutoDj() {
if a.bot.Users.UserIsDj(a.bot.Identity.Id) && a.bot.Room.Djs.Size() > int(a.bot.Config.AutoDjMinDjs) {
if a.bot.Users.UserIsCurrentDj(a.bot.Identity.Id) {
a.bot.Room.AddDjEscorting(a.bot.Identity.Id)
a.bot.RoomMessage("/me will leave the stage at the end of this song to free a slot for humans")
} else {
a.bot.Users.EscortDj(a.bot.Identity.Id)
a.bot.RoomMessage("/me leaves the stage to free a slot for humans")
}
}
}

Expand Down Expand Up @@ -78,22 +92,22 @@ func (a *Actions) EnforceQueueStageReservation(userId string) {
}

func (a *Actions) ConsiderQueueActivation() {
stageIsFull := (a.bot.Room.MaxDjs - a.bot.Room.Djs.Size()) == 0
stageIsFull := a.bot.Room.MaxDjs == a.bot.Room.Djs.Size()

if a.bot.Users.UserIsModerator(a.bot.Identity.Id) && !a.bot.Config.QueueEnabled && stageIsFull {
a.bot.Config.EnableQueue(true)
a.bot.Queue.Empty()
a.bot.RoomMessage("/me has enabled queue mode")
}
}

if stageIsFull && a.bot.Users.UserIsDj(a.bot.Identity.Id) {
if a.bot.Users.UserIsCurrentDj(a.bot.Identity.Id) {
a.bot.Room.AddDjEscorting(a.bot.Identity.Id)
a.bot.RoomMessage("/me will leave the stage at the end of this song to free a slot for humans")
} else {
a.bot.Users.EscortDj(a.bot.Identity.Id)
a.bot.RoomMessage("/me leaves the stage to free a slot for humans")
}
func (a *Actions) ConsiderQueueDeactivation() {
stageIsAvailable := a.bot.Room.MaxDjs-a.bot.Room.Djs.Size() > 0

if a.bot.Users.UserIsModerator(a.bot.Identity.Id) && a.bot.Config.QueueEnabled && stageIsAvailable && a.bot.Queue.Size() == 0 {
a.bot.Config.EnableQueue(false)
a.bot.Queue.Empty()
a.bot.RoomMessage("/me has disabled queue mode")
}
}

Expand Down
2 changes: 1 addition & 1 deletion ttfm/commands/dj.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ func djCommandHandler(b *ttfm.Bot, cmd *ttfm.CommandInput) *ttfm.CommandOutput {
}

b.Actions.AutoDj()
return &ttfm.CommandOutput{Msg: "/me is going on stage", User: user, ReplyType: cmd.Source}
return &ttfm.CommandOutput{User: user, ReplyType: ttfm.MessageTypeNone}
}
5 changes: 4 additions & 1 deletion ttfm/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func onNewSong(b *Bot, e ttapi.NewSongEvt) {
b.Actions.EnforceSongDuration()
b.Actions.AutoBop()
b.Actions.AutoSnag()
b.Actions.AutoDj()

logrus.WithFields(logrus.Fields{
"djName": b.Room.Song.DjName,
Expand Down Expand Up @@ -82,6 +83,7 @@ func onSnagged(b *Bot, e ttapi.SnaggedEvt) {
func onRegistered(b *Bot, e ttapi.RegisteredEvt) {
u := e.User[0]
b.Actions.RegisterUser(u.ID, u.Name)
b.Actions.AutoDj()

logrus.WithFields(logrus.Fields{
"userId": u.ID,
Expand Down Expand Up @@ -121,8 +123,9 @@ func onAddDj(b *Bot, e ttapi.AddDJEvt) {
func onRemDj(b *Bot, e ttapi.RemDJEvt) {
u := e.User[0]
b.Actions.RemoveDj(u.Userid, e.Modid)
b.Actions.AutoDj()
b.Actions.ConsiderQueueDeactivation()
b.Actions.ForwardQueue()
b.Actions.AutoDj()

logrus.WithFields(logrus.Fields{
"userId": u.Userid,
Expand Down

0 comments on commit 9472fce

Please sign in to comment.