From 9472fce1dce431c8b2200ef8a06db44346f60cda Mon Sep 17 00:00:00 2001 From: Andrea Pavoni Date: Fri, 25 Mar 2022 00:07:36 +0100 Subject: [PATCH] fix queues and autodjing --- ttfm/actions.go | 34 ++++++++++++++++++++++++---------- ttfm/commands/dj.go | 2 +- ttfm/events.go | 5 ++++- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/ttfm/actions.go b/ttfm/actions.go index 17d75e4..e71ab65 100644 --- a/ttfm/actions.go +++ b/ttfm/actions.go @@ -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") + } } } @@ -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") } } diff --git a/ttfm/commands/dj.go b/ttfm/commands/dj.go index a7ec8cd..c54d337 100644 --- a/ttfm/commands/dj.go +++ b/ttfm/commands/dj.go @@ -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} } diff --git a/ttfm/events.go b/ttfm/events.go index 70321d2..60368cb 100644 --- a/ttfm/events.go +++ b/ttfm/events.go @@ -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, @@ -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, @@ -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,