Skip to content

Commit 78df25b

Browse files
committed
Refactor code style and fix minor bugs
1 parent 4b9aaa5 commit 78df25b

File tree

7 files changed

+17
-12
lines changed

7 files changed

+17
-12
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = {
3535
],
3636
'linebreak-style': [
3737
'error',
38-
'unix'
38+
'windows'
3939
],
4040
'quotes': [
4141
'error',

src/cron/activity.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import { Client } from 'discord.js';
2+
import chalk from 'chalk';
23

34
export default {
45
cron: '*/15 * * * * *',
56
async execute(client: Client) {
6-
let activityList = [
7+
const activityList = [
78
`with ${client.guilds.cache.size} servers`,
89
`with ${client.users.cache.size} users`,
910
`with ${client.channels.cache.size} channels`,
1011
`with ${client.emojis.cache.size} emojis`,
1112
];
1213

13-
let activity = activityList[Math.floor(Math.random() * activityList.length)];
14-
client.user!.setActivity(activity, {
14+
const activity = activityList[Math.floor(Math.random() * activityList.length)];
15+
16+
if(!client.user) return console.log(chalk.red('[ERROR] ') + chalk.yellow('Client user is undefined.'));
17+
18+
client.user.setActivity(activity, {
1519
name: activity,
1620
type: 1
1721
});

src/events/interactionCreate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
import { Client, Interaction, MessageComponentInteraction, CommandInteraction } from 'discord.js';
23

34
interface CustomInteraction {
@@ -26,7 +27,7 @@ export default {
2627
if (interaction.isUserSelectMenu()) return 'userSelectMenu';
2728
})();
2829

29-
let action = client.interaction.get(`${interactionType}-${interaction.customId || interaction.commandName}`) as CustomInteraction;
30+
const action = client.interaction.get(`${interactionType}-${interaction.customId || interaction.commandName}`) as CustomInteraction;
3031
if (!action) return;
3132
try {
3233
action.execute(client, interaction);

src/events/ready.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { Client } from 'discord.js';
22
import chalk from 'chalk';
33
import { readFileSync } from 'fs';
4-
let version = JSON.parse(readFileSync('./package.json', 'utf8')).version;
4+
const version = JSON.parse(readFileSync('./package.json', 'utf8')).version;
55

66
export default {
77
event: 'ready',
88
async execute(client: Client) {
99
try {
10-
console.log(chalk.yellow(`[LOGIN] logged in as ${client.user!.tag} -> Version ${version}`));
10+
if (!client.user) return console.log(chalk.red('[LOGIN] Failed to login!'));
11+
console.log(chalk.yellow(`[LOGIN] logged in as ${client.user.tag} -> Version ${version}`));
1112
} catch (error) {
1213
return console.log(error);
1314
}

src/handlers/cronjobs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import cron from 'node-cron';
44
import chalk from 'chalk';
55

66
export async function loadCronJobs(folderPath: string, client: Client) {
7-
let files = fs.readdirSync(folderPath);
7+
const files = fs.readdirSync(folderPath);
88

99
for (let i = 0; i < files.length; i++) {
1010
files[i] = files[i].replace('.ts', '.js');
11-
folderPath = folderPath.replace('src/', '');
12-
let cronjob = await import (`../${folderPath}/${files[i]}`);
11+
folderPath = folderPath.replace('dist/', '');
12+
const cronjob = await import (`../${folderPath}/${files[i]}`);
1313
cron.schedule(cronjob.default.cron, () => cronjob.default.execute(client));
1414
console.log(chalk.greenBright(`[CRONJOB] Loaded ${(chalk.yellow(files[i]))}`));
1515
}

src/handlers/events.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ async function loadEvents(client: Client) {
66
const eventFiles = readdirSync('./dist/events').filter(file => file.endsWith('.js'));
77
if (!eventFiles) return;
88
for (let i = 0; i < eventFiles.length; i++) {
9-
eventFiles[i] = eventFiles[i];
109
const event = await import(`../events/${eventFiles[i]}`);
1110
client.on(event.default.event, event.default.execute.bind(null, client));
1211
console.log(chalk.greenBright(`[EVENT] Loaded ${(chalk.yellow(eventFiles[i]))} with event ${(chalk.yellow(event.default.event))}`));

src/interactions/userContextMenus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Client, UserContextMenuCommandInteraction } from 'discord.js';
22
import { ContextMenuCommandBuilder } from '@discordjs/builders';
33

4-
let commandID = 'test';
4+
const commandID = 'test';
55
export default {
66
id: commandID,
77
type: 'contextMenu',

0 commit comments

Comments
 (0)