Skip to content

Commit

Permalink
feat: enable/disable suicide warning
Browse files Browse the repository at this point in the history
  • Loading branch information
sdip15fa committed Feb 16, 2024
1 parent 83abc7c commit 6b7cdbe
Show file tree
Hide file tree
Showing 64 changed files with 482 additions and 260 deletions.
7 changes: 5 additions & 2 deletions commands/afk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Client, Message } from "whatsapp-web.js";
import { Command } from "../types/command.js";
import { startAfk, afkStatus, stopAfk } from "../helpers/afkWrapper.js";

const execute = async (client: Client, msg: Message, args: string[]) => {
Expand Down Expand Up @@ -35,7 +36,7 @@ const execute = async (client: Client, msg: Message, args: string[]) => {
}
default: {
throw new Error(
"Invalid argument. Valid arguments are: on, off, status"
"Invalid argument. Valid arguments are: on, off, status",
);
}
}
Expand All @@ -45,7 +46,7 @@ const execute = async (client: Client, msg: Message, args: string[]) => {
}
};

export default {
const command: Command = {
name: "afk", //name of the module
description: "Turn on or off afk mode", // short description of what this command does
command: "!afk", //command with prefix. Ex command: '!test'
Expand All @@ -56,4 +57,6 @@ export default {
execute,
};

export default command;

// switch to es6 syntax
7 changes: 5 additions & 2 deletions commands/allow.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//jshint esversion:8
import { Client, Message } from "whatsapp-web.js";
import { Command } from "../types/command.js";
import config from "../config.js";
import pmpermit from "../helpers/pmpermit.js";

Expand All @@ -8,12 +9,12 @@ const execute = async (client: Client, msg: Message) => {
if (config.pmpermit_enabled == "true" && !msg.to.includes("-")) {
await pmpermit.permit(msg.to.split("@")[0]);
msg.reply(
"*✅ Allowed*\n\nYou are allowed for PM\n\n _Powered by WhatsBot_"
"*✅ Allowed*\n\nYou are allowed for PM\n\n _Powered by WhatsBot_",
);
}
};

export default {
const command: Command = {
name: "Allow for PM",
description: "Allow personal messaging for a conatct",
command: "!allow",
Expand All @@ -23,3 +24,5 @@ export default {
public: false,
execute,
};

export default command;
13 changes: 7 additions & 6 deletions commands/autoreply.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//jshint esversion:8
import { Client, Message } from "whatsapp-web.js";
import { Command } from "../types/command.js";
import db from "../db/index.js";

const execute = async (client: Client, msg: Message, args: string[]) => {
Expand All @@ -24,17 +25,15 @@ const execute = async (client: Client, msg: Message, args: string[]) => {
await db("chats").coll.updateOne(
{ chatId },
{ $set: { autoreply: !curr } },
{ upsert: true }
{ upsert: true },
);
await client.sendMessage(
(
await msg.getChat()
).id._serialized,
`Autoreply set for ${chatId}.`
(await msg.getChat()).id._serialized,
`Autoreply set for ${chatId}.`,
);
};

export default {
const command: Command = {
name: "Autoreply",
description: "Set a chat to autoreply",
command: "!autoreply",
Expand All @@ -44,3 +43,5 @@ export default {
execute,
public: false,
};

export default command;
5 changes: 4 additions & 1 deletion commands/awake.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Client, Message } from "whatsapp-web.js";
import { Command } from "../types/command.js";

//jshint esversion:8
const execute = async (client: Client, msg: Message) => {
client.sendPresenceAvailable();
msg.reply("```" + "I will be online from now." + "```");
};

export default {
const command: Command = {
name: "Awake",
description: "Stay online always !",
command: "!awake",
Expand All @@ -16,3 +17,5 @@ export default {
public: false,
execute,
};

export default command;
7 changes: 5 additions & 2 deletions commands/block.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Client, Message } from "whatsapp-web.js";
import { Command } from "../types/command.js";

//jshint esversion:8
const execute = async (client: Client, msg: Message) => {
msg.delete(true);
if (!msg.to.includes("-")) {
await msg.reply(
`*❌ Blocked* \n\n You have been blocked\n\n _Powered by WhatsBot_`
`*❌ Blocked* \n\n You have been blocked\n\n _Powered by WhatsBot_`,
);
const chat = await msg.getChat();
const contact = await chat.getContact();
contact.block();
}
};

export default {
const command: Command = {
name: "Block", //name of the module
description: "Block current chat", // short description of what this command does
command: "!block", //command with prefix. Ex command: '!test'
Expand All @@ -23,3 +24,5 @@ export default {
public: false,
execute,
};

export default command;
7 changes: 5 additions & 2 deletions commands/calc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Client, Message } from "whatsapp-web.js";
import { Command } from "../types/command.js";
import scalc from "scalc";

const execute = async (client: Client, msg: Message, args: string[]) => {
Expand All @@ -12,14 +13,14 @@ const execute = async (client: Client, msg: Message, args: string[]) => {
return await client.sendMessage(
chatId,
`${args.join(" ")}
= ${result}`
= ${result}`,
);
} catch {
return await client.sendMessage(chatId, "An error occured.");
}
};

export default {
const command: Command = {
name: "Calculator",
description: "Calculate an expression",
command: "!calc",
Expand All @@ -29,3 +30,5 @@ export default {
execute,
public: true,
};

export default command;
13 changes: 8 additions & 5 deletions commands/carbon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

//TODO: fix it
import whatsapp, { Client, Message } from "whatsapp-web.js";
import { Command } from "../types/command.js";
const { MessageMedia } = whatsapp;
import axios from "../helpers/axios.js";

Expand All @@ -10,9 +11,9 @@ async function carbon(text: string) {
.get<ArrayBuffer>(
`https://carbonnowsh.herokuapp.com/?code=${text.replace(
/ /gi,
"+"
"+",
)}&theme=darcula&backgroundColor=rgba(36, 75, 115)`,
{ responseType: "arraybuffer" }
{ responseType: "arraybuffer" },
)
.catch(() => {
return null;
Expand Down Expand Up @@ -44,7 +45,7 @@ const execute = async (client: Client, msg: Message, args: string[]) => {
await client.sendMessage(
msg.to,
`🙇‍♂️ *Error*\n\n` +
"```Something Unexpected Happened to create the Carbon.```"
"```Something Unexpected Happened to create the Carbon.```",
);
} else {
await client.sendMessage(
Expand All @@ -53,12 +54,12 @@ const execute = async (client: Client, msg: Message, args: string[]) => {
{
caption:
`Carbon for 👇\n` + "```" + msg.body.replace("!carbon ", "") + "```",
}
},
);
}
};

export default {
const command: Command = {
name: "Carbon",
description: "Creates a carbon.now.sh image from text",
command: "!carbon",
Expand All @@ -67,3 +68,5 @@ export default {
help: `*Carbon*\n\nGenerate beautiful image with carbon.now.sh. Just send the text it will generate an image for you.\n\n*!carbon [Text]*\nor,\nReply a message with *!carbon* to Create`,
execute,
};

export default command;
11 changes: 7 additions & 4 deletions commands/chatlist.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
//jshint esversion:8
import { Client, Message } from "whatsapp-web.js";
import { Command } from "../types/command.js";

const execute = async (client: Client, _msg: Message, args: string[]) => {
const page = Number(args[0]) || 1;
const chats = (await client.getChats()).filter(
(_v, index) => index < page * 20 && index >= (page - 1) * 20
(_v, index) => index < page * 20 && index >= (page - 1) * 20,
);
await client.sendMessage(
process.env.WTS_OWNER_ID,
`Chats:
${chats
.map(
(chat, index) =>
`${index + 1}. ${chat.name} \`\`\`${chat.id._serialized}\`\`\``
`${index + 1}. ${chat.name} \`\`\`${chat.id._serialized}\`\`\``,
)
.join("\n")}`
.join("\n")}`,
);
};

export default {
const command: Command = {
name: "Chat list",
description: "Get a list of chats",
command: "!chatlist",
Expand All @@ -28,3 +29,5 @@ export default {
execute,
public: false,
};

export default command;
5 changes: 4 additions & 1 deletion commands/chess.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//jshint esversion:8
// code generated by chatgpt, fixed by wcyat
import whatsapp, { Client, Message } from "whatsapp-web.js";
import { Command } from "../types/command.js";
const { MessageMedia } = whatsapp;
import { Chess } from "chess.js";
import { spawn } from "child_process";
Expand Down Expand Up @@ -189,7 +190,7 @@ async function getBestMove(fen: string, depth = 15): Promise<string> {
});
}

export default {
const command: Command = {
name: "chess",
command: "!chess",
description: "Play a game of Chess!",
Expand All @@ -206,3 +207,5 @@ export default {
execute,
public: true,
};

export default command;
5 changes: 4 additions & 1 deletion commands/cleargpt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//jshint esversion:8
import { Client, Message } from "whatsapp-web.js";
import { Command } from "../types/command.js";
import db from "../db/index.js";

const execute = async (client: Client, msg: Message) => {
Expand All @@ -10,7 +11,7 @@ const execute = async (client: Client, msg: Message) => {
await client.sendMessage(chatId, "Chatgpt context cleared.");
};

export default {
const command: Command = {
name: "cleargpt",
description: "Clear chatgpt context",
command: "!cleargpt",
Expand All @@ -20,3 +21,5 @@ export default {
execute,
public: true,
};

export default command;
11 changes: 7 additions & 4 deletions commands/count.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//jshint esversion:8
import { Client, Message } from "whatsapp-web.js";
import { Command } from "../types/command.js";
import { agenda } from "../helpers/agenda.js";
import { countMessage } from "../helpers/count.js";
import { getDate } from "../helpers/date.js";
Expand All @@ -24,11 +25,11 @@ const execute = async (client: Client, msg: Message, args: string[]) => {
{
timezone: "Asia/Hong_Kong",
skipImmediate: true,
}
},
);
return await client.sendMessage(
chatId,
"Subscribed! Message counts will be sent at 23:59 every day."
"Subscribed! Message counts will be sent at 23:59 every day.",
);
} else {
return await client.sendMessage(chatId, "Already subscribed!");
Expand Down Expand Up @@ -60,11 +61,11 @@ const execute = async (client: Client, msg: Message, args: string[]) => {

await client.sendMessage(
chatId,
await countMessage(chatId, chat.name || "", date)
await countMessage(chatId, chat.name || "", date),
);
};

export default {
const command: Command = {
name: "Count",
description: "Get count of messages in the chat",
command: "!count",
Expand All @@ -74,3 +75,5 @@ export default {
execute,
public: true,
};

export default command;
11 changes: 7 additions & 4 deletions commands/courier.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//jshint esversion:8
// Coded by Sumanjay (https://github.com/cyberboysumanjay)
import { Client, Message } from "whatsapp-web.js";
import { Command } from "../types/command.js";
import axios from "../helpers/axios.js";

async function getTrackingDetails(
trackingService: string,
trackingNumber: string
trackingNumber: string,
) {
let statusString =
"Unable to get information for your shipment. Please check the tracking id or try again later!";
Expand Down Expand Up @@ -51,17 +52,17 @@ const execute = async (client: Client, msg: Message, args: string[]) => {
await client.sendMessage(
chatId,
`🙇‍♂️ *Error*\n\n` +
"```Something unexpected happened while fetching the courier details.```"
"```Something unexpected happened while fetching the courier details.```",
);
} else {
await client.sendMessage(
chatId,
`🙇‍♂️ *Courier/Shipment Details*\n\n` + "```" + data.status + "```"
`🙇‍♂️ *Courier/Shipment Details*\n\n` + "```" + data.status + "```",
);
}
};

export default {
const command: Command = {
name: "Courier",
description:
"Get courier details from multiple providers. Currently supports: Gati Express and Ekart",
Expand All @@ -72,3 +73,5 @@ export default {
execute,
public: true,
};

export default command;
Loading

0 comments on commit 6b7cdbe

Please sign in to comment.