Skip to content

Commit 1ee13a1

Browse files
committed
Refactor: Move utility functions and components to a new structure
1 parent 625e6ea commit 1ee13a1

47 files changed

Lines changed: 408 additions & 172 deletions

Some content is hidden

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

src/commands/ai.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { Message } from "whatsapp-web.js";
2-
import log from "../components/log";
3-
import { openrouter, generateText } from "../components/openRouter";
4-
import { reply } from "../components/reply";
5-
import agentHandler from "../components/agentHandler";
2+
import log from "../components/utils/log";
3+
import agentHandler from "../components/ai/agentHandler";
4+
import {
5+
greetings,
6+
greetingsLength,
7+
} from "../components/ai/response/greetings";
8+
import { client } from "../components/client";
69

710
export const command = "ai";
811
export const role = "user";
912

1013
export default async function (msg: Message) {
1114
const query = msg.body.replace(/^ai\b\s*/i, "").trim();
1215
if (query.length === 0) {
13-
await msg.reply(reply[Math.floor(Math.random() * reply.length)]);
16+
await msg.reply(greetings[Math.floor(Math.random() * greetingsLength)]);
1417
return;
1518
}
1619

@@ -22,5 +25,10 @@ export default async function (msg: Message) {
2225
return;
2326
}
2427

28+
if (Math.random() < 0.5) {
29+
const chat = await msg.getChat();
30+
await client.sendMessage(chat.id._serialized, text);
31+
return;
32+
}
2533
await msg.reply(text);
2634
}

src/commands/alert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Message, MessageMedia } from "whatsapp-web.js";
22
import axios from "axios";
3-
import log from "../components/log";
3+
import log from "../components/utils/log";
44
import fs from "fs/promises";
55

66
export const command = "alert";

src/commands/bible.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Message } from "whatsapp-web.js";
22
import axios from "axios";
3-
import log from "../components/log";
3+
import log from "../components/utils/log";
44

55
export const command = "bible";
66
export const role = "user";

src/commands/caution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Message, MessageMedia } from "whatsapp-web.js";
22
import axios from "axios";
3-
import log from "../components/log";
3+
import log from "../components/utils/log";
44
import fs from "fs/promises";
55
import { client } from "../components/client";
66

src/commands/github.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Message, MessageMedia } from "whatsapp-web.js";
22
import axios from "axios";
3-
import log from "../components/log";
3+
import log from "../components/utils/log";
44
import fs from "fs/promises";
55
import { client } from "../components/client";
66

@@ -24,21 +24,21 @@ export default async function (msg: Message) {
2424
.then(async (response) => {
2525
const user = response.data;
2626
const info = `
27-
*${user.name || user.login}*
28-
${user.bio || ""}
27+
*${user.name || user.login}*
28+
${user.bio || ""}
2929
30-
- Place: ${user.location || "N/A"}
31-
- Repos: ${user.public_repos}
32-
- Followers: ${user.followers}
33-
- Following: ${user.following}
34-
- Gists: ${user.public_gists}
35-
- Repo: ${user.public_repos}
36-
- X: ${
37-
user.twitter_username
38-
? `https://twitter.com/${user.twitter_username}`
39-
: "N/A"
40-
}
41-
- Link: ${user.blog || "N/A"}
30+
- Place: ${user.location || "N/A"}
31+
- Repos: ${user.public_repos}
32+
- Followers: ${user.followers}
33+
- Following: ${user.following}
34+
- Gists: ${user.public_gists}
35+
- Repo: ${user.public_repos}
36+
- X: ${
37+
user.twitter_username
38+
? `https://twitter.com/${user.twitter_username}`
39+
: "N/A"
40+
}
41+
- Link: ${user.blog || "N/A"}
4242
`;
4343

4444
await msg.reply(info);

src/commands/go.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Message } from "whatsapp-web.js";
22
import axios from "axios";
3-
import log from "../components/log";
3+
import log from "../components/utils/log";
44

55
export const command = "go";
66
export const role = "user";

src/commands/god.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Message, MessageMedia } from "whatsapp-web.js";
22
import axios from "axios";
3-
import log from "../components/log";
3+
import log from "../components/utils/log";
44
import fs from "fs/promises";
55
import { client } from "../components/client";
66

src/commands/hwaifu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Message, MessageMedia } from "whatsapp-web.js";
22
import axios from "axios";
3-
import log from "../components/log";
3+
import log from "../components/utils/log";
44
import fs from "fs/promises";
55
import { client } from "../components/client";
66

src/commands/ls.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Message } from "whatsapp-web.js";
2-
import log from "../components/log";
2+
import log from "../components/utils/log";
33
import { commands } from "../index";
44

55
export const command = "ls";

src/commands/mj.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import { Message } from "whatsapp-web.js";
2-
import log from "../components/log";
3-
import { openrouter, generateText } from "../components/openRouter";
4-
import { reply } from "../components/reply";
5-
import Font from "../components/font";
2+
import log from "../components/utils/log";
3+
import Font from "../components/utils/font";
64
import { author } from "../../package.json";
7-
import agentHandler from "../components/agentHandler";
5+
import {
6+
greetings,
7+
greetingsLength,
8+
} from "../components/ai/response/greetings";
9+
import agentHandler from "../components/ai/agentHandler";
10+
import { client } from "../components/client";
811

912
export const command = "mj";
1013
export const role = "user";
1114

1215
export default async function (msg: Message) {
1316
const query = msg.body.replace(/^mj\b\s*/i, "").trim();
1417
if (query.length === 0) {
15-
await msg.reply(reply[Math.floor(Math.random() * reply.length)]);
18+
await msg.reply(greetings[Math.floor(Math.random() * greetingsLength)]);
1619
return;
1720
}
1821

@@ -31,6 +34,12 @@ export default async function (msg: Message) {
3134
);
3235
return;
3336
}
37+
const font = Font(text);
3438

35-
await msg.reply(Font(text));
39+
if (Math.random() < 0.5) {
40+
const chat = await msg.getChat();
41+
await client.sendMessage(chat.id._serialized, font);
42+
return;
43+
}
44+
await msg.reply(font);
3645
}

0 commit comments

Comments
 (0)