Skip to content

Commit

Permalink
Update eslint config, refactor logger usage across the project, add b…
Browse files Browse the repository at this point in the history
…ase path
  • Loading branch information
IgorKowalczyk committed Jan 15, 2025
1 parent a458dd2 commit 3be2ff6
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 56 deletions.
10 changes: 8 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import eslintConfig from "@igorkowalczyk/eslint-config/flat";
import eslintConfig from "@igorkowalczyk/eslint-config";

export default [...eslintConfig];
export default [
// prettier
...eslintConfig.base,
...eslintConfig.node,
...eslintConfig.typescript,
...eslintConfig.prettier,
];
14 changes: 7 additions & 7 deletions events/client/ready.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ActivityType, Client, TextChannel } from "discord.js";
import { logger } from "../../utils/logger.js";
import { defaultConfig } from "../../config.js";
import { defaultConfig } from "@/config";
import { Logger } from "@/utils/logger";

export async function ready(client: Client): Promise<void> {
export function ready(client: Client): void {
try {
logger("ready", `Logged in as ${client.user?.tag}! (ID: ${client.user?.id})`);
if (!defaultConfig.channel) return logger("error", "Channel not found! Please check your CHANNEL_ID .env variable.");
Logger("ready", `Logged in as ${client.user?.tag}! (ID: ${client.user?.id})`);
if (!defaultConfig.channel) return Logger("error", "Channel not found! Please check your CHANNEL_ID .env variable.");
const channel = client.channels.cache.get(defaultConfig.channel) as TextChannel;
logger("ready", `Watching for commands in ${channel.guild.name}#${channel.name}`);
Logger("ready", `Watching for commands in ${channel.guild.name}#${channel.name}`);
client.user?.setActivity("👀 Watching all ports!", { type: ActivityType.Custom });
} catch (error) {
logger("error", `Error setting activity: ${error}`);
Logger("error", `Error setting activity: ${error}`);
}
}
12 changes: 6 additions & 6 deletions events/guild/messageCreate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fs from "node:fs";
import path from "node:path";
import { Client, EmbedBuilder, Message, TextChannel } from "discord.js";
import { defaultConfig } from "../../config.js";
import { execCommand } from "../../utils/execCommand.ts";
import { logger } from "../../utils/logger.js";
import { defaultConfig } from "@/config";
import { execCommand } from "@/utils/execCommand";
import { Logger } from "@/utils/logger";

export async function messageCreate(client: Client, message: Message): Promise<void | Message<boolean>> {
try {
Expand All @@ -28,7 +28,7 @@ export async function messageCreate(client: Client, message: Message): Promise<v

try {
process.chdir(resolvedPath);
defaultConfig.debugger.changeDir && logger("event", `Changed directory from ${defaultConfig.cwd} to ${resolvedPath}`);
if (defaultConfig.debugger.changeDir) Logger("event", `Changed directory from ${defaultConfig.cwd} to ${resolvedPath}`);

const changedDirectory = new EmbedBuilder() // prettier
.setDescription(`${defaultConfig.emojis.change} **Changed directory from \`${defaultConfig.cwd}\` to \`${resolvedPath}\`**`)
Expand All @@ -37,7 +37,7 @@ export async function messageCreate(client: Client, message: Message): Promise<v
defaultConfig.cwd = resolvedPath;
return message.reply({ embeds: [changedDirectory] });
} catch (error) {
defaultConfig.debugger.changeDir && logger("error", `Error changing directory: ${error}`);
if (defaultConfig.debugger.changeDir) Logger("error", `Error changing directory: ${error}`);
const errorEmbed = new EmbedBuilder() // prettier
.setDescription(`${defaultConfig.emojis.error} **Error changing directory**`)
.setColor(defaultConfig.embedColor);
Expand All @@ -54,6 +54,6 @@ export async function messageCreate(client: Client, message: Message): Promise<v

await execCommand(client, message.content);
} catch (error) {
logger("error", `Error executing command: ${error}`);
Logger("error", `Error executing command: ${error}`);
}
}
28 changes: 14 additions & 14 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import "dotenv/config";
import { Client, GatewayIntentBits } from "discord.js";
import loadEvents from "./utils/loadEvents";
import { logger } from "./utils/logger";
import loadEvents from "@/utils/loadEvents";
import { Logger } from "@/utils/logger";

logger("event", "Starting SSH Bot session...");
logger("info", `Running version v${process.env.npm_package_version} on Node.js ${process.version} on ${process.platform} ${process.arch}`);
logger("info", "Check out the source code at https://github.com/igorkowalczyk/discord-ssh!");
logger("info", "Don't forget to star the repository, it helps a lot!");
Logger("event", "Starting SSH Bot session...");
Logger("info", `Running version v${process.env.npm_package_version} on Node.js ${process.version} on ${process.platform} ${process.arch}`);
Logger("info", "Check out the source code at https://github.com/igorkowalczyk/discord-ssh!");
Logger("info", "Don't forget to star the repository, it helps a lot!");

try {
const client = new Client({
Expand All @@ -17,21 +17,21 @@ try {
intents: GatewayIntentBits.Guilds | GatewayIntentBits.GuildMembers | GatewayIntentBits.GuildMessages | GatewayIntentBits.MessageContent,
});

logger("info", "Loading events...");
Logger("info", "Loading events...");
await loadEvents(client);

logger("info", "Logging in...");
Logger("info", "Logging in...");

await client.login(process.env.TOKEN);
} catch (error) {
logger("error", `Error starting the bot: ${error}`);
process.exit(1);
Logger("error", `Error starting the bot: ${error}`);
throw error;
}

process.on("unhandledRejection", async (reason) => {
return logger("error", `Unhandled Rejection: ${reason}`);
process.on("unhandledRejection", (reason) => {
return Logger("error", `Unhandled Rejection: ${reason}`);
});

process.on("uncaughtException", async (err) => {
return logger("error", `Uncaught Exception: ${err}`);
process.on("uncaughtException", (err) => {
return Logger("error", `Uncaught Exception: ${err}`);
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"devDependencies": {
"@igorkowalczyk/eslint-config": "3.0.2",
"@igorkowalczyk/prettier-config": "2.2.0",
"@igorkowalczyk/prettier-config": "3.0.2",
"@types/node": "22.10.6",
"eslint": "9.18.0",
"prettier": "3.4.2",
Expand Down
111 changes: 104 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
"noPropertyAccessFromIndexSignature": false,

"baseUrl": ".",
"paths": {
"@/*": ["*"]
}
}
}
Loading

0 comments on commit 3be2ff6

Please sign in to comment.