Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add random module #176

Open
wants to merge 1 commit into
base: multi-device
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions lib/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ const data = {
PROCESSING: "```Generating QR code. Please wait...```",
IMAGE_CAPTION: "```Here's your QR image.```",
},
random: {
DESCRIPTION: "Given a list of items, pick a random one.",
EXTENDED_DESCRIPTION:
"```Choose a random value by using command``` *.random WatchTV WashDishes ...* .",
NO_ARG: "```Please enter at least one value to be picked. For example .random Value1 Value2```",
},
rbl: {
DESCRIPTION: "Module to enable a blacklist person or group to use the bot.",
EXTENDED_DESCRIPTION:
Expand Down
36 changes: 36 additions & 0 deletions modules/random.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Strings from "../lib/db";
import inputSanitization from "../sidekick/input-sanitization";
import { MessageType } from "../sidekick/message-type";
import Client from "../sidekick/client";
import { proto } from "@adiwajshing/baileys";
import BotsApp from "../sidekick/sidekick";
const random = Strings.random;

export = {
name: "random",
description: random.DESCRIPTION,
extendedDescription: random.EXTENDED_DESCRIPTION,
demo: { isEnabled: true, text: ".random" },
async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise<void> {
if(args.length === 0) {
client.sendMessage(
BotsApp.chatId,
random.NO_ARG,
MessageType.text
);
return;
} else if(args.length >= 1) {
let outcomes = args;
let outcomesIndex = Math.floor(Math.random() * outcomes.length);
try {
client.sendMessage(
BotsApp.chatId,
outcomes[outcomesIndex],
MessageType.text
).catch(err => inputSanitization.handleError(err, client, BotsApp));
} catch (err) {
await inputSanitization.handleError(err, client, BotsApp);
}
}
},
};