make fetchOldest and fetchLatest search for a valid number

This commit is contained in:
Steven Conaway 2020-12-30 17:26:22 -08:00
parent f8231e2367
commit ad78df1314
No known key found for this signature in database
GPG key ID: CEE800CE73DC8E76

View file

@ -38,9 +38,16 @@ async function fetchLatest(id) {
const result = await app.client.conversations.history({
token: token,
channel: id,
limit: 1,
limit: 100,
});
const number = extractNumber(result.messages[0].text)
let number;
for (let x = 0; x < result.messages.length; x++) {
number = extractNumber(
result.messages[x].text,
);
if (!isNaN(number)) break;
}
return number;
} catch (error) {
console.error(error);
@ -49,14 +56,20 @@ async function fetchLatest(id) {
async function fetchOldest(id) {
try {
let last24Hrs;
const result = await app.client.conversations.history({
token: token,
channel: id,
oldest: Math.floor(Date.now() / 1000) - 86400, //debug: 1596326400, actual: Math.floor(Date.now() / 1000) - 86400
inclusive: false
oldest: Math.floor(Date.now() / 1000) - 86400, //debug: 1609295166, actual: Math.floor(Date.now() / 1000) - 86400
inclusive: false,
});
const number = extractNumber(result.messages[result.messages.length - 2].text);
let number;
for (let x = result.messages.length - 2; x >= 0 ; x--) {
number = extractNumber(
result.messages[x].text,
);
if (!isNaN(number)) break;
}
return number - 1;
} catch (error) {
console.error(error);