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 930e7ce
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 31 deletions.
11 changes: 8 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 All @@ -51,6 +55,7 @@
"noAssignInExpressions": "off",
"noAsyncPromiseExecutor": "off",
"noConfusingVoidType": "off",
"noEmptyBlockStatements": "off",
"noEmptyInterface": "off",
"noExplicitAny": "off",
"noThenProperty": "off",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/247.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class _247 extends Command {
embeds: [embed.setDescription(ctx.locale('cmd.247.messages.enabled')).setColor(this.client.color.main)],
});
} catch (error) {
console.error('Error in 247 command:', error);
client.logger.error('Error in 247 command:', error);
return await ctx.sendMessage({
embeds: [embed.setDescription(ctx.locale('cmd.247.errors.generic')).setColor(client.color.red)],
});
Expand Down
8 changes: 4 additions & 4 deletions src/commands/dev/Deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class Deploy extends Command {
components: [row],
});
} catch (error) {
console.error('Failed to send the initial message:', error);
client.logger.error('Failed to send the initial message:', error);
return;
}

Expand All @@ -62,7 +62,7 @@ export default class Deploy extends Command {
content: "You can't interact with this message",
ephemeral: true,
})
.catch(console.error);
.catch(client.logger.error);
return false;
}
return true;
Expand Down Expand Up @@ -90,7 +90,7 @@ export default class Deploy extends Command {
});
}
} catch (error) {
console.error('Failed to handle interaction:', error);
client.logger.error('Failed to handle interaction:', error);
}
});

Expand All @@ -99,7 +99,7 @@ export default class Deploy extends Command {
try {
await msg.delete();
} catch (error) {
console.error('Failed to delete the message:', error);
client.logger.error('Failed to delete the message:', error);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/events/client/InteractionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export default class InteractionCreate extends Event {
try {
await command.autocomplete(interaction);
} catch (error) {
console.error(error);
client.logger.error(error);
}
}
}
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
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"lib": ["ESNext", "WebWorker"],
"moduleResolution": "node",
"declaration": true,
"sourceMap": false,
"strict": true,
"esModuleInterop": true,
"experimentalDecorators": true,
Expand Down

0 comments on commit 930e7ce

Please sign in to comment.