Skip to content

Commit

Permalink
Fixed page size bug in for queue listing, removed old code
Browse files Browse the repository at this point in the history
  • Loading branch information
Kihau committed Feb 19, 2023
1 parent 6d2974b commit f4b6cad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 42 deletions.
48 changes: 12 additions & 36 deletions Shitcord/Data/GuildAudioData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public enum LoopingMode : int
Shuffle = 3,
}

// TODO: Add a button to resend queue and message updates
// TODO: Command to display length of the current queue (also show page length and queue length
// for the queueupdate embed)
// TODO: Delete songs by link, name, author, length
Expand All @@ -39,14 +38,14 @@ public class GuildAudioData
private ConcurrentQueue<LavalinkTrack> PrevQueue { get; set; }
private ConcurrentQueue<LavalinkTrack> Queue { get; set; }
private LavalinkGuildConnection? Player { get; set; }
public LavalinkTrack? CurrentTrack { get; private set; }

// TODO: When in other looping mode than None, previous track is not removed from bottom of the queue
public LavalinkTrack? PreviousTrack { get; private set; }
public LavalinkTrack? CurrentTrack { get; private set; }

public DiscordChannel? Channel => this.Player?.Channel;
public bool SkipEventFire { get; set; } = false;
public bool SkipEnqueue { get; set; } = false;
// TODO: Use this in all sorts of stuff
// public bool InvokedPlayIntro { get; set; } = false;

private LoopingMode _looping;
public LoopingMode Looping {
Expand Down Expand Up @@ -143,13 +142,6 @@ public async Task CreateConnectionAsync(DiscordChannel vchannel)
await Player.SetAudiofiltersAsync(Filters);

Player.PlaybackFinished += PlaybackFinished;

// Intro song is broken
// var tracks = await Lavalink.Rest.GetTracksAsync(new FileInfo("Resources/join-sound.mp3"));
// var track = tracks.Tracks.First();
// if (track != null) {
// await PlayIntroAsync(track);
// }
}

private void InitializeDatabase() {
Expand Down Expand Up @@ -327,8 +319,6 @@ public async Task DestroySongUpdate()
DatabaseUpdateSU();
}

// TODO: FIX: This logic is a little broken track.lengths that are multiples of pace_size
// (for example 180 tracks in the queue)
public DiscordMessageBuilder GenerateQueueMessage()
{
var tracks = this.GetNextTracks();
Expand All @@ -337,25 +327,25 @@ public DiscordMessageBuilder GenerateQueueMessage()
string description = "";

const int page_size = 20;
var page_count = tracks.Length / page_size;
// int page_count = tracks.Length / page_size;
int page_count = ((int)Math.Ceiling(tracks.Length / (float)page_size)) - 1;

if (this.page < 0)
this.page = 0;
else if (this.page > page_count)
this.page = page_count;
if (page < 0) page = 0;
else if (page > page_count)
page = page_count;

for (var i = this.page * page_size; i < tracks.Length && i < (this.page + 1) * page_size; i++)
for (var i = page * page_size; i < tracks.Length && i < (page + 1) * page_size; i++)
description += $"{i + 1}. [{tracks[i].Title}]({tracks[i].Uri})\n";

// if (tracks.Length - this.page * page_size > page_size)
// description += $". . . and {tracks.Length - page_size * (this.page + 1)} more";
// if (tracks.Length - page * page_size > page_size)
// description += $". . . and {tracks.Length - page_size * (page + 1)} more";

if (tracks.Length == 0)
description = "Queue is empty";

embed.WithTitle(":question: | Queue Info: ")
.WithDescription(description)
.WithFooter($"Page {this.page + 1} / {page_count + 1}")
.WithFooter($"Page {page + 1} / {page_count + 1}")
.WithColor(DiscordColor.Purple);

var builder = new DiscordMessageBuilder() {
Expand Down Expand Up @@ -609,7 +599,6 @@ public void RevertQueue() {
Queue = new ConcurrentQueue<LavalinkTrack>(PrevQueue);
}

// TODO: Do not start the next song if PlayIntro was invoked?
private async Task PlayerHandlerAsync()
{
PreviousTrack = CurrentTrack;
Expand Down Expand Up @@ -739,19 +728,6 @@ public async Task PlayAsync()
await this.PlayerHandlerAsync();
}

// public async Task PlayIntroAsync(LavalinkTrack track)
// {
// if (Player is not {IsConnected: true})
// return;
//
// SkipEventFire = true;
// SkipEnqueue = true;
//
// await Player.PlayAsync(track);
// await Player.SeekAsync(TimeSpan.Zero);
// await Task.Delay(track.Length);
// }

public async Task StopAsync()
{
if (this.Player is not {IsConnected: true})
Expand Down
8 changes: 4 additions & 4 deletions Shitcord/Modules/AudioModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,13 @@ public async Task ListQueueCommand(
CommandContext ctx,
[Description("Page number (single page is 10 songs)")] int page = 1
) {
// TODO: Fix this. See other todo mark in GuildAudioData.cs:324 GenerateQueueMessage()
page -= 1;

var tracks = this.Data.GetNextTracks();

const int page_size = 10;
int page_count = tracks.Length / page_size;
// int page_count = tracks.Length / page_size;
int page_count = ((int)Math.Ceiling(tracks.Length / (float)page_size)) - 1;

if (page < 0) page = 0;
else if (page > page_count)
Expand All @@ -300,10 +300,10 @@ public async Task ListQueueCommand(
if (tracks.Length - page * page_size > page_size) {
embed.WithFooter(
$". . . and {tracks.Length - page_size * (page + 1)} more " +
$"(page {page + 1} / {page_count + 1})"
$"| Page {page + 1} / {page_count + 1}"
);
// embed.WithFooter($". . . and {tracks.Length - page * page_size} more");
}
} else embed.WithFooter($"Page {page + 1} / {page_count + 1}");
} break;
case 0: {
description = "Queue is empty";
Expand Down
2 changes: 0 additions & 2 deletions Shitcord/Modules/AuthModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

namespace Shitcord.Modules;

// TODO: Add a restart command that restarts the bot (?)

[RequireAuthorized]
public class AuthModule : BaseCommandModule
{
Expand Down

0 comments on commit f4b6cad

Please sign in to comment.