Skip to content

Commit

Permalink
feat(music): add more music control commands
Browse files Browse the repository at this point in the history
  • Loading branch information
NedcloarBR committed Oct 30, 2023
1 parent 647b22a commit 20c4e6e
Show file tree
Hide file tree
Showing 34 changed files with 419 additions and 147 deletions.
28 changes: 28 additions & 0 deletions Packages/Client/Src/Commands/🎵 Music/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,34 @@ export default class MusicCategoryCommand extends BaseCommand {
"The bot enter in you voice channel and initialize an player",
descriptionLocalizations: Localization.options.join.description,
type: ApplicationCommandOptionType.Subcommand
},
{
name: "leave",
nameLocalizations: Localization.options.leave.name,
description: "leaves from voice channel",
descriptionLocalizations: Localization.options.leave.description,
type: ApplicationCommandOptionType.Subcommand
},
{
name: "pause",
nameLocalizations: Localization.options.pause.name,
description: "Pause the music queue",
descriptionLocalizations: Localization.options.pause.description,
type: ApplicationCommandOptionType.Subcommand
},
{
name: "resume",
nameLocalizations: Localization.options.resume.name,
description: "Resume the music queue",
descriptionLocalizations: Localization.options.resume.description,
type: ApplicationCommandOptionType.Subcommand
},
{
name: "stop",
nameLocalizations: Localization.options.stop.name,
description: "Stop the music queue",
descriptionLocalizations: Localization.options.stop.description,
type: ApplicationCommandOptionType.Subcommand
}
]
},
Expand Down
9 changes: 7 additions & 2 deletions Packages/Client/Src/Commands/🎵 Music/Join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ export default class JoinCommand extends BaseCommand {
},
nsfw: false,
ndcash: 0,
DM: false
DM: false,
slash: {
type: "Sub",
name: "join"
}
};
super(client, options);
}

async run(context: Context) {
await new Music(context.client).Join(context);
const music = new Music();
context.reply(await music.Join(context));
}
}
39 changes: 39 additions & 0 deletions Packages/Client/Src/Commands/🎵 Music/Leave.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Music from "@/Modules/Music";
import { CommandOptions, INDBClient } from "@/Types";
import { BaseCommand, Context } from "@/Utils/Structures";

export default class LeaveCommand extends BaseCommand {
public constructor(protected client: INDBClient) {
const options: CommandOptions = {
name: "leave",
aliases: ["sair"],
description: "Disconnect's the bot from Voice Channel",
category: "🎵 Music",
usage: "",
disable: false,
cooldown: 0,
permissions: {
bot: ["SendMessages"],
user: ["SendMessages"],
guildOnly: false,
ownerOnly: false
},
minArgs: 0,
maxArgs: 0,
nsfw: false,
ndcash: 0,
DM: false,
slash: {
type: "Sub",
name: "leave"
}
};
super(client, options);
}

public async run(context: Context) {
const music = new Music();
const leave = await music.Leave(context);
return context.reply(leave);
}
}
2 changes: 1 addition & 1 deletion Packages/Client/Src/Commands/🎵 Music/NowPlaying.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class NowPlayingCommand extends BaseCommand {

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async run(context: Context) {
const music = new Music(context.client);
const music = new Music();
const nowplaying = await music.NowPlaying(context);
await context.reply(nowplaying);
}
Expand Down
39 changes: 39 additions & 0 deletions Packages/Client/Src/Commands/🎵 Music/Pause.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Music from "@/Modules/Music";
import { CommandOptions, INDBClient } from "@/Types";
import { BaseCommand, Context } from "@/Utils/Structures";

export default class PauseCommand extends BaseCommand {
public constructor(protected client: INDBClient) {
const options: CommandOptions = {
name: "pause",
aliases: ["pausar"],
description: "Pauses the music Queue",
category: "🎵 Music",
usage: "",
disable: false,
cooldown: 0,
permissions: {
bot: ["SendMessages"],
user: ["SendMessages"],
guildOnly: false,
ownerOnly: false
},
minArgs: 0,
maxArgs: 0,
nsfw: false,
ndcash: 0,
DM: false,
slash: {
type: "Sub",
name: "pause"
}
};
super(client, options);
}

public async run(context: Context) {
const music = new Music();
const pause = await music.Pause(context);
return context.reply(pause);
}
}
2 changes: 1 addition & 1 deletion Packages/Client/Src/Commands/🎵 Music/Play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class PlayCommand extends BaseCommand {
}

async run(context: Context) {
const music = new Music(context.client);
const music = new Music();
const play = await music.Play(context);
context.reply(play);
}
Expand Down
39 changes: 39 additions & 0 deletions Packages/Client/Src/Commands/🎵 Music/Resume.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Music from "@/Modules/Music";
import { CommandOptions, INDBClient } from "@/Types";
import { BaseCommand, Context } from "@/Utils/Structures";

export default class ResumeCommand extends BaseCommand {
public constructor(protected client: INDBClient) {
const options: CommandOptions = {
name: "resume",
aliases: ["resumir"],
description: "Resumes the music Queue",
category: "🎵 Music",
usage: "",
disable: false,
cooldown: 0,
permissions: {
bot: ["SendMessages"],
user: ["SendMessages"],
guildOnly: false,
ownerOnly: false
},
minArgs: 0,
maxArgs: 0,
nsfw: false,
ndcash: 0,
DM: false,
slash: {
type: "Sub",
name: "resume"
}
};
super(client, options);
}

public async run(context: Context) {
const music = new Music();
const resume = await music.Resume(context);
return context.reply(resume);
}
}
36 changes: 36 additions & 0 deletions Packages/Client/Src/Commands/🎵 Music/Stop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Music from "@/Modules/Music";
import { CommandOptions, INDBClient } from "@/Types";
import { BaseCommand, Context } from "@/Utils/Structures";

export default class StopCommand extends BaseCommand {
constructor(client: INDBClient) {
const options: CommandOptions = {
name: "stop",
aliases: ["parar"],
description: "Stops the music queue",
category: "🎵 Music",
usage: "",
disable: false,
cooldown: 0,
permissions: {
bot: ["SendMessages"],
user: ["SendMessages"],
guildOnly: false,
ownerOnly: false
},
nsfw: false,
ndcash: 0,
DM: false,
slash: {
type: "Sub",
name: "stop"
}
};
super(client, options);
}

async run(context: Context) {
const music = new Music();
context.reply(await music.Stop(context));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default class TestCommand extends BaseCommand {
}

async run(context: Context) {
console.log(context);
const embeds = [];
for (let i = 0; i < 10; i++) {
embeds.push(new EmbedBuilder().setDescription(`Embed: ${i + 1}`));
Expand Down
4 changes: 1 addition & 3 deletions Packages/Client/Src/Events/Custom/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ export default class CommandEvent extends BaseEvent {
client,
message,
args as Array<string>,
(
await this.client.database.GuildRepo.get(message.guildId)
).Settings.Premium,
(await client.database.GuildRepo.get(message.guildId)).Settings.Premium,
"None"
);
const _Command: BaseCommand = client.Tools.resolveCommand(cmd);
Expand Down
4 changes: 2 additions & 2 deletions Packages/Client/Src/Events/Guild/GuildCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EventOptions, INDBClient } from "@/Types";
import { BaseEvent } from "@/Utils/Structures";
import { Guild } from "discord.js";

module.exports = class GuildCreateEvent extends BaseEvent {
export default class GuildCreateEvent extends BaseEvent {
constructor(client: INDBClient) {
const options: EventOptions = {
name: "guildCreate",
Expand All @@ -18,4 +18,4 @@ module.exports = class GuildCreateEvent extends BaseEvent {
const guildRepository = client.database.GuildRepo;
await guildRepository.create(guild);
}
};
}
4 changes: 2 additions & 2 deletions Packages/Client/Src/Events/Guild/GuildDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EventOptions, INDBClient } from "@/Types";
import { BaseEvent } from "@/Utils/Structures";
import { Guild } from "discord.js";

module.exports = class GuildDeleteEvent extends BaseEvent {
export default class GuildDeleteEvent extends BaseEvent {
constructor(client: INDBClient) {
const options: EventOptions = {
name: "guildDelete",
Expand All @@ -26,4 +26,4 @@ module.exports = class GuildDeleteEvent extends BaseEvent {

await client.database.GuildRepo.delete(guild);
}
};
}
4 changes: 2 additions & 2 deletions Packages/Client/Src/Events/Guild/GuildUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EventOptions, INDBClient } from "@/Types";
import { BaseEvent } from "@/Utils/Structures";
import { Guild } from "discord.js";

module.exports = class GuildUpdateEvent extends BaseEvent {
export default class GuildUpdateEvent extends BaseEvent {
constructor(client: INDBClient) {
const options: EventOptions = {
name: "guildUpdate",
Expand All @@ -17,4 +17,4 @@ module.exports = class GuildUpdateEvent extends BaseEvent {
async run(client: INDBClient, oldGuild: Guild, newGuild: Guild) {
await client.database.GuildRepo.update(oldGuild, newGuild);
}
};
}
4 changes: 2 additions & 2 deletions Packages/Client/Src/Events/Music/VoiceStateUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
VoiceState
} from "discord.js";

module.exports = class VoiceStateUpdateEvent extends BaseEvent {
export default class VoiceStateUpdateEvent extends BaseEvent {
constructor(client: INDBClient) {
const options: EventOptions = {
name: "voiceStateUpdate",
Expand Down Expand Up @@ -182,4 +182,4 @@ module.exports = class VoiceStateUpdateEvent extends BaseEvent {
}
}
}
};
}
13 changes: 12 additions & 1 deletion Packages/Client/Src/Events/Process/beforeExit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { BaseEvent } from "@/Utils/Structures";
export default class beforeExitEvent extends BaseEvent {
constructor(client: INDBClient) {
const options: EventOptions = {
name: "beforeExit",
name: "process",
names: ["beforeExit", "SIGKILL", "SIGINT", "SIGTERM"],
type: "on",
emitter: "process",
enable: false
Expand All @@ -14,6 +15,16 @@ export default class beforeExitEvent extends BaseEvent {
}

async run(client: INDBClient, code) {
try {
const logger = client.logger;
client.removeAllListeners();
await client.database.Disconnect("Before Exit Event");
await client.destroy();
logger.info("Cleanup complete. Exiting...");
process.exit(0);
} catch (error) {
client.logger.error(`Error during termination: ${error}`);
}
client.logger.process("Before Exit", `Code: ${code}`);
}
}
3 changes: 2 additions & 1 deletion Packages/Client/Src/Events/Process/uncaughtException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { BaseEvent } from "@/Utils/Structures";
export default class uncaughtExceptionEvent extends BaseEvent {
constructor(client: INDBClient) {
const options: EventOptions = {
name: "uncaughtException",
name: "process",
names: ["uncaughtException"],
type: "on",
emitter: "process",
enable: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { BaseEvent } from "@/Utils/Structures";
export default class uncaughtExceptionMonitorEvent extends BaseEvent {
constructor(client: INDBClient) {
const options: EventOptions = {
name: "uncaughtExceptionMonitor",
name: "process",
names: ["uncaughtExceptionMonitor"],
type: "on",
emitter: "process",
enable: false
Expand Down
3 changes: 2 additions & 1 deletion Packages/Client/Src/Events/Process/unhandledRejection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { BaseEvent } from "@/Utils/Structures";
export default class unhandledRejectionEvent extends BaseEvent {
constructor(client: INDBClient) {
const options: EventOptions = {
name: "unhandledRejection",
name: "process",
names: ["unhandledRejection"],
type: "on",
emitter: "process",
enable: false
Expand Down
Loading

0 comments on commit 20c4e6e

Please sign in to comment.