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 new module, but without any response #132

Open
Nagrom33 opened this issue Jun 9, 2022 · 0 comments
Open

Add new module, but without any response #132

Nagrom33 opened this issue Jun 9, 2022 · 0 comments

Comments

@Nagrom33
Copy link

Nagrom33 commented Jun 9, 2022

The older version of this repo I created some easy modules. Wich I want to change to .ts and put in the latest version.
I hope that someone sees what exactly I am missing in my code, why this don't return anything.

But I don't know what I'm missing, i added a teammaker.ts with the following code:

import Strings from "../lib/db";
import inputSanitization from "../sidekick/input-sanitization";
import Client from "../sidekick/client";
import { proto } from "@adiwajshing/baileys";
import BotsApp from "../sidekick/sidekick";
import { MessageType } from "../sidekick/message-type";
import STRINGS from "../lib/db";

module.exports = {
    name: "teammaker",
    description: STRINGS.teammaker.DESCRIPTION,
    extendedDescription: STRINGS.teammaker.EXTENDED_DESCRIPTION,
    demo: { isEnabled: false },
    async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise<void> {
        try{
            if(args.length === 0) {
                client.sendMessage(
                    BotsApp.chatId,
                    STRINGS.teammaker.NO_TEXT,
                    MessageType.text
                ).catch(err => inputSanitization.handleError(err, client, BotsApp));
                return;
            }
            if(args.length > 0) {
                const bodySplitter = BotsApp.body.split("|");

                let deelnemers = bodySplitter[0].slice(0, bodySplitter[0].length - 1).split(" ");
                deelnemers.shift();
                const aantalTeams:any = bodySplitter[1];

                function shuffleArray(arr) {
                    arr.sort(() => Math.random() - 0.5);
                }
                
                shuffleArray(deelnemers);

                const spelersPerTeam = deelnemers.length / aantalTeams;
                let teamNumber = 1;
                let i = 0;

                function splitIntoChunk(arr, chunk) {
                    for (i < arr.length; i += chunk;) {
                        let tempArray;
                        tempArray = arr.slice(i, i + chunk);
                        client.sendMessage(
                            BotsApp.chatId,
                            `*░░░░░░░░░░ Team ${teamNumber} ░░░░░░░░░░*\n\n${tempArray.join(',\n')}\n\n *░░░░░░░░░░░░░░░░░░░░░░░░░*`,
                            MessageType.text
                        );
                        teamNumber++;
                    }
                }
                splitIntoChunk(deelnemers, spelersPerTeam);
            }
        } catch (err) {
            await inputSanitization.handleError(err, client, BotsApp);
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant