Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hwangsihu committed Sep 29, 2024
1 parent 42a4065 commit 7470c0c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
10 changes: 7 additions & 3 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"files": {
"ignoreUnknown": true,
"ignore": ["node_modules/", "dist", "package.json", "tsconfig.json", ".vscode"]
"ignore": [".vscode", "dist", "node_modules", "package.json", "tsconfig.json"]
},
"formatter": {
"enabled": true,
Expand All @@ -24,11 +24,15 @@
"linter": {
"enabled": true,
"rules": {
"recommended": false,
"all": true,
"complexity": {
"noBannedTypes": "off",
"noExcessiveCognitiveComplexity": "off",
"noExcessiveCognitiveComplexity": {
"level": "warn",
"options": {
"maxAllowedComplexity": 30
}
},
"noForEach": "off",
"noUselessConstructor": "off"
},
Expand Down
4 changes: 2 additions & 2 deletions src/events/node/Connect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { LavalinkNode } from 'lavalink-client';
import { Event, type Lavamusic } from '../../structures/index';
import BotLog from '../../utils/BotLog';
import { sendLog } from '../../utils/BotLog';

export default class Connect extends Event {
constructor(client: Lavamusic, file: string) {
Expand Down Expand Up @@ -48,7 +48,7 @@ export default class Connect extends Event {
}, index * 1000);
});

BotLog.send(this.client, `Node ${node.id} is ready!`, 'success');
sendLog(this.client, `Node ${node.id} is ready!`, 'success');
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/events/node/Destroy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { DestroyReasonsType, LavalinkNode } from 'lavalink-client';
import { Event, type Lavamusic } from '../../structures/index';
import BotLog from '../../utils/BotLog';
import { sendLog } from '../../utils/BotLog';

export default class Destroy extends Event {
constructor(client: Lavamusic, file: string) {
Expand All @@ -11,7 +11,7 @@ export default class Destroy extends Event {

public async run(node: LavalinkNode, destroyReason?: DestroyReasonsType): Promise<void> {
this.client.logger.success(`Node ${node.id} is destroyed!`);
BotLog.send(this.client, `Node ${node.id} is destroyed: ${destroyReason}`, 'warn');
sendLog(this.client, `Node ${node.id} is destroyed: ${destroyReason}`, 'warn');
}
}

Expand Down
36 changes: 19 additions & 17 deletions src/utils/BotLog.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import type { TextChannel } from 'discord.js';
import type { Lavamusic } from '../structures/index';

export default class BotLog {
public static send(client: Lavamusic, message: string, type: 'error' | 'warn' | 'info' | 'success' = 'info'): void {
if (!client?.channels.cache && client.env.LOG_CHANNEL_ID) return;
export function sendLog(
client: Lavamusic,
message: string,
type: 'error' | 'warn' | 'info' | 'success' = 'info',
): void {
if (!client?.channels.cache && client.env.LOG_CHANNEL_ID) return;

const channel = client.channels.cache.get(client.env.LOG_CHANNEL_ID!) as TextChannel;
if (!channel) return;
const channel = client.channels.cache.get(client.env.LOG_CHANNEL_ID!) as TextChannel;
if (!channel) return;

const colors = {
error: 0xff0000,
warn: 0xffff00,
info: 0x00ff00,
success: 0x00ff00,
} as const;
const colors = {
error: 0xff0000,
warn: 0xffff00,
info: 0x00ff00,
success: 0x00ff00,
} as const;

const color = colors[type];
const embed = client.embed().setColor(color).setDescription(message).setTimestamp();
const color = colors[type];
const embed = client.embed().setColor(color).setDescription(message).setTimestamp();

channel.send({ embeds: [embed] }).catch(() => {
null;
});
}
channel.send({ embeds: [embed] }).catch(() => {
null;
});
}

/**
Expand Down

0 comments on commit 7470c0c

Please sign in to comment.