From 7051a0070d6e4725b163894e07086b16b572357f Mon Sep 17 00:00:00 2001 From: Mohd Salman Ansari Date: Wed, 3 Aug 2022 14:41:36 +0530 Subject: [PATCH] feat: create flip.ts , fix #142 --- modules/flip.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 modules/flip.ts diff --git a/modules/flip.ts b/modules/flip.ts new file mode 100644 index 0000000..e2eeeac --- /dev/null +++ b/modules/flip.ts @@ -0,0 +1,28 @@ +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 flip = Strings.flip; + +export = { + name: "flip", + description: flip.DESCRIPTION, + extendedDescription: flip.EXTENDED_DESCRIPTION, + demo: { isEnabled: true, text: ".flip" }, + async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { + let outcomes = ["Heads", "Tails"]; + //An array that has the possible outcomes from flipping a coin, heads and tails + let outcomesIndex = Math.round(Math.random() * outcomes.length); + try { + client.sendMessage( + BotsApp.chatId, + outcomesIndex, + MessageType.text + ).catch(err => inputSanitization.handleError(err, client, BotsApp)); + } catch (err) { + await inputSanitization.handleError(err, client, BotsApp); + } + }, +};