Skip to content

Commit 18f8216

Browse files
committed
bug fixes and improvements
1 parent 3a4d936 commit 18f8216

10 files changed

Lines changed: 291 additions & 22 deletions

File tree

package-lock.json

Lines changed: 96 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"dependencies": {
2727
"@openrouter/ai-sdk-provider": "^1.0.0-beta.3",
2828
"@prisma/client": "^6.12.0",
29+
"ai": "^5.0.0-canary.24",
2930
"axios": "^1.10.0",
3031
"dotenv": "^17.2.0",
3132
"google-tts-api": "^2.0.2",

src/commands/docker.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { Message } from "whatsapp-web.js";
2+
import axios from "axios";
3+
import log from "../components/utils/log";
4+
5+
export const info = {
6+
command: "docker",
7+
description: "Search for Docker repositories or users.",
8+
usage: "docker <username> | <username/repository>",
9+
example: "docker mrepol742/project-canis",
10+
role: "user",
11+
cooldown: 5000,
12+
};
13+
14+
export default async function (msg: Message) {
15+
const query = msg.body.replace(/^docker\b\s*/i, "").trim();
16+
if (query.length === 0) {
17+
await msg.reply("Please provide a search query.");
18+
return;
19+
}
20+
21+
if (query.includes(" ")) {
22+
await msg.reply(
23+
"Please provide a username or single repository name without spaces."
24+
);
25+
return;
26+
}
27+
28+
await axios
29+
.get(`https://hub.docker.com/v2/repositories/${query}`)
30+
.then(async (response) => {
31+
if (response.data.count === 0 || response.data.message) {
32+
await msg.reply(`No repositories found for "${query}".`);
33+
return;
34+
}
35+
if (!query.includes("/")) {
36+
// The response is a list of repositories for the user
37+
const repos = response.data.results;
38+
if (!repos || repos.length === 0) {
39+
await msg.reply(`No repositories found for user "${query}".`);
40+
return;
41+
}
42+
let reply = `*${query}*\n\n`;
43+
reply += repos
44+
.map(
45+
(repo: any) =>
46+
`*${repo.name}*
47+
}\nStars: ${repo.star_count} Pulls: ${repo.pull_count}`
48+
)
49+
.join("\n\n");
50+
await msg.reply(reply);
51+
return;
52+
}
53+
const repo = response.data;
54+
const info = `
55+
*${repo.name}*
56+
${repo.description || ""}
57+
58+
- Stars: ${repo.star_count}
59+
- Pulls: ${repo.pull_count}
60+
- Last Updated: ${new Date(repo.last_updated).toLocaleDateString()}
61+
- Link: https://hub.docker.com/r/${repo.namespace}/${repo.name}
62+
`;
63+
await msg.reply(info);
64+
})
65+
.catch(async (error) => {
66+
log.error("docker", `Error fetching data: ${error.message}`);
67+
await msg.reply(
68+
`Error fetching data for "${query}". Please try again later.`
69+
);
70+
return;
71+
});
72+
}

src/commands/github.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const info = {
1616
export default async function (msg: Message) {
1717
const query = msg.body.replace(/^github\b\s*/i, "").trim();
1818
if (query.length === 0) {
19-
await msg.reply("Please provide a username.");
19+
await msg.reply("Please provide a search query.");
2020
return;
2121
}
2222

src/commands/help.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type CommandType = {
1616
role: string;
1717
};
1818

19-
const PAGE_SIZE = 15;
19+
const PAGE_SIZE = 10;
2020

2121
function paginate(items: string[], page: number, pageSize: number): string[] {
2222
const start = (page - 1) * pageSize;
@@ -29,19 +29,20 @@ function buildUserPage(
2929
totalPages: number
3030
): string {
3131
let response = `
32-
User commands
32+
Use \`help <command>\` for more details on a specific command.\n
3333
< ─────────── >\n • ${userCommands.join("\n • ") || "_None_"}\n\n`;
34-
response += `< ${page > 1 ? "prev" : ""} ─────────── ${
35-
page == totalPages ? "" : "next"
36-
} >`;
34+
response += `< ─────────── >`;
35+
response += `\n\`Page ${page} of ${totalPages}\``;
3736
return response;
3837
}
3938

4039
function buildAdminPage(adminCommands: string[]): string {
41-
return `Admin commands
40+
return `
41+
Use \`help <command>\` for more details on a specific command.\n
4242
< ─────────── >\n • ${
4343
adminCommands.join("\n • ") || "_None_"
44-
}\n< ─────────── >`;
44+
}\n< ─────────── >
45+
`;
4546
}
4647

4748
export default async function (msg: Message) {
@@ -56,7 +57,7 @@ export default async function (msg: Message) {
5657
const matchCommands = commands[query];
5758
if (matchCommands) {
5859
const response = `
59-
*${matchCommands.command}*
60+
\`${matchCommands.command}\`
6061
${matchCommands.description || "No description"}
6162
6263
*Usage:* ${matchCommands.usage || "No usage"}
@@ -79,7 +80,7 @@ export default async function (msg: Message) {
7980
}
8081

8182
// help [page]
82-
const match = query.match(/help\s*(\d+)?/i);
83+
const match = query.match(/(\d+)?/i);
8384
const page = Math.max(1, match && match[1] ? parseInt(match[1], 10) : 1);
8485

8586
const userCommands = Object.values(commands)

0 commit comments

Comments
 (0)