Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
.env
data/
data/
dist/
6 changes: 3 additions & 3 deletions src/commands/!misc/premium.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SubcommandCallbackOpts } from "../../types/command.js";
import { cacheDB, getCachedDB } from "../../utils/cacheDB.js";
import { createDocument, deleteDocument } from "../../utils/firestore.js";
import type { SubcommandCallbackOpts } from "../../types/command.ts";
import { cacheDB, getCachedDB } from "../../utils/cacheDB.ts";
import { createDocument, deleteDocument } from "../../utils/firestore.ts";

export default {
name: "premium",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/!misc/refreshdb.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CommandCallbackOpts } from "../../types/command.js";
import { cacheDB } from "../../utils/cacheDB.js";
import type { CommandCallbackOpts } from "../../types/command.ts";
import { cacheDB } from "../../utils/cacheDB.ts";

export default {
name: "refreshdb",
Expand Down
6 changes: 3 additions & 3 deletions src/commands/!mod/ban.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EmbedBuilder } from "discord.js";
import type { CommandCallbackOpts } from "../../types/command.js";
import { createDocument } from "../../utils/firestore.js";
import getConfig from "../../utils/getConfig.js";
import type { CommandCallbackOpts } from "../../types/command.ts";
import { createDocument } from "../../utils/firestore.ts";
import getConfig from "../../utils/getConfig.ts";

export default {
name: "ban",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/!mod/checkban.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EmbedBuilder } from "discord.js";
import type { CommandCallbackOpts } from "../../types/command.js";
import { getDocument } from "../../utils/firestore.js";
import type { CommandCallbackOpts } from "../../types/command.ts";
import { getDocument } from "../../utils/firestore.ts";

export default {
name: "checkban",
Expand Down
6 changes: 3 additions & 3 deletions src/commands/!mod/unban.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EmbedBuilder } from "discord.js";
import type { CommandCallbackOpts } from "../../types/command.js";
import { deleteDocument } from "../../utils/firestore.js";
import getConfig from "../../utils/getConfig.js";
import type { CommandCallbackOpts } from "../../types/command.ts";
import { deleteDocument } from "../../utils/firestore.ts";
import getConfig from "../../utils/getConfig.ts";

export default {
name: "unban",
Expand Down
16 changes: 10 additions & 6 deletions src/commands/!stats/stats.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EmbedBuilder } from "discord.js";
import type { CommandCallbackOpts } from "../../types/command.js";
import { getServerStats, getStats } from "../../utils/stats.js";
import type { CommandCallbackOpts } from "../../types/command.ts";
import { getServerStats, getStats } from "../../utils/stats.ts";

export default {
name: "stats",
Expand All @@ -9,8 +9,10 @@ export default {
devOnly: true,
async callback({ client, message, args }: CommandCallbackOpts) {
try {
if (args[0]) {
const serverStats = await getServerStats(args[0] || message.guildId);
if (args[0] || message.guildId) {
const serverStats = await getServerStats(
(args[0] || message.guildId) ?? "",
);
Comment on lines +12 to +15

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional logic change introduces a bug that alters the command's behavior. The original code if (args[0]) only fetched server-specific stats when an argument was explicitly provided. The new condition if (args[0] || message.guildId) will almost always evaluate to true in guild contexts (since message.guildId typically exists), causing the command to always fetch server stats even when the user intended to view global stats.
This breaks the command's logic flow: when no argument is provided, the code should skip to line 58 to fetch global stats, but now it will incorrectly enter the server stats branch.

Confidence: 5/5

Suggested Fix
Suggested change
if (args[0] || message.guildId) {
const serverStats = await getServerStats(
(args[0] || message.guildId) ?? "",
);
if (args[0]) {
const serverStats = await getServerStats(
args[0] ?? message.guildId ?? "",
);

Revert the condition to if (args[0]) to preserve the original behavior. If you need to handle null/undefined args[0], use the nullish coalescing operator within the function call to fall back to message.guildId only when args[0] is explicitly provided but happens to be nullish.

Prompt for AI

Copy this prompt to your AI IDE to fix this issue locally:

In src/commands/!stats/stats.ts around line 12, the conditional logic was changed from "if (args[0])" to "if (args[0] || message.guildId)" which breaks the command's intended behavior. When no argument is provided, the command should fetch global stats (line 58), but the new condition will almost always be true in guild contexts, causing it to incorrectly fetch server stats instead. Revert the condition to "if (args[0])" and keep the nullish coalescing operator inside the function call for safety: "args[0] ?? message.guildId ?? ''".

📍 This suggestion applies to lines 12-15

if (!serverStats) {
return message.reply({
embeds: [
Expand Down Expand Up @@ -54,7 +56,7 @@ export default {
return message.reply({ embeds: [serverEmbed] });
}
const stats = await getStats();
const serverStats = await getServerStats(message.guildId);
const serverStats = await getServerStats(message.guildId ?? "");

const globalData = stats.global || {};
const commandsData = stats.commands || {};
Expand Down Expand Up @@ -87,7 +89,9 @@ export default {
);

// Most used commands embed
const sortedCommands = Object.entries(commandsData)
const sortedCommands = Object.entries(
commandsData as Record<string, number>,
)
.sort((a, b) => b[1] - a[1])
.slice(0, 10);

Expand Down
4 changes: 2 additions & 2 deletions src/commands/code/complexity.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { EmbedBuilder } from "discord.js";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";
import {
parseCodeBlock,
parseCodeCommandInput,
} from "../../utils/codeInput.js";
} from "../../utils/codeInput.ts";

export default {
name: "complexity",
Expand Down
6 changes: 3 additions & 3 deletions src/commands/code/format.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { EmbedBuilder, codeBlock } from "discord.js";
import prettier from "prettier";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";
import {
parseCodeBlock,
parseCodeCommandInput,
} from "../../utils/codeInput.js";
import getConfig from "../../utils/getConfig.js";
} from "../../utils/codeInput.ts";
import getConfig from "../../utils/getConfig.ts";

const parserMap: Record<string, string> = {
js: "babel",
Expand Down
6 changes: 3 additions & 3 deletions src/commands/code/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
} from "discord.js";
import "dotenv/config";
import { Groq } from "groq-sdk";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";
import {
parseCodeBlock,
parseCodeCommandInput,
} from "../../utils/codeInput.js";
import getConfig from "../../utils/getConfig.js";
} from "../../utils/codeInput.ts";
import getConfig from "../../utils/getConfig.ts";

const groq = new Groq({ apiKey: process.env.GROQ_API_KEY });

Expand Down
6 changes: 3 additions & 3 deletions src/commands/code/suggest.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { EmbedBuilder } from "discord.js";
import "dotenv/config";
import { Groq } from "groq-sdk";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";
import {
parseCodeBlock,
parseCodeCommandInput,
} from "../../utils/codeInput.js";
import getConfig from "../../utils/getConfig.js";
} from "../../utils/codeInput.ts";
import getConfig from "../../utils/getConfig.ts";

const groq = new Groq({ apiKey: process.env.GROQ_API_KEY });

Expand Down
6 changes: 3 additions & 3 deletions src/commands/code/whatlang.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { EmbedBuilder } from "discord.js";
import "dotenv/config";
import { Groq } from "groq-sdk";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";
import {
parseCodeBlock,
parseCodeCommandInput,
} from "../../utils/codeInput.js";
import getConfig from "../../utils/getConfig.js";
} from "../../utils/codeInput.ts";
import getConfig from "../../utils/getConfig.ts";

const groq = new Groq({ apiKey: process.env.GROQ_API_KEY });

Expand Down
2 changes: 1 addition & 1 deletion src/commands/docs/mdn.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EmbedBuilder } from "discord.js";
import fetch from "node-fetch";
import TurndownService from "turndown";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";

const turndown = new TurndownService();

Expand Down
2 changes: 1 addition & 1 deletion src/commands/docs/wiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
EmbedBuilder,
} from "discord.js";
import fetch from "node-fetch";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";

export default {
name: "wiki",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/github/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ButtonStyle,
EmbedBuilder,
} from "discord.js";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";

export default {
name: "profile",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/github/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ButtonStyle,
EmbedBuilder,
} from "discord.js";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";

export default {
name: "repo",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/math/math-breakdown.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EmbedBuilder } from "discord.js";
import "dotenv/config";
import { Groq } from "groq-sdk";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";

const groq = new Groq({ apiKey: process.env.GROQ_API_KEY });

Expand Down
2 changes: 1 addition & 1 deletion src/commands/misc/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Client, Message } from "discord.js";
import { EmbedBuilder } from "discord.js";
import path, { join } from "path";
import { fileURLToPath } from "url";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";

type Command = {
name: string;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/misc/ping.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";

export default {
name: "ping",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/search/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
EmbedBuilder,
} from "discord.js";
import fetch from "node-fetch";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";

export default {
name: "npm",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/search/pip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
EmbedBuilder,
} from "discord.js";
import fetch from "node-fetch";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";

export default {
name: "pip",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/static/github.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EmbedBuilder } from "discord.js";
import fetch from "node-fetch";
import type { SubcommandCallbackOpts } from "../../types/command.js";
import type { SubcommandCallbackOpts } from "../../types/command.ts";

export default {
name: "github",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/support/feature.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EmbedBuilder } from "discord.js";
import ucid from "unique-custom-id";
import type { CommandCallbackOpts } from "../../types/command.js";
import getConfig from "../../utils/getConfig.js";
import type { CommandCallbackOpts } from "../../types/command.ts";
import getConfig from "../../utils/getConfig.ts";

export default {
name: "feature",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/support/report.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EmbedBuilder } from "discord.js";
import ucid from "unique-custom-id";
import type { CommandCallbackOpts } from "../../types/command.js";
import getConfig from "../../utils/getConfig.js";
import type { CommandCallbackOpts } from "../../types/command.ts";
import getConfig from "../../utils/getConfig.ts";

export default {
name: "report",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/tools/color.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createCanvas } from "@napi-rs/canvas";
import { AttachmentBuilder, EmbedBuilder } from "discord.js";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";

function hexToRgb(hex: string) {
const clean = hex.replace("#", "");
Expand Down
2 changes: 1 addition & 1 deletion src/commands/tools/http.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EmbedBuilder } from "discord.js";
import fetch from "node-fetch";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";

export default {
name: "http",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/tools/id.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EmbedBuilder } from "discord.js";
import ucid from "unique-custom-id";
import { map } from "unique-custom-id/format";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";

export default {
name: "id",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/tools/regex.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EmbedBuilder } from "discord.js";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";

export default {
name: "regex",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/tools/scan.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActionRowBuilder, ButtonBuilder, EmbedBuilder } from "discord.js";
import "dotenv/config";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";

const GSB_API_KEY = process.env.GSB_API_KEY;
const URLSCAN_API_KEY = process.env.URLSCAN_API_KEY;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/tools/tree.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AttachmentBuilder, codeBlock, EmbedBuilder } from "discord.js";
import type { CommandCallbackOpts } from "../../types/command.js";
import getConfig from "../../utils/getConfig.js";
import type { CommandCallbackOpts } from "../../types/command.ts";
import getConfig from "../../utils/getConfig.ts";

type RepoInfo = {
owner: string;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/tools/whois.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EmbedBuilder } from "discord.js";
import type { CommandCallbackOpts } from "../../types/command.js";
import type { CommandCallbackOpts } from "../../types/command.ts";

type WhoisEvent = {
eventAction?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/events/clientReady/cacheDB.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Client } from "discord.js";
import { cacheDB } from "../../utils/cacheDB.js";
import { cacheDB } from "../../utils/cacheDB.ts";

export default async (client: Client) => {
await cacheDB();
Expand Down
2 changes: 1 addition & 1 deletion src/events/guildCreate/isBanned.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Client, Guild } from "discord.js";
import { getDocument } from "../../utils/firestore.js";
import { getDocument } from "../../utils/firestore.ts";

export default async (client: Client, guild: Guild) => {
try {
Expand Down
10 changes: 5 additions & 5 deletions src/events/messageCreate/handleCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import "dotenv/config";
import NodeCache from "node-cache";
import path, { join } from "path";
import { fileURLToPath } from "url";
import { getCachedDB } from "../../utils/cacheDB.js";
import getAllFiles from "../../utils/getAllFiles.js";
import getConfig from "../../utils/getConfig.js";
import { trackCommandStat } from "../../utils/stats.js";
import { getCachedDB } from "../../utils/cacheDB.ts";
import getAllFiles from "../../utils/getAllFiles.ts";
import getConfig from "../../utils/getConfig.ts";
import { trackCommandStat } from "../../utils/stats.ts";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -238,7 +238,7 @@ export default async (client: Client, message: Message) => {
// Track command statistics
await trackCommandStat(
commandObject.name,
message.guildId,
message.guildId ?? "",
commandObject.devOnly || false,
client,
);
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/eventHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Client, ClientEvents } from "discord.js";
import path from "path";
import { fileURLToPath } from "url";
import getAllFiles from "../utils/getAllFiles.js";
import getAllFiles from "../utils/getAllFiles.ts";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Client, IntentsBitField } from "discord.js";
import "dotenv/config";
import eventHandler from "./handlers/eventHandler.js";
import eventHandler from "./handlers/eventHandler.ts";

const client = new Client({
intents: [
Expand Down
4 changes: 2 additions & 2 deletions src/utils/cacheDB.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "path";
import { readFile, writeFile } from "./fileOps.js";
import { getAllDocuments } from "./firestore.js";
import { readFile, writeFile } from "./fileOps.ts";
import { getAllDocuments } from "./firestore.ts";

import type { DocumentData } from "firebase-admin/firestore";
import fsp from "fs/promises";
Expand Down
Loading
Loading