Skip to content

Commit

Permalink
Update bidome music (still broken rn)
Browse files Browse the repository at this point in the history
  • Loading branch information
Blocksnmore committed Nov 8, 2024
1 parent 42acdea commit f4e9616
Show file tree
Hide file tree
Showing 16 changed files with 230 additions and 597 deletions.
10 changes: 2 additions & 8 deletions commands/music/forceskip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,9 @@ export default class ForceSkip extends Command {
const queue = queues.get(ctx.guild!.id)!;
if (
(await doPermCheck(ctx.member!, botState.channel!)) ||
queue.queue[0].requestedBy == ctx.author.id
queue.player.current.requestedBy == ctx.author.id
) {
const isLooping = queue.loop;
queue.loop = LoopType.OFF;

await queue.player.seek(0);
await queue.player.stop({});
queue.player.skip();

await ctx.message.reply({
embeds: [
Expand All @@ -63,8 +59,6 @@ export default class ForceSkip extends Command {
}).setColor("green"),
],
});

queue.loop = isLooping;
} else {
await ctx.message.reply({
embeds: [
Expand Down
19 changes: 9 additions & 10 deletions commands/music/loop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Command, CommandContext, Embed } from "harmony";
import { doPermCheck, LoopType, queues } from "queue";
import { doPermCheck, queues } from "queue";

export default class Loop extends Command {
name = "loop";
Expand Down Expand Up @@ -42,14 +42,13 @@ export default class Loop extends Command {
} else {
const queue = queues.get(ctx.guild!.id)!;
if (await doPermCheck(ctx.member!, botState.channel)) {
const loopType = queue.loopType;
const loopTypeEnum = queue.loop;
const isLoopDisabled = queue.loop != LoopType.SONG;
const previousLoopType = queue.player.loop.toString();
const isLoopDisabled = queue.player.loop != "track";

if (isLoopDisabled) {
queue.loop = LoopType.SONG;
queue.player.setLoop("track");
} else {
queue.loop = LoopType.OFF;
queue.player.setLoop("off");
}

await ctx.message.reply({
Expand All @@ -61,13 +60,13 @@ export default class Loop extends Command {
},
title: "Toggled song loop",
description: `Song looping is now ${
loopTypeEnum == LoopType.SONG
previousLoopType == "track"
? "Disabled"
: "Enabled"
} ${
loopTypeEnum != LoopType.OFF &&
loopTypeEnum != LoopType.SONG
? `and ${loopType}ing is now disabled`
previousLoopType != "off" &&
previousLoopType != "track"
? `and queue looping is now disabled`
: ""
}`,
}).setColor("green"),
Expand Down
136 changes: 21 additions & 115 deletions commands/music/play.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
fragment,
isMessageComponentInteraction,
} from "harmony";
import { doPermCheck, lavaCluster, queues, ServerQueue, Song } from "queue";
import { doPermCheck, nodes, queues, ServerQueue } from "queue";
import { Track } from "lavadeno";
import { getEmojiByName } from "emoji";
import { shuffleArray } from "tools";
Expand Down Expand Up @@ -89,9 +89,10 @@ export default class Play extends Command {
? ctx.argString
: `ytsearch:${ctx.argString}`;

const { data, loadType } = await lavaCluster.api.loadTracks(
searchString,
);
const { loadType, tracks } = await nodes.search({
query: searchString,
requester: ctx.author.id,
});

if (loadType == "error" || loadType == "empty") {
await message.edit(undefined, {
Expand All @@ -108,37 +109,7 @@ export default class Play extends Command {
],
});
} else {
const songsToAdd: Song[] = [];

const addTrackData = (trackInfo: Track) => {
const {
info: { title, author, uri, length },
track,
} = trackInfo;

let thumbnail: undefined | string = undefined;

if (
uri.toLowerCase().startsWith(
"https://www.youtube.com/",
)
) {
const videoID = uri.substring(uri.indexOf("=") + 1);
thumbnail =
`https://img.youtube.com/vi/${videoID}/hqdefault.jpg`;
}

songsToAdd.push({
title,
author,
url: uri,
msLength: length,
track,
requestedBy: ctx.author.id,
thumbnail,
requestedByString: ctx.author.tag,
});
};
let songsToAdd: Track[] = [];

if (isLink) {
switch (loadType) {
Expand All @@ -153,70 +124,21 @@ export default class Play extends Command {
) {
const tracks: Track[] = [];

for (const track of data.tracks) {
tracks.push({
info: {
author: track.info.author,
identifier:
track.info.identifier,
isSeekable:
track.info.isSeekable,
isStream: track.info.isStream,
length: track.info.length,
position: track.info.position,
sourceName:
track.info.sourceName,
title: track.info.title,
uri: track.info.uri!,
},
track: track.encoded,
});
for (const track of tracks) {
songsToAdd.push(track);
}

const shuffledTracks = shuffleArray(tracks);

for (const track of shuffledTracks) {
addTrackData(track);
}
songsToAdd = shuffleArray(songsToAdd);
} else {
for (const track of data.tracks) {
addTrackData({
info: {
author: track.info.author,
identifier:
track.info.identifier,
isSeekable:
track.info.isSeekable,
isStream: track.info.isStream,
length: track.info.length,
position: track.info.position,
sourceName:
track.info.sourceName,
title: track.info.title,
uri: track.info.uri!,
},
track: track.encoded,
});
for (const track of tracks) {
songsToAdd.push(track);
}
}
break;
}

case "track": {
addTrackData({
info: {
author: data.info.author,
identifier: data.info.identifier,
isSeekable: data.info.isSeekable,
isStream: data.info.isStream,
length: data.info.length,
position: data.info.position,
sourceName: data.info.sourceName,
title: data.info.title,
uri: data.info.uri!,
},
track: data.encoded,
});
songsToAdd.push(tracks[0]);
break;
}
}
Expand All @@ -243,15 +165,15 @@ export default class Play extends Command {
icon_url: ctx.client.user!.avatarURL(),
},
title: "Please select an option",
description: data
description: tracks
.slice(0, 5)
.map(
(track, i) =>
`${
emojiMap[
i as 0 | 1 | 2 | 3 | 4
]
} - [${track.info.title}](${track.info.uri})`,
} - [${track.title}](${track.url})`,
)
.join("\n"),
footer: {
Expand All @@ -263,7 +185,7 @@ export default class Play extends Command {
components: (
<>
<ActionRow>
{data.slice(0, 5).map((_, i) => (
{tracks.slice(0, 5).map((_, i) => (
<Button
style={"blurple"}
emoji={{
Expand Down Expand Up @@ -323,21 +245,8 @@ export default class Play extends Command {
return;
} else {
const [_, selected] = response.customID.split("-");
const selectedTrack = data[parseInt(selected)];
addTrackData({
info: {
author: selectedTrack.info.author,
identifier: selectedTrack.info.identifier,
isSeekable: selectedTrack.info.isSeekable,
isStream: selectedTrack.info.isStream,
length: selectedTrack.info.length,
position: selectedTrack.info.position,
sourceName: selectedTrack.info.sourceName,
title: selectedTrack.info.title,
uri: selectedTrack.info.uri!,
},
track: selectedTrack.encoded,
});
const selectedTrack = tracks[parseInt(selected)];
songsToAdd.push(selectedTrack);
}
}

Expand Down Expand Up @@ -366,9 +275,8 @@ export default class Play extends Command {
} to the queue!`,
footer: {
text: `Songs in queue: ${
queue.queue.length +
songsToAdd.length +
queue.playedSongQueue.length
queue.player.queue.size +
songsToAdd.length
}`,
},
}).setColor("random"),
Expand All @@ -388,10 +296,8 @@ export default class Play extends Command {
songsToAdd[0].title
}](${songsToAdd[0].url}) to the queue!`,
footer: {
text: `Songs in queue: ${
queue.queue.length + 1 +
queue.playedSongQueue.length
}`,
text:
`Songs in queue: ${queue.player.queue.size}`,
},
}).setColor("random"),
],
Expand Down
2 changes: 1 addition & 1 deletion commands/music/queue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class Queue extends Command {
getEmojiByName("eight"),
getEmojiByName("nine"),
];
const queueEntries = [...queue.queue, ...queue.playedSongQueue];
const queueEntries = queue.player.queue.tracks;

await ctx.message.reply(undefined, {
embeds: [
Expand Down
21 changes: 10 additions & 11 deletions commands/music/queueloop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Command, CommandContext, Embed } from "harmony";
import { doPermCheck, LoopType, queues } from "queue";
import { doPermCheck, queues } from "queue";

export default class QueueLoop extends Command {
name = "queueloop";
Expand Down Expand Up @@ -42,14 +42,13 @@ export default class QueueLoop extends Command {
} else {
const queue = queues.get(ctx.guild!.id)!;
if (await doPermCheck(ctx.member!, botState.channel)) {
const loopType = queue.loopType;
const loopTypeEnum = queue.loop;
const isLoopDisabled = queue.loop != LoopType.QUEUE;
const previousLoopType = queue.player.loop.toString();
const isLoopDisabled = queue.player.loop != "queue";

if (isLoopDisabled) {
queue.loop = LoopType.QUEUE;
queue.player.setLoop("queue");
} else {
queue.loop = LoopType.OFF;
queue.player.setLoop("off");
}

await ctx.message.reply({
Expand All @@ -59,15 +58,15 @@ export default class QueueLoop extends Command {
name: "Bidome bot",
icon_url: ctx.client.user!.avatarURL(),
},
title: "Toggled loop",
title: "Toggled song loop",
description: `Queue looping is now ${
loopTypeEnum == LoopType.QUEUE
previousLoopType == "queue"
? "Disabled"
: "Enabled"
} ${
loopTypeEnum != LoopType.OFF &&
loopTypeEnum != LoopType.QUEUE
? `and ${loopType}ing is now disabled`
previousLoopType != "off" &&
previousLoopType != "queue"
? `and track looping is now disabled`
: ""
}`,
}).setColor("green"),
Expand Down
Loading

0 comments on commit f4e9616

Please sign in to comment.