A
A
Alexunkas2020-05-14 21:03:22
Node.js
Alexunkas, 2020-05-14 21:03:22

The bot does not process the message, I do not know what to do js?

It is necessary that the bot checks the validity of the Payeer wallet - ^P[0-9]{7,10}$
Now the bot checks a regular card, but we switched to payeer and I don't know how to make the bot accept the message and skip further , help me please

if(message.user.menu === "qiwi") {
        let cardNumber = message.text.replace(/\s/g, '');
        if(!validateCardNumber(cardNumber)) return message.send(`Введите верный номер карты VISA MASTERCARD`);

        await message.user.set("menu", "enterAmount" + cardNumber);
        return message.send(`Введите сумму на вывод.`);
    }


function validateCardNumber(number) {
    let regex = new RegExp("^[0-9]{16}$");
    if (!regex.test(number))
        return false;

    return luhnCheck(number);
}

function luhnCheck(val) {
    let sum = 0;
    for (let i = 0; i < val.length; i++) {
        let intVal = parseInt(val.substr(i, 1));
        if (i % 2 == 0) {
            intVal *= 2;
            if (intVal > 9) {
                intVal = 1 + (intVal % 10);
            }
        }
        sum += intVal;
    }
    return (sum % 10) === 0;
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question