Skip to content

Commit

Permalink
bot: v3.1.3
Browse files Browse the repository at this point in the history
* discord.js 14.15.2
* cleanups and some changes
  • Loading branch information
nikosszzz committed May 5, 2024
1 parent 0694f06 commit 8d3b413
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 222 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "music-bot",
"version": "3.0.0",
"version": "3.1.2",
"description": "A general music Discord bot.",
"main": "./src/bot.ts",
"repository": {
Expand All @@ -16,11 +16,11 @@
"node": ">=20.0.0"
},
"dependencies": {
"@discordjs/voice": "^0.16.1",
"@discordjs/voice": "^0.17.0",
"array-move": "^3.0.1",
"bufferutil": "^4.0.8",
"chalk": "^4.1.2",
"discord.js": "^14.14.1",
"discord.js": "^14.15.2",
"ffmpeg-static": "^5.2.0",
"lyrics-finder": "^21.7.0",
"opusscript": "^0.1.1",
Expand All @@ -34,9 +34,9 @@
},
"devDependencies": {
"@rollup/plugin-typescript": "^11.1.6",
"@types/node": "^20.12.7",
"@types/node": "^20.12.8",
"esbuild": "^0.20.2",
"rollup": "^4.17.1",
"rollup": "^4.17.2",
"rollup-plugin-esbuild": "^6.1.1",
"rollup-plugin-typescript-paths": "^1.5.0",
"tslib": "^2.6.2",
Expand Down
340 changes: 150 additions & 190 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/commands/info/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default {
.setName("info")
.setDescription("Displays information about the bot."),
async execute(interaction) {

const infoEmbed = new EmbedBuilder()
.setColor("NotQuiteBlack")
.setAuthor({ name: "Music Bot", iconURL: interaction.client.user.avatarURL() ?? undefined })
Expand Down
4 changes: 2 additions & 2 deletions src/commands/music/play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type GuildMember, EmbedBuilder, SlashCommandBuilder, PermissionFlagsBit
import { MusicQueue } from "@components/MusicQueue";
import { Song } from "@components/Song";
import { Logger } from "@components/Logger";
import play from "play-dl";
import { sp_validate, so_validate, yt_validate } from "play-dl";
import type { Command } from "@common/types";

export default {
Expand Down Expand Up @@ -42,7 +42,7 @@ export default {

if (!permissions?.has([PermissionFlagsBits.Connect, PermissionFlagsBits.Speak])) return interaction.reply({ embeds: [botNoPermissions], ephemeral: true });

if (play.yt_validate(url) === "playlist" || await play.so_validate(url) === "playlist" || play.sp_validate(url) === "album" || play.sp_validate(url) === "playlist") {
if (yt_validate(url) === "playlist" || await so_validate(url) === "playlist" || sp_validate(url) === "album" || sp_validate(url) === "playlist") {
return interaction.reply({ content: "Playlist was provided, please use the `playlist` command.", ephemeral: true });
}

Expand Down
5 changes: 0 additions & 5 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ declare module "discord.js" {
}
}

export type AuthTypes = {
TOKEN: string;
CLIENT_ID: string;
};

export type Config = {
TOKEN: string;
DEVTOKEN: string;
Expand Down
6 changes: 3 additions & 3 deletions src/components/Bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import type { Command } from "@common/types";
import { config } from "@components/config";
import { Manager } from "@manager";
import type { MusicQueue } from "@components/MusicQueue";
import play from "play-dl";
import { setToken } from "play-dl";
import { Logger } from "@components/Logger";

export class Bot extends Client {
public commands = new Collection<string, Command>();
public queues = new Collection<string, MusicQueue>();
public readonly debug: boolean = false;
public readonly version: string = "3.1.2";
public readonly version: string = "3.1.3";
public readonly branch: string;

constructor(options: ClientOptions) {
Expand All @@ -20,7 +20,7 @@ export class Bot extends Client {
this.branch = this.debug ? "development" : "stable";

/* Music Authentication */
play.setToken({
setToken({
soundcloud: {
client_id: config.SOUNDCLOUD_CLIENT_ID
},
Expand Down
12 changes: 6 additions & 6 deletions src/components/Playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { CacheType, ChatInputCommandInteraction } from "discord.js";
//@ts-expect-error
import SpotifyUrlInfo, { Tracks } from "spotify-url-info";
import { fetch } from "undici";
import play, { type SoundCloudPlaylist } from "play-dl";
import { sp_validate, so_validate, yt_validate, search as playSearch, soundcloud, type SoundCloudPlaylist } from "play-dl";

export class Playlist {
public readonly data: youtubePlaylist;
Expand All @@ -27,9 +27,9 @@ export class Playlist {
}

public static async from({ url = "", search = "", interaction }: { url: string; search: string; interaction: ChatInputCommandInteraction<CacheType> }): Promise<Playlist> {
const isYoutubeUrl = play.yt_validate(url) === "playlist";
const isSpotifyUrl = ["playlist", "album"].includes(play.sp_validate(url) as string);
const isSoundCloudUrl = await play.so_validate(url) === "playlist";
const isYoutubeUrl = yt_validate(url) === "playlist";
const isSpotifyUrl = ["playlist", "album"].includes(sp_validate(url) as string);
const isSoundCloudUrl = await so_validate(url) === "playlist";

let playlist: youtubePlaylist;
if (isSpotifyUrl) {
Expand All @@ -40,7 +40,7 @@ export class Playlist {
} else if (isYoutubeUrl) {
playlist = await youtube.getPlaylist(url);
} else if (isSoundCloudUrl) {
const scPl = await play.soundcloud(url) as SoundCloudPlaylist;
const scPl = await soundcloud(url) as SoundCloudPlaylist;
const scPlTracks = (await scPl.all_tracks()).map((track) => ({
title: track.name,
url: track.permalink,
Expand All @@ -52,7 +52,7 @@ export class Playlist {
}));
playlist = new youtubePlaylist({ videos: scPlTracks, title: scPl.name, url: scPl.url });
} else {
const result = await play.search(search, {
const result = await playSearch(search, {
source: {
youtube: "playlist"
},
Expand Down
16 changes: 8 additions & 8 deletions src/components/Song.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type AudioResource, createAudioResource } from "@discordjs/voice";
import play, { video_basic_info, stream, type InfoData as videoInfo, type SoundCloud, type SoundCloudTrack, type Spotify, type SpotifyTrack } from "play-dl";
import { yt_validate, sp_validate, so_validate, video_basic_info, stream, spotify, soundcloud, search as playSearch, type InfoData as videoInfo, type SoundCloud, type SoundCloudTrack, type Spotify, type SpotifyTrack } from "play-dl";
import { type ChatInputCommandInteraction, EmbedBuilder, type CacheType } from "discord.js";

export type SongData = {
Expand All @@ -26,19 +26,19 @@ export class Song {
}

public static async from({ url = "", search = "", interaction }: { url: string; search: string; interaction: ChatInputCommandInteraction<CacheType>; }): Promise<Song> {
const isYoutubeUrl = play.yt_validate(url) === "video";
const isSpotifyUrl = play.sp_validate(url) === "track";
const isSoundCloudUrl = await play.so_validate(url) === "track";
const isYoutubeUrl = yt_validate(url) === "video";
const isSpotifyUrl = sp_validate(url) === "track";
const isSoundCloudUrl = await so_validate(url) === "track";

let songInfo: videoInfo | SoundCloud | Spotify;
if (isSpotifyUrl) {
let spotifyTitle: string, spotifyArtist: string;

const spotifyInfo = await play.spotify(url) as SpotifyTrack;
const spotifyInfo = await spotify(url) as SpotifyTrack;
spotifyTitle = spotifyInfo.name;
spotifyArtist = spotifyInfo.artists[0].name;

const spotifyresult = await play.search(`${spotifyArtist} - ${spotifyTitle}`, { limit: 1 });
const spotifyresult = await playSearch(`${spotifyArtist} - ${spotifyTitle}`, { limit: 1 });
songInfo = await video_basic_info(spotifyresult[0].url);

return new this({
Expand All @@ -49,7 +49,7 @@ export class Song {
req: interaction.user.tag
});
} else if (isSoundCloudUrl) {
const scSong = await play.soundcloud(url) as SoundCloudTrack;
const scSong = await soundcloud(url) as SoundCloudTrack;
return new this({
title: scSong.name as string,
url: scSong.permalink,
Expand All @@ -68,7 +68,7 @@ export class Song {
req: interaction.user.tag
});
} else {
const result = await play.search(search, { limit: 1 });
const result = await playSearch(search, { limit: 1 });
songInfo = await video_basic_info(result[0].url);

return new this({
Expand Down
5 changes: 2 additions & 3 deletions src/manager/modules/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { commands as musicCmds } from "commands/music";
import { commands as infoCmds } from "commands/info";
import { commands as utilCmds } from "commands/utility";
import { config } from "@components/config";
import { AuthTypes } from "@common/types";
import { Bot } from "@components/Bot";

export async function ready(client: Bot): Promise<void> {
Expand All @@ -17,7 +16,7 @@ export async function ready(client: Bot): Promise<void> {

async function registerCommands(): Promise<void> {
const commands = [...musicCmds, ...infoCmds, ...utilCmds];
const auth: AuthTypes = {
const auth = {
TOKEN: client.debug ? config.DEVTOKEN : config.TOKEN,
CLIENT_ID: client.debug ? config.DEVID : config.CLIENT_ID,
};
Expand All @@ -43,7 +42,7 @@ export async function ready(client: Bot): Promise<void> {
let state = 0;

setInterval(async () => {
const presences: [{ type: ActivityType.Listening, message: string }] = [
const presences: [{ type: ActivityType, message: string }] = [
{ type: ActivityType.Listening, message: `music.` },
];

Expand Down

0 comments on commit 8d3b413

Please sign in to comment.