make fetchOldest and fetchLatest search for a valid number
This commit is contained in:
parent
f8231e2367
commit
ad78df1314
1 changed files with 19 additions and 6 deletions
25
api/app.js
25
api/app.js
|
@ -38,9 +38,16 @@ async function fetchLatest(id) {
|
||||||
const result = await app.client.conversations.history({
|
const result = await app.client.conversations.history({
|
||||||
token: token,
|
token: token,
|
||||||
channel: id,
|
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;
|
return number;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
@ -49,14 +56,20 @@ async function fetchLatest(id) {
|
||||||
|
|
||||||
async function fetchOldest(id) {
|
async function fetchOldest(id) {
|
||||||
try {
|
try {
|
||||||
let last24Hrs;
|
|
||||||
const result = await app.client.conversations.history({
|
const result = await app.client.conversations.history({
|
||||||
token: token,
|
token: token,
|
||||||
channel: id,
|
channel: id,
|
||||||
oldest: Math.floor(Date.now() / 1000) - 86400, //debug: 1596326400, actual: Math.floor(Date.now() / 1000) - 86400
|
oldest: Math.floor(Date.now() / 1000) - 86400, //debug: 1609295166, actual: Math.floor(Date.now() / 1000) - 86400
|
||||||
inclusive: false
|
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;
|
return number - 1;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
Loading…
Add table
Reference in a new issue