Skip to content

Commit 73c2975

Browse files
committed
feat: add command handling for fork and sql commands with appropriate responses
1 parent 18f8216 commit 73c2975

7 files changed

Lines changed: 56 additions & 0 deletions

File tree

src/commands/fork.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Message } from "whatsapp-web.js";
2+
3+
export const info = {
4+
command: "fork",
5+
description: "Fork this bot on GitHub.",
6+
usage: "fork",
7+
example: "fork",
8+
role: "user",
9+
cooldown: 5000,
10+
};
11+
12+
export default async function (msg: Message) {
13+
if (!/^fork\b/i.test(msg.body)) return;
14+
15+
await msg.reply(
16+
"Fork this bot at https://github.com/mrepol742/project-canis or contribute to the project by submitting issues or pull requests."
17+
);
18+
}

src/commands/ping.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ export const info = {
1111
};
1212

1313
export default function (msg: Message) {
14+
if (!/^ping\b/i.test(msg.body)) return;
1415
msg.reply("pong");
1516
}

src/commands/restart.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const info = {
1212
};
1313

1414
export default async function (msg: Message) {
15+
if (!/^restart\b/i.test(msg.body)) return;
1516
await msg.react("🔄");
1617

1718
const tempDir = "./.temp";

src/commands/sql.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Message, MessageMedia } from "whatsapp-web.js";
2+
import axios from "axios";
3+
import log from "../components/utils/log";
4+
import { prisma } from "../components/prisma";
5+
6+
export const info = {
7+
command: "sql",
8+
description: "Execute a SQL query and return the result.",
9+
usage: "sql <query>",
10+
example: "sql SELECT * FROM users WHERE active = true;",
11+
role: "admin",
12+
cooldown: 5000,
13+
};
14+
15+
export default async function (msg: Message) {
16+
const query = msg.body.replace(/^sql\b\s*/i, "").trim();
17+
if (query.length === 0) {
18+
await msg.reply("Please provide a sql.");
19+
return;
20+
}
21+
22+
try {
23+
const result = await prisma.$queryRawUnsafe(query);
24+
await msg.reply(JSON.stringify(result, null, 2));
25+
} catch (error: any) {
26+
log.error("sql", `Error querying data: ${error.message}`);
27+
await msg.reply(
28+
`Error querying data for "${query}". Please try again later.`
29+
);
30+
}
31+
}

src/commands/stats.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const info = {
1414
};
1515

1616
export default async function (msg: Message) {
17+
if (!/^stats\b/i.test(msg.body)) return;
1718
const stats = {
1819
OS: os.release(),
1920
arch: os.arch(),

src/commands/unsend.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export const info = {
1111
};
1212

1313
export default async function (msg: Message) {
14+
if (!/^unsend\b/i.test(msg.body)) return;
15+
1416
if (!msg.hasQuotedMsg) {
1517
await msg.reply("Please reply the message you want to unsend.");
1618
return;

src/commands/uptime.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export const info = {
1313
};
1414

1515
export default async function (msg: Message) {
16+
if (!/^uptime\b/i.test(msg.body)) return;
17+
1618
const uptimeMinutes = Math.floor(process.uptime() / 60);
1719
const statsMessage = `
1820
*${uptimeMinutes} minutes*

0 commit comments

Comments
 (0)