Answer the question
In order to leave comments, you need to log in
How to implement a restart of the function after the output of the variable?
There is such a telegram bot that parses the site, takes text information and sends it with the button pressed. It works, but displays the same info (Joke variable). Please tell me how to implement a function restart or similar functionality.
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
};
var needle = require('needle');
var cheerio = require('cheerio');
var RandPage = getRandomInt(10, 100);
var URL = 'http://www.site' + RandPage + '.' + 'shtml';
needle.get(URL, function(error, response, body) {
const TelegramBot = require('node-telegram-bot-api');
const token = '';
const bot = new TelegramBot(token, {polling: true});
var rand = getRandomInt(0, 21);
var $ = cheerio.load(body);
function getJoke() {
var currentJoke = [];
currentJoke.splice(0, 1, ($('div').find('p').eq(rand).text()));
return currentJoke;
};
var Joke = getJoke();
var robot = "Joke";
if (msg.text.indexOf(robot) === 0) {
bot.sendMessage(msg.chat.id, Joke[0]);
}
});
bot.onText(/\/start/, (msg) => {
bot.sendMessage(msg.chat.id, "Welcome", {
"reply_markup": {
"keyboard":
}
});
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question