Skip to content

Commit

Permalink
Merge pull request #134 from WillKirkmanM/convert_to_esm
Browse files Browse the repository at this point in the history
Converted to ESM (ES6 Standard)
  • Loading branch information
elbkr authored Jan 13, 2023
2 parents 4c20a2c + dcfbbec commit 0e8dd3e
Show file tree
Hide file tree
Showing 49 changed files with 4,181 additions and 2,595 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require("dotenv").config();
require("./src/utils/Types")();
import "dotenv/config";
import Types from "./src/utils/Types.js";
Types()

/* Import our client structure */
const Bot = require("./src/struct/Bot");
const client = new Bot();
import Bot from "./src/struct/Bot.js";
export const client = new Bot();

/* Call our start function to load the bot instance */
(async () => await client.start(process.env.TOKEN))();
6,532 changes: 4,054 additions & 2,478 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "music-bot",
"version": "1.0.0",
"description": "discord.js music bot w/mongoDB",
"type": "module",
"main": "index.js",
"engines": {
"node": "16.x"
Expand Down Expand Up @@ -29,16 +30,15 @@
"homepage": "https://github.com/elbkr/music-bot#readme",
"dependencies": {
"@discordjs/opus": "^0.8.0",
"@discordjs/rest": "^1.0.0",
"bufferutil": "^4.0.6",
"chalk": "^4.0.0",
"discord-api-types": "^0.36.2",
"discord-music-player": "^9.0.2",
"discord.js": "^14.0.3",
"discordjs-button-pagination": "^3.0.1",
"dotenv": "^16.0.1",
"fs": "^0.0.1-security",
"glob": "^7.2.0",
"isomorphic-unfetch": "^4.0.2",
"moment": "^2.29.4",
"mongoose": "^6.4.5",
"pretty-ms": "^8.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/announce.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class Announce extends Interaction {
export default class Announce extends Interaction {
constructor() {
super({
name: "announce",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/roles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class Roles extends Interaction {
export default class Roles extends Interaction {
constructor() {
super({
name: "roles",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/voice.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class Voice extends Interaction {
export default class Voice extends Interaction {
constructor() {
super({
name: "voice",
Expand Down
6 changes: 3 additions & 3 deletions src/commands/favorite/favorite.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const paginationEmbed = require("../../utils/Pagination");
const users = require("../../models/Users")
import paginationEmbed from "../../utils/Pagination.js";
import users from "../../models/Users.js";

module.exports = class Fav extends Interaction {
export default class Fav extends Interaction {
constructor() {
super({
name: "fav",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/jump.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class Jump extends Interaction {
export default class Jump extends Interaction {
constructor() {
super({
name: "jump",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/last.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class Last extends Interaction {
export default class Last extends Interaction {
constructor() {
super({
name: "last",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/music/loop.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {RepeatMode} = require("discord-music-player");
import { RepeatMode } from "discord-music-player";

module.exports = class Loop extends Interaction {
export default class Loop extends Interaction {
constructor() {
super({
name: "loop",
Expand Down
8 changes: 4 additions & 4 deletions src/commands/music/nowplaying.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const sf = require("seconds-formater");
const {progressBar} = require("../../player/functions/progress-bar");
const {msToSeconds} = require("../../utils/Utils");
import sf from "seconds-formater";
import progressBar from "../../player/functions/progress-bar/index.js";
import msToSeconds from "../../utils/Utils.js";

module.exports = class NowPlaying extends Interaction {
export default class NowPlaying extends Interaction {
constructor() {
super({
name: "nowplaying",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/pause.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class Pause extends Interaction {
export default class Pause extends Interaction {
constructor() {
super({
name: "pause",
Expand Down
8 changes: 4 additions & 4 deletions src/commands/music/play.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {sourceTest, testPlaylist} = require("../../utils/Utils")
import Util from "../../utils/Utils.js";

module.exports = class Play extends Interaction {
export default class Play extends Interaction {
constructor() {
super({
name: "play",
Expand Down Expand Up @@ -69,8 +69,8 @@ module.exports = class Play extends Interaction {
});
}

let source = await sourceTest(song);
let isPlaylist = testPlaylist(song);
let source = await Util.sourceTest(song);
let isPlaylist = Util.testPlaylist(song);

if (isPlaylist) {
return this.client.play(
Expand Down
8 changes: 4 additions & 4 deletions src/commands/music/playlist.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {sourceTest, testPlaylist} = require("../../utils/Utils");
import Util from "../../utils/Utils.js";

module.exports = class Playlist extends Interaction {
export default class Playlist extends Interaction {
constructor() {
super({
name: "playlist",
Expand Down Expand Up @@ -62,8 +62,8 @@ module.exports = class Playlist extends Interaction {
}


let source = await sourceTest(playlist);
let isPlaylist = testPlaylist(playlist);
let source = await Util.sourceTest(playlist);
let isPlaylist = Util.testPlaylist(playlist);

if (!isPlaylist)
return int.reply({
Expand Down
4 changes: 2 additions & 2 deletions src/commands/music/queue.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const paginationEmbed = require("../../utils/Pagination");
import paginationEmbed from "../../utils/Pagination.js";

module.exports = class Queue extends Interaction {
export default class Queue extends Interaction {
constructor() {
super({
name: "queue",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/replay.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class Replay extends Interaction {
export default class Replay extends Interaction {
constructor() {
super({
name: "replay",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/music/search.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const DMP = require("discord-music-player");
import DMP from "discord-music-player";

module.exports = class Search extends Interaction {
export default class Search extends Interaction {
constructor() {
super({
name: "search",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/shuffle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class Shuffle extends Interaction {
export default class Shuffle extends Interaction {
constructor() {
super({
name: "shuffle",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/skip.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class Skip extends Interaction {
export default class Skip extends Interaction {
constructor() {
super({
name: "skip",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/stop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class Stop extends Interaction {
export default class Stop extends Interaction {
constructor() {
super({
name: "stop",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/volume.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class Volume extends Interaction {
export default class Volume extends Interaction {
constructor() {
super({
name: "volume",
Expand Down
7 changes: 1 addition & 6 deletions src/events/client/ready.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class Ready extends Event {
export default class Ready extends Event {
constructor() {
super({
name: "ready",
Expand All @@ -17,11 +17,6 @@ module.exports = class Ready extends Event {
});

let allChannels = new Set();
this.client.guilds.cache.forEach((guild) => {
guild.channels.cache.forEach((channel) => {
allChannels.add(channel.id);
});
});
this.client.logger.log(`Connected into ${this.client.user.tag}`, {
tag: "Ready",
});
Expand Down
2 changes: 1 addition & 1 deletion src/events/guild/channelDelete.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class ChannelDelete extends Event {
export default class ChannelDelete extends Event {
constructor() {
super({
name: "channelDelete",
Expand Down
2 changes: 1 addition & 1 deletion src/events/guild/guildCreate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class GuildCreate extends Event {
export default class GuildCreate extends Event {
constructor() {
super({
name: "guildCreate",
Expand Down
2 changes: 1 addition & 1 deletion src/events/guild/guildDelete.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class GuildDelete extends Event {
export default class GuildDelete extends Event {
constructor() {
super({
name: "guildDelete",
Expand Down
2 changes: 1 addition & 1 deletion src/events/guild/roleDelete.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class RoleDelete extends Event {
export default class RoleDelete extends Event {
constructor() {
super({
name: "roleDelete",
Expand Down
2 changes: 1 addition & 1 deletion src/events/interactions/interactionCreate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class InteractionCreate extends Event {
export default class InteractionCreate extends Event {
constructor() {
super({
name: "interactionCreate",
Expand Down
2 changes: 1 addition & 1 deletion src/events/interactions/slashCommands.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class SlashCommands extends Event {
export default class SlashCommands extends Event {
constructor() {
super({
name: "slashCommands",
Expand Down
4 changes: 2 additions & 2 deletions src/models/Guilds.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {Schema, model} = require("mongoose");
import {Schema, model} from "mongoose";

module.exports = model(
export default model(
"Guilds",
new Schema(
{
Expand Down
4 changes: 2 additions & 2 deletions src/models/Users.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {Schema, model} = require("mongoose");
import {Schema, model} from "mongoose";

module.exports = model(
export default model(
"Users",
new Schema(
{
Expand Down
2 changes: 1 addition & 1 deletion src/player/events/channelEmpty.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class ChannelEmpty extends Event {
export default class ChannelEmpty extends Event {
constructor() {
super({
name: "channelEmpty",
Expand Down
7 changes: 4 additions & 3 deletions src/player/events/playlistAdd.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const {msToSeconds} = require("../../utils/Utils");
const sf = require("seconds-formater");
import Util from "../../utils/Utils.js";
const { msToSeconds } = Util
import sf from "seconds-formater";

module.exports = class PlaylistAdd extends Event {
export default class PlaylistAdd extends Event {
constructor() {
super({
name: "playlistAdd",
Expand Down
2 changes: 1 addition & 1 deletion src/player/events/queueDestroyed.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class QueueDestroyed extends Event {
export default class QueueDestroyed extends Event {
constructor() {
super({
name: "queueDestroyed",
Expand Down
2 changes: 1 addition & 1 deletion src/player/events/queueEnd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class QueueEnd extends Event {
export default class QueueEnd extends Event {
constructor() {
super({
name: "queueEnd",
Expand Down
9 changes: 5 additions & 4 deletions src/player/events/songAdd.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const {msToSeconds} = require("../../utils/Utils");
const sf = require("seconds-formater");
const {MessageEmbed} = require("discord.js");
import Util from "../../utils/Utils.js";
const { msToSeconds } = Util
import sf from "seconds-formater";
import { EmbedBuilder } from "discord.js";

module.exports = class SongAdd extends Event {
export default class SongAdd extends Event {
constructor() {
super({
name: "songAdd",
Expand Down
2 changes: 1 addition & 1 deletion src/player/events/songChanged.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class SongChanged extends Event {
export default class SongChanged extends Event {
constructor() {
super({
name: "songChanged",
Expand Down
2 changes: 1 addition & 1 deletion src/player/events/songFirst.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = class SongFirst extends Event {
export default class SongFirst extends Event {
constructor() {
super({
name: "songFirst",
Expand Down
2 changes: 1 addition & 1 deletion src/player/functions/play.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = async function play(
export default async function play(
client,
int,
data,
Expand Down
4 changes: 1 addition & 3 deletions src/player/functions/progress-bar/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
declare function progressBar(total: number, current: number, size?: number, empty?: string, line?: string, slider?: string, slider2?: string): Array<string>

export {progressBar}
export declare function progressBar(total: number, current: number, size?: number, empty?: string, line?: string, slider?: string, slider2?: string): Array<string>
5 changes: 1 addition & 4 deletions src/player/functions/progress-bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,4 @@ const progressBar = (total, current, size = 40, empty = '▬', line = '▬', sli
}
};


module.exports = {
progressBar
};
export default progressBar;
19 changes: 10 additions & 9 deletions src/player/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const {Player} = require("discord-music-player");
const play = require("./functions/play");
const {sync} = require("glob");
const {resolve} = require("path");
import { Player } from "discord-music-player";
import play from "./functions/play.js";
import pkg from "glob"
const { sync } = pkg
import { resolve } from "path";
import { pathToFileURL } from "url";

async function player(client) {
export default async function player(client) {
client.player = new Player(client, {
leaveOnEmpty: false,
deafenOnJoin: true,
Expand All @@ -15,8 +17,9 @@ async function player(client) {
client.play = play;

const evtFile = await sync(resolve("./src/player/events/*.js"));
evtFile.forEach((filepath) => {
const File = require(filepath);
evtFile.forEach(async (filepath) => {
filepath = pathToFileURL(filepath)
const File = await import(filepath);
if (!(File.prototype instanceof Event)) return;
const event = new File();

Expand All @@ -32,5 +35,3 @@ async function player(client) {
);
});
}

module.exports = player;
Loading

0 comments on commit 0e8dd3e

Please sign in to comment.