Skip to content

Commit

Permalink
husky
Browse files Browse the repository at this point in the history
  • Loading branch information
SudhanPlayz committed Oct 30, 2021
1 parent e8906bb commit 7fc17aa
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 80 deletions.
15 changes: 10 additions & 5 deletions commands/slash/disconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ const command = new SlashCommand()
.setDescription("Stop the music and leave the voice channel")
.setRun(async (client, interaction, options) => {
let player = client.manager.players.get(interaction.guild.id);
if(!player)return interaction.reply({ embeds: [ client.ErrorEmbed("Bot must need to be in a voice channel to disconnect") ]})
if (!player)
return interaction.reply({
embeds: [
client.ErrorEmbed(
"Bot must need to be in a voice channel to disconnect"
),
],
});

player.destroy()
player.destroy();

interaction.reply({
embeds: [
client.Embed(`Successfully left <#${player.voiceChannel.id}>!`),
],
embeds: [client.Embed(`Successfully left <#${player.voiceChannel.id}>!`)],
});
});

Expand Down
6 changes: 2 additions & 4 deletions commands/slash/join.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const command = new SlashCommand()
});

let player = client.manager.players.get(interaction.guild.id);
if (!player){
if (!player) {
player = client.createPlayer(interaction.channel, channel);
player.connect();
}
Expand All @@ -23,9 +23,7 @@ const command = new SlashCommand()
}

interaction.reply({
embeds: [
client.Embed(`Successfully joined <#${channel.id}>!`),
],
embeds: [client.Embed(`Successfully joined <#${channel.id}>!`)],
});
});

Expand Down
9 changes: 6 additions & 3 deletions commands/slash/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ const SlashCommand = require("../../lib/SlashCommand");
const command = new SlashCommand()
.setName("play")
.setDescription("Play music in the voice channel")
.addStringOption(option => option.setName("query")
.setDescription("Search string to search the music")
.setRequired(true))
.addStringOption((option) =>
option
.setName("query")
.setDescription("Search string to search the music")
.setRequired(true)
)
.setRun(async (client, interaction, options) => {
let channel = await client.getChannel(client, interaction);
if (!channel) return;
Expand Down
2 changes: 1 addition & 1 deletion deploy/guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const rl = readline.createInterface({
const config = await getConfig();
const rest = new REST({ version: "9" }).setToken(config.token);
const commands = await LoadCommands().then((cmds) => {
return [].concat(cmds.slash).concat(cmds.context)
return [].concat(cmds.slash).concat(cmds.context);
});

rl.question(
Expand Down
5 changes: 3 additions & 2 deletions events/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ module.exports = (client, interaction) => {
return;
}

if(interaction.isButton()){
if(interaction.customId.startsWith("controller"))Controller(client, interaction)
if (interaction.isButton()) {
if (interaction.customId.startsWith("controller"))
Controller(client, interaction);
}
};
2 changes: 1 addition & 1 deletion events/ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
*/
module.exports = (client) => {
client.manager.init(client.user.id);
client.user.setPresence(client.config.presence)
client.user.setPresence(client.config.presence);
client.log("Successfully Logged in as " + client.user.tag);
};
56 changes: 33 additions & 23 deletions lib/DiscordMusicBot.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
const { Client, Intents, MessageEmbed, Collection, MessageActionRow, MessageButton } = require("discord.js");
const {
Client,
Intents,
MessageEmbed,
Collection,
MessageActionRow,
MessageButton,
} = require("discord.js");
const fs = require("fs");
const path = require("path");
const prettyMilliseconds = require("pretty-ms");
Expand Down Expand Up @@ -27,7 +34,7 @@ class DiscordMusicBot extends Client {
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_VOICE_STATES,
]
],
}
) {
super(props);
Expand Down Expand Up @@ -167,7 +174,10 @@ class DiscordMusicBot extends Client {

let NowPlaying = await client.channels.cache
.get(player.textChannel)
.send({ embeds: [TrackStartedEmbed], components: [client.createController(player.options.guild)] });
.send({
embeds: [TrackStartedEmbed],
components: [client.createController(player.options.guild)],
});
player.setNowplayingMessage(NowPlaying);
})
.on("queueEnd", (player) => {
Expand All @@ -188,9 +198,9 @@ class DiscordMusicBot extends Client {
* @returns {MessageEmbed}
*/
Embed(text) {
let embed = new MessageEmbed().setColor(this.config.embedColor)
if(text)embed.setDescription(text);
let embed = new MessageEmbed().setColor(this.config.embedColor);

if (text) embed.setDescription(text);

return embed;
}
Expand Down Expand Up @@ -283,33 +293,33 @@ class DiscordMusicBot extends Client {
});
}

createController(guild){
createController(guild) {
return new MessageActionRow().addComponents(
new MessageButton()
.setStyle("SECONDARY")
.setCustomId(`controller:${guild}:LowVolume`)
.setEmoji("🔉"),
.setStyle("SECONDARY")
.setCustomId(`controller:${guild}:LowVolume`)
.setEmoji("🔉"),

new MessageButton()
.setStyle("SUCCESS")
.setCustomId(`controller:${guild}:Previous`)
.setEmoji("◀"),
.setStyle("SUCCESS")
.setCustomId(`controller:${guild}:Previous`)
.setEmoji("◀"),

new MessageButton()
.setStyle("DANGER")
.setCustomId(`controller:${guild}:PausePlay`)
.setEmoji("⏯"),
.setStyle("DANGER")
.setCustomId(`controller:${guild}:PausePlay`)
.setEmoji("⏯"),

new MessageButton()
.setStyle("SUCCESS")
.setCustomId(`controller:${guild}:Next`)
.setEmoji("▶"),
.setStyle("SUCCESS")
.setCustomId(`controller:${guild}:Next`)
.setEmoji("▶"),

new MessageButton()
.setStyle("SECONDARY")
.setCustomId(`controller:${guild}:HighVolume`)
.setEmoji("🔊")
)
.setStyle("SECONDARY")
.setCustomId(`controller:${guild}:HighVolume`)
.setEmoji("🔊")
);
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/SlashCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const {
const DiscordMusicBot = require("./DiscordMusicBot");

class SlashCommand extends SlashCommandBuilder {
constructor(){
super()
constructor() {
super();
this.type = 1;
return this
return this;
}
/**
* Set Execution of the command
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
},
"husky": {
"hooks": {
"pre-commit": "npm format",
"pre-push": "npm lint"
"pre-commit": "npm format"
}
},
"repository": {
Expand Down
85 changes: 52 additions & 33 deletions util/Controller.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,62 @@
/**
*
* @param {import("../lib/DiscordMusicBot")} client
* @param {import("discord.js").ButtonInteraction} interaction
*
* @param {import("../lib/DiscordMusicBot")} client
* @param {import("discord.js").ButtonInteraction} interaction
*/
module.exports = async (client, interaction) => {
let guild = client.guilds.cache.get(interaction.customId.split(":")[1])
let property = interaction.customId.split(":")[2]
let player = client.manager.get(guild.id)
let guild = client.guilds.cache.get(interaction.customId.split(":")[1]);
let property = interaction.customId.split(":")[2];
let player = client.manager.get(guild.id);

if(!player)return interaction.reply({ embeds: [ client.Embed("There is no player to control in this server.")] })
if (!player)
return interaction.reply({
embeds: [client.Embed("There is no player to control in this server.")],
});

if(property === "LowVolume"){
player.setVolume(player.volume-10)
return interaction.reply({ embeds: [ client.Embed("Successfully set server volume to "+player.volume) ] })
}
if (property === "LowVolume") {
player.setVolume(player.volume - 10);
return interaction.reply({
embeds: [
client.Embed("Successfully set server volume to " + player.volume),
],
});
}

if(property === "Previous"){
if(!player.queue.previous)return interaction.reply({ embeds: [ client.ErrorEmbed("There is no previous played song") ] })
player.queue.unshift(player.queue.previous)
player.queue.unshift(player.queue.current)
player.stop()
return interaction.deferUpdate()
}
if (property === "Previous") {
if (!player.queue.previous)
return interaction.reply({
embeds: [client.ErrorEmbed("There is no previous played song")],
});
player.queue.unshift(player.queue.previous);
player.queue.unshift(player.queue.current);
player.stop();
return interaction.deferUpdate();
}

if(property === "PlayAndPause"){
if(player.paused)player.play()
else player.pause()
return interaction.reply({ embeds: [ client.Embed(player.paused?"Paused":"Resumed")] })
}
if (property === "PlayAndPause") {
if (player.paused) player.play();
else player.pause();
return interaction.reply({
embeds: [client.Embed(player.paused ? "Paused" : "Resumed")],
});
}

if(property === "Next"){
player.stop()
return interaction.deferUpdate()
}
if (property === "Next") {
player.stop();
return interaction.deferUpdate();
}

if(property === "HighVolume"){
player.setVolume(player.volume+10)
return interaction.reply({ embeds: [ client.Embed("Successfully set server volume to "+player.volume) ] })
}
if (property === "HighVolume") {
player.setVolume(player.volume + 10);
return interaction.reply({
embeds: [
client.Embed("Successfully set server volume to " + player.volume),
],
});
}

return interaction.reply({ ephemeral: true, content: "Unknown controller option" })
}
return interaction.reply({
ephemeral: true,
content: "Unknown controller option",
});
};
6 changes: 3 additions & 3 deletions util/loadCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ const LoadDirectory = (dir) => {
let cmd = require(CommandsDir + "/" + file);
i++;
if (i == f) r = true;
if (!cmd || dir == "context" && !cmd.command)
if (!cmd || (dir == "context" && !cmd.command))
return console.log(
"Unable to load Command: " +
file.split(".")[0] +
", File doesn't have either command"
);
if(dir == "context")commands.push(cmd.command)
else commands.push(cmd)
if (dir == "context") commands.push(cmd.command);
else commands.push(cmd);
if (r) resolve(commands);
});
});
Expand Down

0 comments on commit 7fc17aa

Please sign in to comment.