Fix various issues
This commit is contained in:
parent
7c58140511
commit
60ca079fa0
9 changed files with 810 additions and 1551 deletions
|
@ -1,7 +0,0 @@
|
|||
{"name":"drag-in-files.svg","date":"2016-10-22T16:17:49.954Z","url":"https://cdn.hyperdev.com/drag-in-files.svg","type":"image/svg","size":7646,"imageWidth":276,"imageHeight":276,"thumbnail":"https://cdn.hyperdev.com/drag-in-files.svg","thumbnailWidth":276,"thumbnailHeight":276,"dominantColor":"rgb(102, 153, 205)","uuid":"adSBq97hhhpFNUna"}
|
||||
{"name":"click-me.svg","date":"2016-10-23T16:17:49.954Z","url":"https://cdn.hyperdev.com/click-me.svg","type":"image/svg","size":7116,"imageWidth":276,"imageHeight":276,"thumbnail":"https://cdn.hyperdev.com/click-me.svg","thumbnailWidth":276,"thumbnailHeight":276,"dominantColor":"rgb(243, 185, 186)","uuid":"adSBq97hhhpFNUnb"}
|
||||
{"name":"paste-me.svg","date":"2016-10-24T16:17:49.954Z","url":"https://cdn.hyperdev.com/paste-me.svg","type":"image/svg","size":7242,"imageWidth":276,"imageHeight":276,"thumbnail":"https://cdn.hyperdev.com/paste-me.svg","thumbnailWidth":276,"thumbnailHeight":276,"dominantColor":"rgb(42, 179, 185)","uuid":"adSBq97hhhpFNUnc"}
|
||||
{"uuid":"adSBq97hhhpFNUna","deleted":true}
|
||||
{"uuid":"adSBq97hhhpFNUnb","deleted":true}
|
||||
{"uuid":"adSBq97hhhpFNUnc","deleted":true}
|
||||
{"name":"botdemo.png","date":"2020-07-17T01:20:39.444Z","url":"https://cdn.glitch.com/95c2faf1-779e-4e08-b219-8a122cdceefe%2Fbotdemo.png","type":"image/png","size":65589,"imageWidth":842,"imageHeight":290,"thumbnail":"https://cdn.glitch.com/95c2faf1-779e-4e08-b219-8a122cdceefe%2Fthumbnails%2Fbotdemo.png","thumbnailWidth":330,"thumbnailHeight":114,"uuid":"7cdZLaCux0c3Mte2"}
|
76
.replit
76
.replit
|
@ -1,76 +0,0 @@
|
|||
entrypoint = "index.js"
|
||||
|
||||
hidden = [".config"]
|
||||
run = "node api/app.js"
|
||||
|
||||
[[hints]]
|
||||
regex = "Error \\[ERR_REQUIRE_ESM\\]"
|
||||
message = "We see that you are using require(...) inside your code. We currently do not support this syntax. Please use 'import' instead when using external modules. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)"
|
||||
|
||||
[nix]
|
||||
channel = "stable-21_11"
|
||||
|
||||
[env]
|
||||
PATH = "/home/runner/$REPL_SLUG/.config/npm/node_global/bin:/home/runner/$REPL_SLUG/node_modules/.bin"
|
||||
XDG_CONFIG_HOME = "/home/runner/.config"
|
||||
npm_config_prefix = "/home/runner/$REPL_SLUG/.config/npm/node_global"
|
||||
|
||||
[gitHubImport]
|
||||
requiredFiles = [".replit", "replit.nix", ".config"]
|
||||
|
||||
[packager]
|
||||
language = "nodejs"
|
||||
|
||||
[packager.features]
|
||||
packageSearch = true
|
||||
guessImports = true
|
||||
enabledForHosting = false
|
||||
|
||||
[unitTest]
|
||||
language = "nodejs"
|
||||
|
||||
[languages.javascript]
|
||||
pattern = "**/{*.js,*.jsx,*.ts,*.tsx}"
|
||||
|
||||
[languages.javascript.languageServer]
|
||||
start = "typescript-language-server --stdio"
|
||||
|
||||
[debugger]
|
||||
support = true
|
||||
|
||||
[debugger.interactive]
|
||||
transport = "localhost:0"
|
||||
startCommand = [ "dap-node" ]
|
||||
|
||||
[debugger.interactive.initializeMessage]
|
||||
command = "initialize"
|
||||
type = "request"
|
||||
|
||||
[debugger.interactive.initializeMessage.arguments]
|
||||
clientID = "replit"
|
||||
clientName = "replit.com"
|
||||
columnsStartAt1 = true
|
||||
linesStartAt1 = true
|
||||
locale = "en-us"
|
||||
pathFormat = "path"
|
||||
supportsInvalidatedEvent = true
|
||||
supportsProgressReporting = true
|
||||
supportsRunInTerminalRequest = true
|
||||
supportsVariablePaging = true
|
||||
supportsVariableType = true
|
||||
|
||||
[debugger.interactive.launchMessage]
|
||||
command = "launch"
|
||||
type = "request"
|
||||
|
||||
[debugger.interactive.launchMessage.arguments]
|
||||
args = []
|
||||
console = "externalTerminal"
|
||||
cwd = "."
|
||||
environment = []
|
||||
pauseForSourceMap = false
|
||||
program = "./index.js"
|
||||
request = "launch"
|
||||
sourceMaps = true
|
||||
stopOnEntry = false
|
||||
type = "pwa-node"
|
|
@ -1,2 +0,0 @@
|
|||
language = "nodejs"
|
||||
run = "node api/app.js"
|
67
api/app.js
67
api/app.js
|
@ -1,21 +1,21 @@
|
|||
// Require the Bolt package (github.com/slackapi/bolt)
|
||||
const { App } = require("@slack/bolt");
|
||||
// const keep_alive = require('./keep_alive.js');
|
||||
const addQuotes = require('./quotes.js');
|
||||
const schedule = require('node-schedule');
|
||||
const moment = require('moment');
|
||||
const token = process.env.SLACK_BOT_TOKEN;
|
||||
const channel = "CDJMS683D";
|
||||
const Airtable = require('airtable');
|
||||
require('dotenv').config();
|
||||
|
||||
Airtable.configure({
|
||||
endpointUrl: 'https://api.airtable.com',
|
||||
apiKey: process.env.AIRTABLE_API_KEY
|
||||
});
|
||||
const base = Airtable.base('appogmRaVRo5ElVH7');
|
||||
let speedArr = [];
|
||||
let latest;
|
||||
const base = Airtable.base(process.env.AIRTABLE_BASE_ID);
|
||||
|
||||
const goalDate = '10/31/2023';
|
||||
const token = process.env.SLACK_BOT_TOKEN;
|
||||
const channel = process.env.SLACK_MILLION_CHANNEL;
|
||||
const port = process.env.PORT ?? 3000;
|
||||
|
||||
const goalDate = '12/31/2023';
|
||||
const goalNumber = 300000;
|
||||
|
||||
const app = new App({
|
||||
|
@ -78,7 +78,7 @@ async function fetchOldest(id) {
|
|||
|
||||
async function publishMessage(id, text) {
|
||||
try {
|
||||
const result = await app.client.chat.postMessage({
|
||||
await app.client.chat.postMessage({
|
||||
token: token,
|
||||
channel: id,
|
||||
text: text
|
||||
|
@ -90,7 +90,7 @@ async function publishMessage(id, text) {
|
|||
|
||||
async function postReaction(id, emoji, ts) {
|
||||
try {
|
||||
const result = await app.client.reactions.add({
|
||||
await app.client.reactions.add({
|
||||
token: token,
|
||||
channel: id,
|
||||
name: emoji,
|
||||
|
@ -103,7 +103,7 @@ async function postReaction(id, emoji, ts) {
|
|||
|
||||
async function pinMessage(id, ts) {
|
||||
try {
|
||||
const result = await app.client.pins.add({
|
||||
await app.client.pins.add({
|
||||
token: token,
|
||||
channel: id,
|
||||
timestamp: ts
|
||||
|
@ -113,21 +113,12 @@ async function pinMessage(id, ts) {
|
|||
}
|
||||
}
|
||||
|
||||
function findMean(arr) {
|
||||
let totalSum = 0;
|
||||
for (let i of arr) {
|
||||
totalSum += i;
|
||||
}
|
||||
return totalSum / arr.length;
|
||||
}
|
||||
|
||||
async function addData(db, object) {
|
||||
base(db).create(object, function(err, record) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
// console.log(record.getId());
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -143,30 +134,24 @@ async function getAverage() {
|
|||
let sum = 0;
|
||||
obj.forEach((item) => (sum += item.fields.increase));
|
||||
|
||||
return sum / 30;
|
||||
return sum / obj.length;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async function report() {
|
||||
console.log("Writing daily report...");
|
||||
let oldest = await fetchOldest(channel);
|
||||
let latest = await fetchLatest(channel);
|
||||
let diff = latest - oldest;
|
||||
addData('increase', {
|
||||
"Date": moment().subtract(1, "days").format("YYYY-MM-DD"),
|
||||
"increase": diff,
|
||||
"stats": [
|
||||
"rec2XI8QAsPr7EMVB"
|
||||
],
|
||||
"start": oldest,
|
||||
})
|
||||
let averageSpeed = await getAverage();
|
||||
let thousandsGoal = Math.ceil(latest / 1000) * 1000;
|
||||
let thousandsTime = predictTime(thousandsGoal, latest, averageSpeed);
|
||||
// let tenThousandsGoal = Math.ceil(latest / 5000) * 5000;
|
||||
let pastThousandsGoal = Math.floor(latest / 1000) * 1000;
|
||||
// let tenThousandsTime = predictTime(tenThousandsGoal, latest, averageSpeed);
|
||||
let goals = predictSpeed(goalDate, goalNumber, latest);
|
||||
let message =
|
||||
`Today we've went from *${oldest}* to *${latest}*!
|
||||
|
@ -178,20 +163,13 @@ async function report() {
|
|||
if (pastThousandsGoal > oldest && pastThousandsGoal <= latest) {
|
||||
let messageWithCelebration = `:tada: Congratulations! We've went past ${pastThousandsGoal}! :tada: \n` + message;
|
||||
publishMessage(channel, addQuotes(messageWithCelebration, goals, averageSpeed));
|
||||
// publishMessage('C017W4PHYKS', addQuotes(messageWithCelebration, goals, averageSpeed));
|
||||
} else {
|
||||
publishMessage(channel, addQuotes(message, goals, averageSpeed));
|
||||
// publishMessage('C017W4PHYKS', addQuotes(message, goals, averageSpeed));
|
||||
}
|
||||
|
||||
console.log("Sent daily report.");
|
||||
};
|
||||
|
||||
function predictTime(goal, recent, averageSpeed) {
|
||||
let daysLeft = (goal - recent) / averageSpeed;
|
||||
let unix = new Date(Date.now() + daysLeft * 86400000);
|
||||
return moment(unix).fromNow();
|
||||
}
|
||||
|
||||
function predictSpeed(goalDate, goalNumber, currentNumber) {
|
||||
let today = new Date();
|
||||
let goal = new Date(goalDate);
|
||||
|
@ -205,7 +183,6 @@ function predictSpeed(goalDate, goalNumber, currentNumber) {
|
|||
app.event('message', async (body) => {
|
||||
try {
|
||||
let e = body.event;
|
||||
console.log(e);
|
||||
if (typeof e.subtype === "undefined" && /\d/.test(e.text[0])) {
|
||||
let number = extractNumber(e.text);
|
||||
let ts = e.ts;
|
||||
|
@ -216,7 +193,6 @@ app.event('message', async (body) => {
|
|||
if (number % 5000 === 0) {
|
||||
pinMessage(c, ts);
|
||||
}
|
||||
let l = number.length;
|
||||
if (number.slice(-2) === '69') {
|
||||
postReaction(c, "ok_hand", ts);
|
||||
}
|
||||
|
@ -244,20 +220,21 @@ app.event('app_mention', async (body) => {
|
|||
"What is it? Are you going too slow that you need another supernatural being to help you _speed-count_? If so, you've found the wrong one, because this supernatural being is _trying to sleep!_",
|
||||
"HISSSSSSSSSSS!",
|
||||
"Minions, I had _three hours_ of sleep yesterday, and I am trying to catch up. Please, _leave me alone to sleep._",
|
||||
]
|
||||
];
|
||||
|
||||
publishMessage(c, messageArray[choose])
|
||||
publishMessage(c, messageArray[choose]);
|
||||
|
||||
console.log("App mentioned.");
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
});
|
||||
|
||||
(async (req, res) => {
|
||||
// Start your app
|
||||
(async () => {
|
||||
try {
|
||||
await app.start(process.env.PORT || 3000);
|
||||
let j = schedule.scheduleJob('0 0 * * *', report);
|
||||
// let j = schedule.scheduleJob('*/15 * * * * *', report);
|
||||
await app.start(port);
|
||||
schedule.scheduleJob('0 0 * * *', report);
|
||||
console.log(`Started bot, listening on port ${port}`)
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ let regularEndQuotes = [
|
|||
|
||||
function addQuotes(message, rawGoals, rawSpeed) {
|
||||
let start = regularStartQuotes[Math.floor(Math.random() * regularStartQuotes.length)]
|
||||
let end;
|
||||
let end =regularEndQuotes[Math.floor(Math.random() * regularEndQuotes.length)];
|
||||
let goals = Math.ceil(rawGoals[1]);
|
||||
let days = rawGoals[0];
|
||||
let speed = Math.round(rawSpeed);
|
||||
|
@ -36,7 +36,6 @@ function addQuotes(message, rawGoals, rawSpeed) {
|
|||
} else if (diff > 1000) {
|
||||
end = `You're slogging behind, my minions! Only *${speed}* a day? RiDONKulous! Get that speed up to at least *+${goals}* to get there on time! Hurry up!!! You have *${days}* days left to get there!`
|
||||
}
|
||||
// let end = regularEndQuotes[Math.floor(Math.random() * regularEndQuotes.length)]
|
||||
return start + "\n" + message + "\n" + end;
|
||||
}
|
||||
|
||||
|
|
1156
package-lock.json
generated
1156
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -9,6 +9,7 @@
|
|||
"dependencies": {
|
||||
"@slack/bolt": "^3.3.0",
|
||||
"airtable": "^0.11.0",
|
||||
"dotenv": "^16.3.1",
|
||||
"moment": "^2.29.1",
|
||||
"node-schedule": "^2.0.0"
|
||||
},
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
{ pkgs }: {
|
||||
deps = [
|
||||
pkgs.nodejs-12_x
|
||||
pkgs.nodePackages.typescript-language-server
|
||||
pkgs.yarn
|
||||
pkgs.replitPackages.jest
|
||||
];
|
||||
}
|
1041
shrinkwrap.yaml
1041
shrinkwrap.yaml
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue