Skip to content

Commit

Permalink
fix: bug and formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
LakhindarPal committed Jul 6, 2024
1 parent e18c62b commit 2a3f12f
Show file tree
Hide file tree
Showing 27 changed files with 96 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ DEV_IDS=12345678901234567,98765432101234567
# Support Server Invite Link
SUPPORT_SERVER=https://discord.gg/invite/abc123

# Development Mode (true/false)
DEVELOPMENT_MODE=false
# Node Env (development/production)
NODE_ENV=production
22 changes: 11 additions & 11 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ diverse, inclusive, and healthy community.
Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
- Focusing on what is best not just for us as individuals, but for the
overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
- The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities
Expand Down Expand Up @@ -106,7 +106,7 @@ Violating these terms may lead to a permanent ban.
### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WORKDIR /usr/app
COPY package*.json ./

# Install necessary dependencies only
RUN npm ci --omit=dev --no-optional
RUN npm ci --omit=dev --omit=optional

# Install mediaplex
RUN npm install mediaplex
Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export default [
eslintConfigPrettier,
{
languageOptions: { globals: globals.node },
files: ["src/**/*.js"],
ignores: [".github/*", "node_modules", "src/website"],
files: ["src/**/*.js", "scripts/**/*.js"],
ignores: [".github/*", "node_modules", "docs/", "previews/"],
rules: {
"handle-callback-err": "off",
"max-nested-callbacks": ["error", { "max": 4 }],
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discord-player-bot",
"version": "3.3.1",
"version": "3.3.2",
"description": "A discord music bot built using discord.js and discord-player",
"main": "src/index.js",
"type": "module",
Expand All @@ -9,8 +9,8 @@
"lint:fix": "eslint . --fix",
"format": "prettier . --write",
"doc": "node scripts/cmd-doc.js",
"build": "docker build -t lakhindarpal/discord-player-bot:latest .",
"run": "docker run --env-file .env lakhindarpal/discord-player-bot:latest",
"build": "podman build -t lakhindarpal/discord-player-bot:latest .",
"run": "podman run --env-file .env lakhindarpal/discord-player-bot:latest",
"register": "node scripts/register.js",
"start": "node .",
"dev": "node --watch-path=./src ."
Expand Down Expand Up @@ -54,7 +54,7 @@
"@eslint/js": "^9.6.0",
"eslint": "^9.6.0",
"eslint-config-prettier": "^9.1.0",
"globals": "^15.7.0",
"globals": "^15.8.0",
"prettier": "3.3.2"
}
}
3 changes: 2 additions & 1 deletion src/commands/music/back.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ export const data = {
export async function execute(interaction) {
const history = useHistory(interaction.guildId);

if (history.isEmpty())
if (history.isEmpty()) {
return interaction.reply({
ephemeral: true,
embeds: [ErrorEmbed("There is no previous song to go back.")],
});
}

await interaction.deferReply();

Expand Down
33 changes: 20 additions & 13 deletions src/commands/music/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,34 @@ export function execute(interaction, queue) {
const subcmd = interaction.options.getSubcommand();
const history = useHistory(interaction.guildId);

if ((subcmd === "queue" || subcmd === "all") && queue.isEmpty()) {
return interaction.reply({
ephemeral: true,
embeds: [ErrorEmbed("The queue is already empty.")],
});
}
if ((subcmd === "history" || subcmd === "all") && history.isEmpty()) {
return interaction.reply({
ephemeral: true,
embeds: [ErrorEmbed("The history is already empty.")],
});
}

switch (subcmd) {
case "queue":
if (queue.isEmpty()) {
return interaction.reply({
ephemeral: true,
embeds: [ErrorEmbed("The queue is already empty.")],
});
}
queue.tracks.clear();
break;

case "history":
if (history.isEmpty()) {
return interaction.reply({
ephemeral: true,
embeds: [ErrorEmbed("The history is already empty.")],
});
}
history.clear();
break;

default:
if (history.isEmpty() && history.isEmpty()) {
return interaction.reply({
ephemeral: true,
embeds: [ErrorEmbed("Both queue and history is already empty.")],
});
}
queue.clear();
break;
}
Expand Down
6 changes: 4 additions & 2 deletions src/commands/music/jump.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ export const data = {
};

export function execute(interaction, queue) {
if (queue.isEmpty())
if (queue.isEmpty()) {
return interaction.reply({
ephemeral: true,
embeds: [ErrorEmbed("The queue is empty.")],
});
}

const position = interaction.options.getNumber("position", true);

if (position > queue.size)
if (position > queue.size) {
return interaction.reply({
ephemeral: true,
embeds: [ErrorEmbed("The provided position is not valid.")],
});
}

queue.node.jump(position - 1);

Expand Down
11 changes: 6 additions & 5 deletions src/commands/music/lyrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ export const data = {
export async function execute(interaction, queue) {
await interaction.deferReply({ ephemeral: true });

const query =
interaction.options.getString("query", false) ??
`${queue?.currentTrack?.author} - ${queue?.currentTrack?.title}`;
let query = interaction.options.getString("query", false);

if (!query) {
if (!query && !queue?.currentTrack) {
return interaction.editReply({
embeds: [ErrorEmbed("You forgot to provide the song title.")],
embeds: [ErrorEmbed("Provide a song title to search lyrics.")],
});
}

if (!query)
query = `${queue?.currentTrack?.author} - ${queue?.currentTrack?.title}`;

const result = await lyricsFinder.search(query).catch(() => null);

if (!result || !result.lyrics) {
Expand Down
8 changes: 2 additions & 6 deletions src/commands/music/move.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,10 @@ export function execute(interaction, queue) {
});
}

const track = queue.tracks.at(from);
queue.node.move(from, to);

return interaction.reply({
ephemeral: true,
embeds: [
SuccessEmbed(
`Moved \`${queue.tracks.at(from).title}\` to position ${to + 1}.`
),
],
embeds: [SuccessEmbed(`Moved \`${track.title}\` to position ${to + 1}.`)],
});
}
3 changes: 2 additions & 1 deletion src/commands/music/pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ export const data = {
};

export function execute(interaction, queue) {
if (queue.node.isPaused())
if (queue.node.isPaused()) {
return interaction.reply({
ephemeral: true,
embeds: [ErrorEmbed("The playback is already paused.")],
});
}

queue.node.pause();

Expand Down
3 changes: 2 additions & 1 deletion src/commands/music/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ export async function execute(interaction) {
requestedBy: interaction.user,
});

if (!result.hasTracks())
if (!result.hasTracks()) {
return interaction.editReply({
embeds: [ErrorEmbed(`No results found for \`${query}\`.`)],
});
}

try {
const { queue, track, searchResult } = await player.play(channel, result, {
Expand Down
14 changes: 6 additions & 8 deletions src/commands/music/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,25 @@ export const data = {
};

export function execute(interaction, queue) {
if (queue.isEmpty())
if (queue.isEmpty()) {
return interaction.reply({
ephemeral: true,
embeds: [ErrorEmbed("The queue is empty.")],
});
}

const index = interaction.options.getNumber("position", true) - 1;

if (index >= queue.size)
if (index >= queue.size) {
return interaction.reply({
ephemeral: true,
embeds: [ErrorEmbed("The provided position is not valid.")],
});
}

const removed = queue.node.remove(index);
const track = queue.node.remove(index);

return interaction.reply({
embeds: [
SuccessEmbed(
`Removed [${removed.title}](${removed.url}) from the queue.`
),
],
embeds: [SuccessEmbed(`Removed ${track.toHyperlink()} from the queue.`)],
});
}
10 changes: 7 additions & 3 deletions src/commands/music/repeat.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApplicationCommandOptionType } from "discord.js";
import { QueueRepeatMode } from "discord-player";
import { BaseEmbed } from "../../modules/embeds.js";
import { BaseEmbed, Colors } from "../../modules/embeds.js";

export const data = {
name: "repeat",
Expand Down Expand Up @@ -74,7 +74,11 @@ export function execute(interaction, queue) {
queue.emit("repeatChange", queue);

return interaction.reply({
ephemeral: subCmd !== "status",
embeds: [BaseEmbed().setDescription(description)],
ephemeral: subCmd === "status",
embeds: [
BaseEmbed()
.setDescription(description)
.setColor(subCmd === "status" ? Colors.Blurple : Colors.Green),
],
});
}
3 changes: 2 additions & 1 deletion src/commands/music/resume.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ export const data = {
};

export function execute(interaction, queue) {
if (queue.node.isPlaying())
if (queue.node.isPlaying()) {
return interaction.reply({
ephemeral: true,
embeds: [ErrorEmbed("The playback is not paused.")],
});
}

queue.node.resume();

Expand Down
Loading

0 comments on commit 2a3f12f

Please sign in to comment.