Skip to content

Commit

Permalink
Merge pull request #17 from Syaoran2014/16-bug-replace-youtube-extrac…
Browse files Browse the repository at this point in the history
…ter-with-new-discord-player

16 bug replace youtube extracter with new discord player
  • Loading branch information
Syaoran2014 authored Sep 4, 2024
2 parents e084820 + 5c8d9a3 commit d12336b
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 101 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ Eventaully I want to do more advance things, like patching into Amazon for stora
## Setup

Requirements: Create a `config.json` file in the same directory as `index.js`.
For Music to work - follow the instructions here: https://github.com/retrouser955/discord-player-youtubei under the "Signing into Youtube" Section.
tl;dr run this command:
`$ npx --no discord-player-youtubei`

```json
{
"token": "Bot_token_here",
"clientId": "Your bot's ClientId",
"prefix": "*"
"prefix": "*",
"YoutubeOauthToken": "Paste entire npx command output here"
}
```

Expand All @@ -28,7 +32,8 @@ Currently Alice has the following features!
- Gambling Games
- Betroll, blackjack, coinToss, highlow, rps
- Music! (Bug https://github.com/Syaoran2014/Alice/issues/16)
- Able to play music in one channel per server! Allows music from places like Spotify, Youtube, Apple Music, etc (Default Spotify)
- *Requires Youtube Oauth*
- Able to play music in one channel per server!
- Server Autorole on Join
- Role Menu Support
- Now editable!
Expand Down
105 changes: 98 additions & 7 deletions commands/music/nowPlaying.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { SlashCommandBuilder } = require("discord.js");
const { SlashCommandBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder, ComponentType } = require("discord.js");
const { useQueue } = require("discord-player");

module.exports = {
Expand All @@ -8,15 +8,30 @@ module.exports = {
.setDescription("Shows currently playing song"),
execute: async function(interaction, util) {
const queue = useQueue(interaction.guild);
let djRole = null;

if(!queue) {
return interaction.reply({ content: "No music is currently in queue.", ephemeral: true });
}

const track = queue.currentTrack;
//const progress = queue.node.createProgressBar();
util.dataHandler.getGuildConfig(interaction.guildId, (err, guildInfo) => {
if (err) {
util.logger.error(err.message);
return interaction.reply({ content: "Error in getting Server Configuration.\nIf issue persists, contact bot admin", ephemeral: true });
}
if (!guildInfo) {
util.logger.error(`No Guild info found for ${interaction.guild}`);
return interaction.reply({ content: "No server info was found, Contact bot admin" });
} else {
djRole = guildInfo.DjRole;
}
});

const isAdmin = interaction.member.permissions.toArray().includes("Administrator");
const isDj = interaction.member.roles.cache.has(djRole);

//util.logger.log(JSON.stringify(track, null, 4));
const track = queue.currentTrack;

//Update to be a console.
const embed = {
color: parseInt("f0ccc0", 16),
Expand All @@ -28,7 +43,7 @@ module.exports = {
name: `Now Playing:`,
icon_url: util.bot.user.displayAvatarURL({ size: 1024, dynamic: true}),
},
description: `**Title:** ${track.title}\n **Artist:** ${track.author}`,
description: `**Title:** ${track.title}\n**Artist:** ${track.author}`,
fields: [
{
name: 'Requested by:',
Expand All @@ -46,6 +61,82 @@ module.exports = {
}
};

interaction.reply({ embeds: [embed]});
const mediaService = util.services.get('MediaService');
const mediaEmbed = mediaService.nowPlayingEmbed(util, queue);

const components = [
new ActionRowBuilder().addComponents(
//new ButtonBuilder().setCustomId('previous').setEmoji("\u23EE").setStyle(ButtonStyle.Secondary),
new ButtonBuilder().setCustomId('playpause').setEmoji("\u23EF").setStyle(ButtonStyle.Primary),
new ButtonBuilder().setCustomId('skip').setEmoji("\u23ED").setStyle(ButtonStyle.Secondary),
),
new ActionRowBuilder().addComponents(
new ButtonBuilder().setCustomId('shuffle').setEmoji("\u{1F500}").setStyle(ButtonStyle.Secondary),
new ButtonBuilder().setCustomId('stop').setEmoji("\u23F9").setStyle(ButtonStyle.Danger),
//new ButtonBuilder().setCustomId('test').setEmoji("\u23CF").setStyle(ButtonStyle.Secondary)
)
];

if(!isAdmin && !isDj) {
return interaction.reply({ embeds: [embed] });
}

const mConsole = await interaction.reply({ embeds: [mediaEmbed], components, fetchReply: true });

const buttonCollector = mConsole.createMessageComponentCollector({ componentType: ComponentType.Button, time: 600000 });

buttonCollector.on('collect', async bInt => {
if(bInt.user.id !== interaction.user.id) {
return bInt.reply({ content: 'You cannot use these buttons', ephemeral: true});
}
// #TODO: Allow any admin or DJ to use and console as long as they are in voicechat...

// #TODO: Test current setup
// I think interaction reply will error out, might need to be "buttonInteraction.reply()"
switch(bInt.customId) {
case "playpause":
const newEmbed = mediaService.nowPlayingEmbed(util, queue);

if (queue.node.isPlaying()){
queue.node.pause();
newEmbed.author.name = 'Paused:';
} else if (queue.node.isPaused()) {
queue.node.resume();
}
return bInt.update({ embeds: [newEmbed] });

break;
case "previous":
break;
case "skip":
const success = queue.node.skip();
const skippedEmbed = {
title: success ? `Current track ${queue.currentTrack.title} has been skipped` : `Something went wrong, please try again`,
color: parseInt("f0ccc0", 16),
};
await queue.metadata.channel.send({ embeds: [skippedEmbed] });
return bInt.update({ embeds: [mediaService.nowPlayingEmbed(util, queue)] });
break;
case "shuffle":
await queue.tracks.shuffle();
const shuffleEmbed = {
title: `Queue has shuffled ${queue.tracks.size} song(s)`,
color: parseInt("f0ccc0", 16),
};
queue.metadata.channel.send({ embeds: [shuffleEmbed]});
return bInt.update({content: " "});
break;
case "stop":
queue.delete();
const stopEmbed = {
title: "Music stopped, see you next time! \n(*^ ‿ <*)♡",
color: parseInt("f0ccc0", 16),
};
return bInt.update({ embeds: [stopEmbed], components: []});
break;
case "test":
break;
}
});
}
};
};
33 changes: 17 additions & 16 deletions commands/music/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ module.exports = {
.setName('song')
.setDescription("Adds song to queue.")
.setRequired(true)
)
.addStringOption(option =>
option
.setName("platform")
.setDescription("Platform to search your music on. Default Youtube")
.setRequired(false)
.addChoices(
{ name: 'Spotify', value: "SPOTIFY_SEARCH"},
{ name: 'Youtube', value: "YOUTUBE"},
{ name: 'Apple Music', value: 'APPLE_MUSIC_SEARCH'},
{ name: 'SoundCloud', value: 'SOUNDCLOUD'}
)
),
//TODO: Right now, due to changes with youtube, choosing search is not working right now.
// TBH this might be fine to leave and keep with searchEngine.Auto ....
//.addStringOption(option =>
// option
// .setName("platform")
// .setDescription("Platform to search your music on. Default Spotify")
// .setRequired(false)
// .addChoices(
// { name: 'Spotify', value: "SPOTIFY_SEARCH"},
// { name: 'Youtube', value: "YOUTUBE"},
// { name: 'Apple Music', value: 'APPLE_MUSIC_SEARCH'},
// { name: 'SoundCloud', value: 'SOUNDCLOUD'}
// )
// ),
execute: async function(interaction, util) {
const player = useMainPlayer();
const channel = interaction.member.voice.channel;
Expand Down Expand Up @@ -75,7 +77,7 @@ module.exports = {
}

const queue = await player.nodes.create(interaction.guild, {
metadata: interaction.channel,
metadata: interaction,
leaveOnEmpty: true,
leaveOnEmptyCooldown: 60000,
leaveOnEnd: true,
Expand Down Expand Up @@ -108,7 +110,6 @@ module.exports = {
const query = song;
const res = await player.search(query, {
requestedBy: interaction.member,
searchEngine: platform ? QueryType.platform : QueryType.SPOTIFY_SEARCH
});

if(!res || !res.tracks.length) {
Expand All @@ -117,7 +118,7 @@ module.exports = {
}

const queue = await player.nodes.create(interaction.guild, {
metadata: interaction.channel,
metadata: interaction,
leaveOnEmpty: true,
leaveOnEmptyCooldown: 30000,
leaveOnEnd: true,
Expand Down Expand Up @@ -204,4 +205,4 @@ module.exports = {
// return interaction.followUp(`**${track.title}** queued!`)
// } catch (e) {
// return interaction.followUp(`Something went wrong: ${e}`);
//}
//}
31 changes: 14 additions & 17 deletions commands/music/playNext.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@ module.exports = {
data: new SlashCommandBuilder()
.setName("playnext")
.setDescription("Forces song to play next in queue")
.addStringOption(option =>
option
.addStringOption(option => option
.setName('song')
.setDescription("Adds song to queue.")
.setRequired(true)
)
.addStringOption(option =>
option
.setName("platform")
.setDescription("Platform to search your music on. Default Youtube")
.setRequired(false)
.addChoices(
{ name: 'Spotify', value: "SPOTIFY_SEARCH"},
{ name: 'Youtube', value: "YOUTUBE"},
{ name: 'Apple Music', value: 'APPLE_MUSIC_SEARCH'},
{ name: 'SoundCloud', value: 'SOUNDCLOUD'}
)),
),
//.addStringOption(option => option
// .setName("platform")
// .setDescription("Platform to search your music on. Default Youtube")
// .setRequired(false)
// .addChoices(
// { name: 'Spotify', value: "SPOTIFY_SEARCH"},
// { name: 'Youtube', value: "YOUTUBE"},
// { name: 'Apple Music', value: 'APPLE_MUSIC_SEARCH'},
// { name: 'SoundCloud', value: 'SOUNDCLOUD'}
// )),
execute: async function (interaction, util) {
const player = useMainPlayer();
const queue = useQueue(interaction.guild);
Expand Down Expand Up @@ -77,7 +75,7 @@ module.exports = {
}

const queue = await player.nodes.create(interaction.guild, {
metadata: interaction.channel,
metadata: interaction,
leaveOnEmpty: true,
leaveOnEmptyCooldown: 30000,
leaveOnEnd: true,
Expand Down Expand Up @@ -108,7 +106,6 @@ module.exports = {
const query = song;
const res = await player.search(query, {
requestedBy: interaction.member,
searchEngine: platform ? QueryType.platform : QueryType.SPOTIFY_SEARCH
});

if(!res || !res.tracks.length) {
Expand All @@ -117,7 +114,7 @@ module.exports = {
}

const queue = await player.nodes.create(interaction.guild, {
metadata: interaction.channel,
metadata: interaction,
leaveOnEmpty: true,
leaveOnEmptyCooldown: 30000,
leaveOnEnd: true,
Expand Down
13 changes: 0 additions & 13 deletions data/mediaConfig.js

This file was deleted.

Loading

0 comments on commit d12336b

Please sign in to comment.