From 4acd782f7419c581d859b50e872241fb232adc5f Mon Sep 17 00:00:00 2001 From: Steven Conaway Date: Wed, 30 Dec 2020 17:24:12 -0800 Subject: [PATCH 1/3] Add .gitignore --- .gitignore | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2ab2320 --- /dev/null +++ b/.gitignore @@ -0,0 +1,115 @@ +# Created by https://www.toptal.com/developers/gitignore/api/node +# Edit at https://www.toptal.com/developers/gitignore?templates=node + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test +.env*.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# End of https://www.toptal.com/developers/gitignore/api/node From f8231e2367df294c0b3e84cd78f6444d1d34cb2a Mon Sep 17 00:00:00 2001 From: Steven Conaway Date: Wed, 30 Dec 2020 17:24:32 -0800 Subject: [PATCH 2/3] fix paths in package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 05ee610..2ffba49 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,9 @@ "name": "bolt-app-template", "version": "0.0.1", "description": "A basic template to spin up a Bolt app for Slack", - "main": "app.js", + "main": "api/app.js", "scripts": { - "start": "node app.js" + "start": "node api/app.js" }, "dependencies": { "@slack/bolt": "^2.2.3", From ad78df1314f061680c941012e440d045b55edb94 Mon Sep 17 00:00:00 2001 From: Steven Conaway Date: Wed, 30 Dec 2020 17:26:22 -0800 Subject: [PATCH 3/3] make fetchOldest and fetchLatest search for a valid number --- api/app.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/api/app.js b/api/app.js index 32c3b7d..152facd 100644 --- a/api/app.js +++ b/api/app.js @@ -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);