Skip to content

Commit e14ac59

Browse files
committed
feat Use centralized config and nullish coalescing
Replace direct process.env usage with imports from the shared config module and prefer nullish coalescing (??) for defaults. Initialize dotenv with quiet/debug options, simplify build script logging, and apply small typing/import cleanups across the codebase.
1 parent 5009131 commit e14ac59

49 files changed

Lines changed: 343 additions & 190 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

prisma.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import "dotenv/config";
2-
import { defineConfig, env } from "prisma/config";
1+
import dotenv from "dotenv";
2+
dotenv.config({ quiet: true, debug: process.env.NODE_ENV === "production" });
3+
import { defineConfig } from "prisma/config";
34

45
export default defineConfig({
56
schema: "prisma/schema.prisma",

scripts/build.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ exec("tsc", (err, stdout, stderr) => {
2121
const end = Date.now();
2222
const duration = ((end - start) / 1000).toFixed(2);
2323

24-
if (err) {
25-
console.error("Build failed:", stderr);
26-
process.exit(1);
27-
} else {
28-
console.log(stdout);
29-
console.log(`Build took ${duration} seconds`);
30-
}
24+
console.log(stdout);
25+
console.log(`Build ${err ? "failed" : "success"} took ${duration} seconds`);
26+
if (err) process.exit(1);
3127
});

src/commands/ai.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import log from "../components/utils/log";
33
import agentHandler from "../components/ai/agentHandler";
44
import { greetings } from "../components/utils/data";
55
import { Command, commands } from "../components/utils/cmd/loader";
6-
7-
const PROJECT_CANIS_ALIS: string = process.env.PROJECT_CANIS_ALIAS || "Canis";
6+
import { PROJECT_CANIS_ALIAS } from "../config";
87

98
export const info: Command = {
109
command: "ai",
@@ -29,7 +28,7 @@ export default async function (msg: Message): Promise<void> {
2928
}
3029

3130
const mentioned = msg.mentionedIds.length > 0;
32-
let prompt = `You are ${PROJECT_CANIS_ALIS}. Today's date is %_TODAY_%.
31+
let prompt = `You are ${PROJECT_CANIS_ALIAS}. Today's date is %_TODAY_%.
3332
Respond to the user naturally and briefly. Avoid asking follow-up questions unless necessary.
3433
If the user's message clearly matches the intent of a command listed below, respond strictly using the corresponding usage format.
3534
If there is no clear match, reply normally in your own words.

src/commands/aur.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default async function (msg: Message): Promise<void> {
3131

3232
const info = `
3333
\`${pkg.Name}\` - ${pkg.Version}
34-
${pkg.Description || "No description available."}
34+
${pkg.Description ?? "No description available."}
3535
3636
Votes: ${pkg.NumVotes}
3737
Popularity: ${pkg.Popularity.toFixed(2)}

src/commands/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Message } from "../types/message"
1+
import { Message } from "../types/message";
22
import log from "../components/utils/log";
33
import { exec } from "child_process";
44
import util from "util";

src/commands/docker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default async function (msg: Message): Promise<void> {
5454
const repo = response.data;
5555
const info = `
5656
\`${repo.name}\`
57-
${repo.description || ""}
57+
${repo.description ?? ""}
5858
5959
Stars: ${repo.star_count}
6060
Pulls: ${repo.pull_count}

src/commands/github.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export default async function (msg: Message): Promise<void> {
3737

3838
const info = `
3939
\`${user.name || user.login}\`
40-
${user.bio || ""}
40+
${user.bio ?? ""}
4141
42-
Place: ${user.location || "N/A"}
42+
Place: ${user.location ?? "N/A"}
4343
Followers: ${user.followers}
4444
Following: ${user.following}
4545
Gists: ${user.public_gists}
@@ -49,7 +49,7 @@ export default async function (msg: Message): Promise<void> {
4949
? `https://twitter.com/${user.twitter_username}`
5050
: "N/A"
5151
}
52-
Link: ${user.blog || "N/A"}
52+
Link: ${user.blog ?? "N/A"}
5353
`;
5454
await msg.reply(downloadAvatar, undefined, {
5555
caption: info,

src/commands/help.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ export default async function (msg: Message): Promise<void> {
5454
const cmd = commands[possibleCommand] as CommandType;
5555
const response = `
5656
\`${cmd.command}\`
57-
${cmd.description || "No description"}
57+
${cmd.description ?? "No description"}
5858
59-
*Usage:* ${cmd.usage || "N/A"}
60-
*Example:* ${cmd.example || "N/A"}
59+
*Usage:* ${cmd.usage ?? "N/A"}
60+
*Example:* ${cmd.example ?? "N/A"}
6161
*Role:* ${cmd.role}
6262
*Cooldown:* ${cmd.cooldown || 5000}ms
6363
`;

src/commands/huggingface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default async function (msg: Message): Promise<void> {
2929
const models = response.data[0];
3030
const info = `
3131
\`${models.modelId}\`
32-
${models.tags.splice(0, 5).join(", ") || "N/A"}
32+
${models.tags.splice(0, 5).join(", ") ?? "N/A"}
3333
3434
Library: ${models.library_name}
3535
Pipeline: ${models.pipeline_tag}

src/commands/me.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default async function (msg: Message): Promise<void> {
4242
}
4343

4444
const phoneNumber = parsePhoneNumber(`+${user.number}`);
45-
const countryCode = phoneNumber?.country || "";
45+
const countryCode = phoneNumber?.country ?? "";
4646
const time = getCurrentTimeByCountryCode(countryCode);
4747
const self = (await client()).info.wid._serialized;
4848
const ratelimit: RateEntry = isBlockedTemporarily
@@ -51,7 +51,7 @@ export default async function (msg: Message): Promise<void> {
5151

5252
const text = `
5353
\`${user.name}\`
54-
${user.about || "No more about you (its private)."}
54+
${user.about ?? "No more about you (its private)."}
5555
5656
ID: ${user.lid}
5757
Number: ${user.number}

0 commit comments

Comments
 (0)