Skip to content

Commit

Permalink
feat(music): reenable module
Browse files Browse the repository at this point in the history
  • Loading branch information
NedcloarBR committed Jun 5, 2024
1 parent 30924d3 commit 5a4f320
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"class-validator": "^0.14.1",
"discord-api-types": "^0.37.73",
"discord.js": "^14.14.1",
"ioredis": "^5.3.2",
"ioredis": "^5.4.1",
"lavalink-client": "^2.1.7",
"moment": "^2.30.1",
"necord": "^6.8.3",
Expand Down
2 changes: 2 additions & 0 deletions src/modules/core/NDB.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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 @@ -45,6 +46,7 @@ import { NDBServiceProvider } from "./provider/NDBService.provider";
CommandsModule,
ComponentsModule,
EventsModule,
MusicModule,
ReactionRolesModule,
],
providers: [NDBServiceProvider],
Expand Down
8 changes: 2 additions & 6 deletions src/modules/music/Music.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ export class MusicManager implements OnModuleInit {
private readonly eventEmitter: EventEmitter2,
) {
this.common = new CommonManager(client, config, eventEmitter);
this.premium = new PremiumManager(
client,
config,
eventEmitter,
new RedisClient(),
);
// this.premium = new CommonManager(client, config, eventEmitter);
this.premium = new PremiumManager(client, config, eventEmitter, new RedisClient());
}

public async onModuleInit() {
Expand Down
6 changes: 3 additions & 3 deletions src/modules/music/classes/BaseManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Config } from "@/modules/config/types";
import type {
LavalinkManagerEvents,
NodeManagerEvents,
LavalinkManagerEvents,
NodeManagerEvents,
} from "@/modules/music/types/lavalink-client";
import { Logger } from "@nestjs/common";
import type { ConfigService } from "@nestjs/config";
Expand All @@ -25,7 +25,7 @@ export class BaseManager extends LavalinkManager {
host: process.env.LavalinkHOST,
port: 2333,
authorization: process.env.LAVALINK_SERVER_PASSWORD,
retryAmount: 22,
retryAmount: 4,
retryDelay: 5000,
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/modules/music/classes/CommonManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ConfigService } from "@nestjs/config";
import { EventEmitter2 } from "@nestjs/event-emitter";
import { Client } from "discord.js";
import { BaseManager } from "./BaseManager";
import { BaseManager } from ".";

export class CommonManager extends BaseManager {
public constructor(client: Client, config: ConfigService, eventEmitter: EventEmitter2) {
Expand Down
4 changes: 1 addition & 3 deletions src/modules/music/classes/PremiumManager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { ConfigService } from "@nestjs/config";
import { EventEmitter2 } from "@nestjs/event-emitter";
import { Client } from "discord.js";
import { BaseManager } from "./BaseManager";
import { QueueStore } from "./QueueStore";
import { RedisClient } from "./RedisClient";
import { BaseManager, QueueStore, RedisClient } from ".";

export class PremiumManager extends BaseManager {
public constructor(client: Client, config: ConfigService, eventEmitter: EventEmitter2, redis: RedisClient) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/music/classes/QueueStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { QueueStoreManager, StoredQueue } from "lavalink-client";
import { RedisClient } from "./RedisClient";
import { RedisClient } from ".";

export class QueueStore implements QueueStoreManager {
public constructor(private redis: RedisClient) {}
Expand Down
19 changes: 14 additions & 5 deletions src/modules/music/classes/RedisClient.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { Redis } from "ioredis";
import { Logger } from "@nestjs/common";
import { Cluster } from "ioredis";

export class RedisClient extends Redis {
export class RedisClient extends Cluster {
public constructor() {
super({
port: Number(process.env.RedisPort),
host: process.env.RedisHost,
super([{ host: process.env.RedisHost, port: Number(process.env.RedisPort) }]);

const logger = new Logger(RedisClient.name);
this.ping((err, result) => {
logger.log("Pinging...");
if (err) {
logger.error(`Error when trying to connect: ${err.message}`);
} else {
logger.log(`Response: ${result}`);
}
this.quit();
});
}
}
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4149,9 +4149,9 @@ __metadata:
languageName: node
linkType: hard

"ioredis@npm:^5.3.2":
version: 5.3.2
resolution: "ioredis@npm:5.3.2"
"ioredis@npm:^5.4.1":
version: 5.4.1
resolution: "ioredis@npm:5.4.1"
dependencies:
"@ioredis/commands": "npm:^1.1.1"
cluster-key-slot: "npm:^1.1.0"
Expand All @@ -4162,7 +4162,7 @@ __metadata:
redis-errors: "npm:^1.2.0"
redis-parser: "npm:^3.0.0"
standard-as-callback: "npm:^2.1.0"
checksum: 10c0/0dd2b5b8004e891f5b62edf18ac223194f1f5204698ec827c903e789ea05b0b36f73395491749ec63c66470485bdfb228ccdf1714fbf631a0f78f33211f2c883
checksum: 10c0/5d28b7c89a3cab5b76d75923d7d4ce79172b3a1ca9be690133f6e8e393a7a4b4ffd55513e618bbb5504fed80d9e1395c9d9531a7c5c5c84aa4c4e765cca75456
languageName: node
linkType: hard

Expand Down Expand Up @@ -5227,7 +5227,7 @@ __metadata:
discord-api-types: "npm:^0.37.73"
discord.js: "npm:^14.14.1"
husky: "npm:^9.0.11"
ioredis: "npm:^5.3.2"
ioredis: "npm:^5.4.1"
lavalink-client: "npm:^2.1.7"
lint-staged: "npm:^15.2.2"
moment: "npm:^2.30.1"
Expand Down

0 comments on commit 5a4f320

Please sign in to comment.