嗯,我有这段代码,但是我遇到了一个问题,在这段代码中,我有一个间隔,该间隔重复了从Web获取数据的代码,并且我有一个第一个setInterval,其中包含第二个setInterval,第一个setInterval工作正常,但是我在主setInterval内部有一个第二个setInterval,此秒不能正常工作,设置5秒时间隔为1秒。
var clocks = [10000];
(async () => {
const URL = url
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto(URL, { 'waitUntil' : 'networkidle2' });
setInterval(async () => {
let clock = await page.evaluate(clocks=>{
var a = document.getElementById("task-listing-datatable").getAttribute("data-tasks");
var ar = eval(a);
clocks.pop();
var keyword = ['Duplicate Fashion Product Identification Task', 'Clothing Categorization Task', 'Review Annotated Buildings','Image Annotation'];
for(let i=0; i<ar.length; i++){
for(let j=0; j<keyword.length; j++){
if(ar[i][1] === keyword[j]){
if(ar[i][1] === keyword[j]){ // What is this for?
let dataPoint =`${ar[i][0]} - ${ar[i][1]} - Paga: ${ar[i][3]} @everyone`;
if(!clocks.includes(dataPoint)){
return dataPoint;
}
}
}
}
}
}, clocks);
console.log(clocks);
console.log(`==== first login ====`)
console.log(`==================`)
if(!clocks.includes(clock)) {
client.on('message', (message)=>{
setInterval(()=>{
if(message.channel.id==='613573853565681671'){
message.channel.fetchMessages().then(collected => {
const filtered = collected.filter(message => message.author.bot);
const messages = filtered.first(2);
const text = `${messages[1].content}`;
console.log(text);
if(text === clock){
console.log("It's already in, Cannot be in");
}else if((text === clock) == false && clock != undefined){
client.channels.get(`613573853565681671`).send(clock);
}else if(clock === undefined){
console.log(undefined + "this is a clock");
} ///Here...
});
}
}, clocks)
});
clocks.push(clock);
if(clocks.includes(undefined)){
clocks.pop();
}
// Save the clock so you will remember it next time.
console.log(clocks);
}
await page.reload();
}, clocks)
})()
client.login('token');
第二个设置间隔是这个,这是无效的。
client.on('message', (message)=>{
setInterval(()=>{
if(message.channel.id==='613573853565681671'){
message.channel.fetchMessages().then(collected => {
const filtered = collected.filter(message => message.author.bot);
const messages = filtered.first(2);
const text = `${messages[1].content}`;
console.log(text);
if(text === clock){
console.log("It's already in, Cannot be in");
}else if((text === clock) == false && clock != undefined){
client.channels.get(`613573853565681671`).send(clock);
}else if(clock === undefined){
console.log(undefined + "this is a clock");
} ///Here...
});
}
}, clocks)
});