Skip to content

Commit

Permalink
feat: (re)disable Music module
Browse files Browse the repository at this point in the history
  • Loading branch information
NedcloarBR committed May 18, 2024
1 parent b9c72d4 commit a7e8e4b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 98 deletions.
2 changes: 0 additions & 2 deletions src/modules/core/NDB.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { JSONLocaleLoader, NecordConfigService, config } from "../config";
import type { Config } from "../config/types";
import { DatabaseModule } from "../database/database.module";
import { EventsModule } from "../events/Events.module";
import { MusicModule } from "../music";
import { ReactionRolesModule } from "../reactionRoles/ReactionRoles.module";
import { ScheduleModule } from "../schedule/schedule.module";
import { NDBServiceProvider } from "./provider/NDBService.provider";
Expand Down Expand Up @@ -43,7 +42,6 @@ import { NDBServiceProvider } from "./provider/NDBService.provider";
}),
DatabaseModule,
ScheduleModule,
MusicModule,
CommandsModule,
ComponentsModule,
EventsModule,
Expand Down
123 changes: 27 additions & 96 deletions src/modules/music/Music.service.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import type { Config } from "@/modules/config/types";
import type { IDatabaseService } from "@/modules/database/interfaces/IDatabaseService";
import { Services } from "@/types/Constants";
import {
LOCALIZATION_ADAPTER,
NestedLocalizationAdapter,
} from "@necord/localization";
import { LOCALIZATION_ADAPTER, NestedLocalizationAdapter } from "@necord/localization";
import { Inject, Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import {
channelMention,
type CommandInteraction,
type GuildMember,
type VoiceChannel,
} from "discord.js";
import { type CommandInteraction, type GuildMember, type VoiceChannel, channelMention } from "discord.js";
import type { Player, PlayerOptions, SourceNames } from "lavalink-client";
import moment from "moment";
import ms from "parse-ms";
import type { MusicEmbeds } from "./Music.embeds";
import type { MusicManager } from "./Music.manager";
import { MusicEmbeds } from "./Music.embeds";
import { MusicManager } from "./Music.manager";
import type { IMusicService } from "./interfaces";
import { Music } from "./types/constants";

Expand All @@ -39,10 +31,7 @@ export class MusicService implements IMusicService {
return this.MusicManager.common.getPlayer(interaction.guildId);
}

public async getPlayerEvent(
guildId: string,
isPremium: boolean,
): Promise<Player> {
public async getPlayerEvent(guildId: string, isPremium: boolean): Promise<Player> {
if (isPremium) {
return this.MusicManager.premium.getPlayer(guildId);
}
Expand All @@ -59,14 +48,13 @@ export class MusicService implements IMusicService {
guildId: voiceChannel.guildId,
textChannelId: textChannelId,
voiceChannelId: voiceChannel.id,
selfDeaf:
this.config.getOrThrow<Config["Music"]>("Music").Client.selfDeaf,
selfDeaf: this.config.getOrThrow<Config["Music"]>("Music").Client.selfDeaf,
instaUpdateFiltersFix: false,
volume: this.config.getOrThrow<Config["Music"]>("Music").Volumes.Player,
// vcRegion: voiceChannel.rtcRegion!
};
let player: Player;
if (this.getPremium(interaction.guildId)) {
if (await this.getPremium(interaction.guildId)) {
player = this.MusicManager.premium.createPlayer(createOptions);
player.isPremium = true;
} else {
Expand All @@ -90,23 +78,14 @@ export class MusicService implements IMusicService {

public async sameVoice(interaction: CommandInteraction): Promise<boolean> {
const player = await this.getPlayer(interaction);
const voiceChannel = await interaction.guild.channels.fetch(
player.voiceChannelId,
);
const voiceChannel = await interaction.guild.channels.fetch(player.voiceChannelId);

if (
(interaction.member as GuildMember).voice.channelId !==
player.voiceChannelId
) {
if ((interaction.member as GuildMember).voice.channelId !== player.voiceChannelId) {
await interaction.reply(
this.translate.getTranslation(
"Tools.Music.WrongChannel",
interaction.guildLocale,
{
TextChannel: channelMention(player.textChannelId),
VoiceChannel: channelMention(voiceChannel.id),
},
),
this.translate.getTranslation("Tools.Music.WrongChannel", interaction.guildLocale, {
TextChannel: channelMention(player.textChannelId),
VoiceChannel: channelMention(voiceChannel.id),
}),
);
return false;
}
Expand Down Expand Up @@ -148,8 +127,7 @@ export class MusicService implements IMusicService {
Name: string;
}> {
const URLs = this.config.getOrThrow<Config["URLList"]>("URLList").Music;
const MusicEmojis =
this.config.getOrThrow<Config["Emojis"]>("Emojis").Music;
const MusicEmojis = this.config.getOrThrow<Config["Emojis"]>("Emojis").Music;
let Emoji: string;
let Name: string;

Expand All @@ -170,23 +148,17 @@ export class MusicService implements IMusicService {

for (const value of Props) {
if (isCommand) {
if (
(
(query as CommandInteraction).options.get("query").value as string
).includes(value.URL)
) {
if (((query as CommandInteraction).options.get("query").value as string).includes(value.URL)) {
Emoji = value.Emoji;
Name = value.Name;
break;
}
Emoji = MusicEmojis.Youtube;
Name = "Youtube";
} else {
if ((query as string).includes(value.URL)) {
Emoji = value.Emoji;
Name = value.Name;
break;
}
} else if (!isCommand && (query as string).includes(value.URL)) {
Emoji = value.Emoji;
Name = value.Name;
break;
}
}
return { Emoji, Name };
Expand All @@ -195,56 +167,15 @@ export class MusicService implements IMusicService {
public async progressBar(player: Player): Promise<string> {
const time = ms(player.queue.current.info.duration);
const done = ms(player.position);
const D1 = `[${
done.hours ? (done.hours > 10 ? done.hours : `0${done.hours}`) : ""
}${
done.minutes
? done.minutes >= 10
? done.minutes
: `0${done.minutes}`
: "00"
}:${
done.seconds
? done.seconds > 10
? done.seconds
: `0${done.seconds}`
: ""
}] `;
const D2 = ` [${
time.hours ? (time.hours > 10 ? time.hours : `0${time.hours}`) : ""
}${time.hours ? ":" : ""}${
time.minutes
? time.minutes >= 10
? time.minutes
: `0${time.minutes}`
: "00"
}:${
time.seconds
? time.seconds > 10
? time.seconds
: `0${time.seconds}`
: ""
}]`;
const D1 = `[${done.hours ? (done.hours > 10 ? done.hours : `0${done.hours}`) : ""}${
done.minutes ? (done.minutes >= 10 ? done.minutes : `0${done.minutes}`) : "00"
}:${done.seconds ? (done.seconds > 10 ? done.seconds : `0${done.seconds}`) : ""}] `;
const D2 = ` [${time.hours ? (time.hours > 10 ? time.hours : `0${time.hours}`) : ""}${time.hours ? ":" : ""}${
time.minutes ? (time.minutes >= 10 ? time.minutes : `0${time.minutes}`) : "00"
}:${time.seconds ? (time.seconds > 10 ? time.seconds : `0${time.seconds}`) : ""}]`;
const D3 = moment.duration({ ms: player.position }).asMilliseconds();
const progressBar = [
"▬",
"▬",
"▬",
"▬",
"▬",
"▬",
"▬",
"▬",
"▬",
"▬",
"▬",
"▬",
"▬",
"▬",
];
const calcul = Math.round(
progressBar.length * (D3 / player.queue.current.info.duration),
);
const progressBar = ["▬", "▬", "▬", "▬", "▬", "▬", "▬", "▬", "▬", "▬", "▬", "▬", "▬", "▬"];
const calcul = Math.round(progressBar.length * (D3 / player.queue.current.info.duration));
progressBar[calcul] = "🔘";
return D1 + progressBar.join("") + D2;
}
Expand Down

0 comments on commit a7e8e4b

Please sign in to comment.