mirror of
https://github.com/System-End/slack-end.git
synced 2026-04-19 16:28:19 +00:00
chore: zeon:ai_comment
This commit is contained in:
parent
e7e66d88ee
commit
5fe861ac0d
8 changed files with 138 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -135,3 +135,4 @@ t2.ts
|
|||
ctf/unenc
|
||||
*.bin
|
||||
*.txt
|
||||
t3.ts
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
"@sentry/profiling-node": "^8.41.0",
|
||||
"@slack/bolt": "^3.21.2",
|
||||
"body-parser": "latest",
|
||||
"cheerio": "^1.0.0",
|
||||
"cheerio": "latest",
|
||||
"dotenv": "^16.4.5",
|
||||
"eventsource": "latest",
|
||||
"form-data": "^4.0.1",
|
||||
|
|
|
|||
28
src/commands/bdays.ts
Normal file
28
src/commands/bdays.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { App } from "@slack/bolt";
|
||||
import { Command, onlyForMe } from "../modules/BaseCommand";
|
||||
|
||||
export default class Ping implements Command {
|
||||
name: string;
|
||||
description: string;
|
||||
constructor() {
|
||||
this.name = `/bday`;
|
||||
this.description = `Bday :D`;
|
||||
}
|
||||
run(app: App) {
|
||||
// app.command()
|
||||
app.command(this.name, async ({ command, ack, respond }) => {
|
||||
const stamp = Date.now();
|
||||
await ack();
|
||||
|
||||
// first make it store them
|
||||
// TODO
|
||||
const args = command.text.split(/ +/)
|
||||
const cmd = args.shift().toLowerCase()
|
||||
if(cmd == "config") {
|
||||
|
||||
} else if(cmd == "remove-my-data") {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
31
src/commands/shipments-hackclub.ts
Normal file
31
src/commands/shipments-hackclub.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { App } from "@slack/bolt";
|
||||
import { Command, onlyForMe } from "../modules/BaseCommand";
|
||||
import { createShipmentURL } from "../modules/parseShipments";
|
||||
import { ModifiedApp } from "../modules/slackapp";
|
||||
|
||||
export default class Ping implements Command {
|
||||
name: string;
|
||||
description: string;
|
||||
constructor() {
|
||||
this.name = `/zeon-hackclub-shipments`;
|
||||
this.description = `add your shipment url so zeon can scarpe them`;
|
||||
}
|
||||
run(app: ModifiedApp) {
|
||||
// app.command()
|
||||
app.command(this.name, async ({ command, ack, respond }) => {
|
||||
const stamp = Date.now();
|
||||
await ack();
|
||||
|
||||
|
||||
// respond(`Pong took: \`${Date.now() - stamp}ms\``).then((d) => {
|
||||
// console.debug(`after ping`, d);
|
||||
// });
|
||||
const shipmentURL = command.text
|
||||
if (!shipmentURL) return respond(`:x: You need to provide a shipment url.`);
|
||||
const parse = new URLSearchParams(shipmentURL)
|
||||
const properURL = createShipmentURL(parse.get(`signature`), parse.get(`email`))
|
||||
await app.db.set(`shipment_url_${command.user_id}`, properURL)
|
||||
respond(`:white_check_mark: Shipment URL was set! check the app home to see ur packages`)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -199,5 +199,14 @@ cron.schedule("0 23 * 12 *", async () => {
|
|||
cron.schedule("0 0 * 12 *", () => {
|
||||
app.utils.adventOfCode.newDayNewChallange(app, `C01GF9987SL`);
|
||||
});
|
||||
cron.schedule("* * * * *", async () => {
|
||||
const allUsersWithAShipmentURL = Object.keys(app.db.JSON()).filter(e=>e.startsWith(`shipment_url_`))
|
||||
if(allUsersWithAShipmentURL.length > 0) {
|
||||
for(const userURLID of allUsersWithAShipmentURL) {
|
||||
const shipments = await app.utils.hcshipments.parseShipments(app.db.get(`userURLID`))
|
||||
await app.db.set(`shipments_${userURLID}`, shipments)
|
||||
}
|
||||
}
|
||||
})
|
||||
process.on("unhandledRejection", handleError);
|
||||
process.on("unhandledException", handleError);
|
||||
|
|
|
|||
|
|
@ -10,3 +10,4 @@ export * as songs from "./Songs";
|
|||
export * as nextdns from "./nextdns";
|
||||
export * as hacktime from "./hacktime";
|
||||
export * as adventOfCode from "./adventofcode";
|
||||
export * as hcshipments from "./parseShipments"
|
||||
65
src/modules/parseShipments.ts
Normal file
65
src/modules/parseShipments.ts
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
const cheerio = require('cheerio')
|
||||
export function createShipmentURL(token: string, email: string) {
|
||||
return `https://shipment-viewer.hackclub.com/shipments?email=${encodeURIComponent(email)}&signature=${token}&show_ids=yep`
|
||||
}
|
||||
export function requestEmailForUser() {
|
||||
// TODO
|
||||
}
|
||||
export function parseShipments(shipmentsURL: string) {
|
||||
return new Promise((res,rej) => {
|
||||
const final = []
|
||||
fetch(shipmentsURL).then(r=>r.text()).then(rhtml => {
|
||||
const $ = cheerio.load(rhtml)
|
||||
const divs = ($(`[class="col-12 col-sm-6 col-md-4 col-lg-4"]`))
|
||||
for (const d of divs) {
|
||||
// console.log(d)
|
||||
const dd = $(d)
|
||||
// YYYY-MM-DD
|
||||
const addedDate = $(dd.find(`[class="card-header d-flex align-items-center justify-content-between"]`)).text().replaceAll(`on`, ``).replaceAll(`fulfilled`, ``).replaceAll(`added`, ``).trim()
|
||||
let isDone = $(dd.find(`[class="card-header d-flex align-items-center justify-content-between"]`)).text().includes(`fulfilled`)
|
||||
const shipmentTitle = $(dd.find(`[class="card-title"]`)).text()
|
||||
const potshipProvider = $(Array.from($(dd.find(`[class="card-body"] > div > p`)))[0])
|
||||
const potContents = $($(dd.find(`[class="card-body"] > div > ul`)))
|
||||
const potTracking = $($(Array.from(dd.find(`p`)).find(e=>$(e).text().startsWith(`tracking #`))).find(`a`))
|
||||
const Airtable = $($(Array.from(dd.find(`p`)).find(e=>$(e).text().startsWith(`Airtable`))).find(`a`))
|
||||
let airtable = null;
|
||||
let tracking = null
|
||||
let shiprovider = null;
|
||||
let contents = null;
|
||||
if(potContents) {
|
||||
contents = (Array.from(potContents.find(`li`)).map(e=>$(e).text()))
|
||||
}
|
||||
|
||||
// console.log(potTrackingUrl.html())
|
||||
if(potTracking.html()) {
|
||||
tracking = {
|
||||
text: potTracking.text(),
|
||||
url: potTracking.attr(`href`)
|
||||
}
|
||||
}
|
||||
if(Airtable.html()) {
|
||||
airtable = {
|
||||
text: Airtable.text(),
|
||||
url: Airtable.attr(`href`)
|
||||
}
|
||||
}
|
||||
if(potshipProvider.html) {
|
||||
shiprovider = potshipProvider.text()
|
||||
}
|
||||
final.push({
|
||||
shipmentTitle,
|
||||
shipmentsURL,
|
||||
shiprovider,
|
||||
tracking,
|
||||
isDone,
|
||||
contents,
|
||||
airtable,
|
||||
addedDate
|
||||
})
|
||||
|
||||
}
|
||||
// console.log(final)
|
||||
res (final)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
@ -1082,7 +1082,7 @@ cheerio-select@^2.1.0:
|
|||
domhandler "^5.0.3"
|
||||
domutils "^3.0.1"
|
||||
|
||||
cheerio@^1.0.0:
|
||||
cheerio@latest:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/cheerio/-/cheerio-1.0.0.tgz#1ede4895a82f26e8af71009f961a9b8cb60d6a81"
|
||||
integrity sha512-quS9HgjQpdaXOvsZz82Oz7uxtXiy6UIsIQcpBj7HRw2M63Skasm9qlDocAM7jNuaxdhpPU7c4kJN+gA5MCu4ww==
|
||||
|
|
@ -1216,7 +1216,7 @@ core-util-is@~1.0.0:
|
|||
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"
|
||||
integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==
|
||||
|
||||
cors@~2.8.5:
|
||||
cors@latest, cors@~2.8.5:
|
||||
version "2.8.5"
|
||||
resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29"
|
||||
integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue