Merge pull request #4 from SConaway/fetchOldest-fetchNewest-grab-valid
Make fetchOldest and fetchLatest search for a valid number
This commit is contained in:
commit
2f142d1981
3 changed files with 136 additions and 8 deletions
115
.gitignore
vendored
Normal file
115
.gitignore
vendored
Normal file
|
@ -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
|
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);
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
"name": "bolt-app-template",
|
"name": "bolt-app-template",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "A basic template to spin up a Bolt app for Slack",
|
"description": "A basic template to spin up a Bolt app for Slack",
|
||||||
"main": "app.js",
|
"main": "api/app.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node app.js"
|
"start": "node api/app.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@slack/bolt": "^2.2.3",
|
"@slack/bolt": "^2.2.3",
|
||||||
|
|
Loading…
Add table
Reference in a new issue