File tree Expand file tree Collapse file tree
Application/Interfaces/Services Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,5 +9,6 @@ public interface IMusicQueueService
99 void DequeueAsync ( CancellationToken cancellationToken ) ;
1010 int Count { get ; }
1111 PlayRequest [ ] GetAllRequests ( ) ;
12+ void Rewind ( ) ;
1213 void Clear ( ) ;
1314}
Original file line number Diff line number Diff line change @@ -77,6 +77,27 @@ await executor.ExecuteAsync(async serviceProvider =>
7777 }
7878 }
7979
80+ [ SlashCommand ( "rewind" , "Rewind the current track" ) ]
81+ public async Task Rewind ( )
82+ {
83+ if ( await CommandUtils . NotInVoiceChannel ( Context , ( message ) => RespondAsync ( message ) ) )
84+ {
85+ return ;
86+ }
87+
88+ InteractionMessageProperties message ;
89+ if ( queue . Count == 0 )
90+ {
91+ message = CommandUtils . CreateMessage < InteractionMessageProperties > ( "No songs in queue." ) ;
92+ await RespondAsync ( InteractionCallback . Message ( message ) ) ;
93+ return ;
94+ }
95+
96+ queue . Rewind ( ) ;
97+ message = CommandUtils . CreateMessage < InteractionMessageProperties > ( "Rewinding the current track." ) ;
98+ await RespondAsync ( InteractionCallback . Message ( message ) ) ;
99+ }
100+
80101 [ SlashCommand ( "statistics" , "Show some statistics" ) ]
81102 public async Task Statistics ( )
82103 {
Original file line number Diff line number Diff line change @@ -74,6 +74,30 @@ public PlayRequest[] GetAllRequests()
7474 }
7575 }
7676
77+ public void Rewind ( )
78+ {
79+ lock ( _lock )
80+ {
81+ if ( _queue . Count > 1 )
82+ {
83+ var current = _queue . Peek ( ) ;
84+ var list = _queue . ToList ( ) ;
85+ list . Reverse ( ) ;
86+ list . Add ( current ) ;
87+ list . Reverse ( ) ;
88+ _queue . Clear ( ) ;
89+ foreach ( var item in list )
90+ {
91+ _queue . Enqueue ( item ) ;
92+ }
93+ }
94+ else
95+ {
96+ logger . LogWarning ( "Attempted to rewind with less than two items in the queue." ) ;
97+ }
98+ }
99+ }
100+
77101 public void Clear ( )
78102 {
79103 lock ( _lock )
You can’t perform that action at this time.
0 commit comments